Bug 696833 - Implement dynamically coloured tabs in AwesomeBar (r=mfinkle)
|
@ -43,6 +43,9 @@ import android.content.res.Resources;
|
|||
import android.database.Cursor;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.LightingColorFilter;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.AsyncTask;
|
||||
import android.provider.Browser;
|
||||
|
@ -79,6 +82,8 @@ public class AwesomeBarTabs extends TabHost {
|
|||
|
||||
private static final String LOG_NAME = "AwesomeBarTabs";
|
||||
|
||||
private static final LightingColorFilter tabColorFilter;
|
||||
|
||||
private Context mContext;
|
||||
private OnUrlOpenListener mUrlOpenListener;
|
||||
|
||||
|
@ -86,6 +91,48 @@ public class AwesomeBarTabs extends TabHost {
|
|||
private SimpleCursorAdapter mBookmarksAdapter;
|
||||
private SimpleExpandableListAdapter mHistoryAdapter;
|
||||
|
||||
static {
|
||||
// We want to use the same color on the list items (in pressed state)
|
||||
// and the awesome screen tabs. This code is run only once to pick
|
||||
// the color of list view's pressed state.
|
||||
|
||||
Resources resources = GeckoApp.mAppContext.getResources();
|
||||
|
||||
// Load image resource that is used in list items in awesome screen
|
||||
Drawable listBackground =
|
||||
resources.getDrawable(android.R.drawable.list_selector_background);
|
||||
|
||||
// Set state of drawable to pressed state so that we can pick its
|
||||
// color to use in our tabs.
|
||||
listBackground.setState(new int[] { android.R.attr.state_pressed,
|
||||
android.R.attr.state_window_focused,
|
||||
android.R.attr.state_enabled });
|
||||
|
||||
// This number is arbitrary. We just need the image to
|
||||
// have some size for picking its color.
|
||||
int imageBounds = 40;
|
||||
|
||||
// Get currently used drawable (pressed state) and set bounds
|
||||
// to create a bitmap.
|
||||
Drawable current = listBackground.getCurrent();
|
||||
current.setBounds(0, 0, imageBounds, imageBounds);
|
||||
|
||||
Bitmap bitmap =
|
||||
Bitmap.createBitmap(imageBounds, imageBounds, Bitmap.Config.ARGB_8888);
|
||||
|
||||
// Draw the current drawable in the bitmap
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
current.draw(canvas);
|
||||
|
||||
// Pick color at central position
|
||||
int tabColor = bitmap.getPixel(imageBounds / 2, imageBounds / 2);
|
||||
|
||||
// Release bitmap to be garbage collected
|
||||
bitmap.recycle();
|
||||
|
||||
tabColorFilter = new LightingColorFilter(Color.WHITE, tabColor);
|
||||
}
|
||||
|
||||
// FIXME: This value should probably come from a
|
||||
// prefs key (just like XUL-based fennec)
|
||||
private static final int MAX_RESULTS = 100;
|
||||
|
@ -453,6 +500,9 @@ public class AwesomeBarTabs extends TabHost {
|
|||
(LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
|
||||
View indicatorView = inflater.inflate(R.layout.awesomebar_tab_indicator, null);
|
||||
Drawable background = indicatorView.getBackground();
|
||||
background.setColorFilter(tabColorFilter);
|
||||
|
||||
TextView title = (TextView) indicatorView.findViewById(R.id.title);
|
||||
title.setText(titleId);
|
||||
|
||||
|
|
|
@ -271,14 +271,13 @@ RES_LAYOUT += res/layout/crash_reporter.xml
|
|||
endif
|
||||
|
||||
MOZ_ANDROID_DRAWABLES += embedding/android/resources/drawable/address_bar_bg.xml \
|
||||
embedding/android/resources/drawable/awesomebar_tab_focus.9.png \
|
||||
embedding/android/resources/drawable/awesomebar_tab_focus_selected.9.png \
|
||||
embedding/android/resources/drawable/awesomebar_tab_focus.xml \
|
||||
embedding/android/resources/drawable/awesomebar_tab_focus_selected.xml \
|
||||
embedding/android/resources/drawable/awesomebar_tab_indicator.xml \
|
||||
embedding/android/resources/drawable/awesomebar_tab_press.9.png \
|
||||
embedding/android/resources/drawable/awesomebar_tab_press_selected.9.png \
|
||||
embedding/android/resources/drawable/awesomebar_tab_selected.9.png \
|
||||
embedding/android/resources/drawable/awesomebar_tab_separator.9.png \
|
||||
embedding/android/resources/drawable/awesomebar_tab_unselected.9.png \
|
||||
embedding/android/resources/drawable/awesomebar_tab_press.xml \
|
||||
embedding/android/resources/drawable/awesomebar_tab_press_selected.xml \
|
||||
embedding/android/resources/drawable/awesomebar_tab_selected.xml \
|
||||
embedding/android/resources/drawable/awesomebar_tab_unselected.xml \
|
||||
embedding/android/resources/drawable/desktop_notification.png \
|
||||
embedding/android/resources/drawable/favicon.png \
|
||||
embedding/android/resources/drawable/progress_spinner.xml \
|
||||
|
|
Двоичные данные
embedding/android/resources/drawable/awesomebar_tab_focus.9.png
До Ширина: | Высота: | Размер: 239 B |
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item>
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="@android:color/transparent"/>
|
||||
<size android:height="48dip"/>
|
||||
</shape>
|
||||
</item>
|
||||
|
||||
<item android:top="46dip">
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="#000000"/>
|
||||
</shape>
|
||||
</item>
|
||||
|
||||
</layer-list>
|
До Ширина: | Высота: | Размер: 239 B |
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item>
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="@android:color/transparent"/>
|
||||
<size android:height="48dip"/>
|
||||
</shape>
|
||||
</item>
|
||||
|
||||
<item android:top="36dip">
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="#111111"/>
|
||||
</shape>
|
||||
</item>
|
||||
|
||||
</layer-list>
|
Двоичные данные
embedding/android/resources/drawable/awesomebar_tab_press.9.png
До Ширина: | Высота: | Размер: 239 B |
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item>
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="@android:color/transparent"/>
|
||||
<size android:height="48dip"/>
|
||||
</shape>
|
||||
</item>
|
||||
|
||||
<item android:top="46dip">
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="#111111"/>
|
||||
</shape>
|
||||
</item>
|
||||
|
||||
</layer-list>
|
До Ширина: | Высота: | Размер: 239 B |
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item>
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="@android:color/transparent"/>
|
||||
<size android:height="48dip"/>
|
||||
</shape>
|
||||
</item>
|
||||
|
||||
<item android:top="36dip">
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="#111111"/>
|
||||
</shape>
|
||||
</item>
|
||||
|
||||
</layer-list>
|
До Ширина: | Высота: | Размер: 238 B |
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item>
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="@android:color/transparent"/>
|
||||
<size android:height="48dip"/>
|
||||
</shape>
|
||||
</item>
|
||||
|
||||
<item android:top="36dip">
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="#000000"/>
|
||||
</shape>
|
||||
</item>
|
||||
|
||||
</layer-list>
|
До Ширина: | Высота: | Размер: 219 B |
До Ширина: | Высота: | Размер: 251 B |
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item>
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="@android:color/transparent"/>
|
||||
<size android:height="48dip"/>
|
||||
</shape>
|
||||
</item>
|
||||
|
||||
<item android:top="46dip">
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="#000000"/>
|
||||
</shape>
|
||||
</item>
|
||||
|
||||
</layer-list>
|
|
@ -9,6 +9,7 @@
|
|||
<TextView android:id="@+id/title"
|
||||
style="?android:attr/tabWidgetStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="3dip"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
|
|
@ -8,8 +8,7 @@
|
|||
<TabWidget android:id="@android:id/tabs"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/awesomebar_background"
|
||||
android:divider="@drawable/awesomebar_tab_separator"/>
|
||||
android:background="@color/awesomebar_background"/>
|
||||
|
||||
<FrameLayout android:id="@android:id/tabcontent"
|
||||
android:layout_width="fill_parent"
|
||||
|
|