Home | History | Annotate | Download | only in text
      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 
     17 package com.example.android.supportv4.text;
     18 
     19 import android.app.Activity;
     20 import android.os.Bundle;
     21 
     22 import android.support.v4.text.BidiFormatter;
     23 import android.widget.TextView;
     24 import com.example.android.supportv4.R;
     25 
     26 /**
     27  * This example illustrates a common usage of the BidiFormatter in the Android support library.
     28  */
     29 public 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 = (TextView) findViewById(R.id.textview_without_bidiformatter);
     43         tv_sample.setText(formattedText);
     44 
     45         TextView tv_bidiformatter = (TextView) 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