10.30 alpha

yuying
王宇洋 3 years ago
parent 5eb4fb9813
commit e877ec29cc

@ -2,6 +2,7 @@
plugins {
id 'com.android.application'
}
android {
@ -59,6 +60,7 @@ dependencies {
implementation 'org.tensorflow:tensorflow-lite-metadata:0.1.0'
implementation 'org.tensorflow:tensorflow-lite-gpu:2.3.0'
implementation project(path: ':stinger_game')
implementation project(path: ':photo_editor')
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

@ -37,14 +37,14 @@ public class PhotoLib {
}
public static String saveImageToGallery(Context context, Bitmap bmp) {
// 首先保存图片
File appDir = new File(Environment.getExternalStorageDirectory(), "Colorize");
File appDir = context.getFilesDir();
if (!appDir.exists()) {
appDir.mkdir();
}
String fileName = System.currentTimeMillis() + ".jpg";
File file = new File(appDir, fileName);
try {
FileOutputStream fos = new FileOutputStream(file);
FileOutputStream fos = context.openFileOutput(fileName, Context.MODE_PRIVATE);
bmp.compress(Bitmap.CompressFormat.JPEG, 100, fos);
fos.flush();
fos.close();

@ -8,11 +8,11 @@ import androidx.annotation.NonNull;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import cn.leancloud.LCObject;
import cn.leancloud.LCUser;
import io.reactivex.disposables.Disposable;
/**
@ -20,45 +20,57 @@ import io.reactivex.disposables.Disposable;
* @date 2021-09-22 13:52:43
*/
public class Util {
public static List<String> getFilesAllName(String path) {
File file=new File(path);
File[] files=file.listFiles();
if (files == null){
Log.e("error","空目录");
public static List<String> getFilesAllName(File path) {
File file = path;
File[] files = file.listFiles();
if (files == null) {
Log.e("error", "空目录");
return new ArrayList<>();
}
List<String> s = new ArrayList<>();
for(int i =0;i<files.length;i++){
s.add(files[i].getAbsolutePath());
for (int i = 0; i < files.length; i++) {
System.out.println(files[i].toString());
if (files[i].toString().contains("jpg"))
s.add(files[i].getAbsolutePath());
}
Collections.reverse(s);
return s;
}
public static void updateUser(){
public static void updateUser() {
LCUser currentUser = LCUser.getCurrentUser();
currentUser.fetchInBackground().subscribe(new io.reactivex.Observer<LCObject>() {
public void onSubscribe(Disposable disposable) {}
public void onSubscribe(Disposable disposable) {
}
public void onNext(LCObject user) {
}
public void onError(Throwable throwable) {}
public void onComplete() {}
public void onError(Throwable throwable) {
}
public void onComplete() {
}
});
}
public static Integer getRemaining(){
public static Integer getRemaining() {
LCUser currentUser = LCUser.getCurrentUser();
return currentUser.getInt("RemainingCount");
}
public static void UpdateCountOnProcess(){
public static void UpdateCountOnProcess() {
LCUser currentUser = LCUser.getCurrentUser();
Log.d("UpdateCountOnProcess", currentUser.getUsername());
Log.d("UpdateCountOnProcess", String.valueOf(currentUser.getInt("RemainingCount")));
currentUser.fetchInBackground().subscribe(new io.reactivex.Observer<LCObject>() {
public void onSubscribe(Disposable disposable) {}
public void onSubscribe(Disposable disposable) {
}
public void onNext(LCObject user) {
minusRemainingBy1((LCUser)user);
addCountBy1((LCUser)user);
minusRemainingBy1((LCUser) user);
addCountBy1((LCUser) user);
user.saveInBackground().subscribe(new io.reactivex.Observer<LCObject>() {
@Override
public void onSubscribe(@NonNull Disposable d) {
@ -84,22 +96,27 @@ public class Util {
}
public void onError(Throwable throwable) {}
public void onComplete() {}
public void onError(Throwable throwable) {
}
public void onComplete() {
}
});
}
public static void minusRemainingBy1(LCUser currentUser){
public static void minusRemainingBy1(LCUser currentUser) {
currentUser.put("RemainingCount", currentUser.getInt("RemainingCount") - 1);
}
public static void addCountBy1(LCUser currentUser){
public static void addCountBy1(LCUser currentUser) {
currentUser.put("ProcessedCount", currentUser.getInt("ProcessedCount") + 1);
}
public static String getUUID(Context context) {
String android_id = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
Log.d("ID:", android_id);
@ -108,7 +125,4 @@ public class Util {
}
}

@ -21,11 +21,12 @@ import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.navigation.ui.AppBarConfiguration;
import com.echo.colorizeit.Util;
import com.echo.stinger_game.myganme.GameActivity;
import com.echo.colorizeit.ui.BaseActivity;
import com.echo.colorizeit.ImageUtil.PhotoLib;
import com.echo.colorizeit.Interfaces.RequestsListener;
import com.echo.colorizeit.Util;
import com.echo.colorizeit.ui.BaseActivity;
import com.echo.photo_editor.photo_editor_view.PhotoEditorView;
import com.echo.stinger_game.myganme.GameActivity;
import com.example.myapplication.R;
import com.example.myapplication.databinding.ImageColorizeUploadActivityBinding;
@ -153,7 +154,14 @@ public class ImageUploadViewActivity extends BaseActivity {
binding.ShareButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String data = MediaStore.Images.Media.insertImage(getContentResolver(), model.getColorizedImageBitmap(), "Colorized Image", ":)");
String data = MediaStore.Images.Media.insertImage(getContentResolver(), model.getColorizedImageBitmap(), String.valueOf(System.currentTimeMillis()), ":)");
while (data== null){
try {
Thread.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
ColorizedImageUri = Uri.parse(data);
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
@ -192,6 +200,18 @@ public class ImageUploadViewActivity extends BaseActivity {
}
});
binding.ContinueEditingButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
System.out.println("ContinueEditingButton");
String data = PhotoLib.saveImageToGallery(getApplicationContext(), model.getColorizedImageBitmap());
Intent intent = new Intent(_this, PhotoEditorView.class);
intent.putExtra("sourceFilePath", data);
startActivity(intent);
}
});
setContentView(binding.getRoot());
}
@ -213,6 +233,7 @@ public class ImageUploadViewActivity extends BaseActivity {
binding.ShareButton.setEnabled(true);
binding.SaveImageButton.setEnabled(true);
binding.CompareButton.setEnabled(true);
binding.ContinueEditingButton.setEnabled(true);
binding.uploadFinishAnimationView.playAnimation();
Animation animation_fade_out = AnimationUtils.loadAnimation(_this, R.anim.fade_out);
Animation animation_fade_out1 = AnimationUtils.loadAnimation(_this, R.anim.fade_out);

@ -77,8 +77,8 @@ public class GalleryFragment extends BaseFragment {
}
private List<String> getImagePathList(){
List<String> data = new ArrayList<>();
File skRoot = Environment.getExternalStorageDirectory();
data = Util.getFilesAllName(skRoot.getPath()+"/Colorize");
data = Util.getFilesAllName(this.getContext().getFilesDir());
System.out.println(this.getContext().getFilesDir());
return data;
}
private List<rcImage> getRcImageList(){

@ -21,6 +21,7 @@
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.airbnb.lottie.LottieAnimationView
android:id="@+id/meachine_view_anim"
android:layout_width="200dp"
@ -45,8 +46,8 @@
android:layout_marginEnd="24dp"
android:layout_marginBottom="32dp"
android:gravity="center"
android:scaleType="fitCenter"
android:paddingTop="20dp"
android:scaleType="fitCenter"
android:visibility="invisible"
app:layout_constraintBottom_toTopOf="@+id/ShareButton"
app:layout_constraintEnd_toEndOf="parent"
@ -97,9 +98,8 @@
<com.karacce.buttom.Buttom
android:id="@+id/SaveImageButton"
android:layout_width="0dp"
android:layout_width="170dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="32dp"
android:enabled="false"
@ -112,7 +112,24 @@
app:buttom_gradient_type="linear"
app:buttom_type="gradient"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<com.karacce.buttom.Buttom
android:id="@+id/ContinueEditingButton"
android:layout_width="170dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginBottom="32dp"
android:enabled="false"
android:text="Continue Editing"
android:textColor="@color/white"
app:buttom_corner_radius="30dp"
app:buttom_gradient_end_color="#3F51B5"
app:buttom_gradient_orientation="left_right"
app:buttom_gradient_start_color="#00BCD4"
app:buttom_gradient_type="linear"
app:buttom_type="gradient"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<ImageView

@ -1,12 +1,13 @@
plugins {
id 'com.android.application'
// id 'com.android.application'
id 'com.android.library'
}
android {
compileSdk 30
defaultConfig {
applicationId "com.echo.photo_editor"
// applicationId "com.echo.photo_editor"
minSdk 21
targetSdk 30
versionCode 1

@ -17,20 +17,23 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Photo_editor">
android:theme="@style/Theme.Photo_editor"
android:requestLegacyExternalStorage="true">
<activity
android:name=".photo_editor_view.PhotoEditorView"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar">
android:exported="true">
</activity>
<activity
android:name=".MainActivity"
android:screenOrientation="portrait"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<!-- <intent-filter>-->
<!-- <action android:name="android.intent.action.MAIN" />-->
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<!-- <category android:name="android.intent.category.LAUNCHER" />-->
<!-- </intent-filter>-->
</activity>
</application>

@ -31,10 +31,10 @@ public class MainActivity extends AppCompatActivity {
super.onCreate(savedInstanceState);
binding = ActivityMainBinding.inflate(getLayoutInflater());
//-----------------------------TEST Image-------------------------------
sourceFilePath = "/storage/emulated/0/Pictures/Colorized Image (26).jpg";
Intent intent = new Intent(_this, PhotoEditorView.class);
intent.putExtra("sourceFilePath", sourceFilePath);
startActivity(intent);
// sourceFilePath = "/storage/emulated/0/Pictures/Colorized Image (26).jpg";
// Intent intent = new Intent(_this, PhotoEditorView.class);
// intent.putExtra("sourceFilePath", sourceFilePath);
// startActivity(intent);
binding.chooseImageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

@ -6,6 +6,7 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@ -24,6 +25,8 @@ import com.echo.photo_editor.photo_editor_view.model.EditableImage;
import com.echo.photo_editor.photo_editor_view.model.StyleTool;
import com.echo.photo_editor.photo_editor_view.model.Tool;
import com.echo.photo_editor.photo_editor_view.model.Toolbox;
import com.echo.photo_editor.util.PhotoLib;
import com.google.android.material.snackbar.Snackbar;
import java.util.ArrayList;
@ -84,6 +87,14 @@ public class PhotoEditorView extends AppCompatActivity {
model.getEditableImage().getValue().undo();
}
});
binding.SaveButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
PhotoLib.saveImageToGallery(_this,model.getEditableImage().getValue().getCurrent_bitmap());
showSnackbar("Image saved !");
}
});
ArrayList<Toolbox> toolboxes = new ArrayList<>();
@ -150,6 +161,21 @@ public class PhotoEditorView extends AppCompatActivity {
}
protected void showSnackbar(@NonNull String message) {
runOnUiThread(new Runnable() {
@Override
public void run() {
View view = _this.findViewById(android.R.id.content);
if (view != null) {
Snackbar.make(view, message, Snackbar.LENGTH_SHORT).show();
} else {
Toast.makeText(_this, message, Toast.LENGTH_SHORT).show();
}
}
});
}
public void showLoading(@NonNull String message) {
runOnUiThread(new Runnable() {
@Override

@ -0,0 +1,85 @@
package com.echo.photo_editor.util;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.provider.MediaStore;
import android.util.Base64;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
/**
* @author Wang Yuyang
* @date 2021-09-22 13:52:43
*/
public class PhotoLib {
public static byte[] BitmapToBytes(Bitmap img) {
int bytes = img.getByteCount();
ByteBuffer buf = ByteBuffer.allocate(bytes);
img.copyPixelsToBuffer(buf);
byte[] byteArray = buf.array();
return byteArray;
}
public static Bitmap BytesToBitmap(byte[] bytes) {
Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
return bitmap;
}
public static Bitmap Base64ToBitmap(String data) {
byte[] decodedString = Base64.decode(data, Base64.DEFAULT);
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
return decodedByte;
}
public static String saveImageToGallery(Context context, Bitmap bmp) {
// 首先保存图片
File appDir = context.getFilesDir();
if (!appDir.exists()) {
appDir.mkdir();
}
String fileName = System.currentTimeMillis() + ".jpg";
File file = new File(appDir, fileName);
try {
FileOutputStream fos = context.openFileOutput(fileName, Context.MODE_PRIVATE);
bmp.compress(Bitmap.CompressFormat.JPEG, 100, fos);
fos.flush();
fos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
// 其次把文件插入到系统图库
try {
MediaStore.Images.Media.insertImage(context.getContentResolver(),
file.getAbsolutePath(), fileName, null);
} catch (FileNotFoundException e) {
e.printStackTrace();
String data = MediaStore.Images.Media.insertImage(context.getContentResolver(), bmp, "Colorized Image", ":)");
return data;
}
// 最后通知图库更新
// context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + path)));
return file.getAbsolutePath();
}
public static String getRandomFileName() {
return System.currentTimeMillis() + ".jpg";
}
public static Bitmap rotateImage(Bitmap source, float angle) {
Matrix matrix = new Matrix();
matrix.postRotate(angle);
return Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(),
matrix, true);
}
}
Loading…
Cancel
Save