aboutsummaryrefslogtreecommitdiff
path: root/src/com/android/tv/util/TvSettings.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/tv/util/TvSettings.java')
-rw-r--r--src/com/android/tv/util/TvSettings.java126
1 files changed, 77 insertions, 49 deletions
diff --git a/src/com/android/tv/util/TvSettings.java b/src/com/android/tv/util/TvSettings.java
index c5fde317..ae79e7e5 100644
--- a/src/com/android/tv/util/TvSettings.java
+++ b/src/com/android/tv/util/TvSettings.java
@@ -21,7 +21,6 @@ import android.content.SharedPreferences;
import android.media.tv.TvTrackInfo;
import android.preference.PreferenceManager;
import android.support.annotation.IntDef;
-
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Collections;
@@ -29,11 +28,11 @@ 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.
+ * 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 {
- public static final String PREF_DISPLAY_MODE = "display_mode"; // int value
+ public static final String PREF_DISPLAY_MODE = "display_mode"; // int value
public static final String PREF_PIN = "pin"; // 4-digit string value. Otherwise, it's not set.
// Multi-track audio settings
@@ -56,9 +55,14 @@ public final class TvSettings {
@Retention(RetentionPolicy.SOURCE)
@IntDef({
- CONTENT_RATING_LEVEL_NONE, CONTENT_RATING_LEVEL_HIGH, CONTENT_RATING_LEVEL_MEDIUM,
- CONTENT_RATING_LEVEL_LOW, CONTENT_RATING_LEVEL_CUSTOM })
+ 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;
@@ -69,61 +73,74 @@ public final class TvSettings {
// Multi-track audio settings
public static String getMultiAudioId(Context context) {
- return PreferenceManager.getDefaultSharedPreferences(context).getString(
- PREF_MULTI_AUDIO_ID, null);
+ 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();
+ 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);
+ 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();
+ 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);
+ 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();
+ PreferenceManager.getDefaultSharedPreferences(context)
+ .edit()
+ .putInt(PREF_MULTI_AUDIO_CHANNEL_COUNT, channelCount)
+ .apply();
}
- public static void setDvrPlaybackTrackSettings(Context context, int trackType,
- TvTrackInfo info) {
+ public static void setDvrPlaybackTrackSettings(
+ Context context, int trackType, TvTrackInfo info) {
if (trackType == TvTrackInfo.TYPE_AUDIO) {
if (info == null) {
- PreferenceManager.getDefaultSharedPreferences(context).edit()
- .remove(PREF_DVR_MULTI_AUDIO_ID).apply();
+ PreferenceManager.getDefaultSharedPreferences(context)
+ .edit()
+ .remove(PREF_DVR_MULTI_AUDIO_ID)
+ .apply();
} else {
- PreferenceManager.getDefaultSharedPreferences(context).edit()
+ PreferenceManager.getDefaultSharedPreferences(context)
+ .edit()
.putString(PREF_DVR_MULTI_AUDIO_LANGUAGE, info.getLanguage())
.putInt(PREF_DVR_MULTI_AUDIO_CHANNEL_COUNT, info.getAudioChannelCount())
- .putString(PREF_DVR_MULTI_AUDIO_ID, info.getId()).apply();
+ .putString(PREF_DVR_MULTI_AUDIO_ID, info.getId())
+ .apply();
}
} else if (trackType == TvTrackInfo.TYPE_SUBTITLE) {
if (info == null) {
- PreferenceManager.getDefaultSharedPreferences(context).edit()
- .remove(PREF_DVR_SUBTITLE_ID).apply();
+ PreferenceManager.getDefaultSharedPreferences(context)
+ .edit()
+ .remove(PREF_DVR_SUBTITLE_ID)
+ .apply();
} else {
- PreferenceManager.getDefaultSharedPreferences(context).edit()
+ PreferenceManager.getDefaultSharedPreferences(context)
+ .edit()
.putString(PREF_DVR_SUBTITLE_LANGUAGE, info.getLanguage())
- .putString(PREF_DVR_SUBTITLE_ID, info.getId()).apply();
+ .putString(PREF_DVR_SUBTITLE_ID, info.getId())
+ .apply();
}
}
}
- public static TvTrackInfo getDvrPlaybackTrackSettings(Context context,
- int trackType) {
+ public static TvTrackInfo getDvrPlaybackTrackSettings(Context context, int trackType) {
String language;
String trackId;
int channelCount;
@@ -136,7 +153,9 @@ public final class TvSettings {
language = pref.getString(PREF_DVR_MULTI_AUDIO_LANGUAGE, null);
channelCount = pref.getInt(PREF_DVR_MULTI_AUDIO_CHANNEL_COUNT, 0);
return new TvTrackInfo.Builder(trackType, trackId)
- .setLanguage(language).setAudioChannelCount(channelCount).build();
+ .setLanguage(language)
+ .setAudioChannelCount(channelCount)
+ .build();
} else if (trackType == TvTrackInfo.TYPE_SUBTITLE) {
trackId = pref.getString(PREF_DVR_SUBTITLE_ID, null);
if (trackId == null) {
@@ -153,16 +172,20 @@ public final class TvSettings {
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();
+ 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();
+ PreferenceManager.getDefaultSharedPreferences(context)
+ .edit()
+ .putStringSet(PREF_CONTENT_RATING_SYSTEMS, contentRatingSystemSet)
+ .apply();
}
}
@@ -176,25 +199,28 @@ public final class TvSettings {
*/
public static boolean isContentRatingSystemSet(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context)
- .getStringSet(PREF_CONTENT_RATING_SYSTEMS, null) != null;
+ .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.emptySet()));
+ return new HashSet<>(
+ PreferenceManager.getDefaultSharedPreferences(context)
+ .getStringSet(PREF_CONTENT_RATING_SYSTEMS, Collections.emptySet()));
}
@ContentRatingLevel
@SuppressWarnings("ResourceType")
public static int getContentRatingLevel(Context context) {
- return PreferenceManager.getDefaultSharedPreferences(context).getInt(
- PREF_CONTENT_RATING_LEVEL, CONTENT_RATING_LEVEL_NONE);
+ 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();
+ public static void setContentRatingLevel(Context context, @ContentRatingLevel int level) {
+ PreferenceManager.getDefaultSharedPreferences(context)
+ .edit()
+ .putInt(PREF_CONTENT_RATING_LEVEL, level)
+ .apply();
}
/**
@@ -202,8 +228,8 @@ public final class TvSettings {
* repeatedly).
*/
public static long getDisablePinUntil(Context context) {
- return PreferenceManager.getDefaultSharedPreferences(context).getLong(
- PREF_DISABLE_PIN_UNTIL, 0);
+ return PreferenceManager.getDefaultSharedPreferences(context)
+ .getLong(PREF_DISABLE_PIN_UNTIL, 0);
}
/**
@@ -211,7 +237,9 @@ public final class TvSettings {
* repeatedly).
*/
public static void setDisablePinUntil(Context context, long timeMillis) {
- PreferenceManager.getDefaultSharedPreferences(context).edit().putLong(
- PREF_DISABLE_PIN_UNTIL, timeMillis).apply();
+ PreferenceManager.getDefaultSharedPreferences(context)
+ .edit()
+ .putLong(PREF_DISABLE_PIN_UNTIL, timeMillis)
+ .apply();
}
-} \ No newline at end of file
+}