List of usage examples for android.widget ToggleButton setChecked
@Override public void setChecked(boolean checked)
From source file:com.timothy.android.api.fragment.RightFragment.java
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { activity = (SlidingActivity) getActivity(); mContext = activity.getApplicationContext(); sp = activity.getSharedPreferences("AndroidAPISP", 0); View view = inflater.inflate(R.layout.right, null); boolean syncFlag = SPUtil.getBooleanFromSP(SPUtil.SP_KEY_SYNC_FLAG, sp); //syncFlag//from w ww. j a v a 2s.c o m ToggleButton syncFlagBtn = (ToggleButton) view.findViewById(R.id.syncFlagBtn); syncFlagBtn.setChecked(syncFlag); syncFlagBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ToggleButton tb = (ToggleButton) v; SPUtil.save2SP(SPUtil.SP_KEY_SYNC_FLAG, tb.isChecked(), sp); } }); //lstReadTV TextView lstReadTV = (TextView) view.findViewById(R.id.lstReadTV); lstReadTV.setMovementMethod(ScrollingMovementMethod.getInstance()); int branchIndex = SPUtil.getIntegerFromSP(SPUtil.CURRENT_BRANCH_INDEX, sp); String[] contentsArray = activity.filterBranch(branchIndex); String contents = ContentUtil.getContentsById(contentsArray, SPUtil.getIntegerFromSP(SPUtil.CURRENT_INDEX, sp)); if (contents != null) { String[] contentArray = contents.split(","); if (contentArray != null && contentArray.length >= 4) { String contentName = contentArray[3]; lstReadTV.setText(contentName); } } Button gotoBtn = (Button) view.findViewById(R.id.gotoBtn); gotoBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { refreshActivity(); } }); return view; }
From source file:cn.kavelcortex.bookpriceculculator.TotalPrice.java
private void pressButton(ToggleButton button, boolean b) { button.setChecked(b); }
From source file:org.adaway.ui.tcpdump.TcpdumpFragment.java
@Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { // Inflate layout View view = inflater.inflate(R.layout.tcpdump_fragment, container, false); // Get activity final Activity activity = this.getActivity(); // Create root shell try {/*from w ww .jav a2 s. c o m*/ this.mRootShell = Shell.startRootShell(); } catch (Exception exception) { Log.e(Constants.TAG, "Unable to create root shell for tcpdump.", exception); } /* * Configure view. */ // Get tcpdump toggle button ToggleButton tcpdumpToggleButton = view.findViewById(R.id.tcpdump_toggle_monitoring); // Set tcpdump toggle button checked state according tcpdump running state tcpdumpToggleButton.setChecked(TcpdumpUtils.isTcpdumpRunning(this.mRootShell)); // Set tcpdump toggle button checked listener to start/stop tcpdump tcpdumpToggleButton.setOnCheckedChangeListener((buttonView, checked) -> { // Check shell if (this.mRootShell == null) { return; } // Check button checked state if (checked) { // Start tcpdump if (!TcpdumpUtils.startTcpdump(activity, this.mRootShell)) { // If tcpdump start failed, uncheck button tcpdumpToggleButton.setChecked(false); } } else { // Stop tcpdump TcpdumpUtils.stopTcpdump(this.mRootShell); } }); // Get open button Button openButton = view.findViewById(R.id.tcpdump_show_results); // Set open button on click listener to start tcpdump log activity openButton.setOnClickListener( clickedView -> this.startActivity(new Intent(activity, TcpdumpLogActivity.class))); // Return created view return view; }
From source file:com.quaap.audiometer.MainActivity.java
/** * Dispatch onPause() to fragments./*from www . j a v a 2s . c om*/ */ @Override protected void onPause() { if (mMicLevelReader.isRunning()) { final ToggleButton onoff = (ToggleButton) findViewById(R.id.toggleButton); onoff.setChecked(false); stopit(); } super.onPause(); }
From source file:com.a3did.partner.recosample.MainActivity.java
@Override protected void onResume() { super.onResume(); if (this.isBackgroundMonitoringServiceRunning(this)) { ToggleButton toggle = (ToggleButton) findViewById(R.id.backgroundMonitoringToggleButton); toggle.setChecked(true); }/*from w ww . j a v a 2 s.c om*/ if (this.isBackgroundRangingServiceRunning(this)) { ToggleButton toggle = (ToggleButton) findViewById(R.id.backgroundRangingToggleButton); toggle.setChecked(true); } }
From source file:pl.zajecia.cw3.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.settings_layout); mIntervalEditText = (EditText) findViewById(R.id.intervalEditText); mIntervalSpinner = (Spinner) findViewById(R.id.intervalSpinner); /** //from w ww . ja v a 2s. com * On focus change listener to hide keyboard when focus left editText */ ((LinearLayout) findViewById(R.id.mainLinearLayout)).setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View view, boolean arg) { InputMethodManager imm = (InputMethodManager) view.getContext() .getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(view.getWindowToken(), 0); } }); mRandomOrderCheckBox = (CheckBox) findViewById(R.id.randomOrderCheckBox); mChangeDuringSleepCheckBox = (CheckBox) findViewById(R.id.changeDuringSleepCheckBox); mChangeOnScreenOnCheckBox = (CheckBox) findViewById(R.id.changeOnScreenOnCheckBox); mDisableOnBatteryLowCheckBox = (CheckBox) findViewById(R.id.dontChangeOnBatteryLowCheckBox); mEditPhotosButton = (Button) findViewById(R.id.viewGalleryButton); mSaveSettingsButton = (Button) findViewById(R.id.saveSettingsButton); mActivatedButton = (ToggleButton) findViewById(R.id.activateButton); //Listeners: mSaveSettingsButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { saveSettings(); Toast.makeText(getApplicationContext(), R.string.settings_saved, Toast.LENGTH_SHORT).show(); } }); mActivatedButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ToggleButton button = (ToggleButton) v; if (button.isChecked()) { button.setChecked(runService()); } else { cancelService(); } } }); mEditPhotosButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(getApplication(), PhotosActivity.class); startActivity(intent); } }); }
From source file:com.keysolutions.meteorparties.PartyDetailFragment.java
/** * Updates current RSVP display/*from ww w . ja v a 2 s .c om*/ * @param rootView root view holding all the fields */ @SuppressLint("NewApi") public void updateMyRsvpDisplay(View rootView) { // add info about my RSVP boolean isLoggedIn = MyDDPState.getInstance().isLoggedIn(); ((View) (rootView.findViewById(R.id.login_for_rsvp))) .setVisibility(isLoggedIn ? View.INVISIBLE : View.VISIBLE); ((View) (rootView.findViewById(R.id.rsvp_buttons))) .setVisibility(isLoggedIn ? View.VISIBLE : View.INVISIBLE); ((View) (rootView.findViewById(R.id.label_my_rsvp))) .setVisibility(isLoggedIn ? View.VISIBLE : View.INVISIBLE); if (isLoggedIn) { RadioGroup rsvpButtons = ((RadioGroup) rootView.findViewById(R.id.rsvp_buttons)); rsvpButtons.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup radioGroup, int checkedId) { for (int j = 0; j < radioGroup.getChildCount(); j++) { final ToggleButton view = (ToggleButton) radioGroup.getChildAt(j); view.setChecked(view.getId() == checkedId); } } }); ToggleButton btnYes = ((ToggleButton) rootView.findViewById(R.id.rsvp_yes)); ToggleButton btnNo = ((ToggleButton) rootView.findViewById(R.id.rsvp_no)); ToggleButton btnMaybe = ((ToggleButton) rootView.findViewById(R.id.rsvp_maybe)); OnClickListener toggleListener = new OnClickListener() { @Override public void onClick(View v) { onToggle(v); } }; btnYes.setOnClickListener(toggleListener); btnNo.setOnClickListener(toggleListener); btnMaybe.setOnClickListener(toggleListener); String myRsvp = getMyRsvp(); if (myRsvp != null) { if (myRsvp.equals("yes")) { rsvpButtons.check(R.id.rsvp_yes); } else if (myRsvp.equals("no")) { rsvpButtons.check(R.id.rsvp_no); } else if (myRsvp.equals("maybe")) { rsvpButtons.check(R.id.rsvp_maybe); } } // if we can, add button animation on Yes because it's cool if (android.os.Build.VERSION.SDK_INT > 11) { btnYes.animate().setDuration(200); btnYes.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View button, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { ((ToggleButton) button).animate().setInterpolator(sDecelerator).scaleX(.7f).scaleY(.7f); } else { ((ToggleButton) button).animate().setInterpolator(sOverShooter).scaleX(1f).scaleY(1f); } return false; } }); } } }
From source file:net.illusor.swipeplayer.fragments.PlaylistOptionsFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); View view = this.getView(); ToggleButton btnShuffle = (ToggleButton) view.findViewById(R.id.id_playlist_shuffle); ToggleButton btnRepeat = (ToggleButton) view.findViewById(R.id.id_playlist_repeat); btnShuffle.setOnClickListener(this); btnRepeat.setOnClickListener(this); Context context = this.getActivity(); this.shuffleKey = PreferencesHelper.getShuffleKey(context); this.repeatMode = PreferencesHelper.getRepeatMode(context); btnShuffle.setChecked(this.shuffleKey != SwipeActivity.SHUFFLE_KEY_NOSHUFFLE); btnRepeat.setChecked(this.repeatMode == RepeatMode.Playlist); }
From source file:net.henryco.opalette.application.MainActivity.java
private void checkToggle(ToggleButton button) { for (ToggleButton b : toggleGroup) { if (b == button) button.setChecked(true); else/*from w w w . j a v a 2 s . c o m*/ b.setChecked(false); } }
From source file:com.nikhilnayak.games.octoshootar.ui.fragments.AboutFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fragment_about, container, false); v.findViewById(R.id.beta_sensor_delay).setOnClickListener(new View.OnClickListener() { @Override/*from www . jav a 2 s . co m*/ public void onClick(View v) { new SensorDelayDialogFragment().show(getFragmentManager(), null); } }); final ToggleButton compatibilityMode = ((ToggleButton) v.findViewById(R.id.beta_compatibility_button)); final SharedPreferences betaSharedPreferences = getActivity() .getSharedPreferences(BetaUtils.KEY_SHARED_PREFERENCES, Context.MODE_PRIVATE); final SharedPreferences.Editor editor = betaSharedPreferences.edit(); final boolean isCompatibilityModeActivated = betaSharedPreferences .getBoolean(BetaUtils.KEY_COMPATIBILITY_MODE_ACTIVATED, false); compatibilityMode.setChecked(isCompatibilityModeActivated); compatibilityMode.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { editor.putBoolean(BetaUtils.KEY_COMPATIBILITY_MODE_ACTIVATED, isChecked); editor.commit(); } }); setVersionName(v); initReportButton(v); initEmailButton(v); return v; }