|
9#
楼主 |
发表于 2014-9-5 13:45:00
|
只看该作者
- package com.dolp.view.room.toAnchat;
- import com.bairuitech.anychat.AnyChatBaseEvent;
- import com.bairuitech.anychat.AnyChatCoreSDK;
- import com.bairuitech.anychat.AnyChatDefine;
- import android.R;
- import android.app.Activity;
- import android.content.Intent;
- import android.graphics.Color;
- import android.os.Bundle;
- import android.text.InputType;
- import android.util.DisplayMetrics;
- import android.util.Log;
- import android.view.Gravity;
- import android.view.MotionEvent;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.view.View.OnTouchListener;
- import android.view.ViewGroup.LayoutParams;
- import android.view.inputmethod.InputMethodManager;
- import android.widget.Button;
- import android.widget.CheckBox;
- import android.widget.EditText;
- import android.widget.ImageView;
- import android.widget.LinearLayout;
- import android.widget.ProgressBar;
- import android.widget.TextView;
- import android.widget.Toast;
- import android.widget.ImageView.ScaleType;
- public class To extends Activity implements AnyChatBaseEvent {
- private LinearLayout fullLayout;
- private LinearLayout mainLayout;
- private LinearLayout progressLayout;
- private Button configBtn;
- private Button loginBtn;
- private CheckBox saveCheckBox;
- private ConfigEntity configEntity;
- private EditText nameEditText;
- private EditText passwordEditText;
- private CheckBox anonymousCheckBox;
- private boolean bNeedRelease = false;
- public AnyChatCoreSDK anychat;
- String roomID;
- String UserName;
- TextView tloading;
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(com.dolp.R.layout.room_login);
- Intent intent = getIntent();
- configEntity = ConfigService.LoadConfig(this);
- roomID = intent.getExtras().getString("subId");
- tloading = (TextView) findViewById(com.dolp.R.id.tloading);
- Log.e("", "我进入的房间ID是:" + roomID);
- UserName = intent.getExtras().getString("username");
- InitialSDK();
- Login();
- }
- private void InitialSDK() {
- if (anychat == null) {
- anychat = new AnyChatCoreSDK();
- anychat.SetBaseEvent(this);
- anychat.mSensorHelper.InitSensor(this);
- if (configEntity.useARMv6Lib != 0)
- AnyChatCoreSDK.SetSDKOptionInt(AnyChatDefine.BRAC_SO_CORESDK_USEARMV6LIB, 1);
- anychat.InitSDK(android.os.Build.VERSION.SDK_INT, 0);
- bNeedRelease = true;
- }
- }
- //登陆连接两项操作
- private void Login() {
- configEntity.IsSaveNameAndPw = false;
- ConfigService.SaveConfig(this, configEntity);
- this.anychat.Connect("218.244.135.56", 8906);
- this.anychat.Login(UserName, "");
- }
- protected void onDestroy() {
- myThread();
- super.onDestroy();
- }
- protected void onResume() {
- configEntity = ConfigService.LoadConfig(this);
- anychat.SetBaseEvent(this);
- super.onResume();
- }
- //线程关闭SDK
- private void myThread() {
- // TODO Auto-generated method stub
- Runnable runnable = new Runnable() {
- @Override
- public void run() {
- // TODO Auto-generated method stub
- if (bNeedRelease) {
- anychat.Release(); // 关闭SDK
- }
- }
- };
- Thread thread = new Thread(runnable);
- thread.start();
- }
- @Override
- public void OnAnyChatConnectMessage(boolean bSuccess) {
- if (!bSuccess) {
- loginBtn.setClickable(true);
- Toast.makeText(this, "连接服务器失败,自动重连,请稍后...", Toast.LENGTH_SHORT)
- .show();
- progressLayout.setVisibility(View.GONE);
- }
- }
- @Override
- public void OnAnyChatEnterRoomMessage(int dwRoomId, int dwErrorCode) {
- // TODO Auto-generated method stub
- Log.e("", "进入房间事件"+dwRoomId+"||"+dwErrorCode);
-
- }
- @Override
- public void OnAnyChatLinkCloseMessage(int dwErrorCode) {
- Toast.makeText(this, "连接关闭,error:" + dwErrorCode, Toast.LENGTH_SHORT).show();
- }
- @Override
- public void OnAnyChatLoginMessage(int dwUserId, int dwErrorCode) {
- //当登陆成功后进入房间
- if (dwErrorCode == 0) {
- Toast.makeText(this, "登录成功!" + roomID, 4000).show();
- bNeedRelease = false;
- anychat.EnterRoom(Integer.parseInt(roomID), "");
- } else {
- Toast.makeText(this, "登录失败,错误代码:" + dwErrorCode, Toast.LENGTH_SHORT).show();
- }
- }
- @Override
- public void OnAnyChatOnlineUserMessage(int dwUserNum, int dwRoomId) {
- Log.e("", "当前房间的在线人数:" + dwUserNum);
- int[] dmc = anychat.GetOnlineUser();
- Log.e("", "多少个用户" + dmc.length);
- if (dwUserNum <= 1) {
- tloading.setVisibility(View.VISIBLE);
- }
- for (int i : dmc) {
- Log.e("", "用户:" + i);
- }
- /*
- if(dwUserNum>1){
- Intent intent = new Intent();
- intent.putExtra("UserID", dmc[0] + "");
- intent.setClass(To.this, VideoActivity.class);
- startActivity(intent);
- }
- */
- }
- @Override
- public void OnAnyChatUserAtRoomMessage(int dwUserId, boolean bEnter) {
- Log.e("", "有人进出入房间");
- if (bEnter) {
- //如果有人进入了就跳转到下一个界面
- tloading.setVisibility(View.INVISIBLE);
- Intent intent = new Intent();
- intent.putExtra("UserID", dwUserId + "");
- intent.setClass(To.this, VideoActivity.class);
- startActivity(intent);
- }
- }
- }
复制代码 |
|