From fbb3d9b55e50e8661c45c4284026f3bb05fa95fc Mon Sep 17 00:00:00 2001 From: Winson Chung Date: Tue, 1 Mar 2011 12:43:02 -0800 Subject: Adding "Shop" text beside market icon. Change-Id: I3a3a167185879b0723b51f08325ff8b09d4ebd71 --- src/com/android/launcher2/Launcher.java | 47 +++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 8 deletions(-) (limited to 'src/com/android/launcher2/Launcher.java') diff --git a/src/com/android/launcher2/Launcher.java b/src/com/android/launcher2/Launcher.java index 261569ef6..d5bf7c5b4 100644 --- a/src/com/android/launcher2/Launcher.java +++ b/src/com/android/launcher2/Launcher.java @@ -1038,6 +1038,11 @@ public final class Launcher extends Activity View marketButton = findViewById(R.id.market_button); if (marketButton != null) { allAppsInfoTarget.setOverlappingView(marketButton); + marketButton.setOnClickListener(new OnClickListener() { + public void onClick(View v) { + onClickAppMarketButton(v); + } + }); } } @@ -3087,11 +3092,7 @@ public final class Launcher extends Activity showWorkspace(true, layout); } - // if successful in getting icon, return it; otherwise, set button to use default drawable - private Drawable.ConstantState updateButtonWithIconFromExternalActivity( - int buttonId, ComponentName activityName, int fallbackDrawableId) { - ImageView button = (ImageView) findViewById(buttonId); - Drawable toolbarIcon = null; + private Drawable getExternalPackageToolbarIcon(ComponentName activityName) { try { PackageManager packageManager = getPackageManager(); // Look for the toolbar icon specified in the activity meta-data @@ -3101,12 +3102,37 @@ public final class Launcher extends Activity int iconResId = metaData.getInt(TOOLBAR_ICON_METADATA_NAME); if (iconResId != 0) { Resources res = packageManager.getResourcesForActivity(activityName); - toolbarIcon = res.getDrawable(iconResId); + return res.getDrawable(iconResId); } } } catch (NameNotFoundException e) { // Do nothing } + return null; + } + + // if successful in getting icon, return it; otherwise, set button to use default drawable + private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity( + int buttonId, ComponentName activityName, int fallbackDrawableId) { + TextView button = (TextView) findViewById(buttonId); + Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName); + + // If we were unable to find the icon via the meta-data, use a generic one + if (toolbarIcon == null) { + button.setCompoundDrawablesWithIntrinsicBounds(fallbackDrawableId, 0, 0, 0); + return null; + } else { + button.setCompoundDrawablesWithIntrinsicBounds(toolbarIcon, null, null, null); + return toolbarIcon.getConstantState(); + } + } + + // if successful in getting icon, return it; otherwise, set button to use default drawable + private Drawable.ConstantState updateButtonWithIconFromExternalActivity( + int buttonId, ComponentName activityName, int fallbackDrawableId) { + ImageView button = (ImageView) findViewById(buttonId); + Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName); + // If we were unable to find the icon via the meta-data, use a generic one if (toolbarIcon == null) { button.setImageResource(fallbackDrawableId); @@ -3117,6 +3143,11 @@ public final class Launcher extends Activity } } + private void updateTextButtonWithDrawable(int buttonId, Drawable.ConstantState d) { + TextView button = (TextView) findViewById(buttonId); + button.setCompoundDrawables(d.newDrawable(getResources()), null, null, null); + } + private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) { ImageView button = (ImageView) findViewById(buttonId); button.setImageDrawable(d.newDrawable(getResources())); @@ -3168,14 +3199,14 @@ public final class Launcher extends Activity ComponentName activityName = intent.resolveActivity(getPackageManager()); if (activityName != null) { mAppMarketIntent = intent; - sAppMarketIcon = updateButtonWithIconFromExternalActivity( + sAppMarketIcon = updateTextButtonWithIconFromExternalActivity( R.id.market_button, activityName, R.drawable.app_market_generic); } } } private void updateAppMarketIcon(Drawable.ConstantState d) { - updateButtonWithDrawable(R.id.market_button, d); + updateTextButtonWithDrawable(R.id.market_button, d); } /** -- cgit v1.2.3