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

Commit 26c932ea authored by Roman Birg's avatar Roman Birg
Browse files

SystemUI: implement properly saving tile locations



Use new persisted key which does not use the tiles' ID (which changes
usually across reboots with every tile). When the Custom tile service
comes up, it will update the placeholder tiles created with their real
values and the order is preserved properly.

Ticket: CYNGNOS-2530

Change-Id: I5e75c739553969f1d92c249f521a476259fe0cd6
Signed-off-by: default avatarRoman Birg <roman@cyngn.com>
parent 8aefa311
Loading
Loading
Loading
Loading
+29 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
    Copyright (c) 2015 The CyanogenMod 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.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="48dp"
    android:height="48dp"
    android:viewportWidth="24"
    android:viewportHeight="24">

    <path
        android:fillColor="#FFFFFF"
        android:pathData="M19,5v14H5V5H19
M19,3H5C3.9,3,3,3.9,3,5v14c0,1.1,0.9,2,2,2h14c1.1,0,2-0.9,2-2V5C21,3.9,20.1,3,19,3L19,3z
M10.7,13.3h2.6L12,9.2L10.7,13.3z
M14.6,17l-0.8-2.2h-3.6L9.4,17H7.3l3.6-10h2.2l3.6,10H14.6z" />
</vector>
 No newline at end of file
+3 −0
Original line number Diff line number Diff line
@@ -61,18 +61,21 @@
        <item>@string/dynamic_qs_tile_ime_selector_label</item>
        <item>@string/dynamic_qs_tile_su_label</item>
        <item>@string/dynamic_qs_tile_adb_label</item>
        <item>@string/dynamic_qs_tile_live_display_label</item>
    </string-array>
    <string-array name="dynamic_qs_tiles_icons_resources_ids" translatable="false">
        <item>ic_dynamic_qs_next_alarm</item>
        <item>ic_dynamic_qs_ime_selector</item>
        <item>ic_dynamic_qs_su</item>
        <item>ic_dynamic_qs_adb</item>
        <item>ic_dynamic_qs_live_display</item>
    </string-array>
    <string-array name="dynamic_qs_tiles_values" translatable="false">
        <item>next_alarm</item>
        <item>ime_selector</item>
        <item>su</item>
        <item>adb</item>
        <item>live_display</item>
    </string-array>

    <array name="dockbatterymeter_bolt_points" translatable="false">
+1 −0
Original line number Diff line number Diff line
@@ -206,6 +206,7 @@
    <string name="dynamic_qs_tile_ime_selector_label">IME selector</string>
    <string name="dynamic_qs_tile_su_label">Root access</string>
    <string name="dynamic_qs_tile_adb_label" translatable="false">ADB</string>
    <string name="dynamic_qs_tile_live_display_label">Live Display</string>

    <string name="quick_settings_title_advanced_location">Tri-state location</string>

+95 −64
Original line number Diff line number Diff line
@@ -68,6 +68,7 @@ import org.cyanogenmod.internal.util.QSConstants;
import org.cyanogenmod.internal.util.QSUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
@@ -1901,7 +1902,8 @@ public class QSDragPanel extends QSPanel implements View.OnDragListener, View.On
            final Iterator<String> i = tiles.iterator();
            while (i.hasNext()) {
                final String spec = i.next();
                if (QSUtils.isStaticQsTile(spec) || QSUtils.isDynamicQsTile(spec)) {
                if (QSUtils.isStaticQsTile(spec)
                        || QSUtils.isDynamicQsTile(extractTileTagFromSpec(spec))) {
                    List<String> packageList = mPackageTileMap.get(PACKAGE_ANDROID);
                    packageList.add(spec);
                } else {
@@ -1919,13 +1921,14 @@ public class QSDragPanel extends QSPanel implements View.OnDragListener, View.On
                if (entry.getValue() instanceof Boolean) {
                    if ((Boolean)entry.getValue()) {
                        final String key = entry.getKey();
                        if (QSUtils.isDynamicQsTile(key)) {
                        if (QSUtils.isDynamicQsTile(extractTileTagFromSpec(key))) {
                            mPackageTileMap.get(PACKAGE_ANDROID).add(key);
                        } else {
                            final String customTilePackage = getCustomTilePackage(key);
                            List<String> packageList = mPackageTileMap.get(customTilePackage);
                            if (packageList == null) {
                                mPackageTileMap.put(customTilePackage, packageList = new ArrayList<>());
                                mPackageTileMap.put(customTilePackage,
                                        packageList = new ArrayList<>());
                            }
                            packageList.add(key);

@@ -1939,8 +1942,95 @@ public class QSDragPanel extends QSPanel implements View.OnDragListener, View.On
        }

        private String getCustomTilePackage(String spec) {
            if (mHost.getCustomTileData().get(spec) != null) {
                StatusBarPanelCustomTile sbc = mHost.getCustomTileData().get(spec).sbc;
                return sbc.getPackage();
            } else {
                return extractPackageFromCustomTileSpec(spec);
            }
        }

        private static String extractPackageFromCustomTileSpec(String spec) {
            if (spec != null && !spec.isEmpty()) {
                final String[] split = spec.split("\\|");
                if (split != null && split.length > 2) {
                    return split[1];
                }
            }
            return null;
        }

        private static String extractTileTagFromSpec(String spec) {
            if (spec != null && !spec.isEmpty()) {
                final String[] split = spec.split("\\|");
                if (split != null && split.length == 5) {
                    /** for {@link cyanogenmod.app.StatusBarPanelCustomTile#key() **/
                    return split[3];
                } else if (split != null && split.length == 3) {
                    /** for {@link cyanogenmod.app.StatusBarPanelCustomTile#persistableKey()} **/
                    return split[2];
                }
            }
            return null;
        }

        private Drawable getQSTileIcon(String spec) {
            if (QSUtils.isDynamicQsTile(spec)) {
                return QSTile.ResourceIcon.get(
                        QSUtils.getDynamicQSTileResIconId(mContext, UserHandle.myUserId(), spec))
                        .getDrawable(mContext);
            } else if (QSUtils.isStaticQsTile(spec)) {
                final int res = QSTileHost.getIconResource(spec);
                if (res != 0) {
                    return QSTile.ResourceIcon.get(res).getDrawable(mContext);
                } else {
                    return mContext.getPackageManager().getDefaultActivityIcon();
                }
            } else {
                QSTile<?> tile = mHost.getTile(spec);
                if (tile != null) {
                    QSTile.State state = tile.getState();
                    if (state != null && state.icon != null) {
                        return state.icon.getDrawable(mContext);
                    }
                }
                return getPackageDrawable(getCustomTilePackage(spec));
            }
        }

        private String getPackageLabel(String packageName) {
            try {
                return mContext.getPackageManager().getApplicationLabel(
                        mContext.getPackageManager().getApplicationInfo(packageName, 0)).toString();
            } catch (PackageManager.NameNotFoundException e) {
                e.printStackTrace();
            }
            return null;
        }

        private Drawable getPackageDrawable(String packageName) {
            try {
                return mContext.getPackageManager().getApplicationIcon(packageName);
            } catch (PackageManager.NameNotFoundException e) {
                e.printStackTrace();
            }
            return null;
        }

        private String getQSTileLabel(String spec) {
            if (QSUtils.isStaticQsTile(spec)) {
                int resource = QSTileHost.getLabelResource(spec);
                if (resource != 0) {
                    return mContext.getText(resource).toString();
                } else {
                    return spec;
                }
            } else if (QSUtils.isDynamicQsTile(extractTileTagFromSpec(spec))) {
                return QSUtils.getDynamicQSTileLabel(mContext,
                        UserHandle.myUserId(), extractTileTagFromSpec(spec));
            } else {
                return getPackageLabel(getCustomTilePackage(spec));
            }
        }

        @Override
@@ -2042,65 +2132,6 @@ public class QSDragPanel extends QSPanel implements View.OnDragListener, View.On
            return child;
        }

        private String getQSTileLabel(String spec) {
            if (QSUtils.isStaticQsTile(spec)) {
                int resource = QSTileHost.getLabelResource(spec);
                if (resource != 0) {
                    return mContext.getText(resource).toString();
                } else {
                    return spec;
                }
            } else if (QSUtils.isDynamicQsTile(spec)) {
                return QSUtils.getDynamicQSTileLabel(mContext,
                        UserHandle.myUserId(), spec);
            } else {
                return getPackageLabel(getCustomTilePackage(spec));
            }
        }

        private Drawable getQSTileIcon(String spec) {
            if (QSUtils.isDynamicQsTile(spec)) {
                return QSTile.ResourceIcon.get(
                        QSUtils.getDynamicQSTileResIconId(mContext, UserHandle.myUserId(), spec))
                        .getDrawable(mContext);
            } else if (QSUtils.isStaticQsTile(spec)) {
                final int res = QSTileHost.getIconResource(spec);
                if (res != 0) {
                    return QSTile.ResourceIcon.get(res).getDrawable(mContext);
                } else {
                    return mContext.getPackageManager().getDefaultActivityIcon();
                }
            } else {
                QSTile<?> tile = mHost.getTile(spec);
                if (tile != null) {
                    QSTile.State state = tile.getState();
                    if (state != null && state.icon != null) {
                        return state.icon.getDrawable(mContext);
                    }
                }
                return getPackageDrawable(getCustomTilePackage(spec));
            }
        }

        private String getPackageLabel(String packageName) {
            try {
                return mContext.getPackageManager().getApplicationLabel(
                        mContext.getPackageManager().getApplicationInfo(packageName, 0)).toString();
            } catch (PackageManager.NameNotFoundException e) {
                e.printStackTrace();
            }
            return null;
        }

        private Drawable getPackageDrawable(String packageName) {
            try {
                return mContext.getPackageManager().getApplicationIcon(packageName);
            } catch (PackageManager.NameNotFoundException e) {
                e.printStackTrace();
            }
            return null;
        }

        @Override
        public boolean isChildSelectable(int groupPosition, int childPosition) {
            return true;
+24 −6
Original line number Diff line number Diff line
@@ -32,15 +32,12 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RemoteViews;
import android.widget.TextView;

import com.android.internal.logging.MetricsLogger;

import com.android.systemui.qs.QSDetailItemsGrid;
import com.android.systemui.qs.QSDetailItemsList;
import cyanogenmod.app.CustomTile;
@@ -65,6 +62,13 @@ public class CustomQSTile extends QSTile<QSTile.State> {
    private CustomQSDetailAdapter mDetailAdapter;
    private boolean mCollapsePanel;
    private boolean mUserRemoved;
    private String mPersistedPlaceHolderKey;

    public CustomQSTile(Host host, String persistedSpec) {
        super(host);
        mTile = null;
        mPersistedPlaceHolderKey = persistedSpec;
    }

    public CustomQSTile(Host host, StatusBarPanelCustomTile tile) {
        super(host);
@@ -72,8 +76,16 @@ public class CustomQSTile extends QSTile<QSTile.State> {
        mUserRemoved = getIsUserRemovedPersisted();
    }

    private String getPersistableKey() {
        if (mPersistedPlaceHolderKey != null) {
            return mPersistedPlaceHolderKey;
        } else {
            return getTile().persistableKey();
        }
    }

    private boolean getIsUserRemovedPersisted() {
        return getCustomQSTilePrefs(mContext).getBoolean(getTile().getKey(), false);
        return getCustomQSTilePrefs(mContext).getBoolean(getPersistableKey(), false);
    }

    public boolean isUserRemoved() {
@@ -83,9 +95,9 @@ public class CustomQSTile extends QSTile<QSTile.State> {
    public void setUserRemoved(boolean removed) {
        if (mUserRemoved != removed) {
            if (removed) {
                getCustomQSTilePrefs(mContext).edit().putBoolean(getTile().getKey(), true).apply();
                getCustomQSTilePrefs(mContext).edit().putBoolean(getPersistableKey(), true).apply();
            } else {
                getCustomQSTilePrefs(mContext).edit().remove(getTile().getKey()).apply();
                getCustomQSTilePrefs(mContext).edit().remove(getPersistableKey()).apply();
            }
            mUserRemoved = removed;
            refreshState();
@@ -167,8 +179,14 @@ public class CustomQSTile extends QSTile<QSTile.State> {
    protected void handleUpdateState(State state, Object arg) {
        if (arg instanceof StatusBarPanelCustomTile) {
            mTile = (StatusBarPanelCustomTile) arg;
            mPersistedPlaceHolderKey = null;
            mUserRemoved = getIsUserRemovedPersisted();
        }
        if (mTile == null) {
            state.visible = false;
            // nothing to show, it's a place holder for now
            return;
        }
        final CustomTile customTile = mTile.getCustomTile();
        state.contentDescription = customTile.contentDescription;
        state.label = customTile.label;
Loading