Back to project page book.
The source code is released under:
MIT License
If you think the Android project book listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package fragments; // ww w .j a va 2s . c o m import java.util.HashMap; import java.util.List; import android.app.AlertDialog; import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.ExpandableListView; import android.widget.ImageButton; import android.widget.TextView; import book.Book; import book.ExpandableListAdapter; import com.example.book.R; import edu.sfsu.cs.orange.ocr.CaptureActivity; /* * * bookview * * * * two buttons * one for keyboard input * one for camera * * shows contents of one book in a listview */ public class BookViewFragment extends Fragment implements OnItemClickListener, OnClickListener{ private PagerActivity pager; private View view; private Book book; private ExpandableListAdapter wordAdapter; private ExpandableListView list; private TextView name; private ImageButton delete; static final int PICK_Camera_String_REQUEST=1; private Button button1; public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) { if (container == null) { return null; } this.pager = (PagerActivity) getActivity(); this.view = (View)inflater.inflate(R.layout.bookview, container, false); this.name = (TextView) this.view.findViewById(R.id.bookName); this.list = (ExpandableListView)this.view.findViewById(R.id.wordList); //this.list.setOnItemClickListener(this); button1=(Button)this.view.findViewById(R.id.button1); button1.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { pager.show(pager.EDITBOOK, true); Intent intent = new Intent(); intent.setClass(getActivity(), CaptureActivity.class); startActivityForResult(intent,PICK_Camera_String_REQUEST); } }); ImageButton btn = (ImageButton) this.view.findViewById(R.id.add); btn.setOnClickListener(this); delete = (ImageButton) this.view.findViewById(R.id.delete); delete.setOnClickListener(this); // if this fragment already had a book open if (this.pager.openBook != null){ this.showBook(this.pager.openBook); } return this.view; } public void setName(String name){ this.name.setText(name); } // to show a book... public void showBook(Book book){ this.clear(); this.book = book; this.setName(book.getName()); /* List<Word> words = book.getWords(); for (Word word : words){ this.wordAdapter.addWord(word); } */ if (book.getCount() > 0){ this.wordAdapter = new ExpandableListAdapter(this.pager, book.getWords() ); if (this.wordAdapter != null && this.list != null){ this.list.setAdapter(this.wordAdapter); } } } public void clear(){ this.book = null; this.wordAdapter = new ExpandableListAdapter(this.pager, new HashMap<String, List<String>>() ); this.list.setAdapter(this.wordAdapter); this.setName(""); } @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { } @Override public void onClick(View v) { switch (v.getId()){ case R.id.add: if (this.book != null){ this.pager.show(this.pager.EDITBOOK,false); this.pager.EDITBOOK.setBook(this.book); this.clear(); } else { this.pager.showMessage("open a book first"); } break; case R.id.delete: // x-button is clicked and the book will be deleted if (this.book != null){ this.pager.removeBook(this.book); this.pager.show(pager.BOOKLIST,true); this.clear(); } break; } } }