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

Commit 1f2dfd40 authored by Roman Birg's avatar Roman Birg
Browse files

MasterClear: update UI



Change-Id: I759de586bf5cb8558d42575d08df63aaf84fffa6
Signed-off-by: default avatarRoman Birg <roman@cyngn.com>
parent e2d33968
Loading
Loading
Loading
Loading
+197 −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.
-->

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:orientation="vertical">

    <ScrollView
            android:layout_width="match_parent"
            android:layout_height="0dip"
            android:layout_weight="1">

        <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

            <!-- top section "Personal data & apps" -->
            <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center_vertical"
                    android:minHeight="?android:attr/listPreferredItemHeight"
                    android:orientation="vertical"
                    android:paddingBottom="16dp"
                    android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
                    android:paddingStart="?android:attr/listPreferredItemPaddingStart"
                    android:paddingTop="16dp">

                <TextView
                        android:id="@+id/title"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="@string/factory_reset_instructions_title"
                        android:textAppearance="?android:attr/textAppearanceListItem" />

                <TextView
                        android:id="@+id/summary"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="@string/factory_reset_instructions_summary"
                        android:textAppearance="?android:attr/textAppearanceListItemSecondary"
                        android:textColor="?android:attr/textColorSecondary" />

            </LinearLayout>

            <View
                    style="@style/SolidSettingSeparator"
                    android:layout_marginEnd="0dp"
                    android:layout_marginStart="0dp" />

            <TextView
                    android:layout_width="match_parent"
                    android:layout_height="?android:attr/listPreferredItemHeight"
                    android:gravity="center_vertical"
                    android:orientation="vertical"
                    android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
                    android:paddingStart="?android:attr/listPreferredItemPaddingStart"
                    android:text="@string/factory_reset_personal_content"
                    android:textAppearance="@style/TextAppearance.CategoryTitle" />

            <!-- erase stored content -->
            <LinearLayout
                    android:id="@+id/erase_internal_container"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:clickable="true"
                    android:focusable="true"
                    android:orientation="horizontal"
                    android:paddingBottom="8dp"
                    android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
                    android:paddingStart="?android:attr/listPreferredItemPaddingStart">

                <CheckBox
                        android:id="@+id/erase_internal"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="top"
                        android:clickable="false"
                        android:duplicateParentState="true"
                        android:focusable="false"
                        android:padding="3dp" />

                <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_vertical"
                        android:layout_marginStart="16dp"
                        android:duplicateParentState="true"
                        android:orientation="vertical">

                    <TextView
                            android:id="@+id/erase_storage_checkbox_title"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:duplicateParentState="true"
                            android:text="@string/factory_reset_erase_stored_content"
                            android:textAppearance="?android:attr/textAppearanceListItem"
                            android:textStyle="bold" />

                    <TextView
                            android:id="@+id/erase_storage_checkbox_description"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:duplicateParentState="true"
                            android:text="@string/factory_reset_erase_stored_content_summary"
                            android:textAppearance="?android:attr/textAppearanceListItemSecondary"
                            android:textColor="?android:attr/textColorSecondary" />
                </LinearLayout>
            </LinearLayout>

            <!-- format sd card -->
            <LinearLayout
                    android:id="@+id/erase_external_container"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:clickable="true"
                    android:focusable="true"
                    android:orientation="horizontal"
                    android:paddingBottom="8dp"
                    android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
                    android:paddingStart="?android:attr/listPreferredItemPaddingStart"
                    android:paddingTop="8dp">

                <CheckBox
                        android:id="@+id/erase_external"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="top"
                        android:clickable="false"
                        android:duplicateParentState="true"
                        android:focusable="false"
                        android:padding="3dp" />

                <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_vertical"
                        android:layout_marginStart="16dp"
                        android:duplicateParentState="true"
                        android:orientation="vertical">

                    <TextView
                            android:id="@+id/erase_sdcard_checkbox_title"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:duplicateParentState="true"
                            android:text="@string/factory_reset_erase_sd_card"
                            android:textAppearance="?android:attr/textAppearanceListItem"
                            android:textStyle="bold" />

                    <TextView
                            android:id="@+id/erase_sdcard_checkbox_description"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:duplicateParentState="true"
                            android:text="@string/factory_reset_erase_sd_card_summary"
                            android:textAppearance="?android:attr/textAppearanceListItemSecondary"
                            android:textColor="?android:attr/textColorSecondary" />
                </LinearLayout>
            </LinearLayout>
        </LinearLayout>
    </ScrollView>

    <View style="@style/SolidSettingSeparator" />

    <Button
            android:id="@+id/initiate_master_clear"
            style="?android:attr/borderlessButtonStyle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="right"
            android:layout_marginBottom="8dp"
            android:layout_marginEnd="12dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="8dp"
            android:gravity="center"
            android:padding="10dp"
            android:text="@string/master_clear_button_text"
            android:textColor="@color/factory_reset_color"
            android:textSize="14sp" />

</LinearLayout>
+4 −0
Original line number Diff line number Diff line
@@ -59,4 +59,8 @@

    <!-- Personal Dictionary Add Icon -->
    <drawable name="ic_menu_add_word">@drawable/ic_menu_add_dark</drawable>

    <color name="factory_reset_color">#FFFE412C</color>

    <color name="divider">#ffe0e0e0</color>
</resources>
+12 −0
Original line number Diff line number Diff line
@@ -1198,4 +1198,16 @@
    <string name="preview_version_title">Version</string>
    <string name="preview_country_title">Country</string>
    <string name="preview_carrier_title">Carrier</string>

    <!-- Factory reset strings -->
    <string name="factory_reset_instructions_title">Personal data &amp; apps</string>
    <string name="factory_reset_instructions_summary">This will erase all your accounts, apps, app data, and system settings on this device</string>
    <string name="factory_reset_personal_content">Personal content</string>
    <string name="factory_reset_erase_stored_content">Erase stored content</string>
    <string name="factory_reset_erase_stored_content_summary">Erase music, photos, videos, and other user data stored on this device</string>
    <string name="factory_reset_erase_stored_content_summary_forced">Erase music, photos, videos, and other user data stored on this device. \n\n<b>Content cannot be saved due to device encryption.</b></string>
    <string name="factory_reset_erase_sd_card">Format SD card</string>
    <string name="factory_reset_erase_sd_card_summary">Erase all data on the SD card, including music and photos</string>
    <string name="factory_reset_warning_text_reset_now">RESET NOW</string>
    <string name="factory_reset_warning_text_message">All your accounts, apps, app data, and system settings will be removed from this device. This cannot be reversed.</string>
</resources>
+4 −0
Original line number Diff line number Diff line
@@ -376,6 +376,10 @@
        <item name="android:layout_height">1dp</item>
    </style>

    <style name="SolidSettingSeparator" parent="@style/settingSeparator">
        <item name="android:background">@color/divider</item>
    </style>

    <style name="floating_action_button">
        <item name="android:layout_width">@dimen/fab_size</item>
        <item name="android:layout_height">@dimen/fab_size</item>
+55 −116
Original line number Diff line number Diff line
/*
 * Copyright (C) 2008 The Android Open Source Project
 * 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.
@@ -16,9 +17,6 @@

package com.android.settings;

import android.accounts.Account;
import android.accounts.AccountManager;
import android.accounts.AuthenticatorDescription;
import android.app.Activity;
import android.app.Fragment;
import android.content.Context;
@@ -26,6 +24,9 @@ import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.os.Environment;
import android.os.Process;
@@ -38,7 +39,6 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.TextView;

/**
@@ -56,12 +56,15 @@ public class MasterClear extends Fragment {

    private static final int KEYGUARD_REQUEST = 55;

    static final String WIPE_MEDIA_EXTRA = "wipe_media";
    static final String ERASE_EXTERNAL_EXTRA = "erase_sd";
    //must match MasterClearReceiver.java extra
    public static final String EXTRA_WIPE_MEDIA = "wipe_media";
    public static final String EXTRA_WIPE_SDCARD = "wipe_sdcard";

    private View mContentView;
    private Button mInitiateButton;
    private View mExternalStorageContainer;
    private View mInternalStorageContainer;
    private CheckBox mInternalStorage;
    private CheckBox mExternalStorage;

    /**
@@ -94,17 +97,8 @@ public class MasterClear extends Fragment {
    }

    private void showFinalConfirmation() {
        Preference preference = new Preference(getActivity());
        preference.setFragment(MasterClearConfirm.class.getName());
        preference.setTitle(R.string.master_clear_confirm_title);
        if (mExternalStorage.isChecked()) {
            if (Environment.isExternalStorageEmulated()) {
                preference.getExtras().putBoolean(WIPE_MEDIA_EXTRA, true);
            } else {
                preference.getExtras().putBoolean(ERASE_EXTERNAL_EXTRA, true);
            }
        }
        ((SettingsActivity) getActivity()).onPreferenceStartFragment(null, preference);
        MasterClearConfirm.getInstance(mInternalStorage.isChecked(), mExternalStorage.isChecked())
                .show(getFragmentManager(), MasterClearConfirm.class.getSimpleName());
    }

    /**
@@ -136,124 +130,69 @@ public class MasterClear extends Fragment {
    private void establishInitialState() {
        mInitiateButton = (Button) mContentView.findViewById(R.id.initiate_master_clear);
        mInitiateButton.setOnClickListener(mInitiateListener);
        mInternalStorage = (CheckBox) mContentView.findViewById(R.id.erase_internal);
        mInternalStorageContainer = mContentView.findViewById(R.id.erase_internal_container);
        mExternalStorageContainer = mContentView.findViewById(R.id.erase_external_container);
        mExternalStorage = (CheckBox) mContentView.findViewById(R.id.erase_external);

        /*
         * If the external storage is emulated, it will be erased with a factory
         * reset at any rate. There is no need to have a separate option until
         * we have a factory reset that only erases some directories and not
         * others. Likewise, if it's non-removable storage, it could potentially have been
         * encrypted, and will also need to be wiped.
         */
        boolean isExtStorageEmulated = Environment.isExternalStorageEmulated();
        /* CM's recovery (and most custom ones) does NOT clear emulated
         * storage when asked for a reset  */
        if (!Environment.isExternalStorageRemovable() && isExtStorageEncrypted()) {
            mExternalStorageContainer.setVisibility(View.GONE);
        boolean hasExternalStorage = false;

            final View externalOption = mContentView.findViewById(R.id.erase_external_option_text);
            externalOption.setVisibility(View.GONE);

            final View externalAlsoErased = mContentView.findViewById(R.id.also_erases_external);
            externalAlsoErased.setVisibility(View.VISIBLE);

            // If it's not emulated, it is on a separate partition but it means we're doing
            // a force wipe due to encryption.
            mExternalStorage.setChecked(!isExtStorageEmulated);
        } else {
            mExternalStorageContainer.setOnClickListener(new View.OnClickListener() {
        /**
         * Here we do some logic to ensure the proper states are initialized.
         * - hide internal memory section if device doesn't support it
         * - force internal memory to be erased if the device is encrypted
         * - show and hide the sd card section if the device supports this (and its inserted)
         * TODO: mutli SD card support: no devices we support have this, but that might change
         */

        if (Environment.isExternalStorageEmulated()) {
            // we may have to force wipe internal storage due to encryption.
            mInternalStorageContainer.setEnabled(!isExtStorageEncrypted()
                    && !Environment.isExternalStorageRemovable());
            mInternalStorageContainer.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mExternalStorage.toggle();
                    mInternalStorage.toggle();
                }
            });

            final TextView wipeStorage =
                    (TextView)mContentView.findViewById(R.id.erase_external_option_text);
            wipeStorage.setText(isExtStorageEmulated ?
                    R.string.master_clear_desc_erase_internal_storage :
                    R.string.master_clear_desc_erase_external_storage);

            final TextView wipeStorageTitle =
                    (TextView)mContentView.findViewById(R.id.erase_storage_checkbox_title);
            wipeStorageTitle.setText(isExtStorageEmulated ?
                    R.string.erase_internal_storage :
                    R.string.erase_external_storage);

            final TextView wipeStorageDescription =
                    (TextView)mContentView.findViewById(R.id.erase_storage_checkbox_description);
            wipeStorageDescription.setText(isExtStorageEmulated ?
                    R.string.erase_internal_storage_description :
                    R.string.erase_external_storage_description);
            if (!mInternalStorageContainer.isEnabled()) {
                // force internal wipe
                mInternalStorage.setChecked(true);
                TextView internalSummaryText = (TextView) mContentView.findViewById(
                        R.id.erase_storage_checkbox_description);
                internalSummaryText.setText(
                        R.string.factory_reset_erase_stored_content_summary_forced);
            }

        loadAccountList();
            if (Environment.isExternalStorageRemovable(Environment.getSecondaryStorageDirectory())
                    && Environment.getSecondaryStorageState().equals(Environment.MEDIA_MOUNTED)) {
                hasExternalStorage = true;
            }

    private boolean isExtStorageEncrypted() {
        String state = SystemProperties.get("vold.decrypt");
        return !"".equals(state);
    }

    private void loadAccountList() {
        View accountsLabel = mContentView.findViewById(R.id.accounts_label);
        LinearLayout contents = (LinearLayout)mContentView.findViewById(R.id.accounts);
        contents.removeAllViews();

        Context context = getActivity();
        } else {
            // there's no storage emulation; hide internal storage
            mInternalStorageContainer.setVisibility(View.GONE);

        AccountManager mgr = AccountManager.get(context);
        Account[] accounts = mgr.getAccounts();
        final int N = accounts.length;
        if (N == 0) {
            accountsLabel.setVisibility(View.GONE);
            contents.setVisibility(View.GONE);
            return;
            // primary storage can be removed. but does it exist?
            hasExternalStorage = Environment.isNoEmulatedStorageExist();
        }

        LayoutInflater inflater = (LayoutInflater)context.getSystemService(
                Context.LAYOUT_INFLATER_SERVICE);

        AuthenticatorDescription[] descs = AccountManager.get(context).getAuthenticatorTypes();
        final int M = descs.length;

        for (int i=0; i<N; i++) {
            Account account = accounts[i];
            AuthenticatorDescription desc = null;
            for (int j=0; j<M; j++) {
                if (account.type.equals(descs[j].type)) {
                    desc = descs[j];
                    break;
                }
            }
            if (desc == null) {
                Log.w(TAG, "No descriptor for account name=" + account.name
                        + " type=" + account.type);
                continue;
            }
            Drawable icon = null;
            try {
                if (desc.iconId != 0) {
                    Context authContext = context.createPackageContext(desc.packageName, 0);
                    icon = authContext.getResources().getDrawable(desc.iconId);
                }
            } catch (PackageManager.NameNotFoundException e) {
                Log.w(TAG, "No icon for account type " + desc.type);
        if (hasExternalStorage) {
            mExternalStorageContainer.setVisibility(View.VISIBLE);
            mExternalStorageContainer.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mExternalStorage.toggle();
                }

            TextView child = (TextView)inflater.inflate(R.layout.master_clear_account,
                    contents, false);
            child.setText(account.name);
            if (icon != null) {
                child.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null);
            });
        } else {
            mExternalStorageContainer.setVisibility(View.GONE);
        }
            contents.addView(child);
    }

        accountsLabel.setVisibility(View.VISIBLE);
        contents.setVisibility(View.VISIBLE);
    private boolean isExtStorageEncrypted() {
        String state = SystemProperties.get("vold.decrypt");
        return !"".equals(state);
    }

    @Override
@@ -265,7 +204,7 @@ public class MasterClear extends Fragment {
            return inflater.inflate(R.layout.master_clear_disallowed_screen, null);
        }

        mContentView = inflater.inflate(R.layout.master_clear, null);
        mContentView = inflater.inflate(R.layout.master_clear_cm, null);

        establishInitialState();
        return mContentView;
Loading