Skip to content

Instantly share code, notes, and snippets.

@sharish
Created July 27, 2015 08:27
Show Gist options
  • Save sharish/bf208b5c82595c21eb65 to your computer and use it in GitHub Desktop.
Save sharish/bf208b5c82595c21eb65 to your computer and use it in GitHub Desktop.
package com.cooltechworks.ondownsample;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import com.cooltechworks.bitmapmerger.tasks.BitmapMergerTask;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.hello).setOnTouchListener(new OnDownListener() {
public long getMaxDownCount() {
return 5;
}
public long getInterEventTimeout() {
long maxCount = getMaxDownCount();
long dividedTimeout = 800 / maxCount;
return (maxCount - getDownCount() + 1 ) * dividedTimeout;
}
@Override
public void onDown(final View v, final long callingCount) {
paintForHoldCount((int) callingCount);
}
});
final View flier = findViewById(R.id.hello);
flier.post(new Runnable() {
@Override
public void run() {
flier.setVisibility(View.VISIBLE);
paintForHoldCount(0);
}
});
}
public void paintForHoldCount(final int callingCount) {
final View v = findViewById(R.id.hello);
final View vp = (View) v.getParent();
final float percentage = 0.2f;
final Bitmap bitmap = Bitmap.createBitmap(vp.getWidth(), vp.getHeight(), Bitmap.Config.ARGB_8888);
Bitmap sendButton = BitmapFactory.decodeResource(getResources(), R.drawable.compass);
//Bitmap merger task from here : http://www.cooltechworks.com/bitmap/bitmap-over-another-bitmap/
BitmapMergerTask task = new BitmapMergerTask();
task.setBaseBitmap(bitmap)
.setMergeBitmap(sendButton)
.setScale(percentage * 0.75f )
.setMergeListener(new BitmapMergerTask.OnMergeListener() {
@Override
public void onMerge(BitmapMergerTask task, Bitmap mergedBitmap) {
Bitmap flierBitmap = Bitmap.createBitmap(mergedBitmap, mergedBitmap.getWidth()/4 , mergedBitmap.getHeight() / 4, mergedBitmap.getWidth()/2, mergedBitmap.getHeight()/2);
v.setBackgroundDrawable(new BitmapDrawable(flierBitmap));
if (callingCount > 0) {
Bitmap bitmap2 = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight());
Canvas canvas = new Canvas(bitmap2);
for (int i = 0; i < callingCount; i++) {
int strokeWidth = 10;
int circleCount = i + 1;
float radius = (percentage * (circleCount * vp.getWidth() / 2)) - strokeWidth;
Paint paint = new Paint();
paint.setColor(Color.YELLOW);
paint.setStrokeWidth(strokeWidth);
paint.setStyle(Paint.Style.STROKE);
canvas.drawCircle(vp.getWidth() / 2, vp.getHeight() / 2, radius, paint);
}
vp.setBackgroundDrawable(new BitmapDrawable(bitmap2));
} else {
vp.setBackgroundResource(android.R.color.transparent);
}
}
})
.merge();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment