1
0
Fork 0

For #1072: Adds basic view

master
Sawyer Blatz 2019-03-19 09:13:48 -07:00 committed by Colin Lee
parent 557cb95082
commit 994d88542e
9 changed files with 264 additions and 4 deletions

View File

@ -79,7 +79,7 @@ class BrowserFragment : Fragment(), BackHandler {
sessionId = BrowserFragmentArgs.fromBundle(arguments!!).sessionId
val view = inflater.inflate(R.layout.fragment_browser, container, false)
0
toolbarComponent = ToolbarComponent(
view.browserLayout,
ActionBusFactory.get(this), sessionId,

View File

@ -33,7 +33,7 @@ class ToolbarUIView(
.findViewById(R.id.toolbar)
private val urlBackground = LayoutInflater.from(container.context)
.inflate(R.layout.layout_url_backround, container, false)
.inflate(R.layout.layout_url_background, container, false)
init {
view.apply {

View File

@ -18,7 +18,7 @@ class SessionBottomSheetFragment : BottomSheetDialogFragment(), LayoutContainer
sealed class SessionType {
data class Current(val titles: List<String>) : SessionType()
data class Archived(val archivedSession: ArchivedSession) : SessionType()
data class Private(val titles: List<String>) : SessionType()
data class Private(val titles: List <String>) : SessionType()
}
private var sessionType: SessionType? = null

View File

@ -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()
}
}

View File

@ -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()
}
}

File diff suppressed because one or more lines are too long

View File

@ -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>

View File

@ -14,7 +14,23 @@
<mozilla.components.concept.engine.EngineView
android:id="@+id/engineView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_height="match_parent"/>
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="80dp"
android:background="@color/off_white"
android:clipToPadding="true"
app:behavior_hideable="true"
app:behavior_peekHeight="20dp"
app:layout_behavior="org.mozilla.fenix.quickactionsheet.QuickActionSheetBehavior">
<org.mozilla.fenix.quickactionsheet.QuickActionSheet
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"/>
</androidx.core.widget.NestedScrollView>
<mozilla.components.feature.findinpage.view.FindInPageBar
android:id="@+id/findInPageView"