Showing an interactive floating layout during calls - android

Background
There are some nice apps out there that show some layout on top , while the user is making a call or answering one (like "current caller id").
I need to create an app with the ability to show something on top , during a call, and allow it to be interactive.
The problem
Using broadcastReceiver ,foreground service and SYSTEM_ALERT permission, I've succeeded showing something on the screen during calls.
As long as the content being shown is static, I have no problems.
However, I've noticed that when I try to make the content being shown to be interactive , I face some problems:
Everything is jumpy and this includes not only animations, but also setting visibility to visible/gone. I hate to think how it would work like when I need to make things draggable.
Not sure if this is the reason, but using the SlidingDrawer make the entire width belong to the SlidingDrawer and you cannot click through it. This means that if its location is at the bottom, you can't touch the "answer" button when someone calls you.
The question
What is the reason for those problems?
How can I fix them and be able to show things right?
How do other apps handle it right ?
EDIT: about the SlidingDrawer , it seems that it has terrible bugs about its location and size, and the content area, even when it's not shown to the user and the user can see through, it cannot be touched through. Still, I don't know why, and how to fix it, and I also don't know why things are so jumpy compared to normal apps (probably because of over-drawing, but it's really really slow).
Maybe this question should be more general: how to make a floating window like on AirCalc, that can be moved easily yet still be quite fast.
For the dragging functionality, I've tried to get the layoutParams of the root view (which is of type WindowManager.LayoutParams ) that I show, update it and set it again, but for some reason it didn't do anything. Wonder what I'm doing wrong.
EDIT: it seems that i should be using windowManager.updateViewLayout for updating the layoutParams. Using this post , I've made it perfectly draggable.

Ok, I've come up to some conclusions about this, first to answer my original questions:
it's probably because of overdraw and the views i've used. I wanted to try out libraries that could replace the slidingDrawer , but each had a different problem. using simple views proved that the idea in general works.
in the case of visibility changes, it was jumpy because the size of the view wasn't able to fit using the current WindowManager.LayoutParams size.
slidingDrawaer does have issues since it uses the whole size it get when closed or opened.
now to the rest of the issues :
unable to drag ? instead of the regular setLayoutParams , use windowManager.updateViewLayout .
unable to touch outside of the view ? set its minimal size according to your needs. you can also set the window flags so that touch event would go through .
want to listen to calls events ? you can use the broadcastReceiver for triggering the showing of the app, but I suspect that hanging the call might cause the intent be received later sometimes. I think you can use telephonyManager and listen to events there, using the service you run in the foreground (that i've created just to make sure the app won't close in the middle).
if anyone else has questions, i can help.

Related

Screen rotation breaks widget Android

When I rotate the screen on a tablet, my widget's list view disappears and the buttons become unclickable. I'm not sure what happening with the most recent remote view to cause this. Any suggestions?
Here is my onUpdate function
onUpdate
Since we do not have the full code, it's kind of hard to give an actual answer to your problem.
However, I might have an idea & the cause of your problem could be in your .XML file. The same way your app looks great in a certain rotation, most surely on the one you originally designed your work on, it is very possible that it might result in problems when you changed the rotation.
However, it all depends of the layouts you are using & how they are used. I would advise to share your entire code so we can go through it.

An elegant way to keep integrity of RelativeLayout when animating it?

Ok, so...
I know, there's been a real amount of questions about it, but it either didn't work, or was really fixed in a hard way. Oh, and that's my second day trying to do it, so please, accept my apologies about that and help me for Chet Haase's sake.
I have a button on top of a fragment, and a RecyclerView below it. When i press the button i want it to disappear and a new RelativeLayout with textfields to slide from the top.
I don't want to make it with animateLayoutChanges="true", cause it's not exactly what i was meant to do, and i want rather learn, than do it.
I tried to do it with widget.animate().translation... and the result was that one widget was just thrown in it's place when the rest of layout stood still. That's not what i meant to do.
I tried also to make an "new TranslateAnimation" since it has this "setFillAfter/Before" attribute... but that did not help me neither.
What i tried as well was to update the layout somehow adding to id margins and stuff (don't remember anymore, and i'm in work right now trying to figure it out, sorry) as it was described in some questions.
But none of that worked. I don't include code right now, cause i already tried to do it in some dozens of different ways.
Could you please tell me how to move a widget and make the rest of them to move with it? Is it possible?
I've already got it going once using setVisibility,animateLayoutChanges and animation combination, but that was massive and dirty as a baby duck.
Edit: oh, i almost forgot about it. Another problem is that when i animate/move a widget, only the rendering spod changes, but the real spot of it stays the same (ex. a onclicklistener)
Ok, me again.
I did it this way, that - let's say - i want to slide a button up and remove it.
So i animate it and all the other widgets (right, i can make a ViewGroup) up, put a listener on animation, and on "onAnimationEnd" i clear all the animations and set the visibility to GONE.
The animateLayoutChanges must be set to false
Still it's not what i wanted, so i'd be indebted to anyone who shows me another, better way.

How to implement Android 4.0 like swipe to dismiss functionality in ListView?

I'm working on an app in which I would like to implement swipe-to-dismiss functionality in the ListView - similar to what we see in Android 4.0's notification bar, recent apps list or browser tabs. I want to run the app on the devices running Android 2.2+. See the following image. I also want to change the transparency of the item being swiped-away - just like in ICS.
I checked the source of the ICS web browser on http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android-apps/4.0.1_r1/com/android/browser/TabScrollView.java?av=f but couldn't figure out which class is particularly responsible for implementing this functionality.
Can anyone point me in the right direction here? Can we do this using Android Compatibility Library? Please let me know. Many thanks.
I've thought about implementing such a feature as well, but I haven't done it yet. So the only thing I can provide are some ideas on how I would approach that problem. If I've eventually written some code I will post it here.
The main class needed is a custom Adapter which extends a ListAdapter (ArrayAdapter, SimpleCursorAdapter etc.).
The adapter applies a View.OnTouchListener to all of its Views.
Whenever that listener detects a horizontal scroll dx, it calls concernedView.offsetLeftAndRight(dx) (which will make the view draggable). Of course the adapter has to save the current horizontal offset for the view. If the user was dragging a view and removes his/her finger from the screen, the touchListener will detect this as well and start a slide back animation. Using the current offset we can also calculate an alpha value, so the view will fade out when it approaches the screen borders.
If one list entry is eventually dismissed by the user, it becomes a bit tricky, and I'm still not sure how I would implement the following action: The list content has to be updated (or the adapter has to ignore the dismissed entries) and the views that were below the one that was dismissed must hover upwards in order to fill the gap. I think it might work to let the ListView load the new content, but that would fill the gap instantly. In order to avoid that, I would then start an animation that lets all the concerned views hover from their old position (where we still had the gap) back to their current position (where the gap is filled).
These are just some of my thoughts on the issue that might help some people getting started on working on the problem. Like I said, I'm probably going to implement that sometime in the future and of course I will post the code here.
I would appreciate any feedback in the comments, but I don't want to thorougly explain every single aspect of my idea, that would take me too much time ;)
I know this is quite an old question, but for anyone still searching for this, you can have a look at Roman Nurik's library here: https://github.com/romannurik/Android-SwipeToDismiss
This shows how to create the required behavior for list-view as well as for normal views.

Placing a background picture and then having invisible touch (Android)

I am trying to make an application for android that is based on IPAD app. I want to keep the same look to the app, but I am not a very good designer. So I was wondering if it was possible to for me to crop say the entire header and then have an invisible button or something on top of portions of it. so the design would become a little bit easier. Also if that is possible how would I get the what ever the event item is going to be to overlap with a portion of the image if it has stranger orientation. (I think I could fake this by just moving it closest orientation and extending the size untill it fits, but it would be nice to find a better way.)
How would I go about that?
I tried making the button invisible, but that did not seem to work.
Thanks in advance
I got lost on your description. But if you want to make a button invisible, calling setVisibility(View.INVISIBLE); will not work, because it will not receive click events. You may want to set its color to transparent instead. try using:
button.setBackgroundColor(Color.TRANSPARENT);

Getting blank screen when switching between activities

I am working on an app , where I am switching between two activities. When control is inside onStart of second activity , there is screen drawing and processing logic being handled.Because of this , when switching between the two activities happens, there is a blank screen that comes up.
Along with this , i also need to render a live video feed in background of my activities/app
What could be the best way to deal with this?
TIA
If you're getting a blank screen it could be because your activity is setting a new contentview but it hasn't been processed properly. Does it ever load completely? If it's just that it's black at the beginning and then renders. Try setting the contentview at the end of your switching in onCreate. This will make it remain on the first activity and avoiding switching views on till everything is loaded.
With regards your second question. Is the live video feed from the Camera?
If it is, set the camera view in the background, make a transparent LinearLayout (or whatever your layout is) over it and then put your various views there.
Your question doesn't have enough specific information to get an accurate idea as to what you're talking about, if my answer doesn't address your problem please respond with elaboration and some code! :-)

Categories

Resources