Jelajahi Sumber

1.IM隐藏状态栏和导航栏

王鹏鹏 2 tahun lalu
induk
melakukan
9174b74fce

+ 14 - 2
timcommon/src/main/java/com/tencent/qcloud/tuikit/timcommon/component/activities/BaseLightActivity.java

@@ -1,6 +1,7 @@
 package com.tencent.qcloud.tuikit.timcommon.component.activities;
 
 import android.content.Context;
+import android.graphics.Color;
 import android.os.Build;
 import android.os.Bundle;
 import android.view.View;
@@ -15,20 +16,31 @@ import com.tencent.qcloud.tuicore.TUIThemeManager;
 import com.tencent.qcloud.tuikit.timcommon.R;
 
 public class BaseLightActivity extends AppCompatActivity {
+
     @Override
     protected void onCreate(@Nullable Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
-
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
             getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
             getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
             getWindow().setStatusBarColor(
-                getResources().getColor(TUIThemeManager.getAttrResId(this, com.tencent.qcloud.tuicore.R.attr.core_header_start_color)));
+                    getResources().getColor(TUIThemeManager.getAttrResId(this, com.tencent.qcloud.tuicore.R.attr.core_header_start_color)));
             getWindow().setNavigationBarColor(getResources().getColor(R.color.navigation_bar_color));
             int vis = getWindow().getDecorView().getSystemUiVisibility();
             vis |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
             vis |= View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
             getWindow().getDecorView().setSystemUiVisibility(vis);
+
+            int uiOptions = View.SYSTEM_UI_LAYOUT_FLAGS
+                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
+                    | View.SYSTEM_UI_FLAG_FULLSCREEN
+                    | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
+                    | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
+                    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
+                    | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
+            getWindow().getDecorView().setSystemUiVisibility(uiOptions);
+            getWindow().setStatusBarColor(Color.TRANSPARENT);//透明状态栏
+            getWindow().setNavigationBarColor(Color.TRANSPARENT);  //透明导航栏
         }
     }
 

+ 3 - 6
tuichat/src/main/AndroidManifest.xml

@@ -31,8 +31,9 @@
             android:screenOrientation="portrait" />
         <activity
             android:name=".classicui.page.TUIC2CChatActivity"
-            android:launchMode="singleTask"
             android:configChanges="keyboardHidden|orientation|screenSize"
+            android:launchMode="singleTask"
+            android:screenOrientation="landscape"
             android:windowSoftInputMode="adjustNothing|stateHidden" />
 
 
@@ -47,7 +48,7 @@
             android:screenOrientation="portrait" />
         <activity
             android:name=".component.camera.CameraActivity"
-            android:screenOrientation="portrait" />
+            android:screenOrientation="landscape" />
 
         <provider
             android:name=".classicui.ClassicUIService"
@@ -59,10 +60,6 @@
 
 
         <!-- **************** Minimalist UI Start **************** -->
-        <activity
-            android:name=".minimalistui.component.camera.CameraActivity"
-            android:screenOrientation="portrait" />
-
         <activity
             android:name=".minimalistui.widget.messagepopmenu.ChatPopActivity"
             android:launchMode="singleTask"

+ 5 - 2
tuichat/src/main/java/com/tencent/qcloud/tuikit/tuichat/classicui/page/TUIBaseChatActivity.java

@@ -3,7 +3,9 @@ package com.tencent.qcloud.tuikit.tuichat.classicui.page;
 import android.content.Intent;
 import android.os.Bundle;
 import android.text.TextUtils;
+
 import androidx.annotation.Nullable;
+
 import com.tencent.imsdk.v2.V2TIMGroupAtInfo;
 import com.tencent.imsdk.v2.V2TIMMessage;
 import com.tencent.qcloud.tuicore.TUIConstants;
@@ -18,6 +20,8 @@ import com.tencent.qcloud.tuikit.tuichat.bean.GroupInfo;
 import com.tencent.qcloud.tuikit.tuichat.bean.GroupMemberInfo;
 import com.tencent.qcloud.tuikit.tuichat.util.ChatMessageBuilder;
 import com.tencent.qcloud.tuikit.tuichat.util.TUIChatLog;
+import com.tencent.qcloud.tuikit.tuichat.util.ViewTool;
+
 import java.util.List;
 
 public abstract class TUIBaseChatActivity extends BaseLightActivity {
@@ -26,9 +30,8 @@ public abstract class TUIBaseChatActivity extends BaseLightActivity {
     @Override
     protected void onCreate(@Nullable Bundle savedInstanceState) {
         TUIChatLog.i(TAG, "onCreate " + this);
-
         super.onCreate(savedInstanceState);
-        setContentView(R.layout.chat_activity);
+        setContentView(ViewTool.inflateLayoutPixelsById(this, R.layout.chat_activity, 1194, 834));
         chat(getIntent());
     }
 

+ 429 - 0
tuichat/src/main/java/com/tencent/qcloud/tuikit/tuichat/util/ViewTool.java

@@ -0,0 +1,429 @@
+package com.tencent.qcloud.tuikit.tuichat.util;
+
+import android.annotation.SuppressLint;
+import android.content.Context;
+import android.content.res.Configuration;
+import android.content.res.Resources;
+import android.util.DisplayMetrics;
+import android.util.TypedValue;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.WindowManager;
+import android.widget.Button;
+import android.widget.FrameLayout;
+import android.widget.LinearLayout;
+import android.widget.RelativeLayout;
+import android.widget.TextView;
+
+import androidx.cardview.widget.CardView;
+import androidx.constraintlayout.widget.ConstraintLayout;
+
+import java.lang.reflect.Field;
+
+public class ViewTool {
+
+    public static int heightPixels;
+    public static int widthPixels;
+
+    @SuppressLint("NewApi")
+    public static void initPixels(View views, int width, int height) {
+        if (views instanceof ViewGroup) {
+            ViewGroup viewGroup = (ViewGroup) views;
+            for (int i = 0; i < viewGroup.getChildCount(); i++) {
+                View view = viewGroup.getChildAt(i);
+                ViewGroup.LayoutParams lp = view.getLayoutParams();
+                if (lp.height == lp.width) {
+                    if (lp.height > 0) {
+                        lp.height = (int) (((float) lp.width) / width * widthPixels);
+                    }
+                    if (lp.width > 0) {
+                        lp.width = (int) (((float) lp.width) / width * widthPixels);
+                    }
+                } else {
+                    if (lp.height > 5) {
+                        lp.height = (int) (((float) lp.height) / height * heightPixels);
+                    }
+                    if (lp.width > 5) {
+                        lp.width = (int) (((float) lp.width) / width * widthPixels);
+                    }
+                }
+                int bottom = view.getPaddingBottom();
+                int left = view.getPaddingLeft();
+                int right = view.getPaddingRight();
+                int top = view.getPaddingTop();
+                if (bottom > 0) {
+                    bottom = (int) (((float) bottom) / height * heightPixels);
+                }
+                if (top > 0) {
+                    top = (int) (((float) top) / height * heightPixels);
+                }
+                if (left > 0) {
+                    left = (int) (((float) left) / width * widthPixels);
+                }
+                if (right > 0) {
+                    right = (int) (((float) right) / width * widthPixels);
+                }
+                view.setPadding(left, top, right, bottom);
+                if (views instanceof LinearLayout) {
+                    LinearLayout.LayoutParams lllp = (LinearLayout.LayoutParams) lp;
+                    lllp.leftMargin = (int) (((float) lllp.leftMargin) / width * widthPixels);
+                    lllp.rightMargin = (int) (((float) lllp.rightMargin)
+                            / width * widthPixels);
+                    lllp.topMargin = (int) (((float) lllp.topMargin) / height * heightPixels);
+                    lllp.bottomMargin = (int) (((float) lllp.bottomMargin)
+                            / height * heightPixels);
+                } else if (views instanceof FrameLayout) {
+                    FrameLayout.LayoutParams fllp = (FrameLayout.LayoutParams) lp;
+                    fllp.leftMargin = (int) (((float) fllp.leftMargin) / width * widthPixels);
+                    fllp.rightMargin = (int) (((float) fllp.rightMargin)
+                            / width * widthPixels);
+                    fllp.topMargin = (int) (((float) fllp.topMargin) / height * heightPixels);
+                    fllp.bottomMargin = (int) (((float) fllp.bottomMargin)
+                            / height * heightPixels);
+                }  else if (views instanceof ConstraintLayout) {
+                    ConstraintLayout.LayoutParams fllp = (ConstraintLayout.LayoutParams) lp;
+                    fllp.leftMargin = (int) (((float) fllp.leftMargin) / width * widthPixels);
+                    fllp.rightMargin = (int) (((float) fllp.rightMargin)
+                            / width * widthPixels);
+                    fllp.topMargin = (int) (((float) fllp.topMargin) / height * heightPixels);
+                    fllp.bottomMargin = (int) (((float) fllp.bottomMargin)
+                            / height * heightPixels);
+                } else if (views instanceof RelativeLayout) {
+                    RelativeLayout.LayoutParams fllp = (RelativeLayout.LayoutParams) lp;
+                    fllp.leftMargin = (int) (((float) fllp.leftMargin) / width * widthPixels);
+                    fllp.rightMargin = (int) (((float) fllp.rightMargin)
+                            / width * widthPixels);
+                    fllp.topMargin = (int) (((float) fllp.topMargin) / height * heightPixels);
+                    fllp.bottomMargin = (int) (((float) fllp.bottomMargin)
+                            / height * heightPixels);
+                } else if (views instanceof CardView) {
+                    RelativeLayout.LayoutParams fllp = (RelativeLayout.LayoutParams) lp;
+                    fllp.leftMargin = (int) (((float) fllp.leftMargin) / width * widthPixels);
+                    fllp.rightMargin = (int) (((float) fllp.rightMargin)
+                            / width * widthPixels);
+                    fllp.topMargin = (int) (((float) fllp.topMargin) / height * heightPixels);
+                    fllp.bottomMargin = (int) (((float) fllp.bottomMargin)
+                            / height * heightPixels);
+                }
+                if (view instanceof TextView) {
+                    TextView textView = (TextView) view;
+                    float sp = (float) (height) / (float) (heightPixels);
+                    textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textView.getTextSize() / sp);
+                } else if (view instanceof Button) {
+                    Button button = (Button) view;
+                    float sp = (float) (height) / (float) (heightPixels);
+                    button.setTextSize(TypedValue.COMPLEX_UNIT_PX, button.getTextSize() / sp);
+                } else if (view instanceof ViewGroup) {
+                    initPixels(view, width, height);
+                }
+
+            }
+        }
+
+    }
+
+    public static View inflateLayoutPixels(Context context, View views, int width, int height) {
+        if (views == null) {
+            return null;
+        }
+        DisplayMetrics dm2 = new DisplayMetrics();
+        ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE))
+                .getDefaultDisplay().getMetrics(dm2);
+        if (heightPixels <= 0) {
+            heightPixels = dm2.heightPixels;
+            widthPixels = dm2.widthPixels;
+            Class<?> c = null;
+            Object obj = null;
+            Field field = null;
+            int x = 0, sbar = 0;
+            try {
+                c = Class.forName("com.android.internal.R$dimen");
+                obj = c.newInstance();
+                field = c.getField("status_bar_height");
+                x = Integer.parseInt(field.get(obj).toString());
+                sbar = context.getResources().getDimensionPixelSize(x);
+            } catch (Exception e1) {
+                e1.printStackTrace();
+            }
+            heightPixels = heightPixels - sbar;
+        }
+
+        Resources resources = context.getResources();
+
+        float heightPixelsN, widthPixelsN;
+        heightPixelsN = heightPixels;
+        widthPixelsN = widthPixels;
+        int rid = resources.getIdentifier("config_showNavigationBar", "bool",
+                "android");
+        if (resources.getBoolean(rid)) {
+            // ��ȡ�������Ƿ���ʾtrue or false
+            int resourceId = resources.getIdentifier("navigation_bar_height",
+                    "dimen", "android");
+            if (resourceId > 0) {
+
+                if (isScreenChange(context)) {
+                    widthPixelsN += resources.getDimensionPixelSize(resourceId);
+                } else {
+                    heightPixelsN += resources
+                            .getDimensionPixelSize(resourceId);
+                }
+            }
+
+        }
+        if (widthPixelsN / heightPixelsN == 9.0 / 16.0) {
+            width = (int) ((9.0 / 16.0) * height);
+
+        } else if (widthPixelsN / heightPixelsN == 10.0 / 16.0) {
+            width = (int) ((10.0 / 16.0) * height);
+        }
+        initPixels(views, width, height);
+        ViewGroup.LayoutParams lp = views.getLayoutParams();
+        if (lp != null) {
+
+            if (lp.height > 0) {
+                lp.height = (int) (((float) lp.height) / height * heightPixels);
+            }
+            if (lp.width > 0) {
+                lp.width = (int) (((float) lp.width) / width * widthPixels);
+            }
+            views.setLayoutParams(lp);
+        }
+        return views;
+    }
+
+
+    public static View inflateLayoutPixelsById(Context context, int layoutId,
+                                           int width, int height) {
+		View views = LayoutInflater.from(context).inflate(layoutId, null);
+        if (views == null) {
+            return null;
+        }
+        DisplayMetrics dm2 = new DisplayMetrics();
+        ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE))
+                .getDefaultDisplay().getMetrics(dm2);
+        if (heightPixels <= 0) {
+            heightPixels = dm2.heightPixels;
+            widthPixels = dm2.widthPixels;
+            Class<?> c = null;
+            Object obj = null;
+            Field field = null;
+            int x = 0, sbar = 0;
+            try {
+                c = Class.forName("com.android.internal.R$dimen");
+                obj = c.newInstance();
+                field = c.getField("status_bar_height");
+                x = Integer.parseInt(field.get(obj).toString());
+                sbar = context.getResources().getDimensionPixelSize(x);
+            } catch (Exception e1) {
+                e1.printStackTrace();
+            }
+            heightPixels = heightPixels - sbar;
+        }
+
+        Resources resources = context.getResources();
+
+        float heightPixelsN, widthPixelsN;
+        heightPixelsN = heightPixels;
+        widthPixelsN = widthPixels;
+        int rid = resources.getIdentifier("config_showNavigationBar", "bool",
+                "android");
+        if (resources.getBoolean(rid)) {
+            // ��ȡ�������Ƿ���ʾtrue or false
+            int resourceId = resources.getIdentifier("navigation_bar_height",
+                    "dimen", "android");
+            if (resourceId > 0) {
+
+                if (isScreenChange(context)) {
+                    widthPixelsN += resources.getDimensionPixelSize(resourceId);
+                } else {
+                    heightPixelsN += resources
+                            .getDimensionPixelSize(resourceId);
+                }
+            }
+
+        }
+        if (widthPixelsN / heightPixelsN == 9.0 / 16.0) {
+            width = (int) ((9.0 / 16.0) * height);
+
+        } else if (widthPixelsN / heightPixelsN == 10.0 / 16.0) {
+            width = (int) ((10.0 / 16.0) * height);
+        }
+        initPixels(views, width, height);
+        ViewGroup.LayoutParams lp = views.getLayoutParams();
+        if (lp != null) {
+
+            if (lp.height > 0) {
+                lp.height = (int) (((float) lp.height) / height * heightPixels);
+            }
+            if (lp.width > 0) {
+                lp.width = (int) (((float) lp.width) / width * widthPixels);
+            }
+            views.setLayoutParams(lp);
+        }
+        return views;
+    }
+
+    public static View inflateFragmentPixels(Context context, int layoutId, ViewGroup container,
+                                             int width, int height) {
+        View views = LayoutInflater.from(context).inflate(layoutId, container, false);
+        if (views == null) {
+            return null;
+        }
+        DisplayMetrics dm2 = new DisplayMetrics();
+        ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE))
+                .getDefaultDisplay().getMetrics(dm2);
+        if (heightPixels <= 0) {
+            heightPixels = dm2.heightPixels;
+            widthPixels = dm2.widthPixels;
+            Class<?> c = null;
+            Object obj = null;
+            Field field = null;
+            int x = 0, sbar = 0;
+            try {
+                c = Class.forName("com.android.internal.R$dimen");
+                obj = c.newInstance();
+                field = c.getField("status_bar_height");
+                x = Integer.parseInt(field.get(obj).toString());
+                sbar = context.getResources().getDimensionPixelSize(x);
+            } catch (Exception e1) {
+                e1.printStackTrace();
+            }
+            heightPixels = heightPixels - sbar;
+        }
+
+        Resources resources = context.getResources();
+
+        float heightPixelsN, widthPixelsN;
+        heightPixelsN = heightPixels;
+        widthPixelsN = widthPixels;
+        int rid = resources.getIdentifier("config_showNavigationBar", "bool",
+                "android");
+        if (resources.getBoolean(rid)) {
+            // ��ȡ�������Ƿ���ʾtrue or false
+
+            int resourceId = resources.getIdentifier("navigation_bar_height",
+                    "dimen", "android");
+            if (resourceId > 0) {
+
+                if (isScreenChange(context)) {
+                    widthPixelsN += resources.getDimensionPixelSize(resourceId);
+                } else {
+                    heightPixelsN += resources
+                            .getDimensionPixelSize(resourceId);
+                }
+            }
+
+        }
+
+        if (widthPixelsN / heightPixelsN == 9.0 / 16.0) {
+            width = (int) ((9.0 / 16.0) * height);
+
+        } else if (widthPixelsN / heightPixelsN == 10.0 / 16.0) {
+            width = (int) ((10.0 / 16.0) * height);
+        }
+        initPixels(views, width, height);
+        ViewGroup.LayoutParams lp = views.getLayoutParams();
+        if (lp != null) {
+
+            if (lp.height > 0) {
+                lp.height = (int) (((float) lp.height) / height * heightPixels);
+            }
+            if (lp.width > 0) {
+                lp.width = (int) (((float) lp.width) / width * widthPixels);
+            }
+            views.setLayoutParams(lp);
+        }
+        return views;
+    }
+
+    public static View inflateFragmentPixels(Context context, View views, int width, int height) {
+        if (views == null) {
+            return null;
+        }
+        DisplayMetrics dm2 = new DisplayMetrics();
+        ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE))
+                .getDefaultDisplay().getMetrics(dm2);
+        if (heightPixels <= 0) {
+            heightPixels = dm2.heightPixels;
+            widthPixels = dm2.widthPixels;
+            Class<?> c = null;
+            Object obj = null;
+            Field field = null;
+            int x = 0, sbar = 0;
+            try {
+                c = Class.forName("com.android.internal.R$dimen");
+                obj = c.newInstance();
+                field = c.getField("status_bar_height");
+                x = Integer.parseInt(field.get(obj).toString());
+                sbar = context.getResources().getDimensionPixelSize(x);
+            } catch (Exception e1) {
+                e1.printStackTrace();
+            }
+            heightPixels = heightPixels - sbar;
+        }
+
+        Resources resources = context.getResources();
+
+        float heightPixelsN, widthPixelsN;
+        heightPixelsN = heightPixels;
+        widthPixelsN = widthPixels;
+        int rid = resources.getIdentifier("config_showNavigationBar", "bool",
+                "android");
+        if (resources.getBoolean(rid)) {
+            // ��ȡ�������Ƿ���ʾtrue or false
+
+            int resourceId = resources.getIdentifier("navigation_bar_height",
+                    "dimen", "android");
+            if (resourceId > 0) {
+
+                if (isScreenChange(context)) {
+                    widthPixelsN += resources.getDimensionPixelSize(resourceId);
+                } else {
+                    heightPixelsN += resources
+                            .getDimensionPixelSize(resourceId);
+                }
+            }
+
+        }
+
+        if (widthPixelsN / heightPixelsN == 9.0 / 16.0) {
+            width = (int) ((9.0 / 16.0) * height);
+
+        } else if (widthPixelsN / heightPixelsN == 10.0 / 16.0) {
+            width = (int) ((10.0 / 16.0) * height);
+        }
+        initPixels(views, width, height);
+        ViewGroup.LayoutParams lp = views.getLayoutParams();
+        if (lp != null) {
+
+            if (lp.height > 0) {
+                lp.height = (int) (((float) lp.height) / height * heightPixels);
+            }
+            if (lp.width > 0) {
+                lp.width = (int) (((float) lp.width) / width * widthPixels);
+            }
+            views.setLayoutParams(lp);
+        }
+        return views;
+    }
+
+    public static boolean isScreenChange(Context context) {
+
+        Configuration mConfiguration = context.getResources()
+                .getConfiguration(); // ��ȡ���õ�������Ϣ
+        int ori = mConfiguration.orientation; // ��ȡ��Ļ����
+
+        if (ori == mConfiguration.ORIENTATION_LANDSCAPE) {
+
+            // ����
+            return true;
+        } else if (ori == mConfiguration.ORIENTATION_PORTRAIT) {
+
+            // ����
+            return false;
+        }
+        return false;
+    }
+
+}