Add work/personal profile tab for storage page

- Add ProfileSelectStorageFragment
- Check featureFlag in SecondaryUserController to decide show/hide
workprofile item StorageDashboardFragment

Bug: 141601408
Test: manual
Change-Id: I97762d3b1a4985e2b186b34fc37c7976c2f69224
This commit is contained in:
Raff Tsai
2019-10-25 13:01:34 +08:00
parent 8ed2568882
commit 539ab8ace4
7 changed files with 102 additions and 21 deletions

View File

@@ -22,21 +22,27 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical"> android:orientation="vertical">
<com.google.android.material.tabs.TabLayout
android:background="@android:color/transparent"
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMaxWidth="0dp"
app:tabGravity="fill"
app:tabMode="fixed"
app:tabIndicatorFullWidth="false"
app:tabIndicatorColor="@*android:color/accent_device_default"
app:tabSelectedTextColor="@*android:color/accent_device_default"
app:tabTextColor="?android:attr/textColorSecondary" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?android:attr/listDivider"/>
<androidx.viewpager.widget.ViewPager <androidx.viewpager.widget.ViewPager
android:id="@+id/view_pager" android:id="@+id/view_pager"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<com.google.android.material.tabs.TabLayout
android:background="@android:color/transparent"
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMaxWidth="0dp"
app:tabGravity="fill"
app:tabMode="fixed"
app:tabIndicatorColor="@*android:color/accent_device_default"
app:tabSelectedTextColor="@*android:color/accent_device_default"
app:tabTextColor="?android:attr/textColorSecondary" />
</androidx.viewpager.widget.ViewPager> </androidx.viewpager.widget.ViewPager>
</LinearLayout> </LinearLayout>

View File

@@ -19,9 +19,8 @@ package com.android.settings.dashboard.profileselector;
import android.util.ArrayMap; import android.util.ArrayMap;
import com.android.settings.accounts.AccountDashboardFragment; import com.android.settings.accounts.AccountDashboardFragment;
import com.android.settings.accounts.AccountProfileSelectFragment;
import com.android.settings.applications.manageapplications.ManageApplications; import com.android.settings.applications.manageapplications.ManageApplications;
import com.android.settings.applications.manageapplications.ProfileSelectManageApplications; import com.android.settings.deviceinfo.StorageDashboardFragment;
import java.util.Map; import java.util.Map;
@@ -39,8 +38,10 @@ public class ProfileFragmentBridge {
static { static {
FRAGMENT_MAP = new ArrayMap<>(); FRAGMENT_MAP = new ArrayMap<>();
FRAGMENT_MAP.put(AccountDashboardFragment.class.getName(), FRAGMENT_MAP.put(AccountDashboardFragment.class.getName(),
AccountProfileSelectFragment.class.getName()); ProfileSelectAccountFragment.class.getName());
FRAGMENT_MAP.put(ManageApplications.class.getName(), FRAGMENT_MAP.put(ManageApplications.class.getName(),
ProfileSelectManageApplications.class.getName()); ProfileSelectManageApplications.class.getName());
FRAGMENT_MAP.put(StorageDashboardFragment.class.getName(),
ProfileSelectStorageFragment.class.getName());
} }
} }

View File

@@ -14,15 +14,16 @@
* limitations under the License. * limitations under the License.
*/ */
package com.android.settings.accounts; package com.android.settings.dashboard.profileselector;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import com.android.settings.dashboard.profileselector.ProfileSelectFragment; import com.android.settings.accounts.AccountPersonalDashboardFragment;
import com.android.settings.accounts.AccountWorkProfileDashboardFragment;
/** /**
* Account Setting page for personal/managed profile. * Account Setting page for personal/managed profile.
*/ */
public class AccountProfileSelectFragment extends ProfileSelectFragment { public class ProfileSelectAccountFragment extends ProfileSelectFragment {
@Override @Override
public Fragment[] getFragments() { public Fragment[] getFragments() {

View File

@@ -30,6 +30,8 @@ import androidx.viewpager.widget.ViewPager;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.core.InstrumentedFragment; import com.android.settings.core.InstrumentedFragment;
import com.google.android.material.tabs.TabLayout;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
@@ -69,6 +71,8 @@ public abstract class ProfileSelectFragment extends InstrumentedFragment {
mContentView = inflater.inflate(R.layout.profile_select_tablayout, null /* root */); mContentView = inflater.inflate(R.layout.profile_select_tablayout, null /* root */);
final ViewPager viewPager = mContentView.findViewById(R.id.view_pager); final ViewPager viewPager = mContentView.findViewById(R.id.view_pager);
viewPager.setAdapter(new ViewPagerAdapter(this)); viewPager.setAdapter(new ViewPagerAdapter(this));
final TabLayout tabs = mContentView.findViewById(R.id.tabs);
tabs.setupWithViewPager(viewPager);
return mContentView; return mContentView;
} }

View File

@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package com.android.settings.applications.manageapplications; package com.android.settings.dashboard.profileselector;
import static com.android.settings.applications.manageapplications.ManageApplications.EXTRA_PERSONAL_ONLY; import static com.android.settings.applications.manageapplications.ManageApplications.EXTRA_PERSONAL_ONLY;
import static com.android.settings.applications.manageapplications.ManageApplications.EXTRA_WORK_ONLY; import static com.android.settings.applications.manageapplications.ManageApplications.EXTRA_WORK_ONLY;
@@ -23,10 +23,10 @@ import android.os.Bundle;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import com.android.settings.dashboard.profileselector.ProfileSelectFragment; import com.android.settings.applications.manageapplications.ManageApplications;
/** /**
* Application Setting page for work profile. * Application Setting page for personal/managed profile.
*/ */
public class ProfileSelectManageApplications extends ProfileSelectFragment { public class ProfileSelectManageApplications extends ProfileSelectFragment {
@@ -41,7 +41,7 @@ public class ProfileSelectManageApplications extends ProfileSelectFragment {
personalOnly.putBoolean(EXTRA_PERSONAL_ONLY, true); personalOnly.putBoolean(EXTRA_PERSONAL_ONLY, true);
final Fragment personalFragment = new ManageApplications(); final Fragment personalFragment = new ManageApplications();
personalFragment.setArguments(personalOnly); personalFragment.setArguments(personalOnly);
return new Fragment[] { return new Fragment[]{
personalFragment, //0 personalFragment, //0
workFragment workFragment
}; };

View File

@@ -0,0 +1,62 @@
/*
* Copyright (C) 2019 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.dashboard.profileselector;
import android.content.pm.UserInfo;
import android.os.Bundle;
import android.os.UserManager;
import android.os.storage.VolumeInfo;
import androidx.fragment.app.Fragment;
import com.android.settings.deviceinfo.StorageDashboardFragment;
import com.android.settings.deviceinfo.StorageProfileFragment;
/**
* Storage Setting page for personal/managed profile.
*/
public class ProfileSelectStorageFragment extends ProfileSelectFragment {
@Override
public Fragment[] getFragments() {
final Bundle storageBundle = new Bundle();
storageBundle.putString(VolumeInfo.EXTRA_VOLUME_ID, VolumeInfo.ID_PRIVATE_INTERNAL);
final Fragment storageDashboardFragment = new StorageDashboardFragment();
storageDashboardFragment.setArguments(storageBundle);
UserInfo targetUser = null;
for (UserInfo info : UserManager.get(getActivity()).getUsers()) {
if (!info.isPrimary()) {
targetUser = info;
break;
}
}
// TODO(b/143330969): Need to think about more profile users case
if (targetUser != null) {
storageBundle.putInt(StorageProfileFragment.USER_ID_EXTRA, targetUser.id);
}
final Fragment storageProfileFragment = new StorageProfileFragment();
storageProfileFragment.setArguments(storageBundle);
return new Fragment[]{
storageDashboardFragment,
storageProfileFragment
};
}
}

View File

@@ -20,6 +20,7 @@ import android.content.Context;
import android.content.pm.UserInfo; import android.content.pm.UserInfo;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.UserManager; import android.os.UserManager;
import android.util.FeatureFlagUtils;
import android.util.SparseArray; import android.util.SparseArray;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@@ -29,6 +30,7 @@ import androidx.preference.PreferenceGroup;
import androidx.preference.PreferenceScreen; import androidx.preference.PreferenceScreen;
import com.android.settings.Utils; import com.android.settings.Utils;
import com.android.settings.core.FeatureFlags;
import com.android.settings.core.PreferenceControllerMixin; import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.deviceinfo.StorageItemPreference; import com.android.settings.deviceinfo.StorageItemPreference;
import com.android.settingslib.core.AbstractPreferenceController; import com.android.settingslib.core.AbstractPreferenceController;
@@ -66,7 +68,12 @@ public class SecondaryUserController extends AbstractPreferenceController implem
*/ */
public static List<AbstractPreferenceController> getSecondaryUserControllers( public static List<AbstractPreferenceController> getSecondaryUserControllers(
Context context, UserManager userManager) { Context context, UserManager userManager) {
List<AbstractPreferenceController> controllers = new ArrayList<>(); List<AbstractPreferenceController> controllers = new ArrayList<>();
if (FeatureFlagUtils.isEnabled(context, FeatureFlags.PERSONAL_WORK_PROFILE)) {
controllers.add(new NoSecondaryUserController(context));
return controllers;
}
UserInfo primaryUser = userManager.getPrimaryUser(); UserInfo primaryUser = userManager.getPrimaryUser();
boolean addedUser = false; boolean addedUser = false;
List<UserInfo> infos = userManager.getUsers(); List<UserInfo> infos = userManager.getUsers();