2 Commits bb60786b3e ... 48754abcf8

Author SHA1 Message Date
  LAPTOP-K69FCNBP\crius 48754abcf8 地图 2 years ago
  czq 541b6c10ac 单词泛红控件修改 2 years ago

+ 1 - 0
.idea/misc.xml

@@ -26,6 +26,7 @@
         <entry key="..\:/Progect/gitee/EffectDemo/app/src/main/res/layout/activity_web.xml" value="0.1816123188405797" />
         <entry key="..\:/Progect/gitee/EffectDemo/app/src/main/res/layout/demo_activity.xml" value="0.18020833333333333" />
         <entry key="..\:/Progect/gitee/EffectDemo/app/src/main/res/layout/item_word_sound.xml" value="0.10190217391304347" />
+        <entry key="..\:/work/mozhi/qiqu/EffectDemo/app/src/main/res/layout/activity_map_challenge.xml" value="0.36886005560704355" />
       </map>
     </option>
   </component>

+ 1 - 0
app/build.gradle

@@ -132,6 +132,7 @@ dependencies {
     implementation 'com.qmuiteam:qmui:2.0.0-alpha10'
     implementation 'com.airbnb.android:lottie:5.2.0'
     implementation 'com.github.JadeKkang:like_view:v1.0'
+    implementation 'com.github.bumptech.glide:glide:4.13.2'
     //极光推送
     implementation 'cn.jiguang.sdk:jcore:3.3.0'  // 此处以JCore 3.3.0 版本为例。
     implementation 'cn.jiguang.sdk:jpush:4.7.2'  // 此处以JPush 4.7.2 版本为例

+ 72 - 4
app/src/main/java/com/xunao/effectdemo/activity/MapChallengeActivity.java

@@ -1,20 +1,29 @@
 package com.xunao.effectdemo.activity;
 
-import androidx.appcompat.app.AppCompatActivity;
+import static com.blankj.utilcode.util.ScreenUtils.getScreenHeight;
+import static com.blankj.utilcode.util.ScreenUtils.getScreenWidth;
 
 import android.app.Activity;
 import android.content.Intent;
 import android.os.Bundle;
-import android.util.Log;
-import android.view.View;
+import android.view.ViewGroup;
 import android.widget.Button;
+import android.widget.HorizontalScrollView;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.RelativeLayout;
 
+import com.bumptech.glide.Glide;
+import com.bumptech.glide.load.DecodeFormat;
 import com.xunao.effectdemo.R;
+import com.xunao.effectdemo.bean.MapBean;
+import com.xunao.effectdemo.bean.MapBean.ResultBean.ListBean.StepsBean;
 import com.xunao.effectdemo.net.ApiHttpClient;
 import com.xunao.effectdemo.net.ApiUrl;
 import com.xunao.effectdemo.net.CSMHttpCallback;
 
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -32,15 +41,27 @@ public class MapChallengeActivity extends Activity {
     private String maps_id = "185";
     private String student_id = "180721";
 
+    private List<String> bkg_images;
+    private LinearLayout llMapBg;
+    private RelativeLayout rlMapBg;
+    private HorizontalScrollView scrollView;
+
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_map_challenge);
         initView();
+        initData();
+    }
+
+    void initData(){
+        getMap();
     }
 
     void initView(){
+        llMapBg = findViewById(R.id.ll_map_bg);
+        rlMapBg = findViewById(R.id.rl_map_bg);
         btnMap1 = findViewById(R.id.btn_map_1);
         btnMap2 = findViewById(R.id.btn_map_2);
         btnMap2.setOnClickListener(v -> {
@@ -87,6 +108,45 @@ public class MapChallengeActivity extends Activity {
         });
     }
 
+    private void addBigBg(String url){
+        ImageView child = new ImageView(this);
+//        Glide.with(this).asBitmap().load(url).into(new BitmapImageViewTarget(child){
+//            @Override
+//            public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
+//                child.setLayoutParams(new LinearLayout.LayoutParams(getScreenHeight()* resource.getWidth()/resource.getHeight(),getScreenHeight()));
+//                child.setImageBitmap(resource);
+//            }
+//        });
+        Glide.with(this)
+                .load(url)
+                .format(DecodeFormat.PREFER_RGB_565)
+                .into(child);
+        child.setScaleType(ImageView.ScaleType.FIT_XY);
+        child.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,getScreenHeight()));
+        llMapBg.addView(child);
+    }
+
+    private void addSmallBg(String url, double x, double y){
+        ImageView child = new ImageView(this);
+//        Glide.with(this).asBitmap().load(url).into(new BitmapImageViewTarget(child){
+//            @Override
+//            public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
+//                child.setLayoutParams(new LinearLayout.LayoutParams(getScreenHeight()* resource.getWidth()/resource.getHeight(),getScreenHeight()));
+//                child.setImageBitmap(resource);
+//            }
+//        });
+        Glide.with(this)
+                .load(url)
+                .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());
+        child.setLayoutParams(layoutParams);
+        rlMapBg.addView(child);
+    }
+
     void getMap(){
         Map<String, String> params = new HashMap<>();
         params.put("member_id",member_id);
@@ -96,7 +156,15 @@ public class MapChallengeActivity extends Activity {
         ApiHttpClient.get(ApiUrl.getMap,params, new CSMHttpCallback() {
             @Override
             protected void onSuccess(String jsonStr) {
-
+                MapBean mapBean = MapBean.parse(jsonStr);
+                bkg_images = mapBean.getResult().getList().getBkg_images();
+                for(String url : bkg_images){
+                   addBigBg(url);
+                }
+                List<StepsBean> stepsBeans = mapBean.getResult().getList().getSteps();
+                for(StepsBean stepsBean : stepsBeans){
+                    addSmallBg(stepsBean.getImage(), stepsBean.getCoordinate().getX(), stepsBean.getCoordinate().getY());
+                }
             }
 
             @Override

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

@@ -47,7 +47,7 @@ import com.zhy.view.flowlayout.TagFlowLayout;
 public class NewSongLyricActivity extends Activity {
 
 	private SongLyricTextView textView;
-	private Button start,stop;
+	private Button start,stop,test;
 	private MediaPlayer mediaPlayer;
 	private String TAG = "NewSongLyricActivity";
 	private TagFlowLayout flowLayout;
@@ -99,6 +99,10 @@ public class NewSongLyricActivity extends Activity {
 			textView.stopPlay();
 			handler.removeCallbacks(runnable);
 		});
+		test = findViewById(R.id.test);
+		test.setOnClickListener(v->textView.startNormalLine(
+				0,
+				startIndex));
 		mediaPlayer = new MediaPlayer();
 		flowLayout = findViewById(R.id.tab_flowlayout);
 		getMedia();
@@ -176,24 +180,23 @@ public class NewSongLyricActivity extends Activity {
 						if (num==beanList.size()){
 							num = 0;
 						}
-						textView.startPlayLine(
-								startIndex,
-								startIndex + timeBean.getWord().length(), // 因为有个换行符,所以 + 1
-								1);
-						startIndex += timeBean.getWord().length();
-
 						if (timeBean.getTime()+timeBean.getStartTime()+canTime == timeBean.getEndTime()){
 							canTime =0;
 							normal = startIndex;
 
 						}else{
 							if (canTime==0){
-//								textView.startNormalLine(
-//										0,
-//										startIndex);
 							}
 							canTime +=timeBean.getTime();
 						}
+
+						textView.startPlayLine(
+								startIndex,
+								startIndex + timeBean.getWord().length(), // 因为有个换行符,所以 + 1
+								normal,1);
+						startIndex += timeBean.getWord().length();
+
+
 						timeBean = beanList.get(num);
 					}
 					break;

+ 2 - 1
app/src/main/java/com/xunao/effectdemo/activity/SongLyricActivity.kt

@@ -60,7 +60,8 @@ class SongLyricActivity : AppCompatActivity() {
                     {
                         text.startPlayLine(
                             startIndexTemp,
-                            min(lyric.length, startIndexTemp + it.length + 1), // 因为有个换行符,所以 + 1
+                            min(lyric.length, startIndexTemp + it.length + 1),
+                            startIndexTemp,// 因为有个换行符,所以 + 1
                             duration
                         )
                     },

File diff suppressed because it is too large
+ 18 - 0
app/src/main/java/com/xunao/effectdemo/bean/MapBean.java


+ 20 - 12
app/src/main/java/com/xunao/effectdemo/view/SongLyricTextView.kt

@@ -83,13 +83,13 @@ class SongLyricTextView @JvmOverloads constructor(
                 if (lineWidth <= consumeWidth) {
                     // 如果是之前已经变色区域,直接添加到path中
                     consumeWidth -= lineWidth
-                    path.addRect(
-                        layout.getLineLeft(i),
-                        layout.getLineTop(i).toFloat(),
-                        layout.getLineRight(i),
-                        layout.getLineBottom(i).toFloat(),
-                        Path.Direction.CCW
-                    )
+//                    path.addRect(
+//                        layout.getLineLeft(i),
+//                        layout.getLineTop(i).toFloat(),
+//                        layout.getLineRight(i),
+//                        layout.getLineBottom(i).toFloat(),
+//                        Path.Direction.CCW
+//                    )
                 } else {
                     // 如果该行正好是要变色的行,直接改变颜色
                     // 把需要的consumeWidth放入path中
@@ -120,7 +120,6 @@ class SongLyricTextView @JvmOverloads constructor(
 
                 if (lineWidth <= consumeWidth) {
                     // 如果是之前已经变色区域,直接添加到path中
-                    consumeWidth -= lineWidth
                     path.addRect(
                         layout.getLineLeft(i),
                         layout.getLineTop(i).toFloat(),
@@ -128,6 +127,10 @@ class SongLyricTextView @JvmOverloads constructor(
                         layout.getLineBottom(i).toFloat(),
                         Path.Direction.CCW
                     )
+
+                    oldStartWidth -= lineWidth
+                    consumeWidth -= lineWidth
+
                 } else {
                     // 如果该行正好是要变色的行,直接改变颜色
                     // 把需要的consumeWidth放入path中
@@ -149,6 +152,10 @@ class SongLyricTextView @JvmOverloads constructor(
         }
     }
 
+    private var startWidth : Float = 0f
+    private var endWidth : Float = 0f
+    private var oldStartWidth : Float = 0f
+
     /**
      * 开始播放
      *
@@ -156,12 +163,13 @@ class SongLyricTextView @JvmOverloads constructor(
      * @param endIndex 结束的文字的索引
      * @param duration 播放时长
      * */
-    fun startPlayLine(startIndex: Int, endIndex: Int, duration: Long) {
+    fun startPlayLine(startIndex: Int, endIndex: Int,oldStart: Int, duration: Long) {
         isPlaying = true
         if (startIndex == -1) return
-        val startWidth = mPaint.measureText(this.text.substring(0, startIndex))
-        val endWidth = startWidth + mPaint.measureText(this.text.substring(startIndex, endIndex))
-        animator.setFloatValues(startWidth, endWidth)
+        startWidth = mPaint.measureText(this.text.substring(0, startIndex))
+        oldStartWidth = mPaint.measureText(this.text.substring(0, oldStart))
+        endWidth = startWidth!! + mPaint.measureText(this.text.substring(startIndex, endIndex))
+        animator.setFloatValues(startWidth!!, endWidth!!)
         animator.duration = if (duration > 0) duration else 10
         animator.start()
     }

+ 48 - 32
app/src/main/res/layout/activity_map_challenge.xml

@@ -1,43 +1,59 @@
 <?xml version="1.0" encoding="utf-8"?>
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+
+<HorizontalScrollView 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:id="@+id/scroll_view"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent">
+<RelativeLayout
+    android:id="@+id/rl_map_bg"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:gravity="center"
     tools:context=".activity.MapChallengeActivity"
     android:orientation="horizontal">
-
-    <Button
-        android:id="@+id/btn_map_1"
-        android:text="视频播放"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"/>
-    <Button
-        android:id="@+id/btn_map_2"
-        android:text="点图发声"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"/>
-    <Button
-        android:id="@+id/btn_map_3"
-        android:text="视频点播"
+        <LinearLayout
+            android:id="@+id/ll_map_bg"
+            android:layout_width="match_parent"
+            android:layout_height="match_parent"
+            android:orientation="horizontal" />
+    <LinearLayout
         android:layout_width="wrap_content"
-        android:layout_height="wrap_content"/>
-    <Button
-        android:id="@+id/btn_map_4"
-        android:text="选择题"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"/>
-    <Button
-        android:id="@+id/btn_map_5"
-        android:text="文字泛红"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"/>
-    <Button
-        android:id="@+id/btn_map_6"
-        android:text="角色扮演"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"/>
+        android:layout_height="wrap_content">
+        <Button
+            android:id="@+id/btn_map_1"
+            android:text="视频播放"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"/>
+        <Button
+            android:id="@+id/btn_map_2"
+            android:text="点图发声"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"/>
+        <Button
+            android:id="@+id/btn_map_3"
+            android:text="视频点播"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"/>
+        <Button
+            android:id="@+id/btn_map_4"
+            android:text="选择题"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"/>
+        <Button
+            android:id="@+id/btn_map_5"
+            android:text="文字泛红"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"/>
+        <Button
+            android:id="@+id/btn_map_6"
+            android:text="角色扮演"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"/>
+    </LinearLayout>
+
 
+</RelativeLayout>
 
-</LinearLayout>
+</HorizontalScrollView>

+ 6 - 0
app/src/main/res/layout/activity_songe.xml

@@ -43,4 +43,10 @@
         android:layout_height="wrap_content"
         android:text="结束播放" />
 
+    <Button
+        android:id="@+id/test"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:text="测试数据" />
+
 </LinearLayout>

Some files were not shown because too many files changed in this diff