summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Dubroy <dubroy@google.com>2010-08-30 10:40:53 -0700
committerPatrick Dubroy <dubroy@google.com>2010-08-30 18:08:43 -0700
commitceae05d573255a0143981888e5d257b5891e3925 (patch)
tree215a8a03bdc88b8e0f83f0c6a2514fa0fa446aaa
parentdf7c3a7853abd4dec460247370fe0b17b50866ac (diff)
downloadandroid_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.
-rw-r--r--proguard.flags1
-rw-r--r--res/drawable-xlarge/app_market_generic.pngbin0 -> 2750 bytes
-rw-r--r--res/layout-xlarge/launcher.xml1
-rw-r--r--src/com/android/launcher2/Launcher.java60
4 files changed, 60 insertions, 2 deletions
diff --git a/proguard.flags b/proguard.flags
index 607c14bba..aa75f4a86 100644
--- a/proguard.flags
+++ b/proguard.flags
@@ -5,6 +5,7 @@
public void onClickSearchButton(android.view.View);
public void onClickConfigureButton(android.view.View);
public void onClickAllAppsButton(android.view.View);
+ public void onClickAppMarketButton(android.view.View);
}
-keep class com.android.launcher2.CellLayout {
diff --git a/res/drawable-xlarge/app_market_generic.png b/res/drawable-xlarge/app_market_generic.png
new file mode 100644
index 000000000..0ceaeefde
--- /dev/null
+++ b/res/drawable-xlarge/app_market_generic.png
Binary files differ
diff --git a/res/layout-xlarge/launcher.xml b/res/layout-xlarge/launcher.xml
index 3add9117c..3b39fd150 100644
--- a/res/layout-xlarge/launcher.xml
+++ b/res/layout-xlarge/launcher.xml
@@ -83,6 +83,7 @@
android:layout_height="wrap_content"
android:layout_alignLeft="@id/all_apps_button"
+ android:onClick="onClickAppMarketButton"
android:focusable="false"
android:clickable="false"
android:visibility="gone"/>
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();
}
/**