Merge "Added the icon displayed on no account in search bar"

This commit is contained in:
Sunny Shao
2018-11-05 05:31:03 +00:00
committed by Android (Google) Code Review
6 changed files with 197 additions and 0 deletions

View File

@@ -0,0 +1,60 @@
/*
* Copyright (C) 2018 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.accounts;
import android.accounts.Account;
import android.content.Context;
import android.widget.ImageView;
import androidx.annotation.VisibleForTesting;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.OnLifecycleEvent;
import com.android.settings.R;
import com.android.settings.homepage.SettingsHomepageActivity;
import com.android.settings.overlay.FeatureFactory;
/**
* Avatar related work to the onStart method of registered observable classes
* in {@link SettingsHomepageActivity}.
*/
public class AvatarViewMixin implements LifecycleObserver {
private Context mContext;
private ImageView mAvatarView;
public AvatarViewMixin(Context context, ImageView avatarView) {
mContext = context.getApplicationContext();
mAvatarView = avatarView;
}
@OnLifecycleEvent(Lifecycle.Event.ON_START)
public void onStart() {
if (hasAccount()) {
//TODO(b/117509285): To migrate account icon on search bar
} else {
mAvatarView.setImageResource(R.drawable.ic_account_circle_24dp);
}
}
@VisibleForTesting
boolean hasAccount() {
final Account accounts[] = FeatureFactory.getFactory(
mContext).getAccountFeatureProvider().getAccounts(mContext);
return (accounts != null) && (accounts.length > 0);
}
}

View File

@@ -19,6 +19,7 @@ package com.android.settings.homepage;
import android.content.Intent;
import android.os.Bundle;
import android.util.FeatureFlagUtils;
import android.widget.ImageView;
import android.widget.Toolbar;
import androidx.fragment.app.Fragment;
@@ -27,6 +28,7 @@ import androidx.fragment.app.FragmentTransaction;
import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settings.accounts.AvatarViewMixin;
import com.android.settings.core.FeatureFlags;
import com.android.settings.core.SettingsBaseActivity;
import com.android.settings.homepage.contextualcards.ContextualCardsFragment;
@@ -51,6 +53,10 @@ public class SettingsHomepageActivity extends SettingsBaseActivity {
FeatureFactory.getFactory(this).getSearchFeatureProvider()
.initSearchToolbar(this, toolbar);
final ImageView avatarView = findViewById(R.id.account_avatar);
final AvatarViewMixin avatarViewMixin = new AvatarViewMixin(this, avatarView);
getLifecycle().addObserver(avatarViewMixin);
showFragment(new ContextualCardsFragment(), R.id.contextual_cards_content);
showFragment(new TopLevelSettings(), R.id.main_content);
}