Skip to content

Commit

Permalink
make screen 'rotatable' only on tablets
Browse files Browse the repository at this point in the history
  • Loading branch information
uberspot committed Apr 13, 2014
1 parent 6f21f04 commit 86f180e
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 20 deletions.
Binary file modified 2048.apk
Binary file not shown.
4 changes: 2 additions & 2 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.uberspot.a2048"
android:versionCode="9"
android:versionName="1.8" >
android:versionCode="13"
android:versionName="1.88" >

<uses-sdk
android:minSdkVersion="10"
Expand Down
2 changes: 1 addition & 1 deletion assets/2048
Submodule 2048 updated from f732d4 to a00c9b
61 changes: 44 additions & 17 deletions src/com/uberspot/a2048/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.uberspot.a2048;

import com.uberspot.a2048.R;

import android.os.Bundle;
import android.preference.PreferenceManager;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.provider.Settings;
import android.provider.Settings.SettingNotFoundException;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
Expand All @@ -29,32 +30,54 @@ public class MainActivity extends Activity {
private long mLastTouch;
private static final long mTouchThreshold = 2000;
private Toast pressBackToast;

@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);


// Don't show an action bar or title
requestWindowFeature(Window.FEATURE_NO_TITLE);

// 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) { }

// 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);


// Load webview with game
mWebView = (WebView) findViewById(R.id.mainWebView);
WebSettings settings = mWebView.getSettings();
String packageName = getPackageName();
settings.setJavaScriptEnabled(true);
settings.setDomStorageEnabled(true);
settings.setDatabaseEnabled(true);
settings.setDatabasePath("/data/data/" + packageName + "/databases");


// If there is a previous instance restore it in the webview
if (savedInstanceState != null) {
mWebView.restoreState(savedInstanceState);
} else {
mWebView.loadUrl("file:///android_asset/2048/index.html");
}
Toast.makeText(getApplication(),

Toast.makeText(getApplication(),
R.string.toggle_fullscreen, Toast.LENGTH_SHORT).show();
// Set fullscreen toggle on webview LongClick
mWebView.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
Expand All @@ -75,23 +98,23 @@ public boolean onTouch(View v, MotionEvent event) {
// by the webview as well
return false;
}});
pressBackToast = Toast.makeText(getApplicationContext(),

pressBackToast = Toast.makeText(getApplicationContext(),
R.string.press_back_again_to_exit, Toast.LENGTH_SHORT);
}

@Override
protected void onSaveInstanceState(Bundle outState) {
mWebView.saveState(outState);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
//getMenuInflater().inflate(R.menu.main, menu);
return true;
}

private void saveFullScreen(boolean isFullScreen) {
// save in preferences
SharedPreferences.Editor editor = PreferenceManager
Expand All @@ -105,7 +128,11 @@ private boolean isFullScreen() {
.getDefaultSharedPreferences(this)
.getBoolean(IS_FULLSCREEN_PREF, DEF_FULLSCREEN);
}


/**
* Toggles the activitys fullscreen mode by setting the corresponding window flag
* @param isFullScreen
*/
private void applyFullScreen(boolean isFullScreen) {
if(isFullScreen) {
getWindow().clearFlags(LayoutParams.FLAG_FULLSCREEN);
Expand All @@ -114,12 +141,12 @@ private void applyFullScreen(boolean isFullScreen) {
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
}

@Override
public void onBackPressed() {
long currentTime = System.currentTimeMillis();
Expand Down

0 comments on commit 86f180e

Please sign in to comment.