Skip to content

Commit 902e5af

Browse files
Update MainActivity.java
1 parent abb52c9 commit 902e5af

File tree

1 file changed

+40
-4
lines changed

1 file changed

+40
-4
lines changed

app/src/main/java/com/google/android/youtube/pro/MainActivity.java

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,16 @@
3737
import android.content.pm.PackageInfo;
3838
import android.content.pm.PackageManager;
3939
import android.content.pm.*;
40+
import android.app.PictureInPictureParams;
41+
import android.util.Rational;
4042

4143
public class MainActivity extends Activity {
4244

4345
private WebView web;
4446
private Intent i = new Intent();
47+
private boolean portrait = false;
4548

49+
4650
@Override
4751
protected void onCreate(Bundle savedInstanceState) {
4852
super.onCreate(savedInstanceState);
@@ -111,16 +115,28 @@ public class CustomWebClient extends WebChromeClient {
111115
private View mCustomView;
112116
private WebChromeClient.CustomViewCallback mCustomViewCallback;
113117
protected FrameLayout frame;
114-
private int mOriginalOrientation = android.content.pm.ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE;
118+
private int mOriginalOrientation;
115119
private int mOriginalSystemUiVisibility;
116120
public CustomWebClient() {}
121+
122+
117123
public Bitmap getDefaultVideoPoster() {
118124

119125
if (MainActivity.this == null) {
120126
return null;
121127
}
122-
return BitmapFactory.decodeResource(MainActivity.this.getApplicationContext().getResources(), 2130837573); }
128+
return BitmapFactory.decodeResource(MainActivity.this.getApplicationContext().getResources(), 2130837573);
129+
}
130+
131+
123132
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+
124140
if (this.mCustomView != null) {
125141
onHideCustomView();
126142
return; }
@@ -130,11 +146,19 @@ public void onShowCustomView(View paramView, WebChromeClient.CustomViewCallback
130146
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);
131147
}
132148
public void onHideCustomView() {
149+
133150
((FrameLayout)MainActivity.this.getWindow().getDecorView()).removeView(this.mCustomView);
134151
this.mCustomView = null;
135152
MainActivity.this.getWindow().getDecorView().setSystemUiVisibility(this.mOriginalSystemUiVisibility);
136153
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+
138162
this.mCustomViewCallback = null;
139163
web.clearFocus();
140164
}
@@ -186,6 +210,10 @@ public void downvid(String name,String url, String m) {
186210
downloadFile(name,url,m);
187211
}
188212
@JavascriptInterface
213+
public void fullScreen(boolean value){
214+
portrait = value;
215+
}
216+
@JavascriptInterface
189217
public void oplink(String url) {
190218
Intent i = new Intent();
191219
i.setAction(Intent.ACTION_VIEW);
@@ -207,10 +235,18 @@ public String getInfo() {
207235
public void pipvid(String x) {
208236
if (android.os.Build.VERSION.SDK_INT >= 26) {
209237
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);
211246
} catch (IllegalStateException e) {
212247
e.printStackTrace();
213248
}
249+
214250
} else {
215251
Toast.makeText(getApplicationContext(), "PIP not Supported", Toast.LENGTH_SHORT).show();
216252
}

0 commit comments

Comments
 (0)