mirror of
https://github.com/peterosterlund2/droidfish.git
synced 2025-12-12 09:02:41 +01:00
DroidFish: Left-handed layout mode did not work if droidfish was started in landscape mode. Layout was not updated immediately when handedness was changed in preferences.
This commit is contained in:
@@ -344,8 +344,7 @@ public class DroidFish extends Activity implements GUIInterface {
|
|||||||
settings.registerOnSharedPreferenceChangeListener(new OnSharedPreferenceChangeListener() {
|
settings.registerOnSharedPreferenceChangeListener(new OnSharedPreferenceChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||||
readPrefs();
|
handlePrefsChange();
|
||||||
ctrl.setGameMode(gameMode);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -492,6 +491,11 @@ public class DroidFish extends Activity implements GUIInterface {
|
|||||||
@Override
|
@Override
|
||||||
public void onConfigurationChanged(Configuration newConfig) {
|
public void onConfigurationChanged(Configuration newConfig) {
|
||||||
super.onConfigurationChanged(newConfig);
|
super.onConfigurationChanged(newConfig);
|
||||||
|
reInitUI();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Re-initialize UI when layout should change because of rotation or handedness change. */
|
||||||
|
private final void reInitUI() {
|
||||||
ChessBoardPlay oldCB = cb;
|
ChessBoardPlay oldCB = cb;
|
||||||
String statusStr = status.getText().toString();
|
String statusStr = status.getText().toString();
|
||||||
initUI();
|
initUI();
|
||||||
@@ -513,12 +517,26 @@ public class DroidFish extends Activity implements GUIInterface {
|
|||||||
ctrl.updateMaterialDiffList();
|
ctrl.updateMaterialDiffList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Return true if left-handed layout should be used. */
|
||||||
|
private final boolean leftHandedView() {
|
||||||
|
return settings.getBoolean("leftHanded", false) &&
|
||||||
|
(getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Re-read preferences settings. */
|
||||||
|
private final void handlePrefsChange() {
|
||||||
|
if (leftHanded != leftHandedView())
|
||||||
|
reInitUI();
|
||||||
|
else
|
||||||
|
readPrefs();
|
||||||
|
ctrl.setGameMode(gameMode);
|
||||||
|
}
|
||||||
|
|
||||||
private final void initUI() {
|
private final void initUI() {
|
||||||
Configuration config = getResources().getConfiguration();
|
|
||||||
// The Android app title is removed with the style, but remains
|
// The Android app title is removed with the style, but remains
|
||||||
// individually in the Layout cause we need it to have in 2 lines +
|
// individually in the Layout cause we need it to have in 2 lines +
|
||||||
// landscape and portrait differ quite much
|
// landscape and portrait differ quite much
|
||||||
boolean leftHanded = this.leftHanded && (config.orientation == Configuration.ORIENTATION_LANDSCAPE);
|
leftHanded = leftHandedView();
|
||||||
setContentView(leftHanded ? R.layout.main_left_handed : R.layout.main);
|
setContentView(leftHanded ? R.layout.main_left_handed : R.layout.main);
|
||||||
|
|
||||||
// title lines need to be regenerated every time due to layout changes (rotations)
|
// title lines need to be regenerated every time due to layout changes (rotations)
|
||||||
@@ -810,7 +828,6 @@ public class DroidFish extends Activity implements GUIInterface {
|
|||||||
|
|
||||||
scrollSensitivity = Float.parseFloat(settings.getString("scrollSensitivity", "2"));
|
scrollSensitivity = Float.parseFloat(settings.getString("scrollSensitivity", "2"));
|
||||||
invertScrollDirection = settings.getBoolean("invertScrollDirection", false);
|
invertScrollDirection = settings.getBoolean("invertScrollDirection", false);
|
||||||
leftHanded = settings.getBoolean("leftHanded", false);
|
|
||||||
boolean fullScreenMode = settings.getBoolean("fullScreenMode", false);
|
boolean fullScreenMode = settings.getBoolean("fullScreenMode", false);
|
||||||
Util.setFullScreenMode(this, fullScreenMode);
|
Util.setFullScreenMode(this, fullScreenMode);
|
||||||
useWakeLock = settings.getBoolean("wakeLock", false);
|
useWakeLock = settings.getBoolean("wakeLock", false);
|
||||||
@@ -1146,8 +1163,7 @@ public class DroidFish extends Activity implements GUIInterface {
|
|||||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
switch (requestCode) {
|
switch (requestCode) {
|
||||||
case RESULT_SETTINGS:
|
case RESULT_SETTINGS:
|
||||||
readPrefs();
|
handlePrefsChange();
|
||||||
ctrl.setGameMode(gameMode);
|
|
||||||
break;
|
break;
|
||||||
case RESULT_EDITBOARD:
|
case RESULT_EDITBOARD:
|
||||||
if (resultCode == RESULT_OK) {
|
if (resultCode == RESULT_OK) {
|
||||||
|
|||||||
Reference in New Issue
Block a user