V1.0.0(3)添加开屏页和图片拖拽功能
This commit is contained in:
parent
41f4fe510f
commit
132f7989a8
@ -15,7 +15,7 @@ android {
|
||||
targetSdk = 34
|
||||
versionCode = 1
|
||||
versionName = "1.0.0"
|
||||
setProperty("archivesBaseName", "AR Draw Sketch_V" + versionName + "(${versionCode})_$timestamp")
|
||||
setProperty("archivesBaseName", "AR Canvas Art_V" + versionName + "(${versionCode})_$timestamp")
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
|
||||
|
||||
@ -32,6 +32,9 @@
|
||||
android:exported="false" />
|
||||
<activity
|
||||
android:name=".activity.MainActivity"
|
||||
android:exported="false" />
|
||||
<activity
|
||||
android:name=".activity.SplashActivity"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
13
app/src/main/java/com/lock/arcanvasart/Utils/Tracing.java
Normal file
13
app/src/main/java/com/lock/arcanvasart/Utils/Tracing.java
Normal file
@ -0,0 +1,13 @@
|
||||
package com.lock.arcanvasart.Utils;
|
||||
|
||||
import android.view.MotionEvent;
|
||||
|
||||
public class Tracing {
|
||||
|
||||
public static float getDistance(MotionEvent event) {
|
||||
float dx = event.getX(1) - event.getX(0);
|
||||
float dy = event.getY(1) - event.getY(0);
|
||||
return (float) Math.sqrt(dx * dx + dy * dy);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,352 @@
|
||||
//package com.lock.arcanvasart.activity;
|
||||
//
|
||||
//import androidx.activity.result.ActivityResultLauncher;
|
||||
//import androidx.activity.result.contract.ActivityResultContracts;
|
||||
//import androidx.annotation.NonNull;
|
||||
//import androidx.appcompat.app.AppCompatActivity;
|
||||
//import androidx.camera.core.Camera;
|
||||
//import androidx.camera.core.CameraSelector;
|
||||
//import androidx.camera.core.ImageCapture;
|
||||
//import androidx.camera.core.Preview;
|
||||
//import androidx.camera.lifecycle.ProcessCameraProvider;
|
||||
//import androidx.camera.view.PreviewView;
|
||||
//import androidx.core.app.ActivityCompat;
|
||||
//import androidx.core.content.ContextCompat;
|
||||
//
|
||||
//import android.Manifest;
|
||||
//import android.app.Activity;
|
||||
//import android.content.Intent;
|
||||
//import android.content.pm.PackageManager;
|
||||
//import android.graphics.Bitmap;
|
||||
//import android.graphics.Matrix;
|
||||
//import android.graphics.Point;
|
||||
//import android.graphics.PointF;
|
||||
//import android.net.Uri;
|
||||
//import android.os.Build;
|
||||
//import android.os.Bundle;
|
||||
//import android.provider.MediaStore;
|
||||
//import android.util.Log;
|
||||
//import android.view.MotionEvent;
|
||||
//import android.view.View;
|
||||
//import android.widget.ImageView;
|
||||
//import android.widget.SeekBar;
|
||||
//import android.widget.Toast;
|
||||
//
|
||||
//import com.applovin.mediation.MaxAd;
|
||||
//import com.applovin.mediation.ads.MaxInterstitialAd;
|
||||
//import com.draw.painting.test.Adcallback;
|
||||
//import com.google.common.util.concurrent.ListenableFuture;
|
||||
//import com.draw.painting.test.PaintingApp;
|
||||
//import com.draw.painting.test.R;
|
||||
//import com.draw.painting.test.manager.Utils;
|
||||
//
|
||||
//import java.util.List;
|
||||
//
|
||||
//public class CameraActivity extends AppCompatActivity implements View.OnTouchListener, View.OnClickListener {
|
||||
// private CameraSelector cameraSelector;
|
||||
// private String[] permissions;
|
||||
// private int range;
|
||||
// private Camera camera;
|
||||
// private ImageCapture imageCapture;
|
||||
// private PreviewView previewView;
|
||||
// private ImageView imageView;
|
||||
// private SeekBar seekBar;
|
||||
//
|
||||
// private Double d;
|
||||
//
|
||||
//
|
||||
// private int MODE;//当前状态
|
||||
// public static final int MODE_NONE = 0;//无操作
|
||||
// public static final int MODE_DRAG = 1;//单指操作
|
||||
// public static final int MODE_SCALE = 2;//双指操作
|
||||
//
|
||||
// private Matrix startMatrix;
|
||||
// private Matrix endMatrix = new Matrix();//变化后的矩阵
|
||||
// private PointF startPointF = new PointF();//初始坐标
|
||||
// private float distance;//初始距离
|
||||
// private float scaleMultiple;//缩放倍数
|
||||
//
|
||||
// private ImageView flashIm, imZoom, imBack;
|
||||
// private ImageView imPhoto;
|
||||
//
|
||||
// private String curBitmapPath;
|
||||
// private boolean hasPermission = false;
|
||||
// private boolean isMain;
|
||||
// private String ismain;
|
||||
// private static List<MaxInterstitialAd> adsList;
|
||||
// private ActivityResultLauncher<Intent> intentActivityResultLauncher;
|
||||
//
|
||||
// @Override
|
||||
// protected void onCreate(Bundle savedInstanceState) {
|
||||
// super.onCreate(savedInstanceState);
|
||||
// setContentView(R.layout.activity_camera);
|
||||
// Utils.setStatusBarTextColor(this, true);
|
||||
//
|
||||
// adsList = Utils.getAllAd();
|
||||
// Intent intent = getIntent();
|
||||
// isMain = intent.getBooleanExtra(PaintingApp.Key_ISMAIN, false);
|
||||
//
|
||||
//
|
||||
// showAd();
|
||||
//
|
||||
//
|
||||
// previewView = findViewById(R.id.preview);
|
||||
// imageView = findViewById(R.id.image);
|
||||
// imBack = findViewById(R.id.back);
|
||||
//
|
||||
// seekBar = findViewById(R.id.seekbar);
|
||||
// flashIm = findViewById(R.id.im_flash);
|
||||
// imPhoto = findViewById(R.id.im_photo);
|
||||
// imZoom = findViewById(R.id.im_zoom);
|
||||
//
|
||||
// curBitmapPath = getIntent().getStringExtra(PaintingApp.Key_Camera);
|
||||
//
|
||||
// intentActivityResultLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> {
|
||||
// if (result.getResultCode() == Activity.RESULT_OK && result.getData() != null) {
|
||||
// Uri imageUri = result.getData().getData();
|
||||
//// Log.d("--------------tt","------bitmap-----width="+width+"-----height="+height);
|
||||
// imageView.setImageURI(imageUri);
|
||||
// }
|
||||
//
|
||||
// });
|
||||
//
|
||||
// init();
|
||||
// initClick();
|
||||
// }
|
||||
//
|
||||
// private void showAd() {
|
||||
// MaxInterstitialAd cachedAd = Utils.onCache(adsList);
|
||||
// if (cachedAd == null) {
|
||||
//
|
||||
// } else {
|
||||
// Utils.setCallBcak(cachedAd, new Adcallback() {
|
||||
// @Override
|
||||
// public void onShowFail(MaxAd ad) {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onAdHidden() {
|
||||
//
|
||||
// }
|
||||
// });
|
||||
// cachedAd.showAd(this);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private void onInitIm(float imW, float imH) {
|
||||
// Point screen = Utils.getScreen(this);
|
||||
// float newX = screen.x / 2f - imW / 2;
|
||||
// float newY = screen.y / 2f - imH / 2;
|
||||
// startMatrix = new Matrix();
|
||||
// startMatrix.postTranslate(newX, newY);
|
||||
// imageView.setImageMatrix(startMatrix);
|
||||
//
|
||||
// Log.d("---------------tt", "------startMatrix-----x=" + newX + "------y=" + newY);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean onTouch(View v, MotionEvent event) {
|
||||
// switch (event.getAction() & event.getActionMasked()) {
|
||||
// case MotionEvent.ACTION_DOWN:
|
||||
//
|
||||
// startMatrix.set(imageView.getImageMatrix());
|
||||
// endMatrix.set(imageView.getImageMatrix());
|
||||
//
|
||||
// startPointF.set(event.getX(), event.getY());
|
||||
//
|
||||
//
|
||||
// Log.d("---------------tt", "------ACTION_DOWN-----x=" + event.getX() + "------y=" + event.getY());
|
||||
//
|
||||
// MODE = MODE_DRAG;
|
||||
//
|
||||
// break;
|
||||
// case MotionEvent.ACTION_POINTER_DOWN:
|
||||
//
|
||||
// startMatrix.set(endMatrix);
|
||||
//
|
||||
// distance = Utils.getDistance(event);
|
||||
//
|
||||
// MODE = MODE_SCALE;
|
||||
//
|
||||
// break;
|
||||
// case MotionEvent.ACTION_MOVE://滑动(单+双)
|
||||
// if (MODE == MODE_DRAG) {//单指滑动时
|
||||
//
|
||||
// endMatrix.set(startMatrix);
|
||||
// //向矩阵传入位移距离
|
||||
// endMatrix.postTranslate(event.getX() - startPointF.x, event.getY() - startPointF.y);
|
||||
// Log.d("---------------tt", "------ACTION_MOVE-----x=" + event.getX() + "------y=" + event.getY());
|
||||
// } else if (MODE == MODE_SCALE) {//双指滑动时
|
||||
// //计算缩放倍数
|
||||
// scaleMultiple = Utils.getDistance(event) / distance;
|
||||
// //获取初始矩阵
|
||||
// endMatrix.set(startMatrix);
|
||||
// //向矩阵传入缩放倍数
|
||||
// endMatrix.postScale(scaleMultiple, scaleMultiple, startPointF.x, startPointF.y);
|
||||
// }
|
||||
// break;
|
||||
// case MotionEvent.ACTION_UP://单指离开
|
||||
// case MotionEvent.ACTION_POINTER_UP://双指离开
|
||||
// //手指离开后,重置状态
|
||||
// MODE = MODE_NONE;
|
||||
//
|
||||
// break;
|
||||
// }
|
||||
// //事件结束后,把矩阵的变化同步到ImageView上
|
||||
// imageView.setImageMatrix(endMatrix);
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onClick(View v) {
|
||||
// if (v.equals(imBack)) {
|
||||
//
|
||||
// if (isMain) {
|
||||
// showAd();
|
||||
// finish();
|
||||
// } else {
|
||||
// finish();
|
||||
// }
|
||||
//
|
||||
// } else {
|
||||
// if (!hasPermission) {
|
||||
// showNoPermission();
|
||||
// return;
|
||||
// }
|
||||
// if (v.equals(flashIm)) {
|
||||
// boolean selected = flashIm.isSelected();
|
||||
// flashIm.setSelected(!selected);
|
||||
// camera.getCameraControl().enableTorch(!selected);
|
||||
// } else if (v.equals(imPhoto)) {
|
||||
// Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
|
||||
// intentActivityResultLauncher.launch(intent);
|
||||
// } else if (v.equals(imZoom)) {
|
||||
// if (seekBar.getVisibility() == View.VISIBLE) {
|
||||
// seekBar.setVisibility(View.GONE);
|
||||
// } else if (seekBar.getVisibility() == View.GONE) {
|
||||
// seekBar.setVisibility(View.VISIBLE);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// private void initClick() {
|
||||
// imBack.setOnClickListener(this);
|
||||
// flashIm.setOnClickListener(this);
|
||||
// imPhoto.setOnClickListener(this);
|
||||
// imZoom.setOnClickListener(this);
|
||||
// seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
||||
// @Override
|
||||
// public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
// float v = (seekBar.getMax() - progress) / 10.0f;
|
||||
// imageView.setAlpha(v);
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onStartTrackingTouch(SeekBar seekBar) {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
//
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// private void init() {
|
||||
// cameraSelector = CameraSelector.DEFAULT_BACK_CAMERA;
|
||||
// permissions = new String[]{Manifest.permission.CAMERA};
|
||||
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
// permissions = new String[]{Manifest.permission.CAMERA, Manifest.permission.READ_MEDIA_IMAGES};
|
||||
// } else {
|
||||
// permissions = new String[]{Manifest.permission.CAMERA, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE};
|
||||
// }
|
||||
// if (!checkPermission()) {
|
||||
// hasPermission = false;
|
||||
// imageView.setOnTouchListener(null);
|
||||
// ActivityCompat.requestPermissions(this, permissions, 0);
|
||||
// } else {
|
||||
// hasPermission = true;
|
||||
// imageView.setOnTouchListener(this);
|
||||
// startCamera();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private void startCamera() {
|
||||
// ListenableFuture<ProcessCameraProvider> future = ProcessCameraProvider.getInstance(this);
|
||||
// future.addListener(() -> {
|
||||
// try {
|
||||
// ProcessCameraProvider cameraProvider = future.get();
|
||||
//
|
||||
// Preview preview = new Preview.Builder().build();
|
||||
// cameraProvider.unbindAll();
|
||||
// ImageCapture.Builder builder1 = new ImageCapture.Builder();
|
||||
// imageCapture = builder1.build();
|
||||
// camera = cameraProvider.bindToLifecycle(this, cameraSelector, preview, imageCapture);
|
||||
// range = Utils.getRange(camera);
|
||||
// preview.setSurfaceProvider(previewView.getSurfaceProvider());
|
||||
//
|
||||
// if (curBitmapPath != null) {
|
||||
// Bitmap bitmap = Utils.loadImageFromAssets(this, curBitmapPath);
|
||||
// imageView.setImageBitmap(bitmap);
|
||||
// int width = bitmap.getWidth();
|
||||
// int height = bitmap.getHeight();
|
||||
// onInitIm(width, height);
|
||||
//
|
||||
//
|
||||
// }
|
||||
//
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }, ContextCompat.getMainExecutor(this));
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||
// super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
// if (requestCode == 0) {
|
||||
// if (checkPermission()) {
|
||||
// hasPermission = true;
|
||||
// imageView.setOnTouchListener(this);
|
||||
// startCamera();
|
||||
// } else {
|
||||
// hasPermission = false;
|
||||
// imageView.setOnTouchListener(null);
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// private boolean checkPermission() {
|
||||
// boolean result = true;
|
||||
// for (String per : permissions) {
|
||||
// if (ActivityCompat.checkSelfPermission(this, per) != PackageManager.PERMISSION_GRANTED) {
|
||||
// result = false;
|
||||
// }
|
||||
// }
|
||||
// return result;
|
||||
//
|
||||
// }
|
||||
//
|
||||
// private void showNoPermission() {
|
||||
// Toast.makeText(this, getString(R.string.permission_fail), Toast.LENGTH_SHORT).show();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onBackPressed() {
|
||||
// super.onBackPressed();
|
||||
// if (isMain) {
|
||||
// showAd();
|
||||
// finish();
|
||||
// } else {
|
||||
// finish();
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
@ -2,18 +2,26 @@ package com.lock.arcanvasart.activity;
|
||||
|
||||
import android.Manifest;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.AssetManager;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.PointF;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.provider.MediaStore;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.Toast;
|
||||
|
||||
@ -32,13 +40,14 @@ import androidx.core.content.ContextCompat;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import com.lock.arcanvasart.R;
|
||||
import com.lock.arcanvasart.Utils.PermissionUtils;
|
||||
import com.lock.arcanvasart.Utils.Tracing;
|
||||
import com.lock.arcanvasart.databinding.ActivityCameraBinding;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
public class CameraActivity extends AppCompatActivity implements SeekBar.OnSeekBarChangeListener {
|
||||
public class CameraActivity extends AppCompatActivity implements View.OnTouchListener, SeekBar.OnSeekBarChangeListener {
|
||||
|
||||
// 请求码常量
|
||||
private static final int CAMERA_PERMISSION_REQUEST_CODE = 200; // 相机权限请求码
|
||||
@ -47,21 +56,36 @@ public class CameraActivity extends AppCompatActivity implements SeekBar.OnSeekB
|
||||
|
||||
private ActivityCameraBinding binding;
|
||||
|
||||
private Matrix matrix = new Matrix(); // 当前变换矩阵
|
||||
private Matrix savedMatrix = new Matrix(); // 保存的变换矩阵
|
||||
private PointF startPointF = new PointF(); // 触摸起始点
|
||||
private float initialDistance; // 初始触摸距离
|
||||
private int mode = MODE_NONE; // 当前模式
|
||||
private static final int MODE_NONE = 0; // 无模式
|
||||
private static final int MODE_DRAG = 1; // 拖动模式
|
||||
private static final int MODE_ZOOM = 2; // 缩放模式
|
||||
|
||||
private Bitmap bitmap;
|
||||
private boolean isFlashOn = false; // 闪光灯状态
|
||||
private boolean isReOn = false;
|
||||
private Camera camera; // 相机实例
|
||||
private ImageCapture imageCapture; // 拍照实例
|
||||
|
||||
private ImageView imageView;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
binding = ActivityCameraBinding.inflate(getLayoutInflater());
|
||||
setContentView(binding.getRoot());
|
||||
|
||||
imageView = findViewById(R.id.image_full);
|
||||
imageView.setOnTouchListener(this);
|
||||
|
||||
setupListeners(); // 设置监听器
|
||||
checkPermissionsAndStartCamera(); // 检查权限并启动相机
|
||||
|
||||
|
||||
// 接收传递的图片路径
|
||||
String imagePath = getIntent().getStringExtra("imagePath");
|
||||
Log.d("imagepath", "imagepath: " + imagePath);
|
||||
@ -77,8 +101,27 @@ public class CameraActivity extends AppCompatActivity implements SeekBar.OnSeekB
|
||||
binding.light.setOnClickListener(v -> toggleFlash()); // 闪光灯按钮监听
|
||||
binding.back.setOnClickListener(v -> finish());
|
||||
binding.reversal.setOnClickListener(v -> toggleMirrorEffect());
|
||||
binding.topRightImage.setOnClickListener(v -> clearImage());
|
||||
// binding.topRightImage.setOnClickListener(v -> clearImage());
|
||||
binding.play.setOnClickListener(v -> takePhoto());
|
||||
imageView.setOnTouchListener(this);
|
||||
}
|
||||
|
||||
private void checkPermissionsAndStartCamera() {
|
||||
String[] permissions = getRequiredPermissions();
|
||||
if (PermissionUtils.hasPermissions(this, permissions)) {
|
||||
startCamera();
|
||||
} else {
|
||||
PermissionUtils.requestPermissions(this, permissions, CAMERA_PERMISSION_REQUEST_CODE);
|
||||
}
|
||||
|
||||
// 请求存储权限(用于保存照片和视频)
|
||||
// String[] storagePermissions = new String[]{
|
||||
// Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
||||
// Manifest.permission.READ_EXTERNAL_STORAGE
|
||||
// };
|
||||
// if (!PermissionUtils.hasPermissions(this, storagePermissions)) {
|
||||
// ActivityCompat.requestPermissions(this, storagePermissions, STORAGE_PERMISSION_REQUEST_CODE);
|
||||
// }
|
||||
}
|
||||
|
||||
private void startCamera() {
|
||||
@ -109,6 +152,26 @@ public class CameraActivity extends AppCompatActivity implements SeekBar.OnSeekB
|
||||
}, ContextCompat.getMainExecutor(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
|
||||
// 处理权限请求结果
|
||||
if (requestCode == CAMERA_PERMISSION_REQUEST_CODE) {
|
||||
if (PermissionUtils.handlePermissionsResult(grantResults)) {
|
||||
startCamera();
|
||||
} else {
|
||||
Toast.makeText(this, "相机权限被拒绝,请在设置中启用权限", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
} else if (requestCode == STORAGE_PERMISSION_REQUEST_CODE) {
|
||||
if (PermissionUtils.handlePermissionsResult(grantResults)) {
|
||||
openImagePicker();
|
||||
} else {
|
||||
Toast.makeText(this, "存储权限被拒绝,请在设置中启用权限", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void takePhoto() {
|
||||
// 确保 imageCapture 实例已初始化
|
||||
if (imageCapture == null) {
|
||||
@ -148,57 +211,19 @@ public class CameraActivity extends AppCompatActivity implements SeekBar.OnSeekB
|
||||
}
|
||||
|
||||
private void clearImage() {
|
||||
binding.imageFull.setImageBitmap(null); // 清空当前显示的图片
|
||||
imageView.setImageBitmap(null); // 清空当前显示的图片
|
||||
// 清空图片后显示提示文字和图像
|
||||
showCenterTextAndImage(true);
|
||||
// showCenterTextAndImage(true);
|
||||
}
|
||||
|
||||
private void toggleMirrorEffect() {
|
||||
// 获取当前水平缩放值并反转
|
||||
float scaleX = binding.imageFull.getScaleX();
|
||||
binding.imageFull.setScaleX(scaleX * -1); // 将水平缩放翻转
|
||||
float scaleX =imageView.getScaleX();
|
||||
imageView.setScaleX(scaleX * -1); // 将水平缩放翻转
|
||||
isReOn = !isReOn;
|
||||
binding.reversal.setImageResource(isReOn ? R.drawable.reversal : R.drawable.un_reversal);
|
||||
}
|
||||
|
||||
private void checkPermissionsAndStartCamera() {
|
||||
String[] permissions = getRequiredPermissions();
|
||||
if (PermissionUtils.hasPermissions(this, permissions)) {
|
||||
startCamera();
|
||||
} else {
|
||||
PermissionUtils.requestPermissions(this, permissions, CAMERA_PERMISSION_REQUEST_CODE);
|
||||
}
|
||||
|
||||
// 请求存储权限(用于保存照片和视频)
|
||||
// String[] storagePermissions = new String[]{
|
||||
// Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
||||
// Manifest.permission.READ_EXTERNAL_STORAGE
|
||||
// };
|
||||
// if (!PermissionUtils.hasPermissions(this, storagePermissions)) {
|
||||
// ActivityCompat.requestPermissions(this, storagePermissions, STORAGE_PERMISSION_REQUEST_CODE);
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
|
||||
// 处理权限请求结果
|
||||
if (requestCode == CAMERA_PERMISSION_REQUEST_CODE) {
|
||||
if (PermissionUtils.handlePermissionsResult(grantResults)) {
|
||||
startCamera();
|
||||
} else {
|
||||
Toast.makeText(this, "相机权限被拒绝,请在设置中启用权限", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
} else if (requestCode == STORAGE_PERMISSION_REQUEST_CODE) {
|
||||
if (PermissionUtils.handlePermissionsResult(grantResults)) {
|
||||
openImagePicker();
|
||||
} else {
|
||||
Toast.makeText(this, "存储权限被拒绝,请在设置中启用权限", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String[] getRequiredPermissions() {
|
||||
// 根据 Android 版本获取所需权限
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
@ -230,7 +255,7 @@ public class CameraActivity extends AppCompatActivity implements SeekBar.OnSeekB
|
||||
startActivityForResult(intent, PICK_IMAGE_REQUEST_CODE);
|
||||
}
|
||||
|
||||
showCenterTextAndImage(false);
|
||||
// showCenterTextAndImage(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -240,7 +265,7 @@ public class CameraActivity extends AppCompatActivity implements SeekBar.OnSeekB
|
||||
if (requestCode == PICK_IMAGE_REQUEST_CODE && resultCode == RESULT_OK && data != null) {
|
||||
Uri selectedImageUri = data.getData(); // 获取选中的图片 URI
|
||||
if (selectedImageUri != null) {
|
||||
binding.imageFull.setImageURI(selectedImageUri); // 显示选中的图片
|
||||
imageView.setImageURI(selectedImageUri); // 显示选中的图片
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -255,12 +280,18 @@ public class CameraActivity extends AppCompatActivity implements SeekBar.OnSeekB
|
||||
cameraProvider.unbindAll(); // 解绑所有相机
|
||||
camera = cameraProvider.bindToLifecycle(this, cameraSelector, preview); // 绑定生命周期
|
||||
|
||||
if(bitmap!= null){
|
||||
int width = bitmap.getWidth();
|
||||
int height = bitmap.getHeight();
|
||||
onInitIm(width, height); // 初始化图片位置
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||
// 调整图片透明度
|
||||
binding.imageFull.setAlpha((100 - progress) / 100f); // 根据进度设置透明度
|
||||
imageView.setAlpha((100 - progress) / 100f); // 根据进度设置透明度
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -282,26 +313,26 @@ public class CameraActivity extends AppCompatActivity implements SeekBar.OnSeekB
|
||||
}
|
||||
|
||||
// 加载图片后检查是否有图片,并更新视图
|
||||
showCenterTextAndImage(false);
|
||||
// showCenterTextAndImage(false);
|
||||
}
|
||||
|
||||
private void showCenterTextAndImage(boolean show) {
|
||||
if (show) {
|
||||
// 显示中心提示文字和图片
|
||||
binding.centerText.setVisibility(View.VISIBLE);
|
||||
binding.centerImage.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
// 隐藏中心提示文字和图片
|
||||
binding.centerText.setVisibility(View.GONE);
|
||||
binding.centerImage.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
// private void showCenterTextAndImage(boolean show) {
|
||||
// if (show) {
|
||||
// // 显示中心提示文字和图片
|
||||
// binding.centerText.setVisibility(View.VISIBLE);
|
||||
// binding.centerImage.setVisibility(View.VISIBLE);
|
||||
// } else {
|
||||
// // 隐藏中心提示文字和图片
|
||||
// binding.centerText.setVisibility(View.GONE);
|
||||
// binding.centerImage.setVisibility(View.GONE);
|
||||
// }
|
||||
// }
|
||||
|
||||
// 从设备存储中加载图片
|
||||
private void displayImageFromStorage(String imagePath) {
|
||||
Bitmap bitmap = BitmapFactory.decodeFile(imagePath);
|
||||
if (bitmap != null) {
|
||||
binding.imageFull.setImageBitmap(bitmap);
|
||||
imageView.setImageBitmap(bitmap);
|
||||
} else {
|
||||
Toast.makeText(this, "加载图片失败", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
@ -317,11 +348,79 @@ public class CameraActivity extends AppCompatActivity implements SeekBar.OnSeekB
|
||||
// 将 InputStream 转换为 Bitmap
|
||||
bitmap = BitmapFactory.decodeStream(inputStream);
|
||||
// 显示 Bitmap
|
||||
binding.imageFull.setImageBitmap(bitmap);
|
||||
imageView.setImageBitmap(bitmap);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
Toast.makeText(this, "加载图片失败: " + e.getMessage(), Toast.LENGTH_SHORT).show(); // 显示错误信息
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
ImageView view = (ImageView) v;
|
||||
|
||||
Log.d("----","--------a="+event);
|
||||
switch (event.getActionMasked()) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
savedMatrix.set(matrix); // 保存当前矩阵
|
||||
startPointF.set(event.getX(), event.getY()); // 记录触摸起始点
|
||||
mode = MODE_DRAG; // 设置为拖动模式
|
||||
break;
|
||||
|
||||
case MotionEvent.ACTION_POINTER_DOWN:
|
||||
initialDistance = Tracing.getDistance(event); // 计算初始距离
|
||||
if (initialDistance > 10f) {
|
||||
savedMatrix.set(matrix); // 保存当前矩阵
|
||||
mode = MODE_ZOOM; // 设置为缩放模式
|
||||
}
|
||||
break;
|
||||
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
if (mode == MODE_DRAG) {
|
||||
matrix.set(savedMatrix); // 恢复保存的矩阵
|
||||
matrix.postTranslate(event.getX() - startPointF.x, event.getY() - startPointF.y); // 计算平移
|
||||
} else if (mode == MODE_ZOOM) {
|
||||
float newDistance = Tracing.getDistance(event); // 计算新的距离
|
||||
if (newDistance > 10f) {
|
||||
float scale = newDistance / initialDistance; // 计算缩放比例
|
||||
matrix.set(savedMatrix); // 恢复保存的矩阵
|
||||
matrix.postScale(scale, scale, view.getWidth() / 2f, view.getHeight() / 2f); // 应用缩放
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case MotionEvent.ACTION_UP:
|
||||
case MotionEvent.ACTION_POINTER_UP:
|
||||
mode = MODE_NONE; // 重置模式
|
||||
break;
|
||||
}
|
||||
|
||||
view.setImageMatrix(matrix); // 更新图片矩阵
|
||||
return true; // 处理触摸事件
|
||||
}
|
||||
|
||||
// 初始化图片的位置
|
||||
private void onInitIm(float imW, float imH) {
|
||||
Point screen = getScreen(); // 获取屏幕尺寸
|
||||
float newX = screen.x / 2f - imW / 2; // 计算图片水平居中位置
|
||||
float newY = screen.y / 2f - imH / 2; // 计算图片垂直居中位置
|
||||
matrix.postTranslate(newX, newY); // 设置图片初始位置
|
||||
imageView.setImageMatrix(matrix); // 应用矩阵
|
||||
|
||||
Log.d("---------------tt", "------startMatrix-----x=" + newX + "------y=" + newY);
|
||||
}
|
||||
|
||||
|
||||
public Point getScreen() {
|
||||
DisplayMetrics displayMetrics = new DisplayMetrics();
|
||||
WindowManager windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
|
||||
windowManager.getDefaultDisplay().getMetrics(displayMetrics);
|
||||
int width = displayMetrics.widthPixels;
|
||||
int height = displayMetrics.heightPixels;
|
||||
Point point = new Point();
|
||||
point.x = width;
|
||||
point.y = height;
|
||||
return point;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,54 @@
|
||||
package com.lock.arcanvasart.activity;
|
||||
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.CountDownTimer;
|
||||
import android.widget.ProgressBar;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.lock.arcanvasart.R;
|
||||
|
||||
|
||||
public class SplashActivity extends AppCompatActivity {
|
||||
|
||||
private static final int SPLASH_TIME_OUT = 1500;
|
||||
private ProgressBar progressBar;
|
||||
|
||||
private CountDownTimer countDownTimer;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_splash);
|
||||
|
||||
progressBar = findViewById(R.id.progress_bar);
|
||||
countDownTimer = new CountDownTimer(SPLASH_TIME_OUT, 100) {
|
||||
|
||||
@Override
|
||||
public void onTick(long millisUntilFinished) {
|
||||
|
||||
float v = 100 - (float) millisUntilFinished / SPLASH_TIME_OUT * 100;
|
||||
int v1 = (int) v;
|
||||
progressBar.setProgress(v1);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
progressBar.setProgress(100);
|
||||
Intent intent = new Intent(SplashActivity.this, MainActivity.class);
|
||||
startActivity(intent);
|
||||
finish();
|
||||
}
|
||||
};
|
||||
|
||||
countDownTimer.start();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
30
app/src/main/res/drawable/seek_bar_color2.xml
Normal file
30
app/src/main/res/drawable/seek_bar_color2.xml
Normal file
@ -0,0 +1,30 @@
|
||||
<!-- res/drawable/seekbar_progress_drawable.xml -->
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:id="@android:id/background">
|
||||
<shape>
|
||||
<corners android:radius="5dp" />
|
||||
<solid android:color="#D3D3D3" /> <!-- 背景颜色 -->
|
||||
</shape>
|
||||
</item>
|
||||
|
||||
<item android:id="@android:id/secondaryProgress">
|
||||
<clip>
|
||||
<shape>
|
||||
<corners android:radius="5dp" />
|
||||
<solid android:color="#FFD700" /> <!-- 次级进度颜色 -->
|
||||
</shape>
|
||||
</clip>
|
||||
</item>
|
||||
|
||||
<item android:id="@android:id/progress">
|
||||
<clip>
|
||||
<shape>
|
||||
<corners android:radius="5dp" />
|
||||
<gradient
|
||||
android:startColor="#4891FF"
|
||||
android:endColor="#6CE89E"
|
||||
android:angle="0" />
|
||||
</shape>
|
||||
</clip>
|
||||
</item>
|
||||
</layer-list>
|
||||
@ -18,6 +18,20 @@
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintVertical_bias="0.0" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<androidx.appcompat.widget.AppCompatImageView
|
||||
android:id="@+id/image_full"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:scaleType="matrix" />
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/back"
|
||||
android:layout_width="25dp"
|
||||
@ -56,51 +70,51 @@
|
||||
app:layout_constraintStart_toEndOf="@+id/time"
|
||||
app:layout_constraintTop_toTopOf="@+id/back" />
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center">
|
||||
<!-- <FrameLayout-->
|
||||
<!-- android:layout_width="match_parent"-->
|
||||
<!-- android:layout_height="match_parent"-->
|
||||
<!-- android:gravity="center">-->
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/transparent_rectangle"
|
||||
android:layout_width="200dp"
|
||||
android:layout_height="200dp"
|
||||
android:layout_gravity="center"
|
||||
android:background="#80FFFFFF">
|
||||
<!-- <FrameLayout-->
|
||||
<!-- android:id="@+id/transparent_rectangle"-->
|
||||
<!-- android:layout_width="200dp"-->
|
||||
<!-- android:layout_height="200dp"-->
|
||||
<!-- android:layout_gravity="center"-->
|
||||
<!-- android:background="#80FFFFFF">-->
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/image_full"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:scaleType="centerCrop" />
|
||||
<!-- <ImageView-->
|
||||
<!-- android:id="@+id/image_full1"-->
|
||||
<!-- android:layout_width="match_parent"-->
|
||||
<!-- android:layout_height="match_parent"-->
|
||||
<!-- android:scaleType="centerCrop" />-->
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/center_image"
|
||||
android:layout_width="50dp"
|
||||
android:layout_height="50dp"
|
||||
android:layout_gravity="center"
|
||||
android:src="@drawable/placeholder" />
|
||||
<!-- <ImageView-->
|
||||
<!-- android:id="@+id/center_image"-->
|
||||
<!-- android:layout_width="50dp"-->
|
||||
<!-- android:layout_height="50dp"-->
|
||||
<!-- android:layout_gravity="center"-->
|
||||
<!-- android:src="@drawable/placeholder" />-->
|
||||
|
||||
<TextView
|
||||
android:id="@+id/center_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginTop="45dp"
|
||||
android:text="Choose an image from your album"
|
||||
android:textSize="11sp" />
|
||||
<!-- <TextView-->
|
||||
<!-- android:id="@+id/center_text"-->
|
||||
<!-- android:layout_width="wrap_content"-->
|
||||
<!-- android:layout_height="wrap_content"-->
|
||||
<!-- android:layout_gravity="center"-->
|
||||
<!-- android:layout_marginTop="45dp"-->
|
||||
<!-- android:text="Choose an image from your album"-->
|
||||
<!-- android:textSize="11sp" />-->
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/top_right_image"
|
||||
android:layout_width="30dp"
|
||||
android:layout_height="30dp"
|
||||
android:layout_gravity="top|end"
|
||||
android:padding="5dp"
|
||||
android:src="@drawable/delete" />
|
||||
<!-- <ImageView-->
|
||||
<!-- android:id="@+id/top_right_image"-->
|
||||
<!-- android:layout_width="30dp"-->
|
||||
<!-- android:layout_height="30dp"-->
|
||||
<!-- android:layout_gravity="top|end"-->
|
||||
<!-- android:padding="5dp"-->
|
||||
<!-- android:src="@drawable/delete" />-->
|
||||
|
||||
</FrameLayout>
|
||||
<!-- </FrameLayout>-->
|
||||
|
||||
</FrameLayout>
|
||||
<!-- </FrameLayout>-->
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/seek_bar_background"
|
||||
@ -175,9 +189,9 @@
|
||||
android:id="@+id/play"
|
||||
android:layout_width="41dp"
|
||||
android:layout_height="41dp"
|
||||
android:background="@drawable/camera_background"
|
||||
android:padding="5dp"
|
||||
android:src="@drawable/un_camera"
|
||||
android:background="@drawable/camera_background"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
|
||||
45
app/src/main/res/layout/activity_splash.xml
Normal file
45
app/src/main/res/layout/activity_splash.xml
Normal file
@ -0,0 +1,45 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout 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:id="@+id/main"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@mipmap/init"
|
||||
tools:context=".activity.SplashActivity">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/splash_image"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@mipmap/splash_background"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/splash_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/splash_image" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/progress_bar"
|
||||
style="?android:attr/progressBarStyleHorizontal"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="5dp"
|
||||
android:layout_marginStart="53dp"
|
||||
android:layout_marginEnd="53dp"
|
||||
android:layout_marginBottom="80dp"
|
||||
android:progressDrawable="@drawable/seek_bar_color2"
|
||||
android:max="100"
|
||||
android:progress="0"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent" />
|
||||
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
BIN
app/src/main/res/mipmap-xxxhdpi/init.png
Normal file
BIN
app/src/main/res/mipmap-xxxhdpi/init.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.0 MiB |
BIN
app/src/main/res/mipmap-xxxhdpi/splash_background.png
Normal file
BIN
app/src/main/res/mipmap-xxxhdpi/splash_background.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 21 KiB |
Loading…
Reference in New Issue
Block a user