Java 类android.widget.Switch 实例源码

项目:lineagex86    文件:ZenModeRuleSettingsBase.java   
@Override
public void onSwitchChanged(Switch switchView, boolean isChecked) {
    if (DEBUG) Log.d(TAG, "onSwitchChanged " + isChecked);
    if (mDisableListeners) return;
    final boolean enabled = isChecked;
    if (enabled == mRule.enabled) return;
    MetricsLogger.action(mContext, MetricsLogger.ACTION_ZEN_ENABLE_RULE, enabled);
    if (DEBUG) Log.d(TAG, "onSwitchChanged enabled=" + enabled);
    mRule.enabled = enabled;
    mRule.snoozing = false;
    setZenModeConfig(mConfig);
    if (enabled) {
        final int toastText = getEnabledToastText();
        if (toastText != 0) {
            mEnabledToast = Toast.makeText(mContext, toastText, Toast.LENGTH_SHORT);
            mEnabledToast.show();
        }
    } else {
        if (mEnabledToast != null) {
            mEnabledToast.cancel();
        }
    }
}
项目:GitHub    文件:VerticalMediaControllView.java   
private void initView(Context context) {
    rootView = View.inflate(context, R.layout.widget_ver_controller, this);

    ivBack = (ImageView) findViewById(R.id.iv_thelive_back);
    verMediaControll = findViewById(R.id.verMediaControll);
    infoContainer = findViewById(R.id.infoContainer);
    ll_four_container = (LinearLayout) findViewById(R.id.ll_four_container);
    theliveMore = (ImageView) findViewById(R.id.iv_thelive_more);
    check_gift_switch = (CheckBox) findViewById(R.id.check_gift_switch);
    check_live_pause = (CheckBox) findViewById(R.id.check_live_pause);
    ivFullscreen = (ImageView) findViewById(R.id.iv_thelive_fullscreen);
    theliveNum = (TextView) findViewById(R.id.tv_thelive_num);
    ll_jubao_and_share = (LinearLayout) findViewById(R.id.ll_jubao_and_share);
    tv_jubao = (TextView) findViewById(R.id.tv_jubao);
    tv_share = (TextView) findViewById(R.id.tv_share);
    live_vertical_bottom = (FrameLayout) findViewById(R.id.live_vertical_bottom);

    //info
    ic_head = (ImageView) findViewById(R.id.ic_head);
    nickName = (TextView) findViewById(R.id.nickName);
    titleName = (TextView) findViewById(R.id.title);
    ivIsFocus = (ImageView) findViewById(R.id.iv_thelive_focus);
    swRemind = (Switch) findViewById(R.id.switchview_remind);

}
项目:android-ponewheel    文件:DebugDrawerMockBle.java   
@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;
}
项目:RedirectStorage    文件:MainActivity.java   
@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();
        }
    });
}
项目:B4A_ViewsEx    文件:SwitchWrapper.java   
@Hide
@Override
public void _initialize(final BA ba, Object activityClass, String EventName) {
    final Switch _switch = new Switch(ba.context);
    final String eventName = EventName.toLowerCase(BA.cul);
    setObject(_switch);
    innerInitialize(ba, eventName, true);
    if (ba.subExists(eventName + "_checkedchange")) {
        getObject().setOnCheckedChangeListener(new OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView,
                    boolean isChecked) {
                ba.raiseEventFromUI(_switch,eventName + "_checkedchange", isChecked);
            }

        });
    }
}
项目:Mount    文件:PackageSettingLayout.java   
@Override
protected void onFinishInflate() {
    super.onFinishInflate();

    mIconView = (ImageView) findViewById(R.id.icon);
    mMountSwitch = (Switch) findViewById(R.id.mount_switch);
    mLabelView = (TextView) findViewById(R.id.label);
    mVersionView = (TextView) findViewById(R.id.version);
    mRunView = (TextView) findViewById(R.id.run);
    mInfoView = (TextView) findViewById(R.id.info);
    mAddToLauncherView = (TextView) findViewById(R.id.add_to_launcher);

    mMountSwitch.setOnCheckedChangeListener(this);
    mRunView.setOnClickListener(this);
    mInfoView.setOnClickListener(this);
    mAddToLauncherView.setOnClickListener(this);
}
项目:Transmis    文件:SwitchItem.java   
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();
    });
}
项目:MyBP    文件:NotificationActivity.java   
private void referenceViews() {
    switchNotifications = (Switch) findViewById(R.id.switchNotifications);
    switchNotificationSound = (Switch) findViewById(R.id.switchNotificationSound);
    switchNotificationLight = (Switch) findViewById(R.id.switchNotificationLight);
    switchNotificationVibrations = (Switch) findViewById(R.id.switchNotificationVibrations);
    textViewNotificationPeriod = (TextView) findViewById(R.id.textViewNotificationPeriod);

    String notification = getResources().getString(R.string.notification);
    String notificationSub = getResources().getString(R.string.notification_sub_2);
    Span.span(notification, notificationSub, switchNotifications);

    String notificationSound = getResources().getString(R.string.notification_sound);
    Span.span(notificationSound, switchNotificationSound);

    String notificationLight = getResources().getString(R.string.notification_light);
    Span.span(notificationLight, switchNotificationLight);

    String notificationVibration = getResources().getString(R.string.notification_vibration);
    Span.span(notificationVibration, switchNotificationVibrations);

    String notificationPeriod = getResources().getString(R.string.notification_period);
    String notificationPeriodSub = getResources().getString(R.string.notification_period_sub);
    Span.span(notificationPeriod, notificationPeriodSub, textViewNotificationPeriod);
}
项目:MyBP    文件:SettingsActivity.java   
private void referenceViews() {
    switchProfile = (Switch) findViewById(R.id.switchProfile);
    switchGoogle = (Switch) findViewById(R.id.switchGoogle);
    textViewNotifications = (TextView) findViewById(R.id.textViewNotifications);
    switchCurrency = (Switch) findViewById(R.id.switchCurrency);

    String profile = getResources().getString(R.string.profile);
    String profileSub = getResources().getString(R.string.profile_sub);
    Span.span(profile, profileSub, switchProfile);

    String profileGoogle = getResources().getString(R.string.profile_google);
    String profileGoogleSub = getResources().getString(R.string.profile_google_sub);
    Span.span(profileGoogle, profileGoogleSub, switchGoogle);

    String notification = getResources().getString(R.string.notification);
    String notificationSub = getResources().getString(R.string.notification_sub);
    Span.span(notification, notificationSub, textViewNotifications);

    String currency = getResources().getString(R.string.currency);
    String currencySub = getResources().getString(R.string.currency_sub);
    Span.span(currency, currencySub, switchCurrency);
}
项目:firefox-tv    文件:BlockingItemViewHolder.java   
BlockingItemViewHolder(View itemView, final BrowserFragment fragment) {
    super(itemView);

    this.fragment = fragment;

    final Switch switchView = itemView.findViewById(R.id.blocking_switch);
    switchView.setChecked(fragment.getSession().isBlockingEnabled());
    switchView.setOnCheckedChangeListener(this);

    final View helpView = itemView.findViewById(R.id.help_trackers);
    helpView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (browserFragment != null) {
                browserFragment.onClick(view);
            }
        }
    });

    trackerCounter = itemView.findViewById(R.id.trackers_count);

    updateTrackers(fragment.getSession().getBlockedTrackers().getValue());
}
项目:GoalsAndHabits    文件:MapFiltersActivity.java   
/**
 * Creates menu functionality.
 * @param menu
 * @return
 */
@Override
public boolean onCreateOptionsMenu(Menu menu){
    getMenuInflater().inflate(R.menu.menu_nearby_events, menu);
    final MenuItem nearbyToggle = menu.findItem(R.id.nearbyEventSwitch);
    final Switch actionView = (Switch) nearbyToggle.getActionView().findViewById(R.id.mapSwitch);
    actionView.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked){//Needs to call some method otherwise doesn't work
                addNearbyMarkers(gmap);
            }
            else{
                addAllMarkers(gmap);
            }

        }
    });
    return super.onCreateOptionsMenu(menu);
}
项目:ScreenOffTime    文件:MainActivity.java   
@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));
            }
        }
    });
}
项目:SmartButler    文件:SettingActivity.java   
private void initView()
{
    switch_voice= (Switch) findViewById(R.id.switch_voice);
    switch_sms= (Switch) findViewById(R.id.switch_sms);
    ll_check_version= (LinearLayout) findViewById(R.id.ll_check_version);
    tv_version_name= (TextView) findViewById(R.id.tv_version_name);
    ll_scan_qrcode= (LinearLayout) findViewById(R.id.ll_scan_qrcode);
    ll_my_qrcode= (LinearLayout) findViewById(R.id.ll_my_qrcode);
    ll_location= (LinearLayout) findViewById(R.id.ll_location);
    //获取当前版本信息显示在界面上
    showCurrentVersionInfo();
    //为各种开关设置监听事件
    switch_voice.setOnClickListener(this);
    switch_sms.setOnClickListener(this);
    ll_check_version.setOnClickListener(this);
    ll_scan_qrcode.setOnClickListener(this);
    ll_my_qrcode.setOnClickListener(this);
    ll_location.setOnClickListener(this);
    //进入界面后读取之前保存的开关状态
    switch_voice.setChecked(SharedUtils.getBoolean("voice_key",false));
    switch_sms.setChecked(SharedUtils.getBoolean("sms_key",false));
}
项目:notifications-forwarder    文件:AppsAdapter.java   
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    // Get the data item for this position
    InstalledApp app = getItem(position);
    // Check if an existing view is being reused, otherwise inflate the view
    if (convertView == null) {
        convertView = LayoutInflater.from(getContext()).inflate(R.layout.item_app, parent, false);
    }
    // Lookup view for data population


    appImage = (ImageView) convertView.findViewById(R.id.appImage);
    appPackage = (Switch) convertView.findViewById(R.id.appSwitch);
    appName = (TextView) convertView.findViewById(R.id.appName);
    appImage.setImageDrawable(app.image);
    appPackage.setText(app.packageName);
    appName.setText(app.name);

    // Return the completed view to render on screen
    return convertView;
}
项目:aos-Video    文件:TVMenuItem.java   
@Override
public View createSlaveView() {
    // TODO Auto-generated method stub
    TVMenuItem slaveView;
    if(findViewById(R.id.info_text)!=null && findViewById(R.id.info_text) instanceof RadioButton){
        slaveView = (TVMenuItem)LayoutInflater.from(mContext)
                .inflate(R.layout.menu_item_checkable_layout, null);
    }
    else if(findViewById(R.id.info_text)!=null && findViewById(R.id.info_text) instanceof Switch){
        slaveView = (TVMenuItem)LayoutInflater.from(mContext)
                .inflate(R.layout.menu_item_switchable_layout, null);
    }
    else{
        slaveView = (TVMenuItem)(View)LayoutInflater.from(mContext)
                .inflate(R.layout.menu_item_layout, null);
    }
    setSlaveView(slaveView);
    return slaveView;
}
项目:buildAPKsSamples    文件:BasicManagedProfileFragment.java   
@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);
}
项目:AllHuaji    文件:MainActivity.java   
@SuppressLint("NewApi")
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_demo);
    setting = new Settings(this);
    s = (Switch) findViewById(R.id.switch1);
    s.setChecked(setting.isStarted());
    s.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            // TODO 自动生成的方法存根
            setting.setStarted(isChecked);
        }
    });

}
项目:MaterialDesignWidget    文件:SwitchActivity.java   
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_switch);

        final Switch mSwitch = (Switch) findViewById(R.id.Switch2);
        mSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                Snackbar.make(mSwitch,""+isChecked,Snackbar.LENGTH_SHORT).show();
            }
        });
//        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
//            mSwitch.getThumbDrawable().setColorFilter(Color.RED, PorterDuff.Mode.MULTIPLY);
//            mSwitch.getTrackDrawable().setColorFilter(Color.RED, PorterDuff.Mode.MULTIPLY);
//        }

    }
项目:ifcalc    文件:ConfiguracaoActivity.java   
private void setUpViews() {
    edtPesoB1Anual = (EditText) findViewById(R.id.edtPesoB1Anual);
    edtPesoB2Anual = (EditText) findViewById(R.id.edtPesoB2Anual);
    edtPesoB3Anual = (EditText) findViewById(R.id.edtPesoB3Anual);
    edtPesoB4Anual = (EditText) findViewById(R.id.edtPesoB4Anual);

    edtPesoB1Semestral = (EditText) findViewById(R.id.edtPesoB1Semestral);
    edtPesoB2Semestral = (EditText) findViewById(R.id.edtPesoB2Semestral);

    edtMediaAnual = (EditText) findViewById(R.id.edtMediaAnual);
    edtMediaSemestral = (EditText) findViewById(R.id.edtMediaSemestral);

    switchCalculoPonderado = (Switch) findViewById(R.id.switchCalculoPonderado);

    layoutPesos = (LinearLayout) findViewById(R.id.layoutPesos);
}
项目:MultiplicationBasile    文件:MainActivity.java   
/***********************************************************
 * Managing LifeCycle
 **********************************************************/

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    getSupportActionBar().setDisplayUseLogoEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    getSupportActionBar().setIcon(R.mipmap.ic_launcher);
    btnStart= (Button) findViewById(R.id.btnStart);
    btnStart.setEnabled(false);
    swtThisTableOnly= (Switch) findViewById(R.id.swtThisTableOnly);

    // add the listener to the spinner that listen for item selection
    setListeners();
}
项目:IFWManager    文件:RuleListAdapter.java   
@Override
protected void convert(BaseViewHolder helper, MultiItemEntity item) {
    switch (item.getItemType()) {
        case RuleItem.TYPE_RULE:
            RuleItem ruleItem = (RuleItem) item;
            TextView title = helper.getView(R.id.text1);
            title.setText(ruleItem.getDetail());
            break;
        case RuleItem.TYPE_RULE_GROUP:
            RuleGroup group = (RuleGroup) item;
            Switch enable = helper.getView(R.id.switch_enable);
            enable.setChecked(group.isEnable());
            TextView summary = helper.getView(android.R.id.title);
            summary.setText(Utils.getContext().getString(
                    R.string.block_list_group_summary,
                    String.valueOf(group.getSubItems().size())
            ));
            break;
    }
}
项目:oneM2M-Application-AndroidSample    文件:MainActivity.java   
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    btnRetrieve = (Button) findViewById(R.id.btnRetrieve);
    Switch_MQTT = (Switch) findViewById(R.id.switch_mqtt);
    btnControl_Green = (ToggleButton) findViewById(R.id.btnControl_Green);
    btnControl_Blue = (ToggleButton) findViewById(R.id.btnControl_Blue);
    textViewData = (TextView) findViewById(R.id.textViewData);

    btnRetrieve.setOnClickListener(this);
    Switch_MQTT.setOnCheckedChangeListener(this);
    btnControl_Green.setOnClickListener(this);
    btnControl_Blue.setOnClickListener(this);
    // Create AE and Get AEID

    GetAEInfo();
}
项目:app_secompufscar    文件:Settings.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //Visual (CTRL+Click pra vc abrir rápido)
    setContentView(R.layout.settings);
    //Pega as preferências do usuário
    mPrefs = getApplicationContext().getSharedPreferences("Settings", 0);
    //Set a font
    FontsOverride.setDefaultFont(this, "DEFAULT", "fonts/ClearSans-Regular.ttf");
    //Linka com o visual
    switch_3g = (Switch)findViewById(R.id.settings_3g);
    switch_notifications = (Switch)findViewById(R.id.settings_notification);
    textView = (TextView)findViewById(R.id.fragment_title);
    //Carrega as prefências em variáveis e adiciona o estado switch
    onLoad();
    //Início da gambiarra
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle("");
    textView.setText("Configurações");
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    //Fim da gambiarra


}
项目:XposedNavigationBar    文件:SetOtherFragment.java   
@Override
void initView(View view) {
    btnHomePoint = (LinearLayout) view.findViewById(R.id.btn_home_point);
    tvHomePosition = (TextView) view.findViewById(R.id.tv_home_position);
    btnClearMemLevel = (LinearLayout) view.findViewById(R.id.btn_clear_mem_level);
    tvClearMemLevel = (TextView) view.findViewById(R.id.tv_clear_mem_level);
    btnIconSize = (LinearLayout) view.findViewById(R.id.btn_icon_size);
    tvIconSize = (TextView) view.findViewById(R.id.tv_icon_size);
    //  swHook90 = (Switch) findViewById(R.id.sw_hook_90);
    swRootDown = (Switch) view.findViewById(R.id.sw_root_down);
    settingAboutMarshmallow = (LinearLayout) view.findViewById(R.id.setting_about_marshmallow);
    swChameleonNavbar = (Switch) view.findViewById(R.id.sw_chameleon_navbar);
    btnNavbarHeight = (LinearLayout) view.findViewById(R.id.btn_navbar_height);
    tvNavbarHeight = (TextView) view.findViewById(R.id.tv_navbar_height);
    swVibrate = (Switch) view.findViewById(R.id.sw_navbar_vibrate);
    swHideAppIcon = (Switch) view.findViewById(R.id.sw_hide_app_icon);
}
项目:routineKeen    文件:HabitEditActivity.java   
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.edit_habit);
    titleEditText = (EditText) findViewById(R.id.editHabit_habitTitleField);
    reasonEditText = (EditText) findViewById(R.id.editHabit_habitReasonField);
    saveBtn = (Button) findViewById(R.id.saveButton);
    checkHabitProgressButton = (Button) findViewById(R.id.checkHabitProgressButton);
    monSwitch = (Switch) findViewById(R.id.monSwitch);
    tueSwitch = (Switch) findViewById(R.id.tueSwitch);
    wedSwitch = (Switch) findViewById(R.id.wedSwitch);
    thuSwitch = (Switch) findViewById(R.id.thuSwitch);
    friSwitch = (Switch) findViewById(R.id.friSwitch);
    satSwitch = (Switch) findViewById(R.id.satSwitch);
    sunSwitch = (Switch) findViewById(R.id.sunSwitch);
    initListeners();
}
项目:MyGeofencer    文件:EditGeofenceActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Intent intent = getIntent();
    myGeofence = intent.getParcelableExtra(MYGEOFENCE_EXTRA);
    if(myGeofence == null) {
        Log.e(EditGeofenceActivity.class.getSimpleName(), "Intent extra does not contain a MyGeofence object");
        finish();
    }

    ((MyGeofencerApplication) getApplication()).getMyGeofencerComponent().inject(this);

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);

    setContentView(R.layout.activity_edit_geofence);
    nameEditText = (EditText) findViewById(R.id.name);
    nameEditText.setText(myGeofence.getName());

    monitorSwitch = (Switch) findViewById(R.id.monitor_switch);
    monitorSwitch.setChecked(myGeofence.isEnabled());
}
项目:GitHub    文件:ConfigurationItem.java   
public ViewHolder(View view, FlexibleAdapter adapter) {
    super(view, adapter, true);//True for sticky
    mTitle = (TextView) view.findViewById(R.id.title);
    mDescription = (TextView) view.findViewById(R.id.subtitle);
    mSeekBar = (SeekBar) view.findViewById(R.id.seek_bar);
    mSwitchView = (Switch) view.findViewById(R.id.switch_box);
}
项目:gree-remote    文件:DeviceActivity.java   
private boolean isSwitchChecked(int id) {
    View view = findViewById(id);
    if (view instanceof Switch) {
        return ((Switch) view).isChecked();
    }

    return false;
}
项目:aftercare-app-android    文件:DCSettingsActivity.java   
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addContentView(R.layout.activity_settings);
    setActionBarTitle(R.string.settings_hdl_settings);

    tvSettingsVoice = (DCTextView) findViewById(R.id.tv_settings_voice);
    swSettingsSounds = (Switch) findViewById(R.id.sw_settings_sounds);
    swSettingsMusic = (Switch) findViewById(R.id.sw_settings_music);
    swSettingsVoice = (Switch) findViewById(R.id.sw_settings_voice);
    swSettingsDailyBrushing = (Switch) findViewById(R.id.sw_settings_daily_brushing);
    swSettingsChangeBrush = (Switch) findViewById(R.id.sw_settings_change_brush);
    swSettingsVisitDentist = (Switch) findViewById(R.id.sw_settings_visit_dentist);
    swSettingsReminderToVisit = (Switch) findViewById(R.id.sw_settings_reminder_to_visit);
    swSettingsHealthyHabits = (Switch) findViewById(R.id.sw_settings_healthy_habits);
    swSettingsEnableNotifications = (Switch) findViewById(R.id.sw_settings_enable_notifications);
    llSettingsEnableNotifications = (LinearLayout) findViewById(R.id.ll_settings_enable_notifications);
    llSettingsNotifications = (LinearLayout) findViewById(R.id.ll_settings_notifications);

    setupUI();

    swSettingsSounds.setOnCheckedChangeListener(this);
    swSettingsMusic.setOnCheckedChangeListener(this);
    swSettingsVoice.setOnCheckedChangeListener(this);
    swSettingsDailyBrushing.setOnCheckedChangeListener(this);
    swSettingsChangeBrush.setOnCheckedChangeListener(this);
    swSettingsVisitDentist.setOnCheckedChangeListener(this);
    swSettingsReminderToVisit.setOnCheckedChangeListener(this);
    swSettingsHealthyHabits.setOnCheckedChangeListener(this);
    swSettingsEnableNotifications.setOnCheckedChangeListener(this);
}
项目:ingetin    文件:AdapterAkademik.java   
public ViewHolder(View itemView) {
    super(itemView);
    txt_judul = (TextView) itemView.findViewById(R.id.txt_judul);
    txt_jenis = (TextView) itemView.findViewById(R.id.txt_jenis);
    txt_deadline = (TextView) itemView.findViewById(R.id.txt_deadline);
    switch_done = (Switch) itemView.findViewById(R.id.switch_done);
}
项目:ingetin    文件:AdapterOrganisasi.java   
public ViewHolder(View itemView) {
    super(itemView);
    txt_judul = (TextView) itemView.findViewById(R.id.txt_judul);
    txt_jenis = (TextView) itemView.findViewById(R.id.txt_jenis);
    txt_deadline = (TextView) itemView.findViewById(R.id.txt_deadline);
    switch_done = (Switch) itemView.findViewById(R.id.switch_done);
}
项目:Material-Motion    文件:MainActivity.java   
private void setupWarning(){
    preferences= PreferenceManager.getDefaultSharedPreferences(this);
    preferences.registerOnSharedPreferenceChangeListener(this);
    onSharedPreferenceChanged(preferences,WARNING_KEY);
    final MenuItem item=navigation.getMenu().findItem(R.id.enable_message);
    Switch view=(Switch)MenuItemCompat.getActionView(item);
    view.setChecked(preferences.getBoolean(WARNING_KEY,false));
    view.setOnCheckedChangeListener((button,isChecked)->{
        if(enabledWarning!=isChecked) {
            preferences.edit()
                    .putBoolean(WARNING_KEY, isChecked)
                    .apply();
        }
    });
}
项目:SystemUITuner2    文件:Misc.java   
private void setupSwitches() {
    Switch show_full_zen = view.findViewById(R.id.show_full_zen);
    Switch hu_notif = view.findViewById(R.id.hu_notif);
    Switch vol_warn = view.findViewById(R.id.vol_warn);
    Switch power_notifs = view.findViewById(R.id.power_notifications);
    Switch clock_seconds = view.findViewById(R.id.clock_seconds);
    Switch battery_percent = view.findViewById(R.id.battery_percent);
    CardView power_notif_controls = view.findViewById(R.id.power_notification_controls_card);

    //noinspection deprecation
    battery_percent.setText(Html.fromHtml(getResources().getText(R.string.battery_percentage) + "<br /><small> <font color=\"#777777\">" + getResources().getText(R.string.reboot_required) + "</font></small>"));

    if (Build.VERSION.SDK_INT > 23) {
        clock_seconds.setVisibility(View.VISIBLE); //only show switch if user is on Nougat or later
        power_notif_controls.setVisibility(View.VISIBLE); //this is a Nougat feature; only show it on Nougat devices
    } else {
        clock_seconds.setVisibility(View.GONE);
        power_notif_controls.setVisibility(View.GONE);
    }

    activity.setThings.switches(show_full_zen, SHOW_FULL_ZEN, SECURE, view); //switch listener
    activity.setThings.switches(hu_notif, HUN_ENABLED, GLOBAL, view);
    activity.setThings.switches(vol_warn, SAFE_AUDIO, GLOBAL, view);

    activity.setThings.switches(clock_seconds, CLOCK_SECONDS, SECURE, view);
    activity.setThings.switches(battery_percent, BATTERY_PERCENT, SYSTEM, view);

    activity.setThings.switches(power_notifs, POW_NOTIFS, SECURE, view);
}
项目:SystemUITuner2    文件:Demo.java   
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();
        }
    });
}
项目:RootPGPExplorer    文件:PreferencesActivity.java   
private void setBoxes() {
    Switch box1= (Switch) findViewById(R.id.prefs_autodel_box);
    Switch box2= (Switch) findViewById(R.id.prefs_askenc_box);
    Switch box3= (Switch) findViewById(R.id.prefs_savepass_box);
    box1.setChecked(SharedData.ASK_DEL_AFTER_ENCRYPTION);
    box2.setChecked(SharedData.ASK_ENCRYPTION_CONFIG);
    box3.setChecked(SharedData.ASK_KEY_PASSS_CONFIG);
    box1.setOnClickListener(this);
    box2.setOnClickListener(this);
    box3.setOnClickListener(this);

}
项目:SystemUITuner2    文件:Demo.java   
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();
        }
    });
}
项目:SonoESEO-Android    文件:ActivitiesFragment.java   
/**
 * On click on the sort button.
 * It will open a dialog with two switch to sort the list of categories or not and by ascending
 * dates or not.
 */
@Override
public void onClick(View v) {
    final Dialog dialog = new Dialog(ctx);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.dialog_sort);
    if (dialog.getWindow() != null) {
        dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    }

    final Switch switchCategorized = dialog.findViewById(R.id.switchCategorized);
    final Switch switchAscending = dialog.findViewById(R.id.switchAscending);

    switchCategorized.setChecked(Content.categorized);
    switchAscending.setChecked(Content.ascendingSort);

    Button validate = dialog.findViewById(R.id.validate);
    validate.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Content.categorized = switchCategorized.isChecked();
            Content.ascendingSort = switchAscending.isChecked();
            sort();
            dialog.dismiss();
        }
    });

    dialog.show();
}
项目:Task-Reminder    文件:ReminderAddActivity.java   
public void onSwitchRepeat(View view) {
    boolean on = ((Switch) view).isChecked();
    if (on) {
        mRepeat = "true";
        mRepeatText.setText("Every " + mRepeatNo + " " + mRepeatType + "(s)");
    } else {
        mRepeat = "false";
        mRepeatText.setText(R.string.repeat_off);
    }
}
项目:memento-app    文件:LogActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_log);

    final LogAdapter logAdapter = new LogAdapter();
    ListView listView = (ListView) findViewById(R.id.log);
    listView.setAdapter(logAdapter);

    Switch start_switch = (Switch) findViewById(R.id.start_switch);
    start_switch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                MainService.APP_START = 1;
            } else {
                MainService.APP_START = 0;
            }
        }
    });

    if (MainService.APP_START==1) {
        start_switch.setChecked(true);
    } else {
        start_switch.setChecked(false);
    }


    final Handler handler = new Handler();
    handler.postDelayed(new Runnable() {

        @Override
        public void run() {
            logAdapter.notifyDataSetChanged();
            handler.postDelayed(this, 1000);
        }
    }, 1000);

}
项目:olami-android-client-sdk    文件:SpeechInputActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_speech_input);


    Intent intent = getIntent();
    Config.setLocalizeOption(intent.getIntExtra("LOCALIZE_OPTION", Config.getLocalizeOption()));

    recordButton = (Button) findViewById(R.id.recordButton);
    cancelButton = (Button) findViewById(R.id.cancelButton);
    voiceVolumeText = (TextView) findViewById(R.id.voiceVolume);
    voiceVolumeBar = (TextView) findViewById(R.id.voiceVolumeBar);
    STTText = (TextView) findViewById(R.id.STTText);
    APIResponseText = (TextView) findViewById(R.id.APIResponse);
    APIResponseText.setMovementMethod(ScrollingMovementMethod.getInstance());
    recognizeStatusText = (TextView) findViewById(R.id.recognizeStatus);
    recordStatusText = (TextView) findViewById(R.id.recordStatus);

    recordButton.setOnClickListener(new recordButtonListener());
    cancelButton.setOnClickListener(new cancelButtonListener());

    mAutoStopSwitch = (Switch) findViewById(R.id.autoStopSwitch);
    mAutoStopSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (mRecognizer != null) {
                mRecognizer.enableAutoStopRecording(isChecked);
            }
        }
    });
}