List of usage examples for android.text TextWatcher TextWatcher
TextWatcher
From source file:org.anhonesteffort.flock.SubscriptionStripeFragment.java
private void initCardNumberHelper() { final EditText cardNumberView = (EditText) subscriptionActivity.findViewById(R.id.card_number); final EditText cardExpirationView = (EditText) subscriptionActivity.findViewById(R.id.card_expiration); cardNumberView.setOnTouchListener(new View.OnTouchListener() { @Override/*from w w w. ja v a2 s. co m*/ public boolean onTouch(View v, MotionEvent event) { if (cardNumberView.getText() != null && cardNumberView.getText().toString().contains("*")) { cardNumberView.setText(""); } return false; } }); if (cardNumberTextWatcher != null) cardNumberView.removeTextChangedListener(cardNumberTextWatcher); cardNumberTextWatcher = new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { String cardNumber = s.toString().replace(" ", ""); String formattedCardNumber = ""; for (int i = 0; i < cardNumber.length(); i++) { if (i > 0 && i % 4 == 0) formattedCardNumber += " "; formattedCardNumber += cardNumber.charAt(i); } cardNumberView.removeTextChangedListener(this); cardNumberView.setText(formattedCardNumber); cardNumberView.setSelection(formattedCardNumber.length()); cardNumberView.addTextChangedListener(this); if (!cardNumber.contains("*") && cardNumber.length() == 16) cardExpirationView.requestFocus(); } }; cardNumberView.addTextChangedListener(cardNumberTextWatcher); }
From source file:cn.ucai.superwechat.fragments.ContactlistFragment.java
private void setQueryTextChangedListener() { query.addTextChangedListener(new TextWatcher() { public void onTextChanged(CharSequence s, int start, int before, int count) { adapter.getFilter().filter(s); if (s.length() > 0) { clearSearch.setVisibility(View.VISIBLE); } else { clearSearch.setVisibility(View.INVISIBLE); }//from w ww . ja v a2 s.com } public void beforeTextChanged(CharSequence s, int start, int count, int after) { } public void afterTextChanged(Editable s) { } }); }
From source file:eu.operando.operandoapp.filters.domain.DomainFiltersActivity.java
@OnClick(R.id.add_filter) public void addFilter() { if (viewSelected == 0) { //User Filter View dialogView = getLayoutInflater().inflate(R.layout.user_domain_filter_dialog, null); final EditText input = (EditText) dialogView.findViewById(R.id.filter_content); final CheckBox isWildcard = (CheckBox) dialogView.findViewById(R.id.is_wildcard); AlertDialog.Builder builder = new AlertDialog.Builder(this).setTitle("New DomainFilter") .setView(dialogView)// w w w . j ava2s. c o m .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { DomainFilter domainFilter = new DomainFilter(); domainFilter.setContent(input.getText().toString().toLowerCase()); domainFilter.setSource(null); domainFilter.setIsWildcard(isWildcard.isChecked()); db.createDomainFilter(domainFilter); updateFiltersList(); userDomainFiltersAdapter.notifyItemInserted(userFilters.size() - 1); recyclerView.scrollToPosition(userFilters.size() - 1); } }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // Canceled. } }); final AlertDialog dialog = builder.create(); input.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable s) { if (Patterns.DOMAIN_NAME.matcher(s).matches()) { dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(true); } else dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false); } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } }); dialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false); } }); dialog.show(); } else { //Imported filter list final EditText input = new EditText(this); input.setSingleLine(true); //input.setHint("Enter URL"); input.setText(DatabaseHelper.serverUrl + "/blocked_urls"); new AlertDialog.Builder(this).setTitle("Import filters from remote file (hosts file format)") .setView(input).setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { final String importUrl = input.getText().toString(); long start = System.currentTimeMillis(); importExternalFilters(importUrl); long end = System.currentTimeMillis(); Toast.makeText(DomainFiltersActivity.this, (end - start) + "ms required", Toast.LENGTH_LONG).show(); } }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // Canceled. } }).show(); } }
From source file:android.support.designox.widget.TextInputLayout.java
private void setEditText(EditText editText) { // If we already have an EditText, throw an exception if (mEditText != null) { throw new IllegalArgumentException("We already have an EditText, can only have one"); }//from w ww.ja v a2 s.c o m if (!(editText instanceof TextInputEditText)) { Log.i(LOG_TAG, "EditText added is not a TextInputEditText. Please switch to using that" + " class instead."); } mEditText = editText; // Use the EditText's typeface, and it's text size for our expanded text mCollapsingTextHelper.setTypefaces(mEditText.getTypeface()); mCollapsingTextHelper.setExpandedTextSize(mEditText.getTextSize()); mCollapsingTextHelper.setExpandedTextGravity(mEditText.getGravity()); // Add a TextWatcher so that we know when the text input has changed mEditText.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable s) { updateLabelState(true); if (mCounterEnabled) { updateCounter(s.length()); } } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } }); // Use the EditText's hint colors if we don't have one set if (mDefaultTextColor == null) { mDefaultTextColor = mEditText.getHintTextColors(); } // If we do not have a valid hint, try and retrieve it from the EditText, if enabled if (mHintEnabled && TextUtils.isEmpty(mHint)) { setHint(mEditText.getHint()); // Clear the EditText's hint as we will display it ourselves mEditText.setHint(null); } if (mCounterView != null) { updateCounter(mEditText.getText().length()); } if (mIndicatorArea != null) { adjustIndicatorPadding(); } // Update the label visibility with no animation updateLabelState(false); }
From source file:com.kiva.ohmylinux.MainActivity.java
private void initView() { Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);/* ww w .ja v a 2 s .c o m*/ logScrollView = (ScrollView) findViewById(R.id.mainLogScrollView); logTextView = (AppCompatTextView) findViewById(R.id.mainLogText); L.setLogCallback(this); floatingButton = (FloatingActionButton) findViewById(R.id.fab); floatingButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (status == STATUS_NORMAL) { final String[] items = getResources().getStringArray(R.array.fab_actions); new AlertDialog.Builder(MainActivity.this).setTitle(R.string.action_new) .setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { switch (which) { case 0: // new iamge doCreateNewImage(); break; case 1: // new profile doCreateNewProfile(); break; } } }).setPositiveButton(android.R.string.no, null).show(); } else if (status == STATUS_EDITING) { doClose(); } } }); drawer = (DrawerLayout) findViewById(R.id.mainDrawerLayout); drawerToggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.drawer_open, R.string.drawer_close); drawerToggle.setDrawerIndicatorEnabled(true); drawer.setDrawerListener(new DrawerLayout.DrawerListener() { @Override public void onDrawerSlide(View drawerView, float slideOffset) { drawerToggle.onDrawerSlide(drawerView, slideOffset); } @Override public void onDrawerOpened(View drawerView) { drawerToggle.onDrawerOpened(drawerView); floatingButton.hide(); if (drawer.isDrawerOpen(GravityCompat.START)) { if (profileListAdapter.getCount() == 0) { setTitle(R.string.no_profile); } else { setTitle(R.string.profiles); } } else if (drawer.isDrawerOpen(GravityCompat.END)) { setTitle(R.string.log_console); } } @Override public void onDrawerClosed(View drawerView) { drawerToggle.onDrawerClosed(drawerView); floatingButton.show(); if (!drawer.isDrawerOpen(GravityCompat.START) && !drawer.isDrawerOpen(GravityCompat.END)) { setTitle(R.string.app_name); } } @Override public void onDrawerStateChanged(int newState) { drawerToggle.onDrawerStateChanged(newState); } }); drawerToggle.syncState(); profileListView = (ListView) findViewById(R.id.mainProfileListView); profileListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { drawer.closeDrawer(GravityCompat.START); LinuxProfile profile = (LinuxProfile) profileListAdapter.getItem(position); doSelectProfile(profile); } }); profileListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { LinuxProfile profile = (LinuxProfile) profileListAdapter.getItem(position); doShowOptions(profile); return true; } }); editLayout = (LinearLayout) findViewById(R.id.mainEditLayout); defaultLayout = (LinearLayout) findViewById(R.id.mainDefaultLayout); editNickName = (AppCompatEditText) findViewById(R.id.mainEditNickName); editDevicePath = (AppCompatEditText) findViewById(R.id.mainEditDevicePath); editMountPoint = (AppCompatEditText) findViewById(R.id.mainEditMountPoint); editDiskTableFile = (AppCompatEditText) findViewById(R.id.mainEditDiskTableFile); editInitProgram = (AppCompatEditText) findViewById(R.id.mainEditInitProgram); editInitProgramArgs = (AppCompatEditText) findViewById(R.id.mainEditInitProgramArgs); editFindDevicePath = (AppCompatButton) findViewById(R.id.mainEditFindDevicePath); editFindDiskTableFile = (AppCompatButton) findViewById(R.id.mainEditFindDiskTableFile); editMountSd0 = (AppCompatCheckBox) findViewById(R.id.mainEditMountSd0); editMountSd1 = (AppCompatCheckBox) findViewById(R.id.mainEditMountSd1); editFsType = (FileSystemTypeSpinner) findViewById(R.id.mainEditFsType); editNickName.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { if (currentProfile == null) { return; } String newName = editNickName.getText().toString(); if (newName.isEmpty()) { return; } currentProfile.setNickName(newName); editMountPoint.setText(currentProfile.getMountPoint()); } }); editFindDevicePath.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AppUtils.openFileBrowser(MainActivity.this, REQ_FIND_DEVICE_PATH); } }); editFindDiskTableFile.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AppUtils.openFileBrowser(MainActivity.this, REQ_FIND_DISK_TABLE); } }); }
From source file:com.qiscus.sdk.ui.fragment.QiscusBaseChatFragment.java
protected void onLoadView(View view) { rootView = getRootView(view);// ww w . j av a 2s . c o m emptyChatHolder = getEmptyChatHolder(view); swipeRefreshLayout = getSwipeRefreshLayout(view); messageRecyclerView = getMessageRecyclerView(view); messageInputPanel = getMessageInputPanel(view); messageEditTextContainer = getMessageEditTextContainer(view); messageEditText = getMessageEditText(view); sendButton = getSendButton(view); newMessageButton = getNewMessageButton(view); loadMoreProgressBar = getLoadMoreProgressBar(view); emptyChatImageView = getEmptyChatImageView(view); emptyChatTitleView = getEmptyChatTitleView(view); emptyChatDescView = getEmptyChatDescView(view); attachmentPanel = getAttachmentPanel(view); hideAttachmentButton = getHideAttachmentButton(view); addImageLayout = getAddImageLayout(view); addImageButton = getAddImageButton(view); addImageTextView = getAddImageTextView(view); takeImageLayout = getTakeImageLayout(view); takeImageButton = getTakeImageButton(view); takeImageTextView = getTakeImageTextView(view); addFileLayout = getAddFileLayout(view); addFileButton = getAddFileButton(view); addFileTextView = getAddFileTextView(view); recordAudioLayout = getRecordAudioLayout(view); recordAudioButton = getRecordAudioButton(view); recordAudioTextView = getRecordAudioTextView(view); toggleEmojiButton = getToggleEmojiButton(view); recordAudioPanel = getRecordAudioPanel(view); if (toggleEmojiButton != null && !(messageEditText instanceof EmojiEditText)) { throw new RuntimeException( "Please use EmojiEditText as message text field if you want to using EmojiKeyboard."); } messageEditText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { onMessageEditTextChanged(s); } @Override public void afterTextChanged(Editable s) { } }); messageEditText.setOnClickListener(v -> { if (emojiPopup != null && emojiPopup.isShowing()) { toggleEmoji(); } }); sendButton.setOnClickListener(v -> { String message = messageEditText.getText().toString().trim(); if (message.isEmpty()) { showAttachmentPanel(); } else { sendMessage(message); } }); if (newMessageButton != null) { newMessageButton.setOnClickListener(v -> scrollToBottom()); } if (addImageButton != null) { addImageButton.setOnClickListener(v -> addImage()); } if (takeImageButton != null) { takeImageButton.setOnClickListener(v -> takeImage()); } if (addFileButton != null) { addFileButton.setOnClickListener(v -> addFile()); } if (recordAudioButton != null) { recordAudioButton.setOnClickListener(v -> recordAudio()); } if (toggleEmojiButton != null) { toggleEmojiButton.setOnClickListener(v -> toggleEmoji()); } if (hideAttachmentButton != null) { hideAttachmentButton.setOnClickListener(v -> hideAttachmentPanel()); } if (recordAudioPanel != null) { recordAudioPanel.setRecordListener(this); } }
From source file:com.b44t.ui.PasscodeActivity.java
@Override public View createView(Context context) { actionBar//from w ww . ja v a 2s . c o m .setBackButtonImage(screen == SCREEN0_SETTINGS ? R.drawable.ic_ab_back : R.drawable.ic_close_white); actionBar.setAllowOverlayTitle(false); actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() { @Override public void onItemClick(int id) { if (id == -1) { finishFragment(); } else if (id == done_button) { if (passcodeSetStep == 0) { processNext(); } else if (passcodeSetStep == 1) { processDone(); } } else if (id == pin_item) { currentPasswordType = 0; updateDropDownTextView(); } else if (id == password_item) { currentPasswordType = 1; updateDropDownTextView(); } } }); fragmentView = new FrameLayout(context); FrameLayout frameLayout = (FrameLayout) fragmentView; if (screen != SCREEN0_SETTINGS) { ActionBarMenu menu = actionBar.createMenu(); menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56)); titleTextView = new TextView(context); titleTextView.setTextColor(0xff757575); if (screen == SCREEN1_ENTER_CODE1) { if (UserConfig.passcodeHash.length() != 0) { titleTextView .setText(LocaleController.getString("EnterNewPasscode", R.string.EnterNewPasscode)); } else { titleTextView.setText( LocaleController.getString("EnterNewFirstPasscode", R.string.EnterNewFirstPasscode)); } } else { titleTextView .setText(LocaleController.getString("EnterCurrentPasscode", R.string.EnterCurrentPasscode)); } titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18); titleTextView.setGravity(Gravity.CENTER_HORIZONTAL); frameLayout.addView(titleTextView); FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) titleTextView.getLayoutParams(); layoutParams.width = LayoutHelper.WRAP_CONTENT; layoutParams.height = LayoutHelper.WRAP_CONTENT; layoutParams.gravity = Gravity.CENTER_HORIZONTAL; layoutParams.topMargin = AndroidUtilities.dp(38); titleTextView.setLayoutParams(layoutParams); passwordEditText = new EditText(context); passwordEditText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20); passwordEditText.setTextColor(0xff000000); passwordEditText.setMaxLines(1); passwordEditText.setLines(1); passwordEditText.setGravity(Gravity.CENTER_HORIZONTAL); passwordEditText.setSingleLine(true); if (screen == SCREEN1_ENTER_CODE1) { passcodeSetStep = 0; passwordEditText.setImeOptions(EditorInfo.IME_ACTION_NEXT); } else { passcodeSetStep = 1; passwordEditText.setImeOptions(EditorInfo.IME_ACTION_DONE); } passwordEditText.setTransformationMethod(PasswordTransformationMethod.getInstance()); passwordEditText.setTypeface(Typeface.DEFAULT); AndroidUtilities.clearCursorDrawable(passwordEditText); frameLayout.addView(passwordEditText); layoutParams = (FrameLayout.LayoutParams) passwordEditText.getLayoutParams(); layoutParams.topMargin = AndroidUtilities.dp(90); layoutParams.height = AndroidUtilities.dp(36); layoutParams.leftMargin = AndroidUtilities.dp(40); layoutParams.gravity = Gravity.TOP | Gravity.LEFT; layoutParams.rightMargin = AndroidUtilities.dp(40); layoutParams.width = LayoutHelper.MATCH_PARENT; passwordEditText.setLayoutParams(layoutParams); passwordEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) { if (passcodeSetStep == 0) { processNext(); return true; } else if (passcodeSetStep == 1) { processDone(); return true; } return false; } }); passwordEditText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { if (passwordEditText.length() == 4) { if (screen == SCREEN2_ENTER_CODE2 && UserConfig.passcodeType == 0) { processDone(); } else if (screen == SCREEN1_ENTER_CODE1 && currentPasswordType == 0) { if (passcodeSetStep == 0) { processNext(); } else if (passcodeSetStep == 1) { processDone(); } } } } }); passwordEditText.setCustomSelectionActionModeCallback(new ActionMode.Callback() { public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } public void onDestroyActionMode(ActionMode mode) { } public boolean onCreateActionMode(ActionMode mode, Menu menu) { return false; } public boolean onActionItemClicked(ActionMode mode, MenuItem item) { return false; } }); if (screen == SCREEN1_ENTER_CODE1) { dropDownContainer = new ActionBarMenuItem(context, menu, 0); dropDownContainer.setSubMenuOpenSide(1); dropDownContainer.addSubItem(pin_item, LocaleController.getString("PasscodePIN", R.string.PasscodePIN), 0); dropDownContainer.addSubItem(password_item, LocaleController.getString("PasscodePassword", R.string.PasscodePassword), 0); actionBar.addView(dropDownContainer); layoutParams = (FrameLayout.LayoutParams) dropDownContainer.getLayoutParams(); layoutParams.height = LayoutHelper.MATCH_PARENT; layoutParams.width = LayoutHelper.WRAP_CONTENT; layoutParams.rightMargin = AndroidUtilities.dp(40); layoutParams.leftMargin = AndroidUtilities.isTablet() ? AndroidUtilities.dp(64) : AndroidUtilities.dp(56); layoutParams.gravity = Gravity.TOP | Gravity.LEFT; dropDownContainer.setLayoutParams(layoutParams); dropDownContainer.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { dropDownContainer.toggleSubMenu(); } }); dropDown = new TextView(context); dropDown.setGravity(Gravity.LEFT); dropDown.setSingleLine(true); dropDown.setLines(1); dropDown.setMaxLines(1); dropDown.setEllipsize(TextUtils.TruncateAt.END); dropDown.setTextColor(0xffffffff); dropDown.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_arrow_drop_down, 0); dropDown.setCompoundDrawablePadding(AndroidUtilities.dp(4)); dropDown.setPadding(0, 0, AndroidUtilities.dp(10), 0); dropDownContainer.addView(dropDown); layoutParams = (FrameLayout.LayoutParams) dropDown.getLayoutParams(); layoutParams.width = LayoutHelper.WRAP_CONTENT; layoutParams.height = LayoutHelper.WRAP_CONTENT; layoutParams.leftMargin = AndroidUtilities.dp(16); layoutParams.gravity = Gravity.CENTER_VERTICAL; layoutParams.bottomMargin = AndroidUtilities.dp(1); dropDown.setLayoutParams(layoutParams); } else { actionBar.setTitle(LocaleController.getString("Passcode", R.string.Passcode)); } updateDropDownTextView(); } else { actionBar.setTitle(LocaleController.getString("Passcode", R.string.Passcode)); frameLayout.setBackgroundColor(0xfff0f0f0); listView = new ListView(context); listView.setDivider(null); listView.setDividerHeight(0); listView.setVerticalScrollBarEnabled(false); listView.setDrawSelectorOnTop(true); frameLayout.addView(listView); FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams(); layoutParams.width = LayoutHelper.MATCH_PARENT; layoutParams.height = LayoutHelper.MATCH_PARENT; layoutParams.gravity = Gravity.TOP; listView.setLayoutParams(layoutParams); listView.setAdapter(listAdapter = new ListAdapter(context)); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) { if (i == changePasscodeRow) { presentFragment(new PasscodeActivity(SCREEN1_ENTER_CODE1)); } else if (i == passcodeOnOffRow) { TextCheckCell cell = (TextCheckCell) view; if (UserConfig.passcodeHash.length() != 0) { UserConfig.passcodeHash = ""; UserConfig.appLocked = false; UserConfig.saveConfig(false); int count = listView.getChildCount(); for (int a = 0; a < count; a++) { View child = listView.getChildAt(a); if (child instanceof TextSettingsCell) { TextSettingsCell textCell = (TextSettingsCell) child; textCell.setTextColor(0xffc6c6c6); break; } } cell.setChecked(UserConfig.passcodeHash.length() != 0); NotificationCenter.getInstance() .postNotificationName(NotificationCenter.didSetPasscode); } else { presentFragment(new PasscodeActivity(SCREEN1_ENTER_CODE1)); } } else if (i == autoLockRow) { if (getParentActivity() == null) { return; } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AutoLock", R.string.AutoLock)); final NumberPicker numberPicker = new NumberPicker(getParentActivity()); numberPicker.setMinValue(0); numberPicker.setMaxValue(4); if (UserConfig.autoLockIn == 0) { numberPicker.setValue(0); } else if (UserConfig.autoLockIn == 60) { numberPicker.setValue(1); } else if (UserConfig.autoLockIn == 60 * 5) { numberPicker.setValue(2); } else if (UserConfig.autoLockIn == 60 * 60) { numberPicker.setValue(3); } else if (UserConfig.autoLockIn == 60 * 60 * 5) { numberPicker.setValue(4); } numberPicker.setFormatter(new NumberPicker.Formatter() { @Override public String format(int value) { if (value == 0) { return LocaleController.getString("Disabled", R.string.Disabled); } else if (value == 1) { return ApplicationLoader.applicationContext.getResources() .getQuantityString(R.plurals.Minutes, 1, 1); } else if (value == 2) { return ApplicationLoader.applicationContext.getResources() .getQuantityString(R.plurals.Minutes, 5, 5); } else if (value == 3) { return ApplicationLoader.applicationContext.getResources() .getQuantityString(R.plurals.Hours, 1, 1); } else if (value == 4) { return ApplicationLoader.applicationContext.getResources() .getQuantityString(R.plurals.Hours, 5, 5); } return ""; } }); numberPicker.setWrapSelectorWheel(false); builder.setView(numberPicker); builder.setNegativeButton(LocaleController.getString("Done", R.string.Done), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { which = numberPicker.getValue(); if (which == 0) { UserConfig.autoLockIn = 0; } else if (which == 1) { UserConfig.autoLockIn = 60; } else if (which == 2) { UserConfig.autoLockIn = 60 * 5; } else if (which == 3) { UserConfig.autoLockIn = 60 * 60; } else if (which == 4) { UserConfig.autoLockIn = 60 * 60 * 5; } listView.invalidateViews(); UserConfig.saveConfig(false); } }); showDialog(builder.create()); } else if (i == fingerprintRow) { UserConfig.useFingerprint = !UserConfig.useFingerprint; UserConfig.saveConfig(false); ((TextCheckCell) view).setChecked(UserConfig.useFingerprint); } } }); } return fragmentView; }
From source file:com.minsheng.app.xunchedai.loan.activities.AddLoanActivity.java
/** * ?/* www. j av a2s .co m*/ */ private void initView() { httpUtils = new HttpUtils(); loan = new Loan(); db = DBManager.dbUtils(this); pwTime = new TimePopupWindow(this, TimePopupWindow.Type.YEAR_MONTH_DAY, this); format = new SimpleDateFormat("yyyy-MM-dd"); format.setLenient(false); list_scheme = new ArrayList<>(); intent_before = getIntent(); loan_id = intent_before.getStringExtra("loan_id"); str_installment = intent_before.getStringExtra("installment"); //loan_id, is_new = TextUtils.isEmpty(loan_id); //?? is_from_index = !TextUtils.isEmpty(str_installment); //???? is_draft = intent_before.getBooleanExtra("is_draft", false); showView(); iv_back.setVisibility(View.VISIBLE); ll_add_warranty.setOnClickListener(this); ll_add_invoice.setOnClickListener(this); ll_add_care_card.setOnClickListener(this); ll_add_idcard1.setOnClickListener(this); ll_add_idcard2.setOnClickListener(this); ll_add_bankcard1.setOnClickListener(this); ll_add_bankcard2.setOnClickListener(this); ll_add_license.setOnClickListener(this); ll_add_agreement_apply.setOnClickListener(this); ll_add_agreement_entrust.setOnClickListener(this); ll_add_agreement_transfer.setOnClickListener(this); tv_save.setOnClickListener(this); //et_insurance_amount ll_parent.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { ll_parent.setFocusable(true); ll_parent.setFocusableInTouchMode(true); ll_parent.requestFocus(); return false; } }); //???? et_insurance_amount.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (!hasFocus) { countLoanMount(); } } }); //???? tv_protection_date.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { countLoanMount(); } }); //? pwTime.setOnTimeSelectListener(new TimePopupWindow.OnTimeSelectListener() { @Override public void onTimeSelect(Date date) { tv_protection_date.setText(getTime(date)); tv_protection_date.setTextColor(ContextCompat.getColor(getBaseContext(), R.color.gray_3)); } }); }
From source file:cn.studyjams.s2.sj0132.bowenyan.mygirlfriend.nononsenseapps.notepad.ui.editor.TaskDetailFragment.java
void setListeners() { if (dontLoad) { return;/*from www.ja v a2 s. c o m*/ } taskText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { setShareIntent(s.toString()); } }); }
From source file:com.google.firebase.codelab.friendlychat.activity.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); // Set default username is anonymous. mUsername = ANONYMOUS;// w w w . java2 s .co m // Initialize Firebase Auth mFirebaseAuth = FirebaseAuth.getInstance(); mFirebaseUser = mFirebaseAuth.getCurrentUser(); if (mFirebaseUser == null) { // Not signed in, launch the Sign In activity startActivity(new Intent(this, SignInActivity.class)); finish(); return; } else { mUsername = mFirebaseUser.getDisplayName(); if (mFirebaseUser.getPhotoUrl() != null) { mPhotoUrl = mFirebaseUser.getPhotoUrl().toString(); } } mGoogleApiClient = new GoogleApiClient.Builder(this) .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */) .addApi(Auth.GOOGLE_SIGN_IN_API).addApi(AppInvite.API).build(); // Initialize ProgressBar and RecyclerView. mProgressBar = (ProgressBar) findViewById(R.id.progressBar); mMessageRecyclerView = (RecyclerView) findViewById(R.id.messageRecyclerView); mLinearLayoutManager = new LinearLayoutManager(this); mLinearLayoutManager.setStackFromEnd(true); mMessageRecyclerView.setLayoutManager(mLinearLayoutManager); mProgressBar.setVisibility(ProgressBar.INVISIBLE); // New child entries mFirebaseDatabaseReference = FirebaseDatabase.getInstance().getReference(); mFirebaseAdapter = new FirebaseRecyclerAdapter<FriendlyMessage, MessageViewHolder>(FriendlyMessage.class, R.layout.item_message, MessageViewHolder.class, mFirebaseDatabaseReference.child(MESSAGES_CHILD)) { @Override protected FriendlyMessage parseSnapshot(DataSnapshot snapshot) { FriendlyMessage friendlyMessage = super.parseSnapshot(snapshot); if (friendlyMessage != null) { friendlyMessage.setId(snapshot.getKey()); } return friendlyMessage; } @Override protected void populateViewHolder(MessageViewHolder viewHolder, FriendlyMessage friendlyMessage, int position) { mProgressBar.setVisibility(ProgressBar.INVISIBLE); viewHolder.messageTextView.setText(friendlyMessage.getText()); viewHolder.messengerTextView.setText(friendlyMessage.getName()); if (friendlyMessage.getPhotoUrl() == null) { viewHolder.messengerImageView.setImageDrawable( ContextCompat.getDrawable(MainActivity.this, R.drawable.ic_account_circle_black_36dp)); } else { Glide.with(MainActivity.this).load(friendlyMessage.getPhotoUrl()) .into(viewHolder.messengerImageView); } // write this message to the on-device index FirebaseAppIndex.getInstance().update(getMessageIndexable(friendlyMessage)); // log a view action on it FirebaseUserActions.getInstance().end(getMessageViewAction(friendlyMessage)); } }; 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(); // If the recycler view is initially being loaded or the // user is at the bottom of the list, scroll 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); mMessageEditText = (TextView) findViewById(R.id.messageEditText); mMessageEditText.setFilters(new InputFilter[] { new InputFilter.LengthFilter( mSharedPreferences.getInt(CodelabPreferences.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) { // Send messages on click. FriendlyMessage friendlyMessage = new FriendlyMessage(mMessageEditText.getText().toString(), mUsername, mPhotoUrl); mFirebaseDatabaseReference.child(MESSAGES_CHILD).push().setValue(friendlyMessage); mMessageEditText.setText(""); } }); // 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(); mFirebaseAnalytics = FirebaseAnalytics.getInstance(this); mAdView = (AdView) findViewById(R.id.adView); AdRequest adRequest = new AdRequest.Builder().build(); mAdView.loadAd(adRequest); }