BidiFormatterSupport.java revision def582a5836579a3fadabfdbe4413cb1652bf098
1/* 2 * Copyright (C) 2013 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.example.android.supportv4.text; 18 19import android.app.Activity; 20import android.os.Bundle; 21import android.widget.TextView; 22 23import androidx.core.text.BidiFormatter; 24 25import com.example.android.supportv4.R; 26 27/** 28 * This example illustrates a common usage of the BidiFormatter in the Android support library. 29 */ 30public class BidiFormatterSupport extends Activity { 31 32 private static String text = "%s הוא עסוק"; 33 private static String phone = "+1 650 253 0000"; 34 35 @Override 36 protected void onCreate(Bundle savedInstanceState) { 37 super.onCreate(savedInstanceState); 38 39 setContentView(R.layout.bidiformater_support); 40 41 String formattedText = String.format(text, phone); 42 43 TextView tv_sample = findViewById(R.id.textview_without_bidiformatter); 44 tv_sample.setText(formattedText); 45 46 TextView tv_bidiformatter = findViewById(R.id.textview_with_bidiformatter); 47 String wrappedPhone = BidiFormatter.getInstance(true /* rtlContext */).unicodeWrap(phone); 48 formattedText = String.format(text, wrappedPhone); 49 tv_bidiformatter.setText(formattedText); 50 } 51} 52