Browse Source

1,修改后去用户名方法

yunhaipiaodi 3 years ago
parent
commit
cbefab07cf

+ 3 - 0
.idea/gradle.xml

@@ -3,6 +3,9 @@
   <component name="GradleSettings">
     <option name="linkedExternalProjectsSettings">
       <GradleProjectSettings>
+        <compositeConfiguration>
+          <compositeBuild compositeDefinitionSource="SCRIPT" />
+        </compositeConfiguration>
         <option name="distributionType" value="DEFAULT_WRAPPED" />
         <option name="externalProjectPath" value="$PROJECT_DIR$" />
         <option name="modules">

+ 13 - 2
app/src/main/java/com/haochuan/hciptvbasic/BaseWebActivity.java

@@ -16,6 +16,7 @@ import android.view.WindowManager;
 import android.webkit.WebSettings;
 import android.webkit.WebView;
 import android.webkit.WebViewClient;
+import android.widget.FrameLayout;
 import android.widget.Toast;
 
 import androidx.annotation.Nullable;
@@ -72,7 +73,11 @@ public abstract class BaseWebActivity extends AppCompatActivity {
 
         webView = new WebView(this);
         webView.setBackgroundColor(ContextCompat.getColor(this, android.R.color.transparent));
-        setContentView(webView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
+        //将webView置于DecorView最上一层,不被视频组件遮住
+        FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
+        webView.setLayoutParams(params);
+        ViewGroup viewGroup = (ViewGroup) getWindow().getDecorView();
+        viewGroup.addView(webView, 1);
 
         initWebSetting(webView);
 
@@ -84,6 +89,7 @@ public abstract class BaseWebActivity extends AppCompatActivity {
         String uid = "12398658";
         if(utilToJS != null){
             uid = utilToJS.getUserName();
+
         }
         Logger.d("uid:" + uid);
         ELSUtil.Init(this,els,uid);
@@ -325,6 +331,9 @@ public abstract class BaseWebActivity extends AppCompatActivity {
         });
     }
 
+
+
+
     /**
      * 初始化webview
      * @param webView
@@ -376,7 +385,9 @@ public abstract class BaseWebActivity extends AppCompatActivity {
                 return;
             }
             playerType = type;
-            playerToJS.stop();
+            if (mHCPlayer != null) {
+                mHCPlayer.release();
+            }
         });
     }
     private void setPayToJS(){ payToJS = new PayToJS(this,webView); }

+ 7 - 2
app/src/main/java/com/haochuan/hciptvbasic/webview/PlayerToJS.java

@@ -480,7 +480,7 @@ public class PlayerToJS {
         if (baseMediaPlayer.getParent() == null) {
             Activity activity = (Activity)context;
             ViewGroup viewGroup = (ViewGroup)activity.getWindow().getDecorView();
-            viewGroup.addView(baseMediaPlayer, 1);
+            viewGroup.addView(baseMediaPlayer, 0);
         }
     }
 
@@ -568,9 +568,14 @@ public class PlayerToJS {
     private void destroyVideo(){
         try{
             Logger.d("PlayerToJS,destroyVideo()");
-            if(baseMediaPlayer != null && baseMediaPlayer.getParent() != null){
+            if(baseMediaPlayer != null){
                 Activity activity = (Activity)context;
                 activity.runOnUiThread(()->baseMediaPlayer.release());
+                if(baseMediaPlayer.getParent() == null)
+                {
+                    Logger.d("PlayerToJS,baseMediaPlayer.getParent() is null,return");
+                    return;
+                }
                 ViewGroup viewGroup = (ViewGroup) activity.getWindow().getDecorView();
                 viewGroup.removeView(baseMediaPlayer);
             }else{

+ 20 - 1
app/src/main/java/com/haochuan/hciptvbasic/webview/UtilToJS.java

@@ -221,12 +221,31 @@ public class UtilToJS {
         }
     }
 
+    private String getUserId(){
+        try {
+            Logger.d("UtilToJS,getUserId()");
+            String userId = "";
+            Uri uri = Uri.parse("content://stbconfig/authentication/username");
+            Cursor mCursor = context.getContentResolver().query(uri, null, null, null, null);
+            if (mCursor != null) {
+                while (mCursor.moveToNext()) {
+                    userId = mCursor.getString(mCursor.getColumnIndex("value"));
+                }
+                mCursor.close();
+            }
+            return userId;
+        } catch (Exception e) {
+            e.printStackTrace();
+            return "";
+        }
+    }
+
     /**
      * 返回用户名
      * @return
      */
     public String getUserName(){
-        String userName = getUserNameFromSTB();
+        String userName = getUserId();
         if(TextUtils.isEmpty(userName)){
             return MacUtil.getMac(context);
         }

+ 2 - 2
build.gradle

@@ -19,8 +19,8 @@ buildscript {
             'compileSdk'            : 28,
             'Java'                  : JavaVersion.VERSION_1_8,
             'supportLibrary'        : '28.0.0',
-            'versionCode'           : 1,
-            'versionName'           : "1.0.1"
+            'versionCode'           : 4,
+            'versionName'           : "1.0.4"
     ]
 
     // 引用的lib

+ 5 - 8
systemvideo/src/main/java/com/haochuan/systemvideo/SystemVideoPlayer.java

@@ -281,25 +281,22 @@ public class SystemVideoPlayer extends BaseMediaPlayer {
 
     public void addRenderToViewGroup(){
         videoView = new VideoView(mContext);
-        //videoView创建之后,会自动获取焦点,其实不需要,所以要将检点返回给webview
-
         FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
         params.gravity = Gravity.CENTER;
         videoView.setLayoutParams(params);
 
         if (videoView.getParent() == null) {
-            Activity activity = (Activity)mContext;
-            ViewGroup viewGroup = (ViewGroup)activity.getWindow().getDecorView();
-            viewGroup.addView(videoView, 0);
+           /* Activity activity = (Activity)mContext;
+            ViewGroup viewGroup = (ViewGroup)activity.getWindow().getDecorView();*/
+            this.addView(videoView, 0);
         }
     }
 
     public void removeRenderToViewGroup(){
         HandlerUtil.runOnUiThread(()->{
-            Activity activity = (Activity)mContext;
             if(videoView != null && videoView.getParent() != null){
-                ViewGroup viewGroup = (ViewGroup) activity.getWindow().getDecorView();
-                viewGroup.removeView(videoView);
+                //ViewGroup viewGroup = (ViewGroup) activity.getWindow().getDecorView();
+                this.removeView(videoView);
             }else{
                 Logger.e(PLAYER_OBJ_NULL,"videoView 不能从父组件移除");
             }