diff --git a/assets/resources/application/en.xml b/assets/resources/application/en.xml
index 98c6f211f..09eec4656 100644
--- a/assets/resources/application/en.xml
+++ b/assets/resources/application/en.xml
@@ -154,6 +154,11 @@
+
+
+
+
+
diff --git a/res/layout/cancel_item.xml b/res/layout/cancel_item.xml
new file mode 100644
index 000000000..ea3a6eb5f
--- /dev/null
+++ b/res/layout/cancel_item.xml
@@ -0,0 +1,39 @@
+
+
+
+
+
+
+
+
diff --git a/src/org/geometerplus/android/fbreader/CancelAction.java b/src/org/geometerplus/android/fbreader/CancelAction.java
index cef5ba1af..afc8af3d1 100644
--- a/src/org/geometerplus/android/fbreader/CancelAction.java
+++ b/src/org/geometerplus/android/fbreader/CancelAction.java
@@ -21,25 +21,76 @@ package org.geometerplus.android.fbreader;
import android.content.Intent;
+import org.geometerplus.zlibrary.core.resources.ZLResource;
+
import org.geometerplus.fbreader.fbreader.FBAction;
import org.geometerplus.fbreader.fbreader.FBReaderApp;
class CancelAction extends FBAction {
private final FBReader myBaseActivity;
+ enum Type {
+ OPEN_BOOK,
+ GOTO,
+ CLOSE
+ }
+
+ static final class Description {
+ final Type Type;
+ final String Title;
+ final String Summary;
+
+ Description(Type type, String title, String summary) {
+ Type = type;
+ Title = title;
+ Summary = summary;
+ }
+ }
+
CancelAction(FBReader baseActivity, FBReaderApp fbreader) {
super(fbreader);
myBaseActivity = baseActivity;
}
+ private void fillDescriptionList() {
+ final ZLResource resource = ZLResource.resource("cancelMenu");
+ myBaseActivity.CancelActionsList.clear();
+ myBaseActivity.CancelActionsList.add(new Description(
+ Type.OPEN_BOOK, resource.getResource("previousBook").getValue(), "this is a summary"
+ ));
+ myBaseActivity.CancelActionsList.add(new Description(
+ Type.GOTO, resource.getResource("goto").getValue(), "this is a summary"
+ ));
+ myBaseActivity.CancelActionsList.add(new Description(
+ Type.GOTO, resource.getResource("goto").getValue(), "this is a summary"
+ ));
+ myBaseActivity.CancelActionsList.add(new Description(
+ Type.GOTO, resource.getResource("goto").getValue(), "this is a summary"
+ ));
+ myBaseActivity.CancelActionsList.add(new Description(
+ Type.CLOSE, resource.getResource("close").getValue(), null
+ ));
+ }
+
public void run() {
if (Reader.getCurrentView() != Reader.BookTextView) {
Reader.showBookTextView();
} else {
- final Intent intent = new Intent();
- intent.setClass(myBaseActivity, CancelActivity.class);
- myBaseActivity.startActivity(intent);
- //Reader.closeWindow();
+ fillDescriptionList();
+ if (myBaseActivity.CancelActionsList.size() == 1) {
+ Reader.closeWindow();
+ } else {
+ final Intent intent = new Intent();
+ intent.setClass(myBaseActivity, CancelActivity.class);
+ intent.putExtra(CancelActivity.LIST_SIZE, myBaseActivity.CancelActionsList.size());
+ int index = 0;
+ for (Description description : myBaseActivity.CancelActionsList) {
+ intent.putExtra(CancelActivity.ITEM_TITLE + index, description.Title);
+ intent.putExtra(CancelActivity.ITEM_SUMMARY + index, description.Summary);
+ ++index;
+ }
+ myBaseActivity.startActivityForResult(intent, FBReader.CANCEL_CODE);
+ }
}
}
}
diff --git a/src/org/geometerplus/android/fbreader/CancelActivity.java b/src/org/geometerplus/android/fbreader/CancelActivity.java
index 73e9119ad..931301bcf 100644
--- a/src/org/geometerplus/android/fbreader/CancelActivity.java
+++ b/src/org/geometerplus/android/fbreader/CancelActivity.java
@@ -20,25 +20,37 @@
package org.geometerplus.android.fbreader;
import android.app.ListActivity;
+import android.content.Intent;
import android.os.Bundle;
-import android.widget.BaseAdapter;
-import android.widget.TextView;
+import android.widget.*;
import android.view.*;
import org.geometerplus.zlibrary.ui.android.R;
public class CancelActivity extends ListActivity {
+ static final String LIST_SIZE = "listSize";
+ static final String ITEM_TITLE = "title";
+ static final String ITEM_SUMMARY = "summary";
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
- setListAdapter(new ActionListAdapter());
+ final ActionListAdapter adapter = new ActionListAdapter(getIntent());
+ setListAdapter(adapter);
+ getListView().setOnItemClickListener(adapter);
}
- private class ActionListAdapter extends BaseAdapter {
+ private class ActionListAdapter extends BaseAdapter implements AdapterView.OnItemClickListener {
+ private final Intent myIntent;
+
+ ActionListAdapter(Intent intent) {
+ myIntent = intent;
+ }
+
@Override
public final int getCount() {
- return 5;
+ return myIntent.getIntExtra(LIST_SIZE, 0);
}
@Override
@@ -56,16 +68,18 @@ public class CancelActivity extends ListActivity {
final View view = convertView != null
? convertView
: LayoutInflater.from(parent.getContext()).inflate(R.layout.cancel_item, parent, false);
- final TextView titleView = (TextView)view.findViewById(R.id.cancel_item_title);
- final TextView summaryView = (TextView)view.findViewById(R.id.cancel_item_summary);
- if (position == 0) {
- titleView.setText("Open previous book");
- } else if (position == getCount() - 1) {
- titleView.setText("Close FBReader");
- } else {
- titleView.setText("Go to page");
- }
+ ((TextView)view.findViewById(R.id.cancel_item_title)).setText(
+ myIntent.getStringExtra(ITEM_TITLE + position)
+ );
+ ((TextView)view.findViewById(R.id.cancel_item_summary)).setText(
+ myIntent.getStringExtra(ITEM_SUMMARY + position)
+ );
return view;
}
+
+ public final void onItemClick(AdapterView> parent, View view, int position, long id) {
+ setResult((int)id);
+ finish();
+ }
}
}
diff --git a/src/org/geometerplus/android/fbreader/FBReader.java b/src/org/geometerplus/android/fbreader/FBReader.java
index fe819590a..fcdc10fde 100644
--- a/src/org/geometerplus/android/fbreader/FBReader.java
+++ b/src/org/geometerplus/android/fbreader/FBReader.java
@@ -19,6 +19,7 @@
package org.geometerplus.android.fbreader;
+import java.util.ArrayList;
import java.util.LinkedList;
import android.app.SearchManager;
@@ -58,6 +59,7 @@ public final class FBReader extends ZLAndroidActivity {
public static final String BOOK_PATH_KEY = "BookPath";
final static int REPAINT_CODE = 1;
+ final static int CANCEL_CODE = 2;
private int myFullScreenFlag;
@@ -252,6 +254,9 @@ public final class FBReader extends ZLAndroidActivity {
return true;
}
+ final ArrayList CancelActionsList =
+ new ArrayList(5);
+
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
@@ -270,6 +275,14 @@ public final class FBReader extends ZLAndroidActivity {
fbreader.repaintView();
break;
}
+ case CANCEL_CODE:
+ if (resultCode >= 0 && resultCode < CancelActionsList.size()) {
+ final CancelAction.Description description = CancelActionsList.get(resultCode);
+ if (description.Type == CancelAction.Type.CLOSE) {
+ finish();
+ }
+ }
+ break;
}
}
diff --git a/src/org/geometerplus/android/fbreader/TOCActivity.java b/src/org/geometerplus/android/fbreader/TOCActivity.java
index 8e47d5099..616c94dd4 100644
--- a/src/org/geometerplus/android/fbreader/TOCActivity.java
+++ b/src/org/geometerplus/android/fbreader/TOCActivity.java
@@ -89,7 +89,6 @@ public class TOCActivity extends ListActivity {
}
private final class TOCAdapter extends ZLTreeAdapter {
-
TOCAdapter(TOCTree root) {
super(getListView(), root);
}