[Libreoffice-commits] .: 2 commits - android/experimental
Iain Billett
iainb at kemper.freedesktop.org
Wed Aug 15 03:35:33 PDT 2012
android/experimental/LibreOffice4Android/src/org/libreoffice/android/DocumentLoader.java | 85 ++++++----
android/experimental/LibreOffice4Android/src/org/libreoffice/ui/GridItemAdapter.java | 10 -
android/experimental/LibreOffice4Android/src/org/libreoffice/ui/LibreOfficeUIActivity.java | 43 +++--
3 files changed, 93 insertions(+), 45 deletions(-)
New commits:
commit e40f2678ab4ec8116e562cda51281762a76bb166
Author: Iain Billett <iainbillett at gmail.com>
Date: Wed Aug 15 11:34:00 2012 +0100
Added soft shadow around thumbnails.
Change-Id: I09926356c54e566a26b9fc944f61d3944dbd4ce0
diff --git a/android/experimental/LibreOffice4Android/src/org/libreoffice/android/DocumentLoader.java b/android/experimental/LibreOffice4Android/src/org/libreoffice/android/DocumentLoader.java
index b7da4b9..bfa3eec 100644
--- a/android/experimental/LibreOffice4Android/src/org/libreoffice/android/DocumentLoader.java
+++ b/android/experimental/LibreOffice4Android/src/org/libreoffice/android/DocumentLoader.java
@@ -35,6 +35,10 @@ import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.graphics.Color;
+import android.graphics.BitmapFactory;
+import android.graphics.BlurMaskFilter;
+import android.graphics.Canvas;
+import android.graphics.Paint;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
@@ -91,6 +95,7 @@ import com.sun.star.view.XRenderable;
import java.io.*;
import java.nio.ByteBuffer;
+import java.nio.IntBuffer;
import java.nio.ByteOrder;
import java.util.ArrayList;
@@ -1050,10 +1055,6 @@ public class DocumentLoader
protected void onDestroy()
{
super.onDestroy();
- //Save the thumbnail of the first page as the grid image.
- // Could easily make a new (larger) thumb but recycling
- // should be faster & more efficient, better for the environment ;-)
- //ll = (LinearLayout)findViewById( R.id.navigator);
Bitmap bmpAlpha = ( (ThumbnailView)ll.getChildAt( 0 ) ).getBitmap();
//For now use these 3 lines to turn the bitmap right way up.
@@ -1061,13 +1062,34 @@ public class DocumentLoader
m.preScale( 1.0f , -1.0f );
Bitmap bmp = Bitmap.createBitmap( bmpAlpha, 0, 0, bmpAlpha.getWidth(), bmpAlpha.getHeight(), m, true);
+ BlurMaskFilter blurFilter = new BlurMaskFilter( 3 , BlurMaskFilter.Blur.OUTER);
+ Paint shadowPaint = new Paint();
+ shadowPaint.setMaskFilter(blurFilter);
+
+ int[] offsetXY = new int[2];
+ Bitmap shadowImage = bmp.extractAlpha(shadowPaint, offsetXY);
+ Bitmap shadowImage32 = shadowImage.copy(Bitmap.Config.ARGB_8888, true);
+
+ ByteBuffer pxBuffer = ByteBuffer.allocate( shadowImage32.getByteCount() );
+ IntBuffer intPxBuffer = IntBuffer.allocate( shadowImage32.getByteCount()/4 );
+ shadowImage32.copyPixelsToBuffer( pxBuffer );
+ for( int i = 0 ; i < shadowImage32.getByteCount()/4 ; i++ ){
+ int pxA = (int)( pxBuffer.get( i*4 + 3) );//TODO make sure byte0 is A
+ intPxBuffer.put( i , Color.argb( (int)( pxA*0.25f) , 0 , 0 , 0 ) );
+ }
+ shadowImage32.copyPixelsFromBuffer( intPxBuffer );
+
+ Canvas c = new Canvas(shadowImage32);
+ c.drawBitmap(bmp, -offsetXY[0], -offsetXY[1], null);
+
File file = new File(extras.getString("input"));
Log.i(TAG ,"onDestroy " + extras.getString("input"));
File dir = file.getParentFile();
File thumbnailFile = new File( dir , "." + file.getName().split("[.]")[0] + ".png");
try {
+ Log.i( TAG , Integer.toString( shadowImage32.getWidth() - bmp.getWidth() ) );
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
- bmp.compress(Bitmap.CompressFormat.PNG, 40, bytes);
+ shadowImage32.compress(Bitmap.CompressFormat.PNG, 40, bytes);
thumbnailFile.createNewFile();
FileOutputStream fo = new FileOutputStream( thumbnailFile );
fo.write(bytes.toByteArray());
diff --git a/android/experimental/LibreOffice4Android/src/org/libreoffice/ui/GridItemAdapter.java b/android/experimental/LibreOffice4Android/src/org/libreoffice/ui/GridItemAdapter.java
index 664a04e..1210e0e 100644
--- a/android/experimental/LibreOffice4Android/src/org/libreoffice/ui/GridItemAdapter.java
+++ b/android/experimental/LibreOffice4Android/src/org/libreoffice/ui/GridItemAdapter.java
@@ -12,6 +12,8 @@ import org.libreoffice.R;
import java.io.File;
+import java.nio.ByteBuffer;
+import java.nio.IntBuffer;
import android.content.Context;
import android.util.Log;
@@ -23,18 +25,22 @@ import android.widget.ImageView;
import android.widget.TextView;
import android.graphics.BitmapFactory;
import android.graphics.Bitmap;
+import android.graphics.BlurMaskFilter;
+import android.graphics.Canvas;
+import android.graphics.Paint;
+import android.graphics.Color;
public class GridItemAdapter extends BaseAdapter{
Context mContext;
File[] filePaths;
File currentDirectory;
- String tag = "GridItemAdapter";
+ String TAG = "GridItemAdapter";
public GridItemAdapter(Context mContext, File[] filePaths) {
this.mContext = mContext;
this.filePaths = filePaths;
for(File fn : filePaths){
- Log.d(tag, fn.getName());
+ Log.d(TAG, fn.getName());
}
}
diff --git a/android/experimental/LibreOffice4Android/src/org/libreoffice/ui/LibreOfficeUIActivity.java b/android/experimental/LibreOffice4Android/src/org/libreoffice/ui/LibreOfficeUIActivity.java
index 7c824f8..2a2b22f 100644
--- a/android/experimental/LibreOffice4Android/src/org/libreoffice/ui/LibreOfficeUIActivity.java
+++ b/android/experimental/LibreOffice4Android/src/org/libreoffice/ui/LibreOfficeUIActivity.java
@@ -20,11 +20,6 @@ import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.prefs.Preferences;
-//import android.app.ActionBar;
-//import android.view.Menu;
-//import android.view.MenuInflater;
-//import android.view.MenuItem;
-
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
@@ -33,6 +28,10 @@ import com.actionbarsherlock.app.SherlockActivity;
import android.graphics.drawable.BitmapDrawable;
import android.os.Build;
import android.graphics.Shader.TileMode;
+import android.graphics.BlurMaskFilter;
+import android.graphics.Canvas;
+import android.graphics.Paint;
+import android.graphics.Color;
import android.app.ActionBar.OnNavigationListener;
import android.app.Activity;
@@ -81,6 +80,7 @@ import com.sun.star.view.XRenderable;
import java.io.*;
import java.nio.ByteBuffer;
+import java.nio.IntBuffer;
import java.nio.ByteOrder;
public class LibreOfficeUIActivity extends SherlockActivity implements ActionBar.OnNavigationListener {
@@ -734,16 +734,6 @@ class ListItemAdapter implements ListAdapter{
return null;
}
- protected void onPreExecute ()
- {
- try{
-
- }
- catch (Exception e) {
- e.printStackTrace(System.err);
- }
- }
-
protected Integer doInBackground(String... params)
{
try {
@@ -869,11 +859,32 @@ class ListItemAdapter implements ListAdapter{
Matrix m = new Matrix();
m.preScale( 1.0f , -1.0f );
Bitmap bmp = Bitmap.createBitmap( bm, 0, 0, bm.getWidth(), bm.getHeight(), m, true);
+
+ BlurMaskFilter blurFilter = new BlurMaskFilter( 3 , BlurMaskFilter.Blur.OUTER);
+ Paint shadowPaint = new Paint();
+ shadowPaint.setMaskFilter(blurFilter);
+
+ int[] offsetXY = new int[2];
+ Bitmap shadowImage = bmp.extractAlpha(shadowPaint, offsetXY);
+ Bitmap shadowImage32 = shadowImage.copy(Bitmap.Config.ARGB_8888, true);
+
+ ByteBuffer pxBuffer = ByteBuffer.allocate( shadowImage32.getByteCount() );
+ IntBuffer intPxBuffer = IntBuffer.allocate( shadowImage32.getByteCount()/4 );
+ shadowImage32.copyPixelsToBuffer( pxBuffer );
+ for( int i = 0 ; i < shadowImage32.getByteCount()/4 ; i++ ){
+ int pxA = (int)( pxBuffer.get( i*4 + 3) );
+ intPxBuffer.put( i , Color.argb( (int)( pxA*0.25f) , 0 , 0 , 0 ) );
+ }
+ shadowImage32.copyPixelsFromBuffer( intPxBuffer );
+ //Draw the image onto the shadow bitmap.
+ Canvas c = new Canvas(shadowImage32);
+ c.drawBitmap(bmp, -offsetXY[0], -offsetXY[1], null);
+
File dir = file.getParentFile();
File thumbnailFile = new File( dir , "." + file.getName().split("[.]")[0] + ".png");
try {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
- bmp.compress(Bitmap.CompressFormat.PNG, 40, bytes);
+ shadowImage32.compress(Bitmap.CompressFormat.PNG, 40, bytes);
thumbnailFile.createNewFile();
FileOutputStream fo = new FileOutputStream( thumbnailFile );
fo.write(bytes.toByteArray());
commit 6078a319491c0342aba883ba498f92f056a5e85d
Author: Iain Billett <iainbillett at gmail.com>
Date: Fri Aug 10 12:30:38 2012 +0100
Moved Animation code to DocumentViewer.
Change-Id: I3a21783a1ade19bd0c868f58137d244a13e0d132
diff --git a/android/experimental/LibreOffice4Android/src/org/libreoffice/android/DocumentLoader.java b/android/experimental/LibreOffice4Android/src/org/libreoffice/android/DocumentLoader.java
index edfb13b..b7da4b9 100644
--- a/android/experimental/LibreOffice4Android/src/org/libreoffice/android/DocumentLoader.java
+++ b/android/experimental/LibreOffice4Android/src/org/libreoffice/android/DocumentLoader.java
@@ -148,33 +148,11 @@ public class DocumentLoader
if (event1.getX() - event2.getX() > 120) {
if (((PageViewer)flipper.getCurrentView()).currentPageNumber == pageCount-1)
return false;
-
- Animation inFromRight = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 1, Animation.RELATIVE_TO_SELF, 0,
- Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0);
- inFromRight.setDuration(500);
- flipper.setInAnimation(inFromRight);
-
- Animation outToLeft = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, -1,
- Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0);
- outToLeft.setDuration(500);
- flipper.setOutAnimation(outToLeft);
-
documentViewer.nextPage();
return true;
} else if (event2.getX() - event1.getX() > 120) {
if (((PageViewer)flipper.getCurrentView()).currentPageNumber == 0)
return false;
-
- Animation inFromLeft = new TranslateAnimation(Animation.RELATIVE_TO_SELF, -1, Animation.RELATIVE_TO_SELF, 0,
- Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0);
- inFromLeft.setDuration(500);
- flipper.setInAnimation(inFromLeft);
-
- Animation outToRight = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 1,
- Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0);
- outToRight.setDuration(500);
- flipper.setOutAnimation(outToRight);
-
documentViewer.prevPage();
return true;
}
@@ -811,6 +789,11 @@ public class DocumentLoader
Log.i( TAG , "Page " + Integer.toString( newPage ) + " is out of Bounds [0," + Integer.toString(lastPage) + "]" );
return;
}
+ if( newPage - currentPage > 0 ){
+ setAnimationInFromRight();
+ }else{
+ setAnimationInFromLeft();
+ }
viewFlipper.addView( fetch( newPage ) );
viewFlipper.setDisplayedChild( 1 );//remove after so that transition has two pages.
viewFlipper.removeViewAt( 0 );
@@ -819,6 +802,32 @@ public class DocumentLoader
currentPage = newPage;
}
+ private void setAnimationInFromRight(){//going forward
+ Animation inFromRight = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 1, Animation.RELATIVE_TO_SELF, 0,
+ Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0);
+ inFromRight.setDuration(500);
+ viewFlipper.setInAnimation(inFromRight);
+
+ Animation outToLeft = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, -1,
+ Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0);
+ outToLeft.setDuration(500);
+ viewFlipper.setOutAnimation(outToLeft);
+ return;
+ }
+
+ private void setAnimationInFromLeft(){
+ Animation inFromLeft = new TranslateAnimation(Animation.RELATIVE_TO_SELF, -1, Animation.RELATIVE_TO_SELF, 0,
+ Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0);
+ inFromLeft.setDuration(500);
+ viewFlipper.setInAnimation(inFromLeft);
+
+ Animation outToRight = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 1,
+ Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0);
+ outToRight.setDuration(500);
+ viewFlipper.setOutAnimation(outToRight);
+ return;
+ }
+
private PageViewer fetch( int page ){
int cacheIndex = pageNumbers.indexOf( page );
if( cacheIndex != -1 ){
More information about the Libreoffice-commits
mailing list