diff --git a/mobile/android/focus-android/app/src/main/java/org/mozilla/focus/browser/BrowserMenuControllerAdapter.kt b/mobile/android/focus-android/app/src/main/java/org/mozilla/focus/browser/BrowserMenuControllerAdapter.kt deleted file mode 100644 index fe153472a22a..000000000000 --- a/mobile/android/focus-android/app/src/main/java/org/mozilla/focus/browser/BrowserMenuControllerAdapter.kt +++ /dev/null @@ -1,39 +0,0 @@ -/* 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/. */ - -package org.mozilla.focus.browser - -import android.view.View -import android.widget.PopupWindow -import mozilla.components.concept.menu.MenuController -import mozilla.components.concept.menu.Orientation -import mozilla.components.concept.menu.candidate.MenuCandidate -import mozilla.components.support.base.observer.Observable -import mozilla.components.support.base.observer.ObserverRegistry -import org.mozilla.focus.ext.ifCustomTab -import org.mozilla.focus.fragment.BrowserFragment -import org.mozilla.focus.menu.browser.BrowserMenu - -/** - * This adapter bridges between `browser-toolbar` and the custom, legacy [BrowserMenu] in Focus. - * It allows launching [BrowserMenu] from `BrowserToolbar`. - */ -class BrowserMenuControllerAdapter( - private val fragment: BrowserFragment -) : MenuController, Observable by ObserverRegistry() { - override fun dismiss() { - // Not used. - } - - override fun show(anchor: View, orientation: Orientation?): PopupWindow { - val menu = BrowserMenu(fragment.requireContext(), fragment, fragment.tab.ifCustomTab()?.config) - menu.show(anchor) - - return menu - } - - override fun submitList(list: List) { - // Not used. - } -} diff --git a/mobile/android/focus-android/app/src/main/java/org/mozilla/focus/browser/integration/NavigationButtonsIntegration.kt b/mobile/android/focus-android/app/src/main/java/org/mozilla/focus/browser/integration/NavigationButtonsIntegration.kt index 5adc18b490d1..2158a7b39609 100644 --- a/mobile/android/focus-android/app/src/main/java/org/mozilla/focus/browser/integration/NavigationButtonsIntegration.kt +++ b/mobile/android/focus-android/app/src/main/java/org/mozilla/focus/browser/integration/NavigationButtonsIntegration.kt @@ -34,7 +34,7 @@ class NavigationButtonsIntegration( init { toolbar.addNavigationAction( NavigationButton( - image = ContextCompat.getDrawable(context, R.drawable.ic_back)!!, + image = ContextCompat.getDrawable(context, R.drawable.mozac_ic_back)!!, contentDescription = context.getString(R.string.content_description_back), isEnabled = { store.state.findCustomTabOrSelectedTab(customTabId)?.content?.canGoBack ?: false }, listener = { sessionUseCases.goBack(store.state.findCustomTabOrSelectedTab(customTabId)?.id) } @@ -43,7 +43,7 @@ class NavigationButtonsIntegration( toolbar.addNavigationAction( NavigationButton( - image = ContextCompat.getDrawable(context, R.drawable.ic_forward)!!, + image = ContextCompat.getDrawable(context, R.drawable.mozac_ic_forward)!!, contentDescription = context.getString(R.string.content_description_forward), isEnabled = { store.state.findCustomTabOrSelectedTab(customTabId)?.content?.canGoForward ?: false }, listener = { sessionUseCases.goForward(store.state.findCustomTabOrSelectedTab(customTabId)?.id) } @@ -52,8 +52,8 @@ class NavigationButtonsIntegration( toolbar.addNavigationAction( RefreshStopButton( - refreshImage = ContextCompat.getDrawable(context, R.drawable.ic_refresh)!!, - stopImage = ContextCompat.getDrawable(context, R.drawable.ic_stop)!!, + refreshImage = ContextCompat.getDrawable(context, R.drawable.mozac_ic_refresh)!!, + stopImage = ContextCompat.getDrawable(context, R.drawable.mozac_ic_stop)!!, refreshContentDescription = context.getString(R.string.content_description_reload), stopContentDescription = context.getString(R.string.content_description_stop), isLoading = { store.state.findCustomTabOrSelectedTab(customTabId)?.content?.loading ?: false }, diff --git a/mobile/android/focus-android/app/src/main/java/org/mozilla/focus/menu/browser/BlockingItemViewHolder.kt b/mobile/android/focus-android/app/src/main/java/org/mozilla/focus/menu/browser/BlockingItemViewHolder.kt deleted file mode 100644 index 1a6082996029..000000000000 --- a/mobile/android/focus-android/app/src/main/java/org/mozilla/focus/menu/browser/BlockingItemViewHolder.kt +++ /dev/null @@ -1,103 +0,0 @@ -/* 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/. */ - -package org.mozilla.focus.menu.browser - -import android.view.View -import android.widget.CompoundButton -import android.widget.Switch -import android.widget.TextView -import androidx.lifecycle.coroutineScope -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.launch -import mozilla.components.browser.state.selector.findTabOrCustomTabOrSelectedTab -import mozilla.components.support.ktx.kotlin.tryGetHostFromUrl -import mozilla.components.support.utils.ThreadUtils -import org.mozilla.focus.R -import org.mozilla.focus.exceptions.ExceptionDomains -import org.mozilla.focus.ext.components -import org.mozilla.focus.fragment.BrowserFragment -import org.mozilla.focus.telemetry.TelemetryWrapper - -private const val THUMB_ANIMATION_DURATION = 250L - -internal class BlockingItemViewHolder( - itemView: View, - private val fragment: BrowserFragment -) : BrowserMenuViewHolder(itemView), CompoundButton.OnCheckedChangeListener { - private val trackerCounter: TextView - - init { - val switchView = itemView.findViewById(R.id.blocking_switch) - - switchView.isChecked = fragment.requireContext().components.store.state.findTabOrCustomTabOrSelectedTab( - fragment.tab.id - )!!.trackingProtection.ignoredOnTrackingProtection.not() - - switchView.setOnCheckedChangeListener(this) - - val helpView = itemView.findViewById(R.id.help_trackers) - helpView.setOnClickListener(this) - - trackerCounter = itemView.findViewById(R.id.trackers_count) - - updateTrackers(fragment.tab.trackingProtection.blockedTrackers.size) - } - - fun updateTrackers(trackers: Int) { - if (!fragment.tab.trackingProtection.ignoredOnTrackingProtection) { - updateTrackingCount(trackerCounter, trackers) - } else { - disableTrackingCount(trackerCounter) - } - } - - private fun updateTrackingCount(view: TextView, count: Int) { - ThreadUtils.postToMainThread(Runnable { view.text = count.toString() }) - } - - private fun disableTrackingCount(view: TextView) { - ThreadUtils.postToMainThread(Runnable { view.setText(R.string.content_blocking_disabled) }) - } - - override fun onCheckedChanged(buttonView: CompoundButton, isChecked: Boolean) { - TelemetryWrapper.blockingSwitchEvent(isChecked) - - // Delay closing the menu and reloading the website a bit so that the user can actually see - // the switch change its state. - ThreadUtils.postToMainThreadDelayed( - Runnable { - menu.dismiss() - - buttonView.context.components.apply { - if (isChecked) { - trackingProtectionUseCases.removeException(fragment.tab.id) - } else { - trackingProtectionUseCases.addException(fragment.tab.id) - } - updateExceptionsLocalList(isChecked) - sessionUseCases.reload(fragment.tab.id) - } - }, - THUMB_ANIMATION_DURATION - ) - } - - private fun updateExceptionsLocalList(isChecked: Boolean) { - fragment.lifecycle.coroutineScope.launch(Dispatchers.IO) { - val domain = fragment.tab.content.url.tryGetHostFromUrl() - fragment.context?.let { - if (isChecked) { - ExceptionDomains.remove(it, listOf(domain)) - } else { - ExceptionDomains.add(it, domain) - } - } - } - } - - companion object { - const val LAYOUT_ID = R.layout.menu_blocking_switch - } -} diff --git a/mobile/android/focus-android/app/src/main/java/org/mozilla/focus/menu/browser/BrowserMenu.kt b/mobile/android/focus-android/app/src/main/java/org/mozilla/focus/menu/browser/BrowserMenu.kt deleted file mode 100644 index d794a6541cb4..000000000000 --- a/mobile/android/focus-android/app/src/main/java/org/mozilla/focus/menu/browser/BrowserMenu.kt +++ /dev/null @@ -1,73 +0,0 @@ -/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*- - * 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/. */ -package org.mozilla.focus.menu.browser - -import android.annotation.SuppressLint -import android.content.Context -import android.graphics.Color -import android.graphics.drawable.ColorDrawable -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import android.widget.PopupWindow -import android.widget.TextView -import androidx.recyclerview.widget.LinearLayoutManager -import androidx.recyclerview.widget.RecyclerView -import mozilla.components.browser.state.state.CustomTabConfig -import org.mozilla.focus.R -import org.mozilla.focus.fragment.BrowserFragment -import org.mozilla.focus.utils.ViewUtils.isRTL - -/** - * The overflow menu shown in the BrowserFragment containing page actions like "Refresh", "Share" etc. - */ -class BrowserMenu( - context: Context, - fragment: BrowserFragment, - customTabConfig: CustomTabConfig? -) : PopupWindow() { - private val adapter: BrowserMenuAdapter - - init { - @SuppressLint("InflateParams") // This View will have it's params ignored anyway: - val view = LayoutInflater.from(context).inflate(R.layout.menu, null) - - contentView = view - adapter = BrowserMenuAdapter(context, this, fragment, customTabConfig) - - val menuList: RecyclerView = view.findViewById(R.id.list) - menuList.layoutManager = LinearLayoutManager(context, RecyclerView.VERTICAL, false) - menuList.adapter = adapter - - if (customTabConfig != null) { - val brandingView = view.findViewById(R.id.branding) - brandingView.text = context.getString( - R.string.menu_custom_tab_branding, - context.getString(R.string.app_name) - ) - brandingView.visibility = View.VISIBLE - } - - setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT)) - - isFocusable = true - height = ViewGroup.LayoutParams.WRAP_CONTENT - width = ViewGroup.LayoutParams.WRAP_CONTENT - elevation = context.resources.getDimension(R.dimen.menu_elevation) - } - - fun updateTrackers(trackers: Int) { - adapter.updateTrackers(trackers) - } - - fun updateLoading(loading: Boolean) { - adapter.updateLoading(loading) - } - - fun show(anchor: View) { - val xOffset = if (isRTL(anchor)) -anchor.width else 0 - super.showAsDropDown(anchor, xOffset, -(anchor.height + anchor.paddingBottom)) - } -} diff --git a/mobile/android/focus-android/app/src/main/java/org/mozilla/focus/menu/browser/BrowserMenuAdapter.kt b/mobile/android/focus-android/app/src/main/java/org/mozilla/focus/menu/browser/BrowserMenuAdapter.kt deleted file mode 100644 index f044997e397c..000000000000 --- a/mobile/android/focus-android/app/src/main/java/org/mozilla/focus/menu/browser/BrowserMenuAdapter.kt +++ /dev/null @@ -1,226 +0,0 @@ -/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*- - * 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/. */ - -package org.mozilla.focus.menu.browser - -import android.app.PendingIntent -import android.content.Context -import android.view.LayoutInflater -import android.view.ViewGroup -import androidx.recyclerview.widget.RecyclerView -import mozilla.components.browser.state.state.CustomTabConfig -import org.mozilla.focus.R -import org.mozilla.focus.fragment.BrowserFragment -import org.mozilla.focus.utils.Browsers -import org.mozilla.focus.utils.HardwareUtils -import java.lang.ref.WeakReference - -class BrowserMenuAdapter( - private val context: Context, - private val menu: BrowserMenu, - private val fragment: BrowserFragment, - customTabConfig: CustomTabConfig? -) : RecyclerView.Adapter() { - sealed class MenuItem { - open val viewType = 0 - - open class Default(val id: Int, val label: String, val drawableResId: Int) : MenuItem() { - override val viewType = MenuItemViewHolder.LAYOUT_ID - } - - class Custom( - id: Int, - label: String, - drawableResId: Int, - val pendingIntent: PendingIntent - ) : Default(id, label, drawableResId) { - override val viewType = CustomTabMenuItemViewHolder.LAYOUT_ID - } - - object Navigation : MenuItem() { - override val viewType = NavigationItemViewHolder.LAYOUT_ID - } - - object BlockingSwitch : MenuItem() { - override val viewType = BlockingItemViewHolder.LAYOUT_ID - } - - object RequestDesktopCheck : MenuItem() { - override val viewType = RequestDesktopCheckItemViewHolder.LAYOUT_ID - } - } - - private var items = mutableListOf() - private var navigationItemViewHolderReference = WeakReference(null) - private var blockingItemViewHolderReference = WeakReference(null) - - init { - initializeMenu(fragment.tab.content.url, customTabConfig) - } - - private fun initializeMenu(url: String, customTabConfig: CustomTabConfig?) { - val resources = context.resources - val browsers = Browsers(context, url) - - if (shouldShowButtonToolbar()) { - items.add(MenuItem.Navigation) - } - - items.add(MenuItem.BlockingSwitch) - - if (customTabConfig == null || customTabConfig.showShareMenuItem) { - items.add( - MenuItem.Default( - R.id.share, resources.getString(R.string.menu_share), - R.drawable.ic_share - ) - ) - } - - items.add( - MenuItem.Default( - R.id.add_to_homescreen, - resources.getString(R.string.menu_add_to_home_screen), - R.drawable.ic_home - ) - ) - items.add( - MenuItem.Default( - R.id.find_in_page, - resources.getString(R.string.find_in_page), - R.drawable.ic_search - ) - ) - - if (browsers.hasMultipleThirdPartyBrowsers(context)) { - items.add( - MenuItem.Default( - R.id.open_select_browser, - resources.getString( - R.string.menu_open_with_a_browser2 - ), - R.drawable.ic_open_in - ) - ) - } - - if (customTabConfig != null) { - // "Open in Firefox Focus" to switch from a custom tab to the full-featured browser - val appName = resources.getString(R.string.app_name) - val label = resources.getString(R.string.menu_open_with_default_browser2, appName) - val menuItem = MenuItem.Default(R.id.open_in_firefox_focus, label, 0) - - items.add(menuItem) - } - - if (browsers.hasThirdPartyDefaultBrowser(context)) { - items.add( - MenuItem.Default( - R.id.open_default, - resources.getString( - R.string.menu_open_with_default_browser2, - browsers.defaultBrowser!!.loadLabel( - context.packageManager - ) - ), - 0 - ) - ) - } - - items.add(MenuItem.RequestDesktopCheck) - - if (customTabConfig == null) { - // There’s no need for Settings in a custom tab. - // The user can go to the browser app itself in order to do this. - items.add( - MenuItem.Default( - R.id.settings, resources.getString(R.string.menu_settings), - R.drawable.ic_settings2 - ) - ) - } - - // "Report Site Issue" is available for builds using GeckoView only - items.add( - MenuItem.Default( - R.id.report_site_issue, - resources.getString(R.string.menu_report_site_issue), - 0 - ) - ) - - if (customTabConfig != null) { - val customTabItems = customTabConfig.menuItems - .map { MenuItem.Custom(R.id.custom_tab_menu_item, it.name, 0, it.pendingIntent) } - items.addAll(customTabItems) - } - } - - fun updateTrackers(trackers: Int) { - val navigationItemViewHolder = blockingItemViewHolderReference.get() ?: return - navigationItemViewHolder.updateTrackers(trackers) - } - - fun updateLoading(loading: Boolean) { - val navigationItemViewHolder = navigationItemViewHolderReference.get() ?: return - navigationItemViewHolder.updateLoading(loading) - } - - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BrowserMenuViewHolder { - val inflater = LayoutInflater.from(parent.context) - - return when (viewType) { - NavigationItemViewHolder.LAYOUT_ID -> { - val navigationItemViewHolder = NavigationItemViewHolder( - inflater.inflate(R.layout.menu_navigation, parent, false), fragment - ) - navigationItemViewHolderReference = WeakReference(navigationItemViewHolder) - navigationItemViewHolder - } - BlockingItemViewHolder.LAYOUT_ID -> { - val blockingItemViewHolder = BlockingItemViewHolder( - inflater.inflate(R.layout.menu_blocking_switch, parent, false), fragment - ) - blockingItemViewHolderReference = WeakReference(blockingItemViewHolder) - blockingItemViewHolder - } - RequestDesktopCheckItemViewHolder.LAYOUT_ID -> { - RequestDesktopCheckItemViewHolder( - inflater.inflate(R.layout.request_desktop_check_menu_item, parent, false), - fragment - ) - } - MenuItemViewHolder.LAYOUT_ID -> MenuItemViewHolder( - inflater.inflate( - R.layout.menu_item, - parent, - false - ) - ) - CustomTabMenuItemViewHolder.LAYOUT_ID -> CustomTabMenuItemViewHolder( - inflater.inflate(R.layout.custom_tab_menu_item, parent, false) - ) - else -> throw IllegalArgumentException("Unknown view type: $viewType") - } - } - - override fun onBindViewHolder(holder: BrowserMenuViewHolder, position: Int) { - holder.menu = menu - holder.setOnClickListener(fragment) - - val item = items[position] - when (item) { - is MenuItem.Custom -> (holder as CustomTabMenuItemViewHolder).bind(item) - is MenuItem.Default -> (holder as MenuItemViewHolder).bind(item) - } - } - - override fun getItemViewType(position: Int): Int = items[position].viewType - override fun getItemCount(): Int = items.size - - // On phones we show an extra row with toolbar items (forward/refresh) - private fun shouldShowButtonToolbar(): Boolean = !HardwareUtils.isTablet(context) -} diff --git a/mobile/android/focus-android/app/src/main/java/org/mozilla/focus/menu/browser/BrowserMenuViewHolder.java b/mobile/android/focus-android/app/src/main/java/org/mozilla/focus/menu/browser/BrowserMenuViewHolder.java deleted file mode 100644 index 21cac4ed4e6a..000000000000 --- a/mobile/android/focus-android/app/src/main/java/org/mozilla/focus/menu/browser/BrowserMenuViewHolder.java +++ /dev/null @@ -1,43 +0,0 @@ -/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*- - * 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/. */ - -package org.mozilla.focus.menu.browser; - -import androidx.recyclerview.widget.RecyclerView; -import android.view.View; - -import org.mozilla.focus.fragment.BrowserFragment; - -public abstract class BrowserMenuViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { - private BrowserMenu menu; - protected BrowserFragment browserFragment; - - public BrowserMenuViewHolder(View itemView) { - super(itemView); - } - - public void setMenu(BrowserMenu menu) { - this.menu = menu; - } - - public BrowserMenu getMenu() { - return menu; - } - - public void setOnClickListener(BrowserFragment browserFragment) { - this.browserFragment = browserFragment; - } - - @Override - public void onClick(View view) { - if (menu != null) { - menu.dismiss(); - } - - if (browserFragment != null) { - browserFragment.onClick(view); - } - } -} diff --git a/mobile/android/focus-android/app/src/main/java/org/mozilla/focus/menu/browser/CustomTabMenu.kt b/mobile/android/focus-android/app/src/main/java/org/mozilla/focus/menu/browser/CustomTabMenu.kt index 45edc238930b..660d7520f5c5 100644 --- a/mobile/android/focus-android/app/src/main/java/org/mozilla/focus/menu/browser/CustomTabMenu.kt +++ b/mobile/android/focus-android/app/src/main/java/org/mozilla/focus/menu/browser/CustomTabMenu.kt @@ -40,7 +40,7 @@ class CustomTabMenu( override val menuToolbar by lazy { val back = BrowserMenuItemToolbar.TwoStateButton( - primaryImageResource = R.drawable.ic_back, + primaryImageResource = R.drawable.mozac_ic_back, primaryContentDescription = context.getString(R.string.content_description_back), primaryImageTintResource = context.theme.resolveAttribute(R.attr.primaryText), isInPrimaryState = { @@ -54,7 +54,7 @@ class CustomTabMenu( } val forward = BrowserMenuItemToolbar.TwoStateButton( - primaryImageResource = R.drawable.ic_forward, + primaryImageResource = R.drawable.mozac_ic_forward, primaryContentDescription = context.getString(R.string.content_description_forward), primaryImageTintResource = context.theme.resolveAttribute(R.attr.primaryText), isInPrimaryState = { @@ -68,13 +68,13 @@ class CustomTabMenu( } val refresh = BrowserMenuItemToolbar.TwoStateButton( - primaryImageResource = R.drawable.ic_refresh, + primaryImageResource = R.drawable.mozac_ic_refresh, primaryContentDescription = context.getString(R.string.content_description_reload), primaryImageTintResource = context.theme.resolveAttribute(R.attr.primaryText), isInPrimaryState = { selectedSession?.content?.loading == false }, - secondaryImageResource = R.drawable.ic_stop, + secondaryImageResource = R.drawable.mozac_ic_stop, secondaryContentDescription = context.getString(R.string.content_description_stop), secondaryImageTintResource = context.theme.resolveAttribute(R.attr.primaryText), disableInSecondaryState = false, @@ -92,13 +92,13 @@ class CustomTabMenu( private val menuItems by lazy { val findInPage = BrowserMenuImageText( label = context.getString(R.string.find_in_page), - imageResource = R.drawable.ic_search + imageResource = R.drawable.mozac_ic_search ) { onItemTapped.invoke(ToolbarMenu.Item.FindInPage) } val desktopMode = BrowserMenuImageSwitch( - imageResource = R.drawable.ic_device_desktop, + imageResource = R.drawable.mozac_ic_device_desktop, label = context.getString(R.string.preference_performance_request_desktop_site2), initialState = { selectedSession?.content?.desktopMode ?: true @@ -114,7 +114,7 @@ class CustomTabMenu( val addToHomescreen = BrowserMenuImageText( label = context.getString(R.string.menu_add_to_home_screen), - imageResource = R.drawable.ic_add_to_home_screen + imageResource = R.drawable.mozac_ic_add_to_home_screen ) { onItemTapped.invoke(ToolbarMenu.Item.AddToHomeScreen) } diff --git a/mobile/android/focus-android/app/src/main/java/org/mozilla/focus/menu/browser/CustomTabMenuItemViewHolder.java b/mobile/android/focus-android/app/src/main/java/org/mozilla/focus/menu/browser/CustomTabMenuItemViewHolder.java deleted file mode 100644 index 5de108dc504c..000000000000 --- a/mobile/android/focus-android/app/src/main/java/org/mozilla/focus/menu/browser/CustomTabMenuItemViewHolder.java +++ /dev/null @@ -1,61 +0,0 @@ -package org.mozilla.focus.menu.browser; - -import android.app.PendingIntent; -import android.content.Intent; -import android.net.Uri; -import android.view.View; - -import org.mozilla.focus.R; -import org.mozilla.focus.telemetry.TelemetryWrapper; - -/** - * Custom tab menu items look just the same as any other menu items. The primary difference - * is that they each have a custom pending intent (which we need to execute), as opposed to - * simply redirecting to the BrowserFragment menu item handling (which is performed via the MenuItem - * id). - */ -/* package-private */ class CustomTabMenuItemViewHolder extends MenuItemViewHolder { - /* package-private */ static final int LAYOUT_ID = R.layout.custom_tab_menu_item; - - private BrowserMenu menu; - private PendingIntent pendingIntent; - - /* package-private */ CustomTabMenuItemViewHolder(View itemView) { - super(itemView); - } - - @Override - public void setMenu(BrowserMenu menu) { - this.menu = menu; - } - - @Override - public void onClick(View view) { - // Usually this is done in BrowserMenuViewHolder.onClick(), but that also tries to submit - // the click up to the fragment, which we explicitly don't want here: - if (menu != null) { - menu.dismiss(); - } - - if (pendingIntent == null) { - throw new IllegalStateException("No PendingIntent set for CustomTabMenuItemViewHolder"); - } - - try { - final Intent intent = new Intent(); - intent.setData(Uri.parse(browserFragment.getTab().getContent().getUrl())); - - pendingIntent.send(view.getContext(), 0, intent); - } catch (PendingIntent.CanceledException e) { - // There's really nothing we can do here... - } - - TelemetryWrapper.customTabMenuEvent(); - } - - /* package-private */ void bind(BrowserMenuAdapter.MenuItem.Custom menuItem) { - super.bind(menuItem); - - pendingIntent = menuItem.getPendingIntent(); - } -} diff --git a/mobile/android/focus-android/app/src/main/java/org/mozilla/focus/menu/browser/DefaultBrowserMenu.kt b/mobile/android/focus-android/app/src/main/java/org/mozilla/focus/menu/browser/DefaultBrowserMenu.kt index ad8aff58bb0d..c4908456e287 100644 --- a/mobile/android/focus-android/app/src/main/java/org/mozilla/focus/menu/browser/DefaultBrowserMenu.kt +++ b/mobile/android/focus-android/app/src/main/java/org/mozilla/focus/menu/browser/DefaultBrowserMenu.kt @@ -42,7 +42,7 @@ class DefaultBrowserMenu( override val menuToolbar by lazy { val back = BrowserMenuItemToolbar.TwoStateButton( - primaryImageResource = R.drawable.ic_back, + primaryImageResource = R.drawable.mozac_ic_back, primaryContentDescription = context.getString(R.string.content_description_back), primaryImageTintResource = context.theme.resolveAttribute(R.attr.primaryText), isInPrimaryState = { @@ -56,7 +56,7 @@ class DefaultBrowserMenu( } val forward = BrowserMenuItemToolbar.TwoStateButton( - primaryImageResource = R.drawable.ic_forward, + primaryImageResource = R.drawable.mozac_ic_forward, primaryContentDescription = context.getString(R.string.content_description_forward), primaryImageTintResource = context.theme.resolveAttribute(R.attr.primaryText), isInPrimaryState = { @@ -70,13 +70,13 @@ class DefaultBrowserMenu( } val refresh = BrowserMenuItemToolbar.TwoStateButton( - primaryImageResource = R.drawable.ic_refresh, + primaryImageResource = R.drawable.mozac_ic_refresh, primaryContentDescription = context.getString(R.string.content_description_reload), primaryImageTintResource = context.theme.resolveAttribute(R.attr.primaryText), isInPrimaryState = { selectedSession?.content?.loading == false }, - secondaryImageResource = R.drawable.ic_stop, + secondaryImageResource = R.drawable.mozac_ic_stop, secondaryContentDescription = context.getString(R.string.content_description_stop), secondaryImageTintResource = context.theme.resolveAttribute(R.attr.primaryText), disableInSecondaryState = false, @@ -89,7 +89,7 @@ class DefaultBrowserMenu( } } val share = BrowserMenuItemToolbar.Button( - imageResource = R.drawable.ic_share2, + imageResource = R.drawable.mozac_ic_share, contentDescription = context.getString(R.string.menu_share), listener = { onItemTapped.invoke(ToolbarMenu.Item.Share) @@ -120,13 +120,13 @@ class DefaultBrowserMenu( val findInPage = BrowserMenuImageText( label = context.getString(R.string.find_in_page), - imageResource = R.drawable.ic_search + imageResource = R.drawable.mozac_ic_search ) { onItemTapped.invoke(ToolbarMenu.Item.FindInPage) } val desktopMode = BrowserMenuImageSwitch( - imageResource = R.drawable.ic_device_desktop, + imageResource = R.drawable.mozac_ic_device_desktop, label = context.getString(R.string.preference_performance_request_desktop_site2), initialState = { selectedSession?.content?.desktopMode ?: false @@ -142,14 +142,14 @@ class DefaultBrowserMenu( val addToHomescreen = BrowserMenuImageText( label = context.getString(R.string.menu_add_to_home_screen), - imageResource = R.drawable.ic_add_to_home_screen + imageResource = R.drawable.mozac_ic_add_to_home_screen ) { onItemTapped.invoke(ToolbarMenu.Item.AddToHomeScreen) } val openInApp = BrowserMenuImageText( label = context.getString(R.string.menu_open_with_a_browser2), - imageResource = R.drawable.ic_open_in, + imageResource = R.drawable.mozac_ic_open_in, textColorResource = context.theme.resolveAttribute(R.attr.primaryText) ) { onItemTapped.invoke(ToolbarMenu.Item.OpenInApp) @@ -157,7 +157,7 @@ class DefaultBrowserMenu( val settings = BrowserMenuImageText( label = context.getString(R.string.menu_settings), - imageResource = R.drawable.ic_settings2, + imageResource = R.drawable.mozac_ic_settings, textColorResource = context.theme.resolveAttribute(R.attr.primaryText) ) { onItemTapped.invoke(ToolbarMenu.Item.Settings) diff --git a/mobile/android/focus-android/app/src/main/java/org/mozilla/focus/menu/browser/MenuItemViewHolder.java b/mobile/android/focus-android/app/src/main/java/org/mozilla/focus/menu/browser/MenuItemViewHolder.java deleted file mode 100644 index 80ab86c5ded7..000000000000 --- a/mobile/android/focus-android/app/src/main/java/org/mozilla/focus/menu/browser/MenuItemViewHolder.java +++ /dev/null @@ -1,50 +0,0 @@ -/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*- - * 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/. */ - -package org.mozilla.focus.menu.browser; - -import android.graphics.drawable.Drawable; -import android.view.View; -import android.widget.TextView; - -import org.mozilla.focus.R; - -/* package-private */ class MenuItemViewHolder extends BrowserMenuViewHolder { - /* package-private */ static final int LAYOUT_ID = R.layout.menu_item; - - private final TextView menuItemView; - - /* package-private */ MenuItemViewHolder(View itemView) { - super(itemView); - - menuItemView = (TextView) itemView; - } - - /* package-private */ void bind(BrowserMenuAdapter.MenuItem.Default menuItem) { - menuItemView.setId(menuItem.getId()); - menuItemView.setText(menuItem.getLabel()); - if (menuItem.getDrawableResId() != 0) { - final Drawable drawable = menuItemView.getContext().getDrawable(menuItem.getDrawableResId()); - if (drawable != null) { - drawable.setTint(menuItemView.getContext().getResources().getColor(R.color.colorSettingsTint)); - menuItemView.setCompoundDrawablesRelativeWithIntrinsicBounds( - drawable, - null, - null, - null - ); - } - } - - final boolean isLoading = browserFragment.getTab().getContent().getLoading(); - - if ((menuItem.getId() == R.id.add_to_homescreen || menuItem.getId() == R.id.find_in_page) && isLoading) { - menuItemView.setTextColor(browserFragment.getResources().getColor(R.color.colorTextInactive)); - menuItemView.setClickable(false); - } else { - menuItemView.setOnClickListener(this); - } - } -} diff --git a/mobile/android/focus-android/app/src/main/java/org/mozilla/focus/menu/browser/NavigationItemViewHolder.java b/mobile/android/focus-android/app/src/main/java/org/mozilla/focus/menu/browser/NavigationItemViewHolder.java deleted file mode 100644 index 7cf192d25988..000000000000 --- a/mobile/android/focus-android/app/src/main/java/org/mozilla/focus/menu/browser/NavigationItemViewHolder.java +++ /dev/null @@ -1,43 +0,0 @@ -/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*- - * 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/. */ - -package org.mozilla.focus.menu.browser; - -import android.view.View; - -import org.mozilla.focus.R; -import org.mozilla.focus.fragment.BrowserFragment; - -public class NavigationItemViewHolder extends BrowserMenuViewHolder { - public static final int LAYOUT_ID = R.layout.menu_navigation; - - final View refreshButton; - final View stopButton; - - public NavigationItemViewHolder(View itemView, BrowserFragment fragment) { - super(itemView); - - refreshButton = itemView.findViewById(R.id.refresh); - refreshButton.setOnClickListener(this); - - stopButton = itemView.findViewById(R.id.stop); - stopButton.setOnClickListener(this); - - updateLoading(fragment.getTab().getContent().getLoading()); - - final View forwardView = itemView.findViewById(R.id.forward); - if (!fragment.getTab().getContent().getCanGoForward()) { - forwardView.setEnabled(false); - forwardView.setAlpha(0.5f); - } else { - forwardView.setOnClickListener(this); - } - } - - public void updateLoading(boolean loading) { - refreshButton.setVisibility(loading ? View.GONE : View.VISIBLE); - stopButton.setVisibility(loading ? View.VISIBLE : View.GONE); - } -} diff --git a/mobile/android/focus-android/app/src/main/java/org/mozilla/focus/menu/browser/RequestDesktopCheckItemViewHolder.kt b/mobile/android/focus-android/app/src/main/java/org/mozilla/focus/menu/browser/RequestDesktopCheckItemViewHolder.kt deleted file mode 100644 index 2ee759c4e203..000000000000 --- a/mobile/android/focus-android/app/src/main/java/org/mozilla/focus/menu/browser/RequestDesktopCheckItemViewHolder.kt +++ /dev/null @@ -1,51 +0,0 @@ -/* 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/. */ - -package org.mozilla.focus.menu.browser - -import android.view.View -import android.widget.CheckBox -import android.widget.CompoundButton -import mozilla.components.support.utils.ThreadUtils -import org.mozilla.focus.R -import org.mozilla.focus.ext.requireComponents -import org.mozilla.focus.fragment.BrowserFragment -import org.mozilla.focus.utils.UrlUtils - -internal class RequestDesktopCheckItemViewHolder/* package */( - itemView: View, - private val fragment: BrowserFragment -) : BrowserMenuViewHolder(itemView), CompoundButton.OnCheckedChangeListener { - private val checkbox: CheckBox = itemView.findViewById(R.id.check_menu_item_checkbox) - - init { - checkbox.isChecked = fragment.tab.content.desktopMode - checkbox.setOnCheckedChangeListener(this) - } - - override fun onCheckedChanged(buttonView: CompoundButton, isChecked: Boolean) { - fragment.setShouldRequestDesktop(isChecked) - - // Delay closing the menu and reloading the website a bit so that the user can actually see - // the switch change its state. - ThreadUtils.postToMainThreadDelayed( - Runnable { - menu.dismiss() - - val url = UrlUtils.stripSchemeAndSubDomain(fragment.tab.content.url) - fragment.requireComponents.sessionUseCases.loadUrl(url) - }, - ANIMATION_DURATION - ) - } - - companion object { - const val LAYOUT_ID = R.layout.request_desktop_check_menu_item - - /** - * Switch.THUMB_ANIMATION_DURATION - */ - const val ANIMATION_DURATION = 250L - } -} diff --git a/mobile/android/focus-android/app/src/main/java/org/mozilla/focus/menu/home/HomeMenuAdapter.kt b/mobile/android/focus-android/app/src/main/java/org/mozilla/focus/menu/home/HomeMenuAdapter.kt index cdfd102d00b4..95dda94ae270 100644 --- a/mobile/android/focus-android/app/src/main/java/org/mozilla/focus/menu/home/HomeMenuAdapter.kt +++ b/mobile/android/focus-android/app/src/main/java/org/mozilla/focus/menu/home/HomeMenuAdapter.kt @@ -66,9 +66,9 @@ private class MenuItemViewHolder( fun bind(item: MenuItem) { val iconResourceId = if (item.id == R.id.help) { - R.drawable.ic_help + R.drawable.mozac_ic_help } else { - R.drawable.ic_settings2 + R.drawable.mozac_ic_settings } containerView.apply { id = item.id diff --git a/mobile/android/focus-android/app/src/main/java/org/mozilla/focus/searchsuggestions/ui/SearchSuggestionsFragment.kt b/mobile/android/focus-android/app/src/main/java/org/mozilla/focus/searchsuggestions/ui/SearchSuggestionsFragment.kt index 2d3777456b88..05472c7a8d20 100644 --- a/mobile/android/focus-android/app/src/main/java/org/mozilla/focus/searchsuggestions/ui/SearchSuggestionsFragment.kt +++ b/mobile/android/focus-android/app/src/main/java/org/mozilla/focus/searchsuggestions/ui/SearchSuggestionsFragment.kt @@ -145,7 +145,7 @@ private fun SearchSuggestions( val components = components val query = viewModel.searchQuery.observeAsState() - val icon = ContextCompat.getDrawable(LocalContext.current, R.drawable.ic_search) + val icon = ContextCompat.getDrawable(LocalContext.current, R.drawable.mozac_ic_search) ?.toBitmap() val provider = remember(context) { diff --git a/mobile/android/focus-android/app/src/main/java/org/mozilla/focus/shortcut/IconGenerator.kt b/mobile/android/focus-android/app/src/main/java/org/mozilla/focus/shortcut/IconGenerator.kt index bbd197999ba4..ba86a03570d8 100644 --- a/mobile/android/focus-android/app/src/main/java/org/mozilla/focus/shortcut/IconGenerator.kt +++ b/mobile/android/focus-android/app/src/main/java/org/mozilla/focus/shortcut/IconGenerator.kt @@ -62,7 +62,7 @@ class IconGenerator { val options = BitmapFactory.Options() options.inMutable = true val shape = BitmapFactory.decodeResource(context.resources, R.drawable.ic_search_engine_shape, options) - return drawVectorOnBitmap(context, R.drawable.ic_search, shape, SEARCH_ICON_FRAME) + return drawVectorOnBitmap(context, R.drawable.mozac_ic_search, shape, SEARCH_ICON_FRAME) } private fun drawVectorOnBitmap(context: Context, vectorId: Int, bitmap: Bitmap, frame: Double): Bitmap { diff --git a/mobile/android/focus-android/app/src/main/res/drawable/ic_add_to_home_screen.xml b/mobile/android/focus-android/app/src/main/res/drawable/ic_add_to_home_screen.xml deleted file mode 100644 index cd588ed5ccb7..000000000000 --- a/mobile/android/focus-android/app/src/main/res/drawable/ic_add_to_home_screen.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - - diff --git a/mobile/android/focus-android/app/src/main/res/drawable/ic_back.xml b/mobile/android/focus-android/app/src/main/res/drawable/ic_back.xml deleted file mode 100644 index d7a0f185f5c8..000000000000 --- a/mobile/android/focus-android/app/src/main/res/drawable/ic_back.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - diff --git a/mobile/android/focus-android/app/src/main/res/drawable/ic_clear.xml b/mobile/android/focus-android/app/src/main/res/drawable/ic_clear.xml deleted file mode 100644 index 8301fdd15b0f..000000000000 --- a/mobile/android/focus-android/app/src/main/res/drawable/ic_clear.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - diff --git a/mobile/android/focus-android/app/src/main/res/drawable/ic_close.xml b/mobile/android/focus-android/app/src/main/res/drawable/ic_close.xml deleted file mode 100644 index 3d5c94434fe2..000000000000 --- a/mobile/android/focus-android/app/src/main/res/drawable/ic_close.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - diff --git a/mobile/android/focus-android/app/src/main/res/drawable/ic_device_desktop.xml b/mobile/android/focus-android/app/src/main/res/drawable/ic_device_desktop.xml deleted file mode 100644 index 5326198e4a7d..000000000000 --- a/mobile/android/focus-android/app/src/main/res/drawable/ic_device_desktop.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - diff --git a/mobile/android/focus-android/app/src/main/res/drawable/ic_forward.xml b/mobile/android/focus-android/app/src/main/res/drawable/ic_forward.xml deleted file mode 100644 index 1aed7d3f7212..000000000000 --- a/mobile/android/focus-android/app/src/main/res/drawable/ic_forward.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - diff --git a/mobile/android/focus-android/app/src/main/res/drawable/ic_help.xml b/mobile/android/focus-android/app/src/main/res/drawable/ic_help.xml deleted file mode 100644 index 99e26c6b6dfa..000000000000 --- a/mobile/android/focus-android/app/src/main/res/drawable/ic_help.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - diff --git a/mobile/android/focus-android/app/src/main/res/drawable/ic_home.xml b/mobile/android/focus-android/app/src/main/res/drawable/ic_home.xml deleted file mode 100644 index eb99bda3f31f..000000000000 --- a/mobile/android/focus-android/app/src/main/res/drawable/ic_home.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - diff --git a/mobile/android/focus-android/app/src/main/res/drawable/ic_menu_info.xml b/mobile/android/focus-android/app/src/main/res/drawable/ic_menu_info.xml deleted file mode 100644 index 0cc8dd08b6ae..000000000000 --- a/mobile/android/focus-android/app/src/main/res/drawable/ic_menu_info.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - diff --git a/mobile/android/focus-android/app/src/main/res/drawable/ic_open_in.xml b/mobile/android/focus-android/app/src/main/res/drawable/ic_open_in.xml deleted file mode 100644 index e29e6559b58c..000000000000 --- a/mobile/android/focus-android/app/src/main/res/drawable/ic_open_in.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - diff --git a/mobile/android/focus-android/app/src/main/res/drawable/ic_refresh.xml b/mobile/android/focus-android/app/src/main/res/drawable/ic_refresh.xml deleted file mode 100644 index df69bcc0ee74..000000000000 --- a/mobile/android/focus-android/app/src/main/res/drawable/ic_refresh.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - diff --git a/mobile/android/focus-android/app/src/main/res/drawable/ic_search.xml b/mobile/android/focus-android/app/src/main/res/drawable/ic_search.xml deleted file mode 100644 index 82a6996dfb2d..000000000000 --- a/mobile/android/focus-android/app/src/main/res/drawable/ic_search.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - diff --git a/mobile/android/focus-android/app/src/main/res/drawable/ic_settings2.xml b/mobile/android/focus-android/app/src/main/res/drawable/ic_settings2.xml deleted file mode 100644 index 2077950c3448..000000000000 --- a/mobile/android/focus-android/app/src/main/res/drawable/ic_settings2.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - diff --git a/mobile/android/focus-android/app/src/main/res/drawable/ic_share.xml b/mobile/android/focus-android/app/src/main/res/drawable/ic_share.xml deleted file mode 100644 index a1ce838dc975..000000000000 --- a/mobile/android/focus-android/app/src/main/res/drawable/ic_share.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - diff --git a/mobile/android/focus-android/app/src/main/res/drawable/ic_share2.xml b/mobile/android/focus-android/app/src/main/res/drawable/ic_share2.xml deleted file mode 100644 index 38d7f5387851..000000000000 --- a/mobile/android/focus-android/app/src/main/res/drawable/ic_share2.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - diff --git a/mobile/android/focus-android/app/src/main/res/drawable/ic_stop.xml b/mobile/android/focus-android/app/src/main/res/drawable/ic_stop.xml deleted file mode 100644 index 91d2545e83f4..000000000000 --- a/mobile/android/focus-android/app/src/main/res/drawable/ic_stop.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - diff --git a/mobile/android/focus-android/app/src/main/res/layout/connection_details.xml b/mobile/android/focus-android/app/src/main/res/layout/connection_details.xml index 6560cc63daa2..a2206aa098f8 100644 --- a/mobile/android/focus-android/app/src/main/res/layout/connection_details.xml +++ b/mobile/android/focus-android/app/src/main/res/layout/connection_details.xml @@ -21,7 +21,7 @@ android:scaleType="center" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" - app:srcCompat="@drawable/ic_back" /> + app:srcCompat="@drawable/mozac_ic_back" /> + android:src="@drawable/mozac_ic_forward"/> + android:src="@drawable/mozac_ic_refresh"/> diff --git a/mobile/android/focus-android/app/src/main/res/layout/request_desktop_check_menu_item.xml b/mobile/android/focus-android/app/src/main/res/layout/request_desktop_check_menu_item.xml index 8c3570150233..ad46a9275a61 100644 --- a/mobile/android/focus-android/app/src/main/res/layout/request_desktop_check_menu_item.xml +++ b/mobile/android/focus-android/app/src/main/res/layout/request_desktop_check_menu_item.xml @@ -10,7 +10,7 @@ android:background="?android:attr/selectableItemBackground" android:button="@null" android:clickable="true" - android:drawableStart="@drawable/ic_device_desktop" + android:drawableStart="@drawable/mozac_ic_device_desktop" android:drawableEnd="?android:attr/listChoiceIndicatorMultiple" android:drawablePadding="16dp" android:ellipsize="end" diff --git a/mobile/android/focus-android/app/src/main/res/menu/menu_search_engine_manual_add.xml b/mobile/android/focus-android/app/src/main/res/menu/menu_search_engine_manual_add.xml index 9df208098aeb..88d9413e9346 100644 --- a/mobile/android/focus-android/app/src/main/res/menu/menu_search_engine_manual_add.xml +++ b/mobile/android/focus-android/app/src/main/res/menu/menu_search_engine_manual_add.xml @@ -9,7 +9,7 @@