diff --git a/.idea/misc.xml b/.idea/misc.xml index c7b3ed1..223be44 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -43,7 +43,7 @@ - + diff --git a/app/build.gradle b/app/build.gradle index e970979..8c2e98e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -23,8 +23,8 @@ android { applicationId "com.ansdoship.pixelarteditor" minSdkVersion 16 targetSdkVersion 30 - versionCode 3 - versionName "0.0.3.2-beta" + versionCode 14 + versionName "0.0.3.4-beta" vectorDrawables { useSupportLibrary = true } @@ -48,7 +48,7 @@ dependencies { implementation 'androidx.preference:preference:1.1.1' implementation 'androidx.cardview:cardview:1.0.0' implementation 'com.github.Tianscar:AndroidUtils:1.0.3' - implementation 'com.github.Tianscar:SimpleBitmap:1.0.1c' + implementation 'com.github.Tianscar:SimpleBitmap:1.0.2' implementation 'org.apache.commons.io:commonsIO:2.5.0' implementation project(path: ':colorpicker') implementation 'io.noties.markwon:core:4.6.2' diff --git a/app/src/main/java/com/ansdoship/pixelarteditor/MainActivity.java b/app/src/main/java/com/ansdoship/pixelarteditor/MainActivity.java index cc2c738..91ddb46 100644 --- a/app/src/main/java/com/ansdoship/pixelarteditor/MainActivity.java +++ b/app/src/main/java/com/ansdoship/pixelarteditor/MainActivity.java @@ -103,6 +103,7 @@ import com.tianscar.androidutils.ActivityUtils; import com.tianscar.androidutils.ApplicationUtils; import com.tianscar.androidutils.ColorFactory; +import com.tianscar.androidutils.EnvironmentUtils; import com.tianscar.androidutils.MathUtils; import com.tianscar.androidutils.ScreenUtils; import com.tianscar.simplebitmap.BitmapDecoder; @@ -363,7 +364,7 @@ public static String IMAGE_NAME_DEFAULT() { public final static int IMAGE_QUALITY_MIN = 30; public final static int IMAGE_QUALITY_DEFAULT = IMAGE_QUALITY_MAX; public static String IMAGE_PATH_DEFAULT() { - return Utils.getFilesPath("images"); + return EnvironmentUtils.getAvailableFilesDirPath("images"); } public final static int IMAGE_SCALE_DEFAULT = 16; public final static int IMAGE_SCALE_MIN = 1; @@ -730,7 +731,7 @@ public static List getExternalPaletteNames() { } public static String getPalettesPath() { - return Utils.getFilesPath("palettes"); + return EnvironmentUtils.getAvailableFilesDirPath("palettes"); } @NonNull @@ -748,12 +749,9 @@ public static String getCacheBitmapName() { return "CACHE.png"; } - @Nullable + @NonNull public static String getCacheBitmapPathname() { - String cachePath = Utils.getCachePath(); - if (cachePath == null) { - return null; - } + String cachePath = EnvironmentUtils.getInternalCacheDirPath(); return cachePath + "/" + getCacheBitmapName(); } @@ -762,12 +760,9 @@ public static String getCurrentBitmapName() { return "CURRENT.png"; } - @Nullable + @NonNull public static String getCurrentBitmapPathname() { - String cachePath = Utils.getCachePath(); - if (cachePath == null) { - return null; - } + String cachePath = EnvironmentUtils.getInternalCacheDirPath(); return cachePath + "/" + getCurrentBitmapName(); } @@ -816,6 +811,7 @@ private void setBitmap(@NonNull Bitmap bitmap) { private CheckedImageView imgFill; private CheckedImageView imgSelection; private CheckedImageView imgColorize; + private CheckedImageView imgZoom; // PaletteBar private ImageButton imgPalette; private PaletteList listPalettes; @@ -3224,6 +3220,7 @@ protected void onCreate(Bundle savedInstanceState) { imgFill = findViewById(R.id.img_fill); imgSelection = findViewById(R.id.img_selection); imgColorize = findViewById(R.id.img_colorize); + imgZoom = findViewById(R.id.img_zoom); tvPaintWidth.setOnClickListener(this); // PaletteBar imgPalette = findViewById(R.id.img_palette); @@ -3352,6 +3349,7 @@ public boolean onTouch(View view, MotionEvent event) { pointer0Changed = true; break; case MotionEvent.ACTION_POINTER_DOWN: + scaleModeTouchDistRecord = spacing(event); if (event.getPointerCount() == 2) { pointer0Changed = true; } @@ -3361,7 +3359,9 @@ public boolean onTouch(View view, MotionEvent event) { pointer0Changed = true; } if (event.getPointerCount() <= 2) { - scaleMode = false; + if (toolFlag != ToolFlag.ZOOM) { + scaleMode = false; + } } break; case MotionEvent.ACTION_MOVE: @@ -3477,6 +3477,7 @@ public boolean onTouch(View view, MotionEvent event) { downY = oldDownY; moveX = oldMoveX; moveY = oldMoveY; + flushSelectionSizeView(selectionBitmapDstWidth, selectionBitmapDstHeight); break; } } @@ -3489,7 +3490,7 @@ public boolean onTouch(View view, MotionEvent event) { switch (toolFlag) { case ToolFlag.PAINT: case ToolFlag.ERASER: - int cX = (lastMoveX+moveX)/2, cY = (lastMoveY+moveY)/2; + int cX = (lastMoveX + moveX) / 2, cY = (lastMoveY + moveY) / 2; path.quadTo(lastMoveX + 0.5f * paintWidth, lastMoveY + 0.5f * paintWidth,cX + 0.5f * paintWidth, cY + 0.5f * paintWidth); lastMoveX = moveX; lastMoveY = moveY; @@ -3775,11 +3776,19 @@ public void onCheckedChanged(CheckedImageGroup group, int checkedId, int checked toolFlag = ToolFlag.COLORIZE; imgColorize.setColorFilter(ContextCompat.getColor(MainActivity.this, R.color.colorTheme)); break; + case R.id.img_zoom: + toolFlag = ToolFlag.ZOOM; + scaleMode = true; + imgZoom.setColorFilter(ContextCompat.getColor(MainActivity.this, R.color.colorTheme)); + break; } if (toolFlag != ToolFlag.SELECTION) { selected = false; selectionFlag = ToolFlag.SelectionFlag.NONE; } + if (toolFlag != ToolFlag.ZOOM) { + scaleMode = false; + } canvasView.invalidate(); } }); @@ -3809,6 +3818,10 @@ public void onCheckedChanged(CheckedImageGroup group, int checkedId, int checked groupTools.check(R.id.img_colorize); imgColorize.setColorFilter(ContextCompat.getColor(MainActivity.this, R.color.colorTheme)); break; + case ToolFlag.ZOOM: + groupTools.check(R.id.img_zoom); + imgZoom.setColorFilter(ContextCompat.getColor(MainActivity.this, R.color.colorTheme)); + break; } // Double tap groupTools.setOnDoubleTapListener(new CheckedImageGroup.OnDoubleTapListener() { diff --git a/app/src/main/java/com/ansdoship/pixelarteditor/editor/ToolFlag.java b/app/src/main/java/com/ansdoship/pixelarteditor/editor/ToolFlag.java index e540702..be79a1f 100644 --- a/app/src/main/java/com/ansdoship/pixelarteditor/editor/ToolFlag.java +++ b/app/src/main/java/com/ansdoship/pixelarteditor/editor/ToolFlag.java @@ -31,6 +31,8 @@ public final class ToolFlag { public final static int COLORIZE = 5; + public final static int ZOOM = 6; + public static final class ShapeFlag { public final static int LINE = 0; diff --git a/app/src/main/java/com/ansdoship/pixelarteditor/util/CrashHandler.java b/app/src/main/java/com/ansdoship/pixelarteditor/util/CrashHandler.java index 2a33507..10357b7 100644 --- a/app/src/main/java/com/ansdoship/pixelarteditor/util/CrashHandler.java +++ b/app/src/main/java/com/ansdoship/pixelarteditor/util/CrashHandler.java @@ -30,6 +30,7 @@ import com.ansdoship.pixelarteditor.R; import com.tianscar.androidutils.ApplicationUtils; +import com.tianscar.androidutils.EnvironmentUtils; import org.apache.commons.io.FileUtils; @@ -159,7 +160,7 @@ private String saveCrashInfoToFile(@NonNull Throwable exception) { @Nullable public static String getCrashDir() { - return Utils.getFilesPath("crashes"); + return EnvironmentUtils.getAvailableFilesDirPath("crashes"); } } \ No newline at end of file diff --git a/app/src/main/java/com/ansdoship/pixelarteditor/util/Utils.java b/app/src/main/java/com/ansdoship/pixelarteditor/util/Utils.java index 43f7e82..3ce555c 100644 --- a/app/src/main/java/com/ansdoship/pixelarteditor/util/Utils.java +++ b/app/src/main/java/com/ansdoship/pixelarteditor/util/Utils.java @@ -18,11 +18,7 @@ package com.ansdoship.pixelarteditor.util; import android.content.Context; -import android.os.Build; -import android.os.Environment; -import android.view.MotionEvent; import android.view.View; -import android.view.inputmethod.InputMethodManager; import android.widget.TextView; import android.widget.Toast; @@ -30,12 +26,9 @@ import androidx.annotation.Nullable; import androidx.annotation.StringRes; import androidx.appcompat.app.AlertDialog; -import androidx.core.os.EnvironmentCompat; import com.ansdoship.pixelarteditor.R; -import com.tianscar.androidutils.ApplicationUtils; -import java.io.File; import java.lang.reflect.Field; public final class Utils { @@ -45,9 +38,11 @@ public final class Utils { Field mAlert = AlertDialog.class.getDeclaredField("mAlert"); mAlert.setAccessible(true); Object mAlertController = mAlert.get(dialog); - Field mMessage = mAlertController.getClass().getDeclaredField("mMessageView"); - mMessage.setAccessible(true); - return (TextView) mMessage.get(mAlertController); + if (mAlertController != null) { + Field mMessage = mAlertController.getClass().getDeclaredField("mMessageView"); + mMessage.setAccessible(true); + return (TextView) mMessage.get(mAlertController); + } } catch (IllegalAccessException e) { e.printStackTrace(); @@ -88,63 +83,4 @@ public static void showToast(@NonNull Context context, CharSequence text, int du toast.show(); } - @Nullable - public static String getCachePath () { - Context context = ApplicationUtils.getApplicationContext(); - if (isExternalStorageMounted()) { - File externalCacheDir = context.getExternalCacheDir(); - if (externalCacheDir == null) { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { - File dir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + - "/Android/data/" + context.getPackageName() + "/cache"); - if (dir.mkdirs()) { - return dir.getAbsolutePath(); - } - } - } - else { - return externalCacheDir.getAbsolutePath(); - } - } - else { - return context.getCacheDir().getAbsolutePath(); - } - return null; - } - - @Nullable - public static String getFilesPath (@NonNull String type) { - Context context = ApplicationUtils.getApplicationContext(); - if (!type.equals("")) { - type = "/" + type; - } - if (isExternalStorageMounted()) { - File externalFilesDir = context.getExternalFilesDir(type); - if (externalFilesDir == null) { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) { - File dir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + - "/Android/data/" + context.getPackageName() + "/files" + type); - if (dir.mkdirs()) { - return dir.getAbsolutePath(); - } - } - } - else { - return externalFilesDir.getAbsolutePath(); - } - } - else { - File dir = new File(context.getFilesDir().getAbsolutePath() + type); - if (dir.mkdirs()) { - return dir.getAbsolutePath(); - } - } - return null; - } - - public static boolean isExternalStorageMounted() { - return EnvironmentCompat.getStorageState(Environment.getExternalStorageDirectory()). - equals(Environment.MEDIA_MOUNTED); - } - } diff --git a/app/src/main/res/drawable/ic_baseline_zoom_24.xml b/app/src/main/res/drawable/ic_baseline_zoom_24.xml new file mode 100644 index 0000000..6789f86 --- /dev/null +++ b/app/src/main/res/drawable/ic_baseline_zoom_24.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layout-land/activity_main.xml b/app/src/main/res/layout-land/activity_main.xml index 208bd54..60148c3 100644 --- a/app/src/main/res/layout-land/activity_main.xml +++ b/app/src/main/res/layout-land/activity_main.xml @@ -202,6 +202,14 @@ android:background="?attr/selectableItemBackground" android:tint="@color/colorPrimaryText" app:srcCompat="@drawable/ic_baseline_colorize_24" /> + + diff --git a/app/src/main/res/layout-port/activity_main.xml b/app/src/main/res/layout-port/activity_main.xml index 229d214..009a55c 100644 --- a/app/src/main/res/layout-port/activity_main.xml +++ b/app/src/main/res/layout-port/activity_main.xml @@ -295,6 +295,14 @@ android:background="?attr/selectableItemBackground" android:tint="@color/colorPrimaryText" app:srcCompat="@drawable/ic_baseline_colorize_24" /> + +