├── settings.gradle ├── data ├── demo1.gif ├── device-shot1.png └── device-shot2.png ├── lib ├── src │ └── main │ │ ├── res │ │ ├── values │ │ │ ├── strings.xml │ │ │ ├── attrs.xml │ │ │ └── colors.xml │ │ ├── drawable │ │ │ ├── border_white.9.png │ │ │ ├── border_shadow.9.png │ │ │ ├── border_highlight.9.png │ │ │ └── border_white_light_10.9.png │ │ └── layout │ │ │ └── layout_border.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ └── org │ │ └── evilbinary │ │ └── tv │ │ ├── util │ │ ├── DimensionConvert.java │ │ └── AnimateFactory.java │ │ └── widget │ │ ├── TvGridView.java │ │ ├── TvZorderLinearLayout.java │ │ ├── RoundedFrameLayout.java │ │ ├── AutoGridLayoutManager.java │ │ ├── TvZorderRelativeLayout.java │ │ ├── TvLinearLayoutManager.java │ │ ├── TvHorizontalScrollView.java │ │ ├── TvGridLayoutManagerScrolling.java │ │ ├── TvTextView.java │ │ ├── BorderView.java │ │ ├── RoundImpl.java │ │ └── BorderEffect.java ├── proguard-rules.pro └── build.gradle ├── app ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── colors.xml │ │ │ │ ├── dimens.xml │ │ │ │ └── styles.xml │ │ │ ├── drawable │ │ │ │ ├── g2.png │ │ │ │ ├── g3.png │ │ │ │ ├── g5.png │ │ │ │ ├── demo1.png │ │ │ │ ├── home_bg.png │ │ │ │ ├── border_shape.xml │ │ │ │ ├── border_top_right_shape.xml │ │ │ │ ├── border_down_shape.xml │ │ │ │ ├── border_red.xml │ │ │ │ ├── list_item_shape.xml │ │ │ │ ├── shape.xml │ │ │ │ ├── border_shape_with_border.xml │ │ │ │ └── border_shadow_shap.xml │ │ │ ├── mipmap-hdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-mdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── values-w820dp │ │ │ │ └── dimens.xml │ │ │ └── layout │ │ │ │ ├── demo_fragment.xml │ │ │ │ ├── item_grid.xml │ │ │ │ ├── item2.xml │ │ │ │ ├── demo_recycler_view.xml │ │ │ │ ├── custom_item.xml │ │ │ │ ├── viewpage_item.xml │ │ │ │ ├── demo_grid_view.xml │ │ │ │ ├── item.xml │ │ │ │ ├── item_menu_sub.xml │ │ │ │ ├── demo_menu.xml │ │ │ │ ├── demo_fragment_grid_view.xml │ │ │ │ ├── demo_list_view.xml │ │ │ │ ├── item_list.xml │ │ │ │ ├── demo_two_recycler_view.xml │ │ │ │ ├── item_menu.xml │ │ │ │ ├── item3.xml │ │ │ │ ├── demo_tab_view.xml │ │ │ │ ├── activity_main.xml │ │ │ │ └── activity_home.xml │ │ ├── java │ │ │ └── org │ │ │ │ └── evilbinary │ │ │ │ └── tv │ │ │ │ ├── DemoFragmentActivity.java │ │ │ │ ├── DemoHomeActivity.java │ │ │ │ ├── MyFragment2.java │ │ │ │ ├── MyGridViewAdapter.java │ │ │ │ ├── MyFragment.java │ │ │ │ ├── DemoGridViewActivity.java │ │ │ │ ├── MainActivity.java │ │ │ │ ├── DemoTwoRecyclerViewActivity.java │ │ │ │ ├── DemoListViewActivity.java │ │ │ │ ├── DemoRecyclerViewActivity.java │ │ │ │ ├── MyAdapter.java │ │ │ │ ├── DemoTopBorderActivity.java │ │ │ │ ├── DemoTabActivity.java │ │ │ │ └── DemoMenuActivity.java │ │ └── AndroidManifest.xml │ └── test │ │ └── java │ │ └── evilbinary │ │ └── org │ │ └── tvwidget │ │ └── ExampleUnitTest.java ├── proguard-rules.pro └── build.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── gradle.properties ├── gradlew.bat ├── README.md ├── gradlew └── LICENSE /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':lib' 2 | -------------------------------------------------------------------------------- /data/demo1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evilbinary/TvWidget/HEAD/data/demo1.gif -------------------------------------------------------------------------------- /data/device-shot1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evilbinary/TvWidget/HEAD/data/device-shot1.png -------------------------------------------------------------------------------- /data/device-shot2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evilbinary/TvWidget/HEAD/data/device-shot2.png -------------------------------------------------------------------------------- /lib/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | lib 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | TvWidget 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/g2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evilbinary/TvWidget/HEAD/app/src/main/res/drawable/g2.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/g3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evilbinary/TvWidget/HEAD/app/src/main/res/drawable/g3.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/g5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evilbinary/TvWidget/HEAD/app/src/main/res/drawable/g5.png -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evilbinary/TvWidget/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/drawable/demo1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evilbinary/TvWidget/HEAD/app/src/main/res/drawable/demo1.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/home_bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evilbinary/TvWidget/HEAD/app/src/main/res/drawable/home_bg.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evilbinary/TvWidget/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evilbinary/TvWidget/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /lib/src/main/res/drawable/border_white.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evilbinary/TvWidget/HEAD/lib/src/main/res/drawable/border_white.9.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evilbinary/TvWidget/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evilbinary/TvWidget/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /lib/src/main/res/drawable/border_shadow.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evilbinary/TvWidget/HEAD/lib/src/main/res/drawable/border_shadow.9.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evilbinary/TvWidget/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /lib/src/main/res/drawable/border_highlight.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evilbinary/TvWidget/HEAD/lib/src/main/res/drawable/border_highlight.9.png -------------------------------------------------------------------------------- /lib/src/main/res/drawable/border_white_light_10.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/evilbinary/TvWidget/HEAD/lib/src/main/res/drawable/border_white_light_10.9.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/border_shape.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/border_top_right_shape.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Oct 21 11:34:03 PDT 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip 7 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/border_down_shape.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/border_red.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | -------------------------------------------------------------------------------- /lib/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/list_item_shape.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/shape.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /lib/src/main/res/layout/layout_border.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/border_shape_with_border.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/test/java/evilbinary/org/tvwidget/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package evilbinary.org.tvwidget; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * To work on unit tests, switch the Test Artifact in the Build Variants view. 9 | */ 10 | public class ExampleUnitTest { 11 | @Test 12 | public void addition_isCorrect() throws Exception { 13 | assertEquals(4, 2 + 2); 14 | } 15 | } -------------------------------------------------------------------------------- /app/src/main/res/drawable/border_shadow_shap.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/layout/demo_fragment.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # General 2 | .DS_Store 3 | *~ 4 | 5 | # Android Studio 6 | .idea/ 7 | .gradle 8 | local.properties 9 | /*/out 10 | build 11 | *.iml 12 | *.iws 13 | *.ipr 14 | *.swp 15 | 16 | 17 | 18 | # built application files 19 | *.apk 20 | *.ap_ 21 | 22 | # files for the dex VM 23 | *.dex 24 | 25 | # Java class files 26 | *.class 27 | 28 | # generated files 29 | /app/app.iml 30 | bin/ 31 | gen/ 32 | 33 | # Eclipse project files 34 | .classpath 35 | .project 36 | 37 | # Proguard folder generated by Eclipse 38 | proguard/ 39 | -------------------------------------------------------------------------------- /app/src/main/java/org/evilbinary/tv/DemoFragmentActivity.java: -------------------------------------------------------------------------------- 1 | package org.evilbinary.tv; 2 | 3 | import android.app.Activity; 4 | import android.app.Fragment; 5 | import android.os.Bundle; 6 | 7 | /** 8 | * 作者:evilbinary on 2/28/16. 9 | * 邮箱:rootdebug@163.com 10 | */ 11 | public class DemoFragmentActivity extends Activity{ 12 | 13 | @Override 14 | protected void onCreate(Bundle savedInstanceState) { 15 | super.onCreate(savedInstanceState); 16 | setContentView(R.layout.demo_fragment); 17 | 18 | Fragment fragment=new MyFragment(); 19 | getFragmentManager().beginTransaction().replace(R.id.fragment,fragment).commit(); 20 | 21 | 22 | 23 | } 24 | 25 | 26 | } 27 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/evil/Applications/adt-bundle-mac-x86_64-20140702/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /lib/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/evil/Applications/adt-bundle-mac-x86_64-20140702/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 22 5 | buildToolsVersion "23.0.2" 6 | 7 | defaultConfig { 8 | applicationId "evilbinary.org.tvwidget" 9 | minSdkVersion 14 10 | targetSdkVersion 19 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | testCompile 'junit:junit:4.12' 25 | compile 'com.android.support:appcompat-v7:22.+' 26 | compile 'com.flyco.labelview:FlycoLabelView_Lib:1.0.2@aar' 27 | compile project(':lib') 28 | } 29 | -------------------------------------------------------------------------------- /lib/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 22 5 | buildToolsVersion "23.0.2" 6 | 7 | defaultConfig { 8 | minSdkVersion 14 9 | targetSdkVersion 19 10 | versionCode 1 11 | versionName "1.0" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | android { 20 | lintOptions { 21 | abortOnError false 22 | } 23 | } 24 | } 25 | 26 | dependencies { 27 | compile fileTree(dir: 'libs', include: ['*.jar']) 28 | compile 'com.android.support:appcompat-v7:22.+' 29 | compile 'com.android.support:cardview-v7:22+' 30 | compile 'com.android.support:recyclerview-v7:22+' 31 | } 32 | -------------------------------------------------------------------------------- /lib/src/main/java/org/evilbinary/tv/util/DimensionConvert.java: -------------------------------------------------------------------------------- 1 | package org.evilbinary.tv.util; 2 | 3 | import android.content.Context; 4 | 5 | 6 | public class DimensionConvert { 7 | 8 | /** 9 | * 根据手机的分辨率从 dp 的单位 转成为 px(像素) 10 | * 11 | * @param context 12 | * @param dpValue 要转换的dp值 13 | */ 14 | public static int dip2px(Context context, float dpValue) { 15 | final float scale = context.getResources().getDisplayMetrics().density; 16 | return (int) (dpValue * scale + 0.5f); 17 | } 18 | 19 | /** 20 | * 根据手机的分辨率从 px(像素) 的单位 转成为 dp 21 | * 22 | * @param context 23 | * @param pxValue 要转换的px值 24 | */ 25 | public static int px2dip(Context context, float pxValue) { 26 | final float scale = context.getResources().getDisplayMetrics().density; 27 | return (int) (pxValue / scale + 0.5f); 28 | } 29 | } -------------------------------------------------------------------------------- /app/src/main/res/layout/item_grid.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 12 | 22 | 23 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /app/src/main/java/org/evilbinary/tv/DemoHomeActivity.java: -------------------------------------------------------------------------------- 1 | package org.evilbinary.tv; 2 | 3 | import android.app.Activity; 4 | import android.os.Bundle; 5 | import android.view.ViewGroup; 6 | 7 | import org.evilbinary.tv.widget.BorderView; 8 | 9 | /** 10 | * 作者:evilbinary on 3/19/16. 11 | * 邮箱:rootdebug@163.com 12 | */ 13 | public class DemoHomeActivity extends Activity { 14 | 15 | @Override 16 | protected void onCreate(Bundle savedInstanceState) { 17 | super.onCreate(savedInstanceState); 18 | setContentView(R.layout.activity_home); 19 | 20 | BorderView border = new BorderView(this); 21 | 22 | border.setBackgroundResource(R.drawable.border_red); 23 | //border.setBackgroundColor(Color.GREEN); 24 | 25 | //border.getEffect().setScale(1.1f); 26 | 27 | ViewGroup list = (ViewGroup) findViewById(R.id.list); 28 | border.attachTo(list); 29 | 30 | } 31 | 32 | 33 | } 34 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item2.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /app/src/main/res/layout/demo_recycler_view.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /app/src/main/res/layout/custom_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 25 | 26 | -------------------------------------------------------------------------------- /app/src/main/java/org/evilbinary/tv/MyFragment2.java: -------------------------------------------------------------------------------- 1 | package org.evilbinary.tv; 2 | 3 | import android.app.Fragment; 4 | import android.os.Bundle; 5 | import android.support.annotation.Nullable; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | 10 | import org.evilbinary.tv.widget.BorderView; 11 | 12 | /** 13 | * 作者:evilbinary on 2/28/16. 14 | * 邮箱:rootdebug@163.com 15 | */ 16 | public class MyFragment2 extends Fragment { 17 | private View mView; 18 | 19 | @Nullable 20 | @Override 21 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 22 | mView = inflater.inflate(R.layout.activity_main, container, false); 23 | 24 | 25 | BorderView borderView = new BorderView(getActivity()); 26 | borderView.setBackgroundResource(R.drawable.border_highlight); 27 | borderView.attachTo((ViewGroup) mView); 28 | 29 | return mView; 30 | } 31 | }; -------------------------------------------------------------------------------- /app/src/main/res/layout/viewpage_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /app/src/main/res/layout/demo_grid_view.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 14 | 27 | 28 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_menu_sub.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /lib/src/main/java/org/evilbinary/tv/widget/TvGridView.java: -------------------------------------------------------------------------------- 1 | package org.evilbinary.tv.widget; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | import android.widget.GridView; 6 | 7 | /** 8 | * 作者:evilbinary on 4/2/16. 9 | * 邮箱:rootdebug@163.com 10 | */ 11 | public class TvGridView extends GridView { 12 | private int position=0; 13 | 14 | public TvGridView(Context context, AttributeSet attrs) { 15 | super(context, attrs); 16 | setChildrenDrawingOrderEnabled(true); 17 | } 18 | 19 | @Override 20 | protected void setChildrenDrawingOrderEnabled(boolean enabled) { 21 | super.setChildrenDrawingOrderEnabled(enabled); 22 | } 23 | @Override 24 | protected int getChildDrawingOrder(int childCount, int i) { 25 | position = getSelectedItemPosition() - getFirstVisiblePosition(); 26 | if(position<0){ 27 | return i; 28 | }else{ 29 | if(i == childCount - 1){ 30 | if(position>i){ 31 | position=i; 32 | } 33 | return position; 34 | } 35 | if(i == position){ 36 | return childCount - 1; 37 | } 38 | } 39 | return i; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /lib/src/main/java/org/evilbinary/tv/widget/TvZorderLinearLayout.java: -------------------------------------------------------------------------------- 1 | package org.evilbinary.tv.widget; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | import android.view.View; 6 | import android.widget.LinearLayout; 7 | 8 | /** 9 | * 作者:evilbinary on 2/2/16. 10 | * 邮箱:rootdebug@163.com 11 | */ 12 | public class TvZorderLinearLayout extends LinearLayout { 13 | private int position = 0; 14 | 15 | public TvZorderLinearLayout(Context context) { 16 | super(context); 17 | 18 | } 19 | 20 | public TvZorderLinearLayout(Context context, AttributeSet attrs) { 21 | super(context, attrs); 22 | this.setChildrenDrawingOrderEnabled(true); 23 | } 24 | 25 | 26 | public void setCurrentPosition(int pos) { 27 | this.position = pos; 28 | } 29 | 30 | @Override 31 | protected int getChildDrawingOrder(int childCount, int i) { 32 | View v = getFocusedChild(); 33 | int pos = indexOfChild(v); 34 | if (pos >= 0 && pos < childCount) 35 | setCurrentPosition(pos); 36 | if (i == childCount - 1) {//这是最后一个需要刷新的item 37 | return position; 38 | } 39 | if (i == position) {//这是原本要在最后一个刷新的item 40 | return childCount - 1; 41 | } 42 | return i;//正常次序的item 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /app/src/main/res/layout/demo_menu.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 22 | 23 | 24 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /app/src/main/res/layout/demo_fragment_grid_view.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 23 | 24 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /app/src/main/res/layout/demo_list_view.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 26 | 27 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /lib/src/main/java/org/evilbinary/tv/widget/RoundedFrameLayout.java: -------------------------------------------------------------------------------- 1 | package org.evilbinary.tv.widget; 2 | 3 | import android.content.Context; 4 | import android.graphics.Canvas; 5 | import android.util.AttributeSet; 6 | import android.widget.FrameLayout; 7 | 8 | /** 9 | * 作者:evilbinary on 3/20/16. 10 | * 邮箱:rootdebug@163.com 11 | */ 12 | 13 | 14 | public class RoundedFrameLayout extends FrameLayout implements RoundImpl.RoundedView { 15 | 16 | 17 | RoundImpl round; 18 | 19 | public RoundedFrameLayout(Context context) { 20 | super(context); 21 | init(context, null, 0); 22 | } 23 | 24 | public RoundedFrameLayout(Context context, AttributeSet attrs) { 25 | super(context, attrs); 26 | init(context, attrs, 0); 27 | } 28 | 29 | public RoundedFrameLayout(Context context, AttributeSet attrs, int defStyle) { 30 | super(context, attrs, defStyle); 31 | init(context, attrs, defStyle); 32 | } 33 | 34 | private void init(Context context, AttributeSet attrs, int defStyle) { 35 | round = new RoundImpl(this, context, attrs, defStyle); 36 | setWillNotDraw(false); 37 | 38 | } 39 | 40 | @Override 41 | public void draw(Canvas canvas) { 42 | round.draw(canvas); 43 | } 44 | 45 | 46 | @Override 47 | public void drawSuper(Canvas canvas) { 48 | super.draw(canvas); 49 | } 50 | 51 | @Override 52 | public RoundImpl getRoundImpl() { 53 | return round; 54 | } 55 | } 56 | 57 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_list.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 20 | 21 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /app/src/main/res/layout/demo_two_recycler_view.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 20 | 21 | 22 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /lib/src/main/java/org/evilbinary/tv/widget/AutoGridLayoutManager.java: -------------------------------------------------------------------------------- 1 | package org.evilbinary.tv.widget; 2 | 3 | import android.content.Context; 4 | import android.support.v7.widget.GridLayoutManager; 5 | import android.support.v7.widget.RecyclerView; 6 | import android.view.View; 7 | 8 | /** 9 | * 作者:evilbinary on 2/23/16. 10 | * 邮箱:rootdebug@163.com 11 | */ 12 | public class AutoGridLayoutManager extends GridLayoutManager { 13 | 14 | 15 | private int measuredWidth = 0; 16 | private int measuredHeight = 0; 17 | 18 | 19 | 20 | public AutoGridLayoutManager(Context context, int spanCount) { 21 | super(context, spanCount); 22 | } 23 | 24 | public AutoGridLayoutManager(Context context, int spanCount, 25 | int orientation, boolean reverseLayout) { 26 | super(context, spanCount, orientation, reverseLayout); 27 | } 28 | 29 | @Override 30 | public void onMeasure(RecyclerView.Recycler recycler, 31 | RecyclerView.State state, int widthSpec, int heightSpec) { 32 | if (measuredHeight <= 0) { 33 | View view = recycler.getViewForPosition(0); 34 | if (view != null) { 35 | measureChild(view, widthSpec, heightSpec); 36 | measuredWidth = View.MeasureSpec.getSize(widthSpec); 37 | measuredHeight = view.getMeasuredHeight() * getSpanCount(); 38 | } 39 | } 40 | setMeasuredDimension(measuredWidth, measuredHeight); 41 | } 42 | 43 | } -------------------------------------------------------------------------------- /app/src/main/res/layout/item_menu.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 22 | 23 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item3.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 21 | 22 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /app/src/main/java/org/evilbinary/tv/MyGridViewAdapter.java: -------------------------------------------------------------------------------- 1 | package org.evilbinary.tv; 2 | 3 | import android.view.LayoutInflater; 4 | import android.view.View; 5 | import android.view.ViewGroup; 6 | import android.widget.BaseAdapter; 7 | import android.widget.TextView; 8 | 9 | /** 10 | * 作者:evilbinary on 2/28/16. 11 | * 邮箱:rootdebug@163.com 12 | */ 13 | public class MyGridViewAdapter extends BaseAdapter { 14 | 15 | private int layoutId; 16 | public MyGridViewAdapter(int resId) { 17 | layoutId=resId; 18 | } 19 | 20 | @Override 21 | public int getCount() { 22 | return 200; 23 | } 24 | 25 | @Override 26 | public Object getItem(int position) { 27 | return null; 28 | } 29 | 30 | @Override 31 | public long getItemId(int position) { 32 | return 0; 33 | } 34 | 35 | @Override 36 | public View getView(int position, View convertView, ViewGroup parent) { 37 | 38 | 39 | ViewHolder viewHolder; 40 | if (convertView == null) { 41 | convertView = LayoutInflater.from(parent.getContext() ).inflate(layoutId, parent, false); 42 | viewHolder = new ViewHolder(); 43 | viewHolder.text = (TextView) convertView.findViewById(R.id.textView); 44 | convertView.setTag(viewHolder); 45 | } else { 46 | viewHolder = (ViewHolder) convertView.getTag(); 47 | } 48 | 49 | viewHolder.text.setText("text" + position); 50 | return convertView; 51 | } 52 | 53 | private class ViewHolder { 54 | public TextView text; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /lib/src/main/java/org/evilbinary/tv/widget/TvZorderRelativeLayout.java: -------------------------------------------------------------------------------- 1 | package org.evilbinary.tv.widget; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | import android.view.KeyEvent; 6 | import android.view.View; 7 | import android.widget.RelativeLayout; 8 | 9 | /** 10 | * 作者:evilbinary on 2/2/16. 11 | * 邮箱:rootdebug@163.com 12 | */ 13 | public class TvZorderRelativeLayout extends RelativeLayout { 14 | private int position = 0; 15 | 16 | public TvZorderRelativeLayout(Context context) { 17 | super(context); 18 | 19 | } 20 | 21 | public TvZorderRelativeLayout(Context context, AttributeSet attrs) { 22 | super(context, attrs); 23 | this.setChildrenDrawingOrderEnabled(true); 24 | } 25 | 26 | 27 | public void setCurrentPosition(int pos) { 28 | this.position = pos; 29 | } 30 | 31 | @Override 32 | public boolean dispatchKeyEvent(KeyEvent event) { 33 | View focused = findFocus(); 34 | int pos = indexOfChild(focused); 35 | if (pos >= 0 && pos < getChildCount()) { 36 | setCurrentPosition(pos); 37 | postInvalidate(); 38 | } 39 | 40 | return super.dispatchKeyEvent(event); 41 | } 42 | 43 | @Override 44 | protected int getChildDrawingOrder(int childCount, int i) { 45 | View v = getFocusedChild(); 46 | int pos = indexOfChild(v); 47 | if (pos >= 0 && pos < childCount) 48 | setCurrentPosition(pos); 49 | 50 | if (i == childCount - 1) {//这是最后一个需要刷新的item 51 | return position; 52 | } 53 | if (i == position) {//这是原本要在最后一个刷新的item 54 | return childCount - 1; 55 | } 56 | return i;//正常次序的item 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /lib/src/main/java/org/evilbinary/tv/widget/TvLinearLayoutManager.java: -------------------------------------------------------------------------------- 1 | package org.evilbinary.tv.widget; 2 | 3 | import android.content.Context; 4 | import android.support.v7.widget.LinearLayoutManager; 5 | import android.support.v7.widget.RecyclerView; 6 | import android.util.Log; 7 | import android.view.View; 8 | 9 | /** 10 | * 作者:evilbinary on 1/31/16. 11 | * 邮箱:rootdebug@163.com 12 | */ 13 | 14 | public class TvLinearLayoutManager extends LinearLayoutManager { 15 | 16 | private static String TAG="TvLinearLayoutManager"; 17 | 18 | public class ViewHolder extends RecyclerView.ViewHolder { 19 | 20 | private View mCursor; 21 | 22 | public ViewHolder(View itemView) { 23 | super(itemView); 24 | mCursor = (View) itemView; 25 | 26 | } 27 | public View getCursor(){ 28 | return mCursor; 29 | } 30 | 31 | } 32 | ViewHolder mCursorViewHolder; 33 | 34 | public TvLinearLayoutManager(Context context) { 35 | super(context); 36 | 37 | //ImageView border= (ImageView) View.inflate(context, R.layout.layout_border, null); 38 | //mCursorViewHolder=new ViewHolder(border); 39 | //addDisappearingView(mCursorViewHolder.mCursor); 40 | } 41 | 42 | @Override 43 | public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) { 44 | super.onLayoutChildren(recycler, state); 45 | } 46 | 47 | @Override 48 | public boolean onRequestChildFocus(RecyclerView parent, RecyclerView.State state, View child, View focused) { 49 | Log.d(TAG, "onRequestChildFocus:"+parent.getChildCount()); 50 | //focused.setBackgroundColor(Color.BLUE); 51 | 52 | // View cursor=mCursorViewHolder.mCursor; 53 | // 54 | // 55 | 56 | return super.onRequestChildFocus(parent, state, child, focused); 57 | } 58 | 59 | 60 | } 61 | -------------------------------------------------------------------------------- /lib/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /lib/src/main/java/org/evilbinary/tv/util/AnimateFactory.java: -------------------------------------------------------------------------------- 1 | package org.evilbinary.tv.util; 2 | 3 | import android.view.View; 4 | import android.view.animation.Animation; 5 | import android.view.animation.CycleInterpolator; 6 | import android.view.animation.ScaleAnimation; 7 | import android.view.animation.TranslateAnimation; 8 | 9 | /** 10 | * 作者:evilbinary on 2015/12/10 17:09 11 | * 邮箱:rootdebug@163.com 12 | */ 13 | public class AnimateFactory { 14 | /** 15 | * 缩放动画,用于缩放控件 16 | * 17 | * @param startScale 控件的起始尺寸倍率 18 | * @param endScale 控件的终点尺寸倍率 19 | * @return 20 | */ 21 | public static Animation zoomAnimation(float startScale, float endScale, long duration) { 22 | ScaleAnimation anim = new ScaleAnimation(startScale, endScale, startScale, endScale, 23 | Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); 24 | anim.setFillAfter(true); 25 | anim.setDuration(duration); 26 | return anim; 27 | } 28 | 29 | public static Animation shakeAnimate() { 30 | TranslateAnimation mAnimate = new TranslateAnimation(0, 5, 0, 0); 31 | mAnimate.setInterpolator(new CycleInterpolator(50)); 32 | mAnimate.setDuration(600); 33 | return mAnimate; 34 | } 35 | 36 | public static void zoomInView(View v) { 37 | zoomInView(v, 1.1f); 38 | } 39 | 40 | public static void zoomOutView(View v) { 41 | zoomOutView(v, 1.1f); 42 | } 43 | 44 | public static void zoomInView(View v, float zoomSize) { 45 | zoomInView(v,zoomSize,200); 46 | } 47 | 48 | public static void zoomOutView(View v, float zoomSize) { 49 | zoomOutView(v,zoomSize,200); 50 | } 51 | public static void zoomInView(View v, float zoomSize,long duration) { 52 | if (v != null) { 53 | v.startAnimation(AnimateFactory.zoomAnimation(1.0f, zoomSize,duration)); 54 | } 55 | } 56 | 57 | public static void zoomOutView(View v, float zoomSize,long duration) { 58 | if (v != null) { 59 | v.startAnimation(AnimateFactory.zoomAnimation(zoomSize, 1.0f, duration)); 60 | } 61 | } 62 | 63 | 64 | public static final int ANIMATION_DEFAULT = 0; 65 | public static final int ANIMATION_TRANSLATE = 1; 66 | 67 | } 68 | -------------------------------------------------------------------------------- /app/src/main/java/org/evilbinary/tv/MyFragment.java: -------------------------------------------------------------------------------- 1 | package org.evilbinary.tv; 2 | 3 | import android.app.Fragment; 4 | import android.os.Bundle; 5 | import android.support.annotation.Nullable; 6 | import android.util.Log; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | import android.widget.AdapterView; 11 | import android.widget.GridView; 12 | 13 | import org.evilbinary.tv.widget.BorderView; 14 | 15 | /** 16 | * 作者:evilbinary on 2/28/16. 17 | * 邮箱:rootdebug@163.com 18 | */ 19 | public class MyFragment extends Fragment { 20 | private View mView; 21 | 22 | @Nullable 23 | @Override 24 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 25 | mView = inflater.inflate(R.layout.demo_fragment_grid_view, container, false); 26 | 27 | GridView gridView = (GridView) mView.findViewById(R.id.gridView); 28 | 29 | MyGridViewAdapter myAdapter = new MyGridViewAdapter(R.layout.item2); 30 | gridView.setAdapter(myAdapter); 31 | myAdapter.notifyDataSetChanged(); 32 | 33 | gridView.setSelection(0); 34 | gridView.setSelected(false); 35 | gridView.setFocusable(false); 36 | 37 | gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() { 38 | @Override 39 | public void onItemClick(AdapterView parent, View view, int position, long id) { 40 | Log.d("tt", "setOnItemClickListener"); 41 | MyFragment2 fragment2 = new MyFragment2(); 42 | getFragmentManager().beginTransaction().hide(MyFragment.this).replace(R.id.fragment, fragment2).addToBackStack(null).commit(); 43 | } 44 | }); 45 | //gridView.setFocusable(false); 46 | 47 | BorderView borderView = new BorderView(getActivity()); 48 | borderView.setBackgroundResource(R.drawable.border_white_light_10); 49 | //borderView.getEffect(BorderEffect.class).setMargin(12); 50 | borderView.attachTo((ViewGroup) mView); 51 | 52 | BorderView borderView2 = new BorderView(getActivity()); 53 | borderView2.setBackgroundResource(R.drawable.border_white_light_10); 54 | //borderView2.getEffect(BorderEffect.class).setMargin(12); 55 | borderView2.attachTo((ViewGroup) gridView); 56 | 57 | return mView; 58 | } 59 | }; -------------------------------------------------------------------------------- /app/src/main/java/org/evilbinary/tv/DemoGridViewActivity.java: -------------------------------------------------------------------------------- 1 | package org.evilbinary.tv; 2 | 3 | import android.app.Activity; 4 | import android.os.Bundle; 5 | import android.util.Log; 6 | import android.view.View; 7 | import android.widget.AdapterView; 8 | import android.widget.RelativeLayout; 9 | 10 | import org.evilbinary.tv.widget.BorderEffect; 11 | import org.evilbinary.tv.widget.BorderView; 12 | import org.evilbinary.tv.widget.TvGridView; 13 | 14 | /** 15 | * 作者:evilbinary on 2/22/16. 16 | * 邮箱:rootdebug@163.com 17 | */ 18 | public class DemoGridViewActivity extends Activity { 19 | 20 | 21 | private TvGridView mGridView; 22 | 23 | @Override 24 | protected void onCreate(Bundle savedInstanceState) { 25 | super.onCreate(savedInstanceState); 26 | setContentView(R.layout.demo_grid_view); 27 | 28 | mGridView = (TvGridView) findViewById(R.id.gridView); 29 | 30 | MyGridViewAdapter myAdapter = new MyGridViewAdapter(R.layout.item_grid); 31 | mGridView.setAdapter(myAdapter); 32 | 33 | BorderView borderView = new BorderView(this, R.layout.custom_item); 34 | 35 | 36 | mGridView.setOnFocusChangeListener(new View.OnFocusChangeListener() { 37 | @Override 38 | public void onFocusChange(View v, boolean hasFocus) { 39 | Log.d("tt", "onFocusChange"); 40 | } 41 | }); 42 | 43 | mGridView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { 44 | @Override 45 | public void onItemSelected(AdapterView parent, View view, int position, long id) { 46 | Log.d("tt", "onItemSelected"); 47 | } 48 | 49 | @Override 50 | public void onNothingSelected(AdapterView parent) { 51 | Log.d("tt", "onNothingSelected"); 52 | 53 | } 54 | }); 55 | 56 | borderView.attachTo(mGridView); 57 | borderView.getEffect().setMargin(10); 58 | borderView.getEffect().addOnFocusChanged(new BorderEffect.FocusListener() { 59 | @Override 60 | public void onFocusChanged(View oldFocus, View newFocus) { 61 | Log.d("tt", "onFocusChanged=====>" + oldFocus + " " + newFocus); 62 | } 63 | }); 64 | 65 | // mGridView.setSelection(0); 66 | // mGridView.requestFocus(); 67 | } 68 | 69 | 70 | } 71 | -------------------------------------------------------------------------------- /app/src/main/res/layout/demo_tab_view.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 16 | 17 | 27 | 28 | 38 | 39 | 48 | 49 | 58 | 59 | 60 | 61 | 68 | -------------------------------------------------------------------------------- /app/src/main/java/org/evilbinary/tv/MainActivity.java: -------------------------------------------------------------------------------- 1 | package org.evilbinary.tv; 2 | 3 | import android.app.Activity; 4 | import android.content.Intent; 5 | import android.os.Bundle; 6 | import android.view.View; 7 | import android.widget.RelativeLayout; 8 | 9 | import org.evilbinary.tv.widget.BorderView; 10 | 11 | public class MainActivity extends Activity implements View.OnClickListener { 12 | 13 | private RelativeLayout main; 14 | private BorderView border; 15 | 16 | @Override 17 | protected void onCreate(Bundle savedInstanceState) { 18 | super.onCreate(savedInstanceState); 19 | setContentView(R.layout.activity_main); 20 | 21 | 22 | BorderView border = new BorderView(this); 23 | border.setBackgroundResource(R.drawable.border_highlight); 24 | 25 | main = (RelativeLayout) findViewById(R.id.main); 26 | border.attachTo(main); 27 | 28 | for (int i = 0; i < main.getChildCount(); i++) { 29 | main.getChildAt(i).setOnClickListener(this); 30 | } 31 | 32 | 33 | } 34 | 35 | @Override 36 | public void onClick(View v) { 37 | Intent intent = new Intent(); 38 | if (v == main.getChildAt(0)) { 39 | intent.setClass(this, DemoRecyclerViewActivity.class); 40 | intent.putExtra("linerLayout", ""); 41 | startActivity(intent); 42 | } else if (v == main.getChildAt(1)) { 43 | intent.setClass(this, DemoRecyclerViewActivity.class); 44 | intent.putExtra("gridLayout", ""); 45 | startActivity(intent); 46 | }else if (v == main.getChildAt(2)) { 47 | intent.setClass(this, DemoGridViewActivity.class); 48 | startActivity(intent); 49 | } 50 | else if (v == main.getChildAt(3)) { 51 | intent.setClass(this, DemoListViewActivity.class); 52 | startActivity(intent); 53 | }else if (v == main.getChildAt(4)) { 54 | intent.setClass(this, DemoHomeActivity.class); 55 | startActivity(intent); 56 | }else if (v == main.getChildAt(5)) { 57 | intent.setClass(this, DemoTwoRecyclerViewActivity.class); 58 | startActivity(intent); 59 | } 60 | else if (v == main.getChildAt(6)) { 61 | intent.setClass(this, DemoFragmentActivity.class); 62 | startActivity(intent); 63 | }else if (v == main.getChildAt(7)) { 64 | intent.setClass(this, DemoTopBorderActivity.class); 65 | startActivity(intent); 66 | } 67 | 68 | } 69 | 70 | 71 | } 72 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /app/src/main/java/org/evilbinary/tv/DemoTwoRecyclerViewActivity.java: -------------------------------------------------------------------------------- 1 | package org.evilbinary.tv; 2 | 3 | import android.app.Activity; 4 | import android.os.Bundle; 5 | import android.support.v7.widget.GridLayoutManager; 6 | import android.support.v7.widget.LinearLayoutManager; 7 | import android.support.v7.widget.RecyclerView; 8 | 9 | import org.evilbinary.tv.widget.BorderView; 10 | import org.evilbinary.tv.widget.TvGridLayoutManagerScrolling; 11 | 12 | /** 13 | * 作者:evilbinary on 2/20/16. 14 | * 邮箱:rootdebug@163.com 15 | */ 16 | public class DemoTwoRecyclerViewActivity extends Activity { 17 | 18 | private BorderView border; 19 | @Override 20 | protected void onCreate(Bundle savedInstanceState) { 21 | super.onCreate(savedInstanceState); 22 | setContentView(R.layout.demo_two_recycler_view); 23 | 24 | border = new BorderView(this); 25 | border.setBackgroundResource(R.drawable.border_red); 26 | testRecyclerViewLinerLayout(); 27 | testRecyclerViewGridLayout(); 28 | 29 | 30 | } 31 | 32 | 33 | private void testRecyclerViewLinerLayout() { 34 | //test linearlayout 35 | RecyclerView recyclerView = (RecyclerView) findViewById(R.id.firstRecyclerView); 36 | // 创建一个线性布局管理器 37 | 38 | GridLayoutManager layoutManager = new GridLayoutManager(this,1); 39 | layoutManager.setOrientation(LinearLayoutManager.VERTICAL); 40 | recyclerView.setLayoutManager(layoutManager); 41 | recyclerView.setFocusable(false); 42 | border.attachTo(recyclerView); 43 | 44 | createData(recyclerView, R.layout.item3); 45 | 46 | } 47 | 48 | private void testRecyclerViewGridLayout() { 49 | //test grid 50 | RecyclerView recyclerView = (RecyclerView) findViewById(R.id.secondRecyclerView); 51 | GridLayoutManager gridlayoutManager = new TvGridLayoutManagerScrolling(this, 4); 52 | gridlayoutManager.setOrientation(GridLayoutManager.VERTICAL); 53 | recyclerView.setLayoutManager(gridlayoutManager); 54 | recyclerView.setFocusable(false); 55 | 56 | 57 | border.attachTo(recyclerView); 58 | 59 | createData(recyclerView,R.layout.item); 60 | 61 | } 62 | 63 | 64 | private void createData(RecyclerView recyclerView,int id) { 65 | //创建数据集 66 | String[] dataset = new String[100]; 67 | for (int i = 0; i < dataset.length; i++) { 68 | dataset[i] = "item" + i; 69 | } 70 | // 创建Adapter,并指定数据集 71 | MyAdapter adapter = new MyAdapter(this, dataset,id); 72 | // 设置Adapter 73 | recyclerView.setAdapter(adapter); 74 | recyclerView.scrollToPosition(0); 75 | } 76 | 77 | 78 | } 79 | -------------------------------------------------------------------------------- /app/src/main/java/org/evilbinary/tv/DemoListViewActivity.java: -------------------------------------------------------------------------------- 1 | package org.evilbinary.tv; 2 | 3 | import android.app.Activity; 4 | import android.os.Bundle; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | import android.widget.BaseAdapter; 9 | import android.widget.ListView; 10 | import android.widget.TextView; 11 | 12 | import org.evilbinary.tv.widget.BorderView; 13 | 14 | import java.util.List; 15 | import java.util.Map; 16 | 17 | /** 18 | * 作者:evilbinary on 2/22/16. 19 | * 邮箱:rootdebug@163.com 20 | */ 21 | public class DemoListViewActivity extends Activity { 22 | private List> data; 23 | 24 | @Override 25 | protected void onCreate(Bundle savedInstanceState) { 26 | super.onCreate(savedInstanceState); 27 | setContentView(R.layout.demo_list_view); 28 | 29 | ListView listView = (ListView) findViewById(R.id.listView); 30 | 31 | MyAdapter myAdapter=new MyAdapter(); 32 | listView.setAdapter(myAdapter); 33 | myAdapter.notifyDataSetChanged(); 34 | 35 | listView.setSelected(true); 36 | listView.setSelection(0); 37 | 38 | BorderView borderView = new BorderView(this); 39 | 40 | borderView.setBackgroundResource(R.drawable.border_red); 41 | //borderView.getEffect(BorderEffect.class).setMargin(12); 42 | borderView.attachTo(listView); 43 | 44 | } 45 | 46 | 47 | private class MyAdapter extends BaseAdapter { 48 | 49 | @Override 50 | public int getCount() { 51 | return 200; 52 | } 53 | 54 | @Override 55 | public Object getItem(int position) { 56 | return null; 57 | } 58 | 59 | @Override 60 | public long getItemId(int position) { 61 | return 0; 62 | } 63 | 64 | @Override 65 | public View getView(int position, View convertView, ViewGroup parent) { 66 | 67 | 68 | ViewHolder viewHolder; 69 | if (convertView == null) { 70 | convertView = LayoutInflater.from(DemoListViewActivity.this).inflate(R.layout.item3, parent, false); 71 | viewHolder = new ViewHolder(); 72 | viewHolder.text = (TextView) convertView.findViewById(R.id.textView); 73 | convertView.setTag(viewHolder); 74 | } else { 75 | viewHolder = (ViewHolder) convertView.getTag(); 76 | } 77 | //if (position == 0) 78 | // convertView.requestFocus(); 79 | 80 | viewHolder.text.setText("我是item" + position); 81 | return convertView; 82 | } 83 | 84 | private class ViewHolder { 85 | public TextView text; 86 | } 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /app/src/main/java/org/evilbinary/tv/DemoRecyclerViewActivity.java: -------------------------------------------------------------------------------- 1 | package org.evilbinary.tv; 2 | 3 | import android.app.Activity; 4 | import android.os.Bundle; 5 | import android.support.v7.widget.GridLayoutManager; 6 | import android.support.v7.widget.LinearLayoutManager; 7 | import android.support.v7.widget.RecyclerView; 8 | 9 | import org.evilbinary.tv.widget.BorderView; 10 | import org.evilbinary.tv.widget.TvGridLayoutManagerScrolling; 11 | 12 | /** 13 | * 作者:evilbinary on 2/20/16. 14 | * 邮箱:rootdebug@163.com 15 | */ 16 | public class DemoRecyclerViewActivity extends Activity { 17 | 18 | private BorderView border; 19 | 20 | @Override 21 | protected void onCreate(Bundle savedInstanceState) { 22 | super.onCreate(savedInstanceState); 23 | setContentView(R.layout.demo_recycler_view); 24 | 25 | border = new BorderView(this); 26 | border.setBackgroundResource(R.drawable.border_highlight); 27 | 28 | Bundle bundle = getIntent().getExtras(); 29 | if (bundle == null || bundle.containsKey("linerLayout")) { 30 | testRecyclerViewLinerLayout(); 31 | } else { 32 | testRecyclerViewGridLayout(); 33 | } 34 | 35 | } 36 | 37 | 38 | private void testRecyclerViewLinerLayout() { 39 | //test linearlayout 40 | RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerView); 41 | // 创建一个线性布局管理器 42 | LinearLayoutManager layoutManager = new LinearLayoutManager(this); 43 | layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL); 44 | recyclerView.setLayoutManager(layoutManager); 45 | recyclerView.setFocusable(false); 46 | border.attachTo(recyclerView); 47 | createData(recyclerView); 48 | 49 | } 50 | 51 | private void testRecyclerViewGridLayout() { 52 | //test grid 53 | RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerView); 54 | GridLayoutManager gridlayoutManager = new TvGridLayoutManagerScrolling(this, 4); 55 | gridlayoutManager.setOrientation(GridLayoutManager.HORIZONTAL); 56 | recyclerView.setLayoutManager(gridlayoutManager); 57 | recyclerView.setFocusable(false); 58 | 59 | border.attachTo(recyclerView); 60 | createData(recyclerView); 61 | 62 | } 63 | 64 | 65 | private void createData(RecyclerView recyclerView) { 66 | //创建数据集 67 | String[] dataset = new String[100]; 68 | for (int i = 0; i < dataset.length; i++) { 69 | dataset[i] = "item" + i; 70 | } 71 | // 创建Adapter,并指定数据集 72 | MyAdapter adapter = new MyAdapter(this, dataset); 73 | // 设置Adapter 74 | recyclerView.setAdapter(adapter); 75 | recyclerView.scrollToPosition(0); 76 | } 77 | 78 | 79 | } 80 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TvWidget 2 | 3 | TV常用效果控件,包括焦点、边框处理等。qq群:537960195 4 | 5 | 6 | # 截图 7 | 8 | 界面 9 | 10 | 界面 11 | 12 | 界面 13 | 14 | # 使用 15 | ```java 16 | //基本用法 17 | BorderView border=new BorderView(this); 18 | border.setBackgroundResource(R.drawable.item_highlight); 19 | RelativeLayout main= (RelativeLayout) findViewById(R.id.main); 20 | border.attachTo(main); 21 | 22 | //自定义布局 23 | BorderView borderView = new BorderView(this,R.layout.custom_item); 24 | 25 | //设置放大倍数1.2 26 | borderView.getEffect().setScale(1.2); 27 | ``` 28 | ```xml 29 | //圆角布局 app:radius 为圆角大小 30 | 38 | 44 | 54 | 55 | ``` 56 | 57 | # 项目捐赠 58 | 59 | ![喜欢就支持一下](https://github.com/evilbinary/myblog/raw/master/data/s.png) 60 | # Developed By 61 | 62 | 63 | * evilbinary 64 | * 个人博客 [http://evilbinary.org](http://evilbinary.org) 65 | 66 | #项目主页 67 | * [https://github.com/evilbinary/TvWidget](https://github.com/evilbinary/TvWidget) 68 | 69 | # License 70 | 71 | Copyright 2016 evilbinary 72 | 73 | Licensed under the Apache License, Version 2.0 (the "License"); 74 | you may not use this file except in compliance with the License. 75 | You may obtain a copy of the License at 76 | 77 | http://www.apache.org/licenses/LICENSE-2.0 78 | 79 | Unless required by applicable law or agreed to in writing, software 80 | distributed under the License is distributed on an "AS IS" BASIS, 81 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 82 | See the License for the specific language governing permissions and 83 | limitations under the License. 84 | -------------------------------------------------------------------------------- /app/src/main/java/org/evilbinary/tv/MyAdapter.java: -------------------------------------------------------------------------------- 1 | package org.evilbinary.tv; 2 | 3 | import android.content.Context; 4 | import android.support.v7.widget.RecyclerView; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | import android.widget.TextView; 9 | 10 | /** 11 | * 作者:evilbinary on 2/20/16. 12 | * 邮箱:rootdebug@163.com 13 | */ 14 | public class MyAdapter extends RecyclerView.Adapter { 15 | 16 | // 数据集 17 | private String[] mDataset; 18 | private Context mContex; 19 | private int id; 20 | private View.OnFocusChangeListener mOnFocusChangeListener; 21 | private OnBindListener onBindListener; 22 | public interface OnBindListener{ 23 | public void onBind(View view,int i); 24 | }; 25 | 26 | public MyAdapter(Context context, String[] dataset) { 27 | super(); 28 | mContex = context; 29 | mDataset = dataset; 30 | } 31 | public MyAdapter(Context context, String[] dataset,int id) { 32 | super(); 33 | mContex = context; 34 | mDataset = dataset; 35 | this.id=id; 36 | } 37 | 38 | public MyAdapter(Context context, String[] dataset,int id,View.OnFocusChangeListener onFocusChangeListener) { 39 | super(); 40 | mContex = context; 41 | mDataset = dataset; 42 | this.id=id; 43 | this.mOnFocusChangeListener=onFocusChangeListener; 44 | } 45 | 46 | public void setOnBindListener(OnBindListener onBindListener) { 47 | this.onBindListener = onBindListener; 48 | } 49 | 50 | @Override 51 | public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { 52 | int resId=R.layout.item; 53 | if(this.id>0){ 54 | resId=this.id; 55 | } 56 | View view = LayoutInflater.from(mContex).inflate(resId, viewGroup, false); 57 | ViewHolder holder = new ViewHolder(view); 58 | 59 | return holder; 60 | } 61 | 62 | @Override 63 | public void onBindViewHolder(ViewHolder viewHolder, int i) { 64 | viewHolder.mTextView.setText(mDataset[i]); 65 | viewHolder.itemView.setTag(i); 66 | viewHolder.itemView.setOnFocusChangeListener(mOnFocusChangeListener); 67 | if(onBindListener!=null){ 68 | onBindListener.onBind(viewHolder.itemView,i); 69 | } 70 | } 71 | 72 | @Override 73 | public int getItemCount() { 74 | return mDataset.length; 75 | } 76 | 77 | public class ViewHolder extends RecyclerView.ViewHolder { 78 | 79 | public TextView mTextView; 80 | 81 | public ViewHolder(View itemView) { 82 | super(itemView); 83 | mTextView = (TextView) itemView.findViewById(R.id.textView); 84 | 85 | } 86 | } 87 | 88 | public void setData(String[] data){ 89 | this.mDataset=data; 90 | } 91 | 92 | } 93 | -------------------------------------------------------------------------------- /app/src/main/java/org/evilbinary/tv/DemoTopBorderActivity.java: -------------------------------------------------------------------------------- 1 | package org.evilbinary.tv; 2 | 3 | import android.animation.Animator; 4 | import android.app.Activity; 5 | import android.os.Bundle; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | import android.widget.FrameLayout; 9 | 10 | import org.evilbinary.tv.widget.BorderEffect; 11 | import org.evilbinary.tv.widget.BorderView; 12 | 13 | /** 14 | * 作者:evilbinary on 4/1/16. 15 | * 邮箱:rootdebug@163.com 16 | */ 17 | public class DemoTopBorderActivity extends Activity { 18 | 19 | private String TAG = DemoTopBorderActivity.class.getSimpleName(); 20 | 21 | 22 | @Override 23 | protected void onCreate(Bundle savedInstanceState) { 24 | super.onCreate(savedInstanceState); 25 | 26 | setContentView(R.layout.activity_home); 27 | 28 | FrameLayout roundedFrameLayout = new FrameLayout(this); 29 | roundedFrameLayout.setClipChildren(false); 30 | 31 | final BorderView borderView = new BorderView(roundedFrameLayout); 32 | borderView.setBackgroundResource(R.drawable.border_red); 33 | 34 | ViewGroup list = (ViewGroup) findViewById(R.id.list); 35 | borderView.attachTo(list); 36 | 37 | 38 | borderView.getEffect().addOnFocusChanged(new BorderEffect.FocusListener() { 39 | @Override 40 | public void onFocusChanged(View oldFocus, final View newFocus) { 41 | borderView.getView().setTag(newFocus); 42 | 43 | } 44 | }); 45 | borderView.getEffect().addAnimatorListener(new Animator.AnimatorListener() { 46 | @Override 47 | public void onAnimationStart(Animator animation) { 48 | View t = borderView.getView().findViewWithTag("top"); 49 | if (t != null) { 50 | ((ViewGroup) t.getParent()).removeView(t); 51 | View of = (View) borderView.getView().getTag(borderView.getView().getId()); 52 | ((ViewGroup) of).addView(t); 53 | 54 | } 55 | 56 | } 57 | 58 | @Override 59 | public void onAnimationEnd(Animator animation) { 60 | View nf = (View) borderView.getView().getTag(); 61 | if (nf != null) { 62 | View top = nf.findViewWithTag("top"); 63 | if (top != null) { 64 | ((ViewGroup) top.getParent()).removeView(top); 65 | ((ViewGroup) borderView.getView()).addView(top); 66 | borderView.getView().setTag(borderView.getView().getId(), nf); 67 | 68 | } 69 | } 70 | } 71 | 72 | @Override 73 | public void onAnimationCancel(Animator animation) { 74 | 75 | } 76 | 77 | @Override 78 | public void onAnimationRepeat(Animator animation) { 79 | 80 | } 81 | }); 82 | 83 | 84 | } 85 | 86 | 87 | } 88 | -------------------------------------------------------------------------------- /lib/src/main/java/org/evilbinary/tv/widget/TvHorizontalScrollView.java: -------------------------------------------------------------------------------- 1 | package org.evilbinary.tv.widget; 2 | 3 | /** 4 | * 作者:evilbinary on 3/19/16. 5 | * 邮箱:rootdebug@163.com 6 | */ 7 | 8 | import android.content.Context; 9 | import android.content.res.TypedArray; 10 | import android.graphics.Rect; 11 | import android.util.AttributeSet; 12 | import android.widget.HorizontalScrollView; 13 | 14 | import evilbinary.org.lib.R; 15 | 16 | 17 | public class TvHorizontalScrollView extends HorizontalScrollView { 18 | final String TAG = "SmoothHorizontalScrollView"; 19 | 20 | int fadingEdge ; 21 | 22 | public TvHorizontalScrollView(Context context) { 23 | this(context, null, 0); 24 | } 25 | 26 | public TvHorizontalScrollView(Context context, AttributeSet attrs) { 27 | this(context, attrs, 0); 28 | 29 | } 30 | 31 | public TvHorizontalScrollView(Context context, AttributeSet attrs, 32 | int defStyle) { 33 | super(context, attrs, defStyle); 34 | 35 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TvHorizontalScrollView); 36 | fadingEdge = a.getInt(R.styleable.TvHorizontalScrollView_fadingEdge,100); 37 | 38 | a.recycle(); 39 | } 40 | 41 | 42 | @Override 43 | protected int computeScrollDeltaToGetChildRectOnScreen(Rect rect) { 44 | if (getChildCount() == 0) 45 | return 0; 46 | 47 | int width = getWidth(); 48 | int screenLeft = getScrollX(); 49 | int screenRight = screenLeft + width; 50 | 51 | // leave room for left fading edge as long as rect isn't at very left 52 | if (rect.left > 0) { 53 | screenLeft += fadingEdge; 54 | } 55 | 56 | // leave room for right fading edge as long as rect isn't at very right 57 | if (rect.right < getChildAt(0).getWidth()) { 58 | screenRight -= fadingEdge; 59 | } 60 | 61 | int scrollXDelta = 0; 62 | 63 | if (rect.right > screenRight && rect.left > screenLeft) { 64 | // need to move right to get it in view: move right just enough so 65 | // that the entire rectangle is in view (or at least the first 66 | // screen size chunk). 67 | 68 | if (rect.width() > width) { 69 | // just enough to get screen size chunk on 70 | scrollXDelta += (rect.left - screenLeft); 71 | } else { 72 | // get entire rect at right of screen 73 | scrollXDelta += (rect.right - screenRight); 74 | } 75 | 76 | // make sure we aren't scrolling beyond the end of our content 77 | int right = getChildAt(0).getRight(); 78 | int distanceToRight = right - screenRight; 79 | scrollXDelta = Math.min(scrollXDelta, distanceToRight); 80 | 81 | } else if (rect.left < screenLeft && rect.right < screenRight) { 82 | // need to move right to get it in view: move right just enough so 83 | // that 84 | // entire rectangle is in view (or at least the first screen 85 | // size chunk of it). 86 | 87 | if (rect.width() > width) { 88 | // screen size chunk 89 | scrollXDelta -= (screenRight - rect.right); 90 | } else { 91 | // entire rect at left 92 | scrollXDelta -= (screenLeft - rect.left); 93 | } 94 | 95 | // make sure we aren't scrolling any further than the left our 96 | // content 97 | scrollXDelta = Math.max(scrollXDelta, -getScrollX()); 98 | } 99 | return scrollXDelta; 100 | } 101 | 102 | 103 | } -------------------------------------------------------------------------------- /lib/src/main/java/org/evilbinary/tv/widget/TvGridLayoutManagerScrolling.java: -------------------------------------------------------------------------------- 1 | package org.evilbinary.tv.widget; 2 | 3 | import android.content.Context; 4 | import android.support.v7.widget.GridLayoutManager; 5 | import android.support.v7.widget.RecyclerView; 6 | import android.util.AttributeSet; 7 | import android.view.View; 8 | 9 | /** 10 | * 作者:evilbinary on 3/27/16. 11 | * 邮箱:rootdebug@163.com 12 | */ 13 | public class TvGridLayoutManagerScrolling extends GridLayoutManager { 14 | 15 | public TvGridLayoutManagerScrolling(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 16 | super(context, attrs, defStyleAttr, defStyleRes); 17 | } 18 | 19 | public TvGridLayoutManagerScrolling(Context context, int spanCount) { 20 | super(context, spanCount); 21 | } 22 | 23 | public TvGridLayoutManagerScrolling(Context context, int spanCount, int orientation, boolean reverseLayout) { 24 | super(context, spanCount, orientation, reverseLayout); 25 | } 26 | 27 | @Override 28 | public View onFocusSearchFailed(View focused, int focusDirection, RecyclerView.Recycler recycler, 29 | RecyclerView.State state) { 30 | // Need to be called in order to layout new row/column 31 | View nextFocus = super.onFocusSearchFailed(focused, focusDirection, recycler, state); 32 | 33 | if (nextFocus == null) { 34 | return null; 35 | } 36 | 37 | int fromPos = getPosition(focused); 38 | int nextPos = getNextViewPos(fromPos, focusDirection); 39 | 40 | return findViewByPosition(nextPos); 41 | } 42 | 43 | /** 44 | * Manually detect next view to focus. 45 | * 46 | * @param fromPos from what position start to seek. 47 | * @param direction in what direction start to seek. Your regular 48 | * {@code View.FOCUS_*}. 49 | * @return adapter position of next view to focus. May be equal to 50 | * {@code fromPos}. 51 | */ 52 | protected int getNextViewPos(int fromPos, int direction) { 53 | int offset = calcOffsetToNextView(direction); 54 | 55 | if (hitBorder(fromPos, offset)) { 56 | //return fromPos; 57 | } 58 | return fromPos + offset; 59 | } 60 | 61 | /** 62 | * Calculates position offset. 63 | * 64 | * @param direction regular {@code View.FOCUS_*}. 65 | * @return position offset according to {@code direction}. 66 | */ 67 | protected int calcOffsetToNextView(int direction) { 68 | int spanCount = getSpanCount(); 69 | int orientation = getOrientation(); 70 | 71 | if (orientation == VERTICAL) { 72 | switch (direction) { 73 | case View.FOCUS_DOWN: 74 | return spanCount; 75 | case View.FOCUS_UP: 76 | return -spanCount; 77 | case View.FOCUS_RIGHT: 78 | return 1; 79 | case View.FOCUS_LEFT: 80 | return -1; 81 | } 82 | } else if (orientation == HORIZONTAL) { 83 | switch (direction) { 84 | case View.FOCUS_DOWN: 85 | return 1; 86 | case View.FOCUS_UP: 87 | return -1; 88 | case View.FOCUS_RIGHT: 89 | return spanCount; 90 | case View.FOCUS_LEFT: 91 | return -spanCount; 92 | } 93 | } 94 | 95 | return 0; 96 | } 97 | 98 | /** 99 | * Checks if we hit borders. 100 | * 101 | * @param from from what position. 102 | * @param offset offset to new position. 103 | * @return {@code true} if we hit border. 104 | */ 105 | private boolean hitBorder(int from, int offset) { 106 | int spanCount = getSpanCount(); 107 | 108 | if (Math.abs(offset) == 1) { 109 | int spanIndex = from % spanCount; 110 | int newSpanIndex = spanIndex + offset; 111 | return newSpanIndex < 0 || newSpanIndex >= spanCount; 112 | } else { 113 | int newPos = from + offset; 114 | return newPos < 0 || newPos >= spanCount; 115 | } 116 | } 117 | } -------------------------------------------------------------------------------- /lib/src/main/java/org/evilbinary/tv/widget/TvTextView.java: -------------------------------------------------------------------------------- 1 | package org.evilbinary.tv.widget; 2 | 3 | import android.content.Context; 4 | import android.content.res.TypedArray; 5 | import android.graphics.Canvas; 6 | import android.graphics.Color; 7 | import android.graphics.Paint; 8 | import android.graphics.Rect; 9 | import android.graphics.drawable.Drawable; 10 | import android.util.AttributeSet; 11 | import android.view.View; 12 | import android.view.animation.Animation; 13 | import android.widget.TextView; 14 | 15 | import org.evilbinary.tv.util.AnimateFactory; 16 | 17 | import evilbinary.org.lib.R; 18 | 19 | /** 20 | * 作者:evilbinary on 2015/12/10 17:09 21 | * 邮箱:rootdebug@163.com 22 | */ 23 | public class TvTextView extends TextView implements View.OnFocusChangeListener { 24 | 25 | 26 | private Rect mBound; 27 | private Drawable mBorderDrawable; 28 | private Rect mRect; 29 | 30 | private Animation scaleSmallAnimation; 31 | private Animation scaleBigAnimation; 32 | private int borderSize = 20; 33 | 34 | private boolean mScaleable = true; 35 | private int mKeyNumber; 36 | 37 | private Paint mPaint; 38 | 39 | public TvTextView(Context context) { 40 | super(context); 41 | init(); 42 | } 43 | 44 | public TvTextView(Context context, AttributeSet attrs) { 45 | super(context, attrs); 46 | init(); 47 | 48 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TvTextView); 49 | 50 | mScaleable = a.getBoolean(R.styleable.TvTextView_scaleable, true); 51 | mKeyNumber = a.getInteger(R.styleable.TvTextView_number, -1); 52 | int berderResId = a.getResourceId(R.styleable.TvTextView_borderDrawable, R.drawable.border_highlight); 53 | mBorderDrawable = getResources().getDrawable(berderResId); 54 | 55 | int numberColor = a.getColor(R.styleable.TvTextView_numberColor, Color.WHITE); 56 | 57 | mPaint = new Paint(); 58 | mPaint.setAntiAlias(true); 59 | mPaint.setTextSize(25); 60 | mPaint.setColor(numberColor); 61 | 62 | a.recycle(); 63 | 64 | 65 | } 66 | 67 | protected void init() { 68 | 69 | setFocusable(true); 70 | setClickable(true); 71 | setWillNotDraw(false); 72 | mRect = new Rect(); 73 | mBound = new Rect(); 74 | this.setOnFocusChangeListener(this); 75 | } 76 | 77 | @Override 78 | public void onFocusChange(View view, boolean b) { 79 | if (!mScaleable) 80 | return; 81 | if (b) { 82 | AnimateFactory.zoomInView(view); 83 | } else { 84 | AnimateFactory.zoomOutView(view); 85 | } 86 | } 87 | 88 | @Override 89 | public void draw(Canvas canvas) { 90 | 91 | if (hasFocus()) { 92 | super.getDrawingRect(mRect); 93 | mBound.set(-borderSize + mRect.left, -borderSize + mRect.top, borderSize + mRect.right, borderSize + mRect.bottom); 94 | mBorderDrawable.setBounds(mBound); 95 | canvas.save(); 96 | if (mBorderDrawable != null) 97 | mBorderDrawable.draw(canvas); 98 | canvas.restore(); 99 | } 100 | super.draw(canvas); 101 | } 102 | 103 | 104 | protected void drawCenterNumberText(Canvas canvas, String text, Paint textPaint) { 105 | int xPos = (canvas.getWidth() / 2); 106 | int yPos = (int) ((canvas.getHeight() / 2) - ((textPaint.descent() + textPaint.ascent()) / 2)); 107 | //((textPaint.descent() + textPaint.ascent()) / 2) is the distance from the baseline to the center. 108 | canvas.drawText(text, xPos, yPos, textPaint); 109 | } 110 | 111 | protected void drawBottomNumberText(Canvas canvas, String text, Paint textPaint) { 112 | float strWidth = textPaint.measureText(text); 113 | int xPos = (canvas.getWidth() / 2) - (int) strWidth / 2; 114 | int yPos = (int) ((canvas.getHeight()) + ((textPaint.descent() + textPaint.ascent()) / 2) / 2); 115 | canvas.drawText(text, xPos, yPos, textPaint); 116 | } 117 | 118 | @Override 119 | protected void onDraw(Canvas canvas) { 120 | 121 | if (mKeyNumber >= 0) { 122 | super.getDrawingRect(mRect); 123 | drawBottomNumberText(canvas, "" + mKeyNumber, mPaint); 124 | } 125 | 126 | super.onDraw(canvas); 127 | } 128 | 129 | 130 | } 131 | -------------------------------------------------------------------------------- /app/src/main/java/org/evilbinary/tv/DemoTabActivity.java: -------------------------------------------------------------------------------- 1 | package org.evilbinary.tv; 2 | 3 | import android.app.Activity; 4 | import android.os.Bundle; 5 | import android.support.v4.view.PagerAdapter; 6 | import android.support.v4.view.ViewPager; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | import android.widget.TabWidget; 11 | import android.widget.TextView; 12 | 13 | import org.evilbinary.tv.widget.BorderView; 14 | 15 | /** 16 | * 作者:evilbinary on 2/28/16. 17 | * 邮箱:rootdebug@163.com 18 | */ 19 | public class DemoTabActivity extends Activity { 20 | 21 | private static final String TAG = DemoTabActivity.class.getSimpleName(); 22 | private ViewPager mViewPager; 23 | private PagerAdapter mPagerAdapter; 24 | private TabWidget mTabWidget; 25 | 26 | @Override 27 | protected void onCreate(Bundle savedInstanceState) { 28 | super.onCreate(savedInstanceState); 29 | 30 | setContentView(R.layout.demo_tab_view); 31 | 32 | mTabWidget = ( TabWidget) findViewById(R.id.tabWidget1); 33 | 34 | mTabWidget.setStripEnabled(false); 35 | mTabWidget.setFocusable(false); 36 | 37 | for (int i = 0; i < mTabWidget.getChildCount(); i++) { 38 | mTabWidget.getChildAt(i).setOnClickListener(mTabClickListener); 39 | mTabWidget.getChildAt(i).setOnFocusChangeListener(mTabFocusListener); 40 | } 41 | 42 | mViewPager = (ViewPager) findViewById(R.id.viewPager1); 43 | mPagerAdapter = new MyPagerAdapter(); 44 | mViewPager.setAdapter(mPagerAdapter); 45 | mViewPager.setOnPageChangeListener(mPageChangeListener); 46 | 47 | mPagerAdapter.notifyDataSetChanged(); 48 | 49 | 50 | mTabWidget.focusCurrentTab(0); 51 | 52 | BorderView borderView = new BorderView(this); 53 | 54 | borderView.setBackgroundResource(R.drawable.border_highlight); 55 | borderView.attachTo(mTabWidget); 56 | 57 | BorderView borderView2 = new BorderView(this); 58 | 59 | borderView2.setBackgroundResource(R.drawable.border_white_light_10); 60 | borderView2.attachTo(mViewPager); 61 | 62 | } 63 | 64 | private View.OnFocusChangeListener mTabFocusListener=new View.OnFocusChangeListener(){ 65 | 66 | @Override 67 | public void onFocusChange(View v, boolean hasFocus) { 68 | if(hasFocus){ 69 | for (int i = 0; i < mTabWidget.getChildCount(); i++) { 70 | if (v == mTabWidget.getChildAt(i)) { 71 | mViewPager.setCurrentItem(i); 72 | } 73 | } 74 | } 75 | } 76 | }; 77 | private View.OnClickListener mTabClickListener = new View.OnClickListener() { 78 | @Override 79 | public void onClick(View v) { 80 | for (int i = 0; i < mTabWidget.getChildCount(); i++) { 81 | if (v == mTabWidget.getChildAt(i)) { 82 | mViewPager.setCurrentItem(i); 83 | } 84 | } 85 | 86 | 87 | } 88 | }; 89 | 90 | private ViewPager.OnPageChangeListener mPageChangeListener = new ViewPager.OnPageChangeListener() { 91 | 92 | @Override 93 | public void onPageSelected(int arg0) { 94 | mTabWidget.focusCurrentTab(arg0); 95 | } 96 | 97 | @Override 98 | public void onPageScrolled(int arg0, float arg1, int arg2) { 99 | 100 | } 101 | 102 | @Override 103 | public void onPageScrollStateChanged(int arg0) { 104 | 105 | } 106 | }; 107 | 108 | private class MyPagerAdapter extends PagerAdapter { 109 | @Override 110 | public int getCount() { 111 | return 4; 112 | } 113 | 114 | @Override 115 | public boolean isViewFromObject(View view, Object object) { 116 | 117 | return view == object; 118 | } 119 | 120 | @Override 121 | public Object instantiateItem(ViewGroup container, int position) { 122 | ViewGroup viewGroup = (ViewGroup) LayoutInflater.from(DemoTabActivity.this).inflate(R.layout.viewpage_item, container, false); 123 | 124 | viewGroup.setBackgroundColor(position * 40 % 255); 125 | TextView textView = (TextView) viewGroup.findViewById(R.id.textView); 126 | textView.setText("textView " + position); 127 | 128 | container.addView(viewGroup); 129 | return viewGroup; 130 | } 131 | 132 | @Override 133 | public void destroyItem(ViewGroup container, int position, Object object) { 134 | 135 | } 136 | } 137 | 138 | 139 | } 140 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /app/src/main/java/org/evilbinary/tv/DemoMenuActivity.java: -------------------------------------------------------------------------------- 1 | package org.evilbinary.tv; 2 | 3 | import android.app.Activity; 4 | import android.content.Context; 5 | import android.os.Bundle; 6 | import android.support.v7.widget.GridLayoutManager; 7 | import android.support.v7.widget.LinearLayoutManager; 8 | import android.support.v7.widget.RecyclerView; 9 | import android.util.Log; 10 | import android.view.View; 11 | import android.widget.Toast; 12 | 13 | import org.evilbinary.tv.widget.BorderView; 14 | 15 | /** 16 | * 作者:evilbinary on 4/10/16. 17 | * 邮箱:rootdebug@163.com 18 | */ 19 | public class DemoMenuActivity extends Activity { 20 | private BorderView border; 21 | 22 | private Context mContext; 23 | private String mCategory[] = new String[]{"全部频道", "美食", "休闲娱乐", "购物"}; 24 | //二级列表数据 25 | private String mDatas[][] = new String[][]{ 26 | new String[]{"全部美食", "江浙菜", "川菜", "粤菜", "湘菜"}, 27 | new String[]{"全部休闲娱乐", "咖啡厅", "酒吧", "茶馆", "KTV"}, 28 | new String[]{"全部购物", "综合商场", "服饰鞋包", "运动户外"}, 29 | new String[]{"全部休闲娱乐", "咖啡厅", "酒吧", "茶馆"}, 30 | 31 | }; 32 | 33 | private MyAdapter secondAdapter; 34 | private View lastFocus = null; 35 | private View lastSubFocus = null; 36 | 37 | private RecyclerView secondRecyclerView; 38 | private GridLayoutManager layoutManager2; 39 | 40 | @Override 41 | protected void onCreate(Bundle savedInstanceState) { 42 | super.onCreate(savedInstanceState); 43 | setContentView(R.layout.demo_menu); 44 | mContext = this; 45 | 46 | border = new BorderView(this); 47 | border.setBackgroundResource(R.drawable.border_red); 48 | 49 | RecyclerView firstRecyclerView = (RecyclerView) findViewById(R.id.firstRecyclerView); 50 | secondRecyclerView = (RecyclerView) findViewById(R.id.secondRecyclerView); 51 | 52 | GridLayoutManager layoutManager = new GridLayoutManager(this, 1); 53 | layoutManager.setOrientation(LinearLayoutManager.VERTICAL); 54 | firstRecyclerView.setLayoutManager(layoutManager); 55 | firstRecyclerView.setFocusable(false); 56 | 57 | 58 | layoutManager2 = new GridLayoutManager(this, 1); 59 | layoutManager2.setOrientation(LinearLayoutManager.VERTICAL); 60 | secondRecyclerView.setLayoutManager(layoutManager2); 61 | secondRecyclerView.setFocusable(false); 62 | 63 | 64 | secondAdapter = new MyAdapter(this, new String[]{}, R.layout.item_menu_sub, new View.OnFocusChangeListener() { 65 | @Override 66 | public void onFocusChange(View v, boolean hasFocus) { 67 | 68 | if (hasFocus) { 69 | if (lastSubFocus != null) 70 | lastSubFocus.setBackgroundResource(R.drawable.list_item_shape); 71 | lastSubFocus = v; 72 | v.setBackgroundResource(R.drawable.shape); 73 | 74 | } 75 | 76 | } 77 | }); 78 | secondAdapter.setOnBindListener(new MyAdapter.OnBindListener() { 79 | @Override 80 | public void onBind(View view, int i) { 81 | Log.d("tt", "onBind===>" + i); 82 | 83 | if (lastSubFocus == null||((int)lastSubFocus.getTag())==i) { 84 | view.setBackgroundResource(R.drawable.shape); 85 | lastSubFocus = view; 86 | }else{ 87 | view.setBackgroundResource(R.drawable.list_item_shape); 88 | 89 | } 90 | view.setOnClickListener(onClickListener); 91 | 92 | } 93 | }); 94 | secondRecyclerView.setAdapter(secondAdapter); 95 | 96 | 97 | // 创建Adapter,并指定数据集 98 | MyAdapter adapter = new MyAdapter(this, mCategory, R.layout.item_menu, new View.OnFocusChangeListener() { 99 | @Override 100 | public void onFocusChange(View v, boolean hasFocus) { 101 | if (hasFocus) { 102 | if (v != lastFocus) 103 | lastSubFocus = null; 104 | 105 | int pos = (int) v.getTag(); 106 | secondAdapter.setData(mDatas[pos]); 107 | secondAdapter.notifyDataSetChanged(); 108 | 109 | Log.d("tt", "onFocusChange===>" + pos); 110 | if (lastFocus != null) 111 | lastFocus.setBackgroundResource(R.drawable.list_item_shape); 112 | lastFocus = v; 113 | v.setBackgroundResource(R.drawable.shape); 114 | } 115 | 116 | 117 | } 118 | }); 119 | adapter.setOnBindListener(new MyAdapter.OnBindListener() { 120 | @Override 121 | public void onBind(View view, int i) { 122 | view.setOnClickListener(onClickListener); 123 | } 124 | }); 125 | // 设置Adapter 126 | firstRecyclerView.setAdapter(adapter); 127 | firstRecyclerView.scrollToPosition(0); 128 | 129 | 130 | border.getEffect().setScalable(false); 131 | border.getEffect().setEnableTouch(false); 132 | border.attachTo(firstRecyclerView); 133 | border.attachTo(secondRecyclerView); 134 | 135 | 136 | } 137 | 138 | private View.OnClickListener onClickListener = new View.OnClickListener() { 139 | @Override 140 | public void onClick(View v) { 141 | int pos = (int) v.getTag(); 142 | String tip = "click===" + pos; 143 | Toast.makeText(mContext, tip, Toast.LENGTH_SHORT).show(); 144 | v.setFocusableInTouchMode(true); 145 | v.requestFocus(); 146 | } 147 | }; 148 | 149 | } 150 | -------------------------------------------------------------------------------- /lib/src/main/java/org/evilbinary/tv/widget/BorderView.java: -------------------------------------------------------------------------------- 1 | package org.evilbinary.tv.widget; 2 | 3 | /** 4 | * 作者:evilbinary on 3/25/16. 5 | * 邮箱:rootdebug@163.com 6 | */ 7 | 8 | import android.app.Activity; 9 | import android.content.Context; 10 | import android.os.Build; 11 | import android.util.AttributeSet; 12 | import android.view.LayoutInflater; 13 | import android.view.View; 14 | import android.view.ViewGroup; 15 | import android.view.ViewTreeObserver; 16 | 17 | 18 | /** 19 | * 作者:evilbinary on 3/21/16. 20 | * 邮箱:rootdebug@163.com 21 | */ 22 | public class BorderView implements ViewTreeObserver.OnGlobalFocusChangeListener, ViewTreeObserver.OnScrollChangedListener, ViewTreeObserver.OnGlobalLayoutListener, ViewTreeObserver.OnTouchModeChangeListener { 23 | private String TAG = BorderView.class.getSimpleName(); 24 | 25 | private ViewGroup mViewGroup; 26 | private Effect borderEffect; 27 | 28 | private X mView; 29 | private View mLastView; 30 | 31 | public interface Effect { 32 | public void onFocusChanged(View target, View oldFocus, View newFocus); 33 | 34 | public void onScrollChanged(View target, View attachView); 35 | 36 | public void onLayout(View target, View attachView); 37 | 38 | public void onTouchModeChanged(View target, View attachView, boolean isInTouchMode); 39 | 40 | public void onAttach(View target, View attachView); 41 | 42 | public void OnDetach(View targe, View view); 43 | 44 | public T toEffect(Class t); 45 | } 46 | 47 | public BorderView(Context context) { 48 | this(context, null, 0); 49 | } 50 | 51 | public BorderView(Context context, AttributeSet attrs) { 52 | this(context, attrs, 0); 53 | } 54 | 55 | public BorderView(Context context, AttributeSet attrs, int defStyleAttr) { 56 | init(context, attrs, defStyleAttr); 57 | } 58 | 59 | private void init(Context context, AttributeSet attrs, int defStyleAttr) { 60 | borderEffect = new BorderEffect(); 61 | mView = (X) new View(context, attrs, defStyleAttr); 62 | } 63 | 64 | public BorderView(X view) { 65 | this.mView = view; 66 | borderEffect = new BorderEffect(); 67 | } 68 | public BorderView(X view,Effect effect) { 69 | this.mView = view; 70 | borderEffect =effect; 71 | } 72 | 73 | public BorderView(Context context, int resId) { 74 | this((X) LayoutInflater.from(context).inflate(resId, null, false)); 75 | } 76 | 77 | public X getView() { 78 | return mView; 79 | } 80 | 81 | 82 | public void setBackgroundResource(int resId) { 83 | if (mView != null) 84 | mView.setBackgroundResource(resId); 85 | } 86 | 87 | @Override 88 | public void onScrollChanged() { 89 | borderEffect.onScrollChanged(mView, mViewGroup); 90 | } 91 | 92 | @Override 93 | public void onGlobalLayout() { 94 | borderEffect.onLayout(mView, mViewGroup); 95 | } 96 | 97 | @Override 98 | public void onTouchModeChanged(boolean isInTouchMode) { 99 | borderEffect.onTouchModeChanged(mView, mViewGroup, isInTouchMode); 100 | } 101 | 102 | @Override 103 | public void onGlobalFocusChanged(View oldFocus, View newFocus) { 104 | try { 105 | if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN_MR2) { 106 | if (oldFocus == null && mLastView != null) { 107 | oldFocus = mLastView; 108 | } 109 | } 110 | if (borderEffect != null) 111 | borderEffect.onFocusChanged(mView, oldFocus, newFocus); 112 | mLastView = newFocus; 113 | 114 | } catch (Exception ex) { 115 | ex.printStackTrace(); 116 | } 117 | 118 | } 119 | 120 | 121 | public T getEffect() { 122 | return (T) borderEffect; 123 | } 124 | 125 | public void setEffect(Effect borderEffect) { 126 | this.borderEffect = borderEffect; 127 | } 128 | 129 | 130 | public void attachTo(ViewGroup viewGroup) { 131 | try { 132 | if (viewGroup == null) { 133 | if (mView.getContext() instanceof Activity) { 134 | Activity activity = (Activity) mView.getContext(); 135 | viewGroup = (ViewGroup) activity.getWindow().getDecorView().getRootView(); 136 | } 137 | } 138 | 139 | if (mViewGroup != viewGroup) { 140 | 141 | ViewTreeObserver viewTreeObserver = viewGroup.getViewTreeObserver(); 142 | if (viewTreeObserver.isAlive() && mViewGroup == null) { 143 | viewTreeObserver.addOnGlobalFocusChangeListener(this); 144 | viewTreeObserver.addOnScrollChangedListener(this); 145 | viewTreeObserver.addOnGlobalLayoutListener(this); 146 | viewTreeObserver.addOnTouchModeChangeListener(this); 147 | } 148 | mViewGroup = viewGroup; 149 | } 150 | borderEffect.onAttach(mView, viewGroup); 151 | 152 | 153 | } catch (Exception ex) { 154 | ex.printStackTrace(); 155 | } 156 | } 157 | 158 | public void detach() { 159 | detachFrom(mViewGroup); 160 | } 161 | 162 | public void detachFrom(ViewGroup viewGroup) { 163 | try { 164 | if (viewGroup == mViewGroup) { 165 | ViewTreeObserver viewTreeObserver = mViewGroup.getViewTreeObserver(); 166 | viewTreeObserver.removeOnGlobalFocusChangeListener(this); 167 | viewTreeObserver.removeOnScrollChangedListener(this); 168 | viewTreeObserver.removeOnGlobalLayoutListener(this); 169 | viewTreeObserver.removeOnTouchModeChangeListener(this); 170 | borderEffect.OnDetach(mView, viewGroup); 171 | } 172 | } catch (Exception ex) { 173 | ex.printStackTrace(); 174 | } 175 | } 176 | 177 | } 178 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 13 | 22 | 23 | 34 | 35 | 49 | 50 | 51 | 52 | 66 | 67 | 68 | 69 | 84 | 85 | 102 | 103 | 117 | 118 | 119 | 120 | 121 | 122 | 137 | 138 | 152 | 153 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | -------------------------------------------------------------------------------- /lib/src/main/java/org/evilbinary/tv/widget/RoundImpl.java: -------------------------------------------------------------------------------- 1 | package org.evilbinary.tv.widget; 2 | 3 | import android.content.Context; 4 | import android.content.res.TypedArray; 5 | import android.graphics.Bitmap; 6 | import android.graphics.Canvas; 7 | import android.graphics.Color; 8 | import android.graphics.Paint; 9 | import android.graphics.Path; 10 | import android.graphics.PorterDuff; 11 | import android.graphics.PorterDuffXfermode; 12 | import android.graphics.RectF; 13 | import android.util.AttributeSet; 14 | 15 | import evilbinary.org.lib.R; 16 | 17 | /** 18 | * 作者:evilbinary on 3/20/16. 19 | * 邮箱:rootdebug@163.com 20 | */ 21 | public class RoundImpl { 22 | 23 | 24 | private float mRadius; 25 | private float mTopLeftRadius; 26 | private float mTopRightRadius; 27 | private float mBottomLeftRadius; 28 | private float mBottomRightRadius; 29 | 30 | private Paint mPaint; 31 | private Path mPath; 32 | 33 | private RoundedView mView; 34 | 35 | 36 | public RoundImpl(RoundedView view, Context context, AttributeSet attrs, int defStyle) { 37 | init(context, attrs, defStyle); 38 | mView = view; 39 | } 40 | 41 | 42 | private void init(Context context, AttributeSet attrs, int defStyle) { 43 | 44 | 45 | mPaint = new Paint(); 46 | mPaint.setColor(Color.WHITE); 47 | mPaint.setAntiAlias(true); 48 | mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT)); 49 | mPath = new Path(); 50 | 51 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RoundImpl, defStyle, 0); 52 | mBottomLeftRadius = a.getDimension(R.styleable.RoundImpl_bottomLeftRadius, -1); 53 | mBottomRightRadius = a.getDimension(R.styleable.RoundImpl_bottomRightRadius, -1); 54 | mTopLeftRadius = a.getDimension(R.styleable.RoundImpl_topLeftRadius, -1); 55 | mTopRightRadius = a.getDimension(R.styleable.RoundImpl_topRightRadius, -1); 56 | mRadius = a.getDimension(R.styleable.RoundImpl_radius, -1); 57 | 58 | 59 | if (mRadius > 0) { 60 | if (mBottomLeftRadius < 0) 61 | mBottomLeftRadius = mRadius; 62 | if (mBottomRightRadius < 0) 63 | mBottomRightRadius = mRadius; 64 | if (mTopLeftRadius < 0) 65 | mTopLeftRadius = mRadius; 66 | if (mTopRightRadius < 0) 67 | mTopRightRadius = mRadius; 68 | } 69 | 70 | a.recycle(); 71 | 72 | } 73 | 74 | public interface RoundedView { 75 | 76 | public void drawSuper(Canvas canvas); 77 | 78 | public Context getContext(); 79 | 80 | public RoundImpl getRoundImpl(); 81 | 82 | public int getWidth(); 83 | 84 | public int getHeight(); 85 | } 86 | 87 | 88 | public void draw(Canvas canvas) { 89 | 90 | if (mBottomLeftRadius <= 0 && mBottomRightRadius <= 0 && mTopRightRadius <= 0 && mTopLeftRadius <= 0) { 91 | mView.drawSuper(canvas); 92 | return; 93 | } 94 | 95 | int width = mView.getWidth(); 96 | int height = mView.getHeight(); 97 | 98 | int count = canvas.save(); 99 | int count2 = canvas.saveLayer(0, 0, width, height, null, Canvas.ALL_SAVE_FLAG); 100 | 101 | addRoundPath(width, height); 102 | mView.drawSuper(canvas); 103 | canvas.drawPath(mPath, mPaint); 104 | canvas.restoreToCount(count2); 105 | //drawBorder(canvas); 106 | canvas.restoreToCount(count); 107 | 108 | 109 | } 110 | 111 | private void addRoundPath(int width, int height) { 112 | 113 | 114 | //topleft path 115 | if (mTopLeftRadius > 0) { 116 | Path topLeftPath = new Path(); 117 | topLeftPath.moveTo(0, mTopLeftRadius); 118 | topLeftPath.lineTo(0, 0); 119 | topLeftPath.lineTo(mTopLeftRadius, 0); 120 | RectF arc = new RectF(0, 0, mTopLeftRadius * 2, mTopLeftRadius * 2); 121 | topLeftPath.arcTo(arc, -90, -90); 122 | topLeftPath.close(); 123 | mPath.addPath(topLeftPath); 124 | } 125 | 126 | //topRight path 127 | 128 | if (mTopRightRadius > 0) { 129 | Path topRightPath = new Path(); 130 | topRightPath.moveTo(width, mTopRightRadius); 131 | topRightPath.lineTo(width, 0); 132 | topRightPath.lineTo(width - mTopRightRadius, 0); 133 | RectF arc = new RectF(width - mTopRightRadius * 2, 0, width, mTopRightRadius * 2); 134 | 135 | topRightPath.arcTo(arc, -90, 90); 136 | topRightPath.close(); 137 | 138 | mPath.addPath(topRightPath); 139 | 140 | } 141 | 142 | //bottomLeft path 143 | if (mBottomLeftRadius > 0) { 144 | Path bottomLeftPath = new Path(); 145 | bottomLeftPath.moveTo(0, height - mBottomLeftRadius); 146 | bottomLeftPath.lineTo(0, height); 147 | bottomLeftPath.lineTo(mBottomLeftRadius, height); 148 | RectF arc = new RectF(0, height - mBottomLeftRadius * 2, mBottomLeftRadius * 2, height); 149 | 150 | bottomLeftPath.arcTo(arc, 90, 90); 151 | bottomLeftPath.close(); 152 | mPath.addPath(bottomLeftPath); 153 | } 154 | 155 | //bottomRight path 156 | if (mBottomRightRadius > 0) { 157 | Path bottomRightPath = new Path(); 158 | bottomRightPath.moveTo(width - mBottomRightRadius, height); 159 | bottomRightPath.lineTo(width, height); 160 | bottomRightPath.lineTo(width, height - mBottomRightRadius); 161 | RectF arc = new RectF(width - mBottomRightRadius * 2, height - mBottomRightRadius * 2, width, height); 162 | bottomRightPath.arcTo(arc, 0, 90); 163 | bottomRightPath.close(); 164 | 165 | mPath.addPath(bottomRightPath); 166 | } 167 | 168 | 169 | } 170 | 171 | public static Bitmap getRoundBitmap(Bitmap bitmap, int roundWidth, int roundHeight) { 172 | Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), 173 | bitmap.getHeight(), Bitmap.Config.ARGB_8888); 174 | Canvas canvas = new Canvas(output); 175 | int count = canvas.save(Canvas.ALL_SAVE_FLAG); 176 | final Paint paint = new Paint(); 177 | final RectF rectF = new RectF(0, 0, bitmap.getWidth(), bitmap.getHeight()); 178 | paint.setAntiAlias(true); 179 | canvas.drawARGB(0, 0, 0, 0); 180 | canvas.drawRoundRect(rectF, roundWidth, roundHeight, paint); 181 | paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); 182 | canvas.drawBitmap(bitmap, 0, 0, paint); 183 | canvas.restoreToCount(count); 184 | return output; 185 | } 186 | 187 | 188 | } 189 | -------------------------------------------------------------------------------- /lib/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | #00000000 8 | #FFFFFF 9 | #FFFFF0 10 | #FFFFE0 11 | #FFFF00 12 | #FFFAFA 13 | #FFFAF0 14 | #FFFACD 15 | #FFF8DC 16 | #FFF5EE 17 | #FFF0F5 18 | #FFEFD5 19 | #FFEBCD 20 | #FFE4E1 21 | #FFE4C4 22 | #FFE4B5 23 | #FFDEAD 24 | #FFDAB9 25 | #FFD700 26 | #FFC0CB 27 | #FFB6C1 28 | #FFA500 29 | #FFA07A 30 | #FF8C00 31 | #FF7F50 32 | #FF69B4 33 | #FF6347 34 | #FF4500 35 | #FF1493 36 | #FF00FF 37 | #FF0000 38 | #FDF5E6 39 | #FAFAD2 40 | #FAF0E6 41 | #FAEBD7 42 | #FA8072 43 | #F8F8FF 44 | #F5FFFA 45 | #F5F5F5 46 | #F5F5DC 47 | #F5DEB3 48 | #F4A460 49 | #F0FFFF 50 | #F0FFF0 51 | #F0F8FF 52 | #F0E68C 53 | #F08080 54 | #EEE8AA 55 | #EE82EE 56 | #E9967A 57 | #E6E6FA 58 | #E0FFFF 59 | #DEB887 60 | #DDA0DD 61 | #DCDCDC 62 | #DC143C 63 | #DB7093 64 | #DAA520 65 | #DA70D6 66 | #D8BFD8 67 | #D3D3D3 68 | #D2B48C 69 | #D2691E 70 | #CD853F 71 | #CD5C5C 72 | #C71585 73 | #C0C0C0 74 | #BDB76B 75 | #BC8F8F 76 | #BA55D3 77 | #B8860B 78 | #B22222 79 | #B0E0E6 80 | #B0C4DE 81 | #AFEEEE 82 | #ADFF2F 83 | #ADD8E6 84 | #A9A9A9 85 | #A52A2A 86 | #A0522D 87 | #9932CC 88 | #98FB98 89 | #9400D3 90 | #9370DB 91 | #90EE90 92 | #8FBC8F 93 | #8B4513 94 | #8B008B 95 | #8B0000 96 | #8A2BE2 97 | #87CEFA 98 | #87CEEB 99 | #808080 100 | #808000 101 | #800080 102 | #800000 103 | #7FFFD4 104 | #7FFF00 105 | #7CFC00 106 | #7B68EE 107 | #778899 108 | #708090 109 | #6B8E23 110 | #6A5ACD 111 | #696969 112 | #66CDAA 113 | #6495ED 114 | #5F9EA0 115 | #556B2F 116 | #4B0082 117 | #48D1CC 118 | #483D8B 119 | #4682B4 120 | #4169E1 121 | #40E0D0 122 | #3CB371 123 | #32CD32 124 | #2F4F4F 125 | #2E8B57 126 | #228B22 127 | #20B2AA 128 | #1E90FF 129 | #191970 130 | #00FFFF 131 | #00FFFF 132 | #00FF7F 133 | #00FF00 134 | #00FA9A 135 | #00CED1 136 | #00BFFF 137 | #008B8B 138 | #008080 139 | #008000 140 | #006400 141 | #0000FF 142 | #0000CD 143 | #00008B 144 | #000080 145 | #000000 146 | #99cc33 147 | #cccccc 148 | #8f8f8f 149 | 150 | 151 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_home.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 12 | 15 | 16 | 20 | 21 | 22 | 23 | 26 | 27 | 38 | 39 | 40 | 51 | 52 | 53 | 59 | 60 | 61 | 72 | 73 | 74 | 84 | 85 | 86 | 87 | 88 | 89 | 103 | 104 | 105 | 110 | 111 | 112 | 122 | 123 | 133 | 134 | 135 | 136 | 137 | 155 | 156 | 157 | 163 | 164 | 174 | 175 | 176 | 177 | 178 | 197 | 198 | 199 | 205 | 206 | 207 | 218 | 219 | 229 | 230 | 231 | 232 | 233 | 244 | 245 | 246 | 252 | 253 | 254 | 264 | 265 | 275 | 276 | 277 | 278 | 279 | 280 | 291 | 292 | 293 | 299 | 300 | 301 | 311 | 312 | 322 | 323 | 324 | 325 | 326 | 327 | 338 | 339 | 340 | 346 | 347 | 348 | 358 | 359 | 369 | 370 | 371 | 372 | 373 | 374 | 385 | 386 | 387 | 393 | 394 | 395 | 405 | 406 | 416 | 417 | 418 | 419 | 420 | 421 | 432 | 433 | 434 | 440 | 441 | 442 | 452 | 453 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 474 | 475 | 479 | 480 | 481 | -------------------------------------------------------------------------------- /lib/src/main/java/org/evilbinary/tv/widget/BorderEffect.java: -------------------------------------------------------------------------------- 1 | package org.evilbinary.tv.widget; 2 | 3 | import android.animation.Animator; 4 | import android.animation.AnimatorSet; 5 | import android.animation.ObjectAnimator; 6 | import android.animation.PropertyValuesHolder; 7 | import android.animation.ValueAnimator; 8 | import android.graphics.Rect; 9 | import android.support.v7.widget.RecyclerView; 10 | import android.util.Log; 11 | import android.view.View; 12 | import android.view.ViewGroup; 13 | import android.view.animation.DecelerateInterpolator; 14 | import android.widget.AbsListView; 15 | import android.widget.AdapterView; 16 | 17 | import org.evilbinary.tv.widget.BorderView.Effect; 18 | 19 | import java.util.ArrayList; 20 | import java.util.HashMap; 21 | import java.util.List; 22 | import java.util.Map; 23 | 24 | /** 25 | * 作者:evilbinary on 3/26/16. 26 | * 邮箱:rootdebug@163.com 27 | */ 28 | public class BorderEffect implements Effect { 29 | private String TAG = BorderEffect.class.getSimpleName(); 30 | 31 | 32 | protected boolean mScalable = true; 33 | protected float mScale = 1.1f; 34 | 35 | protected long mDurationTraslate = 200; 36 | protected int mMargin = 0; 37 | protected View lastFocus, oldLastFocus; 38 | protected AnimatorSet mAnimatorSet; 39 | protected List mAnimatorList = new ArrayList(); 40 | protected View mTarget; 41 | 42 | protected boolean mEnableTouch=true; 43 | 44 | public BorderEffect() { 45 | 46 | mFocusListener.add(focusMoveListener); 47 | mFocusListener.add(focusScaleListener); 48 | mFocusListener.add(focusPlayListener); 49 | mFocusListener.add(absListViewFocusListener); 50 | } 51 | 52 | public interface FocusListener { 53 | public void onFocusChanged(View oldFocus, View newFocus); 54 | } 55 | 56 | protected List mFocusListener = new ArrayList(1); 57 | protected List mAnimatorListener = new ArrayList(1); 58 | 59 | 60 | public FocusListener focusScaleListener = new FocusListener() { 61 | @Override 62 | public void onFocusChanged(View oldFocus, View newFocus) { 63 | mAnimatorList.addAll(getScaleAnimator(newFocus, true)); 64 | if (oldFocus != null) { 65 | mAnimatorList.addAll(getScaleAnimator(oldFocus, false)); 66 | } 67 | } 68 | }; 69 | public FocusListener focusPlayListener = new FocusListener() { 70 | @Override 71 | public void onFocusChanged(View oldFocus, View newFocus) { 72 | try { 73 | if (newFocus instanceof AbsListView) { 74 | return; 75 | } 76 | AnimatorSet animatorSet = new AnimatorSet(); 77 | animatorSet.setInterpolator(new DecelerateInterpolator(1)); 78 | animatorSet.setDuration(mDurationTraslate); 79 | animatorSet.playTogether(mAnimatorList); 80 | for (Animator.AnimatorListener listener : mAnimatorListener) { 81 | animatorSet.addListener(listener); 82 | } 83 | mAnimatorSet = animatorSet; 84 | if (oldFocus == null) { 85 | animatorSet.setDuration(0); 86 | mTarget.setVisibility(View.VISIBLE); 87 | } 88 | animatorSet.start(); 89 | }catch (Exception ex){ 90 | ex.printStackTrace(); 91 | } 92 | } 93 | }; 94 | public FocusListener focusMoveListener = new FocusListener() { 95 | @Override 96 | public void onFocusChanged(View oldFocus, View newFocus) { 97 | if (newFocus == null) return; 98 | try { 99 | 100 | mAnimatorList.addAll(getMoveAnimator(newFocus, 0, 0)); 101 | 102 | } catch (Exception ex) { 103 | ex.printStackTrace(); 104 | } 105 | } 106 | }; 107 | 108 | 109 | public FocusListener absListViewFocusListener = new FocusListener() { 110 | 111 | @Override 112 | public void onFocusChanged(View oldFocus, View newFocus) { 113 | 114 | try { 115 | Log.d(TAG, "onFocusChanged==>" + oldFocus + " " + newFocus); 116 | if (oldFocus == null) { 117 | for (int i = 0; i < attacheViews.size(); i++) { 118 | View view = attacheViews.get(i); 119 | if (view instanceof AbsListView) { 120 | final AbsListView absListView = (AbsListView) view; 121 | mTarget.setVisibility(View.INVISIBLE); 122 | if (mFirstFocus) { 123 | absListView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { 124 | @Override 125 | public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { 126 | try { 127 | absListView.removeOnLayoutChangeListener(this); 128 | int factorX = 0, factorY = 0; 129 | Rect rect = new Rect(); 130 | View firstView = (View) absListView.getSelectedView(); 131 | firstView.getLocalVisibleRect(rect); 132 | if (Math.abs(rect.left - rect.right) > firstView.getMeasuredWidth()) { 133 | factorX = (Math.abs(rect.left - rect.right) - firstView.getMeasuredWidth()) / 2 - 1; 134 | factorY = (Math.abs(rect.top - rect.bottom) - firstView.getMeasuredHeight()) / 2; 135 | } 136 | List animatorList = new ArrayList(3); 137 | animatorList.addAll(getScaleAnimator(firstView, true)); 138 | animatorList.addAll(getMoveAnimator(firstView, factorX, factorY)); 139 | mTarget.setVisibility(View.VISIBLE); 140 | AnimatorSet animatorSet = new AnimatorSet(); 141 | animatorSet.setDuration(0); 142 | animatorSet.playTogether(animatorList); 143 | animatorSet.start(); 144 | } catch (Exception ex) { 145 | ex.printStackTrace(); 146 | } 147 | } 148 | }); 149 | 150 | 151 | } 152 | break; 153 | } 154 | } 155 | } else if (oldFocus instanceof AbsListView && newFocus instanceof AbsListView) { 156 | if (attacheViews.indexOf(oldFocus) >= 0 && attacheViews.indexOf(newFocus) >= 0) { 157 | 158 | AbsListView a = (AbsListView) oldFocus; 159 | AbsListView b = (AbsListView) newFocus; 160 | 161 | MyOnItemSelectedListener oldOn = (MyOnItemSelectedListener) onItemSelectedListenerList.get(oldFocus); 162 | MyOnItemSelectedListener newOn = (MyOnItemSelectedListener) onItemSelectedListenerList.get(newFocus); 163 | 164 | 165 | int factorX = 0, factorY = 0; 166 | Rect rect = new Rect(); 167 | View firstView = (View) b.getSelectedView(); 168 | firstView.getLocalVisibleRect(rect); 169 | if (Math.abs(rect.left - rect.right) > firstView.getMeasuredWidth()) { 170 | factorX = (Math.abs(rect.left - rect.right) - firstView.getMeasuredWidth()) / 2 - 1; 171 | factorY = (Math.abs(rect.top - rect.bottom) - firstView.getMeasuredHeight()) / 2; 172 | } 173 | 174 | List animatorList = new ArrayList(3); 175 | animatorList.addAll(getScaleAnimator(firstView, true)); 176 | animatorList.addAll(getScaleAnimator(a.getSelectedView(), false)); 177 | 178 | animatorList.addAll(getMoveAnimator(firstView, factorX, factorY)); 179 | mTarget.setVisibility(View.VISIBLE); 180 | 181 | mAnimatorSet = new AnimatorSet(); 182 | 183 | 184 | mAnimatorSet.setDuration(mDurationTraslate); 185 | mAnimatorSet.playTogether(animatorList); 186 | mAnimatorSet.start(); 187 | 188 | oldOn.oldFocus = null; 189 | oldOn.newFocus = null; 190 | 191 | newOn.oldFocus = null; 192 | if (newOn.newFocus != null && newOn.oldFocus != null) { 193 | newOn.newFocus = null; 194 | } else { 195 | newOn.newFocus = b.getSelectedView(); 196 | } 197 | 198 | } 199 | } 200 | } catch (Exception ex) { 201 | ex.printStackTrace(); 202 | } 203 | } 204 | }; 205 | 206 | protected List getScaleAnimator(View view, boolean isScale) { 207 | 208 | List animatorList = new ArrayList(2); 209 | if(!mScalable) return animatorList; 210 | try { 211 | float scaleBefore = 1.0f; 212 | float scaleAfter = mScale; 213 | if (!isScale) { 214 | scaleBefore = mScale; 215 | scaleAfter = 1.0f; 216 | } 217 | ObjectAnimator scaleX = new ObjectAnimator().ofFloat(view, "scaleX", scaleBefore, scaleAfter); 218 | ObjectAnimator scaleY = new ObjectAnimator().ofFloat(view, "scaleY", scaleBefore, scaleAfter); 219 | animatorList.add(scaleX); 220 | animatorList.add(scaleY); 221 | }catch (Exception ex){ 222 | ex.printStackTrace(); 223 | } 224 | return animatorList; 225 | } 226 | 227 | protected List getMoveAnimator(View newFocus, int factorX, int factorY) { 228 | 229 | List animatorList = new ArrayList(); 230 | int newXY[]; 231 | int oldXY[]; 232 | 233 | try { 234 | 235 | newXY = getLocation(newFocus); 236 | oldXY = getLocation(mTarget); 237 | 238 | int newWidth; 239 | int newHeight; 240 | int oldWidth = mTarget.getMeasuredWidth(); 241 | int oldHeight = mTarget.getMeasuredHeight(); 242 | 243 | if (mScalable) { 244 | float scaleWidth = newFocus.getMeasuredWidth() * mScale; 245 | float scaleHeight = newFocus.getMeasuredHeight() * mScale; 246 | newWidth = (int) (scaleWidth + mMargin * 2 + 0.5); 247 | newHeight = (int) (scaleHeight + mMargin * 2 + 0.5); 248 | newXY[0] = (int) (newXY[0] - (newWidth - newFocus.getMeasuredWidth()) / 2.0f) + factorX; 249 | newXY[1] = (int) (newXY[1] - (newHeight - newFocus.getMeasuredHeight()) / 2.0f + 0.5 + factorY); 250 | 251 | } else { 252 | newWidth = newFocus.getWidth(); 253 | newHeight = newFocus.getHeight(); 254 | } 255 | if (oldHeight == 0 && oldWidth == 0) { 256 | oldHeight = newHeight; 257 | oldWidth = newWidth; 258 | } 259 | 260 | PropertyValuesHolder valuesWithdHolder = PropertyValuesHolder.ofInt("width", oldWidth, newWidth); 261 | PropertyValuesHolder valuesHeightHolder = PropertyValuesHolder.ofInt("height", oldHeight, newHeight); 262 | PropertyValuesHolder valuesXHolder = PropertyValuesHolder.ofFloat("translationX", oldXY[0], newXY[0]); 263 | PropertyValuesHolder valuesYHolder = PropertyValuesHolder.ofFloat("translationY", oldXY[1], newXY[1]); 264 | final ObjectAnimator scaleAnimator = ObjectAnimator.ofPropertyValuesHolder(mTarget, valuesWithdHolder, valuesHeightHolder, valuesYHolder, valuesXHolder); 265 | 266 | scaleAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 267 | @Override 268 | public synchronized void onAnimationUpdate(ValueAnimator animation) { 269 | int width = (int) animation.getAnimatedValue("width"); 270 | int height = (int) animation.getAnimatedValue("height"); 271 | float translationX = (float) animation.getAnimatedValue("translationX"); 272 | float translationY = (float) animation.getAnimatedValue("translationY"); 273 | //Log.d(TAG,"width:"+width+" height:"+height+" translationX:"+translationX+" translationY:"+translationY); 274 | View view = (View) scaleAnimator.getTarget(); 275 | assert view != null; 276 | int w = view.getLayoutParams().width; 277 | view.getLayoutParams().width = width; 278 | view.getLayoutParams().height = height; 279 | if (width > 0) { 280 | view.requestLayout(); 281 | view.postInvalidate(); 282 | 283 | } 284 | } 285 | }); 286 | animatorList.add(scaleAnimator); 287 | } catch (Exception ex) { 288 | ex.printStackTrace(); 289 | } 290 | return animatorList; 291 | } 292 | 293 | protected int[] getLocation(View view) { 294 | int[] location = new int[2]; 295 | try { 296 | view.getLocationOnScreen(location); 297 | } catch (Exception ex) { 298 | ex.printStackTrace(); 299 | } 300 | return location; 301 | } 302 | 303 | public void addOnFocusChanged(FocusListener focusListener) { 304 | this.mFocusListener.add(focusListener); 305 | } 306 | 307 | public void removeOnFocusChanged(FocusListener focusListener) { 308 | this.mFocusListener.remove(focusListener); 309 | } 310 | 311 | public void addAnimatorListener(Animator.AnimatorListener animatorListener) { 312 | this.mAnimatorListener.add(animatorListener); 313 | } 314 | 315 | public void removeAnimatorListener(Animator.AnimatorListener animatorListener) { 316 | this.mAnimatorListener.remove(animatorListener); 317 | } 318 | 319 | private class VisibleScope { 320 | public boolean isVisible; 321 | public View oldFocus; 322 | public View newFocus; 323 | } 324 | 325 | protected VisibleScope checkVisibleScope(View oldFocus, View newFocus) { 326 | VisibleScope scope = new VisibleScope(); 327 | try { 328 | scope.oldFocus = oldFocus; 329 | scope.newFocus = newFocus; 330 | scope.isVisible = true; 331 | if (attacheViews.indexOf(oldFocus) >= 0 && attacheViews.indexOf(newFocus) >= 0) { 332 | return scope; 333 | } 334 | 335 | if (oldFocus != null && newFocus != null) { 336 | if (oldFocus.getParent() != newFocus.getParent()) { 337 | Log.d(TAG, "=====>" + attacheViews.indexOf(newFocus.getParent()) + "=" + attacheViews.indexOf(oldFocus.getParent())); 338 | 339 | if ((attacheViews.indexOf(newFocus.getParent()) < 0) || (attacheViews.indexOf(oldFocus.getParent()) < 0 && attacheViews.indexOf(newFocus.getParent()) > 0)) { 340 | mTarget.setVisibility(View.INVISIBLE); 341 | AnimatorSet animatorSet = new AnimatorSet(); 342 | animatorSet.playTogether(getScaleAnimator(oldFocus, false)); 343 | animatorSet.setDuration(0).start(); 344 | Log.d(TAG, "=====>1"); 345 | scope.isVisible = false; 346 | return scope; 347 | } else { 348 | Log.d(TAG, "=====>2"); 349 | 350 | mTarget.setVisibility(View.VISIBLE); 351 | } 352 | if (attacheViews.indexOf(oldFocus.getParent()) < 0) { 353 | scope.oldFocus = null; 354 | } 355 | 356 | } else { 357 | if (attacheViews.indexOf(newFocus.getParent()) < 0) { 358 | mTarget.setVisibility(View.INVISIBLE); 359 | Log.d(TAG, "=====>3"); 360 | scope.isVisible = false; 361 | return scope; 362 | } 363 | Log.d(TAG, "=====>4"); 364 | 365 | } 366 | Log.d(TAG, "=====>5"); 367 | } 368 | mTarget.setVisibility(View.VISIBLE); 369 | } catch (Exception ex) { 370 | ex.printStackTrace(); 371 | } 372 | return scope; 373 | } 374 | 375 | @Override 376 | public void onFocusChanged(View target, View oldFocus, View newFocus) { 377 | try { 378 | Log.d(TAG, "onFocusChanged:" + oldFocus + "=" + newFocus); 379 | 380 | if (newFocus == null && attacheViews.indexOf(newFocus) >= 0) { 381 | return; 382 | } 383 | if (oldFocus == newFocus) 384 | return; 385 | 386 | if (mAnimatorSet != null && mAnimatorSet.isRunning()) { 387 | mAnimatorSet.end(); 388 | } 389 | 390 | lastFocus = newFocus; 391 | oldLastFocus = oldFocus; 392 | mTarget = target; 393 | Log.d(TAG, "onFocusChanged:111111111" + oldFocus + "=" + newFocus); 394 | 395 | VisibleScope scope = checkVisibleScope(oldFocus, newFocus); 396 | if (!scope.isVisible) { 397 | return; 398 | } else { 399 | oldFocus = scope.oldFocus; 400 | newFocus = scope.newFocus; 401 | oldLastFocus = scope.oldFocus; 402 | } 403 | 404 | if (isScrolling || newFocus == null || newFocus.getWidth() <= 0 || newFocus.getHeight() <= 0) 405 | return; 406 | Log.d(TAG, "onFocusChanged:2222222222" + oldFocus + "=" + newFocus); 407 | 408 | mAnimatorList.clear(); 409 | 410 | for (FocusListener f : this.mFocusListener) { 411 | f.onFocusChanged(oldFocus, newFocus); 412 | } 413 | 414 | } catch (Exception ex) { 415 | ex.printStackTrace(); 416 | } 417 | } 418 | 419 | 420 | @Override 421 | public void onScrollChanged(View target, View attachView) { 422 | try { 423 | // Log.d(TAG, "onScrollChanged"); 424 | 425 | } catch (Exception ex) { 426 | ex.printStackTrace(); 427 | } 428 | } 429 | 430 | @Override 431 | public void onLayout(View target, View attachView) { 432 | try { 433 | // Log.d(TAG, "onLayout"); 434 | ViewGroup viewGroup = (ViewGroup) attachView.getRootView(); 435 | if (target.getParent() != null && target.getParent() != viewGroup) { 436 | target.setVisibility(View.GONE); 437 | if (mFirstFocus) 438 | viewGroup.requestFocus(); 439 | } 440 | } catch (Exception ex) { 441 | ex.printStackTrace(); 442 | } 443 | } 444 | 445 | protected boolean mFirstFocus = true; 446 | 447 | public void setFirstFocus(boolean b) { 448 | this.mFirstFocus = b; 449 | } 450 | 451 | @Override 452 | public void onTouchModeChanged(View target, View attachView, boolean isInTouchMode) { 453 | try { 454 | //Log.d(TAG, "onTouchModeChanged:"+isInTouchMode); 455 | if (mEnableTouch&&isInTouchMode) { 456 | target.setVisibility(View.INVISIBLE); 457 | if (lastFocus != null) { 458 | AnimatorSet animatorSet = new AnimatorSet(); 459 | animatorSet.playTogether(getScaleAnimator(lastFocus, false)); 460 | animatorSet.setDuration(0).start(); 461 | } 462 | } 463 | 464 | } catch (Exception ex) { 465 | ex.printStackTrace(); 466 | } 467 | 468 | } 469 | 470 | protected boolean isScrolling = false; 471 | 472 | protected List attacheViews = new ArrayList<>(); 473 | protected Map onItemSelectedListenerList = new HashMap<>(); 474 | 475 | 476 | @Override 477 | public void onAttach(View target, View attachView) { 478 | try { 479 | mTarget = target; 480 | 481 | if (target.getParent() != null && (target.getParent() instanceof ViewGroup)) { 482 | ViewGroup vg = (ViewGroup) target.getParent(); 483 | vg.removeView(target); 484 | } 485 | 486 | ViewGroup vg = (ViewGroup) attachView.getRootView(); 487 | vg.addView(target); 488 | 489 | target.setVisibility(View.GONE); 490 | if (attachView instanceof RecyclerView) { 491 | RecyclerView recyclerView = (RecyclerView) attachView; 492 | RecyclerView.OnScrollListener recyclerViewOnScrollListener = null; 493 | recyclerViewOnScrollListener = new RecyclerView.OnScrollListener() { 494 | @Override 495 | public void onScrollStateChanged(RecyclerView recyclerView, int newState) { 496 | try { 497 | super.onScrollStateChanged(recyclerView, newState); 498 | //Log.d(TAG, "========>onScrollStateChanged"); 499 | 500 | if (newState == RecyclerView.SCROLL_STATE_IDLE) { 501 | //Log.d(TAG, "========>SCROLL_STATE_IDLE"); 502 | isScrolling = false; 503 | View oldFocus = oldLastFocus; 504 | View newFocus = lastFocus; 505 | VisibleScope scope = checkVisibleScope(oldFocus, newFocus); 506 | if (!scope.isVisible) { 507 | return; 508 | } else { 509 | oldFocus = scope.oldFocus; 510 | newFocus = scope.newFocus; 511 | } 512 | AnimatorSet animatorSet = new AnimatorSet(); 513 | List list = new ArrayList<>(); 514 | // list.addAll(getScaleAnimator(oldLastFocus, false)); 515 | list.addAll(getScaleAnimator(newFocus, true)); 516 | list.addAll(getMoveAnimator(newFocus, 0, 0)); 517 | animatorSet.setDuration(mDurationTraslate); 518 | animatorSet.playTogether(list); 519 | animatorSet.start(); 520 | 521 | 522 | } else if (newState == RecyclerView.SCROLL_STATE_SETTLING) { 523 | //Log.d(TAG, "========>SCROLL_STATE_SETTLING=" + mAnimatorSet.isRunning()); 524 | isScrolling = true; 525 | if (lastFocus != null) { 526 | List list = getScaleAnimator(lastFocus, false); 527 | AnimatorSet animatorSet = new AnimatorSet(); 528 | animatorSet.setDuration(150); 529 | animatorSet.playTogether(list); 530 | animatorSet.start(); 531 | } 532 | } 533 | } catch (Exception ex) { 534 | 535 | } 536 | } 537 | }; 538 | recyclerView.addOnScrollListener(recyclerViewOnScrollListener); 539 | } else if (attachView instanceof AbsListView) { 540 | 541 | final AbsListView absListView = (AbsListView) attachView; 542 | final AdapterView.OnItemSelectedListener onItemSelectedListener = absListView.getOnItemSelectedListener(); 543 | 544 | View temp = null; 545 | if (absListView.getChildCount() > 0) { 546 | temp = absListView.getChildAt(0); 547 | } 548 | final View tempFocus = temp; 549 | MyOnItemSelectedListener myOnItemSelectedListener = new MyOnItemSelectedListener(); 550 | myOnItemSelectedListener.onItemSelectedListener = onItemSelectedListener; 551 | myOnItemSelectedListener.oldFocus = temp; 552 | absListView.setOnItemSelectedListener(myOnItemSelectedListener); 553 | onItemSelectedListenerList.put(attachView, myOnItemSelectedListener); 554 | 555 | } 556 | 557 | attacheViews.add(attachView); 558 | } catch (Exception ex) { 559 | ex.printStackTrace(); 560 | } 561 | 562 | } 563 | 564 | protected class MyOnItemSelectedListener implements AdapterView.OnItemSelectedListener { 565 | public View oldFocus = null; 566 | public View newFocus = null; 567 | public AnimatorSet animatorSet; 568 | public AdapterView.OnItemSelectedListener onItemSelectedListener; 569 | 570 | @Override 571 | public void onItemSelected(AdapterView parent, View view, int position, long id) { 572 | try { 573 | if (onItemSelectedListener != null && parent != null) { 574 | onItemSelectedListener.onItemSelected(parent, view, position, id); 575 | } 576 | if (newFocus == null) 577 | return; 578 | newFocus = view; 579 | Log.d(TAG, "onItemSelected"); 580 | 581 | Rect rect = new Rect(); 582 | view.getLocalVisibleRect(rect); 583 | 584 | ViewGroup vg = (ViewGroup) newFocus.getParent(); 585 | // Log.d(TAG, "onItemSelected:" + vg.getWidth() + " " + newFocus.getMeasuredWidth() + " w=" + (rect.left - rect.right)); 586 | 587 | int factorX = 0, factorY = 0; 588 | if (Math.abs(rect.left - rect.right) > newFocus.getMeasuredWidth()) { 589 | factorX = (Math.abs(rect.left - rect.right) - newFocus.getMeasuredWidth()) / 2 - 1; 590 | factorY = (Math.abs(rect.top - rect.bottom) - newFocus.getMeasuredHeight()) / 2; 591 | 592 | } 593 | 594 | 595 | List animatorList = new ArrayList(3); 596 | animatorList.addAll(getScaleAnimator(newFocus, true)); 597 | if (oldFocus != null) 598 | animatorList.addAll(getScaleAnimator(oldFocus, false)); 599 | animatorList.addAll(getMoveAnimator(newFocus, factorX, factorY)); 600 | mTarget.setVisibility(View.VISIBLE); 601 | 602 | if (animatorSet != null && animatorSet.isRunning()) 603 | animatorSet.end(); 604 | animatorSet = new AnimatorSet(); 605 | animatorSet.setDuration(mDurationTraslate); 606 | animatorSet.playTogether(animatorList); 607 | animatorSet.start(); 608 | 609 | 610 | oldFocus = newFocus; 611 | }catch (Exception ex){ 612 | ex.printStackTrace(); 613 | } 614 | 615 | } 616 | 617 | @Override 618 | public void onNothingSelected(AdapterView parent) { 619 | Log.d(TAG, "onNothingSelected"); 620 | if (onItemSelectedListener != null) { 621 | onItemSelectedListener.onNothingSelected(parent); 622 | } 623 | } 624 | } 625 | 626 | 627 | @Override 628 | public void OnDetach(View targe, View view) { 629 | if (targe.getParent() == view) { 630 | ((ViewGroup) view).removeView(targe); 631 | } 632 | 633 | attacheViews.remove(view); 634 | } 635 | 636 | @Override 637 | public T toEffect(Class t) { 638 | return (T) this; 639 | } 640 | 641 | public void setEnableTouch(boolean enableTouch){ 642 | this.mEnableTouch=enableTouch; 643 | } 644 | public boolean isScalable() { 645 | return mScalable; 646 | } 647 | 648 | public void setScalable(boolean scalable) { 649 | this.mScalable = scalable; 650 | } 651 | 652 | public float getScale() { 653 | return mScale; 654 | } 655 | 656 | public void setScale(float scale) { 657 | this.mScale = scale; 658 | } 659 | 660 | public int getMargin() { 661 | return mMargin; 662 | } 663 | 664 | public void setMargin(int mMargin) { 665 | this.mMargin = mMargin; 666 | } 667 | 668 | } 669 | --------------------------------------------------------------------------------