diff options
| -rw-r--r-- | main/AndroidManifest.xml | 2 | ||||
| -rw-r--r-- | main/res/layout/useful_apps.xml | 24 | ||||
| -rw-r--r-- | main/res/layout/useful_apps_activity.xml | 23 | ||||
| -rw-r--r-- | main/res/layout/useful_apps_item.xml | 3 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/UsefulAppsActivity.java | 102 |
5 files changed, 101 insertions, 53 deletions
diff --git a/main/AndroidManifest.xml b/main/AndroidManifest.xml index 3fb5ff1..0c6c4a0 100644 --- a/main/AndroidManifest.xml +++ b/main/AndroidManifest.xml @@ -69,7 +69,7 @@ </activity> <activity android:name=".UsefulAppsActivity" - android:label="@string/helper" + android:label="@string/helpers" android:windowSoftInputMode="stateHidden" android:configChanges="keyboardHidden|orientation" > </activity> diff --git a/main/res/layout/useful_apps.xml b/main/res/layout/useful_apps.xml deleted file mode 100644 index 8fd73bf..0000000 --- a/main/res/layout/useful_apps.xml +++ /dev/null @@ -1,24 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" - android:layout_width="fill_parent" - android:layout_height="fill_parent" - android:background="?background_color" - android:orientation="vertical" > - - <include layout="@layout/actionbar"/> - - <ScrollView - android:layout_width="fill_parent" - android:layout_height="fill_parent" - android:orientation="vertical" - android:padding="4dip" > - - <LinearLayout - android:id="@+id/parent" - android:layout_width="fill_parent" - android:layout_height="wrap_content" - android:orientation="vertical" > - </LinearLayout> - </ScrollView> - -</LinearLayout>
\ No newline at end of file diff --git a/main/res/layout/useful_apps_activity.xml b/main/res/layout/useful_apps_activity.xml new file mode 100644 index 0000000..84bcf39 --- /dev/null +++ b/main/res/layout/useful_apps_activity.xml @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="UTF-8"?> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="fill_parent" + android:layout_height="fill_parent" + android:background="?background_color" + android:orientation="vertical" > + + <include layout="@layout/actionbar" /> + + <ListView + android:id="@+id/apps_list" + android:layout_width="fill_parent" + android:layout_height="fill_parent" + android:cacheColorHint="?background_color" + android:divider="?background_color" + android:fastScrollEnabled="true" + android:footerDividersEnabled="false" + android:headerDividersEnabled="false" + android:listSelector="?background_color" + android:padding="4dip" > + </ListView> + +</LinearLayout>
\ No newline at end of file diff --git a/main/res/layout/useful_apps_item.xml b/main/res/layout/useful_apps_item.xml index 5c8f6f0..70e7baf 100644 --- a/main/res/layout/useful_apps_item.xml +++ b/main/res/layout/useful_apps_item.xml @@ -4,6 +4,7 @@ android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_marginBottom="10dip" + android:descendantFocusability="blocksDescendants" android:orientation="vertical" > <RelativeLayout style="@style/separator_horizontal_layout" > @@ -43,7 +44,7 @@ android:textColor="?text_color" android:textColorLink="?text_color_link" android:textIsSelectable="false" - android:textSize="14dip" /> + android:textSize="14sp" /> </LinearLayout> </LinearLayout>
\ No newline at end of file diff --git a/main/src/cgeo/geocaching/UsefulAppsActivity.java b/main/src/cgeo/geocaching/UsefulAppsActivity.java index b12c5e0..0fddd89 100644 --- a/main/src/cgeo/geocaching/UsefulAppsActivity.java +++ b/main/src/cgeo/geocaching/UsefulAppsActivity.java @@ -1,6 +1,7 @@ package cgeo.geocaching; import butterknife.InjectView; +import butterknife.Views; import cgeo.geocaching.activity.AbstractActivity; @@ -8,49 +9,96 @@ import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.view.View; -import android.view.View.OnClickListener; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; import android.widget.ImageView; -import android.widget.LinearLayout; +import android.widget.ListView; import android.widget.TextView; public class UsefulAppsActivity extends AbstractActivity { - @InjectView(R.id.parent) protected LinearLayout parentLayout; + @InjectView(R.id.apps_list) protected ListView list; - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState, R.layout.useful_apps); + protected static class ViewHolder { + @InjectView(R.id.title) protected TextView title; + @InjectView(R.id.image) protected ImageView image; + @InjectView(R.id.description) protected TextView description; - addApp(R.string.helper_calendar_title, R.string.helper_calendar_description, R.drawable.cgeo, "cgeo.calendar"); - addApp(R.string.helper_locus_title, R.string.helper_locus_description, R.drawable.helper_locus, "menion.android.locus"); - addApp(R.string.helper_gpsstatus_title, R.string.helper_gpsstatus_description, R.drawable.helper_gpsstatus, "com.eclipsim.gpsstatus2"); - addApp(R.string.helper_bluetoothgps_title, R.string.helper_bluetoothgps_description, R.drawable.helper_bluetoothgps, "googoo.android.btgps"); - addApp(R.string.helper_barcode_title, R.string.helper_barcode_description, R.drawable.helper_barcode, "com.google.zxing.client.android"); + public ViewHolder(View rowView) { + Views.inject(this, rowView); + } } - private void installFromMarket(String marketId) { - try { - startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://search?q=pname:" + marketId))); - } catch (Exception e) { - // market not available in standard emulator + private static class HelperApp { + private final int titleId; + private final int descriptionId; + private final int iconId; + private final String market; + + public HelperApp(final int title, final int description, final int icon, final String market) { + this.titleId = title; + this.descriptionId = description; + this.iconId = icon; + this.market = market; } - finish(); + private void installFromMarket(UsefulAppsActivity activity) { + try { + activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://search?q=pname:" + market))); + } catch (Exception e) { + // market not available in standard emulator + } + + activity.finish(); + } } - private void addApp(final int titleId, final int descriptionId, final int imageId, final String marketUrl) { - final View appLayout = getLayoutInflater().inflate(R.layout.useful_apps_item, null); - ((TextView) appLayout.findViewById(R.id.title)).setText(res.getString(titleId)); - ((ImageView) appLayout.findViewById(R.id.image)).setImageDrawable(res.getDrawable(imageId)); - ((TextView) appLayout.findViewById(R.id.description)).setText(res.getString(descriptionId)); - appLayout.findViewById(R.id.app_layout).setOnClickListener(new OnClickListener() { + private static final HelperApp[] HELPER_APPS = { + new HelperApp(R.string.helper_calendar_title, R.string.helper_calendar_description, R.drawable.cgeo, "cgeo.calendar"), + new HelperApp(R.string.helper_locus_title, R.string.helper_locus_description, R.drawable.helper_locus, "menion.android.locus"), + new HelperApp(R.string.helper_gpsstatus_title, R.string.helper_gpsstatus_description, R.drawable.helper_gpsstatus, "com.eclipsim.gpsstatus2"), + new HelperApp(R.string.helper_bluetoothgps_title, R.string.helper_bluetoothgps_description, R.drawable.helper_bluetoothgps, "googoo.android.btgps"), + new HelperApp(R.string.helper_barcode_title, R.string.helper_barcode_description, R.drawable.helper_barcode, "com.google.zxing.client.android"), + }; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState, R.layout.useful_apps_activity); + + Views.inject(this); + list.setAdapter(new ArrayAdapter<HelperApp>(this, R.layout.useful_apps_item, HELPER_APPS) { @Override - public void onClick(View v) { - installFromMarket(marketUrl); + public View getView(int position, View convertView, android.view.ViewGroup parent) { + View rowView = convertView; + if (null == rowView) { + rowView = getLayoutInflater().inflate(R.layout.useful_apps_item, null); + } + ViewHolder holder = (ViewHolder) rowView.getTag(); + if (null == holder) { + holder = new ViewHolder(rowView); + rowView.setTag(holder); + } + + final HelperApp app = getItem(position); + fillViewHolder(holder, app); + return rowView; + } + + private void fillViewHolder(ViewHolder holder, HelperApp app) { + holder.title.setText(res.getString(app.titleId)); + holder.image.setImageDrawable(res.getDrawable(app.iconId)); + holder.description.setText(res.getString(app.descriptionId)); } }); - parentLayout.addView(appLayout); - } + list.setOnItemClickListener(new AdapterView.OnItemClickListener() { + + @Override + public void onItemClick(AdapterView<?> parent, View view, int position, long id) { + HelperApp helperApp = HELPER_APPS[position]; + helperApp.installFromMarket(UsefulAppsActivity.this); + } + }); + } } |
