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

Commit a779cd2b authored by Daniel Nishi's avatar Daniel Nishi
Browse files

Add a collapsible checkbox preference for deletion helper.

This adds a custom preference group which has both a checkbox
and collapse/expand behavior. This is intended to be used in
the deletion helper for apps deletion and downloads folder
deletion.

This patch implements the apps deletion integration.

Bug: 28769691
Change-Id: I9fb28a1baa4067841742b5dbeaf2083728c16144
parent 07724711
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
    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.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="32dp"
        android:height="32dp"
        android:viewportWidth="24.0"
        android:viewportHeight="24.0">
    <path
            android:fillColor="#FF000000"
            android:pathData="M7.41,7.84L12,12.42l4.59,-4.58L18,9.25l-6,6 -6,-6z"/>
</vector>
 No newline at end of file
+25 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
    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.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="32dp"
        android:height="32dp"
        android:viewportWidth="24.0"
        android:viewportHeight="24.0">
    <path
            android:fillColor="#FF000000"
            android:pathData="M7.41,15.41L12,10.83l4.59,4.58L18,14l-6,-6 -6,6z"/>
</vector>
 No newline at end of file
+6 −0
Original line number Diff line number Diff line
@@ -7620,4 +7620,10 @@
    <!-- Button to activate the storage manager on the storage manager upsell. [CHAR LIMIT=20]-->
    <string name="deletion_helper_upsell_activate">Turn on</string>
    <!-- Title for the apps category in the deletion helper, showing how many apps to delete. [CHAR LIMIT=40]-->
    <string name="deletion_helper_apps_group_title">Apps (<xliff:g id="num_items">%1$d</xliff:g>)</string>
    <!-- Summary for the apps category in the deletion helper, showing how many space to clear. [CHAR LIMIT=NONE]-->
    <string name="deletion_helper_apps_group_summary"><xliff:g id="used" example="1.2GB">%1$s</xliff:g></string>
</resources>
+3 −3
Original line number Diff line number Diff line
@@ -23,8 +23,8 @@
    <com.android.settings.deletionhelper.DownloadsDeletionPreference
        android:key="delete_downloads" />

    <PreferenceCategory
    <com.android.settings.CollapsibleCheckboxPreferenceGroup
            android:key="apps_group"
        android:title="@string/deletion_helper_apps_title" />
            android:icon="@drawable/ic_keyboard_arrow_down_black_32"/>

</PreferenceScreen>
+147 −0
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.settings;

import android.content.Context;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceGroup;
import android.support.v7.preference.PreferenceViewHolder;
import android.util.AttributeSet;

import android.util.Log;
import android.util.TypedValue;
import android.view.View;
import android.widget.Checkable;
import android.widget.TextView;

import java.util.LinkedHashMap;

/**
 * CollapsibleCheckboxPreferenceGroup is a preference group that can be expanded or collapsed and
 * also has a checkbox.
 */
public class CollapsibleCheckboxPreferenceGroup extends PreferenceGroup implements
        View.OnClickListener {
    private boolean mCollapsed;
    private boolean mChecked;

    public CollapsibleCheckboxPreferenceGroup(Context context) {
        this(context, null);
    }

    public CollapsibleCheckboxPreferenceGroup(Context context, AttributeSet attrs) {
        super(context, attrs);
        setWidgetLayoutResource(com.android.settings.R.layout.preference_widget_checkbox);
    }

    @Override
    public void onBindViewHolder(PreferenceViewHolder holder) {
        super.onBindViewHolder(holder);
        View checkbox = holder.findViewById(com.android.internal.R.id.checkbox);
        if (checkbox != null && checkbox instanceof Checkable) {
            ((Checkable) checkbox).setChecked(mChecked);
            checkbox.setClickable(true);
            checkbox.setFocusable(true);
            checkbox.setOnClickListener(this);
        }

        final TextView titleView = (TextView) holder.findViewById(android.R.id.title);
        if (titleView != null) {
            Context context = getContext();
            TypedValue value = new TypedValue();
            context.getTheme().resolveAttribute(android.R.attr.colorAccent, value, true);
            titleView.setTextColor(context.getColor(value.resourceId));
        }
    }

    @Override
    public boolean addPreference(Preference p) {
        super.addPreference(p);
        p.setVisible(!isCollapsed());
        return true;
    }

    // The preference click handler.
    @Override
    protected void onClick() {
        super.onClick();
        setCollapse(!isCollapsed());
    }

    // The checkbox view click handler.
    @Override
    public void onClick(View v) {
        setChecked(!isChecked());
    }

    /**
     * Return if the view is collapsed.
     */
    public boolean isCollapsed() {
        return mCollapsed;
    }

    /**
     * Returns the checked state of the preference.
     */
    public boolean isChecked() {
        return mChecked;
    }

    /**
     * Sets the checked state and notifies listeners of the state change.
     */
    public void setChecked(boolean checked) {
        if (mChecked != checked) {
            mChecked = checked;

            callChangeListener(checked);
            notifyDependencyChange(shouldDisableDependents());
            notifyChanged();
        }
    }

    private void setCollapse(boolean isCollapsed) {
        if (mCollapsed == isCollapsed) {
            return;
        }

        mCollapsed = isCollapsed;
        if (isCollapsed) {
            hideDropdownPreferences();
        } else {
            showDropdownPreferences();
        }
    }

    private void showDropdownPreferences() {
        setAllPreferencesVisibility(true);
        setIcon(R.drawable.ic_keyboard_arrow_down_black_32);
    }

    private void hideDropdownPreferences() {
        setAllPreferencesVisibility(false);
        setIcon(R.drawable.ic_keyboard_arrow_up_black_32);
    }

    private void setAllPreferencesVisibility(boolean visible) {
        for (int i = 0; i < getPreferenceCount(); i++) {
            Preference p = getPreference(i);
            p.setVisible(visible);
        }
    }
}
Loading