|
|
|
@ -36,16 +36,18 @@ import android.view.ViewConfiguration;
|
|
|
|
|
import android.view.WindowManager;
|
|
|
|
|
import android.widget.LinearLayout;
|
|
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
|
import androidx.core.view.ViewCompat;
|
|
|
|
|
import androidx.core.view.ViewConfigurationCompat;
|
|
|
|
|
|
|
|
|
|
import com.bumptech.glide.Glide;
|
|
|
|
|
import com.yinuo.safetywatcher.databinding.ActivityMainProBinding;
|
|
|
|
|
import com.yinuo.safetywatcher.watcher.base.NoOptionsActivity;
|
|
|
|
|
|
|
|
|
|
import tv.danmaku.ijk.media.player.IMediaPlayer;
|
|
|
|
|
|
|
|
|
|
public class ProVideoActivity extends AppCompatActivity {
|
|
|
|
|
public class ProVideoActivity extends NoOptionsActivity {
|
|
|
|
|
private static final String TAG = "ProVideoActivity";
|
|
|
|
|
|
|
|
|
|
public static final int REQUEST_WRITE_STORAGE = 111;
|
|
|
|
@ -63,17 +65,112 @@ public class ProVideoActivity extends AppCompatActivity {
|
|
|
|
|
@SuppressLint("ClickableViewAccessibility")
|
|
|
|
|
@Override
|
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
|
|
|
View decorView = getWindow().getDecorView();
|
|
|
|
|
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
|
|
|
|
|
getWindow().setStatusBarColor(Color.TRANSPARENT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mBinding = ActivityMainProBinding.inflate(getLayoutInflater());
|
|
|
|
|
setContentView(mBinding.getRoot());
|
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// @Override
|
|
|
|
|
// public boolean onKeyDown(int keyCode, KeyEvent event) {
|
|
|
|
|
// if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
|
|
|
|
|
// mVideoView.toggleMediaControlsVisiblity();
|
|
|
|
|
// return true;
|
|
|
|
|
// } else if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) {
|
|
|
|
|
// mediaController.rewindVideo();
|
|
|
|
|
// return true;
|
|
|
|
|
// } else if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
|
|
|
|
|
// mediaController.fastVideo();
|
|
|
|
|
// return true;
|
|
|
|
|
// } else {
|
|
|
|
|
// return super.onKeyDown(keyCode, event);
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean dispatchKeyEvent(@NonNull KeyEvent event) {
|
|
|
|
|
if (!mediaController.isShowing() && !isBackFocused()) {
|
|
|
|
|
mVideoView.toggleMediaControlsVisiblity();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return super.dispatchKeyEvent(event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onStop() {
|
|
|
|
|
super.onStop();
|
|
|
|
|
mVideoView.stopPlayback();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onDestroy() {
|
|
|
|
|
super.onDestroy();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onConfigurationChanged(Configuration newConfig) {
|
|
|
|
|
super.onConfigurationChanged(newConfig);
|
|
|
|
|
LinearLayout container = mBinding.playerContainer;
|
|
|
|
|
|
|
|
|
|
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
|
|
|
|
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
|
|
|
|
setNavVisibility(false);
|
|
|
|
|
// 横屏情况 播放窗口横着排开
|
|
|
|
|
container.setOrientation(LinearLayout.HORIZONTAL);
|
|
|
|
|
} else {
|
|
|
|
|
// 竖屏,取消全屏状态
|
|
|
|
|
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
|
|
|
|
setNavVisibility(true);
|
|
|
|
|
// 竖屏情况 播放窗口竖着排开
|
|
|
|
|
container.setOrientation(LinearLayout.VERTICAL);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isLandscape() {
|
|
|
|
|
int orientation = getResources().getConfiguration().orientation;
|
|
|
|
|
return orientation == ORIENTATION_LANDSCAPE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setNavVisibility(boolean visible) {
|
|
|
|
|
if (!ViewConfigurationCompat.hasPermanentMenuKey(ViewConfiguration.get(this))) {
|
|
|
|
|
int newVis = View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
|
|
|
|
|
|
|
|
|
|
if (!visible) {
|
|
|
|
|
newVis |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If we are now visible, schedule a timer for us to go invisible. Set the new desired visibility.
|
|
|
|
|
getWindow().getDecorView().setSystemUiVisibility(newVis);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void onChangeOrientation(View view) {
|
|
|
|
|
setRequestedOrientation(isLandscape() ? ActivityInfo.SCREEN_ORIENTATION_PORTRAIT : ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void onChangePlayMode(View view) {
|
|
|
|
|
mMode = mVideoView.toggleAspectRatio();
|
|
|
|
|
Log.i(TAG, "画面模式:" + mMode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
|
@Override
|
|
|
|
|
public View generateContentView() {
|
|
|
|
|
if (mBinding != null) {
|
|
|
|
|
return mBinding.getRoot();
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void initView() {
|
|
|
|
|
// mBinding = ActivityMainProBinding.inflate(getLayoutInflater());
|
|
|
|
|
// setContentView(mBinding.getRoot());
|
|
|
|
|
// handle arguments
|
|
|
|
|
mVideoPath = getIntent().getStringExtra("videoPath");
|
|
|
|
|
|
|
|
|
@ -214,79 +311,21 @@ public class ProVideoActivity extends AppCompatActivity {
|
|
|
|
|
// detector.onTouchEvent(event);
|
|
|
|
|
// return true;
|
|
|
|
|
// });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
|
|
|
|
if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
|
|
|
|
|
mVideoView.toggleMediaControlsVisiblity();
|
|
|
|
|
return true;
|
|
|
|
|
} else if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) {
|
|
|
|
|
mediaController.rewindVideo();
|
|
|
|
|
return true;
|
|
|
|
|
} else if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
|
|
|
|
|
mediaController.fastVideo();
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
return super.onKeyDown(keyCode, event);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onStop() {
|
|
|
|
|
super.onStop();
|
|
|
|
|
mVideoView.stopPlayback();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onDestroy() {
|
|
|
|
|
super.onDestroy();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onConfigurationChanged(Configuration newConfig) {
|
|
|
|
|
super.onConfigurationChanged(newConfig);
|
|
|
|
|
LinearLayout container = mBinding.playerContainer;
|
|
|
|
|
|
|
|
|
|
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
|
|
|
|
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
|
|
|
|
setNavVisibility(false);
|
|
|
|
|
// 横屏情况 播放窗口横着排开
|
|
|
|
|
container.setOrientation(LinearLayout.HORIZONTAL);
|
|
|
|
|
} else {
|
|
|
|
|
// 竖屏,取消全屏状态
|
|
|
|
|
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
|
|
|
|
setNavVisibility(true);
|
|
|
|
|
// 竖屏情况 播放窗口竖着排开
|
|
|
|
|
container.setOrientation(LinearLayout.VERTICAL);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isLandscape() {
|
|
|
|
|
int orientation = getResources().getConfiguration().orientation;
|
|
|
|
|
return orientation == ORIENTATION_LANDSCAPE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setNavVisibility(boolean visible) {
|
|
|
|
|
if (!ViewConfigurationCompat.hasPermanentMenuKey(ViewConfiguration.get(this))) {
|
|
|
|
|
int newVis = View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
|
|
|
|
|
|
|
|
|
|
if (!visible) {
|
|
|
|
|
newVis |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE;
|
|
|
|
|
View backArea = getBaseBinding().topBar.getBackArea();
|
|
|
|
|
int backAreaId = backArea.getId();
|
|
|
|
|
backArea.setNextFocusRightId(backAreaId);
|
|
|
|
|
backArea.setNextFocusLeftId(backAreaId);
|
|
|
|
|
backArea.setOnKeyListener(new View.OnKeyListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
|
|
|
|
if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
|
|
|
|
|
if (event.getAction() == KeyEvent.ACTION_DOWN) {
|
|
|
|
|
mediaController.tryFocusSelf();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If we are now visible, schedule a timer for us to go invisible. Set the new desired visibility.
|
|
|
|
|
getWindow().getDecorView().setSystemUiVisibility(newVis);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void onChangeOrientation(View view) {
|
|
|
|
|
setRequestedOrientation(isLandscape() ? ActivityInfo.SCREEN_ORIENTATION_PORTRAIT : ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void onChangePlayMode(View view) {
|
|
|
|
|
mMode = mVideoView.toggleAspectRatio();
|
|
|
|
|
Log.i(TAG, "画面模式:" + mMode);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|