List of usage examples for android.widget ToggleButton setOnCheckedChangeListener
public void setOnCheckedChangeListener(@Nullable OnCheckedChangeListener listener)
From source file:Main.java
public static final ToggleButton initToggleButton(View view, int resourceId, CompoundButton.OnCheckedChangeListener listener) { ToggleButton ret = null; ret = findToggleButtonX(view, resourceId); ret.setOnCheckedChangeListener(listener); return ret;/* w w w . java 2 s. co m*/ }
From source file:com.jefftharris.passwdsafe.lib.AboutDialog.java
/** * Update the fields of the about fragment *///w ww . ja va 2s . c o m public static String updateAboutFields(View detailsView, final String extraLicenseInfo, Context ctx) { String name; StringBuilder version = new StringBuilder(); PackageInfo pkgInfo = PasswdSafeUtil.getAppPackageInfo(ctx); if (pkgInfo != null) { name = ctx.getString(pkgInfo.applicationInfo.labelRes); version.append(pkgInfo.versionName); } else { name = null; } if (PasswdSafeUtil.DEBUG) { version.append(" (DEBUG)"); } TextView tv = (TextView) detailsView.findViewById(R.id.version); tv.setText(version); tv = (TextView) detailsView.findViewById(R.id.build_id); tv.setText(BuildConfig.BUILD_ID); tv = (TextView) detailsView.findViewById(R.id.build_date); tv.setText(BuildConfig.BUILD_DATE); tv = (TextView) detailsView.findViewById(R.id.release_notes); tv.setText(Html.fromHtml(tv.getText().toString().replace("\n", "<br>"))); ToggleButton btn = (ToggleButton) detailsView.findViewById(R.id.toggle_license); final TextView licenseView = (TextView) detailsView.findViewById(R.id.license); btn.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { licenseView.setText(extraLicenseInfo); licenseView.setVisibility(isChecked ? View.VISIBLE : View.GONE); } }); btn.setVisibility((extraLicenseInfo != null) ? View.VISIBLE : View.GONE); return name; }
From source file:net.futuredrama.jomaceld.circularpbexamples.ExampleFragments.Example2Fragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_example2, container, false); // Get a pointer to the layout's progressbar pBar = (CircularProgressBarView) rootView.findViewById(R.id.pbar); if (pBar != null) setupProgressbar();//from w w w. j ava 2 s. c o m ToggleButton toogleButton = (ToggleButton) rootView.findViewById(R.id.anim_toggleButton); toogleButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean b) { setLoading(b); } }); return rootView; }
From source file:com.example.android.supportv4.graphics.RoundedBitmapDrawableActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_rounded_bitmap); // Create a bitmap and set it circular. Bitmap bitmap = BitmapFactory.decodeResource(getResources(), IMAGE_RES); mRoundedBitmapDrawable = RoundedBitmapDrawableFactory.create(getResources(), bitmap); // Get references to the inflated views. ToggleButton toggle = (ToggleButton) findViewById(R.id.toggle_round); ImageView image = (ImageView) findViewById(R.id.image); // Set up initial view state and on checked change listener. image.setImageDrawable(mRoundedBitmapDrawable); toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override/*from w ww .j a v a2 s. com*/ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { mRoundedBitmapDrawable.setCircular(isChecked); } }); }
From source file:com.google.firebase.samples.apps.mlkit.LivePreviewActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.d(TAG, "onCreate"); setContentView(R.layout.activity_live_preview); preview = (CameraSourcePreview) findViewById(R.id.firePreview); if (preview == null) { Log.d(TAG, "Preview is null"); }/*from w w w .j a va2s . c om*/ graphicOverlay = (GraphicOverlay) findViewById(R.id.fireFaceOverlay); if (graphicOverlay == null) { Log.d(TAG, "graphicOverlay is null"); } Spinner spinner = (Spinner) findViewById(R.id.spinner); List<String> options = new ArrayList<>(); options.add(FACE_DETECTION); options.add(TEXT_DETECTION); options.add(BARCODE_DETECTION); options.add(IMAGE_LABEL_DETECTION); options.add(CLASSIFICATION); // Creating adapter for spinner ArrayAdapter<String> dataAdapter = new ArrayAdapter<>(this, R.layout.spinner_style, options); // Drop down layout style - list view with radio button dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // attaching data adapter to spinner spinner.setAdapter(dataAdapter); spinner.setOnItemSelectedListener(this); ToggleButton facingSwitch = (ToggleButton) findViewById(R.id.facingswitch); facingSwitch.setOnCheckedChangeListener(this); if (allPermissionsGranted()) { createCameraSource(selectedModel); } else { getRuntimePermissions(); } }
From source file:ca.ualberta.cs.shoven_habittracker.NewHabitActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_new_habit); final Schedule schedule = new Schedule(); final Integer sun = 0, mon = 1, tue = 2, wed = 3, thu = 4, fri = 5, sat = 6; TextView textView = (TextView) findViewById(R.id.pickDateTextView); textView.setText(new FormattedDate().toString()); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.saveFab); fab.setOnClickListener(new View.OnClickListener() { @Override/*from w w w. j a v a2 s . c o m*/ public void onClick(View view) { saveNewHabit(view, schedule); finish(); } }); ToggleButton sundayToggle = (ToggleButton) findViewById(R.id.sundayToggleButton); sundayToggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { // The toggle is enabled schedule.addToSchedule(sun); } else { // The toggle is disabled schedule.removeFromSchedule(sun); } } }); ToggleButton mondayToggle = (ToggleButton) findViewById(R.id.mondayToggleButton); mondayToggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { // The toggle is enabled schedule.addToSchedule(mon); } else { // The toggle is disabled schedule.removeFromSchedule(mon); } } }); ToggleButton tuesdayToggle = (ToggleButton) findViewById(R.id.tuesdayToggleButton); tuesdayToggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { // The toggle is enabled schedule.addToSchedule(tue); } else { // The toggle is disabled schedule.removeFromSchedule(tue); } } }); ToggleButton wednesdayToggle = (ToggleButton) findViewById(R.id.wednesdayToggleButton); wednesdayToggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { // The toggle is enabled schedule.addToSchedule(wed); } else { // The toggle is disabled schedule.removeFromSchedule(wed); } } }); ToggleButton thursdayToggle = (ToggleButton) findViewById(R.id.thursdayToggleButton); thursdayToggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { // The toggle is enabled schedule.addToSchedule(thu); } else { // The toggle is disabled schedule.removeFromSchedule(thu); } } }); ToggleButton fridayToggle = (ToggleButton) findViewById(R.id.fridayToggleButton); fridayToggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { // The toggle is enabled schedule.addToSchedule(fri); } else { // The toggle is disabled schedule.removeFromSchedule(fri); } } }); ToggleButton saturdayToggle = (ToggleButton) findViewById(R.id.saturdayToggleButton); saturdayToggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { // The toggle is enabled schedule.addToSchedule(sat); } else { // The toggle is disabled schedule.removeFromSchedule(sat); } } }); }
From source file:org.rockettrack.MapFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.map_view, null, false); ToggleButton chkFollowMe = (ToggleButton) v.findViewById(R.id.chkFollowMe); followMe = chkFollowMe.isChecked();/* ww w . j a va2s . com*/ chkFollowMe.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton arg0, boolean arg1) { followMe = arg1; } }); return v; }
From source file:com.google.firebase.samples.apps.mlkit.java.LivePreviewActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.d(TAG, "onCreate"); setContentView(R.layout.activity_live_preview); preview = (CameraSourcePreview) findViewById(R.id.firePreview); if (preview == null) { Log.d(TAG, "Preview is null"); }// w ww .j av a2s . c o m graphicOverlay = (GraphicOverlay) findViewById(R.id.fireFaceOverlay); if (graphicOverlay == null) { Log.d(TAG, "graphicOverlay is null"); } Spinner spinner = (Spinner) findViewById(R.id.spinner); List<String> options = new ArrayList<>(); options.add(FACE_CONTOUR); options.add(FACE_DETECTION); options.add(TEXT_DETECTION); options.add(BARCODE_DETECTION); options.add(IMAGE_LABEL_DETECTION); options.add(CLASSIFICATION_QUANT); options.add(CLASSIFICATION_FLOAT); // Creating adapter for spinner ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, R.layout.spinner_style, options); // Drop down layout style - list view with radio button dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // attaching data adapter to spinner spinner.setAdapter(dataAdapter); spinner.setOnItemSelectedListener(this); ToggleButton facingSwitch = (ToggleButton) findViewById(R.id.facingSwitch); facingSwitch.setOnCheckedChangeListener(this); // Hide the toggle button if there is only 1 camera if (Camera.getNumberOfCameras() == 1) { facingSwitch.setVisibility(View.GONE); } if (allPermissionsGranted()) { createCameraSource(selectedModel); } else { getRuntimePermissions(); } }
From source file:ca.ualberta.cs.shoven_habittracker.EditHabitActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_edit_habit); Schedule scheduleToSet = new Schedule(); final Integer sun = 0, mon = 1, tue = 2, wed = 3, thu = 4, fri = 5, sat = 6; Bundle bundle = getIntent().getExtras(); position = bundle.getInt("position"); activity = bundle.getString("activity"); Habit habitToSet;// www. j a v a 2s .c o m habitToSet = controller.getAllHabits().getHabitList().get(position); final Habit habit = habitToSet; final Schedule schedule = initializeFields(controller, habit, scheduleToSet); FloatingActionButton editFab = (FloatingActionButton) findViewById(R.id.saveEditFab); editFab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Snackbar.make(view, "Habit update saved", Snackbar.LENGTH_LONG).setAction("Action", null).show(); saveHabitChanges(view, habit, schedule); finish(); } }); ToggleButton sundayToggle = (ToggleButton) findViewById(R.id.editSundayToggleButton); sundayToggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { // The toggle is enabled schedule.addToSchedule(sun); } else { // The toggle is disabled schedule.removeFromSchedule(sun); } } }); ToggleButton mondayToggle = (ToggleButton) findViewById(R.id.editMondayToggleButton); mondayToggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { // The toggle is enabled schedule.addToSchedule(mon); } else { // The toggle is disabled schedule.removeFromSchedule(mon); } } }); ToggleButton tuesdayToggle = (ToggleButton) findViewById(R.id.editTuesdayToggleButton); tuesdayToggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { // The toggle is enabled schedule.addToSchedule(tue); } else { // The toggle is disabled schedule.removeFromSchedule(tue); } } }); ToggleButton wednesdayToggle = (ToggleButton) findViewById(R.id.editWednesdayToggleButton); wednesdayToggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { // The toggle is enabled schedule.addToSchedule(wed); } else { // The toggle is disabled schedule.removeFromSchedule(wed); } } }); ToggleButton thursdayToggle = (ToggleButton) findViewById(R.id.editThursdayToggleButton); thursdayToggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { // The toggle is enabled schedule.addToSchedule(thu); } else { // The toggle is disabled schedule.removeFromSchedule(thu); } } }); ToggleButton fridayToggle = (ToggleButton) findViewById(R.id.editFridayToggleButton); fridayToggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { // The toggle is enabled schedule.addToSchedule(fri); } else { // The toggle is disabled schedule.removeFromSchedule(fri); } } }); ToggleButton saturdayToggle = (ToggleButton) findViewById(R.id.editSaturdayToggleButton); saturdayToggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { // The toggle is enabled schedule.addToSchedule(sat); } else { // The toggle is disabled schedule.removeFromSchedule(sat); } } }); }
From source file:com.android.nsboc.ComposeFragment.java
public CompoundButton.OnCheckedChangeListener getNextToggleListener(final LinearLayout complianceLayout) { return new CompoundButton.OnCheckedChangeListener() { @Override/*w w w. j ava2s .com*/ public void onCheckedChanged(CompoundButton toggleButton, boolean isChecked) { if (isChecked) { mAnotherComplianceLayout = (LinearLayout) View.inflate(getActivity(), R.layout.compliance_layout, null); TextView imagePickerLabel = (TextView) mAnotherComplianceLayout .findViewById(R.id.violation_image_picker); imagePickerLabel.setText(imagePickerLabel.getText().toString().replace(" " + mSectionsCount, " " + (mSectionsCount + 1))); EditText commentEditText = (EditText) mAnotherComplianceLayout .findViewById(R.id.comment_edittext); commentEditText.setHint(commentEditText.getText().toString().replace(" " + mSectionsCount, " " + (mSectionsCount + 1))); TextView isAnotherLabel = (TextView) mAnotherComplianceLayout .findViewById(R.id.is_another_label); isAnotherLabel.setText(isAnotherLabel.getText().toString().replace((mSectionsCount + 1) + "?", (mSectionsCount + 2) + "?")); ToggleButton anotherToggle = (ToggleButton) mAnotherComplianceLayout .findViewById(R.id.compliance_toggle); anotherToggle.setOnCheckedChangeListener(getNextToggleListener(mAnotherComplianceLayout)); complianceLayout.addView(mAnotherComplianceLayout); mSectionsCount++; } else { mSectionsCount--; mAnotherComplianceLayout.setVisibility(View.GONE); } } }; }