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

Commit 0b1cd0ec authored by Joey's avatar Joey
Browse files

Launcher3: Add support for icon packs



- Supports icon packs from nova and adw
- Live preview in settings
- Default applied icon pack via overlay

Change-Id: Ie9879fa30f4cd9d52356acf78a423b415657510c
Signed-off-by: default avatarJoey <joey@lineageos.org>
parent 67724ea4
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -178,6 +178,12 @@
            </intent-filter>
        </activity>

        <activity
            android:name="com.android.launcher3.lineage.icon.IconPackSettingsActivity"
            android:label="@string/icon_pack_title"
            android:theme="@android:style/Theme.DeviceDefault.Settings"
            android:autoRemoveFromRecents="true"  />

        <provider
            android:name="com.android.launcher3.testing.TestInformationProvider"
            android:authorities="${packageName}.TestInfo"
+20 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2020 The LineageOS 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.
-->
<resources>

    <!-- Default icon pack package. Set to "android" to use default / original icons -->
    <string name="icon_pack_default_pkg" translatable="false">android</string>
</resources>
+5 −1
Original line number Diff line number Diff line
@@ -25,6 +25,8 @@ import android.os.UserHandle;

import androidx.annotation.NonNull;

import com.android.launcher3.lineage.icon.IconPackStore;

/**
 * This class will be moved to androidx library. There shouldn't be any dependency outside
 * this package.
@@ -215,7 +217,9 @@ public class BaseIconFactory implements AutoCloseable {
        }
        float scale = 1f;

        if (shrinkNonAdaptiveIcons && ATLEAST_OREO) {
        final IconPackStore iconPackStore = new IconPackStore(mContext);
        final boolean defaultIcons = iconPackStore.isUsingSystemIcons();
        if (shrinkNonAdaptiveIcons && ATLEAST_OREO && defaultIcons) {
            if (mWrapperIcon == null) {
                mWrapperIcon = mContext.getDrawable(R.drawable.adaptive_icon_drawable_wrapper)
                        .mutate();
+70 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 Shift GmbH
 *
 * 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.launcher3.lineage.icon;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;

import com.android.launcher3.icons.R;

public final class IconPackStore {
    public static final String SYSTEM_ICON_PACK = "android";
    public static final String KEY_ICON_PACK = "pref_iconPackPackage";

    private Context context;
    private SharedPreferences prefs;

    public IconPackStore(Context context) {
        this.context = context;
        this.prefs = context.getSharedPreferences(
                "com.android.launcher3.prefs", Context.MODE_PRIVATE);
    }

    public String getCurrent() {
        return prefs.getString(KEY_ICON_PACK, getDefaultIconPack());
    }

    public void setCurrent(String pkgName) {
        prefs.edit()
            .putString(KEY_ICON_PACK, pkgName)
            .apply();
    }

    public boolean isUsingSystemIcons() {
        return SYSTEM_ICON_PACK.equals(getCurrent());
    }

    public String getCurrentLabel(String defaultLabel) {
        final String pkgName = getCurrent();
        if (SYSTEM_ICON_PACK.equals(pkgName)) {
            return defaultLabel;
        }

        final PackageManager pm = context.getPackageManager();
        try {
            final ApplicationInfo ai = pm.getApplicationInfo(pkgName, 0);
            return (String) pm.getApplicationLabel(ai);
        } catch (PackageManager.NameNotFoundException e) {
            return defaultLabel;
        }
    }

    private String getDefaultIconPack() {
        return context.getString(R.string.icon_pack_default_pkg);
    }
}
+26 −0
Original line number Diff line number Diff line
<!--
     Copyright (C) 2019 The LineageOS 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="24dp"
    android:height="24dp"
    android:viewportWidth="24"
    android:viewportHeight="24">
    <path
        android:pathData="M 19 3 L 5 3 C 3.89 3 3 3.9 3 5 L 3 19 C 3 20.1 3.89 21 5 21 L 19 21 C 20.1 21 21 20.1 21 19 L 21 5 C 21 3.9 20.1 3 19 3 Z M 19 19 L 5 19 L 5 5 L 19 5 L 19 19 Z M 11 17 L 13 17 L 13 13 L 17 13 L 17 11 L 13 11 L 13 7 L 11 7 L 11 11 L 7 11 L 7 13 L 11 13 Z"
        android:fillColor="?android:attr/textColorPrimary"
        android:strokeWidth="1"/>
</vector>
Loading