1 /* 2 * Copyright (C) 2013 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 18 package android.support.v4.view; 19 20 import android.view.MenuItem; 21 22 class MenuItemCompatIcs { expandActionView(MenuItem item)23 public static boolean expandActionView(MenuItem item) { 24 return item.expandActionView(); 25 } 26 collapseActionView(MenuItem item)27 public static boolean collapseActionView(MenuItem item) { 28 return item.collapseActionView(); 29 } 30 isActionViewExpanded(MenuItem item)31 public static boolean isActionViewExpanded(MenuItem item) { 32 return item.isActionViewExpanded(); 33 } 34 setOnActionExpandListener(MenuItem item, SupportActionExpandProxy listener)35 public static MenuItem setOnActionExpandListener(MenuItem item, 36 SupportActionExpandProxy listener) { 37 return item.setOnActionExpandListener(new OnActionExpandListenerWrapper(listener)); 38 } 39 40 /** 41 * Work around the support lib's build dependency chain. The actual API-lib 42 * depends on -ics, but -ics doesn't depend on the API-lib so it doesn't know 43 * that MenuItemCompat.OnActionExpandListener exists. 44 */ 45 interface SupportActionExpandProxy { onMenuItemActionExpand(MenuItem item)46 boolean onMenuItemActionExpand(MenuItem item); onMenuItemActionCollapse(MenuItem item)47 boolean onMenuItemActionCollapse(MenuItem item); 48 } 49 50 // support => framework 51 static class OnActionExpandListenerWrapper implements MenuItem.OnActionExpandListener { 52 private SupportActionExpandProxy mWrapped; 53 OnActionExpandListenerWrapper(SupportActionExpandProxy wrapped)54 public OnActionExpandListenerWrapper(SupportActionExpandProxy wrapped) { 55 mWrapped = wrapped; 56 } 57 58 @Override onMenuItemActionExpand(MenuItem item)59 public boolean onMenuItemActionExpand(MenuItem item) { 60 return mWrapped.onMenuItemActionExpand(item); 61 } 62 63 @Override onMenuItemActionCollapse(MenuItem item)64 public boolean onMenuItemActionCollapse(MenuItem item) { 65 return mWrapped.onMenuItemActionCollapse(item); 66 } 67 } 68 } 69