[Libreoffice-commits] .: 3 commits - android/experimental
Iain Billett
iainb at kemper.freedesktop.org
Thu Aug 9 17:27:34 PDT 2012
android/experimental/LibreOffice4Android/src/org/libreoffice/android/DocumentLoader.java | 205 +++-------
1 file changed, 69 insertions(+), 136 deletions(-)
New commits:
commit 9031cd89e35be17fb4e6150f5100defca36dfafc
Author: Iain Billett <iainbillett at gmail.com>
Date: Fri Aug 10 01:17:23 2012 +0100
Some minor bug fixes and code clean-up.
Change-Id: I857407ac46ce51be5ee3eab26e9af75afc612a41
diff --git a/android/experimental/LibreOffice4Android/src/org/libreoffice/android/DocumentLoader.java b/android/experimental/LibreOffice4Android/src/org/libreoffice/android/DocumentLoader.java
index b7a41ad..edfb13b 100644
--- a/android/experimental/LibreOffice4Android/src/org/libreoffice/android/DocumentLoader.java
+++ b/android/experimental/LibreOffice4Android/src/org/libreoffice/android/DocumentLoader.java
@@ -160,7 +160,6 @@ public class DocumentLoader
flipper.setOutAnimation(outToLeft);
documentViewer.nextPage();
- //((PageViewer)flipper.getChildAt((flipper.getDisplayedChild() + PAGECACHE_PLUSMINUS) % PAGECACHE_SIZE)).display(((PageViewer)flipper.getCurrentView()).currentPageNumber + PAGECACHE_PLUSMINUS);
return true;
} else if (event2.getX() - event1.getX() > 120) {
if (((PageViewer)flipper.getCurrentView()).currentPageNumber == 0)
@@ -177,9 +176,6 @@ public class DocumentLoader
flipper.setOutAnimation(outToRight);
documentViewer.prevPage();
-
- //((PageViewer)flipper.getChildAt((flipper.getDisplayedChild() + PAGECACHE_SIZE - PAGECACHE_PLUSMINUS) % PAGECACHE_SIZE)).display(((PageViewer)flipper.getCurrentView()).currentPageNumber - PAGECACHE_PLUSMINUS);
-
return true;
}
return false;
@@ -670,7 +666,6 @@ public class DocumentLoader
progressView = new ProgressBar( DocumentLoader.this, null, android.R.attr.progressBarStyleHorizontal);
progressView.setProgress( 10 );
- //flipper = new ViewFlipper(DocumentLoader.this);
ViewFlipper flipper = (ViewFlipper)findViewById( R.id.page_flipper );
flipper.addView( waitView , 0 , matchParent);
flipper.showNext();
@@ -752,30 +747,10 @@ public class DocumentLoader
Log.i(TAG, "onPostExecute: " + result);
if (result == -1)
return;
- //flipper = new ViewFlipper(this);
- //flipper = (ViewFlipper)findViewById( R.id.page_flipper );
- //matchParent = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
- //flipper.removeViewAt( 0 );
documentViewer = new DocumentViewer( (ViewFlipper)findViewById( R.id.page_flipper ) );
- //documentViewer.open(0);
-
- //currentPage = 0;
- //openPageWithPrefetching( currentPage );
-
- /*
- //open method? set current page = 0?
- flipper.addView(new PageViewer(0), 0, matchParent);
- for (int i = 0; i < PAGECACHE_PLUSMINUS; i++)
- flipper.addView(new PageViewer(i+1), i+1, matchParent);
- for (int i = 0; i < PAGECACHE_PLUSMINUS; i++)
- flipper.addView(new PageViewer(-1), PAGECACHE_PLUSMINUS + i+1, matchParent);
- */
ll = (LinearLayout)findViewById( R.id.navigator);
inflater = (LayoutInflater) getApplicationContext().getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
-
-
-
for( int i = 0; i < result.intValue() ; i++ ){
ThumbnailView thumb = new ThumbnailView( i , (int)(120.0f / Math.sqrt(2) ) , 120 );
final int pos = i;
@@ -783,9 +758,6 @@ public class DocumentLoader
@Override
public void onClick(View v) {
- // TODO Auto-generated method stub
- Log.d("nav" , Integer.toString( pos ) );
- //openPageWithPrefetching( pos );
documentViewer.open( pos );
}
});
@@ -799,11 +771,9 @@ public class DocumentLoader
private String TAG = "DocumentViewer";
private int currentPage;
private ViewFlipper viewFlipper;
- //int pageCount;
private int lastPage;
private final int firstPage = 0;
- private final int CACHE_PLUSMINUS = 2;
- private final int CACHE_SIZE = 2*CACHE_PLUSMINUS + 1;
+ private final int CACHE_SIZE = 5;
private ViewGroup.LayoutParams matchParent = new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT);
@@ -811,13 +781,12 @@ public class DocumentLoader
private ArrayList<PageViewer> pageViews = new ArrayList<PageViewer>();
public DocumentViewer(ViewFlipper viewFlipper ){
- //Log.i( TAG , "[ " + Integer.toString( rangeStart ) + " , " + Integer.toString( rangeEnd ) + " ]" );
this.currentPage = 0;
this.viewFlipper = viewFlipper;
this.lastPage = pageCount-1;
Log.i( TAG , "pages [0," + Integer.toString( lastPage) + "]" );
viewFlipper.removeAllViews();
- for( int i = 0 ; i < Math.min( lastPage, this.CACHE_SIZE) ; i++){//perhaps loading backwards is best? LRU -> end not start?
+ for( int i = 0 ; i < Math.min( Math.max(lastPage,1), this.CACHE_SIZE) ; i++){//perhaps loading backwards is best? LRU -> end not start?
pageNumbers.add( new Integer(i) );
pageViews.add( new PageViewer( i , viewFlipper.getWidth() , viewFlipper.getHeight()) );
}
commit 5db8fb7c1fb67571d370be22de0eb249d32b8faf
Author: Iain Billett <iainbillett at gmail.com>
Date: Fri Aug 10 00:45:00 2012 +0100
Added a static loading page.
Change-Id: I20a9972c52e39a821e42851f5f075fb870ea0447
diff --git a/android/experimental/LibreOffice4Android/src/org/libreoffice/android/DocumentLoader.java b/android/experimental/LibreOffice4Android/src/org/libreoffice/android/DocumentLoader.java
index b483511..b7a41ad 100644
--- a/android/experimental/LibreOffice4Android/src/org/libreoffice/android/DocumentLoader.java
+++ b/android/experimental/LibreOffice4Android/src/org/libreoffice/android/DocumentLoader.java
@@ -671,9 +671,9 @@ public class DocumentLoader
progressView.setProgress( 10 );
//flipper = new ViewFlipper(DocumentLoader.this);
- //flipper = (ViewFlipper)findViewById( R.id.page_flipper );
- //flipper.addView( waitView , 0 , matchParent);
- //flipper.showNext();
+ ViewFlipper flipper = (ViewFlipper)findViewById( R.id.page_flipper );
+ flipper.addView( waitView , 0 , matchParent);
+ flipper.showNext();
currentPage = 0;
}
commit 2b5828e374ac985fc172d35a266668ee63622058
Author: Iain Billett <iainbillett at gmail.com>
Date: Fri Aug 10 00:31:52 2012 +0100
Complete internal rework of DocumentViewer.
Change-Id: If080c114d38fa39d50a22127def217ad59f262fd
diff --git a/android/experimental/LibreOffice4Android/src/org/libreoffice/android/DocumentLoader.java b/android/experimental/LibreOffice4Android/src/org/libreoffice/android/DocumentLoader.java
index c470375..b483511 100644
--- a/android/experimental/LibreOffice4Android/src/org/libreoffice/android/DocumentLoader.java
+++ b/android/experimental/LibreOffice4Android/src/org/libreoffice/android/DocumentLoader.java
@@ -92,6 +92,7 @@ import com.sun.star.view.XRenderable;
import java.io.*;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
+import java.util.ArrayList;
import org.libreoffice.android.Bootstrap;
import org.libreoffice.ui.LibreOfficeUIActivity;
@@ -126,8 +127,6 @@ public class DocumentLoader
ViewGroup.LayoutParams matchParent;
- ViewFlipper flipper;
-
DocumentViewer documentViewer;
Bundle extras;
@@ -145,6 +144,7 @@ public class DocumentLoader
float velocityY)
{
Log.i(TAG, "onFling: " + event1 + " " + event2);
+ ViewFlipper flipper = documentViewer.getFlipper();
if (event1.getX() - event2.getX() > 120) {
if (((PageViewer)flipper.getCurrentView()).currentPageNumber == pageCount-1)
return false;
@@ -280,7 +280,7 @@ public class DocumentLoader
// Use dummySmallDevice with no scale of offset just to find out
// the paper size of this page.
Log.i( TAG , "Render( " + Integer.toString( number ) + " )");
-
+ ViewFlipper flipper = documentViewer.getFlipper();
if (renderable == null) {
Log.i( TAG , "no renderable");
return null;
@@ -757,7 +757,7 @@ public class DocumentLoader
//matchParent = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
//flipper.removeViewAt( 0 );
documentViewer = new DocumentViewer( (ViewFlipper)findViewById( R.id.page_flipper ) );
- documentViewer.open(0);
+ //documentViewer.open(0);
//currentPage = 0;
//openPageWithPrefetching( currentPage );
@@ -796,6 +796,7 @@ public class DocumentLoader
class DocumentViewer
{
+ private String TAG = "DocumentViewer";
private int currentPage;
private ViewFlipper viewFlipper;
//int pageCount;
@@ -806,128 +807,91 @@ public class DocumentLoader
private ViewGroup.LayoutParams matchParent = new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT);
+ private ArrayList<Integer> pageNumbers = new ArrayList<Integer>();
+ private ArrayList<PageViewer> pageViews = new ArrayList<PageViewer>();
public DocumentViewer(ViewFlipper viewFlipper ){
+ //Log.i( TAG , "[ " + Integer.toString( rangeStart ) + " , " + Integer.toString( rangeEnd ) + " ]" );
this.currentPage = 0;
this.viewFlipper = viewFlipper;
this.lastPage = pageCount-1;
- //viewFlipper.removeAllViews();
- //Not doing this here doesn't sit right can have uninit viewFlipper
+ Log.i( TAG , "pages [0," + Integer.toString( lastPage) + "]" );
viewFlipper.removeAllViews();
- //need to pre-fetch
- for( int i = 0 ; i < this.CACHE_PLUSMINUS + 1 ; i++ ){//Load 0 + cache+- next pages
- if( i > lastPage)
- break;
- viewFlipper.addView( new PageViewer( i , viewFlipper.getWidth() , viewFlipper.getHeight()) , i );
+ for( int i = 0 ; i < Math.min( lastPage, this.CACHE_SIZE) ; i++){//perhaps loading backwards is best? LRU -> end not start?
+ pageNumbers.add( new Integer(i) );
+ pageViews.add( new PageViewer( i , viewFlipper.getWidth() , viewFlipper.getHeight()) );
}
+ viewFlipper.addView( pageViews.get(0) );
+ viewFlipper.setDisplayedChild( 0 );
}
- public DocumentViewer(ViewFlipper viewFlipper, int n ){
- this.currentPage = n;
- this.viewFlipper = viewFlipper;
- this.lastPage = pageCount-1;
- //viewFlipper.removeAllViews();
- //need to pre-fetch
- int pos = 0;
- for(int i = n - this.CACHE_PLUSMINUS ; i < n + this.CACHE_PLUSMINUS ; i++, pos++ ){
- if( i < firstPage || i > lastPage)
- continue;//Perhaps should continue on < and break on > but this seems neater
- viewFlipper.addView( new PageViewer( i , viewFlipper.getWidth() , viewFlipper.getHeight()) , pos );
- }
+ public void nextPage(){
+ open( currentPage + 1 );
}
- public void nextPage(){
- if( this.currentPage == lastPage ){
+ public void prevPage(){
+ open( currentPage - 1 );
+ }
+
+ public void open( int newPage ){
+ if( newPage == currentPage ){
+ Log.i( TAG , "Page " + Integer.toString( newPage ) + " is the current page" );
return;
}
- this.currentPage++;
- if( !( this.currentPage + this.CACHE_PLUSMINUS > lastPage) ){//don't remove view's if there are no more to add
- viewFlipper.removeViewAt( 0 );
- viewFlipper.addView(
- new PageViewer( this.currentPage + this.CACHE_PLUSMINUS, viewFlipper.getWidth() , viewFlipper.getHeight())
- , this.CACHE_SIZE -1 );
+ if( newPage > lastPage || newPage < firstPage ){
+ Log.i( TAG , "Page " + Integer.toString( newPage ) + " is out of Bounds [0," + Integer.toString(lastPage) + "]" );
+ return;
}
- viewFlipper.showNext();
+ viewFlipper.addView( fetch( newPage ) );
+ viewFlipper.setDisplayedChild( 1 );//remove after so that transition has two pages.
+ viewFlipper.removeViewAt( 0 );
+ preFetch( newPage - 1 );
+ preFetch( newPage +1 );
+ currentPage = newPage;
}
- public void prevPage(){
- if( this.currentPage == firstPage ){
- return;
- }
- this.currentPage--;
- if( !( this.currentPage - this.CACHE_PLUSMINUS < 0) ){//don't remove view's if there are no more to add
- viewFlipper.removeViewAt( CACHE_SIZE - 1 );
- viewFlipper.addView(
- new PageViewer( this.currentPage - this.CACHE_PLUSMINUS , viewFlipper.getWidth() , viewFlipper.getHeight())
- , 0 );
+ private PageViewer fetch( int page ){
+ int cacheIndex = pageNumbers.indexOf( page );
+ if( cacheIndex != -1 ){
+ //move item to most recently accessed position
+ pageNumbers.add( pageNumbers.get( cacheIndex ) );
+ pageViews.add( pageViews.get( cacheIndex ) );
+ pageNumbers.remove( cacheIndex );
+ pageViews.remove( cacheIndex );
+ return pageViews.get( pageViews.size() -1 );
+ }else{
+ pageNumbers.remove( 0 );
+ pageViews.remove( 0 );
+ pageNumbers.add( page );
+ pageViews.add( new PageViewer( page , viewFlipper.getWidth() , viewFlipper.getHeight()) );
+ return pageViews.get( pageViews.size() -1 );
}
- viewFlipper.showPrevious();
}
- public void open( int newPage ){
- int diff = newPage - this.currentPage;
- Log.i( TAG , "open( N )");
- Log.i( TAG , "current page : " + Integer.toString( this.currentPage) );
- Log.i( TAG , "opening : " + Integer.toString( newPage ) + " of " + Integer.toString( pageCount ) );
- //diff = 0 -> do nothing
- //abs(diff) >= cachesize -> fill as in constructor
- //if curr > n : new_low foreach in cache ? # < new_low remove : from >n_upper add to end
- //else : upbound foreach in cache ? # >= upbound remove ; add to start
- if( diff == 0 )
+ private void preFetch( int page ){
+ if( page == currentPage ){
+ Log.i( TAG , "Page " + Integer.toString( page ) + " is the current page" );
return;
- if( Math.abs(diff) >= CACHE_SIZE ){
- int pos = 0;
- viewFlipper.removeAllViews();
- for(int i = newPage - this.CACHE_PLUSMINUS ; i < newPage + this.CACHE_PLUSMINUS ; i++, pos++ ){
- if( i < firstPage || i > lastPage)
- continue;//Perhaps should continue on < and break on > but this seems neater
- viewFlipper.addView( new PageViewer( i , viewFlipper.getWidth() , viewFlipper.getHeight()) , pos );
- }
}
-
- if( diff > 0 ){ // new > curr
- int lowerBound = newPage - this.CACHE_PLUSMINUS;// of the new range
- int pos = 0;
- for(int i = 0 ; i < this.CACHE_SIZE ; i++ ){
- if( i >= viewFlipper.getChildCount() )
- break;
- PageViewer page = (PageViewer)viewFlipper.getChildAt( i );
- if( page.getPage() < lowerBound )
- viewFlipper.removeViewAt( i );
- }
- //for others add to end.
- int numberRecycled = viewFlipper.getChildCount();
- for(int i = lowerBound ; i < newPage + this.CACHE_PLUSMINUS ; i++, pos++ ){
- if( pos < numberRecycled)
- continue;
- if( i < firstPage || i > lastPage)
- continue;
- viewFlipper.addView( new PageViewer( i , viewFlipper.getWidth() , viewFlipper.getHeight()), pos , matchParent );
- }
+ if( page > lastPage || page < firstPage ){
+ Log.i( TAG , "Cannot pre-fetch: " + Integer.toString( page ) + " is out of Bounds [0," + Integer.toString(lastPage) + "]" );
+ return;
}
-
- if( diff < 0 ){ // new < curr
- //FIXME The first 5 thumbnails are forwards only.
- int upperBound = newPage + this.CACHE_PLUSMINUS;
- int pos = 0;
- for(int i = 0 ; i < this.CACHE_SIZE ; i++ ){
- if( i >= viewFlipper.getChildCount() )
- break;
- PageViewer page = (PageViewer)viewFlipper.getChildAt( i );
- if( page.getPage() > upperBound )
- viewFlipper.removeViewAt( i );
- }
- int numberRecycled = viewFlipper.getChildCount();
- for(int i = newPage - this.CACHE_PLUSMINUS ; i < upperBound ; i++, pos++ ){
- if( this.CACHE_SIZE - pos < numberRecycled)
- continue;
- if( i < firstPage || i > lastPage)
- continue;
- viewFlipper.addView( new PageViewer( i , viewFlipper.getWidth() , viewFlipper.getHeight()), 0 , matchParent );
- }
+ int cacheIndex = pageNumbers.indexOf( page );
+ if( cacheIndex != -1 ){
+ //move item to most recently accessed position
+ pageNumbers.add( pageNumbers.get( cacheIndex ) );
+ pageViews.add( pageViews.get( cacheIndex ) );
+ pageNumbers.remove( cacheIndex );
+ pageViews.remove( cacheIndex );
+ return ;
+ }else{
+ pageNumbers.remove( 0 );
+ pageViews.remove( 0 );
+ pageNumbers.add( page );
+ pageViews.add( new PageViewer( page , viewFlipper.getWidth() , viewFlipper.getHeight()) );
+ return;
}
- viewFlipper.setDisplayedChild( this.CACHE_PLUSMINUS );
-// viewFlipper.showNext();
}
public ViewFlipper getFlipper(){
More information about the Libreoffice-commits
mailing list