Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2e2afbfd authored by Jeremie Boulic's avatar Jeremie Boulic Committed by Android (Google) Code Review
Browse files

Merge "[DocsUI Peek] Top bar and back navigation" into main

parents 2b45e2d8 b158ee9c
Loading
Loading
Loading
Loading
+21 −3
Original line number Diff line number Diff line
@@ -14,9 +14,27 @@
     limitations under the License.
-->

<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.coordinatorlayout.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/peek_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/peek_overlay_background"
    android:focusable="false" />
    android:background="@color/peek_overlay_scrim"
    android:focusable="false" >
    <!-- Text and icons using android:white because the underlying black scrim doesn't dynamically
    change colour. -->
    <com.google.android.material.appbar.MaterialToolbar
        android:id="@+id/peek_toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingStart="@dimen/space_extra_small_4"
        android:paddingEnd="@dimen/space_extra_small_4"
        android:background="@color/peek_topbar_scrim"
        app:titleMarginStart="@dimen/space_extra_small_2"
        app:titleTextAppearance="?attr/textAppearanceTitleMedium"
        app:titleTextColor="@android:color/white"
        app:navigationContentDescription="@string/a11y_peek_navigation_icon"
        app:navigationIcon="@drawable/ic_arrow_back"
        app:navigationIconTint="@android:color/white" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
+6 −3
Original line number Diff line number Diff line
@@ -92,7 +92,10 @@
   -->
  <color name="overlay_hover_color_percentage">#14000000</color> <!-- 8% -->

  <!-- Peek overlay static color. Makes the background dimmer with an 80% opacity. This color is not
  intended to be dynamic, and is defined specifically for Peek. -->
  <color name="peek_overlay_background">#CC000000</color> <!-- 80% -->
  <!-- Peek -->
  <!-- Scrim for the overlay. Static color, 80% opacity in black, defined specifically for Peek. -->
  <color name="peek_overlay_scrim">#CC000000</color>
  <!-- Scrim for the Top bar. Static color, 32% opacity in black. The same scrim is used in some
  parts of Android SysUI, it can't be used directly here. -->
  <color name="peek_topbar_scrim">#52000000</color>
</resources>
+3 −0
Original line number Diff line number Diff line
@@ -651,4 +651,7 @@

    <!-- Text used at the top of the text field when saving a document. [CHAR_LIMIT=100] -->
    <string name="file_name_hint">File name</string>

    <!-- Accessibility label for the Peek navigation icon. -->
    <string name="a11y_peek_navigation_icon">Hide file preview</string>
</resources>
+32 −1
Original line number Diff line number Diff line
@@ -16,17 +16,48 @@
package com.android.documentsui.peek

import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment

import com.android.documentsui.R
import com.android.documentsui.base.DocumentInfo
import com.google.android.material.appbar.MaterialToolbar

class PeekFragment : Fragment() {
    companion object {
        const val TAG = "PeekFragment"
    }

    private lateinit var viewManager: PeekViewManager
    private lateinit var toolbar: MaterialToolbar

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
    ): View? {
        return inflater.inflate(R.layout.peek_layout, container, /* attachToRoot= */ false)
        val view = inflater.inflate(R.layout.peek_layout, container, /* attachToRoot= */ false)
        toolbar = view.findViewById(R.id.peek_toolbar)
        toolbar.setNavigationOnClickListener {
            if (!::viewManager.isInitialized) {
                Log.e(TAG, "PeekViewManager has not been initialized")
            } else {
                viewManager.setContainerVisibility(false)
            }
        }
        return view
    }

    fun setViewManager(viewManager: PeekViewManager) {
        this.viewManager = viewManager
    }

    fun updateView(doc: DocumentInfo) {
        if (!::toolbar.isInitialized) {
            Log.e(TAG, "Toolbar has not been initialized")
            return
        }
        toolbar.title = doc.displayName
    }
}
+18 −22
Original line number Diff line number Diff line
@@ -16,11 +16,9 @@
package com.android.documentsui.peek

import android.app.Activity
import android.os.Bundle
import android.util.Log
import android.view.View
import android.widget.FrameLayout
import androidx.annotation.IdRes
import androidx.fragment.app.FragmentManager
import com.android.documentsui.R
import androidx.fragment.app.FragmentTransaction
@@ -37,7 +35,8 @@ open class PeekViewManager(
        const val TAG = "PeekViewManager"
    }

    private var mPeekFragment: PeekFragment? = null
    private lateinit var peekFragment: PeekFragment
    private lateinit var container: FrameLayout

    open fun initFragment(
        fm: FragmentManager
@@ -47,37 +46,34 @@ open class PeekViewManager(
            return
        }

        if (getOverlayContainer() == null) {
        val container: FrameLayout? = mActivity.findViewById(R.id.peek_overlay)
        if (container == null) {
            Log.e(TAG, "Unable to find Peek container")
            return
        }
        this.container = container

        // Load the Peek fragment into its container.
        val peekFragment = PeekFragment()
        mPeekFragment = peekFragment
        peekFragment = PeekFragment()
        peekFragment.setViewManager(this)
        val ft: FragmentTransaction = fm.beginTransaction()
        ft.replace(getOverlayId(), peekFragment)
        ft.replace(R.id.peek_overlay, peekFragment)
        ft.commitAllowingStateLoss()
    }

    open fun peekDocument(doc: DocumentInfo) {
        if (mPeekFragment == null) {
            Log.e(TAG, "Peek fragment not initialized")
        if (!::peekFragment.isInitialized) {
            Log.e(TAG, "PeekFragment has not been initialized")
            return
        }
        show()
        peekFragment.updateView(doc)
        setContainerVisibility(true)
    }

    @IdRes
    private fun getOverlayId(): Int {
        return R.id.peek_overlay
    }

    private fun getOverlayContainer(): FrameLayout? {
        return mActivity.findViewById(getOverlayId())
    fun setContainerVisibility(visible: Boolean) {
        if (!::container.isInitialized) {
            Log.e(TAG, "Container has not been initialized")
            return
        }

    private fun show() {
        getOverlayContainer()?.visibility = View.VISIBLE
        container.visibility = if (visible) View.VISIBLE else View.GONE
    }
}
 No newline at end of file
Loading