2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-03 23:15:31 +00:00

[fenix] For https://github.com/mozilla-mobile/fenix/issues/7387: Change ETP onboarding from popup to a dialog.

Recalculated dialog position and offsets.
Changed ETP onboarding dialog to show only once.
This commit is contained in:
mcarare 2020-04-22 18:32:26 +03:00 committed by Emily Kager
parent 5aa32ad79a
commit 8310691f2d
4 changed files with 36 additions and 35 deletions

View File

@ -4,17 +4,17 @@
package org.mozilla.fenix.trackingprotection package org.mozilla.fenix.trackingprotection
import android.app.Dialog
import android.content.Context import android.content.Context
import android.graphics.Color import android.graphics.Color
import android.graphics.drawable.ColorDrawable import android.graphics.drawable.ColorDrawable
import android.view.Gravity
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.View.MeasureSpec
import android.view.WindowManager
import android.widget.ImageView import android.widget.ImageView
import android.widget.PopupWindow
import androidx.core.view.isGone import androidx.core.view.isGone
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.core.view.marginTop
import kotlinx.android.synthetic.main.tracking_protection_onboarding_popup.view.* import kotlinx.android.synthetic.main.tracking_protection_onboarding_popup.view.*
import mozilla.components.browser.session.Session import mozilla.components.browser.session.Session
import org.mozilla.fenix.R import org.mozilla.fenix.R
@ -44,63 +44,63 @@ class TrackingProtectionOverlay(
@Suppress("MagicNumber", "InflateParams") @Suppress("MagicNumber", "InflateParams")
private fun showTrackingProtectionOnboarding() { private fun showTrackingProtectionOnboarding() {
val trackingOnboardingDialog = Dialog(context)
val layout = LayoutInflater.from(context) val layout = LayoutInflater.from(context)
.inflate(R.layout.tracking_protection_onboarding_popup, null) .inflate(R.layout.tracking_protection_onboarding_popup, null)
val isBottomToolbar = Settings.getInstance(context).shouldUseBottomToolbar val isBottomToolbar = Settings.getInstance(context).shouldUseBottomToolbar
layout.drop_down_triangle.isGone = isBottomToolbar layout.drop_down_triangle.isGone = isBottomToolbar
layout.pop_up_triangle.isVisible = isBottomToolbar layout.pop_up_triangle.isVisible = isBottomToolbar
layout.onboarding_message.text = layout.onboarding_message.text =
context.getString( context.getString(
R.string.etp_onboarding_message_2, R.string.etp_onboarding_message_2,
context.getString(R.string.app_name) context.getString(R.string.app_name)
) )
val res = context.resources
val trackingOnboarding = PopupWindow(
layout,
res.getDimensionPixelSize(R.dimen.tp_onboarding_width),
WindowManager.LayoutParams.WRAP_CONTENT
).apply {
setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
isOutsideTouchable = true
isFocusable = true
elevation = res.getDimension(R.dimen.mozac_browser_menu_elevation)
animationStyle = R.style.Mozac_Browser_Menu_Animation_OverflowMenuBottom
}
val closeButton = layout.findViewById<ImageView>(R.id.close_onboarding) val closeButton = layout.findViewById<ImageView>(R.id.close_onboarding)
closeButton.increaseTapArea(BUTTON_INCREASE_DPS) closeButton.increaseTapArea(BUTTON_INCREASE_DPS)
closeButton.setOnClickListener { closeButton.setOnClickListener {
trackingOnboarding.dismiss() trackingOnboardingDialog.dismiss()
} }
// Measure layout view val res = context.resources
val spec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED) val triangleWidthPx = res.getDimension(R.dimen.tp_onboarding_triangle_height)
layout.measure(spec, spec) val triangleMarginStartPx = res.getDimension(R.dimen.tp_onboarding_triangle_margin_start)
val containerHeight = layout.measuredHeight
val triangleHeight =
(res.getDimension(R.dimen.tp_onboarding_triangle_height) / res.displayMetrics.density).toInt()
val toolbar = getToolbar() val toolbar = getToolbar()
val trackingProtectionIcon: View = val trackingProtectionIcon: View =
toolbar.findViewById(R.id.mozac_browser_toolbar_tracking_protection_indicator) toolbar.findViewById(R.id.mozac_browser_toolbar_tracking_protection_indicator)
val xOffset = res.getDimensionPixelSize(R.dimen.tp_onboarding_x_offset) val xOffset = triangleMarginStartPx + triangleWidthPx / 2
// Positioning the popup above the tp anchor. val gravity = if (isBottomToolbar) {
val yOffset = if (isBottomToolbar) { Gravity.START or Gravity.BOTTOM
-containerHeight - (toolbar.height / 3 * 2) + triangleHeight
} else { } else {
CFR_Y_OFFSET Gravity.START or Gravity.TOP
} }
trackingOnboarding.showAsDropDown(trackingProtectionIcon, xOffset, yOffset) trackingOnboardingDialog.apply {
setContentView(layout)
setCancelable(false)
}
trackingOnboardingDialog.window?.let {
it.setGravity(gravity)
val attr = it.attributes
attr.x =
(trackingProtectionIcon.x + trackingProtectionIcon.width / 2 - xOffset).toInt()
attr.y =
(trackingProtectionIcon.y + trackingProtectionIcon.height - trackingProtectionIcon.marginTop).toInt()
it.attributes = attr
it.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
}
trackingOnboardingDialog.show()
settings.incrementTrackingProtectionOnboardingCount() settings.incrementTrackingProtectionOnboardingCount()
} }
private companion object { private companion object {
private const val CFR_Y_OFFSET = -24
private const val BUTTON_INCREASE_DPS = 12 private const val BUTTON_INCREASE_DPS = 12
} }
} }

View File

@ -46,7 +46,7 @@ class Settings private constructor(
companion object { companion object {
const val showLoginsSecureWarningSyncMaxCount = 1 const val showLoginsSecureWarningSyncMaxCount = 1
const val showLoginsSecureWarningMaxCount = 1 const val showLoginsSecureWarningMaxCount = 1
const val trackingProtectionOnboardingMaximumCount = 2 const val trackingProtectionOnboardingMaximumCount = 1
const val FENIX_PREFERENCES = "fenix_preferences" const val FENIX_PREFERENCES = "fenix_preferences"
private const val BLOCKED_INT = 0 private const val BLOCKED_INT = 0

View File

@ -11,9 +11,9 @@
<ImageView <ImageView
android:visibility="gone" android:visibility="gone"
android:id="@+id/drop_down_triangle" android:id="@+id/drop_down_triangle"
android:layout_width="16dp" android:layout_width="@dimen/tp_onboarding_triangle_width"
android:layout_height="@dimen/tp_onboarding_triangle_height" android:layout_height="@dimen/tp_onboarding_triangle_height"
android:layout_marginStart="16dp" android:layout_marginStart="@dimen/tp_onboarding_triangle_margin_start"
android:importantForAccessibility="no" android:importantForAccessibility="no"
android:rotation="0" android:rotation="0"
app:srcCompat="@drawable/ic_triangle" app:srcCompat="@drawable/ic_triangle"

View File

@ -39,8 +39,9 @@
<dimen name="context_menu_height">48dp</dimen> <dimen name="context_menu_height">48dp</dimen>
<dimen name="context_menu_x_offset">8dp</dimen> <dimen name="context_menu_x_offset">8dp</dimen>
<dimen name="tp_onboarding_width">256dp</dimen> <dimen name="tp_onboarding_width">256dp</dimen>
<dimen name="tp_onboarding_x_offset">-4dp</dimen>
<dimen name="tp_onboarding_triangle_height">16dp</dimen> <dimen name="tp_onboarding_triangle_height">16dp</dimen>
<dimen name="tp_onboarding_triangle_width">16dp</dimen>
<dimen name="tp_onboarding_triangle_margin_start">16dp</dimen>
<dimen name="tab_counter_box_width_height">24dp</dimen> <dimen name="tab_counter_box_width_height">24dp</dimen>