MainActivity.java 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. //package com.vvsip.amdemo;
  2. //
  3. //import android.annotation.SuppressLint;
  4. //import android.app.Fragment;
  5. //import android.app.FragmentManager;
  6. //import android.app.FragmentTransaction;
  7. //import android.os.Build;
  8. //import android.os.Bundle;
  9. //import android.os.Handler;
  10. //import android.os.Message;
  11. //import android.support.v7.app.ActionBarActivity;
  12. //import android.util.Log;
  13. //import android.view.Menu;
  14. //import android.view.MenuItem;
  15. //import android.view.View;
  16. //import android.view.WindowManager;
  17. //import android.widget.Button;
  18. //import android.widget.EditText;
  19. //import android.widget.FrameLayout;
  20. //import android.widget.TextView;
  21. //
  22. //import com.vvsip.ansip.IVvsipService;
  23. //import com.vvsip.ansip.IVvsipServiceListener;
  24. //import com.vvsip.ansip.VvsipCall;
  25. //import com.vvsip.ansip.VvsipService;
  26. //import com.vvsip.ansip.VvsipTask;
  27. //
  28. //import java.util.ArrayList;
  29. //import java.util.List;
  30. //
  31. ///*
  32. // * ������Activity
  33. // */
  34. //public class MainActivity extends ActionBarActivity implements
  35. // View.OnClickListener, IVvsipServiceListener {
  36. //
  37. // private EditText serverAddr;
  38. // private EditText userphone;
  39. // private EditText passwd;
  40. // private EditText callee;
  41. //
  42. // private TextView callStatus;
  43. //
  44. // private Button mButton_register;
  45. // private Button mButton_audioCall;
  46. // private Button mButton_endCall;
  47. // private Button mButton_offHook;
  48. // private Button mButton_addVideo;
  49. // private EditText dtmf;
  50. // private Button mButton_sendDTMF;
  51. //
  52. //
  53. // static String mTag = "MainActivity";
  54. // private List<VvsipCall> mVvsipCalls = null;
  55. //
  56. // private String lan_callee;
  57. //
  58. // @Override
  59. // protected void onCreate(Bundle savedInstanceState) {
  60. // super.onCreate(savedInstanceState);
  61. // setContentView(R.layout.activity_main);
  62. //
  63. // serverAddr = (EditText) findViewById(R.id.server_addr);
  64. // userphone = (EditText) findViewById(R.id.userphone);
  65. // passwd = (EditText) findViewById(R.id.passwd);
  66. // callee = (EditText) findViewById(R.id.callee);
  67. //
  68. // callStatus = (TextView) findViewById(R.id.call_status);
  69. //
  70. // mButton_register = (Button) findViewById(R.id.register);
  71. // mButton_audioCall = (Button) findViewById(R.id.audio_call);
  72. // mButton_endCall = (Button) findViewById(R.id.end_call);
  73. // mButton_offHook = (Button) findViewById(R.id.off_hook);
  74. // mButton_addVideo = (Button) findViewById(R.id.add_video);
  75. // mButton_sendDTMF = (Button) findViewById(R.id.send_dtmf);
  76. //
  77. //
  78. //
  79. // mButton_register.setOnClickListener(this);
  80. // mButton_audioCall.setOnClickListener(this);
  81. // mButton_endCall.setOnClickListener(this);
  82. // mButton_offHook.setOnClickListener(this);
  83. // mButton_addVideo.setOnClickListener(this);
  84. // mButton_sendDTMF.setOnClickListener(this);
  85. //
  86. // IVvsipService _service = VvsipService.getService();
  87. // Log.i(mTag, "lifecycle // _service");
  88. // if (_service != null) {
  89. //
  90. // _service.addListener(this);
  91. // _service.setMessageHandler(messageHandler);
  92. // Log.i(mTag, "lifecycle // addListener");
  93. // } else {
  94. // Log.i(mTag, "lifecycle // _service==null");
  95. // }
  96. //
  97. // if (mVvsipCalls == null) {
  98. // mVvsipCalls = new ArrayList<VvsipCall>();
  99. // }
  100. //
  101. // }
  102. //
  103. // @Override
  104. // public void onDestroy() {
  105. // IVvsipService _service = VvsipService.getService();
  106. // if (_service != null)
  107. // _service.removeListener(this);
  108. // if (mVvsipCalls != null) {
  109. // mVvsipCalls.clear();
  110. // mVvsipCalls = null;
  111. // }
  112. // super.onDestroy();
  113. // Log.i(mTag, "lifecycle // onDestroy");
  114. // }
  115. //
  116. // @Override
  117. // public boolean onCreateOptionsMenu(Menu menu) {
  118. // // Inflate the menu; this adds items to the action bar if it is present.
  119. // getMenuInflater().inflate(R.menu.main, menu);
  120. // return true;
  121. // }
  122. //
  123. // @Override
  124. // public boolean onOptionsItemSelected(MenuItem item) {
  125. // // Handle action bar item clicks here. The action bar will
  126. // // automatically handle clicks on the Home/Up button, so long
  127. // // as you specify a parent activity in AndroidManifest.xml.
  128. // int id = item.getItemId();
  129. // if (id == R.id.action_settings) {
  130. // return true;
  131. // }
  132. // return super.onOptionsItemSelected(item);
  133. // }
  134. //
  135. // @Override
  136. // public void onNewVvsipCallEvent(final VvsipCall call) {
  137. //
  138. // MainActivity.this.runOnUiThread(new Runnable() {
  139. // public void run() {
  140. // try {
  141. // if (call == null) {
  142. // return;
  143. // }
  144. //
  145. // if (mVvsipCalls == null)
  146. // return;
  147. // mVvsipCalls.add(call);
  148. //
  149. // if (Build.VERSION.SDK_INT >= 5) {
  150. // getWindow()
  151. // .addFlags( // WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
  152. // // |
  153. // WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
  154. // | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
  155. // | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
  156. // }
  157. //
  158. // } catch (Exception e) {
  159. // Log.e(mTag, "onNewVvsipCallEvent: " + e);
  160. // }
  161. // }
  162. // });
  163. // }
  164. //
  165. // @Override
  166. // public void onStatusVvsipCallEvent(VvsipCall call) {
  167. // Log.d("SIPTES","call :"+call.mState);
  168. // }
  169. //
  170. // @Override
  171. // public void onRemoveVvsipCallEvent(final VvsipCall call) {
  172. //
  173. // MainActivity.this.runOnUiThread(new Runnable() {
  174. // public void run() {
  175. // try {
  176. // if (call == null) {
  177. // return;
  178. // }
  179. //
  180. // // 4 crash detected here for 4.0.9 with mVvsipCalls=NULL
  181. // if (mVvsipCalls == null)
  182. // return;
  183. // mVvsipCalls.remove(call);
  184. //
  185. // if (mVvsipCalls.size() == 0) {
  186. // if (Build.VERSION.SDK_INT >= 5) {
  187. // getWindow()
  188. // .clearFlags( // WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
  189. // // |
  190. // WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
  191. // | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
  192. // | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
  193. // }
  194. // }
  195. // } catch (Exception e) {
  196. // Log.e(mTag, "onRemoveVvsipCallEvent: " + e);
  197. // }
  198. // }
  199. // });
  200. // }
  201. //
  202. // @Override
  203. // public void onRegistrationEvent(final int rid, final String remoteUri,
  204. // final int code, String reason) {
  205. //
  206. // }
  207. //
  208. // @SuppressLint("HandlerLeak")
  209. // private Handler messageHandler = new Handler() {
  210. //
  211. // @Override
  212. // public void handleMessage(Message msg) {
  213. // Log.i(mTag, "VvsipEvent received (?" + msg.what + " " + msg.arg1
  214. // + " " + msg.arg2 + ")\n");
  215. // Log.i(mTag, "#" + msg.obj);
  216. // callStatus.setText("" + msg.obj + callStatus.getText());
  217. //
  218. // if(msg.obj.toString().contains("autocall")){ //��������
  219. // VvsipCall pCall = null;
  220. // Log.e(mTag, "onClick1");
  221. // for (VvsipCall _pCall : mVvsipCalls) {
  222. // if(_pCall.cid > 0)
  223. // Log.e(mTag, "state#"+_pCall.mState);
  224. // if (_pCall.cid > 0 && _pCall.mState <= 2) {
  225. // pCall = _pCall;
  226. // break;
  227. // }
  228. // }
  229. // Log.e(mTag, "onClick2");
  230. // if (pCall == null)
  231. // return;
  232. // Log.e(mTag, "onClick3#"+pCall.mState);
  233. // IVvsipService _service = VvsipService.getService();
  234. // if (_service == null)
  235. // return;
  236. // VvsipTask _vvsipTask = _service.getVvsipTask();
  237. // if (_vvsipTask == null)
  238. // return;
  239. // pCall.stop();
  240. // _service.setSpeakerModeOff();
  241. // }
  242. //
  243. //
  244. // }
  245. //
  246. // };
  247. //
  248. // @Override
  249. // public void onClick(View v) {
  250. //
  251. // /*
  252. // * ע��
  253. // */
  254. // if (v == mButton_register) {
  255. // MainActivity.this.runOnUiThread(new Runnable() {
  256. // public void run() {
  257. // IVvsipService _service = VvsipService.getService();
  258. // if (_service != null) {
  259. // // _service.StartVvsipLayer();
  260. //
  261. // _service.register(serverAddr.getText().toString(),
  262. // userphone.getText().toString(), passwd
  263. // .getText().toString());
  264. // }
  265. // }
  266. // });
  267. // return;
  268. // }
  269. // /*
  270. // * �������
  271. // */
  272. // if (v == mButton_audioCall) {
  273. // if (callee.getText().length() == 0)
  274. // return;
  275. // MainActivity.this.runOnUiThread(new Runnable() {
  276. // public void run() {
  277. // IVvsipService _service = VvsipService.getService();
  278. // if (_service == null)
  279. // return;
  280. // _service.initiateOutgoingCall(callee.getText().toString());
  281. // }
  282. // });
  283. // return;
  284. // }
  285. // /*
  286. // * ����ͨ��
  287. // */
  288. // if (v == mButton_endCall) {
  289. // VvsipCall pCall = null;
  290. // Log.e(mTag, "onClick1");
  291. // for (VvsipCall _pCall : mVvsipCalls) {
  292. // if(_pCall.cid > 0)
  293. // Log.e(mTag, "state#"+_pCall.mState);
  294. // if (_pCall.cid > 0 && _pCall.mState <= 2) {
  295. // pCall = _pCall;
  296. // break;
  297. // }
  298. // }
  299. // Log.e(mTag, "onClick2");
  300. // if (pCall == null)
  301. // return;
  302. // Log.e(mTag, "onClick3#"+pCall.mState);
  303. // IVvsipService _service = VvsipService.getService();
  304. // if (_service == null)
  305. // return;
  306. // VvsipTask _vvsipTask = _service.getVvsipTask();
  307. // if (_vvsipTask == null)
  308. // return;
  309. // pCall.stop();
  310. // _service.setSpeakerModeOff();
  311. // _service.stopPlayer(); //���йҶϣ�����ֹͣ;��������Closed��Released״̬�л������������ġ�
  312. // //����HDL�DZ�û��Ч����������������һ�� ,By 20160822
  313. // _service.setAudioNormalMode();
  314. // return;
  315. // }
  316. //
  317. // /*
  318. // * �����绰
  319. // */
  320. // if (v == mButton_offHook) {
  321. // for (VvsipCall _pCall : mVvsipCalls) {
  322. // if (_pCall.cid > 0 && _pCall.mState < 2 && _pCall.mIncomingCall) {
  323. // // ANSWER EXISTING CALL
  324. // int i = _pCall.answer(200, 1);
  325. // IVvsipService _service = VvsipService.getService();
  326. // if (_service != null) {
  327. // if (i >= 0) {
  328. // _service.stopPlayer();
  329. // _service.setSpeakerModeOff();
  330. // _service.setAudioInCallMode();
  331. // }
  332. // }
  333. // break;
  334. // }
  335. // }
  336. // }
  337. // /*
  338. // * ������Ƶͨ��
  339. // */
  340. // if (v == mButton_addVideo) {
  341. // MainActivity.this.runOnUiThread(new Runnable() {
  342. // public void run() {
  343. // Fragment fragment = null;
  344. // fragment = new FragmentInVideoCall();
  345. // FragmentManager frgManager = getFragmentManager();
  346. // FragmentTransaction ft = frgManager.beginTransaction()
  347. // .replace(R.id.content_frame, fragment);
  348. //
  349. // ft.addToBackStack(null);
  350. // ft.commit();
  351. // FrameLayout fly = (FrameLayout) MainActivity.this
  352. // .findViewById(R.id.content_frame);
  353. // fly.bringToFront();
  354. // }
  355. // });
  356. // }
  357. //
  358. // /*
  359. // * ����DTMF
  360. // */
  361. // if (v == mButton_sendDTMF) {
  362. // if (dtmf.getText().length() == 0)
  363. // return;
  364. // MainActivity.this.runOnUiThread(new Runnable() {
  365. // public void run() {
  366. // IVvsipService _service = VvsipService.getService();
  367. // if (_service == null)
  368. // return;
  369. // _service.sendDTMF(dtmf.getText().toString());
  370. // }
  371. // });
  372. // return;
  373. // }
  374. //
  375. // }
  376. //}