Skip to content

Commit

Permalink
clean up useless values folders, add greek translation, clean up code…
Browse files Browse the repository at this point in the history
… style in java code
  • Loading branch information
uberspot committed Aug 20, 2014
1 parent 10a5206 commit 8a04f5d
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 163 deletions.
9 changes: 9 additions & 0 deletions res/values-el/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<string name="app_name">2048</string>
<string name="action_settings">Ρυθμίσεις</string>
<string name="press_back_again_to_exit">Πατήστε \'πίσω\' ξανά για έξοδο</string>
<string name="toggle_fullscreen">Πατήστε για ώρα την οθόνη για να μεγιστοποίηση/σμίκρυνση παραθύρου</string>

</resources>
8 changes: 0 additions & 8 deletions res/values-sw600dp/dimens.xml

This file was deleted.

11 changes: 0 additions & 11 deletions res/values-v11/styles.xml

This file was deleted.

12 changes: 0 additions & 12 deletions res/values-v14/styles.xml

This file was deleted.

264 changes: 132 additions & 132 deletions src/com/uberspot/a2048/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

package com.uberspot.a2048;

import android.annotation.SuppressLint;
Expand All @@ -24,146 +25,145 @@

public class MainActivity extends Activity {

private WebView mWebView;
private long mLastBackPress;
private static final long mBackPressThreshold = 3500;
private static final String IS_FULLSCREEN_PREF = "is_fullscreen_pref";
private static boolean DEF_FULLSCREEN = true;
private long mLastTouch;
private static final long mTouchThreshold = 2000;
private Toast pressBackToast;

@SuppressLint({ "SetJavaScriptEnabled", "NewApi", "ShowToast" })
@Override
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,
private WebView mWebView;
private long mLastBackPress;
private static final long mBackPressThreshold = 3500;
private static final String IS_FULLSCREEN_PREF = "is_fullscreen_pref";
private static boolean DEF_FULLSCREEN = true;
private long mLastTouch;
private static final long mTouchThreshold = 2000;
private Toast pressBackToast;

@SuppressLint({ "SetJavaScriptEnabled", "NewApi", "ShowToast" })
@Override
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());
// Apply previous setting about showing status bar or not
applyFullScreen(isFullScreen());

// Check if screen rotation is locked in settings
boolean isOrientationEnabled = false;
// 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.setRenderPriority(RenderPriority.HIGH);
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(),
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) {
// 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);
}

@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
.getDefaultSharedPreferences(this).edit();
editor.putBoolean(IS_FULLSCREEN_PREF, isFullScreen);
editor.commit();
}

private boolean isFullScreen() {
return PreferenceManager
.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);
} else {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
}

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

@Override
public void onBackPressed() {
long currentTime = System.currentTimeMillis();
if (Math.abs(currentTime - mLastBackPress) > mBackPressThreshold) {
pressBackToast.show();
mLastBackPress = currentTime;
} else {
pressBackToast.cancel();
super.onBackPressed();
}
}
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.setRenderPriority(RenderPriority.HIGH);
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(), 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) {
// 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);
}

@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.getDefaultSharedPreferences(this).edit();
editor.putBoolean(IS_FULLSCREEN_PREF, isFullScreen);
editor.commit();
}

private boolean isFullScreen() {
return PreferenceManager.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);
} else {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
}

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

@Override
public void onBackPressed() {
long currentTime = System.currentTimeMillis();
if (Math.abs(currentTime - mLastBackPress) > mBackPressThreshold) {
pressBackToast.show();
mLastBackPress = currentTime;
} else {
pressBackToast.cancel();
super.onBackPressed();
}
}
}

0 comments on commit 8a04f5d

Please sign in to comment.