mirror of
https://github.com/libretro/RetroArch
synced 2025-01-29 18:32:44 +00:00
Add ProgressBar for asset extraction.
This commit is contained in:
parent
2dcc133cab
commit
dd2d8009ca
22
android/phoenix/res/layout/assets.xml
Normal file
22
android/phoenix/res/layout/assets.xml
Normal file
@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/assets_textview"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:text="@string/extracting_assets_please_wait_" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/assets_progress"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center" />
|
||||
|
||||
|
||||
</LinearLayout>
|
@ -9,5 +9,6 @@
|
||||
<string name="report_refreshrate">Report Refresh Rate</string>
|
||||
<string name="key_bind_detect">Detect</string>
|
||||
<string name="optimal_settings_device">Optimal device settings</string>
|
||||
<string name="extracting_assets_please_wait_">Extracting assets, please wait ...</string>
|
||||
|
||||
</resources>
|
||||
|
@ -113,7 +113,6 @@ public class CoreSelection extends Activity implements
|
||||
Settings.Secure.DEFAULT_INPUT_METHOD);
|
||||
|
||||
MainMenuActivity.updateConfigFile();
|
||||
MainMenuActivity.waitAssetThread();
|
||||
|
||||
switch (requestCode) {
|
||||
case ACTIVITY_LOAD_ROM:
|
||||
|
@ -68,7 +68,6 @@ public class HistorySelection extends Activity implements
|
||||
Settings.Secure.DEFAULT_INPUT_METHOD);
|
||||
|
||||
MainMenuActivity.updateConfigFile();
|
||||
MainMenuActivity.waitAssetThread();
|
||||
|
||||
Toast.makeText(this, "Loading: [" + gamePath + "] ...",
|
||||
Toast.LENGTH_SHORT).show();
|
||||
|
@ -6,6 +6,7 @@ import org.retroarch.R;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.SharedPreferences;
|
||||
@ -14,6 +15,7 @@ import android.content.res.AssetManager;
|
||||
import android.media.AudioManager;
|
||||
import android.media.AudioTrack;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.preference.PreferenceActivity;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
@ -24,18 +26,6 @@ import android.widget.Toast;
|
||||
public class MainMenuActivity extends PreferenceActivity {
|
||||
private static MainMenuActivity instance = null;
|
||||
static private final String TAG = "MainMenu";
|
||||
static private Thread assetThread = null;
|
||||
|
||||
public static void waitAssetThread() {
|
||||
if (assetThread != null) {
|
||||
try {
|
||||
assetThread.join();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
assetThread = null;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
@ -46,18 +36,11 @@ public class MainMenuActivity extends PreferenceActivity {
|
||||
PreferenceManager.setDefaultValues(this, R.xml.prefs, false);
|
||||
this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
|
||||
|
||||
// Extracting assets appears to take considerable amount of time, so
|
||||
// move extraction to a thread.
|
||||
assetThread = new Thread(new Runnable() {
|
||||
public void run() {
|
||||
extractAssets();
|
||||
}
|
||||
});
|
||||
assetThread.start();
|
||||
|
||||
SharedPreferences prefs = PreferenceManager
|
||||
.getDefaultSharedPreferences(getBaseContext());
|
||||
|
||||
extractAssets();
|
||||
|
||||
if (!prefs.getBoolean("first_time_refreshrate_calculate", false)) {
|
||||
prefs.edit().putBoolean("first_time_refreshrate_calculate", true)
|
||||
.commit();
|
||||
@ -66,7 +49,7 @@ public class MainMenuActivity extends PreferenceActivity {
|
||||
AlertDialog.Builder alert = new AlertDialog.Builder(this)
|
||||
.setTitle("Welcome to RetroArch")
|
||||
.setMessage(
|
||||
"This is your first time starting up RetroArch. RetroArch will now be preconfigured for the best possible gameplay experience. Please be aware that it might take some time until all shader and overlay assets are extracted...")
|
||||
"This is your first time starting up RetroArch. RetroArch will now be preconfigured for the best possible gameplay experience. Please be aware that it might take some time until all shader and overlay assets are extracted ...")
|
||||
.setPositiveButton("OK",
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
@ -85,7 +68,7 @@ public class MainMenuActivity extends PreferenceActivity {
|
||||
AlertDialog.Builder alert = new AlertDialog.Builder(this)
|
||||
.setTitle("Welcome to RetroArch")
|
||||
.setMessage(
|
||||
"This is your first time starting up RetroArch. Please be aware that it might take some time until all shader and overlay assets are extracted...")
|
||||
"This is your first time starting up RetroArch. Please be aware that it might take some time until all shader and overlay assets are extracted ...")
|
||||
.setPositiveButton("OK", null);
|
||||
alert.show();
|
||||
}
|
||||
@ -370,17 +353,21 @@ public class MainMenuActivity extends PreferenceActivity {
|
||||
writer.close();
|
||||
}
|
||||
}
|
||||
|
||||
private void extractAssets() {
|
||||
|
||||
private int getVersionCode() {
|
||||
int version = 0;
|
||||
try {
|
||||
version = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode;
|
||||
} catch (NameNotFoundException e) {
|
||||
// weird exception, shouldn't happen
|
||||
}
|
||||
|
||||
|
||||
return version;
|
||||
}
|
||||
|
||||
private boolean areAssetsExtracted() {
|
||||
int version = getVersionCode();
|
||||
|
||||
try {
|
||||
AssetManager assets = getAssets();
|
||||
String dataDir = getApplicationInfo().dataDir;
|
||||
File cacheVersion = new File(dataDir, ".cacheversion");
|
||||
if (cacheVersion != null && cacheVersion.isFile()
|
||||
@ -397,9 +384,22 @@ public class MainMenuActivity extends PreferenceActivity {
|
||||
|
||||
if (currentCacheVersion == version) {
|
||||
Log.i("ASSETS", "Assets already extracted, skipping...");
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "Failed to extract assets to cache.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void extractAssetsThread() {
|
||||
try {
|
||||
AssetManager assets = getAssets();
|
||||
String dataDir = getApplicationInfo().dataDir;
|
||||
File cacheVersion = new File(dataDir, ".cacheversion");
|
||||
|
||||
// extractAssets(assets, cacheDir, "", 0);
|
||||
Log.i("ASSETS", "Extracting shader assets now ...");
|
||||
@ -418,22 +418,51 @@ public class MainMenuActivity extends PreferenceActivity {
|
||||
|
||||
DataOutputStream outputCacheVersion = new DataOutputStream(
|
||||
new FileOutputStream(cacheVersion, false));
|
||||
outputCacheVersion.writeInt(version);
|
||||
outputCacheVersion.writeInt(getVersionCode());
|
||||
outputCacheVersion.close();
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "Failed to extract assets to cache.");
|
||||
}
|
||||
}
|
||||
|
||||
private void extractAssets() {
|
||||
if (areAssetsExtracted())
|
||||
return;
|
||||
|
||||
final Dialog dialog = new Dialog(this);
|
||||
final Handler handler = new Handler();
|
||||
dialog.setContentView(R.layout.assets);
|
||||
dialog.setCancelable(false);
|
||||
|
||||
// Java is fun :)
|
||||
Thread assetsThread = new Thread(new Runnable() {
|
||||
public void run() {
|
||||
extractAssetsThread();
|
||||
handler.post(new Runnable() {
|
||||
public void run() {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
assetsThread.start();
|
||||
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
boolean detectDevice(boolean show_dialog) {
|
||||
boolean retval = false;
|
||||
|
||||
boolean mentionPlayStore = !android.os.Build.MODEL.equals("OUYA Console");
|
||||
final String message = "The ideal configuration options for your device will now be preconfigured.\n\nNOTE: For optimal performance, turn off Google Account sync, " +
|
||||
(mentionPlayStore ? "Google Play Store auto-updates, " : "") +
|
||||
"GPS and Wi-Fi in your Android settings menu.";
|
||||
|
||||
Log.i("Device MODEL", android.os.Build.MODEL);
|
||||
if (android.os.Build.MODEL.equals("SHIELD")) {
|
||||
AlertDialog.Builder alert = new AlertDialog.Builder(this)
|
||||
.setTitle("NVidia Shield detected")
|
||||
.setMessage(
|
||||
"The ideal configuration options for your device will now be preconfigured.\nNOTE: For optimal performance, turn off Google Account sync, Google Play Store auto-updates, GPS and Wifi in your Android settings menu.")
|
||||
.setMessage(message)
|
||||
.setPositiveButton("OK",
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
@ -457,8 +486,7 @@ public class MainMenuActivity extends PreferenceActivity {
|
||||
} else if (android.os.Build.MODEL.equals("OUYA Console")) {
|
||||
AlertDialog.Builder alert = new AlertDialog.Builder(this)
|
||||
.setTitle("OUYA detected")
|
||||
.setMessage(
|
||||
"The ideal configuration options for your device will now be preconfigured.\nNOTE: For optimal performance, turn off Google Account sync, GPS and Wifi in your Android settings menu.")
|
||||
.setMessage(message)
|
||||
.setPositiveButton("OK",
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
@ -480,8 +508,7 @@ public class MainMenuActivity extends PreferenceActivity {
|
||||
} else if (android.os.Build.ID.equals("JSS15J")) {
|
||||
AlertDialog.Builder alert = new AlertDialog.Builder(this)
|
||||
.setTitle("Nexus 7 2013 detected")
|
||||
.setMessage(
|
||||
"The ideal configuration options for your device will now be preconfigured.\nNOTE: For optimal performance, turn off Google Account sync, Google Play Store auto-updates, GPS and Wifi in your Android settings menu.")
|
||||
.setMessage(message)
|
||||
.setPositiveButton("OK",
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
|
@ -7,7 +7,6 @@ import android.os.Bundle;
|
||||
public class OverlayActivity extends DirectoryActivity {
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
MainMenuActivity.waitAssetThread();
|
||||
File overlayDir = new File(getBaseContext().getApplicationInfo().dataDir, "overlays");
|
||||
if (overlayDir.exists())
|
||||
super.setStartDirectory(overlayDir.getAbsolutePath());
|
||||
|
@ -7,7 +7,6 @@ import android.os.Bundle;
|
||||
public class ShaderActivity extends DirectoryActivity {
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
MainMenuActivity.waitAssetThread();
|
||||
File shaderDir = new File(getBaseContext().getApplicationInfo().dataDir, "shaders_glsl");
|
||||
if (shaderDir.exists())
|
||||
super.setStartDirectory(shaderDir.getAbsolutePath());
|
||||
|
Loading…
x
Reference in New Issue
Block a user