From 3af030dcfc0ad49d13b895372c6091191ab59841 Mon Sep 17 00:00:00 2001 From: 18561577093 <17882492@qq.com> Date: Fri, 11 Jun 2021 09:54:58 +0800 Subject: [PATCH 1/2] [AD] 00005 [describe] fix dance crash in versions lower than Android p [commiter] wanglixue [AD] 00005 [describe] fix dance crash in versions lower than Android p [commiter] wanglixue --- .../mindspore/dance/view/DanceActivity.java | 5 + .../dance/view/fragment/RunFragment.java | 99 ++++++++++++++----- 2 files changed, 78 insertions(+), 26 deletions(-) diff --git a/model_zoo/official/lite/MindSpore_inhand/dance/src/main/java/com/mindspore/dance/view/DanceActivity.java b/model_zoo/official/lite/MindSpore_inhand/dance/src/main/java/com/mindspore/dance/view/DanceActivity.java index e2d6c15f6f..faa5d48dd1 100644 --- a/model_zoo/official/lite/MindSpore_inhand/dance/src/main/java/com/mindspore/dance/view/DanceActivity.java +++ b/model_zoo/official/lite/MindSpore_inhand/dance/src/main/java/com/mindspore/dance/view/DanceActivity.java @@ -48,4 +48,9 @@ public class DanceActivity extends AppCompatActivity { } + @Override + public void onBackPressed() { + finish(); + } + } diff --git a/model_zoo/official/lite/MindSpore_inhand/dance/src/main/java/com/mindspore/dance/view/fragment/RunFragment.java b/model_zoo/official/lite/MindSpore_inhand/dance/src/main/java/com/mindspore/dance/view/fragment/RunFragment.java index a51d1361b4..d41b84c8ab 100644 --- a/model_zoo/official/lite/MindSpore_inhand/dance/src/main/java/com/mindspore/dance/view/fragment/RunFragment.java +++ b/model_zoo/official/lite/MindSpore_inhand/dance/src/main/java/com/mindspore/dance/view/fragment/RunFragment.java @@ -18,9 +18,9 @@ package com.mindspore.dance.view.fragment; import android.annotation.SuppressLint; import android.media.MediaPlayer; -import android.os.Build; import android.os.Bundle; import android.os.Handler; +import android.os.Message; import android.util.Log; import android.view.Gravity; import android.view.LayoutInflater; @@ -33,11 +33,8 @@ import android.widget.MediaController; import android.widget.TextView; import androidx.annotation.NonNull; -import androidx.annotation.RequiresApi; -import androidx.camera.camera2.Camera2Config; import androidx.camera.core.Camera; import androidx.camera.core.CameraSelector; -import androidx.camera.core.CameraXConfig; import androidx.camera.core.Preview; import androidx.camera.lifecycle.ProcessCameraProvider; import androidx.camera.view.PreviewView; @@ -53,9 +50,15 @@ import com.mindspore.dance.present.video.MyVideoView; import com.mindspore.dance.task.SampleTask; import com.mindspore.dance.util.Tools; +import java.lang.ref.WeakReference; +import java.util.Timer; +import java.util.TimerTask; import java.util.concurrent.ExecutionException; public class RunFragment extends Fragment { + private final static int COUNT_DOWN_1 = 1; + private final static int COUNT_DOWN_2 = 2; + private final static int COUNT_DOWN_3 = 3; private final String TAG = RunFragment.class.getSimpleName(); private FrameLayout root; private MyVideoView videoView; @@ -64,9 +67,10 @@ public class RunFragment extends Fragment { private SampleTask sampleTask; private TextView countdownView; private ImageView info; - private Handler handler; - private final int NEED_CANCEL = -1; private MediaController mediaController; + private int timeWhat; + private Handler mHandler; + private Timer timer; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -77,7 +81,7 @@ public class RunFragment extends Fragment { public void onViewCreated(@NonNull View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); root = view.findViewById(R.id.root); - handler = new Handler(); + mHandler = new MyHandler(this); mediaController = new MediaController(this.getContext()); initView(); @@ -99,27 +103,70 @@ public class RunFragment extends Fragment { } } - @RequiresApi(api = Build.VERSION_CODES.P) + private void setTimer() { + timer.schedule(new TimerTask() { + @Override + public void run() { + Thread thread = new Thread(new Runnable() { + @Override + public void run() { + Log.d(TAG, "run this thread:"+android.os.Process.myTid()); + Message message = new Message(); + message.what = timeWhat; + timeWhat++; + mHandler.sendMessage(message); + } + }); + thread.start(); + } + }, 1000, 1000); + } + + private static class MyHandler extends Handler { + + private WeakReference weakReference; + + public MyHandler(RunFragment fragment) { + weakReference = new WeakReference<>(fragment); + } + + public void handleMessage(Message msg) { + RunFragment thisFragment = this.weakReference.get(); + switch (msg.what) { + case COUNT_DOWN_1: + thisFragment.info.setVisibility(View.VISIBLE); + thisFragment.info.setBackgroundResource(R.drawable.countdown_two); + break; + case COUNT_DOWN_2: + thisFragment.info.setVisibility(View.VISIBLE); + thisFragment.info.setBackgroundResource(R.drawable.countdown_one); + break; + case COUNT_DOWN_3: + thisFragment.beginPlay(); + thisFragment.info.setVisibility(View.GONE); + break; + default: + thisFragment.timer.cancel(); + break; + } + super.handleMessage(msg); + } + } + @Override public void onResume() { + super.onResume(); info.setVisibility(View.VISIBLE); info.setBackgroundResource(R.drawable.countdown_three); - super.onResume(); - handler.postDelayed(() -> { - //execute the task - info.setVisibility(View.VISIBLE); - info.setBackgroundResource(R.drawable.countdown_two); - }, NEED_CANCEL, 1000); - handler.postDelayed(() -> { - //execute the task - info.setVisibility(View.VISIBLE); - info.setBackgroundResource(R.drawable.countdown_one); - }, NEED_CANCEL, 2000); - handler.postDelayed(() -> { - //execute the task - beginPlay(); - info.setVisibility(View.GONE); - }, NEED_CANCEL, 3080); + timer = new Timer(); + timeWhat = COUNT_DOWN_1; + setTimer(); + } + + @Override + public void onDestroy() { + super.onDestroy(); + mHandler = null; } private void start() { @@ -142,7 +189,7 @@ public class RunFragment extends Fragment { @Override public void onPause() { super.onPause(); - handler.removeMessages(NEED_CANCEL); + timer.cancel(); if (sampleTask != null) { sampleTask.setNeedStop(true); sampleTask.clear(); @@ -225,6 +272,6 @@ public class RunFragment extends Fragment { backButton.setOnClickListener(view -> { getActivity().finish(); }); - Tools.addView(getActivity(), root, backButton, 0.1f, 0.2f, 0.12f, 0.1f); + Tools.addView(getActivity(), root, backButton, 0.1f, 0.2f, 0.20f, 0.1f); } } -- Gitee From 914c97f3253ba53a2cea68b543265aaba23ac4f9 Mon Sep 17 00:00:00 2001 From: 18561577093 <17882492@qq.com> Date: Fri, 11 Jun 2021 11:34:34 +0800 Subject: [PATCH 2/2] [AD] 00006 [describe] modify me & college title [commiter] wanglixue --- .../app/src/main/res/layout/fragment_college.xml | 4 ++-- .../MindSpore_inhand/app/src/main/res/layout/fragment_me.xml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/model_zoo/official/lite/MindSpore_inhand/app/src/main/res/layout/fragment_college.xml b/model_zoo/official/lite/MindSpore_inhand/app/src/main/res/layout/fragment_college.xml index fcaaf87543..13e5883989 100644 --- a/model_zoo/official/lite/MindSpore_inhand/app/src/main/res/layout/fragment_college.xml +++ b/model_zoo/official/lite/MindSpore_inhand/app/src/main/res/layout/fragment_college.xml @@ -9,10 +9,10 @@ android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:layout_gravity="center" - android:background="@drawable/bg_title_blue" + android:background="@color/white" android:gravity="center" android:text="@string/main_tab_title_two" - android:textColor="@color/white" + android:textColor="@color/black" android:textSize="17sp" android:textStyle="bold" /> diff --git a/model_zoo/official/lite/MindSpore_inhand/app/src/main/res/layout/fragment_me.xml b/model_zoo/official/lite/MindSpore_inhand/app/src/main/res/layout/fragment_me.xml index d5501e9dc6..2659b39397 100644 --- a/model_zoo/official/lite/MindSpore_inhand/app/src/main/res/layout/fragment_me.xml +++ b/model_zoo/official/lite/MindSpore_inhand/app/src/main/res/layout/fragment_me.xml @@ -12,10 +12,10 @@ android:layout_height="?attr/actionBarSize" android:layout_alignParentTop="true" android:layout_gravity="center" - android:background="@drawable/bg_title_blue" + android:background="@color/white" android:gravity="center" android:text="@string/me_title" - android:textColor="@color/white" + android:textColor="@color/black" android:textSize="17sp" android:textStyle="bold" /> -- Gitee