aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--res/values/strings.xml3
-rw-r--r--src/com/android/tv/TvActivity.java2
-rw-r--r--src/com/android/tv/ui/ChannelListAdapter.java26
-rw-r--r--src/com/android/tv/ui/ItemListView.java1
-rw-r--r--src/com/android/tv/ui/MainMenuView.java69
-rw-r--r--src/com/android/tv/ui/RecommendationListAdapter.java105
6 files changed, 174 insertions, 32 deletions
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 5eac1313..744a3300 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -72,6 +72,9 @@
<!-- Privacy setting dialog title-->
<string name="privacy_dialog_title">Privacy Settings</string>
+ <!-- Recommended channel list title -->
+ <string name="recommended_channel_list_title">Recommended Channels</string>
+
<!-- Confirmation of TV watch logging -->
<string name="privacy_watch_logging">Send TV watch history to Google</string>
diff --git a/src/com/android/tv/TvActivity.java b/src/com/android/tv/TvActivity.java
index cf86373e..66d54dc7 100644
--- a/src/com/android/tv/TvActivity.java
+++ b/src/com/android/tv/TvActivity.java
@@ -852,6 +852,8 @@ public class TvActivity extends Activity implements
&& id != mChannelMap.getCurrentChannelId()) {
if (mChannelMap.moveToChannel(id)) {
tune();
+ } else if (!TextUtils.isEmpty(Utils.getInputIdForChannel(this, id))) {
+ startTv(id);
} else {
Toast.makeText(this, R.string.input_is_not_available, Toast.LENGTH_SHORT).show();
}
diff --git a/src/com/android/tv/ui/ChannelListAdapter.java b/src/com/android/tv/ui/ChannelListAdapter.java
index baacb752..8989daef 100644
--- a/src/com/android/tv/ui/ChannelListAdapter.java
+++ b/src/com/android/tv/ui/ChannelListAdapter.java
@@ -30,6 +30,7 @@ import java.util.ArrayList;
* An adapter of channel list.
*/
public class ChannelListAdapter extends ItemListView.ItemListAdapter {
+ private ChannelMap mChannelMap;
private Channel[] mChannelList;
private ItemListView mListView;
private boolean mBrowsableOnly;
@@ -63,15 +64,27 @@ public class ChannelListAdapter extends ItemListView.ItemListAdapter {
@Override
public void update(ChannelMap channelMap, ItemListView listView) {
- mChannelList = channelMap == null ? null : channelMap.getChannelList(mBrowsableOnly);
+ mChannelMap = channelMap;
+ mListView = listView;
+
+ mChannelList = mChannelMap == null ? null : mChannelMap.getChannelList(mBrowsableOnly);
setItemList(mChannelList);
+ updateTitle();
+ selectCurrentChannel();
+ }
+
+ @Override
+ public void onBeforeShowing() {
+ updateTitle();
+ selectCurrentChannel();
+ }
+
+ private void updateTitle() {
if (mFixedTitle == null) {
mTitle = null;
- mListView = listView;
- if (channelMap != null) {
- setCurrentChannelId(channelMap.getCurrentChannelId());
- mTitle = channelMap.getTvInput().getDisplayName();
+ if (mChannelMap != null) {
+ mTitle = mChannelMap.getTvInput().getDisplayName();
}
if (mListView != null) {
@@ -80,7 +93,8 @@ public class ChannelListAdapter extends ItemListView.ItemListAdapter {
}
}
- public void setCurrentChannelId(long id) {
+ private void selectCurrentChannel() {
+ long id = mChannelMap == null ? Channel.INVALID_ID : mChannelMap.getCurrentChannelId();
if (mListView == null || mChannelList == null || id == Channel.INVALID_ID) {
return;
}
diff --git a/src/com/android/tv/ui/ItemListView.java b/src/com/android/tv/ui/ItemListView.java
index 9e89e5a0..9e162b13 100644
--- a/src/com/android/tv/ui/ItemListView.java
+++ b/src/com/android/tv/ui/ItemListView.java
@@ -87,6 +87,7 @@ public class ItemListView extends LinearLayout {
public abstract String getTitle();
public abstract void update(ChannelMap channelMap);
public abstract void update(ChannelMap channelMap, ItemListView list);
+ public void onBeforeShowing() {}
public ItemListAdapter(Context context, Handler handler, int layoutResId,
View.OnClickListener onClickListener) {
diff --git a/src/com/android/tv/ui/MainMenuView.java b/src/com/android/tv/ui/MainMenuView.java
index 6c38c3ec..2b2a4c13 100644
--- a/src/com/android/tv/ui/MainMenuView.java
+++ b/src/com/android/tv/ui/MainMenuView.java
@@ -32,9 +32,11 @@ import com.android.tv.TvActivity;
import com.android.tv.data.Channel;
import com.android.tv.data.ChannelMap;
import com.android.tv.dialog.PrivacySettingDialogFragment;
+import com.android.tv.recommendation.TvRecommendation;
import com.android.tv.util.Utils;
import java.util.ArrayList;
+import java.util.Arrays;
/*
* A subclass of VerticalGridView that shows tv main menu.
@@ -44,24 +46,19 @@ public class MainMenuView extends VerticalGridView implements View.OnClickListen
private static final int CHANNEL_LIST_TYPE = 1;
private static final int OPTIONS_TYPE = 2;
+ private static final int MAX_COUNT_FOR_RECOMMENDATION = 10;
+
private final LayoutInflater mLayoutInflater;
private final MainMenuAdapter mAdapter = new MainMenuAdapter();
private ChannelMap mChannelMap;
private TvActivity mTvActivity;
+ private TvRecommendation mTvRecommendation;
+
private final Handler mHandler = new Handler();
private final ArrayList<ItemListView.ItemListAdapter> mAllAdapterList =
new ArrayList<ItemListView.ItemListAdapter>();
- private SharedPreferences.OnSharedPreferenceChangeListener mPrefChangeListener =
- new SharedPreferences.OnSharedPreferenceChangeListener() {
- public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
- if (mChannelMap != null) {
- updateAdapters();
- }
- }
- };
-
public MainMenuView(Context context) {
this(context, null, 0);
}
@@ -74,30 +71,39 @@ public class MainMenuView extends VerticalGridView implements View.OnClickListen
super(context, attrs, defStyle);
mLayoutInflater = LayoutInflater.from(context);
-
setAdapter(mAdapter);
+ }
+
+ @Override
+ protected void onAttachedToWindow() {
+ Context context = getContext();
// List for enabled channels
mAllAdapterList.add(new ChannelListAdapter(context, mHandler, this, true, null,
context.getResources().getDimensionPixelOffset(R.dimen.channel_list_view_height)));
+ // List for recommended channels
+ mTvRecommendation = new TvRecommendation(context, mHandler);
+ mAllAdapterList.add(new RecommendationListAdapter(context, mHandler, this,
+ mTvRecommendation, MAX_COUNT_FOR_RECOMMENDATION, R.layout.channel_tile,
+ context.getString(R.string.recommended_channel_list_title),
+ context.getResources().getDimensionPixelOffset(R.dimen.channel_list_view_height)));
+
// List for options
mAllAdapterList.add(new OptionsAdapter(context, mHandler, this));
// Keep all items for the main menu
setItemViewCacheSize(mAllAdapterList.size());
- }
-
- @Override
- protected void onAttachedToWindow() {
- Utils.getSharedPreferencesOfDisplayNameForInput(getContext())
- .registerOnSharedPreferenceChangeListener(mPrefChangeListener);
+ updateAdapters(true);
}
@Override
protected void onDetachedFromWindow() {
- Utils.getSharedPreferencesOfDisplayNameForInput(getContext())
- .unregisterOnSharedPreferenceChangeListener(mPrefChangeListener);
+ mAllAdapterList.clear();
+ updateAdapters(false);
+
+ mTvRecommendation.release();
+ mTvRecommendation = null;
}
public void setTvActivity(TvActivity activity) {
@@ -106,14 +112,16 @@ public class MainMenuView extends VerticalGridView implements View.OnClickListen
public void setChannelMap(ChannelMap channelMap) {
mChannelMap = channelMap;
- updateAdapters();
+ updateAdapters(true);
}
- private void updateAdapters() {
+ private void updateAdapters(boolean channelMapUpdateRequired) {
ArrayList<ItemListView.ItemListAdapter> availableAdapterList =
new ArrayList<ItemListView.ItemListAdapter>();
for (ItemListView.ItemListAdapter adapter : mAllAdapterList) {
- adapter.update(mChannelMap);
+ if (channelMapUpdateRequired) {
+ adapter.update(mChannelMap);
+ }
if (adapter.getItemCount() > 0) {
availableAdapterList.add(adapter);
}
@@ -125,13 +133,20 @@ public class MainMenuView extends VerticalGridView implements View.OnClickListen
private void show() {
if (mChannelMap != null) {
- long id = mChannelMap.getCurrentChannelId();
+ boolean adapterVisibilityChanged = false;
for (ItemListView.ItemListAdapter adapter : mAllAdapterList) {
- if (adapter instanceof ChannelListAdapter) {
- ((ChannelListAdapter) adapter).setCurrentChannelId(id);
+ int prevCount = adapter.getItemCount();
+ adapter.onBeforeShowing();
+ int currCount = adapter.getItemCount();
+ if ((prevCount == 0 && currCount != 0) || (prevCount != 0 && currCount == 0)) {
+ adapterVisibilityChanged = true;
}
}
+
+ if (adapterVisibilityChanged) {
+ updateAdapters(false);
+ }
}
setSelectedPosition(0);
@@ -239,8 +254,10 @@ public class MainMenuView extends VerticalGridView implements View.OnClickListen
private ItemListView.ItemListAdapter[] mAdapters;
public void setItemListAdapters(ItemListView.ItemListAdapter[] adapters) {
- mAdapters = adapters;
- notifyDataSetChanged();
+ if (!Arrays.equals(mAdapters, adapters)) {
+ mAdapters = adapters;
+ notifyDataSetChanged();
+ }
}
@Override
diff --git a/src/com/android/tv/ui/RecommendationListAdapter.java b/src/com/android/tv/ui/RecommendationListAdapter.java
new file mode 100644
index 00000000..906a4a58
--- /dev/null
+++ b/src/com/android/tv/ui/RecommendationListAdapter.java
@@ -0,0 +1,105 @@
+/*
+ * 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.content.Context;
+import android.os.Handler;
+import android.view.View;
+
+import com.android.tv.R;
+import com.android.tv.data.Channel;
+import com.android.tv.data.ChannelMap;
+import com.android.tv.recommendation.TvRecommendation;
+
+/*
+ * An adapter of recommended channel list.
+ */
+public class RecommendationListAdapter extends ItemListView.ItemListAdapter {
+ private ChannelMap mChannelMap;
+ private Channel[] mChannelList;
+ private ItemListView mListView;
+ private final String mTitle;
+ private final int mTileHeight;
+ private final int mMaxCount;
+ private final TvRecommendation mRecommendationEngine;
+
+ public RecommendationListAdapter(Context context, Handler handler,
+ View.OnClickListener onClickListener, TvRecommendation recommendationEngine,
+ int maxCount, int tileResId, String title, int tileHeight) {
+ super(context, handler, tileResId, onClickListener);
+ mRecommendationEngine = recommendationEngine;
+ mMaxCount = maxCount;
+ mTitle = title;
+ mTileHeight = tileHeight;
+ }
+
+ @Override
+ public int getTileHeight() {
+ return mTileHeight;
+ }
+
+ @Override
+ public String getTitle() {
+ return mTitle;
+ }
+
+ @Override
+ public void update(ChannelMap channelMap) {
+ update(channelMap, mListView);
+ }
+
+ @Override
+ public void update(ChannelMap channelMap, ItemListView listView) {
+ mChannelMap = channelMap;
+ mListView = listView;
+
+ updateChannelList();
+ selectCurrentChannel();
+ }
+
+ @Override
+ public void onBeforeShowing() {
+ updateChannelList();
+ selectCurrentChannel();
+ }
+
+ private void updateChannelList() {
+ TvRecommendation.ChannelRecord[] records =
+ mRecommendationEngine.getRecommendedChannelList(mMaxCount);
+ mChannelList = null;
+ if (records != null && records.length > 0) {
+ mChannelList = new Channel[records.length];
+ for (int i = 0; i < records.length; i++) {
+ mChannelList[i] = records[i].getChannel();
+ }
+ }
+ setItemList(mChannelList);
+ }
+
+ private void selectCurrentChannel() {
+ long id = mChannelMap == null ? Channel.INVALID_ID : mChannelMap.getCurrentChannelId();
+ if (mListView == null || mChannelList == null || id == Channel.INVALID_ID) {
+ return;
+ }
+ for (int i = 0; i < mChannelList.length; i++) {
+ if (id == mChannelList[i].getId()) {
+ mListView.setSelectedPosition(i);
+ break;
+ }
+ }
+ }
+} \ No newline at end of file