FilePlaybackFragment.java 源代码
package timeaxis;
import activity.FishEye.FishPlaybackOnlineActivity;
import activity.LocalFile.LocalFileActivity2;
import activity.WallMounted.WallMountedOnlineActivity;
import activity.video.PlaybackOnlineActivity;
import activity.video.PlaybackOnlineDualActivity;
import activity.video.PlaybackOnlineDualActivity_ThreeEyes;
import activity.video.SearchSDCardVideoActivity;
import activity.video.adapter.VideoOnlineListAdapter;
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.drawable.ColorDrawable;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.design.widget.FloatingActionButton;
import android.text.Html;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.Toast;
import base.HiFragment;
import bean.MyCamera;
import butterknife.ButterKnife;
import butterknife.Unbinder;
import com.hichip.callback.ICameraDownloadCallback;
import com.hichip.callback.ICameraIOSessionCallback;
import com.hichip.campro.R;
import com.hichip.content.HiChipDefines;
import com.hichip.control.HiCamera;
import com.xiaomi.mipush.sdk.Constants;
import common.ConstantCommand;
import common.HiDataValue;
import custom.CircleProgressBar;
import java.io.File;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import org.apache.http.cookie.ClientCookie;
import org.greenrobot.eventbus.EventBus;
import timeaxis.bean.FilePlaybackModel;
import timeaxis.bean.MsyIsStop;
import utils.HiLogcatUtil;
import utils.HiTools;
import utils.MyToast;
import utils.SharePreUtils;
import utils.TimeUtil;
public class FilePlaybackFragment extends HiFragment implements View.OnClickListener, AdapterView.OnItemClickListener, ICameraIOSessionCallback, ICameraDownloadCallback {
public static final int HANDLE_MESSAGE_NETWORK_CHANGED = 1048577;
public static final int MY_PERMISSION_REQUEST_CODE = 10046;
public static final String SEARCH_ACTIVITY_END_TIME = "END TIME";
public static final int SEARCH_ACTIVITY_RESULT = 1;
public static final String SEARCH_ACTIVITY_START_TIME = "START TIME";
public static final String VIDEO_PLAYBACK_END_TIME = "VIDEO END TIME";
public static final String VIDEO_PLAYBACK_START_TIME = "VIDEO START TIME";
private static final SimpleDateFormat sdf = new SimpleDateFormat("00:mm:ss");
private VideoOnlineListAdapter adapter;
FloatingActionButton btn_floatingaction;
private CircleProgressBar circleprogressbar;
private long currentMills;
private PopupWindow downloadPopupWindow;
private String download_path;
private ConstantCommand.HI_P2P_FILE_INFO evt;
private String fileName;
private boolean hideSize;
private boolean isClickCancel;
private boolean isVisibleToUser;
private ImageView iv_arrow;
ListView list_video_online;
private Activity mAct;
private MyCamera mMyCamera;
private ConnectionChangeReceiver myReceiver;
private String path;
private TextView popu_tips_down;
private HiChipDefines.HI_P2P_S_SD_INFO sd_info;
private TextView tv_cancel_downloading_video;
private TextView tv_goto_downloading_video;
TextView tv_not_online;
TextView tv_nothing;
private TextView tv_one;
private TextView tv_sort;
private TextView tv_two;
private Unbinder unbinder;
private View searchTimeView = null;
private View loadingView = null;
private List<ConstantCommand.HI_P2P_FILE_INFO> file_list = Collections.synchronizedList(new ArrayList());
private boolean isDownloading = false;
private int mType = 0;
public boolean mIsDataReceveEnd = false;
private boolean mIsDown = true;
private Handler handler = new Handler() {
@Override
public void handleMessage(Message message) {
String str;
switch (message.what) {
case HiDataValue.HANDLE_MESSAGE_SESSION_STATE:
if (message.arg1 == 0 && FilePlaybackFragment.this.isVisibleToUser) {
if (FilePlaybackFragment.this.isDownloading && !TextUtils.isEmpty(FilePlaybackFragment.this.path)) {
File file = new File(FilePlaybackFragment.this.path);
if (file.isFile() && file.exists()) {
file.delete();
}
}
FilePlaybackFragment.this.dismissJuHuaDialog();
MyToast.showToast(FilePlaybackFragment.this.mAct, FilePlaybackFragment.this.getString(R.string.disconnect));
if (FilePlaybackFragment.this.mAct != null) {
FilePlaybackFragment.this.mAct.finish();
return;
}
return;
}
return;
case HiDataValue.HANDLE_MESSAGE_RECEIVE_IOCTRL:
if (message.arg2 == -1) {
MyToast.showToast(FilePlaybackFragment.this.mAct, FilePlaybackFragment.this.getString(R.string.tips_update_system_failed));
FilePlaybackFragment.this.dismissLoadDialog();
return;
}
if (message.arg2 == 0) {
byte[] byteArray = message.getData().getByteArray("data");
int i = message.arg1;
if ((i == 8193 || i == 16685 || i == 16701 || i == 16729) && byteArray.length >= 12) {
byte b = byteArray[8];
byte b2 = byteArray[9];
if (b2 > 0) {
for (int i2 = 0; i2 < b2; i2++) {
byte[] bArr = new byte[24];
int sizeof = (HiChipDefines.HI_P2P_FILE_INFO.sizeof() * i2) + 12;
if (byteArray.length >= sizeof + 24) {
System.arraycopy(byteArray, sizeof, bArr, 0, 24);
ConstantCommand.HI_P2P_FILE_INFO hi_p2p_file_info = new ConstantCommand.HI_P2P_FILE_INFO(bArr);
long timeInMillis2 = hi_p2p_file_info.sEndTime.getTimeInMillis2() - hi_p2p_file_info.sStartTime.getTimeInMillis2();
if (timeInMillis2 <= 1500000 && timeInMillis2 > 0) {
hi_p2p_file_info.fileLength = FilePlaybackFragment.sdf.format(new Date(timeInMillis2 + 1));
FilePlaybackFragment.this.file_list.add(hi_p2p_file_info);
}
}
}
}
if (b == 1) {
FilePlaybackFragment.this.mIsDataReceveEnd = true;
FilePlaybackFragment.this.list_video_online.removeFooterView(FilePlaybackFragment.this.loadingView);
if (FilePlaybackFragment.this.file_list != null && FilePlaybackFragment.this.file_list.size() <= 0) {
FilePlaybackFragment.this.list_video_online.removeHeaderView(FilePlaybackFragment.this.searchTimeView);
FilePlaybackFragment.this.list_video_online.setVisibility(8);
FilePlaybackFragment.this.tv_nothing.setVisibility(0);
int i3 = FilePlaybackFragment.this.mType;
if (i3 == 0) {
str = "<font color='#45A7E6'>" + FilePlaybackFragment.this.getString(R.string.six_hours) + "</font><font color='#666666'/>" + FilePlaybackFragment.this.getString(R.string.click_right_corner) + "</font>";
} else if (i3 == 1) {
str = "<font color='#45A7E6'>" + FilePlaybackFragment.this.getString(R.string.one_hours) + "</font><font color='#666666'/>" + FilePlaybackFragment.this.getString(R.string.click_right_corner) + "</font>";
} else if (i3 == 2) {
str = "<font color='#45A7E6'>" + FilePlaybackFragment.this.getString(R.string.half_day) + "</font><font color='#666666'/>" + FilePlaybackFragment.this.getString(R.string.click_right_corner) + "</font>";
} else if (i3 == 3) {
str = "<font color='#45A7E6'>" + FilePlaybackFragment.this.getString(R.string.one_day) + "</font><font color='#666666'/>" + FilePlaybackFragment.this.getString(R.string.click_right_corner) + "</font>";
} else if (i3 == 4) {
str = "<font color='#45A7E6'>" + FilePlaybackFragment.this.getString(R.string.one_week) + "</font><font color='#666666'/>" + FilePlaybackFragment.this.getString(R.string.click_right_corner) + "</font>";
} else if (i3 != 5) {
str = " ";
} else {
str = "<font color='#45A7E6'>" + FilePlaybackFragment.this.getString(R.string.constom_time) + "</font><font color='#666666'/>" + FilePlaybackFragment.this.getString(R.string.click_right_corner) + "</font>";
}
FilePlaybackFragment.this.tv_nothing.setText(Html.fromHtml(str));
}
FilePlaybackFragment.this.dismissJuHuaDialog();
Collections.reverse(FilePlaybackFragment.this.file_list);
if (FilePlaybackFragment.this.adapter != null) {
FilePlaybackFragment.this.adapter.notifyDataSetChanged();
return;
}
return;
}
return;
}
return;
}
return;
case HiDataValue.HANDLE_MESSAGE_DOWNLOAD_STATE:
FilePlaybackFragment.this.handDownLoad(message);
return;
case 1048577:
FilePlaybackFragment.this.handNETWORK_CHANGED();
return;
default:
return;
}
}
};
@Override
public void callbackDownloadSnapData(HiCamera hiCamera, int i, byte[] bArr, int i2, int i3) {
}
@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
}
@Override
public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
View inflate = layoutInflater.inflate(R.layout.fragment_file_playback, (ViewGroup) null);
this.unbinder = ButterKnife.bind(this, inflate);
getIntentData();
Activity activity2 = this.mAct;
if (activity2 != null && HiTools.cameraWhetherNull(this.mMyCamera, activity2)) {
return null;
}
initView();
setOnLiserners();
return inflate;
}
private void setOnLiserners() {
this.btn_floatingaction.setOnClickListener(this);
}
private void initView() {
this.searchTimeView = getLayoutInflater().inflate(R.layout.search_event_result, (ViewGroup) null);
this.loadingView = getLayoutInflater().inflate(R.layout.loading_events, (ViewGroup) null);
((LinearLayout) this.searchTimeView.findViewById(R.id.ll_sort)).setOnClickListener(this);
this.tv_sort = (TextView) this.searchTimeView.findViewById(R.id.tv_sort);
this.iv_arrow = (ImageView) this.searchTimeView.findViewById(R.id.iv_arrow);
this.list_video_online.setOverScrollMode(2);
}
private void getIntentData() {
String string = getArguments().getString(HiDataValue.EXTRAS_KEY_UID);
if (TextUtils.isEmpty(string)) {
return;
}
for (MyCamera myCamera : HiDataValue.CameraList) {
if (string.equals(myCamera.getUid())) {
this.mMyCamera = myCamera;
return;
}
}
}
private void searchVideo() {
long beforeHourTime = getBeforeHourTime(6);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(TimeUtil.FORMAT_DATE_TIME_FULL);
ListView listView = this.list_video_online;
if (listView == null) {
return;
}
listView.addFooterView(this.loadingView);
if (this.list_video_online.getHeaderViewsCount() == 0) {
this.list_video_online.addHeaderView(this.searchTimeView);
}
if (this.mAct == null) {
return;
}
if (this.mMyCamera.getIsLiteOs()) {
this.hideSize = this.mMyCamera.appGetCommandFunction(65594);
} else {
this.hideSize = this.mMyCamera.appGetCommandFunction(ConstantCommand.HI_P2P_SUPPORT_SDPERCENT);
}
VideoOnlineListAdapter videoOnlineListAdapter = new VideoOnlineListAdapter(this.mAct, this.file_list, this.hideSize);
this.adapter = videoOnlineListAdapter;
this.list_video_online.setAdapter((ListAdapter) videoOnlineListAdapter);
this.list_video_online.setOnItemClickListener(this);
((TextView) this.searchTimeView.findViewById(R.id.txtSearchTimeDuration)).setText(simpleDateFormat.format(new Date(beforeHourTime)) + " - " + HiTools.sdfTimeSec(System.currentTimeMillis()));
MyCamera myCamera = this.mMyCamera;
if (myCamera != null) {
if (myCamera.appGetCommandFunction(HiChipDefines.HI_P2P_PB_QUERY_START_NODST)) {
this.mMyCamera.sendIOCtrl(HiChipDefines.HI_P2P_PB_QUERY_START_NODST, HiChipDefines.HI_P2P_S_PB_LIST_REQ.parseContent(0, beforeHourTime, System.currentTimeMillis(), (byte) 0, 0));
return;
}
if (this.mMyCamera.appGetCommandFunction(HiChipDefines.HI_P2P_PB_QUERY_START_NEW)) {
this.mMyCamera.sendIOCtrl(HiChipDefines.HI_P2P_PB_QUERY_START_NEW, HiChipDefines.HI_P2P_S_PB_LIST_REQ.parseContent(0, beforeHourTime, System.currentTimeMillis(), (byte) 0, 1));
} else if (this.mMyCamera.appGetCommandFunction(HiChipDefines.HI_P2P_PB_QUERY_START_EXT)) {
this.mMyCamera.sendIOCtrl(HiChipDefines.HI_P2P_PB_QUERY_START_EXT, HiChipDefines.HI_P2P_S_PB_LIST_REQ.parseContent(0, beforeHourTime, System.currentTimeMillis(), (byte) 0, 1));
} else {
this.mMyCamera.sendIOCtrl(HiChipDefines.HI_P2P_PB_QUERY_START, HiChipDefines.HI_P2P_S_PB_LIST_REQ.parseContent(0, beforeHourTime, System.currentTimeMillis(), (byte) 0, 1));
}
}
}
public long getBeforeHourTime(int i) {
Calendar calendar = Calendar.getInstance();
calendar.set(11, calendar.get(11) - i);
return calendar.getTimeInMillis();
}
public class ConnectionChangeReceiver extends BroadcastReceiver {
public ConnectionChangeReceiver() {
}
@Override
public void onReceive(Context context, Intent intent) {
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService("connectivity");
NetworkInfo networkInfo = connectivityManager.getNetworkInfo(0);
NetworkInfo networkInfo2 = connectivityManager.getNetworkInfo(1);
if (networkInfo == null || networkInfo.isConnected() || networkInfo2 == null || networkInfo2.isConnected() || !FilePlaybackFragment.this.isDownloading) {
return;
}
FilePlaybackFragment.this.handler.sendEmptyMessage(1048577);
}
}
@Override
public void onClick(View view) {
int id = view.getId();
if (id == R.id.btn_floatingaction) {
if (System.currentTimeMillis() - this.currentMills < 500) {
return;
}
this.currentMills = System.currentTimeMillis();
Activity activity2 = this.mAct;
if (activity2 != null) {
if (!this.mIsDataReceveEnd) {
MyToast.showToast(activity2, getString(R.string.data_get_wait));
return;
}
this.mMyCamera.stopPlaybackNew();
EventBus.getDefault().post(new MsyIsStop(true));
Intent intent = new Intent(this.mAct, (Class<?>) SearchSDCardVideoActivity.class);
intent.putExtra(HiDataValue.EXTRAS_KEY_UID, this.mMyCamera.getUid());
startActivityForResult(intent, 1);
this.mAct.overridePendingTransition(R.anim.in_from_right, R.anim.out_to_left);
return;
}
return;
}
if (id != R.id.ll_sort) {
return;
}
if (this.mIsDataReceveEnd) {
TextView textView = this.tv_sort;
if (textView == null || this.iv_arrow == null) {
return;
}
textView.setText(getString(this.mIsDown ? R.string.asce : R.string.desc));
this.iv_arrow.animate().rotation(this.mIsDown ? 180.0f : 0.0f).setDuration(400L).start();
Collections.reverse(this.file_list);
this.adapter.setClickItemPosition(-10);
this.adapter.notifyDataSetChanged();
this.mIsDown = !this.mIsDown;
return;
}
Activity activity3 = this.mAct;
if (activity3 != null) {
MyToast.showToast(activity3, getString(R.string.data_get_wait));
}
}
@Override
public void onActivityResult(int i, int i2, Intent intent) {
super.onActivityResult(i, i2, intent);
if (i2 == -1) {
this.tv_sort.setText(getString(R.string.desc));
this.mIsDown = true;
this.iv_arrow.animate().rotation(0.0f).setDuration(0L).start();
Bundle bundleExtra = intent.getBundleExtra("data");
long j = bundleExtra.getLong("START TIME");
long j2 = bundleExtra.getLong("END TIME");
this.mType = intent.getIntExtra("type", 5);
this.file_list.clear();
this.adapter.setClickItemPosition(-10);
this.adapter.notifyDataSetChanged();
MyCamera myCamera = this.mMyCamera;
if (myCamera != null) {
this.mIsDataReceveEnd = false;
if (myCamera.appGetCommandFunction(HiChipDefines.HI_P2P_PB_QUERY_START_NODST)) {
this.mMyCamera.sendIOCtrl(HiChipDefines.HI_P2P_PB_QUERY_START_NODST, HiChipDefines.HI_P2P_S_PB_LIST_REQ.parseContent(0, j, j2, (byte) 0, 0));
} else if (this.mMyCamera.appGetCommandFunction(HiChipDefines.HI_P2P_PB_QUERY_START_NEW)) {
this.mMyCamera.sendIOCtrl(HiChipDefines.HI_P2P_PB_QUERY_START_NEW, HiChipDefines.HI_P2P_S_PB_LIST_REQ.parseContent(0, j, j2, (byte) 0, 1));
} else if (this.mMyCamera.appGetCommandFunction(HiChipDefines.HI_P2P_PB_QUERY_START_EXT)) {
this.mMyCamera.sendIOCtrl(HiChipDefines.HI_P2P_PB_QUERY_START_EXT, HiChipDefines.HI_P2P_S_PB_LIST_REQ.parseContent(0, j, j2, (byte) 0, 1));
} else {
this.mMyCamera.sendIOCtrl(HiChipDefines.HI_P2P_PB_QUERY_START, HiChipDefines.HI_P2P_S_PB_LIST_REQ.parseContent(0, j, j2, (byte) 0, 1));
}
}
this.list_video_online.setVisibility(0);
this.tv_nothing.setVisibility(8);
if (this.list_video_online.getHeaderViewsCount() == 0) {
this.list_video_online.addHeaderView(this.searchTimeView);
}
if (this.list_video_online.getFooterViewsCount() == 0) {
this.list_video_online.addFooterView(this.loadingView);
}
((TextView) this.searchTimeView.findViewById(R.id.txtSearchTimeDuration)).setText(HiTools.sdfTimeSec(j) + " - " + HiTools.sdfTimeSec(j2));
this.mMyCamera.registerIOSessionListener(this);
}
}
@Override
public void onItemClick(AdapterView<?> adapterView, View view, final int i, long j) {
if (System.currentTimeMillis() - this.currentMills < 500) {
return;
}
this.currentMills = System.currentTimeMillis();
int i2 = i - 1;
if (i2 >= 0) {
this.adapter.setClickItemPosition(i2);
this.adapter.notifyDataSetChanged();
}
if (HiTools.isCustomFastClick(1000)) {
return;
}
this.list_video_online.postDelayed(new Runnable() {
@Override
public final void run() {
FilePlaybackFragment.this.lambda$onItemClick$0$FilePlaybackFragment(i);
}
}, 150L);
}
public void lambda$onItemClick$0$FilePlaybackFragment(int i) {
Activity activity2;
final int headerViewsCount = i - this.list_video_online.getHeaderViewsCount();
if (headerViewsCount >= 0 && (activity2 = this.mAct) != null) {
View inflate = View.inflate(activity2, R.layout.popview_video_online, null);
final PopupWindow popupWindow = new PopupWindow(inflate);
popupWindow.setBackgroundDrawable(new ColorDrawable(0));
popupWindow.setWidth(-1);
popupWindow.setHeight(-1);
popupWindow.setFocusable(true);
popupWindow.showAtLocation(inflate, 17, 0, 0);
this.evt = this.file_list.get(headerViewsCount);
TextView textView = (TextView) inflate.findViewById(R.id.pup_vo_item_tv_state);
String[] stringArray = getResources().getStringArray(R.array.online_recording_type);
if (this.evt.EventType <= 3 && this.evt.EventType >= 0) {
textView.setText(stringArray[this.evt.EventType]);
}
TextView textView2 = (TextView) inflate.findViewById(R.id.pup_vo_item_tv_time);
String[] split = this.evt.sStartTime.toString().split(" ");
textView2.setText(split[0] + " " + split[1] + " - " + this.evt.sEndTime.toString().split(" ")[1]);
((TextView) inflate.findViewById(R.id.tv_play_video_online)).setOnClickListener(new View.OnClickListener() {
@Override
public final void onClick(View view) {
FilePlaybackFragment.this.lambda$popupMethod$2$FilePlaybackFragment(popupWindow, headerViewsCount, view);
}
});
((TextView) inflate.findViewById(R.id.tv_downlinad_video_online)).setOnClickListener(new View.OnClickListener() {
@Override
public final void onClick(View view) {
FilePlaybackFragment.this.lambda$popupMethod$3$FilePlaybackFragment(popupWindow, headerViewsCount, view);
}
});
((TextView) inflate.findViewById(R.id.tv_downlinad_video_cancel)).setOnClickListener(new View.OnClickListener() {
@Override
public final void onClick(View view) {
popupWindow.dismiss();
}
});
}
}
public void lambda$popupMethod$2$FilePlaybackFragment(PopupWindow popupWindow, final int i, View view) {
popupWindow.dismiss();
MyCamera myCamera = this.mMyCamera;
if (myCamera == null) {
return;
}
myCamera.stopPlaybackNew();
EventBus.getDefault().post(new MsyIsStop(true));
this.list_video_online.postDelayed(new Runnable() {
@Override
public final void run() {
FilePlaybackFragment.this.lambda$popupMethod$1$FilePlaybackFragment(i);
}
}, 100L);
}
public void lambda$popupMethod$3$FilePlaybackFragment(PopupWindow popupWindow, int i, View view) {
popupWindow.dismiss();
if (this.mAct == null || HiTools.HiPermission(getActivity(), getActivity(), 1, 10046)) {
return;
}
downloadRecording(i, this.evt);
}
public void lambda$popupMethod$1$FilePlaybackFragment(int i) {
List<ConstantCommand.HI_P2P_FILE_INFO> list;
if (this.mMyCamera == null || (list = this.file_list) == null || list.size() == 0) {
return;
}
ConstantCommand.HI_P2P_FILE_INFO hi_p2p_file_info = this.file_list.get(i);
Bundle bundle = new Bundle();
bundle.putString(HiDataValue.EXTRAS_KEY_UID, this.mMyCamera.getUid());
bundle.putByteArray("st", hi_p2p_file_info.sStartTime.parseContent());
long timeInMillis2 = hi_p2p_file_info.sStartTime.getTimeInMillis2();
long timeInMillis22 = hi_p2p_file_info.sEndTime.getTimeInMillis2();
bundle.putLong("VIDEO START TIME", timeInMillis2);
bundle.putLong("VIDEO END TIME", timeInMillis22);
String[] split = hi_p2p_file_info.sEndTime.toString().split(" ");
String[] split2 = hi_p2p_file_info.sStartTime.toString().split(" ");
bundle.putString("title", split2[0] + " " + split2[1] + Constants.ACCEPT_TIME_SEPARATOR_SERVER + split[1]);
Intent intent = new Intent();
intent.putExtras(bundle);
if (this.mMyCamera.isWallMounted) {
intent.setClass(this.mAct, WallMountedOnlineActivity.class);
startActivity(intent);
return;
}
if (this.mMyCamera.isFishEye()) {
intent.setClass(this.mAct, FishPlaybackOnlineActivity.class);
} else if (!this.mMyCamera.getdevDual()) {
intent.setClass(this.mAct, PlaybackOnlineActivity.class);
} else if (this.mMyCamera.getIs_ThreeEyes()) {
intent.setClass(this.mAct, PlaybackOnlineDualActivity_ThreeEyes.class);
} else {
intent.setClass(this.mAct, PlaybackOnlineDualActivity.class);
}
startActivity(intent);
EventBus.getDefault().post(new FilePlaybackModel(true));
}
private void downloadRecording(int i, final ConstantCommand.HI_P2P_FILE_INFO hi_p2p_file_info) {
if (HiTools.isSDCardValid()) {
File file = new File(HiDataValue.getPathCameraVideoOnLineDownLoad(this.mMyCamera.getUid(), this.mAct));
if (!file.exists()) {
file.mkdirs();
}
this.download_path = file.getAbsoluteFile() + "/";
this.fileName = splitFileName(hi_p2p_file_info.sStartTime.toString());
HiLogcatUtil.d("####### 11111" + this.fileName);
File file2 = new File(this.download_path + this.fileName + ".avi");
File file3 = new File(this.download_path + this.fileName + ".mp4");
File file4 = new File(this.download_path + this.fileName + ".h264");
File file5 = new File(this.download_path + this.fileName + ".h265");
if (file2.exists() || file3.exists() || file4.exists() || file5.exists()) {
View inflate = View.inflate(this.mAct, R.layout.popuwindow_aleary_down, null);
final PopupWindow popupWindow = new PopupWindow(inflate);
popupWindow.setBackgroundDrawable(new ColorDrawable(0));
popupWindow.setFocusable(true);
popupWindow.setWidth(-1);
popupWindow.setHeight(-1);
popupWindow.showAtLocation(inflate, 17, 0, 0);
((TextView) inflate.findViewById(R.id.item_tv_know)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
popupWindow.dismiss();
}
});
return;
}
showLoadDialog(getString(R.string.tips_loading) + "...", false, false);
this.mMyCamera.stopPlaybackNew();
new Thread() {
@Override
public void run() {
FilePlaybackFragment.this.mMyCamera.startDownloadRecording2(hi_p2p_file_info.sStartTime, FilePlaybackFragment.this.download_path, FilePlaybackFragment.this.fileName, 2);
}
}.start();
EventBus.getDefault().post(new MsyIsStop(true));
return;
}
Toast.makeText(this.mAct, getText(R.string.tips_no_sdcard).toString(), 0).show();
}
private String splitFileName(String str) {
long j;
try {
j = new SimpleDateFormat(TimeUtil.FORMAT_DATE_TIME_FULL, Locale.getDefault()).parse(str).getTime();
} catch (ParseException e) {
e.printStackTrace();
j = 0;
}
return new SimpleDateFormat(TimeUtil.FORMAT_DATE_TIME_NEW2, Locale.getDefault()).format(Long.valueOf(j));
}
@Override
public void receiveSessionState(HiCamera hiCamera, int i) {
Message obtainMessage = this.handler.obtainMessage();
obtainMessage.what = HiDataValue.HANDLE_MESSAGE_SESSION_STATE;
obtainMessage.arg1 = i;
obtainMessage.obj = hiCamera;
this.handler.sendMessage(obtainMessage);
}
@Override
public void receiveIOCtrlData(HiCamera hiCamera, int i, byte[] bArr, int i2) {
Bundle bundle = new Bundle();
bundle.putByteArray("data", bArr);
Message obtainMessage = this.handler.obtainMessage();
obtainMessage.what = HiDataValue.HANDLE_MESSAGE_RECEIVE_IOCTRL;
obtainMessage.obj = hiCamera;
obtainMessage.arg1 = i;
obtainMessage.arg2 = i2;
obtainMessage.setData(bundle);
this.handler.sendMessage(obtainMessage);
}
@Override
public void callbackDownloadState(HiCamera hiCamera, int i, int i2, int i3, String str) {
if (hiCamera != this.mMyCamera) {
return;
}
Bundle bundle = new Bundle();
bundle.putLong("total", i);
bundle.putLong("curSize", i2);
bundle.putString(ClientCookie.PATH_ATTR, str);
Message obtainMessage = this.handler.obtainMessage();
obtainMessage.what = HiDataValue.HANDLE_MESSAGE_DOWNLOAD_STATE;
obtainMessage.arg1 = i3;
obtainMessage.setData(bundle);
this.handler.sendMessage(obtainMessage);
}
public void handNETWORK_CHANGED() {
if (this.isDownloading) {
this.isDownloading = false;
MyCamera myCamera = this.mMyCamera;
if (myCamera != null) {
myCamera.stopDownloadRecording();
if (!TextUtils.isEmpty(this.path)) {
File file = new File(this.path);
if (file.isFile() && file.exists()) {
file.delete();
}
}
}
MyToast.showToast(this.mAct, getString(R.string.tips_network_disconnect));
}
}
public void handDownLoad(Message message) {
float f;
Bundle data = message.getData();
int i = message.arg1;
if (i == -3) {
HiLogcatUtil.e("###### filePlaybackFragment DOWNLOAD_ONLINE_STATE_ERROR #########");
MyCamera myCamera = this.mMyCamera;
if (myCamera != null) {
myCamera.stopDownloadRecording();
this.mMyCamera.setReconnectTimes(10);
}
if (getActivity() != null) {
Toast.makeText(getActivity(), getString(R.string.play_4k_sd_error), 1).show();
}
dismissLoadDialog();
Activity activity2 = this.mAct;
if (activity2 != null) {
activity2.finish();
return;
}
return;
}
if (i == 0) {
Log.i("tedI", "--下载开始 DOWNLOAD_STATE_START--");
dismissLoadDialog();
showPopPupProgress();
this.isDownloading = true;
this.path = data.getString(ClientCookie.PATH_ATTR);
return;
}
if (i == 1) {
Log.i("tedI", "--下载中 DOWNLOAD_STATE_DOWNLOADING--");
if (this.isDownloading) {
long j = data.getLong("total");
if (j == 0) {
f = (float) ((data.getLong("curSize") * 100) / 1048576);
} else {
f = (float) ((data.getLong("curSize") * 100) / j);
}
if (f >= 100.0f) {
f = 99.0f;
}
int i2 = (int) f;
CircleProgressBar circleProgressBar = this.circleprogressbar;
if (circleProgressBar != null) {
circleProgressBar.setProgress(i2);
return;
}
return;
}
return;
}
if (i != 2) {
if (i == 3) {
MyToast.showToast(this.mAct, getString(R.string.tips_wifi_connect_failed));
dismissLoadDialog();
return;
}
if (i != 4) {
return;
}
MyCamera myCamera2 = this.mMyCamera;
if (myCamera2 != null && this.isDownloading) {
myCamera2.stopDownloadRecording();
this.isDownloading = false;
this.mMyCamera.disconnect(1);
this.mMyCamera.connect();
if (!TextUtils.isEmpty(this.path)) {
File file = new File(this.path);
if (file.isFile() && file.exists()) {
file.delete();
}
}
}
dismissLoadDialog();
return;
}
Log.i("tedI", "--下载中 DOWNLOAD_STATE_END--");
ConstantCommand.HI_P2P_FILE_INFO hi_p2p_file_info = this.evt;
if (hi_p2p_file_info != null) {
SharePreUtils.putInt(HiDataValue.CACHE, this.mAct, this.fileName, hi_p2p_file_info.EventType);
}
CircleProgressBar circleProgressBar2 = this.circleprogressbar;
if (circleProgressBar2 != null) {
circleProgressBar2.setProgress(100);
}
this.isDownloading = false;
TextView textView = this.tv_cancel_downloading_video;
if (textView != null) {
textView.setText(R.string.continue_down);
}
TextView textView2 = this.tv_goto_downloading_video;
if (textView2 != null) {
textView2.setVisibility(0);
}
if (this.popu_tips_down != null && isAdded()) {
this.popu_tips_down.setText(getString(R.string.download_done));
}
CircleProgressBar circleProgressBar3 = this.circleprogressbar;
if (circleProgressBar3 != null) {
circleProgressBar3.setVisibility(8);
}
TextView textView3 = this.tv_one;
if (textView3 != null) {
textView3.setVisibility(0);
}
TextView textView4 = this.tv_two;
if (textView4 != null) {
textView4.setVisibility(0);
}
ObjectAnimator ofFloat = ObjectAnimator.ofFloat(this.tv_one, "Alpha", 0.0f, 1.0f);
ofFloat.setDuration(300L);
ofFloat.start();
ObjectAnimator ofFloat2 = ObjectAnimator.ofFloat(this.tv_two, "Alpha", 0.0f, 1.0f);
ofFloat2.setDuration(300L);
ofFloat2.start();
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
this.mAct = (Activity) context;
}
private void showPopPupProgress() {
Activity activity2 = this.mAct;
if (activity2 == null) {
return;
}
View inflate = LayoutInflater.from(activity2).inflate(R.layout.pup_loading_video, (ViewGroup) null, false);
this.downloadPopupWindow = new PopupWindow(inflate);
this.downloadPopupWindow.setBackgroundDrawable(new ColorDrawable(0));
this.downloadPopupWindow.setFocusable(true);
this.downloadPopupWindow.setWidth(-1);
this.downloadPopupWindow.setHeight(-1);
this.circleprogressbar = (CircleProgressBar) inflate.findViewById(R.id.circleprogressbar);
this.popu_tips_down = (TextView) inflate.findViewById(R.id.popu_tips_down);
this.tv_one = (TextView) inflate.findViewById(R.id.tv_one);
this.tv_two = (TextView) inflate.findViewById(R.id.tv_two);
if (this.mAct.isFinishing()) {
return;
}
this.downloadPopupWindow.showAtLocation(inflate, 17, 0, 0);
String[] stringArray = getResources().getStringArray(R.array.online_recording_type);
if (this.evt.EventType <= 3 && this.evt.EventType >= 0) {
this.popu_tips_down.setText(stringArray[this.evt.EventType]);
}
this.downloadPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
@Override
public void onDismiss() {
FilePlaybackFragment.this.isDownloading = false;
if (FilePlaybackFragment.this.mMyCamera != null) {
FilePlaybackFragment.this.mMyCamera.stopDownloadRecording();
}
if (!FilePlaybackFragment.this.isClickCancel && !FilePlaybackFragment.this.getString(R.string.continue_down).equals(FilePlaybackFragment.this.tv_cancel_downloading_video.getText().toString().trim())) {
FilePlaybackFragment.this.deleteLoadingFile();
}
FilePlaybackFragment.this.isClickCancel = false;
}
});
TextView textView = (TextView) inflate.findViewById(R.id.tv_cancel_downloading_video);
this.tv_cancel_downloading_video = textView;
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (FilePlaybackFragment.this.getString(R.string.continue_down).equals(FilePlaybackFragment.this.tv_cancel_downloading_video.getText().toString().trim())) {
FilePlaybackFragment.this.isClickCancel = true;
FilePlaybackFragment.this.downloadPopupWindow.dismiss();
} else {
FilePlaybackFragment.this.isClickCancel = true;
FilePlaybackFragment.this.downloadPopupWindow.dismiss();
FilePlaybackFragment.this.deleteLoadingFile();
}
}
});
TextView textView2 = (TextView) inflate.findViewById(R.id.tv_goto_downloading_video);
this.tv_goto_downloading_video = textView2;
textView2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
FilePlaybackFragment.this.isClickCancel = true;
FilePlaybackFragment.this.downloadPopupWindow.dismiss();
FilePlaybackFragment.this.mMyCamera.stopPlaybackNew();
EventBus.getDefault().post(new MsyIsStop(true));
Intent intent = new Intent(FilePlaybackFragment.this.mAct, (Class<?>) LocalFileActivity2.class);
intent.putExtra(HiDataValue.EXTRAS_KEY_UID, FilePlaybackFragment.this.mMyCamera.getUid());
FilePlaybackFragment.this.startActivity(intent);
}
});
}
public void deleteLoadingFile() {
new File(this.path).delete();
}
private void registerCompent() {
MyCamera myCamera = this.mMyCamera;
if (myCamera != null) {
myCamera.registerIOSessionListener(this);
this.mMyCamera.registerDownloadListener(this);
}
IntentFilter intentFilter = new IntentFilter("android.net.conn.CONNECTIVITY_CHANGE");
ConnectionChangeReceiver connectionChangeReceiver = new ConnectionChangeReceiver();
this.myReceiver = connectionChangeReceiver;
this.mAct.registerReceiver(connectionChangeReceiver, intentFilter);
}
private void unregisterCompent() {
MyCamera myCamera = this.mMyCamera;
if (myCamera != null) {
myCamera.unregisterIOSessionListener(this);
this.mMyCamera.unregisterDownloadListener(this);
}
ConnectionChangeReceiver connectionChangeReceiver = this.myReceiver;
if (connectionChangeReceiver != null) {
try {
this.mAct.unregisterReceiver(connectionChangeReceiver);
} catch (Exception e) {
e.printStackTrace();
}
}
}
@Override
public void onResume() {
Activity activity2;
super.onResume();
registerCompent();
if (this.mMyCamera != null || (activity2 = this.mAct) == null) {
return;
}
activity2.finish();
}
@Override
public void setUserVisibleHint(boolean z) {
super.setUserVisibleHint(z);
this.isVisibleToUser = z;
}
@Override
public void onPause() {
PopupWindow popupWindow;
super.onPause();
if (this.mIsDataReceveEnd) {
unregisterCompent();
}
if (this.isDownloading && (popupWindow = this.downloadPopupWindow) != null && popupWindow.isShowing()) {
this.downloadPopupWindow.dismiss();
deleteLoadingFile();
}
}
@Override
public void onDestroy() {
super.onDestroy();
this.isDownloading = false;
Handler handler = this.handler;
if (handler != null) {
handler.removeCallbacksAndMessages(null);
}
List<ConstantCommand.HI_P2P_FILE_INFO> list = this.file_list;
if (list != null && list.size() > 0) {
this.file_list.clear();
}
dismissLoadDialog();
}
public void getStart() {
if (this.mMyCamera.getConnectState() != 4) {
this.list_video_online.setVisibility(8);
this.tv_not_online.setVisibility(0);
} else {
searchVideo();
}
}
@Override
public void onDestroyView() {
super.onDestroyView();
Unbinder unbinder = this.unbinder;
if (unbinder != null) {
unbinder.unbind();
}
}
@Override
public void onRequestPermissionsResult(int i, String[] strArr, int[] iArr) {
super.onRequestPermissionsResult(i, strArr, iArr);
boolean z = true;
HiLogcatUtil.e("" + i);
int length = strArr.length;
for (int i2 = 0; i2 < length; i2++) {
HiLogcatUtil.e(strArr.length + Constants.COLON_SEPARATOR + strArr[i2]);
}
for (int i3 : iArr) {
HiLogcatUtil.e(iArr.length + Constants.COLON_SEPARATOR + i3);
}
if (i == 10046) {
int length2 = iArr.length;
int i4 = 0;
while (true) {
if (i4 >= length2) {
break;
}
if (iArr[i4] != 0) {
z = false;
break;
}
i4++;
}
if (z) {
return;
}
HiTools.Hi_GoToSetting(strArr, getActivity(), getActivity());
}
}
}