1 of 27

Universal Acceptance (UA) Micro-Learning Module: Module 10- Processing IDN and EAI in Mobile Apps Using Java.

Instructor Guide

1st Edition.

���© 2024 Creative Commons License - Attribution 4.0 International (CC BY 4.0).

Universal Acceptance

2 of 27

Processing IDNs and EAI in Mobile Apps UA Micro-Learning Module Objectives:

  • The micro-learning module covers relevant topics on essential aspects of Unicode character sets and their significance in mobile apps. We will delve into various topics, including text layout and rendering, with a focus on handling bidirectional text and complex scripts effectively as well as IDNs and EAI support in Mobile Apps.
  • At the end of this module, students should be able to:
    • Understand the significance of Unicode character sets in mobile app development;
    • Explain the challenges and considerations involved in text layout and rendering in mobile apps for RTL and complex scripts;
    • Demonstrate an understanding of bidirectional text and complex script rendering in mobile apps;
    • Learn how to use Java-based Android Studio mobile app development frameworks for RTL and complex scripts rendering;
    • Identify the importance of Internationalized Domain Name (IDN) processing in mobile apps; and
    • Explore libraries and examples for IDN processing and Email Address Internationalization (EAI) in mobile apps.

| 2

3 of 27

Note About the Utilization of Unicode String Literals :

  • The Unicode string literals utilized in the code examples necessitate input methods, whether virtual or physical keyboards, suited to the script from which the literals are derived. In the event that these input methods are unavailable, alternatives such as language translation tools can be used.
  • Throughout the module, Unicode string literals derived from various scripts have been used in the examples code, spanning from lesser-known to more widely used ones. This approach aims to broaden learners' exposure to a diverse range of scripts..
  • The module provides the meanings of Unicode string literals used in the example codes in English, along with their transliterations, to aid learners in accurately pronouncing them.
  • Instructors are free to use Unicode literal strings derived from a script of their choice rather than the ones included in the examples code.

| 3

4 of 27

Unicode Character Set Support in Mobile Apps:

  • Key considerations for ensuring Unicode character set support in mobile apps include:
    • Font and Rendering: Mobile apps should utilize Unicode-compliant fonts that can correctly render characters from different scripts.
    • Input Methods and Keyboards: Mobile apps should provide robust text input and editing capabilities that allow users to enter and manipulate Unicode characters.
    • Text Layout and Bi-Directional Support: Mobile apps should handle complex text layout scenarios, such as bidirectional text.
    • String Manipulation and Processing: Mobile app developers should use Unicode-aware string manipulation and processing functions.
    • Localization and Internationalization: Mobile apps should support localization and internationalization features.
    • Character Encoding: Mobile apps should utilize Unicode encoding (e.g., UTF-8) for handling and storing text data.
    • Testing and Device Compatibility: Mobile apps should be thoroughly tested on different devices, operating systems, and language settings

| 4

5 of 27

Unicode Text Layout and Rendering in Mobile Apps:

  • Key considerations for ensuring Unicode character set support in mobile apps include:
    • Font Selection.
    • Glyph Shaping and Rendering.
    • Bi-Directional Text.
    • Line Breaks and Word Wrapping.
    • Complex Script Layout.
    • Text Rendering Performance.
    • Accessibility.
    • Testing and Localization.

| 5

6 of 27

Rendering Bidirectional Text and Complex Scripts in Mobile Apps:

  • Key considerations for ensuring Unicode character set support in mobile apps include:
    • Text Rendering.
    • Bi-Directional Text Support.
    • Text Layout.
    • User Interaction.
    • Special Script Layout Requirements.
    • Testing and Localization.
    • Accessibility Considerations.

| 6

7 of 27

Java Based Mobile Apps Development Frameworks:

  • There are several popular frameworks for developing mobile applications using Python and Java. The following are some of the notable ones:
    • Java:
      • Android Studio (Java)
      • Flutter (Dart with Java interoperability)
      • Codename One (Java)
      • React Native (Java with JavaScript/TypeScript)

| 7

8 of 27

Leveraging ICU for Bidirectional Text and Complex Scripts in Mobile Apps:

  • ICU provides a comprehensive set of APIs and tools for handling various aspects of internationalization and localization, including support for bidirectional text and complex scripts.
  • The following are important points for consideration for using the ICU library for developing mobile apps:
    • Incorporate ICU Library.
    • Unicode Character Handling.
    • Bidirectional Text Layout.
    • Complex Script Rendering and Shaping.
    • Locale and Language Support.
    • Text Input and Editing.
    • Testing and Quality Assurance.
    • Documentation and Resources.

| 8

9 of 27

Rendering Bidirectional Text with Mobile Apps Development Frameworks: Android Studio:

  • Make sure to install the required dependencies in advance:
    • Java:
      • icu, android library.
      • Make sure to include the necessary dependencies for ICU4J in your project.

| 9

10 of 27

Example: RTL and Complex Scripts Rendering in Mobile Apps using Java Android(1/6):

  • Import Statements

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.LinearLayout;

import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.ibm.icu.text.Bidi;

import com.ibm.icu.text.BreakIterator;

import com.ibm.icu.util.ULocale;

  • This block contains all the necessary import statements,

| 10

11 of 27

Example: RTL and Complex Scripts Rendering in Mobile Apps using Java Android(2/6):

public class MobileAppTextRendering extends AppCompatActivity {

private TextView renderedLabel;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setupLayout();

}

private void setupLayout() {

// Create the main layout

LinearLayout layout = new LinearLayout(this);

layout.setOrientation(LinearLayout.VERTICAL);

// Create the rendered label

renderedLabel = new TextView(this);

renderedLabel.setId(View.generateViewId());

// Create the render button

Button renderButton = new Button(this);

renderButton.setText("Render Text");

renderButton.setOnClickListener(v -> renderText());

// Add the views to the layout

layout.addView(renderedLabel);

layout.addView(renderButton);

setContentView(layout);

}

}

| 11

12 of 27

Example: RTL and Complex Scripts Rendering in Mobile Apps using Java Android(3/6):

private void renderText() {

String inputText = "ሀሎ مرحبًا Hello 你好,ආයුබෝවන්";

String locale = "ar"; // Arabic locale

String renderedText = renderBidirectionalText(inputText, locale);

renderedLabel.setText(renderedText);

}

private String renderBidirectionalText(String text, String locale) {

// Create an ICU BreakIterator for line breaking

BreakIterator breakIterator = BreakIterator.createLineInstance(new ULocale(locale));

// Perform bidirectional analysis using ICU's Bidi class

Bidi bidiText = new Bidi(text, Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT);

// Break the text into lines

breakIterator.setText(bidiText.getDisplayText());

StringBuilder stringBuilder = new StringBuilder();

int start = breakIterator.first();

for (int end = breakIterator.next(); end != BreakIterator.DONE; start = end, end = breakIterator.next()) {

stringBuilder.append(bidiText.getDisplayText(start, end));

}

// Render the lines

return stringBuilder.toString();

}

}

| 12

13 of 27

Example: RTL and Complex Scripts Rendering in Mobile Apps using Java Android(4/6):

The following is a summary of how the above Java code works:

  • The import statements specify the necessary classes and libraries for the Android app and ICU4J (International Components for Unicode for Java) text rendering.
  • The `onCreate()` method is called when the activity is created. It sets the layout for the activity using `setContentView(R.layout.activity_main)`, which inflates the XML layout file `activity_main.xml`. See below the xml file created for this purpose.
  • The “onCreate()’ method also initializes the `renderedLabel` variable by finding the corresponding `TextView` in the layout using `findViewById(R.id.rendered_label)`.
  • The `renderText()` method is called when the render button is clicked. It sets the input text and locale variables and calls the `renderBidirectionalText()` method to render the text.
  • The `renderBidirectionalText()` method takes the input text and locale as parameters and returns the rendered text.
  • Inside the renderText()` method, an ICU `BreakIterator` is created to handle line breaking. Then, ICU's `Bidi` class is used to perform bidirectional analysis on the input text.

| 13

14 of 27

Example: RTL and Complex Scripts Rendering in Mobile Apps using Java Android(5/6):

The following is an example of the contents of the XML file used in the above java code.

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:paddingLeft="16dp"

android:paddingTop="16dp"

android:paddingRight="16dp"

android:paddingBottom="16dp"

tools:context=".MainActivity">

<TextView

android:id="@+id/rendered_label"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:textSize="18sp"

android:layout_marginBottom="16dp" />

<Button

android:id="@+id/render_button"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="Render Text" />

</RelativeLayout>

| 14

15 of 27

Example: RTL and Complex Scripts Rendering in Mobile Apps using Java Android(6/6):

Generating the Output:

  • When you run the Android app, the output will be a screen with a "Render Text" button and a TextView below it. Initially, the TextView will be empty.
  • When you click the "Render Text" button, the renderText() method will be called. It will render the input text "ሀሎ مرحبًا Hello 你好,ආයුබෝවන්" using the renderBidirectionalText() method and set the rendered text as the text for the TextView.
  • The rendered text will depend on the input text and the locale. In this case, the input text contains characters from different scripts (Ethiopic, Arabic, Latin, Chinese, and Sinhala). The rendering will take into account the bidirectional nature of the text and the specified locale (in this case, Arabic).

| 15

16 of 27

Mobile IDN Processing: Libraries and Examples(1/3):

  • Java IDNA for Android:
    • icu4j: the icu4j library is applicable for Android app development.
      • It provides comprehensive support for IDN processing using the IDNA class.

| 16

17 of 27

Mobile IDN Processing: Libraries and Examples(2/3):

import android.os.Bundle;

import android.util.Log;

import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.ibm.icu.text.IDNA;

import com.ibm.icu.text.IDNA.Info;

public class IDNProcessing extends AppCompatActivity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

String domain = "こんにちは.com";

IDNA idna = IDNA.getUTS46Instance(IDNA.DEFAULT);

| 17

18 of 27

Mobile IDN Processing: Libraries and Examples(3/3):

Info info = new Info();

StringBuilder encodedDomain = new StringBuilder();

StringBuilder decodedDomain = new StringBuilder();

idna.nameToASCII(domain, encodedDomain, info); // Converts IDN to ACE

idna.nameToUnicode(encodedDomain, decodedDomain, info); // Converts ACE to IDN

// Display the results in a TextView

TextView resultTextView = findViewById(R.id.resultTextView);

resultTextView.setText("Encoded Domain: " + encodedDomain.toString() + "\nDecoded Domain: " + decodedDomain.toString());

// Print the results to the log

Log.d("IDNACode", "Encoded Domain: " + encodedDomain.toString());

Log.d("IDNACode", "Decoded Domain: " + decodedDomain.toString());

}

}

| 18

19 of 27

EAI Support in Mobile Apps – Libraries and Examples(1/6):

import android.os.AsyncTask;

import android.os.Bundle;

import android.util.Log;

import androidx.appcompat.app.AppCompatActivity;

import javax.mail.*;

import javax.mail.internet.InternetAddress;

import javax.mail.internet.MimeMessage;

import java.util.Properties;

public class MainActivity extends AppCompatActivity {

// Member variables and methods will be added in subsequent blocks...

}

| 19

20 of 27

EAI Support in Mobile Apps – Libraries and Examples(2/6):

public class MainActivity extends AppCompatActivity {

private static final String TAG = "EmailSender"; // Log tag for debugging

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

// Replace with your server's email sending logic

new SendEmailTask().execute();

}

}

| 20

21 of 27

EAI Support in Mobile Apps – Libraries and Examples(3/6):

private class SendEmailTask extends AsyncTask<Void, Void, Void> {

@Override

protected Void doInBackground(Void... voids) {

sendEmail();

return null;

}

private void sendEmail() {

// Set your server's email credentials and properties

String username = "your-server-email@example.com";

String password = "your-server-email-password";

String host = "your-email-server-host";

int port = 587;

// Set the properties for the mail session

Properties props = new Properties();

props.put("mail.smtp.auth", "true");

props.put("mail.smtp.starttls.enable", "true");

props.put("mail.smtp.host", host);

props.put("mail.smtp.port", String.valueOf(port));

}

});

| 21

22 of 27

EAI Support in Mobile Apps – Libraries and Examples(4/6):

Session session = Session.getInstance(props, new Authenticator() {

protected PasswordAuthentication getPasswordAuthentication() {

return new PasswordAuthentication(username, password);

}

});

try {

// Create a MimeMessage

MimeMessage message = new MimeMessage(session);

// Set the sender address

String senderEmail = "your-server-email@example.com";

InternetAddress senderAddress = new InternetAddress(senderEmail, true);

message.setFrom(senderAddress);

// Set the recipient address

String recipientEmail = "recipient-email@example.com";

InternetAddress recipientAddress = new InternetAddress(recipientEmail, true);

message.setRecipient(Message.RecipientType.TO, recipientAddress);

| 22

23 of 27

EAI Support in Mobile Apps – Libraries and Examples(5/6):

// Set the email subject and content

message.setSubject("Test Email");

message.setText("This is a test email sent from the mobile app.");

// Send the email

Transport.send(message);

Log.d(TAG, "Email sent successfully.");

} catch (Exception e) {

Log.e(TAG, "Error sending email", e);

}

}

}

| 23

24 of 27

EAI Support in Mobile Apps – Libraries and Examples(6/6):

The following is a summary of what the above code performs:

  • Import necessary modules and libraries, including AsyncTask for background tasks, Bundle for passing data between activities, Log for logging, AppCompatActivity as the base activity class, and JavaMail API classes for email functionality.
  • Define the MainActivity class, which extends AppCompatActivity and serves as the main activity of the application.
  • Override the onCreate method, which is called when the activity is created, and set the layout for the activity.
  • In the onCreate method, instantiate a new instance of the SendEmailTask class and execute it using execute() to send the email in the background.
  • Define the SendEmailTask class, which extends AsyncTask to perform background email sending.
  • Override the doInBackground method in SendEmailTask to implement the email sending logic.
  • In the doInBackground method, call the sendEmail method to send the email.
  • Implement the sendEmail method to handle the email sending functionality:

| 24

25 of 27

Reference:

[1]. Unicode Consortium, (2023, October 5), The Unicode Standard, Version 15.0, Retrieved from https://unicode.org/versions/ on December 14, 2023.

[2]. Android Developer Documentation, (n.d.), Unicode and internationalization, Retrieved from https://stackoverflow.com/questions/16786739/how-to-use-unicode-in-android-resource on December 14, 2023.

[3]. Apple Developer Documentation, (n.d.), Using Unicode in Your App, Retrieved from https://developer.apple.com/documentation/swift/unicode on December 14, 2023.

[4]. Coulthard, M. (2019, May 30), Unicode & Multilingualism in Mobile Apps, Retrieved from https://www.smashingmagazine.com/category/mobile on December 14, 2023.

[5]. Kivy: Kivy Organization, (n.d.), Kivy: Cross-platform Python Framework, Retrieved from https://kivy.org/, on December 14, 2023.

[6]. Google. (n.d.), Android Developer Documentation. Retrieved from https://developer.android.com/docs on December 14, 2023,

[7]. International Components for Unicode (ICU), (n.d.), ICU User Guide, Retrieved from https://unicode-org.github.io/icu/userguide/ on December 14, 2023.

| 25

26 of 27

Reference:

[8]. Stack Overflow. (2015, May 27), Retrieved from https://stackoverflow.com/questions/8126233/how-to-build-icu-so-i-can-use-it-in-an-iphone-app on December 14, 2023.

[9]. International Components for Unicode (ICU), (n.d.), ICU User Guide, Retrieved from https://unicode-org.github.io/icu/userguide/ on December 14, 2023,

[10]. Kivy Team. (n.d.), Kivy Documentation, Retrieved from https://kivy.org/doc/stable/ on December 14, 2023.

[11]. Mendoza, J, (2023, November 25). python-bidi. PyPI. Retrieved from https://pypi.org/project/python-bidi/ on December 14, 2023.

[12]. Mendoza, J. (2023, November 25), idna, PyPI, Retrieved from https://pypi.org/project/idna/ on December 14, 2023,

[13]. International Components for Unicode (ICU). (n.d.). icu4j, GitHub, Retrieved from https://github.com/unicode-org/icu on December 14, 2023.

| 26

27 of 27

Author:

  • Dessalegn Mequanint Yehuala, dessalegn.mequanint@aau.edu.et.

| 27