List of usage examples for android.text TextWatcher TextWatcher
TextWatcher
From source file:com.happynetwork.vrestate.activitys.ContactlistFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); //T??home???appcrash if (savedInstanceState != null && savedInstanceState.getBoolean("isConflict", false)) return;/*w w w . j a va2s .co m*/ inputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); listView = (ListView) getView().findViewById(R.id.list); // sidebar = (Sidebar) getView().findViewById(R.id.sidebar); // sidebar.setListView(listView); back = (ImageView) getView().findViewById(R.id.back); back.setOnClickListener(this); //??? blackList = EMContactManager.getInstance().getBlackListUsernames(); contactList = new ArrayList<User>(); // ?contactlist getContactList(); //? query = (EditText) getView().findViewById(R.id.query); query.setHint(R.string.search); clearSearch = (ImageButton) getView().findViewById(R.id.search_clear); 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); } } public void beforeTextChanged(CharSequence s, int start, int count, int after) { } public void afterTextChanged(Editable s) { } }); clearSearch.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { query.getText().clear(); hideSoftKeyboard(); } }); // adapter adapter = new ContactAdapter(getActivity(), R.layout.row_contact, contactList); listView.setAdapter(adapter); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { String username = adapter.getItem(position).getUsername(); if (Constant.NEW_FRIENDS_USERNAME.equals(username)) { // ? User user = ((DemoHXSDKHelper) HXSDKHelper.getInstance()).getContactList() .get(Constant.NEW_FRIENDS_USERNAME); user.setUnreadMsgCount(0); startActivity(new Intent(getActivity(), NewFriendsMsgActivity.class)); } else if (Constant.GROUP_USERNAME.equals(username)) { // ?? startActivity(new Intent(getActivity(), GroupsActivity.class)); } else if (Constant.CHAT_ROOM.equals(username)) { //?? startActivity(new Intent(getActivity(), PublicChatRoomsActivity.class)); } else if (Constant.CHAT_ROBOT.equals(username)) { //Robot? startActivity(new Intent(getActivity(), RobotsActivity.class)); } else { // demo?? String userName = adapter.getItem(position).getUsername(); startActivity(new Intent(getActivity(), ChatActivity.class).putExtra("userId", userName)); } } }); listView.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { // ?? if (getActivity().getWindow() .getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) { if (getActivity().getCurrentFocus() != null) inputMethodManager.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } return false; } }); ImageView addContactView = (ImageView) getView().findViewById(R.id.iv_new_contact); // ? addContactView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { startActivity(new Intent(getActivity(), AddContactActivity.class)); } }); registerForContextMenu(listView); // progressBar = (View) getView().findViewById(R.id.progress_bar); contactSyncListener = new HXContactSyncListener(); HXSDKHelper.getInstance().addSyncContactListener(contactSyncListener); blackListSyncListener = new HXBlackListSyncListener(); HXSDKHelper.getInstance().addSyncBlackListListener(blackListSyncListener); contactInfoSyncListener = new HXContactInfoSyncListener(); ((DemoHXSDKHelper) HXSDKHelper.getInstance()).getUserProfileManager() .addSyncContactInfoListener(contactInfoSyncListener); boolean ll = HXSDKHelper.getInstance().isContactsSyncedWithServer(); // if (!ll) { // progressBar.setVisibility(View.VISIBLE); // } else { // progressBar.setVisibility(View.GONE); // } }
From source file:com.example.android.CreateNewPlayer.java
private void enableCreatePlayerButton() { userName.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) { }//from w w w .j a va 2 s .c o m public void beforeTextChanged(CharSequence s, int start, int count, int after) { } public void onTextChanged(CharSequence s, int start, int before, int count) { if (userName.getText().length() > 2) { createPlayerButton.setEnabled(true); } else { createPlayerButton.setEnabled(false); } } }); }
From source file:com.eugene.fithealthmaingit.UI.ChooseAddMealSearchFragment.java
@Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fragment_search_add_item_fatsecret, container, false); // Change the notification bar color if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Window w = getActivity().getWindow(); w.setStatusBarColor(getResources().getColor(R.color.light_grey)); }/*from w w w . j av a 2 s .c o m*/ // Get MealType (snack, breakfast, lunch, dinner) Bundle extras = getActivity().getIntent().getExtras(); if (extras != null) { mealType = extras.getString(Globals.MEAL_TYPE); } // Initialize FatSecretSearchMethod mFatSecretSearch = new FatSecretSearchMethod(); mSwipeRefreshLayout = (SwipeRefreshLayout) v.findViewById(R.id.swiperefresh); mSwipeRefreshLayout.setColorSchemeResources(R.color.primary, R.color.red, R.color.primary_dark); mSwipeRefreshLayout.setProgressViewOffset(true, Equations.dpToPx(getActivity(), 0), Equations.dpToPx(getActivity(), 112)); mSwipeRefreshLayout.setEnabled(false); mEtSearch = (EditText) v.findViewById(R.id.etSearch); // LogQuickSearch adapter to add items that have not been saved already mRecentLogAdapter = new LogQuickSearchAdapter(getActivity(), 0, LogQuickSearch.all()); // List for adding items to the mItem = new ArrayList<>(); // Set to prevent duplicates being saved in LogQuickSearch set = new HashSet<>(); /** * set mListViewSearchResults adapter to SearchAdapterItemResult */ llSearch = (LinearLayout) v.findViewById(R.id.llSearch); listSearch = (ListView) v.findViewById(R.id.listSearch); searchLine = v.findViewById(R.id.searchLine); logQuickSearchAdapter = new LogQuickSearchAdapter(getActivity(), 0, LogQuickSearch.all()); mEtSearchAdapter = new SearchAdapterItemResult(getActivity(), mItem); mListViewSearchResults = (ListView) v.findViewById(R.id.listView); ViewGroup header = (ViewGroup) inflater.inflate(R.layout.list_search_header, mListViewSearchResults, false); mListViewSearchResults.addHeaderView(header, null, false); mListViewSearchResults.setAdapter(mEtSearchAdapter); mListViewSearchResults.setOnScrollListener(this); mListViewSearchResults.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Intent i = new Intent(getActivity(), SaveSearchAddItemActivityMain.class); i.putExtra(Globals.MEAL_TYPE, mealType); i.putExtra(Globals.MEAL_ID, mItem.get(position - 1).getID()); i.putExtra(Globals.MEAL_BRAND, mItem.get(position - 1).getBrand()); i.putExtra(Globals.MEAL_FAVORITE, "false"); startActivity(i); } }); // Toolbar mToolbarSearch = (Toolbar) v.findViewById(R.id.toolbar_search); mToolbarSearch.inflateMenu(R.menu.menu_search); mToolbarSearch.setNavigationIcon(R.mipmap.ic_arrow_back_grey); mToolbarSearch.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { getActivity().getSupportFragmentManager().popBackStack(); } }); mToolbarSearch.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { if (menuItem.getItemId() == R.id.action_clear) { mEtSearch.setText(""); } if (menuItem.getItemId() == R.id.action_voice) { promptSpeechInput(); } return false; } }); mEtSearch.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 (mEtSearch.getText().toString().length() >= 1) { mToolbarSearch.getMenu().clear(); mToolbarSearch.inflateMenu(R.menu.menu_search_clear); logQuickSearchAdapter = new LogQuickSearchAdapter(getActivity(), 0, LogQuickSearch.FilterByName(mEtSearch.getText().toString())); listSearch.setAdapter(logQuickSearchAdapter); } else { mToolbarSearch.getMenu().clear(); mToolbarSearch.inflateMenu(R.menu.menu_search); logQuickSearchAdapter = new LogQuickSearchAdapter(getActivity(), 0, LogQuickSearch.all()); listSearch.setAdapter(logQuickSearchAdapter); } mItem.clear(); updateListView(); } @Override public void afterTextChanged(Editable s) { } }); // Quick Search Clicked, start search based on list Item clicked from last fragment Bundle extrasFromRecentCliced = this.getArguments(); if (extrasFromRecentCliced != null) { String mealName = extrasFromRecentCliced.getString("MealName"); if (mealName != null) { mEtSearch.setText(mealName); mToolbarSearch.getMenu().clear(); mToolbarSearch.inflateMenu(R.menu.menu_search_clear); searchFood(mealName, 0); } } else { mEtSearch.requestFocus(); ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE)) .toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY); } /** * Handles softKeyboard search icon being clicked */ mEtSearch.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_SEARCH) { ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE)) .hideSoftInputFromWindow(mEtSearch.getWindowToken(), 0); listSearch.setVisibility(View.GONE); searchLine.setVisibility(View.GONE); searchFood(mEtSearch.getText().toString(), 0); mItem.clear(); mEtSearchAdapter.notifyDataSetChanged(); mEtSearch.clearFocus(); return true; } return false; } }); listSearch.setAdapter(logQuickSearchAdapter); listSearch.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { LogQuickSearch logQuickSearch = logQuickSearchAdapter.getItem(position); mEtSearch.setText(logQuickSearch.getName()); ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE)) .hideSoftInputFromWindow(mEtSearch.getWindowToken(), 0); listSearch.setVisibility(View.GONE); searchLine.setVisibility(View.GONE); searchFood(logQuickSearch.getName(), 0); mItem.clear(); mEtSearchAdapter.notifyDataSetChanged(); mEtSearch.clearFocus(); } }); updateListView(); return v; }
From source file:com.agateau.equiv.ui.MealItemDetailActivity.java
private void setupMealEditor() { TextView.OnEditorActionListener onEditorActionListener = new TextView.OnEditorActionListener() { @Override/*from w w w .j av a2s . c o m*/ public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) { if (actionId == EditorInfo.IME_ACTION_DONE) { save(); return true; } return false; } }; mProductNameView = (TextView) findViewById(R.id.product_name_view); mDetailsLayout = (LinearLayout) findViewById(R.id.details_layout); mQuantityEdit = (EditText) findViewById(R.id.quantity_edit); mQuantityEdit.setOnEditorActionListener(onEditorActionListener); mQuantityEdit.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) { updateQuantityEquivEdit(); } }); mQuantityUnitView = (TextView) findViewById(R.id.quantity_unit); mQuantityEquivEdit = (EditText) findViewById(R.id.quantity_equiv_edit); mQuantityEquivEdit.setOnEditorActionListener(onEditorActionListener); mQuantityEquivEdit.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) { updateQuantityEdit(); } }); mQuantityEquivUnitView = (TextView) findViewById(R.id.quantity_equiv_unit); if (mMealItemPosition != NEW_MEAL_ITEM_POSITION) { setTitle(R.string.edit_meal_item_title); initFromMealItem(mMeal.getItems().get(mMealItemPosition)); } }
From source file:com.esminis.server.library.activity.main.MainViewImpl.java
private void setupListeners(Activity activity) { viewDocumentRoot.setOnClickListener(new View.OnClickListener() { public void onClick(View arg0) { presenter.showDocumentRootChooser(); }//from w ww.jav a 2 s . co m }); viewPort.setOnEditorActionListener(new TextView.OnEditorActionListener() { public boolean onEditorAction(TextView text, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_DONE) { final Activity activity = MainViewImpl.this.activity.get(); if (activity != null) { ((InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE)) .hideSoftInputFromWindow(text.getWindowToken(), 0); return true; } } return false; } }); viewPort.addTextChangedListener(new TextWatcher() { public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { } public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { } public void afterTextChanged(Editable text) { presenter.portModified(text.toString()); } }); activity.findViewById(R.id.start).setOnClickListener(new View.OnClickListener() { public void onClick(View view) { presenter.serverStart(); } }); activity.findViewById(R.id.stop).setOnClickListener(new View.OnClickListener() { public void onClick(View view) { presenter.serverStop(); } }); viewContainer.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent event) { removeFocus(); return true; } }); activity.findViewById(R.id.preloader_button_ok).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { presenter.requestPermission(); } }); buttonStart.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { presenter.serverStart(); } }); buttonStop.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { presenter.serverStop(); } }); viewInstalledPackage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { presenter.requestPackageInstall(); } }); }
From source file:com.pax.pay.trans.action.activity.InputTransData2Activity.java
@Override protected void setListeners() { backBtn.setOnClickListener(this); scanner.setOnClickListener(this); // ?/*from www .ja v a 2s .co m*/ mEditNum.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { confirmBtnChange(); } @Override public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { } @Override public void afterTextChanged(Editable e) { } }); mEditExtraNum.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { confirmBtnChange(); } @Override public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { } @Override public void afterTextChanged(Editable arg0) { } }); confirm.setOnClickListener(this); }
From source file:com.sim2dial.dialer.ChatFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { sipUri = getArguments().getString("SipUri"); String displayName = getArguments().getString("DisplayName"); String pictureUri = getArguments().getString("PictureUri"); view = inflater.inflate(R.layout.chat, container, false); contactName = (TextView) view.findViewById(R.id.contactName); contactPicture = (AvatarWithShadow) view.findViewById(R.id.contactPicture); sendMessage = (TextView) view.findViewById(R.id.sendMessage); sendMessage.setOnClickListener(this); message = (EditText) view.findViewById(R.id.message); if (!getActivity().getResources().getBoolean(R.bool.allow_chat_multiline)) { message.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE); message.setMaxLines(1);/*from w ww .j a v a 2 s. c o m*/ } uploadLayout = (RelativeLayout) view.findViewById(R.id.uploadLayout); textLayout = (RelativeLayout) view.findViewById(R.id.messageLayout); messagesLayout = (RelativeLayout) view.findViewById(R.id.messages); messagesScrollView = (ScrollView) view.findViewById(R.id.chatScrollView); progressBar = (ProgressBar) view.findViewById(R.id.progressbar); sendImage = (TextView) view.findViewById(R.id.sendPicture); registerForContextMenu(sendImage); sendImage.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { pickImage(); } }); cancelUpload = (ImageView) view.findViewById(R.id.cancelUpload); cancelUpload.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { uploadThread.interrupt(); uploadLayout.setVisibility(View.GONE); textLayout.setVisibility(View.VISIBLE); progressBar.setProgress(0); } }); displayChat(displayName, pictureUri); LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull(); if (lc != null) { chatRoom = lc.createChatRoom(sipUri); } uploadServerUri = Engine.getPref().getString(getString(R.string.pref_image_sharing_server_key), getString(R.string.pref_image_sharing_server_default)); textWatcher = new TextWatcher() { public void afterTextChanged(Editable arg0) { } public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { } public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { if (message.getText().toString().equals("")) { sendMessage.setEnabled(false); } else { sendMessage.setEnabled(true); } } }; // Force hide keyboard if (LinphoneActivity.isInstanciated()) { InputMethodManager imm = (InputMethodManager) LinphoneActivity.instance() .getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(view.getWindowToken(), 0); } // Workaround for SGS3 issue if (savedInstanceState != null) { fileToUploadPath = savedInstanceState.getString("fileToUploadPath"); imageToUpload = savedInstanceState.getParcelable("imageToUpload"); } if (fileToUploadPath != null || imageToUpload != null) { sendImage.post(new Runnable() { @Override public void run() { sendImage.showContextMenu(); } }); } return view; }
From source file:com.towson.wavyleaf.Sighting.java
protected void init() { getWindow().setBackgroundDrawable(null); Typeface tf_light = Typeface.createFromAsset(getAssets(), "fonts/roboto_light.ttf"); Typeface tf_bold = Typeface.createFromAsset(getAssets(), "fonts/roboto_bold.ttf"); tvlat = (TextView) findViewById(R.id.tv_latitude); tvlong = (TextView) findViewById(R.id.tv_longitude); tvpicnotes = (TextView) findViewById(R.id.tv_picturenotes); tvper = (TextView) findViewById(R.id.tv_percentageseen); tvper_summary = (TextView) findViewById(R.id.tv_percentageseen_summary); tvcoor = (TextView) findViewById(R.id.tv_coordinates); tvarea = (TextView) findViewById(R.id.tv_areainfested); tvarea_summary = (TextView) findViewById(R.id.tv_areainfested_summary); tv_treatment = (TextView) findViewById(R.id.tv_treatment); notes = (EditText) findViewById(R.id.notes); etarea = (EditText) findViewById(R.id.et_areainfested); b1 = (ToggleButton) findViewById(R.id.bu_1); b2 = (ToggleButton) findViewById(R.id.bu_2); b3 = (ToggleButton) findViewById(R.id.bu_3); b4 = (ToggleButton) findViewById(R.id.bu_4); b5 = (ToggleButton) findViewById(R.id.bu_5); b6 = (ToggleButton) findViewById(R.id.bu_6); cb = (CheckBox) findViewById(R.id.cb_confirm); rg = (RadioGroup) findViewById(R.id.toggleGroup); sp = (Spinner) findViewById(R.id.sp_areainfested); sp_treatment = (Spinner) findViewById(R.id.sp_treatment); mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); locationData = (LocationApplication) getApplication(); currentEditableLocation = locationData.getLocation(); updateLocationTimer = new Timer(); TimerTask updateLocationTask = new TimerTask() { @Override//from w ww . j a v a2 s . c o m public void run() { checkLocation(); } }; updateLocationTimer.scheduleAtFixedRate(updateLocationTask, 0, FIVE_SECONDS); // Listener for EditText in Area Infested etarea.addTextChangedListener(new TextWatcher() { public void onTextChanged(CharSequence s, int start, int before, int count) { if (etarea.getText().length() == 0) { tvarea_summary.setText(""); } else if (etarea.getText().toString().contains("-")) { // Negative number etarea.getEditableText().clear(); Toast.makeText(getApplicationContext(), "Negative values not allowed", Toast.LENGTH_SHORT) .show(); } else { tvarea_summary.setText(etarea.getText() + " " + sp.getSelectedItem().toString()); } } public void afterTextChanged(Editable s) { } public void beforeTextChanged(CharSequence s, int start, int count, int after) { } }); // Listener for spinner in Area Infested sp.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onNothingSelected(AdapterView<?> arg0) { } @Override public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) { if (etarea.getText().length() != 0) tvarea_summary.setText(etarea.getText() + " " + sp.getSelectedItem()); } }); // Adapter for area infested spinner ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.areainfested_array, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); sp.setAdapter(adapter); // Adapter for Treatment spinner ArrayAdapter<CharSequence> adapter2 = ArrayAdapter.createFromResource(this, R.array.treatment_array, android.R.layout.simple_spinner_item); adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); sp_treatment.setAdapter(adapter2); // Just to be safe cb.setChecked(false); // Set all the beautiful typefaces tvlat.setTypeface(tf_light); tvlong.setTypeface(tf_light); tvcoor.setTypeface(tf_bold); tvarea.setTypeface(tf_bold); tvarea_summary.setTypeface(tf_bold); tvper.setTypeface(tf_bold); tvper_summary.setTypeface(tf_bold); tvpicnotes.setTypeface(tf_bold); tv_treatment.setTypeface(tf_bold); cb.setTypeface(tf_light); b1.setTypeface(tf_light); b2.setTypeface(tf_light); b3.setTypeface(tf_light); b4.setTypeface(tf_light); b5.setTypeface(tf_light); b6.setTypeface(tf_light); if (!locationData.isSearching()) findUsersLocation(); ib = (ImageButton) findViewById(R.id.imagebutton_sighting); // Listener for camera button ib.setOnClickListener(new OnClickListener() { public void onClick(View v) { takePicture(); } }); ib_percent = (ImageButton) findViewById(R.id.ib_percent); // Listener for help button in Percentage Infested category ib_percent.setOnClickListener(new OnClickListener() { public void onClick(View v) { showDialog(HELP_PERCENT); } }); ib_treatment = (ImageButton) findViewById(R.id.ib_treatment); // Listener for help button in Treatment catgeory ib_treatment.setOnClickListener(new OnClickListener() { public void onClick(View v) { showDialog(HELP_TREATMENT); // Toast.makeText(getApplicationContext(), "Specify the type of treatment that was done to this area", Toast.LENGTH_LONG).show(); } }); }
From source file:com.cenkgun.chatty.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 . j a va 2 s.c o m 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(); } } // 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", 400L); // Apply config settings and default values. mFirebaseRemoteConfig.setConfigSettings(firebaseRemoteConfigSettings); mFirebaseRemoteConfig.setDefaults(defaultConfigMap); // Fetch remote config. fetchConfig(); mGoogleApiClient = new GoogleApiClient.Builder(this).enableAutoManage(this, this) .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); 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 = (ImageButton) findViewById(R.id.sendButton); mSendButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { ChattyMessage chattyMessage = new ChattyMessage(mMessageEditText.getText().toString(), mUsername, mPhotoUrl, dateFormat.format(date), null /* no image */); mFirebaseDatabaseReference.child(MESSAGES_CHILD).push().setValue(chattyMessage); mMessageEditText.setText(""); } }); // mAddMessageImageView = (ImageView) findViewById(R.id.addMessageImageView); // mAddMessageImageView.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View view) { // Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); // intent.addCategory(Intent.CATEGORY_OPENABLE); // intent.setType("image/*"); // startActivityForResult(intent, REQUEST_IMAGE); // } // }); // New child entries mFirebaseDatabaseReference = FirebaseDatabase.getInstance().getReference(); mFirebaseAdapter = new FirebaseRecyclerAdapter<ChattyMessage, MessageViewHolder>(ChattyMessage.class, R.layout.item_message, MessageViewHolder.class, mFirebaseDatabaseReference.child(MESSAGES_CHILD)) { @Override protected void populateViewHolder(final MessageViewHolder viewHolder, ChattyMessage chattyMessage, int position) { mProgressBar.setVisibility(ProgressBar.INVISIBLE); if (chattyMessage.getText() != null) { viewHolder.messageTextView.setText(chattyMessage.getText()); viewHolder.messageTextView.setVisibility(TextView.VISIBLE); viewHolder.messageImageView.setVisibility(ImageView.GONE); } else { String imageUrl = chattyMessage.getImageUrl(); if (imageUrl.startsWith("gs://")) { StorageReference storageReference = FirebaseStorage.getInstance() .getReferenceFromUrl(imageUrl); storageReference.getDownloadUrl().addOnCompleteListener(new OnCompleteListener<Uri>() { @Override public void onComplete(@NonNull Task<Uri> task) { if (task.isSuccessful()) { String downloadUrl = task.getResult().toString(); Glide.with(viewHolder.messageImageView.getContext()).load(downloadUrl) .into(viewHolder.messageImageView); } else { Log.w(TAG, "Getting download url was not successful.", task.getException()); } } }); } else { Glide.with(viewHolder.messageImageView.getContext()).load(chattyMessage.getImageUrl()) .into(viewHolder.messageImageView); } viewHolder.messageImageView.setVisibility(ImageView.VISIBLE); viewHolder.messageTextView.setVisibility(TextView.GONE); } viewHolder.messengerTime.setText(chattyMessage.getDate()); viewHolder.messengerTextView.setText(chattyMessage.getName()); if (chattyMessage.getPhotoUrl() == null) { viewHolder.messengerImageView.setImageDrawable( ContextCompat.getDrawable(MainActivity.this, R.drawable.ic_account_circle_black_36dp)); } else { Glide.with(MainActivity.this).load(chattyMessage.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); }
From source file:com.hybris.mobile.adapter.FormAdapter.java
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override/* w w w. j a va 2 s . c o m*/ public View getView(final int position, View convertView, ViewGroup parent) { LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View rowView = inflater.inflate(R.layout.form_row, parent, false); LinearLayout lnr = (LinearLayout) rowView.findViewById(R.id.linear_layout_form); final Hashtable<String, Object> obj = (Hashtable<String, Object>) objects.get(position); String className = "com.hybris.mobile.view." + obj.get("cellIdentifier").toString(); Object someObj = null; try { Class cell; cell = Class.forName(className); Constructor constructor = cell.getConstructor(new Class[] { Context.class }); someObj = constructor.newInstance(this.context); } catch (Exception e) { LoggingUtils.e(LOG_TAG, "Error loading class \"" + className + "\". " + e.getLocalizedMessage(), Hybris.getAppContext()); } /* * Text Cell */ if (someObj != null && someObj instanceof HYFormTextEntryCell) { final HYFormTextEntryCell textCell = (HYFormTextEntryCell) someObj; if (isLastEditText(position)) { textCell.setImeDone(this); } lnr.addView(textCell); textCell.setId(position); if (obj.containsKey("inputType")) { Integer val = mInputTypes.get(obj.get("inputType").toString()); textCell.setContentInputType(val); } if (obj.containsKey("value")) { textCell.setContentText(obj.get("value").toString()); } if (obj.containsKey("keyboardType") && StringUtils.equals(obj.get("keyboardType").toString(), "UIKeyboardTypeEmailAddress")) { textCell.setContentInputType(mInputTypes.get("textEmailAddress")); } textCell.addContentChangedListener(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) { } @Override public void afterTextChanged(Editable s) { obj.put("value", s.toString()); notifyFormDataChangedListner(); } }); textCell.setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (!hasFocus) { textCell.setTextColor(context.getResources().getColor(R.color.textMedium)); if (!fieldIsValid(position)) { setIsValid(false); textCell.showMessage(true); } else { textCell.showMessage(false); } showInvalidField(); validateAllFields(); } else { textCell.setTextColor(context.getResources().getColor(R.color.textHighlighted)); setCurrentFocusIndex(position); } } }); textCell.setContentTitle(obj.get("title").toString()); if (obj.containsKey("error")) { textCell.setMessage(obj.get("error").toString()); } if (obj.containsKey("showerror")) { Boolean showerror = Boolean.parseBoolean(obj.get("showerror").toString()); textCell.showMessage(showerror); } else { textCell.showMessage(false); } if (currentFocusIndex == position) { textCell.setFocus(); } } /* * Secure Text Cell */ else if (someObj instanceof HYFormSecureTextEntryCell) { final HYFormSecureTextEntryCell secureTextCell = (HYFormSecureTextEntryCell) someObj; if (isLastEditText(position)) { secureTextCell.setImeDone(this); } lnr.addView(secureTextCell); secureTextCell.setId(position); if (obj.containsKey("value")) { secureTextCell.setContentText(obj.get("value").toString()); } if (obj.containsKey("inputType")) { Integer val = mInputTypes.get(obj.get("inputType").toString()); secureTextCell.setContentInputType(val); } secureTextCell.addContentChangedListener(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) { } @Override public void afterTextChanged(Editable s) { obj.put("value", s.toString()); notifyFormDataChangedListner(); } }); secureTextCell.setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (!hasFocus) { if (!fieldIsValid(position)) { setIsValid(false); secureTextCell.showMessage(true); } else { secureTextCell.showMessage(false); } showInvalidField(); validateAllFields(); } else { setCurrentFocusIndex(position); } } }); secureTextCell.setContentTitle(obj.get("title").toString()); if (obj.containsKey("error")) { secureTextCell.setMessage(obj.get("error").toString()); } if (obj.containsKey("showerror")) { Boolean showerror = Boolean.parseBoolean(obj.get("showerror").toString()); secureTextCell.showMessage(showerror); } else { secureTextCell.showMessage(false); } if (currentFocusIndex == position) { secureTextCell.setFocus(); } } else if (someObj instanceof HYFormTextSelectionCell) { setIsValid(fieldIsValid(position)); HYFormTextSelectionCell selectionTextCell = (HYFormTextSelectionCell) someObj; lnr.addView(selectionTextCell); if (StringUtils.isNotBlank((String) obj.get("value"))) { StringBuilder b = new StringBuilder(obj.get("value").toString()); selectionTextCell.setSpinnerText(b.replace(0, 1, b.substring(0, 1).toUpperCase()).toString()); } else { selectionTextCell.setSpinnerText(obj.get("title").toString()); } } else if (someObj instanceof HYFormTextSelectionCell2) { HYFormTextSelectionCell2 selectionTextCell = (HYFormTextSelectionCell2) someObj; lnr.addView(selectionTextCell); selectionTextCell.init(obj); } else if (someObj instanceof HYFormSwitchCell) { HYFormSwitchCell checkBox = (HYFormSwitchCell) someObj; lnr.addView(checkBox); checkBox.setCheckboxText(obj.get("title").toString()); if (StringUtils.isNotBlank((String) obj.get("value"))) { checkBox.setCheckboxChecked(Boolean.parseBoolean((String) obj.get("value"))); } checkBox.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { HYFormSwitchCell chk = (HYFormSwitchCell) v; chk.toggleCheckbox(); obj.put("value", String.valueOf(chk.isCheckboxChecked())); notifyFormDataChangedListner(); } }); } else if (someObj instanceof HYFormSubmitButton) { HYFormSubmitButton btnCell = (HYFormSubmitButton) someObj; lnr.addView(btnCell); btnCell.setButtonText(obj.get("title").toString()); btnCell.setOnButtonClickListener(new OnClickListener() { @Override public void onClick(View v) { submit(); } }); } return rowView; }