Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 201f1f61 authored by Sunny Shao's avatar Sunny Shao Committed by Android (Google) Code Review
Browse files

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

parents 7d1fc0d3 6dc1cc2a
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
<!--
  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.
  -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="32dp"
    android:height="32dp"
    android:viewportWidth="24"
    android:viewportHeight="24">
  <path
      android:fillColor="#ff4285f4"
      android:pathData="M12,2C6.48,2 2,6.48 2,12c0,5.52 4.48,10 10,10c5.52,0 10,-4.48 10,-10C22,6.48 17.52,2 12,2zM7.07,18.28c0.43,-0.9 3.05,-1.78 4.93,-1.78s4.51,0.88 4.93,1.78C15.57,19.36 13.86,20 12,20S8.43,19.36 7.07,18.28zM18.36,16.83c-1.43,-1.74 -4.9,-2.33 -6.36,-2.33s-4.93,0.59 -6.36,2.33C4.62,15.49 4,13.82 4,12c0,-4.41 3.59,-8 8,-8c4.41,0 8,3.59 8,8C20,13.82 19.38,15.49 18.36,16.83z"/>
  <path
      android:fillColor="#ff4285f4"
      android:pathData="M12,6c-1.94,0 -3.5,1.56 -3.5,3.5S10.06,13 12,13c1.94,0 3.5,-1.56 3.5,-3.5S13.94,6 12,6zM12,11c-0.83,0 -1.5,-0.67 -1.5,-1.5C10.5,8.67 11.17,8 12,8c0.83,0 1.5,0.67 1.5,1.5C13.5,10.33 12.83,11 12,11z"/>
</vector>
+7 −0
Original line number Diff line number Diff line
@@ -45,5 +45,12 @@
                android:layout_height="wrap_content"
                android:text="@string/search_menu"/>
        </Toolbar>
        <ImageView
            android:id="@+id/account_avatar"
            android:layout_marginStart="@dimen/search_bar_avatar_start_margin"
            android:layout_marginEnd="@dimen/search_bar_avatar_end_margin"
            android:layout_width="@dimen/search_bar_avatar_size"
            android:layout_height="@dimen/search_bar_avatar_size"
            android:layout_gravity="end|center_vertical"/>
    </androidx.cardview.widget.CardView>
</FrameLayout>
 No newline at end of file
+3 −0
Original line number Diff line number Diff line
@@ -103,6 +103,9 @@
    <dimen name="search_bar_text_size">16dp</dimen>
    <dimen name="search_bar_card_elevation">2dp</dimen>
    <dimen name="search_bar_content_inset">64dp</dimen>
    <dimen name="search_bar_avatar_size">32dp</dimen>
    <dimen name="search_bar_avatar_start_margin">4dp</dimen>
    <dimen name="search_bar_avatar_end_margin">16dp</dimen>

    <!-- Dimensions for Wifi Assistant Card -->
    <dimen name="wifi_assistant_padding_top_bottom">16dp</dimen>
+60 −0
Original line number Diff line number Diff line
/*
 * 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);
    }
}
+6 −0
Original line number Diff line number Diff line
@@ -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);
    }
Loading