120c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee/* 2816a4be1a0f34f6a48877c8afd3dbbca19eac435Nick Chalko * Copyright (C) 2015 The Android Open Source Project 320c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee * 420c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee * Licensed under the Apache License, Version 2.0 (the "License"); 520c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee * you may not use this file except in compliance with the License. 620c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee * You may obtain a copy of the License at 720c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee * 820c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee * http://www.apache.org/licenses/LICENSE-2.0 920c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee * 1020c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee * Unless required by applicable law or agreed to in writing, software 1120c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee * distributed under the License is distributed on an "AS IS" BASIS, 1220c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1320c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee * See the License for the specific language governing permissions and 1420c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee * limitations under the License. 1520c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee */ 1620c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee 1720c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Leepackage com.android.tv.data; 1820c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee 1920c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Leeimport android.content.Context; 2020c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Leeimport android.media.tv.TvContract.Programs.Genres; 2120c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee 2220c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Leeimport com.android.tv.R; 2320c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee 2420c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Leepublic class GenreItems { 25816a4be1a0f34f6a48877c8afd3dbbca19eac435Nick Chalko /** 26816a4be1a0f34f6a48877c8afd3dbbca19eac435Nick Chalko * Genre ID indicating all channels. 27816a4be1a0f34f6a48877c8afd3dbbca19eac435Nick Chalko */ 28816a4be1a0f34f6a48877c8afd3dbbca19eac435Nick Chalko public static final int ID_ALL_CHANNELS = 0; 2920c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee 3065fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko private static final String[] CANONICAL_GENRES = { 312e1279b8bbe0603fb4399b25b73121bed5953c46Nick Chalko null, // All channels 322e1279b8bbe0603fb4399b25b73121bed5953c46Nick Chalko Genres.FAMILY_KIDS, 332e1279b8bbe0603fb4399b25b73121bed5953c46Nick Chalko Genres.SPORTS, 342e1279b8bbe0603fb4399b25b73121bed5953c46Nick Chalko Genres.SHOPPING, 352e1279b8bbe0603fb4399b25b73121bed5953c46Nick Chalko Genres.MOVIES, 362e1279b8bbe0603fb4399b25b73121bed5953c46Nick Chalko Genres.COMEDY, 372e1279b8bbe0603fb4399b25b73121bed5953c46Nick Chalko Genres.TRAVEL, 382e1279b8bbe0603fb4399b25b73121bed5953c46Nick Chalko Genres.DRAMA, 392e1279b8bbe0603fb4399b25b73121bed5953c46Nick Chalko Genres.EDUCATION, 402e1279b8bbe0603fb4399b25b73121bed5953c46Nick Chalko Genres.ANIMAL_WILDLIFE, 412e1279b8bbe0603fb4399b25b73121bed5953c46Nick Chalko Genres.NEWS, 422e1279b8bbe0603fb4399b25b73121bed5953c46Nick Chalko Genres.GAMING, 432e1279b8bbe0603fb4399b25b73121bed5953c46Nick Chalko Genres.ARTS, 442e1279b8bbe0603fb4399b25b73121bed5953c46Nick Chalko Genres.ENTERTAINMENT, 452e1279b8bbe0603fb4399b25b73121bed5953c46Nick Chalko Genres.LIFE_STYLE, 462e1279b8bbe0603fb4399b25b73121bed5953c46Nick Chalko Genres.MUSIC, 472e1279b8bbe0603fb4399b25b73121bed5953c46Nick Chalko Genres.PREMIER, 482e1279b8bbe0603fb4399b25b73121bed5953c46Nick Chalko Genres.TECH_SCIENCE 49ba5845f23b8fbc985890f892961abc8b39886611Nick Chalko }; 50ba5845f23b8fbc985890f892961abc8b39886611Nick Chalko 5120c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee private GenreItems() { } 5220c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee 53816a4be1a0f34f6a48877c8afd3dbbca19eac435Nick Chalko /** 54816a4be1a0f34f6a48877c8afd3dbbca19eac435Nick Chalko * Returns array of all genre labels. 55816a4be1a0f34f6a48877c8afd3dbbca19eac435Nick Chalko */ 56816a4be1a0f34f6a48877c8afd3dbbca19eac435Nick Chalko public static String[] getLabels(Context context) { 5765fda1eaa94968bb55d5ded10dcb0b3f37fb05f2Nick Chalko String[] items = context.getResources().getStringArray(R.array.genre_labels); 58816a4be1a0f34f6a48877c8afd3dbbca19eac435Nick Chalko if (items.length != CANONICAL_GENRES.length) { 59816a4be1a0f34f6a48877c8afd3dbbca19eac435Nick Chalko throw new IllegalArgumentException("Genre data mismatch"); 6020c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee } 61816a4be1a0f34f6a48877c8afd3dbbca19eac435Nick Chalko return items; 6220c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee } 6320c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee 64816a4be1a0f34f6a48877c8afd3dbbca19eac435Nick Chalko /** 65816a4be1a0f34f6a48877c8afd3dbbca19eac435Nick Chalko * Returns the number of genres including all channels. 66816a4be1a0f34f6a48877c8afd3dbbca19eac435Nick Chalko */ 67816a4be1a0f34f6a48877c8afd3dbbca19eac435Nick Chalko public static int getGenreCount() { 68816a4be1a0f34f6a48877c8afd3dbbca19eac435Nick Chalko return CANONICAL_GENRES.length; 6920c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee } 7020c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee 71816a4be1a0f34f6a48877c8afd3dbbca19eac435Nick Chalko /** 72816a4be1a0f34f6a48877c8afd3dbbca19eac435Nick Chalko * Returns the canonical genre for the given id. 73816a4be1a0f34f6a48877c8afd3dbbca19eac435Nick Chalko * If the id is invalid, {@code null} will be returned instead. 74816a4be1a0f34f6a48877c8afd3dbbca19eac435Nick Chalko */ 75816a4be1a0f34f6a48877c8afd3dbbca19eac435Nick Chalko public static String getCanonicalGenre(int id) { 76816a4be1a0f34f6a48877c8afd3dbbca19eac435Nick Chalko if (id < 0 || id >= CANONICAL_GENRES.length) { 77816a4be1a0f34f6a48877c8afd3dbbca19eac435Nick Chalko return null; 7820c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee } 79816a4be1a0f34f6a48877c8afd3dbbca19eac435Nick Chalko return CANONICAL_GENRES[id]; 8020c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee } 8120c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee 82816a4be1a0f34f6a48877c8afd3dbbca19eac435Nick Chalko /** 83816a4be1a0f34f6a48877c8afd3dbbca19eac435Nick Chalko * Returns id for the given canonical genre. 84816a4be1a0f34f6a48877c8afd3dbbca19eac435Nick Chalko * If the genre is invalid, {@link #ID_ALL_CHANNELS} will be returned instead. 85816a4be1a0f34f6a48877c8afd3dbbca19eac435Nick Chalko */ 86816a4be1a0f34f6a48877c8afd3dbbca19eac435Nick Chalko public static int getId(String canonicalGenre) { 8720c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee if (canonicalGenre == null) { 88816a4be1a0f34f6a48877c8afd3dbbca19eac435Nick Chalko return ID_ALL_CHANNELS; 8920c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee } 9020c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee for (int i = 1; i < CANONICAL_GENRES.length; ++i) { 9120c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee if (CANONICAL_GENRES[i].equals(canonicalGenre)) { 9220c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee return i; 9320c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee } 9420c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee } 95816a4be1a0f34f6a48877c8afd3dbbca19eac435Nick Chalko return ID_ALL_CHANNELS; 9620c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee } 9720c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee} 98