Anyone have an idea how the Amazon mp3 app is displaying the player controls inside of the keyguard? I've been playing with some of the system alert and system overlay window parameters with now luck. The system alert will display over everything except the lock screen and the system overlay will display over the lock screen but in 4.0.3 and above you can not receive the touch events.
I have also seen options like WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG but it only seems to work for an activity; anything else I use it with gives me an exception that tells me that I can not use that flag with this type of window.
What I have noticed is that the player controls either replace or cover the keyguard clock and the player controls change size depending on the type of lock (like pattern lock or swipe lock). I've also noticed that the keyguard does not display my wallpaper anymore...
Any thoughts are welcome!
Related
I am migrating my app target SDK Version to android oreo.
One of the changes which might affect the app is that if the Display size of the device is changed then the app targeting Android Nougat and above will be notified as if there is a change in orientation of the device. Below is the source.
When the device density changes, the system notifies running apps in
the following ways:
If an app targets API level 23 or lower, the system automatically
kills all its background processes. This means that if a user switches
away from such an app to open the Settings screen and changes the
Display size setting, the system kills the app in the same manner that
it would in a low-memory situation. If the app has any foreground
processes, the system notifies those processes of the configuration
change as described in Handling Runtime Changes, just as if the
device's orientation had changed.
If an app targets Android 7.0, all
of its processes (foreground and background) are notified of the
configuration change as described in Handling Runtime Changes.
Now my app has a longrunning process which runs in an Async TSak in an Android Activity. Which means that the App has an AsyncTask which is inside the Activity Code.
I create a Dialog box on the start of the Async Task and hide it when the Async Task has done its work.
Now suppose the users start the task and then goes to the setting and changes the Display Size then return back to my app then the dialog box of the app is gone by the Async Task is still performed till the end which mean that the user might think that the app has finished the task but whereas the app would be actually performing the task. But my Activity is also responding as if restarted except that Async Task is running.
My app's orientation locked to portrait.
How should I handle such a scenario? Any help is appreciated. Thanks!
EDIT: This is the scenario
1) App Start
2) Main Screen
3) Users Press A Button
4) AsyncTask inside Main Screen Started
5) A Dialog Box is shown with the progress of task
6) User Minimizes the App and Goes to setting
7) Changes the Display Size/Density or changes the Font Size of the device
8) My App is called by the OS in such a way as if the device rotation is changed
9) Then the user returns back to the app
10) But the dialog box shown is no more being shown
11) But the async Task is running in the background and is still performing its task
12) The task is actually done but the user thinks that the task is still not done.
In your on_resume() method verify the screen size and the font size have not changed. If they have, adjust, remove and recreate, your dialog box appropriately. This is similar to handling orientation changes while suspended (adding font size as a condition).
EDIT:
Add android:configChanges="fontScale|density" to your manifest file.
static int fontScale = 1;
static int densityDpi = 0;
public void onConfigurationChanged(Configuration newConfig) {
if (newConfig.fontScale != fontScale) {
// destroy and recreate dialog adjusting for font size.
fontScale = newConfig.fontScale;
}
if (newConfig.densityDpi != densityDpi) {
// destroy and recreate dialog adjusting for new screen size.
densityDpi = newConfig.densityDpi;
}
}
It would probably be better to utilize notifications for the async task, since they are unaffected by config changes and are not terminated in low memory conditions.
When you rotate the phone, your activity is actually destroyed and recreated. This includes your dialog. There are two ways to fix it:
1) Turn off this "helpful" functionality. If you don't have different layouts for landscape and portrait its what I'd suggest. Add android:configChange="orientation|resize" to your activity in the manifest.
2) Implement onSaveInstanceState/onRestoreInstanceState and have a variable that says whether or not you need to recreate and relaunch the dialog.
Suggestions:
Try using WorkManager to schedule the task and also ViewModel from the android architecture components which helps to retain the state even after the configuration changes
How can I switch the screen and still save the progress of the current game? For example I have an additional screen, when you press tab key, that shows some information about the player (attributes, stats, etc.), but when you switch the screen again to resume your game the show method is called again and you lose everything... The only method I know is that before you hide the screen to save the game in some format and load it in show but I highly doubt that this is the proper way to do it, as there would be a real performance issue when you switch the screens very fast... I need a way to keep the data from the previous screen and not initialize it every time the screen is showed. This would also apply to the skill tree and inventory which also needs to be saved for the entire game session. The filed loading from save game file format should be done only once not every time a screen changes. Any ideas?
I have an activity that shows up when the phone screen goes to sleep/turns off ie turns black.
For some reason, the phone turns on when the volume buttons or the camera buttons are pressed. By turns on, I mean the screen wakes up or comes back from the black screen state.
I've tried using dispatchKeyEvent(KeyEvent event) and the buttons are disabled on the activity, but they still wake up the phone.
You could try overriding the onKeyDown(KeyEvent) method and change what happens for those keys. However, I'm not too optimistic as if you're running an activity, it will be in an inactive state when the display is off, and also it could be that the phone is hard wired to wake up on those buttons. It could be device specific. Hard to say. Try that out and let me know how it goes, I'm currious
Can anyone kindly help me out?
I want to create an app, like user access control(UAC) application. When UAC is running we cannot click anywhere on the screen, unless we close UAC window. Also we cannot press any key to do anything, like window key or any of the function key. So I want to create a similar application using C ++ code to control keyboard and mouse, that only mouse and keyboard is enabled in my application window and disable outside and unless i do not close my app i cant perform any other task. My application would be just a graphical simple window with a close button, and obove mentioned controls.
A long time ago Windows supported system modal dialogs. These would prevent the user from interacting with other windows including the desktop. Microsoft removed support for this a long time ago due to the problems that it caused.
Now when Windows needs to provide a system modal window for UAC they use a bit of desktop magic. To simulate a system modal window UAC does something like this.
Create a bitmap and take a snapshot of the current desktop.
Darken the bitmap
Create a new desktop
Set the new desktop as the currently active one.
Create a window the size of the new desktop and draw the bitmap in it.
Now they have a desktop that looks like the old and acts as if it were a system model window. You are then free to create a child window to grab input from the user. The example below shows how to create a desktop and switch to it and should be a good starting point for what you want to do
// TODO: Make a copy of the current desktop
// Prepeare a new desktop and activate it
HDESK oldDesktop = GetThreadDesktop(GetCurrentThreadId());
HDESK desktop = CreateDesktop(L"MyDesktop", NULL, NULL, 0, GENERIC_ALL, NULL);
SwitchDesktop(desktop);
// TODO: Create the window that draws the snapshot of the old desktop
// TODO: Create a dialog with buttons and stuff
// Since we don't have a window sit for 5 seconds staring at blank screen
Sleep(5000);
// Switch back to the old desktop and destroy the one we created
// ALERT: If we crash or exit without doing this you will need to
// restart windows
SwitchDesktop(oldDesktop);
CloseDesktop(desktop);
You can find more information on the desktop related API's
My game app has many complex graphical elements and I am worried that having a banner ad continuously on screen will detract too much from the game. My plan is that the user will be able to play each "level" in the game using the full screen without any ads, but upon completion of each level an ad will slide in, on top of the top part of the screen. Presumably this means I have to somehow create a layout programatically that will appear on top of the existing screen layout. Can this be done? If so how?
It can be done.
Afaik you simply have to create a layout which is android:backgroundcolor="transparent".
Else you could do it so you started a new activity on each level completion?