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

Commit c21888d6 authored by Holly Jiuyu Sun's avatar Holly Jiuyu Sun Committed by Android (Google) Code Review
Browse files

Merge "[tile] Consolidate some functions to be reuse by LauncherTileService." into tm-qpr-dev

parents 7b7c22a4 dcb24bd0
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -16,9 +16,11 @@ package com.android.systemui.plugins.qs;

import android.annotation.NonNull;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.metrics.LogMaker;
import android.service.quicksettings.Tile;
import android.text.TextUtils;
import android.view.View;

import androidx.annotation.Nullable;
@@ -175,6 +177,24 @@ public interface QSTile {
        public Drawable sideViewCustomDrawable;
        public String spec;

        /** Get the state text. */
        public String getStateText(int arrayResId, Resources resources) {
            if (state == Tile.STATE_UNAVAILABLE || this instanceof QSTile.BooleanState) {
                String[] array = resources.getStringArray(arrayResId);
                return array[state];
            } else {
                return "";
            }
        }

        /** Get the text for secondaryLabel. */
        public String getSecondaryLabel(String stateText) {
            if (TextUtils.isEmpty(secondaryLabel)) {
                return stateText;
            }
            return secondaryLabel.toString();
        }

        public boolean copyTo(State other) {
            if (other == null) throw new IllegalArgumentException();
            if (!other.getClass().equals(getClass())) throw new IllegalArgumentException();
+4 −0
Original line number Diff line number Diff line
@@ -712,6 +712,10 @@ public abstract class QSTileImpl<TState extends State> implements QSTile, Lifecy
            return context.getDrawable(mResId);
        }

        public int getResId() {
            return mResId;
        }

        @Override
        public boolean equals(Object o) {
            return o instanceof ResourceIcon && ((ResourceIcon) o).mResId == mResId;
+3 −54
Original line number Diff line number Diff line
@@ -440,12 +440,11 @@ open class QSTileViewImpl @JvmOverloads constructor(

        // State handling and description
        val stateDescription = StringBuilder()
        val stateText = getStateText(state)
        val arrayResId = SubtitleArrayMapping.getSubtitleId(state.spec)
        val stateText = state.getStateText(arrayResId, resources)
        state.secondaryLabel = state.getSecondaryLabel(stateText)
        if (!TextUtils.isEmpty(stateText)) {
            stateDescription.append(stateText)
            if (TextUtils.isEmpty(state.secondaryLabel)) {
                state.secondaryLabel = stateText
            }
        }
        if (state.disabledByPolicy && state.state != Tile.STATE_UNAVAILABLE) {
            stateDescription.append(", ")
@@ -591,16 +590,6 @@ open class QSTileViewImpl @JvmOverloads constructor(
        return resources.getStringArray(arrayResId)[Tile.STATE_UNAVAILABLE]
    }

    private fun getStateText(state: QSTile.State): String {
        return if (state.state == Tile.STATE_UNAVAILABLE || state is BooleanState) {
            val arrayResId = SubtitleArrayMapping.getSubtitleId(state.spec)
            val array = resources.getStringArray(arrayResId)
            array[state.state]
        } else {
            ""
        }
    }

    /*
     * The view should not be animated if it's not on screen and no part of it is visible.
     */
@@ -663,46 +652,6 @@ open class QSTileViewImpl @JvmOverloads constructor(
    )
}

@VisibleForTesting
internal object SubtitleArrayMapping {
    private val subtitleIdsMap = mapOf<String?, Int>(
        "internet" to R.array.tile_states_internet,
        "wifi" to R.array.tile_states_wifi,
        "cell" to R.array.tile_states_cell,
        "battery" to R.array.tile_states_battery,
        "dnd" to R.array.tile_states_dnd,
        "flashlight" to R.array.tile_states_flashlight,
        "rotation" to R.array.tile_states_rotation,
        "bt" to R.array.tile_states_bt,
        "airplane" to R.array.tile_states_airplane,
        "location" to R.array.tile_states_location,
        "hotspot" to R.array.tile_states_hotspot,
        "inversion" to R.array.tile_states_inversion,
        "saver" to R.array.tile_states_saver,
        "dark" to R.array.tile_states_dark,
        "work" to R.array.tile_states_work,
        "cast" to R.array.tile_states_cast,
        "night" to R.array.tile_states_night,
        "screenrecord" to R.array.tile_states_screenrecord,
        "reverse" to R.array.tile_states_reverse,
        "reduce_brightness" to R.array.tile_states_reduce_brightness,
        "cameratoggle" to R.array.tile_states_cameratoggle,
        "mictoggle" to R.array.tile_states_mictoggle,
        "controls" to R.array.tile_states_controls,
        "wallet" to R.array.tile_states_wallet,
        "qr_code_scanner" to R.array.tile_states_qr_code_scanner,
        "alarm" to R.array.tile_states_alarm,
        "onehanded" to R.array.tile_states_onehanded,
        "color_correction" to R.array.tile_states_color_correction,
        "dream" to R.array.tile_states_dream,
        "font_scaling" to R.array.tile_states_font_scaling
    )

    fun getSubtitleId(spec: String?): Int {
        return subtitleIdsMap.getOrDefault(spec, R.array.tile_states_default)
    }
}

fun constrainSquishiness(squish: Float): Float {
    return 0.1f + squish * 0.9f
}
+62 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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.qs.tileimpl

import com.android.systemui.R

/** Return the subtitle resource Id of the given tile. */
object SubtitleArrayMapping {
    private val subtitleIdsMap: HashMap<String, Int> = HashMap()
    init {
        subtitleIdsMap["internet"] = R.array.tile_states_internet
        subtitleIdsMap["wifi"] = R.array.tile_states_wifi
        subtitleIdsMap["cell"] = R.array.tile_states_cell
        subtitleIdsMap["battery"] = R.array.tile_states_battery
        subtitleIdsMap["dnd"] = R.array.tile_states_dnd
        subtitleIdsMap["flashlight"] = R.array.tile_states_flashlight
        subtitleIdsMap["rotation"] = R.array.tile_states_rotation
        subtitleIdsMap["bt"] = R.array.tile_states_bt
        subtitleIdsMap["airplane"] = R.array.tile_states_airplane
        subtitleIdsMap["location"] = R.array.tile_states_location
        subtitleIdsMap["hotspot"] = R.array.tile_states_hotspot
        subtitleIdsMap["inversion"] = R.array.tile_states_inversion
        subtitleIdsMap["saver"] = R.array.tile_states_saver
        subtitleIdsMap["dark"] = R.array.tile_states_dark
        subtitleIdsMap["work"] = R.array.tile_states_work
        subtitleIdsMap["cast"] = R.array.tile_states_cast
        subtitleIdsMap["night"] = R.array.tile_states_night
        subtitleIdsMap["screenrecord"] = R.array.tile_states_screenrecord
        subtitleIdsMap["reverse"] = R.array.tile_states_reverse
        subtitleIdsMap["reduce_brightness"] = R.array.tile_states_reduce_brightness
        subtitleIdsMap["cameratoggle"] = R.array.tile_states_cameratoggle
        subtitleIdsMap["mictoggle"] = R.array.tile_states_mictoggle
        subtitleIdsMap["controls"] = R.array.tile_states_controls
        subtitleIdsMap["wallet"] = R.array.tile_states_wallet
        subtitleIdsMap["qr_code_scanner"] = R.array.tile_states_qr_code_scanner
        subtitleIdsMap["alarm"] = R.array.tile_states_alarm
        subtitleIdsMap["onehanded"] = R.array.tile_states_onehanded
        subtitleIdsMap["color_correction"] = R.array.tile_states_color_correction
        subtitleIdsMap["dream"] = R.array.tile_states_dream
        subtitleIdsMap["font_scaling"] = R.array.tile_states_font_scaling
    }

    /** Get the subtitle resource id of the given tile */
    fun getSubtitleId(spec: String?): Int {
        return if (spec == null) {
            R.array.tile_states_default
        } else subtitleIdsMap[spec] ?: R.array.tile_states_default
    }
}