FileDocCategorySizeDatePackage
BiDiTestBasic.javaAPI DocAndroid 5.1 API3406Thu Mar 12 22:22:42 GMT 2015com.android.bidi

BiDiTestBasic

public class BiDiTestBasic extends android.app.Fragment

Fields Summary
private android.view.View
currentView
private android.widget.Button
alertDialogButton
private String[]
items
Constructors Summary
Methods Summary
public android.view.ViewonCreateView(android.view.LayoutInflater inflater, android.view.ViewGroup container, android.os.Bundle savedInstanceState)


    
         
              
        currentView = inflater.inflate(R.layout.basic, container, false);
        return currentView;
    
public voidonViewCreated(android.view.View view, android.os.Bundle savedInstanceState)

        super.onViewCreated(view, savedInstanceState);

        alertDialogButton = (Button) currentView.findViewById(R.id.button_alert_dialog);
        alertDialogButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                showDialog();
            }
        });

        useSpans();
    
private voidshowDialog()

        AlertDialog.Builder builder = new AlertDialog.Builder(currentView.getContext());
        builder.setSingleChoiceItems(items, 0, null);
        builder.show();
    
private voiduseSpans()

        EditText urlEdit = (EditText) currentView.findViewById(R.id.edittext_url);
        Editable url = urlEdit.getText();
        if (url.length() < 1) {
          return;
        }

        String urlString = url.toString();
        int urlLength = urlString.length();
        String domainAndRegistry = "amazon.co.uk";

        int startSchemeIndex = urlString.startsWith("https") ? 5 : 0;
        int startDomainIndex = urlString.indexOf(domainAndRegistry);
        if (startDomainIndex == -1) {
          assert false;
          return;
        }
        int stopIndex = startDomainIndex + domainAndRegistry.length();

        if (startDomainIndex != 0) {
          url.setSpan(new ForegroundColorSpan(0xfff00fff),
                  startSchemeIndex,
                  startDomainIndex,
                  Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }

        url.setSpan(new ForegroundColorSpan(0xff548aff),
                startDomainIndex,
                stopIndex,
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

        if (stopIndex < urlString.length()) {
          url.setSpan(new ForegroundColorSpan(0xfff00fff),
                  stopIndex,
                  urlLength,
                  Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }