Skip to content
This repository has been archived by the owner on Aug 1, 2022. It is now read-only.

Commit

Permalink
Bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Tianscar authored and Tianscar committed Jun 27, 2021
1 parent 49f32c2 commit 4c2e3ae
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 88 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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'
Expand Down
41 changes: 27 additions & 14 deletions app/src/main/java/com/ansdoship/pixelarteditor/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -730,7 +731,7 @@ public static List<String> getExternalPaletteNames() {
}

public static String getPalettesPath() {
return Utils.getFilesPath("palettes");
return EnvironmentUtils.getAvailableFilesDirPath("palettes");
}

@NonNull
Expand All @@ -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();
}

Expand All @@ -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();
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand All @@ -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:
Expand Down Expand Up @@ -3477,6 +3477,7 @@ public boolean onTouch(View view, MotionEvent event) {
downY = oldDownY;
moveX = oldMoveX;
moveY = oldMoveY;
flushSelectionSizeView(selectionBitmapDstWidth, selectionBitmapDstHeight);
break;
}
}
Expand All @@ -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;
Expand Down Expand Up @@ -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();
}
});
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -159,7 +160,7 @@ private String saveCrashInfoToFile(@NonNull Throwable exception) {

@Nullable
public static String getCrashDir() {
return Utils.getFilesPath("crashes");
return EnvironmentUtils.getAvailableFilesDirPath("crashes");
}

}
74 changes: 5 additions & 69 deletions app/src/main/java/com/ansdoship/pixelarteditor/util/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,17 @@
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;

import androidx.annotation.NonNull;
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 {
Expand All @@ -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();
Expand Down Expand Up @@ -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);
}

}
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_baseline_zoom_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#000000"
android:pathData="M10,9h4L14,6h3l-5,-5 -5,5h3v3zM9,10L6,10L6,7l-5,5 5,5v-3h3v-4zM23,12l-5,-5v3h-3v4h3v3l5,-5zM14,15h-4v3L7,18l5,5 5,-5h-3v-3z"/>
</vector>
8 changes: 8 additions & 0 deletions app/src/main/res/layout-land/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,14 @@
android:background="?attr/selectableItemBackground"
android:tint="@color/colorPrimaryText"
app:srcCompat="@drawable/ic_baseline_colorize_24" />

<com.ansdoship.pixelarteditor.ui.view.CheckedImageView
android:id="@+id/img_zoom"
android:layout_width="?attr/actionBarSize"
android:layout_height="?attr/actionBarSize"
android:background="?attr/selectableItemBackground"
android:tint="@color/colorPrimaryText"
app:srcCompat="@drawable/ic_baseline_zoom_24" />
</com.ansdoship.pixelarteditor.ui.viewgroup.CheckedImageGroup>
</ScrollView>

Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/layout-port/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,14 @@
android:background="?attr/selectableItemBackground"
android:tint="@color/colorPrimaryText"
app:srcCompat="@drawable/ic_baseline_colorize_24" />

<com.ansdoship.pixelarteditor.ui.view.CheckedImageView
android:id="@+id/img_zoom"
android:layout_width="?attr/actionBarSize"
android:layout_height="?attr/actionBarSize"
android:background="?attr/selectableItemBackground"
android:tint="@color/colorPrimaryText"
app:srcCompat="@drawable/ic_baseline_zoom_24" />
</com.ansdoship.pixelarteditor.ui.viewgroup.CheckedImageGroup>
</HorizontalScrollView>

Expand Down

0 comments on commit 4c2e3ae

Please sign in to comment.