List of usage examples for android.view View TEXT_ALIGNMENT_GRAVITY
int TEXT_ALIGNMENT_GRAVITY
To view the source code for android.view View TEXT_ALIGNMENT_GRAVITY.
Click Source Link
From source file:com.facebook.litho.widget.TextSpec.java
private static void resolveStyleAttrsForTypedArray(TypedArray a, Output<TruncateAt> ellipsize, Output<Boolean> shouldIncludeFontPadding, Output<Float> spacingMultiplier, Output<Integer> minLines, Output<Integer> maxLines, Output<Integer> minEms, Output<Integer> maxEms, Output<Integer> minWidth, Output<Integer> maxWidth, Output<Boolean> isSingleLine, Output<CharSequence> text, Output<ColorStateList> textColorStateList, Output<Integer> linkColor, Output<Integer> highlightColor, Output<Integer> textSize, Output<Alignment> textAlignment, Output<Integer> textStyle, Output<Float> shadowRadius, Output<Float> shadowDx, Output<Float> shadowDy, Output<Integer> shadowColor, Output<VerticalGravity> verticalGravity) { int viewTextAlignment = View.TEXT_ALIGNMENT_GRAVITY; int gravity = Gravity.NO_GRAVITY; for (int i = 0, size = a.getIndexCount(); i < size; i++) { final int attr = a.getIndex(i); if (attr == R.styleable.Text_android_text) { text.set(a.getString(attr)); } else if (attr == R.styleable.Text_android_textColor) { textColorStateList.set(a.getColorStateList(attr)); } else if (attr == R.styleable.Text_android_textSize) { textSize.set(a.getDimensionPixelSize(attr, 0)); } else if (attr == R.styleable.Text_android_ellipsize) { final int index = a.getInteger(attr, 0); if (index > 0) { ellipsize.set(TRUNCATE_AT[index - 1]); }/* w ww . ja va 2 s . com*/ } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && attr == R.styleable.Text_android_textAlignment) { viewTextAlignment = a.getInt(attr, -1); textAlignment.set(getAlignment(viewTextAlignment, gravity)); } else if (attr == R.styleable.Text_android_gravity) { gravity = a.getInt(attr, -1); textAlignment.set(getAlignment(viewTextAlignment, gravity)); verticalGravity.set(getVerticalGravity(gravity)); } else if (attr == R.styleable.Text_android_includeFontPadding) { shouldIncludeFontPadding.set(a.getBoolean(attr, false)); } else if (attr == R.styleable.Text_android_minLines) { minLines.set(a.getInteger(attr, -1)); } else if (attr == R.styleable.Text_android_maxLines) { maxLines.set(a.getInteger(attr, -1)); } else if (attr == R.styleable.Text_android_singleLine) { isSingleLine.set(a.getBoolean(attr, false)); } else if (attr == R.styleable.Text_android_textColorLink) { linkColor.set(a.getColor(attr, 0)); } else if (attr == R.styleable.Text_android_textColorHighlight) { highlightColor.set(a.getColor(attr, 0)); } else if (attr == R.styleable.Text_android_textStyle) { textStyle.set(a.getInteger(attr, 0)); } else if (attr == R.styleable.Text_android_lineSpacingMultiplier) { spacingMultiplier.set(a.getFloat(attr, 0)); } else if (attr == R.styleable.Text_android_shadowDx) { shadowDx.set(a.getFloat(attr, 0)); } else if (attr == R.styleable.Text_android_shadowDy) { shadowDy.set(a.getFloat(attr, 0)); } else if (attr == R.styleable.Text_android_shadowRadius) { shadowRadius.set(a.getFloat(attr, 0)); } else if (attr == R.styleable.Text_android_shadowColor) { shadowColor.set(a.getColor(attr, 0)); } else if (attr == R.styleable.Text_android_minEms) { minEms.set(a.getInteger(attr, DEFAULT_EMS)); } else if (attr == R.styleable.Text_android_maxEms) { maxEms.set(a.getInteger(attr, DEFAULT_EMS)); } else if (attr == R.styleable.Text_android_minWidth) { minWidth.set(a.getDimensionPixelSize(attr, DEFAULT_MIN_WIDTH)); } else if (attr == R.styleable.Text_android_maxWidth) { maxWidth.set(a.getDimensionPixelSize(attr, DEFAULT_MAX_WIDTH)); } } }
From source file:com.facebook.litho.widget.TextSpec.java
private static Alignment getAlignment(int viewTextAlignment, int gravity) { final Alignment alignment; switch (viewTextAlignment) { case View.TEXT_ALIGNMENT_GRAVITY: alignment = getAlignment(gravity); break;/*from w w w.j a v a2 s .com*/ case View.TEXT_ALIGNMENT_TEXT_START: alignment = ALIGN_NORMAL; break; case View.TEXT_ALIGNMENT_TEXT_END: alignment = ALIGN_OPPOSITE; break; case View.TEXT_ALIGNMENT_CENTER: alignment = ALIGN_CENTER; break; case View.TEXT_ALIGNMENT_VIEW_START: // unsupported, default to normal alignment = ALIGN_NORMAL; break; case View.TEXT_ALIGNMENT_VIEW_END: // unsupported, default to opposite alignment = ALIGN_OPPOSITE; break; case View.TEXT_ALIGNMENT_INHERIT: // unsupported, default to gravity alignment = getAlignment(gravity); break; default: alignment = textAlignment; break; } return alignment; }
From source file:plugin.google.maps.GoogleMaps.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) @Override/*from w ww .j a v a2s. c o m*/ public View getInfoContents(Marker marker) { String title = marker.getTitle(); String snippet = marker.getSnippet(); if ((title == null) && (snippet == null)) { return null; } JSONObject properties = null; JSONObject styles = null; String propertyId = "marker_property_" + marker.getId(); PluginEntry pluginEntry = this.plugins.get("Marker"); PluginMarker pluginMarker = (PluginMarker) pluginEntry.plugin; if (pluginMarker.objects.containsKey(propertyId)) { properties = (JSONObject) pluginMarker.objects.get(propertyId); if (properties.has("styles")) { try { styles = (JSONObject) properties.getJSONObject("styles"); } catch (JSONException e) { } } } // Linear layout LinearLayout windowLayer = new LinearLayout(activity); windowLayer.setPadding(3, 3, 3, 3); windowLayer.setOrientation(LinearLayout.VERTICAL); LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); layoutParams.gravity = Gravity.BOTTOM | Gravity.CENTER; windowLayer.setLayoutParams(layoutParams); //---------------------------------------- // text-align = left | center | right //---------------------------------------- int gravity = Gravity.LEFT; int textAlignment = View.TEXT_ALIGNMENT_GRAVITY; if (styles != null) { try { String textAlignValue = styles.getString("text-align"); switch (TEXT_STYLE_ALIGNMENTS.valueOf(textAlignValue)) { case left: gravity = Gravity.LEFT; textAlignment = View.TEXT_ALIGNMENT_GRAVITY; break; case center: gravity = Gravity.CENTER; textAlignment = View.TEXT_ALIGNMENT_CENTER; break; case right: gravity = Gravity.RIGHT; textAlignment = View.TEXT_ALIGNMENT_VIEW_END; break; } } catch (Exception e) { } } if (title != null) { if (title.indexOf("data:image/") > -1 && title.indexOf(";base64,") > -1) { String[] tmp = title.split(","); Bitmap image = PluginUtil.getBitmapFromBase64encodedImage(tmp[1]); image = PluginUtil.scaleBitmapForDevice(image); ImageView imageView = new ImageView(this.cordova.getActivity()); imageView.setImageBitmap(image); windowLayer.addView(imageView); } else { TextView textView = new TextView(this.cordova.getActivity()); textView.setText(title); textView.setSingleLine(false); int titleColor = Color.BLACK; if (styles != null && styles.has("color")) { try { titleColor = PluginUtil.parsePluginColor(styles.getJSONArray("color")); } catch (JSONException e) { } } textView.setTextColor(titleColor); textView.setGravity(gravity); if (VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { textView.setTextAlignment(textAlignment); } //---------------------------------------- // font-style = normal | italic // font-weight = normal | bold //---------------------------------------- int fontStyle = Typeface.NORMAL; if (styles != null) { try { if ("italic".equals(styles.getString("font-style"))) { fontStyle = Typeface.ITALIC; } } catch (JSONException e) { } try { if ("bold".equals(styles.getString("font-weight"))) { fontStyle = fontStyle | Typeface.BOLD; } } catch (JSONException e) { } } textView.setTypeface(Typeface.DEFAULT, fontStyle); windowLayer.addView(textView); } } if (snippet != null) { //snippet = snippet.replaceAll("\n", ""); TextView textView2 = new TextView(this.cordova.getActivity()); textView2.setText(snippet); textView2.setTextColor(Color.GRAY); textView2.setTextSize((textView2.getTextSize() / 6 * 5) / density); textView2.setGravity(gravity); if (VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { textView2.setTextAlignment(textAlignment); } windowLayer.addView(textView2); } return windowLayer; }