Exemplo n.º 1
0
 @Override
 public void onResume() {
   super.onResume();
   if (!hidden) {
     refresh();
   }
 }
Exemplo n.º 2
0
 @Override
 public void onCreateContextMenu(
     android.view.ContextMenu menu, View v, android.view.ContextMenu.ContextMenuInfo menuInfo) {
   super.onCreateContextMenu(menu, v, menuInfo);
   // 长按前两个不弹menu
   if (((AdapterView.AdapterContextMenuInfo) menuInfo).position > 2) {
     getActivity().getMenuInflater().inflate(R.menu.context_contact_list, menu);
   }
 }
Exemplo n.º 3
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_contact);
    inputMethodManager =
        (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
    listView = (ListView) findViewById(R.id.list);
    sidebar = (Sidebar) findViewById(R.id.sidebar);
    sidebar.setListView(listView);
    // 黑名单列表
    //        blackList = EMContactManager.getInstance().getBlackListUsernames();
    contactList = new ArrayList<User>();
    // 获取设置contactlist
    getContactList();

    // 搜索框
    query = (EditText) findViewById(R.id.query);
    String strSearch = getResources().getString(R.string.search);
    query.setHint(strSearch);
    clearSearch = (ImageButton) 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 View.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 AdapterView.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 =
            // DemoApplication.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 {
            // 直接进入聊天页面
            User u = adapter.getItem(position);
            if (getIntent().getBooleanExtra(Const.Intent.IS_FROM_CHAT_ACTIVITY_KEY, true)) {
              Intent i = new Intent();
              i.setClass(getActivity(), ChatActivity.class);
              i.putExtra(Const.Intent.HX_USER_ID, u.getUserImId());
              i.putExtra(Const.Intent.HX_USER_NICK_NAME, u.getNickName());
              i.putExtra(Const.Intent.HX_USER_TO_CHAT_AVATAR, u.getPortraitURL());
              startActivity(i);
              finish();
            } else {
              setResult(RESULT_OK, getIntent().putExtra(Const.Intent.USER_ENTITY_FROM_CONTACT, u));
              finish();
            }
            //                }
          }
        });
    listView.setOnTouchListener(
        new View.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;
          }
        });

    registerForContextMenu(listView);
  }