[Android] Clean up SplashActivity.java
This commit is contained in:
parent
1e03eacc4e
commit
3a0117c3da
|
@ -1,10 +1,8 @@
|
||||||
package emu.project64;
|
package emu.project64;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.google.android.gms.analytics.HitBuilders;
|
|
||||||
|
|
||||||
import emu.project64.R;
|
import emu.project64.R;
|
||||||
import emu.project64.jni.NativeExports;
|
import emu.project64.jni.NativeExports;
|
||||||
import emu.project64.jni.SettingsID;
|
import emu.project64.jni.SettingsID;
|
||||||
|
@ -13,9 +11,7 @@ import emu.project64.task.ExtractAssetsTask;
|
||||||
import emu.project64.task.ExtractAssetsTask.ExtractAssetsListener;
|
import emu.project64.task.ExtractAssetsTask.ExtractAssetsListener;
|
||||||
import emu.project64.task.ExtractAssetsTask.Failure;
|
import emu.project64.task.ExtractAssetsTask.Failure;
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.app.Activity;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.AlertDialog;
|
|
||||||
import android.app.AlertDialog.Builder;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.DialogInterface.OnClickListener;
|
import android.content.DialogInterface.OnClickListener;
|
||||||
|
@ -23,67 +19,52 @@ import android.content.pm.ActivityInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.support.v4.app.ActivityCompat;
|
import androidx.annotation.NonNull;
|
||||||
import android.support.v4.app.ActivityCompat.OnRequestPermissionsResultCallback;
|
import androidx.core.app.ActivityCompat;
|
||||||
import android.support.v4.content.ContextCompat;
|
import androidx.core.app.ActivityCompat.OnRequestPermissionsResultCallback;
|
||||||
|
import androidx.core.content.ContextCompat;
|
||||||
|
import androidx.appcompat.app.AlertDialog;
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import android.text.Html;
|
import android.text.Html;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.Window;
|
|
||||||
import android.view.WindowManager.LayoutParams;
|
import android.view.WindowManager.LayoutParams;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
/**
|
public class SplashActivity extends AppCompatActivity implements ExtractAssetsListener, OnRequestPermissionsResultCallback
|
||||||
* The main activity that presents the splash screen, extracts the assets if necessary, and launches
|
|
||||||
* the main menu activity.
|
|
||||||
*/
|
|
||||||
public class SplashActivity extends Activity implements ExtractAssetsListener, OnRequestPermissionsResultCallback
|
|
||||||
{
|
{
|
||||||
static final int PERMISSION_REQUEST = 177;
|
static final int PERMISSION_REQUEST = 177;
|
||||||
static final int NUM_PERMISSIONS = 2;
|
static final int NUM_PERMISSIONS = 2;
|
||||||
|
private int TOTAL_ASSETS = 100;
|
||||||
/**
|
|
||||||
* Asset version number, used to determine stale assets. Increment this number every time the
|
|
||||||
* assets are updated on disk.
|
|
||||||
*/
|
|
||||||
private static final int ASSET_VERSION = 3;
|
|
||||||
|
|
||||||
/** The total number of assets to be extracted (for computing progress %). */
|
|
||||||
private static final int TOTAL_ASSETS = 89;
|
|
||||||
|
|
||||||
/** The minimum duration that the splash screen is shown, in milliseconds. */
|
|
||||||
private static final int SPLASH_DELAY = 2000;
|
private static final int SPLASH_DELAY = 2000;
|
||||||
|
|
||||||
/**
|
|
||||||
* The subdirectory within the assets directory to extract. A subdirectory is necessary to avoid
|
|
||||||
* extracting all the default system assets in addition to ours.
|
|
||||||
*/
|
|
||||||
private static final String SOURCE_DIR = "project64_data";
|
private static final String SOURCE_DIR = "project64_data";
|
||||||
|
|
||||||
private static boolean mInit = false;
|
private static boolean mInit = false;
|
||||||
private static boolean mAppInit = false;
|
private static boolean mAppInit = false;
|
||||||
|
|
||||||
/** The text view that displays extraction progress info. */
|
private TextView mTextView;
|
||||||
private static TextView mTextView;
|
|
||||||
|
|
||||||
/** The running count of assets extracted. */
|
|
||||||
private int mAssetsExtracted;
|
private int mAssetsExtracted;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate( Bundle savedInstanceState )
|
public void onCreate( Bundle savedInstanceState )
|
||||||
{
|
{
|
||||||
super.onCreate( savedInstanceState );
|
super.onCreate( savedInstanceState );
|
||||||
Window window = getWindow();
|
|
||||||
|
|
||||||
// Don't let the activity sleep in the middle of extraction
|
getWindow().setFlags( LayoutParams.FLAG_KEEP_SCREEN_ON, LayoutParams.FLAG_KEEP_SCREEN_ON );
|
||||||
window.setFlags( LayoutParams.FLAG_KEEP_SCREEN_ON, LayoutParams.FLAG_KEEP_SCREEN_ON );
|
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
||||||
|
|
||||||
// Lay out the content
|
try
|
||||||
|
{
|
||||||
setContentView( R.layout.splash_activity );
|
setContentView( R.layout.splash_activity );
|
||||||
|
}
|
||||||
|
catch (android.view.InflateException e)
|
||||||
|
{
|
||||||
|
Log.e("SplashActivity", "Resource NOT found");
|
||||||
|
return;
|
||||||
|
}
|
||||||
((TextView) findViewById( R.id.versionText )).setText(NativeExports.appVersion());
|
((TextView) findViewById( R.id.versionText )).setText(NativeExports.appVersion());
|
||||||
mTextView = (TextView) findViewById( R.id.mainText );
|
mTextView = (TextView) findViewById( R.id.mainText );
|
||||||
|
|
||||||
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
|
||||||
|
|
||||||
if ((ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED &&
|
if ((ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED &&
|
||||||
ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) ||
|
ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) ||
|
||||||
!AndroidDevice.IS_LOLLIPOP)
|
!AndroidDevice.IS_LOLLIPOP)
|
||||||
|
@ -142,14 +123,7 @@ public class SplashActivity extends Activity implements ExtractAssetsListener, O
|
||||||
InitProject64();
|
InitProject64();
|
||||||
}
|
}
|
||||||
|
|
||||||
((Project64Application) getApplication()).getDefaultTracker().send(new HitBuilders.EventBuilder()
|
Log.i( "Splash", "extractAssetsTaskLauncher - startup");
|
||||||
.setCategory("start")
|
|
||||||
.setLabel(NativeExports.appVersion())
|
|
||||||
.build());
|
|
||||||
|
|
||||||
// Extract the assets in a separate thread and launch the menu activity
|
|
||||||
// Handler.postDelayed ensures this runs only after activity has resumed
|
|
||||||
Log.e( "Splash", "extractAssetsTaskLauncher - startup");
|
|
||||||
final Handler handler = new Handler();
|
final Handler handler = new Handler();
|
||||||
if (!mAppInit || NativeExports.UISettingsLoadDword(UISettingID.Asserts_Version.getValue()) != ASSET_VERSION)
|
if (!mAppInit || NativeExports.UISettingsLoadDword(UISettingID.Asserts_Version.getValue()) != ASSET_VERSION)
|
||||||
{
|
{
|
||||||
|
@ -266,28 +240,53 @@ public class SplashActivity extends Activity implements ExtractAssetsListener, O
|
||||||
mAppInit = true;
|
mAppInit = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Runnable that launches the non-UI thread from the UI thread after the activity has resumed. */
|
|
||||||
private final Runnable startGalleryLauncher = new Runnable()
|
private final Runnable startGalleryLauncher = new Runnable()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
// Assets already extracted, just launch gallery activity
|
|
||||||
Intent intent = new Intent( SplashActivity.this, GalleryActivity.class );
|
Intent intent = new Intent( SplashActivity.this, GalleryActivity.class );
|
||||||
SplashActivity.this.startActivity( intent );
|
SplashActivity.this.startActivity( intent );
|
||||||
|
|
||||||
// We never want to come back to this activity, so finish it
|
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private boolean CountTotalAssetFiles(String path)
|
||||||
|
{
|
||||||
|
String [] list;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
list = getAssets().list(path);
|
||||||
|
if (list.length > 0)
|
||||||
|
{
|
||||||
|
for (String file : list)
|
||||||
|
{
|
||||||
|
if (!CountTotalAssetFiles(path + "/" + file))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TOTAL_ASSETS += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
private final Runnable extractAssetsTaskLauncher = new Runnable()
|
private final Runnable extractAssetsTaskLauncher = new Runnable()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
Log.e( "Splash", "extractAssetsTaskLauncher - start");
|
Log.e( "Splash", "extractAssetsTaskLauncher - start");
|
||||||
// Extract and merge the assets if they are out of date
|
TOTAL_ASSETS = 0;
|
||||||
|
CountTotalAssetFiles(SOURCE_DIR);
|
||||||
mAssetsExtracted = 0;
|
mAssetsExtracted = 0;
|
||||||
new ExtractAssetsTask( getAssets(), SOURCE_DIR, AndroidDevice.PACKAGE_DIRECTORY, SplashActivity.this ).execute();
|
new ExtractAssetsTask( getAssets(), SOURCE_DIR, AndroidDevice.PACKAGE_DIRECTORY, SplashActivity.this ).execute();
|
||||||
}
|
}
|
||||||
|
@ -311,8 +310,6 @@ public class SplashActivity extends Activity implements ExtractAssetsListener, O
|
||||||
{
|
{
|
||||||
InitProject64();
|
InitProject64();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extraction succeeded, record new asset version and merge cheats
|
|
||||||
mTextView.setText( R.string.assetExtractor_finished );
|
mTextView.setText( R.string.assetExtractor_finished );
|
||||||
NativeExports.UISettingsSaveDword(UISettingID.Asserts_Version.getValue(), ASSET_VERSION);
|
NativeExports.UISettingsSaveDword(UISettingID.Asserts_Version.getValue(), ASSET_VERSION);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue