Search in sources :

Example 6 with SwitchCompat

use of android.support.v7.widget.SwitchCompat in project material-components-android by material-components.

the class NavigationViewTest method testActionLayout.

@Test
public void testActionLayout() {
    // Open our drawer
    onView(withId(R.id.drawer_layout)).perform(openDrawer(GravityCompat.START));
    // There are four conditions to "find" the menu item with action layout (switch):
    // 1. Is in the NavigationView
    // 2. Is direct child of a class that extends RecyclerView
    // 3. Has a child with "people" text
    // 4. Has fully displayed child that extends SwitchCompat
    // Note that condition 2 makes a certain assumption about the internal implementation
    // details of the NavigationMenu, while conditions 3 and 4 aim to be as generic as
    // possible and to not rely on the internal details of the current layout implementation
    // of an individual menu item in NavigationMenu.
    Matcher menuItemMatcher = allOf(isDescendantOfA(withId(R.id.start_drawer)), isChildOfA(isAssignableFrom(RecyclerView.class)), hasDescendant(withText(mMenuStringContent.get(R.id.destination_people))), hasDescendant(allOf(isAssignableFrom(SwitchCompat.class), isCompletelyDisplayed())));
    // While we don't need to perform any action on our row, the invocation of perform()
    // makes our matcher actually run. If for some reason NavigationView fails to inflate and
    // display our SwitchCompat action layout, the next line will fail in the matcher pass.
    onView(menuItemMatcher).perform(click());
    // Check that the full custom view is displayed without title and icon.
    final Resources res = activityTestRule.getActivity().getResources();
    Matcher customItemMatcher = allOf(isDescendantOfA(withId(R.id.start_drawer)), isChildOfA(isAssignableFrom(RecyclerView.class)), hasDescendant(withText(res.getString(R.string.navigate_custom))), hasDescendant(allOf(isAssignableFrom(TextView.class), withEffectiveVisibility(Visibility.GONE))));
    onView(customItemMatcher).perform(click());
}
Also used : Matcher(org.hamcrest.Matcher) TextView(android.widget.TextView) Resources(android.content.res.Resources) SwitchCompat(android.support.v7.widget.SwitchCompat) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test)

Example 7 with SwitchCompat

use of android.support.v7.widget.SwitchCompat in project fresco by facebook.

the class ImageFormatGifFragment method onViewCreated.

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    mSimpleDraweeView = (SimpleDraweeView) view.findViewById(R.id.drawee_view);
    final SwitchCompat switchBackground = (SwitchCompat) view.findViewById(R.id.switch_background);
    switchBackground.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            mSimpleDraweeView.getHierarchy().setBackgroundImage(isChecked ? new CheckerBoardDrawable(getResources()) : null);
        }
    });
    final Spinner spinner = (Spinner) view.findViewById(R.id.spinner);
    spinner.setAdapter(new SimpleUriListAdapter());
    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            final Entry spinnerEntry = SPINNER_ENTRIES[spinner.getSelectedItemPosition()];
            setAnimationUri(spinnerEntry.uri);
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
    spinner.setSelection(0);
}
Also used : Spinner(android.widget.Spinner) TextView(android.widget.TextView) SimpleDraweeView(com.facebook.drawee.view.SimpleDraweeView) View(android.view.View) AdapterView(android.widget.AdapterView) CheckerBoardDrawable(com.facebook.fresco.samples.showcase.misc.CheckerBoardDrawable) AdapterView(android.widget.AdapterView) CompoundButton(android.widget.CompoundButton) SwitchCompat(android.support.v7.widget.SwitchCompat)

Example 8 with SwitchCompat

use of android.support.v7.widget.SwitchCompat in project fresco by facebook.

the class ImageFormatSvgFragment method onViewCreated.

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    mSimpleDraweeView = (SimpleDraweeView) view.findViewById(R.id.drawee_view);
    mSimpleDraweeView.setImageURI(URI_SVG_HALF_TRANSPARENT);
    final SwitchCompat switchBackground = (SwitchCompat) view.findViewById(R.id.switch_background);
    switchBackground.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            mSimpleDraweeView.getHierarchy().setBackgroundImage(isChecked ? new CheckerBoardDrawable(getResources()) : null);
        }
    });
    SwitchCompat switchCompat = (SwitchCompat) view.findViewById(R.id.decoder_switch);
    switchCompat.setChecked(CustomImageFormatConfigurator.isSvgEnabled(getContext()));
    switchCompat.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            CustomImageFormatConfigurator.setSvgEnabled(getContext(), isChecked);
        }
    });
}
Also used : CheckerBoardDrawable(com.facebook.fresco.samples.showcase.misc.CheckerBoardDrawable) CompoundButton(android.widget.CompoundButton) SwitchCompat(android.support.v7.widget.SwitchCompat)

Example 9 with SwitchCompat

use of android.support.v7.widget.SwitchCompat in project NetGuard by M66B.

the class ActivityMain method onSharedPreferenceChanged.

@Override
public void onSharedPreferenceChanged(SharedPreferences prefs, String name) {
    Log.i(TAG, "Preference " + name + "=" + prefs.getAll().get(name));
    if ("enabled".equals(name)) {
        // Get enabled
        boolean enabled = prefs.getBoolean(name, false);
        // Display disabled warning
        TextView tvDisabled = (TextView) findViewById(R.id.tvDisabled);
        tvDisabled.setVisibility(enabled ? View.GONE : View.VISIBLE);
        // Check switch state
        SwitchCompat swEnabled = (SwitchCompat) getSupportActionBar().getCustomView().findViewById(R.id.swEnabled);
        if (swEnabled.isChecked() != enabled)
            swEnabled.setChecked(enabled);
    } else if ("whitelist_wifi".equals(name) || "screen_on".equals(name) || "screen_wifi".equals(name) || "whitelist_other".equals(name) || "screen_other".equals(name) || "whitelist_roaming".equals(name) || "show_user".equals(name) || "show_system".equals(name) || "show_nointernet".equals(name) || "show_disabled".equals(name) || "sort".equals(name) || "imported".equals(name)) {
        updateApplicationList(null);
        final LinearLayout llWhitelist = (LinearLayout) findViewById(R.id.llWhitelist);
        boolean screen_on = prefs.getBoolean("screen_on", true);
        boolean whitelist_wifi = prefs.getBoolean("whitelist_wifi", false);
        boolean whitelist_other = prefs.getBoolean("whitelist_other", false);
        boolean hintWhitelist = prefs.getBoolean("hint_whitelist", true);
        llWhitelist.setVisibility(!(whitelist_wifi || whitelist_other) && screen_on && hintWhitelist ? View.VISIBLE : View.GONE);
    } else if ("manage_system".equals(name)) {
        invalidateOptionsMenu();
        updateApplicationList(null);
        LinearLayout llSystem = (LinearLayout) findViewById(R.id.llSystem);
        boolean system = prefs.getBoolean("manage_system", false);
        boolean hint = prefs.getBoolean("hint_system", true);
        llSystem.setVisibility(!system && hint ? View.VISIBLE : View.GONE);
    } else if ("theme".equals(name) || "dark_theme".equals(name))
        recreate();
}
Also used : TextView(android.widget.TextView) LinearLayout(android.widget.LinearLayout) SwitchCompat(android.support.v7.widget.SwitchCompat)

Example 10 with SwitchCompat

use of android.support.v7.widget.SwitchCompat in project NetGuard by M66B.

the class ActivityLog method onSharedPreferenceChanged.

@Override
public void onSharedPreferenceChanged(SharedPreferences prefs, String name) {
    Log.i(TAG, "Preference " + name + "=" + prefs.getAll().get(name));
    if ("log".equals(name)) {
        // Get enabled
        boolean log = prefs.getBoolean(name, false);
        // Display disabled warning
        TextView tvDisabled = (TextView) findViewById(R.id.tvDisabled);
        tvDisabled.setVisibility(log ? View.GONE : View.VISIBLE);
        // Check switch state
        SwitchCompat swEnabled = (SwitchCompat) getSupportActionBar().getCustomView().findViewById(R.id.swEnabled);
        if (swEnabled.isChecked() != log)
            swEnabled.setChecked(log);
        ServiceSinkhole.reload("changed " + name, ActivityLog.this);
    }
}
Also used : TextView(android.widget.TextView) SwitchCompat(android.support.v7.widget.SwitchCompat)

Aggregations

SwitchCompat (android.support.v7.widget.SwitchCompat)29 TextView (android.widget.TextView)20 View (android.view.View)19 CompoundButton (android.widget.CompoundButton)19 Intent (android.content.Intent)7 ImageView (android.widget.ImageView)7 AlertDialog (android.support.v7.app.AlertDialog)6 ScrollView (android.widget.ScrollView)6 DialogInterface (android.content.DialogInterface)5 SearchView (android.support.v7.widget.SearchView)4 MenuItem (android.view.MenuItem)4 CheckerBoardDrawable (com.facebook.fresco.samples.showcase.misc.CheckerBoardDrawable)4 CardView (android.support.v7.widget.CardView)3 LayoutInflater (android.view.LayoutInflater)3 ViewGroup (android.view.ViewGroup)3 AdapterView (android.widget.AdapterView)3 LinearLayout (android.widget.LinearLayout)3 Spinner (android.widget.Spinner)3 ArrayList (java.util.ArrayList)3 ClipData (android.content.ClipData)2