Home | History | Annotate | Download | only in view
      1 /*
      2  * Copyright 2018 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.core.view;
     18 
     19 import android.annotation.SuppressLint;
     20 import android.view.Menu;
     21 import android.view.MenuItem;
     22 
     23 import androidx.core.internal.view.SupportMenu;
     24 import androidx.core.os.BuildCompat;
     25 
     26 /**
     27  * Helper for accessing features in {@link android.view.Menu}.
     28  */
     29 public final class MenuCompat {
     30     /**
     31      * Call {@link MenuItem#setShowAsAction(int) MenuItem.setShowAsAction()}.
     32      *
     33      * @deprecated Use {@link MenuItem#setShowAsAction(int)} directly.
     34      */
     35     @Deprecated
     36     public static void setShowAsAction(MenuItem item, int actionEnum) {
     37         item.setShowAsAction(actionEnum);
     38     }
     39 
     40     /**
     41      * Enable or disable the group dividers.
     42      *
     43      * @param menu Menu to enable/disable dividers on.
     44      * @param enabled True if enabled
     45      */
     46     @SuppressLint("NewApi")
     47     public static void setGroupDividerEnabled(Menu menu, boolean enabled) {
     48         if (menu instanceof SupportMenu) {
     49             ((SupportMenu) menu).setGroupDividerEnabled(enabled);
     50         } else if (BuildCompat.isAtLeastP()) {
     51             menu.setGroupDividerEnabled(enabled);
     52         }
     53     }
     54 
     55     private MenuCompat() {}
     56 }
     57