Add tootltip for shields

This commit is contained in:
Deep
2020-06-30 17:32:29 -04:00
parent e8a43f1b8a
commit 1ca46aed43
5 changed files with 109 additions and 29 deletions
+2
View File
@@ -63,6 +63,7 @@ brave_java_resources = [
"java/res/drawable/image_credit_rounded_shape.xml",
"java/res/drawable/rect_up_round_corners_12.xml",
"java/res/drawable/enable_rewards_button.xml",
"java/res/drawable/shields_tooltip_background.xml",
"java/res/drawable-hdpi/check.png",
"java/res/drawable-hdpi/btn_bookmark.png",
"java/res/drawable-hdpi/arrow_forward.png",
@@ -664,6 +665,7 @@ brave_java_resources = [
"java/res/layout/brave_shields_main_layout.xml",
"java/res/layout/fragment_brave_rewards_onboarding.xml",
"java/res/layout/brave_shields_toggle_layout.xml",
"java/res/layout/brave_shields_tooltip_layout.xml",
"java/res/layout/new_tab_page_layout.xml",
"java/res/layout/fragment_rate_dialog.xml",
"java/res/layout/brave_ads_new_user_dialog_layout.xml",
@@ -194,7 +194,12 @@ public class BraveShieldsHandler implements BraveRewardsHelper.LargeIconReadyCal
mBraveRewardsNativeWorker = BraveRewardsNativeWorker.getInstance();
mIconFetcher = new BraveRewardsHelper();
showPopupMenu(anchorView, false);
updateValues(mTabId);
}
public PopupWindow showPopupMenu(View anchorView, boolean isTooltip) {
int rotation = ((Activity)mContext).getWindowManager().getDefaultDisplay().getRotation();
// This fixes the bug where the bottom of the menu starts at the top of
// the keyboard, instead of overlapping the keyboard as it should.
@@ -239,9 +244,13 @@ public class BraveShieldsHandler implements BraveRewardsHelper.LargeIconReadyCal
}
LayoutInflater inflater = (LayoutInflater) anchorView.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mPopupView = inflater.inflate(R.layout.brave_shields_main_layout, null);
setUpViews();
if (! isTooltip) {
mPopupView = inflater.inflate(R.layout.brave_shields_main_layout, null);
setUpViews();
} else {
mPopupView = inflater.inflate(R.layout.brave_shields_tooltip_layout, null);
}
//Specify the length and width through constants
int width = LinearLayout.LayoutParams.WRAP_CONTENT;
@@ -251,32 +260,32 @@ public class BraveShieldsHandler implements BraveRewardsHelper.LargeIconReadyCal
boolean focusable = true;
//Create a window with our parameters
mPopupWindow = new PopupWindow(mPopupView, width, height, focusable);
mPopupWindow.setBackgroundDrawable(new ColorDrawable(Color.WHITE));
PopupWindow popupWindow = new PopupWindow(mPopupView, width, height, focusable);
popupWindow.setBackgroundDrawable(new ColorDrawable(Color.WHITE));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
mPopupWindow.setElevation(20);
popupWindow.setElevation(20);
}
// mPopup.setBackgroundDrawable(mContext.getResources().getDrawable(android.R.drawable.picture_frame));
//Set the location of the window on the screen
mPopupWindow.showAsDropDown(anchorView, 0, 0);
mPopupWindow.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED);
mPopupWindow.setAnimationStyle(R.style.OverflowMenuAnim);
popupWindow.showAsDropDown(anchorView, 0, 0);
popupWindow.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED);
popupWindow.setAnimationStyle(R.style.OverflowMenuAnim);
// Turn off window animations for low end devices, and on Android M, which has built-in menu
// animations.
if (SysUtils.isLowEndDevice() || Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
mPopupWindow.setAnimationStyle(0);
popupWindow.setAnimationStyle(0);
}
Rect bgPadding = new Rect();
mPopupWindow.getBackground().getPadding(bgPadding);
popupWindow.getBackground().getPadding(bgPadding);
int popupWidth = wrapper.getResources().getDimensionPixelSize(R.dimen.menu_width)
+ bgPadding.left + bgPadding.right;
mPopupWindow.setWidth(popupWidth);
popupWindow.setWidth(popupWidth);
updateValues(mTabId);
return popupWindow;
}
public void updateHost(String host) {
@@ -21,6 +21,7 @@ import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.PopupWindow;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.ContextUtils;
@@ -238,6 +239,14 @@ public abstract class BraveToolbarLayout extends ToolbarLayout implements OnClic
if (getToolbarDataProvider().getTab() == tab) {
mBraveShieldsHandler.updateHost(url);
updateBraveShieldsButtonState(tab);
PopupWindow mPopupWindow = mBraveShieldsHandler.showPopupMenu(mBraveShieldsButton, true);
mPopupWindow.getContentView().setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mPopupWindow.dismiss();
showShieldsMenu(mBraveShieldsButton);
}
});
}
}
@@ -274,23 +283,7 @@ public abstract class BraveToolbarLayout extends ToolbarLayout implements OnClic
return;
}
if (mBraveShieldsButton == v && mBraveShieldsButton != null) {
Tab currentTab = getToolbarDataProvider().getTab();
if (currentTab == null) {
return;
}
try {
URL url = new URL(currentTab.getUrlString());
// Don't show shields popup if protocol is not valid for shields.
if (!isValidProtocolForShields(url.getProtocol())) {
return;
}
mBraveShieldsHandler.show(mBraveShieldsButton, currentTab.getUrlString(),
url.getHost(), currentTab.getId(), Profile.fromWebContents(((TabImpl)currentTab).getWebContents()));
} catch (Exception e) {
// Do nothing if url is invalid.
// Just return w/o showing shields popup.
return;
}
showShieldsMenu(mBraveShieldsButton);
} else if (mBraveRewardsButton == v && mBraveRewardsButton != null) {
Context context = getContext();
if ((PackageUtils.isFirstInstall(context)
@@ -315,6 +308,26 @@ public abstract class BraveToolbarLayout extends ToolbarLayout implements OnClic
}
}
private void showShieldsMenu(View mBraveShieldsButton) {
Tab currentTab = getToolbarDataProvider().getTab();
if (currentTab == null) {
return;
}
try {
URL url = new URL(currentTab.getUrlString());
// Don't show shields popup if protocol is not valid for shields.
if (!isValidProtocolForShields(url.getProtocol())) {
return;
}
mBraveShieldsHandler.show(mBraveShieldsButton, currentTab.getUrlString(),
url.getHost(), currentTab.getId(), Profile.fromWebContents(((TabImpl)currentTab).getWebContents()));
} catch (Exception e) {
// Do nothing if url is invalid.
// Just return w/o showing shields popup.
return;
}
}
@Override
public boolean onLongClick(View v) {
// Use null as the default description since Toast.showAnchoredToast
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<shape>
<gradient
android:angle="315"
android:startColor="#F73A1C"
android:endColor="#BF14A2"
android:type="linear" />
</shape>
</item>
</layer-list>
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2020 The Brave Authors. All rights reserved.
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this file,
You can obtain one at http://mozilla.org/MPL/2.0/. -->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_layout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="24dp"
android:background="@drawable/shields_tooltip_background">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:singleLine="true"
android:ellipsize="end"
android:fontFamily="sans-serif"
android:layout_marginBottom="8dp"
android:text="Nice!"
android:textColor="@android:color/white"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:fontFamily="sans-serif"
android:layout_marginBottom="16dp"
android:text="You just blocked some trackers &amp; ads."
android:textColor="@android:color/white"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:fontFamily="sans-serif"
android:text="Take a look"
android:textColor="@android:color/white"/>
</LinearLayout>