384 lines
19 KiB
Java
384 lines
19 KiB
Java
package cn.com.magnity.magnitycx;
|
|
|
|
import android.content.Intent;
|
|
import android.graphics.drawable.ColorDrawable;
|
|
import android.os.Bundle;
|
|
import android.support.annotation.Nullable;
|
|
import android.support.v4.app.ActivityCompat;
|
|
import android.support.v4.app.Fragment;
|
|
import android.view.LayoutInflater;
|
|
import android.view.Menu;
|
|
import android.view.MenuItem;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.view.animation.Animation;
|
|
import android.view.animation.AnimationUtils;
|
|
import android.widget.ImageButton;
|
|
import android.widget.ImageView;
|
|
import android.widget.PopupMenu;
|
|
import android.widget.PopupWindow;
|
|
import android.widget.TextView;
|
|
import android.widget.Toast;
|
|
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.MagParameter;
|
|
import cn.com.magnity.magnitycx.sdk.SharedPreferencesManager;
|
|
import cn.com.magnity.magnitycx.sdk.UsbCommunication;
|
|
import com.baidu.mobstat.StatService;
|
|
import java.lang.reflect.Method;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class FragmentMainTop extends Fragment implements DelegateDeviceConnected, PopupMenu.OnMenuItemClickListener, ActivityCompat.OnRequestPermissionsResultCallback {
|
|
private ImageButton btnCross_;
|
|
private ImageButton btnLaserOn_;
|
|
private ImageButton btnMode_;
|
|
private ImageButton btnMore_;
|
|
private ImageButton btnTraceMaxMin_;
|
|
private ImageButton btnZoom_;
|
|
private MainTopClickListener clickListener_;
|
|
private PopupWindow popupWindowMore_;
|
|
private UsbCommunication usbComm_;
|
|
|
|
public interface DelegateDisplayModeChanged {
|
|
boolean onDisplayModeChanged(int i, int i2);
|
|
}
|
|
|
|
@Override // android.support.v4.app.Fragment
|
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
this.clickListener_ = new MainTopClickListener();
|
|
}
|
|
|
|
@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_top, container, false);
|
|
this.btnMode_ = (ImageButton) rootView.findViewById(R.id.id_mode);
|
|
this.btnCross_ = (ImageButton) rootView.findViewById(R.id.id_cross);
|
|
this.btnLaserOn_ = (ImageButton) rootView.findViewById(R.id.id_laser);
|
|
this.btnMore_ = (ImageButton) rootView.findViewById(R.id.id_more);
|
|
this.btnTraceMaxMin_ = (ImageButton) rootView.findViewById(R.id.id_trace_max_min);
|
|
this.btnZoom_ = (ImageButton) rootView.findViewById(R.id.id_zoom);
|
|
this.btnMode_.setOnClickListener(this.clickListener_);
|
|
this.btnCross_.setOnClickListener(this.clickListener_);
|
|
this.btnLaserOn_.setOnClickListener(this.clickListener_);
|
|
this.btnMore_.setOnClickListener(this.clickListener_);
|
|
this.btnTraceMaxMin_.setOnClickListener(this.clickListener_);
|
|
this.btnZoom_.setOnClickListener(this.clickListener_);
|
|
if (MagApplication.magParameter.dispMode == 1) {
|
|
this.btnMode_.setImageResource(R.mipmap.disp_mode_ironly);
|
|
} else {
|
|
this.btnMode_.setImageResource(R.mipmap.disp_mode_pip);
|
|
}
|
|
if (MagApplication.magParameter.isShowCross) {
|
|
this.btnCross_.setImageResource(R.mipmap.center_cross_on);
|
|
} else {
|
|
this.btnCross_.setImageResource(R.mipmap.center_cross_off);
|
|
}
|
|
if (MagApplication.magParameter.isTraceMaxMin) {
|
|
this.btnTraceMaxMin_.setImageResource(R.mipmap.trace_max_min_on);
|
|
} else {
|
|
this.btnTraceMaxMin_.setImageResource(R.mipmap.trace_max_min_off);
|
|
}
|
|
int ratio = MagApplication.magParameter.imageEX;
|
|
if (ratio == 0) {
|
|
this.btnZoom_.setImageResource(R.mipmap.zoom_1x);
|
|
} else if (ratio == 1) {
|
|
this.btnZoom_.setImageResource(R.mipmap.zoom_2x);
|
|
} else if (ratio == 2) {
|
|
this.btnZoom_.setImageResource(R.mipmap.zoom_4x);
|
|
}
|
|
initPopupWindowMore();
|
|
onDeviceDisconnected();
|
|
return rootView;
|
|
}
|
|
|
|
private void initPopupWindowMore() {
|
|
View moreView = LayoutInflater.from(getActivity()).inflate(R.layout.popup_window_more, (ViewGroup) null);
|
|
View viewItem = moreView.findViewById(R.id.id_menu_item_setting);
|
|
viewItem.setOnClickListener(this.clickListener_);
|
|
ImageView viewLogo = (ImageView) viewItem.findViewById(R.id.id_item_menu_logo);
|
|
viewLogo.setImageResource(R.mipmap.settings);
|
|
TextView txtView = (TextView) viewItem.findViewById(R.id.id_item_menu_text);
|
|
txtView.setText(R.string.labelSetting);
|
|
View viewItem2 = moreView.findViewById(R.id.id_menu_item_help);
|
|
viewItem2.setOnClickListener(this.clickListener_);
|
|
ImageView viewLogo2 = (ImageView) viewItem2.findViewById(R.id.id_item_menu_logo);
|
|
viewLogo2.setImageResource(R.mipmap.help);
|
|
TextView txtView2 = (TextView) viewItem2.findViewById(R.id.id_item_menu_text);
|
|
txtView2.setText(R.string.labelHelp);
|
|
this.popupWindowMore_ = new PopupWindow(moreView, -2, -2);
|
|
this.popupWindowMore_.setOutsideTouchable(true);
|
|
this.popupWindowMore_.setFocusable(true);
|
|
this.popupWindowMore_.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.liveBackground)));
|
|
}
|
|
|
|
@Override // cn.com.magnity.magnitycx.sdk.DelegateDeviceConnected
|
|
public void onDeviceConnected(UsbCommunication comm) {
|
|
this.usbComm_ = comm;
|
|
if (this.btnMode_ != null) {
|
|
this.btnMode_.setVisibility(0);
|
|
}
|
|
if (this.btnZoom_ != null) {
|
|
this.btnZoom_.setVisibility(0);
|
|
}
|
|
switch (MagApplication.magParameter.basePara1.devType) {
|
|
case 0:
|
|
case 3:
|
|
case 5:
|
|
case 6:
|
|
if (this.btnCross_ != null) {
|
|
this.btnCross_.setVisibility(0);
|
|
}
|
|
if (this.btnTraceMaxMin_ != null) {
|
|
this.btnTraceMaxMin_.setVisibility(0);
|
|
}
|
|
if (this.btnZoom_ != null) {
|
|
this.btnZoom_.setVisibility(8);
|
|
break;
|
|
}
|
|
break;
|
|
case 1:
|
|
if (this.btnCross_ != null) {
|
|
this.btnCross_.setVisibility(8);
|
|
}
|
|
if (this.btnTraceMaxMin_ != null) {
|
|
this.btnTraceMaxMin_.setVisibility(8);
|
|
}
|
|
if (this.btnLaserOn_ != null) {
|
|
this.btnLaserOn_.setImageResource(R.mipmap.laser_off);
|
|
this.btnLaserOn_.setVisibility(0);
|
|
}
|
|
if (this.btnZoom_ != null) {
|
|
this.btnZoom_.setVisibility(0);
|
|
break;
|
|
}
|
|
break;
|
|
case 2:
|
|
if (this.btnCross_ != null) {
|
|
this.btnCross_.setVisibility(0);
|
|
}
|
|
if (this.btnTraceMaxMin_ != null) {
|
|
this.btnTraceMaxMin_.setVisibility(8);
|
|
}
|
|
if (this.btnLaserOn_ != null) {
|
|
this.btnLaserOn_.setVisibility(0);
|
|
}
|
|
if (this.btnZoom_ != null) {
|
|
this.btnZoom_.setVisibility(0);
|
|
break;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
@Override // cn.com.magnity.magnitycx.sdk.DelegateDeviceConnected
|
|
public void onDeviceDisconnected() {
|
|
this.usbComm_ = null;
|
|
if (this.btnMode_ != null) {
|
|
this.btnMode_.setVisibility(4);
|
|
}
|
|
if (this.btnCross_ != null) {
|
|
this.btnCross_.setVisibility(4);
|
|
}
|
|
if (this.btnTraceMaxMin_ != null) {
|
|
this.btnTraceMaxMin_.setVisibility(8);
|
|
}
|
|
if (this.btnLaserOn_ != null) {
|
|
this.btnLaserOn_.setVisibility(8);
|
|
}
|
|
if (this.btnZoom_ != null) {
|
|
this.btnZoom_.setVisibility(8);
|
|
}
|
|
}
|
|
|
|
public void hideButtonsWhenRecordingStart() {
|
|
this.btnMode_.setVisibility(4);
|
|
this.btnMore_.setVisibility(4);
|
|
}
|
|
|
|
public void showButtonsWhenRecordingFinish() {
|
|
this.btnMode_.setVisibility(0);
|
|
this.btnMore_.setVisibility(0);
|
|
}
|
|
|
|
@Override // android.widget.PopupMenu.OnMenuItemClickListener
|
|
public boolean onMenuItemClick(MenuItem item) {
|
|
return false;
|
|
}
|
|
|
|
private void setIconsVisible(Menu menu, boolean flag) {
|
|
if (menu != null) {
|
|
try {
|
|
Method method = menu.getClass().getDeclaredMethod("setOptionalIconsVisible", Boolean.TYPE);
|
|
if (method != null) {
|
|
method.setAccessible(true);
|
|
method.invoke(menu, Boolean.valueOf(flag));
|
|
}
|
|
} catch (Exception e) {
|
|
}
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public void exchangeLogo(final ImageButton btn, final int resIdOn, final int resIdOff, final boolean on) {
|
|
Animation anim;
|
|
if (getResources().getConfiguration().orientation == 2) {
|
|
anim = AnimationUtils.loadAnimation(getActivity(), R.anim.slide_right_out);
|
|
} else {
|
|
anim = AnimationUtils.loadAnimation(getActivity(), R.anim.slide_bottom_out);
|
|
}
|
|
anim.setDuration(200L);
|
|
anim.setAnimationListener(new Animation.AnimationListener() { // from class: cn.com.magnity.magnitycx.FragmentMainTop.1
|
|
@Override // android.view.animation.Animation.AnimationListener
|
|
public void onAnimationStart(Animation animation) {
|
|
}
|
|
|
|
@Override // android.view.animation.Animation.AnimationListener
|
|
public void onAnimationEnd(Animation animation) {
|
|
Animation anim2;
|
|
if (on) {
|
|
btn.setImageResource(resIdOn);
|
|
} else {
|
|
btn.setImageResource(resIdOff);
|
|
}
|
|
if (FragmentMainTop.this.getResources().getConfiguration().orientation == 2) {
|
|
anim2 = AnimationUtils.loadAnimation(FragmentMainTop.this.getActivity(), R.anim.slide_left_in);
|
|
} else {
|
|
anim2 = AnimationUtils.loadAnimation(FragmentMainTop.this.getActivity(), R.anim.slide_top_in);
|
|
}
|
|
anim2.setDuration(200L);
|
|
btn.startAnimation(anim2);
|
|
}
|
|
|
|
@Override // android.view.animation.Animation.AnimationListener
|
|
public void onAnimationRepeat(Animation animation) {
|
|
}
|
|
});
|
|
btn.startAnimation(anim);
|
|
}
|
|
|
|
public void openLaser() {
|
|
if (!this.usbComm_.setLaserState(1)) {
|
|
Logging.error("Fail to set laser off");
|
|
} else {
|
|
exchangeLogo(this.btnLaserOn_, R.mipmap.laser_on, R.mipmap.laser_off, true);
|
|
MagApplication.magParameter.isLaserOn = true;
|
|
}
|
|
}
|
|
|
|
public void closeLaser() {
|
|
if (!this.usbComm_.setLaserState(0)) {
|
|
Logging.error("Fail to set laser off");
|
|
} else {
|
|
exchangeLogo(this.btnLaserOn_, R.mipmap.laser_on, R.mipmap.laser_off, false);
|
|
MagApplication.magParameter.isLaserOn = false;
|
|
}
|
|
}
|
|
|
|
private class MainTopClickListener implements View.OnClickListener {
|
|
private MainTopClickListener() {
|
|
}
|
|
|
|
@Override // android.view.View.OnClickListener
|
|
public void onClick(View v) {
|
|
int dispMode;
|
|
switch (v.getId()) {
|
|
case R.id.id_mode /* 2131624136 */:
|
|
int dispMode2 = MagApplication.magParameter.dispMode;
|
|
if (dispMode2 == 0) {
|
|
dispMode = 1;
|
|
StatService.onEvent(FragmentMainTop.this.getContext(), MagParameter.EVENT_DISABLE_VISWND_ID, MagParameter.EVENT_DISABLE_VISWND);
|
|
} else {
|
|
dispMode = 0;
|
|
StatService.onEvent(FragmentMainTop.this.getContext(), MagParameter.EVENT_ENABLE_VISWND_ID, MagParameter.EVENT_ENABLE_VISWND);
|
|
}
|
|
FragmentMainTop.this.exchangeLogo(FragmentMainTop.this.btnMode_, R.mipmap.disp_mode_pip, R.mipmap.disp_mode_ironly, dispMode == 0);
|
|
FragmentMainCenter fragment = ((MainActivity) FragmentMainTop.this.getActivity()).getFragmentMainCenter();
|
|
if (fragment instanceof DelegateDisplayModeChanged) {
|
|
boolean ret = fragment.onDisplayModeChanged(0, dispMode);
|
|
if (!ret) {
|
|
FragmentMainTop.this.exchangeLogo(FragmentMainTop.this.btnMode_, R.mipmap.disp_mode_pip, R.mipmap.disp_mode_ironly, dispMode != 0);
|
|
break;
|
|
}
|
|
}
|
|
SharedPreferencesManager.putIntWithCommit(MagParameter.KEY_DISPMODE, dispMode);
|
|
MagApplication.magParameter.dispMode = dispMode;
|
|
int num = MagApplication.magParameter.onceTipVisibleMove;
|
|
if (dispMode == 0) {
|
|
int num2 = num - 1;
|
|
if (num != 0) {
|
|
MagApplication.magParameter.onceTipVisibleMove = num2;
|
|
SharedPreferencesManager.putIntWithCommit(MagParameter.KEY_ONCETIPVISIBLEMOVE, num2);
|
|
Toast.makeText(FragmentMainTop.this.getContext(), R.string.onceTipVisibleMove, 1).show();
|
|
break;
|
|
}
|
|
}
|
|
break;
|
|
case R.id.id_cross /* 2131624137 */:
|
|
MagApplication.magParameter.isShowCross = !MagApplication.magParameter.isShowCross;
|
|
if (MagApplication.magParameter.isShowCross) {
|
|
StatService.onEvent(FragmentMainTop.this.getContext(), MagParameter.EVENT_ENABLE_CENTER_TEMP_ID, MagParameter.EVENT_ENABLE_CENTER_TEMP);
|
|
} else {
|
|
StatService.onEvent(FragmentMainTop.this.getContext(), MagParameter.EVENT_DISABLE_CENTER_TEMP_ID, MagParameter.EVENT_DISABLE_CENTER_TEMP);
|
|
}
|
|
SharedPreferencesManager.putBooleanWithCommit(MagParameter.KEY_SHOWCROSS, MagApplication.magParameter.isShowCross);
|
|
FragmentMainTop.this.exchangeLogo(FragmentMainTop.this.btnCross_, R.mipmap.center_cross_on, R.mipmap.center_cross_off, MagApplication.magParameter.isShowCross);
|
|
break;
|
|
case R.id.id_zoom /* 2131624138 */:
|
|
int ratio = MagApplication.magParameter.imageEX;
|
|
if (ratio == 0) {
|
|
MagApplication.magParameter.imageEX = 1;
|
|
SharedPreferencesManager.putIntWithCommit(MagParameter.KEY_EXMODE, MagApplication.magParameter.imageEX);
|
|
FragmentMainTop.this.exchangeLogo(FragmentMainTop.this.btnZoom_, R.mipmap.zoom_2x, R.mipmap.zoom_1x, true);
|
|
} else if (ratio == 1) {
|
|
MagApplication.magParameter.imageEX = 2;
|
|
FragmentMainTop.this.exchangeLogo(FragmentMainTop.this.btnZoom_, R.mipmap.zoom_4x, R.mipmap.zoom_2x, true);
|
|
} else if (ratio == 2) {
|
|
MagApplication.magParameter.imageEX = 0;
|
|
FragmentMainTop.this.exchangeLogo(FragmentMainTop.this.btnZoom_, R.mipmap.zoom_1x, R.mipmap.zoom_4x, true);
|
|
}
|
|
SharedPreferencesManager.putIntWithCommit(MagParameter.KEY_EXMODE, MagApplication.magParameter.imageEX);
|
|
DeviceController.setEX(MagApplication.magParameter.imageEX, MagApplication.magParameter.basePara1.fpaWidth / 2, MagApplication.magParameter.basePara1.fpaHeight / 2);
|
|
break;
|
|
case R.id.id_trace_max_min /* 2131624139 */:
|
|
MagApplication.magParameter.isTraceMaxMin = !MagApplication.magParameter.isTraceMaxMin;
|
|
SharedPreferencesManager.putBooleanWithCommit(MagParameter.KEY_TRACEMAXMIN, MagApplication.magParameter.isTraceMaxMin);
|
|
FragmentMainTop.this.exchangeLogo(FragmentMainTop.this.btnTraceMaxMin_, R.mipmap.trace_max_min_on, R.mipmap.trace_max_min_off, MagApplication.magParameter.isTraceMaxMin);
|
|
if ((MagApplication.magParameter.basePara1.devType == 0 || MagApplication.magParameter.basePara1.devType == 5 || MagApplication.magParameter.basePara1.devType == 6 || MagApplication.magParameter.basePara1.devType == 3) && MagApplication.magParameter.maxMinTrace == -1 && MagApplication.magParameter.isTraceMaxMin) {
|
|
MagApplication.magParameter.maxMinTrace = 0;
|
|
SharedPreferencesManager.putIntWithCommit(MagParameter.KEY_MAXMINTRACE, MagApplication.magParameter.maxMinTrace);
|
|
break;
|
|
}
|
|
break;
|
|
case R.id.id_laser /* 2131624140 */:
|
|
if (MagApplication.magParameter.isLaserOn) {
|
|
StatService.onEvent(FragmentMainTop.this.getContext(), MagParameter.EVENT_DISABLE_LASER_ID, MagParameter.EVENT_DISABLE_LASER);
|
|
FragmentMainTop.this.closeLaser();
|
|
break;
|
|
} else {
|
|
QueryDialogFragment dlgMediaDel = QueryDialogFragment.newInstance(R.layout.dialog_fragment_query_open_laser);
|
|
StatService.onEvent(FragmentMainTop.this.getContext(), MagParameter.EVENT_ENABLE_LASER_ID, MagParameter.EVENT_ENABLE_LASER);
|
|
dlgMediaDel.show(FragmentMainTop.this.getActivity().getSupportFragmentManager(), "openLaser");
|
|
break;
|
|
}
|
|
case R.id.id_more /* 2131624141 */:
|
|
Intent intent = new Intent(FragmentMainTop.this.getActivity(), (Class<?>) SettingActivity.class);
|
|
FragmentMainTop.this.startActivity(intent);
|
|
break;
|
|
case R.id.id_menu_item_setting /* 2131624220 */:
|
|
Intent intent2 = new Intent(FragmentMainTop.this.getActivity(), (Class<?>) SettingActivity.class);
|
|
FragmentMainTop.this.startActivity(intent2);
|
|
FragmentMainTop.this.popupWindowMore_.dismiss();
|
|
break;
|
|
case R.id.id_menu_item_help /* 2131624221 */:
|
|
Intent intent3 = new Intent(FragmentMainTop.this.getActivity(), (Class<?>) SupportActivity.class);
|
|
FragmentMainTop.this.startActivity(intent3);
|
|
FragmentMainTop.this.popupWindowMore_.dismiss();
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|