10 | * 它继承于 LinearLayout.
11 | * 使用方式和LinerLayout是一样的
12 | * @author hailongqiu 13 | * 14 | */ 15 | public class LinearMainLayout extends LinearLayout { 16 | 17 | public LinearMainLayout(Context context) { 18 | super(context); 19 | init(context); 20 | } 21 | 22 | public LinearMainLayout(Context context, AttributeSet attrs) { 23 | super(context, attrs); 24 | init(context); 25 | } 26 | 27 | WidgetTvViewBring mWidgetTvViewBring; 28 | 29 | private void init(Context context) { 30 | this.setChildrenDrawingOrderEnabled(true); 31 | mWidgetTvViewBring = new WidgetTvViewBring(this); 32 | } 33 | 34 | @Override 35 | public void bringChildToFront(View child) { 36 | mWidgetTvViewBring.bringChildToFront(this, child); 37 | } 38 | 39 | @Override 40 | protected int getChildDrawingOrder(int childCount, int i) { 41 | return mWidgetTvViewBring.getChildDrawingOrder(childCount, i); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /androidtvwidget/src/main/java/com/open/androidtvwidget/view/ListViewTV.java: -------------------------------------------------------------------------------- 1 | package com.open.androidtvwidget.view; 2 | 3 | import android.content.Context; 4 | import android.graphics.Canvas; 5 | import android.util.AttributeSet; 6 | import android.view.View; 7 | import android.widget.ListView; 8 | 9 | public class ListViewTV extends ListView { 10 | 11 | public ListViewTV(Context context) { 12 | super(context); 13 | init(context, null); 14 | } 15 | 16 | public ListViewTV(Context context, AttributeSet attrs) { 17 | super(context, attrs); 18 | init(context, attrs); 19 | } 20 | 21 | /** 22 | * 崩溃了. 23 | */ 24 | @Override 25 | protected void dispatchDraw(Canvas canvas) { 26 | try { 27 | super.dispatchDraw(canvas); 28 | } catch (Exception e) { 29 | e.printStackTrace(); 30 | } 31 | } 32 | 33 | WidgetTvViewBring mWidgetTvViewBring; 34 | 35 | private void init(Context context, AttributeSet attrs) { 36 | this.setChildrenDrawingOrderEnabled(true); 37 | mWidgetTvViewBring = new WidgetTvViewBring(this); 38 | } 39 | 40 | @Override 41 | public void bringChildToFront(View child) { 42 | mWidgetTvViewBring.bringChildToFront(this, child); 43 | } 44 | 45 | @Override 46 | protected int getChildDrawingOrder(int childCount, int i) { 47 | return mWidgetTvViewBring.getChildDrawingOrder(childCount, i); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /androidtvwidget/src/main/java/com/open/androidtvwidget/view/MainLayout.java: -------------------------------------------------------------------------------- 1 | package com.open.androidtvwidget.view; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | import android.view.View; 6 | import android.widget.FrameLayout; 7 | 8 | /** 9 | * 如果有控件放大被挡住,可以使用 MainLayout, 10 | *
11 | * 它继承于 FrameLayout. 12 | *
13 | * 使用方式就和FrameLayout是一样的 14 | *
15 | * 如果你其它的控件也被挡住了,但是这里没有,你可以使用WidgetTvViewBring 16 | *
17 | * 18 | * @author hailongqiu 19 | * 20 | */ 21 | public class MainLayout extends FrameLayout { 22 | 23 | public MainLayout(Context context) { 24 | super(context); 25 | init(context); 26 | } 27 | 28 | public MainLayout(Context context, AttributeSet attrs) { 29 | super(context, attrs); 30 | init(context); 31 | } 32 | 33 | WidgetTvViewBring mWidgetTvViewBring; 34 | 35 | private void init(Context context) { 36 | this.setChildrenDrawingOrderEnabled(true); 37 | mWidgetTvViewBring = new WidgetTvViewBring(this); 38 | } 39 | 40 | @Override 41 | public void bringChildToFront(View child) { 42 | mWidgetTvViewBring.bringChildToFront(this, child); 43 | } 44 | 45 | @Override 46 | protected int getChildDrawingOrder(int childCount, int i) { 47 | return mWidgetTvViewBring.getChildDrawingOrder(childCount, i); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /androidtvwidget/src/main/java/com/open/androidtvwidget/view/RelativeMainLayout.java: -------------------------------------------------------------------------------- 1 | package com.open.androidtvwidget.view; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | import android.view.View; 6 | import android.widget.RelativeLayout; 7 | 8 | /** 9 | * 如果有控件放大被挡住,可以使用 RelativeMainLayout,
10 | * 它继承于 LinearLayout.
11 | * 使用方式和LinerLayout是一样的
12 | * @author hailongqiu 13 | * 14 | */ 15 | public class RelativeMainLayout extends RelativeLayout { 16 | 17 | public RelativeMainLayout(Context context) { 18 | super(context); 19 | init(context); 20 | } 21 | 22 | public RelativeMainLayout(Context context, AttributeSet attrs) { 23 | super(context, attrs); 24 | init(context); 25 | } 26 | 27 | WidgetTvViewBring mWidgetTvViewBring; 28 | 29 | private void init(Context context) { 30 | this.setChildrenDrawingOrderEnabled(true); 31 | mWidgetTvViewBring = new WidgetTvViewBring(this); 32 | } 33 | 34 | @Override 35 | public void bringChildToFront(View child) { 36 | mWidgetTvViewBring.bringChildToFront(this, child); 37 | } 38 | 39 | @Override 40 | protected int getChildDrawingOrder(int childCount, int i) { 41 | return mWidgetTvViewBring.getChildDrawingOrder(childCount, i); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /androidtvwidget/src/main/java/com/open/androidtvwidget/view/SmoothVorizontalScrollView.java: -------------------------------------------------------------------------------- 1 | package com.open.androidtvwidget.view; 2 | 3 | import com.open.androidtvwidget.R; 4 | 5 | import android.content.Context; 6 | import android.graphics.Rect; 7 | import android.util.AttributeSet; 8 | import android.widget.ScrollView; 9 | 10 | /** 11 | * 当你使用滚动窗口焦点错乱的时候,就可以使用这个控件. 12 | *
13 | * 使用方法和滚动窗口是一样的,具体查看DEMO吧. 14 | *
15 | * 如果想改变滚动的系数,R.dimen.fading_edge 16 | *
17 | *
18 | * @author hailongqiu
19 | */
20 | public class SmoothVorizontalScrollView extends ScrollView {
21 |
22 | public SmoothVorizontalScrollView(Context context) {
23 | super(context, null, 0);
24 | }
25 |
26 | public SmoothVorizontalScrollView(Context context, AttributeSet attrs) {
27 | super(context, attrs, 0);
28 | }
29 |
30 | public SmoothVorizontalScrollView(Context context, AttributeSet attrs, int defStyle) {
31 | super(context, attrs, defStyle);
32 | }
33 |
34 | @Override
35 | protected int computeScrollDeltaToGetChildRectOnScreen(Rect rect) {
36 | if (getChildCount() == 0)
37 | return 0;
38 | int height = getHeight();
39 | int screenTop = getScrollY();
40 | int screenBottom = screenTop + height;
41 | int fadingEdge = this.getResources().getDimensionPixelSize(R.dimen.fading_edge);
42 | if (rect.top > 0) {
43 | screenTop += fadingEdge;
44 | }
45 | if (rect.bottom < getChildAt(0).getHeight()) {
46 | screenBottom -= fadingEdge;
47 | }
48 | //
49 | int scrollYDelta = 0;
50 | if (rect.bottom > screenBottom && rect.top > screenTop) {
51 | if (rect.height() > height) {
52 | scrollYDelta += (rect.top - screenTop);
53 | } else {
54 | scrollYDelta += (rect.bottom - screenBottom);
55 | }
56 | int bottom = getChildAt(0).getBottom();
57 | int distanceToBottom = bottom - screenBottom;
58 | scrollYDelta = Math.min(scrollYDelta, distanceToBottom);
59 | } else if (rect.top < screenTop && rect.bottom < screenBottom) {
60 | if (rect.height() > height) {
61 | scrollYDelta -= (screenBottom - rect.bottom);
62 | } else {
63 | scrollYDelta -= (screenTop - rect.top);
64 | }
65 | scrollYDelta = Math.max(scrollYDelta, -getScrollY());
66 | }
67 | return scrollYDelta;
68 | }
69 |
70 | }
71 |
--------------------------------------------------------------------------------
/androidtvwidget/src/main/java/com/open/androidtvwidget/view/TextViewWithTTF.java:
--------------------------------------------------------------------------------
1 | package com.open.androidtvwidget.view;
2 |
3 |
4 | import java.util.HashMap;
5 |
6 | import com.open.androidtvwidget.R;
7 |
8 | import android.content.Context;
9 | import android.content.res.TypedArray;
10 | import android.graphics.Typeface;
11 | import android.util.AttributeSet;
12 | import android.widget.TextView;
13 |
14 | /**
15 | * 一个自定义的TextView控件.
16 | * 加载 /system/font/** 下面的字库.
17 | * @author hailongqiu
18 | *
19 | */
20 | public class TextViewWithTTF extends TextView {
21 |
22 | private static final TypeFaceMgr SFontMgr = new TypeFaceMgr();
23 |
24 | public TextViewWithTTF(Context context) {
25 | super(context);
26 | }
27 |
28 | public TextViewWithTTF(Context context, AttributeSet attrs) {
29 | super(context, attrs);
30 |
31 | TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.TextViewWithTTF);
32 | setTypeface(SFontMgr.getTypeface(array.getString(R.styleable.TextViewWithTTF_ttf_name)));
33 | array.recycle();
34 | }
35 |
36 |
37 |
38 | public TextViewWithTTF(Context context, String aTTFName)
39 | {
40 | super(context);
41 | setTypeface(SFontMgr.getTypeface(aTTFName));
42 | }
43 |
44 | public void setFont(String aTTFName) {
45 | setTypeface(SFontMgr.getTypeface(aTTFName));
46 | }
47 | }
48 |
49 |
50 | class TypeFaceMgr
51 | {
52 | HashMap
8 | * ListView, GridView, ViewGroup中使用. 想要置顶的子控件,不要忘记调用 bringToFront() 噢.
9 | *
10 | * @author hailongqiu
11 | *
12 | */
13 | public class WidgetTvViewBring {
14 |
15 | private int position = 0;
16 |
17 | public WidgetTvViewBring() {
18 | }
19 |
20 | public WidgetTvViewBring(ViewGroup vg) {
21 | vg.setClipChildren(false);
22 | vg.setClipToPadding(false);
23 | // vg.setChildrenDrawingOrderEnabled(true);
24 | }
25 |
26 | public void bringChildToFront(ViewGroup vg, View child) {
27 | position = vg.indexOfChild(child);
28 | if (position != -1) {
29 | vg.postInvalidate();
30 | }
31 | }
32 |
33 | /**
34 | * 此函数 dispatchDraw 中调用.
35 | * 原理就是和最后一个要绘制的view,交换了位置.
36 | * 因为dispatchDraw最后一个绘制的view是在最上层的.
37 | * 这样就避免了使用 bringToFront 导致焦点错乱问题.
38 | */
39 | public int getChildDrawingOrder(int childCount, int i) {
40 | // if (position != -1) {
41 | // if (i == childCount - 1)
42 | // return position;
43 | // if (i == position)
44 | // return childCount - 1;
45 | // }
46 | // return i;
47 | if (position < 0) {
48 | return i;
49 | }
50 | if (i < (childCount - 1)) {
51 | if (position == i)
52 | i = childCount - 1;
53 | } else {
54 | if (position < childCount)
55 | i = position;
56 | }
57 | return i;
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/androidtvwidget/src/main/res/drawable/nocolor.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Dawish/BriskTVLauncher/265753847435804c26ba4f393003680ac2597841/androidtvwidget/src/main/res/drawable/nocolor.png
--------------------------------------------------------------------------------
/androidtvwidget/src/main/res/layout/list_menu_item_icon.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |