Android Show video on home screen like skype after minimizing app - java

How is Skype managing to show video call drag able pop up on home screen after minimizing Skype app during call. You can select and start other application from home screen and Skype popup is still on screen even parallel with other application. If it is App widget then how do I add or remove on home screen and in top of other application UI.

Use WindowManager to add a Float view:
private void createFloatView()
{
Button btn_floatView = new Button();
btn_floatView = new Button(getApplicationContext());
btn_floatView.setText("FloatView");
wm = (WindowManager) getApplicationContext().getSystemService(
Context.WINDOW_SERVICE);
params = new WindowManager.LayoutParams();
params.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
params.format = PixelFormat.RGBA_8888;
params.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
| WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
params.width = 100;
params.height = 100;
btn_floatView.setOnTouchListener(new OnTouchListener()
{
int lastX, lastY;
int paramX, paramY;
public boolean onTouch(View v, MotionEvent event)
{
switch (event.getAction())
{
case MotionEvent.ACTION_DOWN:
lastX = (int) event.getRawX();
lastY = (int) event.getRawY();
paramX = params.x;
paramY = params.y;
break;
case MotionEvent.ACTION_MOVE:
int dx = (int) event.getRawX() - lastX;
int dy = (int) event.getRawY() - lastY;
params.x = paramX + dx;
params.y = paramY + dy;
wm.updateViewLayout(btn_floatView, params);
break;
}
return true;
}
});
wm.addView(btn_floatView, params);
isAdded = true;
}

Related

How to drag a Bitmap in Android

I've tried many different solutions and none worked.
So, how do I drag and drop a Bitmap?
Here is a possible solution that also doesn't work, but I would love to know why:
Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.our_image);
And then activate the OnTouchListener:
#Override
public boolean onTouch (View v, MotionEvent event)
{
Imageview iv = new ImageView(this);
iv.setImageBitmap(bm);
if (v == iv)
{
switch (event.getAction())
{
case MotionEvent.ACTION_DOWN:
eventX = event.getXPrecision();
eventY = event.getYPrecision();
break;
case MotionEvent.ACTION_MOVE:
distX = event.getX() - eventX;
distY = event.getY() - eventY;
iv.setX(distX + eventX);
iv.setY(distY + eventY);
eventX = event.getXPrecision();
eventY = event.getYPrecision();
}
return true;
}
return false;
}
and when I move the ImageView, I update the Bitmap's location to it's coordinates
by creating a canvas and redrawing the Bitmap:
Paint p = new Paint()
Canvas canvas = new Canvas(bm);
canvas.drawBitmap(bm, iv.getLeft(), iv.getTop(), p);
Do I need to put invalidate() here? And if so, why?
Any kind of help would be greatly appreciated! ^_^

What am I doing wrong in creating this android floating bubble animation?

I am trying to translate this Swift code:
#objc func heartFlurry()
{
let heartImage = UIImage(named: "heartWhite")
let heartImageView = UIImageView(image: heartImage)
let screenSize = UIScreen.main.bounds
let heartWidth = Int(heartImage!.size.width)
let heartHeight = Int(heartImage!.size.height)
let randomX = arc4random_uniform(UInt32(screenSize.width))
heartImageView.frame = CGRect(x: Int(randomX) - Int(Double(heartWidth) * 0.5), y: Int(screenSize.height) + heartHeight, width: heartWidth, height: heartHeight)
view.addSubview(heartImageView)
let randomIntFrom0To4 = Int.random(in: 1..<6)
print(randomIntFrom0To4)
self.updateLove()
self.playSound(sound: "pop_\(randomIntFrom0To4)")
UIView.animate(withDuration: 1.5, animations: {
heartImageView.center = CGPoint(x: heartImageView.center.x, y: CGFloat(-heartHeight))
}) { (finished: Bool) in
heartImageView.removeFromSuperview()
}
}
Into Java, The code (when tapped multiple times) creates an effect that looks like this:
So far I have got this into my Java code:
void heartFlurry() {
Drawable heart = getResources().getDrawable( R.drawable.heart );
View v = new ImageView(getBaseContext());
ImageView imageView;
imageView = new ImageView(v.getContext());
imageView.setImageDrawable(heart);
Integer heartWidth = heart.getIntrinsicWidth();
Integer heartHeight = heart.getIntrinsicHeight();
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;
Log.e("Width", "" + width);
Log.e("height", "" + height);
final int randomX = new Random().nextInt(size.x);
Log.e("randomX", "" + randomX);
// RelativeLayout. though you can use xml RelativeLayout here too by `findViewById()`
final RelativeLayout relativeLayout = new RelativeLayout(this);
// Setting layout params to our RelativeLayout
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(size.x, size.y);
// Setting position of our ImageView
layoutParams.leftMargin = randomX;
layoutParams.topMargin = 500;
// Finally Adding the imageView to RelativeLayout and its position
relativeLayout.addView(imageView, layoutParams);
ObjectAnimator animationY = ObjectAnimator.ofFloat(imageView, "translationY", -size.y);
animationY.setDuration(500);
animationY.start();
new CountDownTimer(500, 1000) {
public void onTick(long millisUntilFinished) {
}
public void onFinish() {
relativeLayout.removeAllViews();
}
}.start();
}
I feel like I have all the elements there, creating the imageview, adding a relative layout and setting it at the bottom of the screen and using a random Int for a random X position within the screen width, but nothing happens when I run it. What am I missing?
Thank you.
The problem was with the Relative Layout I created, it was not being properly added to the view.
I added a RelativeLayout in XML to the activities content XML rather than creating it programatically, then referred to it:
RelativeLayout relativeLayout;
relativeLayout = findViewById(R.id.heartLayout);
Then I updated the heartFlurry function to add a rule to the heartImageView params, to start at the bottom of the screen, and use the randomX for the leftMargin.
void heartFlurry() {
Drawable heart = getResources().getDrawable( R.drawable.heart );
View v = new ImageView(getBaseContext());
ImageView imageView;
imageView = new ImageView(v.getContext());
imageView.setImageDrawable(heart);
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;
Log.e("Width", "" + width);
Log.e("height", "" + height);
final int randomX = new Random().nextInt(size.x);
Log.e("randomX", "" + randomX);
RelativeLayout.LayoutParams paramsImage = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
paramsImage.addRule(RelativeLayout.CENTER_IN_PARENT);
imageView.setLayoutParams(paramsImage);
relativeLayout.addView(imageView);
RelativeLayout.LayoutParams heartParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT
);
heartParams.leftMargin = randomX;
heartParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
imageView.setLayoutParams(heartParams);
ObjectAnimator animationY = ObjectAnimator.ofFloat(imageView, "translationY", -size.y);
animationY.setDuration(500);
animationY.start();
new CountDownTimer(1000, 1000) {
public void onTick(long millisUntilFinished) {
}
public void onFinish() {
relativeLayout.removeAllViews();
Log.e("randomX", "Timer Done");
}
}.start();
}

Simply Swipe any Normal Android View without third party library

I want to move any normal view in my app along with swipe.
I am able to detect swipe using OnTouchListener in onTouch method. But am not able to move the view along with the swipe.
I want to move the view along with the swipe.
I think so that something i need to implement inside onTouch method to move the view or item along with swipe, but what i don't know.
Any help will be highly appreciated.
You just need to use view.setTranslationX(diffX) for X coordinate and view.setTranslationY(diffY) for Y coordinate while its MotionEvent.ACTION_MOVE under onTouch() method.
view.setOnTouchListener(new View.OnTouchListener() {
float downX, downY, nowX, nowY, diffX, diffY;
#Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
downX = event.getRawX();
downY = event.getRawY();
break;
case MotionEvent.ACTION_MOVE:
nowX = event.getRawX();
nowY = event.getRawY();
diffX = nowX - downX;
diffY = nowY - downY;
v.setTranslationX(diffX);
v.setTranslationY(diffY);
break;
case MotionEvent.ACTION_UP:
break;
}
return true;
}
});

HOW TO disable getView() method in ListView Adapter?

Is there any way to disable getView() method in ListView Adapter when I use MotionEvent.ACTION_MOVE in OnTouchListener??
I need to do because i try move my conteiner(inside is my ListView) by finger. I use for this method setLayoutParams:
private class MyListener implements View.OnTouchListener{
#Override
public boolean onTouch(View v, MotionEvent event) {
final int Y = (int) event.getRawY();
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_UP:
RelativeLayout.LayoutParams paramsUp = (RelativeLayout.LayoutParams) myBar.getLayoutParams();
paramsUp.topMargin = 0;
myBar.setLayoutParams(paramsUp);
break;
case MotionEvent.ACTION_MOVE:
RelativeLayout.LayoutParams paramsMove = (RelativeLayout.LayoutParams) myBar.getLayoutParams();
paramsMove.topMargin = Y - yDelta;
myBar.setLayoutParams(paramsMove);
break;
case MotionEvent.ACTION_DOWN:
RelativeLayout.LayoutParams lParams = (RelativeLayout.LayoutParams) myBar.getLayoutParams();
yDelta = Y - lParams.leftMargin;
break;
}
//myBar.invalidate();
return true;
}
}
When I moving container, everything happens very slowly. This is because the container changes its size and all objects are loaded again.
And my second question:
How to disbale scroll when I move ListView item? For example: move on left or move on right.
Thx

Not able to Edit a cropped photo in Android

I'm building an Android app where I have to edit a picture which has been picked from the phone gallery and cropped.
So in my layout, I have an ImageView where I am placing the cropped image
xml file
<ImageView
android:id="#+id/ivEditPhoto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:layout_weight=".90"
android:src="#drawable/app_icon_big" />
Placing the cropped image in ImaveView
bitmapPic = (Bitmap) getIntent().getParcelableExtra(
"CroppedBitmapImage");
picView = (ImageView) findViewById(R.id.ivEditPhoto);
picView.setImageBitmap(bitmapPic);
The image is getting placed correctly. But the problem is when I try to edit it.
I have an edit button and on click of that I do the following which includes registering of On Touch Listener.
DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
int height = displaymetrics.heightPixels;
int width = displaymetrics.widthPixels;
Bitmap alteredPastedBitmap = Bitmap.createBitmap(bitmapPic.getWidth(),
bitmapPic.getHeight(), bitmapPic.getConfig());
pasteCanvas = new Canvas(alteredPastedBitmap);
paint = new Paint();
paint.setColor(Color.GREEN);
paint.setStrokeWidth(5);
matrix = new Matrix();
pasteCanvas.drawBitmap(bitmapPic, matrix, paint);
picView.setOnTouchListener(this);
Then the following
public boolean onTouch(View v, MotionEvent event) {
Toast.makeText(this, v.getId(), Toast.LENGTH_SHORT).show();
if (v.getId() == R.id.ivEditPhoto) {
Toast.makeText(this, "onTouch", Toast.LENGTH_SHORT).show();
int action = event.getAction();
x = event.getX();
y = event.getY();
switch (action) {
case MotionEvent.ACTION_DOWN:
sX = event.getX();
sY = event.getY();
break;
case MotionEvent.ACTION_UP:
if (skewedBitmap == null) {
int resID = 0;
if (imageId == 0)
resID = R.drawable.green_arrow;
else
resID = imageId;
bitmapToPaste = BitmapFactory.decodeResource(
getResources(), resID);
} else {
bitmapToPaste = skewedBitmap;
skewedBitmap = null;
}
pasteCanvas.drawBitmap(bitmapToPaste, sX- (bitmapToPaste.getWidth() / 2),sY- (bitmapToPaste.getHeight() / 2), null);
picView.invalidate();
break;
case MotionEvent.ACTION_CANCEL:
break;
default:
break;
}
}
return true;
}
The issue is:
the bitmapPic.getWidth() and bitmapPic.getHeight() is 160*160 and the onTouch event.getX(); and event.getY(); is beyond the co-ordinates (For example: 150.33 & 500.89) although the image seems to be occupying the whole screen and the touch is on the image. So onTouch doesn't place the bitmap and returns a false.
Could any of you please guide me on this?
I had the same issue in one of my applications. I need to see more of your code but this could be related to the onInterceptTouch() method you need to implement.
If that is not the case, then maybe you can look into this code for help on how to move, modify and rotate bitmaps:
http://adblogcat.com/custom-view-to-draw-rotate-erase-and-convert-images-to-black-and-white/
I wrote this tutorial btw and this is my website and I think is easier for you to follow that tutorial than just paste it here.

Categories

Resources