mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-31 14:15:30 +00:00
Bug 880393: FadedTextView for about:home. [r=mfinkle]
This commit is contained in:
parent
70c7a48c1b
commit
7d3b8d6999
@ -6,6 +6,7 @@ package org.mozilla.gecko;
|
||||
|
||||
import org.mozilla.gecko.gfx.LayerView;
|
||||
import org.mozilla.gecko.home.BookmarkFolderView;
|
||||
import org.mozilla.gecko.home.FadedTextView;
|
||||
import org.mozilla.gecko.home.TwoLinePageRow;
|
||||
import org.mozilla.gecko.menu.MenuItemDefault;
|
||||
import org.mozilla.gecko.widget.AboutHomeView;
|
||||
@ -90,6 +91,7 @@ public final class GeckoViewsFactory implements LayoutInflater.Factory {
|
||||
mFactoryMap.put("TextView", GeckoTextView.class.getConstructor(arg1Class, arg2Class));
|
||||
mFactoryMap.put("FaviconView", FaviconView.class.getConstructor(arg1Class, arg2Class));
|
||||
mFactoryMap.put("home.BookmarkFolderView", BookmarkFolderView.class.getConstructor(arg1Class, arg2Class));
|
||||
mFactoryMap.put("home.FadedTextView", FadedTextView.class.getConstructor(arg1Class, arg2Class));
|
||||
mFactoryMap.put("home.TwoLinePageRow", TwoLinePageRow.class.getConstructor(arg1Class, arg2Class));
|
||||
} catch (NoSuchMethodException nsme) {
|
||||
Log.e(LOGTAG, "Unable to initialize views factory", nsme);
|
||||
|
@ -221,6 +221,7 @@ FENNEC_JAVA_FILES = \
|
||||
home/BookmarkFolderView.java \
|
||||
home/HomePager.java \
|
||||
home/HomePagerTabStrip.java \
|
||||
home/FadedTextView.java \
|
||||
home/TwoLinePageRow.java \
|
||||
menu/GeckoMenu.java \
|
||||
menu/GeckoMenuInflater.java \
|
||||
|
67
mobile/android/base/home/FadedTextView.java
Normal file
67
mobile/android/base/home/FadedTextView.java
Normal file
@ -0,0 +1,67 @@
|
||||
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
||||
* 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.home;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.LinearGradient;
|
||||
import android.graphics.Shader;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.mozilla.gecko.R;
|
||||
|
||||
/**
|
||||
* FadedTextView fades the ends of the text by fadeWidth amount,
|
||||
* if the text is too long and requires an ellipsis.
|
||||
*/
|
||||
public class FadedTextView extends TextView {
|
||||
|
||||
// Width of the fade effect from end of the view.
|
||||
private int mFadeWidth;
|
||||
|
||||
public FadedTextView(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
public FadedTextView(Context context, AttributeSet attrs) {
|
||||
this(context, attrs, android.R.attr.textViewStyle);
|
||||
}
|
||||
|
||||
public FadedTextView(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
|
||||
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FadedTextView);
|
||||
mFadeWidth = a.getDimensionPixelSize(R.styleable.FadedTextView_fadeWidth, 0);
|
||||
a.recycle();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void onDraw(Canvas canvas) {
|
||||
int width = getMeasuredWidth();
|
||||
|
||||
// Layout doesn't return a proper width for getWidth().
|
||||
// Instead check the width of the first line, as we've restricted to just one line.
|
||||
if (getLayout().getLineWidth(0) > width) {
|
||||
int color = getCurrentTextColor();
|
||||
float stop = ((float) (width - mFadeWidth) / (float) width);
|
||||
LinearGradient gradient = new LinearGradient(0, 0, width, 0,
|
||||
new int[] { color, color, 0x0 },
|
||||
new float[] { 0, stop, 1.0f },
|
||||
Shader.TileMode.CLAMP);
|
||||
getPaint().setShader(gradient);
|
||||
} else {
|
||||
getPaint().setShader(null);
|
||||
}
|
||||
|
||||
// Do a default draw.
|
||||
super.onDraw(canvas);
|
||||
}
|
||||
}
|
@ -3,7 +3,8 @@
|
||||
- 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">
|
||||
<merge xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:gecko="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<org.mozilla.gecko.widget.FaviconView android:id="@+id/favicon"
|
||||
android:layout_width="@dimen/favicon_bg"
|
||||
@ -15,10 +16,12 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView android:id="@+id/title"
|
||||
style="@style/Widget.TwoLinePageRow.Title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
<org.mozilla.gecko.home.FadedTextView
|
||||
android:id="@+id/title"
|
||||
style="@style/Widget.TwoLinePageRow.Title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
gecko:fadeWidth="30dp"/>
|
||||
|
||||
<TextView android:id="@+id/url"
|
||||
style="@style/Widget.TwoLinePageRow.Url"
|
||||
|
@ -9,7 +9,7 @@
|
||||
<item name="android:textAppearance">@style/TextAppearance.Widget.TwoLinePageRow.Title</item>
|
||||
<item name="android:fontFamily">sans-serif-light</item>
|
||||
<item name="android:singleLine">true</item>
|
||||
<item name="android:ellipsize">middle</item>
|
||||
<item name="android:ellipsize">none</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
|
@ -168,6 +168,10 @@
|
||||
<attr name="tabIndicatorColor" format="color"/>
|
||||
</declare-styleable>
|
||||
|
||||
<declare-styleable name="FadedTextView">
|
||||
<attr name="fadeWidth" format="dimension"/>
|
||||
</declare-styleable>
|
||||
|
||||
<declare-styleable name="BookmarkFolderView">
|
||||
<attr name="state_open" format="boolean"/>
|
||||
</declare-styleable>
|
||||
|
@ -76,7 +76,7 @@
|
||||
<style name="Widget.TwoLinePageRow.Title">
|
||||
<item name="android:textAppearance">@style/TextAppearance.Widget.TwoLinePageRow.Title</item>
|
||||
<item name="android:singleLine">true</item>
|
||||
<item name="android:ellipsize">middle</item>
|
||||
<item name="android:ellipsize">none</item>
|
||||
</style>
|
||||
|
||||
<style name="Widget.TwoLinePageRow.Url">
|
||||
|
Loading…
Reference in New Issue
Block a user