Browse Source

Merge branch 'master' of http://116.62.119.248:10082/cheng_zq/EffectDemo into lwz_

LAPTOP-K69FCNBP\crius 2 years ago
parent
commit
fc9732a70a

+ 8 - 7
app/src/main/java/com/xunao/effectdemo/activity/MapChallengeActivity.java

@@ -1,7 +1,6 @@
 package com.xunao.effectdemo.activity;
 
-import static com.blankj.utilcode.util.ScreenUtils.getScreenHeight;
-import static com.blankj.utilcode.util.ScreenUtils.getScreenWidth;
+import static com.blankj.utilcode.util.ScreenUtils.*;
 
 import android.app.Activity;
 import android.content.Intent;
@@ -60,8 +59,9 @@ public class MapChallengeActivity extends Activity {
     void initData(){
         getMap();
     }
-
+    private float scale = 0f;
     void initView(){
+        scale = (float) (getAppScreenHeight ()/1024.00);
         llMapBg = findViewById(R.id.ll_map_bg);
         rlMapBg = findViewById(R.id.rl_map_bg);
         btnMap1 = findViewById(R.id.btn_map_1);
@@ -124,11 +124,12 @@ public class MapChallengeActivity extends Activity {
                 .format(DecodeFormat.PREFER_RGB_565)
                 .into(child);
         child.setScaleType(ImageView.ScaleType.FIT_XY);
-        child.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,getScreenHeight()));
+        child.setLayoutParams(new ViewGroup.LayoutParams(getAppScreenHeight (),getAppScreenHeight ()));
         llMapBg.addView(child);
         Log.i(TAG, getScreenHeight() + "---" + getScreenWidth());
     }
 
+
     private void addSmallBg(String url, double x, double y){
         ImageView child = new ImageView(this);
 //        Glide.with(this).asBitmap().load(url).into(new BitmapImageViewTarget(child){
@@ -143,9 +144,9 @@ public class MapChallengeActivity extends Activity {
                 .format(DecodeFormat.PREFER_RGB_565)
                 .into(child);
         child.setScaleType(ImageView.ScaleType.FIT_XY);
-        RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(360,300);
-        layoutParams.leftMargin = (int)(x * getScreenWidth()*11);
-        layoutParams.topMargin = (int)(y * getScreenHeight());
+        RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams((int) (scale*376), (int) (scale*306));
+        layoutParams.leftMargin = (int)(x * getAppScreenHeight ()*bkg_images.size());
+        layoutParams.topMargin = (int)(y * getAppScreenHeight ());
         child.setLayoutParams(layoutParams);
         rlMapBg.addView(child);
     }

+ 22 - 10
app/src/main/java/com/xunao/effectdemo/activity/NewSongLyricActivity.java

@@ -123,7 +123,11 @@ public class NewSongLyricActivity extends Activity {
 				setWord(wordList);
 
 				mediaPlayer.setOnPreparedListener(mp -> Log.i(TAG,"onPrepared:准备完成"));
-				mediaPlayer.setOnCompletionListener(mp -> Log.i(TAG,"OnCompletion:播放完成"));
+				mediaPlayer.setOnCompletionListener(mp -> {
+					textView.release();
+					handler.removeCallbacks(runnable);
+					playFinish();
+				});
 				try {
 					mediaPlayer.setDataSource(mediaBean.getResult().getList().getSteps_mp3url());
 					mediaPlayer.prepareAsync();// 开始在后台缓冲音频文件并返回
@@ -180,15 +184,7 @@ public class NewSongLyricActivity extends Activity {
 						if (num==beanList.size()){
 							num = 0;
 						}
-						if (timeBean.getTime()+timeBean.getStartTime()+canTime == timeBean.getEndTime()){
-							canTime =0;
-							normal = startIndex;
 
-						}else{
-							if (canTime==0){
-							}
-							canTime +=timeBean.getTime();
-						}
 
 						textView.startPlayLine(
 								startIndex,
@@ -196,7 +192,15 @@ public class NewSongLyricActivity extends Activity {
 								normal,1);
 						startIndex += timeBean.getWord().length();
 
-
+						if (timeBean.getTime()+timeBean.getStartTime()+canTime == timeBean.getEndTime()){
+							canTime =0;
+							normal = startIndex ;
+							Log.e("MyTag","结束标志:"+normal);
+						}else{
+							if (canTime==0){
+							}
+							canTime +=timeBean.getTime();
+						}
 						timeBean = beanList.get(num);
 					}
 					break;
@@ -211,6 +215,14 @@ public class NewSongLyricActivity extends Activity {
 		handler.post(runnable);
 	}
 
+	private void playFinish(){
+		time = 0;
+		startIndex = 0;
+		num = 0;
+		canTime = 0;
+		normal = 0;
+	}
+
 
 	Timer timer;
 	int time = 0;

+ 29 - 10
app/src/main/java/com/xunao/effectdemo/view/SongLyricTextView.kt

@@ -6,6 +6,7 @@ import android.graphics.Canvas
 import android.graphics.Color
 import android.graphics.Path
 import android.util.AttributeSet
+import android.util.Log
 import android.view.animation.LinearInterpolator
 
 /**
@@ -34,6 +35,8 @@ class SongLyricTextView @JvmOverloads constructor(
      * */
     private var consumeWidth: Float = 0f
 
+    private var normalWidth:Float = 0f;
+
     /**
      * 是否正在播放中
      * */
@@ -56,6 +59,7 @@ class SongLyricTextView @JvmOverloads constructor(
         animator.interpolator = LinearInterpolator()
         animator.addUpdateListener {
             consumeWidth = it.animatedValue as Float
+            normalWidth = oldStartWidth
             invalidate()
         }
         animator
@@ -74,27 +78,32 @@ class SongLyricTextView @JvmOverloads constructor(
             path.reset()
             val lineCount = layout.lineCount
             val content = text.toString()
+
             for (i in 0 until lineCount) {
                 // 计算一行文字的宽度
                 val lineWidth = mPaint.measureText(
                     content.substring(layout.getLineStart(i), layout.getLineEnd(i))
                 )
-
-                if (lineWidth <= consumeWidth) {
+                if (lineWidth < consumeWidth) {
                     // 如果是之前已经变色区域,直接添加到path中
+                    if (normalWidth<lineWidth&&normalWidth>0){
+                        path.addRect(
+                            layout.getLineLeft(i)+normalWidth,
+                            layout.getLineTop(i).toFloat(),
+                            layout.getLineRight(i),
+                            layout.getLineBottom(i).toFloat(),
+                            Path.Direction.CCW
+                        )
+                        normalWidth = 0f;
+                    }
                     consumeWidth -= lineWidth
-//                    path.addRect(
-//                        layout.getLineLeft(i),
-//                        layout.getLineTop(i).toFloat(),
-//                        layout.getLineRight(i),
-//                        layout.getLineBottom(i).toFloat(),
-//                        Path.Direction.CCW
-//                    )
+                    if (normalWidth>0f)normalWidth -= lineWidth
+//                    if(oldStartWidth<0f) oldStartWidth = 0f
                 } else {
                     // 如果该行正好是要变色的行,直接改变颜色
                     // 把需要的consumeWidth放入path中
                     path.addRect(
-                        layout.getLineLeft(i),
+                        layout.getLineLeft(i)+normalWidth,
                         layout.getLineTop(i).toFloat(),
                         layout.getLineLeft(i) + consumeWidth,
                         layout.getLineBottom(i).toFloat(),
@@ -201,4 +210,14 @@ class SongLyricTextView @JvmOverloads constructor(
 //        invalidate()
     }
 
+    /**
+     * 重置
+     */
+    fun release(){
+        isPlaying = false
+        isNormal = false
+        animator.cancel()
+        invalidate()
+    }
+
 }

+ 2 - 2
app/src/main/java/com/xunao/effectdemo/view/VideoPreviewPlay.java

@@ -183,9 +183,9 @@ public class VideoPreviewPlay extends StandardGSYVideoPlayer {
 		mProgressBar.setOnTouchListener(new OnTouchListener() {
 			@Override
 			public boolean onTouch(View view, MotionEvent motionEvent) {
-				if(isFinish){
+				if(!isFinish){
 					soundPoolUtil.playSoundWithRedId(R.raw.buyao);
-					Toast toast = Toast.makeText(context,"触摸事件",Toast.LENGTH_SHORT);
+					Toast toast = Toast.makeText(context,"禁止拖动",Toast.LENGTH_SHORT);
 					toast.setGravity(Gravity.TOP,0,0);
 					toast.show();
 					return true;

+ 2 - 1
app/src/main/res/layout/activity_songe.xml

@@ -41,10 +41,11 @@
         android:id="@+id/end"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
-        android:text="结束播放" />
+        android:text="暂停播放" />
 
     <Button
         android:id="@+id/test"
+        android:visibility="gone"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:text="测试数据" />