GenreItems.java revision 20c5411cd0e3f26ea78543f9166cecb5d08b9220
120c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee/* 220c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee * Copyright (C) 2014 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 { 2520c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee public static final int POSITION_ALL_CHANNELS = 0; 2620c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee 2720c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee private static final String[] CANONICAL_GENRES = { 2820c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee null, // All channels 2920c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee Genres.FAMILY_KIDS, 3020c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee Genres.SPORTS, 3120c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee Genres.SHOPPING, 3220c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee Genres.MOVIES, 3320c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee Genres.COMEDY, 3420c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee Genres.TRAVEL, 3520c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee Genres.DRAMA, 3620c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee Genres.EDUCATION, 3720c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee Genres.ANIMAL_WILDLIFE, 3820c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee Genres.NEWS, 3920c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee Genres.GAMING 4020c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee }; 4120c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee 4220c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee private static String[] sItems; 4320c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee 4420c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee private GenreItems() { } 4520c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee 4620c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee public static final String[] getItems(Context context) { 4720c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee if (sItems == null) { 4820c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee sItems = context.getResources().getStringArray(R.array.show_only_label); 4920c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee } 5020c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee return sItems; 5120c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee } 5220c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee 5320c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee public static final String getLabel(Context context, int item) { 5420c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee return getItems(context)[item]; 5520c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee } 5620c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee 5720c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee public static final String getLabel(Context context, String canonicalGenre) { 5820c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee if (canonicalGenre == null) { 5920c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee return getItems(context)[POSITION_ALL_CHANNELS]; 6020c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee } 6120c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee 6220c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee for (int i = 1; i < CANONICAL_GENRES.length; ++i) { 6320c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee if (CANONICAL_GENRES[i].equals(canonicalGenre)) { 6420c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee return getItems(context)[i]; 6520c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee } 6620c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee } 6720c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee return getItems(context)[POSITION_ALL_CHANNELS]; 6820c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee } 6920c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee 7020c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee public static final String getCanonicalGenre(int item) { 7120c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee return CANONICAL_GENRES[item]; 7220c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee } 7320c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee 7420c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee public static final String getCanonicalGenre(Context context, String item) { 7520c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee int index = 0; 7620c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee for (String genre : getItems(context)) { 7720c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee if (genre.equals(item)) { 7820c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee return CANONICAL_GENRES[index]; 7920c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee } 8020c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee ++index; 8120c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee } 8220c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee return null; 8320c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee } 8420c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee 8520c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee public static final int getPosition(Context context, String item) { 8620c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee int index = 0; 8720c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee for (String genre : getItems(context)) { 8820c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee if (genre.equals(item)) { 8920c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee return index; 9020c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee } 9120c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee ++index; 9220c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee } 9320c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee return POSITION_ALL_CHANNELS; 9420c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee } 9520c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee 9620c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee public static final int getPosition(String canonicalGenre) { 9720c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee if (canonicalGenre == null) { 9820c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee return POSITION_ALL_CHANNELS; 9920c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee } 10020c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee for (int i = 1; i < CANONICAL_GENRES.length; ++i) { 10120c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee if (CANONICAL_GENRES[i].equals(canonicalGenre)) { 10220c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee return i; 10320c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee } 10420c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee } 10520c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee return POSITION_ALL_CHANNELS; 10620c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee } 10720c5411cd0e3f26ea78543f9166cecb5d08b9220Chulwoo Lee} 108