浏览代码

修改老师端直播,添加滤镜

Pq 3 年之前
父节点
当前提交
4976246433

+ 71 - 0
teacher/src/main/java/com/cooleshow/teacher/ui/live/LiveBeautyFilterFragment.java

@@ -0,0 +1,71 @@
+package com.cooleshow.teacher.ui.live;
+
+import android.view.View;
+import android.widget.RadioGroup;
+
+import com.cooleshow.base.ui.fragment.BaseFragment;
+import com.cooleshow.teacher.R;
+import com.cooleshow.teacher.databinding.FragmentBeautyFilterLayoutBinding;
+import com.cooleshow.teacher.databinding.FragmentLiveBeautyLayoutBinding;
+import com.cooleshow.teacher.widgets.helper.LiveRoomBeautyHelper;
+
+/**
+ * Author by pq, Date on 2022/6/13.
+ */
+public class LiveBeautyFilterFragment extends BaseFragment<FragmentBeautyFilterLayoutBinding> implements View.OnClickListener {
+    private OnEventListener mEventListener;
+
+    @Override
+    protected void initView(View rootView) {
+        mViewBinding.rgOptions.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
+            @Override
+            public void onCheckedChanged(RadioGroup group, int checkedId) {
+                int type = LiveRoomBeautyHelper.FILTER_TYPE_NONE;
+                mViewBinding.tvNoFilter.setSelected(false);
+                if (checkedId == R.id.rb_options1) {
+                    type = LiveRoomBeautyHelper.FILTER_TYPE1;
+                } else if (checkedId == R.id.rb_options2) {
+                    type = LiveRoomBeautyHelper.FILTER_TYPE2;
+                } else if (checkedId == R.id.rb_options3) {
+                    type = LiveRoomBeautyHelper.FILTER_TYPE3;
+                }
+                LiveRoomBeautyHelper.getInstance().updateFilterMode(type);
+            }
+        });
+        mViewBinding.ivNoFilter.setOnClickListener(this);
+        mViewBinding.tvNoFilter.setOnClickListener(this);
+    }
+
+    @Override
+    protected void initData() {
+
+    }
+
+
+    @Override
+    protected FragmentBeautyFilterLayoutBinding getLayoutView() {
+        return FragmentBeautyFilterLayoutBinding.inflate(getLayoutInflater());
+    }
+
+    public void setOnEventListener(OnEventListener listener) {
+        this.mEventListener = listener;
+    }
+
+    @Override
+    public void onClick(View v) {
+        int id = v.getId();
+        switch (id) {
+            case R.id.iv_no_filter:
+            case R.id.tv_no_filter:
+                //无滤镜
+                mViewBinding.rgOptions.clearCheck();
+                mViewBinding.tvNoFilter.setSelected(true);
+                LiveRoomBeautyHelper.getInstance().updateFilterMode(LiveRoomBeautyHelper.FILTER_TYPE_NONE);
+                break;
+        }
+    }
+
+    public interface OnEventListener {
+        void onChangeOptions(int type);
+    }
+}

+ 32 - 1
teacher/src/main/java/com/cooleshow/teacher/widgets/dialog/LiveBeautyOptionsDialog.java

@@ -3,6 +3,7 @@ package com.cooleshow.teacher.widgets.dialog;
 import android.app.Activity;
 import android.app.Activity;
 import android.app.Dialog;
 import android.app.Dialog;
 import android.content.Context;
 import android.content.Context;
+import android.graphics.Typeface;
 import android.os.Bundle;
 import android.os.Bundle;
 import android.view.Gravity;
 import android.view.Gravity;
 import android.view.LayoutInflater;
 import android.view.LayoutInflater;
@@ -14,6 +15,7 @@ import android.widget.TextView;
 
 
 import com.cooleshow.teacher.R;
 import com.cooleshow.teacher.R;
 import com.cooleshow.teacher.adapter.LiveBeautyPagerAdapter;
 import com.cooleshow.teacher.adapter.LiveBeautyPagerAdapter;
+import com.cooleshow.teacher.ui.live.LiveBeautyFilterFragment;
 import com.cooleshow.teacher.ui.live.LiveBeautyOptionsFragment;
 import com.cooleshow.teacher.ui.live.LiveBeautyOptionsFragment;
 import com.cooleshow.teacher.widgets.helper.LiveRoomBeautyHelper;
 import com.cooleshow.teacher.widgets.helper.LiveRoomBeautyHelper;
 import com.google.android.material.tabs.TabLayout;
 import com.google.android.material.tabs.TabLayout;
@@ -73,7 +75,7 @@ public class LiveBeautyOptionsDialog extends Dialog implements LiveBeautyOptions
 
 
         LiveBeautyPagerAdapter beautyPagerAdapter = new LiveBeautyPagerAdapter(mActivity);
         LiveBeautyPagerAdapter beautyPagerAdapter = new LiveBeautyPagerAdapter(mActivity);
         LiveBeautyOptionsFragment optionsFragment = new LiveBeautyOptionsFragment();
         LiveBeautyOptionsFragment optionsFragment = new LiveBeautyOptionsFragment();
-        LiveBeautyOptionsFragment optionsFragment2 = new LiveBeautyOptionsFragment();
+        LiveBeautyFilterFragment optionsFragment2 = new LiveBeautyFilterFragment();
         optionsFragment.setOnEventListener(this);
         optionsFragment.setOnEventListener(this);
         ArrayList<Fragment> fragments = new ArrayList();
         ArrayList<Fragment> fragments = new ArrayList();
         fragments.add(optionsFragment);
         fragments.add(optionsFragment);
@@ -90,6 +92,35 @@ public class LiveBeautyOptionsDialog extends Dialog implements LiveBeautyOptions
     }
     }
 
 
     private void initListener() {
     private void initListener() {
+        mTabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
+            @Override
+            public void onTabSelected(TabLayout.Tab tab) {
+                if (tab.getPosition() != 0) {
+                    mSeekBar.setVisibility(View.GONE);
+                } else {
+                    mSeekBar.setVisibility(View.VISIBLE);
+                }
+                if (tab != null && tab.getCustomView() != null) {
+                    View customView = tab.getCustomView();
+                    TextView tv_text = customView.findViewById(R.id.tv_text);
+                    tv_text.setTextColor(getContext().getResources().getColor(com.cooleshow.base.R.color.white));
+                }
+            }
+
+            @Override
+            public void onTabUnselected(TabLayout.Tab tab) {
+                if (tab != null && tab.getCustomView() != null) {
+                    View customView = tab.getCustomView();
+                    TextView tv_text = customView.findViewById(R.id.tv_text);
+                    tv_text.setTextColor(getContext().getResources().getColor(com.cooleshow.base.R.color.white_translucent));
+                }
+            }
+
+            @Override
+            public void onTabReselected(TabLayout.Tab tab) {
+
+            }
+        });
         mSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
         mSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
             @Override
             @Override
             public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
             public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {

+ 30 - 0
teacher/src/main/java/com/cooleshow/teacher/widgets/helper/LiveRoomBeautyHelper.java

@@ -1,6 +1,7 @@
 package com.cooleshow.teacher.widgets.helper;
 package com.cooleshow.teacher.widgets.helper;
 
 
 import cn.rongcloud.beauty.RCRTCBeautyEngine;
 import cn.rongcloud.beauty.RCRTCBeautyEngine;
+import cn.rongcloud.beauty.RCRTCBeautyFilter;
 import cn.rongcloud.beauty.RCRTCBeautyOption;
 import cn.rongcloud.beauty.RCRTCBeautyOption;
 
 
 /**
 /**
@@ -12,7 +13,12 @@ public class LiveRoomBeautyHelper {
     public static final int OPTIONS_TYPE2 = 1;//磨皮
     public static final int OPTIONS_TYPE2 = 1;//磨皮
     public static final int OPTIONS_TYPE3 = 2;//红润
     public static final int OPTIONS_TYPE3 = 2;//红润
     public static final int OPTIONS_TYPE4 = 3;//亮度
     public static final int OPTIONS_TYPE4 = 3;//亮度
+    public static final int FILTER_TYPE_NONE = 5;//无滤镜
+    public static final int FILTER_TYPE1 = 6;//唯美
+    public static final int FILTER_TYPE2 = 7;//清新
+    public static final int FILTER_TYPE3 = 8;//浪漫
     private int currentType = OPTIONS_TYPE1;//默认选择
     private int currentType = OPTIONS_TYPE1;//默认选择
+    private int currentFilterType = FILTER_TYPE_NONE;//默认选择无滤镜
 
 
     private int beauty_whiteness_progress = 0;//美白参数
     private int beauty_whiteness_progress = 0;//美白参数
     private int beauty_smooth_progress = 0;//磨皮参数
     private int beauty_smooth_progress = 0;//磨皮参数
@@ -93,4 +99,28 @@ public class LiveRoomBeautyHelper {
         }
         }
         return 0;
         return 0;
     }
     }
+
+
+    /**
+     * 更新滤镜模式
+     * @param filterType
+     */
+    public void updateFilterMode(int filterType) {
+        if (filterType == FILTER_TYPE_NONE) {
+            //无滤镜模式
+            RCRTCBeautyEngine.getInstance().setBeautyFilter(RCRTCBeautyFilter.NONE);
+        }
+        if (filterType == FILTER_TYPE1) {
+            //唯美模式
+            RCRTCBeautyEngine.getInstance().setBeautyFilter(RCRTCBeautyFilter.ESTHETIC);  // 唯美
+        }
+        if (filterType == FILTER_TYPE2) {
+            //清新模式
+            RCRTCBeautyEngine.getInstance().setBeautyFilter(RCRTCBeautyFilter.FRESH);  // 清新
+        }
+        if (filterType == FILTER_TYPE3) {
+            //浪漫模式
+            RCRTCBeautyEngine.getInstance().setBeautyFilter(RCRTCBeautyFilter.ROMANTIC);  // 浪漫
+        }
+    }
 }
 }

二进制
teacher/src/main/res/drawable-xhdpi/icon_live_beauty_filter.png


二进制
teacher/src/main/res/drawable-xhdpi/icon_live_beauty_no_filter.png


二进制
teacher/src/main/res/drawable-xxhdpi/icon_live_beauty_filter.png


二进制
teacher/src/main/res/drawable-xxhdpi/icon_live_beauty_no_filter.png


+ 25 - 0
teacher/src/main/res/drawable/bg_live_beauty_seekbar.xml

@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
+    <!-- 背景 -->
+    <item android:id="@android:id/background">
+        <shape>
+            <!-- 圆角 -->
+            <corners android:radius="2dp" />
+            <!--            背景色-->
+            <solid android:color="@color/white"/>
+            <size android:height="4dp"/>
+        </shape>
+    </item>
+    <!--    滑动条-->
+    <item android:id="@android:id/progress">
+        <clip>
+            <shape>
+                <!-- 圆角 -->
+                <corners android:radius="2dp" />
+                <!--            背景色-->
+                <solid android:color="@color/gray_32FFD8"/>
+                <size android:height="4dp"/>
+            </shape>
+        </clip>
+    </item>
+</layer-list>

+ 3 - 2
teacher/src/main/res/drawable/selector_live_beauty_options_text_color.xml

@@ -1,5 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <?xml version="1.0" encoding="utf-8"?>
 <selector xmlns:android="http://schemas.android.com/apk/res/android">
 <selector xmlns:android="http://schemas.android.com/apk/res/android">
-    <item android:color="@color/white" android:state_checked="false"/>
-    <item android:color="@color/gray_32FFD8" android:state_checked="true"/>
+    <item android:color="@color/white" android:state_checked="false" />
+    <item android:color="@color/gray_32FFD8" android:state_checked="true" />
+    <item android:color="@color/gray_32FFD8" android:state_selected="true" />
 </selector>
 </selector>

+ 6 - 0
teacher/src/main/res/drawable/shape_live_beauty_seekbar_thumb.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+    android:shape="oval">
+    <solid android:color="@color/white"/>
+    <size android:width="20dp" android:height="20dp"/>
+</shape>

+ 7 - 1
teacher/src/main/res/layout/dialog_live_beauty_layout.xml

@@ -6,10 +6,16 @@
     android:orientation="vertical">
     android:orientation="vertical">
 
 
     <androidx.appcompat.widget.AppCompatSeekBar
     <androidx.appcompat.widget.AppCompatSeekBar
+        android:layout_marginBottom="10dp"
+        android:layout_marginTop="10dp"
         android:id="@+id/seek_bar"
         android:id="@+id/seek_bar"
         android:layout_width="match_parent"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_height="wrap_content"
+        android:thumb="@drawable/shape_live_beauty_seekbar_thumb"
+        android:progressDrawable="@drawable/bg_live_beauty_seekbar"
         android:max="10"
         android:max="10"
+        android:maxHeight="4dp"
+        android:splitTrack="false"
         android:visibility="invisible" />
         android:visibility="invisible" />
 
 
     <androidx.constraintlayout.widget.ConstraintLayout
     <androidx.constraintlayout.widget.ConstraintLayout
@@ -32,7 +38,7 @@
             app:tabIndicatorColor="@color/white"
             app:tabIndicatorColor="@color/white"
             app:tabIndicatorFullWidth="false"
             app:tabIndicatorFullWidth="false"
             app:tabIndicatorHeight="3dp"
             app:tabIndicatorHeight="3dp"
-            app:tabMaxWidth="0dp"
+            app:tabMaxWidth="60dp"
             app:tabMode="scrollable"
             app:tabMode="scrollable"
             app:tabRippleColor="@color/transparent"
             app:tabRippleColor="@color/transparent"
             app:tabSelectedTextColor="@color/color_333333"
             app:tabSelectedTextColor="@color/color_333333"

+ 99 - 0
teacher/src/main/res/layout/fragment_beauty_filter_layout.xml

@@ -0,0 +1,99 @@
+<?xml version="1.0" encoding="utf-8"?>
+<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    tools:background="#E61A1A1A">
+
+    <ImageView
+        android:id="@+id/iv_no_filter"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_marginStart="19dp"
+        android:layout_marginTop="25dp"
+        android:src="@drawable/icon_live_beauty_no_filter"
+        app:layout_constraintLeft_toLeftOf="parent"
+        app:layout_constraintTop_toTopOf="parent" />
+
+    <TextView
+        android:id="@+id/tv_no_filter"
+        android:layout_width="0dp"
+        android:layout_height="wrap_content"
+        android:gravity="center"
+        android:includeFontPadding="false"
+        android:paddingTop="10dp"
+        android:text="无"
+        android:textColor="@drawable/selector_live_beauty_options_text_color"
+        app:layout_constraintLeft_toLeftOf="@+id/iv_no_filter"
+        app:layout_constraintRight_toRightOf="@+id/iv_no_filter"
+        app:layout_constraintTop_toBottomOf="@+id/iv_no_filter" />
+
+    <View
+        android:id="@+id/view_line"
+        android:layout_width="0.5dp"
+        android:layout_height="26dp"
+        android:layout_marginStart="30dp"
+        android:background="@color/white"
+        app:layout_constraintBottom_toBottomOf="@+id/iv_no_filter"
+        app:layout_constraintLeft_toRightOf="@+id/iv_no_filter"
+        app:layout_constraintTop_toTopOf="@+id/iv_no_filter" />
+
+    <RadioGroup
+        android:id="@+id/rg_options"
+        android:layout_width="0dp"
+        android:layout_height="wrap_content"
+        android:layout_marginTop="25dp"
+        android:layout_marginStart="20dp"
+        android:orientation="horizontal"
+        app:layout_constraintLeft_toRightOf="@+id/view_line"
+        app:layout_constraintRight_toRightOf="parent"
+        app:layout_constraintTop_toTopOf="parent">
+
+        <RadioButton
+            android:paddingEnd="9dp"
+            android:paddingStart="9dp"
+            android:id="@+id/rb_options1"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:background="@color/transparent"
+            android:button="@null"
+            android:drawableTop="@drawable/icon_live_beauty_filter"
+            android:drawablePadding="9dp"
+            android:gravity="center"
+            android:text="唯美"
+            android:textColor="@drawable/selector_live_beauty_options_text_color"
+            android:textSize="@dimen/sp_11" />
+
+        <RadioButton
+            android:paddingEnd="9dp"
+            android:paddingStart="9dp"
+            android:id="@+id/rb_options2"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:background="@color/transparent"
+            android:button="@null"
+            android:drawableTop="@drawable/icon_live_beauty_filter"
+            android:drawablePadding="9dp"
+            android:gravity="center"
+            android:text="清新"
+            android:textColor="@drawable/selector_live_beauty_options_text_color"
+            android:textSize="@dimen/sp_11" />
+
+        <RadioButton
+            android:paddingEnd="9dp"
+            android:paddingStart="9dp"
+            android:id="@+id/rb_options3"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:background="@color/transparent"
+            android:button="@null"
+            android:drawableTop="@drawable/icon_live_beauty_filter"
+            android:drawablePadding="9dp"
+            android:gravity="center"
+            android:text="浪漫"
+            android:textColor="@drawable/selector_live_beauty_options_text_color"
+            android:textSize="@dimen/sp_11" />
+    </RadioGroup>
+
+</androidx.constraintlayout.widget.ConstraintLayout>

+ 1 - 0
teacher/src/main/res/layout/fragment_live_beauty_layout.xml

@@ -33,6 +33,7 @@
         android:layout_width="0.5dp"
         android:layout_width="0.5dp"
         android:layout_height="26dp"
         android:layout_height="26dp"
         android:layout_marginStart="30dp"
         android:layout_marginStart="30dp"
+        android:background="@color/white"
         app:layout_constraintBottom_toBottomOf="@+id/iv_switch_live_beauty"
         app:layout_constraintBottom_toBottomOf="@+id/iv_switch_live_beauty"
         app:layout_constraintLeft_toRightOf="@+id/iv_switch_live_beauty"
         app:layout_constraintLeft_toRightOf="@+id/iv_switch_live_beauty"
         app:layout_constraintTop_toTopOf="@+id/iv_switch_live_beauty" />
         app:layout_constraintTop_toTopOf="@+id/iv_switch_live_beauty" />

+ 2 - 2
teacher/src/main/res/layout/view_live_beauty_tab_layout.xml

@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <?xml version="1.0" encoding="utf-8"?>
 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_width="match_parent"
+    android:layout_gravity="center"
     android:layout_height="match_parent">
     android:layout_height="match_parent">
     <TextView
     <TextView
         android:gravity="center"
         android:gravity="center"
@@ -8,7 +9,6 @@
         android:textSize="@dimen/sp_16"
         android:textSize="@dimen/sp_16"
         android:textColor="@color/white"
         android:textColor="@color/white"
         android:id="@+id/tv_text"
         android:id="@+id/tv_text"
-        android:minWidth="60dp"
-        android:layout_width="wrap_content"
+        android:layout_width="match_parent"
         android:layout_height="wrap_content"/>
         android:layout_height="wrap_content"/>
 </FrameLayout>
 </FrameLayout>