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.os.Bundle; 2065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 2165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport com.android.tv.settings.widget.ScrollAdapterView; 2265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 2365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport java.util.ArrayList; 2465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 2565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane/** 2665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * Subclass of ScrollAdapterFragment which handles actions. 2765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * <p> 2865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * Users should instantiate using {@link #newInstance(ArrayList, String)}. To learn when items are 2965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * clicked, the activity should implement {@link ActionAdapter.Listener}. <br/> 3065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * fragments need to call {@link #setListener(ActionAdapter.Listener)} to call their custom listener 3165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane */ 3265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lanepublic class BaseActionFragment extends BaseScrollAdapterFragment 3365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane implements ActionAdapter.Listener, ActionAdapter.OnFocusListener, 3465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane ActionAdapter.OnKeyListener { 3565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 3665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private final LiteFragment mFragment; 3765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 3865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane /** 3965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * Key for a string name for the fragment. 4065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane */ 4165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private static final String EXTRA_NAME = "name"; 4265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 4365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane /** 4465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * Key for a parcelable array of actions. 4565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane */ 4665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private static final String EXTRA_ACTIONS = "actions"; 4765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 4865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane /** 4965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * Key for the selected item index. 5065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane */ 5165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private static final String EXTRA_INDEX = "index"; 5265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 5365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane /** 5465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * Optional name of the fragment. 5565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane */ 5665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private String mName; 5765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private ActionAdapter mAdapter; 5865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private boolean mAddedSavedActions; 5965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 6065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane /** 6165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * If {@code true}, select the first checked item after populating. 6265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane */ 6365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private boolean mSelectFirstChecked; 6465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 6565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private int mIndexToSelect; 6665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 6765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private ActionAdapter.Listener mListener = null; 6865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 6965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public BaseActionFragment(LiteFragment fragment) { 7065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane super(fragment); 7165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mFragment = fragment; 7265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mIndexToSelect = -1; 7365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mSelectFirstChecked = true; 7465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 7565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 7665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane /** 7765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * Creates a new action fragment with the given list of actions and a given name. 7865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane */ 7965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public static Bundle buildArgs(ArrayList<Action> actions, String name) { 8065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return buildArgs(actions, name, -1); 8165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 8265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 8365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane /** 8465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * Creates a new action fragment with the given list of actions and starting index. 8565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane */ 8665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public static Bundle buildArgs(ArrayList<Action> actions, int index) { 8765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return buildArgs(actions, null, index); 8865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 8965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 9065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane /** 9165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * Creates a new action fragment with the given list of actions, given name and starting index. 9265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane */ 9365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public static Bundle buildArgs(ArrayList<Action> actions, String name, int index) { 9465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane Bundle args = new Bundle(); 9565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane args.putParcelableArrayList(EXTRA_ACTIONS, actions); 9665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane args.putString(EXTRA_NAME, name); 9765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane args.putInt(EXTRA_INDEX, index); 9865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return args; 9965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 10065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 10165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public void onCreate(Bundle savedInstanceState) { 10265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mAdapter = new ActionAdapter(mFragment.getActivity()); 10365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mAddedSavedActions = false; 10465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (savedInstanceState != null) { 10565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane ArrayList<Action> actions = savedInstanceState.getParcelableArrayList(EXTRA_ACTIONS); 10665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane int savedIndex = savedInstanceState.getInt(EXTRA_INDEX, -1); 10765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (actions != null) { 10865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane for (Action action : actions) { 10965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mAdapter.addAction(action); 11065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 11165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (savedIndex >= 0 && savedIndex < actions.size()) { 11265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mIndexToSelect = savedIndex; 11365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 11465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mAddedSavedActions = true; 11565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 11665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } else { 11765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane int startIndex = mFragment.getArguments().getInt(EXTRA_INDEX, -1); 11865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (startIndex != -1) { 11965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane // When first launching action fragment and start index is not -1, set it to 12065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane // mIndexToSelect. 12165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mIndexToSelect = startIndex; 12265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 12365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 12465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mName = mFragment.getArguments().getString(EXTRA_NAME); 12565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane loadActionsFromArgumentsIfNecessary(); 12665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mAdapter.setListener(this); 12765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mAdapter.setOnFocusListener(this); 12865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mAdapter.setOnKeyListener(this); 12965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 13065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 13165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public void onResume() { 13265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane // ensure the list is built. 13365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane ScrollAdapterView sav = getScrollAdapterView(); 13465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 13565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane sav.addOnScrollListener(mAdapter); 13665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (getAdapter() != mAdapter) { 13765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mAdapter.setScrollAdapterView(sav); 13865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane setAdapter(mAdapter); 13965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 14065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (mIndexToSelect != -1) { 14165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane getScrollAdapterView().setSelection(mIndexToSelect); 14265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mIndexToSelect = -1; // reset this. 14365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 14465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 14565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 146be1329ee22ce82662e1d68f88289657791d3c1a7Tony Mantler @Override 14765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public void onSaveInstanceState(Bundle outState) { 148be1329ee22ce82662e1d68f88289657791d3c1a7Tony Mantler super.onSaveInstanceState(outState); 14965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (hasCreatedView()) { 15065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane // Try to save instance state only if the view has already been created. 15165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane outState.putParcelableArrayList(EXTRA_ACTIONS, mAdapter.getActions()); 15265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane outState.putInt(EXTRA_INDEX, getScrollAdapterView().getSelectedItemPosition()); 15365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 15465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 15565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 15665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane /** 15765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * If the custom lister has been set using {@link #setListener(ActionAdapter.Listener)}, use it. 15865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * <br/> 15965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * If not, use the activity's default listener. 16065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * <br/> 16165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * Don't broadcast the click if the action is disabled or only displays info. 16265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane */ 16365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane @Override 16465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public void onActionClicked(Action action) { 16565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane // eat events if action is disabled or only displays info 16665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (!action.isEnabled() || action.infoOnly()) { 16765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return; 16865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 16965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 17065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (mListener != null) { 17165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mListener.onActionClicked(action); 17265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } else if (mFragment.getActivity() instanceof ActionAdapter.Listener) { 17365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane ActionAdapter.Listener listener = (ActionAdapter.Listener) mFragment.getActivity(); 17465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane listener.onActionClicked(action); 17565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 17665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 17765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 17865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane @Override 17965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public void onActionFocused(Action action) { 18065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (mFragment.getActivity() instanceof ActionAdapter.OnFocusListener) { 18165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane ActionAdapter.OnFocusListener listener = (ActionAdapter.OnFocusListener) mFragment 18265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane .getActivity(); 18365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane listener.onActionFocused(action); 18465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 18565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 18665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 18765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane @Override 18865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public void onActionSelect(Action action) { 18965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (mFragment.getActivity() instanceof ActionAdapter.OnKeyListener) { 19065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane ActionAdapter.OnKeyListener listener = (ActionAdapter.OnKeyListener) mFragment 19165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane .getActivity(); 19265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane listener.onActionSelect(action); 19365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 19465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 19565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 19665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane @Override 19765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public void onActionUnselect(Action action) { 19865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (mFragment.getActivity() instanceof ActionAdapter.OnKeyListener) { 19965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane ActionAdapter.OnKeyListener listener = (ActionAdapter.OnKeyListener) mFragment 20065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane .getActivity(); 20165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane listener.onActionUnselect(action); 20265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 20365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 20465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 20565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public String getName() { 20665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return mName; 20765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 20865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 20965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane /** 21065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * Fragments need to call this method in its {@link #onResume()} to set the 21165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * custom listener. <br/> 21265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * Activities do not need to call this method 21365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * 21465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * @param listener 21565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane */ 21665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public void setListener(ActionAdapter.Listener listener) { 21765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mListener = listener; 21865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 21965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 22065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public boolean hasListener() { 22165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return mListener != null; 22265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 22365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 22465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane /** 22565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * Sets whether to not to select the first checked action on resume. 22665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane */ 22765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public void setSelectFirstChecked(boolean selectFirstChecked) { 22865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mSelectFirstChecked = selectFirstChecked; 22965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 23065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 23165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private void loadActionsFromArgumentsIfNecessary() { 23265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (mFragment.getArguments() != null && !mAddedSavedActions) { 23365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane ArrayList<Action> actions = mFragment.getArguments() 23465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane .getParcelableArrayList(EXTRA_ACTIONS); 23565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (actions != null) { 23665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane final int size = actions.size(); 23765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane for (int index = 0; index < size; ++index) { 23865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (mSelectFirstChecked && actions.get(index).isChecked() 23965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane && mIndexToSelect == -1) { 24065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mIndexToSelect = index; 24165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 24265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mAdapter.addAction(actions.get(index)); 24365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 24465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 24565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 24665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 24765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane} 248