Search in sources :

Example 1 with ViewSwitcher

use of android.widget.ViewSwitcher in project materialistic by hidroh.

the class WebFragmentTest method testSearch.

@Test
public void testSearch() {
    ShadowLocalBroadcastManager.getInstance(activity).sendBroadcast(new Intent(WebFragment.ACTION_FULLSCREEN).putExtra(WebFragment.EXTRA_FULLSCREEN, true));
    activity.findViewById(R.id.button_find).performClick();
    ViewSwitcher controlSwitcher = (ViewSwitcher) activity.findViewById(R.id.control_switcher);
    assertThat(controlSwitcher.getDisplayedChild()).isEqualTo(1);
    ShadowWebView shadowWebView = (ShadowWebView) ShadowExtractor.extract(activity.findViewById(R.id.web_view));
    // no query
    EditText editText = (EditText) activity.findViewById(R.id.edittext);
    shadowOf(editText).getOnEditorActionListener().onEditorAction(null, 0, null);
    assertThat(activity.findViewById(R.id.button_next)).isDisabled();
    // with results
    shadowWebView.setFindCount(1);
    editText.setText("abc");
    shadowOf(editText).getOnEditorActionListener().onEditorAction(null, 0, null);
    assertThat(activity.findViewById(R.id.button_next)).isEnabled();
    activity.findViewById(R.id.button_next).performClick();
    assertThat(shadowWebView.getFindIndex()).isEqualTo(1);
    activity.findViewById(R.id.button_clear).performClick();
    assertThat(editText).isEmpty();
    assertThat(controlSwitcher.getDisplayedChild()).isEqualTo(0);
    // with no results
    shadowWebView.setFindCount(0);
    editText.setText("abc");
    shadowOf(editText).getOnEditorActionListener().onEditorAction(null, 0, null);
    assertThat(activity.findViewById(R.id.button_next)).isDisabled();
    assertThat(ShadowToast.getTextOfLatestToast()).contains(activity.getString(R.string.no_matches));
}
Also used : EditText(android.widget.EditText) ShadowWebView(io.github.hidroh.materialistic.test.shadow.ShadowWebView) Intent(android.content.Intent) ViewSwitcher(android.widget.ViewSwitcher) Test(org.junit.Test)

Example 2 with ViewSwitcher

use of android.widget.ViewSwitcher in project SmartAndroidSource by jaychou2012.

the class AutoLoading method initializeViewContainer.

private void initializeViewContainer() {
    setDefaultViews();
    mSwitcher = new ViewSwitcher(mContext);
    ViewSwitcher.LayoutParams params = new ViewSwitcher.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    mSwitcher.setLayoutParams(params);
    ViewGroup group = (ViewGroup) mTargetView.getParent();
    int index = 0;
    Clonner target = new Clonner(mTargetView);
    if (group != null) {
        index = group.indexOfChild(mTargetView);
        group.removeView(mTargetView);
    }
    mSwitcher.addView(mContainer, 0);
    mSwitcher.addView(target.getmView(), 1);
    mSwitcher.setDisplayedChild(1);
    if (group != null) {
        group.addView(mSwitcher, index);
    } else {
        ((Activity) mContext).setContentView(mSwitcher);
    }
}
Also used : LayoutParams(android.widget.LinearLayout.LayoutParams) ViewGroup(android.view.ViewGroup) Activity(android.app.Activity) ViewSwitcher(android.widget.ViewSwitcher)

Aggregations

ViewSwitcher (android.widget.ViewSwitcher)2 Activity (android.app.Activity)1 Intent (android.content.Intent)1 ViewGroup (android.view.ViewGroup)1 EditText (android.widget.EditText)1 LayoutParams (android.widget.LinearLayout.LayoutParams)1 ShadowWebView (io.github.hidroh.materialistic.test.shadow.ShadowWebView)1 Test (org.junit.Test)1