List of usage examples for android.text TextWatcher TextWatcher
TextWatcher
From source file:com.google.dotorg.crisisresponse.translationcards.RecordingActivity.java
private void moveToLabelStep() { setContentView(R.layout.recording_label); recycleBitmap();/*from w w w . j a v a2 s. c o m*/ currentBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.recording_label_image); currentBitmapView = (ImageView) findViewById(R.id.recording_label_image); currentBitmapView.setImageBitmap(currentBitmap); final EditText labelField = (EditText) findViewById(R.id.recording_label_field); if (label != null) { labelField.setText(label); labelField.setTextColor(Color.BLACK); labelField.setSelection(label.length()); setLabelNextButtonEnabled(true); } if (inEditMode) { ImageView deleteButton = (ImageView) findViewById(R.id.recording_label_delete_image); deleteButton.setVisibility(View.VISIBLE); deleteButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { DbManager dbm = new DbManager(RecordingActivity.this); dbm.deleteTranslation(translationId); if (!isAsset) { File oldFile = new File(filename); oldFile.delete(); if (!savedIsAsset && (savedFilename != null) && !savedFilename.equals(filename)) { oldFile = new File(savedFilename); oldFile.delete(); } } setResult(RESULT_OK); finish(); } }); findViewById(R.id.recording_label_step_marker).setVisibility(View.GONE); } labelField.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus && labelField.getText().toString().equals(getString(R.string.recording_label_hint_text))) { labelField.setText(""); labelField.setTextColor(Color.BLACK); } else if (!hasFocus && labelField.getText().toString().equals("")) { labelField.setText(getString(R.string.recording_label_hint_text)); labelField.setTextColor(getResources().getColor(R.color.borderColor)); } if (hasFocus) { InputMethodManager inputMethodManager = (InputMethodManager) getSystemService( Context.INPUT_METHOD_SERVICE); inputMethodManager.toggleSoftInputFromWindow(labelField.getApplicationWindowToken(), InputMethodManager.SHOW_FORCED, 0); } } }); labelField.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { // Do nothing here. } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { if (s.length() != 0 && !s.equals(getString(R.string.recording_label_hint_text))) { setLabelNextButtonEnabled(true); } else { setLabelNextButtonEnabled(false); } } @Override public void afterTextChanged(Editable s) { // Do nothing here. } }); View nextButton = (View) findViewById(R.id.recording_label_next); nextButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { label = labelField.getText().toString(); if (label.length() == 0 || label.equals(getString(R.string.recording_label_hint_text))) { return; } moveToAudioStep(); } }); stepHistory.push(Step.LABEL); }
From source file:com.daul.chat.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;/*ww w .ja va2s. c om*/ 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); //Initialize Firebase Analytics. mFirebaseAnalytics = FirebaseAnalytics.getInstance(this); //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(); // 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 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); } } }; 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 (lastVisiblePosition == -1 || (positionStart >= (friendlyMessageCount - 1) && lastVisiblePosition == (positionStart - 1))) { mMessageRecyclerView.scrollToPosition(positionStart); } } }); mMessageRecyclerView.setLayoutManager(mLinearLayoutManager); mMessageRecyclerView.setAdapter(mFirebaseAdapter); mMessageEditText = (EditText) 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(""); } }); mAdView = (AdView) findViewById(R.id.adView); AdRequest adRequest = new AdRequest.Builder().build(); mAdView.loadAd(adRequest); }
From source file:com.hugo.actfinder.ChatActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_chat); mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); //mUsername = ANONYMOUS; // 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();/* ww w . ja v a 2 s .c o m*/ return; } else { mUsername = mFirebaseUser.getDisplayName(); mPhotoUrl = mFirebaseUser.getPhotoUrl().toString(); } mGoogleApiClient = new GoogleApiClient.Builder(this) .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */) .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<FriendlyMessage, MessageViewHolder>(FriendlyMessage.class, R.layout.item_message, MessageViewHolder.class, mFirebaseDatabaseReference.child(MESSAGES_CHILD)) { @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(ChatActivity.this, R.drawable.ic_account_circle_black_36dp)); } else { Glide.with(ChatActivity.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(); // 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); // Initialize and request AdMob ad. mAdView = (AdView) findViewById(R.id.adView); AdRequest adRequest = new AdRequest.Builder().build(); mAdView.loadAd(adRequest); // Initialize Firebase Measurement. mFirebaseAnalytics = FirebaseAnalytics.getInstance(this); // 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(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) { FriendlyMessage friendlyMessage = new FriendlyMessage(mMessageEditText.getText().toString(), mUsername, mPhotoUrl); mFirebaseDatabaseReference.child(MESSAGES_CHILD).push().setValue(friendlyMessage); mMessageEditText.setText(""); mFirebaseAnalytics.logEvent(MESSAGE_SENT_EVENT, null); } }); }
From source file:cn.count.easydrive366.insurance.BuyInsuranceStep2.java
private void process_data(final String result) { JSONObject json = AppSettings.getSuccessJSON(result, this); if (json != null) { try {/*from ww w . j ava 2 s .co m*/ String d = json.getString("registration_date").trim(); if (!d.isEmpty() && d.length() > 10) d = d.substring(0, 10); edt_license.setText(json.getString("car_id")); edt_vin.setText(json.getString("vin")); edt_engine_no.setText(json.getString("engine_no")); edt_init_date.setText(d); edt_owner.setText(json.getString("owner_name")); edt_name.setText(json.getString("name")); edt_identity.setText(json.getString("license_id")); edt_cellphone.setText(json.getString("phone")); edt_owner_license.setText(json.getString("owner_license")); edt_owner_phone.setText(json.getString("owner_phone")); edt_hoder.setText(json.getString("policy_hoder")); edt_hoder_license.setText(json.getString("policy_hoder_license")); chb_hoder.setChecked(true); chb_buyer.setChecked(true); chb_hoder.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { hoder_checked(); } }); chb_buyer.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { buyer_checked(); } }); edt_owner.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 (chb_hoder.isChecked()) { edt_hoder.setText(edt_owner.getText().toString()); } if (chb_buyer.isChecked()) { edt_name.setText(edt_owner.getText().toString()); } } }); edt_owner_license.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 (chb_hoder.isChecked()) { edt_hoder_license.setText(edt_owner_license.getText().toString()); } if (chb_buyer.isChecked()) { edt_identity.setText(edt_owner_license.getText().toString()); } } }); edt_owner_phone.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 (chb_buyer.isChecked()) { edt_cellphone.setText(edt_owner_phone.getText().toString()); } } }); } catch (Exception e) { log(e); } } }
From source file:no.ntnu.idi.socialhitchhiking.map.MapActivityCreateOrEditRoute.java
/** * Constructor//from w ww .j av a2 s. c o m */ @Override protected void onCreate(Bundle icicle) { super.onCreate(icicle); acList = new ArrayList<InitDestFrame>(); r = getResources(); //Calls the initAutoComplete method, adding the autocomplete listeners to acTo and acFrom initAutocomplete(); //Calls the initAddDestButton method, adding the driving through button initAddDestButton(); //Sets hasDrawn to false hasDrawn = false; Bundle extras = getIntent().getExtras(); if (extras != null) { inEditMode = extras.getBoolean("editMode"); positionOfRoute = extras.getInt("routePosition"); } //Hides the checkbox chk_saveRoute = (CheckBox) findViewById(R.id.checkBoxSave); chk_saveRoute.setVisibility(8); //Initialises the draw/next button final Button button = ((Button) findViewById(R.id.btnChooseRoute)); //Adjustments to the gui if in editmode if (inEditMode) { chk_saveRoute.setVisibility(View.GONE); button.setText("Update the route"); button.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1f)); fillFieldsInEdit(); button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { createInputDialog("Route", "Insert name of Route", false); } }); } else { button.setText("Show on map"); button.setEnabled(false); } //Initialises the textviews and the clear buttons final AutoCompleteTextView acFrom = (AutoCompleteTextView) findViewById(R.id.etGoingFrom); final AutoCompleteTextView acTo = (AutoCompleteTextView) findViewById(R.id.etGoingTo); ImageView bClearFrom = ((ImageView) findViewById(R.id.etGoingFromClearIcon)); ImageView bClearTo = ((ImageView) findViewById(R.id.etGoingToClearIcon)); //If map is drawn fill the textviews if (selectedRoute.getMapPoints().size() != 0) { fillFieldsOnClick(); } /** * onClickListener on the clearButton on the acFrom field {@link OnClickListener()} */ //Adds onClickListener to the clearbutton on the acFrom field bClearFrom.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { acFrom.setText(""); button.setEnabled(false); button.setText("Show on Map"); } }); /** * onClickListener on the clearButton on the acTo field {@link OnClickListener} */ //Adds onClickListener to the clearbutton on the acTo field bClearTo.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { acTo.setText(""); button.setEnabled(false); button.setText("Show on Map"); } }); /** * TextWatcher to the acFrom {@link autoCompleteTextView} autoCompleteTextView {@link TextWatcher()} */ //Adds a TextWatcher to the acFrom field, to update the draw/nextbutton, and its functionality acFrom.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { hasDrawn = false; if (checkFields() && selectedRoute.getMapPoints().size() > 1 && hasDrawn == true) { button.setEnabled(true); button.setText("Next"); } else if (checkFields() && selectedRoute.getMapPoints().size() > 1 && hasDrawn == false) { button.setEnabled(true); button.setText("Show on Map"); } else if (checkFields() && selectedRoute.getMapPoints().size() == 0) { button.setEnabled(true); button.setText("Show on map"); } else if (checkFields() == false && selectedRoute.getMapPoints().size() == 0) { button.setText("Show on map"); button.setEnabled(false); } else if (inEditMode) { } else { button.setText("Show on map"); button.setEnabled(false); } } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { // TODO Auto-generated method stub } @Override public void afterTextChanged(Editable s) { // TODO Auto-generated method stub } }); /** * TextWatcher to the acTo {@link autoCompleteTextView} autoCompleteTextView {@link TextWatcher()} */ //Adds a TextWatcher to the acFrom field, to update the draw/nextbutton, and its functionality acTo.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { hasDrawn = false; if (checkFields() && selectedRoute.getMapPoints().size() > 2 && hasDrawn == true) { button.setEnabled(true); button.setText("Next"); } else if (checkFields() && selectedRoute.getMapPoints().size() > 2 && hasDrawn == false) { button.setEnabled(true); button.setText("Show on Map"); } else if (checkFields() && selectedRoute.getMapPoints().size() == 0) { button.setEnabled(true); button.setText("Show on map"); } else if (checkFields() == false && selectedRoute.getMapPoints().size() == 0) { button.setText("Show on map"); button.setEnabled(false); } else if (inEditMode) { } else { button.setText("Show on map"); button.setEnabled(false); } } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { // TODO Auto-generated method stub } @Override public void afterTextChanged(Editable s) { // TODO Auto-generated method stub } }); /** * onClickListener on the button(draw/next) {@link OnClickListener} */ //adds the onclickListener to the draw/next button button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0); if (checkFields() && selectedRoute.getMapPoints().size() > 1 && hasDrawn == true) { button.setText("Next"); createOneTimeJourney(); } else if (checkFields() && selectedRoute.getMapPoints().size() > 1 && hasDrawn == false) { mapView.getOverlays().clear(); createMap(); button.setText("Next"); } else if (checkFields() && selectedRoute.getMapPoints().size() == 0) { mapView.getOverlays().clear(); createMap(); button.setText("Next"); } else if (checkFields() == false && selectedRoute.getMapPoints().size() == 0) { } else if (inEditMode) { createInputDialog("Route", "Insert name of Route", false); button.setText("Next"); } else { } } }); }
From source file:com.openarc.nirmal.nestle.LoginActivity.java
private void initialize() { bLogin = (Button) findViewById(R.id.bLogin); actvUserName = (AutoCompleteTextView) findViewById(R.id.actvUserName); etPassword = (EditText) findViewById(R.id.etPassword); tilUserName = (TextInputLayout) findViewById(R.id.tilUserName); tilPassword = (TextInputLayout) findViewById(R.id.tilPassword); cbLoginRemember = (CheckBox) findViewById(R.id.cbLoginRemember); rlPb = (RelativeLayout) findViewById(R.id.rlPb); tvPb = (TextView) findViewById(R.id.tvPb); rlLogin = (RelativeLayout) findViewById(R.id.rlLogin); actvUserName.clearFocus();//from w w w . jav a2s. co m bLogin.setOnClickListener(bLogin_OnClick); actvUserName.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) { if (s.length() < 1) { tilUserName.setErrorEnabled(true); tilUserName.setError("Enter User Name"); } else if (s.length() > 0) { if (tilUserName.getError() != "") tilUserName.setError(null); tilUserName.invalidate(); tilUserName.setErrorEnabled(false); } } @Override public void afterTextChanged(Editable s) { } }); etPassword.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) { if (s.length() < 1) { tilPassword.setErrorEnabled(true); tilPassword.setError("Enter Password"); } else if (s.length() > 0) { if (tilPassword.getError() != "") tilPassword.setErrorEnabled(false); } } @Override public void afterTextChanged(Editable s) { } }); }
From source file:mp.paschalis.LoginFragment.java
/** * Enables Login/Register form//www . j a va 2 s . c om */ private void enableLoginForm() { textViewLibrary = (TextView) getSherlockActivity().findViewById(R.id.TextViewLoginLibraryName); textViewTitle = (TextView) getSherlockActivity().findViewById(R.id.TextViewLoginTitle); // textViewLibraryLocation = (TextView) getSherlockActivity().findViewById( // R.id.textViewLibraryLocation); buttonLogin = (Button) getSherlockActivity().findViewById(R.id.buttonLogin); editTextUsername = (EditText) getSherlockActivity().findViewById(R.id.editTextLoginUsername); editTextPassword = (EditText) getSherlockActivity().findViewById(R.id.editTextLoginPassword); textViewUsernameDirection = (TextView) getSherlockActivity() .findViewById(R.id.textViewDirectionLoginUsername); textViewPasswordDirection = (TextView) getSherlockActivity() .findViewById(R.id.textViewDirectionLoginPassword); final Button buttonLogin = (Button) getSherlockActivity().findViewById(R.id.buttonLogin); textViewLibrary.setEnabled(true); textViewTitle.setEnabled(true); textViewLibraryLocation.setEnabled(true); editTextUsername.setEnabled(true); textViewUsernameDirection.setEnabled(true); editTextUsername.setText(""); editTextPassword.setText(""); editTextUsername.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { // Clear Login Staff clearLoginStaff(); } @Override public void afterTextChanged(Editable s) { // Enable login button if (editTextUsername.getText().length() >= 4) { editTextPassword.setEnabled(true); textViewPasswordDirection.setEnabled(true); } else { editTextPassword.setEnabled(false); textViewPasswordDirection.setEnabled(false); editTextPassword.setText(""); } } }); editTextPassword.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { // Clear Login Staff clearLoginStaff(); } @Override public void afterTextChanged(Editable s) { if (editTextPassword.getText().length() > 0) { buttonLogin.setEnabled(true); } else buttonLogin.setEnabled(false); } }); // Login Button buttonLogin.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // Create new User app.user = new User(); app.user.username = editTextUsername.getText().toString(); app.user.password = editTextPassword.getText().toString(); // Hide Progress Bar, and reEnable button ProgressBar progressBarLoginButton = (ProgressBar) getSherlockActivity() .findViewById(R.id.progressBarLoginButton); Button buttonLogin = (Button) getSherlockActivity().findViewById(R.id.buttonLogin); buttonLogin.setClickable(false); buttonLogin.setEnabled(false); progressBarLoginButton.setVisibility(View.VISIBLE); // Login User new LoginAsyncTask().execute(app.library); } }); enableLoginFields(); }
From source file:com.adafruit.bluefruit.le.connect.app.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); activity = this; setContentView(R.layout.activity_main); // Init variables mBleManager = BleManager.getInstance(this); restoreRetainedDataFragment();/*from www. j a v a2 s . c o m*/ mPeripheralList = new PeripheralList(); // UI mScannedDevicesListView = (ExpandableHeightExpandableListView) findViewById(R.id.scannedDevicesListView); mScannedDevicesAdapter = new ExpandableListAdapter(); mScannedDevicesListView.setAdapter(mScannedDevicesAdapter); mScannedDevicesListView.setExpanded(true); mScannedDevicesListView.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() { @Override public void onGroupExpand(int groupPosition) { } }); mScanButton = (Button) findViewById(R.id.scanButton); mNoDevicesTextView = (TextView) findViewById(R.id.nodevicesTextView); mDevicesScrollView = (ScrollView) findViewById(R.id.devicesScrollView); mDevicesScrollView.setVisibility(View.GONE); mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipeRefreshLayout); mSwipeRefreshLayout.setOnRefreshListener(new OnRefreshListener() { @Override public void onRefresh() { mScannedDevices.clear(); startScan(null); mSwipeRefreshLayout.postDelayed(new Runnable() { @Override public void run() { mSwipeRefreshLayout.setRefreshing(false); } }, 500); } }); mFiltersPanelView = findViewById(R.id.filtersExpansionView); mFiltersExpandImageView = (ImageView) findViewById(R.id.filtersExpandImageView); mFiltersClearButton = (ImageButton) findViewById(R.id.filtersClearButton); mFiltersTitleTextView = (TextView) findViewById(R.id.filtersTitleTextView); mFiltersNameEditText = (EditText) findViewById(R.id.filtersNameEditText); mFiltersNameEditText.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) { String text = s.toString(); mPeripheralList.setFilterName(text); updateFilters(); } public void beforeTextChanged(CharSequence s, int start, int count, int after) { } public void onTextChanged(CharSequence s, int start, int before, int count) { } }); mFiltersRssiSeekBar = (SeekBar) findViewById(R.id.filtersRssiSeekBar); mFiltersRssiSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { int rssiValue = -seekBar.getProgress(); mPeripheralList.setFilterRssiValue(rssiValue); updateRssiValue(); updateFilters(); } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); mFiltersRssiValueTextView = (TextView) findViewById(R.id.filtersRssiValueTextView); mFiltersUnnamedCheckBox = (CheckBox) findViewById(R.id.filtersUnnamedCheckBox); mFiltersUnnamedCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { mPeripheralList.setFilterUnnamedEnabled(isChecked); updateFilters(); } }); mFiltersUartCheckBox = (CheckBox) findViewById(R.id.filtersUartCheckBox); mFiltersUartCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { mPeripheralList.setFilterOnlyUartEnabled(isChecked); updateFilters(); } }); // Filters SharedPreferences preferences = getSharedPreferences(kPreferences, MODE_PRIVATE); boolean filtersIsPanelOpen = preferences.getBoolean(kPreferences_filtersPanelOpen, false); openFiltersPanel(filtersIsPanelOpen, false); updateFiltersTitle(); mFiltersNameEditText.setText(mPeripheralList.getFilterName()); setRssiSliderValue(mPeripheralList.getFilterRssiValue()); mFiltersUnnamedCheckBox.setChecked(mPeripheralList.isFilterUnnamedEnabled()); mFiltersUartCheckBox.setChecked(mPeripheralList.isFilterOnlyUartEnabled()); // Setup when activity is created for the first time if (savedInstanceState == null) { // Read preferences SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); boolean autoResetBluetoothOnStart = sharedPreferences.getBoolean("pref_resetble", false); boolean disableWifi = sharedPreferences.getBoolean("pref_disableWifi", false); boolean updatesEnabled = sharedPreferences.getBoolean("pref_updatesenabled", true); // Update SoftwareUpdateManager if (updatesEnabled) { mFirmwareUpdater = new FirmwareUpdater(this, this); mFirmwareUpdater.refreshSoftwareUpdatesDatabase(); } // Turn off wifi if (disableWifi) { final boolean isWifiEnabled = BleUtils.isWifiEnabled(this); if (isWifiEnabled) { BleUtils.enableWifi(false, this); mShouldEnableWifiOnQuit = true; } } // Check if bluetooth adapter is available final boolean wasBluetoothEnabled = manageBluetoothAvailability(); final boolean areLocationServicesReadyForScanning = manageLocationServiceAvailabilityForScanning(); // Reset bluetooth if (autoResetBluetoothOnStart && wasBluetoothEnabled && areLocationServicesReadyForScanning) { BleUtils.resetBluetoothAdapter(this, this); } } // Request Bluetooth scanning persmissions requestLocationPermissionIfNeeded(); }
From source file:eu.operando.proxy.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 a v a2 s. 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"); 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(); importExternalFilters(importUrl); } }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // Canceled. } }).show(); } }