Bug 781262: Replaced sync box on about:home with promo box abstraction. r=sriram
Bug 781262: Replaced sync box on about:home with promo box abstraction. r=sriram --HG-- rename : mobile/android/base/resources/drawable-hdpi/abouthome_sync_bg.9.png => mobile/android/base/resources/drawable-hdpi/abouthome_promo_box_bg.9.png rename : mobile/android/base/resources/drawable-hdpi/abouthome_sync_pressed_bg.9.png => mobile/android/base/resources/drawable-hdpi/abouthome_promo_box_pressed_bg.9.png rename : mobile/android/base/resources/drawable-xhdpi/abouthome_sync_bg.9.png => mobile/android/base/resources/drawable-xhdpi/abouthome_promo_box_bg.9.png rename : mobile/android/base/resources/drawable-xhdpi/abouthome_sync_pressed_bg.9.png => mobile/android/base/resources/drawable-xhdpi/abouthome_promo_box_pressed_bg.9.png rename : mobile/android/base/resources/drawable/abouthome_sync_box.xml => mobile/android/base/resources/drawable/abouthome_promo_box.xml rename : mobile/android/base/resources/drawable/abouthome_sync_bg.9.png => mobile/android/base/resources/drawable/abouthome_promo_box_bg.9.png rename : mobile/android/base/resources/drawable/abouthome_sync_pressed_bg.9.png => mobile/android/base/resources/drawable/abouthome_promo_box_pressed_bg.9.png
@ -85,6 +85,7 @@ public class AboutHomeContent extends ScrollView
|
||||
protected SimpleCursorAdapter mTopSitesAdapter;
|
||||
protected GridView mTopSitesGrid;
|
||||
|
||||
private AboutHomePromoBox mPromoBox;
|
||||
protected AboutHomeSection mAddons;
|
||||
protected AboutHomeSection mLastTabs;
|
||||
protected AboutHomeSection mRemoteTabs;
|
||||
@ -155,6 +156,7 @@ public class AboutHomeContent extends ScrollView
|
||||
}
|
||||
});
|
||||
|
||||
mPromoBox = (AboutHomePromoBox) findViewById(R.id.promo_box);
|
||||
mAddons = (AboutHomeSection) findViewById(R.id.recommended_addons);
|
||||
mLastTabs = (AboutHomeSection) findViewById(R.id.last_tabs);
|
||||
mRemoteTabs = (AboutHomeSection) findViewById(R.id.remote_tabs);
|
||||
@ -179,28 +181,6 @@ public class AboutHomeContent extends ScrollView
|
||||
}
|
||||
});
|
||||
|
||||
TextView syncTextView = (TextView) findViewById(R.id.sync_text);
|
||||
String syncText = syncTextView.getText().toString() + " \u00BB";
|
||||
String boldName = getContext().getResources().getString(R.string.abouthome_sync_bold_name);
|
||||
int styleIndex = syncText.indexOf(boldName);
|
||||
|
||||
// Highlight any occurrence of "Firefox Sync" in the string
|
||||
// with a bold style.
|
||||
if (styleIndex >= 0) {
|
||||
SpannableString spannableText = new SpannableString(syncText);
|
||||
spannableText.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), styleIndex, styleIndex + 12, 0);
|
||||
syncTextView.setText(spannableText, TextView.BufferType.SPANNABLE);
|
||||
}
|
||||
|
||||
LinearLayout syncBox = (LinearLayout) findViewById(R.id.sync_box);
|
||||
syncBox.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
Context context = v.getContext();
|
||||
Intent intent = new Intent(context, SetupSyncActivity.class);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
||||
setTopSitesConstants();
|
||||
}
|
||||
|
||||
@ -232,9 +212,11 @@ public class AboutHomeContent extends ScrollView
|
||||
findViewById(R.id.no_top_sites_text).setVisibility(visibilityWithoutTopSites);
|
||||
}
|
||||
|
||||
private void setSyncVisibility(boolean visible) {
|
||||
int visibility = visible ? View.VISIBLE : View.GONE;
|
||||
findViewById(R.id.sync_box).setVisibility(visibility);
|
||||
private void setPromoBoxVisibility(boolean visible, AboutHomePromoBox.Type type) {
|
||||
if (visible)
|
||||
mPromoBox.show(type);
|
||||
else
|
||||
mPromoBox.hide();
|
||||
}
|
||||
|
||||
private void updateLayout(GeckoApp.StartupMode startupMode, boolean syncIsSetup) {
|
||||
@ -246,7 +228,7 @@ public class AboutHomeContent extends ScrollView
|
||||
boolean isFirstRun = (startupMode == GeckoApp.StartupMode.NEW_PROFILE);
|
||||
|
||||
setTopSitesVisibility(!isFirstRun || hasTopSites, hasTopSites);
|
||||
setSyncVisibility(!syncIsSetup);
|
||||
setPromoBoxVisibility(!syncIsSetup, AboutHomePromoBox.Type.SYNC);
|
||||
}
|
||||
|
||||
private void updateLayoutForSync() {
|
||||
|
126
mobile/android/base/AboutHomePromoBox.java
Normal file
@ -0,0 +1,126 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package org.mozilla.gecko;
|
||||
|
||||
import org.mozilla.gecko.sync.setup.activities.SetupSyncActivity;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.text.SpannableString;
|
||||
import android.text.style.StyleSpan;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
/**
|
||||
* A promotional box for the about:home page. The layout contains an ImageView to the left of a
|
||||
* TextView whose resources may be overidden to display custom values for a new type of promo box.
|
||||
* To do this, add a new Type value and update show() to call setResources() for your values -
|
||||
* including a set[Box Type]Resources() helper method is recommended.
|
||||
*/
|
||||
public class AboutHomePromoBox extends LinearLayout implements View.OnClickListener {
|
||||
private static final String LOGTAG = "AboutHomePromoBox";
|
||||
|
||||
public enum Type { SYNC };
|
||||
|
||||
private Type mType;
|
||||
|
||||
private final Context mContext;
|
||||
private final TextView mTextView;
|
||||
private final ImageView mImageView;
|
||||
|
||||
// Use setResources() to set these variables for each PromoBox type.
|
||||
private int mTextResource;
|
||||
private int mBoldTextResource;
|
||||
private int mImageResource;
|
||||
|
||||
public AboutHomePromoBox(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
||||
final LayoutInflater inflater = LayoutInflater.from(context);
|
||||
inflater.inflate(R.layout.abouthome_promo_box, this);
|
||||
|
||||
mContext = context;
|
||||
mTextView = (TextView) findViewById(R.id.text);
|
||||
mImageView = (ImageView) findViewById(R.id.icon);
|
||||
setOnClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Log.d(LOGTAG, "I work out.");
|
||||
switch (mType) {
|
||||
case SYNC:
|
||||
final Context context = v.getContext();
|
||||
final Intent intent = new Intent(context, SetupSyncActivity.class);
|
||||
context.startActivity(intent);
|
||||
break;
|
||||
|
||||
default:
|
||||
Log.e(LOGTAG, "Invalid type was set when promo box was clicked.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the specified promo box. If a promo box is already active, it will be overidden with a
|
||||
* promo box of the specified type.
|
||||
*/
|
||||
public void show(Type type) {
|
||||
mType = type;
|
||||
switch (type) {
|
||||
case SYNC:
|
||||
setSyncResources();
|
||||
break;
|
||||
|
||||
default:
|
||||
Log.e(LOGTAG, "Invalid PromoBoxType specified.");
|
||||
break;
|
||||
}
|
||||
updateViewResources();
|
||||
setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
public void hide() {
|
||||
setVisibility(View.GONE);
|
||||
mType = null;
|
||||
}
|
||||
|
||||
private void setResources(int textResource, int boldTextResource, int imageResource) {
|
||||
mTextResource = textResource;
|
||||
mBoldTextResource = boldTextResource;
|
||||
mImageResource = imageResource;
|
||||
}
|
||||
|
||||
private void updateViewResources() {
|
||||
updateTextViewResources();
|
||||
mImageView.setImageResource(mImageResource);
|
||||
}
|
||||
|
||||
private void updateTextViewResources() {
|
||||
final String promoText = mContext.getResources().getString(mTextResource) + " \u00BB";
|
||||
|
||||
final String boldName = mContext.getResources().getString(mBoldTextResource);
|
||||
final int styleIndex = promoText.indexOf(boldName);
|
||||
if (styleIndex < 0)
|
||||
mTextView.setText(promoText);
|
||||
else {
|
||||
final SpannableString spannableText = new SpannableString(promoText);
|
||||
spannableText.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), styleIndex,
|
||||
styleIndex + boldName.length(), 0);
|
||||
mTextView.setText(spannableText, TextView.BufferType.SPANNABLE);
|
||||
}
|
||||
}
|
||||
|
||||
// Type.SYNC: Setup Firefox sync.
|
||||
private void setSyncResources() {
|
||||
setResources(R.string.abouthome_about_sync, R.string.abouthome_sync_bold_name,
|
||||
R.drawable.abouthome_sync_logo);
|
||||
}
|
||||
}
|
@ -38,7 +38,9 @@ public final class GeckoViewsFactory implements LayoutInflater.Factory {
|
||||
|
||||
Log.i(LOGTAG, "Creating custom Gecko view: " + viewName);
|
||||
|
||||
if (TextUtils.equals(viewName, "AboutHomeSection"))
|
||||
if (TextUtils.equals(viewName, "AboutHomePromoBox"))
|
||||
return new AboutHomePromoBox(context, attrs);
|
||||
else if (TextUtils.equals(viewName, "AboutHomeSection"))
|
||||
return new AboutHomeSection(context, attrs);
|
||||
else if (TextUtils.equals(viewName, "AwesomeBarTabs"))
|
||||
return new AwesomeBarTabs(context, attrs);
|
||||
|
@ -36,6 +36,7 @@ UTIL_JAVA_FILES := \
|
||||
|
||||
FENNEC_JAVA_FILES = \
|
||||
AboutHomeContent.java \
|
||||
AboutHomePromoBox.java \
|
||||
AboutHomeSection.java \
|
||||
ActivityHandlerHelper.java \
|
||||
AndroidImport.java \
|
||||
@ -333,6 +334,7 @@ RES_LAYOUT = \
|
||||
res/layout/select_dialog_list.xml \
|
||||
res/layout/abouthome_addon_row.xml \
|
||||
res/layout/abouthome_last_tabs_row.xml \
|
||||
res/layout/abouthome_promo_box.xml \
|
||||
res/layout/abouthome_section.xml \
|
||||
res/layout/abouthome_remote_tab_row.xml \
|
||||
res/layout/abouthome_topsite_item.xml \
|
||||
@ -419,9 +421,9 @@ RES_DRAWABLE_BASE = \
|
||||
res/drawable/folder.png \
|
||||
res/drawable/abouthome_icon.png \
|
||||
res/drawable/abouthome_logo.png \
|
||||
res/drawable/abouthome_promo_box_bg.9.png \
|
||||
res/drawable/abouthome_sync_logo.png \
|
||||
res/drawable/abouthome_sync_bg.9.png \
|
||||
res/drawable/abouthome_sync_pressed_bg.9.png \
|
||||
res/drawable/abouthome_promo_box_pressed_bg.9.png \
|
||||
res/drawable/abouthome_thumbnail.png \
|
||||
res/drawable/address_bar_bg_shadow.png \
|
||||
res/drawable/alert_addon.png \
|
||||
@ -503,9 +505,9 @@ RES_DRAWABLE_HDPI = \
|
||||
res/drawable-hdpi/home_star.png \
|
||||
res/drawable-hdpi/abouthome_icon.png \
|
||||
res/drawable-hdpi/abouthome_logo.png \
|
||||
res/drawable-hdpi/abouthome_promo_box_bg.9.png \
|
||||
res/drawable-hdpi/abouthome_sync_logo.png \
|
||||
res/drawable-hdpi/abouthome_sync_bg.9.png \
|
||||
res/drawable-hdpi/abouthome_sync_pressed_bg.9.png \
|
||||
res/drawable-hdpi/abouthome_promo_box_pressed_bg.9.png \
|
||||
res/drawable-hdpi/abouthome_thumbnail.png \
|
||||
res/drawable-hdpi/address_bar_bg_shadow.png \
|
||||
res/drawable-hdpi/alert_addon.png \
|
||||
@ -569,9 +571,9 @@ RES_DRAWABLE_XHDPI = \
|
||||
res/drawable-xhdpi/folder.png \
|
||||
res/drawable-xhdpi/abouthome_icon.png \
|
||||
res/drawable-xhdpi/abouthome_logo.png \
|
||||
res/drawable-xhdpi/abouthome_promo_box_bg.9.png \
|
||||
res/drawable-xhdpi/abouthome_sync_logo.png \
|
||||
res/drawable-xhdpi/abouthome_sync_bg.9.png \
|
||||
res/drawable-xhdpi/abouthome_sync_pressed_bg.9.png \
|
||||
res/drawable-xhdpi/abouthome_promo_box_pressed_bg.9.png \
|
||||
res/drawable-xhdpi/abouthome_thumbnail.png \
|
||||
res/drawable-xhdpi/address_bar_bg_curve.png \
|
||||
res/drawable-xhdpi/address_bar_bg_shadow.png \
|
||||
@ -958,7 +960,7 @@ MOZ_ANDROID_DRAWABLES += \
|
||||
$(SYNC_RES_DRAWABLE) \
|
||||
mobile/android/base/resources/drawable/abouthome_bg_repeat.xml \
|
||||
mobile/android/base/resources/drawable/abouthome_divider.xml \
|
||||
mobile/android/base/resources/drawable/abouthome_sync_box.xml \
|
||||
mobile/android/base/resources/drawable/abouthome_promo_box.xml \
|
||||
mobile/android/base/resources/drawable/action_bar_button.xml \
|
||||
mobile/android/base/resources/drawable/address_bar_bg.xml \
|
||||
mobile/android/base/resources/drawable/address_bar_bg_shadow_repeat.xml \
|
||||
|
Before Width: | Height: | Size: 957 B After Width: | Height: | Size: 957 B |
Before Width: | Height: | Size: 932 B After Width: | Height: | Size: 932 B |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
@ -5,7 +5,7 @@
|
||||
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item android:state_pressed="true" android:drawable="@drawable/abouthome_sync_pressed_bg"/>
|
||||
<item android:drawable="@drawable/abouthome_sync_bg"/>
|
||||
<item android:state_pressed="true" android:drawable="@drawable/abouthome_promo_box_pressed_bg"/>
|
||||
<item android:drawable="@drawable/abouthome_promo_box_bg"/>
|
||||
|
||||
</selector>
|
Before Width: | Height: | Size: 582 B After Width: | Height: | Size: 582 B |
Before Width: | Height: | Size: 581 B After Width: | Height: | Size: 581 B |
@ -69,37 +69,18 @@
|
||||
android:textSize="12sp"
|
||||
android:gravity="top|center_horizontal"/>
|
||||
|
||||
<LinearLayout android:id="@+id/sync_box"
|
||||
android:background="@drawable/abouthome_sync_box"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="12dp"
|
||||
android:layout_marginRight="12dp"
|
||||
android:layout_marginTop="17dp"
|
||||
android:layout_marginBottom="14dp"
|
||||
android:gravity="center"
|
||||
android:clickable="true"
|
||||
android:visibility="gone">
|
||||
|
||||
<ImageView android:id="@+id/sync_logo"
|
||||
android:src="@drawable/abouthome_sync_logo"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="0"
|
||||
android:gravity="left|center_vertical"/>
|
||||
|
||||
<TextView android:id="@+id/sync_text"
|
||||
android:text="@string/abouthome_about_sync"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_marginLeft="7dp"
|
||||
android:gravity="center"
|
||||
android:textSize="15sp"
|
||||
android:textColor="#FFFFFF"/>
|
||||
|
||||
</LinearLayout>
|
||||
<org.mozilla.gecko.AboutHomePromoBox android:id="@+id/promo_box"
|
||||
android:orientation="horizontal"
|
||||
android:background="@drawable/abouthome_promo_box"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="12dp"
|
||||
android:layout_marginRight="12dp"
|
||||
android:layout_marginTop="17dp"
|
||||
android:layout_marginBottom="14dp"
|
||||
android:gravity="center"
|
||||
android:clickable="true"
|
||||
android:visibility="gone"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
@ -76,37 +76,18 @@
|
||||
android:textSize="12sp"
|
||||
android:gravity="top|center_horizontal"/>
|
||||
|
||||
<LinearLayout android:id="@+id/sync_box"
|
||||
android:background="@drawable/abouthome_sync_box"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="12dp"
|
||||
android:layout_marginRight="12dp"
|
||||
android:layout_marginTop="17dp"
|
||||
android:layout_marginBottom="14dp"
|
||||
android:gravity="center"
|
||||
android:clickable="true"
|
||||
android:visibility="gone">
|
||||
|
||||
<ImageView android:id="@+id/sync_logo"
|
||||
android:src="@drawable/abouthome_sync_logo"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="0"
|
||||
android:gravity="left|center_vertical"/>
|
||||
|
||||
<TextView android:id="@+id/sync_text"
|
||||
android:text="@string/abouthome_about_sync"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_marginLeft="7dp"
|
||||
android:gravity="center"
|
||||
android:textSize="15sp"
|
||||
android:textColor="#FFFFFF"/>
|
||||
|
||||
</LinearLayout>
|
||||
<org.mozilla.gecko.AboutHomePromoBox android:id="@+id/promo_box"
|
||||
android:orientation="horizontal"
|
||||
android:background="@drawable/abouthome_promo_box"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="12dp"
|
||||
android:layout_marginRight="12dp"
|
||||
android:layout_marginTop="17dp"
|
||||
android:layout_marginBottom="14dp"
|
||||
android:gravity="center"
|
||||
android:clickable="true"
|
||||
android:visibility="gone"/>
|
||||
|
||||
<org.mozilla.gecko.AboutHomeSection android:id="@+id/last_tabs"
|
||||
android:layout_width="fill_parent"
|
||||
|
24
mobile/android/base/resources/layout/abouthome_promo_box.xml
Normal file
@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- This Source Code Form is subject to the terms of the Mozilla Public
|
||||
- License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
|
||||
|
||||
<merge xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:gecko="http://schemas.android.com/apk/res/@ANDROID_PACKAGE_NAME@">
|
||||
|
||||
<ImageView android:id="@+id/icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="0"
|
||||
android:gravity="left|center_vertical"/>
|
||||
|
||||
<TextView android:id="@+id/text"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_marginLeft="7dp"
|
||||
android:gravity="center"
|
||||
android:textSize="15sp"
|
||||
android:textColor="#FFFFFF"/>
|
||||
|
||||
</merge>
|