package com.sekond.liquidroid;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore.Images.Media;
import android.util.Log;
import android.view.Display;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.Toast;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
public class LiquiDroid extends Activity
{
private static final int MENU_ABOUT = 7;
private static final int MENU_CAMERA = 1;
private static final int MENU_DELETE = 2;
private static final int MENU_GALLERY = 4;
private static final int MENU_PREF = 5;
private static final int MENU_SAVE = 3;
private static final int MENU_SHARE = 6;
private static final int SHOW_CAMERA = 0;
private static final int SHOW_GALLERY = 1;
private static final int SHOW_PREFERENCES = 2;
private static final String TAG = "LiquiDroidMain";
private static final float TOUCH_TOLERANCE = 4.0F;
private int CIRCLE_SIZE = 10;
private float DISPLACEMENT_SCALE = 40.0F;
File FILE;
private String FILENAME = "liquidroid.jpg";
private int OFFSET = 40;
private String SD_CARD_DIR = Environment.getExternalStorageDirectory().toString();
public Bitmap mBitmapMap;
private Bitmap mBitmapRes;
private Bitmap mBitmapSource;
private View mDecorView;
private float mDisplScaleNormalized = this.DISPLACEMENT_SCALE / 256.0F;
private int mDisplayHeight = 480;
private int mDisplayWidth = 320;
private int mImageHeight = 480;
private String mImageUri;
private int mImageWidth = 320;
File mLiquiDroidDirectory;
private ImageView mMainView;
private LiquiDroidMapDrawView mMapDrawView;
private float mX;
private float mY;
int[] mdXY = new int[2];
private SimpleDateFormat timeStampFormat = new SimpleDateFormat("yyyy-MM-dd HH.mm.ss");
private int touchXMinusOFFSET = 0;
private int touchXPlusOFFSET = 0;
private int touchYMinusOFFSET = 0;
private int touchYPlusOFFSET = 0;
private int[] applyMapDrawFilter(int paramInt1, int paramInt2)
{
int i = this.mBitmapMap.getPixel((int)Math.floor(paramInt1 / 2.0D), (int)Math.floor(paramInt2 / 2.0D));
int j = 0xFF & i >> 16;
int k = 0xFF & i >> 8;
if ((j == 0) && (k == 0))
{
j = 128;
k = 128;
}
this.mdXY[0] = ((int)((j - 128) * this.mDisplScaleNormalized));
this.mdXY[1] = ((int)((k - 128) * this.mDisplScaleNormalized));
return this.mdXY;
}
private void createLiquidroidDir()
{
this.mLiquiDroidDirectory = new File(new File(this.SD_CARD_DIR), "Liquidroid");
if (!this.mLiquiDroidDirectory.mkdirs())
Log.e("LiquiDroidMain", "Create dir in DCIM failed");
}
private void drawDisplacementMapFilter(int paramInt1, int paramInt2)
{
this.touchXMinusOFFSET = (paramInt1 - this.OFFSET);
this.touchXPlusOFFSET = (paramInt1 + this.OFFSET);
this.touchYMinusOFFSET = (paramInt2 - this.OFFSET);
this.touchYPlusOFFSET = (paramInt2 + this.OFFSET);
double d1 = paramInt1 - this.mX;
double d2 = paramInt2 - this.mY;
double d3 = Math.atan2(-d1, d2);
double d4 = 128.0D + 127.0D * Math.sin(d3);
double d5 = 128.0D - 127.0D * Math.cos(d3);
if ((Math.abs(d1) >= 4.0D) || (Math.abs(d2) >= 4.0D))
{
this.mX = paramInt1;
this.mY = paramInt2;
}
this.mMapDrawView.drawCircle((int)d4, (int)d5, 0, (int)Math.floor(this.mX / 2.0F), (int)Math.floor(this.mY / 2.0F), this.CIRCLE_SIZE);
this.mMapDrawView.invalidate(this.touchXMinusOFFSET, this.touchYPlusOFFSET, this.touchXPlusOFFSET, this.touchYMinusOFFSET);
this.mBitmapMap = this.mMapDrawView.getMap();
}
private void initializeBitmaps()
{
this.mBitmapSource = BitmapFactory.decodeResource(getResources(), 2130837526);
this.mBitmapSource = scaleImagePreserveAspectRatio(this.mBitmapSource, this.mDisplayWidth, this.mDisplayHeight);
this.mImageWidth = this.mBitmapSource.getWidth();
this.mImageHeight = this.mBitmapSource.getHeight();
this.mMapDrawView = new LiquiDroidMapDrawView(this, this.mImageWidth, this.mImageHeight);
this.mMainView = ((ImageView)findViewById(2131165193));
this.mMainView.setImageBitmap(this.mBitmapSource);
this.mMainView.invalidate();
this.mBitmapMap = Bitmap.createBitmap(this.mImageWidth, this.mImageHeight, Bitmap.Config.ARGB_8888);
this.mBitmapRes = this.mBitmapSource.copy(Bitmap.Config.ARGB_8888, true);
}
private void openGallery()
{
Intent localIntent = new Intent("android.intent.action.PICK");
localIntent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "vnd.android.cursor.dir/image");
startActivityForResult(localIntent, 1);
}
private void resetImageToOriginal()
{
this.mMapDrawView.resetMapDrawView(this.mImageWidth, this.mImageHeight);
this.mMapDrawView.invalidate();
this.mBitmapRes = this.mBitmapSource.copy(Bitmap.Config.ARGB_8888, true);
this.mMainView.setImageBitmap(this.mBitmapSource);
this.mMainView.invalidate();
}
private void saveImage()
{
this.FILENAME = this.timeStampFormat.format(new Date());
this.FILE = new File(this.mLiquiDroidDirectory + File.separator + this.FILENAME);
this.mImageUri = MediaStore.Images.Media.insertImage(getContentResolver(), this.mBitmapRes, this.FILENAME, "LiquiDroidMain");
saveImageToSdCard(this.mBitmapRes, this.FILE.getAbsolutePath());
showToast(getApplicationContext(), this.FILE.getAbsolutePath());
}
private void saveImageToSdCard(Bitmap paramBitmap, String paramString)
{
try
{
FileOutputStream localFileOutputStream = new FileOutputStream(paramString + ".jpg");
paramBitmap.compress(Bitmap.CompressFormat.JPEG, 90, localFileOutputStream);
return;
}
catch (Exception localException)
{
while (true)
localException.printStackTrace();
}
}
private Bitmap scaleImagePreserveAspectRatio(Bitmap paramBitmap, int paramInt1, int paramInt2)
{
float f = paramBitmap.getWidth() / paramBitmap.getHeight();
Bitmap localBitmap;
if (paramBitmap.getWidth() > paramInt1)
localBitmap = Bitmap.createScaledBitmap(paramBitmap, paramInt1, Math.round(paramInt1 / f), true);
while (true)
{
return localBitmap;
if (paramBitmap.getHeight() > paramInt2)
localBitmap = Bitmap.createScaledBitmap(paramBitmap, Math.round(f * paramInt1), paramInt2, true);
else
localBitmap = paramBitmap;
}
}
private void shareImage()
{
saveImage();
Intent localIntent = new Intent("android.intent.action.SEND");
localIntent.setType("image/image");
localIntent.addFlags(1);
localIntent.putExtra("android.intent.extra.SUBJECT", "Liquidroid ");
localIntent.putExtra("android.intent.extra.TEXT", "LiquiDroid ");
localIntent.putExtra("android.intent.extra.STREAM", Uri.parse(this.mImageUri));
startActivity(Intent.createChooser(localIntent, "Share image"));
}
private void showToast(Context paramContext, String paramString)
{
Toast.makeText(paramContext, paramString, 0).show();
}
private void startCamera()
{
this.FILENAME = this.timeStampFormat.format(new Date());
this.FILE = new File(this.mLiquiDroidDirectory + File.separator + this.FILENAME);
Intent localIntent = new Intent("android.media.action.IMAGE_CAPTURE");
localIntent.putExtra("output", Uri.fromFile(this.FILE));
startActivityForResult(localIntent, 0);
}
public void applyDisplacementMapFilter()
{
int j;
for (int i = this.touchYMinusOFFSET; ; i++)
{
if (i >= this.touchYPlusOFFSET)
{
this.mMainView.setImageBitmap(this.mBitmapRes);
this.mMainView.invalidate(this.touchXMinusOFFSET, this.touchYPlusOFFSET, this.touchXPlusOFFSET, this.touchYMinusOFFSET);
return;
}
j = this.touchXMinusOFFSET;
if (j < this.touchXPlusOFFSET)
break;
}
if ((i >= 0) && (i < this.mImageHeight) && (j >= 0) && (j < this.mImageWidth))
{
this.mdXY = applyMapDrawFilter(j, i);
int k = j + this.mdXY[0];
int m = i + this.mdXY[1];
if ((m >= this.mImageHeight) || (k >= this.mImageWidth) || (m < 0) || (k < 0))
break label171;
this.mBitmapRes.setPixel(j, i, this.mBitmapSource.getPixel(k, m));
}
while (true)
{
j++;
break;
label171: this.mBitmapRes.setPixel(j, i, this.mBitmapSource.getPixel(j, i));
}
}
protected void onActivityResult(int paramInt1, int paramInt2, Intent paramIntent)
{
this.mBitmapSource.recycle();
this.mBitmapRes.recycle();
System.gc();
if ((paramInt2 != -1) || (paramInt1 != 0) || (this.FILE.isFile()));
while (true)
{
try
{
this.mImageUri = MediaStore.Images.Media.insertImage(getContentResolver(), this.FILE.getAbsolutePath(), this.FILENAME, "LiquiDroid");
this.mBitmapSource = BitmapFactory.decodeFile(this.FILE.getAbsolutePath());
this.mBitmapSource = scaleImagePreserveAspectRatio(this.mBitmapSource, this.mDisplayWidth, this.mDisplayHeight);
this.mImageWidth = this.mBitmapSource.getWidth();
this.mImageHeight = this.mBitmapSource.getHeight();
this.mBitmapRes = this.mBitmapSource.copy(Bitmap.Config.ARGB_8888, true);
this.mMainView.setImageBitmap(this.mBitmapSource);
this.mMainView.invalidate();
this.mMapDrawView.resetMapDrawView(this.mImageWidth, this.mImageHeight);
this.FILE.delete();
if ((paramInt2 == -1) && (paramInt1 == 1))
{
Cursor localCursor = managedQuery(paramIntent.getData(), null, null, null, null);
if (localCursor.moveToFirst())
{
this.FILE = new File(localCursor.getString(1));
this.mBitmapSource = BitmapFactory.decodeFile(this.FILE.getAbsolutePath());
this.mBitmapSource = scaleImagePreserveAspectRatio(this.mBitmapSource, this.mDisplayWidth, this.mDisplayHeight);
this.mImageWidth = this.mBitmapSource.getWidth();
this.mImageHeight = this.mBitmapSource.getHeight();
this.mBitmapRes = this.mBitmapSource.copy(Bitmap.Config.ARGB_8888, true);
this.mMainView.setImageBitmap(this.mBitmapSource);
this.mMainView.invalidate();
this.mMapDrawView.resetMapDrawView(this.mImageWidth, this.mImageHeight);
}
}
if (paramInt2 == 0)
initializeBitmaps();
return;
}
catch (FileNotFoundException localFileNotFoundException)
{
localFileNotFoundException.printStackTrace();
continue;
}
Intent localIntent = new Intent("android.intent.action.PICK");
localIntent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "vnd.android.cursor.dir/image");
startActivityForResult(localIntent, 1);
}
}
protected void onCreate(Bundle paramBundle)
{
super.onCreate(paramBundle);
setContentView(2130903041);
Display localDisplay = ((WindowManager)getSystemService("window")).getDefaultDisplay();
this.mDisplayWidth = localDisplay.getWidth();
this.mDisplayHeight = localDisplay.getHeight();
initializeBitmaps();
this.mDecorView = getWindow().getDecorView();
runOnUiThread(new LiquiDroid.1(this));
((ImageButton)findViewById(2131165194)).setOnClickListener(new LiquiDroid.2(this));
((ImageButton)findViewById(2131165195)).setOnClickListener(new LiquiDroid.3(this));
((ImageButton)findViewById(2131165196)).setOnClickListener(new LiquiDroid.4(this));
((ImageButton)findViewById(2131165197)).setOnClickListener(new LiquiDroid.5(this));
showToast(this, "Touch and squeeze to liquify.\n Have fun!");
createLiquidroidDir();
}
public boolean onCreateOptionsMenu(Menu paramMenu)
{
super.onCreateOptionsMenu(paramMenu);
MenuItem localMenuItem1 = paramMenu.add(0, 1, 0, "Use Camera");
MenuItem localMenuItem2 = paramMenu.add(0, 2, 0, "Reset Image");
MenuItem localMenuItem3 = paramMenu.add(0, 3, 0, "Save Image");
MenuItem localMenuItem4 = paramMenu.add(0, 4, 0, "Open Gallery");
MenuItem localMenuItem5 = paramMenu.add(0, 6, 0, "Share Image");
MenuItem localMenuItem6 = paramMenu.add(0, 7, 0, "About");
localMenuItem1.setIcon(17301559);
localMenuItem2.setIcon(17301580);
localMenuItem3.setIcon(17301582);
localMenuItem4.setIcon(17301567);
localMenuItem5.setIcon(17301586);
localMenuItem6.setIcon(17301569);
return true;
}
public boolean onOptionsItemSelected(MenuItem paramMenuItem)
{
switch (paramMenuItem.getItemId())
{
default:
case 1:
case 3:
case 6:
case 4:
case 2:
case 5:
case 7:
}
while (true)
{
return super.onOptionsItemSelected(paramMenuItem);
startCamera();
continue;
saveImage();
continue;
shareImage();
continue;
openGallery();
continue;
resetImageToOriginal();
continue;
this.mMainView.setImageBitmap(this.mMapDrawView.getMap());
this.mMainView.invalidate();
continue;
startActivity(new Intent(this, LiquiDroidAbout.class));
}
}
public boolean onPrepareOptionsMenu(Menu paramMenu)
{
super.onPrepareOptionsMenu(paramMenu);
return true;
}
public boolean onTouchEvent(MotionEvent paramMotionEvent)
{
float f1 = paramMotionEvent.getX();
float f2 = paramMotionEvent.getY();
switch (paramMotionEvent.getAction())
{
case 1:
default:
case 0:
case 2:
}
while (true)
{
return true;
this.mX = f1;
this.mY = f2;
continue;
drawDisplacementMapFilter((int)f1, (int)f2);
applyDisplacementMapFilter();
}
}
}
-----------------
Vieww Xclasss
package com.sekond.liquidroid;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.BlurMaskFilter;
import android.graphics.BlurMaskFilter.Blur;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.MaskFilter;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.view.View;
public class LiquiDroidMapDrawView extends View
{
public int BLUR_FILTER_SIZE = 8;
private Bitmap mBitmap;
private Paint mBitmapPaint;
private Bitmap mBitmapResult;
private MaskFilter mBlur;
private int mBmpHeight = 240;
private int mBmpWidth = 160;
private Canvas mCanvas;
private Canvas mCanvasResult;
private Paint mPaintMap;
public LiquiDroidMapDrawView(Context paramContext, int paramInt1, int paramInt2)
{
super(paramContext);
this.mBmpWidth = ((int)Math.round(paramInt1 / 2.0D));
this.mBmpHeight = ((int)Math.round(paramInt2 / 2.0D));
this.mBitmap = Bitmap.createBitmap(this.mBmpWidth, this.mBmpHeight, Bitmap.Config.ARGB_8888);
this.mCanvas = new Canvas(this.mBitmap);
this.mBitmapPaint = new Paint(4);
this.mPaintMap = new Paint();
this.mPaintMap.setAntiAlias(false);
this.mPaintMap.setDither(false);
this.mPaintMap.setColor(Color.rgb(128, 128, 128));
this.mPaintMap.setStyle(Paint.Style.FILL);
this.mPaintMap.setStrokeWidth(this.BLUR_FILTER_SIZE);
this.mBlur = new BlurMaskFilter(this.BLUR_FILTER_SIZE, BlurMaskFilter.Blur.NORMAL);
this.mPaintMap.setMaskFilter(this.mBlur);
this.mBitmapResult = Bitmap.createBitmap(this.mBmpWidth, this.mBmpHeight, Bitmap.Config.ARGB_8888);
this.mCanvasResult = new Canvas(this.mBitmapResult);
}
public void drawCircle(int paramInt1, int paramInt2, int paramInt3, float paramFloat1, float paramFloat2, int paramInt4)
{
this.mPaintMap.setColor(Color.rgb(paramInt1, paramInt2, paramInt3));
this.mCanvas.drawCircle(paramFloat1, paramFloat2, paramInt4, this.mPaintMap);
}
public Bitmap getMap()
{
this.mCanvasResult.drawColor(Color.rgb(128, 128, 128));
this.mCanvasResult.drawBitmap(this.mBitmap, 0.0F, 0.0F, this.mBitmapPaint);
draw(this.mCanvasResult);
return this.mBitmapResult;
}
protected void onDraw(Canvas paramCanvas)
{
}
protected void onSizeChanged(int paramInt1, int paramInt2, int paramInt3, int paramInt4)
{
super.onSizeChanged(paramInt1, paramInt2, paramInt3, paramInt4);
}
public void resetMapDrawView(int paramInt1, int paramInt2)
{
this.mBmpWidth = ((int)Math.round(paramInt1 / 2.0D));
this.mBmpHeight = ((int)Math.round(paramInt2 / 2.0D));
this.mBitmap = Bitmap.createBitmap(this.mBmpWidth, this.mBmpHeight, Bitmap.Config.ARGB_8888);
this.mCanvas = new Canvas(this.mBitmap);
this.mBitmapResult = Bitmap.createBitmap(this.mBmpWidth, this.mBmpHeight, Bitmap.Config.ARGB_8888);
this.mCanvasResult = new Canvas(this.mBitmapResult);
}
}
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore.Images.Media;
import android.util.Log;
import android.view.Display;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.Toast;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
public class LiquiDroid extends Activity
{
private static final int MENU_ABOUT = 7;
private static final int MENU_CAMERA = 1;
private static final int MENU_DELETE = 2;
private static final int MENU_GALLERY = 4;
private static final int MENU_PREF = 5;
private static final int MENU_SAVE = 3;
private static final int MENU_SHARE = 6;
private static final int SHOW_CAMERA = 0;
private static final int SHOW_GALLERY = 1;
private static final int SHOW_PREFERENCES = 2;
private static final String TAG = "LiquiDroidMain";
private static final float TOUCH_TOLERANCE = 4.0F;
private int CIRCLE_SIZE = 10;
private float DISPLACEMENT_SCALE = 40.0F;
File FILE;
private String FILENAME = "liquidroid.jpg";
private int OFFSET = 40;
private String SD_CARD_DIR = Environment.getExternalStorageDirectory().toString();
public Bitmap mBitmapMap;
private Bitmap mBitmapRes;
private Bitmap mBitmapSource;
private View mDecorView;
private float mDisplScaleNormalized = this.DISPLACEMENT_SCALE / 256.0F;
private int mDisplayHeight = 480;
private int mDisplayWidth = 320;
private int mImageHeight = 480;
private String mImageUri;
private int mImageWidth = 320;
File mLiquiDroidDirectory;
private ImageView mMainView;
private LiquiDroidMapDrawView mMapDrawView;
private float mX;
private float mY;
int[] mdXY = new int[2];
private SimpleDateFormat timeStampFormat = new SimpleDateFormat("yyyy-MM-dd HH.mm.ss");
private int touchXMinusOFFSET = 0;
private int touchXPlusOFFSET = 0;
private int touchYMinusOFFSET = 0;
private int touchYPlusOFFSET = 0;
private int[] applyMapDrawFilter(int paramInt1, int paramInt2)
{
int i = this.mBitmapMap.getPixel((int)Math.floor(paramInt1 / 2.0D), (int)Math.floor(paramInt2 / 2.0D));
int j = 0xFF & i >> 16;
int k = 0xFF & i >> 8;
if ((j == 0) && (k == 0))
{
j = 128;
k = 128;
}
this.mdXY[0] = ((int)((j - 128) * this.mDisplScaleNormalized));
this.mdXY[1] = ((int)((k - 128) * this.mDisplScaleNormalized));
return this.mdXY;
}
private void createLiquidroidDir()
{
this.mLiquiDroidDirectory = new File(new File(this.SD_CARD_DIR), "Liquidroid");
if (!this.mLiquiDroidDirectory.mkdirs())
Log.e("LiquiDroidMain", "Create dir in DCIM failed");
}
private void drawDisplacementMapFilter(int paramInt1, int paramInt2)
{
this.touchXMinusOFFSET = (paramInt1 - this.OFFSET);
this.touchXPlusOFFSET = (paramInt1 + this.OFFSET);
this.touchYMinusOFFSET = (paramInt2 - this.OFFSET);
this.touchYPlusOFFSET = (paramInt2 + this.OFFSET);
double d1 = paramInt1 - this.mX;
double d2 = paramInt2 - this.mY;
double d3 = Math.atan2(-d1, d2);
double d4 = 128.0D + 127.0D * Math.sin(d3);
double d5 = 128.0D - 127.0D * Math.cos(d3);
if ((Math.abs(d1) >= 4.0D) || (Math.abs(d2) >= 4.0D))
{
this.mX = paramInt1;
this.mY = paramInt2;
}
this.mMapDrawView.drawCircle((int)d4, (int)d5, 0, (int)Math.floor(this.mX / 2.0F), (int)Math.floor(this.mY / 2.0F), this.CIRCLE_SIZE);
this.mMapDrawView.invalidate(this.touchXMinusOFFSET, this.touchYPlusOFFSET, this.touchXPlusOFFSET, this.touchYMinusOFFSET);
this.mBitmapMap = this.mMapDrawView.getMap();
}
private void initializeBitmaps()
{
this.mBitmapSource = BitmapFactory.decodeResource(getResources(), 2130837526);
this.mBitmapSource = scaleImagePreserveAspectRatio(this.mBitmapSource, this.mDisplayWidth, this.mDisplayHeight);
this.mImageWidth = this.mBitmapSource.getWidth();
this.mImageHeight = this.mBitmapSource.getHeight();
this.mMapDrawView = new LiquiDroidMapDrawView(this, this.mImageWidth, this.mImageHeight);
this.mMainView = ((ImageView)findViewById(2131165193));
this.mMainView.setImageBitmap(this.mBitmapSource);
this.mMainView.invalidate();
this.mBitmapMap = Bitmap.createBitmap(this.mImageWidth, this.mImageHeight, Bitmap.Config.ARGB_8888);
this.mBitmapRes = this.mBitmapSource.copy(Bitmap.Config.ARGB_8888, true);
}
private void openGallery()
{
Intent localIntent = new Intent("android.intent.action.PICK");
localIntent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "vnd.android.cursor.dir/image");
startActivityForResult(localIntent, 1);
}
private void resetImageToOriginal()
{
this.mMapDrawView.resetMapDrawView(this.mImageWidth, this.mImageHeight);
this.mMapDrawView.invalidate();
this.mBitmapRes = this.mBitmapSource.copy(Bitmap.Config.ARGB_8888, true);
this.mMainView.setImageBitmap(this.mBitmapSource);
this.mMainView.invalidate();
}
private void saveImage()
{
this.FILENAME = this.timeStampFormat.format(new Date());
this.FILE = new File(this.mLiquiDroidDirectory + File.separator + this.FILENAME);
this.mImageUri = MediaStore.Images.Media.insertImage(getContentResolver(), this.mBitmapRes, this.FILENAME, "LiquiDroidMain");
saveImageToSdCard(this.mBitmapRes, this.FILE.getAbsolutePath());
showToast(getApplicationContext(), this.FILE.getAbsolutePath());
}
private void saveImageToSdCard(Bitmap paramBitmap, String paramString)
{
try
{
FileOutputStream localFileOutputStream = new FileOutputStream(paramString + ".jpg");
paramBitmap.compress(Bitmap.CompressFormat.JPEG, 90, localFileOutputStream);
return;
}
catch (Exception localException)
{
while (true)
localException.printStackTrace();
}
}
private Bitmap scaleImagePreserveAspectRatio(Bitmap paramBitmap, int paramInt1, int paramInt2)
{
float f = paramBitmap.getWidth() / paramBitmap.getHeight();
Bitmap localBitmap;
if (paramBitmap.getWidth() > paramInt1)
localBitmap = Bitmap.createScaledBitmap(paramBitmap, paramInt1, Math.round(paramInt1 / f), true);
while (true)
{
return localBitmap;
if (paramBitmap.getHeight() > paramInt2)
localBitmap = Bitmap.createScaledBitmap(paramBitmap, Math.round(f * paramInt1), paramInt2, true);
else
localBitmap = paramBitmap;
}
}
private void shareImage()
{
saveImage();
Intent localIntent = new Intent("android.intent.action.SEND");
localIntent.setType("image/image");
localIntent.addFlags(1);
localIntent.putExtra("android.intent.extra.SUBJECT", "Liquidroid ");
localIntent.putExtra("android.intent.extra.TEXT", "LiquiDroid ");
localIntent.putExtra("android.intent.extra.STREAM", Uri.parse(this.mImageUri));
startActivity(Intent.createChooser(localIntent, "Share image"));
}
private void showToast(Context paramContext, String paramString)
{
Toast.makeText(paramContext, paramString, 0).show();
}
private void startCamera()
{
this.FILENAME = this.timeStampFormat.format(new Date());
this.FILE = new File(this.mLiquiDroidDirectory + File.separator + this.FILENAME);
Intent localIntent = new Intent("android.media.action.IMAGE_CAPTURE");
localIntent.putExtra("output", Uri.fromFile(this.FILE));
startActivityForResult(localIntent, 0);
}
public void applyDisplacementMapFilter()
{
int j;
for (int i = this.touchYMinusOFFSET; ; i++)
{
if (i >= this.touchYPlusOFFSET)
{
this.mMainView.setImageBitmap(this.mBitmapRes);
this.mMainView.invalidate(this.touchXMinusOFFSET, this.touchYPlusOFFSET, this.touchXPlusOFFSET, this.touchYMinusOFFSET);
return;
}
j = this.touchXMinusOFFSET;
if (j < this.touchXPlusOFFSET)
break;
}
if ((i >= 0) && (i < this.mImageHeight) && (j >= 0) && (j < this.mImageWidth))
{
this.mdXY = applyMapDrawFilter(j, i);
int k = j + this.mdXY[0];
int m = i + this.mdXY[1];
if ((m >= this.mImageHeight) || (k >= this.mImageWidth) || (m < 0) || (k < 0))
break label171;
this.mBitmapRes.setPixel(j, i, this.mBitmapSource.getPixel(k, m));
}
while (true)
{
j++;
break;
label171: this.mBitmapRes.setPixel(j, i, this.mBitmapSource.getPixel(j, i));
}
}
protected void onActivityResult(int paramInt1, int paramInt2, Intent paramIntent)
{
this.mBitmapSource.recycle();
this.mBitmapRes.recycle();
System.gc();
if ((paramInt2 != -1) || (paramInt1 != 0) || (this.FILE.isFile()));
while (true)
{
try
{
this.mImageUri = MediaStore.Images.Media.insertImage(getContentResolver(), this.FILE.getAbsolutePath(), this.FILENAME, "LiquiDroid");
this.mBitmapSource = BitmapFactory.decodeFile(this.FILE.getAbsolutePath());
this.mBitmapSource = scaleImagePreserveAspectRatio(this.mBitmapSource, this.mDisplayWidth, this.mDisplayHeight);
this.mImageWidth = this.mBitmapSource.getWidth();
this.mImageHeight = this.mBitmapSource.getHeight();
this.mBitmapRes = this.mBitmapSource.copy(Bitmap.Config.ARGB_8888, true);
this.mMainView.setImageBitmap(this.mBitmapSource);
this.mMainView.invalidate();
this.mMapDrawView.resetMapDrawView(this.mImageWidth, this.mImageHeight);
this.FILE.delete();
if ((paramInt2 == -1) && (paramInt1 == 1))
{
Cursor localCursor = managedQuery(paramIntent.getData(), null, null, null, null);
if (localCursor.moveToFirst())
{
this.FILE = new File(localCursor.getString(1));
this.mBitmapSource = BitmapFactory.decodeFile(this.FILE.getAbsolutePath());
this.mBitmapSource = scaleImagePreserveAspectRatio(this.mBitmapSource, this.mDisplayWidth, this.mDisplayHeight);
this.mImageWidth = this.mBitmapSource.getWidth();
this.mImageHeight = this.mBitmapSource.getHeight();
this.mBitmapRes = this.mBitmapSource.copy(Bitmap.Config.ARGB_8888, true);
this.mMainView.setImageBitmap(this.mBitmapSource);
this.mMainView.invalidate();
this.mMapDrawView.resetMapDrawView(this.mImageWidth, this.mImageHeight);
}
}
if (paramInt2 == 0)
initializeBitmaps();
return;
}
catch (FileNotFoundException localFileNotFoundException)
{
localFileNotFoundException.printStackTrace();
continue;
}
Intent localIntent = new Intent("android.intent.action.PICK");
localIntent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "vnd.android.cursor.dir/image");
startActivityForResult(localIntent, 1);
}
}
protected void onCreate(Bundle paramBundle)
{
super.onCreate(paramBundle);
setContentView(2130903041);
Display localDisplay = ((WindowManager)getSystemService("window")).getDefaultDisplay();
this.mDisplayWidth = localDisplay.getWidth();
this.mDisplayHeight = localDisplay.getHeight();
initializeBitmaps();
this.mDecorView = getWindow().getDecorView();
runOnUiThread(new LiquiDroid.1(this));
((ImageButton)findViewById(2131165194)).setOnClickListener(new LiquiDroid.2(this));
((ImageButton)findViewById(2131165195)).setOnClickListener(new LiquiDroid.3(this));
((ImageButton)findViewById(2131165196)).setOnClickListener(new LiquiDroid.4(this));
((ImageButton)findViewById(2131165197)).setOnClickListener(new LiquiDroid.5(this));
showToast(this, "Touch and squeeze to liquify.\n Have fun!");
createLiquidroidDir();
}
public boolean onCreateOptionsMenu(Menu paramMenu)
{
super.onCreateOptionsMenu(paramMenu);
MenuItem localMenuItem1 = paramMenu.add(0, 1, 0, "Use Camera");
MenuItem localMenuItem2 = paramMenu.add(0, 2, 0, "Reset Image");
MenuItem localMenuItem3 = paramMenu.add(0, 3, 0, "Save Image");
MenuItem localMenuItem4 = paramMenu.add(0, 4, 0, "Open Gallery");
MenuItem localMenuItem5 = paramMenu.add(0, 6, 0, "Share Image");
MenuItem localMenuItem6 = paramMenu.add(0, 7, 0, "About");
localMenuItem1.setIcon(17301559);
localMenuItem2.setIcon(17301580);
localMenuItem3.setIcon(17301582);
localMenuItem4.setIcon(17301567);
localMenuItem5.setIcon(17301586);
localMenuItem6.setIcon(17301569);
return true;
}
public boolean onOptionsItemSelected(MenuItem paramMenuItem)
{
switch (paramMenuItem.getItemId())
{
default:
case 1:
case 3:
case 6:
case 4:
case 2:
case 5:
case 7:
}
while (true)
{
return super.onOptionsItemSelected(paramMenuItem);
startCamera();
continue;
saveImage();
continue;
shareImage();
continue;
openGallery();
continue;
resetImageToOriginal();
continue;
this.mMainView.setImageBitmap(this.mMapDrawView.getMap());
this.mMainView.invalidate();
continue;
startActivity(new Intent(this, LiquiDroidAbout.class));
}
}
public boolean onPrepareOptionsMenu(Menu paramMenu)
{
super.onPrepareOptionsMenu(paramMenu);
return true;
}
public boolean onTouchEvent(MotionEvent paramMotionEvent)
{
float f1 = paramMotionEvent.getX();
float f2 = paramMotionEvent.getY();
switch (paramMotionEvent.getAction())
{
case 1:
default:
case 0:
case 2:
}
while (true)
{
return true;
this.mX = f1;
this.mY = f2;
continue;
drawDisplacementMapFilter((int)f1, (int)f2);
applyDisplacementMapFilter();
}
}
}
-----------------
Vieww Xclasss
package com.sekond.liquidroid;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.BlurMaskFilter;
import android.graphics.BlurMaskFilter.Blur;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.MaskFilter;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.view.View;
public class LiquiDroidMapDrawView extends View
{
public int BLUR_FILTER_SIZE = 8;
private Bitmap mBitmap;
private Paint mBitmapPaint;
private Bitmap mBitmapResult;
private MaskFilter mBlur;
private int mBmpHeight = 240;
private int mBmpWidth = 160;
private Canvas mCanvas;
private Canvas mCanvasResult;
private Paint mPaintMap;
public LiquiDroidMapDrawView(Context paramContext, int paramInt1, int paramInt2)
{
super(paramContext);
this.mBmpWidth = ((int)Math.round(paramInt1 / 2.0D));
this.mBmpHeight = ((int)Math.round(paramInt2 / 2.0D));
this.mBitmap = Bitmap.createBitmap(this.mBmpWidth, this.mBmpHeight, Bitmap.Config.ARGB_8888);
this.mCanvas = new Canvas(this.mBitmap);
this.mBitmapPaint = new Paint(4);
this.mPaintMap = new Paint();
this.mPaintMap.setAntiAlias(false);
this.mPaintMap.setDither(false);
this.mPaintMap.setColor(Color.rgb(128, 128, 128));
this.mPaintMap.setStyle(Paint.Style.FILL);
this.mPaintMap.setStrokeWidth(this.BLUR_FILTER_SIZE);
this.mBlur = new BlurMaskFilter(this.BLUR_FILTER_SIZE, BlurMaskFilter.Blur.NORMAL);
this.mPaintMap.setMaskFilter(this.mBlur);
this.mBitmapResult = Bitmap.createBitmap(this.mBmpWidth, this.mBmpHeight, Bitmap.Config.ARGB_8888);
this.mCanvasResult = new Canvas(this.mBitmapResult);
}
public void drawCircle(int paramInt1, int paramInt2, int paramInt3, float paramFloat1, float paramFloat2, int paramInt4)
{
this.mPaintMap.setColor(Color.rgb(paramInt1, paramInt2, paramInt3));
this.mCanvas.drawCircle(paramFloat1, paramFloat2, paramInt4, this.mPaintMap);
}
public Bitmap getMap()
{
this.mCanvasResult.drawColor(Color.rgb(128, 128, 128));
this.mCanvasResult.drawBitmap(this.mBitmap, 0.0F, 0.0F, this.mBitmapPaint);
draw(this.mCanvasResult);
return this.mBitmapResult;
}
protected void onDraw(Canvas paramCanvas)
{
}
protected void onSizeChanged(int paramInt1, int paramInt2, int paramInt3, int paramInt4)
{
super.onSizeChanged(paramInt1, paramInt2, paramInt3, paramInt4);
}
public void resetMapDrawView(int paramInt1, int paramInt2)
{
this.mBmpWidth = ((int)Math.round(paramInt1 / 2.0D));
this.mBmpHeight = ((int)Math.round(paramInt2 / 2.0D));
this.mBitmap = Bitmap.createBitmap(this.mBmpWidth, this.mBmpHeight, Bitmap.Config.ARGB_8888);
this.mCanvas = new Canvas(this.mBitmap);
this.mBitmapResult = Bitmap.createBitmap(this.mBmpWidth, this.mBmpHeight, Bitmap.Config.ARGB_8888);
this.mCanvasResult = new Canvas(this.mBitmapResult);
}
}