Skip to content

Commit

Permalink
add:zdc1激活功能
Browse files Browse the repository at this point in the history
版本v0.10
  • Loading branch information
a2633063 committed May 7, 2019
1 parent 38b78ec commit 41bd067
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 6 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ android {
applicationId "com.zyc.zcontrol"
minSdkVersion 19
targetSdkVersion 28
versionCode 11
versionName "0.9"
versionCode 12
versionName "0.10"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
Binary file modified app/release/app-release.apk
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
Expand All @@ -16,13 +17,15 @@
import android.support.v4.app.Fragment;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AlertDialog;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ScrollView;
import android.widget.Switch;
import android.widget.TextView;
Expand Down Expand Up @@ -89,11 +92,18 @@ public void handleMessage(Message msg) {// handler接收到消息后就会执行
switch (msg.what) {
case 1:
Send("{\"mac\": \"" + device_mac + "\","
+ "\"lock\":null,"
+ "\"plug_0\" : {\"on\" : null,\"setting\":{\"name\":null}},"
+ "\"plug_1\" : {\"on\" : null,\"setting\":{\"name\":null}},"
+ "\"plug_2\" : {\"on\" : null,\"setting\":{\"name\":null}},"
+ "\"plug_3\" : {\"on\" : null,\"setting\":{\"name\":null}}}");
break;

case 101:
new AlertDialog.Builder(getActivity()).setTitle("命令超时")
.setMessage("接收反馈数据超时,请重试")
.setPositiveButton("确定", null).show();
break;
}
}
};
Expand Down Expand Up @@ -256,7 +266,25 @@ public void onClick(View v) {
//endregion
//endregion

//region 弹窗激活
void unlock() {

final EditText et = new EditText(getActivity());
new AlertDialog.Builder(getActivity()).setTitle("请输入激活码")
.setView(et)
.setMessage("激活码免费提供,如果您为此花钱购买,那您被骗了~\n索要激活码请至项目主页中查看作者联系方式.(关于页面中有项目地址)")
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
String lockStr = et.getText().toString();
Send("{\"mac\":\"" + device_mac + "\",\"lock\":\"" + lockStr + "\"}");
handler.sendEmptyMessageDelayed(101,1000);
}
}).setNegativeButton("取消", null).show();

}

//endregion
void Send(String message) {
boolean b = getActivity().getSharedPreferences("Setting_" + device_mac, 0).getBoolean("always_UDP", false);
mConnectService.Send(b ? null : "device/zdc1/set", message);
Expand All @@ -282,6 +310,15 @@ void Receive(String topic, String message) {
if (jsonObject.has("setting")) jsonSetting = jsonObject.getJSONObject("setting");
if (mac == null || !mac.equals(device_mac)) return;

if (jsonObject.has("lock")) {
handler.removeMessages(101);
boolean lock = jsonObject.getBoolean("lock");
Log.d(Tag, "lock:" + lock);
if (!lock) {
// Toast.makeText(getContext(), "设备未激活", Toast.LENGTH_SHORT).show();
// unlock();
}
}
if (jsonObject.has("power")) {
String power = jsonObject.getString("power");
Log.d(Tag, "power:" + power);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.app.AlertDialog;
import android.util.Log;
import android.widget.EditText;
import android.widget.Toast;

import com.zyc.webservice.WebService;
Expand Down Expand Up @@ -51,6 +52,7 @@ public class DC1SettingFragment extends PreferenceFragment {
//endregion

Preference fw_version;
Preference lock;
EditTextPreference name_preference;


Expand All @@ -76,7 +78,7 @@ public void handleMessage(Message msg) {// handler接收到消息后就会执行
if (pd != null && pd.isShowing()) pd.dismiss();
String JsonStr = (String) msg.obj;
Log.d(Tag, "result:" + JsonStr);
if(JsonStr==null || JsonStr.length()<3)break;
if (JsonStr == null || JsonStr.length() < 3) break;
try {
obj = new JSONObject(JsonStr);
if (obj.has("id") && obj.has("tag_name") && obj.has("target_commitish")
Expand Down Expand Up @@ -166,6 +168,7 @@ public void onCreate(Bundle savedInstanceState) {
//
// CheckBoxPreference mEtPreference = (CheckBoxPreference) findPreference("theme");
fw_version = findPreference("fw_version");
lock = findPreference("lock");
name_preference = (EditTextPreference) findPreference("name");


Expand Down Expand Up @@ -197,6 +200,13 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
});
//endregion

lock.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
unlock();
return false;
}
});

//region 版本
fw_version.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
Expand Down Expand Up @@ -272,6 +282,26 @@ public void onDestroy() {
super.onDestroy();
}

//region 弹窗激活
void unlock() {

final EditText et = new EditText(getActivity());
new AlertDialog.Builder(getActivity()).setTitle("请输入激活码")
.setView(et)
.setMessage("激活码免费提供,如果您为此花钱购买,那您被骗了~\n索要激活码请至项目主页中查看作者联系方式.(关于页面中有项目地址)")
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
String lockStr = et.getText().toString();
Send("{\"mac\":\"" + device_mac + "\",\"lock\":\"" + lockStr + "\"}");
}
}).setNegativeButton("取消", null).show();

}

//endregion


void Send(String message) {
boolean b = getActivity().getSharedPreferences("Setting_" + device_mac, 0).getBoolean("always_UDP", false);
mConnectService.Send(b ? null : "device/zdc1/set", message);
Expand Down Expand Up @@ -309,6 +339,15 @@ void Receive(String topic, String message) {
fw_version.setSummary(version);
}
//endregion
//region 激活
if (jsonObject.has("lock")) {
if (jsonObject.getBoolean("lock")) {
lock.setSummary("已激活");
}else{
lock.setSummary("未激活");
}
}
//endregion
//region ota结果/进度
if (jsonObject.has("ota_progress")) {
int ota_progress = jsonObject.getInt("ota_progress");
Expand All @@ -332,8 +371,8 @@ void Receive(String topic, String message) {
if (ota_flag) {
//todo 显示更新进度

if(pd!=null && pd.isShowing())
pd.setMessage("正在获取最新固件版本,请稍后....\n"+"进度:"+ota_progress+"%");
if (pd != null && pd.isShowing())
pd.setMessage("正在获取最新固件版本,请稍后....\n" + "进度:" + ota_progress + "%");
// Toast.makeText(getActivity(), "ota进度:"+ota_progress+"%", Toast.LENGTH_SHORT).show();
}
}
Expand Down Expand Up @@ -381,7 +420,7 @@ public void onClick(DialogInterface dialog, int which) {
@Override
public void onServiceConnected(ComponentName componentName, IBinder service) {
mConnectService = ((ConnectService.LocalBinder) service).getService();
Send("{\"mac\":\"" + device_mac + "\",\"version\":null}");
Send("{\"mac\":\"" + device_mac + "\",\"version\":null,\"lock\":null}");
}

@Override
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/xml/dc1_setting.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
<Preference
android:key="fw_version"
android:title="当前版本(点击检查新版本)"/>
<Preference
android:key="lock"
android:title="激活状态"/>
</PreferenceCategory>

</PreferenceScreen>

0 comments on commit 41bd067

Please sign in to comment.