can we change status bar or notification bar position programmatically - java

I had locked my app to portrait only mode and I handled orientation changes myself, but I realized that in landscape mode the status bar stays the same, and the UI experience would be bad.
Now, that I have developed everything accordingly, the only workaround seems to be for me is to change the status bar position programmatically, since I don't(or actually can't at this point) respect system orientation changes.
Is this possible? To change the status bar position programmatically? Only inside my app and restore once I exit?
Below I have illustrated the desired effect:
first, the app is locked to portrait mode and when I rotate the device the app's views rotate since I parse the raw sensor data and apply the rotation, but in this case the status bar doesn't rotate(since the app is locked to portrait mode, and I only have access to app's views for rotation):
A pseudocode of how I've done the above is:
View views[] = new View[]{view1, view2, view3, view4 ....};
float rotationAngle = parseRawSensorData();//typically accelerometer input
for(View view: views){
rotateWithAngle(rotationAngle);
}
Therefore the views rotate but the status bar is affixed.
what I'd like to do is to be able to rotate the status bar using some code like this:
i.e. rotate the statusbar according to the sensordata I fetch.

The statusbar is part of the Android system, not part of your application. So there is no way you could control that from your application.

Instead of rotating a status bar, you can just hide it when using your app.
Import:
import android.view.WindowManager
And write this:
getWindow().setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN
)

Related

MapActivity, how to add a progress bar in the marker popup?

I'm using MapActivity and I would like to put a progress bar in the marker popup that appears by clicking on it. I would like to put it under the marker title, in the area where the snippet would have been.
the marker I use is declared as it follows
new MarkerOptions().position(infoLocal.getUserLocation()).title("Your Location").snippet("This is you!").icon(BitmapDescriptorFactory.fromResource(R.drawable.player3)).anchor(0.5f, 0.5f)
As per the Android docs:
'An info window is not a live View. Instead, the view is rendered as an image on the map. As a result, any listeners you set on the view are disregarded and you cannot distinguish between click events on various parts of the view. You are advised not to place interactive components — such as buttons, checkboxes, or text inputs — within your custom info window.'
Hence you can not put live components (like progress bar) in a info window, As it converts the whole view to an image.
If you still want to achieve this, this library may help:
https://github.com/Appolica/InteractiveInfoWindowAndroid

activity orientation change bug

I'm experiencing a weird bug that I haven't seen in an Android application before. When navigating from an activity locked in portrait mode to an activity locked in landscape mode and back, the activity that's supposed to be in portrait appears in portrait mode, goes to landscape and then back to portrait.
This happens while the device is flat on the table with no actual orientation changes. I'm using two separate activities, and that's the only code that I have in the project.
Here is a video of the bug, and here's a link to the exact project that reproduces this bug. It happens on more than one device so it's not isolated to my device.
Questions:
Do you know what could be causing this?
Is there anything that you can recommend for fixing this?
Things I've tried:
Setting the orientation programatically
Googling and not finding anything
Update 1
More things I've tried:
Setting the portrait activity to "nosensor" and the landscape one to "landscape"
Setting the portrait activity to "nosensor" and programatically setting the landscape activity in onCreate
Update 2
I've been working with the project linked above and just did some overrides to log out everything that's happening. I found that when the onConfigurationChanged is called it does the little shimmy between the landscape and the portrait orientations. The output for a back navigation that doesn't do the shimmy is:
D/class com.mdk_studio.orientationbugtests.MainActivity: onStateNotSaved
D/class com.mdk_studio.orientationbugtests.MainActivity: onRestart
D/class com.mdk_studio.orientationbugtests.MainActivity: onWindowFocusChanged
The output for the shimmy bug is:
D/class com.mdk_studio.orientationbugtests.MainActivity: onStateNotSaved
D/class com.mdk_studio.orientationbugtests.MainActivity: onRestart
D/class com.mdk_studio.orientationbugtests.MainActivity: onWindowFocusChanged
D/class com.mdk_studio.orientationbugtests.MainActivity: onConfigurationChanged
D/class com.mdk_studio.orientationbugtests.MainActivity: onConfigurationChanged
I guess the question now becomes, how do I make sure the orientation change does not get called?
After testing out all the different combinations of manifest level orientation setting and programmatic orientation setting. I have figured out that for the orientation to not be wrong in the onConfigurationChanged function you have to set the orientation before the navigation is actually started.
The combination that worked for me and took the behaviour away completely was to set the activity in the manifest that I want in portrait to "nosensor". Then set the activity that I want in landscape to landscape using
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
and set the orientation back to portrait in the onBackPressed before the navigation occures. That part is important, once the navigation has been triggered and then you set the orientation, in some cases when the newConfiguration comes through in the onConfigurationChanged call it has the wrong orientation, and then it somehow issues another call to it to correct it after it's been updated on the first call.
tl;dr
Set the orientation for the activity you want in portrait to "nosensor". Programatically set the orientation to landscape in onCreate. Set the orientation back to portrait in onBackPressed, before the super call.

Samsung Galaxy S8 full screen mode

Latest Samsung's smartphone has interesting feature called full screen (or in marketing terms infinity display). In this mode app covers also part of display where home/back buttons are. Usual apps don't cover this area, leaving it black. But Samsung's native ones cover this area.
Question: how to achieve this effect? I mean what kind of manifest declaration or programmatic call (possibly Samsung's legacy API) should I use?
To enable new Samsung Galaxy S8 and LG G6 full screen support add to the AndroidManifest.xml under the <application> element:
<meta-data android:name="android.max_aspect" android:value="2.1" />
Where value of 2.1 is aspect ratio 18.5:9 (By default your App defaults to maximum ratio for 16:9 - 1.86). More info in: Android Blog.
Alternatively, you can set the following attribute for Application or Activity:
android:resizeableActivity="true"
Because the documentations states (link):
You do not need to set a maximum aspect ratio if an activity's
android:resizeableActivity attribute is set to true. If your app
targets API level 24 or higher, this attribute defaults to true.
to get full-screen you must overide onWindowFocusChanged method and create decorView object and add System_UI flags into it..
#Override
public void onWindowFocusChanged(boolean hasFocus){
super.onWindowFocusChanged(hasFocus);
View decorView = getWindow().getDecorView();
if(hasFocus){
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY // this flag do=Semi-transparent bars temporarily appear and then hide again
|View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN // Make Content Appear Behind the status Bar
|View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION // it Make Content Appear Behind the Navigation Bar
|View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
|View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
}
}
It can be turned off. I used this tutorial for my S8
How To Enable Full Screen Apps on Galaxy S8/S8+

How to hide notification icons in Android Status Bar?

I'm working on a German Learning app project, inspired by Duolingo app.
I need to make my app to be a little bit similar with this feature. It's like making the user to focus on the quiz, and ignore everything in status bar (notification bar). Now, what I need is i want to hide the icons on notification bar. Is there a way to do so?
This is what I want
And this is the fact
You can dim the status and navigation bars by setting the SYSTEM_UI_FLAG_LOW_PROFILE flag.
View decorView = getActivity().getWindow().getDecorView();
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
https://developer.android.com/training/system-ui/dim.html
This decoration is reset whenever the keyboard is made visible, but you can watch for the keyboard being hidden (using an onGlobalLayoutListener) and resetting the flag.
You could just disable notifications for the offending apps in your device's settings menu. I'm looking for an option to hide them from the status bar while keeping notifications in the shade and on the lock screen. Apparently not on a Samsung device.

When I change orientation portrait to landscape, a function is restarted in Android

When I change orientation portrait to landscape (or landscaper to portrait), a function is restarted. I want the function is saved in Android. I'm making a calculator. I don't want operator buttons to be enable before number buttons is clicked. So I made a function that make operator buttons click after number buttons is clicked. However, when I clicked a number to calculate, then change orientation, the operator buttons are not enable. It's supposed to be enable.
I mean, number click -> operator click -> number click -> equals button click -> the result is showed, this is okay. But number click -> change orientation -> operator buttons are not enable.... This is my code
You have two options:
Go to the manifest file and set the orientation of the activity to
either landscape or portrait.
Save some state that your activity holds in a bundle. In OnCreate, the first thing you do is check if the bundle is null (it will be the first time). If it is not then read the bundle (it is the same one you saved) and reset all the states you saved. Save a bundle with your current state information every time at the end of OnCreate. This should fix your problem of resetting states, also allowing you to rotate the device.
This is a widely know concept and you should probably have used a search engine extensively before posting a question. Google is your friend. :)
when you change the orientation of the device your Activity is destroyed and recreated.so you must save the state with onSaveInstanceState()
before the activity is destroyed and than restore it.
moreover if you want to disable orientation change than simply set android:screenOrientation="portrait in you Manifest. read this to learn how to handle runtime changes in Android.

Categories