DroidFish: UI improvements from Aaro Korhonen. "Edit headers" and "edit comments" are now dialogs instead of activities, which looks much better.

This commit is contained in:
Peter Osterlund 2011-11-27 12:26:14 +00:00
parent 3d994e3381
commit b39e5c7840
6 changed files with 95 additions and 318 deletions

View File

@ -11,7 +11,7 @@
android:debuggable="false">
<activity android:name=".DroidFish"
android:label="@string/app_name"
android:configChanges="orientation">
android:configChanges="orientation|keyboardHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
@ -44,12 +44,6 @@
<activity android:name=".activities.CPUWarning"
android:label="CPU Warning">
</activity>
<activity android:name=".activities.EditHeaders"
android:label="Edit Headers">
</activity>
<activity android:name=".activities.EditComments"
android:label="Edit Comments">
</activity>
</application>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />

View File

@ -3,13 +3,8 @@
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="1"
@ -18,6 +13,7 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:paddingRight="10dp"
android:text="Before">
</TextView>
@ -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">
</EditText>
</TableRow>
@ -68,6 +64,7 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="After">
</TextView>
<EditText
@ -75,31 +72,9 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:lines="5"
android:minLines="5"
android:inputType="textMultiLine">
</EditText>
</TableRow>
</TableLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/ed_comments_ok"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Ok">
</Button>
<Button
android:id="@+id/ed_comments_cancel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Cancel">
</Button>
</LinearLayout>
</LinearLayout>
</ScrollView>

View File

@ -3,11 +3,6 @@
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TableLayout
android:layout_width="fill_parent"
@ -100,26 +95,4 @@
</EditText>
</TableRow>
</TableLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/ed_header_ok"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Ok">
</Button>
<Button
android:id="@+id/ed_header_cancel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Cancel">
</Button>
</LinearLayout>
</LinearLayout>
</ScrollView>

View File

@ -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<String> tags = bundle.getStringArrayList("tags");
ArrayList<String> 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<String> tags = new ArrayList<String>();
ArrayList<String> tagValues = new ArrayList<String>();
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<String,String> headers = new TreeMap<String,String>();
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<String> tags = new ArrayList<String>();
ArrayList<String> tagValues = new ArrayList<String>();
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:

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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();
}
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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<String,String> headers = new TreeMap<String,String>();
@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<String> tags = bundle.getStringArrayList("tags");
ArrayList<String> 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<String> tags = new ArrayList<String>();
ArrayList<String> values = new ArrayList<String>();
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();
}
}