Search in sources :

Example 41 with Switch

use of android.widget.Switch in project qianghongbao by lendylongli.

the class CustomSwitchPreference method clearListenerInViewGroup.

/**
     * Clear listener in Switch for specify ViewGroup.
     *
     * @param viewGroup The ViewGroup that will need to clear the listener.
     */
private void clearListenerInViewGroup(ViewGroup viewGroup) {
    if (null == viewGroup) {
        return;
    }
    int count = viewGroup.getChildCount();
    for (int n = 0; n < count; ++n) {
        View childView = viewGroup.getChildAt(n);
        if (childView instanceof Switch) {
            final Switch switchView = (Switch) childView;
            switchView.setOnCheckedChangeListener(null);
            return;
        } else if (childView instanceof ViewGroup) {
            ViewGroup childGroup = (ViewGroup) childView;
            clearListenerInViewGroup(childGroup);
        }
    }
}
Also used : Switch(android.widget.Switch) ViewGroup(android.view.ViewGroup) View(android.view.View)

Example 42 with Switch

use of android.widget.Switch in project weiciyuan by qii.

the class NotificationFragment method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setRetainInstance(false);
    addPreferencesFromResource(R.xml.notification_pref);
    preferenceList.add(findPreference(SettingActivity.DISABLE_FETCH_AT_NIGHT));
    preferenceList.add(findPreference(SettingActivity.FREQUENCY));
    preferenceList.add(findPreference(SettingActivity.ENABLE_COMMENT_TO_ME));
    preferenceList.add(findPreference(SettingActivity.ENABLE_MENTION_COMMENT_TO_ME));
    preferenceList.add(findPreference(SettingActivity.ENABLE_MENTION_TO_ME));
    preferenceList.add(findPreference(SettingActivity.ENABLE_VIBRATE));
    preferenceList.add(findPreference(SettingActivity.ENABLE_LED));
    preferenceList.add(findPreference(SettingActivity.ENABLE_RINGTONE));
    View title = getActivity().getLayoutInflater().inflate(R.layout.filteractivity_title_layout, null);
    Switch switchBtn = (Switch) title.findViewById(R.id.switchBtn);
    getActivity().getActionBar().setCustomView(title, new ActionBar.LayoutParams(Gravity.RIGHT));
    getActivity().getActionBar().setDisplayShowCustomEnabled(true);
    switchBtn.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            SettingUtility.setEnableFetchMSG(isChecked);
            switchPre(isChecked);
        }
    });
    switchBtn.setChecked(SettingUtility.getEnableFetchMSG());
    switchPre(SettingUtility.getEnableFetchMSG());
    getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
    frequency = findPreference(SettingActivity.FREQUENCY);
    ringtone = findPreference(SettingActivity.ENABLE_RINGTONE);
    ringtone.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
            intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, getString(R.string.pref_ringtone_title));
            intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, true);
            intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
            intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
            intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, uri);
            intent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, uri);
            startActivityForResult(intent, 1);
            return true;
        }
    });
    String path = SettingUtility.getRingtone();
    if (!TextUtils.isEmpty(SettingUtility.getRingtone())) {
        uri = Uri.parse(path);
    }
}
Also used : Switch(android.widget.Switch) Preference(android.preference.Preference) Intent(android.content.Intent) View(android.view.View) ActionBar(android.app.ActionBar) CompoundButton(android.widget.CompoundButton)

Example 43 with Switch

use of android.widget.Switch in project weiciyuan by qii.

the class FilterActivity method initLayout.

private void initLayout() {
    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setDisplayShowHomeEnabled(true);
    getActionBar().setTitle(getString(R.string.filter));
    setContentView(R.layout.viewpager_layout);
    ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setDisplayShowHomeEnabled(true);
    actionBar.setTitle(getString(R.string.filter));
    actionBar.setIcon(R.drawable.ic_filter);
    View title = getLayoutInflater().inflate(R.layout.filteractivity_title_layout, null);
    Switch switchBtn = (Switch) title.findViewById(R.id.switchBtn);
    actionBar.setCustomView(title, new ActionBar.LayoutParams(Gravity.RIGHT));
    actionBar.setDisplayShowCustomEnabled(true);
    switchBtn.setChecked(SettingUtility.isEnableFilter());
    switchBtn.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            SettingUtility.setEnableFilter(isChecked);
        }
    });
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    actionBar.addTab(actionBar.newTab().setText(getString(R.string.filter_keyword)).setTabListener(tabListener));
    actionBar.addTab(actionBar.newTab().setText(getString(R.string.filter_user)).setTabListener(tabListener));
    actionBar.addTab(actionBar.newTab().setText(getString(R.string.filter_topic)).setTabListener(tabListener));
    actionBar.addTab(actionBar.newTab().setText(getString(R.string.filter_source)).setTabListener(tabListener));
    viewPager = (ViewPager) findViewById(R.id.viewpager);
    TimeLinePagerAdapter adapter = new TimeLinePagerAdapter(getSupportFragmentManager());
    viewPager.setOffscreenPageLimit(4);
    viewPager.setAdapter(adapter);
    viewPager.setOnPageChangeListener(onPageChangeListener);
}
Also used : Switch(android.widget.Switch) View(android.view.View) ActionBar(android.app.ActionBar) CompoundButton(android.widget.CompoundButton)

Example 44 with Switch

use of android.widget.Switch in project scalpel by JakeWharton.

the class SampleActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.sample_activity);
    ButterKnife.inject(this);
    pagerView.setAdapter(new SamplePagerAdapter(this));
    Switch enabledSwitch = new Switch(this);
    enabledSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (first) {
                first = false;
                Toast.makeText(SampleActivity.this, R.string.first_run, LENGTH_LONG).show();
            }
            scalpelView.setLayerInteractionEnabled(isChecked);
            invalidateOptionsMenu();
        }
    });
    ActionBar actionBar = getActionBar();
    actionBar.setCustomView(enabledSwitch);
    actionBar.setDisplayOptions(DISPLAY_SHOW_TITLE | DISPLAY_SHOW_CUSTOM);
}
Also used : Switch(android.widget.Switch) CompoundButton(android.widget.CompoundButton) ActionBar(android.app.ActionBar)

Example 45 with Switch

use of android.widget.Switch in project Gadgetbridge by Freeyourgadget.

the class GBAlarmListAdapter method getView.

@Override
public View getView(int position, View view, ViewGroup parent) {
    final GBAlarm alarm = getItem(position);
    if (view == null) {
        LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = inflater.inflate(R.layout.alarm_item, parent, false);
    }
    TextView alarmTime = (TextView) view.findViewById(R.id.alarm_item_time);
    Switch isEnabled = (Switch) view.findViewById(R.id.alarm_item_toggle);
    TextView isSmartWakeup = (TextView) view.findViewById(R.id.alarm_smart_wakeup);
    highlightDay((TextView) view.findViewById(R.id.alarm_item_sunday), alarm.getRepetition(Alarm.ALARM_SUN));
    highlightDay((TextView) view.findViewById(R.id.alarm_item_monday), alarm.getRepetition(Alarm.ALARM_MON));
    highlightDay((TextView) view.findViewById(R.id.alarm_item_tuesday), alarm.getRepetition(Alarm.ALARM_TUE));
    highlightDay((TextView) view.findViewById(R.id.alarm_item_wednesday), alarm.getRepetition(Alarm.ALARM_WED));
    highlightDay((TextView) view.findViewById(R.id.alarm_item_thursday), alarm.getRepetition(Alarm.ALARM_THU));
    highlightDay((TextView) view.findViewById(R.id.alarm_item_friday), alarm.getRepetition(Alarm.ALARM_FRI));
    highlightDay((TextView) view.findViewById(R.id.alarm_item_saturday), alarm.getRepetition(Alarm.ALARM_SAT));
    isEnabled.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            alarm.setEnabled(isChecked);
            update(alarm);
        }
    });
    view.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            ((ConfigureAlarms) mContext).configureAlarm(alarm);
        }
    });
    alarmTime.setText(alarm.getTime());
    isEnabled.setChecked(alarm.isEnabled());
    if (alarm.isSmartWakeup()) {
        isSmartWakeup.setVisibility(TextView.VISIBLE);
    } else {
        isSmartWakeup.setVisibility(TextView.GONE);
    }
    return view;
}
Also used : Switch(android.widget.Switch) GBAlarm(nodomain.freeyourgadget.gadgetbridge.impl.GBAlarm) LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) TextView(android.widget.TextView) View(android.view.View) CompoundButton(android.widget.CompoundButton)

Aggregations

Switch (android.widget.Switch)56 View (android.view.View)29 CompoundButton (android.widget.CompoundButton)18 TextView (android.widget.TextView)18 Context (android.content.Context)11 DialogInterface (android.content.DialogInterface)8 AlertDialog (android.app.AlertDialog)7 LayoutInflater (android.view.LayoutInflater)7 Checkable (android.widget.Checkable)7 OnCancelListener (android.content.DialogInterface.OnCancelListener)6 TypedArray (android.content.res.TypedArray)6 Drawable (android.graphics.drawable.Drawable)6 InputMethodInfo (android.view.inputmethod.InputMethodInfo)6 InputMethodSubtype (android.view.inputmethod.InputMethodSubtype)6 JSONObject (org.json.JSONObject)6 OnClickListener (android.content.DialogInterface.OnClickListener)5 Intent (android.content.Intent)5 LocaleList (android.os.LocaleList)5 ContextThemeWrapper (android.view.ContextThemeWrapper)5 OnCheckedChangeListener (android.widget.CompoundButton.OnCheckedChangeListener)5