diff options
author | 2022-09-01 14:20:18 +0000 | |
---|---|---|
committer | 2022-10-21 14:50:00 +0000 | |
commit | e1ad0e354c95a57e78efd46f6f5926cf077d0dd9 (patch) | |
tree | b631ee649d1acc22e43cb9bbb6ec94597be597c6 | |
parent | 0b7eb3f0dbca72e3168248a8eb7f899e1a055e34 (diff) |
Add Photo Picker Settings activity
Create a basic Settings activity that the user can eventually use to
change Could Provider settings. Users can reach the settings fragment
through the overflow menu in PhotoPickerActivity.
Since the Settings fragment is not completely developed yet, the
settings menu item is by default invisible for now.
Bug: 195009187
Test: atest PhotoPickerSettingsTest
Change-Id: I30089436ad49fed1c4cac6e34fb87f91f3540bea
-rw-r--r-- | AndroidManifest.xml | 8 | ||||
-rw-r--r-- | res/layout/activity_photo_picker_settings.xml | 29 | ||||
-rw-r--r-- | res/menu/picker_overflow_menu.xml | 4 | ||||
-rw-r--r-- | res/values/strings.xml | 15 | ||||
-rw-r--r-- | res/values/styles.xml | 9 | ||||
-rw-r--r-- | src/com/android/providers/media/photopicker/PhotoPickerActivity.java | 93 | ||||
-rw-r--r-- | src/com/android/providers/media/photopicker/PhotoPickerSettingsActivity.java | 70 | ||||
-rw-r--r-- | src/com/android/providers/media/photopicker/util/CloudProviderUtils.java | 3 | ||||
-rw-r--r-- | src/com/android/providers/media/photopicker/viewmodel/PickerViewModel.java | 17 |
9 files changed, 225 insertions, 23 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 5ccc53a2d..ff2e1c27f 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -186,6 +186,14 @@ </intent-filter> </activity> + <activity + android:name="com.android.providers.media.photopicker.PhotoPickerSettingsActivity" + android:theme="@style/PickerSettingsTheme" + android:process=":PhotoPicker" + android:excludeFromRecents="true" + android:exported="true" + android:enabled="false" /> + <activity-alias android:name="com.android.providers.media.photopicker.PhotoPickerGetContentActivity" android:targetActivity="com.android.providers.media.photopicker.PhotoPickerActivity" diff --git a/res/layout/activity_photo_picker_settings.xml b/res/layout/activity_photo_picker_settings.xml new file mode 100644 index 000000000..1288273e3 --- /dev/null +++ b/res/layout/activity_photo_picker_settings.xml @@ -0,0 +1,29 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + ~ Copyright (C) 2022 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. + --> + +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@+id/settings_activity_root" + android:orientation="vertical" + android:layout_height="match_parent" + android:layout_width="match_parent"> + + <FrameLayout + android:id="@+id/settings_fragment_container" + android:layout_width="match_parent" + android:layout_height="0dp" + android:layout_weight="1" /> +</LinearLayout> diff --git a/res/menu/picker_overflow_menu.xml b/res/menu/picker_overflow_menu.xml index 1c48ca0da..932e3d4b8 100644 --- a/res/menu/picker_overflow_menu.xml +++ b/res/menu/picker_overflow_menu.xml @@ -21,4 +21,8 @@ android:id="@+id/browse" android:title="@string/picker_browse" app:showAsAction="never"/> + <item + android:id="@+id/settings" + android:title="@string/picker_settings" + app:showAsAction="never"/> </menu>
\ No newline at end of file diff --git a/res/values/strings.xml b/res/values/strings.xml index 0fed00931..b6524d53d 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -86,6 +86,21 @@ <!-- Add browse menu item in Photo Picker to browse items in DocumentsUI. [CHAR LIMIT=30] --> <string name="picker_browse">Browse\u2026</string> + <!-- Settings menu item in Photo Picker menu. [CHAR LIMIT=30] --> + <string name="picker_settings">Settings</string> + + <!-- Settings page title in Photo Picker. [CHAR LIMIT=NONE] --> + <string name="picker_settings_title">Cloud media app</string> + + <!-- Settings page description in Photo Picker. [CHAR LIMIT=NONE] --> + <string name="picker_settings_description">Share photos and videos you back up from other services in the Android Photopicker</string> + + <!-- Settings page select cloud provider message in Photo Picker. [CHAR LIMIT=NONE] --> + <string name="picker_settings_selection_message">Access cloud media from</string> + + <!-- A label for an option in a single-select choice list that lets user select a Cloud media provider application. [CHAR LIMIT=NONE] --> + <string name="picker_settings_no_provider">None</string> + <!-- Add button for PhotoPicker. [CHAR LIMIT=30] --> <string name="add">Add</string> diff --git a/res/values/styles.xml b/res/values/styles.xml index f76eb2ee9..d7c5c89da 100644 --- a/res/values/styles.xml +++ b/res/values/styles.xml @@ -87,6 +87,11 @@ <item name="android:layout_height">@dimen/picker_profile_dialog_icon_height</item> </style> + <style name="LightActionBarNoBackground" + parent="Widget.AppCompat.Light.ActionBar.Solid"> + <item name="background">@null</item> + </style> + <style name="PickerDefaultTheme" parent="@android:style/Theme.DeviceDefault.DayNight"> <!-- System | Widget section --> <item name="android:backgroundDimEnabled">true</item> @@ -97,6 +102,10 @@ <item name="android:windowNoTitle">true</item> </style> + <style name="PickerSettingsTheme" parent="@style/Theme.AppCompat.Light"> + <item name="actionBarStyle">@style/LightActionBarNoBackground</item> + </style> + <style name="PickerMaterialTheme" parent="@style/Theme.MaterialComponents.DayNight.NoActionBar"> <item name="materialAlertDialogTheme">@style/ProfileDialogTheme</item> <item name="pickerDragBarColor">#DADCE0</item> diff --git a/src/com/android/providers/media/photopicker/PhotoPickerActivity.java b/src/com/android/providers/media/photopicker/PhotoPickerActivity.java index 150942a9c..857132021 100644 --- a/src/com/android/providers/media/photopicker/PhotoPickerActivity.java +++ b/src/com/android/providers/media/photopicker/PhotoPickerActivity.java @@ -38,6 +38,7 @@ import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Binder; import android.os.Bundle; +import android.os.SystemProperties; import android.os.UserHandle; import android.util.Log; import android.view.Menu; @@ -82,6 +83,8 @@ public class PhotoPickerActivity extends AppCompatActivity { private static final float BOTTOM_SHEET_PEEK_HEIGHT_PERCENTAGE = 0.60f; private static final float HIDE_PROFILE_BUTTON_THRESHOLD = -0.5f; private static final String LOGGER_INSTANCE_ID_ARG = "loggerInstanceIdArg"; + private static final String ENABLE_SETTINGS_SYS_PROP = + "debug.photopicker.enable_settings_screen"; private PickerViewModel mPickerViewModel; private Selection mSelection; @@ -176,6 +179,8 @@ public class PhotoPickerActivity extends AppCompatActivity { mFragmentContainerView = findViewById(R.id.fragment_container); mCrossProfileListeners = new CrossProfileListeners(); + + enableSettingsActivity(); } @Override @@ -239,22 +244,51 @@ public class PhotoPickerActivity extends AppCompatActivity { @Override public boolean onCreateOptionsMenu(@NonNull Menu menu) { - if (ACTION_GET_CONTENT.equals(getIntent().getAction())) { - getMenuInflater().inflate(R.menu.picker_overflow_menu, menu); - } - + getMenuInflater().inflate(R.menu.picker_overflow_menu, menu); return true; } @Override + public boolean onPrepareOptionsMenu(@NonNull Menu menu) { + super.onPrepareOptionsMenu(menu); + // All logic to hide/show an item in the menu must be in this method + final MenuItem settingsMenuItem = menu.findItem(R.id.settings); + + // TODO(b/195009187): Settings menu item is hidden by default till Settings page is + // completely developed. + settingsMenuItem.setVisible(isSettingsScreenEnabled()); + + // Browse menu item allows users to launch DocumentsUI. This item should only be shown if + // PhotoPicker was opened via {@link #ACTION_GET_CONTENT}. + menu.findItem(R.id.browse).setVisible(isGetContentAction()); + + return menu.hasVisibleItems(); + } + + @Override public boolean onOptionsItemSelected(MenuItem item) { - if (item.getItemId() == R.id.browse) { - mPickerViewModel.logBrowseToDocumentsUi(Binder.getCallingUid(), getCallingPackage()); - launchDocumentsUiAndFinishPicker(); + switch (item.getItemId()) { + case R.id.browse: + mPickerViewModel.logBrowseToDocumentsUi(Binder.getCallingUid(), + getCallingPackage()); + launchDocumentsUiAndFinishPicker(); + return true; + case R.id.settings: + final Intent intent = new Intent(this, PhotoPickerSettingsActivity.class); + startActivity(intent); + return true; + default: + // Continue to return the result of base class' onOptionsItemSelected(item) } return super.onOptionsItemSelected(item); } + @Override + public void onResume() { + super.onResume(); + // TODO(b/195009187): Conditionally reset PhotoPicker when current profile's cloud + // provider has changed. + } /** * @return {@code true} if the intent was re-routed to the DocumentsUI (and this @@ -482,6 +516,15 @@ public class PhotoPickerActivity extends AppCompatActivity { mPickerViewModel.logPickerCancel(Binder.getCallingUid(), getCallingPackage()); } + private void enableSettingsActivity() { + if (isSettingsScreenEnabled()) { + final ComponentName componentName = new ComponentName(this, + PhotoPickerSettingsActivity.class); + getPackageManager().setComponentEnabledSetting(componentName, + PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); + } + } + /** * Updates the common views such as Title, Toolbar, Navigation bar, status bar and bottom sheet * behavior @@ -643,6 +686,32 @@ public class PhotoPickerActivity extends AppCompatActivity { mPrivacyText.setVisibility(shouldShowPrivacyMessage ? View.VISIBLE : View.GONE); } + /** + * Reset to Photo Picker initial launch state (Photos grid tab) in personal profile mode. + * @param switchToPersonalProfile is true then set personal profile as current profile. + */ + private void reset(boolean switchToPersonalProfile) { + mPickerViewModel.reset(switchToPersonalProfile); + setupInitialLaunchState(); + } + + /** + * Returns {@code true} if settings page is enabled. + */ + private boolean isSettingsScreenEnabled() { + List<String> allowedCloudProviders = mPickerViewModel.getConfigStore() + .getAllowlistedCloudProviders(); + return !allowedCloudProviders.isEmpty() + && SystemProperties.getBoolean(ENABLE_SETTINGS_SYS_PROP, false); + } + + /** + * Returns {@code true} if intent action is ACTION_GET_CONTENT. + */ + private boolean isGetContentAction() { + return ACTION_GET_CONTENT.equals(getIntent().getAction()); + } + private class CrossProfileListeners { private final List<String> MANAGED_PROFILE_FILTER_ACTIONS = Lists.newArrayList( @@ -740,15 +809,7 @@ public class PhotoPickerActivity extends AppCompatActivity { // We reset the state of the PhotoPicker as we do not want to make any // assumptions on the state of the PhotoPicker when it was in Work Profile mode. - resetToPersonalProfile(); - } - - /** - * Reset to Photo Picker initial launch state (Photos grid tab) in personal profile mode. - */ - private void resetToPersonalProfile() { - mPickerViewModel.resetToPersonalProfile(); - setupInitialLaunchState(); + reset(/* switchToPersonalProfile */ true); } } } diff --git a/src/com/android/providers/media/photopicker/PhotoPickerSettingsActivity.java b/src/com/android/providers/media/photopicker/PhotoPickerSettingsActivity.java new file mode 100644 index 000000000..a0a368ff1 --- /dev/null +++ b/src/com/android/providers/media/photopicker/PhotoPickerSettingsActivity.java @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2022 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.providers.media.photopicker; + +import android.annotation.NonNull; +import android.os.Bundle; +import android.view.MenuItem; + +import androidx.appcompat.app.ActionBar; +import androidx.appcompat.app.AppCompatActivity; + +import com.android.providers.media.R; + +/** + * Photo Picker settings page where user can view/edit current cloud media provider. + */ +public class PhotoPickerSettingsActivity extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + // We use the device default theme as the base theme. Apply the material theme for the + // material components. We use force "false" here, only values that are not already defined + // in the base theme will be copied. + getTheme().applyStyle(R.style.PickerMaterialTheme, /* force */ false); + + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_photo_picker_settings); + + displayActionBar(); + switchToFragment(); + } + + private void displayActionBar() { + final ActionBar actionBar = getSupportActionBar(); + actionBar.setDisplayHomeAsUpEnabled(true); + actionBar.setDisplayShowTitleEnabled(false); + } + + @Override + public boolean onOptionsItemSelected(@NonNull MenuItem item) { + switch (item.getItemId()) { + case android.R.id.home: + // Stop PhotoPickerSettingsActivity when back button is pressed. + this.finish(); + return true; + default: + } + return false; + } + + private void switchToFragment() { + // TODO(b/195009187): implement this method. + return; + } + +} diff --git a/src/com/android/providers/media/photopicker/util/CloudProviderUtils.java b/src/com/android/providers/media/photopicker/util/CloudProviderUtils.java index 852780c33..3cced9c8f 100644 --- a/src/com/android/providers/media/photopicker/util/CloudProviderUtils.java +++ b/src/com/android/providers/media/photopicker/util/CloudProviderUtils.java @@ -42,9 +42,6 @@ import java.util.Objects; */ public class CloudProviderUtils { private static final String TAG = "CloudProviderUtils"; - - public static final String ALLOWED_CLOUD_PROVIDERS_KEY = "allowed_cloud_providers"; - /** * @return list of available <b>and</b> allowlisted {@link CloudMediaProvider}-s. */ diff --git a/src/com/android/providers/media/photopicker/viewmodel/PickerViewModel.java b/src/com/android/providers/media/photopicker/viewmodel/PickerViewModel.java index 8efb736de..394b0cf22 100644 --- a/src/com/android/providers/media/photopicker/viewmodel/PickerViewModel.java +++ b/src/com/android/providers/media/photopicker/viewmodel/PickerViewModel.java @@ -26,7 +26,6 @@ import android.app.Application; import android.content.Context; import android.content.Intent; import android.database.Cursor; -import android.os.Binder; import android.text.TextUtils; import android.util.Log; @@ -39,6 +38,7 @@ import androidx.lifecycle.MutableLiveData; import com.android.internal.logging.InstanceId; import com.android.internal.logging.InstanceIdSequence; import com.android.modules.utils.BackgroundThread; +import com.android.providers.media.ConfigStore; import com.android.providers.media.photopicker.data.ItemsProvider; import com.android.providers.media.photopicker.data.MuteStatus; import com.android.providers.media.photopicker.data.Selection; @@ -87,6 +87,7 @@ public class PickerViewModel extends AndroidViewModel { private int mBottomSheetState; private Category mCurrentCategory; + private ConfigStore mConfigStore; public PickerViewModel(@NonNull Application application) { super(application); @@ -97,6 +98,7 @@ public class PickerViewModel extends AndroidViewModel { mMuteStatus = new MuteStatus(); mInstanceId = new InstanceIdSequence(INSTANCE_ID_MAX).newInstanceId(); mLogger = new PhotoPickerUiEventLogger(); + mConfigStore = new ConfigStore.ConfigStoreImpl(); } @VisibleForTesting @@ -132,13 +134,16 @@ public class PickerViewModel extends AndroidViewModel { } /** - * Reset to personal profile mode. + * Reset PickerViewModel. + * @param switchToPersonalProfile is true then set personal profile as current profile. */ - public void resetToPersonalProfile() { + public void reset(boolean switchToPersonalProfile) { // 1. Clear Selected items mSelection.clearSelectedItems(); // 2. Change profile to personal user - mUserIdManager.setPersonalAsCurrentUserProfile(); + if (switchToPersonalProfile) { + mUserIdManager.setPersonalAsCurrentUserProfile(); + } // 3. Update Item and Category lists updateItems(); updateCategories(); @@ -457,4 +462,8 @@ public class PickerViewModel extends AndroidViewModel { public void setInstanceId(InstanceId parcelable) { mInstanceId = parcelable; } + + public ConfigStore getConfigStore() { + return mConfigStore; + } } |