I am using jiaozi video player library for playing video in my android app. Everything is working fine. Now i am facing an issue, on screen orientation change from portrait to landscape the video should be fullscreen, has anyone done this, if yes then pls share me the code or snippet so that i can implement the same.
Examplifying the code I got from here: https://stackoverflow.com/a/5726776/2232127
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Checks the orientation of the screen
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
yourVideoPlayer.setFullscreen(true);
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
yourVideoPlayer.setFullscreen(false);
}
}
I don't actually know your video player library, so the setFullscreen method probably doesn't exist. Try to find the equivalent for that.
Related
I need to show 2 columns in RecyclerView when the orientation is portrait and 4 columns when orientation is land. It works correct on the emulator.
It's RecyclerView in portrait orientation.
Turning the emulator:
As you can see, there is refresh button. And after clicking on it we see 4 columns on screen:
But when I run the project on my mobile phone, there is no refresh button and I see 2 columns in land orientation.
Here's a part of my code:
#Override
public void onConfigurationChanged(Configuration newConfig){
super.onConfigurationChanged(newConfig);
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE){
previewImages.setLayoutManager(new GridLayoutManager(this, 4));
}
else {
previewImages.setLayoutManager(new GridLayoutManager(this, 2));
}
}
And I added this line to manifest:
android:configChanges="orientation"
So, what's the problem and how can I solve it?
can you change your code block in onConfigurationChanged method like this. maybe can help.
new GridLayoutManager(context, 1, GridLayoutManager.HORIZONTAL, false)
I have a problem with JW player. when I touch fullscreen button in JW player nothing happen and just arrow state change. and when I rotate phone JW become from vertical to horizontal but won't be fullscreen. I check my another app that worked in JW player previously but now they won't work too. (JW can play video without any problem but can't be in fullscreen in no way).
may please help me with this?
override fun onConfigurationChanged(newConfig: Configuration?) {
super.onConfigurationChanged(newConfig)
if (newConfig?.orientation == Configuration.ORIENTATION_PORTRAIT) {
if(jw.fullscreen) {
jw.setFullscreen(false, true)
}
} else if (newConfig?.orientation == Configuration.ORIENTATION_LANDSCAPE) {
if(!jw.fullscreen) {
jw.setFullscreen(true, true)
}
}
}
this is my code that controls change rotation in JW player.
If you are using Android 9, you will need to update the JWPlayer SDK at least to 3.4.1 (there was fixed).
Here you can find the answer:
Android - JWplayer Fullscreen not working issue
im working on an android app and im dealing with a webview inside of my android app. i have two layout mainly the activitymain.xml found in layout folder and another layout named activitymain.xml found in layout-land folder and im loading these two from 1 java file but i need these two to load two different webview one for landscape and one for portrait.my question is is it possible to directly put the url/file path of my webview in xml so that when the user change orientation and the activitymain.xml in layout-land load he load a webview for landscape and not the webview that is in portrait xml?
UPDATE:
i was able to run to it on my own terms problem is that it loads again from the start that was a stupid mistake i didnt put into account when the change occurs the app loads a new page which was the plan from that start but the problem is the data of the user before the change is lost and therefor i think that the solution i had is not a solution but a problem can you advice me on how to make change in orientation without the loss of data and to continue where in the last page where the change happened not to start from the beginning again ?
I think he is trying to find some way to set the url directly in the xml-file without having to run the method loadUrl in the Activity. Like: <Webview android:url="#string/my_url" />
But i dont think that is possible. See the official documentation Handling Runtime Changes
Changing it will actually create a new view.
Instead you can do it like this programmatically:
in your onCreate method code it like this
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/*getResources().getConfiguration().ORIENTATION_PORTRAIT;*/
webview = (WebView)findViewById(R.id.webView1);
webview.getSettings().setJavaScriptEnabled(true);
webview.setWebViewClient(new WebViewClient()
{
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Toast.makeText(getApplicationContext(), description, Toast.LENGTH_SHORT).show();
}
});
webview.loadUrl("http://www.facebook.com");
}
Furthermore you can check orientation change via:
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Checks the orientation of the screen
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
webview.loadUrl("http://www.google.com");
Toast.makeText(getApplicationContext(), "landscape", Toast.LENGTH_SHORT).show();
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
webview.loadUrl("http://www.stackoverflow.com");
Toast.makeText(getApplicationContext(), "portrait", Toast.LENGTH_SHORT).show();
}
}
and put this in your manifest.xml <activity>
android:configChanges="orientation|screenSize"
Hopefully this will work for you. works fine for me.
Edit:
Dont forget to give the Internet Permission else it wont run
<uses-permission android:name="android.permission.INTERNET"/>
Else if any problem, then do let me know.
Thank you.
I wrote my layout entirely in java code because it was just more convenient. (I had a lot of textViews and using for statements were more convenient).
However, my TextViews require the day of the week and in portrait mode, I would like to cut the day of the week to a short form. For example, I want "Sunday" to show "Sun" for portrait mode, but "Sunday" for landscape mode.
I understand how to do this in XML files, but how do I do it in code?
I.e. sample code:
LinearLayout parent = new LinearLayout(getApplicationContext());
parent.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT));
TextView example = new TextView;
example.setLayoutParams(mparams);
example.setText("Sunday"); //<--make this "Sun" when in portrait but "Sunday" in landscape
parent.addView(example);
If your application is getting restarted when it moves to landscape then you can define the strings that need to be expanded in Landscape mode in values-land
And it is never a good idea to use hard coded strings. Even if you are creating layouts programmatically use strings.xml to store strings
You can override the onConfigurationChanged() method in your Activity class, and you can set your text, when orientation will change this method will call... Hope it will helpful to you..:)
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
// Here you can set text **Sun**
} else if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
//Here you can set text **Sunday**
}
}
How do I determine whether or not the accelerometer would report a roll of zero when the bottom long side of the screen is facing the ground?
I need to do this without instructing the user to hold the phone in a certain position. I am hoping to be able to do something like:
Context.getResources().getConfiguration().getNaturalOrientation == Orientation.LANDSCAPE
IMPORTANT: The above line of code is not possible, it's just an example of what I would like to do.
I found the answer for this. It's very simple using API8 and higher, simply use Display.getRotation()
this may help you to detect the configuration change
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
//onConfigurationChanged
if (newConfig.equals(Configuration.ORIENTATION_LANDSCAPE)) {
//ORIENTATION_LANDSCAPE
} else if (newConfig.equals(Configuration.ORIENTATION_PORTRAIT)) {
//ORIENTATION_PORTRAIT
}
}