Merge "Add menu option to show/hide internal storage." into nyc-dev
am: 276dcd7
* commit '276dcd7314c7ad8ebe46bfc5290853fabd1c6316':
Add menu option to show/hide internal storage.
Change-Id: Ia99490623e560111a51814bcb5cd857c3a94ee68
This commit is contained in:
@@ -85,6 +85,10 @@
|
||||
android:id="@+id/menu_file_size"
|
||||
android:showAsAction="never"
|
||||
android:visible="false" />
|
||||
<item
|
||||
android:id="@+id/menu_advanced"
|
||||
android:showAsAction="never"
|
||||
android:visible="false" />
|
||||
<item
|
||||
android:id="@+id/menu_settings"
|
||||
android:title="@string/menu_settings"
|
||||
|
||||
@@ -24,8 +24,9 @@
|
||||
<!-- Indicates if the home directory should be hidden in the roots list, that is presented
|
||||
in the drawer/left side panel ) -->
|
||||
<bool name="home_root_hidden">true</bool>
|
||||
<!-- Indicates if the advanced roots like internal storage should be hidden in the roots list) -->
|
||||
<bool name="advanced_roots_hidden">true</bool>
|
||||
<!-- Indicates if the advanced roots like internal storage should be shown in the roots list.
|
||||
When enabled there is no menu option to toggle internal storage visibility. -->
|
||||
<bool name="advanced_roots_shown">false</bool>
|
||||
<!-- Indicates if search view is taking the whole toolbar space -->
|
||||
<bool name="full_bar_search_view">true</bool>
|
||||
</resources>
|
||||
|
||||
@@ -18,6 +18,11 @@ package com.android.documentsui;
|
||||
|
||||
import static com.android.documentsui.Shared.DEBUG;
|
||||
import static com.android.documentsui.Shared.EXTRA_BENCHMARK;
|
||||
import static com.android.documentsui.State.ACTION_CREATE;
|
||||
import static com.android.documentsui.State.ACTION_OPEN;
|
||||
import static com.android.documentsui.State.ACTION_OPEN_TREE;
|
||||
import static com.android.documentsui.State.ACTION_GET_CONTENT;
|
||||
import static com.android.documentsui.State.ACTION_PICK_COPY_DESTINATION;
|
||||
import static com.android.documentsui.State.MODE_GRID;
|
||||
|
||||
import android.app.Activity;
|
||||
@@ -165,6 +170,7 @@ public abstract class BaseActivity extends Activity
|
||||
final MenuItem sortSize = menu.findItem(R.id.menu_sort_size);
|
||||
final MenuItem grid = menu.findItem(R.id.menu_grid);
|
||||
final MenuItem list = menu.findItem(R.id.menu_list);
|
||||
final MenuItem advanced = menu.findItem(R.id.menu_advanced);
|
||||
final MenuItem fileSize = menu.findItem(R.id.menu_file_size);
|
||||
|
||||
// Search uses backend ranking; no sorting, recents doesn't support sort.
|
||||
@@ -176,6 +182,9 @@ public abstract class BaseActivity extends Activity
|
||||
grid.setVisible(mState.derivedMode != State.MODE_GRID);
|
||||
list.setVisible(mState.derivedMode != State.MODE_LIST);
|
||||
|
||||
advanced.setVisible(mState.showAdvancedOption);
|
||||
advanced.setTitle(mState.showAdvancedOption && mState.showAdvanced
|
||||
? R.string.menu_advanced_hide : R.string.menu_advanced_show);
|
||||
fileSize.setTitle(LocalPreferences.getDisplayFileSize(this)
|
||||
? R.string.menu_file_size_hide : R.string.menu_file_size_show);
|
||||
|
||||
@@ -195,25 +204,30 @@ public abstract class BaseActivity extends Activity
|
||||
return state;
|
||||
}
|
||||
|
||||
State state = createSharedState();
|
||||
includeState(state);
|
||||
if (DEBUG) Log.d(mTag, "Created new state object: " + state);
|
||||
return state;
|
||||
}
|
||||
|
||||
private State createSharedState() {
|
||||
State state = new State();
|
||||
|
||||
final Intent intent = getIntent();
|
||||
|
||||
state.localOnly = intent.getBooleanExtra(Intent.EXTRA_LOCAL_ONLY, false);
|
||||
|
||||
state.forceSize = intent.getBooleanExtra(DocumentsContract.EXTRA_SHOW_FILESIZE, false);
|
||||
state.showSize = state.forceSize || LocalPreferences.getDisplayFileSize(this);
|
||||
|
||||
state.initAcceptMimes(intent);
|
||||
state.excludedAuthorities = getExcludedAuthorities();
|
||||
|
||||
includeState(state);
|
||||
|
||||
// Advanced roots are shown by deafult without menu option if forced by config or intent.
|
||||
state.showAdvanced = getResources().getBoolean(R.bool.advanced_roots_shown)
|
||||
|| intent.getBooleanExtra(DocumentsContract.EXTRA_SHOW_ADVANCED, false);
|
||||
// Menu option is shown for whitelisted intents if advanced roots are not shown by default.
|
||||
state.showAdvancedOption = !state.showAdvanced &&
|
||||
(state.action == ACTION_OPEN ||
|
||||
state.action == ACTION_CREATE ||
|
||||
state.action == ACTION_OPEN_TREE ||
|
||||
state.action == ACTION_GET_CONTENT);
|
||||
|
||||
if (DEBUG) Log.d(mTag, "Created new state object: " + state);
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
@@ -287,6 +301,10 @@ public abstract class BaseActivity extends Activity
|
||||
}
|
||||
return true;
|
||||
|
||||
case R.id.menu_advanced:
|
||||
setDisplayAdvancedDevices(!mState.showAdvanced);
|
||||
return true;
|
||||
|
||||
case R.id.menu_file_size:
|
||||
setDisplayFileSize(!LocalPreferences.getDisplayFileSize(this));
|
||||
return true;
|
||||
@@ -452,6 +470,12 @@ public abstract class BaseActivity extends Activity
|
||||
? DocumentsContract.buildRootUri("com.android.providers.downloads.documents",
|
||||
"downloads")
|
||||
: DocumentsContract.buildHomeUri();
|
||||
}
|
||||
|
||||
void setDisplayAdvancedDevices(boolean display) {
|
||||
mState.showAdvanced = display;
|
||||
RootsFragment.get(getFragmentManager()).onDisplayStateChanged();
|
||||
invalidateOptionsMenu();
|
||||
}
|
||||
|
||||
void setDisplayFileSize(boolean display) {
|
||||
|
||||
@@ -477,6 +477,11 @@ public class RootsCache {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!state.showAdvanced && root.isAdvanced()) {
|
||||
if (DEBUG) Log.d(TAG, "Excluding root because: unwanted advanced device.");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (state.localOnly && !root.isLocalOnly()) {
|
||||
if (DEBUG) Log.d(TAG, "Excluding root because: unwanted non-local device.");
|
||||
continue;
|
||||
|
||||
@@ -321,9 +321,6 @@ public class RootsFragment extends Fragment {
|
||||
|
||||
if (root.isHome() && Shared.isHomeRootHidden(context)) {
|
||||
continue;
|
||||
} else if (root.isAdvanced()
|
||||
&& Shared.areAdvancedRootsHidden(context, state)) {
|
||||
continue;
|
||||
} else if (root.isLibrary()) {
|
||||
if (DEBUG) Log.d(TAG, "Adding " + root + " as library.");
|
||||
libraries.add(item);
|
||||
|
||||
@@ -181,12 +181,4 @@ public final class Shared {
|
||||
return context.getResources().getBoolean(R.bool.home_root_hidden);
|
||||
}
|
||||
|
||||
/*
|
||||
* Indicates if the advanced roots should be hidden.
|
||||
*/
|
||||
public static boolean areAdvancedRootsHidden(Context context, State state) {
|
||||
return context.getResources().getBoolean(R.bool.advanced_roots_hidden)
|
||||
&& state.action != ACTION_OPEN_TREE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -93,6 +93,8 @@ public class State implements android.os.Parcelable {
|
||||
public boolean forceSize;
|
||||
public boolean showSize;
|
||||
public boolean localOnly;
|
||||
public boolean showAdvancedOption;
|
||||
public boolean showAdvanced;
|
||||
public boolean restored;
|
||||
/*
|
||||
* Indicates handler was an external app, like photos.
|
||||
@@ -194,6 +196,8 @@ public class State implements android.os.Parcelable {
|
||||
out.writeInt(forceSize ? 1 : 0);
|
||||
out.writeInt(showSize ? 1 : 0);
|
||||
out.writeInt(localOnly ? 1 : 0);
|
||||
out.writeInt(showAdvancedOption ? 1 : 0);
|
||||
out.writeInt(showAdvanced ? 1 : 0);
|
||||
out.writeInt(restored ? 1 : 0);
|
||||
out.writeInt(external ? 1 : 0);
|
||||
DurableUtils.writeToParcel(out, stack);
|
||||
@@ -223,6 +227,8 @@ public class State implements android.os.Parcelable {
|
||||
state.forceSize = in.readInt() != 0;
|
||||
state.showSize = in.readInt() != 0;
|
||||
state.localOnly = in.readInt() != 0;
|
||||
state.showAdvancedOption = in.readInt() != 0;
|
||||
state.showAdvanced = in.readInt() != 0;
|
||||
state.restored = in.readInt() != 0;
|
||||
state.external = in.readInt() != 0;
|
||||
DurableUtils.readFromParcel(in, state.stack);
|
||||
|
||||
@@ -55,6 +55,7 @@ public class RootsCacheTest extends AndroidTestCase {
|
||||
|
||||
mState = new State();
|
||||
mState.action = State.ACTION_OPEN;
|
||||
mState.showAdvanced = true;
|
||||
mState.localOnly = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ public class BugreportStorageProvider extends DocumentsProvider {
|
||||
final MatrixCursor result = new MatrixCursor(resolveRootProjection(projection));
|
||||
final RowBuilder row = result.newRow();
|
||||
row.add(Root.COLUMN_ROOT_ID, DOC_ID_ROOT);
|
||||
row.add(Root.COLUMN_FLAGS, Root.FLAG_LOCAL_ONLY);
|
||||
row.add(Root.COLUMN_FLAGS, Root.FLAG_LOCAL_ONLY | Root.FLAG_ADVANCED);
|
||||
row.add(Root.COLUMN_ICON, android.R.mipmap.sym_def_app_icon);
|
||||
row.add(Root.COLUMN_TITLE, getContext().getString(R.string.bugreport_storage_title));
|
||||
row.add(Root.COLUMN_DOCUMENT_ID, DOC_ID_ROOT);
|
||||
|
||||
Reference in New Issue
Block a user