本文整理汇总了Java中android.support.v7.widget.SwitchCompat.setOnCheckedChangeListener方法的典型用法代码示例。如果您正苦于以下问题:Java SwitchCompat.setOnCheckedChangeListener方法的具体用法?Java SwitchCompat.setOnCheckedChangeListener怎么用?Java SwitchCompat.setOnCheckedChangeListener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v7.widget.SwitchCompat
的用法示例。
在下文中一共展示了SwitchCompat.setOnCheckedChangeListener方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: uiInitBluetooth
import android.support.v7.widget.SwitchCompat; //导入方法依赖的package包/类
private void uiInitBluetooth() {
if (bluetooth != null) {
textBluetoothVisible = (TextView) findViewById(R.id.bluetooth_visible);
viewBluetoothId = (TextView) findViewById(R.id.device_id_bluetooth);
viewBluetoothId.setText(bluetooth.getName());
viewBluetoothId.setVisibility(bluetooth.isEnabled() ? View.VISIBLE : View.GONE);
int textResource = getManager().isBluetoothDiscoverable() ? R.string.swap_visible_bluetooth : R.string.swap_not_visible_bluetooth;
textBluetoothVisible.setText(textResource);
bluetoothSwitch = (SwitchCompat) findViewById(R.id.switch_bluetooth);
Utils.debugLog(TAG, getManager().isBluetoothDiscoverable() ? "Initially marking switch as checked, because Bluetooth is discoverable." : "Initially marking switch as not-checked, because Bluetooth is not discoverable.");
bluetoothSwitch.setOnCheckedChangeListener(onBluetoothSwitchToggled);
setBluetoothSwitchState(getManager().isBluetoothDiscoverable(), true);
LocalBroadcastManager.getInstance(getContext()).registerReceiver(onBluetoothSwapStateChanged, new IntentFilter(SwapService.BLUETOOTH_STATE_CHANGE));
} else {
findViewById(R.id.bluetooth_info).setVisibility(View.GONE);
}
}
示例2: initView
import android.support.v7.widget.SwitchCompat; //导入方法依赖的package包/类
@Override
public void initView() {
headerLayout = (RelativeLayout) findViewById(R.id.rl_setting_header);
account = (TextView) findViewById(R.id.tv_setting_account);
nick = (TextView) findViewById(R.id.tv_tv_setting_nick);
avatar = (RoundAngleImageView) findViewById(R.id.riv_setting_avatar);
RelativeLayout notificationLayout = (RelativeLayout) findViewById(R.id.rl_setting_notification);
((TextView) notificationLayout.findViewById(R.id.tv_setting_item_title)).setText("通知提醒");
notification = (SwitchCompat) findViewById(R.id.switch_setting_item_check);
clear = (LinearLayout) findViewById(R.id.ll_setting_clear);
((TextView) clear.findViewById(R.id.tv_group_info_item_layout_title)).setText("清空所有的聊天记录");
chatFlow = (TextView) clear.findViewById(R.id.tv_group_info_item_layout_value);
logout = (Button) findViewById(R.id.btn_setting_logout);
headerLayout.setOnClickListener(this);
clear.setOnClickListener(this);
logout.setOnClickListener(this);
notification.setOnCheckedChangeListener(this);
}
示例3: onCreateOptionsMenu
import android.support.v7.widget.SwitchCompat; //导入方法依赖的package包/类
@Override
public boolean onCreateOptionsMenu (Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
MenuItem item = menu.findItem(R.id.action_enable);
item.setActionView(R.layout.switch_layout);
SwitchCompat mSwitchEnablePush = item.getActionView().findViewById(R.id.switchForActionBar);
mSwitchEnablePush.setChecked(PushController.isAllEnable(this));
mSwitchEnablePush.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
PushController.setAllEnable(b, MainActivity.this);
Toast.makeText(MainActivity.this,
b ? R.string.msg_enable : R.string.msg_disable
, Toast.LENGTH_SHORT).show();
}
});
return true;
}
示例4: initVariables
import android.support.v7.widget.SwitchCompat; //导入方法依赖的package包/类
private void initVariables() {
thisActivity = this;
localIPText = findViewById(R.id.my_local_ip);
externalIPText = findViewById(R.id.my_external_ip);
statusText = findViewById(R.id.status);
statusText.setMovementMethod(new ScrollingMovementMethod());
sendButton = (Button) findViewById(R.id.send_button);
messageEditText = (EditText) findViewById(R.id.message_edit_text);
extraInformationPanel = (LinearLayout) findViewById(R.id.extra_information_panel);
developerModeText = (TextView) findViewById(R.id.developer_mode_text);
switchDeveloperMode = (SwitchCompat) findViewById(R.id.switch_developer_mode);
switchDeveloperMode.setOnCheckedChangeListener(this);
editTextDestinationIP = findViewById(R.id.destination_IP);
editTextDestinationPort = findViewById(R.id.destination_port);
}
示例5: onBindViewHolder
import android.support.v7.widget.SwitchCompat; //导入方法依赖的package包/类
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
super.onBindViewHolder(holder, position);
SwitchCompat titleView = (SwitchCompat) holder.v.findViewById(R.id.title);
titleView.setOnCheckedChangeListener(null);
titleView.setChecked(value);
titleView.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
value = b;
PreferenceUtils.PreferenceIdentifier identifier = getIdentifier().getPreference();
if (identifier != null)
PreferenceUtils.putPreference(getContext(), getIdentifier().getPreference(), b);
onPreferenceChange(b);
}
});
}
示例6: prepareMenu
import android.support.v7.widget.SwitchCompat; //导入方法依赖的package包/类
private void prepareMenu(Menu m) {
if(m != null) {
SwitchCompat switchh = (SwitchCompat) ((MenuItemImpl) m.findItem(R.id.menu_item_switch)).getActionView().findViewById(R.id.pluginEnabledSwitch);
if(isKeepassInstalled()) {
switchh.setEnabled(true);
switchh.setChecked(isEnabled());
switchh.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
enableDisablePlugin();
}
});
} else
switchh.setChecked(false);
try {
PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
String version = pInfo.versionName;
m.findItem(R.id.menuVersion).setTitle("v:" + version);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
}
}
示例7: onCreate
import android.support.v7.widget.SwitchCompat; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mHeaderView = getLayoutInflater().inflate(R.layout.layout_header_switch, mRecyclerView, false);
mRecyclerView.addHeaderView(mHeaderView);
SwitchCompat switchCompat = (SwitchCompat) mHeaderView.findViewById(R.id.switch_compat);
switchCompat.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mRecyclerView.setItemViewSwipeEnabled(isChecked);
}
});
mRecyclerView.setLongPressDragEnabled(true); // 长按拖拽,默认关闭。
mRecyclerView.setItemViewSwipeEnabled(false); // 滑动删除,默认关闭。
}
示例8: getView
import android.support.v7.widget.SwitchCompat; //导入方法依赖的package包/类
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.app_list_item, parent, false);
final UUID thisUuid = UUID.fromString(uuids[position]);
TextView nameView = (TextView)rowView.findViewById(R.id.app_name);
nameView.setText(PermissionManager.getName(context, thisUuid));
TextView uuidView = (TextView)rowView.findViewById(R.id.app_uuid);
uuidView.setText(thisUuid.toString());
SwitchCompat permSwitch = (SwitchCompat) rowView.findViewById(R.id.app_switch);
boolean permitted = PermissionManager.isPermitted(context, thisUuid);
permSwitch.setChecked(permitted);
permSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
PermissionManager.setPermitted(context, thisUuid, isChecked);
}
});
return rowView;
}
示例9: initNavView
import android.support.v7.widget.SwitchCompat; //导入方法依赖的package包/类
private void initNavView() {
boolean night = SPUtils.getPrefBoolean(Constant.THEME_MODEL, false);
if (night) {
getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_YES);
} else {
getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_NO);
}
MenuItem item = mNavigationView.getMenu().findItem(R.id.nav_theme);
mNavigationView.getMenu().findItem(R.id.nav_home).setChecked(true);
mThemeSwitch = (SwitchCompat) MenuItemCompat.getActionView(item).findViewById(R.id.view_switch);
mThemeSwitch.setChecked(night);
mThemeSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
SPUtils.setPrefBoolean(Constant.THEME_MODEL, isChecked);
mThemeSwitch.setChecked(isChecked);
if (isChecked) {
getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_YES);
} else {
getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_NO);
}
}
});
}
示例10: setStopLoop
import android.support.v7.widget.SwitchCompat; //导入方法依赖的package包/类
private void setStopLoop() {
final boolean stopLoop = preferences.getStopLoopOnSingle();
final SwitchCompat stopLoopSwitch = w.getSwitchCompat(R.id.layout_settings_stop_loop_switch, a);
RelativeLayout stopLoopLayout = w.getRelativeLayout(R.id.layout_settings_stop_loop, a);
stopLoopSwitch.setChecked(stopLoop);
stopLoopSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
if (b != stopLoop) {
// changed
isDeckShouldCleared = true;
}
preferences.setStopLoopOnSingle(b);
isStopLoopOnSingle = b;
}
});
stopLoopLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
stopLoopSwitch.toggle();
}
});
}
示例11: onCreateOptionsMenu
import android.support.v7.widget.SwitchCompat; //导入方法依赖的package包/类
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// We need to inflate the menu for the app bar, to display the switch
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.vibration_activity_menu, menu);
final MenuItem item = menu.findItem(R.id.vibration_switch);
SwitchCompat mainSwitch = (SwitchCompat) item.getActionView();
mainSwitch.setOnCheckedChangeListener
(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged
(CompoundButton buttonView, boolean isChecked) {
settingsModel.setVibrationServiceOn(isChecked);
}
});
// Initialise the switch to the current vibrate service state.
mainSwitch.setChecked(settingsModel.isVibrationServiceOn());
VibrationAlarmScheduler.updateAlarms(this);
return true;
}
示例12: setCheckedEvent
import android.support.v7.widget.SwitchCompat; //导入方法依赖的package包/类
/**
* Switch 按钮 切换事件
* @param dayNightSwitch 按钮
*/
private void setCheckedEvent(SwitchCompat dayNightSwitch){
dayNightSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
isSwitchNight = true;
if(isChecked){
changeToNight();
SharedPreferencesUtil.saveNightMode(true);
}else{
changeToDay();
SharedPreferencesUtil.saveNightMode(false);
}
mDrawerLayout.closeDrawer(GravityCompat.START);
}
});
}
示例13: onCreateView
import android.support.v7.widget.SwitchCompat; //导入方法依赖的package包/类
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_settings, container, false);
version = (TextView) view.findViewById(R.id.settings_version);
version.setText(String.format("v%s", BuildConfig.VERSION_NAME));
notifications = (SwitchCompat) view.findViewById(R.id.settings_toggle_button);
notifications.setChecked(CurrentUser.getInstance().isNotificationsOn());
notifications.setOnCheckedChangeListener(this);
toolbarTitle = (TextView) getActivity().findViewById(R.id.chat_toolbar_title);
progressBar = (ProgressBar) getActivity().findViewById(R.id.main_progress_bar);
return view;
}
示例14: uiInitWifi
import android.support.v7.widget.SwitchCompat; //导入方法依赖的package包/类
private void uiInitWifi() {
viewWifiId = (TextView) findViewById(R.id.device_id_wifi);
viewWifiNetwork = (TextView) findViewById(R.id.wifi_network);
wifiSwitch = (SwitchCompat) findViewById(R.id.switch_wifi);
wifiSwitch.setOnCheckedChangeListener(onWifiSwitchToggled);
setWifiSwitchState(getManager().isBonjourDiscoverable(), true);
textWifiVisible = (TextView) findViewById(R.id.wifi_visible);
int textResource = getManager().isBonjourDiscoverable() ? R.string.swap_visible_wifi : R.string.swap_not_visible_wifi;
textWifiVisible.setText(textResource);
// Note that this is only listening for the WifiSwap, whereas we start both the WifiSwap
// and the Bonjour service at the same time. Technically swap will work fine without
// Bonjour, and that is more of a convenience. Thus, we should show feedback once wifi
// is ready, even if Bonjour is not yet.
LocalBroadcastManager.getInstance(getContext()).registerReceiver(onWifiSwapStateChanged, new IntentFilter(SwapService.WIFI_STATE_CHANGE));
viewWifiNetwork.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
getActivity().promptToSelectWifiNetwork();
}
});
uiUpdateWifiNetwork();
}
示例15: onCreateDialog
import android.support.v7.widget.SwitchCompat; //导入方法依赖的package包/类
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
View root = View.inflate(getActivity(), R.layout.dialog_dialog_options, null);
scEnable = (SwitchCompat) root.findViewById(R.id.enable);
scHighPriority = (SwitchCompat) root.findViewById(R.id.priority);
scSound = (SwitchCompat) root.findViewById(R.id.sound);
scVibro = (SwitchCompat) root.findViewById(R.id.vibro);
scLed = (SwitchCompat) root.findViewById(R.id.led);
scEnable.setChecked(hasFlag(mask, FLAG_SHOW_NOTIF));
scEnable.setOnCheckedChangeListener((buttonView, isChecked) -> resolveOtherSwitches());
scSound.setChecked(hasFlag(mask, FLAG_SOUND));
scHighPriority.setChecked(hasFlag(mask, FLAG_HIGH_PRIORITY));
scVibro.setChecked(hasFlag(mask, FLAG_VIBRO));
scLed.setChecked(hasFlag(mask, FLAG_LED));
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity())
.setTitle(R.string.peer_notification_settings)
.setPositiveButton(R.string.button_ok, (dialog, whichButton) -> onSaveClick())
.setNeutralButton(R.string.set_default, (dialog, which) -> Settings.get()
.notifications()
.setDefault(accountId, peerId));
builder.setView(root);
resolveOtherSwitches();
return builder.create();
}