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

Commit b2498b27 authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Using support lib implementation for launcher preference

Bug: 117519297
Change-Id: Icea5e022a337436e48db9376fd441f805dc34e54
parent 785a3795
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -67,7 +67,8 @@ LOCAL_MODULE_TAGS := optional

LOCAL_STATIC_ANDROID_LIBRARIES := \
    androidx.recyclerview_recyclerview \
    androidx.dynamicanimation_dynamicanimation
    androidx.dynamicanimation_dynamicanimation \
    androidx.preference_preference

LOCAL_STATIC_JAVA_LIBRARIES := libPluginCore

+1 −1
Original line number Diff line number Diff line
@@ -156,7 +156,7 @@
        The settings activity. To extend point settings_fragment_name to appropriate fragment class
        -->
        <activity
            android:name="com.android.launcher3.SettingsActivity"
            android:name="com.android.launcher3.settings.SettingsActivity"
            android:label="@string/settings_button_text"
            android:theme="@android:style/Theme.DeviceDefault.Settings"
            android:autoRemoveFromRecents="true">
+6 −5
Original line number Diff line number Diff line
@@ -14,9 +14,10 @@
     limitations under the License.
-->

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<androidx.preference.PreferenceScreen
    xmlns:android="http://schemas.android.com/apk/res/android">

    <com.android.launcher3.views.ButtonPreference
    <com.android.launcher3.settings.IconBadgingPreference
        android:key="pref_icon_badging"
        android:title="@string/icon_badging_title"
        android:persistent="false"
@@ -27,7 +28,7 @@
                android:name=":settings:fragment_args_key"
                android:value="notification_badging" />
        </intent>
    </com.android.launcher3.views.ButtonPreference>
    </com.android.launcher3.settings.IconBadgingPreference>

    <SwitchPreference
        android:key="pref_add_icon_to_home"
@@ -52,10 +53,10 @@
        android:defaultValue=""
        android:persistent="false" />

    <PreferenceScreen
    <androidx.preference.PreferenceScreen
        android:fragment="com.android.launcher3.config.FlagTogglerPreferenceFragment"
        android:key="flag_toggler"
        android:persistent="false"
        android:title="Feature flags"/>

</PreferenceScreen>
</androidx.preference.PreferenceScreen>
+3 −3
Original line number Diff line number Diff line
@@ -26,9 +26,6 @@ import android.content.Intent;
import android.content.res.Resources;
import android.os.Build;
import android.os.SystemClock;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
@@ -42,6 +39,9 @@ import com.android.launcher3.util.LooperExecutor;
import java.lang.reflect.Field;

import androidx.annotation.NonNull;
import androidx.preference.ListPreference;
import androidx.preference.Preference;
import androidx.preference.Preference.OnPreferenceChangeListener;

/**
 * Utility class to override shape of {@link android.graphics.drawable.AdaptiveIconDrawable}.
+138 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 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.launcher3.settings;

import static com.android.launcher3.settings.SettingsActivity.EXTRA_FRAGMENT_ARG_KEY;
import static com.android.launcher3.settings.SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGS;

import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.provider.Settings;
import android.util.AttributeSet;
import android.view.View;

import com.android.launcher3.R;
import com.android.launcher3.notification.NotificationListener;
import com.android.launcher3.util.SecureSettingsObserver;

import androidx.preference.Preference;
import androidx.preference.PreferenceViewHolder;

/**
 * A {@link Preference} for indicating icon badging status.
 * Also has utility methods for updating UI based on badging status changes.
 */
public class IconBadgingPreference extends Preference
        implements SecureSettingsObserver.OnChangeListener {

    private boolean mWidgetFrameVisible = false;

    /** Hidden field Settings.Secure.ENABLED_NOTIFICATION_LISTENERS */
    private static final String NOTIFICATION_ENABLED_LISTENERS = "enabled_notification_listeners";

    public IconBadgingPreference(
            Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    public IconBadgingPreference(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public IconBadgingPreference(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public IconBadgingPreference(Context context) {
        super(context);
    }

    private void setWidgetFrameVisible(boolean isVisible) {
        if (mWidgetFrameVisible != isVisible) {
            mWidgetFrameVisible = isVisible;
            notifyChanged();
        }
    }

    @Override
    public void onBindViewHolder(PreferenceViewHolder holder) {
        super.onBindViewHolder(holder);

        View widgetFrame = holder.findViewById(android.R.id.widget_frame);
        if (widgetFrame != null) {
            widgetFrame.setVisibility(mWidgetFrameVisible ? View.VISIBLE : View.GONE);
        }
    }

    @Override
    public void onSettingsChanged(boolean enabled) {
        int summary = enabled ? R.string.icon_badging_desc_on : R.string.icon_badging_desc_off;

        boolean serviceEnabled = true;
        if (enabled) {
            // Check if the listener is enabled or not.
            String enabledListeners = Settings.Secure.getString(
                    getContext().getContentResolver(), NOTIFICATION_ENABLED_LISTENERS);
            ComponentName myListener =
                    new ComponentName(getContext(), NotificationListener.class);
            serviceEnabled = enabledListeners != null &&
                    (enabledListeners.contains(myListener.flattenToString()) ||
                            enabledListeners.contains(myListener.flattenToShortString()));
            if (!serviceEnabled) {
                summary = R.string.title_missing_notification_access;
            }
        }
        setWidgetFrameVisible(!serviceEnabled);
        setFragment(serviceEnabled ? null : NotificationAccessConfirmation.class.getName());
        setSummary(summary);
    }

    public static class NotificationAccessConfirmation
            extends DialogFragment implements DialogInterface.OnClickListener {

        @Override
        public Dialog onCreateDialog(Bundle savedInstanceState) {
            final Context context = getActivity();
            String msg = context.getString(R.string.msg_missing_notification_access,
                    context.getString(R.string.derived_app_name));
            return new AlertDialog.Builder(context)
                    .setTitle(R.string.title_missing_notification_access)
                    .setMessage(msg)
                    .setNegativeButton(android.R.string.cancel, null)
                    .setPositiveButton(R.string.title_change_settings, this)
                    .create();
        }

        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            ComponentName cn = new ComponentName(getActivity(), NotificationListener.class);
            Bundle showFragmentArgs = new Bundle();
            showFragmentArgs.putString(EXTRA_FRAGMENT_ARG_KEY, cn.flattenToString());

            Intent intent = new Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS)
                    .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                    .putExtra(EXTRA_FRAGMENT_ARG_KEY, cn.flattenToString())
                    .putExtra(EXTRA_SHOW_FRAGMENT_ARGS, showFragmentArgs);
            getActivity().startActivity(intent);
        }
    }
}
Loading