package fm.jiecao.jiecaovideoplayer;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.MenuItem;
import android.widget.ListView;
import fm.jiecao.jcvideoplayer_lib.JCVideoPlayer;
/**
* Created by Nathen on 16/7/31.
*/
public class ListViewNormalActivity extends AppCompatActivity {
ListView listView;
VideoListAdapter adapterVideoList;
SensorManager sensorManager;
JCVideoPlayer.JCAutoFullscreenListener sensorEventListener;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setDisplayShowTitleEnabled(true);
getSupportActionBar().setDisplayUseLogoEnabled(false);
getSupportActionBar().setTitle("NormalListView");
setContentView(R.layout.activity_listview_content);
listView = (ListView) findViewById(R.id.listview);
adapterVideoList = new VideoListAdapter(this);
listView.setAdapter(adapterVideoList);
sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
sensorEventListener = new JCVideoPlayer.JCAutoFullscreenListener();
}
@Override
public void onBackPressed() {
if (JCVideoPlayer.backPress()) {
return;
}
super.onBackPressed();
}
@Override
protected void onResume() {
super.onResume();
Sensor accelerometerSensor = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
sensorManager.registerListener(sensorEventListener, accelerometerSensor, SensorManager.SENSOR_DELAY_NORMAL);
}
@Override
protected void onPause() {
super.onPause();
sensorManager.unregisterListener(sensorEventListener);
JCVideoPlayer.releaseAllVideos();
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
finish();
break;
}
return super.onOptionsItemSelected(item);
}
}