List of usage examples for android.widget Switch setChecked
@Override public void setChecked(boolean checked)
From source file:at.wada811.android.library.demos.daydream.DayDreamSettingsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_daydream_settings); Switch switchInteractive = (Switch) findViewById(R.id.setInteractive); switchInteractive.setChecked(PreferenceUtils.getBoolean(self, getString(R.string.setInteractive), true)); switchInteractive.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override//w w w.j av a 2 s . c om public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { LogUtils.d(buttonView.getText().toString() + ": " + isChecked); PreferenceUtils.putBoolean(self, getString(R.string.setInteractive), isChecked); } }); Switch switchFullscreen = (Switch) findViewById(R.id.setFullscreen); switchFullscreen.setChecked(PreferenceUtils.getBoolean(self, getString(R.string.setFullscreen), true)); switchFullscreen.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { LogUtils.d(buttonView.getText().toString() + ": " + isChecked); PreferenceUtils.putBoolean(self, getString(R.string.setFullscreen), isChecked); } }); Switch switchScreenBright = (Switch) findViewById(R.id.setScreenBright); switchScreenBright.setChecked(PreferenceUtils.getBoolean(self, getString(R.string.setScreenBright), true)); switchScreenBright.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { LogUtils.d(buttonView.getText().toString() + ": " + isChecked); PreferenceUtils.putBoolean(self, getString(R.string.setScreenBright), isChecked); } }); }
From source file:com.avalond.ad_blocak.main.DNSFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_dns, container, false); RecyclerView mRecyclerView = (RecyclerView) rootView.findViewById(R.id.dns_entries); // use this setting to improve performance if you know that changes // in content do not change the layout size of the RecyclerView mRecyclerView.setHasFixedSize(true); // use a linear layout manager RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getContext()); mRecyclerView.setLayoutManager(mLayoutManager); final ItemRecyclerViewAdapter mAdapter = new ItemRecyclerViewAdapter(MainActivity.config.dnsServers.items); mRecyclerView.setAdapter(mAdapter);/*from w ww . j a v a2s . c o m*/ ItemTouchHelper itemTouchHelper = new ItemTouchHelper(new ItemTouchHelperCallback(mAdapter)); itemTouchHelper.attachToRecyclerView(mRecyclerView); FloatingActionButton fab = (FloatingActionButton) rootView.findViewById(R.id.dns_add); fab.setOnClickListener(view -> { MainActivity main = (MainActivity) getActivity(); main.editItem(null, item -> { MainActivity.config.dnsServers.items.add(item); mAdapter.notifyItemInserted(mAdapter.getItemCount() - 1); FileHelper.writeSettings(getContext(), MainActivity.config); }); }); Switch dnsEnabled = (Switch) rootView.findViewById(R.id.dns_enabled); dnsEnabled.setChecked(MainActivity.config.dnsServers.enabled); dnsEnabled.setOnCheckedChangeListener((buttonView, isChecked) -> { MainActivity.config.dnsServers.enabled = isChecked; FileHelper.writeSettings(getContext(), MainActivity.config); }); return rootView; }
From source file:hosts.file.localvpn.LocalVPN.java
private void updateVPNSwitchState(boolean isOn) { final Switch vpnButton = (Switch) findViewById(R.id.vpn_switch); vpnButton.setChecked(isOn); }
From source file:com.avalond.ad_blocak.main.HostsFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_hosts, container, false); RecyclerView mRecyclerView = (RecyclerView) rootView.findViewById(R.id.host_entries); mRecyclerView.setHasFixedSize(true); RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getContext()); mRecyclerView.setLayoutManager(mLayoutManager); final ItemRecyclerViewAdapter mAdapter = new ItemRecyclerViewAdapter(MainActivity.config.hosts.items); mRecyclerView.setAdapter(mAdapter);/*from w w w . j av a 2 s. c om*/ ItemTouchHelper itemTouchHelper = new ItemTouchHelper(new ItemTouchHelperCallback(mAdapter)); itemTouchHelper.attachToRecyclerView(mRecyclerView); FloatingActionButton fab = (FloatingActionButton) rootView.findViewById(R.id.host_add); fab.setOnClickListener(view -> { final MainActivity main = (MainActivity) getActivity(); main.editItem(null, item -> { MainActivity.config.hosts.items.add(item); mAdapter.notifyItemInserted(mAdapter.getItemCount() - 1); FileHelper.writeSettings(getContext(), MainActivity.config); }); }); Switch hostEnabled = (Switch) rootView.findViewById(R.id.host_enabled); hostEnabled.setChecked(MainActivity.config.hosts.enabled); hostEnabled.setOnCheckedChangeListener((buttonView, isChecked) -> { MainActivity.config.hosts.enabled = isChecked; FileHelper.writeSettings(getContext(), MainActivity.config); }); return rootView; }
From source file:dynamite.zafroshops.app.fragment.HelpDialogFragment.java
@NonNull @Override/*from w w w. j a v a 2 s . c om*/ public Dialog onCreateDialog(Bundle savedInstanceState) { Activity activity = getActivity(); AlertDialog.Builder builder = new AlertDialog.Builder(activity); final LayoutInflater inflater = activity.getLayoutInflater(); View view = inflater.inflate(R.layout.help_dialog, null); SharedPreferences preferences = activity.getPreferences(0); final SharedPreferences.Editor editor = preferences.edit(); builder.setView(view).setTitle(R.string.help_title).setPositiveButton(R.string.help_ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); Switch locationToggle = (Switch) view.findViewById(R.id.help_toggle); locationToggle.setChecked(preferences.getBoolean(StorageKeys.HELP_TOGGLE_KEY, false)); locationToggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean b) { editor.putBoolean(StorageKeys.HELP_TOGGLE_KEY, b); editor.commit(); } }); return builder.create(); }
From source file:org.jak_linux.dns66.main.HostsFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_hosts, container, false); RecyclerView mRecyclerView = (RecyclerView) rootView.findViewById(R.id.host_entries); mRecyclerView.setHasFixedSize(true); RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getContext()); mRecyclerView.setLayoutManager(mLayoutManager); final ItemRecyclerViewAdapter mAdapter = new ItemRecyclerViewAdapter(MainActivity.config.hosts.items, 3); mRecyclerView.setAdapter(mAdapter);/*from w w w . j a v a 2 s . c o m*/ ItemTouchHelper itemTouchHelper = new ItemTouchHelper(new ItemTouchHelperCallback(mAdapter)); itemTouchHelper.attachToRecyclerView(mRecyclerView); FloatingActionButton fab = (FloatingActionButton) rootView.findViewById(R.id.host_add); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { final MainActivity main = (MainActivity) getActivity(); main.editItem(3, null, new ItemChangedListener() { @Override public void onItemChanged(Configuration.Item item) { MainActivity.config.hosts.items.add(item); mAdapter.notifyItemInserted(mAdapter.getItemCount() - 1); FileHelper.writeSettings(getContext(), MainActivity.config); } }); } }); Switch hostEnabled = (Switch) rootView.findViewById(R.id.host_enabled); hostEnabled.setChecked(MainActivity.config.hosts.enabled); hostEnabled.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { MainActivity.config.hosts.enabled = isChecked; FileHelper.writeSettings(getContext(), MainActivity.config); } }); return rootView; }
From source file:ykim81.cs.brown.ykim81.cardemulation.CardEmulationFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View v = inflater.inflate(R.layout.main_fragment, container, false); EditText account = (EditText) v.findViewById(R.id.name_field); account.setText(AccountStorage.getName(getActivity())); account.addTextChangedListener(new AccountUpdater()); Switch blind = (Switch) v.findViewById(R.id.blind_switch); blind.setChecked(AccountStorage.getBlind(getActivity()).equals("T")); blind.setOnClickListener(new View.OnClickListener() { @Override//from ww w . ja va 2s . c o m public void onClick(View v) { Switch blind = (Switch) v.findViewById(R.id.blind_switch); if (blind.isChecked()) { AccountStorage.setBlind(getActivity(), "T"); } else { AccountStorage.setBlind(getActivity(), "F"); } } }); Switch deaf = (Switch) v.findViewById(R.id.deaf_switch); deaf.setChecked(AccountStorage.getDeaf(getActivity()).equals("T")); deaf.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Switch deaf = (Switch) v.findViewById(R.id.deaf_switch); if (deaf.isChecked()) { AccountStorage.setDeaf(getActivity(), "T"); } else { AccountStorage.setDeaf(getActivity(), "F"); } } }); return v; }
From source file:org.jak_linux.dns66.main.DNSFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_dns, container, false); RecyclerView mRecyclerView = (RecyclerView) rootView.findViewById(R.id.dns_entries); // use this setting to improve performance if you know that changes // in content do not change the layout size of the RecyclerView mRecyclerView.setHasFixedSize(true); // use a linear layout manager RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getContext()); mRecyclerView.setLayoutManager(mLayoutManager); final ItemRecyclerViewAdapter mAdapter = new ItemRecyclerViewAdapter(MainActivity.config.dnsServers.items, 2);/*from w w w .j a v a2 s.c om*/ mRecyclerView.setAdapter(mAdapter); ItemTouchHelper itemTouchHelper = new ItemTouchHelper(new ItemTouchHelperCallback(mAdapter)); itemTouchHelper.attachToRecyclerView(mRecyclerView); FloatingActionButton fab = (FloatingActionButton) rootView.findViewById(R.id.dns_add); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { MainActivity main = (MainActivity) getActivity(); main.editItem(2, null, new ItemChangedListener() { @Override public void onItemChanged(Configuration.Item item) { MainActivity.config.dnsServers.items.add(item); mAdapter.notifyItemInserted(mAdapter.getItemCount() - 1); FileHelper.writeSettings(getContext(), MainActivity.config); } }); } }); Switch dnsEnabled = (Switch) rootView.findViewById(R.id.dns_enabled); dnsEnabled.setChecked(MainActivity.config.dnsServers.enabled); dnsEnabled.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { MainActivity.config.dnsServers.enabled = isChecked; FileHelper.writeSettings(getContext(), MainActivity.config); } }); return rootView; }
From source file:ch.dissem.apps.abit.SubscriptionDetailFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_subscription_detail, container, false); // Show the dummy content as text in a TextView. if (item != null) { ((ImageView) rootView.findViewById(R.id.avatar)).setImageDrawable(new Identicon(item)); TextView name = (TextView) rootView.findViewById(R.id.name); name.setText(item.toString());// w w w .j a v a 2 s .c om name.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { // Nothing to do } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { // Nothing to do } @Override public void afterTextChanged(Editable s) { item.setAlias(s.toString()); } }); TextView address = (TextView) rootView.findViewById(R.id.address); address.setText(item.getAddress()); address.setSelected(true); ((TextView) rootView.findViewById(R.id.stream_number)) .setText(getActivity().getString(R.string.stream_number, item.getStream())); Switch active = (Switch) rootView.findViewById(R.id.active); active.setChecked(item.isSubscribed()); active.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { item.setSubscribed(isChecked); } }); } return rootView; }
From source file:org.mozilla.focus.widget.TelemetrySwitchPreference.java
@Override protected void onBindView(final View view) { super.onBindView(view); final Switch switchWidget = view.findViewById(R.id.switch_widget); switchWidget.setChecked(TelemetryWrapper.isTelemetryEnabled(getContext())); switchWidget.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override//from w w w. java 2s . c om public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { TelemetryWrapper.setTelemetryEnabled(getContext(), isChecked); } }); final Resources resources = view.getResources(); final TextView summary = view.findViewById(android.R.id.summary); summary.setText(resources.getString(R.string.preference_mozilla_telemetry_summary2, resources.getString(R.string.app_name))); final TextView learnMoreLink = view.findViewById(R.id.link); learnMoreLink.setPaintFlags(learnMoreLink.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG); learnMoreLink.setTextColor(ContextCompat.getColor(view.getContext(), R.color.colorAction)); learnMoreLink.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // This is a hardcoded link: if we ever end up needing more of these links, we should // move the link into an xml parameter, but there's no advantage to making it configurable now. final String url = SupportUtils.getSumoURLForTopic(getContext(), "usage-data"); final String title = getTitle().toString(); final Intent intent = InfoActivity.getIntentFor(getContext(), url, title); getContext().startActivity(intent); } }); final TypedArray backgroundDrawableArray = view.getContext() .obtainStyledAttributes(new int[] { R.attr.selectableItemBackground }); final Drawable backgroundDrawable = backgroundDrawableArray.getDrawable(0); backgroundDrawableArray.recycle(); learnMoreLink.setBackground(backgroundDrawable); // We still want to allow toggling the pref by touching any part of the pref (except for // the "learn more" link) setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { switchWidget.toggle(); return true; } }); }