List of usage examples for android.text TextWatcher TextWatcher
TextWatcher
From source file:com.eason.marker.emchat.chatuidemo.activity.ContactlistFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); //T??home???appcrash if (savedInstanceState != null && savedInstanceState.getBoolean("isConflict", false)) return;//www.j a va 2 s . c o 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); //??? blackList = EMContactManager.getInstance().getBlackListUsernames(); contactList = new ArrayList<EMUser>(); // ?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)) { // ? EMUser EMUser = ((DemoHXSDKHelper) HXSDKHelper.getInstance()).getContactList() .get(Constant.NEW_FRIENDS_USERNAME); EMUser.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?? startActivity(new Intent(getActivity(), ChatActivity.class).putExtra("userId", adapter.getItem(position).getUsername())); } } }); 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); if (!HXSDKHelper.getInstance().isContactsSyncedWithServer()) { progressBar.setVisibility(View.VISIBLE); } else { progressBar.setVisibility(View.GONE); } }
From source file:com.mifos.mifosxdroid.online.loanrepayment.LoanRepaymentFragment.java
/** * This Method Setting UI and Initializing the Object, TextView or EditText. */// w w w . java 2s.co m public void inflateUI() { tv_clientName.setText(clientName); tv_loanProductShortName.setText(loanProductName); tv_loanAccountNumber.setText(loanId); tv_inArrears.setText(String.valueOf(amountInArrears)); //Setup Form with Default Values et_amount.setText("0.0"); et_amount.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { } @Override public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) { try { tv_total.setText(String.valueOf(calculateTotal())); } catch (NumberFormatException nfe) { et_amount.setText("0"); } finally { tv_total.setText(String.valueOf(calculateTotal())); } } @Override public void afterTextChanged(Editable editable) { } }); et_additionalPayment.setText("0.0"); et_additionalPayment.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { } @Override public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) { try { tv_total.setText(String.valueOf(calculateTotal())); } catch (NumberFormatException nfe) { et_additionalPayment.setText("0"); } finally { tv_total.setText(String.valueOf(calculateTotal())); } } @Override public void afterTextChanged(Editable editable) { } }); et_fees.setText("0.0"); et_fees.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { } @Override public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) { try { tv_total.setText(String.valueOf(calculateTotal())); } catch (NumberFormatException nfe) { et_fees.setText("0"); } finally { tv_total.setText(String.valueOf(calculateTotal())); } } @Override public void afterTextChanged(Editable editable) { } }); inflateRepaymentDate(); tv_total.setText(String.valueOf(calculateTotal())); }
From source file:com.jlabs.peepaid.searchviewlay.SearchViewLayout.java
@Override protected void onFinishInflate() { mCollapsed = (ViewGroup) findViewById(R.id.search_box_collapsed); mSearchIcon = findViewById(R.id.search_magnifying_glass); mCollapsedSearchBox = findViewById(R.id.search_box_start_search); mCollapsedHintView = (TextView) findViewById(R.id.search_box_collapsed_hint); mExpanded = (ViewGroup) findViewById(R.id.search_expanded_root); mSearchEditText = (EditText) mExpanded.findViewById(R.id.search_expanded_edit_text); mBackButtonView = mExpanded.findViewById(R.id.search_expanded_back_button); mExpandedSearchIcon = findViewById(R.id.search_expanded_magnifying_glass); // Convert a long click into a click to expand the search box, and then long click on the // search view. This accelerates the long-press scenario for copy/paste. mCollapsedSearchBox.setOnLongClickListener(new OnLongClickListener() { @Override/*ww w. j av a 2 s. c o m*/ public boolean onLongClick(View view) { mCollapsedSearchBox.performClick(); mSearchEditText.performLongClick(); return false; } }); mCollapsed.setOnClickListener(mSearchViewOnClickListener); mSearchIcon.setOnClickListener(mSearchViewOnClickListener); mCollapsedSearchBox.setOnClickListener(mSearchViewOnClickListener); mSearchEditText.setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { Utils.showInputMethod(v); } else { Utils.hideInputMethod(v); } } }); mSearchEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_SEARCH) { callSearchListener(); Utils.hideInputMethod(v); return true; } return false; } }); mSearchEditText.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { if (mSearchEditText.getText().length() > 0) { if (mExpandedSearchIcon.getVisibility() != View.VISIBLE) { Utils.fadeIn(mExpandedSearchIcon, ANIMATION_DURATION); } } else { Utils.fadeOut(mExpandedSearchIcon, ANIMATION_DURATION); } if (mSearchBoxListener != null) mSearchBoxListener.onTextChanged(s, start, before, count); } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { if (mSearchBoxListener != null) mSearchBoxListener.beforeTextChanged(s, start, count, after); } @Override public void afterTextChanged(Editable s) { if (mSearchBoxListener != null) mSearchBoxListener.afterTextChanged(s); } }); mBackButtonView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { collapse(); } }); mExpandedSearchIcon.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { callSearchListener(); Utils.hideInputMethod(v); } }); mCollapsedDrawable = new ColorDrawable( ContextCompat.getColor(getContext(), R.color.default_color_expanded)); mExpandedDrawable = new ColorDrawable(ContextCompat.getColor(getContext(), R.color.default_color_expanded)); mBackgroundTransition = new TransitionDrawable(new Drawable[] { mCollapsedDrawable, mExpandedDrawable }); mBackgroundTransition.setCrossFadeEnabled(true); setBackground(mBackgroundTransition); Utils.setPaddingAll(SearchViewLayout.this, 8); super.onFinishInflate(); }
From source file:com.google.android.apps.forscience.whistlepunk.project.UpdateProjectFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_update_project, container, false); mCoverButtonLabel = (TextView) view.findViewById(R.id.project_cover_label); mProjectTitle = (EditText) view.findViewById(R.id.project_title); mProjectDescription = (EditText) view.findViewById(R.id.project_description); mProjectCoverButton = (ImageButton) view.findViewById(R.id.project_cover); mProjectCoverButton.getDrawable().setAlpha(ADD_IMAGE_ALPHA); mProjectCoverButton.setOnClickListener(new View.OnClickListener() { @Override/*from w ww.j av a 2 s . c o m*/ public void onClick(View v) { if (ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { launchPhotoPicker(); } else { requestPermissions(new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE); } } }); mProjectTitle.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { if (mProject == null) { return; } if (!s.toString().equals(mProject.getTitle())) { mProject.setTitle(s.toString().trim()); mWasEdited = true; saveProject(); } } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void afterTextChanged(Editable s) { } }); mProjectDescription.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { if (mProject == null) { return; } if (!s.toString().equals(mProject.getDescription())) { mProject.setDescription(s.toString().trim()); mWasEdited = true; saveProject(); } } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void afterTextChanged(Editable s) { } }); return view; }
From source file:com.mycelium.wallet.activity.export.DecryptPrivateKeyActivity.java
/** * Called when the activity is first created. */// w w w.j a v a 2 s .c om @Override public void onCreate(Bundle savedInstanceState) { this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); super.onCreate(savedInstanceState); setContentView(R.layout.export_decrypt_private_key_activity); _mbwManager = MbwManager.getInstance(this); // Get parameters _encryptedPrivateKey = getIntent().getStringExtra("encryptedPrivateKey"); // Decode the header of the encrypted private key try { _header = MrdExport.V1.extractHeader(_encryptedPrivateKey); } catch (DecodingException e) { Toast.makeText(this, R.string.unrecognized_format, Toast.LENGTH_SHORT).show(); finish(); return; } _taskExecutionServiceController = new TaskExecutionServiceController(); _taskExecutionServiceController.bind(this, this); _progressUpdater = new ProgressUpdater(); passwordEdit = (EditText) findViewById(R.id.password); passwordEdit.addTextChangedListener(new TextNormalizer(PASS_NORMALIZER, passwordEdit)); passwordEdit.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 (isValidPassword(s)) { startKeyStretching(); } updatePasswordText(); } }); if (savedInstanceState != null) { setPassword(savedInstanceState.getString("password")); } updatePasswordText(); showKeyboardOrStartStretching(); }
From source file:com.dlam.fragment.ContactlistFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); //T??home???appcrash if (savedInstanceState != null && savedInstanceState.getBoolean("isConflict", false)) return;/*from ww w . j a v a 2s.c o 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); //??? 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?? startActivity(new Intent(getActivity(), ChatActivity.class).putExtra("userId", adapter.getItem(position).getUsername())); } } }); 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); if (!HXSDKHelper.getInstance().isContactsSyncedWithServer()) { progressBar.setVisibility(View.VISIBLE); } else { progressBar.setVisibility(View.GONE); } }
From source file:cn.ucai.wechat.ui.SettingsActivity.java
private void setSettings() { settingsModel = WeChatHelper.getInstance().getModel(); chatOptions = EMClient.getInstance().getOptions(); // the vibrate and sound notification are allowed or not? if (settingsModel.getSettingMsgNotification()) { notifySwitch.openSwitch();// w ww . j a v a 2 s .c o m } else { notifySwitch.closeSwitch(); } // sound notification is switched on or not? if (settingsModel.getSettingMsgSound()) { soundSwitch.openSwitch(); } else { soundSwitch.closeSwitch(); } // vibrate notification is switched on or not? if (settingsModel.getSettingMsgVibrate()) { vibrateSwitch.openSwitch(); } else { vibrateSwitch.closeSwitch(); } // the speaker is switched on or not? if (settingsModel.getSettingMsgSpeaker()) { speakerSwitch.openSwitch(); } else { speakerSwitch.closeSwitch(); } // if allow owner leave if (settingsModel.isChatroomOwnerLeaveAllowed()) { ownerLeaveSwitch.openSwitch(); } else { ownerLeaveSwitch.closeSwitch(); } // delete messages when exit group? if (settingsModel.isDeleteMessagesAsExitGroup()) { switch_delete_msg_when_exit_group.openSwitch(); } else { switch_delete_msg_when_exit_group.closeSwitch(); } if (settingsModel.isAutoAcceptGroupInvitation()) { switch_auto_accept_group_invitation.openSwitch(); } else { switch_auto_accept_group_invitation.closeSwitch(); } if (settingsModel.isAdaptiveVideoEncode()) { switch_adaptive_video_encode.openSwitch(); EMClient.getInstance().callManager().getCallOptions().enableFixedVideoResolution(false); } else { switch_adaptive_video_encode.closeSwitch(); EMClient.getInstance().callManager().getCallOptions().enableFixedVideoResolution(true); } if (settingsModel.isCustomServerEnable()) { customServerSwitch.openSwitch(); } else { customServerSwitch.closeSwitch(); } if (settingsModel.isCustomAppkeyEnabled()) { customAppkeySwitch.openSwitch(); } else { customAppkeySwitch.closeSwitch(); } edit_custom_appkey.setEnabled(settingsModel.isCustomAppkeyEnabled()); edit_custom_appkey.setText(settingsModel.getCutomAppkey()); edit_custom_appkey.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) { PreferenceManager.getInstance().setCustomAppkey(s.toString()); } }); }
From source file:com.example.fertilizercrm.easemob.chatuidemo.activity.ContactlistFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); //T??home???appcrash if (savedInstanceState != null && savedInstanceState.getBoolean("isConflict", false)) return;//www .j av a 2 s.c om 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); //??? 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?? startActivity(new Intent(getActivity(), ChatActivity.class).putExtra("userId", adapter.getItem(position).getUsername())); } } }); 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); if (!HXSDKHelper.getInstance().isContactsSyncedWithServer()) { progressBar.setVisibility(View.VISIBLE); } else { progressBar.setVisibility(View.GONE); } View view = getView().findViewById(R.id.rl_left); view.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { getActivity().finish(); } }); }
From source file:com.easemob.chatuidemo.activity.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 v a 2 s . 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); getView().findViewById(R.id.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?? startActivity(new Intent(getActivity(), ChatActivity.class).putExtra("userId", adapter.getItem(position).getUsername())); } } }); 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); if (!HXSDKHelper.getInstance().isContactsSyncedWithServer()) { progressBar.setVisibility(View.VISIBLE); } else { progressBar.setVisibility(View.GONE); } }
From source file:com.appsimobile.appsii.module.search.SearchController.java
@Override protected void onViewCreated(View view, Bundle savedInstanceState) { mRecyclerView = (RecyclerView) view.findViewById(R.id.recycler); mSearchView = (EditText) view.findViewById(R.id.search_view); mSuggestionsAnchor = view.findViewById(R.id.search_wrapper); mSearchRecyclerView = (RecyclerView) view.findViewById(R.id.search_recycler); mSearchDivider = view.findViewById(R.id.search_divider); mSearchRecyclerView.setLayoutManager(new WrapContentLinearLayoutManager(getContext())); mSearchRecyclerView.setAdapter(mSearchSuggestionsAdapter); mRecyclerView.setLayoutManager(new WrapContentLinearLayoutManager(getContext())); mRecyclerView.setAdapter(mSearchAdapter); mRecyclerView.setItemAnimator(new DefaultItemAnimator()); // mRecyclerView.setOnScrollListener(new ToolbarScrollListener(this, mToolbar)); Resources res = getResources(); float density = res.getDisplayMetrics().density; // calculate the width of the sidebar int contentWidth = getContentWidth(); if (contentWidth == 0) { float pct = mPreferenceHelper.getSidebarWidth() / 100f; contentWidth = (int) (res.getConfiguration().smallestScreenWidthDp * density * pct); }/*from w w w . j a v a 2s . c o m*/ int dp104 = (int) (density * 104); int cellCount = contentWidth / dp104; if (cellCount < 3) cellCount = 3; if (cellCount > 3) cellCount--; mGridLayoutManager = new GridLayoutManager(getContext(), cellCount); mSearchAdapter.setSpanCount(cellCount); mRecyclerView.setLayoutManager(mGridLayoutManager); mGridLayoutManager.setSpanSizeLookup(mSearchAdapter.mSpanSizeLookup); mSearchView.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) { onSearchTextChanged(s); } }); mSearchView.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { onSearchFocusChanged(hasFocus); } }); mSearchSuggestionsAdapter.setOnItemClickListener(this); Button speechButton; /* speechButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); intent.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS, true); // intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS,5); mSpeechRecognizer.startListening(intent); Log.i("111111", "11111111"); } }); */ }