aboutsummaryrefslogtreecommitdiff
path: root/src/com/android/tv/util/TvSettings.java
diff options
context:
space:
mode:
authorNick Chalko <nchalko@google.com>2015-08-03 15:39:56 -0700
committerNick Chalko <nchalko@google.com>2015-08-03 15:53:37 -0700
commit816a4be1a0f34f6a48877c8afd3dbbca19eac435 (patch)
tree4f18dda269764494942f5313acc93db4a35d47db /src/com/android/tv/util/TvSettings.java
parent6edd2b09e5d16a29c703a5fcbd2e88c5cf5e55b7 (diff)
downloadTV-816a4be1a0f34f6a48877c8afd3dbbca19eac435.tar.gz
Migrate Live Channels App Src to AOSP branch
Bug: 21625152 Change-Id: I07e2830b27440556dc757e6340b4f77d1c0cbc66
Diffstat (limited to 'src/com/android/tv/util/TvSettings.java')
-rw-r--r--src/com/android/tv/util/TvSettings.java235
1 files changed, 228 insertions, 7 deletions
diff --git a/src/com/android/tv/util/TvSettings.java b/src/com/android/tv/util/TvSettings.java
index 4ba9da1e..788a7d60 100644
--- a/src/com/android/tv/util/TvSettings.java
+++ b/src/com/android/tv/util/TvSettings.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2014 The Android Open Source Project
+ * Copyright (C) 2015 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.
@@ -16,22 +16,243 @@
package com.android.tv.util;
+import android.content.Context;
+import android.preference.PreferenceManager;
+import android.support.annotation.IntDef;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
/**
* A class about the constants for TV settings.
+ * Objects that are returned from the various {@code get} methods must be treated as immutable.
*/
public final class TvSettings {
private TvSettings() {}
public static final String PREFS_FILE = "settings";
public static final String PREF_TV_WATCH_LOGGING_ENABLED = "tv_watch_logging_enabled";
- 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 String PREF_PIP_LAYOUT = "pip_layout"; // int value
+ public static final String PREF_PIP_SIZE = "pip_size"; // int value
+ public static final String PREF_PIN = "pin"; // 4-digit string value. Otherwise, it's not set.
+
+ // PIP sounds
+ @Retention(RetentionPolicy.SOURCE)
+ @IntDef({
+ PIP_SOUND_MAIN, PIP_SOUND_PIP_WINDOW })
+ public @interface PipSound {}
+ public static final int PIP_SOUND_MAIN = 0;
+ public static final int PIP_SOUND_PIP_WINDOW = PIP_SOUND_MAIN + 1;
+ public static final int PIP_SOUND_LAST = PIP_SOUND_PIP_WINDOW;
+
+ // PIP layouts
+ @Retention(RetentionPolicy.SOURCE)
+ @IntDef({
+ PIP_LAYOUT_BOTTOM_RIGHT, PIP_LAYOUT_TOP_RIGHT, PIP_LAYOUT_TOP_LEFT,
+ PIP_LAYOUT_BOTTOM_LEFT, PIP_LAYOUT_SIDE_BY_SIDE })
+ public @interface PipLayout {}
+ public static final int PIP_LAYOUT_BOTTOM_RIGHT = 0;
+ public static final int PIP_LAYOUT_TOP_RIGHT = PIP_LAYOUT_BOTTOM_RIGHT + 1;
+ public static final int PIP_LAYOUT_TOP_LEFT = PIP_LAYOUT_TOP_RIGHT + 1;
+ public static final int PIP_LAYOUT_BOTTOM_LEFT = PIP_LAYOUT_TOP_LEFT + 1;
+ public static final int PIP_LAYOUT_SIDE_BY_SIDE = PIP_LAYOUT_BOTTOM_LEFT + 1;
+ public static final int PIP_LAYOUT_LAST = PIP_LAYOUT_SIDE_BY_SIDE;
+
+ // PIP sizes
+ @Retention(RetentionPolicy.SOURCE)
+ @IntDef({ PIP_SIZE_SMALL, PIP_SIZE_BIG })
+ public @interface PipSize {}
+ public static final int PIP_SIZE_SMALL = 0;
+ public static final int PIP_SIZE_BIG = PIP_SIZE_SMALL + 1;
+ public static final int PIP_SIZE_LAST = PIP_SIZE_BIG;
+
+ // Multi-track audio settings
+ private static final String PREF_MULTI_AUDIO_ID = "pref.multi_audio_id";
+ private static final String PREF_MULTI_AUDIO_LANGUAGE = "pref.multi_audio_language";
+ private static final String PREF_MULTI_AUDIO_CHANNEL_COUNT = "pref.multi_audio_channel_count";
+
+ // Parental Control settings
+ private static final String PREF_CONTENT_RATING_SYSTEMS = "pref.content_rating_systems";
+ private static final String PREF_CONTENT_RATING_LEVEL = "pref.content_rating_level";
+ private static final String PREF_DISABLE_PIN_UNTIL = "pref.disable_pin_until";
+
+ @Retention(RetentionPolicy.SOURCE)
+ @IntDef({
+ CONTENT_RATING_LEVEL_NONE, CONTENT_RATING_LEVEL_HIGH, CONTENT_RATING_LEVEL_MEDIUM,
+ CONTENT_RATING_LEVEL_LOW, CONTENT_RATING_LEVEL_CUSTOM })
+ public @interface ContentRatingLevel {}
+ public static final int CONTENT_RATING_LEVEL_NONE = 0;
+ public static final int CONTENT_RATING_LEVEL_HIGH = 1;
+ public static final int CONTENT_RATING_LEVEL_MEDIUM = 2;
+ public static final int CONTENT_RATING_LEVEL_LOW = 3;
+ public static final int CONTENT_RATING_LEVEL_CUSTOM = 4;
+
+ // PIP settings
+ /**
+ * Returns the layout of the PIP window stored in the shared preferences.
+ *
+ * @return the saved layout of the PIP window. This value is one of
+ * {@link #PIP_LAYOUT_TOP_LEFT}, {@link #PIP_LAYOUT_TOP_RIGHT},
+ * {@link #PIP_LAYOUT_BOTTOM_LEFT}, {@link #PIP_LAYOUT_BOTTOM_RIGHT} and
+ * {@link #PIP_LAYOUT_SIDE_BY_SIDE}. If the preference value does not exist,
+ * {@link #PIP_LAYOUT_BOTTOM_RIGHT} is returned.
+ */
+ @PipLayout
+ public static int getPipLayout(Context context) {
+ return PreferenceManager.getDefaultSharedPreferences(context).getInt(
+ PREF_PIP_LAYOUT, PIP_LAYOUT_BOTTOM_RIGHT);
+ }
+
+ /**
+ * Stores the layout of PIP window to the shared preferences.
+ *
+ * @param pipLayout This value should be one of {@link #PIP_LAYOUT_TOP_LEFT},
+ * {@link #PIP_LAYOUT_TOP_RIGHT}, {@link #PIP_LAYOUT_BOTTOM_LEFT},
+ * {@link #PIP_LAYOUT_BOTTOM_RIGHT} and {@link #PIP_LAYOUT_SIDE_BY_SIDE}.
+ */
+ public static void setPipLayout(Context context, @PipLayout int pipLayout) {
+ PreferenceManager.getDefaultSharedPreferences(context).edit().putInt(
+ PREF_PIP_LAYOUT, pipLayout).apply();
+ }
+
+ /**
+ * Returns the size of the PIP view stored in the shared preferences.
+ *
+ * @return the saved size of the PIP view. This value is one of
+ * {@link #PIP_SIZE_SMALL} and {@link #PIP_SIZE_BIG}. If the preference value does not
+ * exist, {@link #PIP_SIZE_SMALL} is returned.
+ */
+ @PipSize
+ public static int getPipSize(Context context) {
+ return PreferenceManager.getDefaultSharedPreferences(context).getInt(
+ PREF_PIP_SIZE, PIP_SIZE_SMALL);
+ }
+
+ /**
+ * Stores the size of PIP view to the shared preferences.
+ *
+ * @param pipSize This value should be one of {@link #PIP_SIZE_SMALL} and {@link #PIP_SIZE_BIG}.
+ */
+ public static void setPipSize(Context context, @PipSize int pipSize) {
+ PreferenceManager.getDefaultSharedPreferences(context).edit().putInt(
+ PREF_PIP_SIZE, pipSize).apply();
+ }
+
+ // Multi-track audio settings
+ public static String getMultiAudioId(Context context) {
+ return PreferenceManager.getDefaultSharedPreferences(context).getString(
+ PREF_MULTI_AUDIO_ID, null);
+ }
+
+ public static void setMultiAudioId(Context context, String language) {
+ PreferenceManager.getDefaultSharedPreferences(context).edit().putString(
+ PREF_MULTI_AUDIO_ID, language).apply();
+ }
+
+ public static String getMultiAudioLanguage(Context context) {
+ return PreferenceManager.getDefaultSharedPreferences(context).getString(
+ PREF_MULTI_AUDIO_LANGUAGE, null);
+ }
+
+ public static void setMultiAudioLanguage(Context context, String language) {
+ PreferenceManager.getDefaultSharedPreferences(context).edit().putString(
+ PREF_MULTI_AUDIO_LANGUAGE, language).apply();
+ }
+
+ public static int getMultiAudioChannelCount(Context context) {
+ return PreferenceManager.getDefaultSharedPreferences(context).getInt(
+ PREF_MULTI_AUDIO_CHANNEL_COUNT, 0);
+ }
+
+ public static void setMultiAudioChannelCount(Context context, int channelCount) {
+ PreferenceManager.getDefaultSharedPreferences(context).edit().putInt(
+ PREF_MULTI_AUDIO_CHANNEL_COUNT, channelCount).apply();
+ }
+
+ // Parental Control settings
+ public static void addContentRatingSystems(Context context, Set<String> ids) {
+ Set<String> contentRatingSystemSet = getContentRatingSystemSet(context);
+ if (contentRatingSystemSet.addAll(ids)) {
+ PreferenceManager.getDefaultSharedPreferences(context).edit()
+ .putStringSet(PREF_CONTENT_RATING_SYSTEMS, contentRatingSystemSet).apply();
+ }
+ }
+
+ public static void addContentRatingSystem(Context context, String id) {
+ Set<String> contentRatingSystemSet = getContentRatingSystemSet(context);
+ if (contentRatingSystemSet.add(id)) {
+ PreferenceManager.getDefaultSharedPreferences(context).edit()
+ .putStringSet(PREF_CONTENT_RATING_SYSTEMS, contentRatingSystemSet).apply();
+ }
+ }
+
+ public static void removeContentRatingSystems(Context context, Set<String> ids) {
+ Set<String> contentRatingSystemSet = getContentRatingSystemSet(context);
+ if (contentRatingSystemSet.removeAll(ids)) {
+ PreferenceManager.getDefaultSharedPreferences(context).edit()
+ .putStringSet(PREF_CONTENT_RATING_SYSTEMS, contentRatingSystemSet).apply();
+ }
+ }
+
+ public static void removeContentRatingSystem(Context context, String id) {
+ Set<String> contentRatingSystemSet = getContentRatingSystemSet(context);
+ if (contentRatingSystemSet.remove(id)) {
+ PreferenceManager.getDefaultSharedPreferences(context).edit()
+ .putStringSet(PREF_CONTENT_RATING_SYSTEMS, contentRatingSystemSet).apply();
+ }
+ }
+
+ public static boolean hasContentRatingSystem(Context context, String id) {
+ return getContentRatingSystemSet(context).contains(id);
+ }
+
+ /**
+ * Returns whether the content rating system is ever set. Returns {@code false} only when the
+ * user changes parental control settings for the first time.
+ */
+ public static boolean isContentRatingSystemSet(Context context) {
+ return PreferenceManager.getDefaultSharedPreferences(context)
+ .getStringSet(PREF_CONTENT_RATING_SYSTEMS, null) != null;
+ }
+
+ private static Set<String> getContentRatingSystemSet(Context context) {
+ return new HashSet<>(PreferenceManager.getDefaultSharedPreferences(context)
+ .getStringSet(PREF_CONTENT_RATING_SYSTEMS, Collections.<String>emptySet()));
+ }
+
+ @ContentRatingLevel
+ public static int getContentRatingLevel(Context context) {
+ return PreferenceManager.getDefaultSharedPreferences(context).getInt(
+ PREF_CONTENT_RATING_LEVEL, CONTENT_RATING_LEVEL_NONE);
+ }
+
+ public static void setContentRatingLevel(Context context,
+ @ContentRatingLevel int level) {
+ PreferenceManager.getDefaultSharedPreferences(context).edit().putInt(
+ PREF_CONTENT_RATING_LEVEL, level).apply();
+ }
+
+ /**
+ * Returns the time until we should disable the PIN dialog (because the user input wrong PINs
+ * repeatedly).
+ */
+ public static long getDisablePinUntil(Context context) {
+ return PreferenceManager.getDefaultSharedPreferences(context).getLong(
+ PREF_DISABLE_PIN_UNTIL, 0);
+ }
- 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;
+ /**
+ * Saves the time until we should disable the PIN dialog (because the user input wrong PINs
+ * repeatedly).
+ */
+ public static void setDisablePinUntil(Context context, long timeMillis) {
+ PreferenceManager.getDefaultSharedPreferences(context).edit().putLong(
+ PREF_DISABLE_PIN_UNTIL, timeMillis).apply();
+ }
}