165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane/* 265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * Copyright (C) 2014 The Android Open Source Project 365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * 465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * Licensed under the Apache License, Version 2.0 (the "License"); 565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * you may not use this file except in compliance with the License. 665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * You may obtain a copy of the License at 765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * 865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * http://www.apache.org/licenses/LICENSE-2.0 965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * 1065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * Unless required by applicable law or agreed to in writing, software 1165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * distributed under the License is distributed on an "AS IS" BASIS, 1265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * See the License for the specific language governing permissions and 1465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * limitations under the License. 1565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane */ 1665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 1765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lanepackage com.android.tv.settings.dialog.old; 1865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 1965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.content.Context; 2065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.content.Intent; 2165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.content.pm.PackageManager; 2265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.content.res.Resources; 2365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.graphics.drawable.Drawable; 2465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.net.Uri; 2565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.os.Parcel; 2665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.os.Parcelable; 2765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.util.Log; 2865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 2965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport java.util.ArrayList; 3065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 3165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane/** 3265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * An action within an {@link ActionAdapter}. 3365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane */ 3465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lanepublic class Action implements Parcelable { 3565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 3665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private static final String TAG = "Action"; 3765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 3865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public static final int NO_DRAWABLE = 0; 3965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public static final int NO_CHECK_SET = 0; 4065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public static final int DEFAULT_CHECK_SET_ID = 1; 4165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 4265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private String mKey; 4365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private String mTitle; 4465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private String mDescription; 4565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private Intent mIntent; 4665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 4765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane /** 4865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * If not {@code null}, the package name to use to retrieve {{@link #mDrawableResource}. 4965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane */ 5065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private String mResourcePackageName; 5165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 5265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private int mDrawableResource; 5365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private Uri mIconUri; 5465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private boolean mChecked; 5565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private boolean mMultilineDescription; 5665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private boolean mHasNext; 5765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private boolean mInfoOnly; 5865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private int mCheckSetId; 5965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private boolean mEnabled; 6065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 6165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane /** 6265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * Builds a Action object. 6365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane */ 6465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public static class Builder { 6565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private String mKey; 6665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private String mTitle; 6765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private String mDescription; 6865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private Intent mIntent; 6965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private String mResourcePackageName; 7065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private int mDrawableResource = NO_DRAWABLE; 7165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private Uri mIconUri; 7265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private boolean mChecked; 7365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private boolean mMultilineDescription; 7465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private boolean mHasNext; 7565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private boolean mInfoOnly; 7665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private int mCheckSetId = NO_CHECK_SET; 7765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private boolean mEnabled = true; 7865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 7965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public Action build() { 8065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane Action action = new Action(); 8165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane action.mKey = mKey; 8265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane action.mTitle = mTitle; 8365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane action.mDescription = mDescription; 8465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane action.mIntent = mIntent; 8565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane action.mResourcePackageName = mResourcePackageName; 8665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane action.mDrawableResource = mDrawableResource; 8765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane action.mIconUri = mIconUri; 8865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane action.mChecked = mChecked; 8965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane action.mMultilineDescription = mMultilineDescription; 9065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane action.mHasNext = mHasNext; 9165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane action.mInfoOnly = mInfoOnly; 9265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane action.mCheckSetId = mCheckSetId; 9365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane action.mEnabled = mEnabled; 9465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return action; 9565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 9665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 9765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public Builder key(String key) { 9865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mKey = key; 9965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return this; 10065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 10165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 10265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public Builder title(String title) { 10365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mTitle = title; 10465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return this; 10565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 10665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 10765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public Builder description(String description) { 10865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mDescription = description; 10965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return this; 11065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 11165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 11265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public Builder intent(Intent intent) { 11365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mIntent = intent; 11465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return this; 11565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 11665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 11765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public Builder resourcePackageName(String resourcePackageName) { 11865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mResourcePackageName = resourcePackageName; 11965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return this; 12065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 12165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 12265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public Builder drawableResource(int drawableResource) { 12365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mDrawableResource = drawableResource; 12465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return this; 12565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 12665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 12765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public Builder iconUri(Uri iconUri) { 12865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mIconUri = iconUri; 12965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return this; 13065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 13165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 13265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public Builder checked(boolean checked) { 13365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mChecked = checked; 13465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return this; 13565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 13665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 13765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public Builder multilineDescription(boolean multilineDescription) { 13865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mMultilineDescription = multilineDescription; 13965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return this; 14065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 14165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 14265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public Builder hasNext(boolean hasNext) { 14365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mHasNext = hasNext; 14465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return this; 14565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 14665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 14765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public Builder infoOnly(boolean infoOnly) { 14865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mInfoOnly = infoOnly; 14965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return this; 15065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 15165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 15265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public Builder checkSetId(int checkSetId) { 15365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mCheckSetId = checkSetId; 15465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return this; 15565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 15665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 15765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public Builder enabled(boolean enabled) { 15865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mEnabled = enabled; 15965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return this; 16065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 16165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 16265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 16365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private Action() { 16465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 16565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 16665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane protected Action(String key, String title, String description, String resourcePackageName, 16765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane int drawableResource, boolean checked, boolean multilineDescription, boolean hasNext, 16865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane boolean infoOnly, Intent intent, int checkSetId) { 16965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mKey = key; 17065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mTitle = title; 17165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mDescription = description; 17265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mResourcePackageName = resourcePackageName; 17365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mDrawableResource = drawableResource; 17465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mChecked = checked; 17565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mMultilineDescription = multilineDescription; 17665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mHasNext = hasNext; 17765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mInfoOnly = infoOnly; 17865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mIntent = intent; 17965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mCheckSetId = checkSetId; 18065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mEnabled = true; 18165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 18265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 18365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane /** 18465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * Returns a list of {@link Action} with the specified keys and titles 18565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * matched up. 18665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * <p> 18765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * The key and title arrays must be of equal length. 18865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane */ 18965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public static ArrayList<Action> createActionsFromArrays(String[] keys, String[] titles) { 19065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return createActionsFromArrays(keys, titles, NO_CHECK_SET, null); 19165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 19265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 19365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane /** 19465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * Returns a list of {@link Action} with the specified keys and titles 19565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * matched up. 19665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * <p> 19765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * The key and title arrays must be of equal length. 19865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane */ 19965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public static ArrayList<Action> createActionsFromArrays( 20065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane String[] keys, String[] titles, String checkedItemKey) { 20165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return createActionsFromArrays(keys, titles, DEFAULT_CHECK_SET_ID, checkedItemKey); 20265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 20365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 20465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane /** 20565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * Returns a list of {@link Action} with the specified keys and titles 20665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * matched up and a given check set ID so that they are related. 20765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * <p> 20865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * The key and title arrays must be of equal length. 20965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane */ 21065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public static ArrayList<Action> createActionsFromArrays(String[] keys, String[] titles, 21165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane int checkSetId) { 21265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return createActionsFromArrays(keys, titles, checkSetId, null); 21365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 21465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 21565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane /** 21665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * Returns a list of {@link Action} with the specified keys and titles 21765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * matched up and a given check set ID so that they are related. 21865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * <p> 21965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * The key and title arrays must be of equal length. 22065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane */ 22165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public static ArrayList<Action> createActionsFromArrays(String[] keys, String[] titles, 22265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane int checkSetId, String checkedItemKey) { 22365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane int keysLength = keys.length; 22465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane int titlesLength = titles.length; 22565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 22665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (keysLength != titlesLength) { 22765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane throw new IllegalArgumentException("Keys and titles dimensions must match"); 22865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 22965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 23065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane ArrayList<Action> actions = new ArrayList<Action>(); 23165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane for (int i = 0; i < keysLength; i++) { 23265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane Action.Builder builder = new Action.Builder(); 23365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane builder.key(keys[i]).title(titles[i]).checkSetId(checkSetId); 23465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (checkedItemKey != null) { 23565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (checkedItemKey.equals(keys[i])) { 23665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane builder.checked(true); 23765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } else { 23865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane builder.checked(false); 23965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 24065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 24165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane Action action = builder.build(); 24265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane actions.add(action); 24365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 24465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return actions; 24565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 24665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 24765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public String getKey() { 24865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return mKey; 24965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 25065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 25165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public String getTitle() { 25265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return mTitle; 25365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 25465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 25565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public String getDescription() { 25665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return mDescription; 25765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 25865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 25965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public Intent getIntent() { 26065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return mIntent; 26165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 26265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 26365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public boolean isChecked() { 26465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return mChecked; 26565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 26665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 26765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public int getDrawableResource() { 26865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return mDrawableResource; 26965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 27065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 27165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public Uri getIconUri() { 27265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return mIconUri; 27365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 27465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 27565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public String getResourcePackageName() { 27665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return mResourcePackageName; 27765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 27865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 27965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane /** 28065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * Returns the check set id this action is a part of. All actions in the same list with the 28165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * same check set id are considered linked. When one of the actions within that set is selected 28265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * that action becomes checked while all the other actions become unchecked. 28365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * @return an integer representing the check set this action is a part of or {@NO_CHECK_SET} if 28465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * this action isn't a part of a check set. 28565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane */ 28665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public int getCheckSetId() { 28765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return mCheckSetId; 28865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 28965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 29065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public boolean hasMultilineDescription() { 29165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return mMultilineDescription; 29265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 29365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 29465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public boolean isEnabled() { 29565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return mEnabled; 29665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 29765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 29865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public void setChecked(boolean checked) { 29965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mChecked = checked; 30065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 30165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 30265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public void setEnabled(boolean enabled) { 30365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mEnabled = enabled; 30465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 30565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 30665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane /** 30765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * @return true if the action will request further user input when selected 30865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * (such as showing another dialog or launching a new activity). 30965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * False, otherwise. 31065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane */ 31165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public boolean hasNext() { 31265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return mHasNext; 31365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 31465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 31565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane /** 31665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * @return true if the action will only display information and is thus unactionable. 31765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * If both this and {@link #hasNext()} are true, infoOnly takes precedence. (default is false) 31865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * e.g. Play balance, or cost of an app. 31965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane */ 32065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public boolean infoOnly() { 32165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return mInfoOnly; 32265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 32365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 32465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane /** 32565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * Returns an indicator to be drawn. If null is returned, no space for the 32665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * indicator will be made. 32765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * 32865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * @param context the context of the Activity this Action belongs to 32965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * @return an indicator to draw or null if no indicator space should exist. 33065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane */ 33165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public Drawable getIndicator(Context context) { 33265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (mDrawableResource == NO_DRAWABLE) { 33365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return null; 33465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 33565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (mResourcePackageName == null) { 33665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return context.getResources().getDrawable(mDrawableResource); 33765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 33865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane // If we get to here, need to load the resources. 33965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane Drawable icon = null; 34065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane try { 34165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane Context packageContext = context.createPackageContext(mResourcePackageName, 0); 34265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane icon = packageContext.getResources().getDrawable(mDrawableResource); 34365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } catch (PackageManager.NameNotFoundException e) { 34465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (Log.isLoggable(TAG, Log.WARN)) { 34565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane Log.w(TAG, "No icon for this action."); 34665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 34765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } catch (Resources.NotFoundException e) { 34865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (Log.isLoggable(TAG, Log.WARN)) { 34965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane Log.w(TAG, "No icon for this action."); 35065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 35165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 35265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return icon; 35365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 35465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 35565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public static Parcelable.Creator<Action> CREATOR = new Parcelable.Creator<Action>() { 35665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 35765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane @Override 35865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public Action createFromParcel(Parcel source) { 35965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 36065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return new Action.Builder() 36165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane .key(source.readString()) 36265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane .title(source.readString()) 36365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane .description(source.readString()) 36465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane .intent((Intent) source.readParcelable(Intent.class.getClassLoader())) 36565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane .resourcePackageName(source.readString()) 36665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane .drawableResource(source.readInt()) 36765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane .iconUri((Uri) source.readParcelable(Uri.class.getClassLoader())) 36865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane .checked(source.readInt() != 0) 36965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane .multilineDescription(source.readInt() != 0) 37065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane .checkSetId(source.readInt()) 37165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane .build(); 37265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 37365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 37465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane @Override 37565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public Action[] newArray(int size) { 37665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return new Action[size]; 37765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 37865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane }; 37965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 38065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane @Override 38165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public int describeContents() { 38265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return 0; 38365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 38465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 38565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane @Override 38665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public void writeToParcel(Parcel dest, int flags) { 38765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane dest.writeString(mKey); 38865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane dest.writeString(mTitle); 38965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane dest.writeString(mDescription); 39065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane dest.writeParcelable(mIntent, flags); 39165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane dest.writeString(mResourcePackageName); 39265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane dest.writeInt(mDrawableResource); 39365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane dest.writeParcelable(mIconUri, flags); 39465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane dest.writeInt(mChecked ? 1 : 0); 39565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane dest.writeInt(mMultilineDescription ? 1 : 0); 39665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane dest.writeInt(mCheckSetId); 39765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 39865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane} 399