• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package org.robolectric.shadows;
2 
3 import static org.robolectric.shadow.api.Shadow.directlyOn;
4 
5 import android.widget.PopupMenu;
6 import org.robolectric.RuntimeEnvironment;
7 import org.robolectric.annotation.Implementation;
8 import org.robolectric.annotation.Implements;
9 import org.robolectric.annotation.RealObject;
10 import org.robolectric.shadow.api.Shadow;
11 
12 @Implements(PopupMenu.class)
13 public class ShadowPopupMenu {
14 
15   @RealObject
16   private PopupMenu realPopupMenu;
17 
18   private boolean isShowing;
19   private PopupMenu.OnMenuItemClickListener onMenuItemClickListener;
20 
21   @Implementation
show()22   protected void show() {
23     this.isShowing = true;
24     setLatestPopupMenu(this);
25     directlyOn(realPopupMenu, PopupMenu.class).show();
26   }
27 
28   @Implementation
dismiss()29   protected void dismiss() {
30     this.isShowing = false;
31     directlyOn(realPopupMenu, PopupMenu.class).dismiss();
32   }
33 
34   @Implementation
setOnMenuItemClickListener(PopupMenu.OnMenuItemClickListener listener)35   protected void setOnMenuItemClickListener(PopupMenu.OnMenuItemClickListener listener) {
36     this.onMenuItemClickListener = listener;
37     directlyOn(realPopupMenu, PopupMenu.class).setOnMenuItemClickListener(listener);
38   }
39 
isShowing()40   public boolean isShowing() {
41     return isShowing;
42   }
43 
getLatestPopupMenu()44   public static PopupMenu getLatestPopupMenu() {
45     ShadowApplication shadowApplication = Shadow.extract(RuntimeEnvironment.application);
46     ShadowPopupMenu popupMenu = shadowApplication.getLatestPopupMenu();
47     return popupMenu == null ? null : popupMenu.realPopupMenu;
48   }
49 
setLatestPopupMenu(ShadowPopupMenu latestPopupMenu)50   public static void setLatestPopupMenu(ShadowPopupMenu latestPopupMenu) {
51     ShadowApplication shadowApplication = Shadow.extract(RuntimeEnvironment.application);
52     if (shadowApplication != null) shadowApplication.setLatestPopupMenu(latestPopupMenu);
53   }
54 
getOnMenuItemClickListener()55   public PopupMenu.OnMenuItemClickListener getOnMenuItemClickListener() {
56     return onMenuItemClickListener;
57   }
58 }
59