Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 524fb402 authored by Jason Monk's avatar Jason Monk
Browse files

Move theme out of tuner and into display settings

Change-Id: Id939a8a34e92c6190c59317155238697861a65e5
Fixes: 34682466
Test: Manual
parent 1597e054
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -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.
     */
+15 −0
Original line number Diff line number Diff line
@@ -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>
+0 −5
Original line number Diff line number Diff line
@@ -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>
+0 −78
Original line number Diff line number Diff line
/*
 * 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();
        }
    }
}
+3 −0
Original line number Diff line number Diff line
@@ -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.
Loading