3 次代碼提交 34325f622c ... 362c80a945

作者 SHA1 備註 提交日期
  LAPTOP-K69FCNBP\crius 362c80a945 Merge branch 'master' of http://116.62.119.248:10082/cheng_zq/EffectDemo into lwz_ 2 年之前
  LAPTOP-K69FCNBP\crius 5d3f2556d1 Merge branch 'master' of http://116.62.119.248:10082/cheng_zq/EffectDemo into lwz_ 2 年之前
  LAPTOP-K69FCNBP\crius d2ce08bac1 选择题 2 年之前

+ 6 - 0
app/src/main/AndroidManifest.xml

@@ -138,6 +138,12 @@
         <activity
             android:name=".activity.AudioActivity"
             android:screenOrientation="landscape" />
+        <activity
+            android:name=".activity.RolePlayActivity"
+            android:screenOrientation="landscape" />
+        <activity
+            android:name=".activity.DragActivity"
+            android:screenOrientation="landscape" />
         <activity android:name=".activity.NewSongLyricActivity"/>
     </application>
 

+ 111 - 0
app/src/main/java/com/xunao/effectdemo/activity/DragActivity.java

@@ -0,0 +1,111 @@
+package com.xunao.effectdemo.activity;
+
+import androidx.appcompat.app.AppCompatActivity;
+import androidx.core.content.res.ResourcesCompat;
+
+import android.app.Activity;
+import android.content.ClipData;
+import android.content.Intent;
+import android.os.Bundle;
+import android.os.SystemClock;
+import android.util.Log;
+import android.view.DragEvent;
+import android.view.HapticFeedbackConstants;
+import android.view.MotionEvent;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.animation.Animation;
+import android.view.animation.TranslateAnimation;
+import android.widget.FrameLayout;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.RelativeLayout;
+import android.widget.TextView;
+
+import com.xunao.effectdemo.R;
+
+public class DragActivity extends Activity{
+
+    private static final String RED = "RED";
+
+    private String selectedContent = "";
+    private final String correctAnswer = "选项2";
+    private int wrongNum = 0;
+
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.activity_drag);
+
+        TextView ll_red = findViewById(R.id.ll_red);
+        TextView tv1 = findViewById(R.id.tv_1);
+        TextView tv2 = findViewById(R.id.tv_2);
+
+        tv1.setOnLongClickListener(v -> {
+            selectedContent = tv1.getText().toString();
+//                Intent intent = new Intent();
+//                ClipData clipData = ClipData.newIntent("label", intent);
+            View.DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(v);
+            v.startDrag(null, shadowBuilder, tv1, 0);
+            //震动反馈
+            v.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
+            return true;
+        });
+
+        tv2.setOnLongClickListener(v -> {
+            selectedContent = tv2.getText().toString();
+//                Intent intent = new Intent();
+//                ClipData clipData = ClipData.newIntent("label", intent);
+            View.DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(v);
+            v.startDrag(null, shadowBuilder, tv2, 0);
+            //震动反馈
+            v.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
+            return true;
+        });
+
+        ll_red.setOnDragListener((v, event) -> {
+            String simpleName = v.getClass().getSimpleName();
+            Log.w(RED, "view name:" + simpleName);
+
+            int action = event.getAction();
+            switch (action) {
+                case DragEvent.ACTION_DRAG_STARTED:
+                    Log.i(RED, "开始拖拽");
+//                        tv1.setVisibility(View.INVISIBLE);
+                    break;
+                case DragEvent.ACTION_DRAG_ENDED:
+                    Log.i(RED, "结束拖拽");
+//                        tv1.setVisibility(View.VISIBLE);
+                    break;
+                case DragEvent.ACTION_DRAG_ENTERED:
+                    Log.i(RED, "拖拽的view进入监听的view时");
+                    break;
+                case DragEvent.ACTION_DRAG_EXITED:
+                    Log.i(RED, "拖拽的view离开监听的view时");
+                    break;
+                case DragEvent.ACTION_DRAG_LOCATION:
+                    float x = event.getX();
+                    float y = event.getY();
+                    Log.i(RED, "拖拽的view在RED中的位置:x =" + x + ",y=" + y);
+                    break;
+                case DragEvent.ACTION_DROP:
+                    if(correctAnswer.equals(selectedContent)){
+                        Log.i(RED, "释放拖拽的view");
+                        TextView localState = (TextView) event.getLocalState();
+                        ((ViewGroup) localState.getParent()).removeView(localState);
+                        ll_red.setText(selectedContent);
+                        ll_red.setBackground(ResourcesCompat.getDrawable(getResources(),R.drawable.drag_success_bg,null));
+                    }else{
+                        wrongNum = wrongNum + 1;
+                        if(wrongNum >= 2){
+                            tv2.setBackground(ResourcesCompat.getDrawable(getResources(),R.drawable.drag_hint_bg,null));
+                        }
+                    }
+                    break;
+            }
+            return true;
+        });
+
+    }
+}

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

@@ -53,6 +53,10 @@ public class MapChallengeActivity extends Activity {
             startActivity(intent);
         });
         btnMap4 = findViewById(R.id.btn_map_4);
+        btnMap4.setOnClickListener(v -> {
+            intent = new Intent(MapChallengeActivity.this, DragActivity.class);
+            startActivity(intent);
+        });
         btnMap5 = findViewById(R.id.btn_map_5);
         btnMap5.setOnClickListener(v->{
             intent = new Intent(MapChallengeActivity.this, NewSongLyricActivity.class);

+ 28 - 35
app/src/main/java/com/xunao/effectdemo/activity/RolePlayActivity.java

@@ -1,6 +1,5 @@
 package com.xunao.effectdemo.activity;
 
-import androidx.appcompat.app.AppCompatActivity;
 import androidx.recyclerview.widget.LinearLayoutManager;
 import androidx.recyclerview.widget.RecyclerView;
 import androidx.recyclerview.widget.SimpleItemAnimator;
@@ -10,11 +9,9 @@ import android.os.Bundle;
 import android.util.Log;
 import android.view.View;
 import android.widget.Button;
-import android.widget.Toast;
 
 import com.xunao.effectdemo.R;
 import com.xunao.effectdemo.adapter.RolePlayAdapter;
-import com.xunao.effectdemo.adapter.WordCutAdapter;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -30,6 +27,7 @@ public class RolePlayActivity extends Activity {
     private RecyclerView rvMarquee;
     private RolePlayAdapter rolePlayAdapter;
     private List<String> roleList = new ArrayList<>();
+    private String currentRole;  // 拿到随机选中的角色
 
     // 跑马灯
     private boolean isGameRunning = false; //是否处于转动
@@ -52,13 +50,10 @@ public class RolePlayActivity extends Activity {
 
     private void initView(){
         btnStart = findViewById(R.id.btn_start);
-        btnStart.setOnClickListener(new View.OnClickListener() {
-            @Override
-            public void onClick(View v) {
-                int stayIndex = new Random().nextInt(6);
-                Log.i(TAG, "stayIndex:" + stayIndex);
-                startGame(stayIndex);
-            }
+        btnStart.setOnClickListener(v -> {
+            int stayIndex = new Random().nextInt(roleList.size());
+            Log.i(TAG, "stayIndex:" + stayIndex);
+            startGame(stayIndex);
         });
         rvMarquee = findViewById(R.id.rv_marquee);
         ((SimpleItemAnimator) Objects.requireNonNull(rvMarquee.getItemAnimator())).setSupportsChangeAnimations(false);
@@ -91,41 +86,39 @@ public class RolePlayActivity extends Activity {
         isGameRunning = true;
         isTryToStop = false;
         currentSpeed = DEFAULT_SPEED;
-        new Thread(new Runnable() {
-            @Override
-            public void run() {
-                while (isGameRunning) {
-                    try {
-                        Thread.sleep(getInterruptTime());
-                    } catch (InterruptedException e) {
-                        e.printStackTrace();
-                    }
-
-                    // 防止线程多走了一次
-                    if (!isGameRunning) {
-                        return;
-                    }
-                    // 改变高亮项的索引
-                    runOnUiThread(() -> rolePlayAdapter.changeIndex());
-                    Log.i(TAG, "到" + roleList.get(rolePlayAdapter.getCurrentIndex()) + "--" + rolePlayAdapter.getCurrentIndex());
-
-                    //减速&&速度达到最小&&当前view为指定view——停止
-                    if (isTryToStop && currentSpeed == DEFAULT_SPEED && stayIndex == rolePlayAdapter.getCurrentIndex()) {
-                        isGameRunning = false;
-                        Log.i(TAG, "结束:角色为" + roleList.get(rolePlayAdapter.getCurrentIndex()) + "--" + rolePlayAdapter.getCurrentIndex());
+        new Thread(() -> {
+            while (isGameRunning) {
+                try {
+                    Thread.sleep(getInterruptTime());
+                } catch (InterruptedException e) {
+                    e.printStackTrace();
+                }
+
+                // 防止线程多走了一次
+                if (!isGameRunning) {
+                    return;
+                }
+                // 改变高亮项的索引
+                runOnUiThread(() -> rolePlayAdapter.changeIndex());
+                Log.i(TAG, "到" + roleList.get(rolePlayAdapter.getCurrentIndex()) + "--" + rolePlayAdapter.getCurrentIndex());
+
+                //减速&&速度达到最小&&当前view为指定view——停止
+                if (isTryToStop && currentSpeed == DEFAULT_SPEED && stayIndex == rolePlayAdapter.getCurrentIndex()) {
+                    isGameRunning = false;
+                    Log.i(TAG, "结束:角色为" + roleList.get(rolePlayAdapter.getCurrentIndex()) + "--" + rolePlayAdapter.getCurrentIndex());
 //                        listener.onShop(currentIndex);
-                    }
+                    currentRole = roleList.get(rolePlayAdapter.getCurrentIndex());
                 }
             }
         }).start();
 
-        //秒后开始减速
+        //2秒后开始减速
         timer.schedule(new TimerTask() {
             @Override
             public void run() {
                 tryToStop();
             }
-        }, 5000);
+        }, 2000);
     }
 
     //改变加速状态

+ 6 - 0
app/src/main/res/drawable/drag_default_bg.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shape xmlns:android="http://schemas.android.com/apk/res/android">
+    <solid android:color="@color/colorWhite" />
+    <stroke android:width="1dp" android:color="@color/colorGrayDark"/>
+    <corners android:radius="4dp" />
+</shape>

+ 6 - 0
app/src/main/res/drawable/drag_hint_bg.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shape xmlns:android="http://schemas.android.com/apk/res/android">
+    <solid android:color="@color/colorWhite" />
+    <stroke android:width="1dp" android:color="@color/shadow_tint_color"/>
+    <corners android:radius="4dp" />
+</shape>

+ 6 - 0
app/src/main/res/drawable/drag_success_bg.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shape xmlns:android="http://schemas.android.com/apk/res/android">
+    <solid android:color="@color/colorWhite" />
+    <stroke android:width="1dp" android:color="@color/colorAccent"/>
+    <corners android:radius="4dp" />
+</shape>

+ 46 - 0
app/src/main/res/layout/activity_drag.xml

@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout 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">
+    <LinearLayout
+        android:layout_width="0dp"
+        android:layout_height="match_parent"
+        android:gravity="center"
+        android:background="@color/textGrayColor"
+        android:layout_weight="1">
+        <TextView
+            android:id="@+id/ll_red"
+            android:layout_width="200dp"
+            android:layout_height="40dp"
+            android:gravity="center"
+            android:background="@drawable/drag_default_bg"/>
+    </LinearLayout>
+
+    <LinearLayout
+        android:layout_width="0dp"
+        android:layout_height="match_parent"
+        android:gravity="center"
+        android:orientation="vertical"
+        android:layout_weight="1">
+
+        <TextView
+            android:id="@+id/tv_1"
+            android:layout_width="200dp"
+            android:layout_height="40dp"
+            android:gravity="center"
+            android:background="@drawable/drag_default_bg"
+            android:layout_marginBottom="20dp"
+            android:text="选项1"/>
+
+        <TextView
+            android:id="@+id/tv_2"
+            android:layout_width="200dp"
+            android:layout_height="40dp"
+            android:gravity="center"
+            android:background="@drawable/drag_default_bg"
+            android:text="选项2"/>
+
+    </LinearLayout>
+</LinearLayout>

+ 11 - 0
app/src/main/res/layout/activity_role_play.xml

@@ -15,4 +15,15 @@
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_centerInParent="true"/>
+    <Button
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_alignParentBottom="true"
+        android:text="重置"/>
+    <Button
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_alignParentBottom="true"
+        android:layout_centerHorizontal="true"
+        android:text="GO"/>
 </RelativeLayout>