Bug 855016 - Make the more-text links on about:home sections focusable and gamepad-actionable. r=sriram

This commit is contained in:
Kartikaya Gupta 2013-03-28 11:36:07 -04:00
parent af2eae9ced
commit eb296268de
3 changed files with 30 additions and 1 deletions

View File

@ -4,6 +4,8 @@
package org.mozilla.gecko;
import org.mozilla.gecko.util.GamepadUtils;
import android.content.Context;
import android.content.res.TypedArray;
import android.text.TextUtils;
@ -73,6 +75,7 @@ public class AboutHomeSection extends GeckoLinearLayout {
public void setOnMoreTextClickListener(View.OnClickListener listener) {
mMoreText.setOnClickListener(listener);
mMoreText.setOnKeyListener(GamepadUtils.getClickDispatcher());
}
public void addItem(View item) {

View File

@ -5,14 +5,20 @@
package org.mozilla.gecko;
import android.content.Context;
import android.graphics.Rect;
import android.text.SpannableString;
import android.text.style.BackgroundColorSpan;
import android.text.style.UnderlineSpan;
import android.util.AttributeSet;
import android.widget.TextView;
public class LinkTextView extends TextView {
private final BackgroundColorSpan mFocusBackgroundSpan;
private boolean mFocusApplied;
public LinkTextView(Context context, AttributeSet attrs) {
super(context, attrs);
mFocusBackgroundSpan = new BackgroundColorSpan(context.getResources().getColor(R.color.highlight_focused));
}
@Override
@ -22,4 +28,24 @@ public class LinkTextView extends TextView {
super.setText(content, BufferType.SPANNABLE);
}
@Override
public void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
super.onFocusChanged(focused, direction, previouslyFocusedRect);
if (focused == mFocusApplied) {
return;
}
mFocusApplied = focused;
CharSequence text = getText();
if (text instanceof SpannableString) {
SpannableString spannable = (SpannableString)text;
if (focused) {
spannable.setSpan(mFocusBackgroundSpan, 0, text.length(), 0);
} else {
spannable.removeSpan(mFocusBackgroundSpan);
}
}
}
}

View File

@ -40,6 +40,6 @@
android:textColor="@color/abouthome_section_more_text"
android:textSize="12sp"
android:gravity="center"
android:duplicateParentState="true"/>
android:focusable="true"/>
</merge>