8 changed files with 249 additions and 36 deletions
@ -0,0 +1,119 @@
|
||||
package org.diasurgical.devilutionx; |
||||
|
||||
import android.app.DownloadManager; |
||||
import android.content.BroadcastReceiver; |
||||
import android.content.Context; |
||||
import android.content.Intent; |
||||
import android.content.IntentFilter; |
||||
import android.database.Cursor; |
||||
import android.net.Uri; |
||||
import android.support.v7.app.AppCompatActivity; |
||||
import android.os.Bundle; |
||||
import android.text.method.LinkMovementMethod; |
||||
import android.view.View; |
||||
import android.widget.TextView; |
||||
import android.widget.Toast; |
||||
|
||||
import java.io.File; |
||||
|
||||
public class DataActivity extends AppCompatActivity { |
||||
private String externalDir; |
||||
private DownloadReceiver mReceiver; |
||||
private boolean isDownloading = false; |
||||
|
||||
@Override |
||||
protected void onCreate(Bundle savedInstanceState) { |
||||
externalDir = getExternalFilesDir(null).getAbsolutePath(); |
||||
|
||||
super.onCreate(savedInstanceState); |
||||
setContentView(R.layout.activity_data); |
||||
|
||||
((TextView) findViewById(R.id.full_guide)).setMovementMethod(LinkMovementMethod.getInstance()); |
||||
((TextView) findViewById(R.id.online_guide)).setMovementMethod(LinkMovementMethod.getInstance()); |
||||
} |
||||
|
||||
protected void onResume() { |
||||
super.onResume(); |
||||
startGame(); |
||||
} |
||||
|
||||
public void startGame(View view) { |
||||
startGame(); |
||||
} |
||||
|
||||
private void startGame() { |
||||
if (missingGameData()) { |
||||
Toast toast = Toast.makeText(getApplicationContext(), "Game data missing", Toast.LENGTH_SHORT); |
||||
toast.show(); |
||||
return; |
||||
} |
||||
|
||||
Intent intent = new Intent(this, DevilutionXSDLActivity.class); |
||||
startActivity(intent); |
||||
this.finish(); |
||||
} |
||||
|
||||
/** |
||||
* Check if the game data is present |
||||
*/ |
||||
private boolean missingGameData() { |
||||
File fileLower = new File(externalDir + "/diabdat.mpq"); |
||||
File fileUpper = new File(externalDir + "/DIABDAT.MPQ"); |
||||
File spawnFile = new File(externalDir + "/spawn.mpq"); |
||||
|
||||
return !fileUpper.exists() && !fileLower.exists() && (!spawnFile.exists() || isDownloading); |
||||
} |
||||
|
||||
/** |
||||
* Start downloading the shareware |
||||
*/ |
||||
public void sendDownloadRequest(View view) { |
||||
String url = "https://github.com/d07RiV/diabloweb/raw/3a5a51e84d5dab3cfd4fef661c46977b091aaa9c/spawn.mpq"; |
||||
String fileName = "spawn.mpq"; |
||||
|
||||
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url)) |
||||
.setTitle(fileName) |
||||
.setDescription("Diablo Shareware Data") |
||||
.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE); |
||||
|
||||
request.setDestinationInExternalFilesDir(this, null, fileName); |
||||
|
||||
DownloadManager downloadManager = (DownloadManager)this.getSystemService(Context.DOWNLOAD_SERVICE); |
||||
downloadManager.enqueue(request); |
||||
|
||||
if (mReceiver == null) |
||||
mReceiver = new DownloadReceiver(); |
||||
registerReceiver(mReceiver, new IntentFilter("android.intent.action.DOWNLOAD_COMPLETE")); |
||||
|
||||
isDownloading = true; |
||||
view.setEnabled(false); |
||||
|
||||
Toast toast = Toast.makeText(getApplicationContext(), "Download started", Toast.LENGTH_SHORT); |
||||
toast.show(); |
||||
} |
||||
|
||||
/** |
||||
* Start game when download finishes |
||||
*/ |
||||
private class DownloadReceiver extends BroadcastReceiver { |
||||
@Override |
||||
public void onReceive(Context context, Intent intent) { |
||||
isDownloading = false; |
||||
|
||||
long receivedID = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1L); |
||||
DownloadManager mgr = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE); |
||||
|
||||
DownloadManager.Query query = new DownloadManager.Query(); |
||||
query.setFilterById(receivedID); |
||||
Cursor cur = mgr.query(query); |
||||
int index = cur.getColumnIndex(DownloadManager.COLUMN_STATUS); |
||||
if (cur.moveToFirst()) { |
||||
if (cur.getInt(index) == DownloadManager.STATUS_SUCCESSFUL) { |
||||
startGame(); |
||||
} |
||||
} |
||||
cur.close(); |
||||
findViewById(R.id.download_button).setEnabled(true); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,78 @@
|
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:app="http://schemas.android.com/apk/res-auto" |
||||
xmlns:tools="http://schemas.android.com/tools" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
tools:context=".DataActivity"> |
||||
|
||||
<TextView |
||||
android:id="@+id/headline" |
||||
android:layout_width="0dp" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginStart="16dp" |
||||
android:layout_marginTop="16dp" |
||||
android:text="@string/title_activity_data" |
||||
android:textSize="20sp" |
||||
android:textStyle="bold" |
||||
app:layout_constraintStart_toStartOf="parent" |
||||
app:layout_constraintTop_toTopOf="parent" /> |
||||
|
||||
<TextView |
||||
android:id="@+id/full_guide" |
||||
android:layout_width="0dp" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginStart="16dp" |
||||
android:layout_marginTop="16dp" |
||||
android:layout_marginEnd="16dp" |
||||
android:text="@string/guide_full_installation" |
||||
app:layout_constraintEnd_toEndOf="parent" |
||||
app:layout_constraintStart_toStartOf="parent" |
||||
app:layout_constraintTop_toBottomOf="@+id/headline" /> |
||||
|
||||
<TextView |
||||
android:id="@+id/spawn_guide" |
||||
android:layout_width="0dp" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginStart="16dp" |
||||
android:layout_marginTop="16dp" |
||||
android:layout_marginEnd="16dp" |
||||
android:text="@string/guide_shareware" |
||||
app:layout_constraintEnd_toEndOf="parent" |
||||
app:layout_constraintStart_toStartOf="parent" |
||||
app:layout_constraintTop_toBottomOf="@+id/check_data_button" /> |
||||
|
||||
<TextView |
||||
android:id="@+id/online_guide" |
||||
android:layout_width="0dp" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginStart="16dp" |
||||
android:layout_marginEnd="16dp" |
||||
android:layout_marginBottom="16dp" |
||||
android:text="@string/faq_link" |
||||
app:layout_constraintBottom_toBottomOf="parent" |
||||
app:layout_constraintEnd_toEndOf="parent" |
||||
app:layout_constraintStart_toStartOf="parent" /> |
||||
|
||||
<Button |
||||
android:id="@+id/download_button" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginTop="16dp" |
||||
android:onClick="sendDownloadRequest" |
||||
android:text="@string/download_spawn" |
||||
app:layout_constraintEnd_toEndOf="parent" |
||||
app:layout_constraintStart_toStartOf="parent" |
||||
app:layout_constraintTop_toBottomOf="@+id/spawn_guide" /> |
||||
|
||||
<Button |
||||
android:id="@+id/check_data_button" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginTop="16dp" |
||||
android:onClick="startGame" |
||||
android:text="@string/game_data_retry" |
||||
app:layout_constraintEnd_toEndOf="parent" |
||||
app:layout_constraintStart_toStartOf="parent" |
||||
app:layout_constraintTop_toBottomOf="@+id/full_guide" /> |
||||
</android.support.constraint.ConstraintLayout> |
||||
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<resources> |
||||
<color name="red">#FFFC0000</color> |
||||
<color name="darkred">#FF7E0000</color> |
||||
<color name="black">#FF000000</color> |
||||
<color name="white">#FFFFFFFF</color> |
||||
</resources> |
||||
@ -1,3 +1,11 @@
|
||||
<resources> |
||||
<string name="app_name">DevilutionX</string> |
||||
</resources> |
||||
<resources> |
||||
<string name="app_name">DevilutionX</string> |
||||
<string name="title_activity_data">Game Data</string> |
||||
<!-- Strings used for fragments for navigation --> |
||||
<string name="download_spawn">Download Shareware Data</string> |
||||
|
||||
<string name="guide_full_installation">To play the full version you must place DIABDAT.MPQ from the original game in Android/data/org.diasurgical.devilutionx/files.<br/>\n<br/>\nIf you don\'t have the original game then you can buy Diablo from <a href="https://www.gog.com/game/diablo">GOG.com.</a></string> |
||||
<string name="guide_shareware">Alternatively you can download the spawn version, to play the shareware portion of the game.</string> |
||||
<string name="faq_link">See the <a href="https://github.com/diasurgical/devilutionX/blob/master/docs/installing.md#installing">Installation Instructions</a> for more details.</string> |
||||
<string name="game_data_retry">Check again</string> |
||||
</resources> |
||||
|
||||
@ -0,0 +1,9 @@
|
||||
<resources xmlns:tools="http://schemas.android.com/tools"> |
||||
<!-- Base application theme. --> |
||||
<style name="Theme.MyApplication" parent="Theme.AppCompat.Light.DarkActionBar"> |
||||
<!-- Primary brand color. --> |
||||
<item name="colorPrimary">@color/red</item> |
||||
<item name="colorPrimaryDark">@color/darkred</item> |
||||
<item name="colorAccent">@color/darkred</item> |
||||
</style> |
||||
</resources> |
||||
Loading…
Reference in new issue