summaryrefslogtreecommitdiffstats
path: root/android
diff options
context:
space:
mode:
authorIain Billett <iainbillett@gmail.com>2012-08-15 11:34:00 +0100
committerIain Billett <iainbillett@gmail.com>2012-08-15 11:35:22 +0100
commite40f2678ab4ec8116e562cda51281762a76bb166 (patch)
tree2d17e47acd3c1987b425eae549d3e7269f679395 /android
parentMoved Animation code to DocumentViewer. (diff)
downloadcore-e40f2678ab4ec8116e562cda51281762a76bb166.tar.gz
core-e40f2678ab4ec8116e562cda51281762a76bb166.zip
Added soft shadow around thumbnails.
Change-Id: I09926356c54e566a26b9fc944f61d3944dbd4ce0
Diffstat (limited to 'android')
-rw-r--r--android/experimental/LibreOffice4Android/src/org/libreoffice/android/DocumentLoader.java32
-rw-r--r--android/experimental/LibreOffice4Android/src/org/libreoffice/ui/GridItemAdapter.java10
-rw-r--r--android/experimental/LibreOffice4Android/src/org/libreoffice/ui/LibreOfficeUIActivity.java43
3 files changed, 62 insertions, 23 deletions
diff --git a/android/experimental/LibreOffice4Android/src/org/libreoffice/android/DocumentLoader.java b/android/experimental/LibreOffice4Android/src/org/libreoffice/android/DocumentLoader.java
index b7da4b99cf52..bfa3eec66c23 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 664a04e10c92..1210e0ec7e03 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 7c824f8429d2..2a2b22f9d044 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());