List of usage examples for android.widget ToggleButton setTextOn
public void setTextOn(CharSequence textOn)
From source file:com.todoroo.astrid.ui.ImportanceControlSet.java
@Override protected void afterInflate() { LinearLayout container = (LinearLayout) getView().findViewById(R.id.importance_container); int min = Task.IMPORTANCE_MOST; int max = Task.IMPORTANCE_LEAST; DisplayMetrics metrics = new DisplayMetrics(); activity.getWindowManager().getDefaultDisplay().getMetrics(metrics); for (int i = max; i >= min; i--) { final ToggleButton button = new ToggleButton(activity); LinearLayout.LayoutParams params; int dimension = 25; params = new LinearLayout.LayoutParams((int) (metrics.density * dimension), (int) (metrics.density * dimension)); button.setLayoutParams(params);/* w w w. j a v a 2 s . c o m*/ StringBuilder label = new StringBuilder(); if (i == max) { label.append('\u25CB'); } for (int j = Task.IMPORTANCE_LEAST - 1; j >= i; j--) { label.append('!'); } button.setTextColor(colors[i]); button.setTextOff(label); button.setTextOn(label); button.setPadding(0, 1, 0, 0); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { setImportance((Integer) button.getTag()); } }); button.setTag(i); button.setTextSize(TEXT_SIZE); buttons.add(button); View padding = new View(activity); LinearLayout.LayoutParams paddingParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, 0); paddingParams.weight = 1.0f; padding.setLayoutParams(paddingParams); container.addView(padding); container.addView(button); } }
From source file:com.murrayc.galaxyzoo.app.QuestionFragment.java
private void update() { final FragmentActivity activity = getActivity(); if (activity == null) return;/* w ww .j av a 2 s. c om*/ if (mRootView == null) { //This can happen when update() is called by the parent fragment //after this fragment has been instantiated after an orientation change, //but before onCreateView() has been called. It's not a problem //because onCreateView() will call this method again after setting mRootView. //Log.error("QuestionFragment.update(): mRootView is null."); return; } //Wipe the question details, //to ensure that we don't have old question details if somethng goes wrong when we //try to get and show the correct question details. final TextView textViewTitle = (TextView) mRootView.findViewById(R.id.textViewTitle); if (textViewTitle == null) { Log.error("update(): textViewTitle is null."); return; } textViewTitle.setText(""); //Show the text: final TextView textViewText = (TextView) mRootView.findViewById(R.id.textViewText); if (textViewText == null) { Log.error("update(): textViewText is null."); return; } textViewText.setText(""); final TableLayout layoutAnswers = (TableLayout) mRootView.findViewById(R.id.layoutAnswers); if (layoutAnswers == null) { Log.error("update(): layoutAnswers is null."); return; } layoutAnswers.removeAllViews(); if (getSingleton() == null) { //The parent fragment's onSingletonInitialized has been called //but this fragment's onSingletonInitialized hasn't been called yet. //That's OK. update() will be called, indirectly, later by this fragment's onSingletonInitialized(). return; } final DecisionTree.Question question = getQuestion(); if (question == null) { Log.error("update(): question is null."); return; } //Show the title: textViewTitle.setText(question.getTitle()); //Show the text: textViewText.setText(question.getText()); layoutAnswers.setShrinkAllColumns(true); layoutAnswers.setStretchAllColumns(true); //Checkboxes: mCheckboxButtons.clear(); final int COL_COUNT = 4; int col = 1; int rows = 0; TableRow row = null; final LayoutInflater inflater = LayoutInflater.from(activity); for (final DecisionTree.Checkbox checkbox : question.getCheckboxes()) { //Start a new row if necessary: if (row == null) { row = addRowToTable(activity, layoutAnswers); rows++; } final ToggleButton button = (ToggleButton) inflater.inflate(R.layout.question_answer_checkbox, null); //Use just the highlighting (line, color, etc) to show that it's selected, //instead of On/Off, so we don't need a separate label. //TODO: Use the icon. See http://stackoverflow.com/questions/18598255/android-create-a-toggle-button-with-image-and-no-text //TODO: Avoid the highlight bar thing at the bottom being drawn over the text. final String text = checkbox.getText(); button.setText(text); button.setTextOn(text); button.setTextOff(text); insertButtonInRow(activity, row, button); final BitmapDrawable icon = getIcon(activity, checkbox); button.setCompoundDrawables(null, icon, null, null); mCheckboxButtons.put(checkbox.getId(), button); if (col < COL_COUNT) { col++; } else { col = 1; row = null; } } //Answers: for (final DecisionTree.Answer answer : question.getAnswers()) { //Start a new row if necessary: if (row == null) { row = addRowToTable(activity, layoutAnswers); rows++; } final Button button = createAnswerButton(activity, answer); insertButtonInRow(activity, row, button); final String questionId = question.getId(); final String answerId = answer.getId(); button.setOnClickListener(new View.OnClickListener() { public void onClick(final View v) { // Perform action on click onAnswerButtonClicked(questionId, answerId); } }); if (col < COL_COUNT) { col++; } else { col = 1; row = null; } } //Add empty remaining cells, to avoid the other cells from expanding to fill the space, //because we want them to line up with the same cells above and below. if ((row != null) && (rows > 1)) { final int remaining_in_row = COL_COUNT - col + 1; for (int i = 0; i < remaining_in_row; i++) { //TODO: We could use Space instead of FrameLayout when using API>14. final FrameLayout placeholder = new FrameLayout(activity); insertButtonInRow(activity, row, placeholder); } } if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { /* This wastes even more space to be even more consistent: //Make sure there are always at least 2 rows, //so we request roughly the same amount of space each time: if (rows < 2) { row = addRowToTable(activity, layoutAnswers); final DecisionTree.Answer answer = new DecisionTree.Answer("bogus ID", "bogus title", getArbitraryIconId(), null, 0); final Button button = createAnswerButton(activity, answer); button.setVisibility(View.INVISIBLE); //It won't be seen, but it's size will be used. insertButtonInRow(activity, row, button); } */ //This will be used in a later onLayout(), //so we will know the correct height at least during the second classification, mRootView.setRowsCountForMaxHeightExperienced(rows); //Try to keep the height consistent, to avoid the user seeing everything moving about. final int min = mRootView.getMaximumHeightExperienced(rows); if (min > 0) { mRootView.setMinimumHeight(min); } } else { //Ignore any previously-set minimum height, //to stop the portrait-mode's layout from affecting the layout-mode's layout: mRootView.setMinimumHeight(0); } }
From source file:org.noise_planet.noisecapture.CommentActivity.java
private void addTag(String tagName, int id, ViewGroup column, int color) { ToggleButton tagButton = new ToggleButton(this); if (color != -1) { LinearLayout colorBox = new LinearLayout(this); // Convert the dps to pixels, based on density scale final int tagPaddingPx = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, getResources().getDisplayMetrics()); final int tagPaddingPxBottom = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 3, getResources().getDisplayMetrics()); //use a GradientDrawable with only one color set, to make it a solid color colorBox.setBackgroundResource(R.drawable.tag_round_corner); GradientDrawable gradientDrawable = (GradientDrawable) colorBox.getBackground(); gradientDrawable.setColor(color); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); params.setMargins(tagPaddingPx, tagPaddingPx, tagPaddingPx, tagPaddingPxBottom); colorBox.setLayoutParams(params); colorBox.addView(tagButton);//from www . jav a 2 s. c o m column.addView(colorBox); } else { column.addView(tagButton); } tagButton.setTextOff(tagName); tagButton.setTextOn(tagName); boolean isChecked = checkedTags.contains(id); tagButton.setChecked(isChecked); if (isChecked) { tagButton.setTextColor(selectedColor); } tagButton.setOnCheckedChangeListener(new TagStateListener(id, checkedTags)); tagButton.setMinHeight(0); tagButton.setMinimumHeight(0); tagButton.setTextSize(Dimension.SP, 12); tagButton.setEnabled(record == null || record.getUploadId().isEmpty()); tagButton.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); tagButton.invalidate(); }
From source file:ru.valle.btc.MainActivity.java
private void showQRCodePopupForPrivateKey(final String label, final String address, final String[] data, final String[] dataTypes) { DisplayMetrics dm = getResources().getDisplayMetrics(); final int screenSize = Math.min(dm.widthPixels, dm.heightPixels); new AsyncTask<Void, Void, Bitmap[]>() { @Override//from www . j a v a 2 s . c o m protected Bitmap[] doInBackground(Void... params) { Bitmap[] result = new Bitmap[data.length]; for (int i = 0; i < data.length; i++) { if (data[i] != null) { QRCode qr = QRCode.getMinimumQRCode(data[i], ErrorCorrectLevel.M); result[i] = qr.createImage(screenSize / 2); } } return result; } @Override protected void onPostExecute(final Bitmap[] bitmap) { if (bitmap != null) { View view = getLayoutInflater().inflate(R.layout.private_key_qr, mainLayout, false); if (view != null) { final ToggleButton toggle1 = (ToggleButton) view.findViewById(R.id.toggle_1); final ToggleButton toggle2 = (ToggleButton) view.findViewById(R.id.toggle_2); final ToggleButton toggle3 = (ToggleButton) view.findViewById(R.id.toggle_3); final ImageView qrView = (ImageView) view.findViewById(R.id.qr_code_image); final TextView dataView = (TextView) view.findViewById(R.id.qr_code_data); if (data[0] == null) { toggle1.setVisibility(View.GONE); } else { toggle1.setTextOff(dataTypes[0]); toggle1.setTextOn(dataTypes[0]); toggle1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { toggle2.setChecked(false); toggle3.setChecked(false); qrView.setImageBitmap(bitmap[0]); dataView.setText(data[0]); } else if (!toggle2.isChecked() && !toggle3.isChecked()) { buttonView.setChecked(true); } } }); } if (data[1] == null) { toggle2.setVisibility(View.GONE); } else { toggle2.setTextOff(dataTypes[1]); toggle2.setTextOn(dataTypes[1]); toggle2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { toggle1.setChecked(false); toggle3.setChecked(false); qrView.setImageBitmap(bitmap[1]); dataView.setText(data[1]); } else if (!toggle1.isChecked() && !toggle3.isChecked()) { buttonView.setChecked(true); } } }); } if (data[2] == null) { toggle3.setVisibility(View.GONE); } else { toggle3.setTextOff(dataTypes[2]); toggle3.setTextOn(dataTypes[2]); toggle3.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { toggle1.setChecked(false); toggle2.setChecked(false); qrView.setImageBitmap(bitmap[2]); dataView.setText(data[2]); } else if (!toggle1.isChecked() && !toggle2.isChecked()) { buttonView.setChecked(true); } } }); } if (data[2] != null) { toggle3.setChecked(true); } else if (data[0] != null) { toggle1.setChecked(true); } else { toggle2.setChecked(true); } AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); builder.setTitle(label); builder.setView(view); DialogInterface.OnClickListener shareClickListener = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { int selectedIndex; if (toggle1.isChecked()) { selectedIndex = 0; } else if (toggle2.isChecked()) { selectedIndex = 1; } else { selectedIndex = 2; } Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_SUBJECT, label); intent.putExtra(Intent.EXTRA_TEXT, data[selectedIndex]); startActivity( Intent.createChooser(intent, getString(R.string.share_chooser_title))); } }; if (systemSupportsPrint()) { builder.setPositiveButton(R.string.print, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { int selectedIndex; if (toggle1.isChecked()) { selectedIndex = 0; } else if (toggle2.isChecked()) { selectedIndex = 1; } else { selectedIndex = 2; } Renderer.printWallet(MainActivity.this, label, SCHEME_BITCOIN + address, data[selectedIndex]); } }); builder.setNeutralButton(R.string.share, shareClickListener); } else { builder.setPositiveButton(R.string.share, shareClickListener); } builder.setNegativeButton(android.R.string.cancel, null); builder.show(); } } } }.execute(); }