├── leanbackcards
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── drawable-xhdpi
│ │ │ │ ├── ic_error.png
│ │ │ │ ├── ic_play.png
│ │ │ │ └── ic_tag.png
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ ├── styles.xml
│ │ │ │ └── attrs.xml
│ │ │ └── layout
│ │ │ │ ├── view_loading_card.xml
│ │ │ │ ├── widget_preview_card.xml
│ │ │ │ ├── view_tag_card.xml
│ │ │ │ ├── view_icon_card.xml
│ │ │ │ └── view_live_card.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── hitherejoe
│ │ │ └── leanbackcards
│ │ │ ├── widget
│ │ │ ├── LoopingVideoView.java
│ │ │ └── PreviewCardView.java
│ │ │ ├── TagCardView.java
│ │ │ ├── LoadingCardView.java
│ │ │ ├── IconCardView.java
│ │ │ └── LiveCardView.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── hitherejoe
│ │ └── sample
│ │ └── ApplicationTest.java
├── build.gradle
└── proguard-rules.pro
├── sample
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── drawable-xhdpi
│ │ │ │ ├── circle.png
│ │ │ │ ├── ic_loop.png
│ │ │ │ ├── ic_tag.png
│ │ │ │ └── hitherejoe.png
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── layout
│ │ │ │ ├── activity_main.xml
│ │ │ │ └── item_icon_header.xml
│ │ │ └── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── hitherejoe
│ │ │ │ └── sample
│ │ │ │ └── ui
│ │ │ │ ├── data
│ │ │ │ └── model
│ │ │ │ │ ├── Tag.java
│ │ │ │ │ ├── IconItem.java
│ │ │ │ │ └── Post.java
│ │ │ │ ├── adapter
│ │ │ │ ├── OptionsAdapter.java
│ │ │ │ ├── PostAdapter.java
│ │ │ │ └── CardAdapter.java
│ │ │ │ ├── presenter
│ │ │ │ ├── LoadingPresenter.java
│ │ │ │ ├── IconItemPresenter.java
│ │ │ │ ├── TagItemPresenter.java
│ │ │ │ ├── HeaderItemPresenter.java
│ │ │ │ └── LiveCardPresenter.java
│ │ │ │ ├── activity
│ │ │ │ └── MainActivity.java
│ │ │ │ └── fragment
│ │ │ │ └── MainFragment.java
│ │ └── AndroidManifest.xml
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── hitherejoe
│ │ └── sample
│ │ └── ApplicationTest.java
├── proguard-rules.pro
└── build.gradle
├── images
├── loading.gif
├── tag_card.png
├── icon_card.png
├── live_card.gif
└── title_image.png
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── settings.gradle
├── gradle.properties
├── gradlew.bat
├── gradlew
├── README.md
└── LICENSE.md
/leanbackcards/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/sample/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 | *iml
3 | *.iml
4 | .idea
--------------------------------------------------------------------------------
/images/loading.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hitherejoe/LeanbackCards/HEAD/images/loading.gif
--------------------------------------------------------------------------------
/images/tag_card.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hitherejoe/LeanbackCards/HEAD/images/tag_card.png
--------------------------------------------------------------------------------
/images/icon_card.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hitherejoe/LeanbackCards/HEAD/images/icon_card.png
--------------------------------------------------------------------------------
/images/live_card.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hitherejoe/LeanbackCards/HEAD/images/live_card.gif
--------------------------------------------------------------------------------
/images/title_image.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hitherejoe/LeanbackCards/HEAD/images/title_image.png
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hitherejoe/LeanbackCards/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | /local.properties
3 | /.idea/workspace.xml
4 | .DS_Store
5 | /build
6 | .idea/
7 | *iml
8 | *.iml
9 | */build
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-xhdpi/circle.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hitherejoe/LeanbackCards/HEAD/sample/src/main/res/drawable-xhdpi/circle.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-xhdpi/ic_loop.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hitherejoe/LeanbackCards/HEAD/sample/src/main/res/drawable-xhdpi/ic_loop.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-xhdpi/ic_tag.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hitherejoe/LeanbackCards/HEAD/sample/src/main/res/drawable-xhdpi/ic_tag.png
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-xhdpi/hitherejoe.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hitherejoe/LeanbackCards/HEAD/sample/src/main/res/drawable-xhdpi/hitherejoe.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hitherejoe/LeanbackCards/HEAD/sample/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hitherejoe/LeanbackCards/HEAD/sample/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hitherejoe/LeanbackCards/HEAD/sample/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hitherejoe/LeanbackCards/HEAD/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/leanbackcards/src/main/res/drawable-xhdpi/ic_error.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hitherejoe/LeanbackCards/HEAD/leanbackcards/src/main/res/drawable-xhdpi/ic_error.png
--------------------------------------------------------------------------------
/leanbackcards/src/main/res/drawable-xhdpi/ic_play.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hitherejoe/LeanbackCards/HEAD/leanbackcards/src/main/res/drawable-xhdpi/ic_play.png
--------------------------------------------------------------------------------
/leanbackcards/src/main/res/drawable-xhdpi/ic_tag.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hitherejoe/LeanbackCards/HEAD/leanbackcards/src/main/res/drawable-xhdpi/ic_tag.png
--------------------------------------------------------------------------------
/leanbackcards/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hitherejoe/LeanbackCards/HEAD/leanbackcards/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/leanbackcards/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hitherejoe/LeanbackCards/HEAD/leanbackcards/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/leanbackcards/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hitherejoe/LeanbackCards/HEAD/leanbackcards/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/leanbackcards/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hitherejoe/LeanbackCards/HEAD/leanbackcards/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':sample'
2 |
3 | include ':leanbackcards'
4 | project(':leanbackcards').projectDir = new File(settingsDir, '../LeanbackCards/leanbackcards')
5 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/hitherejoe/sample/ui/data/model/Tag.java:
--------------------------------------------------------------------------------
1 | package com.hitherejoe.sample.ui.data.model;
2 |
3 | public class Tag {
4 | public String tag;
5 | }
6 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/hitherejoe/sample/ui/data/model/IconItem.java:
--------------------------------------------------------------------------------
1 | package com.hitherejoe.sample.ui.data.model;
2 |
3 | public class IconItem {
4 | public String title;
5 | public String value;
6 | public int iconResource;
7 | }
8 |
--------------------------------------------------------------------------------
/leanbackcards/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | LeanbackCards
3 |
4 |
5 | Tag icon to represent a Hashtag
6 |
7 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/hitherejoe/sample/ui/data/model/Post.java:
--------------------------------------------------------------------------------
1 | package com.hitherejoe.sample.ui.data.model;
2 |
3 | public class Post {
4 |
5 | public String videoUrl;
6 | public String description;
7 | public String username;
8 | public int thumbnail;
9 | }
10 |
--------------------------------------------------------------------------------
/leanbackcards/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FFFFFF
4 | #455A64
5 | #607D8B
6 | #607D8B
7 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | LeanbackCards
3 |
4 | Loading card
5 | Icon card
6 | Tag card
7 | Live card
8 |
9 |
--------------------------------------------------------------------------------
/sample/src/androidTest/java/com/hitherejoe/sample/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.hitherejoe.sample;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/leanbackcards/src/androidTest/java/com/hitherejoe/sample/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.hitherejoe.sample;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/leanbackcards/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #607D8B
4 | #455A64
5 | #B2DFDB
6 | #8BC34A
7 | #212121
8 | #727272
9 | #FFFFFF
10 | #B6B6B6
11 |
--------------------------------------------------------------------------------
/leanbackcards/src/main/res/layout/view_loading_card.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
14 |
15 |
--------------------------------------------------------------------------------
/leanbackcards/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 |
4 | android {
5 | compileSdkVersion 23
6 | buildToolsVersion "23.0.2"
7 |
8 | defaultConfig {
9 | minSdkVersion 21
10 | targetSdkVersion 23
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 | compile 'com.android.support:leanback-v17:23.1.1'
25 | }
26 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
9 |
10 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/sample/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/hitherejoe/Library/Android/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 |
--------------------------------------------------------------------------------
/leanbackcards/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/hitherejoe/Library/Android/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 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/item_icon_header.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
16 |
17 |
--------------------------------------------------------------------------------
/sample/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 |
4 | android {
5 | compileSdkVersion 23
6 | buildToolsVersion "23.0.2"
7 |
8 | defaultConfig {
9 | applicationId "com.hitherejoe.leanbackcards.sample"
10 | minSdkVersion 21
11 | targetSdkVersion 23
12 | versionCode 1
13 | versionName "1.0"
14 | }
15 | buildTypes {
16 | release {
17 | minifyEnabled false
18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19 | }
20 | }
21 | }
22 |
23 | dependencies {
24 | compile fileTree(dir: 'libs', include: ['*.jar'])
25 | compile 'com.android.support:recyclerview-v7:23.1.1'
26 | compile 'com.android.support:leanback-v17:23.1.1'
27 | compile project(':leanbackcards')
28 |
29 | compile 'com.github.bumptech.glide:glide:3.6.1'
30 | }
31 |
--------------------------------------------------------------------------------
/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
--------------------------------------------------------------------------------
/sample/src/main/java/com/hitherejoe/sample/ui/adapter/OptionsAdapter.java:
--------------------------------------------------------------------------------
1 | package com.hitherejoe.sample.ui.adapter;
2 |
3 | import android.content.Context;
4 | import android.support.v17.leanback.widget.ArrayObjectAdapter;
5 | import android.support.v17.leanback.widget.Presenter;
6 | import android.support.v17.leanback.widget.PresenterSelector;
7 |
8 | import com.hitherejoe.sample.ui.data.model.IconItem;
9 | import com.hitherejoe.sample.ui.presenter.IconItemPresenter;
10 |
11 | public class OptionsAdapter extends ArrayObjectAdapter {
12 |
13 | private IconItemPresenter mOptionsItemPresenter;
14 |
15 | public OptionsAdapter(Context context) {
16 | mOptionsItemPresenter = new IconItemPresenter();
17 | setPresenterSelector(new PresenterSelector() {
18 | @Override
19 | public Presenter getPresenter(Object item) {
20 | return mOptionsItemPresenter;
21 | }
22 | });
23 | }
24 |
25 | public void addOption(IconItem option) {
26 | add(option);
27 | }
28 |
29 | }
--------------------------------------------------------------------------------
/sample/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
8 |
14 |
15 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/leanbackcards/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
13 |
14 |
21 |
22 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/hitherejoe/sample/ui/adapter/PostAdapter.java:
--------------------------------------------------------------------------------
1 | package com.hitherejoe.sample.ui.adapter;
2 |
3 | import android.content.Context;
4 | import android.support.v17.leanback.widget.ArrayObjectAdapter;
5 | import android.support.v17.leanback.widget.Presenter;
6 | import android.support.v17.leanback.widget.PresenterSelector;
7 |
8 | import com.hitherejoe.sample.ui.data.model.IconItem;
9 | import com.hitherejoe.sample.ui.data.model.Post;
10 | import com.hitherejoe.sample.ui.presenter.IconItemPresenter;
11 | import com.hitherejoe.sample.ui.presenter.LiveCardPresenter;
12 |
13 | public class PostAdapter extends ArrayObjectAdapter {
14 |
15 | private LiveCardPresenter mOptionsItemPresenter;
16 |
17 | public PostAdapter(Context context) {
18 | mOptionsItemPresenter = new LiveCardPresenter(context);
19 | setPresenterSelector(new PresenterSelector() {
20 | @Override
21 | public Presenter getPresenter(Object item) {
22 | return mOptionsItemPresenter;
23 | }
24 | });
25 | }
26 |
27 | public void addOption(Post post) {
28 | add(post);
29 | }
30 |
31 | }
--------------------------------------------------------------------------------
/sample/src/main/java/com/hitherejoe/sample/ui/presenter/LoadingPresenter.java:
--------------------------------------------------------------------------------
1 | package com.hitherejoe.sample.ui.presenter;
2 |
3 | import android.support.v17.leanback.widget.Presenter;
4 | import android.support.v4.content.ContextCompat;
5 | import android.view.ViewGroup;
6 |
7 | import com.hitherejoe.leanbackcards.LoadingCardView;
8 |
9 | public class LoadingPresenter extends Presenter {
10 |
11 | @Override
12 | public ViewHolder onCreateViewHolder(ViewGroup parent) {
13 | LoadingCardView cardView = new LoadingCardView(parent.getContext());
14 | return new ViewHolder(cardView);
15 | }
16 |
17 | @Override
18 | public void onBindViewHolder(ViewHolder viewHolder, Object item) {
19 | if (item instanceof LoadingCardView){
20 | LoadingCardView cardView = (LoadingCardView) viewHolder.view;
21 | cardView.setLoading(true);
22 | }
23 | }
24 |
25 | @Override
26 | public void onUnbindViewHolder(ViewHolder viewHolder) {
27 | if (viewHolder.view instanceof LoadingCardView) {
28 | LoadingCardView cardView = (LoadingCardView) viewHolder.view;
29 | cardView.setLoading(false);
30 | }
31 | }
32 |
33 | }
--------------------------------------------------------------------------------
/sample/src/main/java/com/hitherejoe/sample/ui/activity/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.hitherejoe.sample.ui.activity;
2 |
3 | import android.app.Activity;
4 | import android.app.Fragment;
5 | import android.os.Bundle;
6 | import android.widget.FrameLayout;
7 |
8 | import com.hitherejoe.sample.R;
9 | import com.hitherejoe.sample.ui.fragment.MainFragment;
10 |
11 | public class MainActivity extends Activity {
12 |
13 | FrameLayout mFragmentContainer;
14 |
15 | private Fragment mBrowseFragment;
16 |
17 | @Override
18 | public void onCreate(Bundle savedInstanceState) {
19 | super.onCreate(savedInstanceState);
20 | setContentView(R.layout.activity_main);
21 |
22 | mFragmentContainer = (FrameLayout) findViewById(R.id.frame_container);
23 |
24 | mBrowseFragment = new MainFragment();
25 |
26 | getFragmentManager().beginTransaction()
27 | .replace(mFragmentContainer.getId(), mBrowseFragment).commit();
28 | }
29 |
30 | public boolean isFragmentActive() {
31 | return mBrowseFragment instanceof MainFragment &&
32 | mBrowseFragment.isAdded() &&
33 | !mBrowseFragment.isDetached() &&
34 | !mBrowseFragment.isRemoving() &&
35 | !((MainFragment) mBrowseFragment).isStopping();
36 | }
37 |
38 | }
--------------------------------------------------------------------------------
/leanbackcards/src/main/res/layout/widget_preview_card.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
20 |
21 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/leanbackcards/src/main/res/layout/view_tag_card.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
20 |
21 |
33 |
34 |
--------------------------------------------------------------------------------
/leanbackcards/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 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/hitherejoe/sample/ui/presenter/IconItemPresenter.java:
--------------------------------------------------------------------------------
1 | package com.hitherejoe.sample.ui.presenter;
2 |
3 | import android.content.Context;
4 | import android.support.v17.leanback.widget.Presenter;
5 | import android.support.v4.content.ContextCompat;
6 | import android.view.ViewGroup;
7 |
8 | import com.hitherejoe.sample.R;
9 | import com.hitherejoe.sample.ui.data.model.IconItem;
10 | import com.hitherejoe.leanbackcards.IconCardView;
11 |
12 | public class IconItemPresenter extends Presenter {
13 |
14 | private static int GRID_ITEM_WIDTH = 350;
15 | private static int GRID_ITEM_HEIGHT = 400;
16 |
17 | public IconItemPresenter() { }
18 |
19 | @Override
20 | public ViewHolder onCreateViewHolder(final ViewGroup parent) {
21 | final IconCardView iconCardView = new IconCardView(parent.getContext(), R.style.IconCardStyle);
22 | return new ViewHolder(iconCardView);
23 | }
24 |
25 | @Override
26 | public void onBindViewHolder(ViewHolder viewHolder, Object item) {
27 | if (item instanceof IconItem) {
28 | IconItem iconItem = (IconItem) item;
29 | IconCardView optionView = (IconCardView) viewHolder.view;
30 | optionView.setMainImageDimensions(GRID_ITEM_WIDTH, GRID_ITEM_HEIGHT);
31 | optionView.setTitleText(iconItem.title);
32 | String value = iconItem.value;
33 | if (value != null) optionView.setDetailText(iconItem.value);
34 | Context context = viewHolder.view.getContext();
35 | optionView.setIcon(ContextCompat.getDrawable(context, iconItem.iconResource));
36 | }
37 | }
38 |
39 | @Override
40 | public void onUnbindViewHolder(ViewHolder viewHolder) { }
41 | }
--------------------------------------------------------------------------------
/sample/src/main/java/com/hitherejoe/sample/ui/presenter/TagItemPresenter.java:
--------------------------------------------------------------------------------
1 | package com.hitherejoe.sample.ui.presenter;
2 |
3 | import android.support.v17.leanback.widget.Presenter;
4 | import android.support.v4.content.ContextCompat;
5 | import android.view.ViewGroup;
6 |
7 | import com.hitherejoe.sample.R;
8 | import com.hitherejoe.leanbackcards.TagCardView;
9 |
10 | public class TagItemPresenter extends Presenter {
11 |
12 | private static int sSelectedBackgroundColor;
13 | private static int sDefaultBackgroundColor;
14 |
15 | @Override
16 | public ViewHolder onCreateViewHolder(ViewGroup parent) {
17 | sDefaultBackgroundColor = ContextCompat.getColor(parent.getContext(), R.color.primary);
18 | sSelectedBackgroundColor = ContextCompat.getColor(parent.getContext(), R.color.primary_dark);
19 |
20 | TagCardView cardView = new TagCardView(parent.getContext()) {
21 | @Override
22 | public void setSelected(boolean selected) {
23 | updateCardBackgroundColor(this, selected);
24 | super.setSelected(selected);
25 | }
26 | };
27 |
28 | cardView.setFocusable(true);
29 | cardView.setFocusableInTouchMode(true);
30 | updateCardBackgroundColor(cardView, false);
31 | return new ViewHolder(cardView);
32 | }
33 |
34 | private static void updateCardBackgroundColor(TagCardView view, boolean selected) {
35 | view.setBackgroundColor(selected ? sSelectedBackgroundColor : sDefaultBackgroundColor);
36 | }
37 |
38 | @Override
39 | public void onBindViewHolder(ViewHolder viewHolder, Object item) {
40 | if (item instanceof TagCardView) {
41 | TagCardView cardView = (TagCardView) viewHolder.view;
42 | cardView.setCardText(((TagCardView) item).getCardText());
43 | }
44 | }
45 |
46 | @Override
47 | public void onUnbindViewHolder(ViewHolder viewHolder) {
48 |
49 | }
50 |
51 | }
--------------------------------------------------------------------------------
/leanbackcards/src/main/res/layout/view_icon_card.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
18 |
19 |
20 |
21 |
29 |
30 |
39 |
40 |
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/hitherejoe/sample/ui/adapter/CardAdapter.java:
--------------------------------------------------------------------------------
1 | package com.hitherejoe.sample.ui.adapter;
2 |
3 | import android.content.Context;
4 | import android.support.v17.leanback.widget.ArrayObjectAdapter;
5 | import android.support.v17.leanback.widget.Presenter;
6 | import android.support.v17.leanback.widget.PresenterSelector;
7 |
8 | import com.hitherejoe.leanbackcards.LiveCardView;
9 | import com.hitherejoe.sample.ui.data.model.Post;
10 | import com.hitherejoe.sample.ui.presenter.IconItemPresenter;
11 | import com.hitherejoe.sample.ui.presenter.LiveCardPresenter;
12 | import com.hitherejoe.sample.ui.presenter.LoadingPresenter;
13 | import com.hitherejoe.sample.ui.presenter.TagItemPresenter;
14 | import com.hitherejoe.leanbackcards.IconCardView;
15 | import com.hitherejoe.leanbackcards.LoadingCardView;
16 | import com.hitherejoe.leanbackcards.TagCardView;
17 |
18 |
19 | public class CardAdapter extends ArrayObjectAdapter {
20 |
21 | private LoadingPresenter mLoadingPresenter;
22 | private IconItemPresenter mIconItemPresenter;
23 | private TagItemPresenter mTagItemPresenter;
24 | private LiveCardPresenter mLiveCardPresenter;
25 |
26 | public CardAdapter(Context context) {
27 | mLoadingPresenter = new LoadingPresenter();
28 | mIconItemPresenter = new IconItemPresenter();
29 | mTagItemPresenter = new TagItemPresenter();
30 | mLiveCardPresenter = new LiveCardPresenter(context);
31 | setPresenterSelector(new PresenterSelector() {
32 | @Override
33 | public Presenter getPresenter(Object item) {
34 | if (item instanceof LoadingCardView) {
35 | return mLoadingPresenter;
36 | } else if (item instanceof IconCardView) {
37 | return mIconItemPresenter;
38 | } else if (item instanceof TagCardView) {
39 | return mTagItemPresenter;
40 | } else if (item instanceof Post) {
41 | return mLiveCardPresenter;
42 | }
43 | return null;
44 | }
45 | });
46 | }
47 |
48 | }
--------------------------------------------------------------------------------
/sample/src/main/java/com/hitherejoe/sample/ui/presenter/HeaderItemPresenter.java:
--------------------------------------------------------------------------------
1 | package com.hitherejoe.sample.ui.presenter;
2 |
3 |
4 | import android.content.Context;
5 | import android.support.v17.leanback.widget.HeaderItem;
6 | import android.support.v17.leanback.widget.ListRow;
7 | import android.support.v17.leanback.widget.Presenter;
8 | import android.support.v17.leanback.widget.RowHeaderPresenter;
9 | import android.view.LayoutInflater;
10 | import android.view.View;
11 | import android.view.ViewGroup;
12 | import android.widget.TextView;
13 |
14 | import com.hitherejoe.sample.R;
15 |
16 | public class HeaderItemPresenter extends RowHeaderPresenter {
17 |
18 | private float mUnselectedAlpha;
19 |
20 | @Override
21 | public ViewHolder onCreateViewHolder(ViewGroup viewGroup) {
22 | mUnselectedAlpha = viewGroup.getResources()
23 | .getFraction(R.fraction.lb_browse_header_unselect_alpha, 1, 1);
24 | LayoutInflater inflater = (LayoutInflater) viewGroup.getContext()
25 | .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
26 |
27 | View view = inflater.inflate(R.layout.item_icon_header, null);
28 | return new ViewHolder(view);
29 | }
30 |
31 | @Override
32 | public void onBindViewHolder(Presenter.ViewHolder viewHolder, Object o) {
33 | HeaderItem headerItem = ((ListRow) o).getHeaderItem();
34 | View rootView = viewHolder.view;
35 | rootView.setAlpha(mUnselectedAlpha);
36 | TextView label = (TextView) rootView.findViewById(R.id.header_label);
37 | label.setText(headerItem.getName());
38 | }
39 |
40 | @Override
41 | public void onUnbindViewHolder(Presenter.ViewHolder viewHolder) {
42 | // no op
43 | }
44 |
45 | // TODO: TEMP - remove me when leanback onCreateViewHolder no longer sets the mUnselectAlpha,AND
46 | // also assumes the xml inflation will return a RowHeaderView
47 | @Override
48 | protected void onSelectLevelChanged(RowHeaderPresenter.ViewHolder holder) {
49 | // this is a temporary fix
50 | holder.view.setAlpha(mUnselectedAlpha + holder.getSelectLevel() *
51 | (1.0f - mUnselectedAlpha));
52 | }
53 |
54 | }
--------------------------------------------------------------------------------
/leanbackcards/src/main/java/com/hitherejoe/leanbackcards/widget/LoopingVideoView.java:
--------------------------------------------------------------------------------
1 | package com.hitherejoe.leanbackcards.widget;
2 |
3 | import android.content.Context;
4 | import android.media.MediaPlayer;
5 | import android.net.Uri;
6 | import android.util.AttributeSet;
7 | import android.widget.VideoView;
8 |
9 | public class LoopingVideoView extends VideoView {
10 |
11 | private MediaPlayer mMediaPlayer;
12 |
13 | public LoopingVideoView(Context context) {
14 | super(context);
15 | }
16 |
17 | public LoopingVideoView(Context context, AttributeSet attrs) {
18 | super(context, attrs);
19 | }
20 |
21 | public LoopingVideoView(Context context, AttributeSet attrs, int defStyleAttr) {
22 | super(context, attrs, defStyleAttr);
23 | }
24 |
25 | public LoopingVideoView(Context context,
26 | AttributeSet attrs,
27 | int defStyleAttr,
28 | int defStyleRes) {
29 | super(context, attrs, defStyleAttr, defStyleRes);
30 | }
31 |
32 | public void setupMediaPlayer(String url, final OnVideoReadyListener onVideoReadyListener) {
33 | setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
34 | @Override
35 | public void onPrepared(MediaPlayer mp) {
36 | mMediaPlayer = mp;
37 | mMediaPlayer.setLooping(true);
38 | mMediaPlayer.setVolume(0, 0);
39 | mMediaPlayer.start();
40 | onVideoReadyListener.onVideoReady();
41 | }
42 | });
43 | setOnErrorListener(new MediaPlayer.OnErrorListener() {
44 | @Override
45 | public boolean onError(MediaPlayer mp, int what, int extra) {
46 | onVideoReadyListener.onVideoError();
47 | return false;
48 | }
49 | });
50 | setVideoURI(Uri.parse(url));
51 | }
52 |
53 | public void stopMediaPlayer() {
54 | if (mMediaPlayer != null) {
55 | mMediaPlayer.stop();
56 | mMediaPlayer = null;
57 | }
58 | }
59 |
60 | public interface OnVideoReadyListener {
61 | void onVideoReady();
62 | void onVideoError();
63 | }
64 |
65 | }
--------------------------------------------------------------------------------
/leanbackcards/src/main/res/layout/view_live_card.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
10 |
11 |
15 |
16 |
23 |
24 |
35 |
36 |
47 |
48 |
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/leanbackcards/src/main/java/com/hitherejoe/leanbackcards/widget/PreviewCardView.java:
--------------------------------------------------------------------------------
1 | package com.hitherejoe.leanbackcards.widget;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.util.Log;
6 | import android.view.View;
7 | import android.widget.FrameLayout;
8 | import android.widget.ImageView;
9 | import android.widget.ProgressBar;
10 |
11 | import com.hitherejoe.leanbackcards.R;
12 |
13 | public class PreviewCardView extends FrameLayout {
14 |
15 | private FrameLayout mMainContainer;
16 | private LoopingVideoView mVideoView;
17 | private ImageView mImageView;
18 | private View mOverlayView;
19 | private ProgressBar mProgressCard;
20 | private String mVideoUrl;
21 |
22 | public PreviewCardView(Context context) {
23 | super(context);
24 | init();
25 | }
26 |
27 | public PreviewCardView(Context context, AttributeSet attrs) {
28 | super(context, attrs);
29 | init();
30 | }
31 |
32 | public PreviewCardView(Context context, AttributeSet attrs, int defStyleAttr) {
33 | super(context, attrs, defStyleAttr);
34 | init();
35 | }
36 |
37 | public PreviewCardView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
38 | super(context, attrs, defStyleAttr, defStyleRes);
39 | init();
40 | }
41 |
42 | private void init() {
43 | View view = inflate(getContext(), R.layout.widget_preview_card, this);
44 | mMainContainer = (FrameLayout) view.findViewById(R.id.main_container);
45 | mVideoView = (LoopingVideoView) view.findViewById(R.id.main_video);
46 | mImageView = (ImageView) view.findViewById(R.id.main_image);
47 | mOverlayView = view.findViewById(R.id.view_overlay);
48 | mProgressCard = (ProgressBar) view.findViewById(R.id.progress_card);
49 | }
50 |
51 | public void setVideoUrl(String videoUrl) {
52 | mVideoUrl = videoUrl;
53 | }
54 |
55 | public void setVideoViewSize(int width, int height) {
56 | mVideoView.setLayoutParams(new LayoutParams(width, height));
57 | }
58 |
59 | public ImageView getImageView() {
60 | return mImageView;
61 | }
62 |
63 | public void setLoading() {
64 | mOverlayView.setVisibility(View.VISIBLE);
65 | mProgressCard.setVisibility(View.VISIBLE);
66 | mVideoView.setVisibility(View.VISIBLE);
67 | mVideoView.setupMediaPlayer(mVideoUrl, new LoopingVideoView.OnVideoReadyListener() {
68 | @Override
69 | public void onVideoReady() {
70 | mOverlayView.setVisibility(View.INVISIBLE);
71 | mProgressCard.setVisibility(View.INVISIBLE);
72 | mImageView.setVisibility(View.INVISIBLE);
73 | }
74 |
75 | @Override
76 | public void onVideoError() {
77 | setNotPlayingViewState();
78 | }
79 | });
80 | }
81 |
82 | public void setFinished() {
83 | mVideoView.stopMediaPlayer();
84 | setNotPlayingViewState();
85 | }
86 |
87 | private void setNotPlayingViewState() {
88 | mImageView.setVisibility(View.VISIBLE);
89 | mVideoView.setVisibility(View.INVISIBLE);
90 | mOverlayView.setVisibility(View.INVISIBLE);
91 | mProgressCard.setVisibility(View.INVISIBLE);
92 | }
93 |
94 | }
--------------------------------------------------------------------------------
/leanbackcards/src/main/java/com/hitherejoe/leanbackcards/TagCardView.java:
--------------------------------------------------------------------------------
1 | package com.hitherejoe.leanbackcards;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.support.annotation.ColorInt;
6 | import android.support.annotation.DrawableRes;
7 | import android.support.v17.leanback.widget.BaseCardView;
8 | import android.support.v4.content.ContextCompat;
9 | import android.util.AttributeSet;
10 | import android.view.ContextThemeWrapper;
11 | import android.view.LayoutInflater;
12 | import android.widget.ImageView;
13 | import android.widget.RelativeLayout;
14 | import android.widget.TextView;
15 |
16 | public class TagCardView extends BaseCardView {
17 |
18 | private TextView mTagText;
19 | private ImageView mTagIcon;
20 |
21 | public TagCardView(Context context) {
22 | this(context, null);
23 | }
24 |
25 | public TagCardView(Context context, AttributeSet attrs) {
26 | this(context, attrs, R.attr.imageCardViewStyle);
27 | }
28 |
29 | public TagCardView(Context context, int styleResId) {
30 | super(new ContextThemeWrapper(context, styleResId), null, 0);
31 | buildLoadingCardView(styleResId);
32 | }
33 |
34 | public TagCardView(Context context, AttributeSet attrs, int defStyleAttr) {
35 | super(getStyledContext(context, attrs, defStyleAttr), attrs, defStyleAttr);
36 | buildLoadingCardView(getTagCardViewStyle(context, attrs, defStyleAttr));
37 | }
38 |
39 | @Override
40 | public boolean hasOverlappingRendering() {
41 | return false;
42 | }
43 |
44 | private void buildLoadingCardView(int styleResId) {
45 | setFocusable(false);
46 | setFocusableInTouchMode(false);
47 | setCardType(CARD_TYPE_MAIN_ONLY);
48 |
49 | Context context = getContext();
50 |
51 | LayoutInflater inflater = LayoutInflater.from(getContext());
52 | inflater.inflate(R.layout.view_tag_card, this);
53 | TypedArray cardAttrs = context.obtainStyledAttributes(styleResId, R.styleable.TagCardView);
54 |
55 | int backgroundColor =
56 | cardAttrs.getInt(R.styleable.TagCardView_tag_background_color,
57 | ContextCompat.getColor(context, R.color.default_header));
58 | int textColor =
59 | cardAttrs.getInt(R.styleable.TagCardView_tag_text_color,
60 | ContextCompat.getColor(context, R.color.white));
61 |
62 | int drawableResource =
63 | cardAttrs.getInt(R.styleable.TagCardView_tag_icon, R.drawable.ic_tag);
64 |
65 | mTagIcon = (ImageView) findViewById(R.id.image_icon);
66 | mTagText = (TextView) findViewById(R.id.text_tag);
67 |
68 | setCardBackgroundColor(backgroundColor);
69 | setCardTextColor(textColor);
70 | setCardIcon(drawableResource);
71 |
72 | cardAttrs.recycle();
73 | }
74 |
75 | public void setCardBackgroundColor(@ColorInt int color) {
76 | setBackgroundColor(color);
77 | }
78 |
79 | public void setCardText(String string) {
80 | mTagText.setText(string);
81 | }
82 |
83 | public void setCardTextColor(@ColorInt int color) {
84 | mTagText.setTextColor(color);
85 | }
86 |
87 | public String getCardText() {
88 | return mTagText.getText().toString();
89 | }
90 |
91 | public void setCardIcon(@DrawableRes int resource) {
92 | mTagIcon.setImageResource(resource);
93 | }
94 |
95 | private static Context getStyledContext(Context context, AttributeSet attrs, int defStyleAttr) {
96 | int style = getTagCardViewStyle(context, attrs, defStyleAttr);
97 | return new ContextThemeWrapper(context, style);
98 | }
99 |
100 | private static int getTagCardViewStyle(Context context, AttributeSet attrs, int defStyleAttr) {
101 | int style = null == attrs ? 0 : attrs.getStyleAttribute();
102 | if (0 == style) {
103 | TypedArray styledAttrs =
104 | context.obtainStyledAttributes(R.styleable.TagCardView);
105 | style = styledAttrs.getResourceId(R.styleable.TagCardView_tag_theme, 0);
106 | styledAttrs.recycle();
107 | }
108 | return style;
109 | }
110 |
111 |
112 |
113 | }
--------------------------------------------------------------------------------
/leanbackcards/src/main/java/com/hitherejoe/leanbackcards/LoadingCardView.java:
--------------------------------------------------------------------------------
1 | package com.hitherejoe.leanbackcards;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.graphics.PorterDuff;
6 | import android.support.annotation.ColorInt;
7 | import android.support.v17.leanback.widget.BaseCardView;
8 | import android.support.v4.content.ContextCompat;
9 | import android.util.AttributeSet;
10 | import android.view.ContextThemeWrapper;
11 | import android.view.LayoutInflater;
12 | import android.view.View;
13 | import android.widget.ProgressBar;
14 | import android.widget.RelativeLayout;
15 |
16 | public class LoadingCardView extends BaseCardView {
17 |
18 | private RelativeLayout mLoadingLayout;
19 | private ProgressBar mProgressBar;
20 |
21 | public LoadingCardView(Context context) {
22 | this(context, null);
23 | }
24 |
25 | public LoadingCardView(Context context, AttributeSet attrs) {
26 | this(context, attrs, R.attr.imageCardViewStyle);
27 | }
28 |
29 | public LoadingCardView(Context context, int styleResId) {
30 | super(new ContextThemeWrapper(context, styleResId), null, 0);
31 | buildLoadingCardView(styleResId);
32 | }
33 |
34 | public LoadingCardView(Context context, AttributeSet attrs, int defStyleAttr) {
35 | super(getStyledContext(context, attrs, defStyleAttr), attrs, defStyleAttr);
36 | buildLoadingCardView(getLoadingCardViewStyle(context, attrs, defStyleAttr));
37 | }
38 |
39 | @Override
40 | public boolean hasOverlappingRendering() {
41 | return false;
42 | }
43 |
44 | private void buildLoadingCardView(int styleResId) {
45 | setFocusable(false);
46 | setFocusableInTouchMode(false);
47 | setCardType(CARD_TYPE_MAIN_ONLY);
48 |
49 | Context context = getContext();
50 |
51 | LayoutInflater inflater = LayoutInflater.from(getContext());
52 | inflater.inflate(R.layout.view_loading_card, this);
53 | TypedArray cardAttrs = context.obtainStyledAttributes(styleResId, R.styleable.TagCardView);
54 |
55 | mLoadingLayout = (RelativeLayout) findViewById(R.id.layout_loading);
56 | mProgressBar = (ProgressBar) findViewById(R.id.progress_indicator);
57 |
58 | int backgroundColor =
59 | cardAttrs.getInt(R.styleable.LoadingCardView_loading_background_color,
60 | ContextCompat.getColor(context, R.color.default_header));
61 |
62 | int progressColor =
63 | cardAttrs.getInt(R.styleable.LoadingCardView_loading_progress_color,
64 | ContextCompat.getColor(context, R.color.white));
65 |
66 | setCardBackgroundColor(backgroundColor);
67 | setProgressColor(progressColor);
68 |
69 | cardAttrs.recycle();
70 | }
71 |
72 | public void setCardBackgroundColor(@ColorInt int color) {
73 | setBackgroundColor(color);
74 | }
75 |
76 | public void setProgressColor(@ColorInt int color) {
77 | mProgressBar.getIndeterminateDrawable().setColorFilter(color, PorterDuff.Mode.SRC_IN);
78 | }
79 |
80 | public boolean isLoading() {
81 | return mProgressBar.getVisibility() == View.VISIBLE;
82 | }
83 |
84 | public void setLoading(boolean isLoading) {
85 | mProgressBar.setVisibility(isLoading ? View.VISIBLE : View.GONE);
86 | }
87 |
88 | private static Context getStyledContext(Context context, AttributeSet attrs, int defStyleAttr) {
89 | int style = getLoadingCardViewStyle(context, attrs, defStyleAttr);
90 | return new ContextThemeWrapper(context, style);
91 | }
92 |
93 | private static int getLoadingCardViewStyle(Context context,
94 | AttributeSet attrs,
95 | int defStyleAttr) {
96 | int style = null == attrs ? 0 : attrs.getStyleAttribute();
97 | if (0 == style) {
98 | TypedArray styledAttrs =
99 | context.obtainStyledAttributes(R.styleable.LoadingCardView);
100 | style = styledAttrs.getResourceId(R.styleable.LoadingCardView_loading_theme, 0);
101 | styledAttrs.recycle();
102 | }
103 | return style;
104 | }
105 |
106 |
107 | }
--------------------------------------------------------------------------------
/sample/src/main/java/com/hitherejoe/sample/ui/presenter/LiveCardPresenter.java:
--------------------------------------------------------------------------------
1 | package com.hitherejoe.sample.ui.presenter;
2 |
3 | import android.content.Context;
4 | import android.graphics.drawable.Drawable;
5 | import android.support.v17.leanback.widget.Presenter;
6 | import android.support.v4.content.ContextCompat;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 |
10 | import com.bumptech.glide.Glide;
11 | import com.hitherejoe.leanbackcards.LiveCardView;
12 | import com.hitherejoe.sample.R;
13 | import com.hitherejoe.sample.ui.activity.MainActivity;
14 | import com.hitherejoe.sample.ui.data.model.Post;
15 |
16 | public class LiveCardPresenter extends Presenter {
17 |
18 | private static final int CARD_WIDTH = 300;
19 | private static final int CARD_HEIGHT = 300;
20 | private static int sSelectedBackgroundColor;
21 | private static int sDefaultBackgroundColor;
22 | private Drawable mDefaultCardImage;
23 | private Context mContext;
24 |
25 | public LiveCardPresenter(Context context) {
26 | mContext = context;
27 | }
28 |
29 | @Override
30 | public ViewHolder onCreateViewHolder(ViewGroup parent) {
31 | final Context context = parent.getContext();
32 | sDefaultBackgroundColor = ContextCompat.getColor(context, R.color.primary);
33 | sSelectedBackgroundColor = ContextCompat.getColor(context, R.color.primary_dark);
34 | mDefaultCardImage = ContextCompat.getDrawable(context, R.drawable.ic_play);
35 |
36 | final LiveCardView cardView = new LiveCardView(parent.getContext()) {
37 | @Override
38 | public void setSelected(boolean selected) {
39 | updateCardBackgroundColor(this, selected);
40 | super.setSelected(selected);
41 | }
42 | };
43 |
44 | cardView.setOnClickListener(new View.OnClickListener() {
45 | @Override
46 | public void onClick(View v) {
47 | cardView.stopVideo();
48 | }
49 | });
50 |
51 | cardView.setOnFocusChangeListener(new View.OnFocusChangeListener() {
52 | @Override
53 | public void onFocusChange(View v, boolean hasFocus) {
54 | if (hasFocus) {
55 | cardView.startVideo();
56 | } else {
57 | if (mContext instanceof MainActivity) {
58 | if (((MainActivity) mContext).isFragmentActive()) {
59 | cardView.stopVideo();
60 | }
61 | } else {
62 | cardView.stopVideo();
63 | }
64 | }
65 | }
66 | });
67 |
68 | cardView.setFocusable(true);
69 | cardView.setFocusableInTouchMode(true);
70 | updateCardBackgroundColor(cardView, false);
71 | return new ViewHolder(cardView);
72 | }
73 |
74 | private static void updateCardBackgroundColor(LiveCardView view, boolean selected) {
75 | int color = selected ? sSelectedBackgroundColor : sDefaultBackgroundColor;
76 | // Both background colors should be set because the view's background is temporarily visible
77 | // during animations.
78 | view.setBackgroundColor(color);
79 | view.findViewById(R.id.info_field).setBackgroundColor(color);
80 | }
81 |
82 | @Override
83 | public void onBindViewHolder(Presenter.ViewHolder viewHolder, Object item) {
84 | if (item instanceof Post) {
85 | Post post = (Post) item;
86 |
87 | final LiveCardView cardView = (LiveCardView) viewHolder.view;
88 | cardView.setTitleText(post.description);
89 | cardView.setContentText(post.username);
90 | cardView.setMainContainerDimensions(CARD_WIDTH, CARD_HEIGHT);
91 | int size = (int) (CARD_WIDTH * 1.25);
92 | cardView.setVideoViewSize(size, size);
93 | cardView.setVideoUrl(post.videoUrl);
94 |
95 | Glide.with(cardView.getContext())
96 | .load(post.thumbnail)
97 | .centerCrop()
98 | .error(mDefaultCardImage)
99 | .into(cardView.getMainImageView());
100 | }
101 | }
102 |
103 | @Override
104 | public void onUnbindViewHolder(Presenter.ViewHolder viewHolder) { }
105 | }
--------------------------------------------------------------------------------
/sample/src/main/java/com/hitherejoe/sample/ui/fragment/MainFragment.java:
--------------------------------------------------------------------------------
1 | package com.hitherejoe.sample.ui.fragment;
2 |
3 | import android.os.Bundle;
4 | import android.support.v17.leanback.app.BrowseFragment;
5 | import android.support.v17.leanback.widget.ArrayObjectAdapter;
6 | import android.support.v17.leanback.widget.HeaderItem;
7 | import android.support.v17.leanback.widget.ListRow;
8 | import android.support.v17.leanback.widget.ListRowPresenter;
9 | import android.support.v17.leanback.widget.Presenter;
10 | import android.support.v17.leanback.widget.PresenterSelector;
11 | import android.support.v4.content.ContextCompat;
12 |
13 | import com.hitherejoe.leanbackcards.LoadingCardView;
14 | import com.hitherejoe.leanbackcards.TagCardView;
15 | import com.hitherejoe.sample.ui.adapter.CardAdapter;
16 | import com.hitherejoe.sample.ui.adapter.OptionsAdapter;
17 | import com.hitherejoe.sample.ui.adapter.PostAdapter;
18 | import com.hitherejoe.sample.ui.data.model.IconItem;
19 | import com.hitherejoe.sample.ui.data.model.Post;
20 | import com.hitherejoe.sample.ui.presenter.HeaderItemPresenter;
21 | import com.hitherejoe.sample.R;
22 |
23 | public class MainFragment extends BrowseFragment {
24 |
25 | private ArrayObjectAdapter mRowsAdapter;
26 |
27 | private boolean mIsStopping;
28 |
29 | @Override
30 | public void onActivityCreated(Bundle savedInstanceState) {
31 | super.onActivityCreated(savedInstanceState);
32 | mRowsAdapter = new ArrayObjectAdapter(new ListRowPresenter());
33 | setAdapter(mRowsAdapter);
34 |
35 | setupUIElements();
36 | addCardRows();
37 | }
38 |
39 | @Override
40 | public void onStart() {
41 | super.onStart();
42 | mIsStopping = false;
43 | }
44 |
45 | @Override
46 | public void onStop() {
47 | super.onStop();
48 | mIsStopping = true;
49 | }
50 |
51 | public boolean isStopping() {
52 | return mIsStopping;
53 | }
54 |
55 | private void setupUIElements() {
56 | setTitle(getString(R.string.app_name));
57 | setHeadersState(HEADERS_ENABLED);
58 | setHeadersTransitionOnBackEnabled(true);
59 | setBrandColor(ContextCompat.getColor(getActivity(), R.color.primary));
60 | setSearchAffordanceColor(ContextCompat.getColor(getActivity(), R.color.accent));
61 | setHeaderPresenterSelector(new PresenterSelector() {
62 | @Override
63 | public Presenter getPresenter(Object o) {
64 | return new HeaderItemPresenter();
65 | }
66 | });
67 | }
68 |
69 | private void addCardRows() {
70 | CardAdapter mLoadingCardAdapter = new CardAdapter(getActivity());
71 | mLoadingCardAdapter.add(new LoadingCardView(getActivity(), R.style.LoadingCardStyle));
72 | HeaderItem gridLoadingCardHeader =
73 | new HeaderItem(mRowsAdapter.size(), getString(R.string.header_text_loading_card));
74 | mRowsAdapter.add(new ListRow(gridLoadingCardHeader, mLoadingCardAdapter));
75 |
76 | OptionsAdapter mIconCardAdapter = new OptionsAdapter(getActivity());
77 | IconItem iconItem = new IconItem();
78 | iconItem.title = "auto-loop";
79 | iconItem.value = "enabled";
80 | iconItem.iconResource = R.drawable.ic_loop;
81 | mIconCardAdapter.addOption(iconItem);
82 | HeaderItem gridIconCardHeader =
83 | new HeaderItem(mRowsAdapter.size(), getString(R.string.header_text_icon_card));
84 | mRowsAdapter.add(new ListRow(gridIconCardHeader, mIconCardAdapter));
85 |
86 | CardAdapter mTagCardAdapter = new CardAdapter(getActivity());
87 | TagCardView tagCardView = new TagCardView(getActivity());
88 | tagCardView.setCardText("hitherejoe");
89 | mTagCardAdapter.add(tagCardView);
90 | HeaderItem gridTagCardHeader =
91 | new HeaderItem(mRowsAdapter.size(), getString(R.string.header_text_tag_card));
92 | mRowsAdapter.add(new ListRow(gridTagCardHeader, mTagCardAdapter));
93 |
94 | PostAdapter mVideoCardAdapter = new PostAdapter(getActivity());
95 | Post post = new Post();
96 | post.username = "hitherejoe";
97 | post.description = "Just a video!";
98 | post.thumbnail = R.drawable.hitherejoe;
99 | post.videoUrl =
100 | "http://v.cdn.vine.co/r/videos/CF9585B3A31290758684187713536_43febf64eb6.4.0.3440879595394339929.mp4";
101 | mVideoCardAdapter.addOption(post);
102 | HeaderItem gridLiveCardHeader =
103 | new HeaderItem(mRowsAdapter.size(), getString(R.string.header_text_live_card));
104 | mRowsAdapter.add(new ListRow(gridLiveCardHeader, mVideoCardAdapter));
105 | }
106 |
107 | }
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # LeanbackCards
2 |
3 |
4 |
5 |
6 |
7 | Leanback cards is a Widget library for use with Android TV applications. It provides an extended set of
8 | customisable content cards to enhance your User Interfaces.
9 |
10 | To begin with, you''ll need to add the dependency to your project as below:
11 |
12 | ```gradle
13 | compile 'com.hitherejoe.leanback:leanbackcards:0.1.0'
14 | ```
15 |
16 | Think of this as a playground to try out the cards quickly and easily - so feel free to take the code and use it for the components you need!
17 |
18 | The cards currently include:
19 |
20 | ## Live Card
21 |
22 |
23 |
24 |
25 |
26 | A live card allows you to show a looping video when the card view becomes focused, allowing your
27 | browsing experience to feel more dynamic. You can add a live card in several ways:
28 |
29 | - By creating a new instance and setting it's properties programatically:
30 |
31 | ```java
32 | LiveCardView liveCardView = new LiveCardView(Context context);
33 | ```
34 |
35 | ```java
36 | liveCardView.setVideoViewSize(width, height)
37 | liveCardView.setVideoUrl(videoUrl);
38 | liveCardView.startVideo();
39 | liveCardView.stopVideo();
40 | liveCardView.setCardBackgroundColor(R.color.primary);
41 | liveCardView.setTitleText(getString(R.string.title));
42 | liveCardView.setTextColor(R.color.white);
43 | ```
44 |
45 | - By creating a new instance and passing in a style:
46 |
47 | ```java
48 | LiveCardView liveCardView = new LiveCardView(Context context, AttributeSet attrs);
49 | ```
50 |
51 | ```xml
52 |
56 | ```
57 |
58 | ## Loading Card
59 |
60 |
61 |
62 |
63 |
64 | A loading card allows you to show a simple progress bar to make the user aware that content is being
65 | loaded. You can add a loading card in several ways:
66 |
67 | - By creating a new instance and setting it's properties programatically:
68 |
69 | ```java
70 | LoadingCardView loadingCardView = new LoadingCardView(Context context)
71 | ```
72 |
73 | It's background color can be set using:
74 |
75 | ```java
76 | loadingCardView.setCardBackgroundColor(R.color.primary)
77 | ```
78 |
79 | and you can check it is loading and set it's loading state like so:
80 |
81 | ```java
82 | loadingCardView.setLoading(true);
83 | loadingCardView.setCardBackgroundColor(R.color.primary);
84 | loadingCardView.setProgressColor(R.color.white);
85 | boolean isLoading = loadingCardView.isLoading();
86 | ```
87 |
88 | - By creating a new instance and passing in a style:
89 |
90 | ```java
91 | LoadingCardView loadingCardView = new LoadingCardView(Context context, AttributeSet attrs)
92 | ```
93 |
94 | ```xml
95 |
99 | ```
100 |
101 | ## Tag Card
102 |
103 |
104 |
105 |
106 |
107 | A tag card allows you to show an icon/text pair. You can add a tag card in several ways:
108 |
109 | - By creating a new instance and setting it's properties programatically:
110 |
111 | ```java
112 | TagCardView tagCardView = new TagCardView(Context context)
113 | ```
114 |
115 | ```java
116 | tagCardView.setCardBackgroundColor(R.color.primary)
117 | tagCardView.setCardText(R.color.primary)
118 | tagCardView.setCardTextColor(R.color.primary)
119 | tagCardView.setCardIcon(R.drawable.ic_tag)
120 | ```
121 |
122 | - By creating a new instance and passing in a style:
123 |
124 | ```java
125 | TagCardView tagCardView = new TagCardView(Context context, AttributeSet attrs)
126 | ```
127 |
128 | ```xml
129 |
134 | ```
135 |
136 | ## Icon Card
137 |
138 |
139 |
140 |
141 |
142 | An icon card allows you to display a title/detail pair with an icon for visual representation. You
143 | can add an icon card in several ways:
144 |
145 | - By creating a new instance and setting it's properties programatically:
146 |
147 | ```java
148 | IconCardView iconCardView = new IconCardView(Context context)
149 | ```
150 |
151 | ```java
152 | iconCardView.setCardBackgroundColor(R.color.primary);
153 | iconCardView.setDetailBackgroundColor(R.color.primary_dark);
154 | iconCardView.setTitleText(getString(R.string.your_string));
155 | iconCardView.setDetailText(getString(R.string.your_string));
156 | iconCardView.setTitleTextColor(R.color.white);
157 | iconCardView.setDetailTextColor(R.color.white);
158 | iconCardView.setIcon(R.drawable.ic_icon);
159 | ```
160 |
161 | - By creating a new instance and passing in a style:
162 |
163 | ```java
164 | IconCardView iconCardView = new IconCardView(Context context, AttributeSet attrs)
165 | ```
166 |
167 | ```xml
168 |
175 | ```
176 |
--------------------------------------------------------------------------------
/leanbackcards/src/main/java/com/hitherejoe/leanbackcards/IconCardView.java:
--------------------------------------------------------------------------------
1 | package com.hitherejoe.leanbackcards;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.graphics.drawable.Drawable;
6 | import android.support.annotation.ColorInt;
7 | import android.support.annotation.DrawableRes;
8 | import android.support.v17.leanback.widget.BaseCardView;
9 | import android.support.v4.content.ContextCompat;
10 | import android.util.AttributeSet;
11 | import android.view.ContextThemeWrapper;
12 | import android.view.LayoutInflater;
13 | import android.view.View;
14 | import android.view.ViewGroup;
15 | import android.widget.ImageView;
16 | import android.widget.LinearLayout;
17 | import android.widget.RelativeLayout;
18 | import android.widget.TextView;
19 |
20 | public class IconCardView extends BaseCardView {
21 |
22 | private RelativeLayout mLayout;
23 | private LinearLayout mDetail;
24 | private ImageView mIcon;
25 | private TextView mTitle;
26 | private TextView mValue;
27 |
28 | public IconCardView(Context context) {
29 | this(context, null);
30 | }
31 |
32 | public IconCardView(Context context, AttributeSet attrs) {
33 | this(context, attrs, R.attr.imageCardViewStyle);
34 | }
35 |
36 | public IconCardView(Context context, int styleResId) {
37 | super(new ContextThemeWrapper(context, styleResId), null, 0);
38 | buildIconCardView(styleResId);
39 | }
40 |
41 | public IconCardView(Context context, AttributeSet attrs, int defStyleAttr) {
42 | super(getStyledContext(context, attrs, defStyleAttr), attrs, defStyleAttr);
43 | buildIconCardView(getIconCardViewStyle(context, attrs, defStyleAttr));
44 | }
45 |
46 | @Override
47 | public boolean hasOverlappingRendering() {
48 | return false;
49 | }
50 |
51 | private void buildIconCardView(int styleResId) {
52 | setFocusable(true);
53 | setFocusableInTouchMode(true);
54 | setCardType(CARD_TYPE_MAIN_ONLY);
55 |
56 | Context context = getContext();
57 |
58 | LayoutInflater inflater = LayoutInflater.from(context);
59 | inflater.inflate(R.layout.view_icon_card, this);
60 | TypedArray cardAttrs = context.obtainStyledAttributes(styleResId, R.styleable.IconCardView);
61 |
62 | int headerBackgroundColor =
63 | cardAttrs.getInt(R.styleable.IconCardView_icon_title_background_color,
64 | ContextCompat.getColor(context, R.color.default_header));
65 | int detailBackgroundColor =
66 | cardAttrs.getInt(R.styleable.IconCardView_icon_detail_background_color,
67 | ContextCompat.getColor(context, R.color.default_detail));
68 | int titleTextColor =
69 | cardAttrs.getInt(R.styleable.IconCardView_icon_title_text_color,
70 | ContextCompat.getColor(context, R.color.white));
71 | int detailTextColor =
72 | cardAttrs.getInt(R.styleable.IconCardView_icon_detail_text_color,
73 | ContextCompat.getColor(context, R.color.white));
74 |
75 | int drawableResource =
76 | cardAttrs.getInt(R.styleable.IconCardView_icon_header_icon, R.drawable.ic_error);
77 |
78 | mLayout = (RelativeLayout) findViewById(R.id.layout_option_card);
79 | mDetail = (LinearLayout) findViewById(R.id.layout_detail);
80 | mIcon = (ImageView) findViewById(R.id.image_option);
81 | mTitle = (TextView) findViewById(R.id.text_option_title);
82 | mValue = (TextView) findViewById(R.id.text_option_value);
83 |
84 | setCardBackgroundColor(headerBackgroundColor);
85 | setDetailBackgroundColor(detailBackgroundColor);
86 | setTitleTextColor(titleTextColor);
87 | setDetailTextColor(detailTextColor);
88 | setIcon(drawableResource);
89 |
90 | cardAttrs.recycle();
91 | }
92 |
93 | public void setMainImageDimensions(int width, int height) {
94 | ViewGroup.LayoutParams lp = mLayout.getLayoutParams();
95 | lp.width = width;
96 | lp.height = height;
97 | mLayout.setLayoutParams(lp);
98 | }
99 |
100 | public void setIcon(@DrawableRes Drawable drawable) {
101 | mIcon.setImageDrawable(drawable);
102 | }
103 |
104 | public void setIcon(@DrawableRes int drawable) {
105 | mIcon.setImageResource(drawable);
106 | }
107 |
108 | public void setTitleText(String titleText) {
109 | mTitle.setText(titleText);
110 | }
111 |
112 | public void setDetailText(String detailText) {
113 | mValue.setText(detailText);
114 | }
115 |
116 | public void setTitleTextColor(@ColorInt int color) {
117 | mTitle.setTextColor(color);
118 | }
119 |
120 | public void setDetailTextColor(@ColorInt int color) {
121 | mValue.setTextColor(color);
122 | }
123 |
124 | public void setCardBackgroundColor(@ColorInt int color) {
125 | setBackgroundColor(color);
126 | }
127 |
128 | public void setDetailBackgroundColor(@ColorInt int color) {
129 | mDetail.setBackgroundColor(color);
130 | }
131 |
132 | private static Context getStyledContext(Context context, AttributeSet attrs, int defStyleAttr) {
133 | int style = getIconCardViewStyle(context, attrs, defStyleAttr);
134 | return new ContextThemeWrapper(context, style);
135 | }
136 |
137 | private static int getIconCardViewStyle(Context context, AttributeSet attrs, int defStyleAttr) {
138 | int style = null == attrs ? 0 : attrs.getStyleAttribute();
139 | if (0 == style) {
140 | TypedArray styledAttrs =
141 | context.obtainStyledAttributes(R.styleable.IconCardView);
142 | style = styledAttrs.getResourceId(R.styleable.IconCardView_icon_theme, 0);
143 | styledAttrs.recycle();
144 | }
145 | return style;
146 | }
147 |
148 | }
--------------------------------------------------------------------------------
/leanbackcards/src/main/java/com/hitherejoe/leanbackcards/LiveCardView.java:
--------------------------------------------------------------------------------
1 | package com.hitherejoe.leanbackcards;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.support.annotation.ColorInt;
6 | import android.support.v17.leanback.widget.BaseCardView;
7 | import android.support.v4.content.ContextCompat;
8 | import android.util.AttributeSet;
9 | import android.view.ContextThemeWrapper;
10 | import android.view.LayoutInflater;
11 | import android.view.View;
12 | import android.view.ViewGroup;
13 | import android.widget.ImageView;
14 | import android.widget.TextView;
15 |
16 | import com.hitherejoe.leanbackcards.widget.PreviewCardView;
17 |
18 | public class LiveCardView extends BaseCardView {
19 |
20 | private PreviewCardView mPreviewCard;
21 |
22 | private TextView mTitleView;
23 | private TextView mContentView;
24 | private boolean mAttachedToWindow;
25 |
26 | public LiveCardView(Context context) {
27 | this(context, null);
28 | }
29 |
30 | public LiveCardView(Context context, AttributeSet attrs) {
31 | this(context, attrs, R.attr.imageCardViewStyle);
32 | }
33 |
34 | public LiveCardView(Context context, int styleResId) {
35 | super(new ContextThemeWrapper(context, styleResId), null, 0);
36 | buildImageCardView(styleResId);
37 | }
38 |
39 | public LiveCardView(Context context, AttributeSet attrs, int defStyleAttr) {
40 | super(getStyledContext(context, attrs, defStyleAttr), attrs, defStyleAttr);
41 | buildImageCardView(getImageCardViewStyle(context, attrs, defStyleAttr));
42 | }
43 |
44 | @Override
45 | public boolean hasOverlappingRendering() {
46 | return false;
47 | }
48 |
49 | @Override
50 | protected void onAttachedToWindow() {
51 | super.onAttachedToWindow();
52 | mAttachedToWindow = true;
53 | ImageView mImageView = mPreviewCard.getImageView();
54 | if (mImageView.getAlpha() == 0) fadeIn();
55 | }
56 |
57 | @Override
58 | protected void onDetachedFromWindow() {
59 | ImageView mImageView = mPreviewCard.getImageView();
60 | mAttachedToWindow = false;
61 | mImageView.animate().cancel();
62 | mImageView.setAlpha(1f);
63 | super.onDetachedFromWindow();
64 | }
65 |
66 | private void buildImageCardView(int styleResId) {
67 | setFocusable(true);
68 | setFocusableInTouchMode(true);
69 |
70 | Context context = getContext();
71 | LayoutInflater inflater = LayoutInflater.from(context);
72 | View view = inflater.inflate(R.layout.view_live_card, this);
73 |
74 | mPreviewCard = (PreviewCardView) view.findViewById(R.id.layout_preview_card);
75 | mTitleView = (TextView) findViewById(R.id.title_text);
76 | mContentView = (TextView) findViewById(R.id.content_text);
77 |
78 | TypedArray cardAttrs =
79 | getContext().obtainStyledAttributes(styleResId, R.styleable.LiveCardView);
80 |
81 | int cardBackgroundColor =
82 | cardAttrs.getInt(R.styleable.LiveCardView_live_background_color,
83 | ContextCompat.getColor(context, R.color.default_detail));
84 | int textColor =
85 | cardAttrs.getInt(R.styleable.LiveCardView_live_text_color,
86 | ContextCompat.getColor(context, R.color.white));
87 |
88 | setTextColor(textColor);
89 | setCardBackgroundColor(cardBackgroundColor);
90 |
91 | cardAttrs.recycle();
92 | }
93 |
94 | public void setMainContainerDimensions(int width, int height) {
95 | ViewGroup.LayoutParams lp = mPreviewCard.getLayoutParams();
96 | lp.width = width;
97 | lp.height = height;
98 | mPreviewCard.setLayoutParams(lp);
99 | }
100 |
101 | public final ImageView getMainImageView() {
102 | return mPreviewCard.getImageView();
103 | }
104 |
105 | public void setCardBackgroundColor(@ColorInt int color) {
106 | setBackgroundColor(color);
107 | }
108 |
109 | public void setTitleText(CharSequence text) {
110 | mTitleView.setText(text);
111 | }
112 |
113 | public void setContentText(CharSequence text) {
114 | mContentView.setText(text);
115 | }
116 |
117 | public void setTextColor(@ColorInt int color) {
118 | mTitleView.setTextColor(color);
119 | mContentView.setTextColor(color);
120 | }
121 |
122 | public void setVideoUrl(String url) {
123 | mPreviewCard.setVideoUrl(url);
124 | }
125 |
126 | public void startVideo() {
127 | mPreviewCard.setLoading();
128 | }
129 |
130 | public void setVideoViewSize(int width, int height) {
131 | mPreviewCard.setVideoViewSize(width, height);
132 | }
133 |
134 | public void stopVideo() {
135 | mPreviewCard.setFinished();
136 | }
137 |
138 | private static Context getStyledContext(Context context, AttributeSet attrs, int defStyleAttr) {
139 | int style = getImageCardViewStyle(context, attrs, defStyleAttr);
140 | return new ContextThemeWrapper(context, style);
141 | }
142 |
143 | private static int getImageCardViewStyle(Context context, AttributeSet attrs, int defStyleAttr) {
144 | int style = null == attrs ? 0 : attrs.getStyleAttribute();
145 | if (0 == style) {
146 | TypedArray styledAttrs = context.obtainStyledAttributes(R.styleable.LiveCardView);
147 | style = styledAttrs.getResourceId(R.styleable.LiveCardView_live_theme, 0);
148 | styledAttrs.recycle();
149 | }
150 | return style;
151 | }
152 |
153 | private void fadeIn() {
154 | ImageView mImageView = mPreviewCard.getImageView();
155 | mImageView.setAlpha(0f);
156 | if (mAttachedToWindow) {
157 | int duration =
158 | mImageView.getResources().getInteger(android.R.integer.config_shortAnimTime);
159 | mImageView.animate().alpha(1f).setDuration(duration);
160 | }
161 | }
162 |
163 | }
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | Apache License
2 | ==============
3 |
4 | _Version 2.0, January 2004_
5 | _<>_
6 |
7 | ### Terms and Conditions for use, reproduction, and distribution
8 |
9 | #### 1. Definitions
10 |
11 | “License” shall mean the terms and conditions for use, reproduction, and
12 | distribution as defined by Sections 1 through 9 of this document.
13 |
14 | “Licensor” shall mean the copyright owner or entity authorized by the copyright
15 | owner that is granting the License.
16 |
17 | “Legal Entity” shall mean the union of the acting entity and all other entities
18 | that control, are controlled by, or are under common control with that entity.
19 | For the purposes of this definition, “control” means **(i)** the power, direct or
20 | indirect, to cause the direction or management of such entity, whether by
21 | contract or otherwise, or **(ii)** ownership of fifty percent (50%) or more of the
22 | outstanding shares, or **(iii)** beneficial ownership of such entity.
23 |
24 | “You” (or “Your”) shall mean an individual or Legal Entity exercising
25 | permissions granted by this License.
26 |
27 | “Source” form shall mean the preferred form for making modifications, including
28 | but not limited to software source code, documentation source, and configuration
29 | files.
30 |
31 | “Object” form shall mean any form resulting from mechanical transformation or
32 | translation of a Source form, including but not limited to compiled object code,
33 | generated documentation, and conversions to other media types.
34 |
35 | “Work” shall mean the work of authorship, whether in Source or Object form, made
36 | available under the License, as indicated by a copyright notice that is included
37 | in or attached to the work (an example is provided in the Appendix below).
38 |
39 | “Derivative Works” shall mean any work, whether in Source or Object form, that
40 | is based on (or derived from) the Work and for which the editorial revisions,
41 | annotations, elaborations, or other modifications represent, as a whole, an
42 | original work of authorship. For the purposes of this License, Derivative Works
43 | shall not include works that remain separable from, or merely link (or bind by
44 | name) to the interfaces of, the Work and Derivative Works thereof.
45 |
46 | “Contribution” shall mean any work of authorship, including the original version
47 | of the Work and any modifications or additions to that Work or Derivative Works
48 | thereof, that is intentionally submitted to Licensor for inclusion in the Work
49 | by the copyright owner or by an individual or Legal Entity authorized to submit
50 | on behalf of the copyright owner. For the purposes of this definition,
51 | “submitted” means any form of electronic, verbal, or written communication sent
52 | to the Licensor or its representatives, including but not limited to
53 | communication on electronic mailing lists, source code control systems, and
54 | issue tracking systems that are managed by, or on behalf of, the Licensor for
55 | the purpose of discussing and improving the Work, but excluding communication
56 | that is conspicuously marked or otherwise designated in writing by the copyright
57 | owner as “Not a Contribution.”
58 |
59 | “Contributor” shall mean Licensor and any individual or Legal Entity on behalf
60 | of whom a Contribution has been received by Licensor and subsequently
61 | incorporated within the Work.
62 |
63 | #### 2. Grant of Copyright License
64 |
65 | Subject to the terms and conditions of this License, each Contributor hereby
66 | grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
67 | irrevocable copyright license to reproduce, prepare Derivative Works of,
68 | publicly display, publicly perform, sublicense, and distribute the Work and such
69 | Derivative Works in Source or Object form.
70 |
71 | #### 3. Grant of Patent License
72 |
73 | Subject to the terms and conditions of this License, each Contributor hereby
74 | grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
75 | irrevocable (except as stated in this section) patent license to make, have
76 | made, use, offer to sell, sell, import, and otherwise transfer the Work, where
77 | such license applies only to those patent claims licensable by such Contributor
78 | that are necessarily infringed by their Contribution(s) alone or by combination
79 | of their Contribution(s) with the Work to which such Contribution(s) was
80 | submitted. If You institute patent litigation against any entity (including a
81 | cross-claim or counterclaim in a lawsuit) alleging that the Work or a
82 | Contribution incorporated within the Work constitutes direct or contributory
83 | patent infringement, then any patent licenses granted to You under this License
84 | for that Work shall terminate as of the date such litigation is filed.
85 |
86 | #### 4. Redistribution
87 |
88 | You may reproduce and distribute copies of the Work or Derivative Works thereof
89 | in any medium, with or without modifications, and in Source or Object form,
90 | provided that You meet the following conditions:
91 |
92 | * **(a)** You must give any other recipients of the Work or Derivative Works a copy of
93 | this License; and
94 | * **(b)** You must cause any modified files to carry prominent notices stating that You
95 | changed the files; and
96 | * **(c)** You must retain, in the Source form of any Derivative Works that You distribute,
97 | all copyright, patent, trademark, and attribution notices from the Source form
98 | of the Work, excluding those notices that do not pertain to any part of the
99 | Derivative Works; and
100 | * **(d)** If the Work includes a “NOTICE” text file as part of its distribution, then any
101 | Derivative Works that You distribute must include a readable copy of the
102 | attribution notices contained within such NOTICE file, excluding those notices
103 | that do not pertain to any part of the Derivative Works, in at least one of the
104 | following places: within a NOTICE text file distributed as part of the
105 | Derivative Works; within the Source form or documentation, if provided along
106 | with the Derivative Works; or, within a display generated by the Derivative
107 | Works, if and wherever such third-party notices normally appear. The contents of
108 | the NOTICE file are for informational purposes only and do not modify the
109 | License. You may add Your own attribution notices within Derivative Works that
110 | You distribute, alongside or as an addendum to the NOTICE text from the Work,
111 | provided that such additional attribution notices cannot be construed as
112 | modifying the License.
113 |
114 | You may add Your own copyright statement to Your modifications and may provide
115 | additional or different license terms and conditions for use, reproduction, or
116 | distribution of Your modifications, or for any such Derivative Works as a whole,
117 | provided Your use, reproduction, and distribution of the Work otherwise complies
118 | with the conditions stated in this License.
119 |
120 | #### 5. Submission of Contributions
121 |
122 | Unless You explicitly state otherwise, any Contribution intentionally submitted
123 | for inclusion in the Work by You to the Licensor shall be under the terms and
124 | conditions of this License, without any additional terms or conditions.
125 | Notwithstanding the above, nothing herein shall supersede or modify the terms of
126 | any separate license agreement you may have executed with Licensor regarding
127 | such Contributions.
128 |
129 | #### 6. Trademarks
130 |
131 | This License does not grant permission to use the trade names, trademarks,
132 | service marks, or product names of the Licensor, except as required for
133 | reasonable and customary use in describing the origin of the Work and
134 | reproducing the content of the NOTICE file.
135 |
136 | #### 7. Disclaimer of Warranty
137 |
138 | Unless required by applicable law or agreed to in writing, Licensor provides the
139 | Work (and each Contributor provides its Contributions) on an “AS IS” BASIS,
140 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
141 | including, without limitation, any warranties or conditions of TITLE,
142 | NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are
143 | solely responsible for determining the appropriateness of using or
144 | redistributing the Work and assume any risks associated with Your exercise of
145 | permissions under this License.
146 |
147 | #### 8. Limitation of Liability
148 |
149 | In no event and under no legal theory, whether in tort (including negligence),
150 | contract, or otherwise, unless required by applicable law (such as deliberate
151 | and grossly negligent acts) or agreed to in writing, shall any Contributor be
152 | liable to You for damages, including any direct, indirect, special, incidental,
153 | or consequential damages of any character arising as a result of this License or
154 | out of the use or inability to use the Work (including but not limited to
155 | damages for loss of goodwill, work stoppage, computer failure or malfunction, or
156 | any and all other commercial damages or losses), even if such Contributor has
157 | been advised of the possibility of such damages.
158 |
159 | #### 9. Accepting Warranty or Additional Liability
160 |
161 | While redistributing the Work or Derivative Works thereof, You may choose to
162 | offer, and charge a fee for, acceptance of support, warranty, indemnity, or
163 | other liability obligations and/or rights consistent with this License. However,
164 | in accepting such obligations, You may act only on Your own behalf and on Your
165 | sole responsibility, not on behalf of any other Contributor, and only if You
166 | agree to indemnify, defend, and hold each Contributor harmless for any liability
167 | incurred by, or claims asserted against, such Contributor by reason of your
168 | accepting any such warranty or additional liability.
169 |
170 | _END OF TERMS AND CONDITIONS_
171 |
172 | ### APPENDIX: How to apply the Apache License to your work
173 |
174 | To apply the Apache License to your work, attach the following boilerplate
175 | notice, with the fields enclosed by brackets `[]` replaced with your own
176 | identifying information. (Don't include the brackets!) The text should be
177 | enclosed in the appropriate comment syntax for the file format. We also
178 | recommend that a file or class name and description of purpose be included on
179 | the same “printed page” as the copyright notice for easier identification within
180 | third-party archives.
181 |
182 | Copyright [yyyy] [name of copyright owner]
183 |
184 | Licensed under the Apache License, Version 2.0 (the "License");
185 | you may not use this file except in compliance with the License.
186 | You may obtain a copy of the License at
187 |
188 | http://www.apache.org/licenses/LICENSE-2.0
189 |
190 | Unless required by applicable law or agreed to in writing, software
191 | distributed under the License is distributed on an "AS IS" BASIS,
192 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
193 | See the License for the specific language governing permissions and
194 | limitations under the License.
195 |
--------------------------------------------------------------------------------