diff options
author | Patrick Dubroy <dubroy@google.com> | 2010-08-30 10:40:53 -0700 |
---|---|---|
committer | Patrick Dubroy <dubroy@google.com> | 2010-08-30 18:08:43 -0700 |
commit | ceae05d573255a0143981888e5d257b5891e3925 (patch) | |
tree | 215a8a03bdc88b8e0f83f0c6a2514fa0fa446aaa /src | |
parent | df7c3a7853abd4dec460247370fe0b17b50866ac (diff) | |
download | android_packages_apps_Trebuchet-ceae05d573255a0143981888e5d257b5891e3925.tar.gz android_packages_apps_Trebuchet-ceae05d573255a0143981888e5d257b5891e3925.tar.bz2 android_packages_apps_Trebuchet-ceae05d573255a0143981888e5d257b5891e3925.zip |
Add a market button to the toolbar.
We determine the default app market activity by resolving an intent,
and fetch the icon from the activity's meta-data.
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/launcher2/Launcher.java | 60 |
1 files changed, 58 insertions, 2 deletions
diff --git a/src/com/android/launcher2/Launcher.java b/src/com/android/launcher2/Launcher.java index 80e148124..436ac39a3 100644 --- a/src/com/android/launcher2/Launcher.java +++ b/src/com/android/launcher2/Launcher.java @@ -45,6 +45,7 @@ import android.content.Intent.ShortcutIconResource; import android.content.IntentFilter; import android.content.pm.ActivityInfo; import android.content.pm.PackageManager; +import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.ResolveInfo; import android.content.res.Configuration; import android.content.res.Resources; @@ -82,7 +83,6 @@ import android.view.ViewGroup; import android.view.WindowManager; import android.view.animation.AccelerateInterpolator; import android.view.animation.DecelerateInterpolator; -import android.view.animation.Interpolator; import android.view.inputmethod.InputMethodManager; import android.widget.EditText; import android.widget.ImageView; @@ -180,6 +180,8 @@ public final class Launcher extends Activity private static final String SHORTCUTS_TAG = "shortcuts"; private static final String WALLPAPERS_TAG = "wallpapers"; + private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon"; + /** The different states that Launcher can be in. */ private enum State { WORKSPACE, ALL_APPS, CUSTOMIZE, OVERVIEW }; @@ -239,6 +241,8 @@ public final class Launcher extends Activity private Drawable[] mHotseatIcons = null; private CharSequence[] mHotseatLabels = null; + private Intent mAppMarketIntent = null; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -681,6 +685,9 @@ public final class Launcher extends Activity mModel.startLoader(this, true); mRestoring = false; } + // When we resume Launcher, a different Activity might be responsible for the app + // market intent, so refresh the icon + updateAppMarketIcon(); } @Override @@ -1129,7 +1136,6 @@ public final class Launcher extends Activity boolean allAppsVisible = isAllAppsVisible(); boolean customizationDrawerVisible = isCustomizationDrawerVisible(); - // in all these cases, only animate if we're already on home if (LauncherApplication.isScreenXLarge()) { if (alreadyOnHome && !mWorkspace.isSmall() && @@ -1731,6 +1737,12 @@ public final class Launcher extends Activity showAllApps(true); } + public void onClickAppMarketButton(View v) { + if (mAppMarketIntent != null) { + startActivitySafely(mAppMarketIntent, "app market"); + } + } + void startApplicationDetailsActivity(String packageName) { Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, Uri.fromParts("package", packageName, null)); @@ -2561,6 +2573,46 @@ public final class Launcher extends Activity } /** + * Sets the app market icon (shown when all apps is visible on x-large screens) + */ + private void updateAppMarketIcon() { + if (LauncherApplication.isScreenXLarge()) { + // Find the app market activity by resolving an intent. + // (If multiple app markets are installed, it will return the ResolverActivity.) + PackageManager packageManager = getPackageManager(); + Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET); + ComponentName activityName = intent.resolveActivity(getPackageManager()); + if (activityName != null) { + mAppMarketIntent = intent; + ImageView marketButton = (ImageView) findViewById(R.id.market_button); + Drawable toolbarIcon = null; + try { + // Look for the toolbar icon specified in the activity meta-data + Bundle metaData = packageManager.getActivityInfo( + activityName, PackageManager.GET_META_DATA).metaData; + if (metaData != null) { + int iconResId = metaData.getInt(TOOLBAR_ICON_METADATA_NAME); + if (iconResId != 0) { + Resources res = packageManager.getResourcesForActivity(activityName); + toolbarIcon = res.getDrawable(iconResId); + } + } + } catch (NameNotFoundException e) { + // Do nothing + } + // If we were unable to find the icon via the meta-data, use a generic one + if (toolbarIcon == null) { + marketButton.setImageResource(R.drawable.app_market_generic); + } else { + marketButton.setImageDrawable(toolbarIcon); + } + } else { + mAppMarketIntent = null; + } + } + } + + /** * Displays the shortcut creation dialog and launches, if necessary, the * appropriate activity. */ @@ -2860,6 +2912,7 @@ public final class Launcher extends Activity */ public void bindAllApplications(ArrayList<ApplicationInfo> apps) { mAllAppsGrid.setApps(apps); + updateAppMarketIcon(); } /** @@ -2870,6 +2923,7 @@ public final class Launcher extends Activity public void bindAppsAdded(ArrayList<ApplicationInfo> apps) { removeDialog(DIALOG_CREATE_SHORTCUT); mAllAppsGrid.addApps(apps); + updateAppMarketIcon(); } /** @@ -2881,6 +2935,7 @@ public final class Launcher extends Activity removeDialog(DIALOG_CREATE_SHORTCUT); mWorkspace.updateShortcuts(apps); mAllAppsGrid.updateApps(apps); + updateAppMarketIcon(); } /** @@ -2894,6 +2949,7 @@ public final class Launcher extends Activity mWorkspace.removeItems(apps); } mAllAppsGrid.removeApps(apps); + updateAppMarketIcon(); } /** |