Commit 3eb23d09300e10b5114531550681b45e53713a76
1 parent
d0078183
修改整体逻辑
Showing
8 changed files
with
147 additions
and
260 deletions
app/src/main/AndroidManifest.xml
| ... | ... | @@ -41,14 +41,33 @@ |
| 41 | 41 | > |
| 42 | 42 | </activity> |
| 43 | 43 | |
| 44 | + <activity | |
| 45 | + android:name="com.cnlive.im.ui.LoGinActivity" | |
| 46 | + android:launchMode="singleTop" | |
| 47 | + android:screenOrientation="portrait" | |
| 48 | + android:windowSoftInputMode="adjustResize" | |
| 49 | + android:theme="@style/Theme.AppCompat.Light.NoActionBar" /> | |
| 44 | 50 | |
| 45 | 51 | <activity |
| 52 | + android:name=".ui.UserLoginActivity" | |
| 53 | + android:launchMode="singleTop" | |
| 54 | + android:screenOrientation="portrait" | |
| 55 | + android:windowSoftInputMode="adjustResize" | |
| 56 | + android:theme="@style/Theme.AppCompat.Light.NoActionBar" /> | |
| 57 | + <activity | |
| 46 | 58 | android:name="com.cnlive.im.ui.PrivateChatActivity" |
| 47 | 59 | android:launchMode="singleTop" |
| 48 | 60 | android:screenOrientation="portrait" |
| 49 | 61 | android:windowSoftInputMode="adjustResize" |
| 50 | 62 | android:theme="@style/Theme.AppCompat.Light.NoActionBar" /> |
| 51 | 63 | |
| 64 | + <activity | |
| 65 | + android:name=".ui.ChatItemActivity" | |
| 66 | + android:launchMode="singleTop" | |
| 67 | + android:screenOrientation="portrait" | |
| 68 | + android:windowSoftInputMode="adjustResize" | |
| 69 | + android:theme="@style/Theme.AppCompat.Light.NoActionBar" /> | |
| 70 | + | |
| 52 | 71 | <service |
| 53 | 72 | android:name="io.rong.imlib.ipc.RongService" |
| 54 | 73 | android:exported="true" | ... | ... |
app/src/main/java/com/cnlive/im/ui/ChatRoomActivity.java
| 1 | 1 | package com.cnlive.im.ui; |
| 2 | 2 | |
| 3 | +import android.content.Intent; | |
| 3 | 4 | import android.os.Bundle; |
| 4 | 5 | import android.os.Handler; |
| 5 | 6 | import android.support.v7.app.AppCompatActivity; |
| ... | ... | @@ -36,12 +37,11 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL |
| 36 | 37 | private ListView listViewOne; |
| 37 | 38 | private ChatListAdapter chatListAdapterOne, chatListAdapterTwo; |
| 38 | 39 | private ListView listViewTwo; |
| 39 | - private Button user_switchBtn, foundChatBtn; | |
| 40 | + private Button foundChatBtn; | |
| 40 | 41 | private Button creatChat2Btn; |
| 41 | 42 | private Handler mHandler; |
| 42 | 43 | private RelativeLayout re_chat; |
| 43 | 44 | private LinearLayout lin_user; |
| 44 | - private Button user_imfor_send; | |
| 45 | 45 | private EditText user_id, user_name; |
| 46 | 46 | private CNUserInfo cnUser; |
| 47 | 47 | private Button exit_chat2; |
| ... | ... | @@ -60,6 +60,12 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL |
| 60 | 60 | ChatUtil.setOnChatRoomActionListener(chatRoomActionListener); |
| 61 | 61 | ChatUtil.setOnReceiveMessageListener(receiveMessageListener); |
| 62 | 62 | ChatUtil.setKickedOfflineListener(onKickedOfflineListener); |
| 63 | + Intent intent = getIntent(); | |
| 64 | + String user_name_string = intent.getStringExtra("user_name_string"); | |
| 65 | + String user_id_string = intent.getStringExtra("user_id_string"); | |
| 66 | + if(user_name_string!=null){ | |
| 67 | + ChatUtil.login(new CNUserInfo(user_id_string,user_name_string,""),connectListener); | |
| 68 | + } | |
| 63 | 69 | } |
| 64 | 70 | |
| 65 | 71 | |
| ... | ... | @@ -68,12 +74,10 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL |
| 68 | 74 | exit_chat1 = (Button) findViewById(R.id.exit_chat1); |
| 69 | 75 | user_id = (EditText) findViewById(R.id.user_ID); |
| 70 | 76 | user_name = (EditText) findViewById(R.id.user_name); |
| 71 | - user_imfor_send = (Button) findViewById(R.id.user_imfor_send); | |
| 72 | 77 | lin_user = (LinearLayout) findViewById(R.id.lin_user); |
| 73 | 78 | re_chat = (RelativeLayout) findViewById(R.id.re_chat); |
| 74 | 79 | creatChat2Btn = (Button) findViewById(R.id.creatChat2); |
| 75 | 80 | foundChatBtn = (Button) findViewById(R.id.creatChat); |
| 76 | - user_switchBtn = (Button) findViewById(R.id.user_switch); | |
| 77 | 81 | listViewOne = (ListView) findViewById(R.id.chat_list_viewOne); |
| 78 | 82 | listViewTwo = (ListView) findViewById(R.id.chat_list_viewTwo); |
| 79 | 83 | editText = (EditText) findViewById(R.id.message_content); |
| ... | ... | @@ -81,11 +85,9 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL |
| 81 | 85 | send_messageOneTwo = (Button) findViewById(R.id.send_messageTwo); |
| 82 | 86 | exit_chat1.setOnClickListener(this); |
| 83 | 87 | exit_chat2.setOnClickListener(this); |
| 84 | - user_imfor_send.setOnClickListener(this); | |
| 85 | 88 | foundChatBtn.setOnClickListener(this); |
| 86 | 89 | send_messageOneBtn.setOnClickListener(this); |
| 87 | 90 | send_messageOneTwo.setOnClickListener(this); |
| 88 | - user_switchBtn.setOnClickListener(this); | |
| 89 | 91 | creatChat2Btn.setOnClickListener(this); |
| 90 | 92 | groupChatOneListMy = new ArrayList<>(); |
| 91 | 93 | groupChatTwoListMy = new ArrayList<>(); |
| ... | ... | @@ -96,29 +98,6 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL |
| 96 | 98 | } |
| 97 | 99 | |
| 98 | 100 | |
| 99 | - //连接监听 | |
| 100 | - private IChat.OnConnectListener connectListener = new IChat.OnConnectListener() { | |
| 101 | - @Override | |
| 102 | - public void onTokenIncorrect() { | |
| 103 | - Log.e(TAG, "ConnectListener TokenIncorrect"); | |
| 104 | - Toast.makeText(ChatRoomActivity.this, "TokenIncorrect", Toast.LENGTH_SHORT).show(); | |
| 105 | - | |
| 106 | - } | |
| 107 | - | |
| 108 | - @Override | |
| 109 | - public void onSuccess(String s) { | |
| 110 | - Log.e(TAG, "ConnectListener 连接监听" + s); | |
| 111 | - //Toast.makeText(ChatRoomActivity.this, s, Toast.LENGTH_SHORT).show(); | |
| 112 | - } | |
| 113 | - | |
| 114 | - @Override | |
| 115 | - public void onError(int i, String s) { | |
| 116 | - Log.e(TAG, "ConnectListener errorCode : " + i + " : errorMessage : " + s); | |
| 117 | - Toast.makeText(ChatRoomActivity.this, s, Toast.LENGTH_SHORT).show(); | |
| 118 | - | |
| 119 | - } | |
| 120 | - }; | |
| 121 | - | |
| 122 | 101 | |
| 123 | 102 | /** |
| 124 | 103 | * 发送消息监听 |
| ... | ... | @@ -139,8 +118,7 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL |
| 139 | 118 | @Override |
| 140 | 119 | public void run() { |
| 141 | 120 | Toast.makeText(ChatRoomActivity.this, "发送成功", Toast.LENGTH_SHORT).show(); |
| 142 | - | |
| 143 | - if (("60_" + roomIdOne).equals(cnMessage.getTargetId())) { | |
| 121 | + if ((roomIdOne).equals(cnMessage.getTargetId())) { | |
| 144 | 122 | groupChatOneListMy.add(cnMessage); |
| 145 | 123 | chatListAdapterOne.updateItems(groupChatOneListMy); |
| 146 | 124 | chatListAdapterOne.notifyDataSetChanged(); |
| ... | ... | @@ -150,7 +128,7 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL |
| 150 | 128 | /** |
| 151 | 129 | * 连接两个聊天室30015 错误 |
| 152 | 130 | */ |
| 153 | - if (("60_" + roomIdTwo).equals(cnMessage.getTargetId())) { | |
| 131 | + if ((roomIdTwo).equals(cnMessage.getTargetId())) { | |
| 154 | 132 | groupChatTwoListMy.add(cnMessage); |
| 155 | 133 | chatListAdapterTwo.updateItems(groupChatTwoListMy); |
| 156 | 134 | chatListAdapterTwo.notifyDataSetChanged(); |
| ... | ... | @@ -194,7 +172,7 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL |
| 194 | 172 | mHandler.post(new Runnable() { |
| 195 | 173 | @Override |
| 196 | 174 | public void run() { |
| 197 | - if (("60_" + roomIdOne).equals(cnMessage.getTargetId())) { | |
| 175 | + if (( roomIdOne).equals(cnMessage.getTargetId())) { | |
| 198 | 176 | groupChatOneListMy.add(cnMessage); |
| 199 | 177 | chatListAdapterOne.updateItems(groupChatOneListMy); |
| 200 | 178 | chatListAdapterOne.notifyDataSetChanged(); |
| ... | ... | @@ -204,7 +182,7 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL |
| 204 | 182 | /** |
| 205 | 183 | * 连接两个聊天室30015 错误 |
| 206 | 184 | */ |
| 207 | - if (("60_" + roomIdTwo).equals(cnMessage.getTargetId())) { | |
| 185 | + if (( roomIdTwo).equals(cnMessage.getTargetId())) { | |
| 208 | 186 | groupChatTwoListMy.add(cnMessage); |
| 209 | 187 | chatListAdapterTwo.updateItems(groupChatTwoListMy); |
| 210 | 188 | chatListAdapterTwo.notifyDataSetChanged(); |
| ... | ... | @@ -317,17 +295,12 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL |
| 317 | 295 | editText.setText(""); |
| 318 | 296 | } |
| 319 | 297 | break; |
| 320 | - // 用户 | |
| 321 | - case R.id.user_switch: | |
| 322 | - re_chat.setVisibility(View.INVISIBLE); | |
| 323 | - lin_user.setVisibility(View.VISIBLE); | |
| 324 | - break; | |
| 325 | - // 创建聊天 | |
| 298 | + | |
| 326 | 299 | case R.id.creatChat: |
| 327 | 300 | ChatUtil.joinChatRoom(roomIdOne, -1, onOperationListener); |
| 328 | - //加入聊天室2 | |
| 301 | + //加入聊天室2 | |
| 329 | 302 | case R.id.creatChat2: |
| 330 | - ChatUtil.joinChatRoom(roomIdTwo, -1, onOperationListener); | |
| 303 | + // ChatUtil.joinChatRoom(roomIdTwo, -1, onOperationListener); | |
| 331 | 304 | break; |
| 332 | 305 | |
| 333 | 306 | case R.id.exit_chat2: |
| ... | ... | @@ -338,21 +311,33 @@ public class ChatRoomActivity extends AppCompatActivity implements View.OnClickL |
| 338 | 311 | ChatUtil.quitChatRoom(roomIdOne, onOperationListener); |
| 339 | 312 | break; |
| 340 | 313 | |
| 341 | - | |
| 342 | - case R.id.user_imfor_send: | |
| 343 | - if (user_id.getText().toString().isEmpty()) | |
| 344 | - Toast.makeText(ChatRoomActivity.this, "用户id不能为空", Toast.LENGTH_SHORT).show(); | |
| 345 | - else if (user_name.getText().toString().isEmpty()) | |
| 346 | - Toast.makeText(ChatRoomActivity.this, "用户名不能为空", Toast.LENGTH_SHORT).show(); | |
| 347 | - else { | |
| 348 | - cnUser = new CNUserInfo(user_id.getText().toString(), user_name.getText().toString(), ""); | |
| 349 | - ChatUtil.login(cnUser, connectListener); | |
| 350 | - re_chat.setVisibility(View.VISIBLE); | |
| 351 | - lin_user.setVisibility(View.INVISIBLE); | |
| 352 | - } | |
| 353 | - break; | |
| 354 | 314 | } |
| 355 | 315 | } |
| 356 | 316 | |
| 357 | 317 | |
| 318 | + | |
| 319 | + | |
| 320 | + private IChat.OnConnectListener connectListener = new IChat.OnConnectListener() { | |
| 321 | + @Override | |
| 322 | + public void onTokenIncorrect() { | |
| 323 | + Log.e(TAG, "ConnectListener TokenIncorrect"); | |
| 324 | + Toast.makeText(ChatRoomActivity.this, "TokenIncorrect", Toast.LENGTH_SHORT).show(); | |
| 325 | + | |
| 326 | + } | |
| 327 | + | |
| 328 | + @Override | |
| 329 | + public void onSuccess(String s) { | |
| 330 | + Log.e(TAG, "ConnectListener 连接监听" + s); | |
| 331 | + Toast.makeText(ChatRoomActivity.this, s, Toast.LENGTH_SHORT).show(); | |
| 332 | + } | |
| 333 | + | |
| 334 | + @Override | |
| 335 | + public void onError(int i, String s) { | |
| 336 | + Log.e(TAG, "ConnectListener errorCode : " + i + " : errorMessage : " + s); | |
| 337 | + Toast.makeText(ChatRoomActivity.this, s, Toast.LENGTH_SHORT).show(); | |
| 338 | + | |
| 339 | + } | |
| 340 | + }; | |
| 341 | + | |
| 342 | + | |
| 358 | 343 | } | ... | ... |
app/src/main/java/com/cnlive/im/ui/MainActivity.java
| ... | ... | @@ -3,24 +3,18 @@ package com.cnlive.im.ui; |
| 3 | 3 | import android.content.Intent; |
| 4 | 4 | import android.os.Bundle; |
| 5 | 5 | import android.support.v7.app.AppCompatActivity; |
| 6 | -import android.util.Log; | |
| 7 | 6 | import android.view.View; |
| 8 | 7 | import android.widget.Button; |
| 9 | -import android.widget.Toast; | |
| 10 | 8 | |
| 11 | 9 | import com.cnlive.im.R; |
| 12 | 10 | import com.cnlive.libs.util.chat.ChatUtil; |
| 13 | 11 | import com.cnlive.libs.util.chat.base.IChat; |
| 14 | 12 | |
| 15 | -import static com.cnlive.im.R.id.connect; | |
| 16 | - | |
| 17 | 13 | |
| 18 | 14 | public class MainActivity extends AppCompatActivity implements View.OnClickListener { |
| 19 | 15 | |
| 20 | - private Button groupChatBtn, privateChat; | |
| 21 | - private String TAG = "MainActivity"; | |
| 22 | - private Button connectBtn; | |
| 23 | - private Button re_connect; | |
| 16 | + | |
| 17 | + private Button connectedBtn; | |
| 24 | 18 | |
| 25 | 19 | @Override |
| 26 | 20 | protected void onCreate(Bundle savedInstanceState) { |
| ... | ... | @@ -29,60 +23,35 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe |
| 29 | 23 | initUI(); |
| 30 | 24 | } |
| 31 | 25 | |
| 32 | - //连接监听 | |
| 33 | - private IChat.OnConnectListener connectListener = new IChat.OnConnectListener() { | |
| 26 | + private void initUI() { | |
| 27 | + connectedBtn = (Button) findViewById(R.id.connected); | |
| 28 | + connectedBtn.setOnClickListener(this); | |
| 29 | + } | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + IChat.OnConnectListener connectListener = new IChat.OnConnectListener() { | |
| 34 | 34 | @Override |
| 35 | 35 | public void onTokenIncorrect() { |
| 36 | - Log.e(TAG, "ConnectListener TokenIncorrect"); | |
| 37 | - Toast.makeText(MainActivity.this, "TokenIncorrect", Toast.LENGTH_SHORT).show(); | |
| 38 | - connectBtn.setText("重新连接"); | |
| 36 | + connectedBtn.setText("重新连接"); | |
| 39 | 37 | } |
| 40 | 38 | |
| 41 | 39 | @Override |
| 42 | 40 | public void onSuccess(String s) { |
| 43 | - Log.e(TAG, "ConnectListener 连接监听" + s); | |
| 44 | - Toast.makeText(MainActivity.this, "连接成功", Toast.LENGTH_SHORT).show(); | |
| 45 | - connectBtn.setVisibility(View.INVISIBLE); | |
| 46 | - groupChatBtn.setVisibility(View.VISIBLE); | |
| 47 | - privateChat.setVisibility(View.VISIBLE); | |
| 41 | + Intent intent = new Intent(MainActivity.this,LoGinActivity.class); | |
| 42 | + startActivity(intent); | |
| 48 | 43 | } |
| 49 | 44 | |
| 50 | 45 | @Override |
| 51 | 46 | public void onError(int i, String s) { |
| 52 | - Log.e(TAG, "ConnectListener errorCode : " + i + " : errorMessage : " + s); | |
| 53 | - Toast.makeText(MainActivity.this, s, Toast.LENGTH_SHORT).show(); | |
| 54 | - connectBtn.setText("重新连接"); | |
| 47 | + connectedBtn.setText("重新连接"); | |
| 55 | 48 | |
| 56 | 49 | } |
| 57 | 50 | }; |
| 58 | 51 | |
| 59 | - private void initUI() { | |
| 60 | - groupChatBtn = (Button) findViewById(R.id.groupChat); | |
| 61 | - privateChat = (Button) findViewById(R.id.privateChat); | |
| 62 | - connectBtn = (Button) findViewById(connect); | |
| 63 | - groupChatBtn.setOnClickListener(this); | |
| 64 | - privateChat.setOnClickListener(this); | |
| 65 | - connectBtn.setOnClickListener(this); | |
| 66 | - } | |
| 67 | - | |
| 68 | - | |
| 69 | 52 | @Override |
| 70 | - public void onClick(View view) { | |
| 71 | - switch (view.getId()) { | |
| 72 | - case R.id.groupChat: | |
| 73 | - Intent intent = new Intent(MainActivity.this, ChatRoomActivity.class); | |
| 74 | - startActivity(intent); | |
| 75 | - break; | |
| 76 | - case R.id.privateChat: | |
| 77 | - Intent intent1 = new Intent(MainActivity.this, PrivateChatActivity.class); | |
| 78 | - startActivity(intent1); | |
| 79 | - break; | |
| 80 | - case connect: | |
| 81 | - //调用此方法在聊天室中不切换用户默认为游客 | |
| 82 | - //调用此方法之后不调用断开连接,网络掉线等原因系统会自动重连用户无需处理 | |
| 83 | - ChatUtil.connect(connectListener); | |
| 84 | - | |
| 85 | - } | |
| 53 | + public void onClick(View v) { | |
| 54 | + ChatUtil.connect(connectListener); | |
| 86 | 55 | } |
| 87 | 56 | } |
| 88 | 57 | ... | ... |
app/src/main/java/com/cnlive/im/ui/PrivateChatActivity.java
| 1 | 1 | package com.cnlive.im.ui; |
| 2 | 2 | |
| 3 | +import android.content.Intent; | |
| 3 | 4 | import android.os.Bundle; |
| 4 | 5 | import android.os.Handler; |
| 5 | 6 | import android.support.v7.app.AppCompatActivity; |
| ... | ... | @@ -43,13 +44,10 @@ public class PrivateChatActivity extends AppCompatActivity implements View.OnCli |
| 43 | 44 | private Button userId_btn_top; |
| 44 | 45 | private String oppositeID; |
| 45 | 46 | private LinearLayout edit_layout; |
| 46 | - private EditText my_id_edit; | |
| 47 | - private String my_id_editID; | |
| 48 | - private LinearLayout my_liner_userID; | |
| 49 | 47 | private Handler mHandler; |
| 50 | 48 | private EditText opposite_name_edit; |
| 51 | - private EditText my_name_edit; | |
| 52 | - private String my_name_edit1; | |
| 49 | + private String user_name_string; | |
| 50 | + private String user_id_string; | |
| 53 | 51 | |
| 54 | 52 | @Override |
| 55 | 53 | protected void onCreate(Bundle savedInstanceState) { |
| ... | ... | @@ -63,7 +61,6 @@ public class PrivateChatActivity extends AppCompatActivity implements View.OnCli |
| 63 | 61 | } |
| 64 | 62 | |
| 65 | 63 | private void initView() { |
| 66 | - my_name_edit = (EditText) findViewById(R.id.my_name_edit); | |
| 67 | 64 | opposite_name_edit = (EditText) findViewById(R.id.opposite_name_edit); |
| 68 | 65 | chatListView = (ListView) findViewById(R.id.private_list_view); |
| 69 | 66 | chatListAdapter = new ChatListAdapter(this); |
| ... | ... | @@ -75,10 +72,10 @@ public class PrivateChatActivity extends AppCompatActivity implements View.OnCli |
| 75 | 72 | userId_btn_top = (Button) findViewById(R.id.userId_btn_top); |
| 76 | 73 | userId_btn_top.setOnClickListener(this); |
| 77 | 74 | edit_layout = (LinearLayout) findViewById(R.id.edit_layout); |
| 78 | - my_id_edit = (EditText) findViewById(R.id.my_id_edit); | |
| 79 | 75 | user_id_edit = (EditText) findViewById(opposite_id_edit); |
| 80 | - my_liner_userID = (LinearLayout) findViewById(R.id.my_liner_userID); | |
| 81 | - | |
| 76 | + Intent intent = getIntent(); | |
| 77 | + user_name_string = intent.getStringExtra("user_name_string"); | |
| 78 | + user_id_string = intent.getStringExtra("user_id_string"); | |
| 82 | 79 | } |
| 83 | 80 | |
| 84 | 81 | |
| ... | ... | @@ -98,22 +95,15 @@ public class PrivateChatActivity extends AppCompatActivity implements View.OnCli |
| 98 | 95 | //发送私聊消息,需要传入目标ID与发送的消息内容 |
| 99 | 96 | if (user_id_edit.getText().toString().isEmpty()) { |
| 100 | 97 | Toast.makeText(this, "对方ID不能为空", Toast.LENGTH_SHORT).show(); |
| 101 | - } else if (my_id_edit.getText().toString().isEmpty()) { | |
| 102 | - Toast.makeText(this, "你的ID不能为空", Toast.LENGTH_SHORT).show(); | |
| 103 | - } else if (my_name_edit.getText().toString().isEmpty()) { | |
| 104 | - Toast.makeText(this, "你的name不能为空", Toast.LENGTH_SHORT).show(); | |
| 105 | 98 | } else if (opposite_name_edit.getText().toString().isEmpty()) { |
| 106 | 99 | Toast.makeText(this, "对方name不能为空", Toast.LENGTH_SHORT).show(); |
| 107 | 100 | } else { |
| 108 | 101 | user_id_edit.getText().toString(); |
| 109 | 102 | oppositeID = user_id_edit.getText().toString(); |
| 110 | - my_id_editID = my_id_edit.getText().toString(); | |
| 111 | - my_name_edit1 = my_name_edit.getText().toString(); | |
| 112 | 103 | linearLayoutUseID.setVisibility(View.INVISIBLE); |
| 113 | 104 | edit_layout.setVisibility(View.VISIBLE); |
| 114 | 105 | chatListView.setVisibility(View.VISIBLE); |
| 115 | - my_liner_userID.setVisibility(View.INVISIBLE); | |
| 116 | - CNUserInfo cnName = new CNUserInfo(my_id_editID, my_name_edit1, ""); | |
| 106 | + CNUserInfo cnName = new CNUserInfo(user_id_string, user_name_string, ""); | |
| 117 | 107 | ChatUtil.login(cnName, connectListener); |
| 118 | 108 | } |
| 119 | 109 | ... | ... |
app/src/main/java/com/cnlive/im/ui/UserLoginActivity.java
0 → 100644
| 1 | +package com.cnlive.im.ui; | |
| 2 | + | |
| 3 | +import android.content.Intent; | |
| 4 | +import android.os.Bundle; | |
| 5 | +import android.support.annotation.Nullable; | |
| 6 | +import android.support.v7.app.AppCompatActivity; | |
| 7 | +import android.view.View; | |
| 8 | +import android.widget.Button; | |
| 9 | +import android.widget.EditText; | |
| 10 | +import android.widget.Toast; | |
| 11 | + | |
| 12 | +import com.cnlive.im.R; | |
| 13 | + | |
| 14 | + | |
| 15 | +/** | |
| 16 | + * @author 陈硕 | |
| 17 | + * @time 2017/3/16 18:29 | |
| 18 | + * @desc ${TODD} | |
| 19 | + */ | |
| 20 | +public class UserLoginActivity extends AppCompatActivity implements View.OnClickListener { | |
| 21 | + | |
| 22 | + private EditText user_name; | |
| 23 | + private EditText user_id; | |
| 24 | + private Button userBtn; | |
| 25 | + | |
| 26 | + @Override | |
| 27 | + protected void onCreate(@Nullable Bundle savedInstanceState) { | |
| 28 | + super.onCreate(savedInstanceState); | |
| 29 | + | |
| 30 | + setContentView(R.layout.activity_user); | |
| 31 | + intUI(); | |
| 32 | + } | |
| 33 | + | |
| 34 | + private void intUI() { | |
| 35 | + user_name = (EditText) findViewById(R.id.user_name); | |
| 36 | + user_id = (EditText) findViewById(R.id.user_ID); | |
| 37 | + userBtn = (Button) findViewById(R.id.uconnect); | |
| 38 | + userBtn.setOnClickListener(this); | |
| 39 | + } | |
| 40 | + | |
| 41 | + | |
| 42 | + @Override | |
| 43 | + public void onClick(View v) { | |
| 44 | + if(user_id.getText().toString().isEmpty()){ | |
| 45 | + Toast.makeText(UserLoginActivity.this,"id不能为空",Toast.LENGTH_SHORT).show(); | |
| 46 | + }else if(user_name.getText().toString().isEmpty()){ | |
| 47 | + Toast.makeText(UserLoginActivity.this,"用户名不能为空",Toast.LENGTH_SHORT).show(); | |
| 48 | + }else { | |
| 49 | + String user_name_string = user_name.getText().toString(); | |
| 50 | + String user_id_string = user_id.getText().toString(); | |
| 51 | + Intent intent = new Intent(UserLoginActivity.this, ChatItemActivity.class); | |
| 52 | + intent.putExtra("user_name_string",user_name_string); | |
| 53 | + intent.putExtra("user_id_string",user_id_string); | |
| 54 | + startActivity(intent); | |
| 55 | + } | |
| 56 | + } | |
| 57 | +} | ... | ... |
app/src/main/res/layout/activity_groupchat.xml
| ... | ... | @@ -154,77 +154,14 @@ |
| 154 | 154 | android:layout_height="wrap_content" |
| 155 | 155 | android:text="退出聊天室2" /> |
| 156 | 156 | |
| 157 | - <Button | |
| 158 | - android:id="@+id/user_switch" | |
| 159 | - android:layout_width="wrap_content" | |
| 160 | - android:layout_height="wrap_content" | |
| 161 | - android:text="切换用户" /> | |
| 157 | + | |
| 162 | 158 | |
| 163 | 159 | </LinearLayout> |
| 164 | 160 | </LinearLayout> |
| 165 | 161 | </RelativeLayout> |
| 166 | 162 | |
| 167 | 163 | |
| 168 | - <LinearLayout | |
| 169 | - android:id="@+id/lin_user" | |
| 170 | - android:layout_width="match_parent" | |
| 171 | - android:layout_height="wrap_content" | |
| 172 | - android:layout_centerVertical="true" | |
| 173 | - android:orientation="vertical" | |
| 174 | - android:visibility="invisible"> | |
| 175 | - | |
| 176 | - | |
| 177 | - <LinearLayout | |
| 178 | - android:layout_width="match_parent" | |
| 179 | - android:layout_height="wrap_content"> | |
| 180 | - | |
| 181 | - <TextView | |
| 182 | - android:layout_width="wrap_content" | |
| 183 | - android:layout_height="match_parent" | |
| 184 | - android:gravity="center" | |
| 185 | - android:text="userID :" /> | |
| 186 | - | |
| 187 | - <EditText | |
| 188 | - android:id="@+id/user_ID" | |
| 189 | - android:layout_width="0dp" | |
| 190 | - android:layout_height="match_parent" | |
| 191 | - android:layout_weight="0.7" /> | |
| 192 | - | |
| 193 | - <Button | |
| 194 | - android:layout_width="0dp" | |
| 195 | - android:layout_height="match_parent" | |
| 196 | - android:layout_weight="0.2" | |
| 197 | - android:text="确认" | |
| 198 | - android:visibility="invisible" /> | |
| 199 | - | |
| 200 | - </LinearLayout> | |
| 201 | - | |
| 202 | - | |
| 203 | - <LinearLayout | |
| 204 | - android:layout_width="match_parent" | |
| 205 | - android:layout_height="wrap_content"> | |
| 206 | - | |
| 207 | - <TextView | |
| 208 | - android:layout_width="wrap_content" | |
| 209 | - android:layout_height="match_parent" | |
| 210 | - android:gravity="center" | |
| 211 | - android:text="userName:" /> | |
| 212 | - | |
| 213 | - <EditText | |
| 214 | - android:id="@+id/user_name" | |
| 215 | - android:layout_width="0dp" | |
| 216 | - android:layout_height="match_parent" | |
| 217 | - android:layout_weight="0.7" /> | |
| 218 | - | |
| 219 | - <Button | |
| 220 | - android:id="@+id/user_imfor_send" | |
| 221 | - android:layout_width="0dp" | |
| 222 | - android:layout_height="match_parent" | |
| 223 | - android:layout_weight="0.2" | |
| 224 | - android:text="确认" /> | |
| 225 | - </LinearLayout> | |
| 226 | 164 | |
| 227 | - </LinearLayout> | |
| 228 | 165 | |
| 229 | 166 | |
| 230 | 167 | </RelativeLayout> | ... | ... |
app/src/main/res/layout/activity_main.xml
| ... | ... | @@ -4,37 +4,14 @@ |
| 4 | 4 | android:id="@+id/activity_main" |
| 5 | 5 | android:layout_width="match_parent" |
| 6 | 6 | android:layout_height="match_parent" |
| 7 | - android:paddingBottom="@dimen/activity_vertical_margin" | |
| 8 | - android:paddingLeft="@dimen/activity_horizontal_margin" | |
| 9 | - android:paddingRight="@dimen/activity_horizontal_margin" | |
| 10 | - android:paddingTop="@dimen/activity_vertical_margin" | |
| 11 | 7 | tools:context="com.cnlive.im.ui.MainActivity"> |
| 12 | 8 | |
| 13 | - | |
| 14 | - <Button | |
| 15 | - android:visibility="invisible" | |
| 16 | - android:id="@+id/groupChat" | |
| 17 | - android:layout_width="match_parent" | |
| 18 | - android:layout_height="wrap_content" | |
| 19 | - android:layout_marginTop="140dp" | |
| 20 | - android:text="群聊" /> | |
| 21 | - | |
| 22 | - <Button | |
| 23 | - android:visibility="invisible" | |
| 24 | - android:id="@+id/privateChat" | |
| 25 | - android:layout_width="match_parent" | |
| 26 | - android:layout_height="wrap_content" | |
| 27 | - android:layout_below="@+id/groupChat" | |
| 28 | - android:layout_marginTop="34dp" | |
| 29 | - android:text="私聊" /> | |
| 30 | - | |
| 31 | - <Button | |
| 32 | - android:id="@+id/connect" | |
| 33 | - android:layout_width="match_parent" | |
| 34 | - android:layout_height="wrap_content" | |
| 35 | - android:layout_below="@+id/privateChat" | |
| 36 | - android:layout_marginTop="36dp" | |
| 37 | - android:text="连接服务器" /> | |
| 38 | - | |
| 9 | + <Button | |
| 10 | + android:id="@+id/connected" | |
| 11 | + android:layout_width="match_parent" | |
| 12 | + android:layout_height="wrap_content" | |
| 13 | + android:layout_centerInParent="true" | |
| 14 | + android:text="连接" | |
| 15 | + /> | |
| 39 | 16 | |
| 40 | 17 | </RelativeLayout> | ... | ... |
app/src/main/res/layout/activity_private_chat.xml
| ... | ... | @@ -85,54 +85,7 @@ |
| 85 | 85 | android:text="完成" /> |
| 86 | 86 | |
| 87 | 87 | </LinearLayout> |
| 88 | - <LinearLayout | |
| 89 | - android:id="@+id/my_liner_userID" | |
| 90 | - android:layout_width="match_parent" | |
| 91 | - android:layout_height="wrap_content" | |
| 92 | - android:layout_above="@id/opposite_liner_useID" | |
| 93 | - android:orientation="horizontal"> | |
| 94 | 88 | |
| 95 | - <TextView | |
| 96 | - android:layout_width="wrap_content" | |
| 97 | - android:layout_height="wrap_content" | |
| 98 | - android:layout_gravity="center" | |
| 99 | - android:gravity="center" | |
| 100 | - android:text="我的id :" | |
| 101 | - android:textSize="22dp" | |
| 102 | - android:textStyle="bold" /> | |
| 103 | - | |
| 104 | - <EditText | |
| 105 | - android:id="@+id/my_id_edit" | |
| 106 | - android:layout_width="0dp" | |
| 107 | - android:layout_height="wrap_content" | |
| 108 | - android:layout_gravity="center" | |
| 109 | - android:layout_weight="0.5" /> | |
| 110 | - | |
| 111 | - <TextView | |
| 112 | - android:layout_width="wrap_content" | |
| 113 | - android:layout_height="wrap_content" | |
| 114 | - android:layout_gravity="center" | |
| 115 | - android:gravity="center" | |
| 116 | - android:text="name:" | |
| 117 | - android:textSize="22dp" | |
| 118 | - android:textStyle="bold" /> | |
| 119 | - | |
| 120 | - <EditText | |
| 121 | - android:id="@+id/my_name_edit" | |
| 122 | - android:layout_width="0dp" | |
| 123 | - android:layout_height="wrap_content" | |
| 124 | - android:layout_gravity="center" | |
| 125 | - android:layout_weight="0.5" /> | |
| 126 | - | |
| 127 | - <Button | |
| 128 | - android:id="@+id/my_btn_top" | |
| 129 | - android:layout_width="wrap_content" | |
| 130 | - android:layout_height="wrap_content" | |
| 131 | - android:layout_gravity="center" | |
| 132 | - android:text="完成" | |
| 133 | - android:visibility="invisible" /> | |
| 134 | - | |
| 135 | - </LinearLayout> | |
| 136 | 89 | |
| 137 | 90 | |
| 138 | 91 | </RelativeLayout> | ... | ... |