Commit 82ef6628 authored by Tina Wang's avatar Tina Wang Committed by Commit Bot

[ProfileCard] Introduce entry point UI component

Added Coordinator, coordinaor implementation, view classes.
Added layout file.

Bug: 1053740
Change-Id: Iabb9370888822f643539cbd6b2e8398f3bcafb7c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2063748
Commit-Queue: Tina Wang <tinazwang@chromium.org>
Reviewed-by: default avatarsebsg <sebsg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#742837}
parent aef3e9a4
...@@ -7,6 +7,7 @@ import("//build/config/android/rules.gni") ...@@ -7,6 +7,7 @@ import("//build/config/android/rules.gni")
android_library("java") { android_library("java") {
sources = [ sources = [
"java/src/org/chromium/chrome/browser/profile_card/ContentPreviewPostData.java", "java/src/org/chromium/chrome/browser/profile_card/ContentPreviewPostData.java",
"java/src/org/chromium/chrome/browser/profile_card/EntryPointCoordinator.java",
"java/src/org/chromium/chrome/browser/profile_card/NavigationDelegate.java", "java/src/org/chromium/chrome/browser/profile_card/NavigationDelegate.java",
"java/src/org/chromium/chrome/browser/profile_card/ProfileCardCoordinator.java", "java/src/org/chromium/chrome/browser/profile_card/ProfileCardCoordinator.java",
"java/src/org/chromium/chrome/browser/profile_card/ProfileCardData.java", "java/src/org/chromium/chrome/browser/profile_card/ProfileCardData.java",
......
...@@ -7,6 +7,8 @@ import("//build/config/android/rules.gni") ...@@ -7,6 +7,8 @@ import("//build/config/android/rules.gni")
android_library("java") { android_library("java") {
sources = [ sources = [
"java/src/org/chromium/chrome/browser/profile_card/ContentPreviewPostView.java", "java/src/org/chromium/chrome/browser/profile_card/ContentPreviewPostView.java",
"java/src/org/chromium/chrome/browser/profile_card/EntryPointCoordinatorImpl.java",
"java/src/org/chromium/chrome/browser/profile_card/EntryPointView.java",
"java/src/org/chromium/chrome/browser/profile_card/ProfileCardCoordinatorImpl.java", "java/src/org/chromium/chrome/browser/profile_card/ProfileCardCoordinatorImpl.java",
"java/src/org/chromium/chrome/browser/profile_card/ProfileCardMediator.java", "java/src/org/chromium/chrome/browser/profile_card/ProfileCardMediator.java",
"java/src/org/chromium/chrome/browser/profile_card/ProfileCardProperties.java", "java/src/org/chromium/chrome/browser/profile_card/ProfileCardProperties.java",
......
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2020 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. -->
<org.chromium.chrome.browser.profile_card.EntryPointView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/entry_point"
android:layout_width="wrap_content"
android:layout_height="match_parent">
<org.chromium.ui.widget.ChromeImageButton
android:id="@+id/entry_point_icon"
style="@style/OmniboxIcon"
android:layout_gravity="center_vertical"
android:src="@android:color/transparent"
android:visibility="gone"
android:contentDescription="@strings/profile_card_entry_point"
android:scaleType="center" />
</org.chromium.chrome.browser.profile_card.EntryPointView>
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.profile_card;
import android.content.Context;
import android.graphics.Bitmap;
import android.view.View;
/**
* Implements EntryPointCoordinator.
* Talks to other components and decides when to show/destroy the profile card entry point.
* Initiates and shows the profile card.
*/
public class EntryPointCoordinatorImpl implements EntryPointCoordinator {
private Bitmap mImageBitmap;
private EntryPointView mView;
private ProfileCardCoordinatorImpl mProfileCardCoordinator;
@Override
public void init(Context context, Bitmap bitmap) {
mView = new EntryPointView(context);
mImageBitmap = bitmap;
mView.setIconBitmap(mImageBitmap);
mView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showProfileCard();
}
});
}
@Override
public void show() {
mView.setVisibility(true);
}
@Override
public void hide() {
mView.setVisibility(false);
}
void showProfileCard() {
mProfileCardCoordinator.init(mView, ProfileCardUtil.getProfileCardData());
mProfileCardCoordinator.show();
}
}
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.profile_card;
import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import org.chromium.chrome.browser.profile_card.internal.R;
/**
* UI component that handles showing a profile card view.
*/
public class EntryPointView extends LinearLayout {
private View mMainContentView;
private ImageButton mImageButton;
public EntryPointView(Context context) {
super(context);
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
mMainContentView =
LayoutInflater.from(getContext()).inflate(R.layout.entry_point, /*root=*/null);
mImageButton = mMainContentView.findViewById(R.id.entry_point_icon);
}
void setIconBitmap(Bitmap iconBitmap) {
mImageButton.setImageBitmap(iconBitmap);
}
void setVisibility(boolean visible) {
if (visible) {
mMainContentView.setVisibility(View.VISIBLE);
} else {
mMainContentView.setVisibility(View.GONE);
}
}
}
...@@ -22,8 +22,7 @@ public class ProfileCardCoordinatorImpl implements ProfileCardCoordinator { ...@@ -22,8 +22,7 @@ public class ProfileCardCoordinatorImpl implements ProfileCardCoordinator {
private ProfileCardData mProfileCardData; private ProfileCardData mProfileCardData;
@Override @Override
public void update(View anchorView, ProfileCardData profileCardData) { public void init(View anchorView, ProfileCardData profileCardData) {
if (mProfileCardData == profileCardData) return;
ViewRectProvider rectProvider = new ViewRectProvider(anchorView); ViewRectProvider rectProvider = new ViewRectProvider(anchorView);
mView = new ProfileCardView(anchorView.getContext()); mView = new ProfileCardView(anchorView.getContext());
mProfileCardData = profileCardData; mProfileCardData = profileCardData;
...@@ -37,4 +36,9 @@ public class ProfileCardCoordinatorImpl implements ProfileCardCoordinator { ...@@ -37,4 +36,9 @@ public class ProfileCardCoordinatorImpl implements ProfileCardCoordinator {
public void show() { public void show() {
mMediator.show(); mMediator.show();
} }
@Override
public void hide() {
mMediator.hide();
}
} }
...@@ -36,4 +36,8 @@ class ProfileCardMediator { ...@@ -36,4 +36,8 @@ class ProfileCardMediator {
public void show() { public void show() {
mModel.set(IS_VISIBLE, true); mModel.set(IS_VISIBLE, true);
} }
public void hide() {
mModel.set(IS_VISIBLE, false);
}
} }
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.profile_card;
import android.content.Context;
import android.graphics.Bitmap;
/** Interface for the Profile Card entry point UI. */
public interface EntryPointCoordinator {
/**
* Initiates the entry point coordinator.
*/
void init(Context context, Bitmap bitmap);
/**
* Shows the profile card entry point.
*/
void show();
/**
* Hides the profile card entry point.
*/
void hide();
}
...@@ -9,14 +9,19 @@ import android.view.View; ...@@ -9,14 +9,19 @@ import android.view.View;
/** Interface for the Profile Card related UI. */ /** Interface for the Profile Card related UI. */
public interface ProfileCardCoordinator { public interface ProfileCardCoordinator {
/** /**
* Updates the {@link ProfileCard} * Initiates the profile card coordinator.
* @param view {@link View} triggers the profile card. * @param view {@link View} triggers the profile card.
* @param profileCardData {@link ProfileCardData} stores all data needed by profile card. * @param profileCardData {@link ProfileCardData} stores all data needed by profile card.
*/ */
void update(View view, ProfileCardData profileCardData); void init(View view, ProfileCardData profileCardData);
/** /**
* Shows the profile card drop-down bubble. * Shows the profile card.
*/ */
void show(); void show();
/**
* Hides the profile card.
*/
void hide();
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment