Bug 1014293 - Part 2: Display settings. r=lucas
authorChenxia Liu <liuche@mozilla.com>
Thu, 23 Oct 2014 16:47:23 -0700
changeset 212128 b6b8553a9f5f515b9794853bdad8be691b35395a
parent 212127 7dea866069a8a23827a185bc6a86729344bdfd8e
child 212129 c8e448fd5f6acaf8ac1f341ac397832688811e5b
push id27698
push usercbook@mozilla.com
push dateFri, 24 Oct 2014 13:53:50 +0000
treeherdermozilla-central@6e35802ae3e2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslucas
bugs1014293
milestone36.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1014293 - Part 2: Display settings. r=lucas
mobile/android/base/home/HistoryPanel.java
mobile/android/base/resources/layout/home_empty_panel.xml
--- a/mobile/android/base/home/HistoryPanel.java
+++ b/mobile/android/base/home/HistoryPanel.java
@@ -21,19 +21,26 @@ import org.mozilla.gecko.db.BrowserDB;
 import org.mozilla.gecko.home.HomeContextMenuInfo.RemoveItemType;
 import org.mozilla.gecko.home.HomePager.OnUrlOpenListener;
 
 import android.app.AlertDialog;
 import android.content.ContentResolver;
 import android.content.Context;
 import android.content.DialogInterface;
 import android.database.Cursor;
+import android.graphics.Typeface;
 import android.os.Bundle;
 import android.support.v4.app.LoaderManager.LoaderCallbacks;
 import android.support.v4.content.Loader;
+import android.text.SpannableStringBuilder;
+import android.text.method.LinkMovementMethod;
+import android.text.style.ClickableSpan;
+import android.text.style.UnderlineSpan;
+import android.text.style.StyleSpan;
+import android.text.TextPaint;
 import android.util.Log;
 import android.util.SparseArray;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 import android.view.ViewStub;
 import android.widget.AdapterView;
 import android.widget.ImageView;
@@ -44,16 +51,20 @@ import android.widget.TextView;
  */
 public class HistoryPanel extends HomeFragment {
     // Logging tag name
     private static final String LOGTAG = "GeckoHistoryPanel";
 
     // Cursor loader ID for history query
     private static final int LOADER_ID_HISTORY = 0;
 
+    // String placeholders to mark formatting.
+    private final static String FORMAT_S1 = "%1$s";
+    private final static String FORMAT_S2 = "%2$s";
+
     // Adapter for the list of recent history entries.
     private HistoryAdapter mAdapter;
 
     // The view shown by the fragment.
     private HomeListView mList;
 
     // The button view for clearing browsing history.
     private View mClearHistoryButton;
@@ -206,20 +217,84 @@ public class HistoryPanel extends HomeFr
             mEmptyView = emptyViewStub.inflate();
 
             final ImageView emptyIcon = (ImageView) mEmptyView.findViewById(R.id.home_empty_image);
             emptyIcon.setImageResource(R.drawable.icon_most_recent_empty);
 
             final TextView emptyText = (TextView) mEmptyView.findViewById(R.id.home_empty_text);
             emptyText.setText(R.string.home_most_recent_empty);
 
+            final TextView emptyHint = (TextView) mEmptyView.findViewById(R.id.home_empty_hint);
+            final String hintText = getResources().getString(R.string.home_most_recent_emptyhint);
+
+            final SpannableStringBuilder hintBuilder = formatHintText(hintText);
+            if (hintBuilder != null) {
+                emptyHint.setText(hintBuilder);
+                emptyHint.setText(hintBuilder);
+                emptyHint.setMovementMethod(LinkMovementMethod.getInstance());
+                emptyHint.setVisibility(View.VISIBLE);
+            }
+
             mList.setEmptyView(mEmptyView);
         }
     }
 
+    /**
+     * Make Span that is clickable, italicized, and underlined
+     * between the string markers <code>FORMAT_S1</code> and
+     * <code>FORMAT_S2</code>.
+     *
+     * @param text String to format
+     * @return formatted SpannableStringBuilder, or null if there
+     * is not any text to format.
+     */
+    private SpannableStringBuilder formatHintText(String text) {
+        // Set formatting as marked by string placeholders.
+        final int underlineStart = text.indexOf(FORMAT_S1);
+        final int underlineEnd = text.indexOf(FORMAT_S2);
+
+        // Check that there is text to be formatted.
+        if (underlineStart >= underlineEnd) {
+            return null;
+        }
+
+        final SpannableStringBuilder ssb = new SpannableStringBuilder(text);
+
+        // Set italicization.
+        ssb.setSpan(new StyleSpan(Typeface.ITALIC), 0, ssb.length(), 0);
+
+        // Set clickable text.
+        final ClickableSpan clickableSpan = new ClickableSpan() {
+            @Override
+            public void onClick(View widget) {
+                // TODO Open menu and highlight private tab item.
+            }
+        };
+
+        ssb.setSpan(clickableSpan, 0, text.length(), 0);
+
+        // Remove underlining set by ClickableSpan.
+        final UnderlineSpan noUnderlineSpan = new UnderlineSpan() {
+            @Override
+            public void updateDrawState(TextPaint textPaint) {
+                textPaint.setUnderlineText(false);
+            }
+        };
+
+        ssb.setSpan(noUnderlineSpan, 0, text.length(), 0);
+
+        // Add underlining for "Private Browsing".
+        ssb.setSpan(new UnderlineSpan(), underlineStart, underlineEnd, 0);
+
+        ssb.delete(underlineEnd, underlineEnd + FORMAT_S2.length());
+        ssb.delete(underlineStart, underlineStart + FORMAT_S1.length());
+
+        return ssb;
+    }
+
     private static class HistoryAdapter extends MultiTypeCursorAdapter {
         private static final int ROW_HEADER = 0;
         private static final int ROW_STANDARD = 1;
 
         private static final int[] VIEW_TYPES = new int[] { ROW_STANDARD, ROW_HEADER };
         private static final int[] LAYOUT_TYPES = new int[] { R.layout.home_item_row, R.layout.home_header_row };
 
         // For the time sections in history
--- a/mobile/android/base/resources/layout/home_empty_panel.xml
+++ b/mobile/android/base/resources/layout/home_empty_panel.xml
@@ -31,12 +31,13 @@
               android:layout_weight="2"/>
 
     <TextView android:id="@+id/home_empty_hint"
               android:layout_width="match_parent"
               android:layout_height="0dip"
               android:visibility="gone"
               android:gravity="top|center"
               android:textAppearance="@style/TextAppearance.EmptyHint"
+              android:textColorLink="#FFA62F"
               android:layout_weight="4"/>
 
 </LinearLayout>