chenzubin преди 2 месеца
родител
ревизия
7e4aa892ad

+ 9 - 1
app/build.gradle

@@ -9,7 +9,7 @@ android {
9 9
     defaultConfig {
10 10
         applicationId "com.cfmlg.mlg680"
11 11
         minSdk 24
12
-        targetSdk 33
12
+        targetSdk 29
13 13
         versionCode 1
14 14
         versionName "1.0"
15 15
 
@@ -39,6 +39,10 @@ android {
39 39
             version '3.22.1'
40 40
         }
41 41
     }
42
+
43
+    dataBinding {
44
+        enabled = true
45
+    }
42 46
     buildFeatures {
43 47
         viewBinding true
44 48
     }
@@ -48,6 +52,8 @@ android {
48 52
             jniLibs.srcDirs = ['libs']
49 53
         }
50 54
     }
55
+
56
+
51 57
 }
52 58
 
53 59
 dependencies {
@@ -62,4 +68,6 @@ dependencies {
62 68
     implementation 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
63 69
     implementation 'androidx.appcompat:appcompat:1.4.0'
64 70
     implementation 'com.github.sahooz:ImageMapView:1.0.1'
71
+    implementation 'com.github.getActivity:XXPermissions:20.0'
72
+    implementation 'androidx.databinding:databinding-runtime:4.0.0'
65 73
 }

+ 19 - 3
app/src/main/AndroidManifest.xml

@@ -24,8 +24,20 @@
24 24
         android:theme="@style/Theme.MainTheme"
25 25
         tools:targetApi="31">
26 26
         <activity
27
+            android:name=".HistoryActivity"
28
+            android:exported="true" >
29
+
30
+        </activity>
31
+
32
+        <meta-data
33
+            android:name="ScopedStorage"
34
+            android:value="true" />
35
+
36
+        <activity
27 37
             android:name=".VideoViewActivity"
28
-            android:exported="false" />
38
+            android:exported="true">
39
+
40
+        </activity>
29 41
         <activity
30 42
             android:name=".QuestionActivity"
31 43
             android:exported="false" />
@@ -34,11 +46,15 @@
34 46
             android:configChanges="orientation|keyboardHidden|screenSize"
35 47
             android:exported="true"
36 48
             android:label="@string/title_activity_gather"
37
-            android:theme="@style/Theme.MainTheme.Fullscreen"></activity>
49
+            android:theme="@style/Theme.MainTheme.Fullscreen">
50
+
51
+        </activity>
38 52
         <activity
39 53
             android:name=".Video"
40 54
             android:exported="true"
41
-            android:screenOrientation="landscape"></activity>
55
+            android:screenOrientation="landscape">
56
+
57
+        </activity>
42 58
         <activity
43 59
             android:name=".MainActivity"
44 60
             android:exported="true">

+ 48 - 0
app/src/main/java/com/cfmlg/mlg/CustomImageView.java

@@ -0,0 +1,48 @@
1
+package com.cfmlg.mlg;
2
+
3
+import android.content.Context;
4
+import android.graphics.Bitmap;
5
+import android.graphics.BitmapFactory;
6
+import android.graphics.Canvas;
7
+import android.util.AttributeSet;
8
+import android.view.View;
9
+
10
+public class CustomImageView extends View {
11
+
12
+    private Bitmap bitmap;
13
+
14
+    public CustomImageView(Context context) {
15
+        super(context);
16
+    }
17
+
18
+    public CustomImageView(Context context, AttributeSet attrs) {
19
+        super(context, attrs);
20
+        init(context, attrs);
21
+    }
22
+
23
+    public CustomImageView(Context context, AttributeSet attrs, int defStyleAttr) {
24
+        super(context, attrs, defStyleAttr);
25
+        init(context, attrs);
26
+    }
27
+
28
+    private void init(Context context, AttributeSet attrs) {
29
+        int resId = attrs.getAttributeResourceValue(null, "src", 0);
30
+        if (resId != 0) {
31
+            bitmap = BitmapFactory.decodeResource(context.getResources(), resId);
32
+        }
33
+    }
34
+
35
+    @Override
36
+    protected void onDraw(Canvas canvas) {
37
+        super.onDraw(canvas);
38
+        if (bitmap != null) {
39
+            canvas.drawBitmap(bitmap, 0, 0, null);
40
+        }
41
+    }
42
+
43
+    // 提供方法用于设置Bitmap
44
+    public void setImageBitmap(Bitmap bitmap) {
45
+        this.bitmap = bitmap;
46
+        invalidate(); // 重新绘制视图
47
+    }
48
+}

+ 20 - 0
app/src/main/java/com/cfmlg/mlg/HistoryActivity.java

@@ -0,0 +1,20 @@
1
+package com.cfmlg.mlg;
2
+
3
+import androidx.appcompat.app.AppCompatActivity;
4
+import androidx.databinding.DataBindingUtil;
5
+
6
+import android.os.Bundle;
7
+
8
+import com.cfmlg.mlg.databinding.ActivityHistoryBinding;
9
+
10
+public class HistoryActivity extends AppCompatActivity {
11
+    ActivityHistoryBinding binding;
12
+    @Override
13
+    protected void onCreate(Bundle savedInstanceState) {
14
+        super.onCreate(savedInstanceState);
15
+        binding = ActivityHistoryBinding.inflate(getLayoutInflater());
16
+        setContentView(binding.getRoot());
17
+
18
+        binding.setImageUrl("imageUrl");
19
+    }
20
+}

+ 1 - 2
app/src/main/java/com/cfmlg/mlg/Video.java

@@ -213,6 +213,7 @@ public class Video extends AppCompatActivity {
213 213
                     binding.openDir.setImageResource(R.drawable.ic_app_compare);
214 214
                     Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
215 215
                     Uri uri = Uri.fromFile(new File(getSdPath()));
216
+                    Log.e("czb", path);
216 217
                     intent.setData(uri);
217 218
                     getApplicationContext().sendBroadcast(intent);
218 219
                     Intent intent2 = new Intent(Video.this, VideoViewActivity.class);
@@ -321,7 +322,6 @@ public class Video extends AppCompatActivity {
321 322
                 InputStream inputStream = socket.getInputStream();
322 323
                 length = inputStream.read(bytes);
323 324
                 Log.e(TAG, "serverSocketInit: length = " + length + Arrays.toString(bytes));
324
-                //抓取一张图片
325 325
 
326 326
                 handler.postDelayed(new Runnable() {
327 327
                     @Override
@@ -525,7 +525,6 @@ public class Video extends AppCompatActivity {
525 525
 
526 526
         @Override
527 527
         public void run() {
528
-            Log.e(TAG, isConnect + "   " + GetVersion(new byte[24]));
529 528
             int canShow = GetVersion(new byte[24]);
530 529
 
531 530
             if(!isConnect) {

+ 107 - 99
app/src/main/java/com/cfmlg/mlg/VideoViewActivity.java

@@ -1,119 +1,135 @@
1 1
 package com.cfmlg.mlg;
2 2
 
3
-import androidx.appcompat.app.AppCompatActivity;
4
-
5
-import android.app.Activity;
3
+import android.Manifest;
4
+import android.content.Intent;
5
+import android.content.pm.PackageManager;
6 6
 import android.media.AudioManager;
7 7
 import android.media.MediaPlayer;
8
+import android.net.Uri;
8 9
 import android.os.Bundle;
9 10
 import android.os.Environment;
10 11
 import android.util.Log;
11
-import android.view.SurfaceHolder;
12 12
 import android.view.SurfaceView;
13 13
 import android.view.View;
14
-import android.widget.Button;
15
-import android.widget.MediaController;
14
+import android.widget.ImageButton;
16 15
 import android.widget.SeekBar;
17
-import android.widget.Toast;
18
-import android.widget.VideoView;
16
+
17
+import androidx.annotation.NonNull;
18
+import androidx.appcompat.app.AppCompatActivity;
19
+import androidx.core.app.ActivityCompat;
20
+import androidx.core.content.ContextCompat;
21
+
22
+import com.hjq.permissions.OnPermissionCallback;
23
+import com.hjq.permissions.Permission;
24
+import com.hjq.permissions.XXPermissions;
19 25
 
20 26
 import java.io.File;
21 27
 import java.io.IOException;
22
-import java.util.Timer;
23
-import java.util.TimerTask;
28
+import java.util.List;
24 29
 
25
-public class VideoViewActivity extends Activity {
26
-    private Button btn_start_video = null;
27
-    private Button btn_stop_video = null;
28
-    private SurfaceView surfaceView;
29
-    private SurfaceHolder surfaceHolder;
30
+public class VideoViewActivity extends AppCompatActivity {
30 31
 
31
-    private MediaPlayer m = null;
32
-    private Timer mTimer;
33
-    private TimerTask mTimerTask;
32
+    private MediaPlayer mediaPlayer;
33
+    private SeekBar sb_main_play;
34
+    private SurfaceView sv_main_sur;
34 35
 
35
-    private boolean isChanging=false;//互斥变量,防止定时器与SeekBar拖动时进度冲突
36 36
     @Override
37
-    public void onCreate(Bundle savedInstanceState) {
37
+    protected void onCreate(Bundle savedInstanceState) {
38 38
         super.onCreate(savedInstanceState);
39 39
         setContentView(R.layout.activity_video_view);
40
+        permission();
41
+        sb_main_play = (SeekBar) findViewById(R.id.sb_main_play);
42
+        sv_main_sur = (SurfaceView) findViewById(R.id.sv_main_sur);
40 43
 
41
-        //----------Media控件设置---------//
42
-        m=new MediaPlayer();
43
-
44
-        //播放结束之后弹出提示
45
-        m.setOnCompletionListener(new MediaPlayer.OnCompletionListener(){
44
+        sb_main_play.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
46 45
             @Override
47
-            public void onCompletion(MediaPlayer arg0) {
48
-                Toast.makeText(VideoViewActivity.this, "结束", 1000).show();
49
-                m.release();
46
+            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
50 47
             }
51
-        });
52 48
 
53
-        //----------定时器记录播放进度---------//
54
-        mTimer = new Timer();
55
-        mTimerTask = new TimerTask() {
56 49
             @Override
57
-            public void run() {
58
-                if(isChanging==true)
59
-                    return;
60
-
50
+            public void onStartTrackingTouch(SeekBar seekBar) {
61 51
             }
62
-        };
63 52
 
64
-        mTimer.schedule(mTimerTask, 0, 10);
53
+            @Override
54
+            public void onStopTrackingTouch(SeekBar seekBar) {
55
+                //获取当前进度条位置
56
+                int currentPosition=seekBar.getProgress();
57
+                //跳转到某个位置播放
58
+                mediaPlayer.seekTo(currentPosition);
59
+            }
60
+        });
61
+    }
65 62
 
63
+    private void permission() {
64
+        if (ContextCompat.checkSelfPermission(VideoViewActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
65
+        } else {
66
+            ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 123);
67
+        }
66 68
 
67
-        btn_start_video = (Button) this.findViewById(R.id.Button03);
68
-        btn_stop_video = (Button) this.findViewById(R.id.Button04);
69
-        btn_start_video.setOnClickListener(new ClickEvent());
70
-        btn_stop_video.setOnClickListener(new ClickEvent());
71
-        surfaceView = (SurfaceView) findViewById(R.id.SurfaceView01);
72
-        surfaceHolder = surfaceView.getHolder();
73
-        surfaceHolder.setFixedSize(100, 100);
74
-        surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
69
+        XXPermissions.with(this)
70
+                .permission(Permission.READ_EXTERNAL_STORAGE)
71
+                .request(new OnPermissionCallback() {
72
+
73
+                    @Override
74
+                    public void onGranted(@NonNull List<String> permissions, boolean allGranted) {
75
+                        if (!allGranted) {
76
+                            return;
77
+                        }
78
+                    }
79
+
80
+                    @Override
81
+                    public void onDenied(@NonNull List<String> permissions, boolean doNotAskAgain) {
82
+                        if (doNotAskAgain) {
83
+                        } else {
84
+                        }
85
+                    }
86
+                });
75 87
     }
76
-    /*
77
-     * 按键事件处理
78
-     */
79
-    class ClickEvent implements View.OnClickListener{
80
-        @Override
81
-        public void onClick(View v) {
82
-            if(v==btn_start_video)
83
-            {
84
-                m.reset();//恢复到未初始化的状态
85
-                File file=new File(getSdPath());
86
-                File[] files = file.listFiles();
87
-
88
-                File lFile = null;
89
-                for (File f : files) {
90
-                    lFile = new File(f.getPath());
91
-                    Log.e("czb", f.getPath());
92
-                }
93
-                try {
94
-                    m.setDataSource(lFile.getPath());
95 88
 
96
-                } catch (IOException e) {
97
-                    throw new RuntimeException(e);
89
+    @Override
90
+    public void onRequestPermissionsResult(int requestCode,
91
+                                           String permissions[], int[] grantResults) {
92
+        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
93
+        switch (requestCode) {
94
+            case 123: {
95
+                if (grantResults.length > 0
96
+                        && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
97
+                } else {
98 98
                 }
99
-                m.setAudioStreamType(AudioManager.STREAM_MUSIC);
100
-                m.setDisplay(surfaceHolder);
101
-
102
-                try {
103
-                    m.prepare();
104
-
105
-                } catch (IllegalArgumentException e) {
106
-                    // TODO Auto-generated catch block
107
-                    e.printStackTrace();
108
-                } catch (IllegalStateException e) {
109
-                    // TODO Auto-generated catch block
110
-                    e.printStackTrace();
111
-                } catch (IOException e) {
112
-                    // TODO Auto-generated catch block
113
-                    e.printStackTrace();
99
+                return;
100
+            }
101
+        }
102
+    }
103
+
104
+    public void playOrPause(View view){
105
+        final ImageButton ib= (ImageButton) view;
106
+        if(mediaPlayer==null){//如果没有歌
107
+            //mediaPlayer = MediaPlayer.create(this, R.raw.a);
108
+            long tmp = 0l;
109
+            File files = new File(getSdPath());
110
+            if(files.isDirectory()) {
111
+                File jumpFile = null;
112
+                for(File file : files.listFiles()) {
113
+                    if(file.lastModified() > tmp) {
114
+                        tmp = file.lastModified();
115
+                        jumpFile = new File(file.getAbsoluteFile().toURI());
116
+                    }
114 117
                 }
115
-                m.start();
118
+                Intent it = new Intent(Intent.ACTION_VIEW);
119
+                it.setDataAndType(Uri.parse(jumpFile.getAbsolutePath()), "video/mp4");
120
+                startActivity(it);
116 121
             }
122
+        }else if(mediaPlayer.isPlaying()){//如果正在播放
123
+            //暂停
124
+            mediaPlayer.pause();
125
+            //开始图标
126
+            ib.setImageResource(android.R.drawable.ic_media_play);
127
+        }else {
128
+            //开始播放
129
+            mediaPlayer.start();
130
+            //暂停图标
131
+            ib.setImageResource(android.R.drawable.ic_media_pause);
132
+
117 133
         }
118 134
     }
119 135
 
@@ -126,24 +142,16 @@ public class VideoViewActivity extends Activity {
126 142
         }
127 143
         return null;
128 144
     }
129
-    /*
130
-     * SeekBar进度改变事件
131
-     */
132
-    class SeekBarChangeEvent implements SeekBar.OnSeekBarChangeListener{
133
-        @Override
134
-        public void onProgressChanged(SeekBar seekBar, int progress,
135
-                                      boolean fromUser) {
136
-            // TODO Auto-generated method stub
137
-        }
138
-        @Override
139
-        public void onStartTrackingTouch(SeekBar seekBar) {
140
-            isChanging=true;
141
-        }
142 145
 
146
+    class MyThread extends Thread{
143 147
         @Override
144
-        public void onStopTrackingTouch(SeekBar seekBar) {
145
-            m.seekTo(seekBar.getProgress());
146
-            isChanging=false;
148
+        public void run() {
149
+            super.run();
150
+            while(sb_main_play.getProgress()<sb_main_play.getMax()){
151
+                //获得音乐当前的播放位置
152
+                int currentPosition=mediaPlayer.getCurrentPosition();
153
+                sb_main_play.setProgress(currentPosition);
154
+            }
147 155
         }
148 156
     }
149 157
 }

BIN
app/src/main/res/drawable/ic_app_photo.png


BIN
app/src/main/res/drawable/ic_app_video.png


+ 63 - 0
app/src/main/res/layout/activity_history.xml

@@ -0,0 +1,63 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<layout xmlns:android="http://schemas.android.com/apk/res/android"
3
+    xmlns:app="http://schemas.android.com/apk/res-auto"
4
+    xmlns:tools="http://schemas.android.com/tools">
5
+
6
+    <data>
7
+        <variable
8
+            name="imageUrl"
9
+            type="String" />
10
+    </data>
11
+
12
+    <LinearLayout
13
+        android:layout_width="match_parent"
14
+        android:layout_height="match_parent"
15
+        android:padding="10dp"
16
+        tools:context=".HistoryActivity">
17
+
18
+        <TextView
19
+            android:layout_width="wrap_content"
20
+            android:layout_height="wrap_content"
21
+            android:padding="5dp"
22
+            android:text="图片"
23
+            android:textSize="17sp"
24
+            android:textStyle="bold" />
25
+
26
+        <LinearLayout
27
+            android:layout_width="match_parent"
28
+            android:layout_height="wrap_content"
29
+            android:gravity="center"
30
+            android:orientation="horizontal">
31
+
32
+            <ImageView
33
+                android:id="@+id/img1"
34
+                android:layout_width="80dp"
35
+                android:layout_height="80dp"
36
+                android:layout_margin="5dp"
37
+                android:background="#000000"
38
+                android:src="@{imageUrl}" />
39
+
40
+            <ImageView
41
+                android:id="@+id/img2"
42
+                android:layout_width="80dp"
43
+                android:layout_height="80dp"
44
+                android:layout_margin="5dp"
45
+                android:src="@drawable/camera" />
46
+
47
+            <ImageView
48
+                android:id="@+id/img3"
49
+                android:layout_width="80dp"
50
+                android:layout_height="80dp"
51
+                android:layout_margin="5dp"
52
+                android:src="@drawable/camera" />
53
+
54
+            <ImageView
55
+                android:id="@+id/img4"
56
+                android:layout_width="80dp"
57
+                android:layout_height="80dp"
58
+                android:layout_margin="5dp"
59
+                android:src="@drawable/camera" />
60
+
61
+        </LinearLayout>
62
+    </LinearLayout>
63
+</layout>

+ 6 - 5
app/src/main/res/layout/activity_video.xml

@@ -25,14 +25,15 @@
25 25
         app:layout_constraintLeft_toLeftOf="parent"
26 26
         app:layout_constraintTop_toTopOf="parent"
27 27
         app:srcCompat="@drawable/fan" />
28
-    <com.xinyanruanjian.imagemapview.ImageMapView
28
+    <com.cfmlg.mlg.CustomImageView
29 29
         android:id="@+id/imv"
30 30
         android:layout_width="match_parent"
31 31
         android:layout_height="match_parent"
32
+        android:layout_centerInParent="true"
32 33
         android:src="@drawable/ya"
33
-        android:scaleType="fitCenter"
34
-        android:visibility="gone"
35
-        app:imageMap="@xml/map"/>
34
+        android:visibility="visible"
35
+
36
+        />
36 37
     <LinearLayout
37 38
         android:id="@+id/blakgrond"
38 39
         android:layout_width="wrap_content"
@@ -131,7 +132,7 @@
131 132
             android:layout_width="200dp"
132 133
             android:layout_height="200dp"
133 134
             android:layout_centerInParent="true"
134
-            android:src="@drawable/disconnect">
135
+            >
135 136
 
136 137
         </ImageView>
137 138
 

+ 27 - 15
app/src/main/res/layout/activity_video_view.xml

@@ -1,18 +1,30 @@
1 1
 <?xml version="1.0" encoding="utf-8"?>
2
-<LinearLayout android:id="@+id/LinearLayout01"
3
-    android:layout_width="fill_parent" android:layout_height="fill_parent"
2
+<FrameLayout
4 3
     xmlns:android="http://schemas.android.com/apk/res/android"
5
-    android:orientation="vertical">
6
-
7
-    <SurfaceView android:id="@+id/SurfaceView01"
8
-        android:layout_width="fill_parent" android:layout_height="250px"></SurfaceView>
9
-    <LinearLayout android:id="@+id/LinearLayout02"
10
-        android:layout_width="wrap_content" android:layout_height="wrap_content">
11
-        <Button android:layout_width="wrap_content"
12
-            android:layout_height="wrap_content" android:id="@+id/Button03"
13
-            android:text="播放视频"></Button>
14
-        <Button android:layout_width="wrap_content"
15
-            android:layout_height="wrap_content" android:text="停止播放" android:id="@+id/Button04"></Button>
16
-    </LinearLayout>
17
-</LinearLayout>
4
+    xmlns:app="http://schemas.android.com/apk/res-auto"
5
+    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
6
+    android:layout_height="match_parent"
7
+    tools:context=".MainActivity"
8
+    android:orientation="vertical"
9
+    >
10
+    <SurfaceView
11
+        android:layout_width="match_parent"
12
+        android:layout_height="400dp"
13
+        android:id="@+id/sv_main_sur"
14
+        android:layout_gravity="center"
15
+        />
16
+    <SeekBar
17
+        android:layout_width="match_parent"
18
+        android:layout_height="wrap_content"
19
+        android:visibility="invisible"
20
+        android:id="@+id/sb_main_play"
21
+        />
22
+    <ImageButton
23
+        android:layout_width="100dp"
24
+        android:layout_height="100dp"
25
+        android:layout_gravity="center"
26
+        android:background="@android:drawable/ic_media_play"
27
+        android:onClick="playOrPause"
28
+        />
18 29
 
30
+</FrameLayout>

+ 1 - 1
build.gradle

@@ -2,4 +2,4 @@
2 2
 plugins {
3 3
     id 'com.android.application' version '7.4.1' apply false
4 4
     id 'com.android.library' version '7.4.1' apply false
5
-}
5
+}

+ 2 - 1
gradle.properties

@@ -18,4 +18,5 @@ android.useAndroidX=true
18 18
 # Enables namespacing of each library's R class so that its R class includes only the
19 19
 # resources declared in the library itself and none from the library's dependencies,
20 20
 # thereby reducing the size of the R class for that library
21
-android.nonTransitiveRClass=true
21
+android.nonTransitiveRClass=true
22
+android.enableJetifier = true