List of usage examples for android.widget Switch setOnCheckedChangeListener
public void setOnCheckedChangeListener(@Nullable OnCheckedChangeListener listener)
From source file:com.ibm.mil.readyapps.summit.fragments.ProfileFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View rootLayout = inflater.inflate(R.layout.fragment_profile, container, false); getActivity().setTitle(getString(R.string.profile_title)); TextView username = (TextView) rootLayout.findViewById(R.id.profile_username); username.setTypeface(FontCache.getFont(getActivity(), FontCache.FontName.OSWALD_REGULAR)); mLoginButton = (Button) rootLayout.findViewById(R.id.login_button); mLoginButton.setTypeface(FontCache.getFont(getActivity(), FontCache.FontName.OSWALD_REGULAR)); mLoginButton.setOnClickListener(new View.OnClickListener() { @Override//from w ww . ja v a 2 s .c om public void onClick(View v) { ((MainActivity) getActivity()).setAuthenticationHandler(null); Intent intent = new Intent(getActivity(), LoginActivity.class); getActivity().startActivityForResult(intent, LoginActivity.AUTHENTICATION_REQUEST_CODE); } }); Switch demoSwitch = (Switch) rootLayout.findViewById(R.id.demo_switch); demoSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { SharedPreferences preferences = getActivity().getSharedPreferences("UserPrefs", Context.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); editor.putBoolean("demoMode", isChecked); editor.apply(); } }); return rootLayout; }
From source file:hosts.file.localvpn.LocalVPN.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.d(TAG, "Starting up"); setContentView(R.layout.activity_local_vpn); final Switch vpnButton = (Switch) findViewById(R.id.vpn_switch); vpnButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override//from w ww . j a v a 2 s.com public void onCheckedChanged(CompoundButton compoundButton, boolean b) { if (b) { startVPN(); } else { stopVPN(); } } }); waitingForVPNStart = false; LocalBroadcastManager.getInstance(this).registerReceiver(vpnStateReceiver, new IntentFilter(LocalVPNService.BROADCAST_VPN_STATE)); final TextView startText = (TextView) findViewById(R.id.appStart); startText.setText(startText.getText().toString() + '\n' + appStartTime); }
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);/*w w w.j a va 2 s . co 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:org.deviceconnect.android.uiapp.fragment.profile.ProximityProfileFragment.java
@Override public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { super.onCreate(savedInstanceState); View view = inflater.inflate(R.layout.fragment_proximity_service, container, false); view.setBackgroundColor(getResources().getColor(android.R.color.background_light)); final Switch proximity = (Switch) view.findViewById(R.id.fragment_proximity_ondevice); proximity.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override// ww w . j av a 2s . c om public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) { if (isChecked) { registerEvent(); } else { unregisterEvent(); } } }); return view; }
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 ww w . j a va 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: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);/*w w w . java 2 s . co 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: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);// w w w.j a v a2s. c o m 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());//from ww w. j av a 2 s .c o m 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: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/* ww w .ja va 2 s . com*/ 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:dynamite.zafroshops.app.fragment.HelpDialogFragment.java
@NonNull @Override//from w w w. jav a2s . 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(); }