added BidForFixActivity, rather than having bidforfix as preferences

This commit is contained in:
Pavol Zibrita 2012-02-21 03:42:27 +01:00
parent 00e5b26e58
commit d4871ef33a
9 changed files with 430 additions and 18 deletions

View file

@ -8,7 +8,15 @@
<!-- <uses-sdk android:minSdkVersion="3"/> -->
<!-- uncomment it to allow different screen supports (large/small)-->
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="4"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
<uses-permission android:name="android.permission.WAKE_LOCK"></uses-permission>
<application android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@style/OsmandTheme"
android:debuggable="true" android:name="net.osmand.plus.OsmandApplication"
android:backupAgent="net.osmand.plus.OsmandBackupAgent" android:restoreAnyVersion="true">
@ -72,15 +80,8 @@
<action android:name="com.android.vending.INSTALL_REFERRER" />
</intent-filter>
</receiver>
<activity android:name="net.osmand.plus.activities.OsmandBidForFixActivity"></activity>
</application>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
<uses-permission android:name="android.permission.WAKE_LOCK"></uses-permission>
</manifest>

View file

@ -0,0 +1,59 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/bidforfixitemlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white" >
<TextView
android:id="@+id/bffiText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="24dp"
android:layout_marginTop="8dp"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#72B123" />
<View
android:id="@+id/ruler"
android:layout_width="wrap_content"
android:layout_height="1px"
android:layout_alignParentLeft="true"
android:layout_below="@+id/bffiText"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="6dp"
android:background="#B0B0B0" />
<TextView
android:id="@+id/bffiSupport"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/bffiText"
android:layout_below="@+id/bffiText"
android:layout_marginTop="16dp"
android:text="18 supporters"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="@+id/bffiFunded"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/bffiSupport"
android:layout_below="@+id/bffiSupport"
android:text="Funded: 65%"
android:textAppearance="?android:attr/textAppearanceSmall" />
<ImageView
android:id="@+id/bffiGraph"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/bffiSupport"
android:layout_marginRight="20dp"
android:src="@android:drawable/alert_dark_frame" />
</RelativeLayout>

View file

@ -136,6 +136,9 @@
<CheckBoxPreference android:key="scroll_map_by_gestures" android:title="@string/scroll_map_by_gestures" android:summary="@string/scroll_map_by_gestures_descr"></CheckBoxPreference>
<CheckBoxPreference android:key="use_short_object_names" android:title="@string/use_short_object_names" android:summary="@string/use_short_object_names_descr"></CheckBoxPreference>
</PreferenceScreen>
<Preference android:title="@string/support_new_features" android:key="bidforfix">
</Preference>
</PreferenceCategory>

View file

@ -0,0 +1,202 @@
package com.bidforfix.andorid;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import net.osmand.plus.R;
import android.app.Activity;
import android.app.Dialog;
import android.app.ListActivity;
import android.app.ProgressDialog;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import com.bidforfix.andorid.BidForFixHelper.BFFIssue;
import com.gafmedia.Graph.PieItem;
import com.gafmedia.Graph.View_PieChart;
public abstract class BidForFixActivity extends ListActivity {
private static final int LOAD_ITEMS = 0;
LoadItemsTask loadItemTask;
private BidForFixHelper helper;
public abstract BidForFixHelper getBidForFixHelper();
private BidForFixHelper getHelper() {
if (helper == null) {
helper = getBidForFixHelper();
}
return helper;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(android.R.style.Theme_Light);
super.onCreate(savedInstanceState);
if (getHelper().isReloadNeeded()) {
showDialog(LOAD_ITEMS);
} else {
setListAdapter(new BFFIssueArrayAdapter(this, getHelper().getList()));
}
}
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case LOAD_ITEMS:
return new ProgressDialog(this);
}
return super.onCreateDialog(id);
}
@Override
protected void onPrepareDialog(int id, Dialog dialog) {
switch (id) {
case LOAD_ITEMS:
dialog.setTitle("Loading");
loadItemTask = new LoadItemsTask((ProgressDialog)dialog);
loadItemTask.execute();
return;
}
super.onPrepareDialog(id, dialog);
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
BFFIssue issue = (BFFIssue) getListAdapter().getItem(position);
String url = issue.getLink();
try {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
} catch (ActivityNotFoundException ex) {
Toast.makeText(this, ex.getMessage() + " for " + url, Toast.LENGTH_LONG).show();
}
super.onListItemClick(l, v, position, id);
}
public class LoadItemsTask extends AsyncTask<Object, Integer, Integer> {
private final ProgressDialog dialog;
public LoadItemsTask(ProgressDialog dialog) {
this.dialog = dialog;
this.dialog.setIndeterminate(true);
}
@Override
protected Integer doInBackground(Object... params) {
getHelper().loadList();
return null;
}
@Override
protected void onPostExecute(Integer result) {
super.onPostExecute(result);
//set the adapater (clear,set)
setListAdapter(new BFFIssueArrayAdapter(BidForFixActivity.this, getHelper().getList()));
dismissDialog(LOAD_ITEMS);
}
}
public static class BFFIssueArrayAdapter extends ArrayAdapter<BFFIssue> {
private final Activity context;
private final List<BFFIssue> values;
Random random = new Random();
static class ViewHolder {
public TextView text;
public ImageView image;
public TextView support;
public TextView funded;
}
public BFFIssueArrayAdapter(Activity context, List<BFFIssue> values) {
super(context, R.layout.list_item_bidforfix, values);
this.context = context;
this.values = values;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View rowView = convertView;
if (rowView == null) {
LayoutInflater inflater = context.getLayoutInflater();
rowView = inflater.inflate(R.layout.list_item_bidforfix, null);
ViewHolder viewHolder = new ViewHolder();
viewHolder.text = (TextView) rowView.findViewById(R.id.bffiText);
viewHolder.support = (TextView) rowView.findViewById(R.id.bffiSupport);
viewHolder.funded = (TextView) rowView.findViewById(R.id.bffiFunded);
viewHolder.image = (ImageView) rowView.findViewById(R.id.bffiGraph);
rowView.setTag(viewHolder);
}
ViewHolder holder = (ViewHolder) rowView.getTag();
BFFIssue s = values.get(position);
holder.text.setText(s.getName());
holder.support.setText("18 Supporters");
int funded = random.nextInt(100);
holder.funded.setText("funded: "+funded+"%");
List<PieItem> PieData = new ArrayList<PieItem>();
PieItem item = new PieItem();
item.Count = funded;
item.Color = 0xFF72B123;
PieItem item2 = new PieItem();
item2.Count = 100-funded;
item2.Color = 0xFFDDDDDD;
PieData.add(item);
PieData.add(item2);
int Size = Math.max(holder.image.getHeight(),40);
Bitmap mBackgroundImage = Bitmap.createBitmap(Size, Size, Bitmap.Config.RGB_565);
//------------------------------------------------------------------------------------------
// Generating Pie view
//------------------------------------------------------------------------------------------
View_PieChart pieChartView = new View_PieChart(context);
pieChartView.setLayoutParams(new LayoutParams(Size, Size));
pieChartView.setGeometry(Size, Size, 2, 2, 2, 2, -1); //OverlayId);
pieChartView.setSkinParams(0xffffffff);
pieChartView.setData(PieData, 100);
pieChartView.invalidate();
//------------------------------------------------------------------------------------------
// Draw Pie Vien on Bitmap canvas
//------------------------------------------------------------------------------------------
pieChartView.draw(new Canvas(mBackgroundImage));
pieChartView = null;
holder.image.setImageBitmap(mBackgroundImage);
//MaxCount += ItemCount;
// if (s.startsWith("Windows7") || s.startsWith("iPhone")
// || s.startsWith("Solaris")) {
// holder.image.setImageResource(R.drawable.no);
// } else {
// holder.image.setImageResource(R.drawable.ok);
// }
return rowView;
}
}
}

View file

@ -101,8 +101,16 @@ public class BidForFixHelper {
this.cancelButton = cancelButton;
}
private void loadList() {
if (initialized == null || initialized.before(new Date(System.currentTimeMillis()-DAY))) {
public boolean isReloadNeeded() {
return initialized == null || initialized.before(new Date(System.currentTimeMillis()-DAY));
}
public List<BFFIssue> getList() {
return bffIssues;
}
public void loadList() {
if (isReloadNeeded()) {
BufferedReader in = null;
String url = "http://www.bidforfix.com/p/" + project + "/issues/";
try {

View file

@ -0,0 +1,7 @@
package com.gafmedia.Graph;
public class PieItem {
public int Count;
public String Label;
public float Percent;
public int Color;
}

View file

@ -0,0 +1,116 @@
package com.gafmedia.Graph;
import com.gafmedia.Graph.PieItem;
import java.util.List;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.BitmapFactory.Options;
import android.util.AttributeSet;
import android.view.View;
public class View_PieChart extends View {
private static final int WAIT = 0;
private static final int IS_READY_TO_DRAW = 1;
private static final int IS_DRAW = 2;
private static final float START_INC = 30;
private Paint mBgPaints = new Paint();
private Paint mLinePaints = new Paint();
private int mOverlayId;
private int mWidth;
private int mHeight;
private int mGapLeft;
private int mGapRight;
private int mGapTop;
private int mGapBottom;
private int mBgColor;
private int mState = WAIT;
private float mStart;
private float mSweep;
private int mMaxConnection;
private List<PieItem> mDataArray;
//--------------------------------------------------------------------------------------
public View_PieChart (Context context){
super(context);
}
//--------------------------------------------------------------------------------------
public View_PieChart(Context context, AttributeSet attrs) {
super(context, attrs);
}
//--------------------------------------------------------------------------------------
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
//------------------------------------------------------
if (mState != IS_READY_TO_DRAW) return;
canvas.drawColor(mBgColor);
//------------------------------------------------------
mBgPaints.setAntiAlias(true);
mBgPaints.setStyle(Paint.Style.FILL);
mBgPaints.setColor(0x88FF0000);
mBgPaints.setStrokeWidth(0.5f);
//------------------------------------------------------
mLinePaints.setAntiAlias(true);
mLinePaints.setStyle(Paint.Style.STROKE);
mLinePaints.setColor(0xff000000);
mLinePaints.setStrokeWidth(0.5f);
//------------------------------------------------------
RectF mOvals = new RectF( mGapLeft, mGapTop, mWidth - mGapRight, mHeight - mGapBottom);
//------------------------------------------------------
mStart = START_INC;
PieItem Item;
for (int i = 0; i < mDataArray.size(); i++) {
Item = (PieItem) mDataArray.get(i);
mBgPaints.setColor(Item.Color);
mSweep = (float) 360 * ( (float)Item.Count / (float)mMaxConnection );
canvas.drawArc(mOvals, mStart, mSweep, true, mBgPaints);
canvas.drawArc(mOvals, mStart, mSweep, true, mLinePaints);
mStart += mSweep;
}
//------------------------------------------------------
Options options = new BitmapFactory.Options();
options.inScaled = false;
// Bitmap OverlayBitmap = BitmapFactory.decodeResource(getResources(), mOverlayId, options);
// canvas.drawBitmap(OverlayBitmap, 0.0f, 0.0f, null);
//------------------------------------------------------
mState = IS_DRAW;
}
//--------------------------------------------------------------------------------------
public void setGeometry(int width, int height, int GapLeft, int GapRight, int GapTop, int GapBottom, int OverlayId) {
mWidth = width;
mHeight = height;
mGapLeft = GapLeft;
mGapRight = GapRight;
mGapTop = GapTop;
mGapBottom = GapBottom;
mOverlayId = OverlayId;
}
//--------------------------------------------------------------------------------------
public void setSkinParams(int bgColor) {
mBgColor = bgColor;
}
//--------------------------------------------------------------------------------------
public void setData(List<PieItem> data, int MaxConnection) {
mDataArray = data;
mMaxConnection = MaxConnection;
mState = IS_READY_TO_DRAW;
}
//--------------------------------------------------------------------------------------
public void setState(int State) {
mState = State;
}
//--------------------------------------------------------------------------------------
public int getColorValue( int Index ) {
if (mDataArray == null) return 0;
if (Index < 0){
return ((PieItem)mDataArray.get(0)).Color;
} else if (Index >= mDataArray.size()){
return ((PieItem)mDataArray.get(mDataArray.size()-1)).Color;
} else {
return ((PieItem)mDataArray.get(mDataArray.size()-1)).Color;
}
}
}

View file

@ -0,0 +1,14 @@
package net.osmand.plus.activities;
import net.osmand.plus.OsmandApplication;
import com.bidforfix.andorid.BidForFixActivity;
import com.bidforfix.andorid.BidForFixHelper;
public class OsmandBidForFixActivity extends BidForFixActivity {
@Override
public BidForFixHelper getBidForFixHelper() {
return ((OsmandApplication) getApplication()).getBidForFix();
}
}

View file

@ -59,8 +59,6 @@ import android.preference.PreferenceCategory;
import android.preference.PreferenceScreen;
import android.widget.Toast;
import com.bidforfix.andorid.BidForFixHelper;
public class SettingsActivity extends PreferenceActivity implements OnPreferenceChangeListener, OnPreferenceClickListener {
public static final String INTENT_KEY_SETTINGS_SCREEN = "INTENT_KEY_SETTINGS_SCREEN";
@ -73,6 +71,7 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
private Preference saveCurrentTrack;
private Preference testVoiceCommands;
private Preference localOpenstreetmapPoints;
private Preference bidforfix;
private EditTextPreference applicationDir;
private ListPreference applicationModePreference;
@ -175,8 +174,8 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
PreferenceScreen screen = getPreferenceScreen();
osmandSettings = OsmandApplication.getSettings();
BidForFixHelper bidForFixHelper = getMyApplication().getBidForFix();
bidForFixHelper.generatePreferenceList(screen, getString(R.string.support_new_features), this);
// BidForFixHelper bidForFixHelper = getMyApplication().getBidForFix();
// bidForFixHelper.generatePreferenceList(screen, getString(R.string.support_new_features), this);
registerBooleanPreference(osmandSettings.SHOW_VIEW_ANGLE,screen);
registerBooleanPreference(osmandSettings.USE_TRACKBALL_FOR_MOVEMENTS,screen);
@ -359,8 +358,8 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
applicationDir.setOnPreferenceChangeListener(this);
localOpenstreetmapPoints = (Preference) screen.findPreference(OsmandSettings.LOCAL_OPENSTREETMAP_POINTS);
localOpenstreetmapPoints.setOnPreferenceClickListener(this);
bidforfix = (Preference) screen.findPreference("bidforfix");
bidforfix.setOnPreferenceClickListener(this);
broadcastReceiver = new BroadcastReceiver(){
@Override
@ -823,6 +822,9 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
} else if(preference == localOpenstreetmapPoints){
startActivity(new Intent(this, LocalOpenstreetmapActivity.class));
return true;
} else if(preference == bidforfix){
startActivity(new Intent(this, OsmandBidForFixActivity.class));
return true;
}
return false;
}