List of usage examples for android.widget TextView TextView
public TextView(Context context)
From source file:com.android.contacts.common.list.ContactListItemView.java
/** * Returns the text view for the contact name, creating it if necessary. *///from w w w. j a v a2 s . co m public TextView getNameTextView() { if (mNameTextView == null) { mNameTextView = new TextView(getContext()); mNameTextView.setSingleLine(true); mNameTextView.setEllipsize(getTextEllipsis()); mNameTextView.setTextColor(mNameTextViewTextColor); mNameTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mNameTextViewTextSize); // Manually call setActivated() since this view may be added after the first // setActivated() call toward this whole item view. mNameTextView.setActivated(isActivated()); mNameTextView.setGravity(Gravity.CENTER_VERTICAL); mNameTextView.setTextAlignment(View.TEXT_ALIGNMENT_VIEW_START); mNameTextView.setId(R.id.cliv_name_textview); if (CompatUtils.isLollipopCompatible()) { mNameTextView.setElegantTextHeight(false); } addView(mNameTextView); } return mNameTextView; }
From source file:com.asksven.betterbatterystats.StatsActivity.java
public Dialog getShareDialog() { final ArrayList<Integer> selectedSaveActions = new ArrayList<Integer>(); AlertDialog.Builder builder = new AlertDialog.Builder(this); SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this); boolean saveDumpfile = sharedPrefs.getBoolean("save_dumpfile", true); boolean saveLogcat = sharedPrefs.getBoolean("save_logcat", false); boolean saveDmesg = sharedPrefs.getBoolean("save_dmesg", false); if (saveDumpfile) { selectedSaveActions.add(0);//from w w w. jav a2 s.c o m } if (saveLogcat) { selectedSaveActions.add(1); } if (saveDmesg) { selectedSaveActions.add(2); } //---- LinearLayout layout = new LinearLayout(this); LinearLayout.LayoutParams parms = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); layout.setOrientation(LinearLayout.VERTICAL); layout.setLayoutParams(parms); layout.setGravity(Gravity.CLIP_VERTICAL); layout.setPadding(2, 2, 2, 2); final TextView editTitle = new TextView(StatsActivity.this); editTitle.setText(R.string.share_dialog_edit_title); editTitle.setPadding(40, 40, 40, 40); editTitle.setGravity(Gravity.LEFT); editTitle.setTextSize(20); final EditText editDescription = new EditText(StatsActivity.this); LinearLayout.LayoutParams tv1Params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); tv1Params.bottomMargin = 5; layout.addView(editTitle, tv1Params); layout.addView(editDescription, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); //---- // Set the dialog title builder.setTitle(R.string.title_share_dialog) .setMultiChoiceItems(R.array.saveAsLabels, new boolean[] { saveDumpfile, saveLogcat, saveDmesg }, new DialogInterface.OnMultiChoiceClickListener() { @Override public void onClick(DialogInterface dialog, int which, boolean isChecked) { if (isChecked) { // If the user checked the item, add it to the // selected items selectedSaveActions.add(which); } else if (selectedSaveActions.contains(which)) { // Else, if the item is already in the array, // remove it selectedSaveActions.remove(Integer.valueOf(which)); } } }) .setView(layout) // Set the action buttons .setPositiveButton(R.string.label_button_share, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { ArrayList<Uri> attachements = new ArrayList<Uri>(); Reference myReferenceFrom = ReferenceStore.getReferenceByName(m_refFromName, StatsActivity.this); Reference myReferenceTo = ReferenceStore.getReferenceByName(m_refToName, StatsActivity.this); Reading reading = new Reading(StatsActivity.this, myReferenceFrom, myReferenceTo); // save as text is selected if (selectedSaveActions.contains(0)) { attachements.add(reading.writeDumpfile(StatsActivity.this, editDescription.getText().toString())); } // save logcat if selected if (selectedSaveActions.contains(1)) { attachements.add(StatsProvider.getInstance().writeLogcatToFile()); } // save dmesg if selected if (selectedSaveActions.contains(2)) { attachements.add(StatsProvider.getInstance().writeDmesgToFile()); } if (!attachements.isEmpty()) { Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE); shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, attachements); shareIntent.setType("text/*"); startActivity(Intent.createChooser(shareIntent, "Share info to..")); } } }).setNeutralButton(R.string.label_button_save, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { try { Reference myReferenceFrom = ReferenceStore.getReferenceByName(m_refFromName, StatsActivity.this); Reference myReferenceTo = ReferenceStore.getReferenceByName(m_refToName, StatsActivity.this); Reading reading = new Reading(StatsActivity.this, myReferenceFrom, myReferenceTo); // save as text is selected if (selectedSaveActions.contains(0)) { reading.writeDumpfile(StatsActivity.this, editDescription.getText().toString()); } // save logcat if selected if (selectedSaveActions.contains(1)) { StatsProvider.getInstance().writeLogcatToFile(); } // save dmesg if selected if (selectedSaveActions.contains(2)) { StatsProvider.getInstance().writeDmesgToFile(); } Snackbar.make(findViewById(android.R.id.content), getString(R.string.info_files_written) + ": " + StatsProvider.getWritableFilePath(), Snackbar.LENGTH_LONG).show(); } catch (Exception e) { Log.e(TAG, "an error occured writing files: " + e.getMessage()); Snackbar.make(findViewById(android.R.id.content), R.string.info_files_write_error, Snackbar.LENGTH_LONG).show(); } } }).setNegativeButton(R.string.label_button_cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { // do nothing } }); return builder.create(); }
From source file:com.android.contacts.common.list.ContactListItemView.java
/** * Returns the text view for the phonetic name, creating it if necessary. *///w ww. jav a2 s . co m public TextView getPhoneticNameTextView() { if (mPhoneticNameTextView == null) { mPhoneticNameTextView = new TextView(getContext()); mPhoneticNameTextView.setSingleLine(true); mPhoneticNameTextView.setEllipsize(getTextEllipsis()); mPhoneticNameTextView.setTextAppearance(getContext(), android.R.style.TextAppearance_Small); mPhoneticNameTextView.setTextAlignment(View.TEXT_ALIGNMENT_VIEW_START); mPhoneticNameTextView.setTypeface(mPhoneticNameTextView.getTypeface(), Typeface.BOLD); mPhoneticNameTextView.setActivated(isActivated()); mPhoneticNameTextView.setId(R.id.cliv_phoneticname_textview); addView(mPhoneticNameTextView); } return mPhoneticNameTextView; }
From source file:com.arlib.floatingsearchview.FloatingSearchView.java
private int getSuggestionItemHeight(SearchSuggestion suggestion) { int leftRightMarginsWidth = Util.dpToPx(124); //todo improve efficiency TextView textView = new TextView(getContext()); textView.setTypeface(Typeface.DEFAULT); textView.setText(suggestion.getBody(), TextView.BufferType.SPANNABLE); textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mSuggestionsTextSizePx); int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(mSuggestionsList.getWidth() - leftRightMarginsWidth, View.MeasureSpec.AT_MOST); int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); textView.measure(widthMeasureSpec, heightMeasureSpec); int heightPlusPadding = textView.getMeasuredHeight() + Util.dpToPx(8); int minHeight = Util.dpToPx(48); int height = heightPlusPadding >= minHeight ? heightPlusPadding : minHeight; return heightPlusPadding >= minHeight ? heightPlusPadding : minHeight; }
From source file:com.andreadec.musicplayer.MainActivity.java
private void showItemInfo(PlayableItem item) { if (item == null || item.getInformation() == null) return;//from w w w. j av a 2 s. co m ArrayList<Information> information = item.getInformation(); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.songInfo); View view = getLayoutInflater().inflate(R.layout.layout_songinfo, null, false); LinearLayout linearLayout = (LinearLayout) view.findViewById(R.id.linearLayoutInformation); Bitmap image = item.getImage(); if (image != null) { ImageView imageView = new ImageView(this); imageView.setImageBitmap(image); linearLayout.addView(imageView); } for (Information info : information) { TextView info1 = new TextView(this); info1.setTextAppearance(this, android.R.style.TextAppearance_Medium); info1.setText(getResources().getString(info.key)); TextView info2 = new TextView(this); info2.setText(info.value); info2.setPadding(0, 0, 0, 10); linearLayout.addView(info1); linearLayout.addView(info2); } builder.setView(view); builder.setPositiveButton(R.string.ok, null); builder.show(); }
From source file:com.android.contacts.common.list.ContactListItemView.java
/** * Returns the text view for the data label, creating it if necessary. *//* www . jav a 2 s .co m*/ public TextView getLabelView() { if (mLabelView == null) { mLabelView = new TextView(getContext()); mLabelView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); mLabelView.setSingleLine(true); mLabelView.setEllipsize(getTextEllipsis()); mLabelView.setTextAppearance(getContext(), R.style.TextAppearanceSmall); if (mPhotoPosition == PhotoPosition.LEFT) { mLabelView.setAllCaps(true); } else { mLabelView.setTypeface(mLabelView.getTypeface(), Typeface.BOLD); } mLabelView.setActivated(isActivated()); mLabelView.setId(R.id.cliv_label_textview); addView(mLabelView); } return mLabelView; }
From source file:com.nttec.everychan.ui.gallery.GalleryActivity.java
private void setAudio(final GalleryItemViewTag tag, final File file) { runOnUiThread(new Runnable() { @Override/* ww w .j av a 2 s. c o m*/ public void run() { setOnClickView(tag, getString(R.string.gallery_tap_to_play), new View.OnClickListener() { @Override public void onClick(View v) { if (!settings.useInternalAudioPlayer()) { openExternal(); } else { recycleTag(tag, false); final TextView durationView = new TextView(GalleryActivity.this); durationView.setGravity(Gravity.CENTER); tag.layout.setVisibility(View.VISIBLE); tag.layout.addView(durationView); tag.audioPlayer = new MediaPlayer(); tag.audioPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { @Override public void onPrepared(final MediaPlayer mp) { mp.setLooping(true); durationView.setText( getSpannedText("00:00 / " + formatMediaPlayerTime(mp.getDuration()))); tag.timer = new Timer(); tag.timer.schedule(new TimerTask() { @Override public void run() { runOnUiThread(new Runnable() { @Override public void run() { try { durationView.setText(getSpannedText( formatMediaPlayerTime(mp.getCurrentPosition()) + " / " + formatMediaPlayerTime(mp.getDuration()))); } catch (Exception e) { Logger.e(TAG, e); tag.timer.cancel(); } } }); } }, 1000, 1000); mp.start(); } }); tag.audioPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() { @Override public boolean onError(MediaPlayer mp, int what, int extra) { Logger.e(TAG, "(Audio) Error code: " + what); if (tag.timer != null) tag.timer.cancel(); showError(tag, getString(R.string.gallery_error_play)); return true; } }); try { tag.audioPlayer.setDataSource(file.getAbsolutePath()); tag.audioPlayer.prepareAsync(); } catch (Exception e) { Logger.e(TAG, "audio player error", e); if (tag.timer != null) tag.timer.cancel(); showError(tag, getString(R.string.gallery_error_play)); } } } }); } }); }
From source file:com.android.contacts.list.ContactListItemView.java
/** * Returns the text view for the contact name, creating it if necessary. *//* w w w .j ava2 s . c o m*/ public TextView getNameTextView() { if (mNameTextView == null) { mNameTextView = new TextView(getContext()); mNameTextView.setSingleLine(true); mNameTextView.setEllipsize(getTextEllipsis()); mNameTextView.setTextColor(ResourcesCompat.getColorStateList(getResources(), R.color.contact_list_name_text_color, getContext().getTheme())); mNameTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mNameTextViewTextSize); // Manually call setActivated() since this view may be added after the first // setActivated() call toward this whole item view. mNameTextView.setActivated(isActivated()); mNameTextView.setGravity(Gravity.CENTER_VERTICAL); mNameTextView.setTextAlignment(View.TEXT_ALIGNMENT_VIEW_START); mNameTextView.setId(R.id.cliv_name_textview); if (CompatUtils.isLollipopCompatible()) { mNameTextView.setElegantTextHeight(false); } addView(mNameTextView); } return mNameTextView; }
From source file:com.citrus.sample.WalletPaymentFragment.java
private void showUpdateSubscriptionPrompt(final boolean isUpdateToHigherValue) { final AlertDialog.Builder alert = new AlertDialog.Builder(getActivity()); // final String message = "Update Subscription to Lowe Amount"; String positiveButtonText = "Update Subscription "; LinearLayout linearLayout = new LinearLayout(getActivity()); linearLayout.setOrientation(LinearLayout.VERTICAL); final TextView labelsubscriptionID = new TextView(getActivity()); final EditText edtAmount = new EditText(getActivity()); final TextView labelAmount = new TextView(getActivity()); final EditText editLoadAmount = new EditText(getActivity()); final TextView labelMobileNo = new TextView(getActivity()); final EditText editThresholdAmount = new EditText(getActivity()); editLoadAmount.setSingleLine(true);//from w w w . j av a 2 s . c o m editThresholdAmount.setSingleLine(true); edtAmount.setSingleLine(true); edtAmount.setInputType(InputType.TYPE_NULL); labelsubscriptionID.setText("Load Money Amount"); labelAmount.setText("Current Auto Load Amount"); editLoadAmount.setText(String.valueOf(activeSubscription.getLoadAmount())); labelMobileNo.setText("Current Threshold Amount"); editThresholdAmount.setText(String.valueOf(activeSubscription.getThresholdAmount())); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); labelsubscriptionID.setLayoutParams(layoutParams); edtAmount.setLayoutParams(layoutParams); labelAmount.setLayoutParams(layoutParams); labelMobileNo.setLayoutParams(layoutParams); editLoadAmount.setLayoutParams(layoutParams); editThresholdAmount.setLayoutParams(layoutParams); linearLayout.addView(labelAmount); linearLayout.addView(editLoadAmount); linearLayout.addView(labelMobileNo); linearLayout.addView(editThresholdAmount); linearLayout.addView(labelsubscriptionID); linearLayout.addView(edtAmount); edtAmount.setText("1.00"); int paddingPx = Utils.getSizeInPx(getActivity(), 32); linearLayout.setPadding(paddingPx, paddingPx, paddingPx, paddingPx); editLoadAmount.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL); edtAmount.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL); editLoadAmount.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { /* if (!hasFocus) { if (Double.valueOf(editLoadAmount.getText().toString()) > activeSubscription.getLoadAmount()) { labelsubscriptionID.setVisibility(View.VISIBLE); edtAmount.setVisibility(View.VISIBLE); edtAmount.setText("1.00"); } else { labelsubscriptionID.setVisibility(View.INVISIBLE); edtAmount.setVisibility(View.INVISIBLE); } }*/ } }); editThresholdAmount.setInputType(InputType.TYPE_CLASS_NUMBER); alert.setTitle("Update Subscription "); alert.setMessage("Updating Load amount to higher will require Load Money transactions."); alert.setView(linearLayout); alert.setPositiveButton(positiveButtonText, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { final String trAmount = edtAmount.getText().toString(); final String loadAmount = editLoadAmount.getText().toString(); final String thresHoldAmount = editThresholdAmount.getText().toString(); // Hide the keyboard. InputMethodManager imm = (InputMethodManager) getActivity() .getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(edtAmount.getWindowToken(), 0); if (TextUtils.isEmpty(trAmount) && edtAmount.getVisibility() == View.VISIBLE) { Toast.makeText(getActivity(), " load amount cant be blank", Toast.LENGTH_SHORT).show(); return; } if (TextUtils.isEmpty(loadAmount)) { Toast.makeText(getActivity(), "Auto Load Amount cant be blank", Toast.LENGTH_SHORT).show(); return; } if (TextUtils.isEmpty(thresHoldAmount)) { Toast.makeText(getActivity(), "thresHoldAmount cant be blank", Toast.LENGTH_SHORT).show(); return; } if (Double.valueOf(thresHoldAmount) < new Double("500")) { Toast.makeText(getActivity(), "thresHoldAmount should not be less than 500", Toast.LENGTH_SHORT).show(); return; } if (Double.valueOf(loadAmount) < new Double(thresHoldAmount)) { Toast.makeText(getActivity(), "Load Amount should not be less than thresHoldAmount", Toast.LENGTH_SHORT).show(); return; } if (Double.valueOf(editLoadAmount.getText().toString()) > activeSubscription.getLoadAmount()) { //update to higher value mListener.onAutoLoadSelected(AUTO_LOAD_MONEY, new Amount(trAmount), editLoadAmount.getText().toString(), editThresholdAmount.getText().toString(), true); } else { //update to lower value mCitrusClient.updateSubScriptiontoLoweValue(new Amount(thresHoldAmount), new Amount(loadAmount), new Callback<SubscriptionResponse>() { @Override public void success(SubscriptionResponse subscriptionResponse) { Toast.makeText(getActivity(), subscriptionResponse.toString(), Toast.LENGTH_SHORT).show(); Logger.d("updateSubscription response **" + subscriptionResponse.toString()); activeSubscription = subscriptionResponse;//update the active subscription Object } @Override public void error(CitrusError error) { Toast.makeText(getActivity(), error.getMessage(), Toast.LENGTH_SHORT).show(); Logger.d("ERROR ***updateSubscription" + error.getMessage()); } }); } } }); alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }); editLoadAmount.requestFocus(); alert.show(); }