disable touch focus while loading - android

I have an android app that uses a glSurfaceView that takes a few sections to load up.
I have onTouchEvent overridden, and I'm trying to disable focus while it loads but setFocusable(false) isn't working.
The problem is if the user taps on the screen before everything loads, the app gets a null and it crashes.

I'd pop up a progress dialog and use an AsyncTask to do the loading of the view. Once the view is loaded you can kill the dialog. Any heavy lifting should not be done on the UI thread anyway.

Related

Disable Touch When Running ACTION_RECOGNIZE_SPEECH Intent

Part of my Android app uses speech-to-text, and I want to disable touch events while it does that because otherwise the user can accidentally touch their phone and stop the conversation.
I'm trying to use a ViewGroup that can be the parent for that Activity and absorb the touch events, but am having trouble with it.
I have an Activity, and from there I pull up a DialogFragment where the user can enter information using speech-to-text.
When I tried using an overlay to absorb the touch events from the dialog, it only covered the DialogFragment and not the whole screen. And when I added it to the Activity, I couldn't access it from the DialogFragment.
In any case, it never stopped the touch events anyways because my main problem is when the speech-to-text dialog is up and that would come up on top of the overlay and I don't know how to get the handle for that.
Anyone here done anything like this before? Thanks.

Updating Custom listview item after on resume()

I have a custum listview with image, text, a download button and a progress bar for each item.
The plan is that when I click the download button, the progress bar which original is invisible becomes visible and starts to progress, while the download button changes to a cancel button.
But what happens now is that when I minimize the app to home and opens it back up, the listview refreshes(that is the adapter is called again) as the activity resumes. This undos all the states which have been set.
the progress bar becomes invisible and the download button shows up with the download icon instead of the cancel icon, even though the download continues in Asynctask.
What I need to do is to find a to set the state of the list item, such that the progress bar continues to progress and the button changes to cancel button. i.e to retain the ui state as the download goes on in the Asynctask, even when the listview is reinitialized.
I viewed` your question. The problem is regarding the Asynchronous AsyncTask that you used. I can try to explain you the problem and the recommended solution.
If you start the AsyncTask inside your activity, Now when you close the activity (finish) It is not guaranteed that the running AsyncTask also stop working and finish itself because of your activity is no longer running. That does not happen.
Another fact is that, As previously said that once you fire the AsyncTask you could not reuse it next time when you start the same activity again. In your case, it always starts the new AsyncTask when you open the activity.
Alternative Solution: You can use the Service component that can run in the background (keep in mind that it does not create the separate thread from your application, It's run on the application thread) means it has no UI and could be run even if your activity or application is not in front of the user. You can put your download logic inside it and bind with your running activity.
Regarding the state of the UI in adapter that you can manage by communicating between the activity and running service.
This is simple approach that you can use it.
Hope this will help!
Thanks
Bhavdip

Activity is blocked whenever soft keyboard is shown or hidden

I am having an Activity with two RecyclerView with big amount of data.
Now I'm showing a Dialog on this Activity, Dialog is having multiple EditText and Spinner in it. so as soon as I start typing and keyboard appears at that time my UI is blocked. And same as when I hide keyboard at that time also my UI is blocked for couple of seconds. And ultimately I frequently get ANRs.
And yes If I comment out RecyclerViews from my Activity then same Dialog is working fine without any lag.
So how to overcome this problem can anyone help me in addressing this issue.

Progress Dialog causing Virtual Keyboard to not show on WebView

I have a weirb bug that is pissing me off.
I have an app that is pretty much only a webview with some extra functionalities, one of them is a Custom Loading Dialog (Extended from the progress dialog) that I show on the onPageStarted call, and dismiss on the onPageFinished call. The problem is, if I do that (show the dialog), the virtual keyboard will only show if the user touch TWO times on a form text box (Html or Javascript Text box on the Webview).
I've tried manually giving focus to the webview, before and after the GUI update by the handler that dismisses the Dialog.
Redrawing the WebView
Not showing the dialog (this works, but I need the dialog)
Anyone have an idea on how to fix that?
Thanks!

Loading screen in Android

What's the best way to create a reusable loading screen in Android? The loading screen should have a background image and a loading indicator.
Should I use a separate activity?
The best way is using a separate activity with a SurfaceView that shows the image. Then, you can create an overlay that contains the ProgressBar.
You just could define your own dialog with custom layout. You would handle what happens if your progress screen gets cancelled (pressing back button). You could also prevent it from happening too.
By using an standard dialog you take adavantage of nice efects (background activity darkening with upgrades) and prevents user from interacting with background activity while it is on.

Categories

Resources