NVRSettingNtpActivity.java 源代码
package main.NVR.Setting;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import base.HiActivity;
import bean.MyCamera;
import com.hichip.NVR.content.HiChipNVRDefines;
import com.hichip.callback.ICameraIOSessionCallback;
import com.hichip.campro.R;
import com.hichip.control.HiCamera;
import com.hichip.tools.Packet;
import com.meizu.cloud.pushsdk.constants.PushConstants;
import common.HiDataValue;
import common.TitleView;
import custom.SwitchButton;
import java.util.Iterator;
import utils.HiLogcatUtil;
import utils.HiTools;
public class NVRSettingNtpActivity extends HiActivity implements CompoundButton.OnCheckedChangeListener, ICameraIOSessionCallback, View.OnClickListener {
EditText et_ntptime;
EditText et_nvrntpname;
EditText et_osdsetname;
ImageView iv_ntptime;
ImageView iv_nvrntpname;
ImageView iv_osdsetname;
LinearLayout ll_bgntposdset;
LinearLayout ll_ntpsetting;
LinearLayout ll_osdsetting;
private MyCamera mCamera;
private View mLastView;
private HiChipNVRDefines.PLATFORM_S_CHANNEL_OSD mNvrChnOSD;
private HiChipNVRDefines.PLATFORM_S_NTP mNvrNtp;
SwitchButton switch_btn_blntp;
SwitchButton switch_btn_osdTime;
SwitchButton switch_btn_osdname;
private int mImageModeType = 0;
public int chn = 0;
private boolean nvrsinglechn = false;
private Handler handler = new Handler() {
@Override
public void handleMessage(Message message) {
MyCamera myCamera = (MyCamera) message.obj;
int i = message.what;
if (i == -1879048191) {
NVRSettingNtpActivity.this.handSessionState(message, myCamera);
return;
}
if (i != -1879048189) {
return;
}
if (message.arg2 == 0) {
NVRSettingNtpActivity.this.dismissjuHuaDialog();
byte[] byteArray = message.getData().getByteArray("data");
int i2 = message.arg1;
if (i2 != 268435491) {
if (i2 == 268435495 && byteArray.length > 40) {
NVRSettingNtpActivity.this.mNvrNtp = new HiChipNVRDefines.PLATFORM_S_NTP(byteArray);
HiLogcatUtil.e("HI_NVR_P2P_PLATFORM_NTP" + NVRSettingNtpActivity.this.mNvrNtp.u32Enable + "::" + NVRSettingNtpActivity.this.mNvrNtp.u32Interval + ":::" + Packet.getString(NVRSettingNtpActivity.this.mNvrNtp.aszSvr));
NVRSettingNtpActivity.this.switch_btn_blntp.setChecked(NVRSettingNtpActivity.this.mNvrNtp.u32Enable == 1);
NVRSettingNtpActivity.this.et_ntptime.setText("" + NVRSettingNtpActivity.this.mNvrNtp.u32Interval);
NVRSettingNtpActivity.this.et_nvrntpname.setText("" + Packet.getString(NVRSettingNtpActivity.this.mNvrNtp.aszSvr));
return;
}
return;
}
if (byteArray.length > 76) {
NVRSettingNtpActivity.this.mNvrChnOSD = new HiChipNVRDefines.PLATFORM_S_CHANNEL_OSD(byteArray);
HiLogcatUtil.e("HI_NVR_P2P_PLATFORM_CHANNEL_OSD" + NVRSettingNtpActivity.this.mNvrChnOSD.blEnTime + "::" + NVRSettingNtpActivity.this.mNvrChnOSD.blEnName + ":::" + Packet.getString(NVRSettingNtpActivity.this.mNvrChnOSD.sName));
NVRSettingNtpActivity.this.switch_btn_osdTime.setChecked(NVRSettingNtpActivity.this.mNvrChnOSD.blEnTime == 1);
NVRSettingNtpActivity.this.switch_btn_osdname.setChecked(NVRSettingNtpActivity.this.mNvrChnOSD.blEnName == 1);
NVRSettingNtpActivity.this.et_osdsetname.setText("" + Packet.getString(NVRSettingNtpActivity.this.mNvrChnOSD.sName));
return;
}
return;
}
NVRSettingNtpActivity.this.dismissjuHuaDialog();
}
};
private int spaceTime = 400;
private long lastClickTime = 0;
@Override
protected int setLayoutId() {
return R.layout.activity_nvrntp_setting;
}
@Override
protected void init(Bundle bundle) {
String stringExtra = getIntent().getStringExtra(HiDataValue.EXTRAS_KEY_UID);
this.chn = getIntent().getIntExtra("nvrposition", -1);
this.nvrsinglechn = getIntent().getBooleanExtra("nvrsinglechn", false);
Iterator<MyCamera> it = HiDataValue.CameraList.iterator();
while (true) {
if (!it.hasNext()) {
break;
}
MyCamera next = it.next();
if (stringExtra.equals(next.getUid())) {
this.mCamera = next;
break;
}
}
if (HiTools.cameraWhetherNull(this.mCamera, this)) {
return;
}
getWindow().setSoftInputMode(2);
initView();
setOnListeners();
showjuHuaDialog();
}
private void initView() {
TitleView titleView = (TitleView) findViewById(R.id.title_top);
if (this.nvrsinglechn) {
titleView.setTitle("OSD 设置");
} else {
titleView.setTitle("NTP 设置");
}
titleView.setButton(0);
titleView.setNavigationBarButtonListener(new TitleView.NavigationBarButtonListener() {
@Override
public final void OnNavigationButtonClick(int i) {
NVRSettingNtpActivity.this.lambda$initView$0$NVRSettingNtpActivity(i);
}
});
showjuHuaDialog();
this.mCamera.registerIOSessionListener(this);
if (this.nvrsinglechn) {
this.ll_osdsetting.setVisibility(0);
this.ll_ntpsetting.setVisibility(8);
this.mCamera.sendIOCtrl(HiChipNVRDefines.HI_NVR_P2P_PLATFORM_CHANNEL_OSD, HiChipNVRDefines.PLATFORM_S_CHANNEL_OSD.parseContent(0, this.chn, 76));
} else {
this.ll_osdsetting.setVisibility(8);
this.ll_ntpsetting.setVisibility(0);
this.mCamera.sendIOCtrl(HiChipNVRDefines.HI_NVR_P2P_PLATFORM_NTP, HiChipNVRDefines.PLATFORM_S_NTP.parseContent(0, 48));
}
}
public void lambda$initView$0$NVRSettingNtpActivity(int i) {
if (i != 0) {
return;
}
finish();
}
private void setOnListeners() {
this.ll_bgntposdset.setOnClickListener(this);
this.switch_btn_blntp.setOnCheckedChangeListener(this);
this.iv_ntptime.setOnClickListener(this);
this.iv_nvrntpname.setOnClickListener(this);
this.switch_btn_osdTime.setOnCheckedChangeListener(this);
this.switch_btn_osdname.setOnCheckedChangeListener(this);
this.iv_osdsetname.setOnClickListener(this);
}
@Override
public void onResume() {
super.onResume();
MyCamera myCamera = this.mCamera;
if (myCamera != null) {
myCamera.registerIOSessionListener(this);
}
}
@Override
public void onPause() {
super.onPause();
MyCamera myCamera = this.mCamera;
if (myCamera != null) {
myCamera.unregisterIOSessionListener(this);
}
}
@Override
public void onClick(View view) {
if (HiFocusEText(view)) {
return;
}
switch (view.getId()) {
case R.id.iv_ntptime:
handIvEditValue(this.et_ntptime);
return;
case R.id.iv_nvrntpname:
handIvEditValue(this.et_nvrntpname);
return;
case R.id.iv_osdsetname:
handIvEditValue(this.et_osdsetname);
return;
case R.id.rl_ImageMode:
Intent intent = new Intent(this, (Class<?>) NVRImageModeTypeActivity.class);
intent.putExtra("mImageModeType", this.mImageModeType);
intent.putExtra(HiDataValue.EXTRAS_KEY_UID, this.mCamera.getUid());
startActivityForResult(intent, 110);
return;
default:
return;
}
}
private boolean handDown(EditText editText, int i) {
editText.clearFocus();
editText.setFocusable(false);
((InputMethodManager) getSystemService("input_method")).hideSoftInputFromWindow(editText.getWindowToken(), 0);
String trim = editText.getText().toString().trim();
if (trim.length() == 0) {
trim = PushConstants.PUSH_TYPE_NOTIFY;
}
if (i == 1 || i == 2) {
if (this.mNvrNtp == null) {
return false;
}
} else if (i == 3 && this.mNvrChnOSD == null) {
return false;
}
if (i == 1) {
this.mNvrNtp.u32Interval = Integer.parseInt(trim);
} else if (i == 2) {
System.arraycopy(trim.getBytes(), 0, this.mNvrNtp.aszSvr, 0, trim.getBytes().length);
} else if (i == 3) {
System.arraycopy(trim.getBytes(), 0, this.mNvrChnOSD.sName, 0, trim.getBytes().length);
}
if (this.nvrsinglechn) {
this.mNvrChnOSD.u8mode = 1;
this.mCamera.sendIOCtrl(HiChipNVRDefines.HI_NVR_P2P_PLATFORM_CHANNEL_OSD, this.mNvrChnOSD.parseContent());
} else {
this.mNvrNtp.u8mode = 1;
this.mCamera.sendIOCtrl(HiChipNVRDefines.HI_NVR_P2P_PLATFORM_NTP, this.mNvrNtp.parseContent());
}
HiLogcatUtil.e(editText + "::" + trim + "::" + i);
return false;
}
private boolean HiFocusEText(View view) {
if (this.et_ntptime.hasFocus()) {
if (view.getId() == R.id.iv_return) {
finish();
return false;
}
handDown(this.et_ntptime, 1);
return true;
}
if (this.et_nvrntpname.hasFocus()) {
if (view.getId() == R.id.iv_return) {
finish();
return false;
}
handDown(this.et_nvrntpname, 2);
return true;
}
if (!this.et_osdsetname.hasFocus()) {
return false;
}
if (view.getId() == R.id.iv_return) {
finish();
return false;
}
handDown(this.et_osdsetname, 3);
return true;
}
private void handIvEditValue(EditText editText) {
editText.setFocusable(true);
editText.setFocusableInTouchMode(true);
editText.requestFocus();
if (!TextUtils.isEmpty(editText.getText().toString())) {
editText.setSelection(editText.getText().toString().length());
}
((InputMethodManager) getSystemService("input_method")).showSoftInput(editText, 2);
}
public void handSessionState(Message message, MyCamera myCamera) {
if (message.arg1 == 0 && myCamera != null) {
HiLogcatUtil.i("--CameraFragment p2p DISCONNECTED--:" + myCamera.getUid());
}
}
@Override
public void receiveIOCtrlData(HiCamera hiCamera, int i, byte[] bArr, int i2) {
if (hiCamera != this.mCamera) {
return;
}
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 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);
}
public boolean isFastClick() {
long currentTimeMillis = System.currentTimeMillis();
boolean z = currentTimeMillis - this.lastClickTime <= ((long) this.spaceTime);
this.lastClickTime = currentTimeMillis;
return z;
}
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean z) {
if (isFastClick() && compoundButton == this.mLastView) {
compoundButton.setChecked(!z);
return;
}
this.mLastView = compoundButton;
switch (compoundButton.getId()) {
case R.id.switch_btn_blNtp:
handBtnNtp(z);
return;
case R.id.switch_btn_osdTime:
handBtnosdtime(z);
return;
case R.id.switch_btn_osdname:
handBtnosdname(z);
return;
default:
return;
}
}
private void handBtnNtp(boolean z) {
HiChipNVRDefines.PLATFORM_S_NTP platform_s_ntp = this.mNvrNtp;
if (platform_s_ntp == null) {
return;
}
if (z) {
platform_s_ntp.u32Enable = 1;
} else {
platform_s_ntp.u32Enable = 0;
}
this.mNvrNtp.u8mode = 1;
showjuHuaDialog();
this.mCamera.sendIOCtrl(HiChipNVRDefines.HI_NVR_P2P_PLATFORM_NTP, this.mNvrNtp.parseContent());
}
private void handBtnosdtime(boolean z) {
HiChipNVRDefines.PLATFORM_S_CHANNEL_OSD platform_s_channel_osd = this.mNvrChnOSD;
if (platform_s_channel_osd == null) {
return;
}
if (z) {
platform_s_channel_osd.blEnTime = 1;
} else {
platform_s_channel_osd.blEnTime = 0;
}
this.mNvrChnOSD.u8mode = 1;
showjuHuaDialog();
this.mCamera.sendIOCtrl(HiChipNVRDefines.HI_NVR_P2P_PLATFORM_CHANNEL_OSD, this.mNvrChnOSD.parseContent());
}
private void handBtnosdname(boolean z) {
HiChipNVRDefines.PLATFORM_S_CHANNEL_OSD platform_s_channel_osd = this.mNvrChnOSD;
if (platform_s_channel_osd == null) {
return;
}
if (z) {
platform_s_channel_osd.blEnName = 1;
} else {
platform_s_channel_osd.blEnName = 0;
}
this.mNvrChnOSD.u8mode = 1;
showjuHuaDialog();
this.mCamera.sendIOCtrl(HiChipNVRDefines.HI_NVR_P2P_PLATFORM_CHANNEL_OSD, this.mNvrChnOSD.parseContent());
}
}