• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.xtremelabs.robolectric.shadows;
2 
3 import android.widget.RadioGroup;
4 import com.xtremelabs.robolectric.internal.Implementation;
5 import com.xtremelabs.robolectric.internal.Implements;
6 import com.xtremelabs.robolectric.internal.RealObject;
7 
8 import static android.widget.RadioGroup.OnCheckedChangeListener;
9 
10 @SuppressWarnings({"UnusedDeclaration"})
11 @Implements(RadioGroup.class)
12 public class ShadowRadioGroup extends ShadowLinearLayout {
13     @RealObject
14     protected RadioGroup realGroup;
15 
16     private int checkedRadioButtonId = -1;
17     private OnCheckedChangeListener onCheckedChangeListener;
18 
19     @Implementation
getCheckedRadioButtonId()20     public int getCheckedRadioButtonId() {
21         return checkedRadioButtonId;
22     }
23 
24     @Implementation
check(int id)25     public void check(int id) {
26         checkedRadioButtonId = id;
27         notifyListener();
28     }
29 
30     @Implementation
clearCheck()31     public void clearCheck() {
32         notifyListener();
33         checkedRadioButtonId = -1;
34         notifyListener();
35     }
36 
notifyListener()37     private void notifyListener() {
38         if (onCheckedChangeListener != null) {
39             onCheckedChangeListener.onCheckedChanged(realGroup, checkedRadioButtonId);
40         }
41     }
42 
43     @Implementation
setOnCheckedChangeListener(OnCheckedChangeListener listener)44     public void setOnCheckedChangeListener(OnCheckedChangeListener listener) {
45         onCheckedChangeListener = listener;
46     }
47 
getOnCheckedChangeListener()48     public OnCheckedChangeListener getOnCheckedChangeListener() {
49     	return onCheckedChangeListener;
50     }
51 }
52