Merge "Show a spinner when waiting for the work profile to turn on." into rvc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
f6b536594b
@@ -64,6 +64,7 @@ public abstract class AbstractMultiProfilePagerAdapter extends PagerAdapter {
|
||||
private final UserHandle mPersonalProfileUserHandle;
|
||||
private final UserHandle mWorkProfileUserHandle;
|
||||
private Injector mInjector;
|
||||
private boolean mIsWaitingToEnableWorkProfile;
|
||||
|
||||
AbstractMultiProfilePagerAdapter(Context context, int currentPage,
|
||||
UserHandle personalProfileUserHandle,
|
||||
@@ -90,10 +91,19 @@ public abstract class AbstractMultiProfilePagerAdapter extends PagerAdapter {
|
||||
@Override
|
||||
public void requestQuietModeEnabled(boolean enabled, UserHandle workProfileUserHandle) {
|
||||
userManager.requestQuietModeEnabled(enabled, workProfileUserHandle);
|
||||
mIsWaitingToEnableWorkProfile = true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected void markWorkProfileEnabledBroadcastReceived() {
|
||||
mIsWaitingToEnableWorkProfile = false;
|
||||
}
|
||||
|
||||
protected boolean isWaitingToEnableWorkProfile() {
|
||||
return mIsWaitingToEnableWorkProfile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides the default {@link Injector} for testing purposes.
|
||||
*/
|
||||
@@ -294,8 +304,12 @@ public abstract class AbstractMultiProfilePagerAdapter extends PagerAdapter {
|
||||
R.drawable.ic_work_apps_off,
|
||||
R.string.resolver_turn_on_work_apps,
|
||||
R.string.resolver_turn_on_work_apps_explanation,
|
||||
(View.OnClickListener) v ->
|
||||
mInjector.requestQuietModeEnabled(false, mWorkProfileUserHandle));
|
||||
(View.OnClickListener) v -> {
|
||||
ProfileDescriptor descriptor = getItem(
|
||||
userHandleToPageIndex(activeListAdapter.getUserHandle()));
|
||||
showSpinner(descriptor.getEmptyStateView());
|
||||
mInjector.requestQuietModeEnabled(false, mWorkProfileUserHandle);
|
||||
});
|
||||
return false;
|
||||
}
|
||||
if (UserHandle.myUserId() != listUserHandle.getIdentifier()) {
|
||||
@@ -355,7 +369,8 @@ public abstract class AbstractMultiProfilePagerAdapter extends PagerAdapter {
|
||||
ProfileDescriptor descriptor = getItem(
|
||||
userHandleToPageIndex(activeListAdapter.getUserHandle()));
|
||||
descriptor.rootView.findViewById(R.id.resolver_list).setVisibility(View.GONE);
|
||||
View emptyStateView = descriptor.rootView.findViewById(R.id.resolver_empty_state);
|
||||
View emptyStateView = descriptor.getEmptyStateView();
|
||||
resetViewVisibilities(emptyStateView);
|
||||
emptyStateView.setVisibility(View.VISIBLE);
|
||||
|
||||
ImageView icon = emptyStateView.findViewById(R.id.resolver_empty_state_icon);
|
||||
@@ -372,6 +387,23 @@ public abstract class AbstractMultiProfilePagerAdapter extends PagerAdapter {
|
||||
button.setOnClickListener(buttonOnClick);
|
||||
}
|
||||
|
||||
private void showSpinner(View emptyStateView) {
|
||||
emptyStateView.findViewById(R.id.resolver_empty_state_icon).setVisibility(View.INVISIBLE);
|
||||
emptyStateView.findViewById(R.id.resolver_empty_state_title).setVisibility(View.INVISIBLE);
|
||||
emptyStateView.findViewById(R.id.resolver_empty_state_subtitle)
|
||||
.setVisibility(View.INVISIBLE);
|
||||
emptyStateView.findViewById(R.id.resolver_empty_state_button).setVisibility(View.INVISIBLE);
|
||||
emptyStateView.findViewById(R.id.resolver_empty_state_progress).setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
private void resetViewVisibilities(View emptyStateView) {
|
||||
emptyStateView.findViewById(R.id.resolver_empty_state_icon).setVisibility(View.VISIBLE);
|
||||
emptyStateView.findViewById(R.id.resolver_empty_state_title).setVisibility(View.VISIBLE);
|
||||
emptyStateView.findViewById(R.id.resolver_empty_state_subtitle).setVisibility(View.VISIBLE);
|
||||
emptyStateView.findViewById(R.id.resolver_empty_state_button).setVisibility(View.INVISIBLE);
|
||||
emptyStateView.findViewById(R.id.resolver_empty_state_progress).setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
private void showListView(ResolverListAdapter activeListAdapter) {
|
||||
ProfileDescriptor descriptor = getItem(
|
||||
userHandleToPageIndex(activeListAdapter.getUserHandle()));
|
||||
@@ -409,8 +441,14 @@ public abstract class AbstractMultiProfilePagerAdapter extends PagerAdapter {
|
||||
|
||||
protected class ProfileDescriptor {
|
||||
final ViewGroup rootView;
|
||||
private final ViewGroup mEmptyStateView;
|
||||
ProfileDescriptor(ViewGroup rootView) {
|
||||
this.rootView = rootView;
|
||||
mEmptyStateView = rootView.findViewById(R.id.resolver_empty_state);
|
||||
}
|
||||
|
||||
private ViewGroup getEmptyStateView() {
|
||||
return mEmptyStateView;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -756,7 +756,7 @@ public class ResolverActivity extends Activity implements
|
||||
|
||||
private void registerWorkProfileStateReceiver() {
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(Intent.ACTION_MANAGED_PROFILE_AVAILABLE);
|
||||
filter.addAction(Intent.ACTION_USER_UNLOCKED);
|
||||
filter.addAction(Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE);
|
||||
registerReceiverAsUser(mWorkProfileStateReceiver, UserHandle.ALL, filter, null, null);
|
||||
}
|
||||
@@ -1729,6 +1729,14 @@ public class ResolverActivity extends Activity implements
|
||||
@Override // ResolverListCommunicator
|
||||
public void onHandlePackagesChanged(ResolverListAdapter listAdapter) {
|
||||
if (listAdapter == mMultiProfilePagerAdapter.getActiveListAdapter()) {
|
||||
if (listAdapter.getUserHandle() == getWorkProfileUserHandle()
|
||||
&& mMultiProfilePagerAdapter.isWaitingToEnableWorkProfile()) {
|
||||
// We have just turned on the work profile and entered the pass code to start it,
|
||||
// now we are waiting to receive the ACTION_USER_UNLOCKED broadcast. There is no
|
||||
// point in reloading the list now, since the work profile user is still
|
||||
// turning on.
|
||||
return;
|
||||
}
|
||||
boolean listRebuilt = mMultiProfilePagerAdapter.rebuildActiveTab(true);
|
||||
if (listRebuilt) {
|
||||
ResolverListAdapter activeListAdapter =
|
||||
@@ -1749,10 +1757,18 @@ public class ResolverActivity extends Activity implements
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
if (!TextUtils.equals(action, Intent.ACTION_MANAGED_PROFILE_AVAILABLE)
|
||||
if (!TextUtils.equals(action, Intent.ACTION_USER_UNLOCKED)
|
||||
&& !TextUtils.equals(action, Intent.ACTION_MANAGED_PROFILE_UNAVAILABLE)) {
|
||||
return;
|
||||
}
|
||||
int userHandle = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1);
|
||||
if (TextUtils.equals(action, Intent.ACTION_USER_UNLOCKED)
|
||||
&& userHandle != getWorkProfileUserHandle().getIdentifier()) {
|
||||
return;
|
||||
}
|
||||
if (TextUtils.equals(action, Intent.ACTION_USER_UNLOCKED)) {
|
||||
mMultiProfilePagerAdapter.markWorkProfileEnabledBroadcastReceived();
|
||||
}
|
||||
if (mMultiProfilePagerAdapter.getCurrentUserHandle()
|
||||
== getWorkProfileUserHandle()) {
|
||||
mMultiProfilePagerAdapter.rebuildActiveTab(true);
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
~ limitations under the License.
|
||||
-->
|
||||
|
||||
<LinearLayout
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/resolver_empty_state"
|
||||
android:layout_width="match_parent"
|
||||
@@ -28,25 +28,31 @@
|
||||
android:id="@+id/resolver_empty_state_icon"
|
||||
android:layout_marginTop="48dp"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"/>
|
||||
android:layout_height="24dp"
|
||||
android:layout_centerHorizontal="true" />
|
||||
<TextView
|
||||
android:id="@+id/resolver_empty_state_title"
|
||||
android:layout_below="@+id/resolver_empty_state_icon"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:fontFamily="@string/config_headlineFontFamilyMedium"
|
||||
android:textColor="@color/resolver_empty_state_text"
|
||||
android:textSize="14sp"/>
|
||||
android:textSize="18sp"
|
||||
android:layout_centerHorizontal="true" />
|
||||
<TextView
|
||||
android:id="@+id/resolver_empty_state_subtitle"
|
||||
android:layout_below="@+id/resolver_empty_state_title"
|
||||
android:layout_marginTop="4dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@color/resolver_empty_state_text"
|
||||
android:textSize="12sp"
|
||||
android:gravity="center_horizontal" />
|
||||
android:textSize="14sp"
|
||||
android:gravity="center_horizontal"
|
||||
android:layout_centerHorizontal="true" />
|
||||
<Button
|
||||
android:id="@+id/resolver_empty_state_button"
|
||||
android:layout_below="@+id/resolver_empty_state_subtitle"
|
||||
android:layout_marginTop="16dp"
|
||||
android:text="@string/resolver_switch_on_work"
|
||||
android:layout_width="wrap_content"
|
||||
@@ -54,5 +60,16 @@
|
||||
android:background="@null"
|
||||
android:fontFamily="@string/config_headlineFontFamilyMedium"
|
||||
android:textSize="14sp"
|
||||
android:textColor="@color/resolver_tabs_active_color"/>
|
||||
</LinearLayout>
|
||||
android:textColor="@color/resolver_tabs_active_color"
|
||||
android:layout_centerHorizontal="true" />
|
||||
<ProgressBar
|
||||
android:id="@+id/resolver_empty_state_progress"
|
||||
style="@style/Widget.Material.Light.ProgressBar"
|
||||
android:visibility="gone"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:indeterminate="true"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_below="@+id/resolver_empty_state_subtitle"
|
||||
android:indeterminateTint="@color/resolver_tabs_active_color"/>
|
||||
</RelativeLayout>
|
||||
@@ -3879,6 +3879,7 @@
|
||||
<java-symbol type="id" name="resolver_empty_state_title" />
|
||||
<java-symbol type="id" name="resolver_empty_state_subtitle" />
|
||||
<java-symbol type="id" name="resolver_empty_state_button" />
|
||||
<java-symbol type="id" name="resolver_empty_state_progress" />
|
||||
<java-symbol type="id" name="resolver_tab_divider" />
|
||||
<java-symbol type="string" name="resolver_cant_share_with_work_apps" />
|
||||
<java-symbol type="string" name="resolver_cant_share_with_personal_apps" />
|
||||
|
||||
Reference in New Issue
Block a user