Coder Social home page Coder Social logo

trendingtechnology / simplerecommendationsandroidtv Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ederdoski/simplerecommendationsandroidtv

0.0 1.0 0.0 1.53 MB

This project is a simple interface to facilitate the use of the Recommendations Row of AndroidTV

Java 100.00%

simplerecommendationsandroidtv's Introduction

Android Simple Recommendations Row of AndroidTV

Example

Introduction

AndroidTV allows you to communicate through an API to the TV launcher, which allows you to easily access the content of your application without having to enter. This project is a simple interface to facilitate the use of the Row of Android TV Recommendations, trying to show content cards in the launcher of AndroidTV devices making a minimum configuration, I hope it saves you programming time :).

Install

You can download library files from JCenter or GitHub.

LatestVersion is 1.0.1

Add the following in your app's build.gradle file:

repositories {
  jcenter()
}

dependencies {
   implementation 'com.ederdoski.recommendations:launcherRecommendations:1.0.1' 
}

Usage

  • In Manifest
<manifest>
    ...
     <application>
        ....

       <receiver
            android:name="com.ederdoski.launcherRecommendations.recommendations.RecommendationReceiver"
            android:enabled="true"
            android:exported="false">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
        </receiver>

        <service
            android:name="com.ederdoski.launcherRecommendations.recommendations.UpdateRecommendationsService"
            android:enabled="true" />

    </application>

</manifest>
  • In Java
  1. Create and insert data into an ArrayList where you will place the content you want to display in the Launcher, For your comfort there are 3 different constructors, use the one that best suits your needs.

Warning the ID field should only contain numbers Warning

  • Constructor 1: It's the simplest one just needs a series of basic data to work.
   ArrayList<LauncherRecommended> aRecommendedContent = new ArrayList<>();
   aRecommendedContent.add(new LauncherRecommended("INSERT_ID_ONLY_NUMBER", "INSERT_TITLE", "INSERT_DESCRIPTION", "INSERT_URL_IMG"));
  • Constructor 2: You can add an Extra String parameter, and then obtain it when the user presses the corresponding card.
   ArrayList<LauncherRecommended> aRecommendedContent = new ArrayList<>();
   aRecommendedContent.add(new LauncherRecommended("INSERT_ID_ONLY_NUMBER", "INSERT_TITLE", "INSERT_DESCRIPTION", "INSERT_URL_IMG", "RANDOM_STRING_EXTRA"));
  • Constructor 3: You can add an extra String parameter and an extra ArrayList , designed to handle a larger amount of data, and then obtain it when the user presses the corresponding card.
   ArrayList<LauncherRecommended> aRecommendedContent = new ArrayList<>();
   aRecommendedContent.add(new LauncherRecommended("INSERT_ID_ONLY_NUMBER", "INSERT_TITLE", "INSERT_DESCRIPTION", "INSERT_URL_IMG", "RANDOM_STRING_EXTRA", "ARRAY_LIST_EXTRA_STRING"));
  1. Create an intent that references the UpdateRecommendationsService and sends the previously created ArrayList by parameters, additionally add the name of a class to which you want to redirect the user when you click on the card.
    Intent recommendationIntent = new Intent(this, UpdateRecommendationsService.class);
        recommendationIntent.putExtra("LauncherRecommended", aRecommendedContent);
        recommendationIntent.putExtra("toClass", MainActivity.class);
        startService(recommendationIntent);

Aditional Methods

  • Set a personalized image bottom for the card.
recommendationIntent.putExtra("cardIcon", R.mipmap.ic_launcher);
  • Set a personalized width for the card.
recommendationIntent.putExtra("cardWidth", getResources().getDimensionPixelSize(R.dimen.card_width));
  • Set a personalized height for the card.
recommendationIntent.putExtra("cardWidth", getResources().getDimensionPixelSize(R.dimen.card_height));
  • This method obtains the string set on a card when clicking.
  private String getIntent(Activity act, String field) {
        if(act.getIntent() != null) {
            return act.getIntent().getStringExtra(field);
        }else{
            return Constants.NULL;
        }
    }
  • This method obtains the ArrayList set on a card when clicking.
 private ArrayList<String> getIntentArrayList(Activity act, String field) {
        if(act.getIntent() != null){
            return (ArrayList<String>) act.getIntent().getSerializableExtra(field);
        }else{
            return new ArrayList<>();
        }
    }

NOTE:

  • To retrieve the extra String parameter, you must use the key: recommendation_extra
  • To retrieve the ArrayList extra parameter, you must use the key: recommendation_array_extra
  • For more information check the Example Project

References

Recommendations in Android N and earlier | Android Developers

Recommend TV content | Android Developers

License

This code is open-sourced software licensed under the MIT license.

simplerecommendationsandroidtv's People

Contributors

ederdoski avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.