Bug 1134361 - Hide "tip" to add to reading list in reading list panel on low memory devices. r=nalexander draft
authorMargaret Leibovic <margaret.leibovic@gmail.com>
Mon, 09 Mar 2015 18:36:05 -0700
changeset 249034 8b1050a149548a09ced278be2b416fb4c1ba7efe
parent 249033 c186a66948fb6d85848d9c2fe788808c1dd4f825
child 505587 7b60b2aad6e1b630fbe2a4f76908da5abe312ba5
push id966
push usermleibovic@mozilla.com
push dateTue, 10 Mar 2015 01:36:33 +0000
reviewersnalexander
bugs1134361
milestone39.0a1
Bug 1134361 - Hide "tip" to add to reading list in reading list panel on low memory devices. r=nalexander
mobile/android/base/home/ReadingListPanel.java
mobile/android/base/util/HardwareUtils.java
--- a/mobile/android/base/home/ReadingListPanel.java
+++ b/mobile/android/base/home/ReadingListPanel.java
@@ -13,16 +13,17 @@ import org.mozilla.gecko.ReaderModeUtils
 import org.mozilla.gecko.Telemetry;
 import org.mozilla.gecko.TelemetryContract;
 import org.mozilla.gecko.db.BrowserContract.ReadingListItems;
 import org.mozilla.gecko.db.BrowserContract.URLColumns;
 import org.mozilla.gecko.db.BrowserDB;
 import org.mozilla.gecko.db.ReadingListAccessor;
 import org.mozilla.gecko.home.HomeContextMenuInfo.RemoveItemType;
 import org.mozilla.gecko.home.HomePager.OnUrlOpenListener;
+import org.mozilla.gecko.util.HardwareUtils;
 
 import android.content.Context;
 import android.database.Cursor;
 import android.os.Bundle;
 import android.support.v4.content.Loader;
 import android.support.v4.widget.CursorAdapter;
 import android.text.SpannableStringBuilder;
 import android.text.Spanned;
@@ -134,32 +135,36 @@ public class ReadingListPanel extends Ho
     private void updateUiFromCursor(Cursor c) {
         // We delay setting the empty view until the cursor is actually empty.
         // This avoids image flashing.
         if ((c == null || c.getCount() == 0) && mEmptyView == null) {
             final ViewStub emptyViewStub = (ViewStub) mTopView.findViewById(R.id.home_empty_view_stub);
             mEmptyView = emptyViewStub.inflate();
 
             final TextView emptyHint = (TextView) mEmptyView.findViewById(R.id.home_empty_hint);
-            String readingListHint = emptyHint.getText().toString();
-
-            // Use an ImageSpan to include the reader icon in the "Tip".
-            int imageSpanIndex = readingListHint.indexOf(MATCH_STRING);
-            if (imageSpanIndex != -1) {
-                final ImageSpan readingListIcon = new ImageSpan(getActivity(), R.drawable.reader_cropped, ImageSpan.ALIGN_BOTTOM);
-                final SpannableStringBuilder hintBuilder = new SpannableStringBuilder(readingListHint);
+            if (HardwareUtils.isLowMemoryPlatform()) {
+                emptyHint.setVisibility(View.GONE);
+            } else {
+                String readingListHint = emptyHint.getText().toString();
 
-                // Add additional spacing.
-                hintBuilder.insert(imageSpanIndex + MATCH_STRING.length(), " ");
-                hintBuilder.insert(imageSpanIndex, " ");
+                // Use an ImageSpan to include the reader icon in the "Tip".
+                int imageSpanIndex = readingListHint.indexOf(MATCH_STRING);
+                if (imageSpanIndex != -1) {
+                    final ImageSpan readingListIcon = new ImageSpan(getActivity(), R.drawable.reader_cropped, ImageSpan.ALIGN_BOTTOM);
+                    final SpannableStringBuilder hintBuilder = new SpannableStringBuilder(readingListHint);
 
-                // Add icon.
-                hintBuilder.setSpan(readingListIcon, imageSpanIndex + 1, imageSpanIndex + MATCH_STRING.length() + 1, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+                    // Add additional spacing.
+                    hintBuilder.insert(imageSpanIndex + MATCH_STRING.length(), " ");
+                    hintBuilder.insert(imageSpanIndex, " ");
 
-                emptyHint.setText(hintBuilder, TextView.BufferType.SPANNABLE);
+                    // Add icon.
+                    hintBuilder.setSpan(readingListIcon, imageSpanIndex + 1, imageSpanIndex + MATCH_STRING.length() + 1, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+
+                    emptyHint.setText(hintBuilder, TextView.BufferType.SPANNABLE);
+                }
             }
 
             mList.setEmptyView(mEmptyView);
         }
     }
 
     /**
      * Cursor loader for the list of reading list items.
--- a/mobile/android/base/util/HardwareUtils.java
+++ b/mobile/android/base/util/HardwareUtils.java
@@ -12,16 +12,24 @@ import android.content.pm.PackageManager
 import android.content.res.Configuration;
 import android.os.Build;
 import android.util.Log;
 import android.view.ViewConfiguration;
 
 public final class HardwareUtils {
     private static final String LOGTAG = "GeckoHardwareUtils";
 
+    // Minimum memory threshold for a device to be considered
+    // a low memory platform (see isLowMemoryPlatform). This value
+    // has be in sync with Gecko's equivalent threshold (defined in
+    // xpcom/base/nsMemoryImpl.cpp) and should only be used in cases
+    // where we can't depend on Gecko to be up and running e.g. show/hide
+    // reading list capabilities in HomePager.
+    private static final int LOW_MEMORY_THRESHOLD_MB = 384;
+
     private static final boolean IS_AMAZON_DEVICE = Build.MANUFACTURER.equalsIgnoreCase("Amazon");
     public static final boolean IS_KINDLE_DEVICE = IS_AMAZON_DEVICE &&
                                                    (Build.MODEL.equals("Kindle Fire") ||
                                                     Build.MODEL.startsWith("KF"));
 
     private static volatile boolean sInited;
 
     // These are all set once, during init.
@@ -83,9 +91,22 @@ public final class HardwareUtils {
 
     public static boolean hasMenuButton() {
         return sHasMenuButton;
     }
 
     public static int getMemSize() {
         return SysInfo.getMemSize();
     }
+
+    public static boolean isLowMemoryPlatform() {
+        final int memSize = getMemSize();
+
+        // Fallback to false if we fail to read meminfo
+        // for some reason.
+        if (memSize == 0) {
+            Log.w(LOGTAG, "Could not compute system memory. Falling back to isLowMemoryPlatform = false.");
+            return false;
+        }
+
+        return memSize < LOW_MEMORY_THRESHOLD_MB;
+    }
 }