Source code for enamlnative.android.android_action_menu_view

"""
Copyright (c) 2017, CodeLV.

Distributed under the terms of the MIT License.

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

Created on July 7, 2017

@author: jrm
"""
from atom.api import Atom, Typed, set_default

from enamlnative.widgets.action_menu_view import ProxyActionMenuView

from .android_linear_layout import AndroidLinearLayout, LinearLayout
from .bridge import JavaBridgeObject, JavaMethod, JavaCallback


[docs]class ActionMenuView(LinearLayout): __nativeclass__ = set_default('android.support.v7.widget.ActionMenuView') getMenu = JavaMethod() showOverflowMenu = JavaMethod() hideOverflowMenu = JavaMethod() setOverflowIcon = JavaMethod('android.graphics.drawable') setOnMenuItemClickListener = JavaMethod( 'android.support.v7.widget.ActionMenuView$OnMenuItemClickListener')
onMenuItemClick = JavaCallback('android.view.MenuItem', returns='boolean') super(Atom, self).__init__() __nativeclass__ = set_default('android.view.MenuItem')
[docs]class AndroidActionMenuView(AndroidLinearLayout, ProxyActionMenuView): """ An Android implementation of an Enaml ProxyActionMenuView. """ #: A reference to the widget created by the proxy. widget = Typed(ActionMenuView) # ------------------------------------------------------------------------- # Initialization API # -------------------------------------------------------------------------
[docs] def create_widget(self): """ Create the underlying widget. """
self.widget = ActionMenuView(self.get_context())
[docs] def init_widget(self): """ Initialize the underlying widget. """ super(AndroidActionMenuView, self).init_widget() d = self.declaration w = self.widget #: Kinda hackish, but when we get the menu back, load it w.getMenu().then(self.on_menu) w.setOnMenuItemClickListener(w.getId())
w.onMenuItemClick.connect(self.on_menu_item_click)
[docs] def on_menu(self, menu): """ """
Menu(__id__=menu) # ------------------------------------------------------------------------- # OnMenuItemClickListener API # -------------------------------------------------------------------------
[docs] def on_menu_item_click(self, item):
return False # ------------------------------------------------------------------------- # ProxyActionMenuView API # -------------------------------------------------------------------------
[docs] def set_opened(self, opened): if opened: self.widget.showOverflowMenu() else:
self.widget.hideOverflowMenu()