package com.basic.security.activity;
|
|
import android.content.Intent;
|
import android.media.MediaPlayer;
|
import android.os.SystemClock;
|
import android.support.v4.app.FragmentActivity;
|
import android.support.v4.app.FragmentManager;
|
import android.view.View;
|
import android.widget.EditText;
|
import android.widget.FrameLayout;
|
import android.widget.ImageView;
|
import android.widget.MediaController;
|
import android.widget.RelativeLayout;
|
import android.widget.TextView;
|
import android.widget.VideoView;
|
|
import com.basic.security.R;
|
import com.basic.security.base.BaseApplication;
|
import com.basic.security.base.BaseFragment;
|
import com.basic.security.fragment.HomeFragment;
|
import com.basic.security.fragment.SettingFragment;
|
import com.basic.security.manager.SettingManager;
|
import com.basic.security.service.KeepLifeService;
|
import com.basic.security.utils.FFmpeg;
|
import com.basic.security.utils.KeyboardUtil;
|
import com.basic.security.utils.LztekAndroidRoot;
|
import com.basic.security.widget.AuthDialog;
|
import com.basic.security.widget.MyMediaController;
|
import com.bumptech.glide.Glide;
|
|
import org.androidannotations.annotations.AfterViews;
|
import org.androidannotations.annotations.Background;
|
import org.androidannotations.annotations.Click;
|
import org.androidannotations.annotations.EActivity;
|
import org.androidannotations.annotations.FragmentById;
|
import org.androidannotations.annotations.Touch;
|
import org.androidannotations.annotations.UiThread;
|
import org.androidannotations.annotations.ViewById;
|
|
import java.text.SimpleDateFormat;
|
import java.util.Date;
|
|
@EActivity(R.layout.activity_main)
|
public class MainActivity extends FragmentActivity {
|
|
@FragmentById
|
public HomeFragment fragment_home;
|
@FragmentById
|
public SettingFragment fragment_setting;
|
@ViewById
|
public ImageView fullscreenImageView;
|
@ViewById
|
public VideoView fullscreenVideoView;
|
@ViewById
|
public TextView currentTime;
|
@ViewById
|
public TextView appTitle;
|
@ViewById
|
public ImageView exit_fullscreen;
|
@ViewById
|
public RelativeLayout mainActivityView;
|
@ViewById
|
public RelativeLayout fullscreenParentRL;
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
MediaController mediaController;
|
public BaseFragment currentFragment;
|
|
static {
|
System.loadLibrary("native-lib");
|
}
|
|
public MainActivity() {
|
BaseApplication.getApplication().activity = this;
|
}
|
|
@UiThread
|
public void hideSystemUI() {
|
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
|
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
| View.SYSTEM_UI_FLAG_FULLSCREEN
|
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
|
| View.SYSTEM_UI_FLAG_IMMERSIVE);
|
}
|
|
@AfterViews
|
public void afterViews() {
|
currentFragment = fragment_home;
|
hideSystemUI();
|
getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
|
@Override
|
public void onSystemUiVisibilityChange(int visibility) {
|
hideSystemUI();
|
}
|
});
|
mediaController = new
|
MyMediaController(this, (FrameLayout) findViewById(R.id.controllerAnchor));
|
mediaController.setAnchorView(fullscreenVideoView);
|
fullscreenVideoView.setMediaController(mediaController);
|
goto_home();
|
refreshCurrentTime();
|
fragment_home.pullAlarmDataList();
|
fragment_home.playAlarmSound();
|
KeyboardUtil.setupUI(fragment_setting.getView());
|
stopService(new Intent(this, KeepLifeService.class));
|
startService(new Intent(this, KeepLifeService.class));
|
|
appTitle.setText(SettingManager.getAppTitle());
|
}
|
|
@Background
|
public void ffmpeg() {
|
FFmpeg ffmpeg = new FFmpeg("http://192.168.1.149/alarm.mp4");
|
while(true) {
|
ffmpeg.getPicDecoder();
|
SystemClock.sleep(1000);
|
}
|
}
|
|
@Background
|
public void refreshCurrentTime() {
|
while(true) {
|
setCurrentTime();
|
SystemClock.sleep(1000);
|
}
|
}
|
|
@UiThread
|
public void setCurrentTime() {
|
currentTime.setText(sdf.format(new Date()));
|
}
|
|
public void hideOneFragment(BaseFragment fragment) {
|
fragment.hide();
|
FragmentManager fm = getSupportFragmentManager();
|
fm.beginTransaction()
|
.hide(fragment)
|
.commitAllowingStateLoss();
|
}
|
|
public void showOneFragment(BaseFragment fragment) {
|
currentFragment = fragment;
|
fragment.show();
|
FragmentManager fm = getSupportFragmentManager();
|
fm.beginTransaction()
|
.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out)
|
.show(fragment)
|
.commitAllowingStateLoss();
|
}
|
|
@Click
|
public void goto_setting() {
|
if (currentFragment == fragment_home) {
|
// do_goto_setting();
|
AuthDialog authDialog = new AuthDialog(this);
|
authDialog.show();
|
}
|
}
|
|
public void do_goto_setting() {
|
exit_fullscreen();
|
hideOneFragment(fragment_home);
|
showOneFragment(fragment_setting);
|
fragment_home.stopAllVideoPlays(null);
|
}
|
|
public void goto_home() {
|
showOneFragment(fragment_home);
|
hideOneFragment(fragment_setting);
|
fragment_home.goto_top();
|
}
|
|
public void goto_fullscreenVideoView(String url) {
|
fullscreenParentRL.setVisibility(View.VISIBLE);
|
fullscreenVideoView.setVisibility(View.VISIBLE);
|
fullscreenVideoView.setVideoPath(url);
|
fullscreenVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
|
@Override
|
public void onPrepared(MediaPlayer mp) {
|
mp.start();
|
mediaController.show();
|
mp.setLooping(false);
|
}
|
});
|
fullscreenVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
|
@Override
|
public void onCompletion(MediaPlayer mp) {
|
exit_fullscreen();
|
}
|
});
|
exit_fullscreen.setVisibility(View.VISIBLE);
|
}
|
|
public void goto_fullscreenImageView(String url) {
|
fullscreenParentRL.setVisibility(View.VISIBLE);
|
Glide
|
.with(this)
|
.load(url)
|
.into(fullscreenImageView);
|
fullscreenImageView.setVisibility(View.VISIBLE);
|
exit_fullscreen.setVisibility(View.VISIBLE);
|
}
|
|
public void exit_fullscreen() {
|
fullscreenParentRL.setVisibility(View.INVISIBLE);
|
if (fullscreenImageView.getVisibility() == View.VISIBLE) {
|
fullscreenImageView.setVisibility(View.INVISIBLE);
|
}
|
if (fullscreenVideoView.getVisibility() == View.VISIBLE) {
|
if (fullscreenVideoView.isPlaying()) {
|
fullscreenVideoView.stopPlayback();
|
}
|
fullscreenVideoView.setVisibility(View.INVISIBLE);
|
new Thread(){
|
@Override
|
public void run() {
|
SystemClock.sleep(200);
|
runOnUiThread(new Runnable() {
|
@Override
|
public void run() {
|
fragment_home.resumeVideoPlay();
|
}
|
});
|
}
|
}.start();
|
|
}
|
exit_fullscreen.setVisibility(View.INVISIBLE);
|
}
|
|
@Touch
|
public void fullscreenVideoView() {
|
exit_fullscreen();
|
}
|
|
@Click
|
public void fullscreenImageView() {
|
exit_fullscreen();
|
}
|
|
@Override
|
public void onBackPressed() {
|
android.os.Process.killProcess(android.os.Process.myPid());
|
System.exit(0);
|
}
|
|
public boolean notInFullscreenMode() {
|
if (fullscreenVideoView.getVisibility() == View.VISIBLE ||
|
fullscreenImageView.getVisibility() == View.VISIBLE) {
|
return false;
|
}
|
return true;
|
}
|
|
}
|