GlideEngine

This commit is contained in:
YGRXZYGR 2024-06-19 02:59:40 +08:00
parent 0121730a8a
commit 28cfbc35db
6 changed files with 478 additions and 7 deletions

View File

@ -45,4 +45,10 @@ dependencies {
implementation ("com.baidu.lbsyun:BaiduMapSDK_Location:9.3.7")
implementation ("com.guolindev.permissionx:permissionx:1.7.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")
}

View File

@ -1,7 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_MEDIA_STORAGE" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
<queries package="${applicationId}">
<intent>
<action android:name="android.media.action.IMAGE_CAPTURE">
</action>
</intent>
<intent>
<action android:name="android.media.action.ACTION_VIDEO_CAPTURE">
</action>
</intent>
</queries>
<uses-permission android:name="android.permission.INTERNET" />
<application

View File

@ -0,0 +1,113 @@
package com.hnucm.c202201020328;
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;
}
}

View File

@ -1,6 +1,12 @@
package com.hnucm.c202201020328;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
@ -8,17 +14,60 @@ import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
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.util.ArrayList;
public class RecordActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_record);
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
return insets;
TextView textView=findViewById(R.id.textView69);
ImageView imageView=findViewById(R.id.imageView31);
TextView textView1=findViewById(R.id.textView64);
TextView textView2=findViewById(R.id.textView65);
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
PictureSelector.create(RecordActivity.this)
.openGallery(SelectMimeType.ofImage())
.setImageEngine(GlideEngine.createGlideEngine())
.forResult(new OnResultCallbackListener<LocalMedia>() {
@Override
public void onResult(ArrayList<LocalMedia> result) {
Log.i("text",result.get(0).getRealPath());
Glide.with(RecordActivity.this)
.load(Uri.fromFile(new File(result.get(0).getRealPath())))
.into(imageView);
}
@Override
public void onCancel() {
}
});
}
});
textView1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
Toast.makeText(RecordActivity.this, "已取消", Toast.LENGTH_LONG).show();
}
});
textView2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
Toast.makeText(RecordActivity.this, "已发布", Toast.LENGTH_LONG).show();
}
});
}
}

View File

@ -7,4 +7,87 @@
android:layout_height="match_parent"
tools:context=".RecordActivity">
<TextView
android:id="@+id/textView64"
android:layout_width="60dp"
android:layout_height="40dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:text="取消"
android:textSize="22sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textView65"
android:layout_width="60dp"
android:layout_height="40dp"
android:layout_marginTop="16dp"
android:text="发布"
android:textSize="22sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textView66"
android:layout_width="328dp"
android:layout_height="101dp"
android:layout_marginStart="40dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="40dp"
android:text="记录下...."
android:textSize="22sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView64" />
<TextView
android:id="@+id/textView67"
android:layout_width="51dp"
android:layout_height="30dp"
android:layout_marginEnd="40dp"
android:text="0/300"
android:textColor="#A39D9D"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView66" />
<TextView
android:id="@+id/textView68"
android:layout_width="330dp"
android:layout_height="2dp"
android:layout_marginStart="45dp"
android:layout_marginEnd="48dp"
android:background="#BBBBBB"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.416"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView67" />
<TextView
android:id="@+id/textView69"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginStart="40dp"
android:layout_marginTop="36dp"
android:gravity="center"
android:text="+"
android:textStyle="bold"
android:textSize="70sp"
android:background="#E2E0E0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView68" />
<ImageView
android:id="@+id/imageView31"
android:layout_width="100dp"
android:layout_height="100dp"
app:layout_constraintStart_toEndOf="@+id/textView69"
app:layout_constraintTop_toTopOf="@+id/textView69"
tools:srcCompat="@tools:sample/avatars" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -506,12 +506,13 @@
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="500dp"
android:layout_height="580dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView49">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/constraintLayout13"
android:layout_width="match_parent"
android:layout_height="50dp"
app:layout_constraintEnd_toEndOf="parent"
@ -630,9 +631,10 @@
android:id="@+id/textView53"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginStart="25dp"
android:layout_marginStart="27dp"
android:layout_marginTop="8dp"
android:background="#EB6E6E"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/imageView23"
app:layout_constraintTop_toTopOf="@+id/imageView23" />
@ -671,6 +673,197 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textView56"
android:layout_width="60dp"
android:layout_height="20dp"
android:layout_marginTop="24dp"
android:text="TextView"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/constraintLayout13" />
<ImageView
android:id="@+id/imageView27"
android:layout_width="18dp"
android:layout_height="18dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView56"
tools:srcCompat="@tools:sample/avatars" />
<TextView
android:id="@+id/textView57"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginStart="27dp"
android:layout_marginTop="16dp"
android:background="#EB6E6E"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/imageView27"
app:layout_constraintTop_toBottomOf="@+id/textView56" />
<TextView
android:id="@+id/textView58"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_marginTop="24dp"
android:text="TextView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView57" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/constraintLayout7"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="75dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView58">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/constraintLayout15"
android:layout_width="0dp"
android:layout_height="49dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/constraintLayout14"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="@+id/textView59"
android:layout_width="50dp"
android:layout_height="30dp"
android:layout_marginEnd="17dp"
android:layout_marginBottom="10dp"
android:text="分享"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<ImageView
android:id="@+id/imageView29"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_marginEnd="80dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:srcCompat="@tools:sample/avatars" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/constraintLayout14"
android:layout_width="0dp"
android:layout_height="49dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/constraintLayout16"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/constraintLayout15"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="@+id/textView60"
android:layout_width="50dp"
android:layout_height="30dp"
android:layout_marginEnd="17dp"
android:layout_marginBottom="10dp"
android:text="分享"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<ImageView
android:id="@+id/imageView30"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_marginEnd="80dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:srcCompat="@tools:sample/avatars" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/constraintLayout16"
android:layout_width="0dp"
android:layout_height="49dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/constraintLayout14"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="@+id/textView61"
android:layout_width="50dp"
android:layout_height="30dp"
android:layout_marginEnd="17dp"
android:layout_marginBottom="10dp"
android:text="分享"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<ImageView
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_marginEnd="80dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:srcCompat="@tools:sample/avatars" />
</androidx.constraintlayout.widget.ConstraintLayout>
<TextView
android:id="@+id/textView62"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="@drawable/dotted_line"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<ImageView
android:id="@+id/imageView28"
android:layout_width="72dp"
android:layout_height="72dp"
android:layout_marginStart="24dp"
android:layout_marginTop="1dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView58"
tools:srcCompat="@tools:sample/avatars" />
<ImageView
android:id="@+id/imageView32"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginStart="16dp"
android:layout_marginTop="11dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/constraintLayout7"
tools:srcCompat="@tools:sample/avatars" />
<TextView
android:id="@+id/textView63"
android:layout_width="80dp"
android:layout_height="20dp"
android:layout_marginStart="9dp"
android:layout_marginTop="5dp"
android:text="仅自己可见"
android:textColor="#797676"
app:layout_constraintStart_toEndOf="@+id/imageView32"
app:layout_constraintTop_toTopOf="@+id/imageView32" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>