use of android.text.InputFilter in project android_packages_apps_Settings by SudaMod.
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 android_packages_apps_DU-Tweaks by DirtyUnicorns.
the class CarrierLabel method onPreferenceTreeClick.
@Override
public boolean onPreferenceTreeClick(final Preference preference) {
super.onPreferenceTreeClick(preference);
final ContentResolver resolver = getActivity().getContentResolver();
if (preference.getKey().equals(KEY_CUSTOM_CARRIER_LABEL)) {
AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
alert.setTitle(R.string.custom_carrier_label_title);
alert.setMessage(R.string.custom_carrier_label_explain);
// Set an EditText view to get user input
final EditText input = new EditText(getActivity());
int maxLength = 10;
input.setText(TextUtils.isEmpty(mCustomCarrierLabelText) ? "" : mCustomCarrierLabelText);
input.setFilters(new InputFilter[] { new InputFilter.LengthFilter(maxLength) });
input.setSelection(input.getText().length());
alert.setView(input);
alert.setPositiveButton(getString(android.R.string.ok), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String value = ((Spannable) input.getText()).toString().trim();
Settings.System.putString(resolver, Settings.System.CUSTOM_CARRIER_LABEL, value);
updateCustomLabelTextSummary();
Intent i = new Intent();
i.setAction(Intent.ACTION_CUSTOM_CARRIER_LABEL_CHANGED);
getActivity().sendBroadcast(i);
}
});
alert.setNegativeButton(getString(android.R.string.cancel), null);
alert.show();
}
return true;
}
use of android.text.InputFilter in project android_packages_apps_Settings by DirtyUnicorns.
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 Pix-Art-Messenger by kriztan.
the class EditMessage method onTextContextMenuItem.
@Override
public boolean onTextContextMenuItem(int id) {
if (id == android.R.id.paste) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
return super.onTextContextMenuItem(android.R.id.pasteAsPlainText);
} else {
Editable editable = getEditableText();
InputFilter[] filters = editable.getFilters();
InputFilter[] tempFilters = new InputFilter[filters != null ? filters.length + 1 : 1];
if (filters != null) {
System.arraycopy(filters, 0, tempFilters, 1, filters.length);
}
tempFilters[0] = SPAN_FILTER;
editable.setFilters(tempFilters);
try {
return super.onTextContextMenuItem(id);
} finally {
editable.setFilters(filters);
}
}
} else {
return super.onTextContextMenuItem(id);
}
}
use of android.text.InputFilter in project MifareClassicTool by ikarus23.
the class KeyMapCreator method onChangeSectorRange.
/**
* Show a dialog which lets the user choose the key mapping range.
* If intended, save the mapping range as default
* (using {@link #saveMappingRange(String, String)}).
* @param view The View object that triggered the method
* (in this case the change button).
*/
public void onChangeSectorRange(View view) {
// Build dialog elements.
LinearLayout ll = new LinearLayout(this);
LinearLayout llv = new LinearLayout(this);
int pad = Common.dpToPx(10);
llv.setPadding(pad, pad, pad, pad);
llv.setOrientation(LinearLayout.VERTICAL);
llv.setGravity(Gravity.CENTER);
ll.setGravity(Gravity.CENTER);
TextView tvFrom = new TextView(this);
tvFrom.setText(getString(R.string.text_from) + ": ");
tvFrom.setTextSize(18);
TextView tvTo = new TextView(this);
tvTo.setText(" " + getString(R.string.text_to) + ": ");
tvTo.setTextSize(18);
final CheckBox saveAsDefault = new CheckBox(this);
saveAsDefault.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
saveAsDefault.setText(R.string.action_save_as_default);
saveAsDefault.setTextSize(18);
tvFrom.setTextColor(saveAsDefault.getCurrentTextColor());
tvTo.setTextColor(saveAsDefault.getCurrentTextColor());
InputFilter[] f = new InputFilter[1];
f[0] = new InputFilter.LengthFilter(2);
final EditText from = new EditText(this);
from.setEllipsize(TruncateAt.END);
from.setMaxLines(1);
from.setSingleLine();
from.setInputType(InputType.TYPE_CLASS_NUMBER);
from.setMinimumWidth(60);
from.setFilters(f);
from.setGravity(Gravity.CENTER_HORIZONTAL);
final EditText to = new EditText(this);
to.setEllipsize(TruncateAt.END);
to.setMaxLines(1);
to.setSingleLine();
to.setInputType(InputType.TYPE_CLASS_NUMBER);
to.setMinimumWidth(60);
to.setFilters(f);
to.setGravity(Gravity.CENTER_HORIZONTAL);
ll.addView(tvFrom);
ll.addView(from);
ll.addView(tvTo);
ll.addView(to);
llv.addView(ll);
llv.addView(saveAsDefault);
final Toast err = Toast.makeText(this, R.string.info_invalid_range, Toast.LENGTH_LONG);
// Build dialog and show him.
new AlertDialog.Builder(this).setTitle(R.string.dialog_mapping_range_title).setMessage(R.string.dialog_mapping_range).setView(llv).setPositiveButton(R.string.action_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int whichButton) {
// Read from x to y.
String txtFrom = "" + DEFAULT_SECTOR_RANGE_FROM;
String txtTo = "" + DEFAULT_SECTOR_RANGE_TO;
boolean noFrom = false;
if (!from.getText().toString().equals("")) {
txtFrom = from.getText().toString();
} else {
noFrom = true;
}
if (!to.getText().toString().equals("")) {
txtTo = to.getText().toString();
} else if (noFrom) {
// No values provided. Read all sectors.
mSectorRange.setText(getString(R.string.text_sector_range_all));
if (saveAsDefault.isChecked()) {
saveMappingRange("", "");
}
return;
}
int intFrom = Integer.parseInt(txtFrom);
int intTo = Integer.parseInt(txtTo);
if (intFrom > intTo || intFrom < 0 || intTo > MAX_SECTOR_COUNT - 1) {
// Error.
err.show();
} else {
mSectorRange.setText(txtFrom + " - " + txtTo);
if (saveAsDefault.isChecked()) {
// Save as default.
saveMappingRange(txtFrom, txtTo);
}
}
}
}).setNeutralButton(R.string.action_read_all_sectors, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int whichButton) {
// Read all sectors.
mSectorRange.setText(getString(R.string.text_sector_range_all));
if (saveAsDefault.isChecked()) {
// Save as default.
saveMappingRange("", "");
}
}
}).setNegativeButton(R.string.action_cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int whichButton) {
// Cancel dialog (do nothing).
}
}).show();
}
Aggregations