You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
2.4 KiB
65 lines
2.4 KiB
package edu.hzuapps.androidlabs.watchtv;
|
|
|
|
import androidx.appcompat.app.ActionBar;
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
import android.content.Context;
|
|
import android.content.res.Configuration;
|
|
import android.net.Uri;
|
|
import android.os.Bundle;
|
|
import android.view.View;
|
|
import android.view.WindowManager;
|
|
import android.widget.EditText;
|
|
import android.widget.LinearLayout;
|
|
import android.widget.MediaController;
|
|
import android.widget.RelativeLayout;
|
|
import android.widget.VideoView;
|
|
|
|
import edu.hzuapps.androidlabs.R;
|
|
|
|
public class MovieActivity extends AppCompatActivity {
|
|
|
|
VideoView videoView ;
|
|
EditText editText;
|
|
|
|
@Override
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
setContentView(R.layout.activity_movie);
|
|
|
|
ActionBar actionBar = getSupportActionBar();
|
|
if (actionBar != null) {
|
|
actionBar.hide(); //隐藏标题栏
|
|
}
|
|
|
|
videoView = findViewById(R.id.videoview);
|
|
editText = findViewById(R.id.et_home);
|
|
videoView.setMediaController(new MediaController(this));
|
|
videoView.setVideoURI(getIntent().getData());
|
|
videoView.start();
|
|
}
|
|
@Override
|
|
public void onConfigurationChanged(Configuration newConfig) {
|
|
super.onConfigurationChanged(newConfig);
|
|
videoView = findViewById(R.id.videoview);
|
|
if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
|
|
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
|
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,dip2px(this,235f));
|
|
params.addRule(RelativeLayout.CENTER_IN_PARENT);
|
|
videoView.setLayoutParams(params);
|
|
} else if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
|
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
|
|
|
videoView.setLayoutParams(new RelativeLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 根据手机的分辨率从 dp 的单位 转成为 px(像素)
|
|
*/
|
|
public static int dip2px(Context context, float dpValue) {
|
|
final float scale = context.getResources().getDisplayMetrics().density;
|
|
return (int) (dpValue * scale + 0.5f);
|
|
|
|
}
|
|
} |