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;
21
22import android.support.v4.text.BidiFormatter;
23import android.widget.TextView;
24import com.example.android.supportv4.R;
25
26/**
27 * This example illustrates a common usage of the BidiFormatter in the Android support library.
28 */
29public class BidiFormatterSupport extends Activity {
30
31    private static String text = "%s הוא עסוק";
32    private static String phone = "+1 650 253 0000";
33
34    @Override
35    protected void onCreate(Bundle savedInstanceState) {
36        super.onCreate(savedInstanceState);
37
38        setContentView(R.layout.bidiformater_support);
39
40        String formattedText = String.format(text, phone);
41
42        TextView tv_sample = findViewById(R.id.textview_without_bidiformatter);
43        tv_sample.setText(formattedText);
44
45        TextView tv_bidiformatter = findViewById(R.id.textview_with_bidiformatter);
46        String wrappedPhone = BidiFormatter.getInstance(true /* rtlContext */).unicodeWrap(phone);
47        formattedText = String.format(text, wrappedPhone);
48        tv_bidiformatter.setText(formattedText);
49    }
50}
51