List of usage examples for android.widget Switch setOnCheckedChangeListener
public void setOnCheckedChangeListener(@Nullable OnCheckedChangeListener listener)
From source file:org.mozilla.mozstumbler.client.navdrawer.MainDrawerActivity.java
private void updateStartStopMenuItemState() { if (mMenuItemStartStop == null) { return;/* w ww. j a v a2s . c om*/ } MainApp app = (MainApp) getApplication(); if (app == null) { return; } ClientStumblerService svc = app.getService(); if (svc == null) { return; } if (!svc.isStopped()) { keepScreenOn(ClientPrefs.getInstance(this).getKeepScreenOn()); } else { keepScreenOn(false); } if (Build.VERSION.SDK_INT >= 14) { Switch s = (Switch) mMenuItemStartStop.getActionView(); s.setOnCheckedChangeListener(null); if (app.isScanningOrPaused() && !s.isChecked()) { s.setChecked(true); } else if (!app.isScanningOrPaused() && s.isChecked()) { s.setChecked(false); } s.setOnCheckedChangeListener(mStartStopButtonListener); } else { boolean buttonStateIsScanning = mMenuItemStartStop.getTitle().equals(getString(R.string.stop_scanning)); if (app.isScanningOrPaused() && !buttonStateIsScanning) { mMenuItemStartStop.setIcon(android.R.drawable.ic_media_pause); mMenuItemStartStop.setTitle(R.string.stop_scanning); } else if (!app.isScanningOrPaused() && buttonStateIsScanning) { mMenuItemStartStop.setIcon(android.R.drawable.ic_media_play); mMenuItemStartStop.setTitle(R.string.start_scanning); } } mMapFragment.dimToolbar(); }
From source file:cz.kovar.petr.homevoice.frontend.FragmentSettings.java
private void initZWayLayout(View aView) { final EditText remoteURLEdit = (EditText) aView.findViewById(R.id.remoteURL); remoteURLEdit.setText(m_profile.getRemoteURL()); remoteURLEdit.setOnEditorActionListener(new ClearFocusListener(remoteURLEdit)); remoteURLEdit.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override/*from w ww . j a v a2 s . c o m*/ public void onFocusChange(View view, boolean hasFocus) { if (!hasFocus) { m_profile.setRemoteURL(remoteURLEdit.getText().toString()); onZWayProfileChanged(m_profile); } } }); final EditText localIPEdit = (EditText) aView.findViewById(R.id.localIP); localIPEdit.setText(m_profile.getLocalIP()); localIPEdit.setOnEditorActionListener(new ClearFocusListener(localIPEdit)); localIPEdit.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View view, boolean hasFocus) { if (!hasFocus) { m_profile.setLocalIP(localIPEdit.getText().toString()); onZWayProfileChanged(m_profile); } } }); final EditText localPortEdit = (EditText) aView.findViewById(R.id.localPort); localPortEdit.setText(String.format(Locale.ENGLISH, "%d", m_profile.getLocalPort())); localPortEdit.setOnEditorActionListener(new ClearFocusListener(localPortEdit)); localPortEdit.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View view, boolean hasFocus) { if (!hasFocus) { m_profile.setLocalPort(Integer.valueOf(localPortEdit.getText().toString())); onZWayProfileChanged(m_profile); } } }); final EditText loginEdit = (EditText) aView.findViewById(R.id.login); loginEdit.setText(m_profile.getRemoteLogin()); loginEdit.setOnEditorActionListener(new ClearFocusListener(loginEdit)); loginEdit.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View view, boolean hasFocus) { if (!hasFocus) { m_profile.setRemoteLogin(loginEdit.getText().toString()); onZWayProfileChanged(m_profile); } } }); final EditText passwordEdit = (EditText) aView.findViewById(R.id.password); passwordEdit.setText(m_profile.getPassword()); passwordEdit.setOnEditorActionListener(new ClearFocusListener(passwordEdit)); passwordEdit.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View view, boolean hasFocus) { if (!hasFocus) { m_profile.setPassword(passwordEdit.getText().toString()); onZWayProfileChanged(m_profile); } } }); final Switch remoteSwitch = (Switch) aView.findViewById(R.id.remoteSwitch); remoteSwitch.setChecked(m_profile.useRemote()); remoteSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean b) { m_profile.useRemote(b); onZWayProfileChanged(m_profile); } }); final TextView firebaseAPI = (TextView) aView.findViewById(R.id.firebaseAPI); firebaseAPI.setText(FirebaseInstanceId.getInstance().getToken()); }
From source file:org.deviceconnect.android.deviceplugin.linking.setting.fragment.LinkingBeaconListFragment.java
@Override public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { mAdapter = new ListAdapter(getActivity(), -1); final View root = inflater.inflate(R.layout.fragment_linking_beacon_list, container, false); ListView listView = (ListView) root.findViewById(R.id.fragment_beacon_list_view); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override//from w ww . j a v a 2 s .c o m public void onItemClick(AdapterView<?> parent, View view, int position, long id) { DeviceItem item = (DeviceItem) view.getTag(); if (item != null) { transitionBeaconControl(item); } } }); listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { confirmDeleteBeacon(mAdapter.getItem(position).mDevice); return true; } }); listView.setAdapter(mAdapter); Switch switchBtn = (Switch) root.findViewById(R.id.fragment_beacon_scan_switch); if (switchBtn != null) { switchBtn.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) { if (isChecked) { getLinkingBeaconManager().startForceBeaconScan(); } else { getLinkingBeaconManager().stopForceBeaconScan(); } } }); switchBtn.setChecked(getLinkingBeaconManager().isStartedForceBeaconScan()); } return root; }
From source file:org.jak_linux.dns66.main.WhitelistFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreate(savedInstanceState); View rootView = inflater.inflate(R.layout.activity_whitelist, container, false); appList = (ListView) rootView.findViewById(R.id.list); swipeRefresh = (SwipeRefreshLayout) rootView.findViewById(R.id.swiperefresh); swipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override//from w ww . ja va2 s. c o m public void onRefresh() { appListGenerator = new AppListGenerator(); appListGenerator.execute(); } }); swipeRefresh.setRefreshing(true); Switch switchShowSystemApps = (Switch) rootView.findViewById(R.id.switch_show_system_apps); switchShowSystemApps.setChecked(MainActivity.config.whitelist.showSystemApps); switchShowSystemApps.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { MainActivity.config.whitelist.showSystemApps = isChecked; FileHelper.writeSettings(getContext(), MainActivity.config); appListGenerator = new AppListGenerator(); appListGenerator.execute(); } }); appListGenerator = new AppListGenerator(); appListGenerator.execute(); return rootView; }
From source file:com.readystatesoftware.ghostlog.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Switch mainSwitch = new Switch(this); mainSwitch.setChecked(LogService.isRunning()); mainSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override/*from www.ja va 2 s. com*/ public void onCheckedChanged(CompoundButton compoundButton, boolean b) { Intent intent = new Intent(MainActivity.this, LogService.class); if (b) { if (!LogService.isRunning()) { startService(intent); } } else { stopService(intent); } } }); final ActionBar bar = getActionBar(); final ActionBar.LayoutParams lp = new ActionBar.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); lp.gravity = Gravity.RIGHT | Gravity.CENTER_VERTICAL; lp.rightMargin = getResources().getDimensionPixelSize(R.dimen.main_switch_margin_right); bar.setCustomView(mainSwitch, lp); bar.setDisplayShowCustomEnabled(true); mPrefs = PreferenceManager.getDefaultSharedPreferences(this); if (!mPrefs.getBoolean(PreferenceManager.KEY_HAS_SET_DEFAULT_VALUES, false)) { PreferenceManager.setDefaultValues(this, R.xml.pref_filters, true); PreferenceManager.setDefaultValues(this, R.xml.pref_appearance, true); SharedPreferences.Editor edit = mPrefs.edit(); edit.putBoolean(PreferenceManager.KEY_HAS_SET_DEFAULT_VALUES, true); edit.apply(); } }
From source file:com.example.android.shushme.MainActivity.java
/** * Called when the activity is starting//from ww w.ja v a 2 s . c o m * * @param savedInstanceState The Bundle that contains the data supplied in onSaveInstanceState */ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Set up the recycler view mRecyclerView = (RecyclerView) findViewById(R.id.places_list_recycler_view); mRecyclerView.setLayoutManager(new LinearLayoutManager(this)); mAdapter = new PlaceListAdapter(this, null); mRecyclerView.setAdapter(mAdapter); // Initialize the switch state and Handle enable/disable switch change Switch onOffSwitch = (Switch) findViewById(R.id.enable_switch); mIsEnabled = getPreferences(MODE_PRIVATE).getBoolean(getString(R.string.setting_enabled), false); onOffSwitch.setChecked(mIsEnabled); onOffSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { SharedPreferences.Editor editor = getPreferences(MODE_PRIVATE).edit(); editor.putBoolean(getString(R.string.setting_enabled), isChecked); mIsEnabled = isChecked; editor.commit(); if (isChecked) mGeofencing.registerAllGeofences(); else mGeofencing.unRegisterAllGeofences(); } }); mClient = new GoogleApiClient.Builder(this).addConnectionCallbacks(this).addOnConnectionFailedListener(this) .addApi(LocationServices.API).addApi(Places.GEO_DATA_API).enableAutoManage(this, this).build(); mGeofencing = new Geofencing(this, mClient); }
From source file:sintef.android.gravity.advanced.AdvancedActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { Switch fall_detection_switch = (Switch) menu.findItem(R.id.fall_detection_switch).getActionView() .findViewById(R.id.switch_toolbar); fall_detection_switch .setChecked(PreferencesHelper.getBoolean(PreferencesHelper.FALL_DETECTION_ENABLED, true)); fall_detection_switch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override//from w w w .j ava 2s . c o m public void onCheckedChanged(CompoundButton compoundButton, boolean b) { PreferencesHelper.putBoolean(PreferencesHelper.FALL_DETECTION_ENABLED, b); } }); return super.onPrepareOptionsMenu(menu); }
From source file:com.serenegiant.aceparrot.ConfigAppFragment.java
private void initVoice(final View rootView) { // ??????(Android>=6) mOfflineVoiceRecognition = mPref.getBoolean(KEY_CONFIG_VOICE_RECOGNITION_PREFER_OFFLINE, false) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M; Switch sw = (Switch) rootView.findViewById(R.id.enable_offline_voice_recognition_switch); sw.setEnabled(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M); sw.setChecked(mOfflineVoiceRecognition); sw.setOnCheckedChangeListener(mOnCheckedChangeListener); // /*from w ww . ja va 2s . c om*/ mDampingRateTv = (TextView) rootView.findViewById(R.id.damping_rate_textview); mDampingRate = mPref.getInt(KEY_CONFIG_VOICE_RECOGNITION_DAMPING_RATE, DEFAULT_VOICE_RECOGNITION_DAMPING_RATE); final SeekBar seekBar = (SeekBar) rootView.findViewById(R.id.damping_rate_seekbar); seekBar.setProgress(mDampingRate); seekBar.setOnSeekBarChangeListener(mOnSeekBarChangeListener); updateDampingRate(mDampingRate); // ????????? mScriptVoiceRecognition = mPref.getBoolean(KEY_CONFIG_VOICE_RECOGNITION_ENABLE_SCRIPT, false); sw = (Switch) rootView.findViewById(R.id.enable_voice_recognition_script_switch); sw.setChecked(mScriptVoiceRecognition); sw.setOnCheckedChangeListener(mOnCheckedChangeListener); }
From source file:eu.power_switch.gui.fragment.alarm_clock.StockAlarmClockFragment.java
@Override public void onCreateViewEvent(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { rootView = inflater.inflate(R.layout.fragment_stock_alarm_clock, container, false); setHasOptionsMenu(true);//w w w . java 2s. com final RecyclerViewFragment recyclerViewFragment = this; Switch switchOnOff = (Switch) rootView.findViewById(R.id.switch_on_off); switchOnOff.setChecked(SmartphonePreferencesHandler.getStockAlarmClockEnabled()); switchOnOff.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (buttonView.isPressed()) { SmartphonePreferencesHandler.setStockAlarmClockEnabled(isChecked); } } }); spinnerEventType = (Spinner) rootView.findViewById(R.id.spinner_sleep_as_android_event); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getContext(), R.array.stock_alarm_clock_event_names, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinnerEventType.setAdapter(adapter); SpinnerInteractionListener spinnerInteractionListener = new SpinnerInteractionListener() { @Override public void onItemSelectedByUser(AdapterView<?> parent, View view, int pos, long id) { updateUI(); } }; spinnerEventType.setOnItemSelectedListener(spinnerInteractionListener); spinnerEventType.setOnTouchListener(spinnerInteractionListener); recyclerViewActions = (RecyclerView) rootView.findViewById(R.id.recyclerView); recyclerViewAdapter = new ActionRecyclerViewAdapter(getContext(), actions); recyclerViewAdapter.setOnDeleteClickListener(new ActionRecyclerViewAdapter.OnItemClickListener() { @Override public void onItemClick(View itemView, final int position) { new AlertDialog.Builder(getContext()).setTitle(R.string.delete).setMessage(R.string.are_you_sure) .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { try { actions.remove(position); DatabaseHandler.setAlarmActions( Event.getById(spinnerEventType.getSelectedItemPosition()), actions); StatusMessageHandler.showInfoMessage(recyclerViewFragment.getRecyclerView(), R.string.action_removed, Snackbar.LENGTH_LONG); } catch (Exception e) { StatusMessageHandler.showErrorMessage(recyclerViewFragment.getRecyclerView(), e); } recyclerViewAdapter.notifyDataSetChanged(); } }).setNeutralButton(android.R.string.cancel, null).show(); } }); recyclerViewActions.setAdapter(recyclerViewAdapter); StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(getSpanCount(), StaggeredGridLayoutManager.VERTICAL); recyclerViewActions.setLayoutManager(layoutManager); addActionFAB = (FloatingActionButton) rootView.findViewById(R.id.add_fab); addActionFAB.setImageDrawable(IconicsHelper.getAddIcon(getActivity(), ContextCompat.getColor(getActivity(), android.R.color.white))); addActionFAB.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AddStockAlarmClockEventActionDialog addAlarmEventActionDialog = AddStockAlarmClockEventActionDialog .newInstance(spinnerEventType.getSelectedItemPosition()); addAlarmEventActionDialog.setTargetFragment(recyclerViewFragment, 0); addAlarmEventActionDialog.show(getActivity().getSupportFragmentManager(), null); } }); // BroadcastReceiver to get notifications from background service if room data has changed broadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { Log.d(this, "received intent: " + intent.getAction()); if (LocalBroadcastConstants.INTENT_ALARM_EVENT_ACTION_ADDED.equals(intent.getAction())) { updateUI(); } else { updateUI(); } } }; }
From source file:eu.power_switch.gui.fragment.alarm_clock.SleepAsAndroidFragment.java
@Override public void onCreateViewEvent(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { rootView = inflater.inflate(R.layout.fragment_sleep_as_android, container, false); setHasOptionsMenu(true);// w w w . j a va 2 s . co m final RecyclerViewFragment recyclerViewFragment = this; Switch switchOnOff = (Switch) rootView.findViewById(R.id.switch_on_off); switchOnOff.setChecked(SmartphonePreferencesHandler.getSleepAsAndroidEnabled()); switchOnOff.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (buttonView.isPressed()) { SmartphonePreferencesHandler.setSleepAsAndroidEnabled(isChecked); } } }); layout_installed = (LinearLayout) rootView.findViewById(R.id.layout_installed); layout_not_installed = (LinearLayout) rootView.findViewById(R.id.layout_not_installed); IconicsImageView getFromPlayStore = (IconicsImageView) rootView.findViewById(R.id.get_from_play_store); getFromPlayStore.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { SleepAsAndroidHelper.openPlayStorePage(getActivity()); } }); spinnerEventType = (Spinner) rootView.findViewById(R.id.spinner_sleep_as_android_event); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getContext(), R.array.sleep_as_android_event_names, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinnerEventType.setAdapter(adapter); SpinnerInteractionListener spinnerInteractionListener = new SpinnerInteractionListener() { @Override public void onItemSelectedByUser(AdapterView<?> parent, View view, int pos, long id) { updateUI(); } }; spinnerEventType.setOnItemSelectedListener(spinnerInteractionListener); spinnerEventType.setOnTouchListener(spinnerInteractionListener); recyclerViewActions = (RecyclerView) rootView.findViewById(R.id.recyclerView); recyclerViewAdapter = new ActionRecyclerViewAdapter(getContext(), actions); recyclerViewAdapter.setOnDeleteClickListener(new ActionRecyclerViewAdapter.OnItemClickListener() { @Override public void onItemClick(View itemView, final int position) { new AlertDialog.Builder(getContext()).setTitle(R.string.delete).setMessage(R.string.are_you_sure) .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { try { actions.remove(position); DatabaseHandler.setAlarmActions(SLEEP_AS_ANDROID_ALARM_EVENT .getById(spinnerEventType.getSelectedItemPosition()), actions); StatusMessageHandler.showInfoMessage(recyclerViewFragment.getRecyclerView(), R.string.action_removed, Snackbar.LENGTH_LONG); } catch (Exception e) { StatusMessageHandler.showErrorMessage(recyclerViewFragment.getRecyclerView(), e); } recyclerViewAdapter.notifyDataSetChanged(); } }).setNeutralButton(android.R.string.cancel, null).show(); } }); recyclerViewActions.setAdapter(recyclerViewAdapter); StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(getSpanCount(), StaggeredGridLayoutManager.VERTICAL); recyclerViewActions.setLayoutManager(layoutManager); addActionFAB = (FloatingActionButton) rootView.findViewById(R.id.add_fab); addActionFAB.setImageDrawable(IconicsHelper.getAddIcon(getActivity(), ContextCompat.getColor(getActivity(), android.R.color.white))); addActionFAB.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AddSleepAsAndroidAlarmEventActionDialog addAlarmEventActionDialog = AddSleepAsAndroidAlarmEventActionDialog .newInstance(spinnerEventType.getSelectedItemPosition()); addAlarmEventActionDialog.setTargetFragment(recyclerViewFragment, 0); addAlarmEventActionDialog.show(getActivity().getSupportFragmentManager(), null); } }); // BroadcastReceiver to get notifications from background service if room data has changed broadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { Log.d(this, "received intent: " + intent.getAction()); if (LocalBroadcastConstants.INTENT_ALARM_EVENT_ACTION_ADDED.equals(intent.getAction())) { updateUI(); } else { updateUI(); } } }; }