Home | History | Annotate | Download | only in menu
      1 /*
      2  * Copyright (C) 2006 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package androidx.appcompat.view.menu;
     18 
     19 import static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP;
     20 
     21 import android.graphics.drawable.Drawable;
     22 
     23 import androidx.annotation.RestrictTo;
     24 
     25 /**
     26  * Minimal interface for a menu view.  {@link #initialize(MenuBuilder)} must be called for the
     27  * menu to be functional.
     28  *
     29  * @hide
     30  */
     31 @RestrictTo(LIBRARY_GROUP)
     32 public interface MenuView {
     33     /**
     34      * Initializes the menu to the given menu. This should be called after the
     35      * view is inflated.
     36      *
     37      * @param menu The menu that this MenuView should display.
     38      */
     39     void initialize(MenuBuilder menu);
     40 
     41     /**
     42      * Returns the default animations to be used for this menu when entering/exiting.
     43      * @return A resource ID for the default animations to be used for this menu.
     44      */
     45     int getWindowAnimations();
     46 
     47     /**
     48      * Minimal interface for a menu item view.  {@link #initialize(MenuItemImpl, int)} must be called
     49      * for the item to be functional.
     50      */
     51     interface ItemView {
     52         /**
     53          * Initializes with the provided MenuItemData.  This should be called after the view is
     54          * inflated.
     55          * @param itemData The item that this ItemView should display.
     56          * @param menuType The type of this menu, one of
     57          *            {@link MenuBuilder#TYPE_ICON}, {@link MenuBuilder#TYPE_EXPANDED},
     58          *            {@link MenuBuilder#TYPE_DIALOG}).
     59          */
     60         void initialize(MenuItemImpl itemData, int menuType);
     61 
     62         /**
     63          * Gets the item data that this view is displaying.
     64          * @return the item data, or null if there is not one
     65          */
     66         MenuItemImpl getItemData();
     67 
     68         /**
     69          * Sets the title of the item view.
     70          * @param title The title to set.
     71          */
     72         void setTitle(CharSequence title);
     73 
     74         /**
     75          * Sets the enabled state of the item view.
     76          * @param enabled Whether the item view should be enabled.
     77          */
     78         void setEnabled(boolean enabled);
     79 
     80         /**
     81          * Displays the checkbox for the item view.  This does not ensure the item view will be
     82          * checked, for that use {@link #setChecked}.
     83          * @param checkable Whether to display the checkbox or to hide it
     84          */
     85         void setCheckable(boolean checkable);
     86 
     87         /**
     88          * Checks the checkbox for the item view.  If the checkbox is hidden, it will NOT be
     89          * made visible, call {@link #setCheckable(boolean)} for that.
     90          * @param checked Whether the checkbox should be checked
     91          */
     92         void setChecked(boolean checked);
     93 
     94         /**
     95          * Sets the shortcut for the item.
     96          * @param showShortcut Whether a shortcut should be shown(if false, the value of
     97          * shortcutKey should be ignored).
     98          * @param shortcutKey The shortcut key that should be shown on the ItemView.
     99          */
    100         void setShortcut(boolean showShortcut, char shortcutKey);
    101 
    102         /**
    103          * Set the icon of this item view.
    104          * @param icon The icon of this item. null to hide the icon.
    105          */
    106         void setIcon(Drawable icon);
    107 
    108         /**
    109          * Whether this item view prefers displaying the condensed title rather
    110          * than the normal title. If a condensed title is not available, the
    111          * normal title will be used.
    112          *
    113          * @return Whether this item view prefers displaying the condensed
    114          *         title.
    115          */
    116         boolean prefersCondensedTitle();
    117 
    118         /**
    119          * Whether this item view shows an icon.
    120          *
    121          * @return Whether this item view shows an icon.
    122          */
    123         boolean showsIcon();
    124     }
    125 }
    126