Android Open Source - book Pager Activity






From Project

Back to project page book.

License

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.

Java Source Code

package fragments;
/*  w  w  w. j  av a  2  s.c o m*/
import java.util.ArrayList;
import java.util.List;

import translator.Translator;
import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.FragmentTransaction;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Toast;
import book.Book;

import com.Db;
import com.example.book.R;

import edu.sfsu.cs.orange.ocr.CaptureActivity;
import edu.sfsu.cs.orange.ocr.OcrResult;


/*
 * 
 *       main activity
 * 
 * 
 */


public class PagerActivity extends FragmentActivity implements OnClickListener{
   
    private PageAdapter pgAdapter;  // shit    
    private ViewPager pager;  // handles the fragments
       
    public List<Book> BOOKS;  // books stored in this application
    public Db DB;
    
    public Book openBook; // current book, which is opened in bookFragment
    public Book editBook; // current book at the edit window
    
    public Translator translator;
    
  public String cameraWord;

   // fragments
    public CameraFragment CAMERA;
    public EditBookFragment EDITBOOK;
    public BookListFragment BOOKLIST;
    public BookViewFragment BOOKVIEW;
    public CaptureActivity captureActivity;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
      
        super.onCreate(savedInstanceState);
        super.setContentView(R.layout.viewpager);
        BOOKS = new ArrayList<Book>();
       
     
       this.initialisePaging();
    }
    
    // ridiculously handy keyboard goes to hell
    public void hideKeyboard(EditText field){
    InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(field.getWindowToken(), 0);      
    }
    
    public void showMessage(String msg){
      Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG).show();
    }
    
    /*
     * 
     *  show a book in the bookFragment
     */
    public void showBook(Book book){            
      openBook = book;       
      BOOKVIEW.showBook(book);      
      this.show(this.BOOKVIEW,true);
    }

    
    public void addToBook(Book book){
      editBook = book;
      this.show(this.CAMERA, true);      
    }
/*
    // edit books contents
    public void modifyBook(Book book){      
      editBook = book;
      EDITBOOK.setBook(book);
      this.show(this.EDITBOOK,true);
    }
  */     
    public Book getBook(String name){
      for (Book bk : this.BOOKS){
        if (bk.getName().equals(name)){
          return bk;
        }
      }
      return null;
    }
    
    // check if book already exists
    public boolean hasBook(Book book){      
    for (Book bk : BOOKS){
      if (bk.getName().equals(book.getName())){
        return true;
      }
    }
      return BOOKS.contains(book);
    }
    
    public void addNewBook(String name){
      this.EDITBOOK.createNew(name);
      this.show(EDITBOOK, true);      
    }
    
    public Book createBook(){
      Book bk = new Book(this.DB);
      return bk;
    }
        
    public void update(){
      pager.getAdapter().notifyDataSetChanged();
    }
    
    // method to add book into array
    public void addBook(Book book){
      if (this.editBook != null){
        this.editBook.merge(book);
        if (!BOOKS.contains(this.editBook)){
          BOOKS.add(this.editBook);
        }
      } else if (!this.hasBook(book)){
        BOOKS.add(book);             
      }
    
    this.editBook = null;
      translator.translate(book);
      book.save();
      BOOKLIST.refresh();
    }
    
    public void removeBook(Book book){
      book.remove();
      BOOKS.remove(book);
      BOOKLIST.refresh();
      openBook = null;
    }
   
    public void saveBook(Book book){
      book.save();
      BOOKLIST.refresh();
    }
    
      // show some fragments
    public void show(Fragment frag, Boolean animate){
        pager.setCurrentItem(this.pgAdapter.getPosition(frag), animate);      
    }
    
    // main init
    private void initialisePaging() {
      
      DB = new Db(this);
      BOOKS = DB.load();
      
      translator = new Translator(DB);
      System.out.println(BOOKS.size());
      //CAMERA = new CameraFragment();

      ArrayList<Fragment> fragments = new ArrayList<Fragment>();
      BOOKLIST = new BookListFragment();
      BOOKVIEW = new BookViewFragment();
      EDITBOOK = new EditBookFragment();
      //fragments.add(CAMERA);
      fragments.add(EDITBOOK);
      fragments.add(BOOKLIST);
      fragments.add(BOOKVIEW);      
      pgAdapter  = new PageAdapter(super.getSupportFragmentManager(), fragments);
        pager = (ViewPager)super.findViewById(R.id.viewpager);                         
        pager.setAdapter(pgAdapter);
            

               
        
        // first pane to be shown at startup
      show(this.BOOKLIST,false);
    }


    
    
    // button onclick
  @Override
  public void onClick(View button) {
    
    
  }




  

  
}




Java Source Code List

book.BookListAdapter.java
book.Book.java
book.ExpandableListAdapter.java
book.SelectableWordListAdapter.java
com.BookTable.java
com.Db.java
com.TranslationsTable.java
com.WordTable.java
fragments.BookListFragment.java
fragments.BookViewFragment.java
fragments.CameraFragment.java
fragments.EditBookFragment.java
fragments.PageAdapter.java
fragments.PagerActivity.java
translator.TranslateWordTask.java
translator.Translator.java