mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 18:29:23 +02:00
list of cancel actions
This commit is contained in:
parent
a2bd14443e
commit
b638a3f431
6 changed files with 140 additions and 19 deletions
|
@ -154,6 +154,11 @@
|
||||||
<node name="search" value="Search"/>
|
<node name="search" value="Search"/>
|
||||||
</node>
|
</node>
|
||||||
</node>
|
</node>
|
||||||
|
<node name="cancelMenu">
|
||||||
|
<node name="previousBook" value="Open previous book"/>
|
||||||
|
<node name="goto" value="Go to position"/>
|
||||||
|
<node name="close" value="Close FBReader"/>
|
||||||
|
</node>
|
||||||
<node name="menu">
|
<node name="menu">
|
||||||
<node name="preferences" value="Settings"/>
|
<node name="preferences" value="Settings"/>
|
||||||
<node name="bookInfo" value="Book info"/>
|
<node name="bookInfo" value="Book info"/>
|
||||||
|
|
39
res/layout/cancel_item.xml
Normal file
39
res/layout/cancel_item.xml
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:minHeight="?android:attr/listPreferredItemHeight"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
>
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="fill_parent"
|
||||||
|
android:paddingLeft="8dp"
|
||||||
|
android:paddingRight="8dp"
|
||||||
|
android:orientation="vertical"
|
||||||
|
>
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/cancel_item_title"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:singleLine="true"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||||
|
android:ellipsize="marquee"
|
||||||
|
android:marqueeRepeatLimit="marquee_forever"
|
||||||
|
/>
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/cancel_item_summary"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="5dip"
|
||||||
|
android:singleLine="true"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||||
|
android:ellipsize="marquee"
|
||||||
|
android:marqueeRepeatLimit="marquee_forever"
|
||||||
|
/>
|
||||||
|
</LinearLayout>
|
||||||
|
<View
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="fill_parent"
|
||||||
|
/>
|
||||||
|
</LinearLayout>
|
|
@ -21,25 +21,76 @@ package org.geometerplus.android.fbreader;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
|
||||||
|
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.fbreader.FBAction;
|
import org.geometerplus.fbreader.fbreader.FBAction;
|
||||||
import org.geometerplus.fbreader.fbreader.FBReaderApp;
|
import org.geometerplus.fbreader.fbreader.FBReaderApp;
|
||||||
|
|
||||||
class CancelAction extends FBAction {
|
class CancelAction extends FBAction {
|
||||||
private final FBReader myBaseActivity;
|
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) {
|
CancelAction(FBReader baseActivity, FBReaderApp fbreader) {
|
||||||
super(fbreader);
|
super(fbreader);
|
||||||
myBaseActivity = baseActivity;
|
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() {
|
public void run() {
|
||||||
if (Reader.getCurrentView() != Reader.BookTextView) {
|
if (Reader.getCurrentView() != Reader.BookTextView) {
|
||||||
Reader.showBookTextView();
|
Reader.showBookTextView();
|
||||||
|
} else {
|
||||||
|
fillDescriptionList();
|
||||||
|
if (myBaseActivity.CancelActionsList.size() == 1) {
|
||||||
|
Reader.closeWindow();
|
||||||
} else {
|
} else {
|
||||||
final Intent intent = new Intent();
|
final Intent intent = new Intent();
|
||||||
intent.setClass(myBaseActivity, CancelActivity.class);
|
intent.setClass(myBaseActivity, CancelActivity.class);
|
||||||
myBaseActivity.startActivity(intent);
|
intent.putExtra(CancelActivity.LIST_SIZE, myBaseActivity.CancelActionsList.size());
|
||||||
//Reader.closeWindow();
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,25 +20,37 @@
|
||||||
package org.geometerplus.android.fbreader;
|
package org.geometerplus.android.fbreader;
|
||||||
|
|
||||||
import android.app.ListActivity;
|
import android.app.ListActivity;
|
||||||
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.widget.BaseAdapter;
|
import android.widget.*;
|
||||||
import android.widget.TextView;
|
|
||||||
import android.view.*;
|
import android.view.*;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.ui.android.R;
|
import org.geometerplus.zlibrary.ui.android.R;
|
||||||
|
|
||||||
public class CancelActivity extends ListActivity {
|
public class CancelActivity extends ListActivity {
|
||||||
|
static final String LIST_SIZE = "listSize";
|
||||||
|
static final String ITEM_TITLE = "title";
|
||||||
|
static final String ITEM_SUMMARY = "summary";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||||
setListAdapter(new ActionListAdapter());
|
final ActionListAdapter adapter = new ActionListAdapter(getIntent());
|
||||||
|
setListAdapter(adapter);
|
||||||
|
getListView().setOnItemClickListener(adapter);
|
||||||
|
}
|
||||||
|
|
||||||
|
private class ActionListAdapter extends BaseAdapter implements AdapterView.OnItemClickListener {
|
||||||
|
private final Intent myIntent;
|
||||||
|
|
||||||
|
ActionListAdapter(Intent intent) {
|
||||||
|
myIntent = intent;
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ActionListAdapter extends BaseAdapter {
|
|
||||||
@Override
|
@Override
|
||||||
public final int getCount() {
|
public final int getCount() {
|
||||||
return 5;
|
return myIntent.getIntExtra(LIST_SIZE, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -56,16 +68,18 @@ public class CancelActivity extends ListActivity {
|
||||||
final View view = convertView != null
|
final View view = convertView != null
|
||||||
? convertView
|
? convertView
|
||||||
: LayoutInflater.from(parent.getContext()).inflate(R.layout.cancel_item, parent, false);
|
: LayoutInflater.from(parent.getContext()).inflate(R.layout.cancel_item, parent, false);
|
||||||
final TextView titleView = (TextView)view.findViewById(R.id.cancel_item_title);
|
((TextView)view.findViewById(R.id.cancel_item_title)).setText(
|
||||||
final TextView summaryView = (TextView)view.findViewById(R.id.cancel_item_summary);
|
myIntent.getStringExtra(ITEM_TITLE + position)
|
||||||
if (position == 0) {
|
);
|
||||||
titleView.setText("Open previous book");
|
((TextView)view.findViewById(R.id.cancel_item_summary)).setText(
|
||||||
} else if (position == getCount() - 1) {
|
myIntent.getStringExtra(ITEM_SUMMARY + position)
|
||||||
titleView.setText("Close FBReader");
|
);
|
||||||
} else {
|
|
||||||
titleView.setText("Go to page");
|
|
||||||
}
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||||
|
setResult((int)id);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
package org.geometerplus.android.fbreader;
|
package org.geometerplus.android.fbreader;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
|
||||||
import android.app.SearchManager;
|
import android.app.SearchManager;
|
||||||
|
@ -58,6 +59,7 @@ public final class FBReader extends ZLAndroidActivity {
|
||||||
public static final String BOOK_PATH_KEY = "BookPath";
|
public static final String BOOK_PATH_KEY = "BookPath";
|
||||||
|
|
||||||
final static int REPAINT_CODE = 1;
|
final static int REPAINT_CODE = 1;
|
||||||
|
final static int CANCEL_CODE = 2;
|
||||||
|
|
||||||
private int myFullScreenFlag;
|
private int myFullScreenFlag;
|
||||||
|
|
||||||
|
@ -252,6 +254,9 @@ public final class FBReader extends ZLAndroidActivity {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final ArrayList<CancelAction.Description> CancelActionsList =
|
||||||
|
new ArrayList<CancelAction.Description>(5);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
switch (requestCode) {
|
switch (requestCode) {
|
||||||
|
@ -270,6 +275,14 @@ public final class FBReader extends ZLAndroidActivity {
|
||||||
fbreader.repaintView();
|
fbreader.repaintView();
|
||||||
break;
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -89,7 +89,6 @@ public class TOCActivity extends ListActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
private final class TOCAdapter extends ZLTreeAdapter {
|
private final class TOCAdapter extends ZLTreeAdapter {
|
||||||
|
|
||||||
TOCAdapter(TOCTree root) {
|
TOCAdapter(TOCTree root) {
|
||||||
super(getListView(), root);
|
super(getListView(), root);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue