List of usage examples for android.widget TextView setTextDirection
public void setTextDirection(int textDirection)
From source file:com.outsystemscloud.andrevieira.secureDevice.java
@SuppressLint("NewApi") private void changeTextDirection(Builder dlg) { int currentapiVersion = android.os.Build.VERSION.SDK_INT; dlg.create();//from w w w.j a v a 2 s . c o m AlertDialog dialog = dlg.show(); if (currentapiVersion >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) { TextView messageview = (TextView) dialog.findViewById(android.R.id.message); messageview.setTextDirection(android.view.View.TEXT_DIRECTION_LOCALE); } }
From source file:jp.watnow.plugins.dialog.Notification.java
@SuppressLint("NewApi") private void changeTextDirection(Builder dlg) { int currentapiVersion = android.os.Build.VERSION.SDK_INT; dlg.create();/*from w ww . j ava2s . co m*/ AlertDialog dialog = dlg.show(); if (currentapiVersion >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) { TextView messageview = (TextView) dialog.findViewById(android.R.id.message); if (messageview != null) messageview.setTextDirection(android.view.View.TEXT_DIRECTION_LOCALE); } }
From source file:com.markupartist.sthlmtraveling.ui.view.TripView.java
public void updateViews() { this.setOrientation(VERTICAL); float scale = getResources().getDisplayMetrics().density; this.setPadding(getResources().getDimensionPixelSize(R.dimen.list_horizontal_padding), getResources().getDimensionPixelSize(R.dimen.list_vertical_padding), getResources().getDimensionPixelSize(R.dimen.list_horizontal_padding), getResources().getDimensionPixelSize(R.dimen.list_vertical_padding)); LinearLayout timeStartEndLayout = new LinearLayout(getContext()); TextView timeStartEndText = new TextView(getContext()); timeStartEndText.setText(DateTimeUtil.routeToTimeDisplay(getContext(), trip)); timeStartEndText.setTextColor(ContextCompat.getColor(getContext(), R.color.body_text_1)); timeStartEndText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16); ViewCompat.setPaddingRelative(timeStartEndText, 0, 0, 0, (int) (2 * scale)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { if (RtlUtils.isRtl(Locale.getDefault())) { timeStartEndText.setTextDirection(View.TEXT_DIRECTION_RTL); }/*from www . j ava2s .c o m*/ } // Check if we have Realtime for start and or end. boolean hasRealtime = false; Pair<Date, RealTimeState> transitTime = trip.departsAt(true); if (transitTime.second != RealTimeState.NOT_SET) { hasRealtime = true; } else { transitTime = trip.arrivesAt(true); if (transitTime.second != RealTimeState.NOT_SET) { hasRealtime = true; } } // if (hasRealtime) { // ImageView liveDrawable = new ImageView(getContext()); // liveDrawable.setImageResource(R.drawable.ic_live); // ViewCompat.setPaddingRelative(liveDrawable, 0, (int) (2 * scale), (int) (4 * scale), 0); // timeStartEndLayout.addView(liveDrawable); // // AlphaAnimation animation1 = new AlphaAnimation(0.4f, 1.0f); // animation1.setDuration(600); // animation1.setRepeatMode(Animation.REVERSE); // animation1.setRepeatCount(Animation.INFINITE); // // liveDrawable.startAnimation(animation1); // } timeStartEndLayout.addView(timeStartEndText); LinearLayout startAndEndPointLayout = new LinearLayout(getContext()); TextView startAndEndPoint = new TextView(getContext()); BidiFormatter bidiFormatter = BidiFormatter.getInstance(RtlUtils.isRtl(Locale.getDefault())); startAndEndPoint.setText(String.format("%s %s", bidiFormatter.unicodeWrap(trip.fromStop().getName()), bidiFormatter.unicodeWrap(trip.toStop().getName()))); startAndEndPoint.setTextColor(getResources().getColor(R.color.body_text_1)); // Dark gray startAndEndPoint.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { if (RtlUtils.isRtl(Locale.getDefault())) { startAndEndPoint.setTextDirection(View.TEXT_DIRECTION_RTL); } } ViewCompat.setPaddingRelative(startAndEndPoint, 0, (int) (4 * scale), 0, (int) (4 * scale)); startAndEndPointLayout.addView(startAndEndPoint); RelativeLayout timeLayout = new RelativeLayout(getContext()); LinearLayout routeChanges = new LinearLayout(getContext()); routeChanges.setGravity(Gravity.CENTER_VERTICAL); LinearLayout.LayoutParams changesLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); changesLayoutParams.gravity = Gravity.CENTER_VERTICAL; if (trip.hasAlertsOrNotes()) { ImageView warning = new ImageView(getContext()); warning.setImageResource(R.drawable.ic_trip_deviation); ViewCompat.setPaddingRelative(warning, 0, (int) (2 * scale), (int) (4 * scale), 0); routeChanges.addView(warning); } int currentTransportCount = 1; int transportCount = trip.getLegs().size(); for (Leg leg : trip.getLegs()) { if (!leg.isTransit() && transportCount > 3) { if (leg.getDistance() < 150) { continue; } } if (currentTransportCount > 1 && transportCount >= currentTransportCount) { ImageView separator = new ImageView(getContext()); separator.setImageResource(R.drawable.transport_separator); ViewCompat.setPaddingRelative(separator, 0, 0, (int) (2 * scale), 0); separator.setLayoutParams(changesLayoutParams); routeChanges.addView(separator); if (RtlUtils.isRtl(Locale.getDefault())) { ViewCompat.setScaleX(separator, -1f); } } ImageView changeImageView = new ImageView(getContext()); Drawable transportDrawable = LegUtil.getTransportDrawable(getContext(), leg); changeImageView.setImageDrawable(transportDrawable); if (RtlUtils.isRtl(Locale.getDefault())) { ViewCompat.setScaleX(changeImageView, -1f); } ViewCompat.setPaddingRelative(changeImageView, 0, 0, 0, 0); changeImageView.setLayoutParams(changesLayoutParams); routeChanges.addView(changeImageView); if (currentTransportCount <= 3) { String lineName = leg.getRouteShortName(); if (!TextUtils.isEmpty(lineName)) { TextView lineNumberView = new TextView(getContext()); lineNumberView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 13); RoundedBackgroundSpan roundedBackgroundSpan = new RoundedBackgroundSpan( LegUtil.getColor(getContext(), leg), Color.WHITE, ViewHelper.dipsToPix(getContext().getResources(), 4)); SpannableStringBuilder sb = new SpannableStringBuilder(); sb.append(lineName); sb.append(' '); sb.setSpan(roundedBackgroundSpan, 0, lineName.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); lineNumberView.setText(sb); ViewCompat.setPaddingRelative(lineNumberView, (int) (5 * scale), (int) (1 * scale), (int) (2 * scale), 0); lineNumberView.setLayoutParams(changesLayoutParams); routeChanges.addView(lineNumberView); } } currentTransportCount++; } TextView durationText = new TextView(getContext()); durationText.setText(DateTimeUtil.formatDetailedDuration(getResources(), trip.getDuration() * 1000)); durationText.setTextColor(ContextCompat.getColor(getContext(), R.color.body_text_1)); durationText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16); durationText.setTypeface(Typeface.DEFAULT_BOLD); timeLayout.addView(routeChanges); timeLayout.addView(durationText); RelativeLayout.LayoutParams durationTextParams = (RelativeLayout.LayoutParams) durationText .getLayoutParams(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { durationTextParams.addRule(RelativeLayout.ALIGN_PARENT_END); } else { durationTextParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); } durationText.setLayoutParams(durationTextParams); View divider = new View(getContext()); ViewGroup.LayoutParams dividerParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1); divider.setLayoutParams(dividerParams); this.addView(timeLayout); RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) routeChanges.getLayoutParams(); params.height = LayoutParams.MATCH_PARENT; params.addRule(RelativeLayout.CENTER_VERTICAL); routeChanges.setLayoutParams(params); this.addView(startAndEndPointLayout); this.addView(timeStartEndLayout); if (mShowDivider) { this.addView(divider); } }