diff options
author | Youngsang Cho <youngsang@google.com> | 2014-06-30 21:22:05 +0900 |
---|---|---|
committer | Youngsang Cho <youngsang@google.com> | 2014-07-01 11:00:10 +0900 |
commit | 4871e7e0af07ecdb934d1f102d9e1b368667cff6 (patch) | |
tree | 59811cb2ed2dbaa18fdf2d646aa0524eb541caf4 | |
parent | 0876c00c1eaf1ff68855f4b706c37eea616e3309 (diff) | |
download | TV-4871e7e0af07ecdb934d1f102d9e1b368667cff6.tar.gz |
Add an option to change PIP position
TODO: redesign UI
Bug: 15843702
Change-Id: Ia48579ba78809bcd5fdf4b2a29cf97a715bcc253
-rw-r--r-- | res/drawable-xhdpi/ic_pip_loc_bottom_left.png | bin | 0 -> 1353 bytes | |||
-rw-r--r-- | res/drawable-xhdpi/ic_pip_loc_bottom_right.png | bin | 0 -> 2206 bytes | |||
-rw-r--r-- | res/drawable-xhdpi/ic_pip_loc_top_left.png | bin | 0 -> 1352 bytes | |||
-rw-r--r-- | res/drawable-xhdpi/ic_pip_loc_top_right.png | bin | 0 -> 1351 bytes | |||
-rw-r--r-- | res/drawable-xhdpi/ic_tvoption_locate_pip.png | bin | 0 -> 1840 bytes | |||
-rw-r--r-- | res/layout/activity_tv.xml | 2 | ||||
-rw-r--r-- | res/layout/pip_location_item.xml | 41 | ||||
-rw-r--r-- | res/values/strings.xml | 2 | ||||
-rw-r--r-- | src/com/android/tv/TvActivity.java | 38 | ||||
-rw-r--r-- | src/com/android/tv/ui/BaseOptionFragment.java | 8 | ||||
-rw-r--r-- | src/com/android/tv/ui/MainMenuView.java | 5 | ||||
-rw-r--r-- | src/com/android/tv/ui/MenuAction.java | 12 | ||||
-rw-r--r-- | src/com/android/tv/ui/OptionsAdapter.java | 1 | ||||
-rw-r--r-- | src/com/android/tv/ui/PipLocationFragment.java | 99 | ||||
-rw-r--r-- | src/com/android/tv/util/TvSettings.java | 6 |
15 files changed, 209 insertions, 5 deletions
diff --git a/res/drawable-xhdpi/ic_pip_loc_bottom_left.png b/res/drawable-xhdpi/ic_pip_loc_bottom_left.png Binary files differnew file mode 100644 index 00000000..2e28fc38 --- /dev/null +++ b/res/drawable-xhdpi/ic_pip_loc_bottom_left.png diff --git a/res/drawable-xhdpi/ic_pip_loc_bottom_right.png b/res/drawable-xhdpi/ic_pip_loc_bottom_right.png Binary files differnew file mode 100644 index 00000000..db0727ef --- /dev/null +++ b/res/drawable-xhdpi/ic_pip_loc_bottom_right.png diff --git a/res/drawable-xhdpi/ic_pip_loc_top_left.png b/res/drawable-xhdpi/ic_pip_loc_top_left.png Binary files differnew file mode 100644 index 00000000..539fcc3a --- /dev/null +++ b/res/drawable-xhdpi/ic_pip_loc_top_left.png diff --git a/res/drawable-xhdpi/ic_pip_loc_top_right.png b/res/drawable-xhdpi/ic_pip_loc_top_right.png Binary files differnew file mode 100644 index 00000000..bae9ef2f --- /dev/null +++ b/res/drawable-xhdpi/ic_pip_loc_top_right.png diff --git a/res/drawable-xhdpi/ic_tvoption_locate_pip.png b/res/drawable-xhdpi/ic_tvoption_locate_pip.png Binary files differnew file mode 100644 index 00000000..0faf2dfd --- /dev/null +++ b/res/drawable-xhdpi/ic_tvoption_locate_pip.png diff --git a/res/layout/activity_tv.xml b/res/layout/activity_tv.xml index 2de04e9b..4f13fa29 100644 --- a/res/layout/activity_tv.xml +++ b/res/layout/activity_tv.xml @@ -28,7 +28,9 @@ <com.android.tv.ui.TunableTvView android:id="@+id/pip_view" android:visibility="invisible" + android:layout_marginLeft="56dp" android:layout_marginRight="56dp" + android:layout_marginTop="27dp" android:layout_marginBottom="27dp" android:layout_width="240dp" android:layout_height="135dp" diff --git a/res/layout/pip_location_item.xml b/res/layout/pip_location_item.xml new file mode 100644 index 00000000..37fe80e2 --- /dev/null +++ b/res/layout/pip_location_item.xml @@ -0,0 +1,41 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- 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. +--> + +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="@dimen/option_item_height" + android:paddingRight="@dimen/side_panel_padding_right" + android:paddingLeft="@dimen/side_panel_padding_left" + android:focusable="true" + android:orientation="horizontal" > + + <RadioButton + android:id="@+id/option_item" + android:layout_height="match_parent" + android:layout_width="wrap_content" + android:gravity="left|center_vertical" + android:paddingLeft="@dimen/option_item_padding_left" + android:textSize="@dimen/option_item_text_size" + android:textColor="@color/side_panel_item_text" + android:singleLine="true" + android:focusable="false" + android:fontFamily="@string/font" /> + + <ImageView + android:id="@+id/pip_location" + android:layout_height="wrap_content" + android:layout_width="wrap_content" /> +</LinearLayout> diff --git a/res/values/strings.xml b/res/values/strings.xml index a9b076eb..743bcdf6 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -54,6 +54,8 @@ <string name="menu_select_input">TV Input</string> <!-- Toggle PIP [CHAR LIMIT=15] --> <string name="menu_toggle_pip">PIP</string> + <!-- Locate PIP [CHAR LIMIT=15] --> + <string name="menu_select_pip_location">Locate PIP</string> <!-- Source specific settings menu option [CHAR LIMIT=15] --> <string name="source_specific_setting">More</string> diff --git a/src/com/android/tv/TvActivity.java b/src/com/android/tv/TvActivity.java index 66581c32..3c7500fd 100644 --- a/src/com/android/tv/TvActivity.java +++ b/src/com/android/tv/TvActivity.java @@ -39,6 +39,7 @@ import android.util.Log; import android.view.Display; import android.view.GestureDetector; import android.view.GestureDetector.SimpleOnGestureListener; +import android.view.Gravity; import android.view.InputEvent; import android.view.KeyEvent; import android.view.MotionEvent; @@ -68,6 +69,7 @@ import com.android.tv.ui.EditChannelsFragment; import com.android.tv.ui.InputPickerFragment; import com.android.tv.ui.MainMenuView; import com.android.tv.ui.ChannelNumberView; +import com.android.tv.ui.PipLocationFragment; import com.android.tv.ui.SidePanelContainer; import com.android.tv.ui.SimpleGuideFragment; import com.android.tv.ui.TunableTvView; @@ -162,6 +164,7 @@ public class TvActivity extends Activity implements AudioManager.OnAudioFocusCha private boolean mIsClosedCaptionEnabled; private int mDisplayMode; + private int mPipLocation; private SharedPreferences mSharedPreferences; private SimpleGuideFragment mSimpleGuideFragment; @@ -312,6 +315,7 @@ public class TvActivity extends Activity implements AudioManager.OnAudioFocusCha mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); restoreClosedCaptionEnabled(); restoreDisplayMode(); + restorePipLocation(); onNewIntent(getIntent()); } @@ -548,6 +552,10 @@ public class TvActivity extends Activity implements AudioManager.OnAudioFocusCha showSideFragment(new ClosedCaptionOptionFragment(), initiator); } + public void showPipLocationOption(int initiator) { + showSideFragment(new PipLocationFragment(), initiator); + } + public void showSideFragment(Fragment f, int initiator) { mSidePanelContainer.setTag(SIDE_FRAGMENT_TAG_SHOW); mSidePanelContainer.setKeyDispatchable(true); @@ -1252,6 +1260,36 @@ public class TvActivity extends Activity implements AudioManager.OnAudioFocusCha DisplayMode.MODE_NORMAL), false); } + // Returns a constant defined in TvSettings. + public int getPipLocation() { + return mPipLocation; + } + + public void setPipLocation(int pipLocation, boolean storeInPreference) { + mPipLocation = pipLocation; + if (storeInPreference) { + mSharedPreferences.edit().putInt(TvSettings.PREF_PIP_LOCATION, pipLocation).apply(); + } + FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mPipView.getLayoutParams(); + if (mPipLocation == TvSettings.PIP_LOCATION_TOP_LEFT) { + lp.gravity = Gravity.TOP | Gravity.LEFT; + } else if (mPipLocation == TvSettings.PIP_LOCATION_TOP_RIGHT) { + lp.gravity = Gravity.TOP | Gravity.RIGHT; + } else if (mPipLocation == TvSettings.PIP_LOCATION_BOTTOM_LEFT) { + lp.gravity = Gravity.BOTTOM | Gravity.LEFT; + } else if (mPipLocation == TvSettings.PIP_LOCATION_BOTTOM_RIGHT) { + lp.gravity = Gravity.BOTTOM | Gravity.RIGHT; + } else { + throw new IllegalArgumentException("Invaild PIP location: " + pipLocation); + } + mPipView.setLayoutParams(lp); + } + + public void restorePipLocation() { + setDisplayMode(mSharedPreferences.getInt(TvSettings.PREF_PIP_LOCATION, + TvSettings.PIP_LOCATION_BOTTOM_RIGHT), false); + } + private class HideRunnable implements Runnable { private final View mView; private final long mWaitingTime; diff --git a/src/com/android/tv/ui/BaseOptionFragment.java b/src/com/android/tv/ui/BaseOptionFragment.java index b74e9550..c7d5a0c9 100644 --- a/src/com/android/tv/ui/BaseOptionFragment.java +++ b/src/com/android/tv/ui/BaseOptionFragment.java @@ -60,6 +60,12 @@ public class BaseOptionFragment extends BaseSideFragment { 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); @@ -79,6 +85,8 @@ public class BaseOptionFragment extends BaseSideFragment { } if (tag instanceof String) { radioButton.setText((String) tag); + } else { + radioButton.setText(""); } } diff --git a/src/com/android/tv/ui/MainMenuView.java b/src/com/android/tv/ui/MainMenuView.java index 5ab4bbe0..c0108e4e 100644 --- a/src/com/android/tv/ui/MainMenuView.java +++ b/src/com/android/tv/ui/MainMenuView.java @@ -311,6 +311,11 @@ public class MainMenuView extends FrameLayout implements View.OnClickListener, mTvActivity.togglePipView(); break; + case MenuAction.SELECT_PIP_LOCATION: + mTvActivity.showPipLocationOption( + BaseSideFragment.INITIATOR_MENU); + break; + case MenuAction.EDIT_CHANNEL_LIST_TYPE: mTvActivity.showEditChannelsFragment( BaseSideFragment.INITIATOR_MENU); diff --git a/src/com/android/tv/ui/MenuAction.java b/src/com/android/tv/ui/MenuAction.java index 9aa1d31b..5a3895e6 100644 --- a/src/com/android/tv/ui/MenuAction.java +++ b/src/com/android/tv/ui/MenuAction.java @@ -28,11 +28,10 @@ public class MenuAction { public static final int SELECT_DISPLAY_MODE = 1; public static final int SELECT_TV_INPUT_TYPE = 2; public static final int TOGGLE_PIP_TYPE = 3; - - // TODO: UX is not ready. - public static final int EDIT_CHANNEL_LIST_TYPE = 4; - public static final int AUTO_SCAN_CHANNELS_TYPE = 5; - public static final int INPUT_SETTING_TYPE = 6; + public static final int SELECT_PIP_LOCATION = 4; + public static final int EDIT_CHANNEL_LIST_TYPE = 5; + public static final int AUTO_SCAN_CHANNELS_TYPE = 6; + public static final int INPUT_SETTING_TYPE = 7; public static final MenuAction SELECT_CLOSED_CAPTION_ACTION = new MenuAction(R.string.menu_closed_caption, SELECT_CLOSED_CAPTION, @@ -46,6 +45,9 @@ public class MenuAction { public static final MenuAction TOGGLE_PIP_ACTION = new MenuAction(R.string.menu_toggle_pip, TOGGLE_PIP_TYPE, R.drawable.ic_tvoption_pip); + public static final MenuAction SELECT_PIP_LOCATION_ACTION = + new MenuAction(R.string.menu_select_pip_location, SELECT_PIP_LOCATION, + R.drawable.ic_tvoption_locate_pip); public static final MenuAction EDIT_CHANNEL_LIST_ACTION = new MenuAction(R.string.menu_edit_channels, EDIT_CHANNEL_LIST_TYPE, R.drawable.ic_tvoptions_edit_channels); diff --git a/src/com/android/tv/ui/OptionsAdapter.java b/src/com/android/tv/ui/OptionsAdapter.java index ef54c785..93a4b8a4 100644 --- a/src/com/android/tv/ui/OptionsAdapter.java +++ b/src/com/android/tv/ui/OptionsAdapter.java @@ -62,6 +62,7 @@ public class OptionsAdapter extends ItemListView.ItemListAdapter { actionList.add(MenuAction.SELECT_DISPLAY_MODE_ACTION); actionList.add(MenuAction.SELECT_TV_INPUT_ACTION); actionList.add(MenuAction.TOGGLE_PIP_ACTION); + actionList.add(MenuAction.SELECT_PIP_LOCATION_ACTION); if (channelMap != null && channelMap.size() != 0) { actionList.add(MenuAction.EDIT_CHANNEL_LIST_ACTION); } diff --git a/src/com/android/tv/ui/PipLocationFragment.java b/src/com/android/tv/ui/PipLocationFragment.java new file mode 100644 index 00000000..7e4eb64b --- /dev/null +++ b/src/com/android/tv/ui/PipLocationFragment.java @@ -0,0 +1,99 @@ +/* + * 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; + +import android.os.Bundle; +import android.util.Log; +import android.view.Gravity; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.Toast; + +import com.android.tv.R; +import com.android.tv.TvActivity; +import com.android.tv.util.TvSettings; + +public class PipLocationFragment extends BaseOptionFragment { + private static final String TAG = "PipLocationFragment"; + private static final boolean DEBUG = true; + + 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 + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + mIsFirstResume = true; + mTvActivity = (TvActivity) getActivity(); + + 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; + + initialize(getString(R.string.closed_caption_option_title), + R.layout.pip_location_item, mItem); + return super.onCreateView(inflater, container, savedInstanceState); + } + + @Override + public void onResume() { + super.onResume(); + if (mIsFirstResume) { + mPipLocation = mTvActivity.getPipLocation(); + int initialPosition = mLocationToItemPosition[mPipLocation]; + setSelectedPosition(initialPosition); + setPrevSelectedItemPosition(initialPosition); + mIsFirstResume = false; + } + } + + @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); + } + } + + @Override + public void onItemSelected(View v, int position, Object tag) { + int pipLocation = (Integer) tag; + mTvActivity.setPipLocation(pipLocation, true); + super.onItemSelected(v, position, tag); + } +} diff --git a/src/com/android/tv/util/TvSettings.java b/src/com/android/tv/util/TvSettings.java index 033342c2..4ba9da1e 100644 --- a/src/com/android/tv/util/TvSettings.java +++ b/src/com/android/tv/util/TvSettings.java @@ -28,4 +28,10 @@ public final class TvSettings { public static final String PREF_DISPLAY_INPUT_NAME = "display_input_name_"; public static final String PREF_CLOSED_CAPTION_ENABLED = "is_cc_enabled"; // boolean value public static final String PREF_DISPLAY_MODE = "display_mode"; // int value + public static final String PREF_PIP_LOCATION = "pip_location"; // int value + + public static final int PIP_LOCATION_TOP_LEFT = 0; + public static final int PIP_LOCATION_TOP_RIGHT = 1; + public static final int PIP_LOCATION_BOTTOM_LEFT = 2; + public static final int PIP_LOCATION_BOTTOM_RIGHT = 3; } |