当前位置: 首页>>代码示例>>Java>>正文


Java Switch.setOnCheckedChangeListener方法代码示例

本文整理汇总了Java中android.widget.Switch.setOnCheckedChangeListener方法的典型用法代码示例。如果您正苦于以下问题:Java Switch.setOnCheckedChangeListener方法的具体用法?Java Switch.setOnCheckedChangeListener怎么用?Java Switch.setOnCheckedChangeListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.widget.Switch的用法示例。


在下文中一共展示了Switch.setOnCheckedChangeListener方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onCreate

import android.widget.Switch; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    textView = findViewById(R.id.text);
    updateText();
    Switch s = findViewById(R.id.switch_widget);
    s.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            if (b) {
                RedirectStorage.enable(new PathCallback() {
                    @Override
                    public File onModify(File original) {
                        return getFilesDir();
                    }
                });
            } else {
                RedirectStorage.disable();
            }
            updateText();
        }
    });
}
 
开发者ID:Trumeet,项目名称:RedirectStorage,代码行数:25,代码来源:MainActivity.java

示例2: onViewCreated

import android.widget.Switch; //导入方法依赖的package包/类
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    // Bind event listeners and initial states
    view.findViewById(R.id.set_chrome_restrictions).setOnClickListener(this);
    view.findViewById(R.id.clear_chrome_restrictions).setOnClickListener(this);
    view.findViewById(R.id.enable_forwarding).setOnClickListener(this);
    view.findViewById(R.id.disable_forwarding).setOnClickListener(this);
    view.findViewById(R.id.send_intent).setOnClickListener(this);
    mButtonRemoveProfile = (Button) view.findViewById(R.id.remove_profile);
    mButtonRemoveProfile.setOnClickListener(this);
    Switch toggleCalculator = (Switch) view.findViewById(R.id.toggle_calculator);
    toggleCalculator.setChecked(mCalculatorEnabled);
    toggleCalculator.setOnCheckedChangeListener(this);
    Switch toggleChrome = (Switch) view.findViewById(R.id.toggle_chrome);
    toggleChrome.setChecked(mChromeEnabled);
    toggleChrome.setOnCheckedChangeListener(this);
}
 
开发者ID:sdrausty,项目名称:buildAPKsSamples,代码行数:18,代码来源:BasicManagedProfileFragment.java

示例3: onCreateView

import android.widget.Switch; //导入方法依赖的package包/类
@NonNull
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
    View view = inflater.inflate(R.layout.debug_drawer_mock_ble, parent, false);

    Switch mockBle = view.findViewById(R.id.debug_drawer_ble_mock);
    mockBle.setOnCheckedChangeListener((buttonView, isChecked) -> {
        if (isChecked) {
            mainActivity.provideBluetoothUtil(new BluetoothUtilMockImpl());
        } else {
            mainActivity.provideBluetoothUtil(new BluetoothUtilImpl());
        }

    });

    return view;
}
 
开发者ID:ponewheel,项目名称:android-ponewheel,代码行数:18,代码来源:DebugDrawerMockBle.java

示例4: initView

import android.widget.Switch; //导入方法依赖的package包/类
private void initView() {
    mQrCodeFinderView = (ScannerFinderView) findViewById(R.id.qr_code_view_finder);
    mSurfaceViewStub = (ViewStub) findViewById(R.id.qr_code_view_stub);
    switch1 = (Switch) findViewById(R.id.switch1);
    mHasSurface = false;

    bt = (Button) findViewById(R.id.bt);

    bt.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            bt.setEnabled(false);
            buildProgressDialog();
            CameraManager.get().takeShot(ScannerActivity.this, ScannerActivity.this, ScannerActivity.this);
        }
    });

    Switch switch2 = (Switch) findViewById(R.id.switch2);
    switch2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            CameraManager.get().setFlashLight(isChecked);
        }
    });
}
 
开发者ID:simplezhli,项目名称:Tesseract-OCR-Scanner,代码行数:26,代码来源:ScannerActivity.java

示例5: onCreate

import android.widget.Switch; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);



    mSwitch=(Switch)findViewById(R.id.switch1);
    mSwitch.setChecked(checkSystemWritePermission());
    mSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                // 开启switch,设置提示信息
                getPermission();
            } else {
                // 关闭swtich,设置提示信息
                mSwitch.setText(getString(R.string.text_off));
            }
        }
    });
}
 
开发者ID:gojuukaze,项目名称:ScreenOffTime,代码行数:24,代码来源:MainActivity.java

示例6: onCreate

import android.widget.Switch; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mContextHolder = ContextHolder.getInstance(getApplicationContext());

    mGpioHandler = GpioHandler.getInstance();

    mAlarmTriggerSwitch = (Switch) findViewById(R.id.alarmTrigger);

    mAlarmTriggerSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                EventBus.getDefault().post(new EventHandler(b));
        }
    });

}
 
开发者ID:freeloki,项目名称:AndroidThings-BurglarAlarm,代码行数:20,代码来源:MainActivity.java

示例7: SwitchItem

import android.widget.Switch; //导入方法依赖的package包/类
public SwitchItem(Context context, String title, String key, boolean defaultValue) {
    super(context);
    this.mKey = key;
    this.mDefaultValue = defaultValue;

    View.inflate(getContext(), R.layout.view_switch_item, this);

    TextView titleView = (TextView) findViewById(R.id.title);
    titleView.setText(title);

    mSwitchView = (Switch) findViewById(R.id.switcher);
    mSwitchView.setOnCheckedChangeListener((buttonView, isChecked) -> {
        SharedPreferences.Editor editor = App.sp.edit();
        editor.putBoolean(key, isChecked);
        editor.apply();
    });
}
 
开发者ID:dss886,项目名称:Transmis,代码行数:18,代码来源:SwitchItem.java

示例8: defineObjects

import android.widget.Switch; //导入方法依赖的package包/类
private void defineObjects() {
    message = (TextInputEditText) findViewById(R.id.post_call_text);
    Switch emergency = (Switch) findViewById(R.id.post_call_emergencyswitch);
    String m = user.toUpperCase();
    m += ": ";
    message.setText(m);
    message.requestFocus();
    emergency.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            emergencyBool = isChecked;
        }
    });
}
 
开发者ID:DecentralizedAmateurPagingNetwork,项目名称:DAPNETApp,代码行数:15,代码来源:PostCallActivity.java

示例9: populate

import android.widget.Switch; //导入方法依赖的package包/类
private void populate(final boolean enabled, List<DeviceActionDAO> defaultActions, List<StoryDeviceActionDAO> existingActions) {
    LinearLayout layout;
    if (enabled) {
        layout = findViewById(R.id.storyEnabledLinearLayout);
    } else {
        layout = findViewById(R.id.storyDisabledLinearLayout);
    }
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    lp.setMargins(0, 8, 0, 8);
    for (final DeviceActionDAO action : defaultActions) {
        Switch s = new Switch(this);
        s.setText(action.getName());
        s.setLayoutParams(lp);
        // Check the matching switch for every list
        for (StoryDeviceActionDAO existingAction : existingActions) {
            if (enabled && existingAction.isEnabled() && existingAction.getActionId() == action.getId()) {
                s.setChecked(true);
                break;
            } else if (!enabled && !existingAction.isEnabled() && existingAction.getActionId() == action.getId()) {
                s.setChecked(true);
                break;
            }
        }
        layout.addView(s);
        s.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
                if (checked) {
                    db.createActionForStoryAndDevice(storyId, enabled, action);
                } else {
                    db.deleteActionForStoryAndDevice(storyId, enabled, action);
                }
            }
        });
    }
}
 
开发者ID:MBach,项目名称:home-automation,代码行数:37,代码来源:DeviceActivity.java

示例10: setShowNotifs

import android.widget.Switch; //导入方法依赖的package包/类
private void setShowNotifs(Switch toggle) {
    toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                activity.setThings.editor.putBoolean("showNotifs", true);
                showNotifs = "true";
            } else {
                activity.setThings.editor.putBoolean("showNotifs", false);
                showNotifs = "false";
            }
            activity.setThings.editor.apply();
        }
    });
}
 
开发者ID:zacharee,项目名称:SystemUITuner2,代码行数:16,代码来源:Demo.java

示例11: onCreate

import android.widget.Switch; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_settings);
    mContext = this;

    mSwShowDetails = (Switch) findViewById(R.id.sw_show_details);
    mSwShowDetails.setOnCheckedChangeListener(this);

    mTrackerServiceIntent = new Intent(mContext, TrackerService.class);

    if (getIntent().getBooleanExtra(EXTRA_FROM_QS_TILE, false)) {
        mSwShowDetails.setChecked(true);
    }
}
 
开发者ID:DysaniazzZ,项目名称:TopActivity,代码行数:16,代码来源:SettingsActivity.java

示例12: setAirplaneMode

import android.widget.Switch; //导入方法依赖的package包/类
private void setAirplaneMode(Switch toggle) {
    toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                activity.setThings.editor.putBoolean("showAirplane", true);
                showAirplane = "show";
            } else {
                activity.setThings.editor.putBoolean("showAirplane", false);
                showAirplane = "hide";
            }
            activity.setThings.editor.apply();
        }
    });
}
 
开发者ID:zacharee,项目名称:SystemUITuner2,代码行数:16,代码来源:Demo.java

示例13: setupSwitches

import android.widget.Switch; //导入方法依赖的package包/类
private void setupSwitches() {
    Switch high_brightness_warning = view.findViewById(R.id.high_brightness_warning);

    Switch knox_container = view.findViewById(R.id.knox_container);
    Switch smart_network = view.findViewById(R.id.smart_network);
    Switch glove = view.findViewById(R.id.glove);
    Switch gesture = view.findViewById(R.id.gesture);
    Switch smart_scroll = view.findViewById(R.id.smart_scroll);
    Switch face = view.findViewById(R.id.face);
    Switch gps = view.findViewById(R.id.gps);
    Switch lbs = view.findViewById(R.id.lbs);
    Switch wearable_gear = view.findViewById(R.id.wearable_gear);
    Switch femtoicon = view.findViewById(R.id.femtoicon);
    Switch rcs = view.findViewById(R.id.rcs);
    Switch wifi_p2p = view.findViewById(R.id.wifi_p2p);
    Switch wifi_ap = view.findViewById(R.id.wifi_ap);
    Switch wifi_oxygen = view.findViewById(R.id.wifi_oxygen);
    Switch phone_signal_second_stub = view.findViewById(R.id.phone_signal_second_stub);
    Switch toddler = view.findViewById(R.id.toddler);
    Switch ims_volte = view.findViewById(R.id.ims_volte);
    Switch keyguard_wakeup = view.findViewById(R.id.keyguard_wakeup);
    Switch safezone = view.findViewById(R.id.safezone);
    Switch wimax = view.findViewById(R.id.wimax);
    Switch smart_bonding = view.findViewById(R.id.smart_bonding);
    Switch private_mode = view.findViewById(R.id.private_mode);

    switches.add(knox_container);
    switches.add(smart_network);
    switches.add(glove);
    switches.add(gesture);
    switches.add(smart_scroll);
    switches.add(face);
    switches.add(gps);
    switches.add(lbs);
    switches.add(wearable_gear);
    switches.add(femtoicon);
    switches.add(rcs);
    switches.add(wifi_p2p);
    switches.add(wifi_ap);
    switches.add(wifi_oxygen);
    switches.add(phone_signal_second_stub);
    switches.add(toddler);
    switches.add(ims_volte);
    switches.add(keyguard_wakeup);
    switches.add(safezone);
    switches.add(wimax);
    switches.add(smart_bonding);
    switches.add(private_mode);

    high_brightness_warning.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            activity.setThings.settings(GLOBAL, "limit_brightness_state", isChecked ? "80, 80" : null);
        }
    });

    activity.setThings.switches(knox_container, SLOT_KNOX_CONTAINER, ICON_BLACKLIST, view);
    activity.setThings.switches(smart_network, SLOT_SMART_NETWORK, ICON_BLACKLIST, view);
    activity.setThings.switches(glove, SLOT_GLOVE, ICON_BLACKLIST, view);
    activity.setThings.switches(gesture, SLOT_GESTURE, ICON_BLACKLIST, view);
    activity.setThings.switches(smart_scroll, SLOT_SMART_SCROLL, ICON_BLACKLIST, view);
    activity.setThings.switches(face, SLOT_FACE, ICON_BLACKLIST, view);
    activity.setThings.switches(gps, SLOT_GPS, ICON_BLACKLIST, view);
    activity.setThings.switches(lbs, SLOT_LBS, ICON_BLACKLIST, view);
    activity.setThings.switches(wearable_gear, SLOT_WEARABLE_GEAR, ICON_BLACKLIST, view);
    activity.setThings.switches(femtoicon, SLOT_FEMTOICON, ICON_BLACKLIST, view);
    activity.setThings.switches(rcs, SLOT_RCS, ICON_BLACKLIST, view);
    activity.setThings.switches(wifi_p2p, SLOT_WIFI_P2P, ICON_BLACKLIST, view);
    activity.setThings.switches(wifi_ap, SLOT_WIFI_AP, ICON_BLACKLIST, view);
    activity.setThings.switches(wifi_oxygen, SLOT_WIFI_OXYGEN, ICON_BLACKLIST, view);
    activity.setThings.switches(phone_signal_second_stub, SLOT_PHONE_SIGNAL_SECOND_STUB, ICON_BLACKLIST, view);
    activity.setThings.switches(toddler, SLOT_TODDLER, ICON_BLACKLIST, view);
    activity.setThings.switches(ims_volte, SLOT_IMS_VOLTE, ICON_BLACKLIST, view);
    activity.setThings.switches(keyguard_wakeup, SLOT_KEYGUARD_WAKEUP, ICON_BLACKLIST, view);
    activity.setThings.switches(safezone, SLOT_SAFEZONE, ICON_BLACKLIST, view);
    activity.setThings.switches(wimax, SLOT_WIMAX, ICON_BLACKLIST, view);
    activity.setThings.switches(smart_bonding, SLOT_SMART_BONDING, ICON_BLACKLIST, view);
    activity.setThings.switches(private_mode, SLOT_PRIVATE_MODE, ICON_BLACKLIST, view);
}
 
开发者ID:zacharee,项目名称:SystemUITuner2,代码行数:80,代码来源:TouchWiz.java

示例14: getView

import android.widget.Switch; //导入方法依赖的package包/类
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    final SourceSetting sourceSetting = sources.get(position);

    View v = convertView;
    int type = getItemViewType(position);
    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    switch (type) {
        case PARENT:
            v = inflater.inflate(R.layout.list_item_setting_source_parent, parent, false);
            break;
        case CHILD:
            v = inflater.inflate(R.layout.list_item_setting_source_child, parent, false);
            break;
        default:
            break;
    }

    final TextView sourceNameTextView = (TextView) v.findViewById(R.id.sourceTextView);
    final Switch sourceSwitch = (Switch) v.findViewById(R.id.sourceSwitch);

    sourceNameTextView.setText(sourceSetting.getCleanName());

    SourceSetting src = SourceController.getInstance().getSource(context, sourceSetting.getName());

    sourceSwitch.setChecked(src != null && src.isEnabled());
    if (!sourceSwitch.isChecked()) {
        sourceNameTextView.setTextColor(Color.GRAY);
    } else {
        sourceNameTextView.setTextColor(Color.BLACK);
    }

    sourceSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            SourceController.getInstance().toggleSource(getContext(), sourceSetting.getName());
            boolean refresh = false;
            if (sourceSetting.isParent()) {
                SourceController.getInstance().toggleSourceChildren(getContext(),
                    sourceSetting.getName(),
                    sourceSwitch.isChecked());
                refresh = true;
            }
            if (sourceSwitch.isChecked()) {
                sourceNameTextView.setTextColor(Color.BLACK);
            } else {
                sourceNameTextView.setTextColor(Color.GRAY);
            }
            sort();

            if (refresh) {
                parentActivity.refreshActivity();
            }
        }
    });
    return v;
}
 
开发者ID:BakkerTom,项目名称:happy-news,代码行数:59,代码来源:SourceSettingsAdapter.java

示例15: onCreate

import android.widget.Switch; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_light_settings);

    s = (Switch) findViewById(R.id.active);
    tp = (TimePicker) findViewById(R.id.lockTime);
    tp2 = (TimePicker) findViewById(R.id.unlockTime);


    database = FirebaseDatabase.getInstance();
    lightSettingsRef = database.getReference("lightsettings");
    lightSettingsRef.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            Log.e("db", "dbok in lightsettings.java");
            tp.setOnTimeChangedListener(null);
            tp2.setOnTimeChangedListener(null);
            s.setOnCheckedChangeListener(null);

            tp.setCurrentHour(((Number) dataSnapshot.child("onH").getValue()).intValue());
            tp.setCurrentMinute(((Number) dataSnapshot.child("onM").getValue()).intValue());
            tp2.setCurrentHour(((Number) dataSnapshot.child("offH").getValue()).intValue());
            tp2.setCurrentMinute(((Number) dataSnapshot.child("offM").getValue()).intValue());
            s.setChecked((boolean) dataSnapshot.child("active").getValue());


            tp.setOnTimeChangedListener(timePickerListener);
            tp2.setOnTimeChangedListener(timePickerListener);
            s.setOnCheckedChangeListener(switchListener);


        }
        @Override
        public void onCancelled(DatabaseError databaseError) {
            Log.e("db",databaseError.toString());

        }
    });

    timePickerListener = new TimePicker.OnTimeChangedListener(){
        @Override
        public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
            Log.d("deb","activity.updatesettings");

            lightSettingsRef.setValue(new LightSettingsHelper(
                    s.isChecked(),
                    tp.getCurrentHour(),
                    tp.getCurrentMinute(),
                    tp2.getCurrentHour(),
                    tp2.getCurrentMinute()
            ));
        }

    };

    switchListener = new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            lightSettingsRef.setValue(new LightSettingsHelper(
                    s.isChecked(),
                    tp.getCurrentHour(),
                    tp.getCurrentMinute(),
                    tp2.getCurrentHour(),
                    tp2.getCurrentMinute()
            ));
        }
    };

    tp.setOnTimeChangedListener(timePickerListener);
    tp2.setOnTimeChangedListener(timePickerListener);
    s.setOnCheckedChangeListener(switchListener);

}
 
开发者ID:reevejd,项目名称:SmartHome,代码行数:75,代码来源:LightSettingsActivity.java


注:本文中的android.widget.Switch.setOnCheckedChangeListener方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。