List of usage examples for android.widget TextView TextView
public TextView(Context context)
From source file:brostore.maquillage.custom.PagerSlidingTabStrip.java
private void addCustomTextTab(final int position, String title) { LinearLayout conteneur = new LinearLayout(getContext()); LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); conteneur.setOrientation(LinearLayout.HORIZONTAL); conteneur.setGravity(Gravity.CENTER); TextView tab = new TextView(getContext()); TextView tabCust = new TextView(getContext()); //tabCust.setBackgroundResource(R.drawable.live_nombre); tabCust.setGravity(Gravity.CENTER);/*from w w w . j a v a 2s .c o m*/ tabCust.setTextColor(Color.WHITE); tabCust.setTypeface(tabTypeface); tabCust.setTextSize(11); tabCust.setVisibility(View.GONE); int fiveDip = Utils.convertDpToPixel(5, getResources()); tabCust.setPadding(fiveDip, 0, fiveDip, 0); tabCust.setText("0"); tab.setText(title); tab.setGravity(Gravity.CENTER); tab.setSingleLine(); conteneur.addView(tab, param); param.leftMargin = Utils.convertDpToPixel(10, getResources()); conteneur.addView(tabCust, param); addTab(position, conteneur); }
From source file:com.abcvoipsip.ui.prefs.CodecsFragment.java
@Override @SuppressWarnings("unchecked") public boolean onContextItemSelected(MenuItem item) { AdapterView.AdapterContextMenuInfo info; try {//from w ww. j av a 2s . co m info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); } catch (ClassCastException e) { Log.e(THIS_FILE, "bad menuInfo", e); return false; } HashMap<String, Object> codec = null; codec = (HashMap<String, Object>) mAdapter.getItem(info.position); if (codec == null) { // If for some reason the requested item isn't available, do nothing return false; } int selId = item.getItemId(); if (selId == MENU_ITEM_ACTIVATE) { boolean isDisabled = ((Short) codec.get(CODEC_PRIORITY) == 0); final short newPrio = isDisabled ? (short) 1 : (short) 0; if (NON_FREE_CODECS.containsKey(codec.get(CODEC_ID)) && isDisabled) { final HashMap<String, Object> fCodec = codec; final TextView message = new TextView(getActivity()); final SpannableString s = new SpannableString( getString(R.string.this_codec_is_not_free) + NON_FREE_CODECS.get(codec.get(CODEC_ID))); Linkify.addLinks(s, Linkify.WEB_URLS); message.setText(s); message.setMovementMethod(LinkMovementMethod.getInstance()); message.setPadding(10, 10, 10, 10); //Alert user that we will disable for all incoming calls as he want to quit new AlertDialog.Builder(getActivity()).setTitle(R.string.warning).setView(message) .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { setCodecActivated(fCodec, newPrio); } }).setNegativeButton(R.string.cancel, null).show(); } else { setCodecActivated(codec, newPrio); } return true; } return false; }
From source file:com.hybris.mobile.lib.ui.view.Alert.java
/** * Show the alert//from w w w. j a v a 2 s .c om * * @param context application-specific resources * @param configuration describes all device configuration information * @param text message to be displayed * @param forceClearPreviousAlert true will clear previous alert else keep it */ @SuppressLint("NewApi") private static void showAlertOnScreen(final Activity context, final Configuration configuration, final String text, boolean forceClearPreviousAlert) { final ViewGroup mainView = ((ViewGroup) context.findViewById(android.R.id.content)); boolean currentlyDisplayed = false; int viewId = R.id.alert_view_top; final TextView textView; boolean alertAlreadyExists = false; if (configuration.getOrientation().equals(Configuration.Orientation.BOTTOM)) { viewId = R.id.alert_view_bottom; } // Retrieving the view RelativeLayout relativeLayout = (RelativeLayout) mainView.findViewById(viewId); if (forceClearPreviousAlert) { mainView.removeView(relativeLayout); relativeLayout = null; } // Creating the view if (relativeLayout == null) { // Main layout relativeLayout = new RelativeLayout(context); relativeLayout.setId(viewId); relativeLayout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, configuration.getHeight())); relativeLayout.setGravity(Gravity.CENTER); // Textview textView = new TextView(context); textView.setId(R.id.alert_view_text); textView.setGravity(Gravity.CENTER); textView.setLayoutParams( new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); relativeLayout.addView(textView); setIcon(context, configuration, relativeLayout, textView); if (configuration.getOrientation().equals(Configuration.Orientation.TOP)) { relativeLayout.setY(-configuration.getHeight()); } else { relativeLayout.setY(mainView.getHeight()); } // Adding the view to the global layout mainView.addView(relativeLayout, 0); relativeLayout.bringToFront(); relativeLayout.requestLayout(); relativeLayout.invalidate(); } // View already exists else { alertAlreadyExists = true; textView = (TextView) relativeLayout.findViewById(R.id.alert_view_text); if (configuration.getOrientation().equals(Configuration.Orientation.TOP)) { if (relativeLayout.getY() == 0) { currentlyDisplayed = true; } } else { if (relativeLayout.getY() < mainView.getHeight()) { currentlyDisplayed = true; } } // The view is currently shown to the user if (currentlyDisplayed) { // If the message is not the same, we hide the current message and display the new one if (!StringUtils.equals(text, textView.getText())) { // Anim out the current message ViewPropertyAnimator viewPropertyAnimator = animOut(configuration, mainView, relativeLayout); final RelativeLayout relativeLayoutFinal = relativeLayout; if (viewPropertyAnimator != null) { // Anim in the new message after the animation out has finished if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { viewPropertyAnimator.setListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { setIcon(context, configuration, relativeLayoutFinal, textView); animIn(configuration, relativeLayoutFinal, textView, mainView, text); } }); } else { viewPropertyAnimator.withEndAction(new Runnable() { @Override public void run() { setIcon(context, configuration, relativeLayoutFinal, textView); animIn(configuration, relativeLayoutFinal, textView, mainView, text); } }); } } else { setIcon(context, configuration, relativeLayoutFinal, textView); animIn(configuration, relativeLayoutFinal, textView, mainView, text); } } } } final RelativeLayout relativeLayoutFinal = relativeLayout; // Close the alert by clicking the layout if (configuration.isCloseable()) { relativeLayout.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { animOut(configuration, mainView, relativeLayoutFinal); v.performClick(); return true; } }); } if (!currentlyDisplayed) { // Set the icon in case the alert already exists but it's not currently displayed if (alertAlreadyExists) { setIcon(context, configuration, relativeLayoutFinal, textView); } // We anim in the alert animIn(configuration, relativeLayoutFinal, textView, mainView, text); } }
From source file:com.cloud.widget.viewpager.PagerSlidingTabStrip.java
/** * Modify by Cloud on 15/12/1./* w ww. j a va 2 s.c om*/ * TabViewViewGroup */ private void addTextTab(final int position, String title, float num, boolean hasIndicator, boolean hasNum, int tabNum) { relativeLayout = new RelativeLayout(getContext()); if (hasIndicator) { if (hasNum) { //title RelativeLayout.LayoutParams titleLp = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); titleText = new TextView(getContext()); titleText.setText(title); titleText.setGravity(Gravity.CENTER); titleText.setSingleLine(); titleText.setTypeface(tabTypeface, tabTypefaceStyle); titleText.setTextAppearance(getContext(), tabDefaultTextAppearance); titleLp.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE); titleText.setLayoutParams(titleLp); // RelativeLayout.LayoutParams indicatorLp = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); indicatorText = new TextView(getContext()); indicatorText.setHeight(px2dip(getContext(), 50)); indicatorText.setWidth(px2dip(getContext(), screenWidth)); indicatorText.setText("" + String.valueOf(num)); indicatorText.setGravity(Gravity.CENTER); indicatorText.setSingleLine(); indicatorLp.topMargin = 5; indicatorLp.bottomMargin = 5; indicatorLp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE); indicatorText.setLayoutParams(indicatorLp); relativeLayout.addView(indicatorText); relativeLayout.addView(titleText); } else { //title RelativeLayout.LayoutParams titleLp = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); titleText = new TextView(getContext()); titleText.setText(title); titleText.setGravity(Gravity.CENTER); titleText.setSingleLine(); titleText.setTypeface(tabTypeface, tabTypefaceStyle); titleText.setTextAppearance(getContext(), tabDefaultTextAppearance); titleText.setLayoutParams(titleLp); relativeLayout.addView(titleText); } } else { RelativeLayout.LayoutParams titleLp = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); titleText = new TextView(getContext()); titleText.setGravity(Gravity.CENTER); titleText.setSingleLine(); titleText.setTypeface(tabTypeface, tabTypefaceStyle); titleText.setTextAppearance(getContext(), tabDefaultTextAppearance); titleText.setLayoutParams(titleLp); relativeLayout.addView(titleText); if (num % 1 == 0) { titleText.setText(title + "(" + String.valueOf((int) num) + ")"); } else { titleText.setText(title + "(" + String.valueOf(num) + ")"); } } if (num != 0 && hasIndicator && !hasNum) { // RelativeLayout.LayoutParams indicatorLp = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); indicatorText = new TextView(getContext()); indicatorText.setHeight(px2dip(getContext(), 50)); indicatorText.setWidth(px2dip(getContext(), 50)); if (num % 1 == 0) { indicatorText.setText(String.valueOf((int) num)); } else { indicatorText.setText(String.valueOf(num)); } indicatorText.setGravity(Gravity.CENTER); indicatorText.setSingleLine(); indicatorText .setBackgroundDrawable(getContext().getResources().getDrawable(R.drawable.indicator_red_shape)); indicatorText.setTextAppearance(getContext(), indicatorNum); indicatorLp.topMargin = 10; if (tabNum == 4) { indicatorLp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE); } else { indicatorLp.leftMargin = screenWidth / 4 + screenWidth / 16; } indicatorLp.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE); indicatorText.setLayoutParams(indicatorLp); relativeLayout.addView(indicatorText); } addTab(position, relativeLayout); }
From source file:com.bitants.wally.fragments.MaterialDialogFragment.java
protected void setupViews(Context context) { if (titleResourceId != 0) { textViewTitle.setText(titleResourceId); } else if (titleString != null) { textViewTitle.setText(titleString); }//from w w w. j a v a2 s .com if (primaryColor != 0) { buttonPositive.setTextColor(primaryColor); } if (positiveButtonTextResourceId != 0) { buttonPositive.setText(positiveButtonTextResourceId); } if (negativeButtonTextResourceId != 0) { buttonNegative.setText(negativeButtonTextResourceId); } buttonNegative.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (negativeButtonOnClickListener != null) { negativeButtonOnClickListener.onClick(null, 1); } dismiss(); } }); buttonPositive.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (positiveButtonOnClickListener != null) { positiveButtonOnClickListener.onClick(null, 0); } dismiss(); } }); if (layoutResourceId != 0) { viewStub.setLayoutResource(layoutResourceId); viewStub.inflate(); } else if (message != null || messageResourceId != 0) { TextView textView = new TextView(context); if (messageResourceId != 0) { textView.setText(messageResourceId); } else { textView.setText(message); } textView.setTextColor(getResources().getColor(R.color.Black_Light)); textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16); textView.setLineSpacing(1f, 1.2f); scrollView.removeAllViews(); scrollView.addView(textView); } }
From source file:fr.cph.chicago.core.activity.BusActivity.java
/** * Draw arrivals in current main.java.fr.cph.chicago.res.layout *///from w w w . j a va 2 s . com public void drawArrivals() { final Map<String, TextView> tempMap = new HashMap<>(); if (busArrivals.size() != 0) { Stream.of(busArrivals).filter(arrival -> arrival.getRouteDirection().equals(bound) || arrival.getRouteDirection().equals(boundTitle)).forEach(arrival -> { final String destination = arrival.getBusDestination(); final String arrivalText; if (tempMap.containsKey(destination)) { final TextView arrivalView = tempMap.get(destination); arrivalText = arrival.isDly() ? arrivalView.getText() + " Delay" : arrivalView.getText() + " " + arrival.getTimeLeft(); arrivalView.setText(arrivalText); } else { final TextView arrivalView = new TextView(getApplicationContext()); arrivalText = arrival.isDly() ? arrival.getBusDestination() + " Delay" : arrival.getBusDestination() + " " + arrival.getTimeLeft(); arrivalView.setText(arrivalText); arrivalView.setTextColor(grey); tempMap.put(destination, arrivalView); } }); } else { final TextView arrivalView = new TextView(getApplicationContext()); arrivalView.setTextColor(grey); arrivalView.setText(busActivityNoService); tempMap.put("", arrivalView); } stopsView.removeAllViews(); Stream.of(tempMap.entrySet()).forEach(entry -> stopsView.addView(entry.getValue())); }
From source file:cn.hollo.www.custom_view.PagerSlidingTabStrip.java
private void addTextTab(final int position, String title) { TextView tab = new TextView(getContext()); tab.setText(title);//from ww w .ja v a2 s . com tab.setGravity(Gravity.CENTER); tab.setSingleLine(); if (tabTextColor != null) tab.setTextColor(tabTextColor); else tab.setTextColor(defaultTabTextColor); tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize); addTab(position, tab); }
From source file:org.openhab.habdroid.ui.OpenHABWidgetArrayAdapter.java
private TextView getValueTextView(RelativeLayout widgetView, OpenHABWidget openHABWidget) { // Get TextView for widget value and set it's color Integer valueColor = openHABWidget.getValueColor(); TextView valueTextView = (TextView) widgetView.findViewById(R.id.widgetvalue); if (valueColor != null && valueTextView != null) { Log.d(HABApplication.getLogTag(), String.format("Setting value color to %d", valueColor)); valueTextView.setTextColor(valueColor); } else if (valueTextView != null) { TextView defaultTextView = new TextView(widgetView.getContext()); valueTextView.setTextColor(defaultTextView.getTextColors().getDefaultColor()); }//from w w w.j a va 2s .c o m return valueTextView; }
From source file:ac.robinson.mediaphone.activity.NarrativeBrowserActivity.java
private void initialiseNarrativesView() { mScanningForNarratives = false;//from ww w . j a va 2 s . c o m mNarratives = (NarrativesListView) findViewById(R.id.list_narratives); // for API 11 and above, buttons are in the action bar if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { LayoutInflater layoutInflater = getLayoutInflater(); View headerRow = layoutInflater.inflate(R.layout.narratives_header, null, false); mNarratives.addHeaderView(headerRow, null, false); // false = not selectable View emptyView = layoutInflater.inflate(R.layout.narratives_empty, null, false); ((ViewGroup) mNarratives.getParent()).addView(emptyView); mNarratives.setEmptyView(emptyView); // must add separately as the header isn't shown when empty } else { // initial empty list placeholder - add manually as the < v11 version includes the header row TextView emptyView = new TextView(NarrativeBrowserActivity.this); emptyView.setGravity(Gravity.CENTER | Gravity.TOP); emptyView.setPadding(10, getResources().getDimensionPixelSize(R.dimen.narrative_list_empty_hint_top_padding), 10, 10); // temporary emptyView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); emptyView.setText(getString(R.string.narrative_list_empty)); ((ViewGroup) mNarratives.getParent()).addView(emptyView); mNarratives.setEmptyView(emptyView); } // originally used to fix selection highlights when using hardware button to select // now done by overriding isEnabled in NarrativeAdapter // mNarratives.setFocusable(false); // mNarratives.setFocusableInTouchMode(false); mNarrativeAdapter = new NarrativeAdapter(this, true, false); mNarratives.setAdapter(mNarrativeAdapter); getSupportLoaderManager().initLoader(R.id.loader_narratives_completed, null, this); mNarratives.setOnScrollListener(new ScrollManager()); mNarratives.setOnTouchListener(new FingerTracker()); mNarratives.setOnItemSelectedListener(new SelectionTracker()); mNarratives.setOnItemClickListener(new NarrativeViewer()); mPopupPosition = getLayoutInflater().inflate(R.layout.popup_position, null); mPopupText = (TextView) mPopupPosition.findViewById(R.id.popup_text); }
From source file:com.bt.download.android.gui.adapters.TransferListAdapter.java
@Override public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { Transfer item = getGroupItem(groupPosition); if (convertView == null || convertView instanceof TextView) { // convertView could be a dummy view due to an issue with the slide menu layout request order try {/*ww w . j ava 2s .c o m*/ convertView = View.inflate(context.get(), R.layout.view_transfer_list_item, null); } catch (Throwable e) { // creating a dummy view to avoid a force close due to a NPE // next time the "if" will try to recover the actual layout convertView = new TextView(context.get()); ((TextView) convertView).setText("Rendering error"); } } try { boolean clickable = item.getItems().size() == 0; convertView.setOnClickListener(clickable ? viewOnClickListener : null); convertView.setOnLongClickListener(clickable ? viewOnLongClickListener : null); convertView.setClickable(clickable); convertView.setLongClickable(clickable); setupGroupIndicator(convertView, isExpanded, item); convertView.setTag(item); populateGroupView(convertView, item); } catch (Throwable e) { Log.e(TAG, "Fatal error getting the group view: " + e.getMessage(), e); } return convertView; }