From b39e5c784078e67ea370233827191ce11076c909 Mon Sep 17 00:00:00 2001 From: Peter Osterlund Date: Sun, 27 Nov 2011 12:26:14 +0000 Subject: [PATCH] DroidFish: UI improvements from Aaro Korhonen. "Edit headers" and "edit comments" are now dialogs instead of activities, which looks much better. --- DroidFish/AndroidManifest.xml | 8 +- DroidFish/res/layout/edit_comments.xml | 35 +---- DroidFish/res/layout/edit_headers.xml | 27 ---- .../src/org/petero/droidfish/DroidFish.java | 129 ++++++++++++------ .../droidfish/activities/EditComments.java | 93 ------------- .../droidfish/activities/EditHeaders.java | 121 ---------------- 6 files changed, 95 insertions(+), 318 deletions(-) delete mode 100644 DroidFish/src/org/petero/droidfish/activities/EditComments.java delete mode 100644 DroidFish/src/org/petero/droidfish/activities/EditHeaders.java diff --git a/DroidFish/AndroidManifest.xml b/DroidFish/AndroidManifest.xml index 8185ec9..60e1f70 100644 --- a/DroidFish/AndroidManifest.xml +++ b/DroidFish/AndroidManifest.xml @@ -11,7 +11,7 @@ android:debuggable="false"> + android:configChanges="orientation|keyboardHidden"> @@ -44,12 +44,6 @@ - - - - diff --git a/DroidFish/res/layout/edit_comments.xml b/DroidFish/res/layout/edit_comments.xml index 816d0db..2b77945 100644 --- a/DroidFish/res/layout/edit_comments.xml +++ b/DroidFish/res/layout/edit_comments.xml @@ -3,13 +3,8 @@ xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> - - - @@ -26,7 +22,7 @@ android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" - android:lines="2" + android:minLines="2" android:inputType="textMultiLine"> @@ -68,6 +64,7 @@ - - - - - - - \ No newline at end of file diff --git a/DroidFish/res/layout/edit_headers.xml b/DroidFish/res/layout/edit_headers.xml index 94226f6..05495ba 100644 --- a/DroidFish/res/layout/edit_headers.xml +++ b/DroidFish/res/layout/edit_headers.xml @@ -3,11 +3,6 @@ xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> - - - - - - - - - diff --git a/DroidFish/src/org/petero/droidfish/DroidFish.java b/DroidFish/src/org/petero/droidfish/DroidFish.java index 8c4fecc..f89c12b 100644 --- a/DroidFish/src/org/petero/droidfish/DroidFish.java +++ b/DroidFish/src/org/petero/droidfish/DroidFish.java @@ -26,11 +26,10 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; +import java.util.TreeMap; import org.petero.droidfish.activities.CPUWarning; import org.petero.droidfish.activities.EditBoard; -import org.petero.droidfish.activities.EditComments; -import org.petero.droidfish.activities.EditHeaders; import org.petero.droidfish.activities.EditPGNLoad; import org.petero.droidfish.activities.EditPGNSave; import org.petero.droidfish.activities.LoadScid; @@ -657,9 +656,7 @@ public class DroidFish extends Activity implements GUIInterface { static private final int RESULT_EDITBOARD = 0; static private final int RESULT_SETTINGS = 1; static private final int RESULT_LOAD_PGN = 2; - static private final int RESULT_EDITHEADERS = 3; - static private final int RESULT_EDITCOMMENTS = 4; - static private final int RESULT_SELECT_SCID = 5; + static private final int RESULT_SELECT_SCID = 3; @Override public boolean onOptionsItemSelected(MenuItem item) { @@ -762,24 +759,6 @@ public class DroidFish extends Activity implements GUIInterface { } } break; - case RESULT_EDITHEADERS: - if (resultCode == RESULT_OK) { - Bundle bundle = data.getBundleExtra("org.petero.droidfish.headers"); - ArrayList tags = bundle.getStringArrayList("tags"); - ArrayList tagValues = bundle.getStringArrayList("tagValues"); - ctrl.setHeaders(tags, tagValues); - } - break; - case RESULT_EDITCOMMENTS: - if (resultCode == RESULT_OK) { - Bundle bundle = data.getBundleExtra("org.petero.droidfish.comments"); - DroidChessController.CommentInfo commInfo = new DroidChessController.CommentInfo(); - commInfo.preComment = bundle.getString("preComment"); - commInfo.postComment = bundle.getString("postComment"); - commInfo.nag = bundle.getInt("nag"); - ctrl.setComments(commInfo); - } - break; case RESULT_SELECT_SCID: if (resultCode == RESULT_OK) { String pathName = data.getAction(); @@ -1360,29 +1339,99 @@ public class DroidFish extends Activity implements GUIInterface { public void onClick(DialogInterface dialog, int item) { switch (finalActions.get(item)) { case EDIT_HEADERS: { - Intent i = new Intent(DroidFish.this, EditHeaders.class); - i.setAction(""); - Bundle bundle = new Bundle(); ArrayList tags = new ArrayList(); ArrayList tagValues = new ArrayList(); ctrl.getHeaders(tags, tagValues); - bundle.putStringArrayList("tags", tags); - bundle.putStringArrayList("tagValues", tagValues); - i.putExtra("org.petero.droidfish.headers", bundle); - startActivityForResult(i, RESULT_EDITHEADERS); + + AlertDialog.Builder builder = new AlertDialog.Builder(DroidFish.this); + builder.setTitle(R.string.edit_headers); + View content = View.inflate(DroidFish.this, R.layout.edit_headers, null); + builder.setView(content); + + final TextView event, site, date, round, white, black; + + event = (TextView)content.findViewById(R.id.ed_header_event); + site = (TextView)content.findViewById(R.id.ed_header_site); + date = (TextView)content.findViewById(R.id.ed_header_date); + round = (TextView)content.findViewById(R.id.ed_header_round); + white = (TextView)content.findViewById(R.id.ed_header_white); + black = (TextView)content.findViewById(R.id.ed_header_black); + + final TreeMap headers = new TreeMap(); + for (int i = 0; i < tags.size(); i++) + headers.put(tags.get(i), tagValues.get(i)); + + event.setText(headers.get("Event")); + site .setText(headers.get("Site")); + date .setText(headers.get("Date")); + round.setText(headers.get("Round")); + white.setText(headers.get("White")); + black.setText(headers.get("Black")); + + builder.setNegativeButton("Cancel", null); + builder.setPositiveButton("Ok", new Dialog.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + headers.put("Event", event.getText().toString().trim()); + headers.put("Site", site .getText().toString().trim()); + headers.put("Date", date .getText().toString().trim()); + headers.put("Round", round.getText().toString().trim()); + headers.put("White", white.getText().toString().trim()); + headers.put("Black", black.getText().toString().trim()); + + ArrayList tags = new ArrayList(); + ArrayList tagValues = new ArrayList(); + for (String k : headers.keySet()) { + tags.add(k); + tagValues.add(headers.get(k)); + } + + ctrl.setHeaders(tags, tagValues); + } + }); + + builder.show(); + break; } case EDIT_COMMENTS: { - Intent i = new Intent(DroidFish.this, EditComments.class); - i.setAction(""); - DroidChessController.CommentInfo commInfo = ctrl.getComments(); - Bundle bundle = new Bundle(); - bundle.putString("preComment", commInfo.preComment); - bundle.putString("postComment", commInfo.postComment); - bundle.putInt("nag", commInfo.nag); - bundle.putString("move", commInfo.move); - i.putExtra("org.petero.droidfish.comments", bundle); - startActivityForResult(i, RESULT_EDITCOMMENTS); + AlertDialog.Builder builder = new AlertDialog.Builder(DroidFish.this); + builder.setTitle(R.string.edit_comments); + View content = View.inflate(DroidFish.this, R.layout.edit_comments, null); + builder.setView(content); + + DroidChessController.CommentInfo commInfo = ctrl.getComments(); + + final TextView preComment, moveView, nag, postComment; + preComment = (TextView)content.findViewById(R.id.ed_comments_pre); + moveView = (TextView)content.findViewById(R.id.ed_comments_move); + nag = (TextView)content.findViewById(R.id.ed_comments_nag); + postComment = (TextView)content.findViewById(R.id.ed_comments_post); + + preComment.setText(commInfo.preComment); + postComment.setText(commInfo.postComment); + moveView.setText(commInfo.move); + String nagStr = Node.nagStr(commInfo.nag).trim(); + if ((nagStr.length() == 0) && (commInfo.nag > 0)) + nagStr = String.format("%d", commInfo.nag); + nag.setText(nagStr); + + builder.setNegativeButton("Cancel", null); + builder.setPositiveButton("Ok", new Dialog.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + String pre = preComment.getText().toString().trim(); + String post = postComment.getText().toString().trim(); + int nagVal = Node.strToNag(nag.getText().toString()); + + DroidChessController.CommentInfo commInfo = new DroidChessController.CommentInfo(); + commInfo.preComment = pre; + commInfo.postComment = post; + commInfo.nag = nagVal; + ctrl.setComments(commInfo); + } + }); + + builder.show(); + break; } case REMOVE_SUBTREE: diff --git a/DroidFish/src/org/petero/droidfish/activities/EditComments.java b/DroidFish/src/org/petero/droidfish/activities/EditComments.java deleted file mode 100644 index d321077..0000000 --- a/DroidFish/src/org/petero/droidfish/activities/EditComments.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - DroidFish - An Android chess program. - Copyright (C) 2011 Peter Ă–sterlund, peterosterlund2@gmail.com - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -package org.petero.droidfish.activities; - -import org.petero.droidfish.R; -import org.petero.droidfish.gamelogic.GameTree.Node; - -import android.app.Activity; -import android.content.Intent; -import android.os.Bundle; -import android.view.View; -import android.view.View.OnClickListener; -import android.widget.Button; -import android.widget.TextView; - -/** Activity to edit PGN comments. */ -public class EditComments extends Activity { - TextView preComment, postComment, nag; - private Button okButton; - private Button cancelButton; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - setContentView(R.layout.edit_comments); - preComment = (TextView)findViewById(R.id.ed_comments_pre); - TextView moveView = (TextView)findViewById(R.id.ed_comments_move); - nag = (TextView)findViewById(R.id.ed_comments_nag); - postComment = (TextView)findViewById(R.id.ed_comments_post); - okButton = (Button)findViewById(R.id.ed_comments_ok); - cancelButton = (Button)findViewById(R.id.ed_comments_cancel); - - postComment.requestFocus(); - - Intent data = getIntent(); - Bundle bundle = data.getBundleExtra("org.petero.droidfish.comments"); - String pre = bundle.getString("preComment"); - String post = bundle.getString("postComment"); - String move = bundle.getString("move"); - int nagVal = bundle.getInt("nag"); - preComment.setText(pre); - postComment.setText(post); - moveView.setText(move); - String nagStr = Node.nagStr(nagVal).trim(); - if ((nagStr.length() == 0) && (nagVal > 0)) - nagStr = String.format("%d", nagVal); - nag.setText(nagStr); - - okButton.setOnClickListener(new OnClickListener() { - public void onClick(View v) { - sendBackResult(); - } - }); - cancelButton.setOnClickListener(new OnClickListener() { - public void onClick(View v) { - setResult(RESULT_CANCELED); - finish(); - } - }); - } - - private final void sendBackResult() { - String pre = preComment.getText().toString().trim(); - String post = postComment.getText().toString().trim(); - int nagVal = Node.strToNag(nag.getText().toString()); - - Bundle bundle = new Bundle(); - bundle.putString("preComment", pre); - bundle.putString("postComment", post); - bundle.putInt("nag", nagVal); - Intent data = new Intent(); - data.putExtra("org.petero.droidfish.comments", bundle); - setResult(RESULT_OK, data); - finish(); - } -} diff --git a/DroidFish/src/org/petero/droidfish/activities/EditHeaders.java b/DroidFish/src/org/petero/droidfish/activities/EditHeaders.java deleted file mode 100644 index cea446d..0000000 --- a/DroidFish/src/org/petero/droidfish/activities/EditHeaders.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - DroidFish - An Android chess program. - Copyright (C) 2011 Peter Ă–sterlund, peterosterlund2@gmail.com - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -package org.petero.droidfish.activities; - -import java.util.ArrayList; -import java.util.TreeMap; - -import org.petero.droidfish.R; - -import android.app.Activity; -import android.content.Intent; -import android.os.Bundle; -import android.view.KeyEvent; -import android.view.View; -import android.view.View.OnClickListener; -import android.widget.Button; -import android.widget.TextView; - -/** Activity to edit PGN headers. */ -public class EditHeaders extends Activity { - - private TextView event; - private TextView site; - private TextView date; - private TextView round; - private TextView white; - private TextView black; - private Button okButton; - private Button cancelButton; - - private TreeMap headers = new TreeMap(); - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - setContentView(R.layout.edit_headers); - event = (TextView)findViewById(R.id.ed_header_event); - site = (TextView)findViewById(R.id.ed_header_site); - date = (TextView)findViewById(R.id.ed_header_date); - round = (TextView)findViewById(R.id.ed_header_round); - white = (TextView)findViewById(R.id.ed_header_white); - black = (TextView)findViewById(R.id.ed_header_black); - - okButton = (Button)findViewById(R.id.ed_header_ok); - cancelButton = (Button)findViewById(R.id.ed_header_cancel); - - Intent data = getIntent(); - Bundle bundle = data.getBundleExtra("org.petero.droidfish.headers"); - ArrayList tags = bundle.getStringArrayList("tags"); - ArrayList tagValues = bundle.getStringArrayList("tagValues"); - for (int i = 0; i < tags.size(); i++) - headers.put(tags.get(i), tagValues.get(i)); - event.setText(headers.get("Event")); - site .setText(headers.get("Site")); - date .setText(headers.get("Date")); - round.setText(headers.get("Round")); - white.setText(headers.get("White")); - black.setText(headers.get("Black")); - - okButton.setOnClickListener(new OnClickListener() { - public void onClick(View v) { - sendBackResult(); - } - }); - cancelButton.setOnClickListener(new OnClickListener() { - public void onClick(View v) { - setResult(RESULT_CANCELED); - finish(); - } - }); - } - - @Override - public boolean onKeyDown(int keyCode, KeyEvent event) { - if (keyCode == KeyEvent.KEYCODE_BACK) { - sendBackResult(); - return true; - } - return super.onKeyDown(keyCode, event); - } - - private final void sendBackResult() { - headers.put("Event", event.getText().toString().trim()); - headers.put("Site", site .getText().toString().trim()); - headers.put("Date", date .getText().toString().trim()); - headers.put("Round", round.getText().toString().trim()); - headers.put("White", white.getText().toString().trim()); - headers.put("Black", black.getText().toString().trim()); - - Bundle bundle = new Bundle(); - ArrayList tags = new ArrayList(); - ArrayList values = new ArrayList(); - for (String k : headers.keySet()) { - tags.add(k); - values.add(headers.get(k)); - } - bundle.putStringArrayList("tags", tags); - bundle.putStringArrayList("tagValues", values); - Intent data = new Intent(); - data.putExtra("org.petero.droidfish.headers", bundle); - setResult(RESULT_OK, data); - finish(); - } -}