use of android.text.InputFilter in project Roblu by wdavies973.
the class Drawing method changeWidth.
private void changeWidth() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
final AppCompatEditText input = new AppCompatEditText(this);
Utils.setInputTextLayoutColor(rui.getAccent(), null, input);
input.setHighlightColor(rui.getAccent());
input.setHintTextColor(rui.getText());
input.setTextColor(rui.getText());
input.setInputType(InputType.TYPE_CLASS_NUMBER);
InputFilter[] FilterArray = new InputFilter[1];
FilterArray[0] = new InputFilter.LengthFilter(30);
input.setFilters(FilterArray);
layout.addView(input);
builder.setView(layout);
builder.setPositiveButton("Set", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
canvas.setPaintStrokeWidth(Float.parseFloat(input.getText().toString()));
dialog.dismiss();
}
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
TextView view = new TextView(this);
view.setTextSize(Utils.DPToPX(getApplicationContext(), 5));
view.setPadding(Utils.DPToPX(this, 18), Utils.DPToPX(this, 18), Utils.DPToPX(this, 18), Utils.DPToPX(this, 18));
view.setText(R.string.set_line_width);
view.setTextColor(rui.getText());
AlertDialog dialog = builder.create();
dialog.setCustomTitle(view);
if (dialog.getWindow() != null) {
dialog.getWindow().getAttributes().windowAnimations = rui.getDialogDirection();
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(rui.getBackground()));
}
dialog.show();
dialog.getButton(Dialog.BUTTON_NEGATIVE).setTextColor(rui.getAccent());
dialog.getButton(Dialog.BUTTON_POSITIVE).setTextColor(rui.getAccent());
}
use of android.text.InputFilter in project Roblu by wdavies973.
the class TeamsView method showTeamCreateDialog.
/**
* Shows the team create dialog where the user can manually create a team
*/
private void showTeamCreateDialog() {
if (eventDrawerManager.getEvent() == null)
return;
AlertDialog.Builder builder = new AlertDialog.Builder(this);
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
final AppCompatEditText input = new AppCompatEditText(this);
Utils.setInputTextLayoutColor(settings.getRui().getAccent(), null, input);
input.setHighlightColor(settings.getRui().getAccent());
input.setHintTextColor(settings.getRui().getText());
input.setTextColor(settings.getRui().getText());
input.setInputType(InputType.TYPE_CLASS_TEXT);
input.setHint("Team name");
InputFilter[] FilterArray = new InputFilter[1];
FilterArray[0] = new InputFilter.LengthFilter(30);
input.setFilters(FilterArray);
layout.addView(input);
final AppCompatEditText input2 = new AppCompatEditText(this);
Utils.setInputTextLayoutColor(settings.getRui().getAccent(), null, input2);
input2.setHighlightColor(settings.getRui().getAccent());
input2.setHintTextColor(settings.getRui().getText());
input2.setTextColor(settings.getRui().getText());
input2.setInputType(InputType.TYPE_CLASS_NUMBER);
input2.setHint("Team number");
InputFilter[] FilterArray2 = new InputFilter[1];
FilterArray2[0] = new InputFilter.LengthFilter(6);
input2.setFilters(FilterArray2);
layout.addView(input2);
builder.setView(layout);
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (input2.getText().toString().equals(""))
input2.setText("0");
RTeam team = new RTeam(input.getText().toString(), Integer.parseInt(input2.getText().toString()), io.getNewTeamID(eventDrawerManager.getEvent().getID()));
/*
* Package for cloud
*/
if (eventDrawerManager.getEvent() != null && eventDrawerManager.getEvent().isCloudEnabled()) {
team.verify(io.loadForm(eventDrawerManager.getEvent().getID()));
RCheckout checkout = new RCheckout(team);
checkout.setStatus(0);
io.savePendingCheckout(checkout);
}
io.saveTeam(eventDrawerManager.getEvent().getID(), team);
executeLoadTeamsTask(lastFilter, true);
}
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
TextView view = new TextView(this);
view.setTextSize(Utils.DPToPX(getApplicationContext(), 5));
view.setPadding(Utils.DPToPX(this, 18), Utils.DPToPX(this, 18), Utils.DPToPX(this, 18), Utils.DPToPX(this, 18));
view.setText(R.string.create_team);
view.setTextColor(settings.getRui().getText());
AlertDialog dialog = builder.create();
dialog.setCustomTitle(view);
if (dialog.getWindow() != null) {
dialog.getWindow().getAttributes().windowAnimations = settings.getRui().getAnimation();
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(settings.getRui().getBackground()));
}
dialog.show();
dialog.getButton(Dialog.BUTTON_NEGATIVE).setTextColor(settings.getRui().getAccent());
dialog.getButton(Dialog.BUTTON_POSITIVE).setTextColor(settings.getRui().getAccent());
}
use of android.text.InputFilter in project Anki-Android by Ramblurr.
the class CardEditor method onCreateDialog.
@Override
protected Dialog onCreateDialog(int id) {
StyledDialog dialog = null;
Resources res = getResources();
StyledDialog.Builder builder = new StyledDialog.Builder(this);
switch(id) {
case DIALOG_TAGS_SELECT:
builder.setTitle(R.string.card_details_tags);
builder.setPositiveButton(res.getString(R.string.select), new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (mAddNote) {
try {
JSONArray ja = new JSONArray();
for (String t : selectedTags) {
ja.put(t);
}
mCol.getModels().current().put("tags", ja);
mCol.getModels().setChanged();
} catch (JSONException e) {
throw new RuntimeException(e);
}
mEditorNote.setTags(selectedTags);
}
mCurrentTags = selectedTags;
updateTags();
}
});
builder.setNegativeButton(res.getString(R.string.cancel), null);
mNewTagEditText = (EditText) new EditText(this);
mNewTagEditText.setHint(R.string.add_new_tag);
InputFilter filter = new InputFilter() {
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
for (int i = start; i < end; i++) {
if (source.charAt(i) == ' ' || source.charAt(i) == ',') {
return "";
}
}
return null;
}
};
mNewTagEditText.setFilters(new InputFilter[] { filter });
ImageView mAddTextButton = new ImageView(this);
mAddTextButton.setImageResource(R.drawable.ic_addtag);
mAddTextButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String tag = mNewTagEditText.getText().toString();
if (tag.length() != 0) {
if (mEditorNote.hasTag(tag)) {
mNewTagEditText.setText("");
return;
}
selectedTags.add(tag);
actualizeTagDialog(mTagsDialog);
mNewTagEditText.setText("");
}
}
});
FrameLayout frame = new FrameLayout(this);
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.RIGHT | Gravity.CENTER_VERTICAL);
params.rightMargin = 10;
mAddTextButton.setLayoutParams(params);
frame.addView(mNewTagEditText);
frame.addView(mAddTextButton);
builder.setView(frame, false, true);
dialog = builder.create();
mTagsDialog = dialog;
break;
case DIALOG_DECK_SELECT:
ArrayList<CharSequence> dialogDeckItems = new ArrayList<CharSequence>();
// Use this array to know which ID is associated with each
// Item(name)
final ArrayList<Long> dialogDeckIds = new ArrayList<Long>();
ArrayList<JSONObject> decks = mCol.getDecks().all();
Collections.sort(decks, new JSONNameComparator());
builder.setTitle(R.string.deck);
for (JSONObject d : decks) {
try {
if (d.getInt("dyn") == 0) {
dialogDeckItems.add(d.getString("name"));
dialogDeckIds.add(d.getLong("id"));
}
} catch (JSONException e) {
throw new RuntimeException(e);
}
}
// Convert to Array
String[] items = new String[dialogDeckItems.size()];
dialogDeckItems.toArray(items);
builder.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
long newId = dialogDeckIds.get(item);
if (mCurrentDid != newId) {
if (mAddNote) {
try {
// TODO: mEditorNote.setDid(newId);
mEditorNote.model().put("did", newId);
mCol.getModels().setChanged();
} catch (JSONException e) {
throw new RuntimeException(e);
}
}
mCurrentDid = newId;
updateDeck();
}
}
});
dialog = builder.create();
mDeckSelectDialog = dialog;
break;
case DIALOG_MODEL_SELECT:
ArrayList<CharSequence> dialogItems = new ArrayList<CharSequence>();
// Use this array to know which ID is associated with each
// Item(name)
final ArrayList<Long> dialogIds = new ArrayList<Long>();
ArrayList<JSONObject> models = mCol.getModels().all();
Collections.sort(models, new JSONNameComparator());
builder.setTitle(R.string.note_type);
for (JSONObject m : models) {
try {
dialogItems.add(m.getString("name"));
dialogIds.add(m.getLong("id"));
} catch (JSONException e) {
throw new RuntimeException(e);
}
}
// Convert to Array
String[] items2 = new String[dialogItems.size()];
dialogItems.toArray(items2);
builder.setItems(items2, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
long oldModelId;
try {
oldModelId = mCol.getModels().current().getLong("id");
} catch (JSONException e) {
throw new RuntimeException(e);
}
long newId = dialogIds.get(item);
if (oldModelId != newId) {
mCol.getModels().setCurrent(mCol.getModels().get(newId));
JSONObject cdeck = mCol.getDecks().current();
try {
cdeck.put("mid", newId);
} catch (JSONException e) {
throw new RuntimeException(e);
}
mCol.getDecks().save(cdeck);
int size = mEditFields.size();
String[] oldValues = new String[size];
for (int i = 0; i < size; i++) {
oldValues[i] = mEditFields.get(i).getText().toString();
}
setNote();
resetEditFields(oldValues);
mTimerHandler.removeCallbacks(checkDuplicatesRunnable);
duplicateCheck(false);
}
}
});
dialog = builder.create();
break;
case DIALOG_RESET_CARD:
builder.setTitle(res.getString(R.string.reset_card_dialog_title));
builder.setMessage(res.getString(R.string.reset_card_dialog_message));
builder.setPositiveButton(res.getString(R.string.yes), new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// for (long cardId :
// mDeck.getCardsFromFactId(mEditorNote.getId())) {
// mDeck.cardFromId(cardId).resetCard();
// }
// mDeck.reset();
// setResult(Reviewer.RESULT_EDIT_CARD_RESET);
// mCardReset = true;
// Themes.showThemedToast(CardEditor.this,
// getResources().getString(
// R.string.reset_card_dialog_confirmation), true);
}
});
builder.setNegativeButton(res.getString(R.string.no), null);
builder.setCancelable(true);
dialog = builder.create();
break;
case DIALOG_INTENT_INFORMATION:
dialog = createDialogIntentInformation(builder, res);
}
return dialog;
}
use of android.text.InputFilter in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class WifiP2pSettings method onCreateDialog.
@Override
public Dialog onCreateDialog(int id) {
if (id == DIALOG_DISCONNECT) {
String deviceName = TextUtils.isEmpty(mSelectedWifiPeer.device.deviceName) ? mSelectedWifiPeer.device.deviceAddress : mSelectedWifiPeer.device.deviceName;
String msg;
if (mConnectedDevices > 1) {
msg = getActivity().getString(R.string.wifi_p2p_disconnect_multiple_message, deviceName, mConnectedDevices - 1);
} else {
msg = getActivity().getString(R.string.wifi_p2p_disconnect_message, deviceName);
}
AlertDialog dialog = new AlertDialog.Builder(getActivity()).setTitle(R.string.wifi_p2p_disconnect_title).setMessage(msg).setPositiveButton(getActivity().getString(R.string.dlg_ok), mDisconnectListener).setNegativeButton(getActivity().getString(R.string.dlg_cancel), null).create();
return dialog;
} else if (id == DIALOG_CANCEL_CONNECT) {
int stringId = R.string.wifi_p2p_cancel_connect_message;
String deviceName = TextUtils.isEmpty(mSelectedWifiPeer.device.deviceName) ? mSelectedWifiPeer.device.deviceAddress : mSelectedWifiPeer.device.deviceName;
AlertDialog dialog = new AlertDialog.Builder(getActivity()).setTitle(R.string.wifi_p2p_cancel_connect_title).setMessage(getActivity().getString(stringId, deviceName)).setPositiveButton(getActivity().getString(R.string.dlg_ok), mCancelConnectListener).setNegativeButton(getActivity().getString(R.string.dlg_cancel), null).create();
return dialog;
} else if (id == DIALOG_RENAME) {
mDeviceNameText = new EditText(getActivity());
mDeviceNameText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(30) });
if (mSavedDeviceName != null) {
mDeviceNameText.setText(mSavedDeviceName);
mDeviceNameText.setSelection(mSavedDeviceName.length());
} else if (mThisDevice != null && !TextUtils.isEmpty(mThisDevice.deviceName)) {
mDeviceNameText.setText(mThisDevice.deviceName);
mDeviceNameText.setSelection(0, mThisDevice.deviceName.length());
}
mSavedDeviceName = null;
AlertDialog dialog = new AlertDialog.Builder(getActivity()).setTitle(R.string.wifi_p2p_menu_rename).setView(mDeviceNameText).setPositiveButton(getActivity().getString(R.string.dlg_ok), mRenameListener).setNegativeButton(getActivity().getString(R.string.dlg_cancel), null).create();
return dialog;
} else if (id == DIALOG_DELETE_GROUP) {
int stringId = R.string.wifi_p2p_delete_group_message;
AlertDialog dialog = new AlertDialog.Builder(getActivity()).setMessage(getActivity().getString(stringId)).setPositiveButton(getActivity().getString(R.string.dlg_ok), mDeleteGroupListener).setNegativeButton(getActivity().getString(R.string.dlg_cancel), mDeleteGroupListener).create();
return dialog;
}
return null;
}
use of android.text.InputFilter in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class Utf8ByteLengthFilterTest method testFilter.
@SmallTest
public void testFilter() {
// Define the variables
CharSequence source;
SpannableStringBuilder dest;
// Constructor to create a LengthFilter
InputFilter lengthFilter = new Utf8ByteLengthFilter(10);
InputFilter[] filters = { lengthFilter };
// filter() implicitly invoked. If the total length > filter length, the filter will
// cut off the source CharSequence from beginning to fit the filter length.
source = "abc";
dest = new SpannableStringBuilder("abcdefgh");
dest.setFilters(filters);
dest.insert(1, source);
String expectedString1 = "aabbcdefgh";
assertEquals(expectedString1, dest.toString());
dest.replace(5, 8, source);
String expectedString2 = "aabbcabcgh";
assertEquals(expectedString2, dest.toString());
dest.insert(2, source);
assertEquals(expectedString2, dest.toString());
dest.delete(1, 3);
String expectedString3 = "abcabcgh";
assertEquals(expectedString3, dest.toString());
dest.append("12345");
String expectedString4 = "abcabcgh12";
assertEquals(expectedString4, dest.toString());
// 2 Chinese chars == 6 bytes in UTF-8
source = "\u60a8\u597d";
dest.replace(8, 10, source);
assertEquals(expectedString3, dest.toString());
dest.replace(0, 1, source);
String expectedString5 = "\u60a8bcabcgh";
assertEquals(expectedString5, dest.toString());
dest.replace(0, 4, source);
String expectedString6 = "\u60a8\u597dbcgh";
assertEquals(expectedString6, dest.toString());
// 2 Latin-1 chars == 4 bytes in UTF-8
source = "\u00a3\u00a5";
dest.delete(2, 6);
dest.insert(0, source);
String expectedString7 = "\u00a3\u00a5\u60a8\u597d";
assertEquals(expectedString7, dest.toString());
dest.replace(2, 3, source);
String expectedString8 = "\u00a3\u00a5\u00a3\u597d";
assertEquals(expectedString8, dest.toString());
dest.replace(3, 4, source);
String expectedString9 = "\u00a3\u00a5\u00a3\u00a3\u00a5";
assertEquals(expectedString9, dest.toString());
// filter() explicitly invoked
dest = new SpannableStringBuilder("abcdefgh");
CharSequence beforeFilterSource = "TestLengthFilter";
String expectedAfterFilter = "TestLength";
CharSequence actualAfterFilter = lengthFilter.filter(beforeFilterSource, 0, beforeFilterSource.length(), dest, 0, dest.length());
assertEquals(expectedAfterFilter, actualAfterFilter);
}
Aggregations