playing video fullscreen mode in webview fragment android - android

I have untypical problem. I have fragment with webview and I need to play video in fullscreen. I have no problems with it. But when screen orientation changes - fragment recreated. But I need to continue playing video in fullscreen.
I can't use android:configChanges="orientation|screensize" in AndroidManifest to MainActivity, because MainActivity has two different layout for lanscape and portrait mode.

you can programatically force the screen orientation to be landscape on your fragment, so if the user rotates it do not change(you said you want the video to be fullscreen only so no reason to change a thing when it rotates), and when your activity is open but the fragment not the override on onConfigurationChanged will not be called.
So simply add this on your fragment:
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
It should works... if for any reason doesn't, try to use the same logic on onAttach/onDetach or to check the config change of the activity (if the fragment is open lock the orientation), but I think the code above should solve your problem ;]

Related

How to make a one fragment screen always in landscape mode and reamaining not.?

I have one activity which i am using as host for calling all my fragments.I am using setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) for setting screen in landscape mode.But problem is that it is making every fragment in landscape mode because their is only one parent activity for all of them.I can not use android:screenOrientation="landscape" because this will also work the same.
I want one of my fragment to be displayed always in landscape mode and remaining fragment as according to device orientation.Is their is another ways for doing it?
If you wanna show one specific Fragment in landscape you can call
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
in the onCreate() of your Fragment.
In this Fragments onPause() f.e. you can call
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
which is the default value and enables screen rotation changes.

How to lock screen orientation when anctivity isn't recreated

I have an activity used to display a video (VideoView).
By default the user can change screen orientation to see the video.
I avoid destroying/recreating the activity upon orientation changes because of latency issue.
The rotation is painless without any sound break.
android:configChanges="keyboardHidden|orientation|screenSize"
What I want to do now is add a button that will force the activity to remain on current orientation.
The problem is that because the activity isn't recreated after the rotation, I don't know which method to override to avoid the rotation to happen.
Overriding onConfigurationChanged is useless because the rotation already happened.
Use setRequestedOrientation().
E.g. to lock the orientation to portrait, call:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
In your activity.

Force Android orientation to landscape

As the title suggests, I am having trouble locking the orientation.
I am using the below code:
android:screenOrientation="landscape"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
This is working ok as far as it loads in landscape and when I rotate the mobile, it stays in landscape.
The problem however, is when the power button is pressed to lock the phone, upon unlocking the app is now forced portrait.
Is there a way to capture the unlock event and force it to goto landscape again or any other method?
Thanks in advance.
Just fixed it myself, if anyone else is experiencing the same issue try the following:
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
Set this in the onCreate() method, as well as in the onResume(), you can also set it in the onStop() as well:
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

Set initial screen orientation

I am making an app where the first screen I want to view is Portrait. I then go to the next activity which is set in landscape.
The problem i'm facing is that if I return to the first screen it will be set as landscape, evidently inheriting the orientation from the previous screen.
Is there a possible way to set the initial screen orientation as portrait which is set but the user can then go ahead and change it to landscape when they want?
Thanks
EDIT: SOLVED
Thank you for your suggestions. I've overcome the issue. It's slightly difficult to explain but will try my up most.
So my first activity has a feature whereby if the phone is turned to landscape it will show an image, full screen. And again, if the phone was portrait, the portrait view, where I have a list view.
The second activity loads an editing page to let me change that image.
So now if i press back on the editor activity. The first activity would load into a list view in LANDSCAPE. which is NOT what I want.
therefore in order to get around this. I have firstly disabled the back button when the first activity is landscape so the user can not remove himself from the view without turning the phone to landscape.
I then moved the code:
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
//Show landscape picture
}
}
to the top of my class before the onCreate method.
This has solved my issue so that now, if I was to go back to my first activity whilst in landscape the only thing that would show is the landscape view.
I hope that was clear enough for all to understand :)
Again thanks for the help!
you can set the screen orientation programmatically in the onCreate()- method:
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
just right before the call of super.onCreate();.
I hope, I could help you.
Best regards,
G_J
You can change the orientation of individual activities using this in the manifest file of your application within each of your activity's tags:
android:configChanges="orientation"
with either
android:screenOrientation="portrait"
OR
android:screenOrientation="landscape"
as per your needs
you can set the screen orientation programmatically in the onCreate() method:
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
just right after the call of super.onCreate();.
OR
You can also specify the orientation in the Manifest file like this
<activity android:name="com.example.project.activity"
android:screenOrientation="portrait"/>
Thank you for your suggestions. I've overcome the issue. It's slightly difficult to explain but will try my up most.
So my first activity has a feature whereby if the phone is turned to landscape it will show an image, full screen. And again, if the phone was portrait, the portrait view, where I have a list view.
The second activity loads an editing page to let me change that image.
So now if i press back on the editor activity. The first activity would load into a list view in LANDSCAPE. which is NOT what I want.
therefore in order to get around this. I have firstly disabled the back button when the first activity is landscape so the user can not remove himself from the view without turning the phone to landscape.
I then moved the code:
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
//Show landscape picture
}
}
to the top of my class before the onCreate method.
This has solved my issue so that now, if I was to go back to my first activity whilst in landscape the only thing that would show is the landscape view.
I hope that was clear enough for all to understand
Again thanks for the help!

android:configChanges="keyboardHidden|orientation" Issue Android

Am using android:configChanges="keyboardHidden|orientation"for switching between portrait and landscape modes. But when user opens softkeyboard in portrait and changes to landscape keyboard should hide or dissappera but its not happening with that.
If you are intercepting orientation without overriding public void onConfigurationChanged(Configuration newConfig) in your Activity it is normal that the keyboard remains open.
You can either
override this method to reset the display
or avoid intercepting orientation to let the Activity restart (in which case your Activity will be reinitialized and onCreate() will be called again)
I'm not sure in it but I think that you need to write keyboardHidden|orientation|portrait (or landscape).

Categories

Resources