diff --git a/mobile/android/base/home/HomeFragment.java b/mobile/android/base/home/HomeFragment.java index b1bd65cb3de..47766c9d433 100644 --- a/mobile/android/base/home/HomeFragment.java +++ b/mobile/android/base/home/HomeFragment.java @@ -26,7 +26,6 @@ import android.content.Intent; import android.graphics.Bitmap; import android.os.Bundle; import android.support.v4.app.Fragment; -import android.text.TextUtils; import android.util.Log; import android.view.ContextMenu; import android.view.ContextMenu.ContextMenuInfo; @@ -46,9 +45,6 @@ abstract class HomeFragment extends Fragment { // Share MIME type. private static final String SHARE_MIME_TYPE = "text/plain"; - // URL to Title replacement regex. - private static final String REGEX_URL_TO_TITLE = "^([a-z]+://)?(www\\.)?"; - // Whether the fragment can load its content or not // This is used to defer data loading until the editing // mode animation ends. @@ -87,7 +83,7 @@ abstract class HomeFragment extends Fragment { MenuInflater inflater = new MenuInflater(view.getContext()); inflater.inflate(R.menu.home_contextmenu, menu); - menu.setHeaderTitle(info.title); + menu.setHeaderTitle(info.getDisplayTitle()); // Hide the "Edit" menuitem if this item isn't a bookmark. if (info.bookmarkId < 0) { @@ -126,7 +122,7 @@ abstract class HomeFragment extends Fragment { Log.e(LOGTAG, "Can't share because URL is null"); } else { GeckoAppShell.openUriExternal(info.url, SHARE_MIME_TYPE, "", "", - Intent.ACTION_SEND, info.title); + Intent.ACTION_SEND, info.getDisplayTitle()); } } @@ -136,8 +132,7 @@ abstract class HomeFragment extends Fragment { return false; } - String shortcutTitle = TextUtils.isEmpty(info.title) ? info.url.replaceAll(REGEX_URL_TO_TITLE, "") : info.title; - new AddToLauncherTask(info.url, shortcutTitle).execute(); + new AddToLauncherTask(info.url, info.getDisplayTitle()).execute(); return true; } diff --git a/mobile/android/base/home/HomeListView.java b/mobile/android/base/home/HomeListView.java index d2a4a1605b1..969b71e6796 100644 --- a/mobile/android/base/home/HomeListView.java +++ b/mobile/android/base/home/HomeListView.java @@ -15,6 +15,7 @@ import android.content.Context; import android.content.res.TypedArray; import android.database.Cursor; import android.graphics.drawable.Drawable; +import android.text.TextUtils; import android.util.AttributeSet; import android.view.ContextMenu.ContextMenuInfo; import android.view.MotionEvent; @@ -110,6 +111,10 @@ public class HomeListView extends ListView * A ContextMenuInfo for HomeListView that adds details from the cursor. */ public static class HomeContextMenuInfo extends AdapterContextMenuInfo { + + // URL to Title replacement regex. + private static final String REGEX_URL_TO_TITLE = "^([a-z]+://)?(www\\.)?"; + public int bookmarkId; public int historyId; public String url; @@ -179,5 +184,9 @@ public class HomeListView extends ListView display = Combined.DISPLAY_NORMAL; } } + + public String getDisplayTitle() { + return TextUtils.isEmpty(title) ? url.replaceAll(REGEX_URL_TO_TITLE, "") : title; + } } }