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

Commit 699efba1 authored by Daniel Nishi's avatar Daniel Nishi Committed by Android (Google) Code Review
Browse files

Merge "Add the automatic storage manager settings." into nyc-mr1-dev

parents 97a8db3c 116a55cd
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -1031,4 +1031,18 @@
        <item>Red</item>
    </string-array>

    <!-- Automatic storage management settings. The amount of days for the automatic storage manager
         to retain. These are shown in a list dialog. [CHAR LIMIT=70] -->
    <string-array name="automatic_storage_management_days">
        <item>Over 30 days old</item>
        <item>Over 60 days old</item>
        <item>Over 90 days old</item>
    </string-array>

    <string-array name="automatic_storage_management_days_values" translatable="false">
        <item>30</item>
        <item>60</item>
        <item>90</item>
    </string-array>

</resources>
+3 −0
Original line number Diff line number Diff line
@@ -40,4 +40,7 @@

    <!-- Whether none security option is hide or not  (country specific). -->
    <bool name="config_hide_none_security_option">false</bool>

    <!--Whether the storage manager exists. -->
    <bool name="config_has_storage_manager">false</bool>
</resources>
+9 −0
Original line number Diff line number Diff line
@@ -7602,4 +7602,13 @@
    <!-- Button label for the dialog prompt for clearing data in deletion helper. [CHAR LIMIT=40] -->
    <string name="deletion_helper_clear_dialog_remove">Remove</string>
    <!-- Used as title on the automatic storage manager settings. [CHAR LIMIT=60] -->
    <string name="automatic_storage_manager_settings">Storage manager</string>
    <!-- Used as wall of text to describe the feature. [CHAR LIMIT=NONE] -->
    <string name="automatic_storage_manager_text">To help free up storage space, storage manager removes backed up photos and videos from your device.</string>
    <!-- Dropdown preference title for dropdown describing how many days of data to retain.-->
    <string name="automatic_storage_manager_days_title">Remove photos &amp; videos</string>
</resources>
+35 −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.
-->

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:settings="http://schemas.android.com/apk/res-auto"
        android:title="@string/automatic_storage_manager_settings" >

    <DropDownPreference
        android:key="days"
        android:summary="%s"
        android:title="@string/automatic_storage_manager_days_title"
        android:entries="@array/automatic_storage_management_days"
        android:entryValues="@array/automatic_storage_management_days_values"/>

    <com.android.settings.fuelgauge.WallOfTextPreference
        android:key="disclaimer"
        android:summary="@string/automatic_storage_manager_text"
        android:persistent="false"
        android:selectable="false"
        settings:allowDividerAbove="true" />

</PreferenceScreen>
 No newline at end of file
+99 −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.deletionhelper;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Switch;
import android.support.v7.preference.DropDownPreference;
import android.support.v7.preference.Preference;
import android.support.v7.preference.Preference.OnPreferenceChangeListener;
import android.support.v7.preference.PreferenceScreen;

import com.android.internal.logging.MetricsProto.MetricsEvent;
import com.android.settings.SettingsActivity;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.R;
import com.android.settings.widget.SwitchBar;
import com.android.settings.widget.SwitchBar.OnSwitchChangeListener;

/**
 * AutomaticStorageManagerSettings is the Settings screen for configuration and management of the
 * automatic storage manager.
 */
public class AutomaticStorageManagerSettings extends SettingsPreferenceFragment implements
        OnSwitchChangeListener, OnPreferenceChangeListener {
    private static final String KEY_DAYS = "days";

    private SwitchBar mSwitchBar;
    private DropDownPreference mDaysToRetain;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.automatic_storage_management_settings);
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        Activity activity = getActivity();
        mSwitchBar = ((SettingsActivity) activity).getSwitchBar();
        mSwitchBar.show();
        mSwitchBar.addOnSwitchChangeListener(this);
        // TODO: Initialize the switch bar position based on if the storage manager is active.

        mDaysToRetain = (DropDownPreference) findPreference(KEY_DAYS);
        mDaysToRetain.setOnPreferenceChangeListener(this);
    }

    @Override
    public void onResume() {
        super.onResume();
        // TODO: Initialize the switch bar position based on if the storage manager is active.
        maybeShowDayDropdown(mSwitchBar.isChecked());
    }

    @Override
    public void onSwitchChanged(Switch switchView, boolean isChecked) {
        // TODO: Flip a setting which controls if the storage manager should run.
        maybeShowDayDropdown(isChecked);
    }

    @Override
    public boolean onPreferenceChange(Preference preference, Object newValue) {
        // TODO: Configure a setting which controls how many days of data the storage manager
        // should retain.
        return true;
    }

    @Override
    protected int getMetricsCategory() {
        return MetricsEvent.STORAGE_MANAGER_SETTINGS;
    }

    private void maybeShowDayDropdown(boolean shouldShow) {
        PreferenceScreen screen = getPreferenceScreen();
        if (shouldShow) {
            screen.addPreference(mDaysToRetain);
        } else {
            screen.removePreference(mDaysToRetain);
        }
    }
}
Loading