use of android.text.InputFilter in project material-dialogs by afollestad.
the class ColorChooserDialog method onCreateDialog.
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
if (getArguments() == null || !getArguments().containsKey("builder")) {
throw new IllegalStateException("ColorChooserDialog should be created using its Builder interface.");
}
generateColors();
int preselectColor;
boolean foundPreselectColor = false;
if (savedInstanceState != null) {
foundPreselectColor = !savedInstanceState.getBoolean("in_custom", false);
preselectColor = getSelectedColor();
} else {
if (getBuilder().setPreselectionColor) {
preselectColor = getBuilder().preselectColor;
if (preselectColor != 0) {
for (int topIndex = 0; topIndex < colorsTop.length; topIndex++) {
if (colorsTop[topIndex] == preselectColor) {
foundPreselectColor = true;
topIndex(topIndex);
if (getBuilder().accentMode) {
subIndex(2);
} else if (colorsSub != null) {
findSubIndexForColor(topIndex, preselectColor);
} else {
subIndex(5);
}
break;
}
if (colorsSub != null) {
for (int subIndex = 0; subIndex < colorsSub[topIndex].length; subIndex++) {
if (colorsSub[topIndex][subIndex] == preselectColor) {
foundPreselectColor = true;
topIndex(topIndex);
subIndex(subIndex);
break;
}
}
if (foundPreselectColor) {
break;
}
}
}
}
} else {
preselectColor = Color.BLACK;
foundPreselectColor = true;
}
}
circleSize = getResources().getDimensionPixelSize(R.dimen.md_colorchooser_circlesize);
final Builder builder = getBuilder();
MaterialDialog.Builder bd = new MaterialDialog.Builder(getActivity()).title(getTitle()).autoDismiss(false).customView(R.layout.md_dialog_colorchooser, false).negativeText(builder.cancelBtn).positiveText(builder.doneBtn).neutralText(builder.allowUserCustom ? builder.customBtn : 0).onPositive(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
callback.onColorSelection(ColorChooserDialog.this, getSelectedColor());
dismiss();
}
}).onNegative(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
if (isInSub()) {
dialog.setActionButton(DialogAction.NEGATIVE, getBuilder().cancelBtn);
isInSub(false);
// Do this to avoid ArrayIndexOutOfBoundsException
subIndex(-1);
invalidate();
} else {
dialog.cancel();
}
}
}).onNeutral(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
toggleCustom(dialog);
}
}).showListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
invalidateDynamicButtonColors();
}
});
if (builder.theme != null) {
bd.theme(builder.theme);
}
final MaterialDialog dialog = bd.build();
final View v = dialog.getCustomView();
grid = (GridView) v.findViewById(R.id.md_grid);
if (builder.allowUserCustom) {
selectedCustomColor = preselectColor;
colorChooserCustomFrame = v.findViewById(R.id.md_colorChooserCustomFrame);
customColorHex = (EditText) v.findViewById(R.id.md_hexInput);
customColorIndicator = v.findViewById(R.id.md_colorIndicator);
customSeekA = (SeekBar) v.findViewById(R.id.md_colorA);
customSeekAValue = (TextView) v.findViewById(R.id.md_colorAValue);
customSeekR = (SeekBar) v.findViewById(R.id.md_colorR);
customSeekRValue = (TextView) v.findViewById(R.id.md_colorRValue);
customSeekG = (SeekBar) v.findViewById(R.id.md_colorG);
customSeekGValue = (TextView) v.findViewById(R.id.md_colorGValue);
customSeekB = (SeekBar) v.findViewById(R.id.md_colorB);
customSeekBValue = (TextView) v.findViewById(R.id.md_colorBValue);
if (!builder.allowUserCustomAlpha) {
v.findViewById(R.id.md_colorALabel).setVisibility(View.GONE);
customSeekA.setVisibility(View.GONE);
customSeekAValue.setVisibility(View.GONE);
customColorHex.setHint("2196F3");
customColorHex.setFilters(new InputFilter[] { new InputFilter.LengthFilter(6) });
} else {
customColorHex.setHint("FF2196F3");
customColorHex.setFilters(new InputFilter[] { new InputFilter.LengthFilter(8) });
}
if (!foundPreselectColor) {
// If color wasn't found in the preset colors, it must be custom
toggleCustom(dialog);
}
}
invalidate();
return dialog;
}
use of android.text.InputFilter in project android_frameworks_base by ResurrectionRemix.
the class TextView method onInitializeAccessibilityNodeInfoInternal.
/** @hide */
@Override
public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
super.onInitializeAccessibilityNodeInfoInternal(info);
final boolean isPassword = hasPasswordTransformationMethod();
info.setPassword(isPassword);
info.setText(getTextForAccessibility());
if (mBufferType == BufferType.EDITABLE) {
info.setEditable(true);
if (isEnabled()) {
info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_SET_TEXT);
}
}
if (mEditor != null) {
info.setInputType(mEditor.mInputType);
if (mEditor.mError != null) {
info.setContentInvalid(true);
info.setError(mEditor.mError);
}
}
if (!TextUtils.isEmpty(mText)) {
info.addAction(AccessibilityNodeInfo.ACTION_NEXT_AT_MOVEMENT_GRANULARITY);
info.addAction(AccessibilityNodeInfo.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY);
info.setMovementGranularities(AccessibilityNodeInfo.MOVEMENT_GRANULARITY_CHARACTER | AccessibilityNodeInfo.MOVEMENT_GRANULARITY_WORD | AccessibilityNodeInfo.MOVEMENT_GRANULARITY_LINE | AccessibilityNodeInfo.MOVEMENT_GRANULARITY_PARAGRAPH | AccessibilityNodeInfo.MOVEMENT_GRANULARITY_PAGE);
info.addAction(AccessibilityNodeInfo.ACTION_SET_SELECTION);
}
if (isFocused()) {
if (canCopy()) {
info.addAction(AccessibilityNodeInfo.ACTION_COPY);
}
if (canPaste()) {
info.addAction(AccessibilityNodeInfo.ACTION_PASTE);
}
if (canCut()) {
info.addAction(AccessibilityNodeInfo.ACTION_CUT);
}
if (canShare()) {
info.addAction(new AccessibilityNodeInfo.AccessibilityAction(ACCESSIBILITY_ACTION_SHARE, getResources().getString(com.android.internal.R.string.share)));
}
if (canProcessText()) {
// also implies mEditor is not null.
mEditor.mProcessTextIntentActionsHandler.onInitializeAccessibilityNodeInfo(info);
}
}
// Check for known input filter types.
final int numFilters = mFilters.length;
for (int i = 0; i < numFilters; i++) {
final InputFilter filter = mFilters[i];
if (filter instanceof InputFilter.LengthFilter) {
info.setMaxTextLength(((InputFilter.LengthFilter) filter).getMax());
}
}
if (!isSingleLine()) {
info.setMultiLine(true);
}
}
use of android.text.InputFilter in project android_frameworks_base by ResurrectionRemix.
the class TextView method setFilters.
/**
* Sets the list of input filters on the specified Editable,
* and includes mInput in the list if it is an InputFilter.
*/
private void setFilters(Editable e, InputFilter[] filters) {
if (mEditor != null) {
final boolean undoFilter = mEditor.mUndoInputFilter != null;
final boolean keyFilter = mEditor.mKeyListener instanceof InputFilter;
int num = 0;
if (undoFilter)
num++;
if (keyFilter)
num++;
if (num > 0) {
InputFilter[] nf = new InputFilter[filters.length + num];
System.arraycopy(filters, 0, nf, 0, filters.length);
num = 0;
if (undoFilter) {
nf[filters.length] = mEditor.mUndoInputFilter;
num++;
}
if (keyFilter) {
nf[filters.length + num] = (InputFilter) mEditor.mKeyListener;
}
e.setFilters(nf);
return;
}
}
e.setFilters(filters);
}
use of android.text.InputFilter in project RSAndroidApp by RailwayStations.
the class AuthActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_auth);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
subscribtionStatus();
mUsername = ANONYMOUS;
// Initialize Firebase Auth
mFirebaseAuth = FirebaseAuth.getInstance();
mFirebaseUser = mFirebaseAuth.getCurrentUser();
ChatMessage friendly_chat = new ChatMessage();
mTimeStamp = friendly_chat.setChatTimeStamp();
if (mFirebaseUser == null) {
// Not signed in, launch the Sign In activity
startActivity(new Intent(this, SignInActivity.class));
finish();
return;
} else {
mUsername = mFirebaseUser.getDisplayName();
mPhotoUrl = mFirebaseUser.getPhotoUrl().toString();
}
mGoogleApiClient = new GoogleApiClient.Builder(this).enableAutoManage(this, /* FragmentActivity */
this).addApi(Auth.GOOGLE_SIGN_IN_API).build();
mProgressBar = (ProgressBar) findViewById(R.id.progressBar);
mMessageRecyclerView = (RecyclerView) findViewById(R.id.messageRecyclerView);
mLinearLayoutManager = new LinearLayoutManager(this);
mLinearLayoutManager.setStackFromEnd(true);
mFirebaseDatabaseReference = FirebaseDatabase.getInstance().getReference();
mFirebaseAdapter = new FirebaseRecyclerAdapter<ChatMessage, MessageViewHolder>(ChatMessage.class, R.layout.item_message, MessageViewHolder.class, mFirebaseDatabaseReference.child(MESSAGES_CHILD)) {
@Override
protected void populateViewHolder(MessageViewHolder viewHolder, ChatMessage friendlyMessage, int position) {
mProgressBar.setVisibility(ProgressBar.INVISIBLE);
viewHolder.messageTextView.setText(friendlyMessage.getText());
viewHolder.messengerTextView.setText(friendlyMessage.getName());
viewHolder.messengerTimeStamp.setText(friendlyMessage.getChatTimeStamp());
if (friendlyMessage.getPhotoUrl() == null) {
viewHolder.messengerImageView.setImageDrawable(ContextCompat.getDrawable(AuthActivity.this, R.drawable.ic_account_circle_black_36dp));
} else {
Glide.with(AuthActivity.this).load(friendlyMessage.getPhotoUrl()).into(viewHolder.messengerImageView);
}
}
};
mFirebaseAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
@Override
public void onItemRangeInserted(int positionStart, int itemCount) {
super.onItemRangeInserted(positionStart, itemCount);
int friendlyMessageCount = mFirebaseAdapter.getItemCount();
int lastVisiblePosition = mLinearLayoutManager.findLastCompletelyVisibleItemPosition();
// to the bottom of the list to show the newly added message.
if (lastVisiblePosition == -1 || (positionStart >= (friendlyMessageCount - 1) && lastVisiblePosition == (positionStart - 1))) {
mMessageRecyclerView.scrollToPosition(positionStart);
}
}
});
mMessageRecyclerView.setLayoutManager(mLinearLayoutManager);
mMessageRecyclerView.setAdapter(mFirebaseAdapter);
// Initialize Firebase Remote Config.
mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance();
// Define Firebase Remote Config Settings.
FirebaseRemoteConfigSettings firebaseRemoteConfigSettings = new FirebaseRemoteConfigSettings.Builder().setDeveloperModeEnabled(true).build();
// Define default config values. Defaults are used when fetched config values are not
// available. Eg: if an error occurred fetching values from the server.
Map<String, Object> defaultConfigMap = new HashMap<>();
defaultConfigMap.put("friendly_msg_length", 10L);
// Apply config settings and default values.
mFirebaseRemoteConfig.setConfigSettings(firebaseRemoteConfigSettings);
mFirebaseRemoteConfig.setDefaults(defaultConfigMap);
// Fetch remote config.
fetchConfig();
mMessageEditText = (EditText) findViewById(R.id.messageEditText);
mMessageEditText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(mSharedPreferences.getInt(FRIENDLY_MSG_LENGTH, DEFAULT_MSG_LENGTH_LIMIT)) });
mMessageEditText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
if (charSequence.toString().trim().length() > 0) {
mSendButton.setEnabled(true);
} else {
mSendButton.setEnabled(false);
}
}
@Override
public void afterTextChanged(Editable editable) {
}
});
mSendButton = (Button) findViewById(R.id.sendButton);
mSendButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ChatMessage chatMessage = new ChatMessage(mMessageEditText.getText().toString(), mUsername, mPhotoUrl, mTimeStamp);
mFirebaseDatabaseReference.child(MESSAGES_CHILD).push().setValue(chatMessage);
mMessageEditText.setText("");
}
});
}
use of android.text.InputFilter in project UltimateAndroid by cymcsg.
the class AbstractPasscodeKeyboardActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.passlock_passcode_keyboard);
topMessage = (TextView) findViewById(R.id.top_message);
Bundle extras = getIntent().getExtras();
if (extras != null) {
String message = extras.getString("message");
if (message != null) {
topMessage.setText(message);
}
}
filters = new InputFilter[2];
filters[0] = new InputFilter.LengthFilter(1);
filters[1] = onlyNumber;
//Setup the pin fields row
pinCodeField1 = (EditText) findViewById(R.id.pincode_1);
setupPinItem(pinCodeField1);
pinCodeField2 = (EditText) findViewById(R.id.pincode_2);
setupPinItem(pinCodeField2);
pinCodeField3 = (EditText) findViewById(R.id.pincode_3);
setupPinItem(pinCodeField3);
pinCodeField4 = (EditText) findViewById(R.id.pincode_4);
setupPinItem(pinCodeField4);
//setup the keyboard
((Button) findViewById(R.id.button0)).setOnClickListener(defaultButtonListener);
((Button) findViewById(R.id.button1)).setOnClickListener(defaultButtonListener);
((Button) findViewById(R.id.button2)).setOnClickListener(defaultButtonListener);
((Button) findViewById(R.id.button3)).setOnClickListener(defaultButtonListener);
((Button) findViewById(R.id.button4)).setOnClickListener(defaultButtonListener);
((Button) findViewById(R.id.button5)).setOnClickListener(defaultButtonListener);
((Button) findViewById(R.id.button6)).setOnClickListener(defaultButtonListener);
((Button) findViewById(R.id.button7)).setOnClickListener(defaultButtonListener);
((Button) findViewById(R.id.button8)).setOnClickListener(defaultButtonListener);
((Button) findViewById(R.id.button9)).setOnClickListener(defaultButtonListener);
((Button) findViewById(R.id.button_erase)).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
if (pinCodeField1.isFocused()) {
} else if (pinCodeField2.isFocused()) {
pinCodeField1.requestFocus();
pinCodeField1.setText("");
} else if (pinCodeField3.isFocused()) {
pinCodeField2.requestFocus();
pinCodeField2.setText("");
} else if (pinCodeField4.isFocused()) {
pinCodeField3.requestFocus();
pinCodeField3.setText("");
}
}
});
}
Aggregations