37
37
import android .content .pm .PackageInfo ;
38
38
import android .content .pm .PackageManager ;
39
39
import android .content .pm .*;
40
+ import android .app .PictureInPictureParams ;
41
+ import android .util .Rational ;
40
42
41
43
public class MainActivity extends Activity {
42
44
43
45
private WebView web ;
44
46
private Intent i = new Intent ();
47
+ private boolean portrait = false ;
45
48
49
+
46
50
@ Override
47
51
protected void onCreate (Bundle savedInstanceState ) {
48
52
super .onCreate (savedInstanceState );
@@ -111,16 +115,28 @@ public class CustomWebClient extends WebChromeClient {
111
115
private View mCustomView ;
112
116
private WebChromeClient .CustomViewCallback mCustomViewCallback ;
113
117
protected FrameLayout frame ;
114
- private int mOriginalOrientation = android . content . pm . ActivityInfo . SCREEN_ORIENTATION_SENSOR_LANDSCAPE ;
118
+ private int mOriginalOrientation ;
115
119
private int mOriginalSystemUiVisibility ;
116
120
public CustomWebClient () {}
121
+
122
+
117
123
public Bitmap getDefaultVideoPoster () {
118
124
119
125
if (MainActivity .this == null ) {
120
126
return null ;
121
127
}
122
- return BitmapFactory .decodeResource (MainActivity .this .getApplicationContext ().getResources (), 2130837573 ); }
128
+ return BitmapFactory .decodeResource (MainActivity .this .getApplicationContext ().getResources (), 2130837573 );
129
+ }
130
+
131
+
123
132
public void onShowCustomView (View paramView , WebChromeClient .CustomViewCallback viewCallback ) {
133
+
134
+ if (portrait ){
135
+ this .mOriginalOrientation = android .content .pm .ActivityInfo .SCREEN_ORIENTATION_SENSOR_PORTRAIT ;
136
+ }else {
137
+ this .mOriginalOrientation = android .content .pm .ActivityInfo .SCREEN_ORIENTATION_SENSOR_LANDSCAPE ;
138
+ }
139
+
124
140
if (this .mCustomView != null ) {
125
141
onHideCustomView ();
126
142
return ; }
@@ -130,11 +146,19 @@ public void onShowCustomView(View paramView, WebChromeClient.CustomViewCallback
130
146
this .mOriginalOrientation = android .content .pm .ActivityInfo .SCREEN_ORIENTATION_PORTRAIT ;this .mCustomViewCallback = viewCallback ; ((FrameLayout )MainActivity .this .getWindow ().getDecorView ()).addView (this .mCustomView , new FrameLayout .LayoutParams (-1 , -1 )); MainActivity .this .getWindow ().getDecorView ().setSystemUiVisibility (3846 );
131
147
}
132
148
public void onHideCustomView () {
149
+
133
150
((FrameLayout )MainActivity .this .getWindow ().getDecorView ()).removeView (this .mCustomView );
134
151
this .mCustomView = null ;
135
152
MainActivity .this .getWindow ().getDecorView ().setSystemUiVisibility (this .mOriginalSystemUiVisibility );
136
153
MainActivity .this .setRequestedOrientation (this .mOriginalOrientation );
137
- this .mOriginalOrientation = android .content .pm .ActivityInfo .SCREEN_ORIENTATION_SENSOR_LANDSCAPE ; this .mCustomViewCallback .onCustomViewHidden ();
154
+
155
+
156
+ if (portrait ){
157
+ this .mOriginalOrientation = android .content .pm .ActivityInfo .SCREEN_ORIENTATION_SENSOR_PORTRAIT ;
158
+ }else {
159
+ this .mOriginalOrientation = android .content .pm .ActivityInfo .SCREEN_ORIENTATION_SENSOR_LANDSCAPE ;
160
+ }
161
+
138
162
this .mCustomViewCallback = null ;
139
163
web .clearFocus ();
140
164
}
@@ -186,6 +210,10 @@ public void downvid(String name,String url, String m) {
186
210
downloadFile (name ,url ,m );
187
211
}
188
212
@ JavascriptInterface
213
+ public void fullScreen (boolean value ){
214
+ portrait = value ;
215
+ }
216
+ @ JavascriptInterface
189
217
public void oplink (String url ) {
190
218
Intent i = new Intent ();
191
219
i .setAction (Intent .ACTION_VIEW );
@@ -207,10 +235,18 @@ public String getInfo() {
207
235
public void pipvid (String x ) {
208
236
if (android .os .Build .VERSION .SDK_INT >= 26 ) {
209
237
try {
210
- enterPictureInPictureMode ();
238
+ PictureInPictureParams params ;
239
+ if (portrait ){
240
+ params = new PictureInPictureParams .Builder ().setAspectRatio (new Rational (9 ,16 )).build ();
241
+ }
242
+ else {
243
+ params = new PictureInPictureParams .Builder ().setAspectRatio (new Rational (16 , 9 )).build ();
244
+ }
245
+ enterPictureInPictureMode (params );
211
246
} catch (IllegalStateException e ) {
212
247
e .printStackTrace ();
213
248
}
249
+
214
250
} else {
215
251
Toast .makeText (getApplicationContext (), "PIP not Supported" , Toast .LENGTH_SHORT ).show ();
216
252
}
0 commit comments