Merge "Move theme out of tuner and into display settings"
This commit is contained in:
committed by
Android (Google) Code Review
commit
fbcb01cde7
@@ -58,10 +58,15 @@ interface IUiModeManager {
|
||||
void setTheme(String theme);
|
||||
|
||||
/**
|
||||
* Gets whith theme overlays to use within /vendor/overlay.
|
||||
* Gets which theme overlays to use within /vendor/overlay.
|
||||
*/
|
||||
String getTheme();
|
||||
|
||||
/**
|
||||
* Gets the themes available in /vendor/overlay.
|
||||
*/
|
||||
String[] getAvailableThemes();
|
||||
|
||||
/**
|
||||
* Tells if UI mode is locked or not.
|
||||
*/
|
||||
|
||||
@@ -270,6 +270,21 @@ public class UiModeManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the valid inputs to {@link #setTheme(String)}.
|
||||
* @hide
|
||||
*/
|
||||
public String[] getAvailableThemes() {
|
||||
if (mService != null) {
|
||||
try {
|
||||
return mService.getAvailableThemes();
|
||||
} catch (RemoteException e) {
|
||||
throw e.rethrowFromSystemServer();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the currently configured night mode.
|
||||
* <p>
|
||||
|
||||
@@ -23,10 +23,5 @@
|
||||
android:key="power_notification_controls"
|
||||
android:title="@string/tuner_full_importance_settings"
|
||||
android:fragment="com.android.systemui.tuner.PowerNotificationControlsFragment"/>
|
||||
e
|
||||
<com.android.systemui.tuner.ThemePreference
|
||||
android:key="theme"
|
||||
android:title="@string/theme"
|
||||
android:summary="%s" />
|
||||
|
||||
</PreferenceScreen>
|
||||
|
||||
@@ -1,78 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2016 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. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the
|
||||
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the specific language governing
|
||||
* permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.systemui.tuner;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.UiModeManager;
|
||||
import android.content.Context;
|
||||
import android.os.SystemProperties;
|
||||
import android.support.v7.preference.ListPreference;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import com.android.systemui.R;
|
||||
|
||||
import libcore.util.Objects;
|
||||
|
||||
import com.google.android.collect.Lists;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class ThemePreference extends ListPreference {
|
||||
|
||||
public ThemePreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttached() {
|
||||
super.onAttached();
|
||||
String def = SystemProperties.get("ro.boot.vendor.overlay.theme");
|
||||
if (TextUtils.isEmpty(def)) {
|
||||
def = getContext().getString(R.string.default_theme);
|
||||
}
|
||||
String[] fileList = new File("/vendor/overlay").list();
|
||||
ArrayList<String> options = fileList != null
|
||||
? Lists.newArrayList(fileList) : new ArrayList<>();
|
||||
if (!options.contains(def)) {
|
||||
options.add(0, def);
|
||||
}
|
||||
String[] list = options.toArray(new String[options.size()]);
|
||||
setVisible(options.size() > 1);
|
||||
setEntries(list);
|
||||
setEntryValues(list);
|
||||
updateValue();
|
||||
}
|
||||
|
||||
private void updateValue() {
|
||||
setValue(getContext().getSystemService(UiModeManager.class).getTheme());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void notifyChanged() {
|
||||
super.notifyChanged();
|
||||
if (!Objects.equal(getValue(),
|
||||
getContext().getSystemService(UiModeManager.class).getTheme())) {
|
||||
new AlertDialog.Builder(getContext())
|
||||
.setTitle(R.string.change_theme_reboot)
|
||||
.setPositiveButton(com.android.internal.R.string.global_action_restart, (d, i)
|
||||
-> getContext().getSystemService(UiModeManager.class)
|
||||
.setTheme(getValue()))
|
||||
.setNegativeButton(android.R.string.cancel, (d, i) -> updateValue())
|
||||
.show();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3336,6 +3336,9 @@ message MetricsEvent {
|
||||
// OS: 8.0
|
||||
TTS_SLIDERS = 815;
|
||||
|
||||
// ACTION: Settings -> Display -> Theme
|
||||
ACTION_THEME = 816;
|
||||
|
||||
// ---- End O Constants, all O constants go above this line ----
|
||||
|
||||
// Add new aosp constants above this line.
|
||||
|
||||
@@ -45,12 +45,16 @@ import android.provider.Settings;
|
||||
import android.service.dreams.Sandman;
|
||||
import android.service.vr.IVrManager;
|
||||
import android.service.vr.IVrStateCallbacks;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Slog;
|
||||
import android.view.WindowManagerInternal;
|
||||
import android.view.WindowManagerPolicy;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileDescriptor;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
||||
import com.android.internal.R;
|
||||
import com.android.internal.app.DisableCarModeActivity;
|
||||
@@ -342,6 +346,28 @@ final class UiModeManagerService extends SystemService {
|
||||
return SystemProperties.get("persist.vendor.overlay.theme");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getAvailableThemes() {
|
||||
if (getContext().checkCallingOrSelfPermission(
|
||||
android.Manifest.permission.MODIFY_THEME_OVERLAY)
|
||||
!= PackageManager.PERMISSION_GRANTED) {
|
||||
Slog.e(TAG, "getAvailableThemes requires MODIFY_THEME_OVERLAY permission");
|
||||
return null;
|
||||
}
|
||||
String def = SystemProperties.get("ro.boot.vendor.overlay.theme");
|
||||
if (TextUtils.isEmpty(def)) {
|
||||
def = null;
|
||||
}
|
||||
String[] fileList = new File("/vendor/overlay").list();
|
||||
if (fileList == null) return new String[0];
|
||||
ArrayList<String> options = new ArrayList(fileList.length + 1);
|
||||
Collections.addAll(options, fileList);
|
||||
if (!options.contains(def)) {
|
||||
options.add(0, def);
|
||||
}
|
||||
return options.toArray(new String[options.size()]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNightMode() {
|
||||
synchronized (mLock) {
|
||||
|
||||
Reference in New Issue
Block a user