From 4030739a99a2e1ce232c6c3ab92ab21ad5bc3b4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Fri, 6 Sep 2013 08:40:13 +0200 Subject: [PATCH] api apps adapter with icons --- .../res/layout/api_apps_adapter_list_item.xml | 28 +++++++++++++++++++ OpenPGP-Keychain/res/values/strings.xml | 1 - .../remote_api/AppSettingsActivity.java | 3 +- .../remote_api/RegisteredAppsAdapter.java | 18 +++++++----- 4 files changed, 41 insertions(+), 9 deletions(-) create mode 100644 OpenPGP-Keychain/res/layout/api_apps_adapter_list_item.xml diff --git a/OpenPGP-Keychain/res/layout/api_apps_adapter_list_item.xml b/OpenPGP-Keychain/res/layout/api_apps_adapter_list_item.xml new file mode 100644 index 000000000..cb20a20af --- /dev/null +++ b/OpenPGP-Keychain/res/layout/api_apps_adapter_list_item.xml @@ -0,0 +1,28 @@ + + + + + + + \ No newline at end of file diff --git a/OpenPGP-Keychain/res/values/strings.xml b/OpenPGP-Keychain/res/values/strings.xml index 5aa4081fb..4165e9057 100644 --- a/OpenPGP-Keychain/res/values/strings.xml +++ b/OpenPGP-Keychain/res/values/strings.xml @@ -362,7 +362,6 @@ No registered applications! - Unknown app Show advanced settingsā€¦ Hide advanced settingsā€¦ No key selected diff --git a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/remote_api/AppSettingsActivity.java b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/remote_api/AppSettingsActivity.java index 8d32dd3f5..44212b5b3 100644 --- a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/remote_api/AppSettingsActivity.java +++ b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/remote_api/AppSettingsActivity.java @@ -145,7 +145,8 @@ public class AppSettingsActivity extends SherlockFragmentActivity { appName = (String) pm.getApplicationLabel(ai); appIcon = pm.getApplicationIcon(ai); } catch (final NameNotFoundException e) { - appName = getString(R.string.api_unknown_app); + // fallback + appName = mPackageName; } appNameView.setText(appName); appIconView.setImageDrawable(appIcon); diff --git a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/remote_api/RegisteredAppsAdapter.java b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/remote_api/RegisteredAppsAdapter.java index 71a819ec2..9bf66a90a 100644 --- a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/remote_api/RegisteredAppsAdapter.java +++ b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/remote_api/RegisteredAppsAdapter.java @@ -28,6 +28,7 @@ import android.support.v4.widget.CursorAdapter; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.ImageView; import android.widget.TextView; public class RegisteredAppsAdapter extends CursorAdapter { @@ -44,28 +45,31 @@ public class RegisteredAppsAdapter extends CursorAdapter { @Override public void bindView(View view, Context context, Cursor cursor) { - TextView text1 = (TextView) view.findViewById(android.R.id.text1); - TextView text2 = (TextView) view.findViewById(android.R.id.text2); + TextView text = (TextView) view.findViewById(R.id.api_apps_adapter_item_name); + ImageView icon = (ImageView) view.findViewById(R.id.api_apps_adapter_item_icon); String packageName = cursor.getString(cursor.getColumnIndex(ApiApps.PACKAGE_NAME)); if (packageName != null) { - text2.setText(packageName); - // get application name try { ApplicationInfo ai = pm.getApplicationInfo(packageName, 0); - text1.setText(pm.getApplicationLabel(ai)); + text.setText(pm.getApplicationLabel(ai)); + icon.setImageDrawable(pm.getApplicationIcon(ai)); } catch (final NameNotFoundException e) { - text1.setText(R.string.api_unknown_app); + // fallback + text.setText(packageName); } + } else { + // fallback + text.setText(packageName); } } @Override public View newView(Context context, Cursor cursor, ViewGroup parent) { - return mInflater.inflate(android.R.layout.simple_list_item_2, null); + return mInflater.inflate(R.layout.api_apps_adapter_list_item, null); } }