diff --git a/app/build.gradle b/app/build.gradle index 726696e..64a0202 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -13,8 +13,8 @@ android { applicationId "de.tobiasbielefeld.brickgames" minSdkVersion 9 targetSdkVersion 24 - versionCode 13 - versionName '2.1.1' + versionCode 14 + versionName '2.2' } buildTypes { release { diff --git a/app/src/main/assets/changelog.html b/app/src/main/assets/changelog.html index 40b1d70..2d1da4e 100644 --- a/app/src/main/assets/changelog.html +++ b/app/src/main/assets/changelog.html @@ -1,3 +1,9 @@ +
+ - Added landscape support + - Added an entry in the settings to set a fixed orientation +
+
- Changed the info text for the physical keyboard input
diff --git a/app/src/main/java/de/tobiasbielefeld/brickgames/classes/CustomAppCompatActivity.java b/app/src/main/java/de/tobiasbielefeld/brickgames/classes/CustomAppCompatActivity.java
index dc6fb6a..c0b08c7 100644
--- a/app/src/main/java/de/tobiasbielefeld/brickgames/classes/CustomAppCompatActivity.java
+++ b/app/src/main/java/de/tobiasbielefeld/brickgames/classes/CustomAppCompatActivity.java
@@ -56,14 +56,14 @@ protected void attachBaseContext(Context base) {
@Override
public void onResume() {
super.onResume();
- // setOrientation(this);
+ setOrientation(this);
showOrHideStatusBar(this);
}
/*
* Sets the screen orientation according to the settings. It is called from onResume().
* @param activity The activity to apply the orientation on.
-
+ */
public static void setOrientation(Activity activity) {
switch (savedData.getString("pref_key_orientation", "1")) {
case "1": //follow system settings
@@ -79,17 +79,19 @@ public static void setOrientation(Activity activity) {
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
break;
}
- }*/
+ }
/**
* Hides the status bar according to the settings. It is called from onResume().
* @param activity The activity to apply the changes on.
*/
public void showOrHideStatusBar(Activity activity) {
- if (savedData.getBoolean(getString(R.string.prefKeyHideStatusBar), false))
+ if (savedData.getBoolean("prefKeyHideStatusBar", true)) {
activity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
- else
+ }
+ else {
activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
+ }
}
}
diff --git a/app/src/main/java/de/tobiasbielefeld/brickgames/ui/Main.java b/app/src/main/java/de/tobiasbielefeld/brickgames/ui/Main.java
index c194dbf..008522d 100644
--- a/app/src/main/java/de/tobiasbielefeld/brickgames/ui/Main.java
+++ b/app/src/main/java/de/tobiasbielefeld/brickgames/ui/Main.java
@@ -21,6 +21,7 @@
import android.annotation.TargetApi;
import android.content.Intent;
import android.content.pm.ActivityInfo;
+import android.content.res.Configuration;
import android.media.AudioAttributes;
import android.media.AudioManager;
import android.media.SoundPool;
@@ -36,6 +37,7 @@
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
+import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
@@ -50,7 +52,6 @@
import de.tobiasbielefeld.brickgames.surfaceViews.GameView2;
import de.tobiasbielefeld.brickgames.ui.about.AboutActivity;
-import static android.view.View.GONE;
import static de.tobiasbielefeld.brickgames.SharedData.*;
import static de.tobiasbielefeld.brickgames.classes.Game.*;
@@ -79,13 +80,13 @@ public class Main extends CustomAppCompatActivity implements Runnable, View.OnTo
LinearLayout linearLayoutGameField;
LinearLayout linearLayoutTexts ;
LinearLayout linearLayoutGameExtra ;
- LinearLayout linearLayoutButtons ;
+ LinearLayout layoutButtons1;
+ FrameLayout layoutButtons2;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
- setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
createSoundPool();
mLinearLayoutBackground = (LinearLayout) findViewById(R.id.linearLayoutBackground); //the whole display
@@ -94,7 +95,8 @@ public void onCreate(Bundle savedInstanceState) {
linearLayoutGameField = (LinearLayout) findViewById(R.id.linearLayoutGameField);
linearLayoutTexts = (LinearLayout) findViewById(R.id.linearLayoutTexts);
linearLayoutGameExtra = (LinearLayout) findViewById(R.id.linearLayoutGameExtra);
- linearLayoutButtons = (LinearLayout) findViewById(R.id.linearLayoutButtons);
+ layoutButtons1 = (LinearLayout) findViewById(R.id.layoutButtons1);
+ layoutButtons2 = (FrameLayout) findViewById(R.id.layoutButtons2);
vibration = (Vibrator) getSystemService(VIBRATOR_SERVICE);
mToolbar = (Toolbar) findViewById(R.id.toolbar);
@@ -142,8 +144,6 @@ public void onCreate(Bundle savedInstanceState) {
mButton[i].setOnTouchListener(this);
}
- //linearLayoutButtons.setOnTouchListener(this);
-
setBackgroundColor();
changeButtonColor();
@@ -154,7 +154,11 @@ public void onCreate(Bundle savedInstanceState) {
mLinearLayoutBackground.post(new Runnable() {
@Override
public void run() {
- setUpDimensions();
+ if (getResources().getConfiguration().orientation==Configuration.ORIENTATION_PORTRAIT) {
+ setUpDimensions();
+ } else {
+ setUpDimensionsLandscape();
+ }
}
});
@@ -221,8 +225,13 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (data.getIntExtra(getString(R.string.prefKeyHideStatusBar), 0) > 0)
showOrHideStatusBar(this);
- if (data.getIntExtra(getString(R.string.prefKeyEnableKeyboardInput),0) > 0)
- setUpDimensions();
+ if (data.getIntExtra(getString(R.string.prefKeyEnableKeyboardInput),0) > 0) {
+ if (getResources().getConfiguration().orientation==Configuration.ORIENTATION_PORTRAIT) {
+ setUpDimensions();
+ } else {
+ setUpDimensionsLandscape();
+ }
+ }
}
}
@@ -576,6 +585,41 @@ public void handleMessage(Message msg) {
}
}
+ private void setUpDimensionsLandscape(){
+ int marginTop;
+ int totalWidth = mLinearLayoutBackground.getWidth();
+ int totalHeight = mLinearLayoutBackground.getHeight();
+
+ width = (int)( (totalWidth * 0.225)/ (FIELD_WIDTH));
+ params = new LinearLayout.LayoutParams((FIELD_WIDTH) * width ,totalHeight);
+
+ marginTop = (totalHeight - (FIELD_HEIGHT)* width - distanceWidth * 2)/2;
+
+ if (savedData.getBoolean(getString(R.string.prefKeyEnableKeyboardInput),false)) {
+
+ layoutButtons1.setVisibility(View.GONE);
+ layoutButtons2.setVisibility(View.GONE);
+ } else {
+
+ layoutButtons1.setVisibility(View.VISIBLE);
+ layoutButtons2.setVisibility(View.VISIBLE);
+ }
+
+ params = new LinearLayout.LayoutParams((FIELD_WIDTH) * width + distanceWidth * 2,(FIELD_HEIGHT)* width + distanceWidth * 2);
+ params.setMargins(0, marginTop, 0, 0); //width is okay
+ linearLayoutGameField.setLayoutParams(params);
+
+ linearLayoutGameExtra.setLayoutParams(new LinearLayout.LayoutParams(width * FIELD_WIDTH_2 + distanceWidth * 2, width * FIELD_HEIGHT_2 + distanceHeight * 2));
+ //
+ //l1.setLayoutParams(params);
+ /*linearLayoutMenuButtons.setLayoutParams(new LinearLayout.LayoutParams((totalWidth / 2 - ((FIELD_WIDTH * width) / 2)) - distanceWidth, LinearLayout.LayoutParams.MATCH_PARENT));
+ linearLayoutGameField.setLayoutParams(new LinearLayout.LayoutParams(FIELD_WIDTH * width + distanceWidth * 2, LinearLayout.LayoutParams.MATCH_PARENT));
+ params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
+ params.setMargins(width, 0, 0, 0);
+ linearLayoutTexts.setLayoutParams(params);
+ linearLayoutGameExtra.setLayoutParams(new LinearLayout.LayoutParams(width * FIELD_WIDTH_2 + distanceWidth * 2, width * FIELD_HEIGHT_2 + distanceHeight * 2));*/
+ }
+
private void setUpDimensions(){
int marginTop;
int totalWidth = mLinearLayoutBackground.getWidth();
@@ -586,10 +630,12 @@ private void setUpDimensions(){
if (savedData.getBoolean(getString(R.string.prefKeyEnableKeyboardInput),false)) {
marginTop = (totalHeight - params.height)/2;
- linearLayoutButtons.setVisibility(View.GONE);
+ layoutButtons1.setVisibility(View.GONE);
+ layoutButtons2.setVisibility(View.GONE);
} else {
marginTop = width;
- linearLayoutButtons.setVisibility(View.VISIBLE);
+ layoutButtons1.setVisibility(View.VISIBLE);
+ layoutButtons2.setVisibility(View.VISIBLE);
}
params.setMargins(0, marginTop, 0, 0); //width is okay
diff --git a/app/src/main/java/de/tobiasbielefeld/brickgames/ui/Settings.java b/app/src/main/java/de/tobiasbielefeld/brickgames/ui/Settings.java
index d147d5b..8b10d15 100644
--- a/app/src/main/java/de/tobiasbielefeld/brickgames/ui/Settings.java
+++ b/app/src/main/java/de/tobiasbielefeld/brickgames/ui/Settings.java
@@ -54,8 +54,7 @@ public class Settings extends AppCompatPreferenceActivity
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
- //((ViewGroup) getListView().getParent()).setPadding(0, 0, 0, 0); //remove huge padding in landscape
+ ((ViewGroup) getListView().getParent()).setPadding(0, 0, 0, 0); //remove huge padding in landscape
addPreferencesFromResource(R.xml.pref_settings);
showOrHideStatusBar();
@@ -189,6 +188,9 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin
case "prefKeyEnableKeyboardInput":
getIntent().putExtra(getString(R.string.prefKeyEnableKeyboardInput), 1);
break;
+ case "pref_key_orientation":
+ setOrientation();
+ break;
}
setResult(RESULT_OK, getIntent());
@@ -207,4 +209,24 @@ private void showOrHideStatusBar() {
else
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
+
+ /**
+ * Applies the user setting of the screen orientation.
+ */
+ private void setOrientation() {
+ switch (savedData.getString("pref_key_orientation", "1")) {
+ case "1": //follow system settings
+ setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER);
+ break;
+ case "2": //portrait
+ setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
+ break;
+ case "3": //landscape
+ setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
+ break;
+ case "4": //landscape upside down
+ setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
+ break;
+ }
+ }
}
diff --git a/app/src/main/res/layout-land/main.xml b/app/src/main/res/layout-land/main.xml
new file mode 100644
index 0000000..019e665
--- /dev/null
+++ b/app/src/main/res/layout-land/main.xml
@@ -0,0 +1,505 @@
+
+