"removedialog" issue when displaying 2 dialogs at the same time - java

In the method "OnCreate" of my actvity, I'm displaying a little progress dialog while loading data. It's done every time the "OnCreate" method is called so even when the screen orientation change.$
In the nominal case, there is no problem even if the user change the screen orientation.
But, if the user opens another dialog (used to select an item in a list), then change the orientation, the progress dialog is displayed behind the "list" dialog and is not impacted by the "removeDialog".
Do you have any clues on that behavior ?
Thanks

call "removeDialog" or "dismissDialog" before "startDialog" with try-catch and so on. You can call "removeDialog" or "dismissDialog" several times...

Related

Show progress bar when switching activities

Please direct me how to show progress bar when switching between activiies.
On my second activity there are lots of calculations and coded views and it leads to expected delays in opening. But I want to show a loading progress in percentage
More details on attached screen shot
screenshot
I have an idea but not the best one you could use the sharedPreference to recover the value

Improving user experience with toggling on/off over 300 CheckBoxes

I made a simple cooking app where user can select multiple items and get a list of recipes with selected ingredients. There are 2 modes of selecting the ingredients: by tags and by checkboxes. In the second mode you can enter the number of ingredients you wish and hit the button "randomize" or just press "Select/Deselect all ingredients" buttons. The problem started with the number of checkboxes over 300 (386, to be specific). Code is working fine, but the time of GUI remain frozen is too big.
So, I've got HashMap <String/CheckBox> checkBoxHashMap, where key is tag of the check box. To select all (same for deselect all, but with false value) I am using this code:
for (CheckBox chkBox: checkBoxHashMap.values()) {
chkBox.setChecked(true);
}
What I tried to use:
1) Using ProgressBar. The problem was, that animation of ProgressBar is frozen during the selection/deselection of all CheckBoxes. Plus, most of the times ProgressBar even didn't showed up (I hid the ProgressBar after all the CheckBoxes were selected;
2) Using chkBox.jumpDrawablesToCurrentState(); right after calling chkBox.setChecked(true); and it was the best I could acquire in performance, but still it lagged and didn't satisfied me.
What I want:
I want to make it more user friendly (frozen GUI is not user friendly at all, I believe). I want to implement soft toggling on/off all the CheckBoxes (chain-like animation) or something else like disabling animation and enabling it back after all the CheckBoxes have changed their state and redrawing them all together.
Is there a way to achieve something like that?
Honestly, if I were you, I'd use RecyclerView to handle this situation.
Displaying 300 items at the same time on the screen is never a good idea: user can't possibly need all of them at once, nor system should handle a load of this kind.
The concept is to recycle views, meaning that as soon as a view becomes invisible, resources required for it are disposed and can be reused for another data cell.
I made an introductory article about RecyclerView with lots of examples, take a look
In your particular case, just make appropriate data set for checkboxes and alter it asynchronously, using result of this operation on UI thread just to update RCV (it's a very lightweight operation compared to what you have right now)
The setChecked operation is expensive enough that performing it on a large number of objects in the foreground thread is leading to your UI freezing because the work takes too long and the app can't finish updating the UI within a refresh cycle. You should perform expensive operations in the background:
new AsyncTask() {
#Override
protected Object doInBackground(Object[] objects) {
for (CheckBox chkBox: checkBoxHashMap.values()) {
chkBox.setChecked(true);
}
return null;
}
}.execute();

Android: Customizing recent apps thumbnail (screenshot by default)

The app I'm working on shows some sensitive information that must not be shown on the "Recent Tasks" screen when stopping the app by pressing the home button.
I'd like to blur the sensitive data in the screenshot or show the app logo instead.
I am aware of the following approaches but they don't fit my requirements:
Setting the actvitie's android:excludeFromRecents to true in the manifiest prevents the app from being shown at all in the recent tasks. This would disrupt the user experience.
Using FLAG_SECURE results in a blank card on the recents tasks screen. (How do I prevent Android taking a screenshot when my app goes to the background?) I don't like the blank screen. However, I'll stick to this solution if there is no workaround.
Overriding onCreateThumbnail seems like the ideal solution but, unfortunately, doesn't work as it's currently not invoked by the OS :( (https://code.google.com/p/android/issues/detail?id=29370)
And then there are some workarounds that I tried out but that didn't work as hoped:
Start a new activity that shows the app logo in onPause so that it's screenshot is shown instead of the actual activitie's one. But the new activity takes too long to open and it disrupts the user experience.
Set the activitie's content view to an image of the app logo in onPause. That seemed like a great solution to me. Unfortunately, the screenshot for the recent tasks screen is taken at an unspecified time. During testing the app logo quickly appears before the app is closed when pressing 'Home' but the resulting screenshot shows the activity a short time before that.
Removing the sensitive data from the widgets (e.g. textView.setText("")) has the same problem of screenshot timing just mentioned.
Any alternative ideas or solutions to the listed workarounds?
I looked into this a couple of months ago for the same purpose as you.
Unfortunately, I had to conclude that it is simply not possible. I dug through the android source code and confirmed it.
There is no callbacks or methods from android that allows you to customize it (that works anyway). Besides FLAG_SECURE, this part of the code does not accept any input or change.
OnPause and similar lifecycle methods are called too late (the screenshot is taken already). All lifecycle methods that would hint that you're about to go into the background runs too late.
The image you see in the recent tasks is an actual screenshot - and thus isn't affected by changes you do (too late) to your view. That means you can't modify your view just-in-time (like making it invisible, replacing with something else, adding SECURE_FLAG, or any other obstruction of the view). As an aside, these images can be found on an emulator at /data/system_ce/0/recent_images.
The only exception is using FLAG_SECURE, which will prevent the screenshot from being taken of your application. I experimented with setting this FLAG in onPause and removing it in onResume, however as mentioned already these lifecycle methods runs after the screenshot is taken already, and thus had absolutely no effect.
As discussed in How to change the snapshot shown by recent apps list? there used to be a callback that you could use to customize the thumbnail: onCreateThumbnail. However, this does not work and it is never called. To be clear, the callback is still there, it is simply never called by the OS. The fact that it stopped working is poorly documented, but apparently was silently deprecated/removed in 4.0.3
As for the thumbnail itself, it is a screenshot taken serverside. It is taken before onPause is called (or in fact before any callbacks indicating that your activity is about to go into the background is called).
When your app does go into the background, your actual view is animated (to get that zoom-out transition). That animation can be affected through changes you do in onPause (if you're fast enough that is) (I experimented with setting opacity to 0 on the window among other things). This will however only affect the animation. When the animation is finished, the view is replaced by the screenshot taken earlier.
Also see these questions that discuss this:
When does Android take its recent apps switcher screenshot?
Show custom application image in task manager on ICS or JB
Android never call method onCreateThumbnail
Currently (28/10/2020) is impossibile customizing app thumbnail in recent apps screen.
As explained by #Dellkan in the previous answer, the onCreateThumbnail method is not called anymore by the OS.
Unfortunately, also the suggestion to create a kind of launcher/splash screen without the FLAG_SECURE flag to let the app take a screenshot of that activity is not working, because the screenshot is taken on the activity you see and not at the launch of the app.
You cannot even customize the color of window background when using FLAG_SECURE as reported here.
How about implementing a layout overlay on top of your entire activity?
Make it transparent, it's click-through by default, so no negative impact on UX while in use.
In onPause() set a half-transparent, blurred image as the background of that layout, the data will be scrambled behind it. In onResume() change the background to fully transparent again. Voila.
It might be faster than other types of overlays. The positive side effect is, if you do the unblurring as a short animation effect when the user goes back (with a proper library that uses C++ instead of Java), it might even look cool and the users wouldnt even mind seeing it.
I haven't tried this myself, but it's something you haven't tried yet.
Since onPause is called to late, I use WindowFocusChangeListener to observe when the Fragment loses focus. At this moment we can hide all view which show sensitive data:
#Override
public void onViewCreated(#NonNull View view, #Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
view.getViewTreeObserver().addOnWindowFocusChangeListener(new ViewTreeObserver.OnWindowFocusChangeListener() {
#Override
public void onWindowFocusChanged(boolean hasFocus) {
// hide sensitive data when window moves to background (before system screenshot is captured)
myViewWithSensitiveData.setVisibility(hasFocus ? View.VISIBLE : View.INVISIBLE);
}
});
There is a way to customize it. You need your Activities with sensitive data to FLAG_SECURE in onCreate before you setContentView. Then you need an empty Activity, which renders whatever you want to have as the customized thumbnail. This usually is some sort of splash screen. This new Activity needs to be the launcher and is the only Activity not FLAG_SECURE. This Activity is launched and in onResume starts your actual Activity with the sensitive data.
Android OS will take a screenshot of that new Activity at the beginning of your App. Unfortunately the users will also see this Activity for a short moment. Since every other Activity is FLAG_SECURE, Android OS will use the only available screenshot it made at the beginning.
Was looking for a solution and found some dirty things in case you don't want to use 'FLAG_SECURE'. It doesn't give a nice picture but protects data and doesn't prevent making screenshots for the user while they are in the app.
protected void onPause () {
this.getWindow().getDecorView().getRootView().setScaleX((float)200);
this.getWindow().getDecorView().getRootView().setScaleY((float)200);
super.onPause();
}
protected void onResume () {
this.getWindow().getDecorView().getRootView().setScaleX((float)1);
this.getWindow().getDecorView().getRootView().setScaleY((float)1);
super.onResume();
}
I think this can only achieve through BroadCastReceiver but there is no receiver present. So therefore you first disable default screenshot functionality in android and then implementing your own functionality to take screenshot and before taking screenshot you should blur your secure information.

Close Dialog by clicking outside of it

Working with libGDX, and in this particular project we are using Dialog to have a box popup when the user clicks a certain button.
What I want is to be able to dismiss the Dialog by clicking outside of it.
At other times, I have used two tables, a background table and a menu table, and added a transparent background to the background table that when clicked will remove both of those tables from the Stage.
I have tried making a class that has a both a Dialog and a background table like the one mentioned above, but the background table never receives any actions.
I have also tried simply adding this background table to the stage before creating the dialog box, but this does not work either.
Finally, I have also tried to subclass Dialog, the idea being to override the show(stage) method to change its behavior, but I don't know how to do this one, and I'm not sure if it would work, anyway.
I believe the problem is that dialog.show(stage) changes the situation in the stage to only accept clicks inside the Window of the dialog box. I have seen this question about adding a close button to a dialog box, but playing with the clipping settings is not working to fix this problem.
There is also the possibility that when show() calls the pack() method and does its layout thing that something is happening that is making what I am trying to do impossible. I think that the solution will be overriding show() or overriding pack(), or both, but I don't know how to do this.
I can post code if need be, but this should be a pretty complete description of what I have tried and what I need to accomplish.
I know this is an old question but for those like me that searched the entire web for an answer only to find it inside libGDX code, the answer to .close() a libGDX dialog by code is simply to call the method
dialog.hide();
EDIT (added from the comments below):
so all he needs to do is register a global touch down event and see if
the touch has happened inside the Rectangle of his dialog, if not,
close it

Making an Android App (Java) 'Wait' Until Something Finishes

I have this app that originally has you take a picture, shows you a progress bar, and uploads it to a website.
What I want to add is something so that before the progress bar shows, an Intent starts an activity that loads a layout with a dropdown menu that allows you to choose a descriptor for the picture. Following this, once you hit the 'OK' button on this new layout, the program should return back to where it had left off and display the progress bar.
Does anyone have any ideas on how to achieve this?
It seems that all I really want is some way to tell the program to stall for a while to call an intent, and when the user hits 'OK', the code may resume.
You should be using OnActivityResult().. More information on the link below http://developer.android.com/reference/android/app/Activity.html#startActivityForResult(android.content.Intent, int)

Categories