package cn.com.magnity.magnitycx; import android.graphics.Bitmap; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.animation.Animation; import android.view.animation.AnimationUtils; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Toast; import cn.com.magnity.magnitycx.FragmentMainTop; import cn.com.magnity.magnitycx.log.Logging; import cn.com.magnity.magnitycx.sdk.DelegateDeviceConnected; import cn.com.magnity.magnitycx.sdk.DeviceController; import cn.com.magnity.magnitycx.sdk.GlobalFunc; import cn.com.magnity.magnitycx.sdk.UsbCommunication; import cn.com.magnity.magnitycx.sdk.UsbConnection; import cn.com.magnity.magnitycx.sdk.VisibleCamera; import com.baidu.mobstat.StatService; import com.github.lzyzsd.circleprogress.DonutProgress; import java.io.File; import java.io.FileOutputStream; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; /* loaded from: classes.dex */ public class FragmentMainCenter extends Fragment implements DelegateDeviceConnected, FragmentMainTop.DelegateDisplayModeChanged, UsbCommunication.IProgressCallback { public static ImageViewerVisible imgViewerVisible_; private Bitmap bmpCaptured_; private ImageView imgViewAnim_; private ImageViewer imgViewer_; private LinearLayout layout_; private DonutProgress progBarLoading_; private String recordingFileName_ = ""; private TextView tvTipInfo_; public interface DelegateCapture { Bitmap onCapture(); void onCaptureFinished(String str); boolean onStartRecording(String str); void onStopRecording(); } @Override // android.support.v4.app.Fragment public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); } @Override // android.support.v4.app.Fragment @Nullable public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View rootViewer = inflater.inflate(R.layout.fragment_main_center, container, false); this.imgViewAnim_ = (ImageView) rootViewer.findViewById(R.id.id_imgViewAnim); this.imgViewer_ = (ImageViewer) rootViewer.findViewById(R.id.id_imgviewer); this.progBarLoading_ = (DonutProgress) rootViewer.findViewById(R.id.id_loading); this.tvTipInfo_ = (TextView) rootViewer.findViewById(R.id.id_text); imgViewerVisible_ = (ImageViewerVisible) rootViewer.findViewById(R.id.id_imgViewerVisible); this.layout_ = (LinearLayout) rootViewer.findViewById(R.id.id_layoutDevUnconn); onDeviceDisconnected(); return rootViewer; } @Override // android.support.v4.app.Fragment public void onDestroyView() { super.onDestroyView(); } @Override // android.support.v4.app.Fragment public void onDestroy() { super.onDestroy(); } @Override // cn.com.magnity.magnitycx.sdk.DelegateDeviceConnected public void onDeviceConnected(UsbCommunication comm) { if (this.imgViewer_ != null) { this.imgViewer_.setVisibility(0); } if (imgViewerVisible_ != null) { boolean hasPermission = VisibleCamera.isCameraPermission(); if (MagApplication.magParameter.dispMode == 1) { imgViewerVisible_.setVisibility(4); } else if (hasPermission) { imgViewerVisible_.setVisibility(0); } } if (this.layout_ != null) { this.layout_.setVisibility(4); } if (comm != null && this.imgViewer_ != null) { this.imgViewer_.initData(MagApplication.magParameter.basePara1.fpaWidth, MagApplication.magParameter.basePara1.fpaHeight); comm.setImageViewer(this.imgViewer_); } } public void startLoading() { this.layout_.setVisibility(4); this.progBarLoading_.setVisibility(0); this.progBarLoading_.setProgress(0.0f); this.tvTipInfo_.setVisibility(0); this.tvTipInfo_.setText(""); } @Override // android.support.v4.app.Fragment public void onResume() { super.onResume(); StatService.onPageStart(getActivity(), "主页面中"); } @Override // android.support.v4.app.Fragment public void onPause() { super.onPause(); StatService.onPageEnd(getActivity(), "主页面中"); } public void stopLoading(boolean succ) { this.progBarLoading_.setVisibility(8); this.tvTipInfo_.setVisibility(8); if (!succ) { this.layout_.setVisibility(0); } } @Override // cn.com.magnity.magnitycx.sdk.DelegateDeviceConnected public void onDeviceDisconnected() { getResources(); if (this.layout_ != null) { this.layout_.setVisibility(0); } if (this.imgViewAnim_ != null) { this.imgViewAnim_.clearAnimation(); this.imgViewAnim_.invalidate(); this.imgViewAnim_.setVisibility(4); } if (this.imgViewer_ != null) { this.imgViewer_.setVisibility(4); } if (imgViewerVisible_ != null) { imgViewerVisible_.setVisibility(4); } if (this.progBarLoading_ != null) { this.progBarLoading_.setVisibility(8); } if (this.tvTipInfo_ != null) { this.tvTipInfo_.setVisibility(8); } } @Override // cn.com.magnity.magnitycx.sdk.UsbCommunication.IProgressCallback public void progressCancel(int id) { getActivity().setRequestedOrientation(10); switch (id) { case 0: stopLoading(false); UsbConnection.getInstance().notifyObervers(0); break; } Toast.makeText(getContext(), R.string.tipForFail, 1).show(); } @Override // cn.com.magnity.magnitycx.sdk.UsbCommunication.IProgressCallback public void progressFinished(int id) { switch (id) { case 0: stopLoading(true); UsbConnection.getInstance().notifyObervers(1); getActivity().setRequestedOrientation(10); break; case 1: stopLoading(true); getActivity().setRequestedOrientation(10); break; } } @Override // cn.com.magnity.magnitycx.sdk.UsbCommunication.IProgressCallback public void progressChanged(int id, int progress) { switch (id) { case 0: case 1: this.progBarLoading_.setProgress(progress); break; } } @Override // cn.com.magnity.magnitycx.sdk.UsbCommunication.IProgressCallback public void progressStart(int id) { getActivity().setRequestedOrientation(14); switch (id) { case 0: startLoading(); this.tvTipInfo_.setText(R.string.tipForNewMobile); break; case 1: startLoading(); this.tvTipInfo_.setText(R.string.tipForDeviceInit); break; } } @Override // cn.com.magnity.magnitycx.FragmentMainTop.DelegateDisplayModeChanged public boolean onDisplayModeChanged(int oldMode, int newMode) { boolean hasPermission = VisibleCamera.isCameraPermission(); if (newMode == 0 && hasPermission) { imgViewerVisible_.setVisibility(0); } else { imgViewerVisible_.setVisibility(8); if (!hasPermission) { return false; } } return true; } public ImageViewer getImageViewer() { return this.imgViewer_; } public boolean startRecording() { this.imgViewAnim_.clearAnimation(); this.imgViewAnim_.invalidate(); this.imgViewAnim_.setVisibility(4); if (!(this.imgViewer_ instanceof DelegateCapture) || this.imgViewer_.getVisibility() != 0) { return false; } String type = ""; switch (MagApplication.magParameter.basePara1.devType) { case 0: type = getResources().getString(R.string.c1); break; case 1: type = getResources().getString(R.string.c3); break; case 2: type = getResources().getString(R.string.c3p); break; case 3: type = getResources().getString(R.string.core160); break; case 5: type = getResources().getString(R.string.c1pro); break; case 6: type = getResources().getString(R.string.c1prolite); break; } this.recordingFileName_ = MagApplication.magParameter.mediaDir + File.separator + type + new SimpleDateFormat("yyyyMMddHHmmssSSS", Locale.US).format(new Date()) + ".mp4"; if (!this.imgViewer_.onStartRecording(this.recordingFileName_)) { Logging.warn("Fail to start recording"); return false; } return true; } public void stopRecording() { this.imgViewer_.onStopRecording(); FragmentMainBottom fragmentMainBottom = ((MainActivity) getActivity()).getFragmentMainBottom(); if (fragmentMainBottom instanceof DelegateCapture) { fragmentMainBottom.onCaptureFinished(this.recordingFileName_); GlobalFunc.notifyMediaSync(getContext(), new File(this.recordingFileName_)); } this.recordingFileName_ = ""; } public boolean capturePhoto() { if (MagApplication.magParameter.mediaDir.isEmpty()) { Logging.error("Media not mounted"); return false; } String type = ""; switch (MagApplication.magParameter.basePara1.devType) { case 0: type = getResources().getString(R.string.c1); break; case 1: type = getResources().getString(R.string.c3); break; case 2: type = getResources().getString(R.string.c3p); break; case 3: type = getResources().getString(R.string.core160); break; case 5: type = getResources().getString(R.string.c1pro); break; case 6: type = getResources().getString(R.string.c1prolite); break; } String pathName = MagApplication.magParameter.mediaDir + File.separator + type + new SimpleDateFormat("yyyyMMddHHmmssSSS", Locale.US).format(new Date()) + ".jpg"; if ((this.imgViewer_ instanceof DelegateCapture) && this.imgViewer_.getVisibility() == 0) { this.bmpCaptured_ = this.imgViewer_.onCapture(); if (MagApplication.magParameter.basePara1.devType == 2) { DeviceController.Lock(); DeviceController.saveDDT(pathName.replace(".jpg", ".ddt")); DeviceController.Unlock(); } } if (this.bmpCaptured_ == null) { Logging.error("Capture photo fail because of ir bmp is null"); return false; } try { FileOutputStream out = new FileOutputStream(pathName); this.bmpCaptured_.compress(Bitmap.CompressFormat.JPEG, 100, out); out.close(); GlobalFunc.notifyMediaSync(getContext(), new File(pathName)); FragmentMainBottom fragmentMainBottom = ((MainActivity) getActivity()).getFragmentMainBottom(); if (fragmentMainBottom instanceof DelegateCapture) { fragmentMainBottom.onCaptureFinished(pathName); } Animation anim = AnimationUtils.loadAnimation(getActivity(), R.anim.photo_capture); anim.setFillAfter(true); anim.setAnimationListener(new Animation.AnimationListener() { // from class: cn.com.magnity.magnitycx.FragmentMainCenter.1 @Override // android.view.animation.Animation.AnimationListener public void onAnimationStart(Animation animation) { } @Override // android.view.animation.Animation.AnimationListener public void onAnimationEnd(Animation animation) { FragmentMainCenter.this.imgViewAnim_.clearAnimation(); FragmentMainCenter.this.imgViewAnim_.invalidate(); } @Override // android.view.animation.Animation.AnimationListener public void onAnimationRepeat(Animation animation) { } }); this.imgViewAnim_.startAnimation(anim); return true; } catch (Exception e) { Logging.error("Capture photo fail (" + e.getMessage() + ")"); return false; } } }