Source code for enamlnative.android.android_app_bar_layout

"""
Copyright (c) 2017-2022, CodeLV.

Distributed under the terms of the MIT License.

The full license is in the file LICENSE, distributed with this software.

Created on Mar 13, 2018


"""
from atom.api import Typed
from enamlnative.widgets.app_bar_layout import ProxyAppBarLayout
from .android_content import Context
from .android_linear_layout import AndroidLinearLayout, LinearLayout
from .bridge import JavaCallback, JavaMethod


class AppBarLayout(LinearLayout):
    package = "com.google.android.material.appbar"

    __nativeclass__ = f"{package}.AppBarLayout"
    __signature__ = [Context]

    addOnOffsetChangedListener = JavaMethod(
        f"{package}.AppBarLayout$OnOffsetChangedListener"
    )
    removeOnOffsetChangedListener = JavaMethod(
        f"{package}.AppBarLayout$OnOffsetChangedListener"
    )

    setExpanded = JavaMethod(bool)

    onOffsetChanged = JavaCallback(f"{package}.AppBarLayout", int)


[docs]class AndroidAppBarLayout(AndroidLinearLayout, ProxyAppBarLayout): """An Android implementation of an Enaml ProxyAppBarLayout.""" #: A reference to the widget created by the proxy. widget = Typed(AppBarLayout) # ------------------------------------------------------------------------- # Initialization API # -------------------------------------------------------------------------
[docs] def create_widget(self): """Create the underlying widget.""" self.widget = AppBarLayout(self.get_context())
[docs] def init_widget(self): super().init_widget() w = self.widget w.addOnOffsetChangedListener(w.getId()) w.onOffsetChanged.connect(self.on_offset_changed)
def on_offset_changed(self, layout, offset): d = self.declaration d.vertical_offset = offset def set_expanded(self, expanded): self.widget.setExpanded(expanded)