Guest User

Untitled

a guest
Nov 12th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.45 KB | None | 0 0
  1. protected void onCreate(Bundle savedInstanceState) {
  2. super.onCreate(savedInstanceState);
  3.  
  4. // Don't show an action bar or title
  5. requestWindowFeature(Window.FEATURE_NO_TITLE);
  6.  
  7. // If on android 3.0+ activate hardware acceleration
  8. if (Build.VERSION.SDK_INT >= 11) {
  9. getWindow().setFlags(WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
  10. WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
  11. }
  12.  
  13. // Apply previous setting about showing status bar or not
  14. applyFullScreen(isFullScreen());
  15.  
  16. // Check if screen rotation is locked in settings
  17. boolean isOrientationEnabled = false;
  18. try {
  19. isOrientationEnabled = Settings.System.getInt(getContentResolver(),
  20. Settings.System.ACCELEROMETER_ROTATION) == 1;
  21. } catch (SettingNotFoundException e) {
  22. Log.d(MAIN_ACTIVITY_TAG, "Settings could not be loaded");
  23. }
  24.  
  25. // If rotation isn't locked and it's a LARGE screen then add orientation changes based on sensor
  26. int screenLayout = getResources().getConfiguration().screenLayout
  27. & Configuration.SCREENLAYOUT_SIZE_MASK;
  28. if (((screenLayout == Configuration.SCREENLAYOUT_SIZE_LARGE)
  29. || (screenLayout == Configuration.SCREENLAYOUT_SIZE_XLARGE))
  30. && isOrientationEnabled) {
  31. setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
  32. }
  33.  
  34. setContentView(R.layout.activity_main);
  35.  
  36. ChangeLog cl = new ChangeLog(this);
  37. if (cl.isFirstRun()) {
  38. cl.getLogDialog().show();
  39. }
  40.  
  41. // Load webview with game
  42. mWebView = findViewById(R.id.mainWebView);
  43. WebSettings settings = mWebView.getSettings();
  44. settings.setJavaScriptEnabled(true);
  45. settings.setDomStorageEnabled(true);
  46. settings.setDatabaseEnabled(true);
  47. settings.setRenderPriority(RenderPriority.HIGH);
  48. settings.setDatabasePath(getFilesDir().getParentFile().getPath() + "/databases");
  49.  
  50. // If there is a previous instance restore it in the webview
  51. if (savedInstanceState != null) {
  52. mWebView.restoreState(savedInstanceState);
  53. } else {
  54. // Load webview with current Locale language
  55. mWebView.loadUrl("file:///android_asset/2048/index.html?lang=" + Locale.getDefault().getLanguage());
  56. }
  57.  
  58. Toast.makeText(getApplication(), R.string.toggle_fullscreen, Toast.LENGTH_SHORT).show();
  59. // Set fullscreen toggle on webview LongClick
  60. mWebView.setOnTouchListener((v, event) -> {
  61. // Implement a long touch action by comparing
  62. // time between action up and action down
  63. long currentTime = System.currentTimeMillis();
  64. if ((event.getAction() == MotionEvent.ACTION_UP)
  65. && (Math.abs(currentTime - mLastTouch) > mTouchThreshold)) {
  66. boolean toggledFullScreen = !isFullScreen();
  67. saveFullScreen(toggledFullScreen);
  68. applyFullScreen(toggledFullScreen);
  69. } else if (event.getAction() == MotionEvent.ACTION_DOWN) {
  70. mLastTouch = currentTime;
  71. }
  72. // return so that the event isn't consumed but used
  73. // by the webview as well
  74. return false;
  75. });
  76.  
  77. pressBackToast = Toast.makeText(getApplicationContext(), R.string.press_back_again_to_exit,
  78. Toast.LENGTH_SHORT);
  79. }
Add Comment
Please, Sign In to add comment