From d4871ef33a09e03db3db7ad4150645b5735fcf6e Mon Sep 17 00:00:00 2001 From: Pavol Zibrita Date: Tue, 21 Feb 2012 03:42:27 +0100 Subject: [PATCH] added BidForFixActivity, rather than having bidforfix as preferences --- OsmAnd/AndroidManifest.xml | 21 +- OsmAnd/res/layout/list_item_bidforfix.xml | 59 +++++ OsmAnd/res/xml/settings_pref.xml | 3 + .../bidforfix/andorid/BidForFixActivity.java | 202 ++++++++++++++++++ .../bidforfix/andorid/BidForFixHelper.java | 12 +- OsmAnd/src/com/gafmedia/Graph/PieItem.java | 7 + .../src/com/gafmedia/Graph/View_PieChart.java | 116 ++++++++++ .../activities/OsmandBidForFixActivity.java | 14 ++ .../plus/activities/SettingsActivity.java | 14 +- 9 files changed, 430 insertions(+), 18 deletions(-) create mode 100644 OsmAnd/res/layout/list_item_bidforfix.xml create mode 100644 OsmAnd/src/com/bidforfix/andorid/BidForFixActivity.java create mode 100644 OsmAnd/src/com/gafmedia/Graph/PieItem.java create mode 100644 OsmAnd/src/com/gafmedia/Graph/View_PieChart.java create mode 100644 OsmAnd/src/net/osmand/plus/activities/OsmandBidForFixActivity.java diff --git a/OsmAnd/AndroidManifest.xml b/OsmAnd/AndroidManifest.xml index b77f8db5b8..10963625a0 100644 --- a/OsmAnd/AndroidManifest.xml +++ b/OsmAnd/AndroidManifest.xml @@ -8,7 +8,15 @@ - + + + + + + + + + @@ -72,15 +80,8 @@ + + - - - - - - - - - diff --git a/OsmAnd/res/layout/list_item_bidforfix.xml b/OsmAnd/res/layout/list_item_bidforfix.xml new file mode 100644 index 0000000000..67eca6da5d --- /dev/null +++ b/OsmAnd/res/layout/list_item_bidforfix.xml @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/xml/settings_pref.xml b/OsmAnd/res/xml/settings_pref.xml index 30eb7a3c11..a81fbff5f8 100644 --- a/OsmAnd/res/xml/settings_pref.xml +++ b/OsmAnd/res/xml/settings_pref.xml @@ -136,6 +136,9 @@ + + + diff --git a/OsmAnd/src/com/bidforfix/andorid/BidForFixActivity.java b/OsmAnd/src/com/bidforfix/andorid/BidForFixActivity.java new file mode 100644 index 0000000000..c029214cc5 --- /dev/null +++ b/OsmAnd/src/com/bidforfix/andorid/BidForFixActivity.java @@ -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 { + + 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 { + private final Activity context; + private final List 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 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 PieData = new ArrayList(); + 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; + } + } +} diff --git a/OsmAnd/src/com/bidforfix/andorid/BidForFixHelper.java b/OsmAnd/src/com/bidforfix/andorid/BidForFixHelper.java index 3a6e69ba99..a135debfb8 100644 --- a/OsmAnd/src/com/bidforfix/andorid/BidForFixHelper.java +++ b/OsmAnd/src/com/bidforfix/andorid/BidForFixHelper.java @@ -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 getList() { + return bffIssues; + } + + public void loadList() { + if (isReloadNeeded()) { BufferedReader in = null; String url = "http://www.bidforfix.com/p/" + project + "/issues/"; try { diff --git a/OsmAnd/src/com/gafmedia/Graph/PieItem.java b/OsmAnd/src/com/gafmedia/Graph/PieItem.java new file mode 100644 index 0000000000..d00d262b93 --- /dev/null +++ b/OsmAnd/src/com/gafmedia/Graph/PieItem.java @@ -0,0 +1,7 @@ +package com.gafmedia.Graph; +public class PieItem { + public int Count; + public String Label; + public float Percent; + public int Color; +} diff --git a/OsmAnd/src/com/gafmedia/Graph/View_PieChart.java b/OsmAnd/src/com/gafmedia/Graph/View_PieChart.java new file mode 100644 index 0000000000..4a368b5e3c --- /dev/null +++ b/OsmAnd/src/com/gafmedia/Graph/View_PieChart.java @@ -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 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 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; + } + } +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/activities/OsmandBidForFixActivity.java b/OsmAnd/src/net/osmand/plus/activities/OsmandBidForFixActivity.java new file mode 100644 index 0000000000..17f94ed67f --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/activities/OsmandBidForFixActivity.java @@ -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(); + } +} diff --git a/OsmAnd/src/net/osmand/plus/activities/SettingsActivity.java b/OsmAnd/src/net/osmand/plus/activities/SettingsActivity.java index 17c2e1e83b..aa4b321c1b 100644 --- a/OsmAnd/src/net/osmand/plus/activities/SettingsActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/SettingsActivity.java @@ -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; }