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

Commit 9ac30701 authored by Steve McKay's avatar Steve McKay Committed by android-build-merger
Browse files

Make device storage option controlled by option.

am: 6525a19f

Change-Id: Id365d9069cb10fb5cf8ecca5a27283d5ceb4f7d8
parents b78726e1 6525a19f
Loading
Loading
Loading
Loading
+20 −26
Original line number Diff line number Diff line
@@ -18,11 +18,6 @@ package com.android.documentsui;

import static com.android.documentsui.base.Shared.DEBUG;
import static com.android.documentsui.base.Shared.EXTRA_BENCHMARK;
import static com.android.documentsui.base.State.ACTION_CREATE;
import static com.android.documentsui.base.State.ACTION_GET_CONTENT;
import static com.android.documentsui.base.State.ACTION_OPEN;
import static com.android.documentsui.base.State.ACTION_OPEN_TREE;
import static com.android.documentsui.base.State.ACTION_PICK_COPY_DESTINATION;
import static com.android.documentsui.base.State.MODE_GRID;

import android.app.Activity;
@@ -59,6 +54,7 @@ import com.android.documentsui.base.EventHandler;
import com.android.documentsui.base.Events;
import com.android.documentsui.base.LocalPreferences;
import com.android.documentsui.base.RootInfo;
import com.android.documentsui.base.ScopedPreferences;
import com.android.documentsui.base.Shared;
import com.android.documentsui.base.State;
import com.android.documentsui.base.State.ViewMode;
@@ -108,11 +104,16 @@ public abstract class BaseActivity<T extends ActionHandler>
    @LayoutRes
    private int mLayoutId;

    private RootsMonitor<BaseActivity> mRootsMonitor;
    private RootsMonitor<BaseActivity<?>> mRootsMonitor;

    private boolean mNavDrawerHasFocus;
    private long mStartTime;

    public BaseActivity(@LayoutRes int layoutId, String tag) {
        mLayoutId = layoutId;
        mTag = tag;
    }

    protected abstract void onTaskFinished(Uri... uris);
    protected abstract void refreshDirectory(int anim);
    /** Allows sub-classes to include information in a newly created State instance. */
@@ -125,6 +126,12 @@ public abstract class BaseActivity<T extends ActionHandler>
     */
    public abstract ActivityConfig getActivityConfig();

    /**
     * Provides Activity a means of injection into and specialization of
     * DirectoryFragment.
     */
    public abstract ScopedPreferences getScopedPreferences();

    /**
     * Provides Activity a means of injection into and specialization of
     * DirectoryFragment.
@@ -169,11 +176,6 @@ public abstract class BaseActivity<T extends ActionHandler>
        return mMessages;
    }

    public BaseActivity(@LayoutRes int layoutId, String tag) {
        mLayoutId = layoutId;
        mTag = tag;
    }

    @CallSuper
    @Override
    public void onCreate(Bundle icicle) {
@@ -298,19 +300,11 @@ public abstract class BaseActivity<T extends ActionHandler>

        includeState(state);

        // Advanced roots are shown by default without menu option if forced by config or intent.
        boolean forceAdvanced = Shared.shouldShowDeviceRoot(this, intent);
        boolean chosenAdvanced = LocalPreferences.getShowDeviceRoot(this, state.action);
        state.showAdvanced = forceAdvanced || chosenAdvanced;
        state.showAdvanced =
                Shared.mustShowDeviceRoot(intent) || getScopedPreferences().getShowDeviceRoot();

        // Menu option is shown for whitelisted intents if advanced roots are not shown by default.
        state.showAdvancedOption = !forceAdvanced && (
                Shared.shouldShowFancyFeatures(this)
                || state.action == ACTION_OPEN
                || state.action == ACTION_CREATE
                || state.action == ACTION_OPEN_TREE
                || state.action == ACTION_PICK_COPY_DESTINATION
                || state.action == ACTION_GET_CONTENT);
        // Only show the toggle if advanced isn't forced enabled.
        state.showAdvancedOption = !Shared.mustShowDeviceRoot(intent);

        if (DEBUG) Log.d(mTag, "Created new state object: " + state);

@@ -479,8 +473,8 @@ public abstract class BaseActivity<T extends ActionHandler>
        return (root.flags & Root.FLAG_SUPPORTS_SEARCH) != 0;
    }

    public static BaseActivity get(Fragment fragment) {
        return (BaseActivity) fragment.getActivity();
    public static BaseActivity<?> get(Fragment fragment) {
        return (BaseActivity<?>) fragment.getActivity();
    }

    public State getDisplayState() {
@@ -499,7 +493,7 @@ public abstract class BaseActivity<T extends ActionHandler>
        Metrics.logUserAction(this,
                display ? Metrics.USER_ACTION_SHOW_ADVANCED : Metrics.USER_ACTION_HIDE_ADVANCED);

        LocalPreferences.setShowDeviceRoot(this, mState.action, display);
        getScopedPreferences().setShowDeviceRoot(display);
        mState.showAdvanced = display;
        RootsFragment.get(getFragmentManager()).onDisplayStateChanged();
        invalidateOptionsMenu();
+2 −2
Original line number Diff line number Diff line
@@ -296,9 +296,9 @@ public abstract class MenuManager {
    }

    public static class DirectoryDetails {
        private final BaseActivity mActivity;
        private final BaseActivity<?> mActivity;

        public DirectoryDetails(BaseActivity activity) {
        public DirectoryDetails(BaseActivity<?> activity) {
            mActivity = activity;
        }

+0 −11
Original line number Diff line number Diff line
@@ -26,14 +26,12 @@ import android.content.SharedPreferences.Editor;
import android.os.UserHandle;
import android.preference.PreferenceManager;

import com.android.documentsui.base.State.ActionType;
import com.android.documentsui.base.State.ViewMode;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

public class LocalPreferences {
    private static final String INCLUDE_DEVICE_ROOT = "includeDeviceRoot-";
    private static final String ROOT_VIEW_MODE_PREFIX = "rootViewMode-";

    public static @ViewMode int getViewMode(Context context, RootInfo root,
@@ -41,15 +39,6 @@ public class LocalPreferences {
        return getPrefs(context).getInt(createKey(root), fallback);
    }

    public static boolean getShowDeviceRoot(Context context, @ActionType int action) {
        return getPrefs(context).getBoolean(INCLUDE_DEVICE_ROOT + action, false);
    }

    public static void setShowDeviceRoot(
            Context context, @ActionType int action, boolean display) {
        getPrefs(context).edit().putBoolean(INCLUDE_DEVICE_ROOT + action, display).apply();
    }

    public static void setViewMode(Context context, RootInfo root, @ViewMode int viewMode) {
        assert(viewMode != MODE_UNKNOWN);
        getPrefs(context).edit().putInt(createKey(root), viewMode).apply();
+54 −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.documentsui.base;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

public interface ScopedPreferences {

    boolean getShowDeviceRoot();
    void setShowDeviceRoot(boolean display);

    public static ScopedPreferences create(Context context, String scope) {
        return new RuntimeScopedPreferences(
                PreferenceManager.getDefaultSharedPreferences(context), scope);
    }

    static final class RuntimeScopedPreferences implements ScopedPreferences {

        private static final String INCLUDE_DEVICE_ROOT = "includeDeviceRoot-";

        private SharedPreferences mSharedPrefs;
        private String mScope;

        private RuntimeScopedPreferences(SharedPreferences sharedPrefs, String scope)  {
            mSharedPrefs = sharedPrefs;
            mScope = scope;
        }

        @Override
        public boolean getShowDeviceRoot() {
            return mSharedPrefs.getBoolean(INCLUDE_DEVICE_ROOT + mScope, false);
        }

        @Override
        public void setShowDeviceRoot(boolean display) {
            mSharedPrefs.edit().putBoolean(INCLUDE_DEVICE_ROOT + mScope, display).apply();
        }
    }
}
+2 −3
Original line number Diff line number Diff line
@@ -251,9 +251,8 @@ public final class Shared {
    /*
     * Returns true if device root should be shown.
     */
    public static boolean shouldShowDeviceRoot(Context context, Intent intent) {
        return isProductivityMode(context, intent)
                || intent.getBooleanExtra(DocumentsContract.EXTRA_SHOW_ADVANCED, false);
    public static boolean mustShowDeviceRoot(Intent intent) {
        return intent.getBooleanExtra(DocumentsContract.EXTRA_SHOW_ADVANCED, false);
    }

    /**
Loading