├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ └── ic_launcher_round.png │ │ │ ├── drawable-xhdpi │ │ │ │ └── bg_light_focus.9.png │ │ │ ├── values │ │ │ │ ├── colors.xml │ │ │ │ ├── strings.xml │ │ │ │ └── styles.xml │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ ├── ic_launcher.xml │ │ │ │ └── ic_launcher_round.xml │ │ │ ├── layout │ │ │ │ ├── fragment_scrollable_view_focus.xml │ │ │ │ ├── recycler_item.xml │ │ │ │ ├── dialog_for_focus_demo.xml │ │ │ │ ├── activity_main.xml │ │ │ │ └── fragment_simple_view_focus.xml │ │ │ ├── drawable-v24 │ │ │ │ └── ic_launcher_foreground.xml │ │ │ └── drawable │ │ │ │ └── ic_launcher_background.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── com │ │ │ └── ryanhuen │ │ │ └── androidtvfocus │ │ │ ├── fragment │ │ │ ├── ScrollableViewFocusFragment.java │ │ │ └── SimpleViewFocusFragment.java │ │ │ ├── adapter │ │ │ └── SampleAdapter.java │ │ │ └── MainActivity.java │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── ryanhuen │ │ │ └── androidtvfocus │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── ryanhuen │ │ └── androidtvfocus │ │ └── ExampleInstrumentedTest.java ├── proguard-rules.pro └── build.gradle ├── lib ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── integers.xml │ │ │ │ └── ids.xml │ │ │ └── drawable-xhdpi │ │ │ │ └── focus_highlight.9.png │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── com │ │ │ └── ryanhuen │ │ │ └── lib │ │ │ └── widget │ │ │ ├── FocusHighlightOptions.java │ │ │ ├── FocusHighlightHelper.java │ │ │ └── ShadowFocusView.java │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── ryanhuen │ │ │ └── lib │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── ryanhuen │ │ └── lib │ │ └── ExampleInstrumentedTest.java ├── build.gradle └── proguard-rules.pro ├── settings.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── README.md ├── gradle.properties ├── .gitignore ├── gradlew.bat └── gradlew /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /lib/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':lib' 2 | -------------------------------------------------------------------------------- /lib/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | FocusLib 3 | 4 | -------------------------------------------------------------------------------- /lib/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RyanHuen/AndroidTVFocus/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RyanHuen/AndroidTVFocus/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RyanHuen/AndroidTVFocus/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RyanHuen/AndroidTVFocus/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RyanHuen/AndroidTVFocus/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RyanHuen/AndroidTVFocus/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/bg_light_focus.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RyanHuen/AndroidTVFocus/HEAD/app/src/main/res/drawable-xhdpi/bg_light_focus.9.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RyanHuen/AndroidTVFocus/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RyanHuen/AndroidTVFocus/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RyanHuen/AndroidTVFocus/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RyanHuen/AndroidTVFocus/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RyanHuen/AndroidTVFocus/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /lib/src/main/res/drawable-xhdpi/focus_highlight.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RyanHuen/AndroidTVFocus/HEAD/lib/src/main/res/drawable-xhdpi/focus_highlight.9.png -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /lib/src/main/res/values/integers.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 500 4 | 300 5 | 100 6 | 7 | -------------------------------------------------------------------------------- /lib/src/main/res/values/ids.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Mar 19 09:35:41 CST 2018 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-4.1-all.zip 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AndroidTVFocus 2 | Android TV的Focus动态效果(支持滚动) 3 | # Demo APK下载 4 | [Demo APK 地址](https://github.com/RyanHuen/AndroidTVFocus/releases/download/v1.0.0/demo_apk.apk) 5 | 也可以前往本工程release处自行下载 6 | # 使用方式: 7 | 请查阅本人博客文章,地址如下: 8 | [Android TV Focus效果库使用方式](https://ryanhuen.tech/blog/article/25/) 9 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | AndroidTVFocus 3 | 普通View Focus 4 | 滚动View Focus 5 | 6 | 7 | Hello blank fragment 8 | 9 | -------------------------------------------------------------------------------- /lib/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'com.github.dcendents.android-maven' 3 | 4 | group='com.github.ryanhuen' 5 | 6 | android { 7 | compileSdkVersion 27 8 | 9 | defaultConfig { 10 | minSdkVersion 23 11 | targetSdkVersion 27 12 | } 13 | 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | 21 | } -------------------------------------------------------------------------------- /lib/src/test/java/com/ryanhuen/lib/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.ryanhuen.lib; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /app/src/test/java/com/ryanhuen/androidtvfocus/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.ryanhuen.androidtvfocus; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_scrollable_view_focus.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 13 | -------------------------------------------------------------------------------- /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 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /lib/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /lib/src/androidTest/java/com/ryanhuen/lib/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.ryanhuen.lib; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.ryanhuen.lib", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the ART/Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | out/ 15 | 16 | # Gradle files 17 | .gradle/ 18 | build/ 19 | 20 | # Local configuration file (sdk path, etc) 21 | local.properties 22 | 23 | # Proguard folder generated by Eclipse 24 | proguard/ 25 | 26 | # Log Files 27 | *.log 28 | 29 | # Android Studio Navigation editor temp files 30 | .navigation/ 31 | 32 | # Android Studio captures folder 33 | captures/ 34 | 35 | # Intellij 36 | *.iml 37 | .idea/ 38 | # Keystore files 39 | *.jks 40 | 41 | # External native build folder generated in Android Studio 2.2 and later 42 | .externalNativeBuild 43 | 44 | # Google Services (e.g. APIs or Firebase) 45 | google-services.json 46 | 47 | # Freeline 48 | freeline.py 49 | freeline/ 50 | freeline_project_description.json 51 | -------------------------------------------------------------------------------- /app/src/main/res/layout/recycler_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 14 | 15 | 23 | 24 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/ryanhuen/androidtvfocus/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.ryanhuen.androidtvfocus; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.ryanhuen.androidtvfocus", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/res/layout/dialog_for_focus_demo.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 16 | 17 | 25 | 26 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 27 5 | defaultConfig { 6 | applicationId "com.ryanhuen.androidtvfocus" 7 | minSdkVersion 23 8 | targetSdkVersion 27 9 | versionCode 1 10 | versionName "1.0" 11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | } 20 | 21 | dependencies { 22 | implementation fileTree(include: ['*.jar'], dir: 'libs') 23 | implementation 'com.android.support:appcompat-v7:27.1.0' 24 | testImplementation 'junit:junit:4.12' 25 | androidTestImplementation 'com.android.support.test:runner:1.0.1' 26 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' 27 | implementation project(':lib') 28 | implementation 'com.android.support:design:27.1.0' 29 | } 30 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/java/com/ryanhuen/androidtvfocus/fragment/ScrollableViewFocusFragment.java: -------------------------------------------------------------------------------- 1 | package com.ryanhuen.androidtvfocus.fragment; 2 | 3 | 4 | import android.app.Fragment; 5 | import android.os.Bundle; 6 | import android.support.v7.widget.GridLayoutManager; 7 | import android.support.v7.widget.RecyclerView; 8 | import android.view.LayoutInflater; 9 | import android.view.View; 10 | import android.view.ViewGroup; 11 | 12 | import com.ryanhuen.androidtvfocus.R; 13 | import com.ryanhuen.androidtvfocus.adapter.SampleAdapter; 14 | import com.ryanhuen.lib.widget.FocusHighlightHelper; 15 | 16 | /** 17 | * A simple {@link Fragment} subclass. 18 | */ 19 | public class ScrollableViewFocusFragment extends Fragment { 20 | 21 | private RecyclerView mRecyclerView; 22 | 23 | public ScrollableViewFocusFragment() { 24 | // Required empty public constructor 25 | } 26 | 27 | @Override 28 | public View onCreateView(LayoutInflater inflater, ViewGroup container, 29 | Bundle savedInstanceState) { 30 | // Inflate the layout for this fragment 31 | View view = inflater.inflate(R.layout.fragment_scrollable_view_focus, container, false); 32 | mRecyclerView = view.findViewById(R.id.recycler_view); 33 | mRecyclerView.setLayoutManager( 34 | new GridLayoutManager(getActivity(), 4, 35 | GridLayoutManager.VERTICAL, false)); 36 | mRecyclerView.setAdapter(new SampleAdapter(getActivity())); 37 | mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { 38 | @Override 39 | public void onScrollStateChanged(RecyclerView recyclerView, int newState) { 40 | super.onScrollStateChanged(recyclerView, newState); 41 | if (newState != RecyclerView.SCROLL_STATE_IDLE) { 42 | FocusHighlightHelper.setMetroClipView(mRecyclerView); 43 | } else { 44 | FocusHighlightHelper.clearMetroClipView(mRecyclerView); 45 | } 46 | } 47 | }); 48 | return view; 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 13 | 14 | 20 | 21 | 30 | 31 | 40 | 41 | 42 | 43 | 47 | 48 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /app/src/main/java/com/ryanhuen/androidtvfocus/adapter/SampleAdapter.java: -------------------------------------------------------------------------------- 1 | package com.ryanhuen.androidtvfocus.adapter; 2 | 3 | import android.content.Context; 4 | import android.support.annotation.NonNull; 5 | import android.support.v7.widget.RecyclerView; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.ImageView; 10 | import android.widget.TextView; 11 | 12 | import com.ryanhuen.androidtvfocus.R; 13 | import com.ryanhuen.lib.widget.FocusHighlightHelper; 14 | import com.ryanhuen.lib.widget.FocusHighlightOptions; 15 | 16 | /** 17 | * Created by ryanhuen on 18-3-19. 18 | */ 19 | 20 | public class SampleAdapter extends RecyclerView.Adapter { 21 | 22 | private Context mContext; 23 | 24 | public SampleAdapter(Context context) { 25 | mContext = context; 26 | } 27 | 28 | @NonNull 29 | @Override 30 | public SampleViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { 31 | return new SampleViewHolder(LayoutInflater.from(mContext) 32 | .inflate(R.layout.recycler_item, parent, false)); 33 | } 34 | 35 | @Override 36 | public void onBindViewHolder(@NonNull final SampleViewHolder holder, int position) { 37 | if (position % 2 == 0) { 38 | holder.itemView.setOnFocusChangeListener(new View.OnFocusChangeListener() { 39 | @Override 40 | public void onFocusChange(View v, boolean hasFocus) { 41 | FocusHighlightHelper.focusHighlightView(holder.itemView, hasFocus, new FocusHighlightOptions()); 42 | } 43 | }); 44 | } else { 45 | holder.itemView.setOnFocusChangeListener(new View.OnFocusChangeListener() { 46 | @Override 47 | public void onFocusChange(View v, boolean hasFocus) { 48 | FocusHighlightHelper.focusHighlightView(holder.itemView, hasFocus, new FocusHighlightOptions.Builder() 49 | .specifiedViewWithBorder(holder.mIcon).build()); 50 | } 51 | }); 52 | 53 | } 54 | } 55 | 56 | @Override 57 | public int getItemCount() { 58 | return 500; 59 | } 60 | 61 | class SampleViewHolder extends RecyclerView.ViewHolder { 62 | ImageView mIcon; 63 | TextView mTitle; 64 | 65 | public SampleViewHolder(View itemView) { 66 | super(itemView); 67 | mIcon = itemView.findViewById(R.id.icon); 68 | mTitle = itemView.findViewById(R.id.title); 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /app/src/main/java/com/ryanhuen/androidtvfocus/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.ryanhuen.androidtvfocus; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.view.View; 6 | import android.widget.FrameLayout; 7 | import android.widget.LinearLayout; 8 | import android.widget.TextView; 9 | 10 | import com.ryanhuen.androidtvfocus.fragment.ScrollableViewFocusFragment; 11 | import com.ryanhuen.androidtvfocus.fragment.SimpleViewFocusFragment; 12 | import com.ryanhuen.lib.widget.FocusHighlightHelper; 13 | import com.ryanhuen.lib.widget.FocusHighlightOptions; 14 | 15 | public class MainActivity extends AppCompatActivity implements View.OnFocusChangeListener { 16 | 17 | private LinearLayout mSwitchMenu; 18 | private TextView mSimpleViewFocus; 19 | private TextView mScrollableViewFocus; 20 | private FrameLayout mMainContent; 21 | 22 | private ScrollableViewFocusFragment mScrollableViewFocusFragment; 23 | private SimpleViewFocusFragment mSimpleViewFocusFragment; 24 | 25 | @Override 26 | protected void onCreate(Bundle savedInstanceState) { 27 | super.onCreate(savedInstanceState); 28 | setContentView(R.layout.activity_main); 29 | initView(); 30 | initFragments(); 31 | } 32 | 33 | private void initFragments() { 34 | mScrollableViewFocusFragment = new ScrollableViewFocusFragment(); 35 | mSimpleViewFocusFragment = new SimpleViewFocusFragment(); 36 | } 37 | 38 | private void initView() { 39 | mSwitchMenu = findViewById(R.id.switch_menu); 40 | mSimpleViewFocus = findViewById(R.id.simple_view_focus); 41 | mScrollableViewFocus = findViewById(R.id.scrollable_view_focus); 42 | mMainContent = findViewById(R.id.main_content); 43 | 44 | mSimpleViewFocus.setOnFocusChangeListener(this); 45 | mScrollableViewFocus.setOnFocusChangeListener(this); 46 | } 47 | 48 | @Override 49 | public void onFocusChange(View v, boolean hasFocus) { 50 | v.setTag(R.id.shadow_focus_item_pivot_horizontal,FocusHighlightHelper.VIEW_SCALE_PIVOT_X_LEFT); 51 | FocusHighlightHelper.focusHighlightView(v, hasFocus, new FocusHighlightOptions()); 52 | if (v.getId() == R.id.simple_view_focus) { 53 | //simple view focus 54 | getFragmentManager().beginTransaction().replace(R.id.main_content 55 | , mSimpleViewFocusFragment).commit(); 56 | } else if (v.getId() == R.id.scrollable_view_focus) { 57 | //scrollable view focus 58 | getFragmentManager().beginTransaction().replace(R.id.main_content 59 | , mScrollableViewFocusFragment).commit(); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /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/res/layout/fragment_simple_view_focus.xml: -------------------------------------------------------------------------------- 1 | 8 | 9 | 17 | 18 | 26 | 27 | 35 | 36 | 44 | 45 | 52 | 53 | 60 | 61 | 67 | 68 | 69 |