Advertisement
Guest User

Untitled

a guest
Feb 20th, 2016
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.03 KB | None | 0 0
  1. apply plugin: 'com.android.application'
  2.  
  3. android {
  4. compileSdkVersion 'Google Inc.:Google APIs:23'
  5. buildToolsVersion "23.0.2"
  6.  
  7. defaultConfig {
  8. applicationId "com.hm.runanddelete"
  9. minSdkVersion 14
  10. targetSdkVersion 23
  11. versionCode 1
  12. versionName "1.0"
  13. }
  14. buildTypes {
  15. release {
  16. minifyEnabled false
  17. proguardFiles getDefaultProguardFile('proguard- android.txt'), 'proguard-rules.pro'
  18. }
  19. }
  20. }
  21.  
  22. dependencies {
  23. testCompile 'junit:junit:4.12'
  24. compile fileTree(dir: 'libs', include: ['*.jar'])
  25.  
  26.  
  27. }
  28.  
  29. // Top-level build file where you can add configuration options common to all sub-projects/modules.
  30.  
  31. buildscript {
  32. repositories {
  33. jcenter()
  34. }
  35.  
  36. dependencies {
  37. classpath 'com.android.tools.build:gradle:2.0.0-alpha5'
  38.  
  39. // NOTE: Do not place your application dependencies here; they belong
  40. // in the individual module build.gradle files
  41. }
  42. }
  43.  
  44. allprojects {
  45. repositories {
  46. jcenter()
  47. }
  48. }
  49.  
  50. task clean(type: Delete) {
  51. delete rootProject.buildDir
  52. }
  53.  
  54. <?xml version="1.0" encoding="utf-8"?>
  55. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  56. package="com.hm.runanddelete">
  57.  
  58. <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
  59. <uses-feature android:name="android.hardware.camera.front" />
  60. <uses-feature android:name="android.hardware.microphone"/>
  61. <uses-permission android:name="android.permission.CAMERA" />
  62. <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
  63. <uses-permission android:name="android.permission.RECORD_AUDIO" />
  64. <uses-permission android:name="android.permission.INTERNET" />
  65. <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
  66. <uses-permission android:name="android.permission.VIBRATE" />
  67. <uses-permission android:name="android.permission.READ_PHONE_STATE" />
  68. <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
  69.  
  70. <uses-feature android:name="android.hardware.camera" />
  71. <uses-feature android:name="android.hardware.camera.autofocus" />
  72.  
  73. <uses-feature
  74. android:glEsVersion="0x00020000"
  75. android:required="true" />
  76.  
  77.  
  78.  
  79.  
  80. <application
  81. android:allowBackup="true"
  82. android:icon="@mipmap/ic_launcher"
  83. android:label="@string/app_name"
  84. android:supportsRtl="true"
  85. android:theme="@style/AppTheme">
  86. <activity android:name=".MainActivity">
  87. <intent-filter>
  88. <action android:name="android.intent.action.MAIN" />
  89.  
  90. <category android:name="android.intent.category.LAUNCHER" />
  91. </intent-filter>
  92. </activity>
  93. </application>
  94.  
  95. </manifest>
  96.  
  97. public class MainActivity extends Activity implements QBRTCClientSessionCallbacks, QBRTCClientVideoTracksCallbacks {
  98. static final String APP_ID = "...";
  99. static final String AUTH_KEY = "...";
  100. static final String AUTH_SECRET = "...";
  101. static final String ACCOUNT_KEY = "...";
  102.  
  103.  
  104. String login = "";
  105. String password = "";
  106.  
  107.  
  108. QBChatService chatService;
  109. QBRTCClient rtcClient;
  110.  
  111.  
  112. EditText et_user, et_paw, et_id;
  113. Button btn_call, btn_login;
  114.  
  115. @Override
  116. protected void onCreate(Bundle savedInstanceState) {
  117. super.onCreate(savedInstanceState);
  118. setContentView(R.layout.activity_main);
  119.  
  120. et_user = (EditText) findViewById(R.id.et_caller_user);
  121. et_paw = (EditText) findViewById(R.id.et_caller_pw);
  122. et_id = (EditText) findViewById(R.id.et_caller_tid);
  123. btn_call = (Button) findViewById(R.id.btn_caller_call);
  124. btn_login = (Button) findViewById(R.id.btn_caller_login);
  125.  
  126.  
  127. btn_login.setOnClickListener(new View.OnClickListener() {
  128. @Override
  129. public void onClick(View v) {
  130. login = et_user.getText().toString();
  131. password = et_paw.getText().toString();
  132. initializingQB();
  133. }
  134. });
  135. btn_call.setOnClickListener(new View.OnClickListener() {
  136. @Override
  137. public void onClick(View v) {
  138.  
  139.  
  140. starcall(Integer.parseInt(et_id.getText().toString()));
  141.  
  142. }
  143. });
  144.  
  145.  
  146. }
  147.  
  148. private void initializingQB() {
  149. QBSettings.getInstance().init(getApplicationContext(), APP_ID, AUTH_KEY, AUTH_SECRET);
  150. QBSettings.getInstance().setAccountKey(ACCOUNT_KEY);
  151.  
  152. final QBUser user = new QBUser(login, password);
  153.  
  154. // CREATE SESSION WITH USER
  155. // If you use create session with user data,
  156. // then the user will be logged in automatically
  157. QBAuth.createSession(login, password, new QBEntityCallback<QBSession>() {
  158. @Override
  159. public void onSuccess(QBSession session, Bundle bundle) {
  160.  
  161. user.setId(session.getUserId());
  162. Toast.makeText(MainActivity.this, "Loging in!!!", Toast.LENGTH_LONG).show();
  163. Log.w("qb", "logedin app");
  164. // INIT CHAT SERVICE
  165. chatService = QBChatService.getInstance();
  166. Log.w("qb", "loging chat");
  167. // LOG IN CHAT SERVICE
  168. chatService.login(user, new QBEntityCallback<QBUser>() {
  169.  
  170.  
  171. @Override
  172. public void onSuccess(QBUser qbUser, Bundle bundle) {
  173. Log.w("qb", "loged chat");
  174. initQBRTCClient();
  175.  
  176. }
  177.  
  178. @Override
  179. public void onError(QBResponseException errors) {
  180. Log.w("qb", "not logedn" + errors.getMessage());
  181. //error
  182.  
  183. }
  184. });
  185. }
  186.  
  187. @Override
  188. public void onError(QBResponseException errors) {
  189. //error
  190. Toast.makeText(MainActivity.this, "ERROR!!!n" + errors.getMessage(), Toast.LENGTH_LONG).show();
  191. }
  192. });
  193. }
  194.  
  195. private void initQBRTCClient() {
  196. rtcClient = QBRTCClient.getInstance(this);
  197.  
  198. // Add signalling manager
  199. QBChatService.getInstance().getVideoChatWebRTCSignalingManager().addSignalingManagerListener(new QBVideoChatSignalingManagerListener() {
  200. @Override
  201. public void signalingCreated(QBSignaling qbSignaling, boolean createdLocally) {
  202. if (!createdLocally) {
  203. rtcClient.addSignaling((QBWebRTCSignaling) qbSignaling);
  204. }
  205. }
  206. });
  207.  
  208. rtcClient.setCameraErrorHendler(new VideoCapturerAndroid.CameraErrorHandler() {
  209. @Override
  210. public void onCameraError(final String s) {
  211. MainActivity.this.runOnUiThread(new Runnable() {
  212. @Override
  213. public void run() {
  214. Toast.makeText(MainActivity.this, s, Toast.LENGTH_LONG).show();
  215. }
  216. });
  217. }
  218. });
  219.  
  220.  
  221. // Configure
  222. //
  223.  
  224.  
  225. QBRTCConfig.setMaxOpponentsCount(2);
  226. QBRTCConfig.setDisconnectTime(30);
  227. QBRTCConfig.setAnswerTimeInterval(301);
  228. QBRTCConfig.setDebugEnabled(true);
  229.  
  230.  
  231. rtcClient.addVideoTrackCallbacksListener(this);
  232.  
  233. // rtcSession.removeVideoTrackCallbacksListener(this);
  234. // Add activity as callback to RTCClient
  235. rtcClient.addSessionCallbacksListener(this);
  236. //QBRTCClient.getInstance(this).removeSessionCallbacksListener(this);
  237. // Start mange QBRTCSessions according to VideoCall parser's callbacks
  238. rtcClient.prepareToProcessCalls();
  239.  
  240.  
  241. }
  242.  
  243. private void starcall(int tid) {
  244.  
  245.  
  246. //Set conference type
  247. //There are two types of calls:
  248. // - QB_CONFERENCE_TYPE_VIDEO - for video call;
  249. // - QB_CONFERENCE_TYPE_AUDIO - for audio call;
  250. QBRTCTypes.QBConferenceType qbConferenceType = QBRTCTypes.QBConferenceType.QB_CONFERENCE_TYPE_VIDEO;
  251.  
  252.  
  253. //Initiate opponents list
  254. List<Integer> opponents = new ArrayList<Integer>();
  255. opponents.add(tid); //12345 - QBUser ID
  256.  
  257. //Set user information
  258. // User can set any string key and value in user info
  259. // Then retrieve this data from sessions which is returned in callbacks
  260. // and parse them as he wish
  261. Map<String, String> userInfo = new HashMap<>();
  262. userInfo.put("key", "value");
  263.  
  264. //Init session
  265. QBRTCSession session = rtcClient.createNewSessionWithOpponents(opponents, qbConferenceType);
  266. session.addVideoTrackCallbacksListener(this);
  267.  
  268. //Start call
  269. session.startCall(userInfo);
  270. Log.w("qb", "startcall: " + String.valueOf(tid));
  271. }
  272.  
  273.  
  274. @Override
  275. public void onReceiveNewSession(QBRTCSession qbrtcSession) {
  276. // obtain received user info
  277. Map<String, String> userInfo = qbrtcSession.getUserInfo();
  278.  
  279. // .....
  280. // ..... your code
  281. // .....
  282.  
  283.  
  284. // Set userInfo
  285. // User can set any string key and value in user info
  286. userInfo = new HashMap<String, String>();
  287. userInfo.put("Key", "Value");
  288.  
  289. // Accept incoming call
  290. qbrtcSession.addVideoTrackCallbacksListener(this);
  291.  
  292. qbrtcSession.acceptCall(userInfo);
  293.  
  294. Log.w("call", "accepted:" + String.valueOf(qbrtcSession.getSessionID()));
  295. }
  296.  
  297. @Override
  298. public void onUserNotAnswer(QBRTCSession qbrtcSession, Integer integer) {
  299.  
  300. }
  301.  
  302. @Override
  303. public void onCallRejectByUser(QBRTCSession qbrtcSession, Integer integer, Map<String, String> map) {
  304.  
  305. }
  306.  
  307. @Override
  308. public void onCallAcceptByUser(QBRTCSession qbrtcSession, Integer integer, Map<String, String> map) {
  309.  
  310. }
  311.  
  312. @Override
  313. public void onReceiveHangUpFromUser(QBRTCSession qbrtcSession, Integer integer) {
  314.  
  315. }
  316.  
  317. @Override
  318. public void onUserNoActions(QBRTCSession qbrtcSession, Integer integer) {
  319.  
  320. }
  321.  
  322. @Override
  323. public void onSessionClosed(QBRTCSession qbrtcSession) {
  324.  
  325. }
  326.  
  327. @Override
  328. public void onSessionStartClose(QBRTCSession qbrtcSession) {
  329.  
  330. }
  331.  
  332. RTCGLVideoView LocalVideoView;
  333. RTCGLVideoView remoteVideoView ;
  334. @Override
  335. public void onLocalVideoTrackReceive(QBRTCSession qbrtcSession, QBRTCVideoTrack qbrtcVideoTrack) {
  336. // RTCGLVideoView videoView, QBRTCVideoTrack videoTrack, boolean remoteRenderer
  337. LocalVideoView = (RTCGLVideoView) findViewById(R.id.localView);
  338. fillVideoView(LocalVideoView, qbrtcVideoTrack, false);
  339.  
  340. Log.w("TAG", "onLocalVideoTrackReceive()");
  341.  
  342.  
  343.  
  344. }
  345.  
  346. @Override
  347. public void onRemoteVideoTrackReceive(QBRTCSession qbrtcSession, QBRTCVideoTrack qbrtcVideoTrack, Integer integer) {
  348. remoteVideoView = (RTCGLVideoView) findViewById(R.id.opponentView);
  349. fillVideoView(remoteVideoView, qbrtcVideoTrack, true);
  350. Log.w("TAG", "onRemoteVideoTrackReceive(),,,");
  351. }
  352.  
  353.  
  354. private void fillVideoView(RTCGLVideoView videoView, QBRTCVideoTrack videoTrack, boolean remoteRenderer) {
  355. videoTrack.addRenderer(new VideoRenderer(remoteRenderer ?
  356. videoView.obtainVideoRenderer(RTCGLVideoView.RendererSurface.MAIN) :
  357. videoView.obtainVideoRenderer(RTCGLVideoView.RendererSurface.SECOND)));
  358. }
  359.  
  360. }
  361.  
  362. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  363. xmlns:tools="http://schemas.android.com/tools"
  364. android:layout_width="match_parent"
  365. android:layout_height="match_parent"
  366. xmlns:custom="http://schemas.android.com/apk/res-auto"
  367. android:paddingBottom="@dimen/activity_vertical_margin"
  368. android:paddingLeft="@dimen/activity_horizontal_margin"
  369. android:paddingRight="@dimen/activity_horizontal_margin"
  370. android:paddingTop="@dimen/activity_vertical_margin"
  371. tools:context="com.hm.runanddelete.MainActivity">
  372.  
  373.  
  374.  
  375.  
  376. <com.quickblox.videochat.webrtc.view.RTCGLVideoView
  377. xmlns:android="http://schemas.android.com/apk/res/android"
  378. android:id="@+id/localView"
  379. android:layout_width="150dp"
  380. android:layout_height="150dp"
  381. />
  382.  
  383. <com.quickblox.videochat.webrtc.view.RTCGLVideoView
  384. android:id="@+id/opponentView"
  385. android:layout_width="150dp"
  386. android:layout_height="150dp"
  387. android:layout_alignParentBottom="true"
  388. android:layout_alignRight="@+id/btn_caller_login"
  389. android:layout_alignEnd="@+id/btn_caller_login" />
  390.  
  391. <Button
  392. android:layout_width="wrap_content"
  393. android:layout_height="wrap_content"
  394. android:text="LOGIN"
  395. android:id="@+id/btn_caller_login"
  396. android:layout_below="@+id/et_caller_pw"
  397. android:layout_alignParentRight="true"
  398. android:layout_alignParentEnd="true" />
  399.  
  400. <EditText
  401. android:layout_width="wrap_content"
  402. android:layout_height="wrap_content"
  403. android:id="@+id/et_caller_user"
  404. android:hint="QB USERNAME"
  405. android:layout_below="@+id/localView"
  406. android:layout_alignParentLeft="true"
  407. android:layout_alignParentStart="true"
  408. android:layout_marginTop="25dp"
  409. android:layout_alignRight="@+id/et_caller_pw"
  410. android:layout_alignEnd="@+id/et_caller_pw"
  411. android:text="" />
  412.  
  413. <EditText
  414. android:layout_width="wrap_content"
  415. android:layout_height="wrap_content"
  416. android:id="@+id/et_caller_pw"
  417. android:layout_below="@+id/et_caller_user"
  418. android:layout_alignParentLeft="true"
  419. android:layout_alignParentStart="true"
  420. android:layout_alignRight="@+id/btn_caller_login"
  421. android:layout_alignEnd="@+id/btn_caller_login"
  422. android:hint="QB PASSWORD"
  423. android:text="" />
  424.  
  425. <EditText
  426. android:layout_width="wrap_content"
  427. android:layout_height="wrap_content"
  428. android:id="@+id/et_caller_tid"
  429. android:hint="QB TARGET ID"
  430. android:layout_below="@+id/et_caller_pw"
  431. android:layout_alignParentLeft="true"
  432. android:layout_alignParentStart="true"
  433. android:layout_toLeftOf="@+id/btn_caller_login"
  434. android:layout_toStartOf="@+id/btn_caller_login"
  435. android:text="" />
  436.  
  437. <Button
  438. android:layout_width="wrap_content"
  439. android:layout_height="wrap_content"
  440. android:text="MAKE CALL"
  441. android:id="@+id/btn_caller_call"
  442. android:layout_below="@+id/et_caller_tid"
  443. android:layout_alignParentLeft="true"
  444. android:layout_alignParentStart="true"
  445. android:layout_alignRight="@+id/btn_caller_login"
  446. android:layout_alignEnd="@+id/btn_caller_login" />
  447.  
  448. </RelativeLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement