List of usage examples for android.widget ToggleButton setOnCheckedChangeListener
public void setOnCheckedChangeListener(@Nullable OnCheckedChangeListener listener)
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 {// w w w .j av a 2 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.android.nsboc.ComposeFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (mItem != null) { switch (mItem.id + "") { case "1": mRootView = inflater.inflate(R.layout.form_unlicensed, container, false); break; case "2": mRootView = inflater.inflate(R.layout.form_salon, container, false); break; }/* ww w. j ava2 s . co m*/ } showCurrentDateInEditText(); ToggleButton complianceToggle = (ToggleButton) mRootView.findViewById(R.id.compliance_toggle); if (complianceToggle != null) { final LinearLayout complianceContainer = (LinearLayout) mRootView .findViewById(R.id.compliance_container); complianceToggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (!isChecked) { complianceContainer.setVisibility(View.VISIBLE); final LinearLayout complianceLayout = (LinearLayout) View.inflate(getActivity(), R.layout.compliance_layout, null); Spinner violationTypeSpinner = (Spinner) complianceLayout .findViewById(R.id.violation_type_spinner); violationTypeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { switch (position) { case 0: complianceLayout.findViewById(R.id.type_citation_container) .setVisibility(View.VISIBLE); break; case 1: complianceLayout.findViewById(R.id.type_citation_container) .setVisibility(View.GONE); break; } } @Override public void onNothingSelected(AdapterView<?> parent) { } }); ToggleButton anotherToggle = (ToggleButton) complianceLayout .findViewById(R.id.compliance_toggle); anotherToggle.setOnCheckedChangeListener(getNextToggleListener(complianceLayout)); complianceContainer.addView(complianceLayout); } else { complianceContainer.setVisibility(View.GONE); } } }); } ToggleButton emailToggle = (ToggleButton) mRootView.findViewById(R.id.emailTo_toggle); if (emailToggle != null) { final LinearLayout emailLayout = (LinearLayout) mRootView.findViewById(R.id.emailTo_layout); emailToggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { emailLayout.setVisibility(View.VISIBLE); } else { emailLayout.setVisibility(View.GONE); } } }); } final TextView noticeTextView = (TextView) mRootView.findViewById(R.id.notice_textview); if (noticeTextView != null) { noticeTextView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (noticeTextView.getCurrentTextColor() == Color.BLACK) { noticeTextView.setText(R.string.civil_citation_header); noticeTextView.setTextColor(Color.parseColor("#17405e")); noticeTextView.setText(Html.fromHtml("<u>" + noticeTextView.getText() + "</u>")); mRootView.findViewById(R.id.civil_citation).requestFocus(); } else { noticeTextView.setText(R.string.civil_citation_notice); noticeTextView.setMaxLines(Integer.MAX_VALUE); noticeTextView.setTextColor(Color.BLACK); noticeTextView.setText( noticeTextView.getText().toString().replace("<u>", "").replace("</u>", "")); } } }); } Spinner stateSpinner = (Spinner) mRootView.findViewById(R.id.state); if (stateSpinner != null) { stateSpinner.setSelection(27); } return mRootView; }
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// w w w .ja v a 2 s. c om 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; }
From source file:com.thalmic.android.sample.helloworld.HelloWorldActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_hello_world); sensorManager = (SensorManager) this.getSystemService(SENSOR_SERVICE); vector = sensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR); acc = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); mag = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD); mLockStateView = (TextView) findViewById(R.id.lock_state); mTextView = (TextView) findViewById(R.id.text); mRoll = (TextView) findViewById(R.id.roll); mPitch = (TextView) findViewById(R.id.pitch); mYaw = (TextView) findViewById(R.id.yaw); EditText videoip = (EditText) findViewById(R.id.videoip); videoip.setOnEditorActionListener(new OnEditorActionListener() { @Override//from ww w . j a v a2s .c o m public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { boolean handled = false; if (actionId == EditorInfo.IME_ACTION_SEND) { ip = v.getText().toString(); startVideo(); handled = true; } return handled; } }); EditText connect = (EditText) findViewById(R.id.connect); connect.setOnEditorActionListener(new OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { boolean handled = false; if (actionId == EditorInfo.IME_ACTION_SEND) { try { String address = v.getText().toString(); client = new Client(("tcp://" + address + ":6767"), "client"); try { client.send("runtime", "getUptime"); //client.send("runtime", "start", "arduino", "Arduino"); //client.send("runtime", "start", "servo01", "Servo"); } catch (IOException e) { e.printStackTrace(); } } catch (URISyntaxException e) { e.printStackTrace(); } handled = true; } return handled; } }); EditText comPort = (EditText) findViewById(R.id.comport); comPort.setOnEditorActionListener(new OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { boolean handled = false; if (actionId == EditorInfo.IME_ACTION_SEND) { String address = v.getText().toString(); if (client != null) { try { client.send("arduino", "connect", address); } catch (IOException e) { e.printStackTrace(); } } handled = true; } return handled; } }); final Button calibrate = (Button) findViewById(R.id.calibrate); calibrate.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // // Perform action on click if (client != null) { try { client.send("oculus", "calibrate"); } catch (IOException e) { e.printStackTrace(); } } } }); ToggleButton toggleCardboard = (ToggleButton) findViewById(R.id.cardboard); toggleCardboard.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { cardboardMode = true; } else { cardboardMode = false; } } }); ToggleButton toggleHeadTracking = (ToggleButton) findViewById(R.id.headTrackingButton); toggleHeadTracking.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { headTrackingMode = true; } else { headTrackingMode = false; } } }); // First, we initialize the Hub singleton with an application identifier. Hub hub = Hub.getInstance(); if (!hub.init(this, getPackageName())) { // We can't do anything with the Myo device if the Hub can't be initialized, so exit. Toast.makeText(this, "Couldn't initialize Hub", Toast.LENGTH_SHORT).show(); finish(); return; } // Next, register for DeviceListener callbacks. hub.addListener(mListener); //hub.attachToAdjacentMyo(); StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); }
From source file:org.mythtv.client.ui.MainMenuFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View mainMenuView = inflater.inflate(R.layout.fragment_main_menu, container, false); ToggleButton toggleIsAway = (ToggleButton) mainMenuView.findViewById(R.id.toggleButtonIsAway); toggleIsAway.setOnCheckedChangeListener(this.homeAwayCheckedChanged); // set version string - we only do this to prepend the 'V' TextView tView = (TextView) mainMenuView.findViewById(R.id.textview_mainmenu_version); tView.setText("V" + this.getString(R.string.app_version)); // set frontends spinner Spinner spinner = (Spinner) mainMenuView.findViewById(R.id.spinner_frontends); spinner.setAdapter(adapter);//w ww . j a v a 2 s . c o m spinner.setOnItemSelectedListener(this); // set preference button click listener ImageButton prefButton = (ImageButton) mainMenuView.findViewById(R.id.imagebutton_main_menu_preferences); prefButton.setOnClickListener(this.preferenceButtonOnClick); // set mythmote button click listener ImageButton mmButton = (ImageButton) mainMenuView.findViewById(R.id.imagebutton_main_menu_mythmote); mmButton.setOnClickListener(this.mythmoteButtonOnClick); // set activities button click listeners Button aBtn = (Button) mainMenuView.findViewById(R.id.button_main_menu_guide); aBtn.setOnClickListener(this.activityButtonOnClick); aBtn = (Button) mainMenuView.findViewById(R.id.button_main_menu_music); aBtn.setOnClickListener(this.activityButtonOnClick); aBtn = (Button) mainMenuView.findViewById(R.id.button_main_menu_pictures); aBtn.setOnClickListener(this.activityButtonOnClick); aBtn = (Button) mainMenuView.findViewById(R.id.button_main_menu_recording_rules); aBtn.setOnClickListener(this.activityButtonOnClick); aBtn = (Button) mainMenuView.findViewById(R.id.button_main_menu_recordings); aBtn.setOnClickListener(this.activityButtonOnClick); aBtn = (Button) mainMenuView.findViewById(R.id.button_main_menu_upcoming); aBtn.setOnClickListener(this.activityButtonOnClick); aBtn = (Button) mainMenuView.findViewById(R.id.button_main_menu_videos); aBtn.setOnClickListener(this.activityButtonOnClick); return mainMenuView; }
From source file:org.mythtv.client.ui.MainMenuFragment.java
@Override public void onResume() { super.onResume(); // get connected location profile LocationProfile profile = this.mLocationProfileDaoHelper.findConnectedProfile(this.getActivity()); // check if we have a connected profile if (null == profile) { // auto connected to the first profile found List<LocationProfile> profiles = mLocationProfileDaoHelper.findAll(getActivity()); if (profiles.size() > 0) { profile = profiles.get(0);/*from w w w . j a va2s.co m*/ // mLocationProfileDaoHelper.setConnectedLocationProfile( // getActivity(), profile.getId() ); isConnected = true; } else { isConnected = false; } } else { isConnected = true; } // get away/home toggle ToggleButton toggleIsAway = (ToggleButton) this.getActivity().findViewById(R.id.toggleButtonIsAway); toggleIsAway.setOnCheckedChangeListener(this.homeAwayCheckedChanged); // set away/home toggle based on the connected location profile if (null != profile && null != toggleIsAway) { toggleIsAway.setChecked(profile.getType() == LocationProfile.LocationType.AWAY); } // if frontend list is empty start a scan. if (frontends.isEmpty()) { scanForFrontends(); } if (isConnected) { DateTime etag = mEtagDaoHelper.findDateByEndpointAndDataId(getActivity(), profile, ChannelEndpoint.GET_CHANNEL_INFO_LIST.name(), ""); if (null != etag) { DateTime now = DateUtils.convertUtc(new DateTime(System.currentTimeMillis())); if (now.getMillis() - etag.getMillis() > 86400000) { if (!mRunningServiceHelper.isServiceRunning(getActivity(), "org.mythtv.service.channel.ChannelDownloadService")) { getActivity().startService(new Intent(ChannelDownloadService.ACTION_DOWNLOAD)); } } } else { if (!mRunningServiceHelper.isServiceRunning(getActivity(), "org.mythtv.service.channel.ChannelDownloadService")) { getActivity().startService(new Intent(ChannelDownloadService.ACTION_DOWNLOAD)); } } } }
From source file:cat.wuyingren.rorhelper.fragments.dialogs.ManageSenatorDialogFragment.java
@NonNull @Override/* ww w . j av a 2 s . co m*/ public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); LayoutInflater inflater = getActivity().getLayoutInflater(); final View v = inflater.inflate(R.layout.dialog_managesenator, null); final TextView randomKillTitle = (TextView) v.findViewById(R.id.managesenator_randomTitle); final ToggleButton randomKillButton = (ToggleButton) v.findViewById(R.id.managesenator_randomToggle); final LinearLayout selectors = (LinearLayout) v.findViewById(R.id.managesenator_selectors); dataSource = MainActivity.getDataSource(); context = MainActivity.getContext(); currentGameId = getArguments().getLong(ARG_GAMEID); killMode = getArguments().getBoolean(ARG_MODE); statesman = getArguments().getBoolean(ARG_TYPE); result.setKill(killMode); result.setStatesman(statesman); final Spinner senatorSpinner = (Spinner) v.findViewById(R.id.managesenator_senatorSpinner); randomKillButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { result.setRandomKill(isChecked); if (isChecked) { selectors.setVisibility(View.GONE); } else { selectors.setVisibility(View.VISIBLE); } } }); if (!killMode) { randomKillTitle.setVisibility(View.GONE); randomKillButton.setVisibility(View.GONE); String[] keys = getArguments().getStringArray(ARG_ARRAY); ArrayList<String> values = getArguments().getStringArrayList(ARG_VALUES); /*ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(MainActivity.getContext(), android.R.layout.simple_spinner_item, keys);*/ SenatorAdapter adapter = new SenatorAdapter(MainActivity.getContext(), android.R.layout.simple_spinner_item, keys, values); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); senatorSpinner.setAdapter(adapter); } else { randomKillTitle.setVisibility(View.VISIBLE); randomKillButton.setVisibility(View.VISIBLE); } senatorSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { result.setSenatorID(parent.getSelectedItem().toString()); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); final Spinner factionSpinner = SystemUtils.configureSpinner(v, R.id.managesenator_factionSpinner, R.array.faction_nameID); factionSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { long factionID = dataSource.getFactionId(currentGameId, getResources().getStringArray(R.array.faction_nameID)[position]); result.setFactionID(factionID); if (killMode) { ArrayList<Senator> senators = dataSource.getAllSenatorsOfFaction(factionID); Iterator<Senator> ite = senators.iterator(); ArrayList<CharSequence> array = new ArrayList<CharSequence>(); ArrayList<String> values = new ArrayList<String>(); while (ite.hasNext()) { Senator s = ite.next(); array.add(String.valueOf(s.getId())); values.add(String.valueOf(s.getName())); } String[] keys = new String[array.size()]; keys = array.toArray(keys); //ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(context, android.R.layout.simple_spinner_item, array); SenatorAdapter adapter = new SenatorAdapter(context, android.R.layout.simple_spinner_item, keys, values); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); senatorSpinner.setAdapter(adapter); } } @Override public void onNothingSelected(AdapterView<?> parent) { } }); builder.setView(v).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { mListener.onManageSenatorDialogPositiveClick(result); } }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { getDialog().cancel(); } }); String stringA, stringB; if (killMode) { stringA = getString(R.string.dialog_managesenator_kill_title); } else { stringA = getString(R.string.dialog_managesenator_title); } if (statesman) { stringB = getString(R.string.statesman); } else { stringB = getString(R.string.senator); } builder.setTitle(stringA + " " + stringB); return builder.create(); }
From source file:com.chatwing.whitelabel.fragments.CommunicationMessagesFragment.java
private void configBBCodeControls() { for (final BBCodeParser.BBCode code : mBBCodeControls.keySet()) { Button button = mBBCodeControls.get(code); // Config listener accordingly if (button instanceof ToggleButton) { // If it is a toggle button, set checked change listener. // When unchecked, the code is removed. ToggleButton toggle = (ToggleButton) button; if (code == BBCodeParser.BBCode.COLOR || code == BBCodeParser.BBCode.BACKGROUND_COLOR) { // When checked, show color picker. toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override/*from ww w . j a v a2s.c o m*/ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // Check mSyncingBBCodeControls to avoid recursion. if (!mSyncingBBCodeControls) { if (isChecked) { mDelegate.showColorPickerDialogFragment(code); // Invalidate the checked property now, // because user can cancel the action later. // The toggle will be updated later when user // confirmed the action. buttonView.setChecked(false); } else { removeBBCode(code); } } } }); } else { // When checked, append the code with an empty value. toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // Check mSyncingBBCodeControls to avoid recursion. if (!mSyncingBBCodeControls) { if (isChecked) { appendBBCode(new BBCodePair(code)); } else { removeBBCode(code); } } } }); } } else { // It is a normal button, set on click listener. When clicked, // append the code with empty value. button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { appendBBCode(new BBCodePair(code)); } }); } } }
From source file:com.csounds.examples.tests.SynthActivity.java
public void initSeekBar(ToggleButton diode3, ToggleButton diode4) { SeekBar slider3 = (SeekBar) findViewById(R.id.slider3); SeekBar slider4 = (SeekBar) findViewById(R.id.slider4); // setSeekBarValue(slider, 1, 4, 1.5); this.slider = (SeekBar) findViewById(R.id.slider); this.slider2 = (SeekBar) findViewById(R.id.slider2); setSeekBarValue(this.slider, 0, 1, 0.1); setSeekBarValue(this.slider2, 0, 1, 0.1); diode4.setOnCheckedChangeListener(new OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { String csd = getResourceFileAsString(R.raw.multitouch_xy_kfreq); File f = createTempFile(csd); Log.d("aaa", "raw multifreq diode 4 loaded"); CsoundUI csoundUI = new CsoundUI(csoundObj); csoundUI.addSlider(SynthActivity.this.slider, "freq", 0., 1.); // csoundObj.stop(); csoundObj.getCsound().Reset(); csoundObj.startCsound(f); } else { channelPtr[0].SetValue(0, 0); //csoundObj.stop(); }/*from w w w. j a va 2 s. co m*/ } }); diode3.setOnCheckedChangeListener(new OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { String csd = getResourceFileAsString(R.raw.multitouch_xy_kfreq); File f = createTempFile(csd); Log.d("aaa", "raw multifreq diode 3 loaded"); CsoundUI csoundUI = new CsoundUI(csoundObj); csoundUI.addSlider(SynthActivity.this.slider2, "hertz", 0., 1.); // csoundObj.stop(); csoundObj.getCsound().Reset(); csoundObj.startCsound(f); } else { channelPtr[1].SetValue(0, 0); //csoundObj.stop(); } } }); }
From source file:apps.junkuvo.alertapptowalksafely.MainActivity.java
public void setToggleButtonInLayout(View layout) { ToggleButton tgbPedometer = (ToggleButton) layout.findViewById(R.id.tgbPedometer); tgbPedometer.setChecked(mShouldShowPedometer); tgbPedometer.setOnCheckedChangeListener(new Switch.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { mShouldShowPedometer = isChecked; if (isChecked) { findViewById(R.id.llStepCount).setVisibility(View.VISIBLE); findViewById(R.id.txtExplanation).setVisibility(View.VISIBLE); } else { findViewById(R.id.llStepCount).setVisibility(View.INVISIBLE); if (mAlertService.IsRunningAlertService()) { findViewById(R.id.txtExplanation).setVisibility(View.INVISIBLE); }/*from ww w. j av a 2 s. c om*/ } } }); }