aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorYoungsang Cho <youngsang@google.com>2014-08-05 22:54:35 +0900
committerYoungsang Cho <youngsang@google.com>2014-08-05 22:58:02 +0900
commit5f496abf04ad5de1df0fd371f1f61a445bc70c6b (patch)
tree435654860d773aecc498334aa889beea7b0679fb /src
parentd2f225ac4f8a4604e1799cd289be722aa3476c33 (diff)
downloadTV-5f496abf04ad5de1df0fd371f1f61a445bc70c6b.tar.gz
Revive old side panel fragments until the new ones keep the feature parities
Newly refactored fragments missed some features like the back key behavior. Until they satisfy the parity, we need to keep both old and new ones. Change-Id: Ib08efe9581817e4cde1ecb0e017b08be30435ee7
Diffstat (limited to 'src')
-rw-r--r--src/com/android/tv/TvActivity.java6
-rw-r--r--src/com/android/tv/ui/sidepanel/BaseOptionFragment.java104
-rw-r--r--src/com/android/tv/ui/sidepanel/ClosedCaptionOptionFragment.java92
-rw-r--r--src/com/android/tv/ui/sidepanel/DisplayModeOptionFragment.java88
-rw-r--r--src/com/android/tv/ui/sidepanel/EditChannelsFragment.java219
-rw-r--r--src/com/android/tv/ui/sidepanel/InputPickerFragment.java125
-rw-r--r--src/com/android/tv/ui/sidepanel/PipLocationFragment.java108
7 files changed, 573 insertions, 169 deletions
diff --git a/src/com/android/tv/TvActivity.java b/src/com/android/tv/TvActivity.java
index 23cb4596..770ad0b8 100644
--- a/src/com/android/tv/TvActivity.java
+++ b/src/com/android/tv/TvActivity.java
@@ -73,7 +73,9 @@ import com.android.tv.ui.TunableTvView.OnTuneListener;
import com.android.tv.ui.sidepanel.ActionItem;
import com.android.tv.ui.sidepanel.BaseSideFragment;
import com.android.tv.ui.sidepanel.ClosedCaptionFragment;
+import com.android.tv.ui.sidepanel.ClosedCaptionOptionFragment;
import com.android.tv.ui.sidepanel.DisplayModeFragment;
+import com.android.tv.ui.sidepanel.DisplayModeOptionFragment;
import com.android.tv.ui.sidepanel.EditChannelsFragment;
import com.android.tv.ui.sidepanel.InputPickerFragment;
import com.android.tv.ui.sidepanel.Item;
@@ -567,11 +569,11 @@ public class TvActivity extends Activity implements AudioManager.OnAudioFocusCha
}
public void showDisplayModeOption(int initiator) {
- showSideFragment(new DisplayModeFragment(), initiator);
+ showSideFragment(new DisplayModeOptionFragment(), initiator);
}
public void showClosedCaptionOption(int initiator) {
- showSideFragment(new ClosedCaptionFragment(), initiator);
+ showSideFragment(new ClosedCaptionOptionFragment(), initiator);
}
public void showPipLocationOption(int initiator) {
diff --git a/src/com/android/tv/ui/sidepanel/BaseOptionFragment.java b/src/com/android/tv/ui/sidepanel/BaseOptionFragment.java
new file mode 100644
index 00000000..b8d45acc
--- /dev/null
+++ b/src/com/android/tv/ui/sidepanel/BaseOptionFragment.java
@@ -0,0 +1,104 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.tv.ui.sidepanel;
+
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.RadioButton;
+
+import com.android.tv.R;
+import com.android.tv.TvActivity;
+
+public class BaseOptionFragment extends BaseSideFragment {
+ private static final String TAG = "ClosedCaptionOptionFragment";
+ private static final boolean DEBUG = true;
+
+ private View mMainView;
+ private boolean mClosingByItemSelected;
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ mMainView = super.onCreateView(inflater, container, savedInstanceState);
+ return mMainView;
+ }
+
+ @Override
+ public void onDetach() {
+ super.onDetach();
+ if (!mClosingByItemSelected) {
+ ((TvActivity) getActivity()).onSideFragmentCanceled(getInitiator());
+ }
+ ((TvActivity) getActivity()).hideOverlays(false, false, true);
+ }
+
+ @Override
+ public final void initialize(String title, Object[] itemTags, int fragmentLayoutId,
+ int itemLayoutId, int itemBgColor, int itemFocusedBgColor, int itemHeightResId) {
+ throw new UnsupportedOperationException("Call initialize(String title, Object[] itemTags)");
+ }
+
+ public void initialize(String title, Object[] itemTags) {
+ super.initialize(title, itemTags, R.layout.option_fragment, R.layout.option_item,
+ R.color.option_item_background, R.color.option_item_focused_background,
+ R.dimen.option_item_height);
+ }
+
+ public void initialize(String title, int itemLayoutResId, Object[] itemTags) {
+ super.initialize(title, itemTags, R.layout.option_fragment, itemLayoutResId,
+ R.color.option_item_background, R.color.option_item_focused_background,
+ R.dimen.option_item_height);
+ }
+
+ @Override
+ public void onItemSelected(View v, int position, Object tag) {
+ RadioButton radioButton = (RadioButton) v.findViewById(R.id.option_item);
+ uncheckAllRadioButtons((ViewGroup) mMainView);
+ radioButton.setChecked(true);
+ mClosingByItemSelected = true;
+ ((TvActivity) getActivity()).popFragmentBackStack();
+ }
+
+ @Override
+ public void onBindView(View v, int position, Object tag, boolean prevSelected) {
+ RadioButton radioButton = (RadioButton) v.findViewById(R.id.option_item);
+ if (prevSelected) {
+ radioButton.setChecked(true);
+ } else {
+ radioButton.setChecked(false);
+ }
+ if (tag instanceof String) {
+ radioButton.setText((String) tag);
+ } else {
+ radioButton.setText("");
+ }
+ }
+
+ private static void uncheckAllRadioButtons(ViewGroup parent) {
+ int count = parent.getChildCount();
+ for (int i = 0; i < count; ++i) {
+ View v = parent.getChildAt(i);
+ if (v instanceof ViewGroup) {
+ uncheckAllRadioButtons((ViewGroup) v);
+ } else if (v instanceof RadioButton) {
+ ((RadioButton) v).setChecked(false);
+ }
+ }
+ }
+}
diff --git a/src/com/android/tv/ui/sidepanel/ClosedCaptionOptionFragment.java b/src/com/android/tv/ui/sidepanel/ClosedCaptionOptionFragment.java
new file mode 100644
index 00000000..3db185ff
--- /dev/null
+++ b/src/com/android/tv/ui/sidepanel/ClosedCaptionOptionFragment.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.tv.ui.sidepanel;
+
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Toast;
+
+import com.android.tv.R;
+import com.android.tv.TvActivity;
+
+public class ClosedCaptionOptionFragment extends BaseOptionFragment {
+ private static final String TAG = "ClosedCaptionOptionFragment";
+ private static final boolean DEBUG = true;
+
+ private static final int CC_ON = 0;
+ private static final int CC_OFF = 1;
+
+ private TvActivity mTvActivity;
+ private boolean mIsFirstResume;
+ private boolean mLastStoredCcEnabled;
+ private boolean mCcEnabled;
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ mIsFirstResume = true;
+ mTvActivity = (TvActivity) getActivity();
+
+ Object[] items = new Object[2];
+ items[0] = getString(R.string.option_item_on);
+ items[1] = getString(R.string.option_item_off);
+
+ initialize(getString(R.string.closed_caption_option_title), items);
+ return super.onCreateView(inflater, container, savedInstanceState);
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ if (mIsFirstResume) {
+ mCcEnabled = mTvActivity.isClosedCaptionEnabled();
+ mLastStoredCcEnabled = mCcEnabled;
+ int initialPosition = mCcEnabled ? CC_ON : CC_OFF;
+ setSelectedPosition(initialPosition);
+ setPrevSelectedItemPosition(initialPosition);
+ mIsFirstResume = false;
+ }
+ }
+
+ @Override
+ public void onDetach() {
+ super.onDetach();
+ if (mLastStoredCcEnabled != mCcEnabled) {
+ mTvActivity.restoreClosedCaptionEnabled();
+ }
+ }
+
+ @Override
+ public void onItemFocusChanged(View v, boolean focusGained, int position, Object tag) {
+ super.onItemFocusChanged(v, focusGained, position, tag);
+ if (focusGained) {
+ mCcEnabled = (position == CC_ON);
+ mTvActivity.setClosedCaptionEnabled(mCcEnabled, false);
+ }
+ }
+
+ @Override
+ public void onItemSelected(View v, int position, Object tag) {
+ mCcEnabled = (position == CC_ON);
+ mTvActivity.setClosedCaptionEnabled(mCcEnabled, true);
+ mLastStoredCcEnabled = mCcEnabled;
+ super.onItemSelected(v, position, tag);
+ Toast.makeText(getActivity(), R.string.not_implemented_yet, Toast.LENGTH_SHORT).show();
+ }
+}
diff --git a/src/com/android/tv/ui/sidepanel/DisplayModeOptionFragment.java b/src/com/android/tv/ui/sidepanel/DisplayModeOptionFragment.java
new file mode 100644
index 00000000..43b446d4
--- /dev/null
+++ b/src/com/android/tv/ui/sidepanel/DisplayModeOptionFragment.java
@@ -0,0 +1,88 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.tv.ui.sidepanel;
+
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+import com.android.tv.R;
+import com.android.tv.TvActivity;
+import com.android.tv.data.DisplayMode;
+
+public class DisplayModeOptionFragment extends BaseOptionFragment {
+ private static final String TAG = "AspectRatioOptionFragment";
+ private static final boolean DEBUG = true;
+
+ private TvActivity mTvActivity;
+ private boolean mIsFirstResume;
+ private int mLastStoredAspectRatio;
+ private int mAspectRatio;
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ mIsFirstResume = true;
+ mTvActivity = (TvActivity) getActivity();
+
+ Object[] items = new Object[DisplayMode.SIZE_OF_RATIO_TYPES];
+ for (int i = 0; i < DisplayMode.SIZE_OF_RATIO_TYPES; ++i) {
+ items[i] = DisplayMode.getLabel(i, getActivity());
+ }
+ initialize(getString(R.string.display_mode_option_title), items);
+ return super.onCreateView(inflater, container, savedInstanceState);
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ if (mIsFirstResume) {
+ mAspectRatio = mTvActivity.getDisplayMode();
+ mLastStoredAspectRatio = mAspectRatio;
+ int initialPosition = mAspectRatio;
+ setSelectedPosition(initialPosition);
+ setPrevSelectedItemPosition(initialPosition);
+ mIsFirstResume = false;
+ }
+ }
+
+ @Override
+ public void onDetach() {
+ super.onDetach();
+ if (mLastStoredAspectRatio != mAspectRatio) {
+ mTvActivity.restoreDisplayMode();
+ }
+ }
+
+ @Override
+ public void onItemFocusChanged(View v, boolean focusGained, int position, Object tag) {
+ super.onItemFocusChanged(v, focusGained, position, tag);
+ if (focusGained) {
+ mAspectRatio = position;
+ mTvActivity.setDisplayMode(position, false);
+ }
+ }
+
+ @Override
+ public void onItemSelected(View v, int position, Object tag) {
+ mAspectRatio = position;
+ mTvActivity.setDisplayMode(mAspectRatio, true);
+ mLastStoredAspectRatio = mAspectRatio;
+ super.onItemSelected(v, position, tag);
+ }
+}
diff --git a/src/com/android/tv/ui/sidepanel/EditChannelsFragment.java b/src/com/android/tv/ui/sidepanel/EditChannelsFragment.java
index 2497630b..48d21fd3 100644
--- a/src/com/android/tv/ui/sidepanel/EditChannelsFragment.java
+++ b/src/com/android/tv/ui/sidepanel/EditChannelsFragment.java
@@ -19,110 +19,191 @@ package com.android.tv.ui.sidepanel;
import android.content.ContentValues;
import android.media.tv.TvContract;
import android.net.Uri;
+import android.os.Bundle;
import android.text.TextUtils;
+import android.view.LayoutInflater;
import android.view.View;
+import android.view.ViewGroup;
+import android.widget.CheckBox;
+import android.widget.TextView;
import android.widget.Toast;
+import com.android.internal.util.Preconditions;
import com.android.tv.R;
+import com.android.tv.TvActivity;
import com.android.tv.data.Channel;
+import com.android.tv.input.TvInput;
+
+public class EditChannelsFragment extends BaseSideFragment {
+ private static final int ACTION_SHOW_ALL = 0;
+ private static final int ACTION_HIDE_ALL = 1;
+
+ private TvInput mSelectedInput;
+
+ private TvActivity mTvActivity;
+ private Item[] mItems;
+ private String[] mActions;
+ private Channel[] mChannels;
+ private int mBrowsableChannelCount;
+
+ private static final class Item {
+ private static final int TYPE_ACTION = 0;
+ private static final int TYPE_CHANNEL = 1;
+ private static final int TYPE_DIVIDER = 2;
+
+ private Item(int type, int action, Channel channel) {
+ mType = type;
+ mAction = action;
+ Preconditions.checkState(!(type == TYPE_CHANNEL && channel == null));
+ mChannel = channel;
+ }
-import java.util.ArrayList;
-import java.util.List;
-
-public class EditChannelsFragment extends SideFragment {
- Channel[] mChannels;
+ private int mType;
+ private int mAction;
+ private Channel mChannel;
+ }
public EditChannelsFragment(Channel[] channels) {
mChannels = channels;
+ mBrowsableChannelCount = 0;
+ for (Channel channel : channels) {
+ if (channel.isBrowsable()) {
+ ++mBrowsableChannelCount;
+ }
+ }
}
@Override
- protected String getTitle() {
- String displayName = getTvActivity().getSelectedTvInput().getDisplayName();
- return String.format(getString(R.string.edit_channels_title), displayName);
+ public void onDetach() {
+ super.onDetach();
+ mTvActivity.onSideFragmentCanceled(getInitiator());
+ mTvActivity.hideOverlays(false, false, true);
}
@Override
- protected List<Item> getItemList() {
- ArrayList<Item> items = new ArrayList<>();
- items.add(new ActionItem(getString(R.string.edit_channels_show_all)) {
- @Override
- protected void onSelected() {
- super.onSelected();
- updateAllChannels(true);
- }
- });
- items.add(new ActionItem(getString(R.string.edit_channels_hide_all)) {
- @Override
- protected void onSelected() {
- super.onSelected();
- updateAllChannels(false);
- }
- });
- items.add(new DividerItem());
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ mTvActivity = (TvActivity) getActivity();
+ mSelectedInput = mTvActivity.getSelectedTvInput();
+
+ mActions = getActivity().getResources().getStringArray(R.array.edit_channels_actions);
+ mItems = new Item[mActions.length + mChannels.length + 1];
+ int index = 0;
+ for (; index < mActions.length; ++index) {
+ mItems[index] = new Item(Item.TYPE_ACTION, index ,null);
+ }
+ mItems[index++] = new Item(Item.TYPE_DIVIDER, 0, null);
for (Channel channel : mChannels) {
- final Channel currentChannel = channel;
- items.add(new CheckBoxItem(getChannelName(channel)) {
- @Override
- protected void bind(View view) {
- super.bind(view);
- setChecked(currentChannel.isBrowsable());
- }
-
- @Override
- protected void onSelected() {
- super.onSelected();
-
- Uri uri = TvContract.buildChannelUri(currentChannel.getId());
- ContentValues values = new ContentValues();
- values.put(TvContract.Channels.COLUMN_BROWSABLE, getChecked() ? 1 : 0);
- getActivity().getContentResolver().update(uri, values, null, null);
-
- currentChannel.setBrowsable(getChecked());
- if (!getChecked()) {
- maybeDisplayAllUnchecked();
- }
- }
- });
+ mItems[index++] = new Item(Item.TYPE_CHANNEL, 0, channel);
}
- return items;
- }
+ String displayName = mSelectedInput.getDisplayName();
+ String title = String.format(getString(R.string.edit_channels_title), displayName);
+ initialize(title, mItems, R.layout.option_fragment, R.layout.edit_channels_item,
+ R.color.option_item_background, R.color.option_item_focused_background,
+ R.dimen.edit_channels_item_height);
- private void maybeDisplayAllUnchecked() {
- if (!hasBrowsableChannel()) {
+ if (mBrowsableChannelCount <= 0) {
Toast.makeText(getActivity(), R.string.all_the_channels_are_unchecked,
Toast.LENGTH_SHORT).show();
}
+
+ return super.onCreateView(inflater, container, savedInstanceState);
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ // TODO: the current channel should be initially focused.
+ setSelectedPosition(0);
+ }
+
+ @Override
+ public void onBindView(View v, int position, Object tag, boolean prevSelected) {
+ super.onBindView(v, position, tag, prevSelected);
+
+ CheckBox checkBox = (CheckBox) v.findViewById(R.id.check_box);
+ TextView textView = (TextView) v.findViewById(R.id.channel_text_view);
+ View itemContainer = v.findViewById(R.id.item_container);
+ View divider = v.findViewById(R.id.divider);
+
+ Item item = (Item) tag;
+ if (item.mType == Item.TYPE_ACTION) {
+ checkBox.setVisibility(View.GONE);
+ textView.setText(mActions[item.mAction]);
+ } else if (item.mType == Item.TYPE_CHANNEL) {
+ checkBox.setVisibility(View.VISIBLE);
+ checkBox.setChecked(item.mChannel.isBrowsable());
+
+ String channelNumber = item.mChannel.getDisplayNumber();
+ String channelName = item.mChannel.getDisplayName();
+ String channelString;
+ if (TextUtils.isEmpty(channelName)) {
+ channelString = channelNumber;
+ } else {
+ channelString = String.format(getString(R.string.channel_item),
+ channelNumber, channelName);
+ }
+ textView.setText(channelString);
+ }
+ divider.setVisibility(item.mType == Item.TYPE_DIVIDER ? View.VISIBLE : View.GONE);
+ itemContainer.setVisibility(item.mType != Item.TYPE_DIVIDER ? View.VISIBLE : View.GONE);
+ v.setFocusable(item.mType != Item.TYPE_DIVIDER);
+ }
+
+ @Override
+ public void onItemSelected(View v, int position, Object tag) {
+ Item item = (Item) tag;
+ if (item.mType == Item.TYPE_ACTION) {
+ if (item.mAction == ACTION_SHOW_ALL) {
+ updateAllChannels(true);
+ } else if (item.mAction == ACTION_HIDE_ALL) {
+ updateAllChannels(false);
+ }
+ } else if (item.mType == Item.TYPE_CHANNEL) {
+ CheckBox checkBox = (CheckBox) v.findViewById(R.id.check_box);
+ boolean checked = checkBox.isChecked();
+
+ Channel channel = item.mChannel;
+ Uri uri = TvContract.buildChannelUri(channel.getId());
+ ContentValues values = new ContentValues();
+ values.put(TvContract.Channels.COLUMN_BROWSABLE, checked ? 0 : 1);
+ getActivity().getContentResolver().update(uri, values, null, null);
+ channel.setBrowsable(!checked);
+
+ checkBox.setChecked(!checked);
+ mBrowsableChannelCount += checked ? -1 : 1;
+ if (mBrowsableChannelCount <= 0) {
+ Toast.makeText(getActivity(), R.string.all_the_channels_are_unchecked,
+ Toast.LENGTH_SHORT).show();
+ }
+ }
+
+ super.onItemSelected(v, position, tag);
}
private void updateAllChannels(boolean browsable) {
- Uri uri = getTvActivity().getSelectedTvInput().buildChannelsUri(null);
+ Uri uri = mSelectedInput.buildChannelsUri(null);
ContentValues values = new ContentValues();
values.put(TvContract.Channels.COLUMN_BROWSABLE, browsable ? 1 : 0);
+
getActivity().getContentResolver().update(uri, values, null, null);
for (Channel channel : mChannels) {
channel.setBrowsable(browsable);
}
notifyDataSetChanged();
- maybeDisplayAllUnchecked();
- }
- private boolean hasBrowsableChannel() {
- for (Channel channel : mChannels) {
- if (channel.isBrowsable()) {
- return true;
- }
+ if (browsable) {
+ mBrowsableChannelCount = mChannels.length;
+ } else {
+ mBrowsableChannelCount = 0;
+ Toast.makeText(getActivity(), R.string.all_the_channels_are_unchecked,
+ Toast.LENGTH_SHORT).show();
}
- return false;
}
- private String getChannelName(Channel channel) {
- String channelName = channel.getDisplayName();
- String channelNumber = channel.getDisplayNumber();
- if (TextUtils.isEmpty(channelName)) {
- return channelNumber;
- }
- return String.format(getString(R.string.channel_item), channelNumber, channelName);
+ @Override
+ public void onItemFocusChanged(View v, boolean focusGained, int position, Object tag) {
+ super.onItemFocusChanged(v, focusGained, position, tag);
}
-} \ No newline at end of file
+}
diff --git a/src/com/android/tv/ui/sidepanel/InputPickerFragment.java b/src/com/android/tv/ui/sidepanel/InputPickerFragment.java
index ffd48793..8a05cc1e 100644
--- a/src/com/android/tv/ui/sidepanel/InputPickerFragment.java
+++ b/src/com/android/tv/ui/sidepanel/InputPickerFragment.java
@@ -17,80 +17,99 @@
package com.android.tv.ui.sidepanel;
import android.media.tv.TvInputInfo;
+import android.media.tv.TvInputManager;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.RadioButton;
+import com.android.internal.util.Preconditions;
import com.android.tv.R;
+import com.android.tv.TvActivity;
import com.android.tv.input.TisTvInput;
import com.android.tv.input.TvInput;
import com.android.tv.input.UnifiedTvInput;
-import com.android.tv.util.Utils;
+import com.android.tv.util.TvInputManagerHelper;
-import java.util.ArrayList;
-import java.util.Collections;
+import java.util.Arrays;
+import java.util.Collection;
import java.util.Comparator;
-import java.util.List;
-public class InputPickerFragment extends SideFragment {
- @Override
- protected String getTitle() {
- return getString(R.string.select_input_device);
- }
+public class InputPickerFragment extends BaseOptionFragment {
+ private TvInput mSelectedInput;
- @Override
- protected List<Item> getItemList() {
- ArrayList<Item> items = new ArrayList<>();
+ private TvActivity mTvActivity;
+ private boolean mIsFirstResume;
+ private int mInitialPosition;
- items.add(new TvInputItem(
- new UnifiedTvInput(getTvActivity().getTvInputManagerHelper(), getActivity())));
+ private TvInputManagerHelper mInputManager;
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ mIsFirstResume = true;
+ mTvActivity = (TvActivity) getActivity();
+ mInputManager = mTvActivity.getTvInputManagerHelper();
+ mInputManager.update();
+ Collection<TvInputInfo> inputInfos = mInputManager.getTvInputInfos(false);
+ int inputSize = inputInfos.size();
+ Preconditions.checkState(inputSize > 0);
+ mSelectedInput = mTvActivity.getSelectedTvInput();
- getTvActivity().getTvInputManagerHelper().update();
- List<TvInputInfo> infos = new ArrayList<>(
- getTvActivity().getTvInputManagerHelper().getTvInputInfos(false));
- Collections.sort(infos, new Comparator<TvInputInfo>() {
+ Object[] items = new Object[inputSize + 1];
+ // Unified TV input is always the first item.
+ items[0] = new UnifiedTvInput(mInputManager, getActivity());
+ int i = 1;
+ for (TvInputInfo inputInfo : inputInfos) {
+ items[i++] = new TisTvInput(mInputManager, inputInfo, mTvActivity);
+ }
+ Arrays.sort(items, 1, items.length, new Comparator<Object>() {
@Override
- public int compare(TvInputInfo lhs, TvInputInfo rhs) {
- String a = Utils.getDisplayNameForInput(getActivity(), lhs);
- String b = Utils.getDisplayNameForInput(getActivity(), rhs);
- return a.compareTo(b);
+ public int compare(Object lhs, Object rhs) {
+ return ((TvInput) lhs).getDisplayName().compareTo(((TvInput) rhs).getDisplayName());
}
});
- for (TvInputInfo inputInfo : infos) {
- if (inputInfo.getType() == TvInputInfo.TYPE_TUNER) {
- items.add(new TvInputItem(new TisTvInput(
- getTvActivity().getTvInputManagerHelper(), inputInfo, getActivity())));
- }
- }
- TvInput selected = getTvActivity().getSelectedTvInput();
- if (selected == null) {
- ((TvInputItem) items.get(0)).setChecked(true);
- } else {
- for (Item item : items) {
- if (((TvInputItem) item).getTvInput().equals(selected)) {
- ((TvInputItem) item).setChecked(true);
- break;
- }
+ mInitialPosition = 0;
+ for (i = 0; i < items.length; ++i) {
+ if (items[i].equals(mSelectedInput)) {
+ mInitialPosition = i;
+ break;
}
}
-
- return items;
+ initialize(getString(R.string.select_input_device), items);
+ return super.onCreateView(inflater, container, savedInstanceState);
}
- private class TvInputItem extends RadioButtonItem {
- private TvInput mTvInput;
-
- private TvInputItem(TvInput tvInput) {
- super(tvInput.getDisplayName());
- mTvInput = tvInput;
+ @Override
+ public void onResume() {
+ super.onResume();
+ if (mIsFirstResume) {
+ setSelectedPosition(mInitialPosition);
+ setPrevSelectedItemPosition(mInitialPosition);
+ mIsFirstResume = false;
}
+ }
- public TvInput getTvInput() {
- return mTvInput;
- }
+ @Override
+ public void onBindView(View v, int position, Object tag, boolean prevSelected) {
+ super.onBindView(v, position, tag, prevSelected);
+ TvInput input = (TvInput) tag;
+ boolean available = input.getInputState() != TvInputManager.INPUT_STATE_DISCONNECTED;
+ v.setEnabled(available);
+ v.setClickable(available);
+
+ RadioButton radioButton = (RadioButton) v.findViewById(R.id.option_item);
+ radioButton.setEnabled(available);
+ radioButton.setText(input.getDisplayName());
+ }
- @Override
- protected void onSelected() {
- super.onSelected();
- getTvActivity().onInputPicked(mTvInput);
+ @Override
+ public void onItemSelected(View v, int position, Object tag) {
+ if (!((TvInput) tag).equals(mSelectedInput)) {
+ mTvActivity.onInputPicked((TvInput) tag);
}
+ super.onItemSelected(v, position, tag);
}
-} \ No newline at end of file
+}
diff --git a/src/com/android/tv/ui/sidepanel/PipLocationFragment.java b/src/com/android/tv/ui/sidepanel/PipLocationFragment.java
index f901d702..23c97274 100644
--- a/src/com/android/tv/ui/sidepanel/PipLocationFragment.java
+++ b/src/com/android/tv/ui/sidepanel/PipLocationFragment.java
@@ -16,63 +16,81 @@
package com.android.tv.ui.sidepanel;
-import android.graphics.Bitmap;
-import android.graphics.drawable.BitmapDrawable;
-import android.view.Gravity;
+import android.os.Bundle;
+import android.view.LayoutInflater;
import android.view.View;
-import android.widget.RadioButton;
+import android.view.ViewGroup;
+import android.widget.ImageView;
import com.android.tv.R;
+import com.android.tv.TvActivity;
import com.android.tv.util.TvSettings;
-import java.util.ArrayList;
-import java.util.List;
+public class PipLocationFragment extends BaseOptionFragment {
+ private static final String TAG = "PipLocationFragment";
+ private static final boolean DEBUG = true;
-public class PipLocationFragment extends SideFragment {
- @Override
- protected String getTitle() {
- return getString(R.string.pip_location_option_title);
- }
+ private TvActivity mTvActivity;
+ private boolean mIsFirstResume;
+ private int mPipLocation;
+ private final int[] mLocationToItemPosition = new int[4];
+ private final Object[] mItem = new Integer[] {
+ TvSettings.PIP_LOCATION_BOTTOM_RIGHT,
+ TvSettings.PIP_LOCATION_TOP_RIGHT,
+ TvSettings.PIP_LOCATION_TOP_LEFT,
+ TvSettings.PIP_LOCATION_BOTTOM_LEFT,
+ };
@Override
- protected List<Item> getItemList() {
- ArrayList<Item> items = new ArrayList<>();
- items.add(new PipLocationRadio(
- TvSettings.PIP_LOCATION_TOP_LEFT, R.drawable.ic_pip_loc_top_left));
- items.add(new PipLocationRadio(
- TvSettings.PIP_LOCATION_TOP_RIGHT, R.drawable.ic_pip_loc_top_right));
- items.add(new PipLocationRadio(
- TvSettings.PIP_LOCATION_BOTTOM_LEFT, R.drawable.ic_pip_loc_bottom_left));
- items.add(new PipLocationRadio(
- TvSettings.PIP_LOCATION_BOTTOM_RIGHT, R.drawable.ic_pip_loc_bottom_right));
- return items;
- }
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ mIsFirstResume = true;
+ mTvActivity = (TvActivity) getActivity();
- private class PipLocationRadio extends RadioButtonItem {
- int mLocation;
- int mDrawable;
+ mLocationToItemPosition[TvSettings.PIP_LOCATION_BOTTOM_RIGHT] = 0;
+ mLocationToItemPosition[TvSettings.PIP_LOCATION_TOP_RIGHT] = 1;
+ mLocationToItemPosition[TvSettings.PIP_LOCATION_TOP_LEFT] = 2;
+ mLocationToItemPosition[TvSettings.PIP_LOCATION_BOTTOM_LEFT] = 3;
- private PipLocationRadio(int location, int drawable) {
- super(null);
- mLocation = location;
- mDrawable = drawable;
- }
+ initialize(getString(R.string.pip_location_option_title),
+ R.layout.pip_location_item, mItem);
+ return super.onCreateView(inflater, container, savedInstanceState);
+ }
- @Override
- protected void bind(View view) {
- super.bind(view);
- RadioButton radioButton = (RadioButton) view.findViewById(R.id.radio_button);
- BitmapDrawable drawable = (BitmapDrawable) getResources().getDrawable(mDrawable);
- drawable.setGravity(Gravity.CENTER);
- drawable.setTargetDensity(Bitmap.DENSITY_NONE);
- drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
- radioButton.setCompoundDrawablesRelative(drawable, null, null, null);
+ @Override
+ public void onResume() {
+ super.onResume();
+ if (mIsFirstResume) {
+ mPipLocation = mTvActivity.getPipLocation();
+ int initialPosition = mLocationToItemPosition[mPipLocation];
+ setSelectedPosition(initialPosition);
+ setPrevSelectedItemPosition(initialPosition);
+ mIsFirstResume = false;
}
+ }
- @Override
- protected void onSelected() {
- super.onSelected();
- getTvActivity().setPipLocation(mLocation, true);
+ @Override
+ public void onBindView(View v, int position, Object tag, boolean prevSelected) {
+ super.onBindView(v, position, tag, prevSelected);
+ ImageView pipLocationImageView = (ImageView) v.findViewById(R.id.pip_location);
+ int location = (Integer) tag;
+ if (location == TvSettings.PIP_LOCATION_TOP_LEFT) {
+ pipLocationImageView.setImageResource(R.drawable.ic_pip_loc_top_left);
+ } else if (location == TvSettings.PIP_LOCATION_TOP_RIGHT) {
+ pipLocationImageView.setImageResource(R.drawable.ic_pip_loc_top_right);
+ } else if (location == TvSettings.PIP_LOCATION_BOTTOM_LEFT) {
+ pipLocationImageView.setImageResource(R.drawable.ic_pip_loc_bottom_left);
+ } else if (location == TvSettings.PIP_LOCATION_BOTTOM_RIGHT) {
+ pipLocationImageView.setImageResource(R.drawable.ic_pip_loc_bottom_right);
+ } else {
+ throw new IllegalArgumentException("Invaild PIP location: " + location);
}
}
-} \ No newline at end of file
+
+ @Override
+ public void onItemSelected(View v, int position, Object tag) {
+ int pipLocation = (Integer) tag;
+ mTvActivity.setPipLocation(pipLocation, true);
+ super.onItemSelected(v, position, tag);
+ }
+}