package cn.com.magnity.magnitycx; import android.animation.ObjectAnimator; import android.content.Intent; import android.graphics.Bitmap; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.util.DisplayMetrics; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageButton; import android.widget.ImageView; import android.widget.RelativeLayout; import android.widget.TextView; import cn.com.magnity.magnitycx.FragmentMainCenter; import cn.com.magnity.magnitycx.MainActivity; import cn.com.magnity.magnitycx.sdk.BitmapUtilities; 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.MagParameter; import cn.com.magnity.magnitycx.sdk.SharedPreferencesManager; import cn.com.magnity.magnitycx.sdk.TimerHelper; import cn.com.magnity.magnitycx.sdk.UsbCommunication; import com.baidu.mobstat.Config; import com.baidu.mobstat.StatService; import java.io.File; import java.util.ArrayList; /* loaded from: classes.dex */ public class FragmentMainBottom extends Fragment implements MainActivity.DelegateFling, DelegateDeviceConnected, FragmentMainCenter.DelegateCapture { static final int PHOTO_MARGIN_MARGIN = 0; private ImageButton btnCapture_; private ImageButton btnPalette_; private Handler handler_; private RelativeLayout layoutSelection_; private MagClickListener magClickListener_; private int modeSelection_; private int screenHeight_; private int screenWidth_; private TimerHelper timerHelper_; private TextView tvPhoto_; private TextView tvRecord_; private ImageButton viewBrowse_; private View viewRecordingPoint_; private ImageView viewSelectPointer_; @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 rootView = inflater.inflate(R.layout.fragment_main_bottom, container, false); init(rootView); return rootView; } @Override // android.support.v4.app.Fragment public void onResume() { ArrayList fileNames = new ArrayList<>(); GlobalFunc globalFunc = MagApplication.globalFunc; GlobalFunc.updateFileList(fileNames); if (fileNames.size() == 0) { this.viewBrowse_.setScaleType(ImageView.ScaleType.CENTER); this.viewBrowse_.setImageResource(R.mipmap.empty_photo); } else { String pathName = MagApplication.magParameter.mediaDir + File.separator + fileNames.get(0); int w = getResources().getDimensionPixelSize(R.dimen.mainBottomButtonSize); BitmapUtilities.getBitmapThumbnail(pathName, w, w); this.viewBrowse_.setScaleType(ImageView.ScaleType.CENTER_CROP); this.viewBrowse_.setImageBitmap(BitmapUtilities.getBitmapThumbnail(pathName, getResources().getDimensionPixelSize(R.dimen.mainBottomButtonSize), getResources().getDimensionPixelSize(R.dimen.mainBottomButtonSize))); } super.onResume(); } @Override // android.support.v4.app.Fragment public void onStop() { if (DeviceController.isRecording()) { this.btnCapture_.performClick(); } super.onStop(); } private void init(View v) { this.magClickListener_ = new MagClickListener(); this.tvPhoto_ = (TextView) v.findViewById(R.id.id_photo); this.tvRecord_ = (TextView) v.findViewById(R.id.id_record); this.btnCapture_ = (ImageButton) v.findViewById(R.id.id_capture); this.btnPalette_ = (ImageButton) v.findViewById(R.id.id_palette); this.viewBrowse_ = (ImageButton) v.findViewById(R.id.id_browse); this.viewSelectPointer_ = (ImageView) v.findViewById(R.id.id_selector_point); this.layoutSelection_ = (RelativeLayout) v.findViewById(R.id.id_selection); this.viewRecordingPoint_ = v.findViewById(R.id.id_recording_point); this.tvPhoto_.setOnClickListener(this.magClickListener_); this.tvRecord_.setOnClickListener(this.magClickListener_); this.btnCapture_.setOnClickListener(this.magClickListener_); this.btnPalette_.setOnClickListener(this.magClickListener_); this.viewBrowse_.setOnClickListener(this.magClickListener_); DisplayMetrics outMetrics = new DisplayMetrics(); getActivity().getWindow().getWindowManager().getDefaultDisplay().getMetrics(outMetrics); this.screenWidth_ = outMetrics.widthPixels; this.screenHeight_ = outMetrics.heightPixels; initModeSelection(); onDeviceDisconnected(); } public void initModeSelection() { this.modeSelection_ = SharedPreferencesManager.getInt("modeSelection", 0); int orientation = getActivity().getResources().getConfiguration().orientation; RelativeLayout.LayoutParams layoutPhoto = (RelativeLayout.LayoutParams) this.tvPhoto_.getLayoutParams(); RelativeLayout.LayoutParams layoutRecord = (RelativeLayout.LayoutParams) this.tvRecord_.getLayoutParams(); if (layoutPhoto.getRules()[13] != 0) { layoutPhoto.addRule(13, 0); } if (layoutPhoto.getRules()[0] != 0) { layoutPhoto.addRule(0, 0); } if (layoutPhoto.getRules()[3] != 0) { layoutPhoto.addRule(3, 0); } if (layoutRecord.getRules()[13] != 0) { layoutRecord.addRule(13, 0); } if (layoutRecord.getRules()[1] != 0) { layoutRecord.addRule(1, 0); } if (layoutRecord.getRules()[2] != 0) { layoutRecord.addRule(2, 0); } if (this.modeSelection_ == 0) { this.btnCapture_.setImageResource(R.drawable.button_capture_photo_select); } else { this.btnCapture_.setImageResource(R.mipmap.recording_finished); } if (orientation == 1) { if (this.modeSelection_ == 0) { if (layoutPhoto.getRules()[13] == 0) { layoutPhoto.addRule(13); } if (layoutRecord.getRules()[1] == 0) { layoutRecord.addRule(1, R.id.id_photo); } this.tvPhoto_.setTextColor(getResources().getColor(R.color.selectedModeText)); this.tvRecord_.setTextColor(getResources().getColor(R.color.textColor)); return; } if (this.modeSelection_ == 1) { if (layoutRecord.getRules()[13] == 0) { layoutRecord.addRule(13); } if (layoutPhoto.getRules()[0] == 0) { layoutPhoto.addRule(0, R.id.id_record); } this.tvPhoto_.setTextColor(getResources().getColor(R.color.textColor)); this.tvRecord_.setTextColor(getResources().getColor(R.color.selectedModeText)); return; } return; } if (this.modeSelection_ == 0) { if (layoutPhoto.getRules()[13] == 0) { layoutPhoto.addRule(13); } if (layoutRecord.getRules()[2] == 0) { layoutRecord.addRule(2, R.id.id_photo); } this.tvPhoto_.setTextColor(getResources().getColor(R.color.selectedModeText)); this.tvRecord_.setTextColor(getResources().getColor(R.color.textColor)); return; } if (this.modeSelection_ == 1) { if (layoutRecord.getRules()[13] == 0) { layoutRecord.addRule(13); } if (layoutPhoto.getRules()[3] == 0) { layoutPhoto.addRule(3, R.id.id_record); } this.tvPhoto_.setTextColor(getResources().getColor(R.color.textColor)); this.tvRecord_.setTextColor(getResources().getColor(R.color.selectedModeText)); } } @Override // cn.com.magnity.magnitycx.sdk.DelegateDeviceConnected public void onDeviceConnected(UsbCommunication usbComm) { if (this.btnPalette_ != null) { this.btnPalette_.setVisibility(0); } if (this.btnCapture_ != null) { this.btnCapture_.setVisibility(0); } if (this.viewSelectPointer_ != null) { this.viewSelectPointer_.setVisibility(0); } if (this.layoutSelection_ != null) { this.layoutSelection_.setVisibility(0); } } @Override // cn.com.magnity.magnitycx.sdk.DelegateDeviceConnected public void onDeviceDisconnected() { if (DeviceController.isRecording()) { ((MainActivity) getActivity()).getFragmentMainCenter().stopRecording(); updateButtonsWhenRecordingStatusChanged(true); blinkWhenRecordingStatusChanged(false); getActivity().setRequestedOrientation(10); } if (this.btnPalette_ != null) { this.btnPalette_.setVisibility(4); } if (this.btnCapture_ != null) { if (this.modeSelection_ == 0) { this.btnCapture_.setImageResource(R.drawable.button_capture_photo_select); } else { this.btnCapture_.setImageResource(R.mipmap.recording_finished); } this.btnCapture_.setVisibility(4); } if (this.viewSelectPointer_ != null) { this.viewSelectPointer_.setVisibility(8); } if (this.layoutSelection_ != null) { this.layoutSelection_.setVisibility(8); } } @Override // cn.com.magnity.magnitycx.FragmentMainCenter.DelegateCapture public Bitmap onCapture() { return null; } @Override // cn.com.magnity.magnitycx.FragmentMainCenter.DelegateCapture public void onCaptureFinished(String pathName) { this.viewBrowse_.setScaleType(ImageView.ScaleType.CENTER_CROP); this.viewBrowse_.setImageBitmap(BitmapUtilities.getBitmapThumbnail(pathName, getResources().getDimensionPixelSize(R.dimen.mainBottomButtonSize), getResources().getDimensionPixelSize(R.dimen.mainBottomButtonSize))); } @Override // cn.com.magnity.magnitycx.FragmentMainCenter.DelegateCapture public boolean onStartRecording(String pathName) { return false; } @Override // cn.com.magnity.magnitycx.FragmentMainCenter.DelegateCapture public void onStopRecording() { } @Override // cn.com.magnity.magnitycx.MainActivity.DelegateFling public void afterFling(int index) { setNewSelection(index); } void setNewSelection(int index) { String sProperty; if (this.modeSelection_ != index && !DeviceController.isRecording()) { float posPhoto = 0.0f; float posRecord = 0.0f; int orientation = getActivity().getResources().getConfiguration().orientation; if (orientation == 1) { sProperty = "x"; if (index == 0) { posPhoto = (this.screenWidth_ - this.tvPhoto_.getWidth()) / 2; posRecord = posPhoto + 0.0f + this.tvPhoto_.getWidth(); } else if (index == 1) { posRecord = (this.screenWidth_ - this.tvRecord_.getWidth()) / 2; posPhoto = (posRecord - 0.0f) - this.tvPhoto_.getWidth(); } } else { sProperty = Config.EXCEPTION_TYPE; if (index == 0) { posPhoto = (this.screenHeight_ - this.tvPhoto_.getHeight()) / 2; posRecord = (posPhoto - 0.0f) - this.tvRecord_.getHeight(); } else if (index == 1) { posRecord = (this.screenHeight_ - this.tvRecord_.getHeight()) / 2; posPhoto = posRecord + 0.0f + this.tvRecord_.getHeight(); } } ObjectAnimator oaPhoto = ObjectAnimator.ofFloat(this.tvPhoto_, sProperty, posPhoto); oaPhoto.setDuration(300L); ObjectAnimator oaRecord = ObjectAnimator.ofFloat(this.tvRecord_, sProperty, posRecord); oaRecord.setDuration(300L); switch (index) { case 0: oaPhoto.setStartDelay(30L); this.tvPhoto_.setTextColor(getResources().getColor(R.color.selectedModeText)); this.tvRecord_.setTextColor(getResources().getColor(R.color.textColor)); this.btnCapture_.setImageResource(R.drawable.button_capture_photo_select); break; case 1: oaRecord.setStartDelay(30L); this.tvPhoto_.setTextColor(getResources().getColor(R.color.textColor)); this.tvRecord_.setTextColor(getResources().getColor(R.color.selectedModeText)); this.btnCapture_.setImageResource(R.mipmap.recording_finished); break; } oaPhoto.start(); oaRecord.start(); this.modeSelection_ = index; SharedPreferencesManager.putIntWithCommit("modeSelection", this.modeSelection_); } } /* JADX INFO: Access modifiers changed from: private */ public void updateButtonsWhenRecordingStatusChanged(boolean visible) { FragmentMainTop fragmentMainTop = ((MainActivity) getActivity()).getFragmentMainTop(); if (visible) { this.viewSelectPointer_.setVisibility(0); this.viewBrowse_.setVisibility(0); this.layoutSelection_.setVisibility(0); fragmentMainTop.showButtonsWhenRecordingFinish(); return; } this.viewSelectPointer_.setVisibility(8); this.viewBrowse_.setVisibility(4); this.layoutSelection_.setVisibility(8); fragmentMainTop.hideButtonsWhenRecordingStart(); } /* JADX INFO: Access modifiers changed from: private */ public void blinkWhenRecordingStatusChanged(boolean blink) { if (blink) { this.viewRecordingPoint_.setVisibility(0); this.handler_ = new Handler() { // from class: cn.com.magnity.magnitycx.FragmentMainBottom.1 @Override // android.os.Handler public void handleMessage(Message msg) { if (DeviceController.isRecording()) { if (FragmentMainBottom.this.viewRecordingPoint_.getVisibility() == 0) { FragmentMainBottom.this.viewRecordingPoint_.setVisibility(4); } else { FragmentMainBottom.this.viewRecordingPoint_.setVisibility(0); } } } }; this.timerHelper_ = new TimerHelper() { // from class: cn.com.magnity.magnitycx.FragmentMainBottom.2 @Override // cn.com.magnity.magnitycx.sdk.TimerHelper public void run() { FragmentMainBottom.this.handler_.sendEmptyMessage(0); } }; this.timerHelper_.start(0L, 500L); return; } this.timerHelper_.stop(); this.viewRecordingPoint_.setVisibility(4); } private class MagClickListener implements View.OnClickListener { private MagClickListener() { } @Override // android.view.View.OnClickListener public void onClick(View v) { switch (v.getId()) { case R.id.id_photo /* 2131624122 */: FragmentMainBottom.this.setNewSelection(0); break; case R.id.id_record /* 2131624123 */: FragmentMainBottom.this.setNewSelection(1); break; case R.id.id_browse /* 2131624124 */: ArrayList fileNames = new ArrayList<>(); GlobalFunc globalFunc = MagApplication.globalFunc; GlobalFunc.updateFileList(fileNames); if (!fileNames.isEmpty()) { Intent intent = new Intent(FragmentMainBottom.this.getActivity(), (Class) MediaSingleActivity.class); intent.putExtra(MediaSingleActivity.MEDIAWINDOWFLAG, 0); intent.putExtra(MediaSingleActivity.MEDIAINDEX, 0); intent.putStringArrayListExtra(MediaSingleActivity.MEDIANAMELIST, fileNames); FragmentMainBottom.this.startActivity(intent); break; } break; case R.id.id_capture /* 2131624126 */: FragmentMainCenter fragmentMainCenter = ((MainActivity) FragmentMainBottom.this.getActivity()).getFragmentMainCenter(); if (FragmentMainBottom.this.modeSelection_ == 0) { StatService.onEvent(FragmentMainBottom.this.getContext(), MagParameter.EVENT_PHOTO_ID, MagParameter.EVENT_PHOTO); fragmentMainCenter.capturePhoto(); break; } else if (DeviceController.isRecording()) { fragmentMainCenter.stopRecording(); FragmentMainBottom.this.updateButtonsWhenRecordingStatusChanged(true); FragmentMainBottom.this.blinkWhenRecordingStatusChanged(false); FragmentMainBottom.this.btnCapture_.setImageResource(R.mipmap.recording_finished); FragmentMainBottom.this.getActivity().setRequestedOrientation(10); break; } else if (fragmentMainCenter.startRecording()) { StatService.onEvent(FragmentMainBottom.this.getContext(), MagParameter.EVENT_VIDEO_ID, MagParameter.EVENT_VIDEO); FragmentMainBottom.this.updateButtonsWhenRecordingStatusChanged(false); FragmentMainBottom.this.blinkWhenRecordingStatusChanged(true); FragmentMainBottom.this.btnCapture_.setImageResource(R.mipmap.recording_normal); FragmentMainBottom.this.getActivity().setRequestedOrientation(14); break; } break; case R.id.id_palette /* 2131624128 */: DialogFragmentPalette fragmentPalette = new DialogFragmentPalette(); StatService.onEvent(FragmentMainBottom.this.getContext(), MagParameter.EVENT_COLOR_PALETTE_ID, MagParameter.EVENT_COLOR_PALETTE); fragmentPalette.show(FragmentMainBottom.this.getFragmentManager(), "FragmentPalette"); break; } } } }