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());
}
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);
}
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);
}
});
}
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();
}
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);
}
}
Aggregations