List of usage examples for android.widget CompoundButton setOnCheckedChangeListener
public void setOnCheckedChangeListener(@Nullable OnCheckedChangeListener listener)
From source file:com.vuze.android.remote.fragment.OpenOptionsGeneralFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { FragmentActivity activity = getActivity(); Intent intent = activity.getIntent(); if (AndroidUtils.DEBUG) { Log.d(TAG, activity + "] onCreateview " + this); }//from w w w . j a v a 2 s . c o m final Bundle extras = intent.getExtras(); if (extras == null) { Log.e(TAG, "No extras!"); } else { String remoteProfileID = extras.getString(SessionInfoManager.BUNDLE_KEY); if (remoteProfileID != null) { sessionInfo = SessionInfoManager.getSessionInfo(remoteProfileID, activity); } torrentID = extras.getLong("TorrentID"); } if (activity instanceof TorrentOpenOptionsActivity) { ourActivity = (TorrentOpenOptionsActivity) activity; } topView = inflater.inflate(R.layout.frag_openoptions_general, container, false); ImageButton btnEditDir = (ImageButton) topView.findViewById(R.id.openoptions_btn_editdir); ImageButton btnEditName = (ImageButton) topView.findViewById(R.id.openoptions_btn_editname); tvName = (TextView) topView.findViewById(R.id.openoptions_name); tvSaveLocation = (TextView) topView.findViewById(R.id.openoptions_saveloc); tvFreeSpace = (TextView) topView.findViewById(R.id.openoptions_freespace); CompoundButton btnPositionLast = (CompoundButton) topView.findViewById(R.id.openoptions_sw_position); CompoundButton btnStateQueued = (CompoundButton) topView.findViewById(R.id.openoptions_sw_state); if (ourActivity != null) { if (btnPositionLast != null) { btnPositionLast.setChecked(ourActivity.isPositionLast()); btnPositionLast.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { ourActivity.setPositionLast(isChecked); } }); } if (btnStateQueued != null) { btnStateQueued.setChecked(ourActivity.isStateQueued()); btnStateQueued.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { ourActivity.setStateQueued(isChecked); } }); } } final Map<?, ?> torrent = sessionInfo.getTorrent(torrentID); if (torrent == null) { getActivity().finish(); VuzeEasyTracker.getInstance(getActivity()).logError("Torrent doesn't exist", TAG); return topView; } if (torrent.containsKey(TransmissionVars.FIELD_TORRENT_DOWNLOAD_DIR)) { updateFields(torrent); } else { sessionInfo.executeRpc(new RpcExecuter() { @Override public void executeRpc(TransmissionRPC rpc) { rpc.getTorrent(TAG, torrentID, Collections.singletonList(TransmissionVars.FIELD_TORRENT_DOWNLOAD_DIR), new TorrentListReceivedListener() { @Override public void rpcTorrentListReceived(String callID, List<?> addedTorrentMaps, List<?> removedTorrentIDs) { AndroidUtils.runOnUIThread(OpenOptionsGeneralFragment.this, new Runnable() { @Override public void run() { updateFields(torrent); } }); } }); } }); } if (btnEditDir != null) { btnEditDir.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Map<?, ?> torrent = sessionInfo.getTorrent(torrentID); DialogFragmentMoveData.openMoveDataDialog(torrent, sessionInfo, getFragmentManager()); } }); } if (btnEditName != null) { if (sessionInfo.getSupportsTorrentRename()) { btnEditName.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Builder builder = new AlertDialog.Builder(getActivity()); final TextView textView = new EditText(getActivity()); textView.setText(tvName.getText()); textView.setSingleLine(); if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) { builder.setInverseBackgroundForced(true); } builder.setView(textView); builder.setTitle(R.string.change_name_title); builder.setMessage(R.string.change_name_message); builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { final String newName = textView.getText().toString(); tvName.setText(newName); sessionInfo.executeRpc(new RpcExecuter() { @Override public void executeRpc(TransmissionRPC rpc) { rpc.setDisplayName(TAG, torrentID, newName); } }); } }); builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); builder.create().show(); } }); } else { btnEditName.setVisibility(View.GONE); } } return topView; }
From source file:com.vuze.android.remote.activity.TorrentOpenOptionsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { AndroidUtilsUI.onCreate(this); super.onCreate(savedInstanceState); Intent intent = getIntent();//from w w w . j a va2 s . c om final Bundle extras = intent.getExtras(); if (extras == null) { Log.e(TAG, "No extras!"); finish(); return; } String remoteProfileID = extras.getString(SessionInfoManager.BUNDLE_KEY); if (remoteProfileID != null) { sessionInfo = SessionInfoManager.getSessionInfo(remoteProfileID, this); } torrentID = extras.getLong("TorrentID"); if (sessionInfo == null) { Log.e(TAG, "sessionInfo NULL!"); finish(); return; } Map<?, ?> torrent = sessionInfo.getTorrent(torrentID); if (torrent == null) { Log.e(TAG, "torrent NULL"); finish(); return; } RemoteProfile remoteProfile = sessionInfo.getRemoteProfile(); positionLast = remoteProfile.isAddPositionLast(); stateQueued = remoteProfile.isAddStateQueued(); setContentView(R.layout.activity_torrent_openoptions); setupActionBar(); Button btnAdd = (Button) findViewById(R.id.openoptions_btn_add); Button btnCancel = (Button) findViewById(R.id.openoptions_btn_cancel); CompoundButton cbSilentAdd = (CompoundButton) findViewById(R.id.openoptions_cb_silentadd); if (btnAdd != null) { btnAdd.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { finish(true); } }); } if (btnCancel != null) { btnCancel.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { finish(false); } }); } if (cbSilentAdd != null) { cbSilentAdd.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { sessionInfo.getRemoteProfile().setAddTorrentSilently(isChecked); } }); cbSilentAdd.setChecked(sessionInfo.getRemoteProfile().isAddTorrentSilently()); } }
From source file:se.toxbee.sleepfighter.activity.EditGPSFilterAreaActivity.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB) private void setupActionBar() { String name = this.printName(); if (Build.VERSION.SDK_INT >= 11) { // add the custom view to the action bar. ActionBar actionBar = getActionBar(); actionBar.setCustomView(R.layout.gpsfilter_area_actionbar); actionBar.setDisplayOptions(/*from w w w .j ava 2 s. c o m*/ ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_CUSTOM); View customView = actionBar.getCustomView(); // Setup edit name component. EditText editNameView = (EditText) customView.findViewById(R.id.edit_gpsfilter_area_title_edit); editNameView.setText(name); editNameView.setOnEditorActionListener(new OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { area.setName(GPSFilterTextUtils.printName(getResources(), v.getText().toString())); InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(v.getWindowToken(), 0); return false; } }); editNameView.clearFocus(); // Setup enabled switch. CompoundButton activatedSwitch = (CompoundButton) customView .findViewById(R.id.edit_gpsfilter_area_toggle); activatedSwitch.setChecked(this.area.isEnabled()); activatedSwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { area.setEnabled(isChecked); } }); } else { this.setTitle(name); } }
From source file:com.darshancomputing.BatteryIndicatorPro.AlarmsFragment.java
private void bindView(View view) { final TextView summary_tv = (TextView) view.findViewById(R.id.alarm_summary); final View summary_box = view.findViewById(R.id.alarm_summary_box); final CompoundButton toggle = (CompoundButton) view.findViewById(R.id.toggle); final int id = mCursor.getInt(AlarmDatabase.INDEX_ID); String type = mCursor.getString(AlarmDatabase.INDEX_TYPE); String threshold = mCursor.getString(AlarmDatabase.INDEX_THRESHOLD); Boolean enabled = (mCursor.getInt(AlarmDatabase.INDEX_ENABLED) == 1); String s = pfrag.str.alarm_types_display[pfrag.str.indexOf(pfrag.str.alarm_type_values, type)]; if (type.equals("temp_rises")) { s += " " + pfrag.str.formatTemp(Integer.valueOf(threshold), convertF, false); } else if (type.equals("charge_drops") || type.equals("charge_rises")) { s += " " + threshold + "%"; }// www .ja v a2s . c o m final String summary = s; summary_tv.setText(summary); toggle.setChecked(enabled); toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { alarms.setEnabled(id, isChecked); } }); summary_box.setOnCreateContextMenuListener(new OnCreateContextMenuListener() { public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { curId = id; curIndex = mAlarmsList.indexOfChild((View) v.getParent().getParent()); getActivity().getMenuInflater().inflate(R.menu.alarm_item_context, menu); menu.setHeaderTitle(summary); } }); summary_box.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, android.view.KeyEvent event) { if (keyCode == event.KEYCODE_DPAD_CENTER && event.getAction() == event.ACTION_DOWN) v.setPressed(true); return false; } }); summary_box.setOnClickListener(new OnClickListener() { public void onClick(View v) { ComponentName comp = new ComponentName(getActivity().getPackageName(), AlarmEditActivity.class.getName()); startActivity(new Intent().setComponent(comp).putExtra(AlarmEditActivity.EXTRA_ALARM_ID, id)); } }); }
From source file:de.j4velin.wifiAutoOff.Preferences.java
@SuppressLint("NewApi") @Override//ww w . java 2s . com public boolean onCreateOptionsMenu(final Menu menu) { getMenuInflater().inflate(R.menu.menu, menu); if (android.os.Build.VERSION.SDK_INT >= 11) { CompoundButton enable = (CompoundButton) menu.findItem(R.id.enable).getActionView(); if (android.os.Build.VERSION.SDK_INT < 14) { enable.setText("Enable"); } enable.setChecked(getPackageManager().getComponentEnabledSetting( new ComponentName(this, Receiver.class)) != PackageManager.COMPONENT_ENABLED_STATE_DISABLED); // disable initially if not checked if (!enable.isChecked()) { @SuppressWarnings("deprecation") PreferenceScreen ps = getPreferenceScreen(); for (int i = 0; i < ps.getPreferenceCount(); i++) { ps.getPreference(i).setEnabled(false); } } enable.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { @SuppressWarnings("deprecation") PreferenceScreen ps = getPreferenceScreen(); // start at 1 to skip "status" preference for (int i = 1; i < ps.getPreferenceCount(); i++) { ps.getPreference(i).setEnabled(isChecked); } getPackageManager().setComponentEnabledSetting( new ComponentName(Preferences.this, Receiver.class), isChecked ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); if (!isChecked) stopService(new Intent(Preferences.this, ScreenChangeDetector.class)); getPackageManager().setComponentEnabledSetting( new ComponentName(Preferences.this, ScreenChangeDetector.class), isChecked ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); } }); } return true; }
From source file:uk.org.ngo.squeezer.dialog.AlarmSettingsDialog.java
@NonNull @Override/* w w w . java2s . co m*/ public Dialog onCreateDialog(Bundle savedInstanceState) { @SuppressLint({ "InflateParams" }) // OK, as view is passed to AlertDialog.Builder.setView() final View view = getActivity().getLayoutInflater().inflate(R.layout.alarm_settings_dialog, null); final TextView alarmVolumeHint = (TextView) view.findViewById(R.id.alarm_volume_hint); final TextView alarmSnoozeHint = (TextView) view.findViewById(R.id.alarm_snooze_hint); final TextView alarmTimeoutHint = (TextView) view.findViewById(R.id.alarm_timeout_hint); final TextView alarmFadeHint = (TextView) view.findViewById(R.id.alarm_fade_hint); final SeekBar alarmVolume = (SeekBar) view.findViewById(R.id.alarm_volume_seekbar); final SeekBar alarmSnooze = (SeekBar) view.findViewById(R.id.alarm_snooze_seekbar); final SeekBar alarmTimeout = (SeekBar) view.findViewById(R.id.alarm_timeout_seekbar); final CompoundButton alarmFadeToggle = (CompoundButton) view.findViewById(R.id.alarm_fade); alarmVolume.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { alarmVolumeHint.setText(String.format("%d%%", progress)); } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); alarmSnooze.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { alarmSnoozeHint.setText( getResources().getQuantityString(R.plurals.alarm_snooze_hint_text, progress, progress)); } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); alarmTimeout.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { if (progress == 0) { alarmTimeoutHint.setText(R.string.alarm_timeout_hint_text_zero); } else { alarmTimeoutHint.setText(getResources().getQuantityString(R.plurals.alarm_timeout_hint_text, progress, progress)); } } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); alarmFadeToggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { alarmFadeHint.setText(isChecked ? R.string.alarm_fade_on_text : R.string.alarm_fade_off_text); } }); alarmVolume.setProgress(Integer.valueOf(mHostActivity.getPlayerPref(Player.Pref.ALARM_DEFAULT_VOLUME))); alarmSnooze .setProgress(Integer.valueOf(mHostActivity.getPlayerPref(Player.Pref.ALARM_SNOOZE_SECONDS)) / 60); alarmTimeout .setProgress(Integer.valueOf(mHostActivity.getPlayerPref(Player.Pref.ALARM_TIMEOUT_SECONDS)) / 60); alarmFadeToggle.setChecked("1".equals(mHostActivity.getPlayerPref(Player.Pref.ALARM_FADE_SECONDS))); Builder builder = new Builder(getActivity()); builder.setView(view); builder.setTitle(getResources().getString(R.string.alarms_settings_dialog_title, mHostActivity.getPlayer().getName())); builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { mHostActivity.onPositiveClick(alarmVolume.getProgress(), alarmSnooze.getProgress() * 60, alarmTimeout.getProgress() * 60, alarmFadeToggle.isChecked()); } }); builder.setNegativeButton(android.R.string.cancel, null); return builder.create(); }