Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- // Don't show an action bar or title
- requestWindowFeature(Window.FEATURE_NO_TITLE);
- // If on android 3.0+ activate hardware acceleration
- if (Build.VERSION.SDK_INT >= 11) {
- getWindow().setFlags(WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
- WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
- }
- // Apply previous setting about showing status bar or not
- applyFullScreen(isFullScreen());
- // Check if screen rotation is locked in settings
- boolean isOrientationEnabled = false;
- try {
- isOrientationEnabled = Settings.System.getInt(getContentResolver(),
- Settings.System.ACCELEROMETER_ROTATION) == 1;
- } catch (SettingNotFoundException e) {
- Log.d(MAIN_ACTIVITY_TAG, "Settings could not be loaded");
- }
- // If rotation isn't locked and it's a LARGE screen then add orientation changes based on sensor
- int screenLayout = getResources().getConfiguration().screenLayout
- & Configuration.SCREENLAYOUT_SIZE_MASK;
- if (((screenLayout == Configuration.SCREENLAYOUT_SIZE_LARGE)
- || (screenLayout == Configuration.SCREENLAYOUT_SIZE_XLARGE))
- && isOrientationEnabled) {
- setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
- }
- setContentView(R.layout.activity_main);
- ChangeLog cl = new ChangeLog(this);
- if (cl.isFirstRun()) {
- cl.getLogDialog().show();
- }
- // Load webview with game
- mWebView = findViewById(R.id.mainWebView);
- WebSettings settings = mWebView.getSettings();
- settings.setJavaScriptEnabled(true);
- settings.setDomStorageEnabled(true);
- settings.setDatabaseEnabled(true);
- settings.setRenderPriority(RenderPriority.HIGH);
- settings.setDatabasePath(getFilesDir().getParentFile().getPath() + "/databases");
- // If there is a previous instance restore it in the webview
- if (savedInstanceState != null) {
- mWebView.restoreState(savedInstanceState);
- } else {
- // Load webview with current Locale language
- mWebView.loadUrl("file:///android_asset/2048/index.html?lang=" + Locale.getDefault().getLanguage());
- }
- Toast.makeText(getApplication(), R.string.toggle_fullscreen, Toast.LENGTH_SHORT).show();
- // Set fullscreen toggle on webview LongClick
- mWebView.setOnTouchListener((v, event) -> {
- // Implement a long touch action by comparing
- // time between action up and action down
- long currentTime = System.currentTimeMillis();
- if ((event.getAction() == MotionEvent.ACTION_UP)
- && (Math.abs(currentTime - mLastTouch) > mTouchThreshold)) {
- boolean toggledFullScreen = !isFullScreen();
- saveFullScreen(toggledFullScreen);
- applyFullScreen(toggledFullScreen);
- } else if (event.getAction() == MotionEvent.ACTION_DOWN) {
- mLastTouch = currentTime;
- }
- // return so that the event isn't consumed but used
- // by the webview as well
- return false;
- });
- pressBackToast = Toast.makeText(getApplicationContext(), R.string.press_back_again_to_exit,
- Toast.LENGTH_SHORT);
- }
Add Comment
Please, Sign In to add comment