Bug 1122302 - Change "Add to Firefox" -> "Send to other devices" when sharing inside Firefox. r=rnewman a=sylvestre
authorMichael Comella <michael.l.comella@gmail.com>
Tue, 03 Mar 2015 15:09:28 -0800
changeset 257963 909e80e07d18c88cd1c3276b94ea79f40d985f41
parent 257962 bf04f67325267df57bbf99134ff86bbcad92efe8
child 257964 4dcad21fe5d1658b5b3eee8897fc7356a621e31b
push id4610
push userjlund@mozilla.com
push dateMon, 30 Mar 2015 18:32:55 +0000
treeherdermozilla-beta@4df54044d9ef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrnewman, sylvestre
bugs1122302
milestone38.0a2
Bug 1122302 - Change "Add to Firefox" -> "Send to other devices" when sharing inside Firefox. r=rnewman a=sylvestre The alternative is to remove "Add to Firefox" entirely via the ActivityChooserModel and add a "Send tab" Activity. Fairly comparable solutions but this one requires less work - there is no need to refactor the existing ShareDialog and the classes it depends on.
mobile/android/base/widget/ActivityChooserModel.java
--- a/mobile/android/base/widget/ActivityChooserModel.java
+++ b/mobile/android/base/widget/ActivityChooserModel.java
@@ -16,18 +16,21 @@
 
 /**
  * Mozilla: Changing the package.
  */
 //package android.widget;
 package org.mozilla.gecko.widget;
 
 // Mozilla: New import
+import android.content.pm.PackageManager;
 import org.mozilla.gecko.distribution.Distribution;
 import org.mozilla.gecko.GeckoProfile;
+import org.mozilla.gecko.overlays.ui.ShareDialog;
+import org.mozilla.gecko.R;
 import java.io.File;
 
 import android.content.BroadcastReceiver;
 import android.content.ComponentName;
 import android.content.Context;
 import android.content.Intent;
 import android.content.IntentFilter;
 import android.content.pm.ResolveInfo;
@@ -731,18 +734,39 @@ public class ActivityChooserModel extend
      */
     private boolean loadActivitiesIfNeeded() {
         if (mReloadActivities && mIntent != null) {
             mReloadActivities = false;
             mActivities.clear();
             List<ResolveInfo> resolveInfos = mContext.getPackageManager()
                     .queryIntentActivities(mIntent, 0);
             final int resolveInfoCount = resolveInfos.size();
+
+            /**
+             * Mozilla: Temporary variables to prevent performance degradation in the loop.
+             */
+            final PackageManager packageManager = mContext.getPackageManager();
+            final String channelToRemoveLabel = mContext.getResources().getString(R.string.overlay_share_label);
+
             for (int i = 0; i < resolveInfoCount; i++) {
                 ResolveInfo resolveInfo = resolveInfos.get(i);
+
+                /**
+                 * Mozilla: We want "Add to Firefox" to appear differently inside of Firefox than
+                 * from external applications - override the name and icon here.
+                 *
+                 * Note: we check both the class name and the label to ensure we only change the
+                 * label of the current channel.
+                 */
+                if (ShareDialog.class.getCanonicalName().equals(resolveInfo.activityInfo.name) &&
+                        channelToRemoveLabel.equals(resolveInfo.loadLabel(packageManager))) {
+                    resolveInfo.labelRes = R.string.overlay_share_send_other;
+                    resolveInfo.icon = R.drawable.share_plane;
+                }
+
                 mActivities.add(new ActivityResolveInfo(resolveInfo));
             }
             return true;
         }
         return false;
     }
 
     /**