From 6d0b312466c4ed41c80b19d6007ea69147bb81cb Mon Sep 17 00:00:00 2001 From: staphen Date: Tue, 29 Mar 2022 19:13:17 -0400 Subject: [PATCH] [Android] Add shortcut to import game data --- .../app/src/main/AndroidManifest.xml | 8 ++ .../devilutionx/ImportActivity.java | 93 ++++++++++++++++++ .../mipmap-hdpi/ic_launcher_import_data.png | Bin 0 -> 489 bytes .../mipmap-mdpi/ic_launcher_import_data.png | Bin 0 -> 335 bytes .../mipmap-xhdpi/ic_launcher_import_data.png | Bin 0 -> 523 bytes .../mipmap-xxhdpi/ic_launcher_import_data.png | Bin 0 -> 893 bytes .../ic_launcher_import_data.png | Bin 0 -> 985 bytes .../app/src/main/res/values/strings.xml | 1 + .../app/src/main/res/xml/shortcuts.xml | 13 +++ 9 files changed, 115 insertions(+) create mode 100644 android-project/app/src/main/java/org/diasurgical/devilutionx/ImportActivity.java create mode 100644 android-project/app/src/main/res/mipmap-hdpi/ic_launcher_import_data.png create mode 100644 android-project/app/src/main/res/mipmap-mdpi/ic_launcher_import_data.png create mode 100644 android-project/app/src/main/res/mipmap-xhdpi/ic_launcher_import_data.png create mode 100644 android-project/app/src/main/res/mipmap-xxhdpi/ic_launcher_import_data.png create mode 100644 android-project/app/src/main/res/mipmap-xxxhdpi/ic_launcher_import_data.png create mode 100644 android-project/app/src/main/res/xml/shortcuts.xml diff --git a/android-project/app/src/main/AndroidManifest.xml b/android-project/app/src/main/AndroidManifest.xml index cc417db7b..5eedbd4eb 100644 --- a/android-project/app/src/main/AndroidManifest.xml +++ b/android-project/app/src/main/AndroidManifest.xml @@ -79,11 +79,19 @@ --> + + + + + diff --git a/android-project/app/src/main/java/org/diasurgical/devilutionx/ImportActivity.java b/android-project/app/src/main/java/org/diasurgical/devilutionx/ImportActivity.java new file mode 100644 index 000000000..a7ca99215 --- /dev/null +++ b/android-project/app/src/main/java/org/diasurgical/devilutionx/ImportActivity.java @@ -0,0 +1,93 @@ +package org.diasurgical.devilutionx; + +import android.app.Activity; +import android.content.ClipData; +import android.content.ContentResolver; +import android.content.Intent; +import android.net.Uri; +import android.support.annotation.Nullable; +import android.os.Bundle; +import android.support.v4.provider.DocumentFile; +import android.util.Log; + +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.Objects; + +public class ImportActivity extends Activity { + + private static final int IMPORT_REQUEST_CODE = 0xD1AB70; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); + intent.addCategory(Intent.CATEGORY_OPENABLE); + intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true); + intent.setType("*/*"); + startActivityForResult(intent, IMPORT_REQUEST_CODE); + } + + @Override + protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { + if (requestCode != IMPORT_REQUEST_CODE) + return; + + if (resultCode == Activity.RESULT_OK && data != null) { + importFile(data.getData()); + handleClipData(data.getClipData()); + } + + finish(); + } + + private void handleClipData(ClipData clipData) { + if (clipData == null) + return; + + for (int i = 0; i < clipData.getItemCount(); i++) { + ClipData.Item item = clipData.getItemAt(i); + if (item == null) + continue; + + importFile(item.getUri()); + } + } + + private void importFile(Uri fileUri) { + if (fileUri == null) + return; + + DocumentFile file = DocumentFile.fromSingleUri(getApplicationContext(), fileUri); + String fileName = file.getName(); + String externalFilesDir = getExternalFilesDir(null).getAbsolutePath(); + String externalFilesPath = externalFilesDir + "/" + fileName; + + try { + InputStream inputStream = null; + OutputStream outputStream = null; + + try { + ContentResolver contentResolver = getContentResolver(); + inputStream = contentResolver.openInputStream(fileUri); + outputStream = new FileOutputStream(externalFilesPath); + + // Transfer bytes from in to out + byte[] buf = new byte[4096]; + int len; + while ((len = inputStream.read(buf)) > 0) { + outputStream.write(buf, 0, len); + } + } finally { + if (inputStream != null) + inputStream.close(); + if (outputStream != null) + outputStream.close(); + } + } catch (IOException exception) { + Log.e("importFile", Objects.requireNonNull(exception.getMessage())); + } + } +} diff --git a/android-project/app/src/main/res/mipmap-hdpi/ic_launcher_import_data.png b/android-project/app/src/main/res/mipmap-hdpi/ic_launcher_import_data.png new file mode 100644 index 0000000000000000000000000000000000000000..ff35a00e63fb8578ed5af1c0c38b4b313c5a89c0 GIT binary patch literal 489 zcmeAS@N?(olHy`uVBq!ia0vp^9w5xY3?!3`olAifV{wqX6T`Z5GB1G~mUKs7M+SzC z{oH>NS%G}c0*}aI1_r*vAk26?e?T zq^zozTYu!(xhq$%-M;tf_dka0z{fzhGJCo>hD02GJN+hKvx0zYtKK%&H);m||1YgI zn6;&JLiDm+AB%n||2+?SoG*uHO`X5U_xVfS)dA=4xz18tp!POnUV`Do&LfR`gO67o zD47?e=3rv;sc7TgK&ktZbCt9Fyw$q$<|}9M{hib~=bWJK^2HgOTqIxavbk7fHD8nI zdsVDb>Q1GDE~nVm-7%QRo3m3VguC8W0qFk44ofy`glX(f`u%tWsIx;Y9 z?C1WI$O`0h7I;J!GcfQS24TkI`72U@g6aW2A+A807;snU=T@LPo{}KHUfAL7DEb#VlIC5UbdHRY*uY`=7#cb`t5^@wd8Xo6ZJ-#3|+PD9}!9z!`eER%{vp3QN=tf;n7srr{dv9l)>WC~iU!V{k55H3r5_Vg zYUb=b*s}ca^8CYRW^Z+|?_yM9`Ybg^L_y`llO+tAiXDuXf~Af!C>}h`XykN~pDp3m;EdcmcXOa_f#<_uH*er@Rb&(H9{y=8yOALFCqQu{(5 z%$D63`gTe~DWM4fBB-{n literal 0 HcmV?d00001 diff --git a/android-project/app/src/main/res/mipmap-xxhdpi/ic_launcher_import_data.png b/android-project/app/src/main/res/mipmap-xxhdpi/ic_launcher_import_data.png new file mode 100644 index 0000000000000000000000000000000000000000..b3381dbf594d12efc45945315486e1ab730541bd GIT binary patch literal 893 zcmeAS@N?(olHy`uVBq!ia0vp^6F``Q8Ax83A=Cw=7>k44ofy`glX(f`u%tWsIx;Y9 z?C1WI$O`0h7I;J!GcfQS24TkI`72U@f|CP$LR^9LU;|Z^%B4Uz8I%P11v4{G4 zo-U3d6}R5bzFpL0AkgNR?Y-c}=1W~oUs`UR+V}tR*JazbO3IqOnKZX>e|GvGHG9R` z8#tL<14W=nBG71_{`Ct@XTB^DK2~|v!TOb44_oHNFm{GlJ$KW0F^Zf?7Fp&Y|L)2o zCWhQ2mis@keK6f7sm;!hvHo~ho#TKR_O-s_!y zS27+r{q@4~2|w-a!cVW9IbIewIXzMm z{vL38_BW>Zo=4O8D!W%7_~abZsJ6aEG~!A3ZMKuQHMs70bzA35D3?+GaKP)%#Cdz1 z{Tq)Tdc=3`X>F9ikB_c*o@=s)c(nQjpV+%`(n`stUz9`SM52BOTHU$u}T#&fhS5QRLaMb>pRnQmpx}R~~j1zW3}7L$zr8?pjNZg6UIlNblMIJnHr9 lnAnV~OzSne7D3RLbK+kFzofX%*~t&e5}vMpF6*2UngG`1R(=2g literal 0 HcmV?d00001 diff --git a/android-project/app/src/main/res/mipmap-xxxhdpi/ic_launcher_import_data.png b/android-project/app/src/main/res/mipmap-xxxhdpi/ic_launcher_import_data.png new file mode 100644 index 0000000000000000000000000000000000000000..7d41908582dc9bf7bb8c754559e8b825a21c3a1c GIT binary patch literal 985 zcmeAS@N?(olHy`uVBq!ia0vp^2SAvE8Azrw%`pX1jKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85sBugD~Uq{1quc!Il7@5LX~Q;NZ`yybVA{XqN=}1v9X+iHM46 zXliNe=<4Yk7#bOyxVYBVPntYs-~K~4Zry+W;^nK?Z{EIp|KXGQlP}2(3{1;CT^vIy zZoQpzGw+arfUBpJ*LU8eZ47rC&;0)%e?K5pRjJeV+nrbQzI%P2B5>O{%}v>fL$O5w zPD~KKS+eoowM)Y3s&$6;rxbD|o}}tJZ%haXdE{8teA18Q=7JAr=HF6S@3Mf`OE9Ck zQ1=EKH;{g#aD&ZQFsFHGgY+7fI|<4U*tRxE|M9)>lRy63BFDY4`pY7D7*bJ?iErVp)a^!NWD?}#dM0Tbzj4$;3=y}`e#n!IV z*0AiLPFKUCgGPM~^A2iFYM6CUZCb;vcUH3;Hhtz~)o@_s3OF#Sq4);Vx!q>d!w&om z7oW_vgW>DNDNK4Ut>z0GxPun^sXsUra&t204u{&N5GK8l<;oKqxUa4DRDN)%boL|; zlV{VfbBi=S`;$LiW4?p;Kh9I-3oQTt7CjZcLiNAtDXR-}{y%0*Rn0s1zp{Iic-G1K z_D#~c=l+-W7s+Lu{NGTdlzs01-;N@+ymR~OomP5nc~bATl6&VuS#D*f=FifC67%l2 zHMrLaGui#r<*0aSuJB;G{oaQ3I<60bhyDva-tYEN-006*mVaq{_13-h3l7=`J(7R* z@wC>DR^30BlYHQSHrwjb8teh^=AXn#>#{Y(D; zw^aWf4ga(H_>bxPKd!(3+Zh-v4NM{(+5#00L4V|3@^iT7{P+BIYTJRI3mLp`Gd(|U zbOtCS-y@h8vXD*IZ8D3r*h;7NhXxCemA=~Jay)ig-=%d9H#6UI8*U0~U-fu}+5d$H zt=?GqpPoI#m{JZ)8 l>)(B^RghAcfYXWn&)E;y`-wg~=L^c744$rjF6*2UngAPefx7?z literal 0 HcmV?d00001 diff --git a/android-project/app/src/main/res/values/strings.xml b/android-project/app/src/main/res/values/strings.xml index 2e695fafc..b4ad488bf 100644 --- a/android-project/app/src/main/res/values/strings.xml +++ b/android-project/app/src/main/res/values/strings.xml @@ -11,4 +11,5 @@ Game data missing Download started Diablo Demo Data + Import Data diff --git a/android-project/app/src/main/res/xml/shortcuts.xml b/android-project/app/src/main/res/xml/shortcuts.xml new file mode 100644 index 000000000..fa7825eb5 --- /dev/null +++ b/android-project/app/src/main/res/xml/shortcuts.xml @@ -0,0 +1,13 @@ + + + + + +