aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/com/android/tv/data/StreamInfo.java2
-rw-r--r--src/com/android/tv/ui/ChannelBannerView.java13
-rw-r--r--src/com/android/tv/ui/TunableTvView.java16
-rw-r--r--src/com/android/tv/util/Utils.java31
4 files changed, 59 insertions, 3 deletions
diff --git a/src/com/android/tv/data/StreamInfo.java b/src/com/android/tv/data/StreamInfo.java
index bd8eb61e..cce9786e 100644
--- a/src/com/android/tv/data/StreamInfo.java
+++ b/src/com/android/tv/data/StreamInfo.java
@@ -29,6 +29,8 @@ public interface StreamInfo {
TvInputInfo getCurrentTvInputInfo();
+ int getVideoWidth();
+ int getVideoHeight();
int getVideoDefinitionLevel();
int getAudioChannelCount();
boolean hasClosedCaption();
diff --git a/src/com/android/tv/ui/ChannelBannerView.java b/src/com/android/tv/ui/ChannelBannerView.java
index d09b2926..e4710c4b 100644
--- a/src/com/android/tv/ui/ChannelBannerView.java
+++ b/src/com/android/tv/ui/ChannelBannerView.java
@@ -163,12 +163,19 @@ public class ChannelBannerView extends RelativeLayout implements Channel.LoadLog
} else {
mResolutionTextView.setVisibility(View.GONE);
}
- // TODO: implement aspect ratio.
- mAspectRatioTextView.setVisibility(View.GONE);
+
+ String aspectRatio =
+ Utils.getAspectRatioString(info.getVideoWidth(), info.getVideoHeight());
+ if (!TextUtils.isEmpty(aspectRatio)) {
+ mAspectRatioTextView.setVisibility(View.VISIBLE);
+ mAspectRatioTextView.setText(aspectRatio);
+ } else {
+ mAspectRatioTextView.setVisibility(View.GONE);
+ }
+
if (!TextUtils.isEmpty(Utils.getAudioChannelString(info.getAudioChannelCount()))) {
mAudioChannelTextView.setVisibility(View.VISIBLE);
mAudioChannelTextView.setText(Utils.getAudioChannelString(info.getAudioChannelCount()));
- mAudioChannelTextView.setVisibility(View.VISIBLE);
} else {
mAudioChannelTextView.setVisibility(View.GONE);
}
diff --git a/src/com/android/tv/ui/TunableTvView.java b/src/com/android/tv/ui/TunableTvView.java
index 68534971..058c4411 100644
--- a/src/com/android/tv/ui/TunableTvView.java
+++ b/src/com/android/tv/ui/TunableTvView.java
@@ -25,6 +25,8 @@ public class TunableTvView extends TvView implements StreamInfo {
private boolean mStarted;
private TvInputInfo mInputInfo;
private OnTuneListener mOnTuneListener;
+ private int mVideoWidth;
+ private int mVideoHeight;
private int mVideoFormat = StreamInfo.VIDEO_DEFINITION_LEVEL_UNKNOWN;
private int mAudioChannelCount = StreamInfo.AUDIO_CHANNEL_COUNT_UNKNOWN;
private boolean mHasClosedCaption = false;
@@ -79,6 +81,8 @@ public class TunableTvView extends TvView implements StreamInfo {
@Override
public void onVideoStreamChanged(String inputId, int width, int height,
boolean interlaced) {
+ mVideoWidth = width;
+ mVideoHeight = height;
mVideoFormat = Utils.getVideoDefinitionLevelFromSize(width, height);
if (mOnTuneListener != null) {
mOnTuneListener.onStreamInfoChanged(TunableTvView.this);
@@ -150,6 +154,8 @@ public class TunableTvView extends TvView implements StreamInfo {
throw new IllegalStateException("TvView isn't started");
}
if (DEBUG) Log.d(TAG, "tuneTo " + channelId);
+ mVideoWidth = 0;
+ mVideoHeight = 0;
mVideoFormat = StreamInfo.VIDEO_DEFINITION_LEVEL_UNKNOWN;
mAudioChannelCount = StreamInfo.AUDIO_CHANNEL_COUNT_UNKNOWN;
mHasClosedCaption = false;
@@ -211,6 +217,16 @@ public class TunableTvView extends TvView implements StreamInfo {
}
@Override
+ public int getVideoWidth() {
+ return mVideoWidth;
+ }
+
+ @Override
+ public int getVideoHeight() {
+ return mVideoHeight;
+ }
+
+ @Override
public int getVideoDefinitionLevel() {
return mVideoFormat;
}
diff --git a/src/com/android/tv/util/Utils.java b/src/com/android/tv/util/Utils.java
index e945db44..dc99f0fd 100644
--- a/src/com/android/tv/util/Utils.java
+++ b/src/com/android/tv/util/Utils.java
@@ -74,6 +74,24 @@ public class Utils {
private static int VIDEO_ULTRA_HD_WIDTH = 2048;
private static int VIDEO_ULTRA_HD_HEIGHT = 1536;
+ private enum AspectRatio {
+ ASPECT_RATIO_4_3(4, 3),
+ ASPECT_RATIO_16_9(16, 9),
+ ASPECT_RATIO_21_9(21, 9);
+
+ final int width;
+ final int height;
+
+ AspectRatio(int width, int height) {
+ this.width = width;
+ this.height = height;
+ }
+
+ public String toString() {
+ return String.format("%d:%d", width, height);
+ }
+ }
+
// TODO: Remove this and add inputId into TvProvider.
public static String getInputIdForComponentName(ComponentName name) {
return name.flattenToShortString();
@@ -226,6 +244,19 @@ public class Utils {
return getActivityInfo(context, input, action) != null;
}
+ public static String getAspectRatioString(int width, int height) {
+ if (width == 0 || height == 0) {
+ return "";
+ }
+
+ for (AspectRatio ratio: AspectRatio.values()) {
+ if (Math.abs((float) ratio.height / ratio.width - (float) height / width) < 0.05f) {
+ return ratio.toString();
+ }
+ }
+ return "";
+ }
+
public static int getVideoDefinitionLevelFromSize(int width, int height) {
if (width >= VIDEO_ULTRA_HD_WIDTH && height >= VIDEO_ULTRA_HD_HEIGHT) {
return StreamInfo.VIDEO_DEFINITION_LEVEL_ULTRA_HD;