[fenix] For https://github.com/mozilla-mobile/fenix/issues/1072: Adds basic view
parent
cf13448018
commit
c1da6491d8
@ -0,0 +1,109 @@
|
||||
package org.mozilla.fenix.quickactionsheet
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.LinearLayout
|
||||
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
import androidx.core.widget.NestedScrollView
|
||||
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
||||
import kotlinx.android.synthetic.main.component_quickactionsheet.view.*
|
||||
import mozilla.components.browser.toolbar.BrowserToolbar
|
||||
import mozilla.components.feature.findinpage.view.FindInPageBar
|
||||
import org.mozilla.fenix.R
|
||||
import kotlin.math.absoluteValue
|
||||
|
||||
class QuickActionSheet @JvmOverloads constructor(
|
||||
context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
defStyle: Int = 0,
|
||||
defStyleRes: Int = 0
|
||||
) : LinearLayout(context, attrs, defStyle, defStyleRes) {
|
||||
|
||||
var currentMargin : Float = 0f
|
||||
var previousY : Float = 0f
|
||||
|
||||
init {
|
||||
LayoutInflater.from(context)
|
||||
.inflate(R.layout.component_quickactionsheet, this, true)
|
||||
}
|
||||
|
||||
/*
|
||||
override fun onAttachedToWindow() {
|
||||
super.onAttachedToWindow()
|
||||
|
||||
val linearLayout = findViewById<LinearLayout>(R.id.quick_action_sheet)
|
||||
val bottomSheetBehavior = BottomSheetBehavior.from(linearLayout)
|
||||
bottomSheetBehavior.state = BottomSheetBehavior.STATE_EXPANDED
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
override fun onInterceptTouchEvent(ev: MotionEvent?): Boolean {
|
||||
Log.d("touchEvent", "starting: " + rootView.y)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onTouchEvent(event: MotionEvent?): Boolean {
|
||||
/*
|
||||
val layout = findViewById<LinearLayout>(R.id.quick_action_sheet)
|
||||
|
||||
val params = layout.layoutParams as ViewGroup.MarginLayoutParams
|
||||
|
||||
when (event?.action) {
|
||||
MotionEvent.ACTION_MOVE -> {
|
||||
Log.d("touchEvent", "handle move: " + (currentMargin))
|
||||
|
||||
|
||||
previousY = event.y
|
||||
|
||||
params.bottomMargin += diff.toInt()
|
||||
requestLayout()
|
||||
}
|
||||
MotionEvent.ACTION_UP -> Log.d("touchEvent", "handle up")
|
||||
MotionEvent.ACTION_DOWN -> Log.d("touchEvent", "handle down")
|
||||
else -> Log.d("touchEvent", "" + event?.action)
|
||||
}
|
||||
*/
|
||||
return true
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
@Suppress("unused") // Referenced from XML
|
||||
class QuickActionSheetBehavior(
|
||||
context: Context,
|
||||
attrs: AttributeSet
|
||||
) : BottomSheetBehavior<NestedScrollView>(context, attrs) {
|
||||
override fun layoutDependsOn(parent: CoordinatorLayout, child: NestedScrollView, dependency: View): Boolean {
|
||||
if (dependency is BrowserToolbar) {
|
||||
return true
|
||||
}
|
||||
|
||||
return super.layoutDependsOn(parent, child, dependency)
|
||||
}
|
||||
|
||||
override fun onDependentViewChanged(
|
||||
parent: CoordinatorLayout,
|
||||
child: NestedScrollView,
|
||||
dependency: View
|
||||
): Boolean {
|
||||
return if (dependency is BrowserToolbar) {
|
||||
repositionQuickActionSheet(child, dependency)
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
private fun repositionQuickActionSheet(quickActionSheetContainer: NestedScrollView, toolbar: BrowserToolbar) {
|
||||
state = BottomSheetBehavior.STATE_COLLAPSED
|
||||
quickActionSheetContainer.translationY = (toolbar.translationY + toolbar.height * -1.0).toFloat()
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package org.mozilla.fenix.quickactionsheet
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.View
|
||||
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
import mozilla.components.browser.toolbar.BrowserToolbar
|
||||
import mozilla.components.feature.findinpage.view.FindInPageBar
|
||||
|
||||
/**
|
||||
* [CoordinatorLayout.Behavior] that will always position the [QuickActionSheetBar] above the [BrowserToolbar] (including
|
||||
* when the browser toolbar is scrolling or performing a snap animation).
|
||||
*/
|
||||
@Suppress("unused") // Referenced from XML
|
||||
class QuickActionSheetIntegration(
|
||||
context: Context,
|
||||
attrs: AttributeSet
|
||||
) : CoordinatorLayout.Behavior<FindInPageBar>(context, attrs) {
|
||||
override fun layoutDependsOn(parent: CoordinatorLayout, child: FindInPageBar, dependency: View): Boolean {
|
||||
if (dependency is BrowserToolbar) {
|
||||
return true
|
||||
}
|
||||
|
||||
return super.layoutDependsOn(parent, child, dependency)
|
||||
}
|
||||
|
||||
override fun onDependentViewChanged(parent: CoordinatorLayout, child: FindInPageBar, dependency: View): Boolean {
|
||||
return if (dependency is BrowserToolbar) {
|
||||
repositionFindInPageBar(child, dependency)
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
private fun repositionFindInPageBar(findInPageView: FindInPageBar, toolbar: BrowserToolbar) {
|
||||
findInPageView.translationY = (toolbar.translationY + toolbar.height * -1.0).toFloat()
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 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/. -->
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item>
|
||||
<shape android:shape="oval">
|
||||
<size
|
||||
android:width="48dp"
|
||||
android:height="48dp" />
|
||||
<solid android:color="@color/library_screenshots_icon_background" />
|
||||
</shape>
|
||||
</item>
|
||||
<item
|
||||
android:bottom="8dp"
|
||||
android:left="8dp"
|
||||
android:right="8dp"
|
||||
android:top="8dp">
|
||||
<vector
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="@color/library_screenshots_icon"
|
||||
android:fillType="evenOdd"
|
||||
android:pathData="M6,7.1707C7.1652,7.5825 8,8.6938 8,10C8,10.2312 7.9738,10.4563 7.9243,10.6725L10.4097,12.5843L14.9445,9.4447C16.0797,8.6588 17.6371,8.942 18.423,10.0772L7.9279,17.3431C7.9751,17.5545 8,17.7743 8,18C8,19.6569 6.6569,21 5,21C3.3431,21 2,19.6569 2,18C2,16.3431 3.3431,15 5,15C5.5103,15 5.9909,15.1274 6.4116,15.3522L8.2516,14.0783L6.4,12.654C5.9821,12.8749 5.5056,13 5,13C3.3431,13 2,11.6569 2,10C2,8.6938 2.8348,7.5825 4,7.1707L4,6L6,6L6,7.1707ZM6,2L6,4L4,4C4,2.8954 4.8954,2 6,2ZM8,2L10,2L10,4L8,4L8,2ZM12,2L14,2L14,4L12,4L12,2ZM16,2L18,2L18,4L16,4L16,2ZM20,2C21.1046,2 22,2.8954 22,4L20,4L20,2ZM20,6L22,6L22,8L20,8L20,6ZM20,10L22,10L22,12L20,12L20,10ZM20,14L22,14C22,15.1046 21.1046,16 20,16L20,14ZM13.648,15.0753L18.7621,19.0092C17.9203,20.1036 16.3507,20.3083 15.2563,19.4665L11.49,16.5693L13.648,15.0753ZM5,11C5.5523,11 6,10.5523 6,10C6,9.4477 5.5523,9 5,9C4.4477,9 4,9.4477 4,10C4,10.5523 4.4477,11 5,11ZM5,19C5.5523,19 6,18.5523 6,18C6,17.4477 5.5523,17 5,17C4.4477,17 4,17.4477 4,18C4,18.5523 4.4477,19 5,19Z"
|
||||
android:strokeWidth="1"
|
||||
android:strokeColor="#00000000" />
|
||||
</vector>
|
||||
</item>
|
||||
</layer-list>
|
@ -0,0 +1,64 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- 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"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/quick_action_sheet"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="80dp"
|
||||
android:background="@color/photonBlue50">
|
||||
|
||||
<ImageButton
|
||||
android:layout_weight="1"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:src="@drawable/library_icon_screenshots_circle_background"
|
||||
android:background="?android:attr/selectableItemBackground"/>
|
||||
|
||||
<ImageButton
|
||||
android:layout_weight="1"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:src="@drawable/library_icon_downloads_circle_background"
|
||||
android:background="?android:attr/selectableItemBackground"/>
|
||||
|
||||
<ImageButton
|
||||
android:layout_weight="1"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:src="@drawable/library_icon_favorites_circle_background"
|
||||
android:background="?android:attr/selectableItemBackground"/>
|
||||
|
||||
<ImageButton
|
||||
android:layout_weight="1"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:src="@drawable/library_icon_history_circle_background"
|
||||
android:background="?android:attr/selectableItemBackground"/>
|
||||
|
||||
<ImageButton
|
||||
android:layout_weight="1"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:src="@drawable/library_icon_history_circle_background"
|
||||
android:background="?android:attr/selectableItemBackground"/>
|
||||
</LinearLayout>
|
Loading…
Reference in New Issue