public void setNames() { ToggleButton tb1 = (ToggleButton) findViewById(R.id.Person1); ToggleButton tb2 = (ToggleButton) findViewById(R.id.Person2); ToggleButton tb3 = (ToggleButton) findViewById(R.id.Person3); tb1.setTextOn(names[0]); tb1.setTextOff(names[0]); tb2.setTextOn(names[1]); tb2.setTextOff(names[1]); tb3.setTextOn(names[2]); tb3.setTextOff(names[2]); personManager(currentPerson); }
public void addSegment(String title) { DisplayMetrics metrics = new DisplayMetrics(); ((Activity) getContext()).getWindowManager().getDefaultDisplay().getMetrics(metrics); ToggleButton b = new ToggleButton(getContext()); b.setText(title); b.setTextOff(title); b.setTextOn(title); b.setTextColor(Color.WHITE); b.setTypeface(Typeface.DEFAULT_BOLD); b.setMinimumWidth((int) (40 * metrics.density)); if (mSwitches.size() == 0) { b.setBackgroundResource(mLeftDrawable); b.setEnabled(false); b.setChecked(true); } else { if (mSwitches.size() > 1) { ToggleButton temp = mSwitches.get(mSwitches.size() - 1); temp.setBackgroundResource(mMidDrawable); } b.setBackgroundResource(mRightDrawable); } LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); params.weight = 0.1f; params.gravity = Gravity.CENTER; b.setLayoutParams(params); b.setOnCheckedChangeListener(this); mSwitches.add(b); addView(b); }
private void setupImageDemoButton() { CharSequence txtoff = "Image demo off"; CharSequence txton = "Image demo on"; txtoff.toString().toLowerCase(); txton.toString().toLowerCase(); imagebtn.setTextOff(txtoff); imagebtn.setTextOn(txton); }
private ToggleButton initToggleButton(View view, int id) { ToggleButton ret = (ToggleButton) view.findViewById(id); ret.setFocusable(false); ret.setEnabled(false); CharSequence str = ret.getText(); ret.setTextOff(str); ret.setTextOn(str); return ret; }
@Override public View newView(Context context, Cursor cursor, ViewGroup parent) { final View view = mFactory.inflate(R.layout.alarm_time, parent, false); // standard view holder optimization final ItemHolder holder = new ItemHolder(); holder.alarmItem = (LinearLayout) view.findViewById(R.id.alarm_item); holder.clock = (DigitalClock) view.findViewById(R.id.digital_clock); holder.clock.setLive(false); holder.onoff = (Switch) view.findViewById(R.id.onoff); holder.onoff.setTypeface(mRobotoNormal); holder.daysOfWeek = (TextView) view.findViewById(R.id.daysOfWeek); holder.label = (TextView) view.findViewById(R.id.label); holder.expandArea = view.findViewById(R.id.expand_area); holder.infoArea = view.findViewById(R.id.info_area); holder.repeat = (CheckBox) view.findViewById(R.id.repeat_onoff); holder.clickableLabel = (TextView) view.findViewById(R.id.edit_label); holder.hairLine = view.findViewById(R.id.hairline); holder.repeatDays = (LinearLayout) view.findViewById(R.id.repeat_days); // Build button for each day. for (int i = 0; i < 7; i++) { final ViewGroup viewgroup = (ViewGroup) mFactory.inflate(R.layout.day_button, holder.repeatDays, false); final ToggleButton button = (ToggleButton) viewgroup.getChildAt(0); final int dayToShowIndex = DAY_ORDER[i]; button.setText(mShortWeekDayStrings[dayToShowIndex]); button.setTextOn(mShortWeekDayStrings[dayToShowIndex]); button.setTextOff(mShortWeekDayStrings[dayToShowIndex]); button.setContentDescription(mLongWeekDayStrings[dayToShowIndex]); holder.repeatDays.addView(viewgroup); holder.dayButtons[i] = button; holder.dayButtonParents[i] = viewgroup; } holder.vibrate = (CheckBox) view.findViewById(R.id.vibrate_onoff); holder.collapse = (ViewGroup) view.findViewById(R.id.collapse); holder.ringtone = (TextView) view.findViewById(R.id.choose_ringtone); view.setTag(holder); return view; }
public ImportanceControlSet(int containerId) { LinearLayout layout = (LinearLayout) findViewById(containerId); int min = Task.IMPORTANCE_MOST; int max = Task.IMPORTANCE_LEAST; int importanceOffset = max; if (ProducteevUtilities.INSTANCE.isLoggedIn()) { max = 5; importanceOffset = max - 1; } for (int i = min; i <= max; i++) { final ToggleButton button = new ToggleButton(TaskEditActivity.this); button.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 1)); StringBuilder label = new StringBuilder(); if (ProducteevUtilities.INSTANCE.isLoggedIn()) label.append(5 - i).append("\n\u2605"); // $NON-NLS-1$ else { for (int j = importanceOffset; j >= i; j--) label.append('!'); } button.setTextColor(colors[i]); button.setTextOff(label); button.setTextOn(label); button.setOnClickListener( new View.OnClickListener() { public void onClick(View v) { setImportance((Integer) button.getTag()); } }); button.setTag(i); buttons.add(button); layout.addView(button); } }
public void setNumberOfSegments(int num) { mSwitches.clear(); DisplayMetrics metrics = new DisplayMetrics(); ((Activity) getContext()).getWindowManager().getDefaultDisplay().getMetrics(metrics); for (int i = 0; i < num; i++) { ToggleButton b = new ToggleButton(getContext()); if (i == 0) { b.setBackgroundResource(mLeftDrawable); b.setEnabled(false); b.setChecked(true); } else if (i == num - 1) { b.setBackgroundResource(mRightDrawable); } else { b.setBackgroundResource(mMidDrawable); } b.setText(""); b.setTextOff(""); b.setTextOn(""); b.setTextColor(Color.WHITE); b.setTypeface(Typeface.DEFAULT_BOLD); b.setMinimumWidth((int) (40 * metrics.density)); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); params.gravity = Gravity.CENTER; params.weight = 0.1f; b.setLayoutParams(params); b.setOnCheckedChangeListener(this); mSwitches.add(b); addView(b); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.show_settings_value); // track we come here ActivityGroupSettings.group.parent.trackPageView(TrackingValues.pageShowSettingFoodComposition); rbCarb = (RadioButton) findViewById(R.id.radioCarbs); rbProt = (RadioButton) findViewById(R.id.radioProt); rbFat = (RadioButton) findViewById(R.id.radioFat); rbKcal = (RadioButton) findViewById(R.id.radioKcal); tgCarb = (ToggleButton) findViewById(R.id.toggleButtonCarbs); tgProt = (ToggleButton) findViewById(R.id.toggleButtonProt); tgFat = (ToggleButton) findViewById(R.id.toggleButtonFat); tgKcal = (ToggleButton) findViewById(R.id.toggleButtonKcal); btNext = (Button) findViewById(R.id.buttonNext); btBack = (Button) findViewById(R.id.buttonBack); btBack.setOnClickListener( new OnClickListener() { public void onClick(View v) { ActivityGroupSettings.group.back(); } }); // set text off tgCarb.setTextOff(getResources().getString(R.string.invisible)); tgProt.setTextOff(getResources().getString(R.string.invisible)); tgFat.setTextOff(getResources().getString(R.string.invisible)); tgKcal.setTextOff(getResources().getString(R.string.invisible)); // set text on tgCarb.setTextOn(getResources().getString(R.string.visible)); tgProt.setTextOn(getResources().getString(R.string.visible)); tgFat.setTextOn(getResources().getString(R.string.visible)); tgKcal.setTextOn(getResources().getString(R.string.visible)); rbCarb.setOnClickListener( new OnClickListener() { public void onClick(View v) { updatedChecked(1); } }); rbCarb.setOnClickListener( new OnClickListener() { public void onClick(View v) { updatedChecked(1); } }); rbProt.setOnClickListener( new OnClickListener() { public void onClick(View v) { updatedChecked(2); } }); rbFat.setOnClickListener( new OnClickListener() { public void onClick(View v) { updatedChecked(3); } }); rbKcal.setOnClickListener( new OnClickListener() { public void onClick(View v) { updatedChecked(4); } }); tgCarb.setOnClickListener( new OnClickListener() { public void onClick(View v) { changeToggleButton(1); } }); tgProt.setOnClickListener( new OnClickListener() { public void onClick(View v) { changeToggleButton(2); } }); tgFat.setOnClickListener( new OnClickListener() { public void onClick(View v) { changeToggleButton(3); } }); tgKcal.setOnClickListener( new OnClickListener() { public void onClick(View v) { changeToggleButton(4); } }); btNext.setOnClickListener( new OnClickListener() { public void onClick(View v) { // call finish on click button next so we go back to showStart finish(); } }); }
private void setupToggleButton() { toggleButton = (ToggleButton) findViewById(R.id.toggleButton); toggleButton.setChecked(true); toggleButton.setTextOn(TEXT_ON); toggleButton.setTextOff(TEXT_OFF); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_card_add_user_hobby); Intent intent = getIntent(); String hobby = intent.getStringExtra(CardEditActivity.EDIT_HOBBY_STR); String[] hobbys = hobby.split(";|£º| "); Map<String, Boolean> hobbymap = new HashMap<String, Boolean>(); for (String item : hobbys) { hobbymap.put(item, false); } LayoutInflater inflater = LayoutInflater.from(CardAddUserHobbyActivity.this); TableLayout tl = (TableLayout) findViewById(R.id.tableLayout); this.width = DeviceInfoUtil.getDeviceCsw(getApplicationContext()); this.times = DeviceInfoUtil.getDeviceCsd(getApplicationContext()); padding = (int) (padding * times); baseMargin = (int) (baseMargin * times); int restWidth = width - 2 * padding - 3 * baseMargin; int widthOne = restWidth / 4; baseMargin = (int) ((restWidth - widthOne * 4) / 3) + baseMargin; tl.setPadding(padding, 0, padding, 0); String[] items = getResources().getStringArray(R.array.array_hobby); TableRow tr = null; for (int i = 0; i < items.length; i++) { if (i % 4 == 0) { tr = new TableRow(CardAddUserHobbyActivity.this); tl.addView(tr); } ToggleButton tb = (ToggleButton) inflater.inflate(R.layout.item_toggle, null); tb.setText(items[i]); tb.setTextOn(items[i]); tb.setTextOff(items[i]); tb.setOnCheckedChangeListener( new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { buttonView.setTextColor(Color.rgb(0, 72, 255)); selected.put(buttonView.getText().toString(), true); } else { buttonView.setTextColor(Color.rgb(52, 52, 52)); selected.put(buttonView.getText().toString(), false); } } }); tr.addView(tb); TableRow.LayoutParams trlp = new TableRow.LayoutParams(widthOne, TableRow.LayoutParams.WRAP_CONTENT); trlp.rightMargin = baseMargin; trlp.bottomMargin = baseMargin * 3 / 8; trlp.topMargin = baseMargin * 3 / 8; tb.setLayoutParams(trlp); if (hobbymap.containsKey(items[i])) { tb.setChecked(true); hobbymap.put(items[i], true); selected.put(items[i], true); } else { selected.put(items[i], false); } } String hobbyStr = ""; for (String item : hobbymap.keySet()) { if (!hobbymap.get(item)) { hobbyStr += item + " "; } } ((EditText) findViewById(R.id.editText)).setText(hobbyStr); initClick(); }
/** * Set the text that is displayed when the toggler is toggled off. * * @param text */ public void TextOff(String text) { view.setTextOff(text); }