List of usage examples for android.widget Switch setOnCheckedChangeListener
public void setOnCheckedChangeListener(@Nullable OnCheckedChangeListener listener)
From source file:com.brewcrewfoo.performance.fragments.BatteryInfo.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup root, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.battery_info, root, false); mbattery_percent = (TextView) view.findViewById(R.id.batt_percent); mbattery_volt = (TextView) view.findViewById(R.id.batt_volt); mbattery_status = (TextView) view.findViewById(R.id.batt_status); mBattIcon = (ImageView) view.findViewById(R.id.batt_icon); if (new File(BAT_VOLT_PATH).exists()) { int volt = Integer.parseInt(Helpers.readOneLine(BAT_VOLT_PATH)); if (volt > 5000) volt = (int) Math.round(volt / 1000.0);// in microvolts mbattery_volt.setText(volt + " mV"); mBattIcon.setVisibility(ImageView.GONE); mbattery_volt.setVisibility(TextView.VISIBLE); mbattery_volt.setOnClickListener(new View.OnClickListener() { @Override//www.ja v a2 s. c o m public void onClick(View view) { Intent powerUsageIntent = new Intent(Intent.ACTION_POWER_USAGE_SUMMARY); if (powerUsageIntent.resolveActivity(context.getPackageManager()) != null) startActivity(powerUsageIntent); } }); mbattery_volt.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View view) { mBattIcon.setVisibility(ImageView.VISIBLE); mbattery_volt.setVisibility(TextView.GONE); return true; } }); } else { mBattIcon.setVisibility(ImageView.VISIBLE); mbattery_volt.setVisibility(TextView.GONE); mBattIcon.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { try { Intent powerUsageIntent = new Intent(Intent.ACTION_POWER_USAGE_SUMMARY); startActivity(powerUsageIntent); } catch (Exception e) { } } }); } SeekBar mBlxSlider = (SeekBar) view.findViewById(R.id.blx_slider); if (new File(BLX_PATH).exists()) { no_settings = false; mBlxSlider.setMax(100); mBlxVal = (TextView) view.findViewById(R.id.blx_val); mBlxVal.setText(getString(R.string.blx_title) + " " + Helpers.readOneLine(BLX_PATH) + "%"); mBlxSlider.setProgress(Integer.parseInt(Helpers.readOneLine(BLX_PATH))); mBlxSlider.setOnSeekBarChangeListener(this); Switch mSetOnBoot = (Switch) view.findViewById(R.id.blx_sob); mSetOnBoot.setChecked(mPreferences.getBoolean(BLX_SOB, false)); mSetOnBoot.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton v, boolean checked) { final SharedPreferences.Editor editor = mPreferences.edit(); editor.putBoolean(BLX_SOB, checked); if (checked) { editor.putInt(PREF_BLX, Integer.parseInt(Helpers.readOneLine(BLX_PATH))); } editor.commit(); } }); } else { LinearLayout mpart = (LinearLayout) view.findViewById(R.id.blx_layout); mpart.setVisibility(LinearLayout.GONE); } mFastChargePath = Helpers.fastcharge_path(); if (mFastChargePath != null) { no_settings = false; mFastchargeOnBoot = (Switch) view.findViewById(R.id.fastcharge_sob); mFastchargeOnBoot.setChecked( mPreferences.getBoolean(PREF_FASTCHARGE, Helpers.readOneLine(mFastChargePath).equals("1"))); mFastchargeOnBoot.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton v, boolean checked) { mPreferences.edit().putBoolean(PREF_FASTCHARGE, checked).apply(); final NotificationManager nm = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); if (checked) { new CMDProcessor().su.runWaitFor("busybox echo 1 > " + mFastChargePath); Notification n = new Notification.Builder(context) .setContentTitle(context.getText(R.string.app_name)) .setContentText(context.getText(R.string.fast_charge_notification_title)) .setTicker(context.getText(R.string.fast_charge_notification_title)) .setSmallIcon(R.drawable.ic_fastcharge).setWhen(System.currentTimeMillis()) .getNotification(); //n.flags = Notification.FLAG_NO_CLEAR; nm.notify(1337, n); } else { new CMDProcessor().su.runWaitFor("busybox echo 0 > " + mFastChargePath); nm.cancel(1337); } } }); } else { LinearLayout mpart = (LinearLayout) view.findViewById(R.id.fastcharge_layout); mpart.setVisibility(LinearLayout.GONE); } if (no_settings) { LinearLayout ns = (LinearLayout) view.findViewById(R.id.no_settings); ns.setVisibility(LinearLayout.VISIBLE); } return view; }
From source file:com.dirtyunicorns.hfm.mainFragment.java
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { settings = this.getActivity().getPreferences(Context.MODE_PRIVATE); editor = settings.edit();/*from w ww .ja va 2s . c om*/ defHosts = new File("/etc/hosts.og"); altHosts = new File("/etc/hosts.alt"); hosts = new File("/etc/hosts"); View mainView = inflater.inflate(R.layout.fragment_main, container, false); Switch sw = (Switch) mainView.findViewById(R.id.switch1); if (settings != null) { if (settings.getString("default", null) == "true") { sw.setChecked(true); } else if (settings.getString("default", null) == null) { sw.setChecked(true); } else { sw.setChecked(false); } } else { sw.setChecked(true); } sw.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { try { RunAsRoot("mount -o remount, rw /system"); } catch (IOException e) { e.printStackTrace(); } if (isChecked) { if (hosts.exists() && defHosts.exists()) { try { hosts.delete(); copyFiles(defHosts); settings.edit().putString("default", "true").commit(); } catch (IOException e) { e.printStackTrace(); } } } else { if (hosts.exists() && altHosts.exists()) { try { hosts.delete(); copyFiles(altHosts); settings.edit().putString("default", "false").commit(); } catch (IOException e) { e.printStackTrace(); } } } } }); return mainView; }
From source file:com.garlicg.screenrecord4cm.SettingsActivity.java
/** * InvisibleRecord//from w ww . j ava2s . c o m */ private void createInvisibleRecord(Bundle savedInstanceState) { boolean value = mPrefs.getInvisibleRecord(); final Switch sw = ViewFinder.byId(this, R.id.invisibleRecord); sw.setChecked(value); sw.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { mPrefs.saveInvisibleRecord(isChecked); } }); }
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(); }/* ww w .j a va 2s . c om*/ } }); 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:com.example.android.apprestrictionenforcer.AppRestrictionEnforcerFragment.java
private void updateApprovals(Context context, String[] approvals, String[] selectedApprovals) { mCurrentRestrictions.putStringArray(RESTRICTION_KEY_APPROVALS, selectedApprovals); mLayoutApprovals.removeAllViews();// w w w. ja va 2 s .c om for (String approval : approvals) { Switch sw = new Switch(context); sw.setText(approval); sw.setTag(approval); sw.setChecked(Arrays.asList(selectedApprovals).contains(approval)); sw.setOnCheckedChangeListener(this); sw.setId(R.id.approval); mLayoutApprovals.addView(sw); } }
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 ww w .j av a 2 s.c o m public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { mSharedPrefs.setGeofenceEnabled(isChecked); invalidateOptionsMenu(); } }); }
From source file:com.synox.android.ui.fragment.ShareFileFragment.java
/** * Binds listener for user actions to create or delete a public share * to the views receiving the user events. * * @param shareView Root view in the fragment. *//*www. j a va 2 s . co m*/ private void initShareViaLinkListener(View shareView) { mOnShareViaLinkSwitchCheckedChangeListener = new OnShareViaLinkListener(); Switch shareViaLinkSwitch = (Switch) shareView.findViewById(R.id.shareViaLinkSectionSwitch); shareViaLinkSwitch.setOnCheckedChangeListener(mOnShareViaLinkSwitchCheckedChangeListener); }
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/* ww w . j av a 2s .co 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:com.TwentyCodes.android.IOIOTruck.NavigationActivity.java
/** * (non-Javadoc)//from w ww . j av a2s.c o m * @see android.support.v4.app.FragmentActivity#onCreate(android.os.Bundle) */ @Override protected void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.nav_activity); /* * init UI */ mLog = (TextView) findViewById(R.id.log_textView); mGoButton = (Button) findViewById(R.id.go_button); mProgress = (ProgressBar) findViewById(R.id.progressBar); mScrollView = (ScrollView) findViewById(R.id.scrollview); Switch scrollSwitch = (Switch) findViewById(R.id.scrolling_switch); mAccuracyTextView = (TextView) findViewById(R.id.accuracy_textview); mLastUpdateTextView = (TextView) findViewById(R.id.time_textview); /* * init listeners */ scrollSwitch.setOnCheckedChangeListener(this); mGoButton.setOnClickListener(this); findViewById(R.id.mark_my_lcoation_button).setOnClickListener(this); findViewById(R.id.my_location_button).setOnClickListener(this); findViewById(R.id.map_button).setOnClickListener(this); mIOIOManager = new IOIOTruckConnectionManager(this, this); mIOIOManager.getIOIOAndroidApplicationHelper().create(); }
From source file:net.henryco.opalette.application.programs.sub.programs.aImage.RotationControl.java
@Override protected void onFragmentCreate(View view, AppMainProto context, @Nullable Bundle savedInstanceState) { updateFunc = () -> {// w w w . ja v a 2 s.com imgHolder.setStateUpdated(); context.getRenderSurface().update(); }; Switch[] switches = new Switch[2]; OPallViewInjector<AppMainProto> flipButtons = new OPallViewInjector<AppMainProto>(view, R.layout.flip_buttons_layout) { @Override protected void onInject(AppMainProto context, View view) { Texture image = imgHolder.getRenderData(); int textColor = ContextCompat.getColor(context.getActivityContext(), InjectableSeekBar.TEXT_COLOR_DEFAULT_DARK); Switch horizontal = (Switch) view.findViewById(R.id.flipHorizontalButton); Switch vertical = (Switch) view.findViewById(R.id.flipVerticalButton); switches[0] = horizontal; switches[1] = vertical; horizontal.setTextColor(textColor); horizontal.setChecked(image.getFlip()[0]); vertical.setTextColor(textColor); vertical.setChecked(image.getFlip()[1]); horizontal.setOnCheckedChangeListener((button, isChecked) -> { image.setFlip(isChecked, image.getFlip()[1]); updateFunc.run(); }); vertical.setOnCheckedChangeListener((button, isChecked) -> { image.setFlip(image.getFlip()[0], isChecked); updateFunc.run(); }); } }; String ang = context.getActivityContext().getResources().getString(R.string.angle); InjectableSeekBar angleBar = new InjectableSeekBar(view, ang).setDefaultPoint(0, (int) (max_angle * 0.5f)) .setMax((int) max_angle); angleBar.onBarCreate( bar -> bar.setProgress(angleBar.de_norm(imgHolder.getRenderData().getRotation() / max_angle))); angleBar.setBarListener(new OPallSeekBarListener().onStop(stop).onProgress((bar, progress, fromUser) -> { if (fromUser) { imgHolder.getRenderData().setFilterEnable(false).setRotation(angleBar.norm(progress) * max_angle); updateFunc.run(); } })); backListener = context.getRenderSurface().getLastTouchEventListener(); context.getRenderSurface().removeTouchEventListener(backListener); touchEventListener = new OPallSurfaceTouchListener(context.getActivityContext()); touchEventListener.setOnActionUp(event -> timer.startIfWaiting().refresh()); context.getRenderSurface().addOnTouchEventListener(touchEventListener.setOnActionMove((dx, dy, event) -> { float angle = clamp(imgHolder.getRenderData().getRotation() + dx * touch_sensitivity, max_angle, -max_angle); imgHolder.getRenderData().setFilterEnable(false).setRotation(angle); angleBar.setProgress(angleBar.de_norm(angle / max_angle)); updateFunc.run(); })); context.setTopControlButton( button -> button.setTitle(R.string.control_top_bar_button_reset).setVisible(true).setEnabled(true), () -> { angleBar.setProgress(angleBar.de_norm(0)); imgHolder.getRenderData().setRotation(0).setFlip(false, false); switches[0].setChecked(false); switches[1].setChecked(false); updateFunc.run(); }); OPallViewInjector.inject(context.getActivityContext(), flipButtons, angleBar); }