List of usage examples for android.widget Switch setChecked
@Override public void setChecked(boolean checked)
From source file:nl.hnogames.domoticz.GeoSettingsActivity.java
private void initSwitches() { Switch geoSwitch = (Switch) findViewById(R.id.switch_button); geoSwitch.setChecked(mSharedPrefs.isGeofenceEnabled()); geoSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override/*from w w w . ja va 2s .co m*/ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { mSharedPrefs.setGeofenceEnabled(isChecked); invalidateOptionsMenu(); } }); }
From source file:com.zuluindia.watchpresenter.MainActivity.java
private void updateInterface() { if (registered) { setContentView(com.zuluindia.watchpresenter.R.layout.activity_main); Switch swtEnableWearGestures = (Switch) findViewById(R.id.enableWearGestureDetection); swtEnableWearGestures.setOnCheckedChangeListener(null); swtEnableWearGestures.setChecked(State.gesturesEnabled); swtEnableWearGestures.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton arg0, boolean arg1) { if (arg1) { showGestureExperimental(); startGestureDetection(); } else { stopGestureDetection(); }//from w ww . j a va2 s . co m } }); Switch swtVibration = (Switch) findViewById(R.id.vibrationSwitch); swtVibration.setOnCheckedChangeListener(null); swtVibration.setChecked(vibration); swtVibration.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton arg0, boolean arg1) { setVibration(arg1); } }); } else { setContentView(R.layout.no_extension_detected); } TextView versionTextView = (TextView) findViewById(com.zuluindia.watchpresenter.R.id.versionText); versionTextView.setText(getResources().getString(R.string.versionPrefix) + " " + versionName); }
From source file:mx.klozz.xperience.tweaker.fragments.CPUSettings.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup root, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.cpu_settings, root, false); mIsTegra3 = new File(TEGRA_MAX_FREQ_PATH).exists(); mIsDynFreq = new File(DYN_MAX_FREQ_PATH).exists() && new File(DYN_MIN_FREQ_PATH).exists(); lCurrentCPU = (LinearLayout) view.findViewById(R.id.lCurCPU); mCurFreq = (TextView) view.findViewById(R.id.current_speed); mCurFreq.setOnClickListener(new View.OnClickListener() { @Override//from w w w .ja va 2 s . c o m public void onClick(View view) { if (nCpus == 1) return; if (++MainActivity.CurrentCPU > (nCpus - 1)) MainActivity.CurrentCPU = 0; setCPUval(MainActivity.CurrentCPU); } }); mCurFreq.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View view) { if (new File(CPU_ON_PATH.replace("cpu0", "cpu" + MainActivity.CurrentCPU)).exists() && MainActivity.CurrentCPU > 0) { final StringBuilder sb = new StringBuilder(); if (MainActivity.mCPUOn.get(MainActivity.CurrentCPU).equals("1")) { sb.append("set_val \"").append(CPU_ON_PATH.replace("cpu0", "cpu" + MainActivity.CurrentCPU)) .append("\" \"0\";\n"); MainActivity.mCPUOn.set(MainActivity.CurrentCPU, "0"); } else { sb.append("set_val \"").append(CPU_ON_PATH.replace("cpu0", "cpu" + MainActivity.CurrentCPU)) .append("\" \"1\";\n"); MainActivity.mCPUOn.set(MainActivity.CurrentCPU, "1"); } Helpers.shExec(sb, context, true); setCPUval(MainActivity.CurrentCPU); } return true; } }); final int mFrequenciesNum = MainActivity.mAvailableFrequencies.length - 1; mMaxSlider = (SeekBar) view.findViewById(R.id.max_slider); mMaxSlider.setMax(mFrequenciesNum); mMaxSlider.setOnSeekBarChangeListener(this); mMaxSpeedText = (TextView) view.findViewById(R.id.max_speed_text); mMinSlider = (SeekBar) view.findViewById(R.id.min_slider); mMinSlider.setMax(mFrequenciesNum); mMinSlider.setOnSeekBarChangeListener(this); mMinSpeedText = (TextView) view.findViewById(R.id.min_speed_text); mGovernor = (Spinner) view.findViewById(R.id.pref_governor); String[] mAvailableGovernors = Helpers.LeerUnaLinea(GOVERNORS_LIST_PATH).split(" "); ArrayAdapter<CharSequence> governorAdapter = new ArrayAdapter<CharSequence>(context, android.R.layout.simple_spinner_item); governorAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); for (String mAvailableGovernor : mAvailableGovernors) { governorAdapter.add(mAvailableGovernor.trim()); } mGovernor.setAdapter(governorAdapter); mGovernor.setSelection(Arrays.asList(mAvailableGovernors) .indexOf(MainActivity.mCurrentGovernor.get(MainActivity.CurrentCPU))); mGovernor.post(new Runnable() { public void run() { mGovernor.setOnItemSelectedListener(new GovListener()); } }); mIo = (Spinner) view.findViewById(R.id.pref_io); String[] mAvailableIo = Helpers.getAvailableIOSchedulers(IO_SCHEDULER_PATH); ArrayAdapter<CharSequence> ioAdapter = new ArrayAdapter<CharSequence>(context, android.R.layout.simple_spinner_item); ioAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); for (String aMAvailableIo : mAvailableIo) { ioAdapter.add(aMAvailableIo); } mIo.setAdapter(ioAdapter); mIo.setSelection( Arrays.asList(mAvailableIo).indexOf(MainActivity.mCurrentIOSched.get(MainActivity.CurrentCPU))); mIo.post(new Runnable() { public void run() { mIo.setOnItemSelectedListener(new IOListener()); } }); Switch mSetOnBoot = (Switch) view.findViewById(R.id.cpu_sob); mSetOnBoot.setChecked(mPreferences.getBoolean(CPU_SOB, false)); mSetOnBoot.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton v, boolean checked) { final SharedPreferences.Editor editor = mPreferences.edit(); editor.putBoolean(CPU_SOB, checked); if (checked) { for (int i = 0; i < nCpus; i++) { editor.putString(PREF_MIN_CPU + i, MainActivity.mMinimunFreqSetting.get(i)); editor.putString(PREF_MAX_CPU + i, MainActivity.mMaximunFreqSetting.get(i)); editor.putString(PREF_GOV, MainActivity.mCurrentGovernor.get(i)); editor.putString(PREF_IO, MainActivity.mCurrentIOSched.get(i)); editor.putString("cpuon" + i, MainActivity.mCPUOn.get(i)); } } editor.apply(); } }); //if(nCpus>1){ LinearLayout vcpus[] = new LinearLayout[nCpus]; for (int i = 0; i < nCpus; i++) { vcpus[i] = (LinearLayout) inflater.inflate(R.layout.cpu_view, root, false); vcpus[i].setId(i); TextView nc = (TextView) vcpus[i].findViewById(R.id.ncpu); nc.setText(Integer.toString(i + 1)); if (i != MainActivity.CurrentCPU) nc.setText(" "); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, (float) 0.1); lCurrentCPU.addView(vcpus[i], params); } //} setCPUval(MainActivity.CurrentCPU); return view; }
From source file:mx.klozz.xperience.tweaker.fragments.VoltageControlSettings.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup root, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.voltage_settings, root, false); final ListView listView = (ListView) view.findViewById(R.id.ListView); final Switch setOnBoot = (Switch) view.findViewById(R.id.applyAtBoot); if (mVoltages.isEmpty()) { (view.findViewById(R.id.emptyList)).setVisibility(View.VISIBLE); (view.findViewById(R.id.BottomBar)).setVisibility(View.GONE); }// w ww . ja v a 2 s . co m setOnBoot.setChecked(mPreferences.getBoolean(VOLTAGE_SOB, false)); setOnBoot.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { mPreferences.edit().putBoolean(VOLTAGE_SOB, isChecked).apply(); if (isChecked) { String warningMessage = getString(R.string.volt_info); new AlertDialog.Builder(context).setMessage(warningMessage) .setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { setOnBoot.setChecked(false); } }).setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }).create().show(); } } }); (view.findViewById(R.id.applyBtn)).setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { final StringBuilder sb = new StringBuilder(); final String vdd = Helpers.getVoltagePath(); if (vdd.equals(VDD_PATH)) { for (final Voltage volt : mVoltages) { if (!volt.getSavedMV().equals(volt.getCurrentMv())) { for (int i = 0; i < Helpers.getNumOfCPUS(); i++) { sb.append("busybox echo \"").append(volt.getFreq()).append(" ") .append(volt.getSavedMV()).append("\" > ") .append(vdd.replace("cpu0", "cpu" + i)).append(";\n"); } } } } else if (vdd.equals(VDD_TABLE)) { for (final Voltage volt : mVoltages) { if (!volt.getSavedMV().equals(volt.getCurrentMv())) { sb.append("busybox echo \"").append(volt.getFreq()).append(" ") .append(volt.getSavedMV()).append("\" > ").append(vdd).append(";\n"); } } } else { final StringBuilder b = new StringBuilder(); for (final Voltage volt : mVoltages) { b.append(volt.getSavedMV()).append(" "); } if (vdd.equals(COMMON_VDD_PATH)) { sb.append("busybox echo \"").append(b.toString()).append("\" > ").append(vdd).append(";\n"); } else { for (int i = 0; i < Helpers.getNumOfCPUS(); i++) { sb.append("busybox echo \"").append(b.toString()).append("\" > ") .append(vdd.replace("cpu0", "cpu" + i)).append(";\n"); } } } Helpers.shExec(sb, context, true); final List<Voltage> volts = getVolts(mPreferences); mVoltages.clear(); mVoltages.addAll(volts); mAdapter.notifyDataSetChanged(); } }); mAdapter.setListItems(mVoltages); listView.setAdapter(mAdapter); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { mVoltage = mVoltages.get(position); showDialog(vmin, vstep, nvsteps); } }); return view; }
From source file:io.oceanos.shaderbox.dialog.PropertiesDialogFragment.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); LayoutInflater inflater = getActivity().getLayoutInflater(); final Shader shader = (Shader) getArguments().getSerializable("shader"); View view = inflater.inflate(R.layout.dialog_properties, null); final EditText nameView = (EditText) view.findViewById(R.id.name); Switch vrMode = (Switch) view.findViewById(R.id.vr_mode); Switch preview = (Switch) view.findViewById(R.id.preview); Spinner resolutionFactor = (Spinner) view.findViewById(R.id.resolution_factor); resolutionFactor.setSelection(Integer.numberOfTrailingZeros(shader.getResolution())); resolutionFactor.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override//from ww w . ja v a 2 s. co m public void onItemSelected(AdapterView<?> adapterView, View view, int pos, long id) { shader.setResolution(1 << pos); } @Override public void onNothingSelected(AdapterView<?> adapterView) { } }); nameView.setText(shader.getName()); vrMode.setChecked(shader.getVrMode() == 1); vrMode.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { shader.setVrMode(isChecked ? 1 : 0); } }); preview.setChecked(shader.getPreviewMode() == 1); preview.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { shader.setPreviewMode(isChecked ? 1 : 0); } }); builder.setTitle(R.string.properties).setView(view) .setPositiveButton(R.string.save, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { shader.setName(nameView.getText().toString()); mListener.onSave(shader); } }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { mListener.onCancel(shader); } }); return builder.create(); }
From source file:ch.ethz.coss.nervousnet.hub.ui.SensorDisplayActivity.java
@Override public void updateActionBar() { getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); LayoutInflater inflator = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View v = inflator.inflate(R.layout.ab_nn, null); ActionBar actionBar;// w ww .j av a2 s. c om Switch mainSwitch; actionBar = getActionBar(); actionBar.setDisplayHomeAsUpEnabled(false); actionBar.setDisplayShowHomeEnabled(false); actionBar.setDisplayShowCustomEnabled(true); actionBar.setDisplayShowTitleEnabled(false); actionBar.setCustomView(v); mainSwitch = (Switch) findViewById(R.id.mainSwitch); byte state = ((Application) getApplication()).getState(); NNLog.d("SensorDisplayActivity", "state = " + state); mainSwitch.setChecked(state == 0 ? false : true); mainSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { startStopSensorService(isChecked); } }); }
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//www . j av a 2 s.c om 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:com.avalond.ad_blocak.main.StartFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_start, container, false); Switch switchOnBoot = (Switch) rootView.findViewById(R.id.switch_onboot); ImageView view = (ImageView) rootView.findViewById(R.id.start_button); TextView stateText = (TextView) rootView.findViewById(R.id.state_textview); stateText.setText(getString(AdVpnService.vpnStatusToTextId(AdVpnService.vpnStatus))); view.setOnLongClickListener(v -> { if (AdVpnService.vpnStatus != AdVpnService.VPN_STATUS_STOPPED) { Log.i(TAG, "Attempting to disconnect"); Intent intent = new Intent(getActivity(), AdVpnService.class); intent.putExtra("COMMAND", Command.STOP.ordinal()); getActivity().startService(intent); } else {// w w w .j a v a 2 s . c om checkHostsFilesAndStartService(); } return true; }); switchOnBoot.setChecked(MainActivity.config.autoStart); switchOnBoot.setOnCheckedChangeListener((buttonView, isChecked) -> { MainActivity.config.autoStart = isChecked; FileHelper.writeSettings(getContext(), MainActivity.config); }); return rootView; }
From source file:fm.krui.kruifm.StreamFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); // Instantiate class members prefManager = new PreferenceManager(getActivity()); favTrackManager = new FavoriteTrackManager(getActivity()); // FIXME: Move these to PreferenceManager after expanding its scope for cleaner code trackPrefs = getActivity().getSharedPreferences(StreamService.PREFS_NAME, 0); // Instantiate broadcast receiver broadcastReceiver = new BroadcastReceiver() { @Override//from w w w . ja v a 2 s . c o m public void onReceive(Context context, Intent intent) { processBroadcastCommand(intent); } }; // Determine the URL we need to use to stream based on the station tag and quality preferences streamUrl = getStreamUrl(stationTag); Log.v(TAG, "streamUrl is now set to: " + streamUrl); // Perform initial configuration of audio server changeUrl(stationTag); // Begin buffering the audio startAudio((ImageView) getActivity().findViewById(R.id.play_audio_imageview)); // Build play button listener final ImageView playButton = (ImageView) getActivity().findViewById(R.id.play_audio_imageview); playButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { handleAudio(playButton); } }); // Build volume seek bar listener // ** DISABLED FOR NOW -- This might be completely thrown out. ** /*final SeekBar volumeSeekBar = (SeekBar)getActivity().findViewById(R.id.volume_seekbar); volumeSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { // When seek bar progress is changed, change the audio of the media player appropriately. @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { // Send new volume via intent? Will this be slow? } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); */ // Build settings button listener and apply it to settings icon and submit button View.OnClickListener flipListener = new View.OnClickListener() { @Override public void onClick(View v) { // Card flip animation which toggles between stream controls and settings views flipCard(); } }; final ImageView settingsButton = (ImageView) getActivity().findViewById(R.id.stream_settings_imageview); final Button saveSettingsButton = (Button) getActivity().findViewById(R.id.set_stream_settings_button); settingsButton.setOnClickListener(flipListener); saveSettingsButton.setOnClickListener(flipListener); // Build favorite button listener final ImageView favoriteButton = (ImageView) getActivity().findViewById(R.id.stream_favorite_imageview); favoriteButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (trackIsFavorite) { favoriteButton.setImageResource(R.drawable.star_unfilled_white); trackIsFavorite = false; removeTrackFromFavorites(); } else { favoriteButton.setImageResource(R.drawable.star_filled_white); trackIsFavorite = true; addTrackToFavorites(); } } }); // Build settings switches final Switch streamQualitySwitch = (Switch) getActivity().findViewById(R.id.stream_quality_switch); final Switch albumArtSwitch = (Switch) getActivity().findViewById(R.id.stream_album_art_switch); // Set initial state of switches albumArtSwitch.setChecked(prefManager.getAlbumArtDownloadPreference()); if (prefManager.getStreamQuality() == prefManager.HIGH_QUALITY) { streamQualitySwitch.setChecked(true); } else { streamQualitySwitch.setChecked(false); } // Assign listeners to switches streamQualitySwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { prefManager.setStreamQuality(prefManager.HIGH_QUALITY); Log.v(TAG, "Stream quality setting is now: " + prefManager.getStreamQuality()); } else { prefManager.setStreamQuality(prefManager.LOW_QUALITY); Log.v(TAG, "Stream quality setting is now: " + prefManager.getStreamQuality()); } changeUrl(stationSpinnerPosition); } }); albumArtSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { prefManager.setAlbumArtDownloadPreference(true); Log.v(TAG, "Album Art Download setting is now " + prefManager.getAlbumArtDownloadPreference()); } else { prefManager.setAlbumArtDownloadPreference(false); Log.v(TAG, "Album Art Download setting is now " + prefManager.getAlbumArtDownloadPreference()); } } }); }
From source file:de.tu_berlin.snet.commstat.SensorFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.sensor_fragment, container, false); statusTextView = (TextView) rootView.findViewById(R.id.status); infoTextView = (TextView) rootView.findViewById(R.id.info); final Switch enable = (Switch) rootView.findViewById(R.id.pipeline); enable.setEnabled(false);//from w w w. ja va 2 s.c o m enable.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (enable.isChecked()) { funfMgr.enablePipeline(PIPELINE_NAME); pipeline = (BasicPipeline) funfMgr.getRegisteredPipeline(PIPELINE_NAME); } else { funfMgr.disablePipeline(PIPELINE_NAME); } } }); handle.postDelayed(new Runnable() { @Override public void run() { enable.setChecked(funfMgr.isEnabled(PIPELINE_NAME)); enable.setEnabled(true); reloadStatus(); reloadInfo(); } }, 2000); return rootView; }