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
.Instance
;
18 import be
.nikiroo
.fanfix
.data
.MetaData
;
19 import be
.nikiroo
.fanfix
.reader
.Reader
;
20 import be
.nikiroo
.utils
.Image
;
21 import be
.nikiroo
.utils
.android
.ImageUtilsAndroid
;
23 public class AndroidReaderBook
extends Fragment
{
24 private Reader reader
;
25 private OnFragmentInteractionListener listener
;
26 private MetaData meta
;
29 * This interface must be implemented by activities that contain this
30 * fragment to allow an interaction in this fragment to be communicated to
31 * the activity and potentially other fragments contained in that activity.
33 * See the Android Training lesson <a href=
34 * "http://developer.android.com/training/basics/fragments/communicating.html"
35 * >Communicating with Other Fragments</a> for more information.
37 public interface OnFragmentInteractionListener
{
38 void onFragmentInteraction(MetaData meta
);
41 public AndroidReaderBook() {
42 // Required empty public constructor
46 public View
onCreateView(LayoutInflater inflater
, ViewGroup container
,
47 Bundle savedInstanceState
) {
48 return inflater
.inflate(R
.layout
.fragment_android_reader_book
,
53 public void onAttach(Activity context
) {
54 super.onAttach(context
);
55 if (context
instanceof OnFragmentInteractionListener
) {
56 listener
= (OnFragmentInteractionListener
) context
;
61 public void onDetach() {
66 public void fill(final Reader reader
, final String luid
) {
67 View view
= getView();
72 final ImageView cover
= view
.findViewById(R
.id
.cover
);
73 final TextView title
= view
.findViewById(R
.id
.title
);
74 final FrameLayout frame
= view
.findViewById(R
.id
.coverWidget
);
76 new AsyncTask
<Void
, Void
, MetaData
>() {
78 protected MetaData
doInBackground(Void
[] objects
) {
79 return Instance
.getLibrary().getInfo(luid
);
83 protected void onPostExecute(MetaData meta
) {
84 AndroidReaderBook
.this.meta
= meta
;
87 title
.setText(meta
.getTitle());
89 Image coverImage
= reader
.getLibrary().getCover(
91 if (coverImage
!= null) {
92 Bitmap coverBitmap
= ImageUtilsAndroid
93 .fromImage(coverImage
);
94 coverBitmap
= Bitmap
.createScaledBitmap(
95 coverBitmap
, 128, 128, true);
96 cover
.setImageBitmap(coverBitmap
);
98 } catch (IOException e
) {
103 frame
.setClickable(true);
104 frame
.setFocusable(true);
105 frame
.setOnClickListener(new View
.OnClickListener() {
107 public void onClick(View v
) {
108 OnFragmentInteractionListener llistener
= listener
;
109 if (llistener
!= null) {
111 .onFragmentInteraction(AndroidReaderBook
.this.meta
);