commit e950034c99758c9be9610184d9e3f9af01a04088 Author: Galaxy Date: Mon May 20 15:43:46 2024 +0800 test1 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..27212d6 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,46 @@ +plugins { + id("com.android.application") +} + +android { + namespace = "com.hnucm.drawerlayout" + compileSdk = 34 + + defaultConfig { + applicationId = "com.hnucm.drawerlayout" + minSdk = 24 + targetSdk = 34 + versionCode = 1 + versionName = "1.0" + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + isMinifyEnabled = false + proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") + } + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 + } +} + +dependencies { + + implementation("androidx.appcompat:appcompat:1.6.1") + implementation("com.google.android.material:material:1.9.0") + implementation("androidx.constraintlayout:constraintlayout:2.1.4") + testImplementation("junit:junit:4.13.2") + androidTestImplementation("androidx.test.ext:junit:1.1.5") + androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1") + + + implementation ("io.github.lucksiege:pictureselector:v3.11.2") + implementation ("io.github.lucksiege:compress:v3.11.2") + implementation ("io.github.lucksiege:ucrop:v3.11.2") + implementation ("io.github.lucksiege:camerax:v3.11.2") + implementation ("com.github.bumptech.glide:glide:4.15.1") +} \ No newline at end of file diff --git a/proguard-rules.pro b/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/src/androidTest/java/com/hnucm/drawerlayout/ExampleInstrumentedTest.java b/src/androidTest/java/com/hnucm/drawerlayout/ExampleInstrumentedTest.java new file mode 100644 index 0000000..f93e9fb --- /dev/null +++ b/src/androidTest/java/com/hnucm/drawerlayout/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.hnucm.drawerlayout; + +import android.content.Context; + +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + assertEquals("com.hnucm.drawerlayout", appContext.getPackageName()); + } +} \ No newline at end of file diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml new file mode 100644 index 0000000..649d5c5 --- /dev/null +++ b/src/main/AndroidManifest.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/assets/a1.mp3 b/src/main/assets/a1.mp3 new file mode 100644 index 0000000..5184e3d Binary files /dev/null and b/src/main/assets/a1.mp3 differ diff --git a/src/main/java/com/hnucm/drawerlayout/GlideEngine.java b/src/main/java/com/hnucm/drawerlayout/GlideEngine.java new file mode 100644 index 0000000..c72935f --- /dev/null +++ b/src/main/java/com/hnucm/drawerlayout/GlideEngine.java @@ -0,0 +1,116 @@ +package com.hnucm.drawerlayout; + + + + +import android.content.Context; +import android.widget.ImageView; + +import com.bumptech.glide.Glide; +import com.bumptech.glide.load.resource.bitmap.CenterCrop; +import com.bumptech.glide.load.resource.bitmap.RoundedCorners; +import com.luck.picture.lib.engine.ImageEngine; +import com.luck.picture.lib.utils.ActivityCompatHelper; + + +public class GlideEngine implements ImageEngine { + + /** + * 加载图片 + * + * @param context 上下文 + * @param url 资源url + * @param imageView 图片承载控件 + */ + @Override + public void loadImage(Context context, String url, ImageView imageView) { + if (!ActivityCompatHelper.assertValidRequest(context)) { + return; + } + Glide.with(context) + .load(url) + .into(imageView); + } + + @Override + public void loadImage(Context context, ImageView imageView, String url, int maxWidth, int maxHeight) { + if (!ActivityCompatHelper.assertValidRequest(context)) { + return; + } + Glide.with(context) + .load(url) + .override(maxWidth, maxHeight) + .into(imageView); + } + + /** + * 加载相册目录封面 + * + * @param context 上下文 + * @param url 图片路径 + * @param imageView 承载图片ImageView + */ + @Override + public void loadAlbumCover(Context context, String url, ImageView imageView) { + if (!ActivityCompatHelper.assertValidRequest(context)) { + return; + } + Glide.with(context) + .asBitmap() + .load(url) + .override(180, 180) + .sizeMultiplier(0.5f) + .transform(new CenterCrop(), new RoundedCorners(8)) + .placeholder(R.drawable.ic_launcher_background) + .into(imageView); + } + + + /** + * 加载图片列表图片 + * + * @param context 上下文 + * @param url 图片路径 + * @param imageView 承载图片ImageView + */ + @Override + public void loadGridImage(Context context, String url, ImageView imageView) { + if (!ActivityCompatHelper.assertValidRequest(context)) { + return; + } + Glide.with(context) + .load(url) + .override(200, 200) + .centerCrop() + .placeholder(R.drawable.ic_launcher_background) + .into(imageView); + } + + @Override + public void pauseRequests(Context context) { + if (!ActivityCompatHelper.assertValidRequest(context)) { + return; + } + Glide.with(context).pauseRequests(); + } + + @Override + public void resumeRequests(Context context) { + if (!ActivityCompatHelper.assertValidRequest(context)) { + return; + } + Glide.with(context).resumeRequests(); + } + + private GlideEngine() { + } + + private static final class InstanceHolder { + static final GlideEngine instance = new GlideEngine(); + } + + public static GlideEngine createGlideEngine() { + return InstanceHolder.instance; + } +} + diff --git a/src/main/java/com/hnucm/drawerlayout/MainActivity.java b/src/main/java/com/hnucm/drawerlayout/MainActivity.java new file mode 100644 index 0000000..e1c6e1c --- /dev/null +++ b/src/main/java/com/hnucm/drawerlayout/MainActivity.java @@ -0,0 +1,81 @@ +package com.hnucm.drawerlayout; + +import androidx.appcompat.app.AppCompatActivity; +import androidx.drawerlayout.widget.DrawerLayout; + +import android.media.MediaParser; +import android.media.MediaPlayer; +import android.net.Uri; +import android.os.Bundle; +import android.util.Log; +import android.view.Gravity; +import android.view.View; +import android.widget.ImageView; +import android.widget.VideoView; + +import com.bumptech.glide.Glide; +import com.luck.picture.lib.basic.PictureSelector; +import com.luck.picture.lib.config.SelectMimeType; +import com.luck.picture.lib.entity.LocalMedia; +import com.luck.picture.lib.interfaces.OnResultCallbackListener; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; + +public class MainActivity extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); +// MediaPlayer mediaPlayer = new MediaPlayer(); +// VideoView videoView = findViewById(R.id.videoView); + ImageView imageView = findViewById(R.id.imageView); + + findViewById(R.id.button).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + //播放音乐 +// try { +// mediaPlayer.setDataSource(getAssets().openFd("a1.mp3")); +// mediaPlayer.prepare(); +// mediaPlayer.start(); +// } catch (IOException e) { +// throw new RuntimeException(e); +// } +// videoView.setVideoURI(Uri.parse("android.resource://"+getPackageName()+"/raw/"+R.raw.a2)); +// videoView.start(); +// + PictureSelector.create(MainActivity.this) + .openGallery(SelectMimeType.ofImage()) + .setImageEngine(GlideEngine.createGlideEngine()) + .forResult(new OnResultCallbackListener() { + @Override + public void onResult(ArrayList result) { + Log.i("test",result.get(0).getRealPath()); + Glide.with(MainActivity.this) + .load(Uri.fromFile(new File(result.get(0).getRealPath()))) + .into( imageView); + } + + @Override + public void onCancel() { + + } + }); + } + }); + findViewById(R.id.button2).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { +// //暂停音乐 +// if (mediaPlayer.isPlaying()) { +// mediaPlayer.pause(); +// } +// videoView.pause(); + + } + }); + } +} \ No newline at end of file diff --git a/src/main/res/drawable/ic_launcher_background.xml b/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..07d5da9 --- /dev/null +++ b/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/res/drawable/ic_launcher_foreground.xml b/src/main/res/drawable/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/src/main/res/drawable/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/res/layout/activity_main.xml b/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..87271ef --- /dev/null +++ b/src/main/res/layout/activity_main.xml @@ -0,0 +1,70 @@ + + + + + + + +