mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-06 03:50:19 +02:00
148 lines
4.8 KiB
Java
148 lines
4.8 KiB
Java
/*
|
|
* Copyright (C) 2010 Geometer Plus <contact@geometerplus.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 2 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, write to the Free Software
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
* 02110-1301, USA.
|
|
*/
|
|
|
|
package org.geometerplus.android.fbreader.library;
|
|
|
|
import java.util.List;
|
|
|
|
import android.app.ListActivity;
|
|
import android.content.Intent;
|
|
import android.graphics.Bitmap;
|
|
import android.os.Bundle;
|
|
import android.util.Log;
|
|
import android.view.*;
|
|
import android.widget.*;
|
|
|
|
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
|
import org.geometerplus.zlibrary.core.image.ZLImage;
|
|
|
|
import org.geometerplus.zlibrary.ui.android.image.ZLAndroidImageData;
|
|
import org.geometerplus.zlibrary.ui.android.image.ZLAndroidImageManager;
|
|
|
|
import org.geometerplus.fbreader.tree.FBTree;
|
|
|
|
import org.geometerplus.zlibrary.ui.android.R;
|
|
|
|
import org.geometerplus.android.fbreader.tree.ZLAndroidTree;
|
|
|
|
abstract class LibraryBaseActivity extends ListActivity {
|
|
public static final String SELECTED_BOOK_PATH_KEY = "SelectedBookPath";
|
|
|
|
protected final ZLResource myResource = ZLResource.resource("libraryView");
|
|
protected String mySelectedBookPath;
|
|
|
|
@Override
|
|
public void onCreate(Bundle icicle) {
|
|
super.onCreate(icicle);
|
|
Thread.setDefaultUncaughtExceptionHandler(new org.geometerplus.zlibrary.ui.android.library.UncaughtExceptionHandler(this));
|
|
mySelectedBookPath = getIntent().getStringExtra(SELECTED_BOOK_PATH_KEY);
|
|
}
|
|
|
|
@Override
|
|
public void onListItemClick(ListView listView, View view, int position, long rowId) {
|
|
FBTree tree = ((LibraryAdapter)getListAdapter()).getItem(position);
|
|
}
|
|
|
|
protected final class LibraryAdapter extends BaseAdapter {
|
|
private final List<FBTree> myItems;
|
|
|
|
public LibraryAdapter(List<FBTree> items) {
|
|
myItems = items;
|
|
}
|
|
|
|
public final int getCount() {
|
|
return myItems.size();
|
|
}
|
|
|
|
public final FBTree getItem(int position) {
|
|
return myItems.get(position);
|
|
}
|
|
|
|
public final long getItemId(int position) {
|
|
return position;
|
|
}
|
|
|
|
private int myCoverWidth = -1;
|
|
private int myCoverHeight = -1;
|
|
|
|
public View getView(int position, View convertView, final ViewGroup parent) {
|
|
final FBTree tree = getItem(position);
|
|
final View view = (convertView != null) ? convertView :
|
|
LayoutInflater.from(parent.getContext()).inflate(R.layout.library_ng_tree_item, parent, false);
|
|
|
|
((TextView)view.findViewById(R.id.library_ng_tree_item_name)).setText(tree.getName());
|
|
((TextView)view.findViewById(R.id.library_ng_tree_item_childrenlist)).setText(tree.getSecondString());
|
|
|
|
if (myCoverWidth == -1) {
|
|
view.measure(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
|
myCoverHeight = view.getMeasuredHeight();
|
|
myCoverWidth = myCoverHeight * 15 / 32;
|
|
view.requestLayout();
|
|
}
|
|
|
|
final ImageView coverView = (ImageView)view.findViewById(R.id.library_ng_tree_item_icon);
|
|
coverView.getLayoutParams().width = myCoverWidth;
|
|
coverView.getLayoutParams().height = myCoverHeight;
|
|
coverView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
|
|
coverView.requestLayout();
|
|
|
|
if (tree instanceof ZLAndroidTree) {
|
|
coverView.setImageResource(((ZLAndroidTree)tree).getCoverResourceId());
|
|
} else {
|
|
Bitmap coverBitmap = null;
|
|
ZLImage cover = tree.getCover();
|
|
if (cover != null) {
|
|
final ZLAndroidImageData data =
|
|
((ZLAndroidImageManager)ZLAndroidImageManager.Instance()).getImageData(cover);
|
|
if (data != null) {
|
|
coverBitmap = data.getBitmap(2 * myCoverWidth, 2 * myCoverHeight);
|
|
}
|
|
}
|
|
if (coverBitmap != null) {
|
|
coverView.setImageBitmap(coverBitmap);
|
|
} else {
|
|
coverView.setImageResource(R.drawable.fbreader);
|
|
}
|
|
}
|
|
|
|
return view;
|
|
}
|
|
}
|
|
|
|
protected class OpenTreeRunnable implements Runnable {
|
|
private final String myTreePath;
|
|
private final String mySelectedBookPath;
|
|
|
|
public OpenTreeRunnable(String treePath, String selectedBookPath) {
|
|
myTreePath = treePath;
|
|
mySelectedBookPath = selectedBookPath;
|
|
|
|
// TODO delete later
|
|
Log.v(FileManager.FILE_MANAGER_LOG_TAG, "===" + myTreePath + mySelectedBookPath);
|
|
}
|
|
|
|
public void run() {
|
|
startActivity(
|
|
new Intent(LibraryBaseActivity.this, LibraryTreeActivity.class)
|
|
.putExtra(SELECTED_BOOK_PATH_KEY, mySelectedBookPath)
|
|
.putExtra(LibraryTreeActivity.TREE_PATH_KEY, myTreePath)
|
|
);
|
|
}
|
|
}
|
|
}
|