Fixed image picker picking & capturing

Co-authored-by: SVolf <a.zhiganov@mintmail.ru>
This commit is contained in:
Artem Zhiganov 2023-12-09 22:26:35 +07:00 committed by GitHub
parent b008bc96f2
commit dfa1572670
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 225 additions and 152 deletions

View file

@ -78,7 +78,7 @@ android {
}
}
flavorDimensions "version", "abi"
flavorDimensions "version"
productFlavors {
extreme {
@ -94,42 +94,6 @@ android {
// dimension "version"
// buildConfigField "boolean", "IS_TRIAL", "true"
// }
x86 {
dimension "abi"
versionCode Integer.parseInt("8" + defaultConfig.versionCode)
ndk {
abiFilter "x86"
}
}
armv7 {
dimension "abi"
versionCode Integer.parseInt("2" + defaultConfig.versionCode)
ndk {
abiFilter "armeabi-v7a"
}
}
arm {
dimension "abi"
versionCode Integer.parseInt("1" + defaultConfig.versionCode)
ndk {
abiFilter "armeabi"
}
}
armv64 {
dimension "abi"
versionCode Integer.parseInt("3" + defaultConfig.versionCode)
ndk {
abiFilter "arm64-v8a"
}
}
x86_64 {
dimension "abi"
versionCode Integer.parseInt("9" + defaultConfig.versionCode)
ndk {
abiFilter "x86_64"
}
}
}
buildFeatures {
aidl true
@ -137,12 +101,12 @@ android {
namespace 'net.pierrox.lightning_launcher_extreme'
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = '11'
jvmTarget = '17'
}
}

View file

@ -8,6 +8,7 @@
<uses-permission android:name="android.permission.SET_WALLPAPER_HINTS"/>
<uses-permission android:name="android.permission.REORDER_TASKS"/>
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<!-- backup & restore -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
@ -125,6 +126,16 @@
android:exported="true"
android:grantUriPermissions="true"/>
<provider
android:authorities="${applicationId}.provider"
android:name="androidx.core.content.FileProvider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths" />
</provider>
<activity
android:name="net.pierrox.lightning_launcher.feature.settings.RootSettings"
android:excludeFromRecents="true"

View file

@ -43,8 +43,6 @@ import net.pierrox.lightning_launcher.script.Script;
import net.pierrox.lightning_launcher.util.EmptyService;
import net.pierrox.lightning_launcher.util.MPReceiver;
import org.koin.android.java.KoinAndroidApplication;
public abstract class LLAppPhone extends LLApp {
private MPReceiver mMPReceiver;
@ -53,12 +51,6 @@ public abstract class LLAppPhone extends LLApp {
public void onCreate() {
super.onCreate();
KoinAndroidApplication
.create(this)
.modules(
// Define vararg of modules...
);
// Implicit broadcasts cannot be registered anymore in the manifest starting at Android O,
// however it is still possible to register them at runtime.
// the consequence is that these events will not be received if the app is not running,

View file

@ -103,6 +103,7 @@ import net.pierrox.lightning_launcher.prefs.LLPreferenceListView;
import net.pierrox.lightning_launcher.prefs.LLPreferenceListView.OnLLPreferenceListViewEventListener;
import net.pierrox.lightning_launcher.prefs.LLPreferenceSlider;
import net.pierrox.lightning_launcher.prefs.LLPreferenceSlider.ValueType;
import net.pierrox.lightning_launcher.util.FilesHolder;
import net.pierrox.lightning_launcher.util.PhoneUtils;
import net.pierrox.lightning_launcher.util.Setup;
import net.pierrox.lightning_launcher.views.BoxEditorView;
@ -120,6 +121,7 @@ import net.pierrox.lightning_launcher_extreme.R;
import org.json.JSONException;
import org.json.JSONObject;
import org.koin.java.KoinJavaComponent;
import java.io.File;
import java.io.FileOutputStream;
@ -130,6 +132,8 @@ import java.util.ArrayList;
public class Customize extends ResourceWrapperActivity implements
OnLLPreferenceListViewEventListener, ItemLayoutListener,
OnPageChangeListener {
private final FilesHolder filesHolder = KoinJavaComponent.get(FilesHolder.class);
/* package */public static final String INTENT_EXTRA_PAGE_ID = "p";
/* package */public static final String INTENT_EXTRA_PAGE_PATH = "t";
/* package */public static final String INTENT_EXTRA_LAUNCHED_FROM = "f";
@ -1020,7 +1024,7 @@ public class Customize extends ResourceWrapperActivity implements
}
} else if (requestCode == REQUEST_PICK_SCREEN_WALLPAPER) {
if (resultCode == RESULT_OK) {
File tmp_image_file = Utils.getTmpImageFile();
File tmp_image_file = filesHolder.getTempImageFile();
final File wallpaperFile = mPage.getWallpaperFile();
if (tmp_image_file.exists()) {
Utils.copyFileSafe(null, tmp_image_file, wallpaperFile);
@ -1043,7 +1047,7 @@ public class Customize extends ResourceWrapperActivity implements
if (resultCode == RESULT_OK) {
FileOutputStream fos = null;
File icon_dir = mPage.getAndCreateIconDir();
File tmp_image_file = Utils.getTmpImageFile();
File tmp_image_file = filesHolder.getTempImageFile();
byte[] buffer = new byte[4096];
try {
if (mPickedPreference == mPGFolderBoxNpNormal || mPickedPreference == mPGAppDrawerABBackground) {

View file

@ -149,6 +149,7 @@ import net.pierrox.lightning_launcher.script.ScriptExecutor;
import net.pierrox.lightning_launcher.script.ScriptManager;
import net.pierrox.lightning_launcher.script.api.ImageBitmap;
import net.pierrox.lightning_launcher.util.AddItemDialog;
import net.pierrox.lightning_launcher.util.FilesHolder;
import net.pierrox.lightning_launcher.util.PhoneUtils;
import net.pierrox.lightning_launcher.util.Setup;
import net.pierrox.lightning_launcher.views.BubbleLayout;
@ -169,6 +170,7 @@ import net.pierrox.lightning_launcher.views.item.WidgetView;
import net.pierrox.lightning_launcher_extreme.BuildConfig;
import net.pierrox.lightning_launcher_extreme.R;
import org.koin.java.KoinJavaComponent;
import org.mozilla.javascript.Function;
import java.io.File;
@ -187,6 +189,7 @@ import java.util.Stack;
public class Dashboard extends ResourceWrapperActivity implements OnLongClickListener, OnClickListener, View.OnTouchListener, Setup.OnFirstTimeInitEvent, UndoStack.UndoListener, HierarchyScreen.HierarchyScreenListener {
private final FilesHolder filesHolder = KoinJavaComponent.get(FilesHolder.class);
public static final int REQUEST_FROM_CUSTOMIZE_VIEW = 100;
public static final String BROADCAST_ACTION_LOCKED = LLApp.LLX_PKG_NAME + ".ACTION_LOCKED";
public static final String BROADCAST_ACTION_UNLOCKED = LLApp.LLX_PKG_NAME + ".ACTION_UNLOCKED";
@ -1197,12 +1200,12 @@ public class Dashboard extends ResourceWrapperActivity implements OnLongClickLis
break;
case REQUEST_SCRIPT_PICK_IMAGE:
mScriptExecutorForCallback.setFileForPickImage(Utils.getTmpImageFile());
mScriptExecutorForCallback.setFileForPickImage(filesHolder.getTempImageFile());
mScriptExecutorForCallback = null;
break;
case REQUEST_SCRIPT_CROP_IMAGE:
Bitmap bitmap = Utils.loadBitmap(Utils.getTmpImageFile(), 0, 0, 0);
Bitmap bitmap = Utils.loadBitmap(filesHolder.getTempImageFile(), 0, 0, 0);
ImageBitmap image = new ImageBitmap(mScriptExecutorForCallback.getLightning(), bitmap);
mScriptExecutorForCallback.setImageForCropImage(image);
mScriptExecutorForCallback = null;
@ -1215,7 +1218,7 @@ public class Dashboard extends ResourceWrapperActivity implements OnLongClickLis
if (item instanceof Shortcut) {
Shortcut shortcut = (Shortcut) item;
File icon_file = shortcut.getCustomIconFile();
File tmp_image_file = Utils.getTmpImageFile();
File tmp_image_file = filesHolder.getTempImageFile();
boolean copied = false;
if (tmp_image_file.exists()) {
FileOutputStream fos = null;
@ -6461,7 +6464,7 @@ public class Dashboard extends ResourceWrapperActivity implements OnLongClickLis
return;
}
final File file = Utils.getTmpImageFile();
final File file = filesHolder.getTempImageFile();
final ProgressDialog d = new ProgressDialog(Dashboard.this);
d.setMessage(getString(R.string.please_wait));

View file

@ -43,14 +43,19 @@ import android.widget.TextView;
import android.widget.Toast;
import net.pierrox.lightning_launcher.data.Utils;
import net.pierrox.lightning_launcher.util.FilesHolder;
import net.pierrox.lightning_launcher.views.CropperView;
import net.pierrox.lightning_launcher_extreme.R;
import org.koin.java.KoinJavaComponent;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
public class ImageCropper extends ResourceWrapperActivity implements View.OnClickListener, CropperView.OnCropperViewEvent {
private FilesHolder filesHolder = KoinJavaComponent.get(FilesHolder.class);
public static final String INTENT_EXTRA_IMAGE = "i";
public static final String INTENT_EXTRA_FULL_SIZE = "f";
@ -58,10 +63,10 @@ public class ImageCropper extends ResourceWrapperActivity implements View.OnClic
private TextView mSelectionText;
private CropperView mCropperView;
public static void startActivity(Activity from, File image, int requestCode) {
public static Intent genIntent(Activity from, File image) {
final Intent intent = new Intent(from, ImageCropper.class);
intent.putExtra(INTENT_EXTRA_IMAGE, image.getAbsolutePath());
from.startActivityForResult(intent, requestCode);
return intent;
}
@Override
@ -96,7 +101,7 @@ public class ImageCropper extends ResourceWrapperActivity implements View.OnClic
case R.id.ok:
final Rect r = mCropperView.getSelection();
final Bitmap original_image = ((BitmapDrawable) mCropperView.getDrawable()).getBitmap();
final File destinationFile = Utils.getTmpImageFile();
final File destinationFile = filesHolder.getTempImageFile();
if (r.left == 0 && r.top == 0 && r.width() == original_image.getWidth() && r.height() == original_image.getHeight()) {
boolean success;
@ -141,6 +146,7 @@ public class ImageCropper extends ResourceWrapperActivity implements View.OnClic
if (fos != null) try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}

View file

@ -49,10 +49,10 @@ import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.preference.PreferenceManager;
import android.provider.MediaStore;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
@ -70,14 +70,22 @@ import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.PickVisualMediaRequest;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.core.content.FileProvider;
import net.margaritov.preference.colorpicker.ColorPickerDialog;
import net.pierrox.lightning_launcher.LLApp;
import net.pierrox.lightning_launcher.data.Page;
import net.pierrox.lightning_launcher.data.Utils;
import net.pierrox.lightning_launcher.util.FilesHolder;
import net.pierrox.lightning_launcher.util.LruCache;
import net.pierrox.lightning_launcher.views.EditTextIme;
import net.pierrox.lightning_launcher_extreme.R;
import org.koin.java.KoinJavaComponent;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
@ -91,6 +99,7 @@ import java.util.List;
public class ImagePicker extends ResourceWrapperActivity implements AdapterView.OnItemSelectedListener, AdapterView.OnItemClickListener, View.OnClickListener, ColorPickerDialog.OnColorChangedListener, View.OnLongClickListener, AdapterView.OnItemLongClickListener, EditTextIme.OnEditTextImeListener, TextWatcher {
private FilesHolder filesHolder = KoinJavaComponent.get(FilesHolder.class);
private static final int MODE_NONE = -1;
private static final int MODE_ICON_PACK = 0;
private static final int MODE_PATH = 1;
@ -101,11 +110,6 @@ public class ImagePicker extends ResourceWrapperActivity implements AdapterView.
private static final String INTENT_EXTRA_CROP = "c";
private static final int REQUEST_CAPTURE_IMAGE = 1;
private static final int REQUEST_PICK_IMAGE = 2;
private static final int REQUEST_CROP_IMAGE = 3;
private static final String PREF_CURRENT_MODE = "ip_m";
private static final String PREF_CURRENT_PATH = "ip_pa";
private static final String PREF_CURRENT_PKG = "ip_pk";
@ -152,6 +156,35 @@ public class ImagePicker extends ResourceWrapperActivity implements AdapterView.
private View mClickedView;
private LruCache<String, BitmapInfo> mThumbnailCache;
private final ActivityResultLauncher<PickVisualMediaRequest> imageRequest = registerForActivityResult(
new ActivityResultContracts.PickVisualMedia(),
uri -> {
if (uri != null) {
copyToTempFile(uri);
imagePicked(true);
}
}
);
private final ActivityResultLauncher<Uri> cameraRequest = registerForActivityResult(
new ActivityResultContracts.TakePicture(),
captured -> {
if (captured) {
imagePicked(true);
}
}
);
private final ActivityResultLauncher<Intent> cropRequest = registerForActivityResult(
new ActivityResultContracts.StartActivityForResult(),
result -> {
if (result.getResultCode() == Activity.RESULT_OK) {
setResult(RESULT_OK);
finish();
}
}
);
public static void startActivity(Activity from, int requestCode) {
final Intent intent = new Intent(from, ImagePicker.class);
intent.putExtra(INTENT_EXTRA_CROP, true);
@ -160,14 +193,12 @@ public class ImagePicker extends ResourceWrapperActivity implements AdapterView.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState == null) {
// if recreated because the activity has been disposed by the framework, don't remove
// the temp file, it will be used for instance in the activity result callback
Utils.getTmpImageFile().delete();
filesHolder.getTempImageFile().delete();
}
final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
@ -315,14 +346,21 @@ public class ImagePicker extends ResourceWrapperActivity implements AdapterView.
setSearchMode(false);
String[] permissions;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
permissions = new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE};
} else {
permissions = new String[]{Manifest.permission.READ_MEDIA_IMAGES};
}
checkPermissions(
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE},
permissions,
new int[]{R.string.pr_r4, R.string.pr_r5},
REQUEST_PERMISSION_BASE);
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (areAllPermissionsGranted(grantResults, R.string.pr_f3)) {
if (mCurrentMode == MODE_PATH) {
setMode(MODE_PATH);
@ -382,7 +420,7 @@ public class ImagePicker extends ResourceWrapperActivity implements AdapterView.
if (adapterView == mGridView) {
byte[] buffer = new byte[4096];
Object item = mGridView.getItemAtPosition(position);
File tmp_image_file = Utils.getTmpImageFile();
File tmp_image_file = filesHolder.getTempImageFile();
if (mCurrentMode == MODE_PATH) {
ImageFile imf = (ImageFile) item;
if (imf.file.isDirectory()) {
@ -479,8 +517,6 @@ public class ImagePicker extends ResourceWrapperActivity implements AdapterView.
@Override
public void onClick(View view) {
Intent intent;
Intent chooser;
ColorPickerDialog color_picker_dialog;
mClickedView = view;
@ -488,25 +524,20 @@ public class ImagePicker extends ResourceWrapperActivity implements AdapterView.
final int id = view.getId();
switch (id) {
case R.id.none:
Utils.getTmpImageFile().delete();
filesHolder.getTempImageFile().delete();
imagePicked(false);
break;
case R.id.ext_file:
intent = new Intent();
intent.setType("*/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
// intent.addCategory(Intent.CATEGORY_OPENABLE);
chooser = Intent.createChooser(intent, null);
startActivityForResult(chooser, REQUEST_PICK_IMAGE);
final var builder = new PickVisualMediaRequest.Builder()
.setMediaType(ActivityResultContracts.PickVisualMedia.ImageOnly.INSTANCE)
.build();
imageRequest.launch(builder);
break;
case R.id.camera:
File out = Utils.getTmpImageFile();
intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(out));
chooser = Intent.createChooser(intent, null);
startActivityForResult(chooser, REQUEST_CAPTURE_IMAGE);
final var uri = FileProvider.getUriForFile(this, filesHolder.getFileProviderName(), filesHolder.getTempImageFile());
cameraRequest.launch(uri);
break;
case R.id.bgcolor:
@ -558,56 +589,6 @@ public class ImagePicker extends ResourceWrapperActivity implements AdapterView.
return true;
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case REQUEST_CAPTURE_IMAGE:
if (resultCode == RESULT_OK) {
imagePicked(true);
}
break;
case REQUEST_PICK_IMAGE:
if (resultCode == RESULT_OK) {
FileOutputStream fos = null;
InputStream is = null;
try {
fos = new FileOutputStream(Utils.getTmpImageFile());
is = getContentResolver().openInputStream(data.getData());
byte[] buffer = new byte[4096];
int n;
while ((n = is.read(buffer)) > 0) {
fos.write(buffer, 0, n);
}
imagePicked(true);
} catch (IOException e) {
// pass
} finally {
if (fos != null) try {
fos.close();
} catch (IOException e) {
}
if (is != null) try {
is.close();
} catch (IOException e) {
}
}
}
break;
case REQUEST_CROP_IMAGE:
if (resultCode == RESULT_OK) {
setResult(RESULT_OK);
finish();
}
break;
default:
super.onActivityResult(requestCode, resultCode, data);
break;
}
}
private void setGridViewAdapter(ListAdapter adapter) {
mNoIconTextView.setVisibility(adapter == null || adapter.getCount() == 0 ? View.VISIBLE : View.GONE);
mGridView.setAdapter(adapter);
@ -887,7 +868,7 @@ public class ImagePicker extends ResourceWrapperActivity implements AdapterView.
b.eraseColor(color);
FileOutputStream fos = null;
try {
fos = new FileOutputStream(Utils.getTmpImageFile());
fos = new FileOutputStream(filesHolder.getTempImageFile());
b.compress(Bitmap.CompressFormat.PNG, 100, fos);
imagePicked(false);
} catch (FileNotFoundException e) {
@ -922,7 +903,7 @@ public class ImagePicker extends ResourceWrapperActivity implements AdapterView.
private void imagePicked(boolean allow_crop) {
// if(getIntent().getBooleanExtra(INTENT_EXTRA_CROP, false) && allow_crop) {
File file = Utils.getTmpImageFile();
File file = filesHolder.getTempImageFile();
if (allow_crop) {
if (Utils.isSvgFile(file)) {
allow_crop = false;
@ -930,7 +911,8 @@ public class ImagePicker extends ResourceWrapperActivity implements AdapterView.
}
if (allow_crop) {
ImageCropper.startActivity(this, file, REQUEST_CROP_IMAGE);
final var intent = ImageCropper.genIntent(this, file);
cropRequest.launch(intent);
} else {
setResult(RESULT_OK);
finish();
@ -979,6 +961,31 @@ public class ImagePicker extends ResourceWrapperActivity implements AdapterView.
}
private void copyToTempFile(Uri contentUri) {
InputStream is = null;
FileOutputStream fos = null;
try {
is = getContentResolver().openInputStream(contentUri);
fos = new FileOutputStream(filesHolder.getTempImageFile());
byte[] buffer = new byte[8192];
int n;
while ((n = is.read(buffer)) > 0) {
fos.write(buffer, 0, n);
}
} catch (IOException ignored) {
// pass
} finally {
if (fos != null) try {
fos.close();
} catch (IOException ignored) {
}
if (is != null) try {
is.close();
} catch (IOException ignored) {
}
}
}
private static class BitmapInfo {
Bitmap bitmap;
boolean isNinePatch; // need to be stored because 9patch chunk is lost during resize

View file

@ -71,11 +71,14 @@ import net.pierrox.lightning_launcher.data.Screen;
import net.pierrox.lightning_launcher.data.Shortcut;
import net.pierrox.lightning_launcher.data.Utils;
import net.pierrox.lightning_launcher.engine.LightningEngine;
import net.pierrox.lightning_launcher.util.FilesHolder;
import net.pierrox.lightning_launcher.util.PhoneUtils;
import net.pierrox.lightning_launcher.views.ItemLayout;
import net.pierrox.lightning_launcher.views.item.ItemView;
import net.pierrox.lightning_launcher_extreme.R;
import org.koin.java.KoinJavaComponent;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
@ -83,6 +86,8 @@ import java.util.ArrayList;
import java.util.List;
public class ScreenManager extends ResourceWrapperActivity implements OnClickListener, View.OnLongClickListener {
private final FilesHolder filesHolder = KoinJavaComponent.get(FilesHolder.class);
protected static final int SCREEN_MODE_LWP = 6;
private static final int DIALOG_LABEL = 2;
private static final int DIALOG_CONFIRM_DELETE = 3;
@ -381,7 +386,7 @@ public class ScreenManager extends ResourceWrapperActivity implements OnClickLis
if (resultCode == RESULT_OK) {
FileOutputStream fos = null;
try {
File tmpImageFile = Utils.getTmpImageFile();
File tmpImageFile = filesHolder.getTempImageFile();
File icon_file = Page.getPageIconFile(mLightningEngine.getBaseDir(), mCurrentPage);
Screen screen = mScreens.get(getScreenIndex(mCurrentPage));
if (tmpImageFile.exists()) {

View file

@ -101,10 +101,13 @@ import net.pierrox.lightning_launcher.prefs.LLPreferenceText;
import net.pierrox.lightning_launcher.script.Script;
import net.pierrox.lightning_launcher.util.BindingEditDialog;
import net.pierrox.lightning_launcher.util.FileAndDirectoryPickerDialog;
import net.pierrox.lightning_launcher.util.FilesHolder;
import net.pierrox.lightning_launcher.util.PhoneUtils;
import net.pierrox.lightning_launcher.util.ScriptPickerDialog;
import net.pierrox.lightning_launcher_extreme.R;
import org.koin.java.KoinJavaComponent;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
@ -117,6 +120,7 @@ import java.util.HashMap;
public class CustomizeItemView extends MyViewPager implements LLPreferenceListView.OnLLPreferenceListViewEventListener, LLApp.SystemConfigListener {
private final FilesHolder filesHolder = KoinJavaComponent.get(FilesHolder.class);
private static final int REQUEST_EDIT_EVENT_ACTION = Dashboard.REQUEST_FROM_CUSTOMIZE_VIEW + 1;
private static final int REQUEST_PICK_ICON_EFFECT_B = Dashboard.REQUEST_FROM_CUSTOMIZE_VIEW + 5;
private static final int REQUEST_PICK_ICON_EFFECT_O = Dashboard.REQUEST_FROM_CUSTOMIZE_VIEW + 6;
@ -1929,7 +1933,7 @@ public class CustomizeItemView extends MyViewPager implements LLPreferenceListVi
file = ShortcutConfig.getIconMaskFile(icon_dir, Item.NO_ID);
}
Utils.copyOrDeleteFile(Utils.getTmpImageFile(), file);
Utils.copyOrDeleteFile(filesHolder.getTempImageFile(), file);
pageShortcutConfig.iconBack = null;
@ -1956,7 +1960,7 @@ public class CustomizeItemView extends MyViewPager implements LLPreferenceListVi
file = ShortcutConfig.getIconMaskFile(icon_dir, itemId);
}
Utils.copyOrDeleteFile(Utils.getTmpImageFile(), file);
Utils.copyOrDeleteFile(filesHolder.getTempImageFile(), file);
ShortcutConfig shortcutConfig = ((Shortcut) item).getShortcutConfig();
shortcutConfig.iconBack = pageShortcutConfig.iconBack;
@ -1974,7 +1978,7 @@ public class CustomizeItemView extends MyViewPager implements LLPreferenceListVi
if (resultCode == Activity.RESULT_OK) {
File icon_dir = mPage.getAndCreateIconDir();
File tmp_image_file = Utils.getTmpImageFile();
File tmp_image_file = filesHolder.getTempImageFile();
if (mForPage) {
mUndoStack.storePageState(mPage);

View file

@ -35,12 +35,12 @@ android {
namespace 'net.pierrox.lightning_launcher'
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = '11'
jvmTarget = '17'
}
}
@ -48,6 +48,7 @@ dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation files('libs/dx.jar')
implementation libs.lsvg
implementation libs.koin.android
implementation libs.androidx.appcomat
implementation libs.androidx.material
implementation project(':plugin-api')

View file

@ -1,5 +1,7 @@
package net.pierrox.lightning_launcher;
import static org.koin.core.context.DefaultContextExtKt.startKoin;
import android.app.Application;
import android.appwidget.AppWidgetHost;
import android.appwidget.AppWidgetHostView;
@ -21,6 +23,7 @@ import net.pierrox.lightning_launcher.data.Item;
import net.pierrox.lightning_launcher.data.JsonLoader;
import net.pierrox.lightning_launcher.data.Page;
import net.pierrox.lightning_launcher.data.Utils;
import net.pierrox.lightning_launcher.di.UtilitiesModule;
import net.pierrox.lightning_launcher.engine.LightningEngine;
import net.pierrox.lightning_launcher.engine.Screen;
import net.pierrox.lightning_launcher.script.api.Property;
@ -29,11 +32,15 @@ import net.pierrox.lightning_launcher.views.NativeImage;
import net.pierrox.lightning_launcher.views.SharedAsyncGraphicsDrawable;
import org.json.JSONObject;
import org.koin.android.java.KoinAndroidApplication;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public abstract class LLApp extends Application {
public static final String LL_PKG_NAME = "net.pierrox.lightning_launcher";
@ -82,6 +89,18 @@ public abstract class LLApp extends Application {
sThis = this;
final var allModules = Stream.of(
UtilitiesModule.INSTANCE.getModules()
)
.flatMap(Collection::stream)
.collect(Collectors.toList());
final var koin = KoinAndroidApplication
.create(this)
.modules(allModules);
startKoin(koin);
NativeImage.init(this);
Utils.deleteDirectory(FileUtils.getCachedDrawablesDir(this), false);

View file

@ -44,7 +44,7 @@ public class FileUtils {
};
public static final File LL_EXT_DIR = new File(Environment.getExternalStorageDirectory(), "LightningLauncher");
public static final File LL_TMP_DIR = new File(LL_EXT_DIR, "tmp");
public static final File LL_TMP_DIR = new File(Environment.getDataDirectory(), "tmp");
public static final File LL_EXT_SCRIPT_DIR = new File(LL_EXT_DIR, "script");
public static final String THEMES_DIR = "LightningLauncher/themes";
private static final byte[] copy_buffer = new byte[4096];

View file

@ -350,6 +350,7 @@ public class Utils {
copyFile(buffer, from, to);
return true;
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
@ -1005,12 +1006,6 @@ public class Utils {
}
}
public static File getTmpImageFile() {
File tmp_dir = FileUtils.LL_TMP_DIR;
tmp_dir.mkdirs();
return new File(tmp_dir, "pick_me");
}
public static EventAction decodeEventActionFromLightningIntent(Intent intent) {
EventAction eventAction = null;
String s_ea = intent.getStringExtra(LightningIntent.INTENT_EXTRA_EVENT_ACTION);

View file

@ -0,0 +1,12 @@
package net.pierrox.lightning_launcher.di
import org.koin.core.module.Module
/**
* Base interface which provides DI modules
**/
interface FeatureModule {
val modules: List<Module>
}

View file

@ -0,0 +1,18 @@
package net.pierrox.lightning_launcher.di
import net.pierrox.lightning_launcher.util.FilesHolder
import org.koin.core.module.Module
import org.koin.dsl.module
object UtilitiesModule : FeatureModule {
override val modules: List<Module>
get() = listOf(
filesHolderModule,
)
}
private val filesHolderModule = module {
factory {
FilesHolder(context = get())
}
}

View file

@ -0,0 +1,26 @@
package net.pierrox.lightning_launcher.util
import android.content.Context
import java.io.File
/**
* An object which used to hold and manage common app files and directories
*
* @param context application context
**/
class FilesHolder(private val context: Context) {
private fun getTempDir() = File(context.filesDir, "tmp").apply { mkdirs() }
/**
* Gets a temporary picked image file
* @return image file
**/
fun getTempImageFile() = File(getTempDir(), "image")
/**
* File authority name which used by AndroidX FileProvider
**/
val fileProviderName = "${context.packageName}.provider"
}

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<paths>
<files-path
name="temp"
path="tmp" />
</paths>

View file

@ -14,12 +14,12 @@ android {
namespace 'net.pierrox.lightning_launcher.plugin'
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = '11'
jvmTarget = '17'
}
}