MainActivity.java 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package io.github.sdlpal;
  2. import android.content.Intent;
  3. import android.os.*;
  4. import android.support.v7.app.AppCompatActivity;
  5. import java.io.*;
  6. public class MainActivity extends AppCompatActivity {
  7. private static final String TAG = "sdlpal-debug";
  8. public static native void setAppPath(String basepath, String datapath, String cachepath);
  9. public static boolean crashed = false;
  10. @Override
  11. public void onCreate(Bundle savedInstanceState) {
  12. super.onCreate(savedInstanceState);
  13. System.loadLibrary("SDL2");
  14. System.loadLibrary("main");
  15. String dataPath = getApplicationContext().getFilesDir().getPath();
  16. String cachePath = getApplicationContext().getCacheDir().getPath();
  17. String sdcardState = Environment.getExternalStorageState();
  18. if (sdcardState.equals(Environment.MEDIA_MOUNTED)){
  19. setAppPath(Environment.getExternalStorageDirectory().getPath() + "/sdlpal/", dataPath, cachePath);
  20. } else {
  21. setAppPath("/sdcard/sdlpal/", dataPath, cachePath);
  22. }
  23. File runningFile = new File(cachePath + "/running");
  24. crashed = runningFile.exists();
  25. Intent intent;
  26. if (SettingsActivity.loadConfigFile() || crashed) {
  27. runningFile.delete();
  28. intent = new Intent(this, SettingsActivity.class);
  29. } else {
  30. intent = new Intent(this, PalActivity.class);
  31. }
  32. intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  33. startActivity(intent);
  34. finish();
  35. }
  36. @Override
  37. public void onDestroy() {
  38. super.onDestroy();
  39. }
  40. }