1 package be
.nikiroo
.fanfix
.reader
.android
;
3 import android
.app
.Activity
;
4 import android
.app
.Fragment
;
5 import android
.graphics
.Bitmap
;
6 import android
.os
.AsyncTask
;
7 import android
.os
.Bundle
;
8 import android
.view
.LayoutInflater
;
9 import android
.view
.View
;
10 import android
.view
.ViewGroup
;
11 import android
.widget
.FrameLayout
;
12 import android
.widget
.ImageView
;
13 import android
.widget
.TextView
;
15 import java
.io
.IOException
;
17 import be
.nikiroo
.fanfix
.data
.MetaData
;
18 import be
.nikiroo
.fanfix
.reader
.Reader
;
19 import be
.nikiroo
.utils
.Image
;
20 import be
.nikiroo
.utils
.android
.ImageUtilsAndroid
;
22 public class AndroidReaderBook
extends Fragment
{
23 private OnFragmentInteractionListener listener
;
26 * This interface must be implemented by activities that contain this
27 * fragment to allow an interaction in this fragment to be communicated to
28 * the activity and potentially other fragments contained in that activity.
30 * See the Android Training lesson <a href=
31 * "http://developer.android.com/training/basics/fragments/communicating.html"
32 * >Communicating with Other Fragments</a> for more information.
34 public interface OnFragmentInteractionListener
{
35 void onFragmentInteraction(MetaData meta
);
38 public AndroidReaderBook() {
39 // Required empty public constructor
43 public View
onCreateView(LayoutInflater inflater
, ViewGroup container
,
44 Bundle savedInstanceState
) {
45 return inflater
.inflate(R
.layout
.fragment_android_reader_book
,
50 public void onAttach(Activity context
) {
51 super.onAttach(context
);
52 if (context
instanceof OnFragmentInteractionListener
) {
53 listener
= (OnFragmentInteractionListener
) context
;
58 public void onDetach() {
63 public void fill(final MetaData meta
, final Reader reader
) {
64 ViewHolder viewHolder
= new ViewHolder(getView());
66 viewHolder
.title
.setText(meta
.getTitle());
67 viewHolder
.author
.setText(meta
.getAuthor());
68 viewHolder
.frame
.setClickable(true);
69 viewHolder
.frame
.setFocusable(true);
70 viewHolder
.frame
.setOnClickListener(new View
.OnClickListener() {
72 public void onClick(View v
) {
73 OnFragmentInteractionListener llistener
= listener
;
74 if (llistener
!= null) {
75 llistener
.onFragmentInteraction(meta
);
80 new AsyncTask
<MetaData
, Void
, Image
>() {
82 protected Image
doInBackground(MetaData
[] metas
) {
83 if (metas
[0].getCover() != null) {
84 return metas
[0].getCover();
87 return reader
.getLibrary().getCover(metas
[0].getLuid());
91 protected void onPostExecute(Image coverImage
) {
92 ViewHolder viewHolder
= new ViewHolder(getView());
95 if (coverImage
!= null) {
96 Bitmap coverBitmap
= ImageUtilsAndroid
97 .fromImage(coverImage
);
98 coverBitmap
= Bitmap
.createScaledBitmap(coverBitmap
,
100 viewHolder
.cover
.setImageBitmap(coverBitmap
);
102 } catch (IOException e
) {
109 private class ViewHolder
{
110 public FrameLayout frame
;
111 public TextView title
;
112 public TextView author
;
113 public ImageView cover
;
115 public ViewHolder(View book
) {
116 frame
= book
.findViewById(R
.id
.Book
);
117 title
= book
.findViewById(R
.id
.Book_lblTitle
);
118 author
= book
.findViewById(R
.id
.Book_lblAuthor
);
119 cover
= book
.findViewById(R
.id
.Book_imgCover
);