@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_group_pick_contacts); // String groupName = getIntent().getStringExtra("groupName"); String groupId = getIntent().getStringExtra("groupId"); if (groupId == null) { // 创建群组 isCreatingNewGroup = true; } else { // 获取此群组的成员列表 EMGroup group = EMGroupManager.getInstance().getGroup(groupId); exitingMembers = group.getMembers(); } if (exitingMembers == null) exitingMembers = new ArrayList<String>(); // 获取好友列表 final List<User> alluserList = new ArrayList<User>(); for (User user : BeewayApplication.getInstance().getContactList().values()) { if (!user.getUsername().equals(Constant.NEW_FRIENDS_USERNAME) & !user.getUsername().equals(Constant.GROUP_USERNAME) & !user.getUsername().equals(Constant.CHAT_ROOM) & !user.getUsername().equals(Constant.CHAT_ROBOT)) alluserList.add(user); } friendDao = new FriendDao(this); // 对list进行排序 Collections.sort( alluserList, new Comparator<User>() { @Override public int compare(User lhs, User rhs) { return (friendDao.getFriend(lhs.getUsername()).getLetter()) .compareTo(friendDao.getFriend(rhs.getUsername()).getLetter()); // return (lhs.getUsername().compareTo(rhs.getUsername())); } }); listView = (ListView) findViewById(R.id.list); contactAdapter = new PickContactAdapter(this, R.layout.row_contact_with_checkbox, alluserList); listView.setAdapter(contactAdapter); ((Sidebar) findViewById(R.id.sidebar)).setListView(listView); listView.setOnItemClickListener( new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { CheckBox checkBox = (CheckBox) view.findViewById(R.id.checkbox); checkBox.toggle(); } }); }
private void initializeContacts() { Map<String, User> userlist = new HashMap<String, User>(); // 添加user"申请与通知" User newFriends = new User(); newFriends.setUsername(Constant.NEW_FRIENDS_USERNAME); String strChat = getResources().getString(R.string.Application_and_notify); newFriends.setNick(strChat); userlist.put(Constant.NEW_FRIENDS_USERNAME, newFriends); // 添加"群聊" User groupUser = new User(); String strGroup = getResources().getString(R.string.group_chat); groupUser.setUsername(Constant.GROUP_USERNAME); groupUser.setNick(strGroup); groupUser.setHeader(""); userlist.put(Constant.GROUP_USERNAME, groupUser); // 存入内存 BeewayApplication.getInstance().setContactList(userlist); // 存入db UserDao dao = new UserDao(LoginActivity.this); List<User> users = new ArrayList<User>(userlist.values()); dao.saveContactList(users); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // 如果用户名密码都有,直接进入主页面 // if (DemoHXSDKHelper.getInstance().isLogined()) { // autoLogin = true; // startActivity(new Intent(LoginActivity.this, MainActivity.class)); // return; // } setContentView(R.layout.activity_login); registerMessageReceiver(); usernameEditText = (EditText) findViewById(R.id.username); passwordEditText = (EditText) findViewById(R.id.password); usernameEditText.setSelection(usernameEditText.getText().length()); passwordEditText.setSelection(passwordEditText.getText().length()); iv_code = (Button) findViewById(R.id.iv_code); iv_code.setOnClickListener(this); iv_username = (ImageView) findViewById(R.id.iv_username); iv_password = (ImageView) findViewById(R.id.iv_password); usernameEditText.setOnFocusChangeListener( new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { iv_username.setImageResource(R.drawable.icon_account_black); } else { iv_username.setImageResource(R.drawable.icon_account); } } }); passwordEditText.setOnFocusChangeListener( new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { iv_password.setImageResource(R.drawable.icon_pwd_black); } else { iv_password.setImageResource(R.drawable.icon_pwd); } } }); // 如果用户名改变,清空密码 usernameEditText.addTextChangedListener( new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { passwordEditText.setText(null); } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) {} @Override public void afterTextChanged(Editable s) {} }); if (BeewayApplication.getInstance().getUserName() != null) { usernameEditText.setText(BeewayApplication.getInstance().getUserName()); } context = this; if (BeewayApplication.getInstance().getUserName() != null) { usernameEditText.setText(BeewayApplication.getInstance().getUserName()); } isauto = BeewayApplication.getInstance().getAutologin(context); forget_password = (TextView) findViewById(R.id.forget_password); login_Code = (TextView) findViewById(R.id.login_Code); login_number = (TextView) findViewById(R.id.login_number); login_number.setOnClickListener(this); login_Code.setOnClickListener(this); login_register = (TextView) findViewById(R.id.login_register); forget_password.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(LoginActivity.this, RegisterActivity.class); intent.putExtra("forget", forget); startActivity(intent); finish(); } }); // 注册 login_register.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { startActivityForResult( new Intent(context, com.easemob.chatui.activity.RegisterActivity.class), 0); finish(); } }); }