diff options
author | TreeHugger Robot <treehugger-gerrit@google.com> | 2018-12-19 21:58:09 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2018-12-19 21:58:09 +0000 |
commit | 7b536fe5de1ea9f74b7fc7b0dd0a619f2e107406 (patch) | |
tree | 885a5932cfdef9a24ea97a1efff9f8d7d0b79642 /common | |
parent | 9219048ec4419d4f13def353833b9b83ebd8ba69 (diff) | |
parent | c36d72b76800064828c32b03bac02e43969a4b82 (diff) | |
download | TV-7b536fe5de1ea9f74b7fc7b0dd0a619f2e107406.tar.gz |
Merge "Use HasSingletons for application singletons"
Diffstat (limited to 'common')
-rw-r--r-- | common/src/com/android/tv/common/BaseApplication.java | 8 | ||||
-rw-r--r-- | common/src/com/android/tv/common/singletons/HasSingletons.java | 7 |
2 files changed, 14 insertions, 1 deletions
diff --git a/common/src/com/android/tv/common/BaseApplication.java b/common/src/com/android/tv/common/BaseApplication.java index 6166b46b..566bd25b 100644 --- a/common/src/com/android/tv/common/BaseApplication.java +++ b/common/src/com/android/tv/common/BaseApplication.java @@ -40,7 +40,13 @@ public abstract class BaseApplication extends Application implements BaseSinglet */ @VisibleForTesting public static BaseSingletons sSingletons; - /** Returns the {@link BaseSingletons} using the application context. */ + /** + * Returns the {@link BaseSingletons} using the application context. + * + * @deprecated use {@link com.android.tv.common.singletons.HasSingletons#get(Class, Context)} + * instead + */ + @Deprecated public static BaseSingletons getSingletons(Context context) { // STOP-SHIP: changing the method to protected once the Tuner application is created. // No need to be "synchronized" because this doesn't create any instance. diff --git a/common/src/com/android/tv/common/singletons/HasSingletons.java b/common/src/com/android/tv/common/singletons/HasSingletons.java index b72ee4fc..193aed3a 100644 --- a/common/src/com/android/tv/common/singletons/HasSingletons.java +++ b/common/src/com/android/tv/common/singletons/HasSingletons.java @@ -15,12 +15,19 @@ */ package com.android.tv.common.singletons; +import android.content.Context; + /** * A type that can know about and supply a singleton, typically a type t such as an android activity * or application. */ public interface HasSingletons<C> { + @SuppressWarnings("unchecked") // injection + static <C> C get(Class<C> clazz, Context context) { + return ((HasSingletons<C>) context).singletons(); + } + /** Returns the strongly typed singleton. */ C singletons(); } |