sdk: Styles API finalization for API9
Changes: - Added getter for global style and current accent - Added getter for a list of (available) trusted overlays - Apps that want to change the global style now MUST specify their package name when calling setGlobalStyle(). LineageParts will expose the name of the app that's currently managing the global style - Improved documentation Change-Id: Iaa1b106f43684b4120aa0f39023ebfddcb379806 Signed-off-by: Joey <joey@lineageos.org>
This commit is contained in:
@@ -1331,6 +1331,15 @@ public final class LineageSettings {
|
||||
public static final Validator BERRY_CURRENT_ACCENT_VALIDATOR =
|
||||
sNonNullStringValidator;
|
||||
|
||||
/**
|
||||
* Current application managing the style
|
||||
*/
|
||||
public static final String BERRY_MANAGED_BY_APP = "berry_managed_by_app";
|
||||
|
||||
/** @hide */
|
||||
public static final Validator BERRY_MANAGED_BY_APP_VALIDATOR =
|
||||
sNonNullStringValidator;
|
||||
|
||||
/**
|
||||
* Enable looking up of phone numbers of nearby places
|
||||
* 0 = 0ff, 1 = on
|
||||
@@ -2192,6 +2201,7 @@ public final class LineageSettings {
|
||||
VALIDATORS.put(PROXIMITY_ON_WAKE, PROXIMITY_ON_WAKE_VALIDATOR);
|
||||
VALIDATORS.put(BERRY_GLOBAL_STYLE, BERRY_GLOBAL_STYLE_VALIDATOR);
|
||||
VALIDATORS.put(BERRY_CURRENT_ACCENT, BERRY_CURRENT_ACCENT_VALIDATOR);
|
||||
VALIDATORS.put(BERRY_MANAGED_BY_APP, BERRY_MANAGED_BY_APP_VALIDATOR);
|
||||
VALIDATORS.put(ENABLE_FORWARD_LOOKUP, ENABLE_FORWARD_LOOKUP_VALIDATOR);
|
||||
VALIDATORS.put(ENABLE_PEOPLE_LOOKUP, ENABLE_PEOPLE_LOOKUP_VALIDATOR);
|
||||
VALIDATORS.put(ENABLE_REVERSE_LOOKUP, ENABLE_REVERSE_LOOKUP_VALIDATOR);
|
||||
|
||||
@@ -20,9 +20,14 @@ package lineageos.style;
|
||||
import android.graphics.Bitmap;
|
||||
import lineageos.style.Suggestion;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/** {@hide} */
|
||||
interface IStyleInterface {
|
||||
boolean setGlobalStyle(int style);
|
||||
boolean setGlobalStyle(int style, String pkgName);
|
||||
int getGlobalStyle();
|
||||
boolean setAccent(String pkgName);
|
||||
String getAccent();
|
||||
Suggestion getSuggestion(in Bitmap source, in int[] colors);
|
||||
List<String> getTrustedAccents();
|
||||
}
|
||||
@@ -25,6 +25,14 @@ import android.util.Log;
|
||||
|
||||
import lineageos.app.LineageContextConstants;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Interface used to customize the System colors. It's capable of setting a global
|
||||
* light and dark mode and custom color accents.
|
||||
*/
|
||||
|
||||
public class StyleInterface {
|
||||
|
||||
/**
|
||||
@@ -56,8 +64,8 @@ public class StyleInterface {
|
||||
public static final int STYLE_GLOBAL_DARK = 3;
|
||||
|
||||
/**
|
||||
* Default accent
|
||||
* Used to remove any active accent and use default one
|
||||
* Default accent name.
|
||||
* It can also be used to remove any active accent
|
||||
*
|
||||
* @see #setAccent
|
||||
*/
|
||||
@@ -95,8 +103,9 @@ public class StyleInterface {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get or create an instance of the {@link lineageos.app.StyleInterface}
|
||||
* @param context
|
||||
* Get or create an instance of the {@link lineageos.style.StyleInterface}
|
||||
*
|
||||
* @param context Used to get the service
|
||||
* @return {@link StyleInterface}
|
||||
*/
|
||||
public static StyleInterface getInstance(Context context) {
|
||||
@@ -138,19 +147,42 @@ public class StyleInterface {
|
||||
* {@link #STYLE_GLOBAL_AUTO_DAYTIME},
|
||||
* {@link #STYLE_GLOBAL_LIGHT} or
|
||||
* {@link #STYLE_GLOBAL_DARK}
|
||||
* @param pkgName The package name of the calling application
|
||||
*
|
||||
* @return Whether the process failed
|
||||
*/
|
||||
public boolean setGlobalStyle(int style) {
|
||||
public boolean setGlobalStyle(int style, String pkgName) {
|
||||
if (sService == null) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
return sService.setGlobalStyle(style);
|
||||
return sService.setGlobalStyle(style, pkgName);
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, e.getLocalizedMessage(), e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current global style.
|
||||
*
|
||||
* @return One of {@link #STYLE_GLOBAL_AUTO_WALLPAPER},
|
||||
* {@link #STYLE_GLOBAL_AUTO_DAYTIME},
|
||||
* {@link #STYLE_GLOBAL_LIGHT} or
|
||||
* {@link #STYLE_GLOBAL_DARK}
|
||||
*/
|
||||
public int getGlobalStyle() {
|
||||
if (sService == null) {
|
||||
return STYLE_GLOBAL_AUTO_WALLPAPER;
|
||||
}
|
||||
try {
|
||||
return sService.getGlobalStyle();
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, e.getLocalizedMessage(), e);
|
||||
}
|
||||
return STYLE_GLOBAL_AUTO_WALLPAPER;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set color accent package.
|
||||
*
|
||||
@@ -158,6 +190,8 @@ public class StyleInterface {
|
||||
* to utilize this functionality.
|
||||
*
|
||||
* @param pkgName The package name of the accent
|
||||
*
|
||||
* @return Whether the process failed
|
||||
*/
|
||||
public boolean setAccent(String pkgName) {
|
||||
if (sService == null) {
|
||||
@@ -171,13 +205,51 @@ public class StyleInterface {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current accent package.
|
||||
*
|
||||
* @return The current accent package name. Defaults to {#ACCENT_DEFAULT}
|
||||
*/
|
||||
public String getAccent() {
|
||||
if (sService == null) {
|
||||
return ACCENT_DEFAULT;
|
||||
}
|
||||
try {
|
||||
return sService.getAccent();
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, e.getLocalizedMessage(), e);
|
||||
}
|
||||
return ACCENT_DEFAULT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of trusted accents that are included in the build.
|
||||
*
|
||||
* The first element (if any) is the default accent.
|
||||
*
|
||||
* @see #setAccent
|
||||
*
|
||||
* @return A list of accents package names that can be used with {#setAccent}.
|
||||
*/
|
||||
public List<String> getTrustedAccents() {
|
||||
if (sService == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
try {
|
||||
return sService.getTrustedAccents();
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, e.getLocalizedMessage(), e);
|
||||
}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the best color that suites a bitmap object and the appropriate global style
|
||||
*
|
||||
* @param source The object you want the suggested color to be matched with
|
||||
* @param colors A list of colors that the selection will be made from
|
||||
*
|
||||
* @return suggestion for global style + accent combination
|
||||
* @return A {@link lineageos.style.Suggestion} which holds the best style + accent combination
|
||||
*/
|
||||
public Suggestion getSuggestion(Bitmap source, int[] colors) {
|
||||
if (colors.length == 0) {
|
||||
@@ -196,4 +268,4 @@ public class StyleInterface {
|
||||
}
|
||||
return fallback;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,10 @@ import lineageos.os.Build;
|
||||
import lineageos.os.Concierge;
|
||||
import lineageos.os.Concierge.ParcelInfo;
|
||||
|
||||
/**
|
||||
* Style suggestion holder class.
|
||||
* This is returned when calling {@link #lineageos.style.StyleInterface#getSuggestion}
|
||||
*/
|
||||
public class Suggestion implements Parcelable {
|
||||
public final int globalStyle;
|
||||
public final int selectedAccent;
|
||||
@@ -31,10 +35,11 @@ public class Suggestion implements Parcelable {
|
||||
/**
|
||||
* Default constructor
|
||||
*
|
||||
* @see lineageos.style.StyleInterface#getSuggestion
|
||||
* @see {@link lineageos.style.StyleInterface#getSuggestion}
|
||||
*
|
||||
* @param globalStyle one of {@link #STYLE_GLOBAL_LIGHT} or {@link #STYLE_GLOBAL_DARK}
|
||||
* @param colorPosition position of selected color in the input array
|
||||
* @param globalStyle One of {@link #lineageos.style.StyleInterface#STYLE_GLOBAL_LIGHT} or
|
||||
* {@link #lineageos.style.StyleInterface#STYLE_GLOBAL_DARK}
|
||||
* @param selectedAccent The position of the selected color in the input array
|
||||
*/
|
||||
public Suggestion(int globalStyle, int selectedAccent) {
|
||||
this.globalStyle = globalStyle;
|
||||
|
||||
Reference in New Issue
Block a user