use of android.text.Editable in project android_frameworks_base by ResurrectionRemix.
the class AutoCompleteTextView method replaceText.
/**
* <p>Performs the text completion by replacing the current text by the
* selected item. Subclasses should override this method to avoid replacing
* the whole content of the edit box.</p>
*
* @param text the selected suggestion in the drop down list
*/
protected void replaceText(CharSequence text) {
clearComposingText();
setText(text);
// make sure we keep the caret at the end of the text view
Editable spannable = getText();
Selection.setSelection(spannable, spannable.length());
}
use of android.text.Editable in project android_frameworks_base by ResurrectionRemix.
the class MultiAutoCompleteTextView method performValidation.
/**
* Instead of validating the entire text, this subclass method validates
* each token of the text individually. Empty tokens are removed.
*/
@Override
public void performValidation() {
Validator v = getValidator();
if (v == null || mTokenizer == null) {
return;
}
Editable e = getText();
int i = getText().length();
while (i > 0) {
int start = mTokenizer.findTokenStart(e, i);
int end = mTokenizer.findTokenEnd(e, start);
CharSequence sub = e.subSequence(start, end);
if (TextUtils.isEmpty(sub)) {
e.replace(start, i, "");
} else if (!v.isValid(sub)) {
e.replace(start, i, mTokenizer.terminateToken(v.fixText(sub)));
}
i = start;
}
}
use of android.text.Editable in project android_frameworks_base by ResurrectionRemix.
the class MultiAutoCompleteTextView method replaceText.
/**
* <p>Performs the text completion by replacing the range from
* {@link Tokenizer#findTokenStart} to {@link #getSelectionEnd} by the
* the result of passing <code>text</code> through
* {@link Tokenizer#terminateToken}.
* In addition, the replaced region will be marked as an AutoText
* substition so that if the user immediately presses DEL, the
* completion will be undone.
* Subclasses may override this method to do some different
* insertion of the content into the edit box.</p>
*
* @param text the selected suggestion in the drop down list
*/
@Override
protected void replaceText(CharSequence text) {
clearComposingText();
int end = getSelectionEnd();
int start = mTokenizer.findTokenStart(getText(), end);
Editable editable = getText();
String original = TextUtils.substring(editable, start, end);
QwertyKeyListener.markAsReplaced(editable, start, end, original);
editable.replace(start, end, mTokenizer.terminateToken(text));
}
use of android.text.Editable in project android_frameworks_base by ResurrectionRemix.
the class MultiAutoCompleteTextView method enoughToFilter.
/**
* Instead of filtering whenever the total length of the text
* exceeds the threshhold, this subclass filters only when the
* length of the range from
* {@link Tokenizer#findTokenStart} to {@link #getSelectionEnd}
* meets or exceeds {@link #getThreshold}.
*/
@Override
public boolean enoughToFilter() {
Editable text = getText();
int end = getSelectionEnd();
if (end < 0 || mTokenizer == null) {
return false;
}
int start = mTokenizer.findTokenStart(text, end);
if (end - start >= getThreshold()) {
return true;
} else {
return false;
}
}
use of android.text.Editable 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("");
}
});
}
Aggregations