Bug 817138: Re-create back/forward button in code. [r=mfinkle]

--HG--
rename : mobile/android/base/resources/drawable/address_bar_back_button.xml => mobile/android/base/resources/drawable/address_bar_nav_button.xml
extra : rebase_source : 8bfb59c06c0ad3fe648a2e0fc3ca6176c5617291
This commit is contained in:
Sriram Ramasubramanian 2012-11-30 13:16:45 -08:00
parent 79b7f7961e
commit 9e45a4e900
20 changed files with 218 additions and 84 deletions

View File

@ -0,0 +1,85 @@
/* 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 android.content.Context;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PorterDuff.Mode;
import android.graphics.Shader;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.StateListDrawable;
import android.util.AttributeSet;
public class BackButton extends ShapedButton {
private Path mBorderPath;
private Paint mBorderPaint;
public BackButton(Context context, AttributeSet attrs) {
super(context, attrs);
// Paint to draw the border.
mBorderPaint = new Paint();
mBorderPaint.setAntiAlias(true);
mBorderPaint.setColor(0xFF000000);
mBorderPaint.setStyle(Paint.Style.STROKE);
// Path is masked.
mPath = new Path();
mBorderPath = new Path();
mCanvasDelegate = new CanvasDelegate(this, Mode.DST_IN);
}
@Override
protected void onSizeChanged(int width, int height, int oldWidth, int oldHeight) {
super.onSizeChanged(width, height, oldWidth, oldHeight);
mPath.reset();
mPath.addCircle(width/2, height/2, width/2, Path.Direction.CW);
float borderWidth = getContext().getResources().getDimension(R.dimen.nav_button_border_width);
mBorderPaint.setStrokeWidth(borderWidth);
mBorderPath.reset();
mBorderPath.addCircle(width/2, height/2, (width/2) - borderWidth, Path.Direction.CW);
mBorderPaint.setShader(new LinearGradient(0, 0,
0, height,
0xFF898D8F, 0xFFFEFEFE,
Shader.TileMode.CLAMP));
}
@Override
public void draw(Canvas canvas) {
mCanvasDelegate.draw(canvas, mPath, getWidth(), getHeight());
// Draw the border on top.
canvas.drawPath(mBorderPath, mBorderPaint);
}
// The drawable is constructed as per @drawable/address_bar_nav_button.
@Override
public void onLightweightThemeChanged() {
Drawable drawable = mActivity.getLightweightTheme().getDrawable(this);
if (drawable == null)
return;
Resources resources = getContext().getResources();
StateListDrawable stateList = new StateListDrawable();
stateList.addState(new int[] { android.R.attr.state_pressed }, resources.getDrawable(R.drawable.highlight));
stateList.addState(new int[] {}, drawable);
setBackgroundDrawable(stateList);
}
@Override
public void onLightweightThemeReset() {
setBackgroundResource(R.drawable.address_bar_nav_button);
}
}

View File

@ -68,8 +68,8 @@ public class BrowserToolbar implements ViewSwitcher.ViewFactory,
private boolean mAnimateSiteSecurity;
private GeckoImageButton mTabs;
private int mTabsPaneWidth;
private ImageView mBack;
private ImageView mForward;
private ImageButton mBack;
private ImageButton mForward;
public ImageButton mFavicon;
public ImageButton mStop;
public ImageButton mSiteSecurity;

View File

@ -0,0 +1,80 @@
/* 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 android.content.Context;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PorterDuff.Mode;
import android.graphics.Shader;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.StateListDrawable;
import android.util.AttributeSet;
public class ForwardButton extends ShapedButton {
private Path mBorderPath;
private Paint mBorderPaint;
public ForwardButton(Context context, AttributeSet attrs) {
super(context, attrs);
// Paint to draw the border.
mBorderPaint = new Paint();
mBorderPaint.setAntiAlias(true);
mBorderPaint.setColor(0xFF000000);
mBorderPaint.setStyle(Paint.Style.STROKE);
mBorderPath = new Path();
}
@Override
protected void onSizeChanged(int width, int height, int oldWidth, int oldHeight) {
super.onSizeChanged(width, height, oldWidth, oldHeight);
float borderWidth = getContext().getResources().getDimension(R.dimen.nav_button_border_width);
mBorderPaint.setStrokeWidth(borderWidth);
mBorderPath.reset();
mBorderPath.moveTo(width - borderWidth, 0);
mBorderPath.lineTo(width - borderWidth, height);
mBorderPaint.setShader(new LinearGradient(0, 0,
0, height,
0xFF898D8F, 0xFFFEFEFE,
Shader.TileMode.CLAMP));
}
@Override
public void draw(Canvas canvas) {
super.draw(canvas);
// Draw the border on top.
canvas.drawPath(mBorderPath, mBorderPaint);
}
// The drawable is constructed as per @drawable/address_bar_nav_button.
@Override
public void onLightweightThemeChanged() {
Drawable drawable = mActivity.getLightweightTheme().getDrawable(this);
if (drawable == null)
return;
Resources resources = getContext().getResources();
StateListDrawable stateList = new StateListDrawable();
stateList.addState(new int[] { android.R.attr.state_pressed }, resources.getDrawable(R.drawable.highlight));
stateList.addState(new int[] {}, drawable);
setBackgroundDrawable(stateList);
}
@Override
public void onLightweightThemeReset() {
setBackgroundResource(R.drawable.address_bar_nav_button);
}
}

View File

@ -60,6 +60,8 @@ public final class GeckoViewsFactory implements LayoutInflater.Factory {
return new AwesomeBarTabs(context, attrs);
else if (TextUtils.equals(viewName, "AwesomeBarTabs.Background"))
return new AwesomeBarTabs.Background(context, attrs);
else if (TextUtils.equals(viewName, "BackButton"))
return new BackButton(context, attrs);
else if (TextUtils.equals(viewName, "BrowserToolbarBackground"))
return new BrowserToolbarBackground(context, attrs);
else if (TextUtils.equals(viewName, "BrowserToolbar$RightEdge"))

View File

@ -51,6 +51,7 @@ FENNEC_JAVA_FILES = \
awesomebar/AllPagesTab.java \
awesomebar/BookmarksTab.java \
awesomebar/HistoryTab.java \
BackButton.java \
BrowserApp.java \
BrowserToolbar.java \
BrowserToolbarBackground.java \
@ -71,6 +72,7 @@ FENNEC_JAVA_FILES = \
FlowLayout.java \
FontSizePreference.java \
FormAssistPopup.java \
ForwardButton.java \
GeckoAccessibility.java \
GeckoApplication.java \
GeckoApp.java \
@ -538,10 +540,6 @@ RES_DRAWABLE_BASE = \
res/drawable/tab_thumbnail_shadow.png \
res/drawable/tabs_carat.png \
res/drawable/tabs_carat_pb.png \
res/drawable/address_bar_back_button.xml \
res/drawable/address_bar_back_button_bg.xml \
res/drawable/address_bar_back_button_pressed_bg.xml \
res/drawable/address_bar_forward_button.xml \
res/drawable/address_bar_texture_port.png \
res/drawable/address_bar_texture_port_pb.png \
res/drawable/address_bar_url_default.9.png \
@ -896,8 +894,6 @@ RES_DRAWABLE_LARGE_MDPI_V11 = \
res/drawable-large-mdpi-v11/address_bar_bg_private.xml \
res/drawable-large-mdpi-v11/address_bar_texture_tablet.png \
res/drawable-large-mdpi-v11/address_bar_texture_tablet_pb.png \
res/drawable-large-mdpi-v11/address_bar_back_button_bg.png \
res/drawable-large-mdpi-v11/address_bar_back_button_pressed_bg.png \
res/drawable-large-mdpi-v11/address_bar_url_default.9.png \
res/drawable-large-mdpi-v11/address_bar_url_default_pb.9.png \
res/drawable-large-mdpi-v11/address_bar_url_pressed.9.png \
@ -924,8 +920,6 @@ RES_DRAWABLE_LARGE_MDPI_V11 = \
RES_DRAWABLE_LARGE_HDPI_V11 = \
res/drawable-large-hdpi-v11/address_bar_texture_tablet.png \
res/drawable-large-hdpi-v11/address_bar_texture_tablet_pb.png \
res/drawable-large-hdpi-v11/address_bar_back_button_bg.png \
res/drawable-large-hdpi-v11/address_bar_back_button_pressed_bg.png \
res/drawable-large-hdpi-v11/address_bar_url_default.9.png \
res/drawable-large-hdpi-v11/address_bar_url_default_pb.9.png \
res/drawable-large-hdpi-v11/address_bar_url_pressed.9.png \
@ -952,8 +946,6 @@ RES_DRAWABLE_LARGE_HDPI_V11 = \
RES_DRAWABLE_LARGE_XHDPI_V11 = \
res/drawable-large-xhdpi-v11/address_bar_texture_tablet.png \
res/drawable-large-xhdpi-v11/address_bar_texture_tablet_pb.png \
res/drawable-large-xhdpi-v11/address_bar_back_button_bg.png \
res/drawable-large-xhdpi-v11/address_bar_back_button_pressed_bg.png \
res/drawable-large-xhdpi-v11/address_bar_url_default.9.png \
res/drawable-large-xhdpi-v11/address_bar_url_default_pb.9.png \
res/drawable-large-xhdpi-v11/address_bar_url_pressed.9.png \
@ -1042,6 +1034,7 @@ MOZ_ANDROID_DRAWABLES += \
mobile/android/base/resources/drawable/address_bar_bg_normal.xml \
mobile/android/base/resources/drawable/address_bar_bg_private.xml \
mobile/android/base/resources/drawable/address_bar_bg_shadow_repeat.xml \
mobile/android/base/resources/drawable/address_bar_nav_button.xml \
mobile/android/base/resources/drawable/autocomplete_list_bg.9.png \
mobile/android/base/resources/drawable/awesomebar_tab_indicator.xml \
mobile/android/base/resources/drawable/awesomebar_tab_selected.xml \

View File

@ -56,7 +56,10 @@ public abstract class ShapedButton extends GeckoImageButton
@Override
public void draw(Canvas canvas) {
mCanvasDelegate.draw(canvas, mPath, getWidth(), getHeight());
if (mCanvasDelegate != null)
mCanvasDelegate.draw(canvas, mPath, getWidth(), getHeight());
else
defaultDraw(canvas);
}
@Override

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.2 KiB

View File

@ -1,11 +0,0 @@
<?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/. -->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/address_bar_back_button_pressed_bg"/>
<item android:drawable="@drawable/address_bar_back_button_bg"/>
</selector>

View File

@ -1,11 +0,0 @@
<?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/. -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@android:color/transparent"/>
</shape>

View File

@ -1,11 +0,0 @@
<?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/. -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@android:color/transparent"/>
</shape>

View File

@ -5,7 +5,10 @@
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- pressed state -->
<item android:state_pressed="true" android:drawable="@drawable/highlight"/>
<item android:drawable="@drawable/address_bar_bg"/>
<!-- normal mode -->
<item android:drawable="@drawable/address_bar_bg_normal"/>
</selector>

View File

@ -69,26 +69,26 @@
</Gecko.RelativeLayout>
<ImageButton android:id="@+id/forward"
style="@style/AddressBar.ImageButton"
android:layout_width="64dip"
android:layout_height="40dip"
android:layout_marginLeft="21dp"
android:paddingLeft="21dp"
android:layout_gravity="center_vertical"
android:src="@drawable/ic_menu_forward"
android:contentDescription="@string/forward"
android:background="@drawable/address_bar_forward_button"/>
<org.mozilla.gecko.ForwardButton android:id="@+id/forward"
style="@style/AddressBar.ImageButton"
android:layout_width="64dip"
android:layout_height="42dip"
android:layout_marginLeft="21dp"
android:paddingLeft="21dp"
android:layout_gravity="center_vertical"
android:src="@drawable/ic_menu_forward"
android:contentDescription="@string/forward"
android:background="@drawable/address_bar_nav_button"/>
<ImageButton android:id="@+id/back"
style="@style/AddressBar.ImageButton"
android:layout_width="50dip"
android:layout_height="50dip"
android:layout_marginLeft="1dp"
android:layout_gravity="center_vertical"
android:src="@drawable/ic_menu_back"
android:contentDescription="@string/back"
android:background="@drawable/address_bar_back_button"/>
<org.mozilla.gecko.BackButton android:id="@+id/back"
style="@style/AddressBar.ImageButton"
android:layout_width="50dip"
android:layout_height="50dip"
android:layout_marginLeft="1dp"
android:layout_gravity="center_vertical"
android:src="@drawable/ic_menu_back"
android:contentDescription="@string/back"
android:background="@drawable/address_bar_nav_button"/>
<LinearLayout style="@style/AddressBar.Button"
android:layout_marginLeft="90dp"

View File

@ -104,25 +104,25 @@
</Gecko.RelativeLayout>
<ImageButton android:id="@+id/forward"
style="@style/AddressBar.ImageButton"
android:layout_width="64dip"
android:layout_height="40dip"
android:layout_marginLeft="22dp"
android:paddingLeft="22dp"
android:layout_centerVertical="true"
android:src="@drawable/ic_menu_forward"
android:contentDescription="@string/forward"
android:background="@drawable/address_bar_forward_button"/>
<org.mozilla.gecko.ForwardButton android:id="@+id/forward"
style="@style/AddressBar.ImageButton"
android:layout_width="64dip"
android:layout_height="42dip"
android:layout_marginLeft="22dp"
android:paddingLeft="22dp"
android:layout_centerVertical="true"
android:src="@drawable/ic_menu_forward"
android:contentDescription="@string/forward"
android:background="@drawable/address_bar_nav_button"/>
<ImageButton android:id="@+id/back"
style="@style/AddressBar.ImageButton"
android:layout_width="50dip"
android:layout_height="50dip"
android:layout_centerVertical="true"
android:src="@drawable/ic_menu_back"
android:contentDescription="@string/back"
android:background="@drawable/address_bar_back_button"/>
<org.mozilla.gecko.BackButton android:id="@+id/back"
style="@style/AddressBar.ImageButton"
android:layout_width="50dip"
android:layout_height="50dip"
android:layout_centerVertical="true"
android:src="@drawable/ic_menu_back"
android:contentDescription="@string/back"
android:background="@drawable/address_bar_nav_button"/>
<LinearLayout style="@style/AddressBar.Button"
android:layout_marginLeft="84dp"

View File

@ -31,6 +31,7 @@
<dimen name="menu_item_row_width">240dp</dimen>
<dimen name="menu_popup_width">256dp</dimen>
<dimen name="menu_popup_offset">8dp</dimen>
<dimen name="nav_button_border_width">1dp</dimen>
<dimen name="prompt_service_group_padding_size">32dp</dimen>
<dimen name="prompt_service_icon_size">72dp</dimen>
<dimen name="prompt_service_icon_text_padding">10dp</dimen>