List of usage examples for android.view.inputmethod InputMethodManager HIDE_NOT_ALWAYS
int HIDE_NOT_ALWAYS
To view the source code for android.view.inputmethod InputMethodManager HIDE_NOT_ALWAYS.
Click Source Link
From source file:cn.ucai.superwechat.ui.GroupsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.em_fragment_groups); instance = this; inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); grouplist = EMClient.getInstance().groupManager().getAllGroups(); groupListView = (ListView) findViewById(R.id.list); //show group list groupAdapter = new GroupAdapter(this, 1, grouplist); groupListView.setAdapter(groupAdapter); swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_layout); swipeRefreshLayout.setColorSchemeResources(R.color.holo_blue_bright, R.color.holo_green_light, R.color.holo_orange_light, R.color.holo_red_light); //pull down to refresh swipeRefreshLayout.setOnRefreshListener(new OnRefreshListener() { @Override/*from ww w.j a v a 2 s . c om*/ public void onRefresh() { new Thread() { @Override public void run() { try { EMClient.getInstance().groupManager().getJoinedGroupsFromServer(); handler.sendEmptyMessage(0); } catch (HyphenateException e) { e.printStackTrace(); handler.sendEmptyMessage(1); } } }.start(); } }); groupListView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if (position == 1) { // create a new group startActivityForResult(new Intent(GroupsActivity.this, NewGroupActivity.class), 0); } else if (position == 2) { // join a public group startActivityForResult(new Intent(GroupsActivity.this, PublicGroupsActivity.class), 0); } else { // enter group chat Intent intent = new Intent(GroupsActivity.this, ChatActivity.class); // it is group chat intent.putExtra("chatType", Constant.CHATTYPE_GROUP); intent.putExtra("userId", groupAdapter.getItem(position - 3).getGroupId()); startActivityForResult(intent, 0); } } }); groupListView.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (getWindow() .getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) { if (getCurrentFocus() != null) inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } return false; } }); }
From source file:com.safeness.im.activity.ChatHistoryFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); inputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); errorItem = (RelativeLayout) getView().findViewById(R.id.rl_error_item); errorText = (TextView) errorItem.findViewById(R.id.tv_connect_errormsg); // contact list contactList = PatientApplication.getInstance().getContactList(); listView = (ListView) getView().findViewById(R.id.list); adapter = new ChatHistoryAdapter(getActivity(), 1, loadUsersWithRecentChat()); // adapter//from www . j a va 2s. c o m listView.setAdapter(adapter); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { EMContact emContact = adapter.getItem(position); if (adapter.getItem(position).getUsername().equals(PatientApplication.getInstance().getUserName())) Toast.makeText(getActivity(), "??", Toast.LENGTH_SHORT).show(); else { // ?? Intent intent = new Intent(getActivity(), ChatActivity.class); if (emContact instanceof EMGroup) { //it is group chat intent.putExtra("chatType", ChatActivity.CHATTYPE_GROUP); intent.putExtra("groupId", ((EMGroup) emContact).getGroupId()); } else { //it is single chat intent.putExtra("userId", emContact.getUsername()); } startActivity(intent); } } }); // ?? registerForContextMenu(listView); 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; } }); // ? query = (EditText) getView().findViewById(R.id.query); // ?button 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(); } }); }
From source file:niltor.net.chatuidemo.activity.ChatHistoryFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); inputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); errorItem = (RelativeLayout) getView().findViewById(R.id.rl_error_item); errorText = (TextView) errorItem.findViewById(R.id.tv_connect_errormsg); // contact list contactList = DemoApplication.getInstance().getContactList(); listView = (ListView) getView().findViewById(R.id.list); adapter = new ChatHistoryAdapter(getActivity(), 1, loadUsersWithRecentChat()); // adapter/*from w ww.ja v a 2 s .c om*/ listView.setAdapter(adapter); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { EMContact emContact = adapter.getItem(position); if (adapter.getItem(position).getUsername().equals(DemoApplication.getInstance().getUserName())) Toast.makeText(getActivity(), "??", Toast.LENGTH_SHORT).show(); else { // ?? Intent intent = new Intent(getActivity(), ChatActivity.class); if (emContact instanceof EMGroup) { //it is group chat intent.putExtra("chatType", ChatActivity.CHATTYPE_GROUP); intent.putExtra("groupId", ((EMGroup) emContact).getGroupId()); } else { //it is single chat intent.putExtra("userId", emContact.getUsername()); } startActivity(intent); } } }); // ?? registerForContextMenu(listView); 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; } }); // ? query = (EditText) getView().findViewById(R.id.query); // ?button 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(); } }); }
From source file:la.zmkm.agent.activity.ChatHistoryFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); inputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); errorItem = (RelativeLayout) getView().findViewById(R.id.rl_error_item); errorText = (TextView) errorItem.findViewById(R.id.tv_connect_errormsg); // contact list contactList = DemoApplication.getInstance().getContactList(); listView = (ListView) getView().findViewById(R.id.list); adapter = new ChatHistoryAdapter(getActivity(), 1, loadUsersWithRecentChat()); // adapter//from w ww . j a va2 s . co m listView.setAdapter(adapter); final String st = getResources().getString(R.string.Cant_chat_with_yourself); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { EMContact emContact = adapter.getItem(position); if (adapter.getItem(position).getUsername().equals(DemoApplication.getInstance().getUserName())) Toast.makeText(getActivity(), st, 0).show(); else { // ?? Intent intent = new Intent(getActivity(), ChatActivity.class); if (emContact instanceof EMGroup) { //it is group chat intent.putExtra("chatType", ChatActivity.CHATTYPE_GROUP); intent.putExtra("groupId", ((EMGroup) emContact).getGroupId()); } else { //it is single chat intent.putExtra("userId", emContact.getUsername()); } startActivity(intent); } } }); // ?? registerForContextMenu(listView); 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; } }); // ? query = (EditText) getView().findViewById(R.id.query); // ?button 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(); } }); }
From source file:sean.dataexchange.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); test = new SurveyPointHandler("TestFile.txt", this.getApplicationContext()); test.loadSurveyPoints();//from w w w . j av a2 s . c o m if (savedInstanceState == null) { FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); BluetoothChatFragment fragment = new BluetoothChatFragment(); transaction.replace(R.id.sample_content_fragment, fragment); transaction.commit(); } flagnumber_before = 0; // -------------------------------------- Start Lat Long------------------------------------------------// // TURN OFF ONCE SURVEY BUTTON WORKS // Latitude and Longitude are stored to TextView files to be used in SurveyFileHandler // Use textLatitude and textLongitude initComponents(); //---------------------------------------End Lat Long --------------------------------------------------// //---------------------------------------- Start Time/Day ----------------------------------------------// Calendar c = Calendar.getInstance(); //int millisec = c.get(Calendar.MILLISECOND); //int seconds = c.get(Calendar.SECOND); //int minutes = c.get(Calendar.MINUTE); //int hours = c.get(Calendar.HOUR); //int day = c.get(Calendar.DAY_OF_MONTH); //int month = c.get(Calendar.MONTH); //int year = c.get(Calendar.YEAR); // Integer to String // Integer.toString(millisec) //----------------------------------------- End Time/Day -----------------------------------------------// //----------------------------------------- Start User Input-------------------------------------------// // The Name, Surveytype and Flagnumber are stored to TextView Files for use in the SurveyFileHandler // Use: textName, textSurveyType, and textFlagNumber EditText editTextName = (EditText) findViewById(R.id.editName); EditText editFlagNumber = (EditText) findViewById(R.id.editFlagNumber); final TextView textName = (TextView) findViewById(R.id.textName); final TextView textFlagNumber = (TextView) findViewById(R.id.textFlagNumber); editTextName.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) { boolean handled = false; if (i == EditorInfo.IME_ACTION_DONE) { String inputText = textView.getText().toString(); Toast.makeText(MainActivity.this, "Name: " + inputText, Toast.LENGTH_SHORT).show(); InputMethodManager inputManager = (InputMethodManager) getSystemService( Context.INPUT_METHOD_SERVICE); inputManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); textName.setText(inputText); handled = true; } return handled; } }); editFlagNumber.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) { boolean handled = false; if (i == EditorInfo.IME_ACTION_DONE) { String inputText = textView.getText().toString(); Toast.makeText(MainActivity.this, "Flag Number: " + inputText, Toast.LENGTH_SHORT).show(); InputMethodManager inputManager = (InputMethodManager) getSystemService( Context.INPUT_METHOD_SERVICE); inputManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); textFlagNumber.setText(inputText); handled = true; } return handled; } }); // -----------------------------------End User Input Work---------------------------------------------------------------// //------------------------------------Select Survey Type------------------------------------------------------------// method_spinner = (Spinner) findViewById(R.id.method_spinner); //------------------------------------Select Survey Type------------------------------------------------------------// //---------------------------------------Start Survey Data Point--------------------------------------------------// btnCollectSurveyPt = (Button) findViewById(R.id.btnGetSurveyPoint); btnCollectSurveyPt.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { // Make Sure User Input Fields are completed if (!textFlagNumber.getText().toString().matches("\\d+") || textName.getText().toString() == "") { if (!textFlagNumber.getText().toString().matches("\\d+")) { Toast.makeText(MainActivity.this, "Enter Numeric Flag", Toast.LENGTH_SHORT).show(); } else if (textName.getText().toString() == "") { Toast.makeText(MainActivity.this, "Enter Missing User Name", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(MainActivity.this, "Enter Missing Survey Type", Toast.LENGTH_SHORT).show(); } } else { // Collect User Input int flagnumber = Integer.parseInt(textFlagNumber.getText().toString()); String user = textName.getText().toString(); String method = String.valueOf(method_spinner.getSelectedItem()); double latitude = 0.0; double longitude = 0.0; // Collect Lat/Long gps = new GPSTracker(MainActivity.this); if (gps.canGetLocation()) { latitude = gps.getLatitude(); longitude = gps.getLongitude(); textLatitude.setText("\nLatitude: " + "" + latitude); textLongitude.setText("\nLongitude: " + "" + longitude); } else { gps.showSettingsAlert(); } // Tell the User We have done something Toast.makeText(MainActivity.this, method + " Point collected at Flag Number: " + textFlagNumber.getText().toString(), Toast.LENGTH_SHORT).show(); // USE SURVEY POINT HANDLER HERE test.recordSurveyPoint(latitude, longitude, flagnumber, user, method); // Set Flag Number to zero to make people enter next flag flagnumber_after = flagnumber; increment = flagnumber_after - flagnumber_before; textFlagNumber.setText(Integer.toString(flagnumber + increment)); flagnumber_before = flagnumber_after; } } }); //---------------------------------------Start Survey Data Point----------------------------------------// if (savedInstanceState == null) { FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); BluetoothChatFragment fragment = new BluetoothChatFragment(); transaction.replace(R.id.sample_content_fragment, fragment); transaction.commit(); } }
From source file:com.zhixu.icu.activity.ChatHistoryFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); inputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); errorItem = (RelativeLayout) getView().findViewById(R.id.rl_error_item); errorText = (TextView) errorItem.findViewById(R.id.tv_connect_errormsg); // contact list contactList = DemoApplication.getInstance().getContactList(); listView = (ListView) getView().findViewById(R.id.list); adapter = new ChatHistoryAdapter(getActivity(), 1, loadUsersWithRecentChat()); // adapter// w ww . j a va 2 s. c o m listView.setAdapter(adapter); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { EMContact emContact = adapter.getItem(position); if (adapter.getItem(position).getUsername().equals(DemoApplication.getInstance().getUserName())) Toast.makeText(getActivity(), "??", 0).show(); else { // ?? Intent intent = new Intent(getActivity(), ChatActivity.class); if (emContact instanceof EMGroup) { //it is group chat intent.putExtra("chatType", ChatActivity.CHATTYPE_GROUP); intent.putExtra("groupId", ((EMGroup) emContact).getGroupId()); } else { //it is single chat intent.putExtra("userId", emContact.getUsername()); } startActivity(intent); } } }); // ?? registerForContextMenu(listView); 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; } }); // ? query = (EditText) getView().findViewById(R.id.query); // ?button 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(); } }); }
From source file:cn.kangeqiu.kq.activity.ChatHistoryFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); inputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); errorItem = (RelativeLayout) getView().findViewById(R.id.rl_error_item); errorText = (TextView) errorItem.findViewById(R.id.tv_connect_errormsg); // contact list contactList = BaseApplication.getInstance().getContactList(); listView = (ListView) getView().findViewById(R.id.list); adapter = new ChatHistoryAdapter(getActivity(), 1, loadUsersWithRecentChat()); // adapter/*w w w .j a v a 2 s. c o m*/ listView.setAdapter(adapter); final String st = getResources().getString(R.string.Cant_chat_with_yourself); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { EMContact emContact = adapter.getItem(position); if (adapter.getItem(position).getUsername().equals(BaseApplication.getInstance().getUserName())) Toast.makeText(getActivity(), st, 0).show(); else { // ?? Intent intent = new Intent(getActivity(), ChatActivity.class); if (emContact instanceof EMGroup) { //it is group chat intent.putExtra("chatType", ChatActivity.CHATTYPE_GROUP); intent.putExtra("groupId", ((EMGroup) emContact).getGroupId()); } else { //it is single chat intent.putExtra("userId", emContact.getUsername()); } startActivity(intent); } } }); // ?? registerForContextMenu(listView); 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; } }); // ? query = (EditText) getView().findViewById(R.id.query); // ?button 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(); } }); }
From source file:cn.xcom.helper.chat.ui.GroupsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.em_fragment_groups); instance = this; inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); grouplist = EMClient.getInstance().groupManager().getAllGroups(); groupListView = (ListView) findViewById(R.id.list); //show group list groupAdapter = new GroupAdapter(this, 1, grouplist); groupListView.setAdapter(groupAdapter); swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_layout); swipeRefreshLayout.setColorSchemeResources(R.color.holo_blue_bright, R.color.holo_green_light, R.color.holo_orange_light, R.color.holo_red_light); //pull down to refresh swipeRefreshLayout.setOnRefreshListener(new OnRefreshListener() { @Override/* w w w.j a va2s. c o m*/ public void onRefresh() { new Thread() { @Override public void run() { try { EMClient.getInstance().groupManager().getJoinedGroupsFromServer(); handler.sendEmptyMessage(0); } catch (HyphenateException e) { e.printStackTrace(); handler.sendEmptyMessage(1); } } }.start(); } }); groupListView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if (position == 1) { // create a new group startActivityForResult(new Intent(GroupsActivity.this, NewGroupActivity.class), 0); } else if (position == 2) { // join a public group startActivityForResult(new Intent(GroupsActivity.this, PublicGroupsActivity.class), 0); } else { // enter group chat Intent intent = new Intent(GroupsActivity.this, ChatActivity.class); // it is group chat intent.putExtra("chatType", Constant.CHATTYPE_GROUP); intent.putExtra("userId", groupAdapter.getItem(position - 3).getGroupId()); startActivityForResult(intent, 0); } } }); groupListView.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (getWindow() .getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) { if (getCurrentFocus() != null) inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } return false; } }); }
From source file:com.dong.huang.imdemo.ui.GroupsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.em_fragment_groups); instance = this; inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); grouplist = EMClient.getInstance().groupManager().getAllGroups(); groupListView = (ListView) findViewById(R.id.list); //show group list groupAdapter = new GroupAdapter(this, 1, grouplist); groupListView.setAdapter(groupAdapter); swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_layout); swipeRefreshLayout.setColorSchemeResources(R.color.holo_blue_bright, R.color.holo_green_light, R.color.holo_orange_light, R.color.holo_red_light); ////from ww w . j a va 2 s .c o m swipeRefreshLayout.setOnRefreshListener(new OnRefreshListener() { @Override public void onRefresh() { new Thread() { @Override public void run() { try { EMClient.getInstance().groupManager().getJoinedGroupsFromServer(); handler.sendEmptyMessage(0); } catch (HyphenateException e) { e.printStackTrace(); handler.sendEmptyMessage(1); } } }.start(); } }); groupListView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if (position == 1) { // ? startActivityForResult(new Intent(GroupsActivity.this, NewGroupActivity.class), 0); } else if (position == 2) { // startActivityForResult(new Intent(GroupsActivity.this, PublicGroupsActivity.class), 0); } else { // ? Intent intent = new Intent(GroupsActivity.this, ChatActivity.class); // it is group chat intent.putExtra("chatType", Constant.CHATTYPE_GROUP); intent.putExtra("userId", groupAdapter.getItem(position - 3).getGroupId()); startActivityForResult(intent, 0); } } }); groupListView.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (getWindow() .getAttributes().softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN) { if (getCurrentFocus() != null) inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } return false; } }); }
From source file:com.app.jiaxiaotong.activity.ChatHistoryFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); inputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); errorText = (TextView) errorItem.findViewById(R.id.tv_connect_errormsg); // contact list contactList = ((MyHXSDKHelper) HXSDKHelper.getInstance()).getContactList(); listView = (ListView) getView().findViewById(R.id.list); adapter = new ChatHistoryAdapter(getActivity(), 1, loadUsersWithRecentChat()); // adapter/*w w w. j av a 2s .c o m*/ listView.setAdapter(adapter); final String st = getResources().getString(R.string.Cant_chat_with_yourself); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { EMContact emContact = adapter.getItem(position); if (adapter.getItem(position).getUsername().equals(AppContext.getAppContext().getUserName())) Toast.makeText(getActivity(), st, Toast.LENGTH_SHORT).show(); else { // ?? Intent intent = new Intent(getActivity(), ChatActivity.class); if (emContact instanceof EMGroup) { //it is group chat intent.putExtra("chatType", ChatActivity.CHATTYPE_GROUP); intent.putExtra("groupId", ((EMGroup) emContact).getGroupId()); } else { //it is single chat intent.putExtra("userId", emContact.getUsername()); } startActivity(intent); } } }); // ?? registerForContextMenu(listView); 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; } }); // ? query = (EditText) getView().findViewById(R.id.query); // ?button 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(); } }); }