Some adjustments
This commit is contained in:
committed by
Mihai Alexandru
parent
f91261f748
commit
314d8af9c8
+11
-20
@@ -3,42 +3,33 @@ package funkin.extensions;
|
||||
import android.content.Intent;
|
||||
|
||||
import org.haxe.extension.Extension;
|
||||
|
||||
import org.haxe.lime.HaxeObject;
|
||||
|
||||
public class CallbackUtil extends Extension
|
||||
{
|
||||
public static HaxeObject cbObject;
|
||||
|
||||
/**
|
||||
* Constant representing the event when the data folder is closed.
|
||||
*/
|
||||
public static int DATA_FOLDER_CLOSED = 0x01;
|
||||
|
||||
private static HaxeObject haxeObject;
|
||||
|
||||
/**
|
||||
* Initializes the callback object for handling Haxe callbacks.
|
||||
*
|
||||
* @param cbObject The HaxeObject instance to handle callbacks.
|
||||
* @param haxeObject The HaxeObject instance to handle callbacks.
|
||||
*/
|
||||
public static void initCallBack(final HaxeObject cbObject)
|
||||
public static void initCallBack(final HaxeObject haxeObject)
|
||||
{
|
||||
CallbackUtil.cbObject = cbObject;
|
||||
CallbackUtil.haxeObject = haxeObject;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onActivityResult(int requestCode, int resultCode, Intent data)
|
||||
{
|
||||
if (cbObject != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
Object[] args = new Object[2];
|
||||
args[0] = requestCode;
|
||||
args[1] = resultCode;
|
||||
|
||||
cbObject.call("onActivityResult", args);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (haxeObject != null)
|
||||
haxeObject.call2("onActivityResult", requestCode, resultCode);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
+5
-33
@@ -7,13 +7,10 @@ import android.os.Build;
|
||||
import android.provider.DocumentsContract;
|
||||
import android.content.pm.PackageInfo;
|
||||
|
||||
import funkin.extensions.CallbackUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.haxe.extension.Extension;
|
||||
|
||||
|
||||
public class DataFolderUtil
|
||||
{
|
||||
/**
|
||||
@@ -21,41 +18,16 @@ public class DataFolderUtil
|
||||
* It's highly based on some code borrowed from Mterial Files
|
||||
* https://github.com/zhanghai/MaterialFiles
|
||||
*/
|
||||
public static void openDataFolder()
|
||||
public static void openDataFolder(int requestCode)
|
||||
{
|
||||
::if (APP_PACKAGE != "")::
|
||||
if (Extension.mainActivity != null)
|
||||
{
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setDataAndType(DocumentsContract.buildRootUri("::APP_PACKAGE::.docprovider", ""), "vnd.android.document/directory");
|
||||
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
|
||||
String documentsUiPackage = getDocumentsUiPackage();
|
||||
if (documentsUiPackage != null) {
|
||||
intent.setPackage(documentsUiPackage);
|
||||
Extension.mainActivity.startActivityForResult(intent, CallbackUtil.DATA_FOLDER_CLOSED);
|
||||
}
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setDataAndType(DocumentsContract.buildRootUri("::APP_PACKAGE::.docprovider", ""), "vnd.android.document/directory");
|
||||
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
Extension.mainActivity.startActivityForResult(intent, requestCode);
|
||||
}
|
||||
::end::
|
||||
}
|
||||
|
||||
private static String getDocumentsUiPackage() {
|
||||
List<PackageInfo> packageInfos = Extension.mainContext.getPackageManager().getPackagesHoldingPermissions(
|
||||
new String[]{"android.permission.MANAGE_DOCUMENTS"}, 0
|
||||
);
|
||||
|
||||
PackageInfo targetPackage = null;
|
||||
for (PackageInfo pkg : packageInfos) {
|
||||
if (pkg.packageName.endsWith(".documentsui")) {
|
||||
targetPackage = pkg;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (targetPackage == null && !packageInfos.isEmpty()) {
|
||||
targetPackage = packageInfos.get(0);
|
||||
}
|
||||
|
||||
return targetPackage != null ? targetPackage.packageName : null;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ import java.util.List;
|
||||
|
||||
import org.haxe.extension.Extension;
|
||||
|
||||
public class ScreenUtils
|
||||
public class ScreenUtil
|
||||
{
|
||||
public static Rect[] getCutoutDimensions()
|
||||
{
|
||||
Reference in New Issue
Block a user