1 /* 2 * Copyright (C) 2008 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 android.widget.cts; 18 19 import static org.junit.Assert.assertEquals; 20 import static org.junit.Assert.assertFalse; 21 import static org.junit.Assert.assertNotNull; 22 import static org.junit.Assert.assertSame; 23 import static org.junit.Assert.assertTrue; 24 import static org.junit.Assert.fail; 25 26 import android.Manifest; 27 import android.app.Activity; 28 import android.content.Context; 29 import android.util.AttributeSet; 30 import android.util.Xml; 31 import android.view.Gravity; 32 import android.view.View; 33 import android.view.ViewGroup; 34 import android.view.ViewGroup.OnHierarchyChangeListener; 35 import android.view.accessibility.AccessibilityNodeInfo; 36 import android.widget.LinearLayout; 37 import android.widget.RadioButton; 38 import android.widget.RadioGroup; 39 import android.widget.RadioGroup.LayoutParams; 40 import android.widget.RadioGroup.OnCheckedChangeListener; 41 import android.widget.RelativeLayout; 42 43 import androidx.test.annotation.UiThreadTest; 44 import androidx.test.filters.SmallTest; 45 import androidx.test.rule.ActivityTestRule; 46 import androidx.test.runner.AndroidJUnit4; 47 48 import com.android.compatibility.common.util.AdoptShellPermissionsRule; 49 50 import org.junit.Before; 51 import org.junit.Rule; 52 import org.junit.Test; 53 import org.junit.runner.RunWith; 54 import org.xmlpull.v1.XmlPullParser; 55 import org.xmlpull.v1.XmlPullParserException; 56 57 import java.io.IOException; 58 import java.util.Vector; 59 60 /** 61 * Test {@link RadioGroup}. 62 */ 63 @SmallTest 64 @RunWith(AndroidJUnit4.class) 65 public class RadioGroupTest { 66 private Activity mActivity; 67 private RadioGroup mRadioGroup; 68 69 @Rule(order = 0) 70 public AdoptShellPermissionsRule mAdoptShellPermissionsRule = new AdoptShellPermissionsRule( 71 androidx.test.platform.app.InstrumentationRegistry 72 .getInstrumentation().getUiAutomation(), 73 Manifest.permission.START_ACTIVITIES_FROM_SDK_SANDBOX); 74 75 @Rule(order = 1) 76 public ActivityTestRule<RadioGroupCtsActivity> mActivityRule = 77 new ActivityTestRule<>(RadioGroupCtsActivity.class); 78 79 @Before setup()80 public void setup() { 81 mActivity = mActivityRule.getActivity(); 82 mRadioGroup = (RadioGroup) mActivity.findViewById(R.id.radio_group); 83 } 84 85 @Test testConstructors()86 public void testConstructors() { 87 new RadioGroup(mActivity); 88 89 AttributeSet attrs = getAttributeSet(R.layout.radiogroup_1); 90 new RadioGroup(mActivity, attrs); 91 new RadioGroup(mActivity, null); 92 } 93 94 @UiThreadTest 95 @Test testSetOnHierarchyChangeListener()96 public void testSetOnHierarchyChangeListener() { 97 MockOnHierarchyChangeListener listener = new MockOnHierarchyChangeListener(); 98 mRadioGroup.setOnHierarchyChangeListener(listener); 99 100 View button3 = mRadioGroup.findViewById(R.id.radio_button_3); 101 listener.reset(); 102 mRadioGroup.removeView(button3); 103 assertSame(mRadioGroup, listener.getOnChildViewRemovedParentParam()); 104 assertSame(button3, listener.getOnChildViewRemovedChildParam()); 105 106 listener.reset(); 107 mRadioGroup.addView(button3); 108 assertSame(mRadioGroup, listener.getOnChildViewAddedParentParam()); 109 assertSame(button3, listener.getOnChildViewAddedChildParam()); 110 111 // Set listener to null 112 mRadioGroup.setOnHierarchyChangeListener(null); 113 // and no exceptions thrown in the following method calls 114 mRadioGroup.removeView(button3); 115 mRadioGroup.addView(button3); 116 } 117 118 @UiThreadTest 119 @Test testInternalPassThroughHierarchyChangeListener()120 public void testInternalPassThroughHierarchyChangeListener() { 121 RadioButton newButton = new RadioButton(mActivity); 122 123 assertEquals(View.NO_ID, newButton.getId()); 124 mRadioGroup.addView(newButton, new RadioGroup.LayoutParams( 125 RadioGroup.LayoutParams.WRAP_CONTENT, RadioGroup.LayoutParams.WRAP_CONTENT)); 126 // aapt-generated IDs have a nonzero high byte; check that the ID generated by 127 // RadioGroup falls within a range that will not collide with aapt IDs. 128 assertEquals(0, newButton.getId() & 0xFF000000); 129 } 130 131 @UiThreadTest 132 @Test testInternalCheckedStateTracker()133 public void testInternalCheckedStateTracker() { 134 RadioButton newButton = new RadioButton(mActivity); 135 // inject the tracker to the button when the button is added by 136 // CompoundButton#setOnCheckedChangeWidgetListener(OnCheckedChangeListener) 137 mRadioGroup.addView(newButton, new RadioGroup.LayoutParams( 138 RadioGroup.LayoutParams.WRAP_CONTENT, RadioGroup.LayoutParams.WRAP_CONTENT)); 139 MockOnCheckedChangeListener listener = new MockOnCheckedChangeListener(); 140 mRadioGroup.setOnCheckedChangeListener(listener); 141 142 listener.reset(); 143 newButton.setChecked(true); 144 // the tracker informs the checked state change of the button to the group 145 assertHasCalledOnCheckedChanged(listener); 146 147 listener.reset(); 148 // the tracker informs the checked state change of the button to the group 149 newButton.setChecked(false); 150 assertHasCalledOnCheckedChanged(listener); 151 152 // remove the tracker from the button when the button is removed 153 mRadioGroup.removeView(newButton); 154 listener.reset(); 155 newButton.setChecked(true); 156 assertHaveNotCalledOnCheckedChanged(listener); 157 158 listener.reset(); 159 newButton.setChecked(false); 160 assertHaveNotCalledOnCheckedChanged(listener); 161 } 162 163 @UiThreadTest 164 @Test testGetCheckedRadioButtonId()165 public void testGetCheckedRadioButtonId() { 166 assertEquals(-1, mRadioGroup.getCheckedRadioButtonId()); 167 168 mRadioGroup.check(R.id.radio_button_0); 169 assertEquals(R.id.radio_button_0, mRadioGroup.getCheckedRadioButtonId()); 170 171 mRadioGroup.check(R.id.radio_button_3); 172 assertEquals(R.id.radio_button_3, mRadioGroup.getCheckedRadioButtonId()); 173 174 // None of the buttons inside the group has of of the following IDs 175 mRadioGroup.check(4); 176 assertEquals(4, mRadioGroup.getCheckedRadioButtonId()); 177 178 mRadioGroup.check(-1); 179 assertEquals(-1, mRadioGroup.getCheckedRadioButtonId()); 180 181 mRadioGroup.check(-3); 182 assertEquals(-3, mRadioGroup.getCheckedRadioButtonId()); 183 } 184 185 @UiThreadTest 186 @Test testClearCheck()187 public void testClearCheck() { 188 MockOnCheckedChangeListener listener = new MockOnCheckedChangeListener(); 189 mRadioGroup.setOnCheckedChangeListener(listener); 190 191 mRadioGroup.check(R.id.radio_button_3); 192 assertEquals(R.id.radio_button_3, mRadioGroup.getCheckedRadioButtonId()); 193 194 listener.reset(); 195 mRadioGroup.clearCheck(); 196 assertEquals(-1, mRadioGroup.getCheckedRadioButtonId()); 197 assertHasCalledOnCheckedChanged(listener); 198 // uncheck the original button 199 assertOnCheckedChangedParams(listener, 0, mRadioGroup, R.id.radio_button_3); 200 201 // None of the buttons inside the group has of of the following IDs 202 mRadioGroup.check(4); 203 assertEquals(4, mRadioGroup.getCheckedRadioButtonId()); 204 205 listener.reset(); 206 mRadioGroup.clearCheck(); 207 assertEquals(-1, mRadioGroup.getCheckedRadioButtonId()); 208 // why the method is called while none of the button is checked or unchecked? 209 assertHasCalledOnCheckedChanged(listener); 210 assertOnCheckedChangedParams(listener, 0, mRadioGroup, -1); 211 212 mRadioGroup.check(-1); 213 assertEquals(-1, mRadioGroup.getCheckedRadioButtonId()); 214 215 listener.reset(); 216 mRadioGroup.clearCheck(); 217 assertEquals(-1, mRadioGroup.getCheckedRadioButtonId()); 218 // why the method is called while none of the button is checked or unchecked? 219 assertHasCalledOnCheckedChanged(listener); 220 assertOnCheckedChangedParams(listener, 0, mRadioGroup, -1); 221 } 222 223 @UiThreadTest 224 @Test testCheck()225 public void testCheck() { 226 MockOnCheckedChangeListener listener = new MockOnCheckedChangeListener(); 227 mRadioGroup.setOnCheckedChangeListener(listener); 228 assertEquals(-1, mRadioGroup.getCheckedRadioButtonId()); 229 230 listener.reset(); 231 mRadioGroup.check(R.id.radio_button_0); 232 assertHasCalledOnCheckedChanged(listener); 233 assertOnCheckedChangedParams(listener, 0, mRadioGroup, R.id.radio_button_0); 234 235 listener.reset(); 236 mRadioGroup.check(R.id.radio_button_1); 237 assertHasCalledOnCheckedChanged(listener); 238 // uncheck the original button 239 assertOnCheckedChangedParams(listener, 0, mRadioGroup, R.id.radio_button_0); 240 // check the new button 241 assertOnCheckedChangedParams(listener, 1, mRadioGroup, R.id.radio_button_1); 242 243 listener.reset(); 244 mRadioGroup.check(-1); 245 assertHasCalledOnCheckedChanged(listener); 246 // uncheck the original button 247 assertOnCheckedChangedParams(listener, 0, mRadioGroup, R.id.radio_button_1); 248 assertOnCheckedChangedParams(listener, 1, mRadioGroup, -1); 249 250 // None of the buttons inside the group has of of the following IDs 251 listener.reset(); 252 mRadioGroup.check(-1); 253 // why the method is called while none of the inside buttons has been changed 254 assertHasCalledOnCheckedChanged(listener); 255 assertOnCheckedChangedParams(listener, 0, mRadioGroup, -1); 256 257 listener.reset(); 258 mRadioGroup.check(4); 259 // why the method is called while none of the inside buttons has been changed 260 assertHasCalledOnCheckedChanged(listener); 261 assertOnCheckedChangedParams(listener, 0, mRadioGroup, 4); 262 263 // Set listener to null 264 mRadioGroup.setOnCheckedChangeListener(null); 265 // no exceptions thrown during the following method 266 mRadioGroup.check(0); 267 } 268 269 @UiThreadTest 270 @Test testSetOnCheckedChangeListener()271 public void testSetOnCheckedChangeListener() { 272 MockOnCheckedChangeListener listener = new MockOnCheckedChangeListener(); 273 mRadioGroup.setOnCheckedChangeListener(listener); 274 275 listener.reset(); 276 mRadioGroup.check(R.id.radio_button_0); 277 assertHasCalledOnCheckedChanged(listener); 278 279 // does not call the method if the button the id is already checked 280 listener.reset(); 281 mRadioGroup.check(R.id.radio_button_0); 282 assertHaveNotCalledOnCheckedChanged(listener); 283 284 // call the method if none of the buttons inside the group has the id 285 listener.reset(); 286 mRadioGroup.check(-3); 287 assertHasCalledOnCheckedChanged(listener); 288 289 // does not call the method if the button the id is already checked 290 // and none of the buttons inside the group has the id 291 listener.reset(); 292 mRadioGroup.check(-3); 293 assertHaveNotCalledOnCheckedChanged(listener); 294 295 // always call the method if the checked id is -1 296 listener.reset(); 297 mRadioGroup.clearCheck(); 298 assertHasCalledOnCheckedChanged(listener); 299 300 listener.reset(); 301 mRadioGroup.check(-1); 302 assertHasCalledOnCheckedChanged(listener); 303 304 // Set listener to null 305 mRadioGroup.setOnCheckedChangeListener(null); 306 // no exceptions thrown during the following method 307 mRadioGroup.check(0); 308 } 309 310 @Test testGenerateLayoutParams()311 public void testGenerateLayoutParams() { 312 RadioGroup.LayoutParams layoutParams = 313 mRadioGroup.generateLayoutParams((AttributeSet) null); 314 assertNotNull(layoutParams); 315 // default values 316 assertEquals(0.0, layoutParams.weight, 0); 317 assertEquals(-1, layoutParams.gravity); 318 assertEquals(0, layoutParams.leftMargin); 319 assertEquals(0, layoutParams.topMargin); 320 assertEquals(0, layoutParams.rightMargin); 321 assertEquals(0, layoutParams.bottomMargin); 322 assertEquals(LayoutParams.WRAP_CONTENT, layoutParams.width); 323 assertEquals(LayoutParams.WRAP_CONTENT, layoutParams.height); 324 325 AttributeSet attrs = getAttributeSet(R.layout.radiogroup_1); 326 layoutParams = mRadioGroup.generateLayoutParams(attrs); 327 // values from layout 328 assertNotNull(layoutParams); 329 assertEquals(0.5, layoutParams.weight, 0); 330 assertEquals(Gravity.BOTTOM, layoutParams.gravity); 331 assertEquals(5, layoutParams.leftMargin); 332 assertEquals(5, layoutParams.topMargin); 333 assertEquals(5, layoutParams.rightMargin); 334 assertEquals(5, layoutParams.bottomMargin); 335 assertEquals(LayoutParams.MATCH_PARENT, layoutParams.width); 336 assertEquals(LayoutParams.MATCH_PARENT, layoutParams.height); 337 } 338 339 @Test testCheckLayoutParams()340 public void testCheckLayoutParams() { 341 MockRadioGroup mRadioGroupWrapper = new MockRadioGroup(mActivity); 342 343 assertFalse(mRadioGroupWrapper.checkLayoutParams(null)); 344 345 RelativeLayout.LayoutParams relativeParams = new RelativeLayout.LayoutParams( 346 RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT); 347 assertFalse(mRadioGroupWrapper.checkLayoutParams(relativeParams)); 348 349 LinearLayout.LayoutParams linearParams = new LinearLayout.LayoutParams( 350 LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT); 351 assertFalse(mRadioGroupWrapper.checkLayoutParams(linearParams)); 352 353 RadioGroup.LayoutParams radioParams = new RadioGroup.LayoutParams( 354 RadioGroup.LayoutParams.MATCH_PARENT, RadioGroup.LayoutParams.MATCH_PARENT); 355 assertTrue(mRadioGroupWrapper.checkLayoutParams(radioParams)); 356 } 357 358 @Test testGenerateDefaultLayoutParams()359 public void testGenerateDefaultLayoutParams() { 360 MockRadioGroup radioGroupWrapper = new MockRadioGroup(mActivity); 361 LinearLayout.LayoutParams p = radioGroupWrapper.generateDefaultLayoutParams(); 362 363 assertTrue(p instanceof RadioGroup.LayoutParams); 364 assertEquals(RadioGroup.LayoutParams.WRAP_CONTENT, p.width); 365 assertEquals(RadioGroup.LayoutParams.WRAP_CONTENT, p.height); 366 } 367 368 @UiThreadTest 369 @Test testOnFinishInflate()370 public void testOnFinishInflate() { 371 MockRadioGroup radioGroup = new MockRadioGroup(mActivity); 372 int checkId = 100; 373 radioGroup.check(checkId); 374 // the button is added after the check(int)method 375 // and it not checked though it has exactly the checkId 376 RadioButton button = new RadioButton(mActivity); 377 button.setId(checkId); 378 radioGroup.addView(button, new LinearLayout.LayoutParams( 379 LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); 380 MockOnCheckedChangeListener listener = new MockOnCheckedChangeListener(); 381 radioGroup.setOnCheckedChangeListener(listener); 382 383 // check the button which id is CheckedRadioButtonId 384 listener.reset(); 385 assertFalse(button.isChecked()); 386 radioGroup.onFinishInflate(); 387 assertTrue(button.isChecked()); 388 assertHasCalledOnCheckedChanged(listener); 389 assertEquals(checkId, radioGroup.getCheckedRadioButtonId()); 390 391 radioGroup = new MockRadioGroup(mActivity); 392 button = new RadioButton(mActivity); 393 radioGroup.addView(button, new LinearLayout.LayoutParams( 394 LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); 395 listener = new MockOnCheckedChangeListener(); 396 radioGroup.setOnCheckedChangeListener(listener); 397 398 // nothing happens if checkedRadioButtonId is -1 399 assertEquals(-1, radioGroup.getCheckedRadioButtonId()); 400 assertFalse(button.isChecked()); 401 listener.reset(); 402 radioGroup.onFinishInflate(); 403 assertHaveNotCalledOnCheckedChanged(listener); 404 assertEquals(-1, radioGroup.getCheckedRadioButtonId()); 405 assertFalse(button.isChecked()); 406 } 407 408 @UiThreadTest 409 @Test testAddView()410 public void testAddView() { 411 mRadioGroup.check(R.id.radio_button_0); 412 assertEquals(R.id.radio_button_0, mRadioGroup.getCheckedRadioButtonId()); 413 assertEquals(4, mRadioGroup.getChildCount()); 414 415 int id = R.id.radio_button_3 + 10; 416 RadioButton choice4 = new RadioButton(mActivity); 417 choice4.setText("choice4"); 418 choice4.setId(id); 419 choice4.setChecked(true); 420 mRadioGroup.addView(choice4, 4, new ViewGroup.LayoutParams(100, 200)); 421 assertEquals(id, mRadioGroup.getCheckedRadioButtonId()); 422 assertEquals(5, mRadioGroup.getChildCount()); 423 } 424 425 @UiThreadTest 426 @Test testOnInitializeAccessibilityNodeInfo_populatesCollectionInfo()427 public void testOnInitializeAccessibilityNodeInfo_populatesCollectionInfo() { 428 AccessibilityNodeInfo info = AccessibilityNodeInfo.obtain(); 429 mRadioGroup.onInitializeAccessibilityNodeInfo(info); 430 431 AccessibilityNodeInfo.CollectionInfo colInfo = info.getCollectionInfo(); 432 assertNotNull(colInfo); 433 assertEquals(colInfo.getRowCount(), mRadioGroup.getChildCount()); 434 } 435 436 @UiThreadTest 437 @Test testOnInitializeAccessibilityNodeInfo_populatesCollectionItemInfo()438 public void testOnInitializeAccessibilityNodeInfo_populatesCollectionItemInfo() { 439 RadioButton child = (RadioButton) mRadioGroup.getChildAt(1); 440 child.setChecked(true); 441 442 AccessibilityNodeInfo info = AccessibilityNodeInfo.obtain(); 443 child.onInitializeAccessibilityNodeInfo(info); 444 445 AccessibilityNodeInfo.CollectionItemInfo colItemInfo = info.getCollectionItemInfo(); 446 assertEquals(colItemInfo.getRowIndex(), 1); 447 assertEquals(colItemInfo.isSelected(), true); 448 } 449 450 @UiThreadTest 451 @Test testOnInitializeAccessibilityNodeInfo_populatesColInfoWithInvalidCount()452 public void testOnInitializeAccessibilityNodeInfo_populatesColInfoWithInvalidCount() { 453 for (int i = 0; i < mRadioGroup.getChildCount(); i++) { 454 ((RadioButton) mRadioGroup.getChildAt(i)).setText(""); 455 } 456 AccessibilityNodeInfo info = AccessibilityNodeInfo.obtain(); 457 mRadioGroup.onInitializeAccessibilityNodeInfo(info); 458 459 AccessibilityNodeInfo.CollectionInfo colInfo = info.getCollectionInfo(); 460 assertNotNull(colInfo); 461 assertEquals(colInfo.getRowCount(), 0); 462 } 463 getAttributeSet(int resId)464 private AttributeSet getAttributeSet(int resId) { 465 XmlPullParser parser = mActivity.getResources().getLayout(resId); 466 assertNotNull(parser); 467 int type = 0; 468 try { 469 while ((type = parser.next()) != XmlPullParser.START_TAG 470 && type != XmlPullParser.END_DOCUMENT) { 471 // Empty 472 } 473 } catch (XmlPullParserException e) { 474 fail(e.getMessage()); 475 } catch (IOException e) { 476 fail(e.getMessage()); 477 } 478 479 assertEquals("No RadioGroup element found", XmlPullParser.START_TAG, type); 480 assertEquals("The first element is not RadioGroup", "RadioGroup", parser.getName()); 481 return Xml.asAttributeSet(parser); 482 } 483 assertHaveNotCalledOnCheckedChanged(MockOnCheckedChangeListener listener)484 private void assertHaveNotCalledOnCheckedChanged(MockOnCheckedChangeListener listener) { 485 assertEquals(0, listener.getOnCheckedChangedGroupParams().size()); 486 assertEquals(0, listener.getOnCheckedChangedCheckedIdParams().size()); 487 } 488 assertHasCalledOnCheckedChanged(MockOnCheckedChangeListener listener)489 private void assertHasCalledOnCheckedChanged(MockOnCheckedChangeListener listener) { 490 assertTrue(listener.getOnCheckedChangedGroupParams().size() > 0); 491 assertTrue(listener.getOnCheckedChangedCheckedIdParams().size() > 0); 492 } 493 assertOnCheckedChangedParams(MockOnCheckedChangeListener listener, int time, RadioGroup paramGroup, int paramCheckedId)494 private void assertOnCheckedChangedParams(MockOnCheckedChangeListener listener, int time, 495 RadioGroup paramGroup, int paramCheckedId) { 496 assertSame(paramGroup, 497 listener.getOnCheckedChangedGroupParams().get(time)); 498 assertEquals(paramCheckedId, listener 499 .getOnCheckedChangedCheckedIdParams().get(time).intValue()); 500 } 501 502 private class MockOnCheckedChangeListener implements OnCheckedChangeListener { 503 private Vector<RadioGroup> mOnCheckedChangedGroupParams = new Vector<RadioGroup>(); 504 505 private Vector<Integer> mOnCheckedChangedCheckedIdParams = new Vector<Integer>(); 506 getOnCheckedChangedGroupParams()507 public Vector<RadioGroup> getOnCheckedChangedGroupParams() { 508 return mOnCheckedChangedGroupParams; 509 } 510 getOnCheckedChangedCheckedIdParams()511 public Vector<Integer> getOnCheckedChangedCheckedIdParams() { 512 return mOnCheckedChangedCheckedIdParams; 513 } 514 reset()515 public void reset() { 516 mOnCheckedChangedGroupParams.clear(); 517 mOnCheckedChangedCheckedIdParams.clear(); 518 } 519 onCheckedChanged(RadioGroup group, int checkedId)520 public void onCheckedChanged(RadioGroup group, int checkedId) { 521 mOnCheckedChangedGroupParams.add(group); 522 mOnCheckedChangedCheckedIdParams.add(checkedId); 523 } 524 } 525 526 private class MockOnHierarchyChangeListener implements OnHierarchyChangeListener { 527 private View mOnChildViewAddedParentParam; 528 529 private View mOnChildViewAddedChildParam; 530 531 private View mOnChildViewRemovedParentParam; 532 533 private View mOnChildViewRemovedChildParam; 534 getOnChildViewAddedParentParam()535 public View getOnChildViewAddedParentParam() { 536 return mOnChildViewAddedParentParam; 537 } 538 getOnChildViewAddedChildParam()539 public View getOnChildViewAddedChildParam() { 540 return mOnChildViewAddedChildParam; 541 } 542 getOnChildViewRemovedParentParam()543 public View getOnChildViewRemovedParentParam() { 544 return mOnChildViewRemovedParentParam; 545 } 546 getOnChildViewRemovedChildParam()547 public View getOnChildViewRemovedChildParam() { 548 return mOnChildViewRemovedChildParam; 549 } 550 reset()551 public void reset() { 552 mOnChildViewAddedParentParam = null; 553 mOnChildViewAddedChildParam = null; 554 mOnChildViewRemovedParentParam = null; 555 mOnChildViewRemovedChildParam = null; 556 } 557 onChildViewAdded(View parent, View child)558 public void onChildViewAdded(View parent, View child) { 559 mOnChildViewAddedParentParam = parent; 560 mOnChildViewAddedChildParam = child; 561 } 562 onChildViewRemoved(View parent, View child)563 public void onChildViewRemoved(View parent, View child) { 564 mOnChildViewRemovedParentParam = parent; 565 mOnChildViewRemovedChildParam = child; 566 } 567 } 568 569 public static class MockRadioGroup extends RadioGroup { MockRadioGroup(Context context)570 public MockRadioGroup(Context context) { 571 super(context); 572 } 573 574 @Override checkLayoutParams(ViewGroup.LayoutParams p)575 protected boolean checkLayoutParams(ViewGroup.LayoutParams p) { 576 return super.checkLayoutParams(p); 577 } 578 579 @Override generateDefaultLayoutParams()580 protected android.widget.LinearLayout.LayoutParams generateDefaultLayoutParams() { 581 return super.generateDefaultLayoutParams(); 582 } 583 584 @Override onFinishInflate()585 protected void onFinishInflate() { 586 super.onFinishInflate(); 587 } 588 } 589 } 590