Java Code Examples for android.widget.Switch#setText()

The following examples show how to use android.widget.Switch#setText() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KeyAssignmentUtils.java    From talkback with Apache License 2.0 6 votes vote down vote up
/**
 * Configures the screen switch preference toggle based on whether and where the screen switch is
 * currently assigned.
 *
 * @param screenSwitchToggle A switch that corresponds to the current assignment status of the
 *     screen switch.
 * @param keyCombos List of keys currently assigned to this action
 * @param context Context used to determine if the screen switch is currently assigned to a
 *     different action
 * @param key The key to the map that pairs an action with a set of switches currently assigned to
 *     said action.
 */
public static void updateScreenAsASwitchToggle(
    Switch screenSwitchToggle, Set<Long> keyCombos, Context context, String key) {
  long screenSwitchKeyCombo =
      KeyAssignmentUtils.keyEventToExtendedKeyCode(SCREEN_SWITCH_EVENT_UP);

  if (!keyCombos.isEmpty() && keyCombos.contains(screenSwitchKeyCombo)) {
    screenSwitchToggle.setEnabled(true);
    screenSwitchToggle.setChecked(true);
    screenSwitchToggle.setText(R.string.key_combo_preference_screen_switch_toggle);
  } else if (KeyAssignmentUtils.otherActionAssociatedWithKey(
      screenSwitchKeyCombo, context, key)) {
    screenSwitchToggle.setEnabled(false);
    screenSwitchToggle.setChecked(false);
    screenSwitchToggle.setText(R.string.key_combo_preference_screen_switch_toggle_disabled);
  } else {
    screenSwitchToggle.setEnabled(true);
    screenSwitchToggle.setChecked(false);
    screenSwitchToggle.setText(R.string.key_combo_preference_screen_switch_toggle);
  }
}
 
Example 2
Source File: ToggleElement.java    From debugdrawer with Apache License 2.0 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup root) {
    final Context context = root.getContext();
    checked = new BooleanPreference(
        context.getSharedPreferences(getKey(),Context.MODE_PRIVATE),
        getTitle(),
        String.valueOf(defaultValue));
    if(!checked.isSet()) checked.set(defaultValue);

    aSwitch = new Switch(new ContextThemeWrapper(context, R.style.Widget_U2020_DebugDrawer_RowWidget));
    aSwitch.setText(title);
    aSwitch.setChecked(checked.get());
    aSwitch.setEnabled(isEnabled());
    aSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            checked.set(isChecked);
            onSwitch(isChecked);
        }
    });
    aSwitch.setGravity(Gravity.START | Gravity.END | Gravity.CENTER_VERTICAL); // "start|end|center_vertical"
    return aSwitch;
}
 
Example 3
Source File: FloatingModMenuService.java    From FloatingModMenu with GNU General Public License v3.0 5 votes vote down vote up
private void addSwitch(String name, final SW listner) {
    Switch sw = new Switch(this);
    sw.setText(name);
    sw.setTextColor(Color.WHITE);
    //sw.setTextSize(dipToPixels());
    sw.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            listner.OnWrite(isChecked);
        }
    });
    patches.addView(sw);
}
 
Example 4
Source File: AppRestrictionEnforcerFragment.java    From enterprise-samples with Apache License 2.0 5 votes vote down vote up
private void updateApprovals(Context context, String[] approvals,
                             String[] selectedApprovals) {
    mCurrentRestrictions.putStringArray(RESTRICTION_KEY_APPROVALS, selectedApprovals);
    mLayoutApprovals.removeAllViews();
    for (String approval : approvals) {
        Switch sw = new Switch(context);
        sw.setText(approval);
        sw.setTag(approval);
        sw.setChecked(Arrays.asList(selectedApprovals).contains(approval));
        sw.setOnCheckedChangeListener(this);
        sw.setId(R.id.approval);
        mLayoutApprovals.addView(sw);
    }
}
 
Example 5
Source File: Misc.java    From SystemUITuner2 with MIT License 5 votes vote down vote up
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);
}
 
Example 6
Source File: AppRestrictionEnforcerFragment.java    From android-AppRestrictionEnforcer with Apache License 2.0 5 votes vote down vote up
private void updateApprovals(Context context, String[] approvals,
                             String[] selectedApprovals) {
    mCurrentRestrictions.putStringArray(RESTRICTION_KEY_APPROVALS, selectedApprovals);
    mLayoutApprovals.removeAllViews();
    for (String approval : approvals) {
        Switch sw = new Switch(context);
        sw.setText(approval);
        sw.setTag(approval);
        sw.setChecked(Arrays.asList(selectedApprovals).contains(approval));
        sw.setOnCheckedChangeListener(this);
        sw.setId(R.id.approval);
        mLayoutApprovals.addView(sw);
    }
}
 
Example 7
Source File: OBooleanField.java    From hr with GNU Affero General Public License v3.0 4 votes vote down vote up
public void initControl() {
    mReady = false;
    LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT);
    removeAllViews();
    setOrientation(VERTICAL);
    if (isEditable()) {
        if (mWidget != null) {
            switch (mWidget) {
                case Switch:
                    mSwitch = new Switch(mContext);
                    mSwitch.setLayoutParams(params);
                    mSwitch.setOnCheckedChangeListener(this);
                    setValue(getValue());
                    if (mLabel != null)
                        mSwitch.setText(mLabel);
                    if (textSize > -1) {
                        mSwitch.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
                    }
                    if (appearance > -1) {
                        mSwitch.setTextAppearance(mContext, appearance);
                    }
                    mSwitch.setTextColor(textColor);
                    addView(mSwitch);
                    break;
                default:
                    break;
            }
        } else {
            mCheckbox = new CheckBox(mContext);
            mCheckbox.setLayoutParams(params);
            mCheckbox.setOnCheckedChangeListener(this);
            if (mLabel != null)
                mCheckbox.setText(mLabel);
            if (textSize > -1) {
                mCheckbox.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
            }
            if (appearance > -1) {
                mCheckbox.setTextAppearance(mContext, appearance);
            }
            mCheckbox.setTextColor(textColor);
            addView(mCheckbox);
        }
    } else {
        txvView = new TextView(mContext);
        txvView.setLayoutParams(params);
        txvView.setText(getCheckBoxLabel());
        if (mLabel != null)
            txvView.setText(mLabel);
        if (textSize > -1) {
            txvView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
        }
        if (appearance > -1) {
            txvView.setTextAppearance(mContext, appearance);
        }
        addView(txvView);
    }
}
 
Example 8
Source File: OBooleanField.java    From framework with GNU Affero General Public License v3.0 4 votes vote down vote up
public void initControl() {
    mReady = false;
    LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT);
    removeAllViews();
    setOrientation(VERTICAL);
    if (isEditable()) {
        if (mWidget != null) {
            switch (mWidget) {
                case Switch:
                    mSwitch = new Switch(mContext);
                    mSwitch.setLayoutParams(params);
                    mSwitch.setOnCheckedChangeListener(this);
                    setValue(getValue());
                    if (mLabel != null)
                        mSwitch.setText(mLabel);
                    if (textSize > -1) {
                        mSwitch.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
                    }
                    if (appearance > -1) {
                        mSwitch.setTextAppearance(mContext, appearance);
                    }
                    mSwitch.setTextColor(textColor);
                    addView(mSwitch);
                    break;
                default:
                    break;
            }
        } else {
            mCheckbox = new CheckBox(mContext);
            mCheckbox.setLayoutParams(params);
            mCheckbox.setOnCheckedChangeListener(this);
            if (mLabel != null)
                mCheckbox.setText(mLabel);
            if (textSize > -1) {
                mCheckbox.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
            }
            if (appearance > -1) {
                mCheckbox.setTextAppearance(mContext, appearance);
            }
            mCheckbox.setTextColor(textColor);
            addView(mCheckbox);
        }
    } else {
        txvView = new TextView(mContext);
        txvView.setLayoutParams(params);
        txvView.setText(getCheckBoxLabel());
        if (mLabel != null)
            txvView.setText(mLabel);
        if (textSize > -1) {
            txvView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
        }
        if (appearance > -1) {
            txvView.setTextAppearance(mContext, appearance);
        }
        addView(txvView);
    }
}