BiDiTestBasicpublic class BiDiTestBasic extends android.app.Fragment
Fields Summary |
---|
private android.view.View | currentView | private android.widget.Button | alertDialogButton | private String[] | items |
Methods Summary |
---|
public android.view.View | onCreateView(android.view.LayoutInflater inflater, android.view.ViewGroup container, android.os.Bundle savedInstanceState)
currentView = inflater.inflate(R.layout.basic, container, false);
return currentView;
| public void | onViewCreated(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 void | showDialog()
AlertDialog.Builder builder = new AlertDialog.Builder(currentView.getContext());
builder.setSingleChoiceItems(items, 0, null);
builder.show();
| private void | useSpans()
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);
}
|
|