liuzhenxing1118 8 bulan lalu
induk
melakukan
bea96b41bc

+ 38 - 28
app/src/main/java/com/xplora/xpvideo/activity/MainActivity.java

@@ -105,7 +105,7 @@ public class MainActivity extends Activity implements Listener.VideoListener {
     private void initData() {
         Log.d(TAG, "initData: ");
         if (Macros.DEBUG) {
-            mVideoType = 1;
+            mVideoType = 0;
             mVideoId = "3523b1d1-8543-43d9-92c9-df663a3f147d";
         } else {
             mVideoType = getIntent().getIntExtra(Constant.EXTRA_VIDEO_TYPE, 0);
@@ -128,20 +128,18 @@ public class MainActivity extends Activity implements Listener.VideoListener {
 
     @Override
     public void onLoginCallback(boolean isOK) {
-        if (isOK) {
-            if (mVideoType == 1) { //呼出
-                mVideoManager.call(mVideoId);
-            }
+        //呼出
+        if (isOK && mVideoType == 1) {
+            mVideoManager.call(mVideoId);
         }
     }
 
     @Override
     public void onCallItemAdd(JCCallItem item) {
-        if (item.getDirection() == JCCall.DIRECTION_OUT && item.getVideo()) {
-            mAnswerBtn.setVisibility(View.GONE);
-        }
         // 2. 做出相应的处理,如在界面上显示“振铃中”
-        mMediaPlayerUtils.playSound(this, R.raw.video_call, true);
+        if (mMediaPlayerUtils != null) {
+            mMediaPlayerUtils.playSound(this, R.raw.video_call, true);
+        }
     }
 
     @Override
@@ -155,6 +153,7 @@ public class MainActivity extends Activity implements Listener.VideoListener {
 
         int state = item.getState();
         Log.d(TAG, "updateLayout: " + state);
+        updateLayout_button(item);
         if (state == JCCall.STATE_INIT || state == JCCall.STATE_PENDING) {
             updateLayout_pending(item);
         } else if (state == JCCall.STATE_CONNECTING) {
@@ -164,6 +163,17 @@ public class MainActivity extends Activity implements Listener.VideoListener {
         }
     }
 
+    private void updateLayout_button(JCCallItem item) {
+        int state = item.getState();
+        if (state == JCCall.STATE_INIT || state == JCCall.STATE_PENDING) {
+            if (item.getDirection() == JCCall.DIRECTION_OUT) {
+                mAnswerBtn.setVisibility(View.GONE);
+            }
+        } else {
+            mAnswerBtn.setVisibility(View.GONE);
+        }
+    }
+
     private void updateLayout_pending(JCCallItem item) {
         boolean isL = mLocalCanvas == null;
         boolean isU = item.getUploadVideoStreamSelf();
@@ -216,12 +226,12 @@ public class MainActivity extends Activity implements Listener.VideoListener {
         Log.d(TAG, "onCallItemRemove: ");
         stopTimeoutTimer();
         stopTalkingTimer();
-        mMediaPlayerUtils.playSound(this, R.raw.video_cancel, false);
-        Log.d(TAG, "onCallItemRemove: 1");
+        if (mMediaPlayerUtils != null) {
+            mMediaPlayerUtils.playSound(this, R.raw.video_cancel, false);
+        }
         new Handler().postDelayed(new Runnable() {
             @Override
             public void run() {
-                Log.d(TAG, "onCallItemRemove: finish");
                 finish();
             }
         }, 2000);
@@ -247,8 +257,13 @@ public class MainActivity extends Activity implements Listener.VideoListener {
         mTimeoutTimer.schedule(new TimerTask() {
             @Override
             public void run() {
-                stopTimeoutTimer();
-                onTimeoutTimerCallback();
+                runOnUiThread(new Runnable() {
+                    @Override
+                    public void run() {
+                        stopTimeoutTimer();
+                        onTimeoutTimerCallback();
+                    }
+                });
             }
         }, 1000*60);
     }
@@ -271,7 +286,12 @@ public class MainActivity extends Activity implements Listener.VideoListener {
         mTalkingTimer.schedule(new TimerTask() {
             @Override
             public void run() {
-                onTalkingTiemrCallback();
+                runOnUiThread(new Runnable() {
+                    @Override
+                    public void run() {
+                        onTalkingTiemrCallback();
+                    }
+                });
             }
         }, 1000, 1000);
     }
@@ -302,22 +322,12 @@ public class MainActivity extends Activity implements Listener.VideoListener {
         long second = count %= 60;
         String text = hours > 0 ? String.format("%02d:%02d:%02d", hours, minutes, second) : String.format("%02d:%02d", minutes, second);
         Log.d(TAG, "onTalkingTiemrCallback: text:" + text);
-        runOnUiThread(new Runnable() {
-            @Override
-            public void run() {
-                mHintText.setText(text);
-            }
-        });
+        mHintText.setText(text);
     }
 
     private void showToast(String content) {
-        runOnUiThread(new Runnable() {
-            @Override
-            public void run() {
-                Toast t = Toast.makeText(getApplicationContext(), content, Toast.LENGTH_SHORT);
-                t.show();
-            }
-        });
+        Toast t = Toast.makeText(getApplicationContext(), content, Toast.LENGTH_SHORT);
+        t.show();
     }
 
     @Override

+ 1 - 0
app/src/main/java/com/xplora/xpvideo/manager/DatabaseUtils.java

@@ -25,6 +25,7 @@ public class DatabaseUtils {
         if (Macros.DEBUG) {
             ContactBean bean = new ContactBean();
             bean.userId = userId;
+            bean.name = "Father";
             return bean;
         } else {
             Uri uri = Uri.parse(MetaData.DB_CONTACTS);

+ 7 - 8
app/src/main/res/layout/activity_main.xml

@@ -20,7 +20,7 @@
             android:id="@+id/layout_info"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
-            android:layout_marginTop="20dp"
+            android:layout_marginTop="30dp"
             >
             <ImageView
                 android:id="@+id/iconIv"
@@ -37,9 +37,8 @@
                 android:layout_alignTop="@+id/iconIv"
                 android:layout_marginStart="5dp"
                 android:textColor="@color/white"
-                android:textSize="12sp"
+                android:textSize="13sp"
                 android:textStyle="bold"
-                android:text="nameafdsafdsa"
                 />
             <TextView
                 android:id="@+id/hintTv"
@@ -50,7 +49,7 @@
                 android:layout_marginStart="5dp"
                 android:textColor="@color/white"
                 android:textSize="11sp"
-                android:text="invent afdasfdsafdsa"
+                android:textStyle="bold"
                 />
         </RelativeLayout>
 
@@ -64,13 +63,13 @@
             >
             <ImageButton
                 android:id="@+id/cancelBtn"
-                android:layout_width="40dp"
-                android:layout_height="40dp"
+                android:layout_width="50dp"
+                android:layout_height="50dp"
                 android:background="@drawable/hangup"/>
             <ImageButton
                 android:id="@+id/answerBtn"
-                android:layout_width="40dp"
-                android:layout_height="40dp"
+                android:layout_width="50dp"
+                android:layout_height="50dp"
                 android:layout_marginStart="30dp"
                 android:background="@drawable/answer"
                 />