Upgrade to Pro — share decks privately, control downloads, hide ads and more …

TextViews and Localization

TextViews and Localization

Elliott Chenger

August 27, 2015
Tweet

More Decks by Elliott Chenger

Other Decks in Programming

Transcript

  1. Imaginary line which a line of text rests upon Baseline

    getBaseline(); getLineBounds(0, null); getLineBounds(1, null);
  2. Imaginary line which a line of text rests upon Baseline

    getBaseline(); getLineBounds(0, null); getLineBounds(
  3. Baseline getBaseline(); getLineBounds(0, null); public final int getLineBaseline(int line) {


    // getLineTop(line+1) == getLineTop(line)
 return getLineTop(line+1) - getLineDescent(line);
 }
  4. Imaginary line which a line of text rests upon Baseline

    getBaseline(); getLineBounds(0, null); getLineBounds(
  5. Imaginary line which a line of text rests upon Baseline

    getBaseline() getLineBounds( getLineBounds(1, null);
  6. The invisible line marking the farthest distance between the baseline

    and the top of the glyph. Ascent Line textView.getPaint().ascent()
  7. textView.getPaint().ascent() /**
 * Return the distance above (negative) the baseline

    (ascent) based on the
 * current typeface and text size.
 *
 * @return the distance above (negative) the baseline (ascent) based on the
 * current typeface and text size.
 */ Ascent Line
  8. /**
 * The maximum distance above the baseline for the

    tallest glyph in
 * the font at a given text size.
 */ textView.getPaint().getFontMetrics().top Ascent Line
  9. The invisible line marking the lowest point of the descenders

    within a font. Descender Line textView.getPaint().descent()
  10. The spacing between the baselines of each line of text

    Leading textView .setLineSpacing(add,mult); “Multiple people defending fragment API and behavior pretty hard around the internet lately. Enjoy your straw houses, little pigs.” “Multiple people defending fragment API and behavior pretty hard around the internet lately. Enjoy your straw houses, little pigs.”
  11. The spacing between the baselines of each line of text

    Leading textView .setLineSpacing(add,mult); Add: pixels added to each line height “Multiple people defending fragment API and behavior pretty hard around the internet lately. Enjoy your straw houses, little pigs.” “Multiple people defending fragment API and behavior pretty hard around the internet lately. Enjoy your straw houses, little pigs.”
  12. The spacing between the baselines of each line of text

    Leading textView .setLineSpacing(add,mult); Add: pixels added to each line height Mult: float to multiply each line height by. Initially 1.0 “Multiple people defending fragment API and behavior pretty hard around the internet lately. Enjoy your straw houses, little pigs.” “Multiple people defending fragment API and behavior pretty hard around the internet lately. Enjoy your straw houses, little pigs.”
  13. Localization The act of making a product meet language and

    cultural requirements for a locale*.
  14. Locale in Android Locale.class getDefault() Returns the users preferred locale

    getDisplayLanguage() Get language name for default Locale getDisplayCountry() Get country name for default Locale
  15. 1.Identify target languages and locales 2.Design for localization 3.Manage Strings

    for localization 4.Translate UI Strings and other resources 5.Test your localized app 6.Prepare for localized app 7.Support international users after launch Google Localization Checklist
  16. 1.Identify target languages and locales 2.Design for localization (and develop

    your layouts
 using proper localization standards) 3.Manage Strings for localization 4.Translate UI Strings and other resources 5.Test your localized app 6.Prepare for localized app 7.Support international users after launch Google Localization Checklist
  17. Google Localization Checklist 1.Identify target languages and locales 2.Design for

    localization (and develop your layouts
 using proper localization standards) 3.Manage Strings for localization 4.Translate UI Strings and other resources 5.Test your localized app 6.Prepare for localized app 7.Support international users after launch
  18. private void loadCustomFont(Context context, AttributeSet attrs) {
 TypedArray typedArray =


    context.obtainStyledAttributes(attrs, R.styleable.DebugTextView);
 String fontLocation = typedArray.getString(R.styleable.DebugTextView_font);
 Typeface customTypeFace = Typeface.createFromAsset(getContext().getAssets(), fontLocation);
 super.setTypeface(customTypeFace);
 } CustomTextView.java Cache in memory Fonts
  19. 1.Support RTL 2.Make font file a localized String 3.Mind font

    padding Elliott’s Development Localization Checklist
  20. 1.Support RTL 2.Make font file a localized String 3.Mind font

    padding 4.One layout to rule them all Elliott’s Development Localization Checklist
  21. “In cases where your UI can't accommodate text in one

    of your target languages, you can create an alternative layout for that language only.” Google Localization Checklist https://developer.android.com/distribute/tools/localization-checklist.html One Layout
  22. “In cases where your UI can't accommodate text in one

    of your target languages, you can create an alternative layout for that language only.” “While the flexibility of alternative layouts exists it can also make your apps harder to maintain over time. In general, using a single, more flexible layout is preferred.” Google Localization Checklist https://developer.android.com/distribute/tools/localization-checklist.html One Layout
  23. “In cases where your UI can't accommodate text in one

    of your target languages, you can create an alternative layout for that language only.” “While the flexibility of alternative layouts exists it can also make your apps harder to maintain over time. In general, using a single, more flexible layout is preferred.” Google Localization Checklist https://developer.android.com/distribute/tools/localization-checklist.html One Layout
  24. <Layout> <com.omitneedlesscode.droidconnyc.DebugTextView
 android:text="@string/test_string"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:id="@+id/example_text_view"
 android:layout_marginStart="20dp"
 android:layout_marginEnd="20dp"
 android:textSize=“28sp"/> </Layout>

    <Layout> <com.omitneedlesscode.droidconnyc.DebugTextView
 android:id="@+id/example_text_view"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_marginRight="20dp"
 android:layout_marginLeft="20dp"
 android:text="@string/test_string"
 android:textSize=“28sp"/> </Layout>
 API 17+ API <17 One Layout
  25. <Layout> <com.omitneedlesscode.droidconnyc.DebugTextView
 android:text="@string/test_string"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:id="@+id/example_text_view"
 android:layout_marginStart="20dp"
 android:layout_marginEnd="20dp"
 android:textSize=“28sp"/> </Layout>

    <Layout> <com.omitneedlesscode.droidconnyc.DebugTextView
 android:id="@+id/example_text_view"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_marginRight="20dp"
 android:layout_marginLeft="20dp"
 android:text="@string/test_string"
 android:textSize=“28sp"/> </Layout>
 API 17+ API <17 One Layout
  26. 1.Support RTL 2.Make font file a localized String 3.Mind font

    padding 4.One layout to rule them all 5.Be careful with Spans Elliott’s Development Localization Checklist
  27. 1.Support RTL 2.Make font file a localized String 3.Mind font

    padding 4.One layout to rule them all 5.Be careful with Spans 6.Localize Line Heights Elliott’s Development Localization Checklist
  28. Line Height Add/Mult <resources>
 <item name="line_mult" format="float" type="integer">0.8</item>
 </resources> <resources>


    <item name="line_mult" format="float" type=“integer">1.0</item>
 </resources> values/integers.xml values-th/integers.xml
  29. 1.Support RTL 2.Make font file a localized String 3.Mind font

    padding 4.One layout to rule them all 5.Be careful with Spans 6.Localize Line Heights 7.Pseudolocalizations Elliott’s Development Localization Checklist
  30. Pseudolocalization buildTypes {
 debug{
 pseudoLocalesEnabled true
 }
 release {
 minifyEnabled

    false
 proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
 }
 }
  31. Pseudolocalization buildTypes {
 debug{
 pseudoLocalesEnabled true
 }
 release {
 minifyEnabled

    false
 proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
 }
 }