Merge "Fix UI issue in LocationSettings"

This commit is contained in:
TreeHugger Robot
2019-12-17 09:06:38 +00:00
committed by Android (Google) Code Review
21 changed files with 442 additions and 246 deletions

View File

@@ -20,8 +20,8 @@ import android.util.ArrayMap;
import com.android.settings.accounts.AccountDashboardFragment;
import com.android.settings.applications.manageapplications.ManageApplications;
import com.android.settings.deviceinfo.StorageDashboardFragment;
import com.android.settings.location.LocationSettings;
import com.android.settings.location.RecentLocationRequestSeeAllFragment;
import java.util.Map;
@@ -42,9 +42,9 @@ public class ProfileFragmentBridge {
ProfileSelectAccountFragment.class.getName());
FRAGMENT_MAP.put(ManageApplications.class.getName(),
ProfileSelectManageApplications.class.getName());
FRAGMENT_MAP.put(StorageDashboardFragment.class.getName(),
ProfileSelectStorageFragment.class.getName());
FRAGMENT_MAP.put(LocationSettings.class.getName(),
ProfileSelectLocationFragment.class.getName());
FRAGMENT_MAP.put(RecentLocationRequestSeeAllFragment.class.getName(),
ProfileSelectRecentLocationRequestFragment.class.getName());
}
}

View File

@@ -16,10 +16,13 @@
package com.android.settings.dashboard.profileselector;
import static android.content.Intent.EXTRA_USER_ID;
import android.annotation.IntDef;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.UserHandle;
import android.os.UserManager;
import android.view.LayoutInflater;
import android.view.View;
@@ -27,6 +30,7 @@ import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import androidx.annotation.VisibleForTesting;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentStatePagerAdapter;
import androidx.recyclerview.widget.RecyclerView;
@@ -97,21 +101,7 @@ public abstract class ProfileSelectFragment extends DashboardFragment {
Bundle savedInstanceState) {
mContentView = (ViewGroup) super.onCreateView(inflater, container, savedInstanceState);
final Activity activity = getActivity();
final int intentUser = activity.getIntent().getContentUserHint();
int selectedTab = 0;
// Start intent from a specific user eg: adb shell --user 10
if (intentUser > 0 && Utils.getManagedProfile(UserManager.get(activity)).getIdentifier()
== intentUser) {
selectedTab = WORK_TAB;
}
// Set selected tab using fragment argument
final int extraTab = getArguments() != null ? getArguments().getInt(
SettingsActivity.EXTRA_SHOW_FRAGMENT_TAB, -1) : -1;
if (extraTab != -1) {
selectedTab = extraTab;
}
final int selectedTab = getTabId(activity, getArguments());
final View tabContainer = mContentView.findViewById(R.id.tab_container);
final ViewPager viewPager = tabContainer.findViewById(R.id.view_pager);
@@ -155,6 +145,28 @@ public abstract class ProfileSelectFragment extends DashboardFragment {
return TAG;
}
@VisibleForTesting
int getTabId(Activity activity, Bundle bundle) {
if (bundle != null) {
final int extraTab = bundle.getInt(SettingsActivity.EXTRA_SHOW_FRAGMENT_TAB, -1);
if (extraTab != -1) {
return WORK_TAB;
}
final int userId = bundle.getInt(EXTRA_USER_ID, UserHandle.SYSTEM.getIdentifier());
final boolean isWorkProfile = UserManager.get(activity).isManagedProfile(userId);
if (isWorkProfile) {
return WORK_TAB;
}
}
// Start intent from a specific user eg: adb shell --user 10
final int intentUser = activity.getIntent().getContentUserHint();
if (UserManager.get(activity).isManagedProfile(intentUser)) {
return WORK_TAB;
}
return PERSONAL_TAB;
}
static class ViewPagerAdapter extends FragmentStatePagerAdapter {
private final Fragment[] mChildFragments;

View File

@@ -46,9 +46,19 @@ public class ProfileSelectLocationFragment extends ProfileSelectFragment {
@Override
public Fragment[] getFragments() {
final Bundle workOnly = new Bundle();
workOnly.putInt(EXTRA_PROFILE, ProfileSelectFragment.ProfileType.WORK);
final Fragment workFragment = new LocationWorkProfileSettings();
workFragment.setArguments(workOnly);
final Bundle personalOnly = new Bundle();
personalOnly.putInt(EXTRA_PROFILE, ProfileSelectFragment.ProfileType.PERSONAL);
final Fragment personalFragment = new LocationPersonalSettings();
personalFragment.setArguments(personalOnly);
return new Fragment[]{
new LocationPersonalSettings(),
new LocationWorkProfileSettings()
personalFragment,
workFragment
};
}
}

View File

@@ -0,0 +1,46 @@
/*
* 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.os.Bundle;
import androidx.fragment.app.Fragment;
import com.android.settings.location.RecentLocationRequestSeeAllFragment;
/**
* Recent location request page for personal/managed profile.
*/
public class ProfileSelectRecentLocationRequestFragment extends ProfileSelectFragment {
@Override
public Fragment[] getFragments() {
final Bundle workOnly = new Bundle();
workOnly.putInt(EXTRA_PROFILE, ProfileSelectFragment.ProfileType.WORK);
final Fragment workFragment = new RecentLocationRequestSeeAllFragment();
workFragment.setArguments(workOnly);
final Bundle personalOnly = new Bundle();
personalOnly.putInt(EXTRA_PROFILE, ProfileSelectFragment.ProfileType.PERSONAL);
final Fragment personalFragment = new RecentLocationRequestSeeAllFragment();
personalFragment.setArguments(personalOnly);
return new Fragment[]{
personalFragment, //0
workFragment
};
}
}

View File

@@ -1,64 +0,0 @@
/*
* 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.os.Bundle;
import android.os.UserHandle;
import android.os.UserManager;
import android.os.storage.VolumeInfo;
import androidx.fragment.app.Fragment;
import com.android.settings.R;
import com.android.settings.Utils;
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);
storageBundle.putInt(EXTRA_PROFILE, ProfileSelectFragment.ProfileType.PERSONAL);
final Fragment storageDashboardFragment = new StorageDashboardFragment();
storageDashboardFragment.setArguments(storageBundle);
final UserHandle userHandle = Utils.getManagedProfile(UserManager.get(getActivity()));
if (userHandle != null) {
storageBundle.putInt(StorageProfileFragment.USER_ID_EXTRA, userHandle.getIdentifier());
}
final Fragment storageProfileFragment = new StorageProfileFragment();
storageProfileFragment.setArguments(storageBundle);
return new Fragment[]{
storageDashboardFragment,
storageProfileFragment
};
}
@Override
protected int getPreferenceScreenResId() {
return R.xml.storage_summary_donut;
}
}