master
parent
f84afd11c1
commit
ee567ea782
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
@ -1,34 +0,0 @@
|
||||
package com.gizwits.opensource.appkit.CommonModule;
|
||||
|
||||
import android.net.wifi.ScanResult;
|
||||
|
||||
import com.gizwits.gizwifisdk.api.GizDeviceSharingInfo;
|
||||
import com.gizwits.gizwifisdk.api.GizUserInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class GosConstant {
|
||||
|
||||
// 设备热点默认前缀
|
||||
public static final String SoftAP_Start = "XPG-GAgent";
|
||||
|
||||
public static final String SSIDPsw = "#10v3#";
|
||||
public static boolean isOpenHot = false;
|
||||
/**
|
||||
* 0 使用旧接口 setDeviceOnboarding
|
||||
* 1 配网绑定接口 setDeviceOnboardingByBind
|
||||
* 2 域名配网接口 setDeviceOnboardingDeploy false
|
||||
* 3 域名配网接口 setDeviceOnboardingDeploy true
|
||||
*/
|
||||
public static int mNew = 0;
|
||||
public static List<ScanResult> ssidList = new ArrayList<ScanResult>();
|
||||
public static int nowPager = -1;
|
||||
public static List<GizUserInfo> mybindUsers = new ArrayList<GizUserInfo>();
|
||||
public static boolean isEdit = false;
|
||||
|
||||
public static List<GizDeviceSharingInfo> mydeviceSharingInfos = new ArrayList<GizDeviceSharingInfo>();
|
||||
public static List<GizDeviceSharingInfo> newmydeviceSharingInfos = new ArrayList<GizDeviceSharingInfo>();
|
||||
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -1,56 +0,0 @@
|
||||
package com.gizwits.opensource.appkit.CommonModule;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
public class NoScrollViewPager extends ViewPager {
|
||||
private boolean noScroll = false;
|
||||
|
||||
public NoScrollViewPager(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public NoScrollViewPager(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public void setNoScroll(boolean noScroll) {
|
||||
this.noScroll = noScroll;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void scrollTo(int x, int y) {
|
||||
super.scrollTo(x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent arg0) {
|
||||
/* return false;//super.onTouchEvent(arg0); */
|
||||
if (noScroll)
|
||||
return false;
|
||||
else
|
||||
return super.onTouchEvent(arg0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onInterceptTouchEvent(MotionEvent arg0) {
|
||||
if (noScroll)
|
||||
return false;
|
||||
else
|
||||
return super.onInterceptTouchEvent(arg0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCurrentItem(int item, boolean smoothScroll) {
|
||||
super.setCurrentItem(item, smoothScroll);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCurrentItem(int item) {
|
||||
super.setCurrentItem(item);
|
||||
}
|
||||
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
package com.gizwits.opensource.appkit.CommonModule;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gizwits.opensource.appkit.R;
|
||||
|
||||
|
||||
public class TipsDialog extends Dialog implements
|
||||
View.OnClickListener {
|
||||
|
||||
private Button btnSure;
|
||||
private TextView tvTips;
|
||||
|
||||
public TipsDialog(Context context) {
|
||||
super(context);
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
getWindow().setBackgroundDrawableResource(R.drawable.shape_button2);
|
||||
setContentView(R.layout.dialog_tips);
|
||||
initView();
|
||||
setCancelable(false);
|
||||
|
||||
}
|
||||
|
||||
public TipsDialog(Context context, String txt) {
|
||||
this(context);
|
||||
|
||||
tvTips.setText(txt);
|
||||
}
|
||||
|
||||
public TipsDialog(Context context, int res) {
|
||||
this(context);
|
||||
|
||||
tvTips.setText(res);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private void initView() {
|
||||
btnSure = (Button) findViewById(R.id.btnSure);
|
||||
tvTips = (TextView) findViewById(R.id.tvTips);
|
||||
|
||||
btnSure.setOnClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
switch (v.getId()) {
|
||||
case R.id.btnSure:
|
||||
cancel();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
@ -1,505 +0,0 @@
|
||||
package com.gizwits.opensource.appkit.ConfigModule;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.location.LocationManager;
|
||||
import android.net.wifi.ScanResult;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.text.TextUtils;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.CompoundButton.OnCheckedChangeListener;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ListView;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.gizwits.opensource.appkit.R;
|
||||
import com.gizwits.opensource.appkit.CommonModule.GosDeploy;
|
||||
import com.gizwits.opensource.appkit.DeviceModule.GosMainActivity;
|
||||
import com.gizwits.opensource.appkit.utils.NetUtils;
|
||||
import com.gizwits.opensource.appkit.utils.ToolUtils;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@SuppressLint("InflateParams")
|
||||
public class GosAirlinkChooseDeviceWorkWiFiActivity extends GosConfigModuleBaseActivity implements OnClickListener {
|
||||
|
||||
private AlertDialog create;
|
||||
private ArrayList<ScanResult> wifiList;
|
||||
|
||||
private static final int REQUEST_EXTERNAL_STORAGE = 1;
|
||||
private static String[] PERMISSIONS_STORAGE = {
|
||||
"android.permission.ACCESS_FINE_LOCATION",
|
||||
"android.permission.ACCESS_COARSE_LOCATION"};
|
||||
/**
|
||||
* wifi信息
|
||||
*/
|
||||
public WifiInfo wifiInfo;
|
||||
|
||||
/**
|
||||
* The et SSID
|
||||
*/
|
||||
private EditText etSSID;
|
||||
|
||||
/**
|
||||
* The et Psw
|
||||
*/
|
||||
private EditText etPsw;
|
||||
|
||||
/**
|
||||
* The btn Next
|
||||
*/
|
||||
private Button btnNext;
|
||||
|
||||
/** The ll ChooseMode */
|
||||
//private LinearLayout llChooseMode;
|
||||
|
||||
/**
|
||||
* The cb Laws
|
||||
*/
|
||||
private CheckBox cbLaws;
|
||||
|
||||
/** The tv Mode */
|
||||
//private TextView tvMode;
|
||||
|
||||
/**
|
||||
* The rl WiFiList
|
||||
*/
|
||||
private RelativeLayout rlWiFiList;
|
||||
|
||||
/**
|
||||
* 配置用参数
|
||||
*/
|
||||
private String workSSID, workSSIDPsw;
|
||||
|
||||
/**
|
||||
* The data
|
||||
*/
|
||||
List<String> modeList;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_gos_airlink_choose_device_workwifi);
|
||||
// 设置ActionBar
|
||||
setToolBar(true, getString(R.string.choose_wifi));
|
||||
|
||||
initData();
|
||||
initView();
|
||||
ininEvent();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
try {
|
||||
// 预设workSSID && workSSIDPsw
|
||||
workSSID = NetUtils.getCurentWifiSSID(this);
|
||||
String mypass = spf.getString("mypass", "");
|
||||
|
||||
if (!TextUtils.isEmpty(workSSID)) {
|
||||
etSSID.setText(workSSID);
|
||||
etSSID.setSelection(workSSID.length());
|
||||
if (!TextUtils.isEmpty(mypass)) {
|
||||
JSONObject obj = new JSONObject(mypass);
|
||||
|
||||
if (obj.has(workSSID)) {
|
||||
String pass = obj.getString(workSSID);
|
||||
etPsw.setText(pass);
|
||||
} else {
|
||||
etPsw.setText("");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
etSSID.setText(NetUtils.getCurentWifiSSID(this));
|
||||
}
|
||||
|
||||
// 当没有任何文字的时候设置为明文显示
|
||||
// if (TextUtils.isEmpty(etPsw.getText().toString())) {
|
||||
// cbLaws.setChecked(true);
|
||||
// etPsw.setInputType(0x90);
|
||||
// } else {
|
||||
// etPsw.setInputType(0x81);
|
||||
// cbLaws.setChecked(false);
|
||||
// }
|
||||
} catch(JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
//tvMode = (TextView) findViewById(R.id.tvMode);
|
||||
etSSID = (EditText) findViewById(R.id.etSSID);
|
||||
|
||||
etPsw = (EditText) findViewById(R.id.etPsw);
|
||||
cbLaws = (CheckBox) findViewById(R.id.cbLaws);
|
||||
btnNext = (Button) findViewById(R.id.btnNext);
|
||||
//llChooseMode = (LinearLayout) findViewById(R.id.llChooseMode);
|
||||
rlWiFiList = (RelativeLayout) findViewById(R.id.rlWiFiList);
|
||||
|
||||
// 配置文件部署
|
||||
btnNext.setBackgroundDrawable(GosDeploy.appConfig_BackgroundColor());
|
||||
btnNext.setTextColor(GosDeploy.appConfig_Contrast());
|
||||
// llChooseMode.setVisibility(GosDeploy.setModuleSelectOn());
|
||||
|
||||
//llChooseMode.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
|
||||
private void ininEvent() {
|
||||
btnNext.setOnClickListener(this);
|
||||
rlWiFiList.setOnClickListener(this);
|
||||
//llChooseMode.setOnClickListener(this);
|
||||
|
||||
cbLaws.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
String psw = etPsw.getText().toString();
|
||||
|
||||
if (isChecked) {
|
||||
etPsw.setInputType(0x90);
|
||||
} else {
|
||||
etPsw.setInputType(0x81);
|
||||
}
|
||||
etPsw.setSelection(psw.length());
|
||||
}
|
||||
});
|
||||
|
||||
//检测是否有位置定位的权限
|
||||
int permission = ActivityCompat.checkSelfPermission(GosAirlinkChooseDeviceWorkWiFiActivity.this,
|
||||
"android.permission.ACCESS_FINE_LOCATION");
|
||||
if (permission != PackageManager.PERMISSION_GRANTED) {
|
||||
try {
|
||||
// 没有写的权限,去申请写的权限,会弹出对话框
|
||||
ActivityCompat.requestPermissions(GosAirlinkChooseDeviceWorkWiFiActivity.this, PERMISSIONS_STORAGE, REQUEST_EXTERNAL_STORAGE);
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void initData() {
|
||||
modeList = new ArrayList<String>();
|
||||
String[] modes = this.getResources().getStringArray(R.array.mode);
|
||||
for (String string : modes) {
|
||||
modeList.add(string);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
switch (v.getId()) {
|
||||
case R.id.btnNext:
|
||||
if (ToolUtils.noDoubleClick()) {
|
||||
workSSID = etSSID.getText().toString();
|
||||
workSSIDPsw = etPsw.getText().toString();
|
||||
|
||||
if (TextUtils.isEmpty(workSSID)) {
|
||||
Toast.makeText(GosAirlinkChooseDeviceWorkWiFiActivity.this, R.string.choose_wifi_list_title, toastTime)
|
||||
.show();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!workSSID.equals(NetUtils.getCurentWifiSSID(this))) {
|
||||
final Dialog dialog1 = new AlertDialog.Builder(this, R.style.alert_dialog_style)
|
||||
.setView(new EditText(this)).create();
|
||||
dialog1.setCanceledOnTouchOutside(false);
|
||||
dialog1.show();
|
||||
|
||||
Window window = dialog1.getWindow();
|
||||
window.setContentView(R.layout.alert_gos_wifi);
|
||||
|
||||
LinearLayout llNo, llSure;
|
||||
llNo = (LinearLayout) window.findViewById(R.id.llNo);
|
||||
llSure = (LinearLayout) window.findViewById(R.id.llSure);
|
||||
|
||||
llNo.setOnClickListener(new OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dialog1.cancel();
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
llSure.setOnClickListener(new OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (dialog1.isShowing()) {
|
||||
dialog1.cancel();
|
||||
}
|
||||
isEmptyAlert();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
isEmptyAlert();
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case R.id.rlWiFiList:
|
||||
AlertDialog.Builder dia = new AlertDialog.Builder(GosAirlinkChooseDeviceWorkWiFiActivity.this);
|
||||
View view = View.inflate(GosAirlinkChooseDeviceWorkWiFiActivity.this, R.layout.alert_gos_wifi_list, null);
|
||||
ListView listview = (ListView) view.findViewById(R.id.wifi_list);
|
||||
List<ScanResult> rsList = NetUtils.getCurrentWifiScanResult(this);
|
||||
List<String> localList = new ArrayList<String>();
|
||||
localList.clear();
|
||||
wifiList = new ArrayList<ScanResult>();
|
||||
wifiList.clear();
|
||||
for (ScanResult sss : rsList) {
|
||||
if (sss.SSID.contains(SoftAP_Start)) {
|
||||
} else {
|
||||
if (localList.toString().contains(sss.SSID)) {
|
||||
} else {
|
||||
localList.add(sss.SSID);
|
||||
wifiList.add(sss);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (wifiList.size() == 0) {
|
||||
LocationManager locManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
|
||||
if (!locManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
|
||||
// 未打开位置开关,可能导致定位失败或定位不准,提示用户或做相应处理
|
||||
Toast.makeText(this, getString(R.string.open), Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
}
|
||||
WifiListAdapter adapter = new WifiListAdapter(wifiList);
|
||||
listview.setAdapter(adapter);
|
||||
listview.setOnItemClickListener(new OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
|
||||
ScanResult sResult = wifiList.get(arg2);
|
||||
String sSID = sResult.SSID;
|
||||
etSSID.setText(sSID);
|
||||
etSSID.setSelection(sSID.length());
|
||||
etPsw.setText("");
|
||||
create.dismiss();
|
||||
}
|
||||
});
|
||||
dia.setView(view);
|
||||
create = dia.create();
|
||||
create.show();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private static final String TAG = "GosAirlinkChooseDevice";
|
||||
|
||||
private void toAirlinkReady() {
|
||||
// 需要记录所有配置过的wifi和密码
|
||||
|
||||
try {
|
||||
String mypass = spf.getString("mypass", "");
|
||||
if (TextUtils.isEmpty(mypass)) {
|
||||
JSONObject mUserAndPass = new JSONObject();
|
||||
mUserAndPass.put(workSSID, workSSIDPsw);
|
||||
spf.edit().putString("mypass", mUserAndPass.toString()).commit();
|
||||
} else {
|
||||
JSONObject obj = new JSONObject(mypass);
|
||||
obj.put(workSSID, workSSIDPsw);
|
||||
spf.edit().putString("mypass", obj.toString()).commit();
|
||||
}
|
||||
} catch(JSONException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
spf.edit().putString("workSSID", workSSID).commit();
|
||||
spf.edit().putString("workSSIDPsw", workSSIDPsw).commit();
|
||||
//wifiModuleType-false-start wifiModuleType-true-start
|
||||
if (GosDeploy.appConfig_WifiModuleType().size() == 0) {
|
||||
//wifiModuleType-false-end
|
||||
Intent intent = new Intent(this, GosModeListActivity2.class);
|
||||
startActivity(intent);
|
||||
//wifiModuleType-false-start
|
||||
} else {
|
||||
//wifiModuleType-true-end
|
||||
List<Integer> moduleTypes = GosDeploy.appConfig_WifiModuleType();
|
||||
JSONArray array = new JSONArray();
|
||||
for (int type : moduleTypes) {
|
||||
if (type == 4) {
|
||||
type = 0;
|
||||
} else if (type < 4) {
|
||||
type = type + 1;
|
||||
} else if (type == 12) {
|
||||
type = 6;
|
||||
} else if (type >= 6 && type < 12) {
|
||||
type = type + 1;
|
||||
}
|
||||
array.put(type);
|
||||
}
|
||||
spf.edit().putString("modulestyles", array.toString()).commit();
|
||||
Intent intent = new Intent(this, GosAirlinkReadyActivity.class);
|
||||
startActivity(intent);
|
||||
//wifiModuleType-true-start
|
||||
}
|
||||
//wifiModuleType-false-end wifiModuleType-true-end
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* // 检查当前使用的WiFi是否曾经用过 protected boolean checkworkSSIDUsed(String workSSID)
|
||||
* { if (spf.contains("workSSID")) { if (spf.getString("workSSID",
|
||||
* "").equals(workSSID)) { return true; } } return false; }
|
||||
*/
|
||||
|
||||
// 屏蔽掉返回键
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||
Intent intent = new Intent(this, GosMainActivity.class);
|
||||
startActivity(intent);
|
||||
//quitAlert(this, intent);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
Intent intent = new Intent(this, GosMainActivity.class);
|
||||
startActivity(intent);
|
||||
//quitAlert(this, intent);
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private void isEmptyAlert() {
|
||||
if (TextUtils.isEmpty(workSSIDPsw)) {
|
||||
final Dialog dialog = new AlertDialog.Builder(this, R.style.alert_dialog_style)
|
||||
.setView(new EditText(this)).create();
|
||||
dialog.setCanceledOnTouchOutside(false);
|
||||
dialog.show();
|
||||
|
||||
Window window = dialog.getWindow();
|
||||
window.setContentView(R.layout.alert_gos_empty);
|
||||
WindowManager.LayoutParams layoutParams = window.getAttributes();
|
||||
layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
|
||||
window.setAttributes(layoutParams);
|
||||
LinearLayout llNo, llSure;
|
||||
llNo = (LinearLayout) window.findViewById(R.id.llNo);
|
||||
llSure = (LinearLayout) window.findViewById(R.id.llSure);
|
||||
|
||||
llNo.setOnClickListener(new OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dialog.cancel();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
llSure.setOnClickListener(new OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
if (dialog.isShowing()) {
|
||||
dialog.cancel();
|
||||
}
|
||||
toAirlinkReady();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
toAirlinkReady();
|
||||
}
|
||||
}
|
||||
|
||||
class WifiListAdapter extends BaseAdapter {
|
||||
|
||||
ArrayList<ScanResult> xpgList;
|
||||
|
||||
public WifiListAdapter(ArrayList<ScanResult> list) {
|
||||
this.xpgList = list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return xpgList.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int position) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
View view = convertView;
|
||||
Holder holder;
|
||||
if (view == null) {
|
||||
view = LayoutInflater.from(GosAirlinkChooseDeviceWorkWiFiActivity.this)
|
||||
.inflate(R.layout.item_gos_wifi_list, null);
|
||||
holder = new Holder(view);
|
||||
view.setTag(holder);
|
||||
} else {
|
||||
holder = (Holder) view.getTag();
|
||||
}
|
||||
|
||||
String ssid = xpgList.get(position).SSID;
|
||||
holder.getTextView().setText(ssid);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Holder {
|
||||
View view;
|
||||
|
||||
public Holder(View view) {
|
||||
this.view = view;
|
||||
}
|
||||
|
||||
TextView textView;
|
||||
|
||||
public TextView getTextView() {
|
||||
if (textView == null) {
|
||||
textView = (TextView) view.findViewById(R.id.SSID_text);
|
||||
}
|
||||
return textView;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,310 +0,0 @@
|
||||
package com.gizwits.opensource.appkit.ConfigModule;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableString;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup.LayoutParams;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.gizwits.opensource.appkit.R;
|
||||
import com.gizwits.gizwifisdk.api.GizWifiSDK;
|
||||
import com.gizwits.gizwifisdk.enumration.GizWifiConfigureMode;
|
||||
import com.gizwits.gizwifisdk.enumration.GizWifiErrorCode;
|
||||
import com.gizwits.gizwifisdk.enumration.GizWifiGAgentType;
|
||||
import com.gizwits.opensource.appkit.CommonModule.GosConstant;
|
||||
import com.gizwits.opensource.appkit.CommonModule.GosDeploy;
|
||||
import com.gizwits.opensource.appkit.DeviceModule.GosMainActivity;
|
||||
import com.gizwits.opensource.appkit.view.RoundProgressBar;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
import static com.gizwits.gizwifisdk.enumration.GizWifiErrorCode.GIZ_SDK_ONBOARDING_STOPPED;
|
||||
|
||||
@SuppressLint("HandlerLeak")
|
||||
public class GosAirlinkConfigCountdownActivity extends
|
||||
GosConfigModuleBaseActivity {
|
||||
|
||||
/** The tv Time */
|
||||
//private TextView tvTimer;
|
||||
|
||||
/**
|
||||
* The rpb Config
|
||||
*/
|
||||
private RoundProgressBar rpbConfig;
|
||||
|
||||
/**
|
||||
* 倒计时
|
||||
*/
|
||||
int secondleft = 60;
|
||||
|
||||
/**
|
||||
* The timer
|
||||
*/
|
||||
Timer timer;
|
||||
|
||||
/**
|
||||
* 配置用参数
|
||||
*/
|
||||
String workSSID, workSSIDPsw;
|
||||
|
||||
|
||||
List<GizWifiGAgentType> modeList, modeDataList;
|
||||
private TextView tvLeft;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_gos_airlink_config_countdown);
|
||||
// 设置ActionBar
|
||||
setToolBar(false, R.string.search_join);
|
||||
initView();
|
||||
initData();
|
||||
startAirlink();
|
||||
tvLeft = (TextView) findViewById(R.id.tvLeft);
|
||||
tvLeft.setVisibility(View.VISIBLE);
|
||||
SpannableString ssTitle = new SpannableString(this.getString(R.string.cancel));
|
||||
ssTitle.setSpan(new ForegroundColorSpan(GosDeploy.appConfig_Contrast()), 0, ssTitle.length(),
|
||||
Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||
tvLeft.setText(ssTitle);
|
||||
tvLeft.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(GosAirlinkConfigCountdownActivity.this, GosMainActivity.class);
|
||||
quitAlert(GosAirlinkConfigCountdownActivity.this, intent, getString(R.string.cancel_configuration));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
WindowManager wm = this.getWindowManager();
|
||||
int width = wm.getDefaultDisplay().getWidth();
|
||||
|
||||
RelativeLayout cel_layout = (RelativeLayout) findViewById(R.id.params);
|
||||
LayoutParams params = cel_layout.getLayoutParams();
|
||||
params.height = width;
|
||||
params.width = width;
|
||||
cel_layout.setLayoutParams(params);
|
||||
//tvTimer = (TextView) findViewById(R.id.tvTimer);
|
||||
|
||||
rpbConfig = (RoundProgressBar) findViewById(R.id.rpbConfig);
|
||||
|
||||
}
|
||||
|
||||
private static final String TAG = "GosAirlinkConfigCountdo";
|
||||
|
||||
private void initData() {
|
||||
workSSID = spf.getString("workSSID", "");
|
||||
workSSIDPsw = spf.getString("workSSIDPsw", "");
|
||||
modeDataList = new ArrayList<GizWifiGAgentType>();
|
||||
modeDataList.add(GizWifiGAgentType.GizGAgentESP);
|
||||
modeDataList.add(GizWifiGAgentType.GizGAgentMXCHIP);
|
||||
modeDataList.add(GizWifiGAgentType.GizGAgentHF);
|
||||
modeDataList.add(GizWifiGAgentType.GizGAgentRTK);
|
||||
modeDataList.add(GizWifiGAgentType.GizGAgentWM);
|
||||
modeDataList.add(GizWifiGAgentType.GizGAgentQCA);
|
||||
modeDataList.add(GizWifiGAgentType.GizGAgentFlyLink);
|
||||
modeDataList.add(GizWifiGAgentType.GizGAgentTI);
|
||||
modeDataList.add(GizWifiGAgentType.GizGAgentFSK);
|
||||
modeDataList.add(GizWifiGAgentType.GizGAgentMXCHIP3);
|
||||
modeDataList.add(GizWifiGAgentType.GizGAgentBL);
|
||||
modeDataList.add(GizWifiGAgentType.GizGAgentAtmelEE);
|
||||
modeDataList.add(GizWifiGAgentType.GizGAgentOther);
|
||||
modeList = new ArrayList<GizWifiGAgentType>();
|
||||
|
||||
String types = spf.getString("modulestyles", null);
|
||||
if (types != null) {
|
||||
try {
|
||||
JSONArray array = new JSONArray(types);
|
||||
for (int i = 0; i < array.length(); i++) {
|
||||
int type = (Integer) array.get(i);
|
||||
modeList.add(modeDataList.get(type));
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void startAirlink() {
|
||||
String nullStr = null;
|
||||
switch (GosConstant.mNew) {
|
||||
case 0:
|
||||
GizWifiSDK.sharedInstance().setDeviceOnboarding(workSSID, workSSIDPsw,
|
||||
GizWifiConfigureMode.GizWifiAirLink, null, 60, modeList);
|
||||
break;
|
||||
case 1:
|
||||
GizWifiSDK.sharedInstance().setDeviceOnboardingByBind(workSSID, workSSIDPsw,
|
||||
GizWifiConfigureMode.GizWifiAirLink, null, 60, modeList);
|
||||
break;
|
||||
case 2:
|
||||
GizWifiSDK.sharedInstance().setDeviceOnboardingDeploy(
|
||||
workSSID,
|
||||
workSSIDPsw,
|
||||
GizWifiConfigureMode.GizWifiAirLink,
|
||||
nullStr,
|
||||
60,
|
||||
modeList,
|
||||
false
|
||||
);
|
||||
break;
|
||||
case 3:
|
||||
GizWifiSDK.sharedInstance().setDeviceOnboardingDeploy(
|
||||
workSSID,
|
||||
workSSIDPsw,
|
||||
GizWifiConfigureMode.GizWifiAirLink,
|
||||
nullStr,
|
||||
60,
|
||||
modeList,
|
||||
true
|
||||
);
|
||||
break;
|
||||
}
|
||||
handler.sendEmptyMessage(handler_key.START_TIMER.ordinal());
|
||||
}
|
||||
|
||||
private enum handler_key {
|
||||
|
||||
/**
|
||||
* 倒计时提示
|
||||
*/
|
||||
TIMER_TEXT,
|
||||
|
||||
/**
|
||||
* 倒计时开始
|
||||
*/
|
||||
START_TIMER,
|
||||
|
||||
/**
|
||||
* 配置成功
|
||||
*/
|
||||
SUCCESSFUL,
|
||||
|
||||
/**
|
||||
* 配置失败
|
||||
*/
|
||||
FAILED,
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The handler.
|
||||
*/
|
||||
Handler handler = new Handler() {
|
||||
public void handleMessage(Message msg) {
|
||||
super.handleMessage(msg);
|
||||
handler_key key = handler_key.values()[msg.what];
|
||||
switch (key) {
|
||||
|
||||
case START_TIMER:
|
||||
isStartTimer();
|
||||
break;
|
||||
|
||||
case SUCCESSFUL:
|
||||
Toast.makeText(GosAirlinkConfigCountdownActivity.this,
|
||||
R.string.configuration_successful, toastTime).show();
|
||||
Intent intent1 = new Intent(GosAirlinkConfigCountdownActivity.this, GosMainActivity.class);
|
||||
startActivity(intent1);
|
||||
break;
|
||||
|
||||
case FAILED:
|
||||
if (GosDeploy.appConfig_Config_Softap()) {
|
||||
Toast.makeText(GosAirlinkConfigCountdownActivity.this,
|
||||
getString(R.string.configuration_timeout), toastTime).show();
|
||||
Intent intent = new Intent(
|
||||
GosAirlinkConfigCountdownActivity.this,
|
||||
GosDeviceReadyActivity.class);
|
||||
/** 判断是否是从一键配置界面传过去的 */
|
||||
intent.putExtra("isAirLink", true);
|
||||
startActivity(intent);
|
||||
} else {
|
||||
Intent intent = new Intent(
|
||||
GosAirlinkConfigCountdownActivity.this,
|
||||
GosConfigFailedActivity.class);
|
||||
/** 判断是否是从一键配置界面传过去的 */
|
||||
intent.putExtra("isAirLink", true);
|
||||
startActivity(intent);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// 屏蔽掉返回键
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||
Intent intent = new Intent(GosAirlinkConfigCountdownActivity.this, GosMainActivity.class);
|
||||
//quitAlert(this, intent);
|
||||
quitAlert(this, intent, getString(R.string.cancel_configuration));
|
||||
overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// 倒计时
|
||||
public void isStartTimer() {
|
||||
|
||||
secondleft = 60;
|
||||
timer = new Timer();
|
||||
timer.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
secondleft--;
|
||||
rpbConfig.setProgress((60 - secondleft) * (100 / 60.0));
|
||||
}
|
||||
}, 1000, 1000);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设备配置回调
|
||||
*
|
||||
* @param result 错误码
|
||||
* @param mac MAC
|
||||
* @param did DID
|
||||
* @param productKey PK
|
||||
*/
|
||||
protected void didSetDeviceOnboarding(GizWifiErrorCode result, String mac,
|
||||
String did, String productKey) {
|
||||
if (GizWifiErrorCode.GIZ_SDK_DEVICE_CONFIG_IS_RUNNING == result) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (timer != null) {
|
||||
timer.cancel();
|
||||
}
|
||||
Message message = new Message();
|
||||
if (result == GizWifiErrorCode.GIZ_SDK_SUCCESS) {
|
||||
message.what = handler_key.SUCCESSFUL.ordinal();
|
||||
} else if (result == GIZ_SDK_ONBOARDING_STOPPED) {
|
||||
|
||||
} else {
|
||||
message.what = handler_key.FAILED.ordinal();
|
||||
message.obj = toastError(result);
|
||||
}
|
||||
Log.i("Apptest", result.toString());
|
||||
handler.sendMessage(message);
|
||||
}
|
||||
}
|
@ -1,132 +0,0 @@
|
||||
package com.gizwits.opensource.appkit.ConfigModule;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.text.SpannableString;
|
||||
import android.text.Spanned;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gizwits.opensource.appkit.R;
|
||||
import com.gizwits.opensource.appkit.CommonModule.GosDeploy;
|
||||
import com.gizwits.opensource.appkit.utils.AssetsUtils;
|
||||
import com.gizwits.opensource.appkit.utils.ToolUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class GosAirlinkReadyActivity extends GosConfigModuleBaseActivity implements OnClickListener {
|
||||
|
||||
|
||||
/**
|
||||
* The tv Ready
|
||||
*/
|
||||
TextView tvReady;
|
||||
|
||||
|
||||
/**
|
||||
* The btn Next
|
||||
*/
|
||||
Button btnNext;
|
||||
|
||||
TextView tvDeviceTip;
|
||||
|
||||
private int sum = 0;
|
||||
|
||||
//private TextView moudlechoose;
|
||||
|
||||
private List<String> modeList;
|
||||
private ImageView ivReady;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.actvity_gos_airlink_ready);
|
||||
// 设置ActionBar
|
||||
setToolBar(true, R.string.airlink_ready_title);
|
||||
|
||||
initData();
|
||||
initView();
|
||||
initEvent();
|
||||
}
|
||||
|
||||
private void initData() {
|
||||
// workSSID = spf.getString("workSSID", "");
|
||||
|
||||
modeList = new ArrayList<String>();
|
||||
String[] modes = this.getResources().getStringArray(R.array.mode);
|
||||
for (String string : modes) {
|
||||
modeList.add(string);
|
||||
}
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
tvReady = (TextView) findViewById(R.id.tvReady);
|
||||
btnNext = (Button) findViewById(R.id.btnNext);
|
||||
tvDeviceTip = (TextView) findViewById(R.id.tvDeviceTip);
|
||||
ivReady = (ImageView) findViewById(R.id.ivReady);
|
||||
SpannableString spannableString = new SpannableString(getString(R.string.common_ready_message));
|
||||
if (AssetsUtils.isZh(this)) {
|
||||
spannableString.setSpan(new ForegroundColorSpan(Color.parseColor("#007AFF")), 9, 14, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
} else {
|
||||
spannableString.setSpan(new ForegroundColorSpan(Color.parseColor("#007AFF")), 28, 45, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
}
|
||||
|
||||
tvReady.setText(spannableString);
|
||||
|
||||
// 配置文件部署
|
||||
btnNext.setBackgroundDrawable(GosDeploy.appConfig_BackgroundColor());
|
||||
btnNext.setTextColor(GosDeploy.appConfig_Contrast());
|
||||
}
|
||||
|
||||
private void initEvent() {
|
||||
btnNext.setOnClickListener(this);
|
||||
tvDeviceTip.setOnClickListener(this);
|
||||
ivReady.setOnClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
switch (v.getId()) {
|
||||
case R.id.btnNext:
|
||||
if (ToolUtils.noDoubleClick()) {
|
||||
sum = 0;
|
||||
Intent intent = new Intent(this, GosAirlinkConfigCountdownActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
sum = 0;
|
||||
this.finish();
|
||||
//overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right);
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
// Intent intent = new Intent(this, GosAirlinkChooseDeviceWorkWiFiActivity.class);
|
||||
// startActivity(intent);
|
||||
// overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right);
|
||||
// this.finish();
|
||||
// return true;
|
||||
// }
|
||||
|
||||
|
||||
}
|
@ -1,279 +0,0 @@
|
||||
package com.gizwits.opensource.appkit.ConfigModule;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.location.LocationManager;
|
||||
import android.net.wifi.ScanResult;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.gizwits.opensource.appkit.R;
|
||||
import com.gizwits.gizwifisdk.log.SDKLog;
|
||||
import com.gizwits.opensource.appkit.CommonModule.GosConstant;
|
||||
import com.gizwits.opensource.appkit.utils.AssetsUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
@SuppressLint({"InflateParams", "HandlerLeak"})
|
||||
public class GosChooseDeviceActivity extends GosConfigModuleBaseActivity implements OnClickListener {
|
||||
|
||||
/**
|
||||
* The tv Nodevice
|
||||
*/
|
||||
TextView tvNodevice;
|
||||
|
||||
/**
|
||||
* The list View
|
||||
*/
|
||||
ListView listView;
|
||||
|
||||
/**
|
||||
* 系统WiFi集合
|
||||
*/
|
||||
ArrayList<ScanResult> list;
|
||||
|
||||
/**
|
||||
* 设备热点集合
|
||||
*/
|
||||
ArrayList<ScanResult> softList;
|
||||
|
||||
/**
|
||||
* 适配器
|
||||
*/
|
||||
Myadapter myadapter;
|
||||
|
||||
/**
|
||||
* 计时器
|
||||
*/
|
||||
Timer timer;
|
||||
|
||||
int flag = 0;
|
||||
|
||||
private enum handler_key {
|
||||
|
||||
/**
|
||||
* 刷新列表
|
||||
*/
|
||||
UPDATALIST,
|
||||
|
||||
}
|
||||
|
||||
Handler handler = new Handler() {
|
||||
public void handleMessage(android.os.Message msg) {
|
||||
super.handleMessage(msg);
|
||||
handler_key key = handler_key.values()[msg.what];
|
||||
switch (key) {
|
||||
// 更新列表
|
||||
case UPDATALIST:
|
||||
initData();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
;
|
||||
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_gos_choose_device);
|
||||
// 设置ActionBar
|
||||
setToolBar(true, R.string.choosedevice);
|
||||
|
||||
initView();
|
||||
initEvent();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
startTimer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
timer.cancel();
|
||||
}
|
||||
|
||||
private void initData() {
|
||||
// list = new ArrayList<ScanResult>();
|
||||
list = (ArrayList<ScanResult>) GosConstant.ssidList;
|
||||
//list = (ArrayList<ScanResult>) NetUtils.getCurrentWifiScanResult(GosChooseDeviceActivity.this);
|
||||
softList = new ArrayList<ScanResult>();
|
||||
ScanResult scanResult;
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
scanResult = list.get(i);
|
||||
if (scanResult.SSID.length() > SoftAP_Start.length()) {
|
||||
if (scanResult.SSID.contains(SoftAP_Start)) {
|
||||
softList.add(scanResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
myadapter = new Myadapter(softList);
|
||||
listView.setAdapter(myadapter);
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
tvNodevice = (TextView) findViewById(R.id.nodevice);
|
||||
listView = (ListView) findViewById(R.id.list_view);
|
||||
}
|
||||
|
||||
private void initEvent() {
|
||||
tvNodevice.setOnClickListener(this);
|
||||
|
||||
listView.setOnItemClickListener(new OnItemClickListener() {
|
||||
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
Intent intent = new Intent(GosChooseDeviceActivity.this, GosConfigCountdownActivity.class);
|
||||
intent.putExtra("softSSID", softList.get(position).SSID);
|
||||
startActivity(intent);
|
||||
finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
switch (v.getId()) {
|
||||
case R.id.nodevice:
|
||||
if (list == null) {
|
||||
LocationManager locManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
|
||||
if (!locManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
|
||||
// 未打开位置开关,可能导致定位失败或定位不准,提示用户或做相应处理
|
||||
Toast.makeText(this, getString(R.string.open), Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
} else if (list.size() == 0) {
|
||||
LocationManager locManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
|
||||
if (!locManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
|
||||
// 未打开位置开关,可能导致定位失败或定位不准,提示用户或做相应处理
|
||||
Toast.makeText(this, getString(R.string.open), Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
}
|
||||
finish();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void startTimer() {
|
||||
timer = new Timer();
|
||||
timer.schedule(new TimerTask() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
handler.sendEmptyMessage(handler_key.UPDATALIST.ordinal());
|
||||
}
|
||||
}, 0, 3000);
|
||||
}
|
||||
|
||||
class Myadapter extends BaseAdapter {
|
||||
|
||||
ArrayList<ScanResult> softList;
|
||||
|
||||
public Myadapter(ArrayList<ScanResult> list) {
|
||||
this.softList = list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return softList.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int position) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
View view = convertView;
|
||||
Holder holder;
|
||||
if (view == null) {
|
||||
view = LayoutInflater.from(GosChooseDeviceActivity.this).inflate(R.layout.item_gos_wifi_device, null);
|
||||
holder = new Holder(view);
|
||||
view.setTag(holder);
|
||||
} else {
|
||||
|
||||
holder = (Holder) view.getTag();
|
||||
}
|
||||
String ssid = softList.get(position).SSID;
|
||||
|
||||
// String itemStart = (String) getText(R.string.itemtext_start);
|
||||
// String itemEnd = (String) getText(R.string.itemtext_end);
|
||||
String s = "";
|
||||
if (AssetsUtils.isZh(GosChooseDeviceActivity.this)) {
|
||||
s = getString(R.string.device) + ssid.substring(ssid.length() - 4);
|
||||
} else {
|
||||
s = getString(R.string.device) + " " + ssid.substring(ssid.length() - 4);
|
||||
}
|
||||
holder.getTextView().setText(s);
|
||||
|
||||
return view;
|
||||
}
|
||||
}
|
||||
|
||||
class Holder {
|
||||
View view;
|
||||
|
||||
public Holder(View view) {
|
||||
this.view = view;
|
||||
}
|
||||
|
||||
TextView textView;
|
||||
|
||||
public TextView getTextView() {
|
||||
if (textView == null) {
|
||||
textView = (TextView) view.findViewById(R.id.SSID_text);
|
||||
}
|
||||
return textView;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
finish();
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// 屏蔽掉返回键
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||
finish();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -1,465 +0,0 @@
|
||||
package com.gizwits.opensource.appkit.ConfigModule;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.location.LocationManager;
|
||||
import android.net.wifi.ScanResult;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.text.TextUtils;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.CompoundButton.OnCheckedChangeListener;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ListView;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.gizwits.opensource.appkit.CommonModule.GosConstant;
|
||||
import com.gizwits.opensource.appkit.CommonModule.GosDeploy;
|
||||
import com.gizwits.opensource.appkit.DeviceModule.GosMainActivity;
|
||||
import com.gizwits.opensource.appkit.R;
|
||||
import com.gizwits.opensource.appkit.utils.NetUtils;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class GosChooseDeviceWorkWiFiActivity extends GosConfigModuleBaseActivity
|
||||
implements OnClickListener, OnItemClickListener {
|
||||
|
||||
private AlertDialog create;
|
||||
private ArrayList<ScanResult> wifiList;
|
||||
|
||||
private static final int REQUEST_EXTERNAL_STORAGE = 1;
|
||||
private static String[] PERMISSIONS_STORAGE = {
|
||||
"android.permission.ACCESS_FINE_LOCATION",
|
||||
"android.permission.ACCESS_COARSE_LOCATION"};
|
||||
|
||||
/**
|
||||
* wifi信息
|
||||
*/
|
||||
public WifiInfo wifiInfo;
|
||||
|
||||
/**
|
||||
* The et SSID
|
||||
*/
|
||||
private EditText etSSID;
|
||||
|
||||
/**
|
||||
* The et Psw
|
||||
*/
|
||||
private EditText etPsw;
|
||||
|
||||
/**
|
||||
* The btn Next
|
||||
*/
|
||||
private Button btnNext;
|
||||
|
||||
/**
|
||||
* The cb Laws
|
||||
*/
|
||||
private CheckBox cbLaws;
|
||||
|
||||
/**
|
||||
* The img WiFiList
|
||||
*/
|
||||
private RelativeLayout rlWiFiList;
|
||||
|
||||
/**
|
||||
* 配置用参数
|
||||
*/
|
||||
private String softSSID, workSSID, workSSIDPsw;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_gos_choose_device_workwifi);
|
||||
// 设置ActionBar
|
||||
setToolBar(true, R.string.choose_wifi);
|
||||
|
||||
initData();
|
||||
initView();
|
||||
ininEvent();
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
etSSID = (EditText) findViewById(R.id.etSSID);
|
||||
etPsw = (EditText) findViewById(R.id.etPsw);
|
||||
btnNext = (Button) findViewById(R.id.btnNext);
|
||||
cbLaws = (CheckBox) findViewById(R.id.cbLaws);
|
||||
rlWiFiList = (RelativeLayout) findViewById(R.id.rlWiFiList);
|
||||
// 配置文件部署
|
||||
btnNext.setBackgroundDrawable(GosDeploy.appConfig_BackgroundColor());
|
||||
btnNext.setTextColor(GosDeploy.appConfig_Contrast());
|
||||
if (!TextUtils.isEmpty(workSSID)) {
|
||||
etSSID.setText(workSSID);
|
||||
etSSID.setSelection(workSSID.length());
|
||||
if (checkworkSSIDUsed(workSSID)) {
|
||||
if (!TextUtils.isEmpty(spf.getString("workSSIDPsw", ""))) {
|
||||
etPsw.setText(spf.getString("workSSIDPsw", ""));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void ininEvent() {
|
||||
|
||||
btnNext.setOnClickListener(this);
|
||||
rlWiFiList.setOnClickListener(this);
|
||||
|
||||
cbLaws.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
String psw = etPsw.getText().toString();
|
||||
|
||||
if (isChecked) {
|
||||
etPsw.setInputType(0x90);
|
||||
} else {
|
||||
etPsw.setInputType(0x81);
|
||||
}
|
||||
etPsw.setSelection(psw.length());
|
||||
}
|
||||
});
|
||||
|
||||
//检测是否有位置定位的权限
|
||||
int permission = ActivityCompat.checkSelfPermission(GosChooseDeviceWorkWiFiActivity.this,
|
||||
"android.permission.ACCESS_FINE_LOCATION");
|
||||
if (permission != PackageManager.PERMISSION_GRANTED) {
|
||||
try {
|
||||
// 没有写的权限,去申请写的权限,会弹出对话框
|
||||
ActivityCompat.requestPermissions(GosChooseDeviceWorkWiFiActivity.this, PERMISSIONS_STORAGE, REQUEST_EXTERNAL_STORAGE);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void initData() {
|
||||
//softSSID = getIntent().getStringExtra("softssid");
|
||||
workSSID = spf.getString("workSSID", "");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
||||
try {
|
||||
// 预设workSSID && workSSIDPsw
|
||||
workSSID = NetUtils.getCurentWifiSSID(this);
|
||||
String mypass = spf.getString("mypass", "");
|
||||
|
||||
if (!TextUtils.isEmpty(workSSID)) {
|
||||
etSSID.setText(workSSID);
|
||||
etSSID.setSelection(workSSID.length());
|
||||
if (!TextUtils.isEmpty(mypass)) {
|
||||
JSONObject obj = new JSONObject(mypass);
|
||||
|
||||
if (obj.has(workSSID)) {
|
||||
String pass = obj.getString(workSSID);
|
||||
etPsw.setText(pass);
|
||||
} else {
|
||||
etPsw.setText("");
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
etSSID.setText(NetUtils.getCurentWifiSSID(this));
|
||||
}
|
||||
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
Intent intent = new Intent(this, GosMainActivity.class);
|
||||
startActivity(intent);
|
||||
//quitAlert(this, intent);
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
switch (v.getId()) {
|
||||
case R.id.btnNext:
|
||||
workSSID = etSSID.getText().toString();
|
||||
workSSIDPsw = etPsw.getText().toString();
|
||||
|
||||
if (TextUtils.isEmpty(workSSID)) {
|
||||
Toast.makeText(GosChooseDeviceWorkWiFiActivity.this, R.string.choose_wifi_list_title,
|
||||
Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
if (TextUtils.isEmpty(workSSIDPsw)) {
|
||||
final Dialog dialog = new AlertDialog.Builder(this, R.style.alert_dialog_style)
|
||||
.setView(new EditText(this)).create();
|
||||
dialog.setCanceledOnTouchOutside(false);
|
||||
dialog.show();
|
||||
|
||||
Window window = dialog.getWindow();
|
||||
window.setContentView(R.layout.alert_gos_empty);
|
||||
WindowManager.LayoutParams layoutParams = window.getAttributes();
|
||||
layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
|
||||
window.setAttributes(layoutParams);
|
||||
LinearLayout llNo, llSure;
|
||||
llNo = (LinearLayout) window.findViewById(R.id.llNo);
|
||||
llSure = (LinearLayout) window.findViewById(R.id.llSure);
|
||||
|
||||
llNo.setOnClickListener(new OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dialog.cancel();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
llSure.setOnClickListener(new OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
if (dialog.isShowing()) {
|
||||
dialog.cancel();
|
||||
}
|
||||
Intent intent = null;
|
||||
//wifiModuleType-false-start wifiModuleType-true-start
|
||||
if (GosDeploy.appConfig_WifiModuleType().size() == 0) {
|
||||
//wifiModuleType-false-end
|
||||
intent = new Intent(GosChooseDeviceWorkWiFiActivity.this,
|
||||
GosModeListActivity2.class);
|
||||
//wifiModuleType-false-start
|
||||
} else {
|
||||
//wifiModuleType-true-end
|
||||
List<Integer> moduleTypes = GosDeploy.appConfig_WifiModuleType();
|
||||
JSONArray array = new JSONArray();
|
||||
for (int type : moduleTypes) {
|
||||
if (type == 4) {
|
||||
type = 0;
|
||||
} else if (type < 4) {
|
||||
type = type + 1;
|
||||
} else if (type == 12) {
|
||||
type = 6;
|
||||
} else if (type >= 6 && type < 12) {
|
||||
type = type + 1;
|
||||
}
|
||||
array.put(type);
|
||||
}
|
||||
spf.edit().putString("modulestyles", array.toString()).commit();
|
||||
intent = new Intent(GosChooseDeviceWorkWiFiActivity.this,
|
||||
GosDeviceReadyActivity.class);
|
||||
//wifiModuleType-true-start
|
||||
}
|
||||
//wifiModuleType-false-end wifiModuleType-true-end
|
||||
spf.edit().putString("workSSID", workSSID).commit();
|
||||
spf.edit().putString("workSSIDPsw", workSSIDPsw).commit();
|
||||
intent.putExtra("isAirlink", false);
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
Intent intent = null;
|
||||
//wifiModuleType-false-start wifiModuleType-true-start
|
||||
if (GosDeploy.appConfig_WifiModuleType().size() == 0) {
|
||||
//wifiModuleType-false-end
|
||||
intent = new Intent(GosChooseDeviceWorkWiFiActivity.this,
|
||||
GosModeListActivity2.class);
|
||||
//wifiModuleType-false-start
|
||||
} else {
|
||||
//wifiModuleType-true-end
|
||||
List<Integer> moduleTypes = GosDeploy.appConfig_WifiModuleType();
|
||||
JSONArray array = new JSONArray();
|
||||
for (int type : moduleTypes) {
|
||||
if (type == 4) {
|
||||
type = 0;
|
||||
} else if (type < 4) {
|
||||
type = type + 1;
|
||||
} else if (type == 12) {
|
||||
type = 6;
|
||||
} else if (type >= 6 && type < 12) {
|
||||
type = type + 1;
|
||||
}
|
||||
array.put(type);
|
||||
}
|
||||
spf.edit().putString("modulestyles", array.toString()).commit();
|
||||
intent = new Intent(GosChooseDeviceWorkWiFiActivity.this,
|
||||
GosDeviceReadyActivity.class);
|
||||
//wifiModuleType-true-start
|
||||
}
|
||||
//wifiModuleType-false-end wifiModuleType-true-end
|
||||
spf.edit().putString("workSSID", workSSID).commit();
|
||||
spf.edit().putString("workSSIDPsw", workSSIDPsw).commit();
|
||||
/** 判断是否是从一键配置界面传过去的 */
|
||||
intent.putExtra("isAirlink", false);
|
||||
startActivity(intent);
|
||||
}
|
||||
break;
|
||||
|
||||
case R.id.rlWiFiList:
|
||||
AlertDialog.Builder dia = new AlertDialog.Builder(GosChooseDeviceWorkWiFiActivity.this);
|
||||
View view = View.inflate(GosChooseDeviceWorkWiFiActivity.this, R.layout.alert_gos_wifi_list, null);
|
||||
ListView listview = (ListView) view.findViewById(R.id.wifi_list);
|
||||
List<ScanResult> rsList = NetUtils.getCurrentWifiScanResult(this);
|
||||
List<String> localList = new ArrayList<String>();
|
||||
localList.clear();
|
||||
wifiList = new ArrayList<ScanResult>();
|
||||
wifiList.clear();
|
||||
|
||||
for (ScanResult sss : rsList) {
|
||||
if (sss.SSID.contains(GosConstant.SoftAP_Start)) {
|
||||
|
||||
} else {
|
||||
if (localList.toString().contains(sss.SSID)) {
|
||||
} else {
|
||||
localList.add(sss.SSID);
|
||||
wifiList.add(sss);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (wifiList.size() == 0) {
|
||||
LocationManager locManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
|
||||
if (!locManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
|
||||
// 未打开位置开关,可能导致定位失败或定位不准,提示用户或做相应处理
|
||||
Toast.makeText(this, getString(R.string.open), Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
WifiListAdapter adapter = new WifiListAdapter(wifiList);
|
||||
listview.setAdapter(adapter);
|
||||
listview.setOnItemClickListener(this);
|
||||
dia.setView(view);
|
||||
create = dia.create();
|
||||
create.show();
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
|
||||
|
||||
ScanResult sResult = wifiList.get(arg2);
|
||||
String sSID = sResult.SSID;
|
||||
etSSID.setText(sSID);
|
||||
etSSID.setSelection(sSID.length());
|
||||
etPsw.setText("");
|
||||
create.dismiss();
|
||||
}
|
||||
|
||||
// 检查当前使用的WiFi是否曾经用过
|
||||
protected boolean checkworkSSIDUsed(String workSSID) {
|
||||
if (spf.contains("workSSID")) {
|
||||
if (spf.getString("workSSID", "").equals(workSSID)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// 屏蔽掉返回键
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||
Intent intent = new Intent(this, GosMainActivity.class);
|
||||
startActivity(intent);
|
||||
//quitAlert(this, intent);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
class WifiListAdapter extends BaseAdapter {
|
||||
|
||||
ArrayList<ScanResult> xpgList;
|
||||
|
||||
public WifiListAdapter(ArrayList<ScanResult> list) {
|
||||
this.xpgList = list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return xpgList.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int position) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@SuppressLint("InflateParams")
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
View view = convertView;
|
||||
Holder holder;
|
||||
if (view == null) {
|
||||
view = LayoutInflater.from(GosChooseDeviceWorkWiFiActivity.this).inflate(R.layout.item_gos_wifi_list,
|
||||
null);
|
||||
holder = new Holder(view);
|
||||
view.setTag(holder);
|
||||
} else {
|
||||
holder = (Holder) view.getTag();
|
||||
}
|
||||
String ssid = xpgList.get(position).SSID;
|
||||
holder.getTextView().setText(ssid);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Holder {
|
||||
View view;
|
||||
|
||||
public Holder(View view) {
|
||||
this.view = view;
|
||||
}
|
||||
|
||||
TextView textView;
|
||||
|
||||
public TextView getTextView() {
|
||||
if (textView == null) {
|
||||
textView = (TextView) view.findViewById(R.id.SSID_text);
|
||||
}
|
||||
return textView;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
package com.gizwits.opensource.appkit.ConfigModule;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.webkit.WebSettings;
|
||||
import android.webkit.WebView;
|
||||
|
||||
import com.gizwits.opensource.appkit.R;
|
||||
import com.gizwits.opensource.appkit.utils.AssetsUtils;
|
||||
|
||||
|
||||
/**
|
||||
* Created by admin on 2017/6/15.
|
||||
*/
|
||||
|
||||
public class GosChooseModuleHelpActivity extends com.gizwits.opensource.appkit.ConfigModule.GosConfigModuleBaseActivity {
|
||||
private WebView webHelp;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_gos_choose_module_help);
|
||||
initView();
|
||||
initEvent();
|
||||
}
|
||||
|
||||
private void initEvent() {
|
||||
setToolBar(true, getString(R.string.module_help));
|
||||
WebSettings wSet = webHelp.getSettings();
|
||||
wSet.setJavaScriptEnabled(true);
|
||||
if (AssetsUtils.isZh(this)) {
|
||||
webHelp.loadUrl("file:///android_asset/moduleTypeInfo.html");
|
||||
} else {
|
||||
webHelp.loadUrl("file:///android_asset/moduleTypeInfoEnglish.html");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
webHelp = (WebView) findViewById(R.id.webHelp);
|
||||
}
|
||||
}
|
@ -1,118 +0,0 @@
|
||||
package com.gizwits.opensource.appkit.ConfigModule;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableString;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gizwits.opensource.appkit.R;
|
||||
import com.gizwits.opensource.appkit.CommonModule.GosDeploy;
|
||||
import com.gizwits.opensource.appkit.DeviceModule.GosMainActivity;
|
||||
import com.gizwits.opensource.appkit.utils.ToolUtils;
|
||||
|
||||
public class GosConfigFailedActivity extends GosConfigModuleBaseActivity implements OnClickListener {
|
||||
|
||||
/**
|
||||
* The btn Again
|
||||
*/
|
||||
Button btnAgain;
|
||||
|
||||
/**
|
||||
* The soft SSID
|
||||
*/
|
||||
String softSSID;
|
||||
|
||||
/**
|
||||
* The data
|
||||
*/
|
||||
String promptText, cancelBesureText, beSureText, cancelText;
|
||||
private boolean isAirLink;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_gos_config_failed);
|
||||
// 设置ActionBar
|
||||
setToolBar(false, R.string.join_failed_title);
|
||||
TextView tvLeft = (TextView) findViewById(R.id.tvLeft);
|
||||
tvLeft.setVisibility(View.VISIBLE);
|
||||
SpannableString ssTitle = new SpannableString(this.getString(R.string.cancel));
|
||||
ssTitle.setSpan(new ForegroundColorSpan(GosDeploy.appConfig_Contrast()), 0, ssTitle.length(),
|
||||
Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||
tvLeft.setText(ssTitle);
|
||||
tvLeft.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(GosConfigFailedActivity.this, GosMainActivity.class);
|
||||
quitAlert(GosConfigFailedActivity.this, intent);
|
||||
}
|
||||
});
|
||||
initView();
|
||||
initEvent();
|
||||
initData();
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
btnAgain = (Button) findViewById(R.id.btnAgain);
|
||||
|
||||
// 配置文件部署
|
||||
btnAgain.setBackgroundDrawable(GosDeploy.appConfig_BackgroundColor());
|
||||
btnAgain.setTextColor(GosDeploy.appConfig_Contrast());
|
||||
}
|
||||
|
||||
private void initEvent() {
|
||||
btnAgain.setOnClickListener(this);
|
||||
}
|
||||
|
||||
private void initData() {
|
||||
/** 判断是否是从一键配置界面传过去的 */
|
||||
isAirLink = getIntent().getBooleanExtra("isAirLink", false);
|
||||
promptText = (String) getText(R.string.prompt);
|
||||
cancelBesureText = (String) getText(R.string.cancel_besure);
|
||||
beSureText = (String) getText(R.string.besure);
|
||||
cancelText = (String) getText(R.string.cancel);
|
||||
}
|
||||
|
||||
// 屏蔽掉返回键
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||
Intent intent = new Intent(GosConfigFailedActivity.this, GosMainActivity.class);
|
||||
quitAlert(this, intent);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
switch (v.getId()) {
|
||||
case R.id.btnAgain:
|
||||
if (ToolUtils.noDoubleClick()) {
|
||||
if (isAirLink) {
|
||||
//config_airlink-false-start
|
||||
Intent intent = new Intent(this, GosAirlinkChooseDeviceWorkWiFiActivity.class);
|
||||
startActivity(intent);
|
||||
//config_airlink-false-end
|
||||
} else {
|
||||
// config_softap-false-start
|
||||
Intent intent = new Intent(this, GosChooseDeviceWorkWiFiActivity.class);
|
||||
startActivity(intent);
|
||||
// config_softap-false-end
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,139 +0,0 @@
|
||||
package com.gizwits.opensource.appkit.ConfigModule;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.text.SpannableString;
|
||||
import android.text.Spanned;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gizwits.opensource.appkit.CommonModule.GosDeploy;
|
||||
import com.gizwits.opensource.appkit.DeviceModule.GosMainActivity;
|
||||
import com.gizwits.opensource.appkit.R;
|
||||
import com.gizwits.opensource.appkit.utils.AssetsUtils;
|
||||
import com.gizwits.opensource.appkit.utils.ToolUtils;
|
||||
|
||||
public class GosDeviceReadyActivity extends GosConfigModuleBaseActivity implements OnClickListener {
|
||||
|
||||
/**
|
||||
* The tv Ready
|
||||
*/
|
||||
TextView tvReady;
|
||||
|
||||
/**
|
||||
* The tv DeviceTip
|
||||
*/
|
||||
TextView tvDeviceTips;
|
||||
|
||||
/**
|
||||
* The btn Next
|
||||
*/
|
||||
Button btnNext;
|
||||
|
||||
private int sum = 0;
|
||||
/**
|
||||
* The flag
|
||||
*/
|
||||
boolean flag = false;
|
||||
|
||||
boolean isAirLink = false;
|
||||
private ImageView ivReady;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_gos_device_ready);
|
||||
// 设置ActionBar
|
||||
setToolBar(true, R.string.model_confirmation);
|
||||
/** 判断是否是从一键配置界面传过去的 */
|
||||
isAirLink = getIntent().getBooleanExtra("isAirLink", false);
|
||||
|
||||
initView();
|
||||
initEvent();
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
tvReady = (TextView) findViewById(R.id.tvReady);
|
||||
tvDeviceTips = (TextView) findViewById(R.id.tvDeviceTip);
|
||||
btnNext = (Button) findViewById(R.id.btnNext);
|
||||
ivReady = (ImageView) findViewById(R.id.ivReady);
|
||||
SpannableString spannableString = new SpannableString(getString(R.string.common_ready_message));
|
||||
if (AssetsUtils.isZh(this)) {
|
||||
spannableString.setSpan(new ForegroundColorSpan(Color.parseColor("#FF9500")), 9, 14, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
} else {
|
||||
spannableString.setSpan(new ForegroundColorSpan(Color.parseColor("#FF9500")), 28, 45, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
}
|
||||
|
||||
tvReady.setText(spannableString);
|
||||
|
||||
// 配置文件部署
|
||||
btnNext.setBackgroundDrawable(GosDeploy.appConfig_BackgroundColor());
|
||||
btnNext.setTextColor(GosDeploy.appConfig_Contrast());
|
||||
|
||||
}
|
||||
|
||||
private void initEvent() {
|
||||
btnNext.setOnClickListener(this);
|
||||
tvDeviceTips.setOnClickListener(this);
|
||||
ivReady.setOnClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
switch (v.getId()) {
|
||||
|
||||
case R.id.btnNext:
|
||||
if (ToolUtils.noDoubleClick()) {
|
||||
sum = 0;
|
||||
Intent intent2 = new Intent(GosDeviceReadyActivity.this, GosChooseDeviceActivity.class);
|
||||
startActivity(intent2);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 屏蔽掉返回键
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||
sum = 0;
|
||||
if (isAirLink) {
|
||||
Intent intent = new Intent(GosDeviceReadyActivity.this, GosMainActivity.class);
|
||||
startActivity(intent);
|
||||
} else {
|
||||
finish();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
sum = 0;
|
||||
if (isAirLink) {
|
||||
Intent intent = new Intent(GosDeviceReadyActivity.this, GosMainActivity.class);
|
||||
startActivity(intent);
|
||||
} else {
|
||||
finish();
|
||||
}
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,143 +0,0 @@
|
||||
package com.gizwits.opensource.appkit.ConfigModule;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.CompoundButton.OnCheckedChangeListener;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gizwits.opensource.appkit.R;
|
||||
import com.gizwits.opensource.appkit.CommonModule.GosDeploy;
|
||||
|
||||
public class GosDeviceResetActivity extends GosConfigModuleBaseActivity implements OnClickListener {
|
||||
|
||||
/**
|
||||
* The cb Select
|
||||
*/
|
||||
CheckBox cbSelect;
|
||||
|
||||
/**
|
||||
* The tv Select
|
||||
*/
|
||||
TextView tvSelect;
|
||||
|
||||
/**
|
||||
* The btn Next
|
||||
*/
|
||||
Button btnNext;
|
||||
|
||||
/**
|
||||
* The flag
|
||||
*/
|
||||
String flag;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.actvity_gos_device_reset);
|
||||
// 设置ActionBar
|
||||
setToolBar(true, R.string.reset_device);
|
||||
|
||||
initView();
|
||||
initEvent();
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
cbSelect = (CheckBox) findViewById(R.id.cbSelect);
|
||||
tvSelect = (TextView) findViewById(R.id.tvSelect);
|
||||
btnNext = (Button) findViewById(R.id.btnNext);
|
||||
|
||||
|
||||
/** 加载标志位 */
|
||||
flag = getIntent().getStringExtra("flag").toString();
|
||||
|
||||
// 配置文件部署
|
||||
btnNext.setBackgroundDrawable(GosDeploy.appConfig_BackgroundColor());
|
||||
btnNext.setTextColor(GosDeploy.appConfig_Contrast());
|
||||
|
||||
}
|
||||
|
||||
private void initEvent() {
|
||||
btnNext.setOnClickListener(this);
|
||||
tvSelect.setOnClickListener(this);
|
||||
btnNext.setClickable(false);
|
||||
btnNext.setBackgroundResource(R.drawable.btn_next_shape_gray);
|
||||
|
||||
cbSelect.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
||||
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
if (isChecked) {
|
||||
btnNext.setBackgroundDrawable(GosDeploy.appConfig_BackgroundColor());
|
||||
btnNext.setClickable(true);
|
||||
} else {
|
||||
btnNext.setBackgroundResource(R.drawable.btn_next_shape_gray);
|
||||
btnNext.setClickable(false);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
switch (v.getId()) {
|
||||
case R.id.btnNext:
|
||||
if (TextUtils.isEmpty(flag)) {
|
||||
Intent intent = new Intent(GosDeviceResetActivity.this, GosChooseDeviceActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
finish();
|
||||
|
||||
break;
|
||||
|
||||
case R.id.tvSelect:
|
||||
if (cbSelect.isChecked()) {
|
||||
cbSelect.setChecked(false);
|
||||
} else {
|
||||
cbSelect.setChecked(true);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
if (TextUtils.isEmpty(flag)) {
|
||||
Intent intent = new Intent(GosDeviceResetActivity.this, GosDeviceReadyActivity.class);
|
||||
startActivity(intent);
|
||||
overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right);
|
||||
}
|
||||
this.finish();
|
||||
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||
if (TextUtils.isEmpty(flag)) {
|
||||
Intent intent = new Intent(GosDeviceResetActivity.this, GosDeviceReadyActivity.class);
|
||||
startActivity(intent);
|
||||
overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right);
|
||||
}
|
||||
this.finish();
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,222 +0,0 @@
|
||||
package com.gizwits.opensource.appkit.ConfigModule;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.gizwits.opensource.appkit.R;
|
||||
import com.gizwits.opensource.appkit.CommonModule.GosDeploy;
|
||||
import com.gizwits.opensource.appkit.utils.ToolUtils;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class GosModeListActivity extends GosConfigModuleBaseActivity {
|
||||
|
||||
/**
|
||||
* The lv Mode
|
||||
*/
|
||||
ListView lvMode;
|
||||
|
||||
/**
|
||||
* The data
|
||||
*/
|
||||
List<String> modeList;
|
||||
|
||||
/**
|
||||
* The Adapter
|
||||
*/
|
||||
ModeListAdapter modeListAdapter;
|
||||
|
||||
List<Integer> list = new ArrayList<Integer>();
|
||||
|
||||
private Button btnOk;
|
||||
|
||||
private boolean isAirlink = true;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_gos_modelist);
|
||||
// 设置ActionBar
|
||||
setToolBar(true, R.string.choose_mode_start);
|
||||
final Drawable add = getResources().getDrawable(R.drawable.config_help_button);
|
||||
int color = GosDeploy.appConfig_Contrast();
|
||||
add.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
|
||||
mToolbar.setOverflowIcon(add);
|
||||
initData();
|
||||
initView();
|
||||
initEvent();
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
lvMode = (ListView) findViewById(R.id.lvMode);
|
||||
|
||||
lvMode.setAdapter(modeListAdapter);// 初始化
|
||||
|
||||
btnOk = (Button) findViewById(R.id.btnOk);
|
||||
btnOk.setBackgroundDrawable(GosDeploy.appConfig_BackgroundColor());
|
||||
btnOk.setTextColor(GosDeploy.appConfig_Contrast());
|
||||
|
||||
}
|
||||
|
||||
private void initEvent() {
|
||||
|
||||
lvMode.setOnItemClickListener(new OnItemClickListener() {
|
||||
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
|
||||
modeListAdapter.selectIndex = arg2;
|
||||
modeListAdapter.notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
|
||||
btnOk.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (ToolUtils.noDoubleClick()) {
|
||||
if (modeListAdapter.selectIndex == 100) {
|
||||
Toast.makeText(GosModeListActivity.this, getString(R.string.selece_module_type), toastTime).show();
|
||||
} else {
|
||||
JSONArray array = new JSONArray();
|
||||
array.put(modeListAdapter.selectIndex);
|
||||
spf.edit().putString("modulestyles", array.toString()).commit();
|
||||
if (isAirlink) {
|
||||
// config_airlink-false-start
|
||||
Intent intent = new Intent(GosModeListActivity.this, GosAirlinkReadyActivity.class);
|
||||
startActivity(intent);
|
||||
// config_airlink-false-end
|
||||
} else {
|
||||
//config_softap-false-start
|
||||
Intent intent = new Intent(GosModeListActivity.this, GosDeviceReadyActivity.class);
|
||||
startActivity(intent);
|
||||
//config_softap-false-end
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initData() {
|
||||
isAirlink = getIntent().getBooleanExtra("isAirlink", true);
|
||||
modeList = new ArrayList<String>();
|
||||
String[] modes = this.getResources().getStringArray(R.array.mode);
|
||||
for (String string : modes) {
|
||||
modeList.add(string);
|
||||
}
|
||||
modeListAdapter = new ModeListAdapter(this, modeList);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.module_style, menu);
|
||||
return super.onCreateOptionsMenu(menu);
|
||||
}
|
||||
|
||||
class ModeListAdapter extends BaseAdapter {
|
||||
|
||||
Context context;
|
||||
List<String> modeList;
|
||||
int selectIndex = 100;
|
||||
|
||||
public ModeListAdapter(Context context, List<String> modeList) {
|
||||
super();
|
||||
this.context = context;
|
||||
this.modeList = modeList;
|
||||
if (spf.getString("modulestyles", null) != null) {
|
||||
try {
|
||||
JSONArray array = new JSONArray(spf.getString("modulestyles", null));
|
||||
for (int i = 0; i < array.length(); i++) {
|
||||
selectIndex = Integer.parseInt(array.get(i).toString());
|
||||
}
|
||||
} catch(JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return modeList.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int position) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
if (null == convertView) {
|
||||
convertView = View.inflate(context, R.layout.item_gos_mode_list, null);
|
||||
}
|
||||
|
||||
TextView tvModeText = (TextView) convertView.findViewById(R.id.tvModeText);
|
||||
|
||||
String modeText = modeList.get(position);
|
||||
tvModeText.setText(modeText);
|
||||
|
||||
ImageView ivChoosed = (ImageView) convertView.findViewById(R.id.ivChoosed);
|
||||
if (selectIndex == position) {
|
||||
ivChoosed.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
ivChoosed.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
|
||||
return convertView;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
this.finish();
|
||||
overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right);
|
||||
break;
|
||||
case R.id.module_help:
|
||||
if (ToolUtils.noDoubleClick()) {
|
||||
startActivity(new Intent(GosModeListActivity.this, GosChooseModuleHelpActivity.class));
|
||||
}
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
// Intent intent = new Intent(this, GosAirlinkChooseDeviceWorkWiFiActivity.class);
|
||||
// startActivity(intent);
|
||||
// overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right);
|
||||
// this.finish();
|
||||
// return true;
|
||||
// }
|
||||
|
||||
}
|
@ -1,219 +0,0 @@
|
||||
package com.gizwits.opensource.appkit.ConfigModule;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.gizwits.opensource.appkit.R;
|
||||
import com.gizwits.opensource.appkit.CommonModule.GosDeploy;
|
||||
import com.gizwits.opensource.appkit.utils.ToolUtils;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class GosModeListActivity2 extends GosConfigModuleBaseActivity {
|
||||
|
||||
/**
|
||||
* The lv Mode
|
||||
*/
|
||||
ListView lvMode;
|
||||
|
||||
/**
|
||||
* The data
|
||||
*/
|
||||
List<String> modeList;
|
||||
|
||||
/**
|
||||
* The Adapter
|
||||
*/
|
||||
ModeListAdapter modeListAdapter;
|
||||
|
||||
List<Integer> list = new ArrayList<Integer>();
|
||||
|
||||
private Button btnOk;
|
||||
private boolean isAirlink = true;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_gos_modelist);
|
||||
// 设置ActionBar
|
||||
setToolBar(true, R.string.choose_mode_start);
|
||||
initData();
|
||||
initView();
|
||||
initEvent();
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
lvMode = (ListView) findViewById(R.id.lvMode);
|
||||
|
||||
lvMode.setAdapter(modeListAdapter);// 初始化
|
||||
|
||||
btnOk = (Button) findViewById(R.id.btnOk);
|
||||
btnOk.setBackgroundDrawable(GosDeploy.appConfig_BackgroundColor());
|
||||
btnOk.setTextColor(GosDeploy.appConfig_Contrast());
|
||||
}
|
||||
|
||||
private void initEvent() {
|
||||
|
||||
lvMode.setOnItemClickListener(new OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
|
||||
boolean isRemove = false;
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
if (list.get(i) == arg2) {
|
||||
list.remove(i);
|
||||
isRemove = true;
|
||||
}
|
||||
}
|
||||
if (!isRemove) {
|
||||
list.add(arg2);
|
||||
}
|
||||
modeListAdapter.notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
btnOk.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (ToolUtils.noDoubleClick()) {
|
||||
if (list.size() == 0) {
|
||||
Toast.makeText(GosModeListActivity2.this, getString(R.string.selece_module_type), toastTime).show();
|
||||
} else {
|
||||
JSONArray array = new JSONArray();
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
array.put(list.get(i));
|
||||
}
|
||||
Log.e("TAG", "onClick: " + array.toString());
|
||||
spf.edit().putString("modulestyles", array.toString()).commit();
|
||||
if (isAirlink) {
|
||||
// config_airlink-false-start
|
||||
Intent intent = new Intent(GosModeListActivity2.this, GosAirlinkReadyActivity.class);
|
||||
startActivity(intent);
|
||||
// config_airlink-false-end
|
||||
} else {
|
||||
//config_softap-false-start
|
||||
Intent intent = new Intent(GosModeListActivity2.this, GosDeviceReadyActivity.class);
|
||||
startActivity(intent);
|
||||
//config_softap-false-end
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initData() {
|
||||
isAirlink = getIntent().getBooleanExtra("isAirlink", true);
|
||||
String modules = spf.getString("modulestyles", null);
|
||||
if (modules != null) {
|
||||
try {
|
||||
JSONArray array = new JSONArray(modules);
|
||||
for (int i = 0; i < array.length(); i++) {
|
||||
int type = (Integer) array.get(i);
|
||||
list.add(type);
|
||||
}
|
||||
} catch(JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
modeList = new ArrayList<String>();
|
||||
String[] modes = this.getResources().getStringArray(R.array.mode);
|
||||
for (String string : modes) {
|
||||
modeList.add(string);
|
||||
}
|
||||
modeListAdapter = new ModeListAdapter(this, modeList);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.module_style, menu);
|
||||
MenuItem menuItem = menu.findItem(R.id.module_help);
|
||||
menuItem.setIcon(ToolUtils.editIcon(getResources(), R.drawable.config_help_button));
|
||||
return super.onCreateOptionsMenu(menu);
|
||||
}
|
||||
|
||||
class ModeListAdapter extends BaseAdapter {
|
||||
|
||||
Context context;
|
||||
List<String> modeList;
|
||||
|
||||
public ModeListAdapter(Context context, List<String> modeList) {
|
||||
super();
|
||||
this.context = context;
|
||||
this.modeList = modeList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return modeList.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int position) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
if (null == convertView) {
|
||||
convertView = View.inflate(context, R.layout.item_gos_mode_list, null);
|
||||
}
|
||||
|
||||
TextView tvModeText = (TextView) convertView.findViewById(R.id.tvModeText);
|
||||
|
||||
String modeText = modeList.get(position);
|
||||
tvModeText.setText(modeText);
|
||||
|
||||
ImageView ivChoosed = (ImageView) convertView.findViewById(R.id.ivChoosed);
|
||||
if (list.contains(position)) {
|
||||
ivChoosed.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
ivChoosed.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
return convertView;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
this.finish();
|
||||
overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right);
|
||||
break;
|
||||
case R.id.module_help:
|
||||
if (ToolUtils.noDoubleClick()) {
|
||||
startActivity(new Intent(GosModeListActivity2.this, GosChooseModuleHelpActivity.class));
|
||||
}
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
package com.gizwits.opensource.appkit.ConfigModule;
|
||||
|
||||
import com.gizwits.opensource.appkit.CommonModule.GosBaseActivity;
|
||||
import com.gizwits.opensource.appkit.utils.NetUtils;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.wifi.WifiManager;
|
||||
|
||||
|
||||
public class GosWifiChangeReciver extends BroadcastReceiver {
|
||||
|
||||
SharedPreferences spf;
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
|
||||
spf = context.getSharedPreferences(GosBaseActivity.SPF_Name, Context.MODE_PRIVATE);
|
||||
|
||||
String wifiname = spf.getString("workSSID", "");
|
||||
String wifipass = spf.getString("workSSIDPsw", "");
|
||||
String connectWifiSsid = NetUtils.getConnectWifiSsid(context);
|
||||
if (connectWifiSsid != null && connectWifiSsid.contains(GosBaseActivity.SoftAP_Start)) {
|
||||
} else {
|
||||
if (connectWifiSsid.contains(wifiname)) {
|
||||
return;
|
||||
}
|
||||
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
||||
WifiAutoConnectManager manager = new WifiAutoConnectManager(wifiManager);
|
||||
manager.connect(wifiname, wifipass, WifiAutoConnectManager.getCipherType(context, wifiname));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
@ -1,735 +0,0 @@
|
||||
package com.gizwits.opensource.appkit.DeviceModule;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
|
||||
import com.gizwits.opensource.appkit.R;
|
||||
import com.gizwits.gizwifisdk.enumration.GizWifiErrorCode;
|
||||
|
||||
/**
|
||||
* author: smile .
|
||||
* date: On 2018/6/7
|
||||
*/
|
||||
public class GosBaseFragment extends Fragment {
|
||||
/**
|
||||
* 存储器
|
||||
*/
|
||||
public SharedPreferences spf;
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
spf = getActivity().getSharedPreferences("set", Context.MODE_PRIVATE);
|
||||
}
|
||||
public String toastError(GizWifiErrorCode errorCode) {
|
||||
String errorString = (String) getText(R.string.UNKNOWN_ERROR);
|
||||
switch (errorCode) {
|
||||
case GIZ_SDK_SUCCESS:
|
||||
errorString=(String)getText(R.string.GIZ_SDK_SUCCESS);
|
||||
break;
|
||||
case GIZ_SDK_PARAM_FORM_INVALID:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_PARAM_FORM_INVALID);
|
||||
break;
|
||||
case GIZ_SDK_CLIENT_NOT_AUTHEN:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_CLIENT_NOT_AUTHEN);
|
||||
break;
|
||||
case GIZ_SDK_CLIENT_VERSION_INVALID:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_CLIENT_VERSION_INVALID);
|
||||
break;
|
||||
case GIZ_SDK_UDP_PORT_BIND_FAILED:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_UDP_PORT_BIND_FAILED);
|
||||
break;
|
||||
case GIZ_SDK_DAEMON_EXCEPTION:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_DAEMON_EXCEPTION);
|
||||
break;
|
||||
case GIZ_SDK_PARAM_INVALID:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_PARAM_INVALID);
|
||||
break;
|
||||
case GIZ_SDK_APPID_LENGTH_ERROR:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_APPID_LENGTH_ERROR);
|
||||
break;
|
||||
case GIZ_SDK_LOG_PATH_INVALID:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_LOG_PATH_INVALID);
|
||||
break;
|
||||
case GIZ_SDK_LOG_LEVEL_INVALID:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_LOG_LEVEL_INVALID);
|
||||
break;
|
||||
case GIZ_SDK_UID_INVALID:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_UID_INVALID);
|
||||
break;
|
||||
case GIZ_SDK_TOKEN_INVALID:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_TOKEN_INVALID);
|
||||
break;
|
||||
case GIZ_SDK_USER_NOT_LOGIN:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_USER_NOT_LOGIN);
|
||||
break;
|
||||
case GIZ_SDK_APPID_INVALID:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_APPID_INVALID);
|
||||
break;
|
||||
case GIZ_SDK_APP_SECRET_INVALID:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_APP_SECRET_INVALID);
|
||||
break;
|
||||
case GIZ_SDK_PRODUCT_KEY_INVALID:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_PRODUCT_KEY_INVALID);
|
||||
break;
|
||||
case GIZ_SDK_PRODUCT_SECRET_INVALID:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_PRODUCT_SECRET_INVALID);
|
||||
break;
|
||||
case GIZ_SDK_DEVICE_NOT_IN_LAN:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_DEVICE_NOT_IN_LAN);
|
||||
break;
|
||||
case GIZ_SDK_PRODUCTKEY_NOT_IN_SPECIAL_LIST:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_PRODUCTKEY_NOT_IN_SPECIAL_LIST);
|
||||
break;
|
||||
case GIZ_SDK_PRODUCTKEY_NOT_RELATED_WITH_APPID:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_PRODUCTKEY_NOT_RELATED_WITH_APPID);
|
||||
break;
|
||||
case GIZ_SDK_NO_AVAILABLE_DEVICE:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_NO_AVAILABLE_DEVICE);
|
||||
break;
|
||||
case GIZ_SDK_DEVICE_CONFIG_SEND_FAILED:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_DEVICE_CONFIG_SEND_FAILED);
|
||||
break;
|
||||
case GIZ_SDK_DEVICE_CONFIG_IS_RUNNING:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_DEVICE_CONFIG_IS_RUNNING);
|
||||
break;
|
||||
case GIZ_SDK_DEVICE_CONFIG_TIMEOUT:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_DEVICE_CONFIG_TIMEOUT);
|
||||
break;
|
||||
case GIZ_SDK_DEVICE_DID_INVALID:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_DEVICE_DID_INVALID);
|
||||
break;
|
||||
case GIZ_SDK_DEVICE_MAC_INVALID:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_DEVICE_MAC_INVALID);
|
||||
break;
|
||||
case GIZ_SDK_SUBDEVICE_INVALID:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_SUBDEVICE_INVALID);
|
||||
break;
|
||||
case GIZ_SDK_DEVICE_PASSCODE_INVALID:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_DEVICE_PASSCODE_INVALID);
|
||||
break;
|
||||
case GIZ_SDK_DEVICE_NOT_CENTERCONTROL:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_DEVICE_NOT_CENTERCONTROL);
|
||||
break;
|
||||
case GIZ_SDK_DEVICE_NOT_SUBSCRIBED:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_DEVICE_NOT_SUBSCRIBED);
|
||||
break;
|
||||
case GIZ_SDK_DEVICE_NO_RESPONSE:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_DEVICE_NO_RESPONSE);
|
||||
break;
|
||||
case GIZ_SDK_DEVICE_NOT_READY:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_DEVICE_NOT_READY);
|
||||
break;
|
||||
case GIZ_SDK_DEVICE_NOT_BINDED:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_DEVICE_NOT_BINDED);
|
||||
break;
|
||||
case GIZ_SDK_DEVICE_CONTROL_WITH_INVALID_COMMAND:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_DEVICE_CONTROL_WITH_INVALID_COMMAND);
|
||||
break;
|
||||
// case GIZ_SDK_DEVICE_CONTROL_FAILED:
|
||||
// errorString= (String) getText(R.string.GIZ_SDK_DEVICE_CONTROL_FAILED);
|
||||
// break;
|
||||
case GIZ_SDK_DEVICE_GET_STATUS_FAILED:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_DEVICE_GET_STATUS_FAILED);
|
||||
break;
|
||||
case GIZ_SDK_DEVICE_CONTROL_VALUE_TYPE_ERROR:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_DEVICE_CONTROL_VALUE_TYPE_ERROR);
|
||||
break;
|
||||
case GIZ_SDK_DEVICE_CONTROL_VALUE_OUT_OF_RANGE:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_DEVICE_CONTROL_VALUE_OUT_OF_RANGE);
|
||||
break;
|
||||
case GIZ_SDK_DEVICE_CONTROL_NOT_WRITABLE_COMMAND:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_DEVICE_CONTROL_NOT_WRITABLE_COMMAND);
|
||||
break;
|
||||
case GIZ_SDK_BIND_DEVICE_FAILED:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_BIND_DEVICE_FAILED);
|
||||
break;
|
||||
case GIZ_SDK_UNBIND_DEVICE_FAILED:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_UNBIND_DEVICE_FAILED);
|
||||
break;
|
||||
case GIZ_SDK_DNS_FAILED:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_DNS_FAILED);
|
||||
break;
|
||||
case GIZ_SDK_M2M_CONNECTION_SUCCESS:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_M2M_CONNECTION_SUCCESS);
|
||||
break;
|
||||
case GIZ_SDK_SET_SOCKET_NON_BLOCK_FAILED:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_SET_SOCKET_NON_BLOCK_FAILED);
|
||||
break;
|
||||
case GIZ_SDK_CONNECTION_TIMEOUT:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_CONNECTION_TIMEOUT);
|
||||
break;
|
||||
case GIZ_SDK_CONNECTION_REFUSED:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_CONNECTION_REFUSED);
|
||||
break;
|
||||
case GIZ_SDK_CONNECTION_ERROR:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_CONNECTION_ERROR);
|
||||
break;
|
||||
case GIZ_SDK_CONNECTION_CLOSED:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_CONNECTION_CLOSED);
|
||||
break;
|
||||
case GIZ_SDK_SSL_HANDSHAKE_FAILED:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_SSL_HANDSHAKE_FAILED);
|
||||
break;
|
||||
case GIZ_SDK_DEVICE_LOGIN_VERIFY_FAILED:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_DEVICE_LOGIN_VERIFY_FAILED);
|
||||
break;
|
||||
case GIZ_SDK_INTERNET_NOT_REACHABLE:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_INTERNET_NOT_REACHABLE);
|
||||
break;
|
||||
case GIZ_SDK_M2M_CONNECTION_FAILED:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_M2M_CONNECTION_FAILED);
|
||||
break;
|
||||
case GIZ_SDK_HTTP_SERVER_NOT_SUPPORT_API:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_HTTP_SERVER_NOT_SUPPORT_API);
|
||||
break;
|
||||
case GIZ_SDK_HTTP_ANSWER_FORMAT_ERROR:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_HTTP_ANSWER_FORMAT_ERROR);
|
||||
break;
|
||||
case GIZ_SDK_HTTP_ANSWER_PARAM_ERROR:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_HTTP_ANSWER_PARAM_ERROR);
|
||||
break;
|
||||
case GIZ_SDK_HTTP_SERVER_NO_ANSWER:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_HTTP_SERVER_NO_ANSWER);
|
||||
break;
|
||||
case GIZ_SDK_HTTP_REQUEST_FAILED:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_HTTP_REQUEST_FAILED);
|
||||
break;
|
||||
case GIZ_SDK_OTHERWISE:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_OTHERWISE);
|
||||
break;
|
||||
case GIZ_SDK_MEMORY_MALLOC_FAILED:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_MEMORY_MALLOC_FAILED);
|
||||
break;
|
||||
case GIZ_SDK_THREAD_CREATE_FAILED:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_THREAD_CREATE_FAILED);
|
||||
break;
|
||||
case GIZ_SDK_JSON_OBJECT_CREATE_FAILED:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_JSON_OBJECT_CREATE_FAILED);
|
||||
break;
|
||||
case GIZ_SDK_JSON_PARSE_FAILED:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_JSON_PARSE_FAILED);
|
||||
break;
|
||||
case GIZ_SDK_SCHEDULER_CREATE_FAILED:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_SCHEDULER_CREATE_FAILED);
|
||||
break;
|
||||
case GIZ_SDK_SCHEDULER_DELETE_FAILED:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_SCHEDULER_DELETE_FAILED);
|
||||
break;
|
||||
case GIZ_SDK_SCHEDULER_EDIT_FAILED:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_SCHEDULER_EDIT_FAILED);
|
||||
break;
|
||||
case GIZ_SDK_SCHEDULER_LIST_UPDATE_FAILED:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_SCHEDULER_LIST_UPDATE_FAILED);
|
||||
break;
|
||||
case GIZ_SDK_SCHEDULER_TASK_EDIT_FAILED:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_SCHEDULER_TASK_EDIT_FAILED);
|
||||
break;
|
||||
case GIZ_SDK_SCHEDULER_TASK_LIST_UPDATE_FAILED:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_SCHEDULER_TASK_LIST_UPDATE_FAILED);
|
||||
break;
|
||||
case GIZ_SDK_SCHEDULER_ID_INVALID:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_SCHEDULER_ID_INVALID);
|
||||
break;
|
||||
case GIZ_SDK_SCHEDULER_ENABLE_DISABLE_FAILED:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_SCHEDULER_ENABLE_DISABLE_FAILED);
|
||||
break;
|
||||
case GIZ_SDK_SCHEDULER_STATUS_UPDATE_FAILED:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_SCHEDULER_STATUS_UPDATE_FAILED);
|
||||
break;
|
||||
case GIZ_SDK_GROUP_ID_INVALID:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_GROUP_ID_INVALID);
|
||||
break;
|
||||
case GIZ_SDK_GROUP_FAILED_DELETE_DEVICE:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_GROUP_FAILED_DELETE_DEVICE);
|
||||
break;
|
||||
case GIZ_SDK_GROUP_FAILED_ADD_DEVICE:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_GROUP_FAILED_ADD_DEVICE);
|
||||
break;
|
||||
case GIZ_SDK_GROUP_PRODUCTKEY_INVALID:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_GROUP_PRODUCTKEY_INVALID);
|
||||
break;
|
||||
case GIZ_SDK_GROUP_CREATE_FAILED:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_GROUP_CREATE_FAILED);
|
||||
break;
|
||||
case GIZ_SDK_GROUP_DELETE_FAILED:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_GROUP_FAILED_DELETE_DEVICE);
|
||||
break;
|
||||
case GIZ_SDK_GROUP_EDIT_FAILED:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_GROUP_EDIT_FAILED);
|
||||
break;
|
||||
case GIZ_SDK_GROUP_LIST_UPDATE_FAILED:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_GROUP_GET_DEVICE_FAILED);
|
||||
break;
|
||||
case GIZ_SDK_SCENE_CREATE_FAILED:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_SCENE_CREATE_FAILED);
|
||||
break;
|
||||
case GIZ_SDK_SCENE_DELETE_FAILED:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_SCENE_DELETE_FAILED);
|
||||
break;
|
||||
case GIZ_SDK_SCENE_EDIT_FAILED:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_SCENE_EDIT_FAILED);
|
||||
break;
|
||||
case GIZ_SDK_SCENE_LIST_UPDATE_FAILED:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_SCENE_LIST_UPDATE_FAILED);
|
||||
break;
|
||||
case GIZ_SDK_SCENE_ITEM_LIST_EDIT_FAILED:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_SCENE_ITEM_LIST_EDIT_FAILED);
|
||||
break;
|
||||
case GIZ_SDK_SCENE_ITEM_LIST_UPDATE_FAILED:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_SCENE_ITEM_LIST_UPDATE_FAILED);
|
||||
break;
|
||||
case GIZ_SDK_SCENE_ID_INVALID:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_SCENE_ID_INVALID);
|
||||
break;
|
||||
case GIZ_SDK_SCENE_RUN_FAILED:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_SCENE_RUN_FAILED);
|
||||
break;
|
||||
case GIZ_SDK_SCENE_STATUS_UPDATE_FAILED:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_SCENE_STATUS_UPDATE_FAILED);
|
||||
break;
|
||||
case GIZ_SDK_JOINT_ACTION_CREATE_FAILED:
|
||||
errorString= (String) getText(R.string.GIZ_SDK_JOINT_ACTION_CREATE_FAILED);
|
||||
break;
|
||||
case GIZ_SDK_JOINT_ACTION_DELETE_FAILED:
|
||||
errorString= (String) getText(R.string.GIZ_SDK_JOINT_ACTION_DELETE_FAILED);
|
||||
break;
|
||||
case GIZ_SDK_JOINT_ACTION_VER_UNSUPPORTED:
|
||||
errorString= (String) getText(R.string.GIZ_SDK_JOINT_ACTION_VER_UNSUPPORTED);
|
||||
break;
|
||||
// case GIZ_SDK_JOINT_ACTION_INVALID_CONDITION_TYPE:
|
||||
// errorString= (String) getText(R.string.GIZ_SDK_JOINT_ACTION_INVALID_CONDITION_TYPE);
|
||||
// break;
|
||||
// case GIZ_SDK_JOINT_ACTION_INVALID_RESULT_EVENT_TYPE:
|
||||
// errorString= (String) getText(R.string.GIZ_SDK_JOINT_ACTION_INVALID_RESULT_EVENT_TYPE);
|
||||
// break;
|
||||
case GIZ_SDK_DATAPOINT_NOT_DOWNLOAD:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_DATAPOINT_NOT_DOWNLOAD);
|
||||
break;
|
||||
case GIZ_SDK_DATAPOINT_SERVICE_UNAVAILABLE:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_DATAPOINT_SERVICE_UNAVAILABLE);
|
||||
break;
|
||||
case GIZ_SDK_DATAPOINT_PARSE_FAILED:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_DATAPOINT_PARSE_FAILED);
|
||||
break;
|
||||
// case GIZ_SDK_NOT_INITIALIZED:
|
||||
// errorString= (String) getText(R.string.GIZ_SDK_SDK_NOT_INITIALIZED);
|
||||
// break;
|
||||
case GIZ_SDK_APK_CONTEXT_IS_NULL:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_APK_CONTEXT_IS_NULL);
|
||||
break;
|
||||
case GIZ_SDK_APK_PERMISSION_NOT_SET:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_APK_PERMISSION_NOT_SET);
|
||||
break;
|
||||
case GIZ_SDK_CHMOD_DAEMON_REFUSED:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_CHMOD_DAEMON_REFUSED);
|
||||
break;
|
||||
case GIZ_SDK_EXEC_DAEMON_FAILED:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_EXEC_DAEMON_FAILED);
|
||||
break;
|
||||
case GIZ_SDK_EXEC_CATCH_EXCEPTION:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_EXEC_CATCH_EXCEPTION);
|
||||
break;
|
||||
case GIZ_SDK_APPID_IS_EMPTY:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_APPID_IS_EMPTY);
|
||||
break;
|
||||
case GIZ_SDK_UNSUPPORTED_API:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_UNSUPPORTED_API);
|
||||
break;
|
||||
case GIZ_SDK_REQUEST_TIMEOUT:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_REQUEST_TIMEOUT);
|
||||
break;
|
||||
case GIZ_SDK_DAEMON_VERSION_INVALID:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_DAEMON_VERSION_INVALID);
|
||||
break;
|
||||
case GIZ_SDK_PHONE_NOT_CONNECT_TO_SOFTAP_SSID:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_PHONE_NOT_CONNECT_TO_SOFTAP_SSID);
|
||||
break;
|
||||
case GIZ_SDK_DEVICE_CONFIG_SSID_NOT_MATCHED:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_DEVICE_CONFIG_SSID_NOT_MATCHED);
|
||||
break;
|
||||
case GIZ_SDK_NOT_IN_SOFTAPMODE:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_NOT_IN_SOFTAPMODE);
|
||||
break;
|
||||
// case GIZ_SDK_PHONE_WIFI_IS_UNAVAILABLE:
|
||||
// errorString= (String)getText(R.string.GIZ_SDK_PHONE_WIFI_IS_UNAVAILABLE);
|
||||
// break;
|
||||
case GIZ_SDK_RAW_DATA_TRANSMIT:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_RAW_DATA_TRANSMIT);
|
||||
break;
|
||||
case GIZ_SDK_PRODUCT_IS_DOWNLOADING:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_PRODUCT_IS_DOWNLOADING);
|
||||
break;
|
||||
case GIZ_SDK_START_SUCCESS:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_START_SUCCESS);
|
||||
break;
|
||||
case GIZ_SDK_NEED_UPDATE_TO_LATEST:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_NEED_UPDATE_TO_LATEST);
|
||||
break;
|
||||
case GIZ_SDK_ONBOARDING_STOPPED:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_ONBOARDING_STOPPED);
|
||||
break;
|
||||
case GIZ_SDK_ONBOARDING_WIFI_IS_5G:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_ONBOARDING_WIFI_IS_5G);
|
||||
break;
|
||||
case GIZ_SDK_OTA_FIRMWARE_IS_LATEST:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_OTA_FIRMWARE_IS_LATEST);
|
||||
break;
|
||||
case GIZ_SDK_OTA_FIRMWARE_CHECK_UPDATE_FAILED:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_OTA_FIRMWARE_CHECK_UPDATE_FAILED);
|
||||
break;
|
||||
case GIZ_SDK_OTA_FIRMWARE_DOWNLOAD_OK:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_OTA_FIRMWARE_DOWNLOAD_OK);
|
||||
break;
|
||||
case GIZ_SDK_OTA_FIRMWARE_DOWNLOAD_FAILED:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_OTA_FIRMWARE_DOWNLOAD_FAILED);
|
||||
break;
|
||||
case GIZ_SDK_OTA_DEVICE_BUSY_IN_UPGRADE:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_OTA_DEVICE_BUSY_IN_UPGRADE);
|
||||
break;
|
||||
case GIZ_SDK_OTA_PUSH_FAILED:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_OTA_PUSH_FAILED);
|
||||
break;
|
||||
case GIZ_SDK_OTA_FIRMWARE_VERSION_TOO_LOW:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_OTA_FIRMWARE_VERSION_TOO_LOW);
|
||||
break;
|
||||
case GIZ_SDK_OTA_FIRMWARE_CHECK_FAILED:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_OTA_FIRMWARE_CHECK_FAILED);
|
||||
break;
|
||||
case GIZ_SDK_OTA_UPGRADE_FAILED:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_OTA_UPGRADE_FAILED);
|
||||
break;
|
||||
case GIZ_SDK_OTA_FIRMWARE_VERIFY_SUCCESS:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_OTA_FIRMWARE_VERIFY_SUCCESS);
|
||||
break;
|
||||
case GIZ_SDK_OTA_DEVICE_NOT_SUPPORT:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_OTA_DEVICE_NOT_SUPPORT);
|
||||
break;
|
||||
case GIZ_SDK_WS_HANDSHAKE_FAILED:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_WS_HANDSHAKE_FAILED);
|
||||
break;
|
||||
case GIZ_SDK_WS_LOGIN_FAILED:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_WS_LOGIN_FAILED);
|
||||
break;
|
||||
// case GIZ_SDK_WS_DEVICE_SUBSCRIBE_FAILED:
|
||||
// errorString = (String) getText(R.string.GIZ_SDK_WS_DEVICE_SUBSCRIBE_FAILED);
|
||||
// break;
|
||||
// case GIZ_SDK_WS_DEVICE_UNSUBSCRIBE_FAILED:
|
||||
// errorString = (String) getText(R.string.GIZ_SDK_WS_DEVICE_UNSUBSCRIBE_FAILED);
|
||||
// break;
|
||||
case GIZ_SITE_PRODUCTKEY_INVALID:
|
||||
errorString = (String) getText(R.string.GIZ_SITE_PRODUCTKEY_INVALID);
|
||||
break;
|
||||
case GIZ_SITE_DATAPOINTS_NOT_DEFINED:
|
||||
errorString = (String) getText(R.string.GIZ_SITE_DATAPOINTS_NOT_DEFINED);
|
||||
break;
|
||||
case GIZ_SITE_DATAPOINTS_NOT_MALFORME:
|
||||
errorString = (String) getText(R.string.GIZ_SITE_DATAPOINTS_NOT_MALFORME);
|
||||
break;
|
||||
case GIZ_OPENAPI_MAC_ALREADY_REGISTERED:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_MAC_ALREADY_REGISTERED);
|
||||
break;
|
||||
case GIZ_OPENAPI_PRODUCT_KEY_INVALID:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_PRODUCT_KEY_INVALID);
|
||||
break;
|
||||
case GIZ_OPENAPI_APPID_INVALID:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_APPID_INVALID);
|
||||
break;
|
||||
case GIZ_OPENAPI_TOKEN_INVALID:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_TOKEN_INVALID);
|
||||
break;
|
||||
case GIZ_OPENAPI_USER_NOT_EXIST:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_USER_NOT_EXIST);
|
||||
break;
|
||||
case GIZ_OPENAPI_TOKEN_EXPIRED:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_TOKEN_EXPIRED);
|
||||
break;
|
||||
case GIZ_OPENAPI_M2M_ID_INVALID:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_M2M_ID_INVALID);
|
||||
break;
|
||||
case GIZ_OPENAPI_SERVER_ERROR:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_SERVER_ERROR);
|
||||
break;
|
||||
case GIZ_OPENAPI_CODE_EXPIRED:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_CODE_EXPIRED);
|
||||
break;
|
||||
case GIZ_OPENAPI_CODE_INVALID:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_CODE_INVALID);
|
||||
break;
|
||||
case GIZ_OPENAPI_SANDBOX_SCALE_QUOTA_EXHAUSTED:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_SANDBOX_SCALE_QUOTA_EXHAUSTED);
|
||||
break;
|
||||
case GIZ_OPENAPI_PRODUCTION_SCALE_QUOTA_EXHAUSTED:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_PRODUCTION_SCALE_QUOTA_EXHAUSTED);
|
||||
break;
|
||||
case GIZ_OPENAPI_PRODUCT_HAS_NO_REQUEST_SCALE:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_PRODUCT_HAS_NO_REQUEST_SCALE);
|
||||
break;
|
||||
case GIZ_OPENAPI_DEVICE_NOT_FOUND:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_DEVICE_NOT_FOUND);
|
||||
break;
|
||||
case GIZ_OPENAPI_FORM_INVALID:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_FORM_INVALID);
|
||||
break;
|
||||
case GIZ_OPENAPI_DID_PASSCODE_INVALID:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_DID_PASSCODE_INVALID);
|
||||
break;
|
||||
case GIZ_OPENAPI_DEVICE_NOT_BOUND:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_DEVICE_NOT_BOUND);
|
||||
break;
|
||||
case GIZ_OPENAPI_PHONE_UNAVALIABLE:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_PHONE_UNAVALIABLE);
|
||||
break;
|
||||
case GIZ_OPENAPI_USERNAME_UNAVALIABLE:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_USERNAME_UNAVALIABLE);
|
||||
break;
|
||||
case GIZ_OPENAPI_USERNAME_PASSWORD_ERROR:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_USERNAME_PASSWORD_ERROR);
|
||||
break;
|
||||
case GIZ_OPENAPI_SEND_COMMAND_FAILED:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_SEND_COMMAND_FAILED);
|
||||
break;
|
||||
case GIZ_OPENAPI_EMAIL_UNAVALIABLE:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_EMAIL_UNAVALIABLE);
|
||||
break;
|
||||
case GIZ_OPENAPI_DEVICE_DISABLED:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_DEVICE_DISABLED);
|
||||
break;
|
||||
case GIZ_OPENAPI_FAILED_NOTIFY_M2M:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_FAILED_NOTIFY_M2M);
|
||||
break;
|
||||
case GIZ_OPENAPI_ATTR_INVALID:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_ATTR_INVALID);
|
||||
break;
|
||||
case GIZ_OPENAPI_USER_INVALID:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_USER_INVALID);
|
||||
break;
|
||||
case GIZ_OPENAPI_FIRMWARE_NOT_FOUND:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_FIRMWARE_NOT_FOUND);
|
||||
break;
|
||||
case GIZ_OPENAPI_JD_PRODUCT_NOT_FOUND:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_JD_PRODUCT_NOT_FOUND);
|
||||
break;
|
||||
case GIZ_OPENAPI_DATAPOINT_DATA_NOT_FOUND:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_DATAPOINT_DATA_NOT_FOUND);
|
||||
break;
|
||||
case GIZ_OPENAPI_SCHEDULER_NOT_FOUND:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_SCHEDULER_NOT_FOUND);
|
||||
break;
|
||||
case GIZ_OPENAPI_QQ_OAUTH_KEY_INVALID:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_QQ_OAUTH_KEY_INVALID);
|
||||
break;
|
||||
case GIZ_OPENAPI_OTA_SERVICE_OK_BUT_IN_IDLE:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_OTA_SERVICE_OK_BUT_IN_IDLE);
|
||||
break;
|
||||
case GIZ_OPENAPI_BT_FIRMWARE_UNVERIFIED:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_BT_FIRMWARE_UNVERIFIED);
|
||||
break;
|
||||
case GIZ_OPENAPI_BT_FIRMWARE_NOTHING_TO_UPGRADE:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_SAVE_KAIROSDB_ERROR);
|
||||
break;
|
||||
case GIZ_OPENAPI_SAVE_KAIROSDB_ERROR:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_SAVE_KAIROSDB_ERROR);
|
||||
break;
|
||||
case GIZ_OPENAPI_EVENT_NOT_DEFINED:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_EVENT_NOT_DEFINED);
|
||||
break;
|
||||
case GIZ_OPENAPI_SEND_SMS_FAILED:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_SEND_SMS_FAILED);
|
||||
break;
|
||||
// case GIZ_OPENAPI_APPLICATION_AUTH_INVALID:
|
||||
// errorString= (String)
|
||||
// getText(R.string.GIZ_OPENAPI_APPLICATION_AUTH_INVALID);
|
||||
// break;
|
||||
case GIZ_OPENAPI_NOT_ALLOWED_CALL_API:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_NOT_ALLOWED_CALL_API);
|
||||
break;
|
||||
case GIZ_OPENAPI_BAD_QRCODE_CONTENT:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_BAD_QRCODE_CONTENT);
|
||||
break;
|
||||
case GIZ_OPENAPI_REQUEST_THROTTLED:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_REQUEST_THROTTLED);
|
||||
break;
|
||||
case GIZ_OPENAPI_DEVICE_OFFLINE:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_DEVICE_OFFLINE);
|
||||
break;
|
||||
case GIZ_OPENAPI_TIMESTAMP_INVALID:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_TIMESTAMP_INVALID);
|
||||
break;
|
||||
case GIZ_OPENAPI_SIGNATURE_INVALID:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_SIGNATURE_INVALID);
|
||||
break;
|
||||
case GIZ_OPENAPI_DEPRECATED_API:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_DEPRECATED_API);
|
||||
break;
|
||||
case GIZ_OPENAPI_REGISTER_IS_BUSY:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_REGISTER_IS_BUSY);
|
||||
break;
|
||||
case GIZ_OPENAPI_ALTER_PASSWORD_FAILED:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_ALTER_PASSWORD_FAILED);
|
||||
break;
|
||||
case GIZ_OPENAPI_APPID_PK_NOT_RELATION:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_APPID_PK_NOT_RELATION);
|
||||
break;
|
||||
case GIZ_OPENAPI_CALL_INNER_FAILED:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_CALL_INNER_FAILED);
|
||||
break;
|
||||
case GIZ_OPENAPI_DEVICE_SHARING_NOT_ENABLED:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_DEVICE_SHARING_NOT_ENABLED);
|
||||
break;
|
||||
case GIZ_OPENAPI_NOT_FIRST_USER_OF_DEVICE:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_NOT_FIRST_USER_OF_DEVICE);
|
||||
break;
|
||||
case GIZ_OPENAPI_PRODUCT_KEY_AUTHEN_FAULT:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_PRODUCT_KEY_AUTHEN_FAULT);
|
||||
break;
|
||||
case GIZ_OPENAPI_BUSY_NOW:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_BUSY_NOW);
|
||||
break;
|
||||
case GIZ_OPENAPI_TWITTER_CONSUMER_KEY_INVALID:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_TWITTER_CONSUMER_KEY_INVALID);
|
||||
break;
|
||||
case GIZ_OPENAPI_NOT_ALLOW_WEEK_PASSWORD:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_NOT_ALLOW_WEEK_PASSWORD);
|
||||
break;
|
||||
// case GIZ_OPENAPI_CODE_NOT_EXIST:
|
||||
// errorString = (String) getText(R.string.GIZ_OPENAPI_CODE_NOT_EXIST);
|
||||
// break;
|
||||
// case GIZ_OPENAPI_EMAIL_NOT_ACTIVE:
|
||||
// errorString = (String) getText(R.string.GIZ_OPENAPI_EMAIL_NOT_ACTIVE);
|
||||
// break;
|
||||
// case GIZ_OPENAPI_EMAIL_NOT_ENABLE:
|
||||
// errorString = (String) getText(R.string.GIZ_OPENAPI_EMAIL_NOT_ENABLE);
|
||||
// break;
|
||||
// case GIZ_OPENAPI_DEVICE_REGISTER_NOT_FOUND:
|
||||
// errorString = (String) getText(R.string.GIZ_OPENAPI_DEVICE_REGISTER_NOT_FOUND);
|
||||
// break;
|
||||
case GIZ_OPENAPI_CANNOT_SHARE_TO_SELF:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_CANNOT_SHARE_TO_SELF);
|
||||
break;
|
||||
case GIZ_OPENAPI_ONLY_OWNER_CAN_SHARE:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_ONLY_OWNER_CAN_SHARE);
|
||||
break;
|
||||
case GIZ_OPENAPI_NOT_FOUND_GUEST:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_NOT_FOUND_GUEST);
|
||||
break;
|
||||
case GIZ_OPENAPI_GUEST_ALREADY_BOUND:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_GUEST_ALREADY_BOUND);
|
||||
break;
|
||||
case GIZ_OPENAPI_NOT_FOUND_SHARING_INFO:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_NOT_FOUND_SHARING_INFO);
|
||||
break;
|
||||
case GIZ_OPENAPI_NOT_FOUND_THE_MESSAGE:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_NOT_FOUND_THE_MESSAGE);
|
||||
break;
|
||||
case GIZ_OPENAPI_SHARING_IS_WAITING_FOR_ACCEPT:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_SHARING_IS_WAITING_FOR_ACCEPT);
|
||||
break;
|
||||
case GIZ_OPENAPI_SHARING_IS_EXPIRED:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_SHARING_IS_EXPIRED);
|
||||
break;
|
||||
case GIZ_OPENAPI_SHARING_IS_COMPLETED:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_SHARING_IS_COMPLETED);
|
||||
break;
|
||||
case GIZ_OPENAPI_INVALID_SHARING_BECAUSE_UNBINDING:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_INVALID_SHARING_BECAUSE_UNBINDING);
|
||||
break;
|
||||
case GIZ_OPENAPI_ONLY_OWNER_CAN_BIND:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_ONLY_OWNER_CAN_BIND);
|
||||
break;
|
||||
case GIZ_OPENAPI_ONLY_OWNER_CAN_OPERATE:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_ONLY_OWNER_CAN_OPERATE);
|
||||
break;
|
||||
case GIZ_OPENAPI_SHARING_ALREADY_CANCELLED:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_SHARING_ALREADY_CANCELLED);
|
||||
break;
|
||||
case GIZ_OPENAPI_OWNER_CANNOT_UNBIND_SELF:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_OWNER_CANNOT_UNBIND_SELF);
|
||||
break;
|
||||
case GIZ_OPENAPI_ONLY_GUEST_CAN_CHECK_QRCODE:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_ONLY_GUEST_CAN_CHECK_QRCODE);
|
||||
break;
|
||||
case GIZ_OPENAPI_MESSAGE_ALREADY_DELETED:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_MESSAGE_ALREADY_DELETED);
|
||||
break;
|
||||
case GIZ_OPENAPI_BINDING_NOTIFY_FAILED:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_BINDING_NOTIFY_FAILED);
|
||||
break;
|
||||
case GIZ_OPENAPI_ONLY_SELF_CAN_MODIFY_ALIAS:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_ONLY_SELF_CAN_MODIFY_ALIAS);
|
||||
break;
|
||||
case GIZ_OPENAPI_ONLY_RECEIVER_CAN_MARK_MESSAGE:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_ONLY_RECEIVER_CAN_MARK_MESSAGE);
|
||||
break;
|
||||
case GIZ_OPENAPI_GUEST_NOT_BIND:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_GUEST_NOT_BIND);
|
||||
break;
|
||||
case GIZ_OPENAPI_CANNOT_TRANSFER_OWNER_TO_SELF:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_CANNOT_TRANSFER_OWNER_TO_SELF);
|
||||
break;
|
||||
case GIZ_OPENAPI_TRANSFER_OWNER_TO_LIMIT_GUEST:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_TRANSFER_OWNER_TO_LIMIT_GUEST);
|
||||
break;
|
||||
case GIZ_OPENAPI_RESERVED:
|
||||
errorString = (String) getText(R.string.GIZ_OPENAPI_RESERVED);
|
||||
break;
|
||||
case GIZ_PUSHAPI_BODY_JSON_INVALID:
|
||||
errorString = (String) getText(R.string.GIZ_PUSHAPI_BODY_JSON_INVALID);
|
||||
break;
|
||||
case GIZ_PUSHAPI_DATA_NOT_EXIST:
|
||||
errorString = (String) getText(R.string.GIZ_PUSHAPI_DATA_NOT_EXIST);
|
||||
break;
|
||||
case GIZ_PUSHAPI_NO_CLIENT_CONFIG:
|
||||
errorString = (String) getText(R.string.GIZ_PUSHAPI_NO_CLIENT_CONFIG);
|
||||
break;
|
||||
case GIZ_PUSHAPI_NO_SERVER_DATA:
|
||||
errorString = (String) getText(R.string.GIZ_PUSHAPI_NO_SERVER_DATA);
|
||||
break;
|
||||
case GIZ_PUSHAPI_GIZWITS_APPID_EXIST:
|
||||
errorString = (String) getText(R.string.GIZ_PUSHAPI_GIZWITS_APPID_EXIST);
|
||||
break;
|
||||
case GIZ_PUSHAPI_PARAM_ERROR:
|
||||
errorString = (String) getText(R.string.GIZ_PUSHAPI_PARAM_ERROR);
|
||||
break;
|
||||
case GIZ_PUSHAPI_AUTH_KEY_INVALID:
|
||||
errorString = (String) getText(R.string.GIZ_PUSHAPI_AUTH_KEY_INVALID);
|
||||
break;
|
||||
case GIZ_PUSHAPI_APPID_OR_TOKEN_ERROR:
|
||||
errorString = (String) getText(R.string.GIZ_PUSHAPI_APPID_OR_TOKEN_ERROR);
|
||||
break;
|
||||
case GIZ_PUSHAPI_TYPE_PARAM_ERROR:
|
||||
errorString = (String) getText(R.string.GIZ_PUSHAPI_TYPE_PARAM_ERROR);
|
||||
break;
|
||||
case GIZ_PUSHAPI_ID_PARAM_ERROR:
|
||||
errorString = (String) getText(R.string.GIZ_PUSHAPI_ID_PARAM_ERROR);
|
||||
break;
|
||||
case GIZ_PUSHAPI_APPKEY_SECRETKEY_INVALID:
|
||||
errorString = (String) getText(R.string.GIZ_PUSHAPI_APPKEY_SECRETKEY_INVALID);
|
||||
break;
|
||||
case GIZ_PUSHAPI_CHANNELID_ERROR_INVALID:
|
||||
errorString = (String) getText(R.string.GIZ_PUSHAPI_CHANNELID_ERROR_INVALID);
|
||||
break;
|
||||
case GIZ_PUSHAPI_PUSH_ERROR:
|
||||
errorString = (String) getText(R.string.GIZ_PUSHAPI_PUSH_ERROR);
|
||||
break;
|
||||
case GIZ_SDK_SUBDEVICE_ADD_FAILED:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_ADD_SUBDEVICE_FAILED);
|
||||
break;
|
||||
|
||||
case GIZ_SDK_SUBDEVICE_DELETE_FAILED:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_DELETE_SUBDEVICE_FAILED);
|
||||
break;
|
||||
|
||||
case GIZ_SDK_SUBDEVICE_LIST_UPDATE_FAILED:
|
||||
errorString = (String) getText(R.string.GIZ_SDK_GET_SUBDEVICES_FAILED);
|
||||
break;
|
||||
default:
|
||||
errorString = (String) getText(R.string.UNKNOWN_ERROR);
|
||||
break;
|
||||
}
|
||||
return errorString;
|
||||
}
|
||||
}
|
@ -1,311 +0,0 @@
|
||||
package com.gizwits.opensource.appkit.DeviceModule;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.Switch;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.gizwits.gizwifisdk.api.GizWifiCentralControlDevice;
|
||||
import com.gizwits.gizwifisdk.api.GizWifiDevice;
|
||||
import com.gizwits.gizwifisdk.enumration.GizDeviceSharingUserRole;
|
||||
import com.gizwits.gizwifisdk.enumration.GizWifiDeviceNetStatus;
|
||||
import com.gizwits.opensource.appkit.CommonModule.GosDeploy;
|
||||
import com.gizwits.opensource.appkit.R;
|
||||
import com.gizwits.opensource.appkit.sharingdevice.addSharedActivity;
|
||||
import com.gizwits.opensource.appkit.utils.AssetsUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.gizwits.gizwifisdk.enumration.GizWifiDeviceType.GizDeviceCenterControl;
|
||||
|
||||
|
||||
@SuppressLint("InflateParams")
|
||||
public class GosDeviceListAdapter extends BaseAdapter {
|
||||
|
||||
private static final String TAG = "GosDeviceListAdapter";
|
||||
Handler handler = new Handler();
|
||||
SharedPreferences spf;
|
||||
protected static final int UNBOUND = 99;
|
||||
protected static final int SHARE = 100;
|
||||
|
||||
public void setHandler(Handler handler) {
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
Context context;
|
||||
List<GizWifiDevice> deviceList;
|
||||
|
||||
public GosDeviceListAdapter(Context context, List<GizWifiDevice> deviceList) {
|
||||
super();
|
||||
this.context = context;
|
||||
this.deviceList = deviceList;
|
||||
}
|
||||
|
||||
public void setSpf(SharedPreferences spf) {
|
||||
this.spf = spf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return deviceList.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int position) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
View view = convertView;
|
||||
Holder holder;
|
||||
|
||||
if (view == null) {
|
||||
view = LayoutInflater.from(context).inflate(
|
||||
R.layout.item_gos_device_list, null);
|
||||
holder = new Holder(view);
|
||||
view.setTag(holder);
|
||||
} else {
|
||||
holder = (Holder) view.getTag();
|
||||
}
|
||||
final GizWifiDevice device = deviceList.get(position);
|
||||
|
||||
String deviceAlias = device.getAlias();
|
||||
String devicePN = device.getProductName();
|
||||
|
||||
GizDeviceSharingUserRole role = device.getSharingRole();
|
||||
|
||||
if (role != null) {
|
||||
if (role.name().equals("GizDeviceSharingSpecial") || role.name().equals("GizDeviceSharingOwner")) {
|
||||
holder.getDelete2().setVisibility(View.VISIBLE);
|
||||
holder.getDelete1().setVisibility(View.VISIBLE);
|
||||
holder.getDevice().setPadding(0, 0, AssetsUtils.diptopx(context, -181), 0);
|
||||
} else {
|
||||
holder.getDelete1().setVisibility(View.GONE);
|
||||
holder.getDelete2().setVisibility(View.VISIBLE);
|
||||
holder.getDevice().setPadding(0, 0, AssetsUtils.diptopx(context, -91), 0);
|
||||
}
|
||||
}
|
||||
GizWifiCentralControlDevice centralControlDevice = null;
|
||||
holder.getTvDeviceMac().setVisibility(View.GONE);
|
||||
holder.getTvDeviceMac().setVisibility(View.VISIBLE);
|
||||
holder.getTvDeviceMac().setText(device.getMacAddress());
|
||||
|
||||
if (device.getNetStatus() == GizWifiDeviceNetStatus.GizDeviceOnline
|
||||
|| device.getNetStatus() == GizWifiDeviceNetStatus.GizDeviceControlled) {
|
||||
|
||||
if (device.isLAN()) {
|
||||
holder.getLlLeft().setImageResource(R.drawable.common_device_lan_online);
|
||||
} else {
|
||||
holder.getLlLeft().setImageResource(R.drawable.common_device_remote_online);
|
||||
}
|
||||
holder.getImgRight().setVisibility(View.VISIBLE);
|
||||
|
||||
if (device.isBind()) {// 已绑定设备
|
||||
if (device.getProductType() == GizDeviceCenterControl) {
|
||||
if (device instanceof GizWifiCentralControlDevice) {
|
||||
centralControlDevice = (GizWifiCentralControlDevice) device;
|
||||
}
|
||||
}
|
||||
if (centralControlDevice != null) {
|
||||
if (centralControlDevice.getSubDeviceList().size() != 0) {
|
||||
holder.getTvDeviceMac().setVisibility(View.VISIBLE);
|
||||
if (AssetsUtils.isZh(context)) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append("已连接");
|
||||
sb.append(centralControlDevice.getSubDeviceList().size());
|
||||
sb.append("个设备");
|
||||
holder.getTvDeviceMac().setText(sb.toString());
|
||||
} else {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append(centralControlDevice.getSubDeviceList().size());
|
||||
sb.append(" devices connected");
|
||||
holder.getTvDeviceMac().setText(sb.toString());
|
||||
}
|
||||
if (AssetsUtils.isZh(context)) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append(centralControlDevice.getMacAddress());
|
||||
sb.append(" 已连接");
|
||||
sb.append(centralControlDevice.getSubDeviceList().size());
|
||||
sb.append("个设备");
|
||||
holder.getTvDeviceMac().setText(sb.toString());
|
||||
} else {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append(centralControlDevice.getMacAddress());
|
||||
sb.append(" ");
|
||||
sb.append(centralControlDevice.getSubDeviceList().size());
|
||||
sb.append(" devices connected");
|
||||
holder.getTvDeviceMac().setText(sb.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
//这里会出现箭头不显示的状态
|
||||
// holder.getImgRight().setVisibility(View.VISIBLE);
|
||||
|
||||
} else {// 未绑定设备
|
||||
holder.getDelete2().setVisibility(View.GONE);
|
||||
holder.getDevice().setPadding(0, 0, AssetsUtils.diptopx(context, 0), 0);
|
||||
}
|
||||
} else {// 设备不在线
|
||||
holder.getSbDeviceStatus().setClickable(false);
|
||||
holder.getImgRight().setVisibility(View.GONE);
|
||||
if (device.isLAN()) {
|
||||
holder.getLlLeft().setImageResource(R.drawable.common_device_lan_offline);
|
||||
} else {
|
||||
holder.getLlLeft().setImageResource(R.drawable.common_device_remote_offline);
|
||||
}
|
||||
}
|
||||
if (TextUtils.isEmpty(deviceAlias)) {
|
||||
List<Map<String, Object>> list = GosDeploy.appConfig_DeviceInfo();
|
||||
boolean isName = true;
|
||||
for (Map<String, Object> map : list) {
|
||||
if (map.containsKey("productKey")) {
|
||||
if (device.getProductKey().equals(map.get("productKey"))) {
|
||||
if (AssetsUtils.isZh(context)) {
|
||||
if (map.containsKey("productNameCH")) {
|
||||
isName = false;
|
||||
holder.getTvDeviceName().setText(map.get("productNameCH").toString());
|
||||
}
|
||||
} else {
|
||||
if (map.containsKey("productNameEN")) {
|
||||
isName = false;
|
||||
holder.getTvDeviceName().setText(map.get("productNameEN").toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isName) {
|
||||
holder.getTvDeviceName().setText(devicePN);
|
||||
}
|
||||
} else {
|
||||
holder.getTvDeviceName().setText(deviceAlias);
|
||||
}
|
||||
holder.getDelete2().setOnClickListener(new OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Message message = new Message();
|
||||
message.what = UNBOUND;
|
||||
message.obj = device.getDid().toString();
|
||||
handler.sendMessage(message);
|
||||
|
||||
}
|
||||
});
|
||||
holder.getDelete1().setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Message message = new Message();
|
||||
message.what = SHARE;
|
||||
message.obj = device.getDid().toString();
|
||||
handler.sendMessage(message);
|
||||
|
||||
if (!TextUtils.isEmpty(spf.getString("UserName", "")) && !TextUtils.isEmpty(spf.getString("PassWord", ""))) {
|
||||
Intent intent = new Intent(context, addSharedActivity.class);
|
||||
intent.putExtra("productname", device.getProductName());
|
||||
intent.putExtra("did", device.getDid());
|
||||
context.startActivity(intent);
|
||||
} else {
|
||||
Toast.makeText(context, context.getString(R.string.please_login), 2000).show();
|
||||
}
|
||||
}
|
||||
});
|
||||
return view;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Holder {
|
||||
View view;
|
||||
|
||||
public Holder(View view) {
|
||||
this.view = view;
|
||||
}
|
||||
|
||||
private TextView tvDeviceMac, tvDeviceStatus, tvDeviceName;
|
||||
|
||||
private RelativeLayout delete1, delete2, device;
|
||||
|
||||
private ImageView imgRight;
|
||||
|
||||
private ImageView lvLeft;
|
||||
|
||||
private Switch sbDeviceStatus;
|
||||
|
||||
public ImageView getLlLeft() {
|
||||
if (null == lvLeft) {
|
||||
lvLeft = (ImageView) view.findViewById(R.id.imgLeft);
|
||||
}
|
||||
return lvLeft;
|
||||
}
|
||||
|
||||
public ImageView getImgRight() {
|
||||
if (null == imgRight) {
|
||||
imgRight = (ImageView) view.findViewById(R.id.imgRight);
|
||||
}
|
||||
return imgRight;
|
||||
}
|
||||
|
||||
public RelativeLayout getDevice() {
|
||||
if (null == device) {
|
||||
device = (RelativeLayout) view.findViewById(R.id.rl_device);
|
||||
}
|
||||
return device;
|
||||
}
|
||||
|
||||
public RelativeLayout getDelete2() {
|
||||
if (null == delete2) {
|
||||
delete2 = (RelativeLayout) view.findViewById(R.id.delete2);
|
||||
}
|
||||
return delete2;
|
||||
}
|
||||
|
||||
public RelativeLayout getDelete1() {
|
||||
if (null == delete1) {
|
||||
delete1 = (RelativeLayout) view.findViewById(R.id.delete1);
|
||||
}
|
||||
return delete1;
|
||||
}
|
||||
|
||||
public TextView getTvDeviceMac() {
|
||||
if (null == tvDeviceMac) {
|
||||
tvDeviceMac = (TextView) view.findViewById(R.id.tvDeviceMac);
|
||||
}
|
||||
return tvDeviceMac;
|
||||
}
|
||||
|
||||
|
||||
public TextView getTvDeviceName() {
|
||||
if (null == tvDeviceName) {
|
||||
tvDeviceName = (TextView) view.findViewById(R.id.tvDeviceName);
|
||||
}
|
||||
return tvDeviceName;
|
||||
}
|
||||
|
||||
public Switch getSbDeviceStatus() {
|
||||
if (null == sbDeviceStatus) {
|
||||
sbDeviceStatus = (Switch) view.findViewById(R.id.sbDeviceStatus);
|
||||
}
|
||||
return sbDeviceStatus;
|
||||
}
|
||||
|
||||
}
|
@ -1,108 +0,0 @@
|
||||
package com.gizwits.opensource.appkit.DeviceModule;
|
||||
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.wifi.ScanResult;
|
||||
import android.os.Handler;
|
||||
import android.os.HandlerThread;
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
import android.widget.RemoteViews;
|
||||
|
||||
import com.gizwits.opensource.appkit.R;
|
||||
import com.gizwits.opensource.appkit.CommonModule.GosBaseActivity;
|
||||
import com.gizwits.opensource.appkit.CommonModule.GosConstant;
|
||||
import com.gizwits.opensource.appkit.utils.NetUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class GosMessageHandler {
|
||||
|
||||
NotificationManager nm;
|
||||
|
||||
protected static final int SHOWDIALOG = 999;
|
||||
|
||||
private Context mcContext;
|
||||
|
||||
private ArrayList<String> newDeviceList = new ArrayList<String>();
|
||||
|
||||
private Handler mainHandler;
|
||||
// 做一个单例
|
||||
private static GosMessageHandler mInstance = new GosMessageHandler();
|
||||
|
||||
public static GosMessageHandler getSingleInstance() {
|
||||
return mInstance;
|
||||
}
|
||||
|
||||
public void SetHandler(Handler handler) {
|
||||
this.mainHandler = handler;
|
||||
}
|
||||
|
||||
public void StartLooperWifi(Context context) {
|
||||
this.mcContext = context;
|
||||
HandlerThread looperwifi = new HandlerThread("looperwifi");
|
||||
looperwifi.start();
|
||||
looper = new MyLooperHandler(looperwifi.getLooper());
|
||||
looper.post(mRunnable);
|
||||
}
|
||||
|
||||
class MyLooperHandler extends Handler {
|
||||
public MyLooperHandler(Looper looper) {
|
||||
super(looper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
super.handleMessage(msg);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 子线程实现
|
||||
*/
|
||||
private Runnable mRunnable = new Runnable() {
|
||||
|
||||
public void run() {
|
||||
if (mcContext == null) {
|
||||
return;
|
||||
}
|
||||
newDeviceList.clear();
|
||||
List<ScanResult> currentWifiScanResult = NetUtils
|
||||
.getCurrentWifiScanResult(mcContext);
|
||||
GosConstant.ssidList = currentWifiScanResult;
|
||||
int flog = 0;
|
||||
if (currentWifiScanResult != null) {
|
||||
for (ScanResult scanResult : currentWifiScanResult) {
|
||||
String ssid = scanResult.SSID;
|
||||
// 获取系统的NotificationManager服务
|
||||
nm = (NotificationManager) mcContext
|
||||
.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
if (ssid.contains(GosBaseActivity.SoftAP_Start)
|
||||
&& ssid.length() > GosBaseActivity.SoftAP_Start.length()
|
||||
&& !newDeviceList.toString().contains(ssid)) {
|
||||
newDeviceList.add(ssid);
|
||||
flog++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (mainHandler != null && newDeviceList.size() > 0) {
|
||||
mainHandler.sendEmptyMessage(SHOWDIALOG);
|
||||
}
|
||||
|
||||
looper.postDelayed(mRunnable, 2000);
|
||||
}
|
||||
};
|
||||
private MyLooperHandler looper;
|
||||
|
||||
|
||||
public ArrayList<String> getNewDeviceList() {
|
||||
return newDeviceList;
|
||||
}
|
||||
|
||||
}
|
@ -1,136 +0,0 @@
|
||||
package com.gizwits.opensource.appkit.DeviceModule;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gizwits.opensource.appkit.R;
|
||||
import com.gizwits.opensource.appkit.SettingsModule.GosAboutActivity;
|
||||
import com.gizwits.opensource.appkit.UserModule.GosUserManager;
|
||||
import com.gizwits.opensource.appkit.sharingdevice.SharedDeviceListAcitivity;
|
||||
|
||||
public class GosSettiingsFragment extends GosBaseFragment implements OnClickListener {
|
||||
|
||||
private static final int SETTINGS = 123;
|
||||
/**
|
||||
* The ll About
|
||||
*/
|
||||
private LinearLayout llAbout;
|
||||
|
||||
/**
|
||||
* The Intent
|
||||
*/
|
||||
Intent intent;
|
||||
|
||||
private LinearLayout usermanager;
|
||||
|
||||
private RelativeLayout lllogin;
|
||||
private LinearLayout llDeviceShared;
|
||||
|
||||
private TextView phoneusername;
|
||||
private View allView;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
allView = inflater.inflate(R.layout.activity_gos_settings, container, false);
|
||||
initView();
|
||||
initEvent();
|
||||
return allView;
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
llAbout = (LinearLayout) allView.findViewById(R.id.llAbout);
|
||||
usermanager = (LinearLayout) allView.findViewById(R.id.usermanager);
|
||||
lllogin = (RelativeLayout) allView.findViewById(R.id.lllogin);
|
||||
phoneusername = (TextView) allView.findViewById(R.id.phoneusername);
|
||||
llDeviceShared = (LinearLayout) allView.findViewById(R.id.deviceshared);
|
||||
}
|
||||
|
||||
private void initEvent() {
|
||||
llAbout.setOnClickListener(this);
|
||||
usermanager.setOnClickListener(this);
|
||||
lllogin.setOnClickListener(this);
|
||||
llDeviceShared.setOnClickListener(this);
|
||||
|
||||
if (!TextUtils.isEmpty(spf.getString("UserName", "")) && !TextUtils.isEmpty(spf.getString("PassWord", ""))) {
|
||||
usermanager.setVisibility(View.VISIBLE);
|
||||
lllogin.setVisibility(View.GONE);
|
||||
phoneusername.setText(spf.getString("UserName", ""));
|
||||
} else if (TextUtils.isEmpty(spf.getString("UserName", "")) && TextUtils.isEmpty(spf.getString("PassWord", ""))
|
||||
&& !TextUtils.isEmpty(spf.getString("thirdUid", ""))) {
|
||||
usermanager.setVisibility(View.VISIBLE);
|
||||
String uid = spf.getString("thirdUid", "");
|
||||
|
||||
lllogin.setVisibility(View.GONE);
|
||||
String myuid = uid.substring(0, 2) + "***" + uid.substring(uid.length() - 4, uid.length());
|
||||
phoneusername.setText(myuid);
|
||||
} else {
|
||||
usermanager.setVisibility(View.GONE);
|
||||
lllogin.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
switch (v.getId()) {
|
||||
case R.id.llAbout:
|
||||
intent = new Intent(getContext(), GosAboutActivity.class);
|
||||
startActivity(intent);
|
||||
llAbout.setEnabled(false);
|
||||
llAbout.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
llAbout.setEnabled(true);
|
||||
}
|
||||
}, 1000);
|
||||
break;
|
||||
|
||||
case R.id.usermanager:
|
||||
intent = null;
|
||||
if (intent == null) {
|
||||
intent = new Intent(getContext(), GosUserManager.class);
|
||||
}
|
||||
startActivityForResult(intent, SETTINGS);
|
||||
usermanager.setEnabled(false);
|
||||
usermanager.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
usermanager.setEnabled(true);
|
||||
}
|
||||
}, 1000);
|
||||
break;
|
||||
case R.id.lllogin:
|
||||
lllogin.setEnabled(false);
|
||||
lllogin.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
lllogin.setEnabled(true);
|
||||
}
|
||||
}, 1000);
|
||||
getActivity().finish();
|
||||
break;
|
||||
case R.id.deviceshared:
|
||||
Intent deviceshared1 = new Intent(getContext(), SharedDeviceListAcitivity.class);
|
||||
startActivity(deviceshared1);
|
||||
llDeviceShared.setEnabled(false);
|
||||
llDeviceShared.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
llDeviceShared.setEnabled(true);
|
||||
}
|
||||
}, 1000);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,136 +0,0 @@
|
||||
package com.gizwits.opensource.appkit.DeviceModule;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.gizwits.gizwifisdk.api.GizDeviceSharing;
|
||||
import com.gizwits.gizwifisdk.api.GizMessage;
|
||||
import com.gizwits.gizwifisdk.enumration.GizMessageStatus;
|
||||
import com.gizwits.gizwifisdk.enumration.GizMessageType;
|
||||
import com.gizwits.gizwifisdk.enumration.GizWifiErrorCode;
|
||||
import com.gizwits.gizwifisdk.listener.GizDeviceSharingListener;
|
||||
import com.gizwits.opensource.appkit.R;
|
||||
import com.gizwits.opensource.appkit.sharingdevice.MsgNoticeActivity;
|
||||
import com.gizwits.opensource.appkit.sharingdevice.deviceSharedMessageActivity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
//personalCenter_deviceSharing-false-start
|
||||
//personalCenter_deviceSharing-false-end
|
||||
|
||||
public class MessageCenterFragment extends GosBaseFragment {
|
||||
|
||||
|
||||
private LinearLayout llGizwitsmes;
|
||||
//personalCenter_deviceSharing-false-start
|
||||
private View redpoint;
|
||||
private LinearLayout llDevicesShared;
|
||||
//personalCenter_deviceSharing-false-end
|
||||
private View allView;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
allView = inflater.inflate(R.layout.activity_gos_message, container, false);
|
||||
initView();
|
||||
initEvent();
|
||||
return allView;
|
||||
}
|
||||
|
||||
//界面可见时再加载数据
|
||||
@Override
|
||||
public void setUserVisibleHint(boolean isVisibleToUser) {
|
||||
super.setUserVisibleHint(isVisibleToUser);
|
||||
if (isVisibleToUser) {
|
||||
//请求网络数据
|
||||
//personalCenter_deviceSharing-false-start
|
||||
String token = spf.getString("Token", "");
|
||||
GizDeviceSharing.queryMessageList(token, GizMessageType.GizMessageSharing);
|
||||
//GizDeviceSharing.queryMessageList(token, GizMessageType.GizMessageSystem);
|
||||
|
||||
GizDeviceSharing.setListener(new GizDeviceSharingListener() {
|
||||
|
||||
@Override
|
||||
public void didQueryMessageList(GizWifiErrorCode result, List<GizMessage> messageList) {
|
||||
super.didQueryMessageList(result, messageList);
|
||||
|
||||
if (messageList.size() > 0) {
|
||||
isShowRedPoint(messageList);
|
||||
} else {
|
||||
redpoint.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if (result.ordinal() != 0) {
|
||||
Toast.makeText(getContext(), toastError(result), 2).show();
|
||||
}
|
||||
}
|
||||
});
|
||||
//personalCenter_deviceSharing-false-end
|
||||
}
|
||||
}
|
||||
|
||||
//personalCenter_deviceSharing-false-start
|
||||
private void isShowRedPoint(List<GizMessage> messageList) {
|
||||
|
||||
boolean isshow = false;
|
||||
redpoint.setVisibility(View.GONE);
|
||||
for (int i = 0; i < messageList.size(); i++) {
|
||||
|
||||
GizMessage gizMessage = messageList.get(i);
|
||||
GizMessageStatus status = gizMessage.getStatus();
|
||||
if (status.ordinal() == 0) {
|
||||
isshow = true;
|
||||
redpoint.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
//personalCenter_deviceSharing-false-end
|
||||
|
||||
private void initView() {
|
||||
llGizwitsmes = (LinearLayout) allView.findViewById(R.id.gizwitsmes);
|
||||
//personalCenter_deviceSharing-false-start
|
||||
// 判断当前的view 是否需要显示这个红点
|
||||
redpoint = allView.findViewById(R.id.redpoint);
|
||||
llDevicesShared = (LinearLayout) allView.findViewById(R.id.deviceshared);
|
||||
//personalCenter_deviceSharing-false-end
|
||||
}
|
||||
|
||||
private void initEvent() {
|
||||
llGizwitsmes.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// 跳转到机智云公告页面
|
||||
Intent intent = new Intent(getContext(), MsgNoticeActivity.class);
|
||||
startActivity(intent);
|
||||
llGizwitsmes.setEnabled(false);
|
||||
llGizwitsmes.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
llGizwitsmes.setEnabled(true);
|
||||
}
|
||||
}, 1000);
|
||||
}
|
||||
});
|
||||
//personalCenter_deviceSharing-false-start
|
||||
llDevicesShared.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent tent = new Intent(getContext(), deviceSharedMessageActivity.class);
|
||||
startActivity(tent);
|
||||
llDevicesShared.setEnabled(false);
|
||||
llDevicesShared.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
llDevicesShared.setEnabled(true);
|
||||
}
|
||||
}, 1000);
|
||||
}
|
||||
});
|
||||
//personalCenter_deviceSharing-false-end
|
||||
}
|
||||
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
package com.gizwits.opensource.appkit;
|
||||
|
||||
import android.app.Application;
|
||||
public class GosApplication extends Application {
|
||||
|
||||
public static int flag = 0;
|
||||
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,112 +0,0 @@
|
||||
package com.gizwits.opensource.appkit;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.text.TextUtils;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.gizwits.gizwifisdk.api.GizWifiSDK;
|
||||
import com.gizwits.gizwifisdk.enumration.GizLogPrintLevel;
|
||||
import com.gizwits.opensource.appkit.CommonModule.GosConstant;
|
||||
import com.gizwits.opensource.appkit.CommonModule.GosDeploy;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class MessageCenter {
|
||||
private static MessageCenter mCenter;
|
||||
int flag = 0;
|
||||
|
||||
GosDeploy gosDeploy;
|
||||
|
||||
private int SETCLOUD = 1111;
|
||||
|
||||
private MessageCenter(Context c) {
|
||||
if (mCenter == null) {
|
||||
init(c);
|
||||
}
|
||||
}
|
||||
|
||||
private void init(Context c) {
|
||||
gosDeploy = new GosDeploy(c);
|
||||
//config-all-start
|
||||
if (GosDeploy.appConfig_UseOnboardingDeploy()) {
|
||||
if (GosDeploy.appConfig_OnboardingBind()) {
|
||||
GosConstant.mNew = 3;
|
||||
} else {
|
||||
GosConstant.mNew = 2;
|
||||
}
|
||||
} else {
|
||||
if (GosDeploy.appConfig_OnboardingBind()) {
|
||||
GosConstant.mNew = 1;
|
||||
} else {
|
||||
GosConstant.mNew = 0;
|
||||
}
|
||||
}
|
||||
//config-all-end
|
||||
String AppID = GosDeploy.appConfig_GizwitsInfoAppID();
|
||||
String AppSecret = GosDeploy.appConfig_GizwitsInfoAppSecret();
|
||||
List<ConcurrentHashMap<String, String>> productInfoList = GosDeploy.appConfig_ProductInfoList();
|
||||
if (productInfoList.size() == 0) {
|
||||
productInfoList = null;
|
||||
}
|
||||
|
||||
if (AppID == null || AppSecret == null || TextUtils.isEmpty(AppID) || AppID.contains("BeJson")
|
||||
|| TextUtils.isEmpty(AppSecret) || AppSecret.contains("BeJson")
|
||||
|| AppID.length() != 32 || AppSecret.length() != 32) {
|
||||
String AppID_Toast = c.getString(R.string.AppID_Toast);
|
||||
if (flag == 0) {
|
||||
Toast.makeText(c, AppID_Toast, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
flag++;
|
||||
} else {
|
||||
// 启动SDK
|
||||
ConcurrentHashMap<String, String> serverMap = new ConcurrentHashMap<String, String>();
|
||||
ConcurrentHashMap<String, String> appInfo = new ConcurrentHashMap<String, String>();
|
||||
appInfo.put("appId", AppID);
|
||||
appInfo.put("appSecret", AppSecret);
|
||||
|
||||
String api = GosDeploy.appConfig_CloudServiceApi();
|
||||
String site = GosDeploy.appConfig_CloudServiceSite();
|
||||
String push = GosDeploy.appConfig_CloudServicePush();
|
||||
Pattern pattern = Pattern.compile("(^[a-zA-Z0-9\\-]{1,}\\.[a-zA-Z0-9]{1,}\\.[a-zA-Z0-9]{1,}\\:(\\d){1,}\\&(\\d){1,}$)|(^[a-zA-Z0-9\\-]{1,}\\.[a-zA-Z0-9]{1,}\\.[a-zA-Z0-9]{1,}$)");
|
||||
Pattern pattern1 = Pattern.compile("(^([1-9]|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])(\\.(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])){3}\\:(\\d){1,}\\&(\\d){1,}$)|(^([1-9]|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])(\\.(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])){3}$)");
|
||||
if (api != null) {
|
||||
if (pattern.matcher(api).matches() || pattern1.matcher(api).matches()) {
|
||||
serverMap.put("openAPIInfo", api);
|
||||
if (site != null) {
|
||||
serverMap.put("siteInfo", site);
|
||||
}
|
||||
if (push != null && !push.isEmpty()) {
|
||||
serverMap.put("pushInfo", GosDeploy.appConfig_CloudServicePush());
|
||||
}
|
||||
GizWifiSDK.sharedInstance().startWithAppInfo(c, appInfo, productInfoList, serverMap, false);
|
||||
} else {
|
||||
GizWifiSDK.sharedInstance().startWithAppInfo(c, appInfo,
|
||||
productInfoList, null, false);
|
||||
}
|
||||
} else {
|
||||
GizWifiSDK.sharedInstance().startWithAppInfo(c, appInfo,
|
||||
productInfoList, null, false);
|
||||
}
|
||||
}
|
||||
hand.sendEmptyMessageDelayed(SETCLOUD, 3000);
|
||||
}
|
||||
|
||||
public static MessageCenter getInstance(Context c) {
|
||||
if (mCenter == null) {
|
||||
mCenter = new MessageCenter(c);
|
||||
}
|
||||
return mCenter;
|
||||
}
|
||||
|
||||
Handler hand = new Handler() {
|
||||
public void handleMessage(android.os.Message msg) {
|
||||
GizWifiSDK.sharedInstance().setLogLevel(
|
||||
GizLogPrintLevel.GizLogPrintAll);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
}
|
Binary file not shown.
@ -1,67 +0,0 @@
|
||||
package com.gizwits.opensource.appkit.PushModule;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import com.baidu.android.pushservice.PushMessageReceiver;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class BaiDuPushReceiver extends PushMessageReceiver {
|
||||
|
||||
// BaiDuPush_Channel_ID(此处需要在百度推送的Receiver里赋值)
|
||||
public static String BaiDuPush_Channel_ID;
|
||||
|
||||
@Override
|
||||
public void onBind(Context arg0, int arg1, String arg2, String arg3, String arg4, String arg5) {
|
||||
// TODO Auto-generated method stub
|
||||
BaiDuPush_Channel_ID = arg4;
|
||||
Log.i("Apptest", BaiDuPush_Channel_ID + "---");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDelTags(Context arg0, int arg1, List<String> arg2, List<String> arg3, String arg4) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onListTags(Context arg0, int arg1, List<String> arg2, String arg3) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessage(Context arg0, String arg1, String arg2) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNotificationArrived(Context arg0, String arg1, String arg2, String arg3) {
|
||||
// TODO Auto-generated method stub
|
||||
String notifyString = "通知到达 onNotificationArrived title=\"" + arg1
|
||||
+ "\" description=\"" + arg2 + "\" customContent="
|
||||
+ arg3;
|
||||
Log.i(TAG, notifyString);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNotificationClicked(Context arg0, String arg1, String arg2, String arg3) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSetTags(Context arg0, int arg1, List<String> arg2, List<String> arg3, String arg4) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUnbind(Context arg0, int arg1, String arg2) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,136 +0,0 @@
|
||||
package com.gizwits.opensource.appkit.PushModule;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
//push_baidu-false-start
|
||||
import com.baidu.android.pushservice.PushConstants;
|
||||
import com.baidu.android.pushservice.PushManager;
|
||||
import com.baidu.android.pushservice.PushSettings;
|
||||
//push_baidu-false-end
|
||||
import com.gizwits.opensource.appkit.R;
|
||||
import com.gizwits.gizwifisdk.api.GizWifiSDK;
|
||||
import com.gizwits.gizwifisdk.enumration.GizPushType;
|
||||
import com.gizwits.opensource.appkit.CommonModule.GosBaseActivity;
|
||||
import com.gizwits.opensource.appkit.CommonModule.GosDeploy;
|
||||
|
||||
import java.util.Set;
|
||||
//push_jiguang-false-start
|
||||
import cn.jpush.android.api.JPushInterface;
|
||||
import cn.jpush.android.api.TagAliasCallback;
|
||||
//push_jiguang-false-end
|
||||
|
||||
|
||||
public class GosPushManager {
|
||||
|
||||
static GizPushType gizPushType;
|
||||
|
||||
static Context context;
|
||||
|
||||
public GosPushManager(int PushType, Context context) {
|
||||
super();
|
||||
GosPushManager.context = context;
|
||||
//push_jiguang-false-start
|
||||
if (PushType == 1) {
|
||||
GosPushManager.gizPushType = GizPushType.GizPushJiGuang;
|
||||
jPush();
|
||||
}
|
||||
//push_jiguang-false-end
|
||||
//push_baidu-false-start
|
||||
if (PushType == 2) {
|
||||
GosPushManager.gizPushType = GizPushType.GizPushBaiDu;
|
||||
bDPush();
|
||||
}
|
||||
//push_baidu-false-end
|
||||
}
|
||||
|
||||
/**
|
||||
* Channel_ID
|
||||
*/
|
||||
public static String Channel_ID;
|
||||
|
||||
//push_jiguang-false-start
|
||||
|
||||
/**
|
||||
* 此方法完成了初始化JPush SDK等功能 但仍需在MainActivity的onResume和onPause添加相应方法
|
||||
* JPushInterface.onResume(context); JPushInterface.onPause(context);
|
||||
*/
|
||||
public void jPush() {
|
||||
// 设置JPush调试模式
|
||||
JPushInterface.setDebugMode(true);
|
||||
// 初始化JPushSDK
|
||||
JPushInterface.init(context);
|
||||
}
|
||||
//push_jiguang-false-end
|
||||
|
||||
//push_baidu-false-start
|
||||
public void bDPush() {
|
||||
final String BDPushAppKey = GosDeploy.appConfig_BpushAppKey();
|
||||
if (BDPushAppKey != null) {
|
||||
if (TextUtils.isEmpty(BDPushAppKey) || BDPushAppKey.contains("your_bpush_api_key")) {
|
||||
GosBaseActivity.noIDAlert(context, R.string.BDPushAppID_Toast);
|
||||
} else {
|
||||
PushManager.startWork(context, PushConstants.LOGIN_TYPE_API_KEY, BDPushAppKey);
|
||||
PushSettings.enableDebugMode(context, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
//push_baidu-false-end
|
||||
|
||||
/**
|
||||
* 向云端绑定推送
|
||||
*
|
||||
* @param userId
|
||||
* @param token
|
||||
*/
|
||||
public static void pushBindService(String userId, String token) {
|
||||
//push_jiguang-false-start
|
||||
if (GizPushType.GizPushJiGuang == gizPushType) {
|
||||
// 获取JPush的RegistrationID,即Channel_ID
|
||||
Channel_ID = JPushInterface.getRegistrationID(context);
|
||||
// 设定JPush类型
|
||||
JPushInterface.setAlias(context, Channel_ID, new TagAliasCallback() {
|
||||
@Override
|
||||
public void gotResult(int arg0, String arg1, Set<String> arg2) {
|
||||
if (arg0 == 0) {
|
||||
Log.i("Apptest", "Alias: " + arg1);
|
||||
} else {
|
||||
Log.i("Apptest", "Result: " + arg0);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
//push_jiguang-false-end
|
||||
//push_baidu-false-start
|
||||
if (GizPushType.GizPushBaiDu == gizPushType) {
|
||||
// 获取BDPush的Channel_ID
|
||||
Channel_ID = BaiDuPushReceiver.BaiDuPush_Channel_ID;
|
||||
Log.e("Manager", "pushBindService----: " + Channel_ID);
|
||||
}
|
||||
//push_baidu-false-end
|
||||
// TODO 绑定推送
|
||||
GizWifiSDK.sharedInstance().channelIDBind(token, Channel_ID, userId, gizPushType);
|
||||
}
|
||||
|
||||
public static void pushUnBindService(String token) {
|
||||
if (token.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
//push_jiguang-false-start
|
||||
if (GizPushType.GizPushJiGuang == gizPushType) {
|
||||
// 获取JPush的RegistrationID,即Channel_ID
|
||||
Channel_ID = JPushInterface.getRegistrationID(context);
|
||||
}
|
||||
//push_jiguang-false-end
|
||||
//push_baidu-false-start
|
||||
if (GizPushType.GizPushBaiDu == gizPushType) {
|
||||
// 获取BDPush的Channel_ID
|
||||
Channel_ID = BaiDuPushReceiver.BaiDuPush_Channel_ID;
|
||||
}
|
||||
//push_baidu-false-end
|
||||
// TODO 绑定推送
|
||||
//Log.i("Apptest", Channel_ID + "\n" + gizPushType.toString() + "\n" + token);
|
||||
GizWifiSDK.sharedInstance().channelIDUnBind(token, Channel_ID);
|
||||
}
|
||||
|
||||
}
|
@ -1,135 +0,0 @@
|
||||
package com.gizwits.opensource.appkit.SettingsModule;
|
||||
|
||||
import android.app.ActionBar;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gizwits.opensource.appkit.R;
|
||||
import com.gizwits.gizwifisdk.api.GizWifiSDK;
|
||||
import com.gizwits.opensource.appkit.CommonModule.GosBaseActivity;
|
||||
import com.gizwits.opensource.appkit.CommonModule.GosDeploy;
|
||||
import com.gizwits.opensource.appkit.utils.AssetsUtils;
|
||||
|
||||
public class GosAboutActivity extends GosBaseActivity {
|
||||
|
||||
/**
|
||||
* The tv SDKVersion.
|
||||
*/
|
||||
TextView tv_SDKVersion;
|
||||
|
||||
/**
|
||||
* the tv appCode
|
||||
*/
|
||||
TextView tv_AppVersion;
|
||||
|
||||
/**
|
||||
* The ActionBar
|
||||
*/
|
||||
ActionBar actionBar;
|
||||
private LinearLayout llApp;
|
||||
private LinearLayout llSDK;
|
||||
private LinearLayout llAbout;
|
||||
private TextView tvAbout;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_gos_about);
|
||||
// 设置ActionBar
|
||||
setToolBar(true, R.string.about);
|
||||
|
||||
initView();
|
||||
initEvent();
|
||||
}
|
||||
|
||||
private void initEvent() {
|
||||
if (!GosDeploy.appConfig_ShowAPPVersion() && !GosDeploy.appConfig_ShowSDKVersion()) {
|
||||
llApp.setVisibility(View.VISIBLE);
|
||||
llSDK.setVisibility(View.VISIBLE);
|
||||
llAbout.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
if (!GosDeploy.appConfig_ShowAPPVersion()) {
|
||||
llApp.setVisibility(View.GONE);
|
||||
}
|
||||
if (!GosDeploy.appConfig_ShowSDKVersion()) {
|
||||
llSDK.setVisibility(View.GONE);
|
||||
}
|
||||
if (GosDeploy.appConfig_AboutInfoCH() != null) {
|
||||
if (GosDeploy.appConfig_AboutInfoEN() != null) {
|
||||
if (AssetsUtils.isZh(this)) {
|
||||
tvAbout.setText(GosDeploy.appConfig_AboutInfoCH());
|
||||
} else {
|
||||
tvAbout.setText(GosDeploy.appConfig_AboutInfoEN());
|
||||
}
|
||||
} else {
|
||||
tvAbout.setText(GosDeploy.appConfig_AboutInfoCH());
|
||||
}
|
||||
llAbout.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
if (GosDeploy.appConfig_AboutInfoEN() != null) {
|
||||
tvAbout.setText(GosDeploy.appConfig_AboutInfoEN());
|
||||
llAbout.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
llAbout.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Inits the view.
|
||||
*/
|
||||
private void initView() {
|
||||
llApp = (LinearLayout) findViewById(R.id.llAPP);
|
||||
llSDK = (LinearLayout) findViewById(R.id.llSDK);
|
||||
llAbout = (LinearLayout) findViewById(R.id.llAbout);
|
||||
tvAbout = (TextView) findViewById(R.id.tvAbout);
|
||||
tv_SDKVersion = (TextView) findViewById(R.id.versionCode);
|
||||
tv_AppVersion = (TextView) findViewById(R.id.appCode);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
tv_SDKVersion.setText(GizWifiSDK.sharedInstance().getVersion().toString());
|
||||
tv_AppVersion.setText(getAppVersionName(this));
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回当前程序版本名
|
||||
*/
|
||||
public static String getAppVersionName(Context context) {
|
||||
String versionName = "";
|
||||
try {
|
||||
// ---get the package info---
|
||||
PackageManager pm = context.getPackageManager();
|
||||
PackageInfo pi = pm.getPackageInfo(context.getPackageName(), 0);
|
||||
versionName = pi.versionName;
|
||||
if (versionName == null || versionName.length() <= 0) {
|
||||
return "";
|
||||
}
|
||||
} catch(Exception e) {
|
||||
Log.i("Apptest", "Exception", e);
|
||||
}
|
||||
return versionName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
this.finish();
|
||||
break;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
package com.gizwits.opensource.appkit.ThirdAccountModule;
|
||||
|
||||
import com.tencent.tauth.IUiListener;
|
||||
import com.tencent.tauth.UiError;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class BaseUiListener implements IUiListener {
|
||||
|
||||
@Override
|
||||
public void onCancel() {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete(Object arg0) {
|
||||
doComplete((JSONObject)arg0);
|
||||
}
|
||||
|
||||
protected void doComplete(JSONObject values) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(UiError arg0) {
|
||||
// TODO Auto-generated method stu
|
||||
}
|
||||
|
||||
}
|
@ -1,226 +0,0 @@
|
||||
package com.gizwits.opensource.appkit.UserModule;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.text.method.HideReturnsTransformationMethod;
|
||||
import android.text.method.PasswordTransformationMethod;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.CompoundButton.OnCheckedChangeListener;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.gizwits.opensource.appkit.R;
|
||||
import com.gizwits.gizwifisdk.api.GizWifiSDK;
|
||||
import com.gizwits.gizwifisdk.listener.GizWifiSDKListener;
|
||||
import com.gizwits.opensource.appkit.CommonModule.GosBaseActivity;
|
||||
import com.gizwits.opensource.appkit.CommonModule.GosDeploy;
|
||||
|
||||
public class GosChangeUserPasswordActivity extends GosBaseActivity {
|
||||
|
||||
private EditText oldpass;
|
||||
private EditText newpass;
|
||||
private EditText confrimpass;
|
||||
private Button btnConfirm;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.activity_gos_change_password);
|
||||
setToolBar(true, R.string.edit_password);
|
||||
initView();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
// TODO Auto-generated method stub
|
||||
super.onResume();
|
||||
|
||||
GizWifiSDK.sharedInstance().setListener(listener);
|
||||
}
|
||||
|
||||
GizWifiSDKListener listener = new GizWifiSDKListener() {
|
||||
|
||||
public void didChangeUserPassword(
|
||||
com.gizwits.gizwifisdk.enumration.GizWifiErrorCode result) {
|
||||
|
||||
if (result.getResult() == 0) {
|
||||
Toast.makeText(GosChangeUserPasswordActivity.this,
|
||||
getResources().getString(R.string.passsuccess), 2000)
|
||||
.show();
|
||||
|
||||
finish();
|
||||
|
||||
spf.edit().putString("PassWord", newpass.getText().toString())
|
||||
.commit();
|
||||
} else {
|
||||
|
||||
if (result.getResult() == 9020) {
|
||||
Toast.makeText(GosChangeUserPasswordActivity.this,
|
||||
getResources().getString(R.string.oldpasserror),
|
||||
2000).show();
|
||||
} else {
|
||||
Toast.makeText(GosChangeUserPasswordActivity.this,
|
||||
getResources().getString(R.string.passerror), 2000)
|
||||
.show();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
;
|
||||
};
|
||||
private CheckBox oldcheck;
|
||||
private CheckBox newcheck;
|
||||
private CheckBox concheck;
|
||||
|
||||
private void initView() {
|
||||
btnConfirm = (Button) findViewById(R.id.btnLogin);
|
||||
oldpass = (EditText) findViewById(R.id.oldpass);
|
||||
newpass = (EditText) findViewById(R.id.newpass);
|
||||
confrimpass = (EditText) findViewById(R.id.confrimpass);
|
||||
confrimpass.setTransformationMethod(PasswordTransformationMethod
|
||||
.getInstance());
|
||||
oldpass.setTransformationMethod(PasswordTransformationMethod
|
||||
.getInstance());
|
||||
newpass.setTransformationMethod(PasswordTransformationMethod
|
||||
.getInstance());
|
||||
|
||||
oldcheck = (CheckBox) findViewById(R.id.oldcheck);
|
||||
newcheck = (CheckBox) findViewById(R.id.newcheck);
|
||||
concheck = (CheckBox) findViewById(R.id.concheck);
|
||||
// 配置文件部署
|
||||
oldcheck.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
||||
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView,
|
||||
boolean isChecked) {
|
||||
String psw = oldpass.getText().toString();
|
||||
|
||||
if (isChecked) {
|
||||
// oldpass.setInputType(0x90);
|
||||
oldpass.setTransformationMethod(HideReturnsTransformationMethod
|
||||
.getInstance());
|
||||
} else {
|
||||
// oldpass.setInputType(0x81);
|
||||
oldpass.setTransformationMethod(PasswordTransformationMethod
|
||||
.getInstance());
|
||||
}
|
||||
oldpass.setSelection(psw.length());
|
||||
}
|
||||
});
|
||||
|
||||
newcheck.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
||||
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView,
|
||||
boolean isChecked) {
|
||||
String psw = newpass.getText().toString();
|
||||
|
||||
if (isChecked) {
|
||||
// newpass.setInputType(0x90);
|
||||
newpass.setTransformationMethod(HideReturnsTransformationMethod
|
||||
.getInstance());
|
||||
} else {
|
||||
// newpass.setInputType(0x81);
|
||||
newpass.setTransformationMethod(PasswordTransformationMethod
|
||||
.getInstance());
|
||||
}
|
||||
newpass.setSelection(psw.length());
|
||||
}
|
||||
});
|
||||
|
||||
concheck.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
||||
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView,
|
||||
boolean isChecked) {
|
||||
String psw = confrimpass.getText().toString();
|
||||
|
||||
if (isChecked) {
|
||||
// confrimpass.setInputType(0x90);
|
||||
confrimpass
|
||||
.setTransformationMethod(HideReturnsTransformationMethod
|
||||
.getInstance());
|
||||
} else {
|
||||
// confrimpass.setInputType(0x81);
|
||||
confrimpass
|
||||
.setTransformationMethod(PasswordTransformationMethod
|
||||
.getInstance());
|
||||
}
|
||||
confrimpass.setSelection(psw.length());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void confirm(View v) {
|
||||
|
||||
if (TextUtils.isEmpty(oldpass.getText().toString())
|
||||
|| TextUtils.isEmpty(newpass.getText().toString())
|
||||
|| TextUtils.isEmpty(confrimpass.getText().toString())) {
|
||||
|
||||
if (TextUtils.isEmpty(oldpass.getText().toString())) {
|
||||
|
||||
Toast.makeText(
|
||||
this,
|
||||
getResources().getString(
|
||||
R.string.enter_current_password), 2000).show();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (TextUtils.isEmpty(newpass.getText().toString())) {
|
||||
Toast.makeText(this,
|
||||
getResources().getString(R.string.enter_new_password),
|
||||
2000).show();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (TextUtils.isEmpty(confrimpass.getText().toString())) {
|
||||
Toast.makeText(
|
||||
this,
|
||||
getResources()
|
||||
.getString(R.string.re_enter_new_password),
|
||||
2000).show();
|
||||
return;
|
||||
}
|
||||
|
||||
} else {
|
||||
//oldpass.getText().length() < 6 ||
|
||||
if (newpass.getText().length() < 6 || confrimpass.getText().length() < 6) {
|
||||
Toast.makeText(this,
|
||||
getResources().getString(R.string.toast_psw_short),
|
||||
2000).show();
|
||||
}
|
||||
|
||||
String npass = newpass.getText().toString();
|
||||
String cpass = confrimpass.getText().toString();
|
||||
if (npass.equals(cpass)) {
|
||||
GizWifiSDK.sharedInstance().changeUserPassword(
|
||||
spf.getString("Token", ""),
|
||||
oldpass.getText().toString(), npass);
|
||||
} else {
|
||||
Toast.makeText(this,
|
||||
getResources().getString(R.string.nosamepass), 2000)
|
||||
.show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
|
||||
finish();
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,385 +0,0 @@
|
||||
package com.gizwits.opensource.appkit.UserModule;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.drawable.GradientDrawable;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.text.InputType;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.gizwits.opensource.appkit.R;
|
||||
import com.gizwits.gizwifisdk.api.GizWifiSDK;
|
||||
import com.gizwits.gizwifisdk.enumration.GizUserAccountType;
|
||||
import com.gizwits.gizwifisdk.enumration.GizWifiErrorCode;
|
||||
import com.gizwits.opensource.appkit.CommonModule.GosDeploy;
|
||||
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
||||
@SuppressLint("HandlerLeak")
|
||||
public class GosForgetPasswordActivity extends GosUserModuleBaseActivity implements
|
||||
OnClickListener {
|
||||
|
||||
/**
|
||||
* The et Name
|
||||
*/
|
||||
private EditText etName;
|
||||
/**
|
||||
* The ll phone
|
||||
*/
|
||||
private LinearLayout llPhone;
|
||||
|
||||
/**
|
||||
* The btn GetCode
|
||||
*/
|
||||
private TextView tvGetCode;
|
||||
|
||||
/**
|
||||
* The et Code
|
||||
*/
|
||||
private EditText etCode;
|
||||
|
||||
/**
|
||||
* The et Psw
|
||||
*/
|
||||
private EditText etPsw;
|
||||
|
||||
/**
|
||||
* The et ConfirmPsw
|
||||
*/
|
||||
private EditText etConfirmPsw;
|
||||
/**
|
||||
* 验证码重发倒计时
|
||||
*/
|
||||
int secondleft = 60;
|
||||
|
||||
/**
|
||||
* The timer.
|
||||
*/
|
||||
Timer timer;
|
||||
//resetPassword_phoneUser-false-end
|
||||
/**
|
||||
* The btn Register
|
||||
*/
|
||||
private Button btnReset;
|
||||
|
||||
/**
|
||||
* 数据变量
|
||||
*/
|
||||
String name, code, psw, confirmpsw;
|
||||
|
||||
|
||||
private enum handler_key {
|
||||
//resetPassword_phoneUser-false-start
|
||||
/**
|
||||
* 获取验证码.
|
||||
*/
|
||||
GETCODE,
|
||||
|
||||
/**
|
||||
* 手机验证码发送成功.
|
||||
*/
|
||||
SENDSUCCESSFUL,
|
||||
|
||||
/**
|
||||
* 倒计时通知
|
||||
*/
|
||||
TICK_TIME,
|
||||
//resetPassword_phoneUser-false-end
|
||||
|
||||
/**
|
||||
* 提示信息
|
||||
*/
|
||||
TOAST,
|
||||
|
||||
/**
|
||||
* 重置密码
|
||||
*/
|
||||
RESET,
|
||||
}
|
||||
|
||||
Handler handler = new Handler() {
|
||||
public void handleMessage(Message msg) {
|
||||
super.handleMessage(msg);
|
||||
handler_key key = handler_key.values()[msg.what];
|
||||
switch (key) {
|
||||
//resetPassword_phoneUser-false-start
|
||||
case GETCODE:
|
||||
progressDialog.show();
|
||||
String AppSecret = GosDeploy.appConfig_GizwitsInfoAppSecret();
|
||||
GizWifiSDK.sharedInstance().requestSendPhoneSMSCode(AppSecret,
|
||||
msg.obj.toString());
|
||||
break;
|
||||
case SENDSUCCESSFUL:
|
||||
etName.setEnabled(false);
|
||||
etName.setTextColor(getResources().getColor(
|
||||
R.color.text_gray_light));
|
||||
isStartTimer();
|
||||
|
||||
break;
|
||||
|
||||
case TICK_TIME:
|
||||
String getCodeAgain = getString(R.string.getcode_again);
|
||||
String timerMessage = getString(R.string.timer_message);
|
||||
secondleft--;
|
||||
if (secondleft <= 0) {
|
||||
timer.cancel();
|
||||
tvGetCode.setTextColor(getResources().getColor(R.color.tomato));
|
||||
tvGetCode.setEnabled(true);
|
||||
tvGetCode.setText(getCodeAgain);
|
||||
} else {
|
||||
tvGetCode.setText(secondleft + timerMessage);
|
||||
}
|
||||
break;
|
||||
//resetPassword_phoneUser-false-end
|
||||
case TOAST:
|
||||
String successfulText = (String) getText(R.string.reset_successful);
|
||||
Toast.makeText(GosForgetPasswordActivity.this, msg.obj + "",
|
||||
toastTime).show();
|
||||
if (msg.obj.toString().equals(successfulText)) {
|
||||
// spf.edit().putString("UserName", name).commit();
|
||||
// spf.edit().putString("PassWord", psw).commit();
|
||||
isclean = true;
|
||||
//resetPassword_phoneUser-false-start
|
||||
if (llPhone.getVisibility() == View.GONE) {
|
||||
//resetPassword_phoneUser-false-end
|
||||
Intent intent = new Intent(GosForgetPasswordActivity.this, GosSendEmailPasswordActivity.class);
|
||||
startActivity(intent);
|
||||
spf.edit().putString("Email", name).commit();
|
||||
//resetPassword_phoneUser-false-start
|
||||
} else {
|
||||
finish();
|
||||
}
|
||||
//resetPassword_phoneUser-false-end
|
||||
}
|
||||
break;
|
||||
case RESET:
|
||||
progressDialog.show();
|
||||
GizWifiSDK.sharedInstance().resetPassword(name, code, psw,
|
||||
GizUserAccountType.GizUserPhone);
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_gos_forget_password);
|
||||
// 设置ActionBar
|
||||
setToolBar(true, R.string.forget_pass);
|
||||
|
||||
initView();
|
||||
initEvent();
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
etName = (EditText) findViewById(R.id.etName);
|
||||
//resetPassword_phoneUser-false-start
|
||||
llPhone = (LinearLayout) findViewById(R.id.llPhone);
|
||||
tvGetCode = (TextView) findViewById(R.id.tvGetCode);
|
||||
etCode = (EditText) findViewById(R.id.etCode);
|
||||
etPsw = (EditText) findViewById(R.id.etPsw);
|
||||
etConfirmPsw = (EditText) findViewById(R.id.etConfirmPsw);
|
||||
//resetPassword_phoneUser-false-end
|
||||
btnReset = (Button) findViewById(R.id.btnReset);
|
||||
setPhoneOrEmailIsVisable();
|
||||
}
|
||||
|
||||
private void setPhoneOrEmailIsVisable() {
|
||||
//resetPassword_phoneUser-true-start resetPassword_phoneUser-false-start
|
||||
if (GosDeploy.appConfig_ResetPassword_PhoneUser()) {
|
||||
//resetPassword_phoneUser-true-end
|
||||
etName.setHint(getResources().getString(R.string.name_phone));
|
||||
llPhone.setVisibility(View.VISIBLE);
|
||||
etName.setInputType(InputType.TYPE_CLASS_PHONE);
|
||||
btnReset.setText(getResources().getString(R.string.reset));
|
||||
//resetPassword_phoneUser-true-start
|
||||
} else {
|
||||
//resetPassword_phoneUser-false-end
|
||||
//resetPassword_phoneUser-false-start
|
||||
}
|
||||
//resetPassword_phoneUser-true-end resetPassword_phoneUser-false-end
|
||||
}
|
||||
|
||||
private void initEvent() {
|
||||
|
||||
final Timer etTimer = new Timer();
|
||||
etTimer.schedule(new TimerTask() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
etName.requestFocus();
|
||||
InputMethodManager imm = (InputMethodManager) etName
|
||||
.getContext().getSystemService(
|
||||
Context.INPUT_METHOD_SERVICE);
|
||||
imm.toggleSoftInput(0, InputMethodManager.SHOW_FORCED);
|
||||
etTimer.cancel();
|
||||
|
||||
}
|
||||
}, 500);
|
||||
//resetPassword_phoneUser-false-start
|
||||
tvGetCode.setOnClickListener(this);
|
||||
//resetPassword_phoneUser-false-end
|
||||
btnReset.setOnClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
switch (v.getId()) {
|
||||
//resetPassword_phoneUser-false-start
|
||||
case R.id.tvGetCode:
|
||||
name = etName.getText().toString();
|
||||
if (TextUtils.isEmpty(name)) {
|
||||
Toast.makeText(GosForgetPasswordActivity.this,
|
||||
R.string.toast_name_wrong, toastTime).show();
|
||||
return;
|
||||
}
|
||||
Message msg = new Message();
|
||||
msg.obj = name;
|
||||
msg.what = handler_key.GETCODE.ordinal();
|
||||
handler.sendMessage(msg);
|
||||
break;
|
||||
//resetPassword_phoneUser-false-end
|
||||
case R.id.btnReset:
|
||||
name = etName.getText().toString();
|
||||
//resetPassword_phoneUser-false-start
|
||||
code = etCode.getText().toString();
|
||||
psw = etPsw.getText().toString();
|
||||
confirmpsw = etConfirmPsw.getText().toString();
|
||||
if (TextUtils.isEmpty(name)) {
|
||||
Toast.makeText(GosForgetPasswordActivity.this,
|
||||
R.string.toast_name_wrong, toastTime).show();
|
||||
return;
|
||||
}
|
||||
|
||||
if (llPhone.getVisibility() == View.VISIBLE) {
|
||||
if (code.length() != 6) {
|
||||
Toast.makeText(GosForgetPasswordActivity.this, R.string.no_getcode, toastTime).show();
|
||||
return;
|
||||
}
|
||||
if (TextUtils.isEmpty(psw)) {
|
||||
Toast.makeText(GosForgetPasswordActivity.this,
|
||||
R.string.toast_psw_wrong, toastTime).show();
|
||||
return;
|
||||
}
|
||||
if (psw.length() < 6) {
|
||||
Toast.makeText(GosForgetPasswordActivity.this,
|
||||
R.string.toast_psw_short, toastTime).show();
|
||||
return;
|
||||
}
|
||||
if (!psw.equals(confirmpsw)) {
|
||||
Toast.makeText(GosForgetPasswordActivity.this, R.string.toast_psw_confirm_failed, toastTime).show();
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
//resetPassword_phoneUser-false-end
|
||||
if (!name.contains("@")) {
|
||||
Toast.makeText(GosForgetPasswordActivity.this, R.string.toase_name_email_fault, toastTime).show();
|
||||
return;
|
||||
}
|
||||
//resetPassword_phoneUser-false-start
|
||||
}
|
||||
//resetPassword_phoneUser-false-end
|
||||
|
||||
/*
|
||||
* if (psw.length() < 6) {
|
||||
* Toast.makeText(GosForgetPasswordActivity.this,
|
||||
* R.string.toast_psw_short, toastTime).show(); return; }
|
||||
*/
|
||||
handler.sendEmptyMessage(handler_key.RESET.ordinal());
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 倒计时
|
||||
*/
|
||||
public void isStartTimer() {
|
||||
tvGetCode.setEnabled(false);
|
||||
tvGetCode.setTextColor(getResources().getColor(R.color.hint_color));
|
||||
secondleft = 60;
|
||||
timer = new Timer();
|
||||
timer.schedule(new TimerTask() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
handler.sendEmptyMessage(handler_key.TICK_TIME.ordinal());
|
||||
}
|
||||
}, 1000, 1000);
|
||||
}
|
||||
|
||||
/**
|
||||
* 手机验证码回调
|
||||
*/
|
||||
@Override
|
||||
protected void didRequestSendPhoneSMSCode(GizWifiErrorCode result,
|
||||
String token) {
|
||||
if (progressDialog != null) {
|
||||
progressDialog.cancel();
|
||||
}
|
||||
Message msg = new Message();
|
||||
if (GizWifiErrorCode.GIZ_SDK_SUCCESS != result) {
|
||||
// String sendFailed = (String) getText(R.string.send_failed);
|
||||
msg.what = handler_key.TOAST.ordinal();
|
||||
msg.obj = toastError(result);// sendFailed + "\n" +
|
||||
// errorMessage;toastError(errorCode)
|
||||
handler.sendMessage(msg);
|
||||
} else {
|
||||
handler.sendEmptyMessage(handler_key.SENDSUCCESSFUL.ordinal());
|
||||
msg.what = handler_key.TOAST.ordinal();
|
||||
String sendSuccessful = (String) getText(R.string.send_successful);
|
||||
msg.obj = sendSuccessful;
|
||||
handler.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
//resetPassword_phoneUser-false-end
|
||||
|
||||
/**
|
||||
* 重置密码回调
|
||||
*/
|
||||
@Override
|
||||
public void didChangeUserPassword(GizWifiErrorCode result) {
|
||||
if (progressDialog != null) {
|
||||
progressDialog.cancel();
|
||||
}
|
||||
Message msg = new Message();
|
||||
if (GizWifiErrorCode.GIZ_SDK_SUCCESS != result) {
|
||||
// String resetFailed = (String) getText(R.string.reset_failed);
|
||||
msg.what = handler_key.TOAST.ordinal();
|
||||
msg.obj = toastError(result);// resetFailed + "\n" + errorMessage;
|
||||
handler.sendMessage(msg);
|
||||
} else {
|
||||
msg.what = handler_key.TOAST.ordinal();
|
||||
String resetSuccessful = (String) getText(R.string.reset_successful);
|
||||
msg.obj = resetSuccessful;
|
||||
handler.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
progressDialog = null;
|
||||
}
|
||||
}
|
@ -1,359 +0,0 @@
|
||||
package com.gizwits.opensource.appkit.UserModule;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.GradientDrawable;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.text.InputType;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.gizwits.opensource.appkit.R;
|
||||
import com.gizwits.gizwifisdk.api.GizWifiSDK;
|
||||
import com.gizwits.gizwifisdk.enumration.GizUserAccountType;
|
||||
import com.gizwits.gizwifisdk.enumration.GizWifiErrorCode;
|
||||
import com.gizwits.opensource.appkit.CommonModule.GosDeploy;
|
||||
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@SuppressLint("HandlerLeak")
|
||||
public class GosRegisterUserActivity extends GosUserModuleBaseActivity implements OnClickListener, AdapterView.OnItemSelectedListener {
|
||||
|
||||
/**
|
||||
* The et Name
|
||||
*/
|
||||
private EditText etName;
|
||||
//register_phoneUser-false-start
|
||||
/**
|
||||
* The ll code
|
||||
*/
|
||||
private LinearLayout llCode;
|
||||
|
||||
/**
|
||||
* The btn GetCode
|
||||
*/
|
||||
private TextView tvGetCode;
|
||||
|
||||
/**
|
||||
* The et Code
|
||||
*/
|
||||
private EditText etCode;
|
||||
/**
|
||||
* 验证码重发倒计时
|
||||
*/
|
||||
int secondleft = 60;
|
||||
|
||||
/**
|
||||
* The timer.
|
||||
*/
|
||||
Timer timer;
|
||||
|
||||
//register_phoneUser-false-end
|
||||
/**
|
||||
* The et Psw
|
||||
*/
|
||||
private EditText etPsw;
|
||||
|
||||
/**
|
||||
* The et ConfirmPsw
|
||||
*/
|
||||
private EditText etConfirmPsw;
|
||||
|
||||
/**
|
||||
* The btn Rrgister
|
||||
*/
|
||||
private Button btnRrgister;
|
||||
|
||||
/**
|
||||
* 数据变量
|
||||
*/
|
||||
String name, code, psw, confirmpsw;
|
||||
|
||||
private int usertype = 0;
|
||||
|
||||
private enum handler_key {
|
||||
//register_phoneUser-false-start
|
||||
/**
|
||||
* 获取验证码.
|
||||
*/
|
||||
GETCODE,
|
||||
/**
|
||||
* 手机验证码发送成功.
|
||||
*/
|
||||
SENDSUCCESSFUL,
|
||||
//register_phoneUser-false-end
|
||||
|
||||
/**
|
||||
* 提示信息
|
||||
*/
|
||||
TOAST,
|
||||
/**
|
||||
* 倒计时通知
|
||||
*/
|
||||
TICK_TIME,
|
||||
|
||||
/**
|
||||
* 注册
|
||||
*/
|
||||
REGISTER,
|
||||
}
|
||||
|
||||
Handler handler = new Handler() {
|
||||
public void handleMessage(Message msg) {
|
||||
super.handleMessage(msg);
|
||||
handler_key key = handler_key.values()[msg.what];
|
||||
switch (key) {
|
||||
//register_phoneUser-false-start
|
||||
case GETCODE:
|
||||
progressDialog.show();
|
||||
String AppSecret = GosDeploy.appConfig_GizwitsInfoAppSecret();
|
||||
GizWifiSDK.sharedInstance().requestSendPhoneSMSCode(AppSecret, msg.obj.toString());
|
||||
break;
|
||||
case SENDSUCCESSFUL:
|
||||
etName.setEnabled(false);
|
||||
etName.setTextColor(getResources().getColor(R.color.text_gray_light));
|
||||
isStartTimer();
|
||||
break;
|
||||
case TICK_TIME:
|
||||
String getCodeAgain = getString(R.string.getcode_again);
|
||||
String timerMessage = getString(R.string.timer_message);
|
||||
secondleft--;
|
||||
if (secondleft <= 0) {
|
||||
timer.cancel();
|
||||
tvGetCode.setTextColor(getResources().getColor(R.color.tomato));
|
||||
tvGetCode.setEnabled(true);
|
||||
tvGetCode.setText(getCodeAgain);
|
||||
} else {
|
||||
tvGetCode.setText(secondleft + timerMessage);
|
||||
}
|
||||
break;
|
||||
//register_phoneUser-false-end
|
||||
case TOAST:
|
||||
Toast.makeText(GosRegisterUserActivity.this, msg.obj.toString(), toastTime).show();
|
||||
String successfulText = (String) getText(R.string.register_successful);
|
||||
|
||||
if (msg.obj.toString().equals(successfulText)) {
|
||||
spf.edit().putString("UserName", name).commit();
|
||||
spf.edit().putString("PassWord", psw).commit();
|
||||
isclean = true;
|
||||
finish();
|
||||
}
|
||||
break;
|
||||
case REGISTER:
|
||||
progressDialog.show();
|
||||
GizWifiSDK.sharedInstance().registerUser(name, psw, code, GizUserAccountType.GizUserPhone);
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_gos_register_user);
|
||||
// 设置ActionBar
|
||||
setToolBar(true, R.string.register);
|
||||
initView();
|
||||
initEvent();
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
etName = (EditText) findViewById(R.id.etName);
|
||||
//register_phoneUser-false-start
|
||||
tvGetCode = (TextView) findViewById(R.id.tvGetCode);
|
||||
etCode = (EditText) findViewById(R.id.etCode);
|
||||
llCode = (LinearLayout) findViewById(R.id.llCode);
|
||||
//register_phoneUser-false-end
|
||||
etPsw = (EditText) findViewById(R.id.etPsw);
|
||||
etConfirmPsw = (EditText) findViewById(R.id.etConfirmPsw);
|
||||
btnRrgister = (Button) findViewById(R.id.btnRrgister);
|
||||
setPhoneOrEmailOrNormalIsVisable();
|
||||
}
|
||||
|
||||
private void setPhoneOrEmailOrNormalIsVisable() {
|
||||
etName.setHint(getResources().getString(R.string.name_phone));
|
||||
usertype = 0;
|
||||
}
|
||||
|
||||
|
||||
private void initEvent() {
|
||||
final Timer etTimer = new Timer();
|
||||
etTimer.schedule(new TimerTask() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
etName.requestFocus();
|
||||
InputMethodManager imm = (InputMethodManager) etName.getContext()
|
||||
.getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.toggleSoftInput(0, InputMethodManager.SHOW_FORCED);
|
||||
etTimer.cancel();
|
||||
|
||||
}
|
||||
}, 500);
|
||||
//register_phoneUser-false-start
|
||||
tvGetCode.setOnClickListener(this);
|
||||
//register_phoneUser-false-end
|
||||
btnRrgister.setOnClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
switch (v.getId()) {
|
||||
//register_phoneUser-false-start
|
||||
case R.id.tvGetCode:
|
||||
name = etName.getText().toString();
|
||||
if (TextUtils.isEmpty(name)) {
|
||||
Toast.makeText(GosRegisterUserActivity.this, R.string.toast_name_wrong, toastTime).show();
|
||||
return;
|
||||
}
|
||||
Message msg = new Message();
|
||||
msg.obj = name;
|
||||
msg.what = handler_key.GETCODE.ordinal();
|
||||
handler.sendMessage(msg);
|
||||
break;
|
||||
//register_phoneUser-false-end
|
||||
case R.id.btnRrgister:
|
||||
name = etName.getText().toString();
|
||||
//register_phoneUser-false-start
|
||||
code = etCode.getText().toString();
|
||||
//register_phoneUser-false-end
|
||||
psw = etPsw.getText().toString();
|
||||
confirmpsw = etConfirmPsw.getText().toString();
|
||||
if (TextUtils.isEmpty(name)) {
|
||||
Toast.makeText(GosRegisterUserActivity.this, R.string.toast_name_wrong, toastTime).show();
|
||||
return;
|
||||
}
|
||||
if (usertype == 0) {
|
||||
if (code.length() != 6) {
|
||||
Toast.makeText(GosRegisterUserActivity.this, R.string.no_getcode, toastTime).show();
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (TextUtils.isEmpty(psw)) {
|
||||
Toast.makeText(GosRegisterUserActivity.this, R.string.toast_psw_wrong, toastTime).show();
|
||||
return;
|
||||
}
|
||||
|
||||
if (psw.length() < 6) {
|
||||
Toast.makeText(GosRegisterUserActivity.this, R.string.toast_psw_short, toastTime).show();
|
||||
return;
|
||||
}
|
||||
|
||||
if (TextUtils.isEmpty(confirmpsw)) {
|
||||
Toast.makeText(GosRegisterUserActivity.this, R.string.toast_psw_confirm, toastTime).show();
|
||||
return;
|
||||
}
|
||||
if (!psw.equals(confirmpsw)) {
|
||||
Toast.makeText(GosRegisterUserActivity.this, R.string.toast_psw_confirm_failed, toastTime).show();
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* if (psw.length() < 6) {
|
||||
* Toast.makeText(GosRegisterUserActivity.this,
|
||||
* R.string.toast_psw_short, toastTime).show(); return; }
|
||||
*/
|
||||
handler.sendEmptyMessage(handler_key.REGISTER.ordinal());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
etName.setText("");
|
||||
etName.setEnabled(true);
|
||||
etName.setTextColor(getResources().getColor(R.color.text_color));
|
||||
//register_phoneUser-false-start
|
||||
etCode.setText("");
|
||||
//register_phoneUser-false-end
|
||||
etPsw.setText("");
|
||||
etConfirmPsw.setText("");
|
||||
etName.setHint(getResources().getString(R.string.name_phone));
|
||||
llCode.setVisibility(View.VISIBLE);
|
||||
etName.setInputType(InputType.TYPE_CLASS_PHONE);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> parent) {
|
||||
|
||||
}
|
||||
//register_phoneUser-false-start
|
||||
|
||||
/**
|
||||
* 手机验证码回调
|
||||
*/
|
||||
@Override
|
||||
protected void didRequestSendPhoneSMSCode(GizWifiErrorCode result, String token) {
|
||||
progressDialog.cancel();
|
||||
Message msg = new Message();
|
||||
if (GizWifiErrorCode.GIZ_SDK_SUCCESS != result) {
|
||||
msg.what = handler_key.TOAST.ordinal();
|
||||
msg.obj = toastError(result);
|
||||
handler.sendMessage(msg);
|
||||
} else {
|
||||
handler.sendEmptyMessage(handler_key.SENDSUCCESSFUL.ordinal());
|
||||
msg.what = handler_key.TOAST.ordinal();
|
||||
String sendSuccessful = (String) getText(R.string.send_successful);
|
||||
msg.obj = sendSuccessful;
|
||||
handler.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 倒计时
|
||||
*/
|
||||
public void isStartTimer() {
|
||||
tvGetCode.setEnabled(false);
|
||||
tvGetCode.setTextColor(getResources().getColor(R.color.hint_color));
|
||||
secondleft = 60;
|
||||
timer = new Timer();
|
||||
timer.schedule(new TimerTask() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
handler.sendEmptyMessage(handler_key.TICK_TIME.ordinal());
|
||||
}
|
||||
}, 1000, 1000);
|
||||
}
|
||||
//register_phoneUser-false-end
|
||||
|
||||
/**
|
||||
* 用户注册回调
|
||||
*/
|
||||
@Override
|
||||
protected void didRegisterUser(GizWifiErrorCode result, String uid, String token) {
|
||||
progressDialog.cancel();
|
||||
if (GizWifiErrorCode.GIZ_SDK_SUCCESS != result) {
|
||||
Message msg = new Message();
|
||||
msg.what = handler_key.TOAST.ordinal();
|
||||
msg.obj = toastError(result);
|
||||
handler.sendMessage(msg);
|
||||
} else {
|
||||
Message msg = new Message();
|
||||
msg.what = handler_key.TOAST.ordinal();
|
||||
String registerSuccessful = (String) getText(R.string.register_successful);
|
||||
msg.obj = registerSuccessful;
|
||||
handler.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,69 +0,0 @@
|
||||
package com.gizwits.opensource.appkit.UserModule;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.text.SpannableString;
|
||||
import android.text.Spanned;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gizwits.opensource.appkit.R;
|
||||
import com.gizwits.opensource.appkit.CommonModule.GosBaseActivity;
|
||||
|
||||
|
||||
public class GosSendEmailPasswordActivity extends GosBaseActivity {
|
||||
|
||||
private TextView tvEmail;
|
||||
private Button btnReturn;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_gos_send_email_password);
|
||||
// 设置ActionBar
|
||||
setToolBar(true, R.string.forget_pass);
|
||||
initView();
|
||||
initEvent();
|
||||
}
|
||||
|
||||
private static final String TAG = "GosSendEmailPasswordAct";
|
||||
|
||||
private void initView() {
|
||||
tvEmail = (TextView) findViewById(R.id.tvEmail);
|
||||
btnReturn = (Button) findViewById(R.id.btnReturn);
|
||||
}
|
||||
|
||||
private void initEvent() {
|
||||
String email = spf.getString("Email", "xxx@xxx.xx");
|
||||
String s = getResources().getString(R.string.send_email_pass);
|
||||
//字符串截取
|
||||
String bb = s.substring(10, 20);
|
||||
//字符串替换
|
||||
String cc = s.replace(bb, email);
|
||||
SpannableString spannableString = new SpannableString(cc);
|
||||
spannableString.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.tomato)), 10, 10 + email.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
tvEmail.setText(spannableString);
|
||||
btnReturn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(GosSendEmailPasswordActivity.this, GosUserLoginActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
this.finish();
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,163 +0,0 @@
|
||||
package com.gizwits.opensource.appkit.UserModule;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gizwits.opensource.appkit.CommonModule.GosBaseActivity;
|
||||
import com.gizwits.opensource.appkit.CommonModule.GosDeploy;
|
||||
import com.gizwits.opensource.appkit.DeviceModule.GosDeviceListFragment;
|
||||
import com.gizwits.opensource.appkit.PushModule.GosPushManager;
|
||||
import com.gizwits.opensource.appkit.R;
|
||||
|
||||
//push-all-start
|
||||
//push-all-end
|
||||
|
||||
public class GosUserManager extends GosBaseActivity {
|
||||
|
||||
private static final int GOSUSERMANAGER = 234;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_gos_usermanager);
|
||||
setToolBar(true, R.string.user_management);
|
||||
initView();
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
TextView phoneusernumber = (TextView) findViewById(R.id.phoneusernumber);
|
||||
//personalCenter_changePassword-false-start
|
||||
LinearLayout changeuserpassword = (LinearLayout) findViewById(R.id.changeuserpassword);
|
||||
if (!GosDeploy.appConfig_PersonalCenter_ChangePassword()) {
|
||||
changeuserpassword.setVisibility(View.GONE);
|
||||
}
|
||||
//personalCenter_changePassword-false-end
|
||||
if (!TextUtils.isEmpty(spf.getString("UserName", ""))) {
|
||||
phoneusernumber.setText(spf.getString("UserName", ""));
|
||||
} else {
|
||||
//personalCenter_changePassword-false-start
|
||||
String uid = spf.getString("thirdUid", "");
|
||||
if (!TextUtils.isEmpty(uid) && uid.length() != 0) {
|
||||
String myuid = uid.substring(0, 2) + "***" + uid.substring(uid.length() - 4, uid.length());
|
||||
phoneusernumber.setText(myuid);
|
||||
changeuserpassword.setVisibility(View.GONE);
|
||||
}
|
||||
//personalCenter_changePassword-false-end
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void userlogout(View v) {
|
||||
setResult(GOSUSERMANAGER);
|
||||
logoutToClean();
|
||||
|
||||
Intent intent = new Intent(GosUserManager.this, GosUserLoginActivity.class);
|
||||
quitAlert(intent, getString(R.string.exit_login));
|
||||
|
||||
}
|
||||
|
||||
//personalCenter_changePassword-false-start
|
||||
public void changeuserpassword(View v) {
|
||||
Intent tent = new Intent(this, GosChangeUserPasswordActivity.class);
|
||||
startActivity(tent);
|
||||
}
|
||||
//personalCenter_changePassword-false-end
|
||||
|
||||
private void logoutToClean() {
|
||||
//push-all-start
|
||||
GosPushManager.pushUnBindService(spf.getString("Token", ""));
|
||||
//push-all-end
|
||||
spf.edit().putString("UserName", "").commit();
|
||||
isclean = true;
|
||||
spf.edit().putString("PassWord", "").commit();
|
||||
spf.edit().putString("Uid", "").commit();
|
||||
spf.edit().putString("Token", "").commit();
|
||||
|
||||
spf.edit().putString("thirdUid", "").commit();
|
||||
|
||||
if (GosDeviceListFragment.loginStatus == 1) {
|
||||
GosDeviceListFragment.loginStatus = 0;
|
||||
} else {
|
||||
GosDeviceListFragment.loginStatus = 4;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
isclean = false;
|
||||
finish();
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||
isclean = false;
|
||||
finish();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 推出提示
|
||||
*
|
||||
* @param
|
||||
*/
|
||||
protected void quitAlert(final Intent intent, String content) {
|
||||
final Dialog dialog = new AlertDialog.Builder(this, R.style.alert_dialog_style)
|
||||
.setView(new EditText(this)).create();
|
||||
dialog.setCanceledOnTouchOutside(false);
|
||||
dialog.show();
|
||||
|
||||
Window window = dialog.getWindow();
|
||||
window.setContentView(R.layout.alert_gos_quit);
|
||||
WindowManager.LayoutParams layoutParams = window.getAttributes();
|
||||
layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
|
||||
window.setAttributes(layoutParams);
|
||||
TextView tvContent;
|
||||
LinearLayout llNo, llSure;
|
||||
llNo = (LinearLayout) window.findViewById(R.id.llNo);
|
||||
llSure = (LinearLayout) window.findViewById(R.id.llSure);
|
||||
tvContent = (TextView) window.findViewById(R.id.tv_prompt);
|
||||
|
||||
tvContent.setText(content);
|
||||
|
||||
llNo.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dialog.cancel();
|
||||
}
|
||||
});
|
||||
|
||||
llSure.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
dialog.cancel();
|
||||
|
||||
startActivity(intent);
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@ -1,82 +0,0 @@
|
||||
package com.gizwits.opensource.appkit.sharingdevice;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.MenuItem;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gizwits.opensource.appkit.CommonModule.GosBaseActivity;
|
||||
import com.gizwits.opensource.appkit.R;
|
||||
|
||||
|
||||
/**
|
||||
* Created by Sunny on 2015年6月25日
|
||||
*
|
||||
* @author Sunny
|
||||
*/
|
||||
public class MsgNoticeActivity extends GosBaseActivity {
|
||||
|
||||
private ListView lvNotice;
|
||||
private TextView tvNoNotice;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_notice);
|
||||
|
||||
// setActionBar(true, true, R.string.msg_xnotice);
|
||||
initView();
|
||||
// initData();
|
||||
}
|
||||
|
||||
private void initView(){
|
||||
lvNotice=(ListView) findViewById(R.id.lvNotice);
|
||||
tvNoNotice=(TextView) findViewById(R.id.tvNoNotice);
|
||||
}
|
||||
|
||||
// private void initData(){
|
||||
// NoticeDBService dbService= new NoticeDBService(this);
|
||||
// ArrayList<NoticeBean> lsNotice=dbService.getNoticeList();
|
||||
//
|
||||
// if(lsNotice!=null&&lsNotice.size()>0){
|
||||
// lvNotice.setVisibility(View.VISIBLE);
|
||||
// tvNoNotice.setVisibility(View.GONE);
|
||||
//
|
||||
// NoticeAdapter na=new NoticeAdapter(this, lsNotice);
|
||||
// lvNotice.setAdapter(na);
|
||||
// }else{
|
||||
// lvNotice.setVisibility(View.GONE);
|
||||
// tvNoNotice.setVisibility(View.VISIBLE);
|
||||
// }
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
// initData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
public boolean onOptionsItemSelected(MenuItem menu) {
|
||||
super.onOptionsItemSelected(menu);
|
||||
switch (menu.getItemId()) {
|
||||
case android.R.id.home:
|
||||
finish();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
finish();
|
||||
}
|
||||
|
||||
}
|
@ -1,233 +0,0 @@
|
||||
package com.gizwits.opensource.appkit.sharingdevice;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentStatePagerAdapter;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.gizwits.gizwifisdk.api.GizDeviceSharing;
|
||||
import com.gizwits.gizwifisdk.api.GizDeviceSharingInfo;
|
||||
import com.gizwits.gizwifisdk.enumration.GizDeviceSharingType;
|
||||
import com.gizwits.gizwifisdk.enumration.GizWifiErrorCode;
|
||||
import com.gizwits.gizwifisdk.listener.GizDeviceSharingListener;
|
||||
import com.gizwits.opensource.appkit.CommonModule.GosBaseActivity;
|
||||
import com.gizwits.opensource.appkit.CommonModule.GosConstant;
|
||||
import com.gizwits.opensource.appkit.CommonModule.NoScrollViewPager;
|
||||
import com.gizwits.opensource.appkit.R;
|
||||
import com.gizwits.opensource.appkit.utils.DateUtil;
|
||||
import com.gizwits.opensource.appkit.view.ViewPagerIndicator;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
public class SharedDeviceListAcitivity extends GosBaseActivity {
|
||||
|
||||
private List<String> tabList;
|
||||
private List<Fragment> myfragmentlist;
|
||||
private String token;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.activity_gos_shared_device_list);
|
||||
|
||||
setToolBar(true, R.string.sharedlist);
|
||||
initData();
|
||||
initView();
|
||||
}
|
||||
|
||||
// 初始化tab标签中应该显示的文字
|
||||
private void initData() {
|
||||
|
||||
token = spf.getString("Token", "");
|
||||
|
||||
myfragmentlist = new ArrayList<Fragment>();
|
||||
|
||||
SharedFragment ment1 = new SharedFragment();
|
||||
|
||||
InvitedFragment ment2 = new InvitedFragment();
|
||||
|
||||
|
||||
myfragmentlist.add(ment1);
|
||||
myfragmentlist.add(ment2);
|
||||
|
||||
tabList = new ArrayList<String>();
|
||||
tabList.add(getResources().getString(R.string.shared));
|
||||
tabList.add(getResources().getString(R.string.invited));
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
|
||||
ViewPagerIndicator indicator = (ViewPagerIndicator) findViewById(
|
||||
R.id.vpi_indicator);
|
||||
|
||||
indicator.setVisibleTabCount(2);
|
||||
indicator.setTabItemTitles(tabList);
|
||||
NoScrollViewPager vp_shared = (NoScrollViewPager) findViewById(R.id.vp_shared_list);
|
||||
|
||||
vp_shared.setNoScroll(true);
|
||||
|
||||
vp_shared.setAdapter(new myFragmentAdapter(getSupportFragmentManager()));
|
||||
|
||||
indicator.setViewPager(vp_shared, 0);
|
||||
|
||||
indicator.setOnPageChangeListener(new ViewPagerIndicator.PageChangeListener() {
|
||||
|
||||
@Override
|
||||
public void onPageSelected(int position) {
|
||||
GosConstant.nowPager = position;
|
||||
|
||||
switch (GosConstant.nowPager) {
|
||||
case 0:
|
||||
|
||||
break;
|
||||
|
||||
case 1:
|
||||
GizDeviceSharing.getDeviceSharingInfos(token, GizDeviceSharingType.GizDeviceSharingToMe, null);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageScrollStateChanged(int state) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
class myFragmentAdapter extends FragmentStatePagerAdapter {
|
||||
|
||||
public myFragmentAdapter(FragmentManager fm) {
|
||||
super(fm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment getItem(int arg0) {
|
||||
|
||||
if (arg0 == 0) {
|
||||
SharedFragment shared = new SharedFragment();
|
||||
|
||||
return shared;
|
||||
} else {
|
||||
InvitedFragment shared = (InvitedFragment) myfragmentlist.get(arg0);
|
||||
|
||||
return shared;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
finish();
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
// TODO Auto-generated method stub
|
||||
super.onResume();
|
||||
|
||||
initListener();
|
||||
}
|
||||
|
||||
// 初始化接口数据
|
||||
private void initListener() {
|
||||
|
||||
GizDeviceSharing.setListener(new GizDeviceSharingListener() {
|
||||
|
||||
@Override
|
||||
public void didGetDeviceSharingInfos(GizWifiErrorCode result, String deviceID,
|
||||
List<GizDeviceSharingInfo> deviceSharingInfos) {
|
||||
super.didGetDeviceSharingInfos(result, deviceID, deviceSharingInfos);
|
||||
|
||||
|
||||
if (deviceSharingInfos != null) {
|
||||
Collections.sort(deviceSharingInfos, new Comparator<GizDeviceSharingInfo>() {
|
||||
|
||||
@Override
|
||||
public int compare(GizDeviceSharingInfo arg0, GizDeviceSharingInfo arg1) {
|
||||
|
||||
String updatedAt = DateUtil.utc2Local(arg0.getUpdatedAt());
|
||||
String updatedAt2 = DateUtil.utc2Local(arg1.getUpdatedAt());
|
||||
|
||||
int diff = (int) DateUtil.getDiff(updatedAt2, updatedAt);
|
||||
|
||||
return diff;
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
GosConstant.newmydeviceSharingInfos = deviceSharingInfos;
|
||||
|
||||
InvitedFragment fragment = (InvitedFragment) myfragmentlist.get(1);
|
||||
TextView myview = fragment.getmyview();
|
||||
if (deviceSharingInfos.size() == 0) {
|
||||
|
||||
myview.setVisibility(View.VISIBLE);
|
||||
myview.setText(getResources().getString(R.string.no_guest_users));
|
||||
} else {
|
||||
myview.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
InvitedFragment.myadapter getmyadapter = fragment.getmyadapter();
|
||||
getmyadapter.notifyDataSetChanged();
|
||||
|
||||
if (result.ordinal() != 0) {
|
||||
Toast.makeText(SharedDeviceListAcitivity.this, toastError(result), 2).show();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void didAcceptDeviceSharing(GizWifiErrorCode result, int sharingID) {
|
||||
super.didAcceptDeviceSharing(result, sharingID);
|
||||
|
||||
if (result.ordinal() != 0) {
|
||||
Toast.makeText(SharedDeviceListAcitivity.this, toastError(result), 2).show();
|
||||
}
|
||||
|
||||
GizDeviceSharing.getDeviceSharingInfos(token, GizDeviceSharingType.GizDeviceSharingToMe, null);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@ -1,282 +0,0 @@
|
||||
package com.gizwits.opensource.appkit.sharingdevice;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Bundle;
|
||||
import android.os.Message;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentStatePagerAdapter;
|
||||
import android.view.MenuItem;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.gizwits.gizwifisdk.api.GizDeviceSharing;
|
||||
import com.gizwits.gizwifisdk.api.GizDeviceSharingInfo;
|
||||
import com.gizwits.gizwifisdk.api.GizUserInfo;
|
||||
import com.gizwits.gizwifisdk.enumration.GizDeviceSharingType;
|
||||
import com.gizwits.gizwifisdk.enumration.GizWifiErrorCode;
|
||||
import com.gizwits.gizwifisdk.listener.GizDeviceSharingListener;
|
||||
import com.gizwits.opensource.appkit.CommonModule.GosBaseActivity;
|
||||
import com.gizwits.opensource.appkit.CommonModule.GosConstant;
|
||||
import com.gizwits.opensource.appkit.CommonModule.NoScrollViewPager;
|
||||
import com.gizwits.opensource.appkit.R;
|
||||
import com.gizwits.opensource.appkit.utils.DateUtil;
|
||||
import com.gizwits.opensource.appkit.view.ViewPagerIndicator;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
public class SharedDeviceManagerActivity extends GosBaseActivity {
|
||||
|
||||
private List<String> tabList;
|
||||
private String productname;
|
||||
private String deviceid;
|
||||
private List<Fragment> myfragmentlist;
|
||||
private int viewPagerSelected = 0;
|
||||
private boolean isgetsharing;
|
||||
private String token;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.activity_gos_shared_device_list);
|
||||
|
||||
setToolBar(true, R.string.sharedmanager);
|
||||
GosConstant.isEdit = false;
|
||||
initData();
|
||||
initView();
|
||||
token = spf.getString("Token", "");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
||||
GizDeviceSharing.setListener(new GizDeviceSharingListener() {
|
||||
|
||||
@Override
|
||||
public void didSharingDevice(GizWifiErrorCode result, String deviceID, int sharingID, Bitmap QRCodeImage) {
|
||||
super.didSharingDevice(result, deviceID, sharingID, QRCodeImage);
|
||||
|
||||
if (result.ordinal() != 0) {
|
||||
Toast.makeText(SharedDeviceManagerActivity.this, toastError(result), 1).show();
|
||||
}
|
||||
GizDeviceSharing.getDeviceSharingInfos(token, GizDeviceSharingType.GizDeviceSharingByMe, deviceid);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void didModifySharingInfo(GizWifiErrorCode result, int sharingID) {
|
||||
super.didModifySharingInfo(result, sharingID);
|
||||
|
||||
if (result.ordinal() != 0) {
|
||||
Toast.makeText(SharedDeviceManagerActivity.this, toastError(result), 1).show();
|
||||
}
|
||||
GizDeviceSharing.getDeviceSharingInfos(token, GizDeviceSharingType.GizDeviceSharingByMe, deviceid);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void didGetDeviceSharingInfos(GizWifiErrorCode result, String deviceID,
|
||||
List<GizDeviceSharingInfo> deviceSharingInfos) {
|
||||
super.didGetDeviceSharingInfos(result, deviceID, deviceSharingInfos);
|
||||
|
||||
if (deviceSharingInfos != null) {
|
||||
Collections.sort(deviceSharingInfos, new Comparator<GizDeviceSharingInfo>() {
|
||||
|
||||
@Override
|
||||
public int compare(GizDeviceSharingInfo arg0, GizDeviceSharingInfo arg1) {
|
||||
|
||||
String updatedAt = DateUtil.utc2Local(arg0.getUpdatedAt());
|
||||
String updatedAt2 = DateUtil.utc2Local(arg1.getUpdatedAt());
|
||||
|
||||
int diff = (int) DateUtil.getDiff(updatedAt2, updatedAt);
|
||||
|
||||
return diff;
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
GosConstant.mydeviceSharingInfos = deviceSharingInfos;
|
||||
SharedStateFragment fragment = (SharedStateFragment) myfragmentlist.get(0);
|
||||
Message msg = new Message();
|
||||
msg.what = 1;
|
||||
fragment.handler.sendMessage(msg);
|
||||
SharedUserFragment fragment1 = (SharedUserFragment) myfragmentlist.get(1);
|
||||
Message msg1 = new Message();
|
||||
msg1.what = 1;
|
||||
fragment1.handler.sendMessage(msg1);
|
||||
if (result.ordinal() != 0) {
|
||||
Toast.makeText(SharedDeviceManagerActivity.this, toastError(result), 1).show();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void didGetBindingUsers(GizWifiErrorCode result, String deviceID, List<GizUserInfo> bindUsers) {
|
||||
super.didGetBindingUsers(result, deviceID, bindUsers);
|
||||
GosConstant.mybindUsers = bindUsers;
|
||||
SharedUserFragment fragment = (SharedUserFragment) myfragmentlist.get(1);
|
||||
SharedUserFragment.myadapter getmyadapter = fragment.getmyadapter();
|
||||
|
||||
if (getmyadapter != null) {
|
||||
getmyadapter.notifyDataSetChanged();
|
||||
}
|
||||
if (result.ordinal() != 0) {
|
||||
Toast.makeText(SharedDeviceManagerActivity.this, toastError(result), 1).show();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void didUnbindUser(GizWifiErrorCode result, String deviceID, String guestUID) {
|
||||
// TODO Auto-generated method stub
|
||||
super.didUnbindUser(result, deviceID, guestUID);
|
||||
|
||||
GizDeviceSharing.getBindingUsers(token, deviceid);
|
||||
|
||||
if (result.ordinal() != 0) {
|
||||
Toast.makeText(SharedDeviceManagerActivity.this, toastError(result), 1).show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void didRevokeDeviceSharing(GizWifiErrorCode result, int sharingID) {
|
||||
// TODO Auto-generated method stub
|
||||
super.didRevokeDeviceSharing(result, sharingID);
|
||||
|
||||
if (result.ordinal() == 0) {
|
||||
GizDeviceSharing.getDeviceSharingInfos(token, GizDeviceSharingType.GizDeviceSharingByMe, deviceid);
|
||||
} else {
|
||||
|
||||
Toast.makeText(SharedDeviceManagerActivity.this, toastError(result), 1).show();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
// 初始化tab标签中应该显示的文字
|
||||
private void initData() {
|
||||
productname = getIntent().getStringExtra("productname");
|
||||
deviceid = getIntent().getStringExtra("deviceid");
|
||||
isgetsharing = getIntent().getBooleanExtra("isgetsharing", false);
|
||||
|
||||
tabList = new ArrayList<String>();
|
||||
tabList.add(getResources().getString(R.string.sharedstated));
|
||||
tabList.add(getResources().getString(R.string.boundusers));
|
||||
|
||||
SharedStateFragment shared = new SharedStateFragment();
|
||||
|
||||
SharedUserFragment shared1 = new SharedUserFragment();
|
||||
|
||||
myfragmentlist = new ArrayList<Fragment>();
|
||||
|
||||
myfragmentlist.add(shared);
|
||||
myfragmentlist.add(shared1);
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
|
||||
ViewPagerIndicator indicator = (ViewPagerIndicator) findViewById(
|
||||
R.id.vpi_indicator);
|
||||
|
||||
indicator.setVisibleTabCount(2);
|
||||
indicator.setTabItemTitles(tabList);
|
||||
NoScrollViewPager vp_shared = (NoScrollViewPager) findViewById(
|
||||
R.id.vp_shared_list);
|
||||
|
||||
vp_shared.setNoScroll(true);
|
||||
|
||||
vp_shared.setAdapter(new myFragmentAdapter(getSupportFragmentManager()));
|
||||
|
||||
indicator.setViewPager(vp_shared, 0);
|
||||
indicator.setOnPageChangeListener(new ViewPagerIndicator.PageChangeListener() {
|
||||
|
||||
@Override
|
||||
public void onPageSelected(int position) {
|
||||
|
||||
viewPagerSelected = position;
|
||||
|
||||
if (position == 0 && isgetsharing) {
|
||||
SharedPreferences spf = getSharedPreferences("set", Context.MODE_PRIVATE);
|
||||
String token = spf.getString("Token", "");
|
||||
GizDeviceSharing.getDeviceSharingInfos(token, GizDeviceSharingType.GizDeviceSharingByMe, deviceid);
|
||||
|
||||
} else if (position == 1 && isgetsharing) {
|
||||
SharedStateFragment fragment3 = (SharedStateFragment) myfragmentlist.get(0);
|
||||
Message msg = new Message();
|
||||
msg.what = 2;
|
||||
fragment3.handler.sendMessage(msg);
|
||||
SharedPreferences spf = getSharedPreferences("set", Context.MODE_PRIVATE);
|
||||
String token = spf.getString("Token", "");
|
||||
GizDeviceSharing.getBindingUsers(token, deviceid);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageScrollStateChanged(int state) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
class myFragmentAdapter extends FragmentStatePagerAdapter {
|
||||
|
||||
public myFragmentAdapter(FragmentManager fm) {
|
||||
super(fm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Fragment getItem(int arg0) {
|
||||
|
||||
Bundle b = new Bundle();
|
||||
b.putString("productname", productname);
|
||||
b.putString("deviceid", deviceid);
|
||||
|
||||
Fragment fragment = myfragmentlist.get(arg0);
|
||||
|
||||
fragment.setArguments(b);
|
||||
|
||||
return fragment;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return myfragmentlist.size();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
|
||||
finish();
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
// 刷新menu的方法
|
||||
private void refreshMenu() {
|
||||
// 核心是Activity这个方法
|
||||
supportInvalidateOptionsMenu();
|
||||
}
|
||||
}
|
@ -1,88 +0,0 @@
|
||||
package com.gizwits.opensource.appkit.sharingdevice;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.gizwits.opensource.appkit.CommonModule.GosBaseActivity;
|
||||
import com.gizwits.opensource.appkit.R;
|
||||
|
||||
|
||||
public class addSharedActivity extends GosBaseActivity {
|
||||
|
||||
private String productname;
|
||||
private String did;
|
||||
private LinearLayout devicetwoshared;
|
||||
private LinearLayout usershared;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.activity_gos_addshared);
|
||||
setToolBar(true, R.string.addshared);
|
||||
|
||||
initData();
|
||||
initView();
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
usershared = (LinearLayout) findViewById(R.id.usershared);
|
||||
devicetwoshared = (LinearLayout) findViewById(R.id.devicetwoshared);
|
||||
}
|
||||
|
||||
private void initData() {
|
||||
Intent tent = getIntent();
|
||||
productname = tent.getStringExtra("productname");
|
||||
did = tent.getStringExtra("did");
|
||||
}
|
||||
|
||||
// personalCenter_deviceSharing_qrcode-false-start
|
||||
// 二维码分享
|
||||
public void devicetwoshared(View v) {
|
||||
Intent tent = new Intent(this, twoSharedActivity.class);
|
||||
tent.putExtra("productname", productname);
|
||||
tent.putExtra("did", did);
|
||||
startActivity(tent);
|
||||
|
||||
devicetwoshared.setEnabled(false);
|
||||
devicetwoshared.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
devicetwoshared.setEnabled(true);
|
||||
}
|
||||
}, 1000);
|
||||
|
||||
}
|
||||
//personalCenter_deviceSharing_qrcode-false-end
|
||||
|
||||
// 用户账号分享
|
||||
|
||||
public void usershared(View v) {
|
||||
|
||||
Intent tent = new Intent(this, userSharedActivity.class);
|
||||
tent.putExtra("productname", productname);
|
||||
tent.putExtra("did", did);
|
||||
startActivity(tent);
|
||||
|
||||
usershared.setEnabled(false);
|
||||
usershared.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
usershared.setEnabled(true);
|
||||
}
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
this.finish();
|
||||
break;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
@ -1,276 +0,0 @@
|
||||
package com.gizwits.opensource.appkit.sharingdevice;
|
||||
|
||||
|
||||
import android.app.ProgressDialog;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gizwits.gizwifisdk.api.GizDeviceSharing;
|
||||
import com.gizwits.gizwifisdk.api.GizMessage;
|
||||
import com.gizwits.gizwifisdk.enumration.GizMessageStatus;
|
||||
import com.gizwits.gizwifisdk.enumration.GizMessageType;
|
||||
import com.gizwits.gizwifisdk.enumration.GizWifiErrorCode;
|
||||
import com.gizwits.gizwifisdk.listener.GizDeviceSharingListener;
|
||||
import com.gizwits.opensource.appkit.CommonModule.GosBaseActivity;
|
||||
import com.gizwits.opensource.appkit.R;
|
||||
import com.gizwits.opensource.appkit.utils.DateUtil;
|
||||
import com.gizwits.opensource.appkit.view.SlideListView2;
|
||||
import com.gizwits.opensource.appkit.view.VerticalSwipeRefreshLayout;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
public class deviceSharedMessageActivity extends GosBaseActivity implements SwipeRefreshLayout.OnRefreshListener {
|
||||
|
||||
private List<GizMessage> mymessageList = new ArrayList<GizMessage>();
|
||||
private myadapter myadapter;
|
||||
private String token;
|
||||
private String myid = "";
|
||||
private int myposition = -1;
|
||||
// 删除时需要用到的对话框
|
||||
private ProgressDialog progressDialog;
|
||||
private TextView tvNoMessage;
|
||||
private VerticalSwipeRefreshLayout mSwipeLayout;
|
||||
|
||||
Handler handler = new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
super.handleMessage(msg);
|
||||
switch (msg.what) {
|
||||
case 1:
|
||||
mSwipeLayout.setRefreshing(false);
|
||||
GizDeviceSharing.queryMessageList(token, GizMessageType.GizMessageSharing);
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_device_shared_message_list);
|
||||
setToolBar(true, R.string.devicesharedmess);
|
||||
initView();
|
||||
initData();
|
||||
initProgressBar();
|
||||
}
|
||||
|
||||
private void initProgressBar() {
|
||||
progressDialog = new ProgressDialog(this);
|
||||
String loadingText = getString(R.string.loadingtext);
|
||||
progressDialog.setMessage(loadingText);
|
||||
progressDialog.setCanceledOnTouchOutside(false);
|
||||
}
|
||||
|
||||
// 初始化分享设备的数据
|
||||
private void initData() {
|
||||
//
|
||||
// GizDeviceSharing.setListener(new GizDeviceSharingListener() {
|
||||
//
|
||||
// @Override
|
||||
// public void didQueryMessageList(GizWifiErrorCode result,
|
||||
// List<GizMessage> messageList) {
|
||||
// super.didQueryMessageList(result, messageList);
|
||||
//
|
||||
// mymessageList = messageList;
|
||||
// myadapter.notifyDataSetChanged();
|
||||
// }
|
||||
//
|
||||
// });
|
||||
token = spf.getString("Token", "");
|
||||
GizDeviceSharing.queryMessageList(token, GizMessageType.GizMessageSharing);
|
||||
// GizDeviceSharing.queryMessageList(token,
|
||||
// GizMessageType.GizMessageSystem);
|
||||
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
|
||||
SlideListView2 devicelist = (SlideListView2) findViewById(R.id.devicelist);
|
||||
tvNoMessage = (TextView) findViewById(R.id.tvNoMessage);
|
||||
devicelist.initSlideMode(SlideListView2.MOD_RIGHT);
|
||||
|
||||
myadapter = new myadapter();
|
||||
devicelist.setAdapter(myadapter);
|
||||
|
||||
// 下拉刷新
|
||||
|
||||
mSwipeLayout = (VerticalSwipeRefreshLayout) findViewById(R.id.id_swipe_ly);
|
||||
|
||||
mSwipeLayout.setOnRefreshListener(this);
|
||||
mSwipeLayout.setColorSchemeResources(android.R.color.holo_blue_bright, android.R.color.holo_green_light,
|
||||
android.R.color.holo_orange_light, android.R.color.holo_red_light);
|
||||
|
||||
devicelist.setOnItemClickListener(new OnItemClickListener() {
|
||||
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
|
||||
|
||||
View redpoint = arg1.findViewById(R.id.redpoint);
|
||||
|
||||
if (redpoint.getVisibility() == 0) {
|
||||
redpoint.setVisibility(View.GONE);
|
||||
GizMessage gizMessage = mymessageList.get(arg2);
|
||||
|
||||
GizDeviceSharing.markMessageStatus(token, gizMessage.getId(), GizMessageStatus.GizMessageRead);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
Message msg = new Message();
|
||||
msg.what = 1;
|
||||
handler.sendMessageDelayed(msg, 2000);
|
||||
}
|
||||
|
||||
class myadapter extends BaseAdapter {
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
|
||||
return mymessageList.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int arg0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int arg0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(final int arg0, View arg1, ViewGroup arg2) {
|
||||
|
||||
View view = View.inflate(deviceSharedMessageActivity.this, R.layout.activity_device_item, null);
|
||||
|
||||
TextView mess = (TextView) view.findViewById(R.id.mess);
|
||||
TextView timemess = (TextView) view.findViewById(R.id.timemess);
|
||||
|
||||
View redpoint = view.findViewById(R.id.redpoint);
|
||||
|
||||
RelativeLayout delete2 = (RelativeLayout) view.findViewById(R.id.delete2);
|
||||
|
||||
delete2.setOnClickListener(new OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View c) {
|
||||
GizMessage gizMessage = mymessageList.get(arg0);
|
||||
|
||||
String id = gizMessage.getId();
|
||||
myid = id;
|
||||
myposition = arg0;
|
||||
GizDeviceSharing.markMessageStatus(token, gizMessage.getId(), GizMessageStatus.GizMessageDeleted);
|
||||
progressDialog.show();
|
||||
}
|
||||
});
|
||||
|
||||
GizMessage gizMessage = mymessageList.get(arg0);
|
||||
|
||||
mess.setText(gizMessage.getContent());
|
||||
|
||||
timemess.setText(DateUtil.utc2Local(gizMessage.getUpdatedAt()));
|
||||
|
||||
int ordinal = gizMessage.getStatus().ordinal();
|
||||
|
||||
if (ordinal == 0) {
|
||||
redpoint.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
redpoint.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
finish();
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
//GizDeviceSharing.queryMessageList
|
||||
|
||||
GizDeviceSharing.setListener(new GizDeviceSharingListener() {
|
||||
|
||||
@Override
|
||||
public void didMarkMessageStatus(GizWifiErrorCode result, String messageID) {
|
||||
super.didMarkMessageStatus(result, messageID);
|
||||
|
||||
if (result.ordinal() == 0 && myid.equals(messageID)) {
|
||||
|
||||
if (mymessageList.size() > myposition && myposition != -1) {
|
||||
|
||||
GizDeviceSharing.queryMessageList(token, GizMessageType.GizMessageSharing);
|
||||
}
|
||||
} else {
|
||||
|
||||
if (progressDialog != null && progressDialog.isShowing()) {
|
||||
progressDialog.cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void didQueryMessageList(GizWifiErrorCode result, List<GizMessage> messageList) {
|
||||
super.didQueryMessageList(result, messageList);
|
||||
|
||||
if (messageList != null) {
|
||||
Collections.sort(messageList, new Comparator<GizMessage>() {
|
||||
|
||||
@Override
|
||||
public int compare(GizMessage arg0, GizMessage arg1) {
|
||||
|
||||
String updatedAt = DateUtil.utc2Local(arg0.getUpdatedAt());
|
||||
String updatedAt2 = DateUtil.utc2Local(arg1.getUpdatedAt());
|
||||
|
||||
int diff = (int) DateUtil.getDiff(updatedAt2, updatedAt);
|
||||
|
||||
return diff;
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
if (progressDialog.isShowing()) {
|
||||
progressDialog.cancel();
|
||||
}
|
||||
mymessageList = messageList;
|
||||
if (mymessageList.size() != 0) {
|
||||
tvNoMessage.setVisibility(View.GONE);
|
||||
}
|
||||
myadapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
@ -1,235 +0,0 @@
|
||||
package com.gizwits.opensource.appkit.sharingdevice;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.gizwits.gizwifisdk.api.GizDeviceSharing;
|
||||
import com.gizwits.gizwifisdk.enumration.GizWifiErrorCode;
|
||||
import com.gizwits.gizwifisdk.listener.GizDeviceSharingListener;
|
||||
import com.gizwits.opensource.appkit.CommonModule.GosBaseActivity;
|
||||
import com.gizwits.opensource.appkit.R;
|
||||
import com.gizwits.opensource.appkit.utils.DateUtil;
|
||||
|
||||
public class gosZxingDeviceSharingActivity extends GosBaseActivity {
|
||||
|
||||
private String code;
|
||||
private int time = 15;
|
||||
private String[] split2s;
|
||||
private String tip;
|
||||
private TextView tiptext;
|
||||
private String token;
|
||||
private Button yes;
|
||||
private Button no;
|
||||
private TextView zxingtext;
|
||||
private String whoshared;
|
||||
private String[] splits;
|
||||
private String userName;
|
||||
private String productName;
|
||||
private String deviceAlias;
|
||||
private String expiredAt;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.gos_devicesharing_zxing_activity);
|
||||
setToolBar(true, R.string.QR_code);
|
||||
initData();
|
||||
initView();
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
|
||||
zxingtext = (TextView) findViewById(R.id.zxingtext);
|
||||
|
||||
yes = (Button) findViewById(R.id.yes);
|
||||
|
||||
no = (Button) findViewById(R.id.no);
|
||||
|
||||
whoshared = getResources().getString(R.string.whoshared);
|
||||
|
||||
splits = whoshared.split("xxx");
|
||||
// [, 向你共享, ,你接受并绑定设备吗?]
|
||||
whoshared = userName + splits[1] + productName + splits[splits.length - 1];
|
||||
zxingtext.setText(whoshared);
|
||||
|
||||
String timeByFormat = DateUtil.getCurTimeByFormat("yyyy-MM-dd HH:mm:ss");
|
||||
expiredAt = DateUtil.utc2Local(expiredAt);
|
||||
long diff = DateUtil.getDiff(expiredAt, timeByFormat);
|
||||
if (diff >= 0) {
|
||||
double c = diff / 60.0;
|
||||
time = (int) Math.ceil(c);
|
||||
} else {
|
||||
tiptext.setText(getResources().getString(R.string.requestoutoftime));
|
||||
yes.setClickable(false);
|
||||
yes.setTextColor(getResources().getColor(R.color.gray));
|
||||
return;
|
||||
}
|
||||
tiptext = (TextView) findViewById(R.id.tiptext);
|
||||
tip = getResources().getString(R.string.tipthings);
|
||||
split2s = tip.split("xx");
|
||||
|
||||
tip = split2s[0] + time + split2s[1];
|
||||
|
||||
tiptext.setText(tip);
|
||||
|
||||
hand.sendEmptyMessageDelayed(1, diff % 60 * 1000);
|
||||
|
||||
yes.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
GizDeviceSharing.acceptDeviceSharingByQRCode(spf.getString("Token", ""), code);
|
||||
}
|
||||
});
|
||||
|
||||
no.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initData() {
|
||||
|
||||
Intent intent = getIntent();
|
||||
code = intent.getStringExtra("code");
|
||||
userName = intent.getStringExtra("userName");
|
||||
productName = intent.getStringExtra("productName");
|
||||
deviceAlias = intent.getStringExtra("deviceAlias");
|
||||
expiredAt = intent.getStringExtra("expiredAt");
|
||||
|
||||
token = spf.getString("Token", "");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
||||
if (time > 0) {
|
||||
tip = split2s[0] + time + split2s[1];
|
||||
|
||||
tiptext.setText(tip);
|
||||
} else {
|
||||
tiptext.setText(getResources().getString(R.string.requestoutoftime));
|
||||
yes.setClickable(false);
|
||||
yes.setTextColor(getResources().getColor(R.color.gray));
|
||||
}
|
||||
|
||||
GizDeviceSharing.setListener(new GizDeviceSharingListener() {
|
||||
|
||||
@Override
|
||||
public void didAcceptDeviceSharing(GizWifiErrorCode result, int sharingID) {
|
||||
super.didAcceptDeviceSharing(result, sharingID);
|
||||
if (result.ordinal() == 0) {
|
||||
finish();
|
||||
} else {
|
||||
Toast.makeText(gosZxingDeviceSharingActivity.this, toastError(result), 1).show();
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void didAcceptDeviceSharingByQRCode(GizWifiErrorCode result) {
|
||||
super.didAcceptDeviceSharingByQRCode(result);
|
||||
if (result.ordinal() == 0) {
|
||||
Toast.makeText(gosZxingDeviceSharingActivity.this, "success", 1).show();
|
||||
|
||||
finish();
|
||||
} else {
|
||||
Toast.makeText(gosZxingDeviceSharingActivity.this, toastError(result), 1).show();
|
||||
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void didCheckDeviceSharingInfoByQRCode(GizWifiErrorCode result, String userName, String productName,
|
||||
String deviceAlias, String expiredAt) {
|
||||
super.didCheckDeviceSharingInfoByQRCode(result, userName, productName, deviceAlias, expiredAt);
|
||||
|
||||
int errorcode = result.ordinal();
|
||||
|
||||
if (8041 <= errorcode && errorcode <= 8050 || errorcode == 8308) {
|
||||
tiptext.setVisibility(View.GONE);
|
||||
yes.setClickable(false);
|
||||
no.setClickable(false);
|
||||
yes.setTextColor(getResources().getColor(R.color.gray));
|
||||
no.setTextColor(getResources().getColor(R.color.gray));
|
||||
zxingtext.setText(getResources().getString(R.string.sorry));
|
||||
} else if (errorcode != 0) {
|
||||
tiptext.setVisibility(View.GONE);
|
||||
yes.setClickable(false);
|
||||
no.setClickable(false);
|
||||
yes.setTextColor(getResources().getColor(R.color.gray));
|
||||
no.setTextColor(getResources().getColor(R.color.gray));
|
||||
zxingtext.setText(getResources().getString(R.string.verysorry));
|
||||
} else {
|
||||
tiptext.setVisibility(View.VISIBLE);
|
||||
yes.setClickable(true);
|
||||
no.setClickable(true);
|
||||
yes.setTextColor(getResources().getColor(R.color.text_color));
|
||||
no.setTextColor(getResources().getColor(R.color.text_color));
|
||||
|
||||
whoshared = userName + splits[1] + productName + splits[splits.length - 1];
|
||||
zxingtext.setText(whoshared);
|
||||
|
||||
String timeByFormat = DateUtil.getCurTimeByFormat("yyyy-MM-dd HH:mm:ss");
|
||||
expiredAt = DateUtil.utc2Local(expiredAt);
|
||||
long diff = DateUtil.getDiff(expiredAt, timeByFormat);
|
||||
|
||||
if (diff >= 0) {
|
||||
time = (int) Math.ceil(diff / 60);
|
||||
} else {
|
||||
|
||||
}
|
||||
Toast.makeText(gosZxingDeviceSharingActivity.this, diff % 60 + "", 1).show();
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
Handler hand = new Handler() {
|
||||
public void handleMessage(android.os.Message msg) {
|
||||
|
||||
time = time - 1;
|
||||
|
||||
if (time > 0) {
|
||||
tip = split2s[0] + time + split2s[1];
|
||||
|
||||
tiptext.setText(tip);
|
||||
hand.sendEmptyMessageDelayed(1, 60000);
|
||||
} else {
|
||||
tiptext.setText(getResources().getString(R.string.requestoutoftime));
|
||||
yes.setClickable(false);
|
||||
yes.setTextColor(getResources().getColor(R.color.gray));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
;
|
||||
};
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
this.finish();
|
||||
break;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
}
|
@ -1,175 +0,0 @@
|
||||
package com.gizwits.opensource.appkit.sharingdevice;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.gizwits.gizwifisdk.api.GizDeviceSharing;
|
||||
import com.gizwits.gizwifisdk.enumration.GizDeviceSharingWay;
|
||||
import com.gizwits.gizwifisdk.enumration.GizWifiErrorCode;
|
||||
import com.gizwits.gizwifisdk.listener.GizDeviceSharingListener;
|
||||
import com.gizwits.opensource.appkit.CommonModule.GosBaseActivity;
|
||||
import com.gizwits.opensource.appkit.R;
|
||||
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
public class twoSharedActivity extends GosBaseActivity {
|
||||
|
||||
private String productname;
|
||||
private String did;
|
||||
private ImageView myimage;
|
||||
private TextView timeout;
|
||||
private TextView bottomtext;
|
||||
private int time = 15;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.activity_gos_two_shared);
|
||||
|
||||
setToolBar(true, R.string.scan_code_sharing);
|
||||
|
||||
initData();
|
||||
initView();
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
TextView usersharedtext = (TextView) findViewById(R.id.usersharedtext);
|
||||
|
||||
myimage = (ImageView) findViewById(R.id.myimageview);
|
||||
|
||||
timeout = (TextView) findViewById(R.id.timeout);
|
||||
|
||||
timeout2 = splits[0] + time + splits[1];
|
||||
|
||||
timeout.setText(timeout2);
|
||||
|
||||
bottomtext = (TextView) findViewById(R.id.bottomtext);
|
||||
|
||||
usersharedtext.setText(getResources().getString(R.string.shared) + " " + productname
|
||||
+ getResources().getString(R.string.friends));
|
||||
}
|
||||
|
||||
private void initData() {
|
||||
|
||||
Intent tent = getIntent();
|
||||
productname = tent.getStringExtra("productname");
|
||||
did = tent.getStringExtra("did");
|
||||
|
||||
timeout2 = getResources().getString(R.string.zxingtimeout);
|
||||
splits = timeout2.split("15");
|
||||
GizDeviceSharing.sharingDevice(spf.getString("Token", ""), did, GizDeviceSharingWay.GizDeviceSharingByQRCode,
|
||||
null, null);
|
||||
|
||||
}
|
||||
|
||||
private void startTimer() {
|
||||
timer = new Timer();
|
||||
timer.schedule(new TimerTask() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
time = time - 1;
|
||||
hand.sendEmptyMessage(1);
|
||||
}
|
||||
}, 60000, 60000);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
if (time > 0) {
|
||||
timeout2 = splits[0] + time + splits[1];
|
||||
|
||||
timeout.setText(timeout2);
|
||||
} else {
|
||||
timeout.setText(getResources().getString(R.string.twofailed));
|
||||
}
|
||||
GizDeviceSharing.setListener(new GizDeviceSharingListener() {
|
||||
|
||||
@Override
|
||||
public void didSharingDevice(GizWifiErrorCode result, String deviceID, int sharingID,
|
||||
Bitmap QRCodeImage) {
|
||||
super.didSharingDevice(result, deviceID, sharingID, QRCodeImage);
|
||||
|
||||
if (QRCodeImage != null) {
|
||||
myimage.setImageBitmap(QRCodeImage);
|
||||
bottomtext.setVisibility(View.VISIBLE);
|
||||
|
||||
// hand.sendEmptyMessageDelayed(1, 60000);
|
||||
startTimer();
|
||||
} else {
|
||||
int errorcode = result.ordinal();
|
||||
|
||||
if (8041 <= errorcode && errorcode <= 8050 || errorcode == 8308) {
|
||||
|
||||
timeout.setText(getResources().getString(R.string.twosharedtimeout));
|
||||
bottomtext.setVisibility(View.GONE);
|
||||
|
||||
} else {
|
||||
timeout.setText(getResources().getString(R.string.sharedfailed));
|
||||
bottomtext.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
|
||||
finish();
|
||||
break;
|
||||
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
Handler hand = new Handler() {
|
||||
public void handleMessage(android.os.Message msg) {
|
||||
|
||||
// time = time - 1;
|
||||
|
||||
if (time > 0) {
|
||||
timeout2 = splits[0] + time + splits[1];
|
||||
|
||||
timeout.setText(timeout2);
|
||||
// hand.sendEmptyMessageDelayed(1, 60000);
|
||||
} else {
|
||||
timeout.setText(getResources().getString(R.string.twofailed));
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
// TODO Auto-generated method stub
|
||||
super.onDestroy();
|
||||
|
||||
time = 15;
|
||||
|
||||
hand.removeMessages(1);
|
||||
if (timer != null) {
|
||||
timer.cancel();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private String timeout2;
|
||||
private String[] splits;
|
||||
private Timer timer;
|
||||
}
|
@ -1,145 +0,0 @@
|
||||
package com.gizwits.opensource.appkit.sharingdevice;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.gizwits.gizwifisdk.api.GizDeviceSharing;
|
||||
import com.gizwits.gizwifisdk.enumration.GizDeviceSharingWay;
|
||||
import com.gizwits.gizwifisdk.enumration.GizUserAccountType;
|
||||
import com.gizwits.gizwifisdk.enumration.GizWifiErrorCode;
|
||||
import com.gizwits.gizwifisdk.listener.GizDeviceSharingListener;
|
||||
import com.gizwits.opensource.appkit.CommonModule.GosBaseActivity;
|
||||
import com.gizwits.opensource.appkit.CommonModule.GosDeploy;
|
||||
import com.gizwits.opensource.appkit.CommonModule.TipsDialog;
|
||||
import com.gizwits.opensource.appkit.R;
|
||||
|
||||
public class userSharedActivity extends GosBaseActivity {
|
||||
|
||||
private String productname;
|
||||
private EditText username;
|
||||
private int chooseitem = 0;
|
||||
private String did;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
// TODO Auto-generated method stub
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_gos_user_shared);
|
||||
|
||||
setToolBar(true, R.string.account_shared);
|
||||
|
||||
initData();
|
||||
initView();
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
TextView usersharedtext = (TextView) findViewById(R.id.usersharedtext);
|
||||
Button button = (Button) findViewById(R.id.button);
|
||||
button.setBackgroundDrawable(GosDeploy.appConfig_BackgroundColor());
|
||||
button.setTextColor(GosDeploy.appConfig_Contrast());
|
||||
|
||||
username = (EditText) findViewById(R.id.username);
|
||||
usersharedtext.setText(
|
||||
getResources().getString(R.string.shared) + productname + getResources().getString(R.string.friends));
|
||||
}
|
||||
|
||||
private void initData() {
|
||||
|
||||
Intent tent = getIntent();
|
||||
productname = tent.getStringExtra("productname");
|
||||
did = tent.getStringExtra("did");
|
||||
}
|
||||
|
||||
public void usershared(View v) {
|
||||
|
||||
final String usernametext = username.getText().toString();
|
||||
if (TextUtils.isEmpty(usernametext)) {
|
||||
|
||||
// Toast.makeText(this,
|
||||
// getResources().getString(R.string.toast_name_empet), 0).show();
|
||||
|
||||
TipsDialog dia = new TipsDialog(this, getResources().getString(R.string.toast_name_empet));
|
||||
dia.show();
|
||||
return;
|
||||
}
|
||||
|
||||
SharedPreferences spf = getSharedPreferences("set", Context.MODE_PRIVATE);
|
||||
String token = spf.getString("Token", "");
|
||||
if (usernametext.length() < 32) {
|
||||
if (usernametext.matches("[0-9]+")) {
|
||||
GizDeviceSharing.sharingDevice(token, did, GizDeviceSharingWay.GizDeviceSharingByNormal, usernametext,
|
||||
GizUserAccountType.GizUserPhone);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
if (usernametext.contains("@")) {
|
||||
GizDeviceSharing.sharingDevice(token, did, GizDeviceSharingWay.GizDeviceSharingByNormal, usernametext,
|
||||
GizUserAccountType.GizUserEmail);
|
||||
return;
|
||||
}
|
||||
if (usernametext.length() == 32) {
|
||||
if (usernametext.matches("[a-zA-Z0-9]+")) {
|
||||
GizDeviceSharing.sharingDevice(token, did, GizDeviceSharingWay.GizDeviceSharingByNormal, usernametext,
|
||||
GizUserAccountType.GizUserOther);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
Toast.makeText(this, getString(R.string.account_incorrect), Toast.LENGTH_LONG).show();
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
||||
GizDeviceSharing.setListener(new GizDeviceSharingListener() {
|
||||
|
||||
@Override
|
||||
public void didSharingDevice(GizWifiErrorCode result, String deviceID, int sharingID,
|
||||
Bitmap QRCodeImage) {
|
||||
super.didSharingDevice(result, deviceID, sharingID, QRCodeImage);
|
||||
|
||||
if (result.ordinal() == 0) {
|
||||
Toast.makeText(userSharedActivity.this, getResources().getString(R.string.alawyssend), 1).show();
|
||||
finish();
|
||||
} else if (result == GizWifiErrorCode.GIZ_OPENAPI_GUEST_ALREADY_BOUND) {
|
||||
Toast.makeText(userSharedActivity.this, getResources().getString(R.string.account_shared2), toastTime).show();
|
||||
} else if (result == GizWifiErrorCode.GIZ_OPENAPI_NOT_FOUND_GUEST) {
|
||||
Toast.makeText(userSharedActivity.this, getResources().getString(R.string.user_not_exist), toastTime).show();
|
||||
} else if (result == GizWifiErrorCode.GIZ_OPENAPI_CANNOT_SHARE_TO_SELF) {
|
||||
Toast.makeText(userSharedActivity.this, getResources().getString(R.string.not_shared_self), toastTime).show();
|
||||
} else {
|
||||
Toast.makeText(userSharedActivity.this, getResources().getString(R.string.send_failed1), 2).show();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
|
||||
finish();
|
||||
break;
|
||||
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
}
|
Binary file not shown.
File diff suppressed because it is too large
Load Diff
@ -1,58 +0,0 @@
|
||||
package com.gizwits.opensource.appkit.utils;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class HexStrUtils {
|
||||
|
||||
public static byte[] hexStringToBytes(String hexString) {
|
||||
if (hexString == null || hexString.equals("")) {
|
||||
return null;
|
||||
}
|
||||
hexString = hexString.toUpperCase(Locale.getDefault());
|
||||
int length = hexString.length() / 2;
|
||||
char[] hexChars = hexString.toCharArray();
|
||||
byte[] d = new byte[length];
|
||||
for (int i = 0; i < length; i++) {
|
||||
int pos = i * 2;
|
||||
d[i] = (byte) (charToByte(hexChars[pos]) << 4 | charToByte(hexChars[pos + 1]));
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
private static byte charToByte(char c) {
|
||||
return (byte) "0123456789ABCDEF".indexOf(c);
|
||||
}
|
||||
|
||||
/**
|
||||
* 数组转换成十六进制字符串
|
||||
*
|
||||
* @param byte[]
|
||||
* @return HexString
|
||||
*/
|
||||
public static final String bytesToHexString(byte[] bArray) {
|
||||
if (bArray == null) {
|
||||
return "";
|
||||
}
|
||||
StringBuffer sb = new StringBuffer(bArray.length);
|
||||
String sTemp;
|
||||
for (int i = 0; i < bArray.length; i++) {
|
||||
sTemp = Integer.toHexString(0xFF & bArray[i]);
|
||||
if (sTemp.length() < 2)
|
||||
sb.append(0);
|
||||
sb.append(sTemp.toUpperCase(Locale.getDefault()));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static final String splitBytesString(String byteString) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < byteString.length(); i++) {
|
||||
sb.append(byteString.charAt(i));
|
||||
if (sb.length() % 3 == 0 && sb.charAt(sb.length() - 1) != ' ') {
|
||||
sb.insert(sb.length() - 1, ' ');
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
package com.gizwits.opensource.appkit.utils;
|
||||
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.support.v4.graphics.drawable.DrawableCompat;
|
||||
|
||||
public class SkxDrawableHelper {
|
||||
|
||||
/**
|
||||
* 对目标Drawable 进行着色
|
||||
*
|
||||
* @param drawable 目标Drawable
|
||||
* @param color 着色的颜色值
|
||||
* @return 着色处理后的Drawable
|
||||
*/
|
||||
public static Drawable tintDrawable(Drawable drawable, int color) {
|
||||
// 获取此drawable的共享状态实例
|
||||
Drawable wrappedDrawable = getCanTintDrawable(drawable);
|
||||
// 进行着色
|
||||
DrawableCompat.setTint(wrappedDrawable, color);
|
||||
return wrappedDrawable;
|
||||
}
|
||||
|
||||
/**
|
||||
* 对目标Drawable 进行着色。
|
||||
* 通过ColorStateList 指定单一颜色
|
||||
*
|
||||
* @param drawable 目标Drawable
|
||||
* @param color 着色值
|
||||
* @return 着色处理后的Drawable
|
||||
*/
|
||||
public static Drawable tintListDrawable(Drawable drawable, int color) {
|
||||
return tintListDrawable(drawable, ColorStateList.valueOf(color));
|
||||
}
|
||||
|
||||
/**
|
||||
* 对目标Drawable 进行着色
|
||||
*
|
||||
* @param drawable 目标Drawable
|
||||
* @param colors 着色值
|
||||
* @return 着色处理后的Drawable
|
||||
*/
|
||||
public static Drawable tintListDrawable( Drawable drawable, ColorStateList colors) {
|
||||
Drawable wrappedDrawable = getCanTintDrawable(drawable);
|
||||
// 进行着色
|
||||
DrawableCompat.setTintList(wrappedDrawable, colors);
|
||||
return wrappedDrawable;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取可以进行tint 的Drawable
|
||||
* <p>
|
||||
* 对原drawable进行重新实例化 newDrawable()
|
||||
* 包装 warp()
|
||||
* 可变操作 mutate()
|
||||
*
|
||||
* @param drawable 原始drawable
|
||||
* @return 可着色的drawable
|
||||
*/
|
||||
private static Drawable getCanTintDrawable(Drawable drawable) {
|
||||
// 获取此drawable的共享状态实例
|
||||
Drawable.ConstantState state = drawable.getConstantState();
|
||||
// 对drawable 进行重新实例化、包装、可变操作
|
||||
return DrawableCompat.wrap(state == null ? drawable : state.newDrawable()).mutate();
|
||||
}
|
||||
}
|
@ -1,146 +0,0 @@
|
||||
package com.gizwits.opensource.appkit.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.gizwits.opensource.appkit.CommonModule.GosDeploy;
|
||||
import com.gizwits.opensource.appkit.R;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by admin on 2017/7/25.
|
||||
*/
|
||||
|
||||
public class ToolUtils {
|
||||
public static float getHue(int color) {
|
||||
float[] HSV = new float[3];
|
||||
Color.colorToHSV(color, HSV);
|
||||
return (HSV[0] * 255 / 360);
|
||||
}
|
||||
|
||||
public static int getInnerColor(float hue) {
|
||||
float[] HSV = new float[3];
|
||||
HSV[0] = hue * 360 / 255;
|
||||
HSV[1] = 255;
|
||||
HSV[2] = 255;
|
||||
return Color.HSVToColor(HSV);
|
||||
}
|
||||
|
||||
private static long lastClickTime = 0;
|
||||
public static final int MIN_CLICK_DELAY_TIME = 800;
|
||||
|
||||
public static boolean noDoubleClick() {
|
||||
long currentTime = Calendar.getInstance().getTimeInMillis();
|
||||
if (currentTime - lastClickTime > MIN_CLICK_DELAY_TIME) {
|
||||
lastClickTime = currentTime;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static List<Map<String, Object>> parseJson(Context context, String str) throws JSONException {
|
||||
if (str == null || str.equals("")) {
|
||||
Toast.makeText(context, context.getString(R.string.download_fail), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
JSONObject uiJsonObject = new JSONObject(str);
|
||||
JSONObject jsonObject = uiJsonObject.has("object") ? uiJsonObject.getJSONObject("object") : null;
|
||||
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
|
||||
if (uiJsonObject != null) {
|
||||
JSONArray sessionJsonArrays = uiJsonObject.getJSONArray("sections");
|
||||
if (sessionJsonArrays != null) {
|
||||
for (int i = 0; i < sessionJsonArrays.length(); i++) {
|
||||
JSONObject session = sessionJsonArrays.getJSONObject(i);
|
||||
JSONArray elementjJsonArray = session.getJSONArray("elements");
|
||||
if (elementjJsonArray != null) {
|
||||
for (int j = 0; j < elementjJsonArray.length(); j++) {
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
JSONObject elementObject = elementjJsonArray.getJSONObject(j);
|
||||
String type = elementObject.getString("type");
|
||||
String title = elementObject.has("title") ? elementObject.getString("title") : "";
|
||||
map.put("title", title);
|
||||
map.put("type", type);
|
||||
String value = null;
|
||||
if (type.equals("QBooleanElement")) {
|
||||
value = elementObject.has("boolValue") ? elementObject.getString("boolValue") : "";
|
||||
} else if (type.equals("QFloatElement")) {
|
||||
value = elementObject.has("value") ? elementObject.getString("value") : "";
|
||||
}
|
||||
map.put("value", value);
|
||||
list.add(map);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
public static Drawable editIconAlpha(Resources res, int id) {
|
||||
int color = GosDeploy.appConfig_Contrast();
|
||||
Drawable drawable = SkxDrawableHelper.tintDrawable(res.getDrawable(id), color);
|
||||
drawable.setAlpha(60);
|
||||
return drawable;
|
||||
}
|
||||
|
||||
public static Drawable editIcon(Resources res, int id) {
|
||||
int color = GosDeploy.appConfig_Contrast();
|
||||
return SkxDrawableHelper.tintDrawable(res.getDrawable(id), color);
|
||||
}
|
||||
|
||||
public static int editTextAlpha() {
|
||||
int color = GosDeploy.appConfig_Contrast();
|
||||
int red = Color.red(color);
|
||||
int green = Color.green(color);
|
||||
int blue = Color.blue(color);
|
||||
int color1 = Color.argb(160, red, green, blue);
|
||||
return color1;
|
||||
}
|
||||
|
||||
public static int editStatusBarColor(int color) {
|
||||
int red = Color.red(color);
|
||||
int green = Color.green(color);
|
||||
int blue = Color.blue(color);
|
||||
int color1 = Color.argb(255, red, green, blue);
|
||||
return color1;
|
||||
}
|
||||
// // 需要点击几次 就设置几
|
||||
// static long[] mHits = null;
|
||||
// //public static boolean mShow = false;
|
||||
//
|
||||
// public static void onDisplaySettingButton() {
|
||||
// if (mHits == null) {
|
||||
// mHits = new long[5];
|
||||
// }
|
||||
// System.arraycopy(mHits, 1, mHits, 0, mHits.length - 1);//把从第二位至最后一位之间的数字复制到第一位至倒数第一位
|
||||
// mHits[mHits.length - 1] = SystemClock.uptimeMillis();//记录一个时间
|
||||
// if (SystemClock.uptimeMillis() - mHits[0] <= 1000) {//一秒内连续点击。
|
||||
// mHits = null; //这里说明一下,我们在进来以后需要还原状态,否则如果点击过快,第六次,第七次 都会不断进来触发该效果。重新开始计数即可
|
||||
//// if (mShow) {
|
||||
//// mShow = false;
|
||||
//// } else {
|
||||
//// mShow = true;
|
||||
//// }
|
||||
// mShow = true;
|
||||
// Log.e("Tool", "onDisplaySettingButton: 连点五次进入deploy模式");
|
||||
// //这里一般会把mShow存储到sp中。
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
}
|
Binary file not shown.
@ -1,210 +0,0 @@
|
||||
package com.gizwits.opensource.appkit.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.inputmethodservice.Keyboard;
|
||||
import android.inputmethodservice.KeyboardView;
|
||||
import android.text.Editable;
|
||||
import android.text.TextUtils;
|
||||
import android.util.TypedValue;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
|
||||
/**
|
||||
* Created by xud on 2017/3/2.
|
||||
*/
|
||||
|
||||
public abstract class BaseKeyboard extends Keyboard implements KeyboardView.OnKeyboardActionListener {
|
||||
|
||||
private EditText mEditText;
|
||||
|
||||
private View mNextFocusView;
|
||||
|
||||
private KeyStyle mKeyStyle;
|
||||
|
||||
protected Context mContext;
|
||||
|
||||
public BaseKeyboard(Context context, int xmlLayoutResId) {
|
||||
super(context, xmlLayoutResId);
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
public BaseKeyboard(Context context, int xmlLayoutResId, int modeId, int width, int height) {
|
||||
super(context, xmlLayoutResId, modeId, width, height);
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
public BaseKeyboard(Context context, int xmlLayoutResId, int modeId) {
|
||||
super(context, xmlLayoutResId, modeId);
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
public BaseKeyboard(Context context, int layoutTemplateResId, CharSequence characters, int columns, int horizontalPadding) {
|
||||
super(context, layoutTemplateResId, characters, columns, horizontalPadding);
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
public void setEditText(EditText editText) {
|
||||
mEditText = editText;
|
||||
}
|
||||
|
||||
public void setNextFocusView(View nextFocusView) {
|
||||
mNextFocusView = nextFocusView;
|
||||
}
|
||||
|
||||
public void setKeyStyle(KeyStyle keyStyle) {
|
||||
mKeyStyle = keyStyle;
|
||||
}
|
||||
|
||||
public EditText getEditText() {
|
||||
return mEditText;
|
||||
}
|
||||
|
||||
public View getNextFocusView() {
|
||||
return mNextFocusView;
|
||||
}
|
||||
|
||||
public KeyStyle getKeyStyle() {
|
||||
return mKeyStyle;
|
||||
}
|
||||
|
||||
public int getKeyCode( int redId) {
|
||||
return mContext.getResources().getInteger(redId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPress(int primaryCode) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRelease(int primaryCode) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onKey(int primaryCode, int[] keyCodes) {
|
||||
if (null != mEditText && mEditText.hasFocus() && !handleSpecialKey(primaryCode)) {
|
||||
Editable editable = mEditText.getText();
|
||||
int start = mEditText.getSelectionStart();
|
||||
int end = mEditText.getSelectionEnd();
|
||||
if (end > start) {
|
||||
editable.delete(start, end);
|
||||
}
|
||||
if (primaryCode == KEYCODE_DELETE) {
|
||||
if (!TextUtils.isEmpty(editable)) {
|
||||
if (start > 0) {
|
||||
editable.delete(start - 1, start);
|
||||
}
|
||||
}
|
||||
} else if (primaryCode == KEYCODE_CANCEL) {
|
||||
hideKeyboard();
|
||||
} else {
|
||||
editable.insert(start, Character.toString((char) primaryCode));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onText(CharSequence text) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void swipeLeft() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void swipeRight() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void swipeDown() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void swipeUp() {
|
||||
|
||||
}
|
||||
|
||||
public void hideKeyboard() {
|
||||
if (mNextFocusView != null) {
|
||||
mNextFocusView.requestFocus();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param primaryCode
|
||||
* @return true if handle the key
|
||||
* false no handle and dispatch
|
||||
*/
|
||||
public abstract boolean handleSpecialKey(int primaryCode);
|
||||
|
||||
public interface KeyStyle {
|
||||
|
||||
public Drawable getKeyBackound(Key key);
|
||||
|
||||
public Float getKeyTextSize(Key key);
|
||||
|
||||
public Integer getKeyTextColor(Key key);
|
||||
|
||||
public CharSequence getKeyLabel(Key key);
|
||||
}
|
||||
|
||||
public Padding getPadding() {
|
||||
return new Padding(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
public static class DefaultKeyStyle implements KeyStyle {
|
||||
|
||||
@Override
|
||||
public Drawable getKeyBackound(Key key) {
|
||||
return key.iconPreview;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Float getKeyTextSize(Key key) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getKeyTextColor(Key key) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getKeyLabel(Key key) {
|
||||
return key.label;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Padding {
|
||||
public int top;
|
||||
public int left;
|
||||
public int bottom;
|
||||
public int right;
|
||||
|
||||
/**
|
||||
* px
|
||||
*
|
||||
* @param top
|
||||
* @param left
|
||||
* @param bottom
|
||||
* @param right
|
||||
*/
|
||||
public Padding(int top, int left, int bottom, int right) {
|
||||
this.top = top;
|
||||
this.left = left;
|
||||
this.bottom = bottom;
|
||||
this.right = right;
|
||||
}
|
||||
}
|
||||
|
||||
public float convertSpToPixels(Context context, float sp) {
|
||||
float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, sp, context.getResources().getDisplayMetrics());
|
||||
return px;
|
||||
}
|
||||
}
|
@ -1,202 +0,0 @@
|
||||
package com.gizwits.opensource.appkit.view;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.Typeface;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.inputmethodservice.Keyboard;
|
||||
import android.inputmethodservice.KeyboardView;
|
||||
import android.os.Build;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.EditText;
|
||||
|
||||
import com.gizwits.opensource.appkit.utils.ReflectionUtils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by xud on 2017/3/2.
|
||||
*/
|
||||
|
||||
public class BaseKeyboardView extends KeyboardView {
|
||||
|
||||
private static final String TAG = "BaseKeyboardView";
|
||||
private Drawable rKeyBackground;
|
||||
private int rLabelTextSize;
|
||||
private int rKeyTextSize;
|
||||
private int rKeyTextColor;
|
||||
private float rShadowRadius;
|
||||
private int rShadowColor;
|
||||
|
||||
private Rect rClipRegion;
|
||||
private Keyboard.Key rInvalidatedKey;
|
||||
|
||||
public BaseKeyboardView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init(context, attrs, 0, 0);
|
||||
}
|
||||
|
||||
public BaseKeyboardView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init(context, attrs, defStyleAttr, 0);
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
public BaseKeyboardView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
init(context, attrs, defStyleAttr, defStyleRes);
|
||||
}
|
||||
|
||||
private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
rKeyBackground = (Drawable) ReflectionUtils.getFieldValue(this, "mKeyBackground");
|
||||
rLabelTextSize = (Integer) ReflectionUtils.getFieldValue(this, "mLabelTextSize");
|
||||
rKeyTextSize = (Integer) ReflectionUtils.getFieldValue(this, "mKeyTextSize");
|
||||
rKeyTextColor = (Integer) ReflectionUtils.getFieldValue(this, "mKeyTextColor");
|
||||
rShadowColor = (Integer) ReflectionUtils.getFieldValue(this, "mShadowColor");
|
||||
rShadowRadius = (Float) ReflectionUtils.getFieldValue(this, "mShadowRadius");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDraw(Canvas canvas) {
|
||||
//说明CustomKeyboardView只针对CustomBaseKeyboard键盘进行重绘,
|
||||
// 且CustomBaseKeyboard必需有设置CustomKeyStyle的回调接口实现, 才进行重绘, 这才有意义
|
||||
if (null == getKeyboard() || !(getKeyboard() instanceof BaseKeyboard) || null == ((BaseKeyboard) getKeyboard()).getKeyStyle()) {
|
||||
super.onDraw(canvas);
|
||||
return;
|
||||
}
|
||||
rClipRegion = (Rect) ReflectionUtils.getFieldValue(this, "mClipRegion");
|
||||
rInvalidatedKey = (Keyboard.Key) ReflectionUtils.getFieldValue(this, "mInvalidatedKey");
|
||||
super.onDraw(canvas);
|
||||
onRefreshKey(canvas);
|
||||
}
|
||||
|
||||
/**
|
||||
* onRefreshKey是对父类的private void onBufferDraw()进行的重写. 只是在对key的绘制过程中进行了重新设置.
|
||||
*
|
||||
* @param canvas
|
||||
*/
|
||||
private void onRefreshKey(Canvas canvas) {
|
||||
final Paint paint = (Paint) ReflectionUtils.getFieldValue(this, "mPaint");
|
||||
final Rect padding = (Rect) ReflectionUtils.getFieldValue(this, "mPadding");
|
||||
|
||||
paint.setColor(rKeyTextColor);
|
||||
final int kbdPaddingLeft = getPaddingLeft();
|
||||
final int kbdPaddingTop = getPaddingTop();
|
||||
Drawable keyBackground = null;
|
||||
|
||||
final Rect clipRegion = rClipRegion;
|
||||
final Keyboard.Key invalidKey = rInvalidatedKey;
|
||||
boolean drawSingleKey = false;
|
||||
if (invalidKey != null && canvas.getClipBounds(clipRegion)) {
|
||||
// Is clipRegion completely contained within the invalidated key?
|
||||
if (invalidKey.x + kbdPaddingLeft - 1 <= clipRegion.left &&
|
||||
invalidKey.y + kbdPaddingTop - 1 <= clipRegion.top &&
|
||||
invalidKey.x + invalidKey.width + kbdPaddingLeft + 1 >= clipRegion.right &&
|
||||
invalidKey.y + invalidKey.height + kbdPaddingTop + 1 >= clipRegion.bottom) {
|
||||
drawSingleKey = true;
|
||||
}
|
||||
}
|
||||
|
||||
//拿到当前键盘被弹起的输入源 和 键盘为每个key的定制实现customKeyStyle
|
||||
EditText etCur = ((BaseKeyboard) getKeyboard()).getEditText();
|
||||
BaseKeyboard.KeyStyle customKeyStyle = ((BaseKeyboard) getKeyboard()).getKeyStyle();
|
||||
|
||||
List<Keyboard.Key> keys = getKeyboard().getKeys();
|
||||
final int keyCount = keys.size();
|
||||
//canvas.drawColor(0x00000000, PorterDuff.Mode.CLEAR);
|
||||
for (int i = 0; i < keyCount; i++) {
|
||||
final Keyboard.Key key = keys.get(i);
|
||||
if (drawSingleKey && invalidKey != key) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//获取为Key自定义的背景, 若没有定制, 使用KeyboardView的默认属性keyBackground设置
|
||||
keyBackground = customKeyStyle.getKeyBackound(key);
|
||||
if (null == keyBackground) {
|
||||
keyBackground = rKeyBackground;
|
||||
}
|
||||
|
||||
int[] drawableState = key.getCurrentDrawableState();
|
||||
keyBackground.setState(drawableState);
|
||||
|
||||
//获取为Key自定义的Label, 若没有定制, 使用xml布局中指定的
|
||||
CharSequence keyLabel = customKeyStyle.getKeyLabel(key);
|
||||
if (null == keyLabel) {
|
||||
keyLabel = key.label;
|
||||
}
|
||||
// Switch the character to uppercase if shift is pressed
|
||||
String label = keyLabel == null ? null : adjustCase(keyLabel).toString();
|
||||
|
||||
final Rect bounds = keyBackground.getBounds();
|
||||
if (key.width != bounds.right ||
|
||||
key.height != bounds.bottom) {
|
||||
keyBackground.setBounds(0, 0, key.width, key.height);
|
||||
}
|
||||
canvas.translate(key.x + kbdPaddingLeft, key.y + kbdPaddingTop);
|
||||
keyBackground.draw(canvas);
|
||||
|
||||
if (label != null) {
|
||||
//获取为Key的Label的字体大小, 若没有定制, 使用KeyboardView的默认属性keyTextSize设置
|
||||
Float customKeyTextSize = customKeyStyle.getKeyTextSize(key);
|
||||
// For characters, use large font. For labels like "Done", use small font.
|
||||
if (null != customKeyTextSize) {
|
||||
paint.setTextSize(customKeyTextSize);
|
||||
paint.setTypeface(Typeface.DEFAULT);
|
||||
//paint.setTypeface(Typeface.DEFAULT_BOLD);
|
||||
} else {
|
||||
if (label.length() > 1 && key.codes.length < 2) {
|
||||
paint.setTextSize(rLabelTextSize);
|
||||
paint.setTypeface(Typeface.DEFAULT);
|
||||
//paint.setTypeface(Typeface.DEFAULT_BOLD);
|
||||
} else {
|
||||
paint.setTextSize(rKeyTextSize);
|
||||
paint.setTypeface(Typeface.DEFAULT);
|
||||
//paint.setTypeface(Typeface.DEFAULT);
|
||||
}
|
||||
}
|
||||
|
||||
//获取为Key的Label的字体颜色, 若没有定制, 使用KeyboardView的默认属性keyTextColor设置
|
||||
Integer customKeyTextColor = customKeyStyle.getKeyTextColor(key);
|
||||
if (null != customKeyTextColor) {
|
||||
paint.setColor(customKeyTextColor);
|
||||
} else {
|
||||
paint.setColor(rKeyTextColor);
|
||||
}
|
||||
// Draw a drop shadow for the text
|
||||
paint.setShadowLayer(rShadowRadius, 0, 0, rShadowColor);
|
||||
// Draw the text
|
||||
canvas.drawText(label,
|
||||
(key.width - padding.left - padding.right) / 2
|
||||
+ padding.left,
|
||||
(key.height - padding.top - padding.bottom) / 2
|
||||
+ (paint.getTextSize() - paint.descent()) / 2 + padding.top,
|
||||
paint);
|
||||
// Turn off drop shadow
|
||||
paint.setShadowLayer(0, 0, 0, 0);
|
||||
} else if (key.icon != null) {
|
||||
final int drawableX = (key.width - padding.left - padding.right
|
||||
- key.icon.getIntrinsicWidth()) / 2 + padding.left;
|
||||
final int drawableY = (key.height - padding.top - padding.bottom
|
||||
- key.icon.getIntrinsicHeight()) / 2 + padding.top;
|
||||
canvas.translate(drawableX, drawableY);
|
||||
key.icon.setBounds(0, 0,
|
||||
key.icon.getIntrinsicWidth(), key.icon.getIntrinsicHeight());
|
||||
key.icon.draw(canvas);
|
||||
canvas.translate(-drawableX, -drawableY);
|
||||
}
|
||||
canvas.translate(-key.x - kbdPaddingLeft, -key.y - kbdPaddingTop);
|
||||
}
|
||||
rInvalidatedKey = null;
|
||||
}
|
||||
|
||||
private CharSequence adjustCase(CharSequence label) {
|
||||
if (getKeyboard().isShifted() && label != null && label.length() < 3
|
||||
&& Character.isLowerCase(label.charAt(0))) {
|
||||
label = label.toString().toUpperCase();
|
||||
}
|
||||
return label;
|
||||
}
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
package com.gizwits.opensource.appkit.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Paint.Style;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
|
||||
import com.gizwits.opensource.appkit.R;
|
||||
|
||||
|
||||
public class DotView extends View {
|
||||
private Paint p;
|
||||
private int width;
|
||||
private int height;
|
||||
private int dash;
|
||||
|
||||
public DotView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init(context);
|
||||
}
|
||||
|
||||
public DotView(Context context) {
|
||||
super(context);
|
||||
init(context);
|
||||
}
|
||||
private void init(Context context){
|
||||
p = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
p.setStyle(Style.FILL);
|
||||
p.setColor(context.getResources().getColor(R.color.line_gray));
|
||||
|
||||
final float scale = context.getResources().getDisplayMetrics().density;
|
||||
dash=(int) (3 * scale + 0.5f);
|
||||
}
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
|
||||
if(width>10){
|
||||
for(int i=0;i<width;i+=dash){
|
||||
canvas.drawLine(i, 0, i+=dash, 0, p);
|
||||
}
|
||||
}
|
||||
super.onDraw(canvas);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSizeChanged(int w, int h, int oldw, int oldh) {
|
||||
super.onSizeChanged(w, h, oldw, oldh);
|
||||
width=w;
|
||||
height=h;
|
||||
p.setStrokeWidth(height);
|
||||
this.postInvalidate();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
package com.gizwits.opensource.appkit.view;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.widget.EditText;
|
||||
|
||||
public class HexWatcher implements TextWatcher {
|
||||
private EditText _text;
|
||||
|
||||
public HexWatcher(EditText _text) {
|
||||
this._text = _text;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
if (s == null || s.length() == 0)
|
||||
return;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < s.length(); i++) {
|
||||
if (s.charAt(i) == ' ' && i < s.length() - 1) {
|
||||
continue;
|
||||
} else {
|
||||
sb.append(s.charAt(i));
|
||||
if (sb.length() % 3 == 0 && sb.charAt(sb.length() - 1) != ' ') {
|
||||
sb.insert(sb.length() - 1, ' ');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!sb.toString().equals(s.toString())) {
|
||||
int index = start + 1;
|
||||
if (sb.charAt(start) == ' ') {
|
||||
if (before == 0) {
|
||||
index++;
|
||||
} else {
|
||||
index--;
|
||||
}
|
||||
} else {
|
||||
if (before == 1) {
|
||||
index--;
|
||||
}
|
||||
}
|
||||
_text.setText(sb.toString().toUpperCase(Locale.getDefault()));
|
||||
_text.setSelection(index);
|
||||
}
|
||||
|
||||
// _text.removeTextChangedListener(this);
|
||||
// _text.setText(s.toString().toUpperCase(Locale.getDefault()));
|
||||
// _text.addTextChangedListener(this);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
}
|
||||
|
||||
}
|
@ -1,123 +0,0 @@
|
||||
package com.gizwits.opensource.appkit.view;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.gizwits.opensource.appkit.R;
|
||||
|
||||
|
||||
/**
|
||||
* Created by xud on 2017/3/9.
|
||||
*/
|
||||
|
||||
public class KeyboardWithSearchView extends LinearLayout {
|
||||
|
||||
|
||||
private Context mContext;
|
||||
|
||||
|
||||
private BaseKeyboardView mBaseKeyboardView;
|
||||
|
||||
private LinearLayout mKeyboadViewContainer;
|
||||
|
||||
//private OnSizeChangedListener mOnSizeChangedListener;
|
||||
|
||||
|
||||
public KeyboardWithSearchView(Context context) {
|
||||
super(context);
|
||||
init(context);
|
||||
}
|
||||
|
||||
public KeyboardWithSearchView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init(context);
|
||||
}
|
||||
|
||||
public KeyboardWithSearchView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init(context);
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
public KeyboardWithSearchView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
init(context);
|
||||
}
|
||||
|
||||
// protected RecyclerView getRecyclerView() {
|
||||
// return mRecyclerView;
|
||||
// }
|
||||
|
||||
public BaseKeyboardView getBaseKeyboardView() {
|
||||
return mBaseKeyboardView;
|
||||
}
|
||||
|
||||
|
||||
// public void setOnSizeChangedListener(OnSizeChangedListener onSizeChangedListener) {
|
||||
// mOnSizeChangedListener = onSizeChangedListener;
|
||||
// }
|
||||
|
||||
public LinearLayout getKeyboadViewContainer() {
|
||||
return mKeyboadViewContainer;
|
||||
}
|
||||
|
||||
|
||||
private void init(Context context) {
|
||||
mContext = context;
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.layout_recycler_keyboard_view, this, true);
|
||||
// mRecyclerView = (RecyclerView) view.findViewById(R.id.search_recycler_view);
|
||||
mBaseKeyboardView = (BaseKeyboardView) view.findViewById(R.id.keyboard_view);
|
||||
mKeyboadViewContainer = (LinearLayout) view.findViewById(R.id.keyboard_container);
|
||||
}
|
||||
|
||||
// public void initRecyclerView(KeyboardSearchBaseAdapter adapter, RecyclerView.LayoutManager manager, RecyclerView.ItemDecoration itemDecoration) {
|
||||
// mRecyclerView.setAdapter(adapter);
|
||||
// mRecyclerView.setLayoutManager(manager);
|
||||
// mRecyclerView.addItemDecoration(itemDecoration);
|
||||
// }
|
||||
//
|
||||
// public void setSearchResult(List list, boolean hasFixedSize) {
|
||||
// if(mRecyclerView.getAdapter() == null) {
|
||||
// throw new RuntimeException("this view has not invoked init method");
|
||||
// }
|
||||
// mRecyclerView.getLayoutManager().scrollToPosition(0);
|
||||
// if(list == null || list.size() ==0) {
|
||||
// mRecyclerView.setVisibility(GONE);
|
||||
// } else {
|
||||
// int height = AssetsUtils.diptopx(mContext, Math.min(3,list.size()) * 49) +
|
||||
// Math.min(3,list.size());
|
||||
// ViewGroup.LayoutParams params = mRecyclerView.getLayoutParams();
|
||||
// if(params != null) {
|
||||
// params.height = height;
|
||||
// }else {
|
||||
// LinearLayout.LayoutParams newParams =
|
||||
// new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
// height);
|
||||
// mRecyclerView.setLayoutParams(newParams);
|
||||
// }
|
||||
// mRecyclerView.setVisibility(VISIBLE);
|
||||
// }
|
||||
// mRecyclerView.setHasFixedSize(hasFixedSize);
|
||||
//
|
||||
// KeyboardSearchBaseAdapter adapter = (KeyboardSearchBaseAdapter) mRecyclerView.getAdapter();
|
||||
// adapter.setAdapterData(list);
|
||||
// adapter.notifyDataSetChanged();
|
||||
// }
|
||||
|
||||
// @Override
|
||||
// protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
||||
// super.onSizeChanged(w, h, oldw, oldh);
|
||||
// if(mOnSizeChangedListener != null) {
|
||||
// mOnSizeChangedListener.sizeChanged(w,h,oldw,oldh);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// protected interface OnSizeChangedListener {
|
||||
// void sizeChanged(int w, int h, int oldw, int oldh);
|
||||
// }
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -1,473 +0,0 @@
|
||||
package com.gizwits.opensource.appkit.view;
|
||||
|
||||
|
||||
/**
|
||||
* Created by qiaoning on 2017/8/16.
|
||||
*/
|
||||
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Path;
|
||||
import android.graphics.RadialGradient;
|
||||
import android.graphics.RectF;
|
||||
import android.graphics.Shader;
|
||||
import android.os.Build;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.TypedValue;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.animation.AccelerateInterpolator;
|
||||
|
||||
import com.gizwits.opensource.appkit.R;
|
||||
|
||||
|
||||
public class SwitchView extends View {
|
||||
|
||||
|
||||
private final int DEFAULT_COLOR_PRIMARY = 0xFF4BD763;
|
||||
private final int DEFAULT_COLOR_PRIMARY_DARK = 0xFF3AC652;
|
||||
private final float RATIO_ASPECT = 0.68f;
|
||||
private final float ANIMATION_SPEED = 0.1f; // (0,1]
|
||||
private static final int STATE_SWITCH_ON = 4; // you change value you die
|
||||
private static final int STATE_SWITCH_ON2 = 3;
|
||||
private static final int STATE_SWITCH_OFF2 = 2;
|
||||
private static final int STATE_SWITCH_OFF = 1;
|
||||
|
||||
private final AccelerateInterpolator interpolator = new AccelerateInterpolator(2);
|
||||
private final Paint paint = new Paint();
|
||||
private final Path sPath = new Path();
|
||||
private final Path bPath = new Path();
|
||||
private final RectF bRectF = new RectF();
|
||||
private float sAnim, bAnim;
|
||||
private RadialGradient shadowGradient;
|
||||
|
||||
private int state;
|
||||
private int lastState;
|
||||
private boolean isCanVisibleDrawing = false;
|
||||
private OnClickListener mOnClickListener;
|
||||
private int colorPrimary;
|
||||
private int colorPrimaryDark;
|
||||
private boolean hasShadow;
|
||||
private boolean isOpened;
|
||||
|
||||
private int mWidth, mHeight;
|
||||
private int actuallyDrawingAreaLeft;
|
||||
private int actuallyDrawingAreaRight;
|
||||
private int actuallyDrawingAreaTop;
|
||||
private int actuallyDrawingAreaBottom;
|
||||
|
||||
private float sWidth, sHeight;
|
||||
private float sLeft, sTop, sRight, sBottom;
|
||||
private float sCenterX, sCenterY;
|
||||
private float sScale;
|
||||
|
||||
private float bOffset;
|
||||
private float bRadius, bStrokeWidth;
|
||||
private float bWidth;
|
||||
private float bLeft, bTop, bRight, bBottom;
|
||||
private float bOnLeftX, bOn2LeftX, bOff2LeftX, bOffLeftX;
|
||||
|
||||
private float shadowReservedHeight;
|
||||
|
||||
public SwitchView(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
||||
public SwitchView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
setLayerType(LAYER_TYPE_SOFTWARE, null);
|
||||
|
||||
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SwitchView);
|
||||
colorPrimary = a.getColor(R.styleable.SwitchView_primaryColor, DEFAULT_COLOR_PRIMARY);
|
||||
colorPrimaryDark = a.getColor(R.styleable.SwitchView_primaryColorDark, DEFAULT_COLOR_PRIMARY_DARK);
|
||||
hasShadow = a.getBoolean(R.styleable.SwitchView_hasShadow, true);
|
||||
isOpened = a.getBoolean(R.styleable.SwitchView_isOpened, false);
|
||||
state = isOpened ? STATE_SWITCH_ON : STATE_SWITCH_OFF;
|
||||
lastState = state;
|
||||
a.recycle();
|
||||
|
||||
if (colorPrimary == DEFAULT_COLOR_PRIMARY && colorPrimaryDark == DEFAULT_COLOR_PRIMARY_DARK) {
|
||||
try {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
TypedValue primaryColorTypedValue = new TypedValue();
|
||||
context.getTheme().resolveAttribute(android.R.attr.colorPrimary, primaryColorTypedValue, true);
|
||||
if (primaryColorTypedValue.data > 0) colorPrimary = primaryColorTypedValue.data;
|
||||
TypedValue primaryColorDarkTypedValue = new TypedValue();
|
||||
context.getTheme().resolveAttribute(android.R.attr.colorPrimaryDark, primaryColorDarkTypedValue, true);
|
||||
if (primaryColorDarkTypedValue.data > 0)
|
||||
colorPrimaryDark = primaryColorDarkTypedValue.data;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setColor(int newColorPrimary, int newColorPrimaryDark) {
|
||||
colorPrimary = newColorPrimary;
|
||||
colorPrimaryDark = newColorPrimaryDark;
|
||||
invalidate();
|
||||
}
|
||||
|
||||
public void setShadow(boolean shadow) {
|
||||
hasShadow = shadow;
|
||||
invalidate();
|
||||
}
|
||||
|
||||
public boolean isOpened() {
|
||||
return isOpened;
|
||||
}
|
||||
|
||||
public void setOpened(boolean isOpened) {
|
||||
int wishState = isOpened ? STATE_SWITCH_ON : STATE_SWITCH_OFF;
|
||||
if (wishState == state) {
|
||||
return;
|
||||
}
|
||||
refreshState(wishState);
|
||||
}
|
||||
|
||||
public void toggleSwitch(boolean isOpened) {
|
||||
int wishState = isOpened ? STATE_SWITCH_ON : STATE_SWITCH_OFF;
|
||||
if (wishState == state) {
|
||||
return;
|
||||
}
|
||||
if ((wishState == STATE_SWITCH_ON && (state == STATE_SWITCH_OFF || state == STATE_SWITCH_OFF2))
|
||||
|| (wishState == STATE_SWITCH_OFF && (state == STATE_SWITCH_ON || state == STATE_SWITCH_ON2))) {
|
||||
sAnim = 1;
|
||||
}
|
||||
bAnim = 1;
|
||||
refreshState(wishState);
|
||||
}
|
||||
|
||||
private void refreshState(int newState) {
|
||||
if (!isOpened && newState == STATE_SWITCH_ON) {
|
||||
isOpened = true;
|
||||
} else if (isOpened && newState == STATE_SWITCH_OFF) {
|
||||
isOpened = false;
|
||||
}
|
||||
lastState = state;
|
||||
state = newState;
|
||||
postInvalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
|
||||
int widthMode = MeasureSpec.getMode(widthMeasureSpec);
|
||||
int resultWidth;
|
||||
if (widthMode == MeasureSpec.EXACTLY) {
|
||||
resultWidth = widthSize;
|
||||
} else {
|
||||
resultWidth = (int) (56 * getResources().getDisplayMetrics().density + 0.5f)
|
||||
+ getPaddingLeft() + getPaddingRight();
|
||||
if (widthMode == MeasureSpec.AT_MOST) {
|
||||
resultWidth = Math.min(resultWidth, widthSize);
|
||||
}
|
||||
}
|
||||
|
||||
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
|
||||
int heightMode = MeasureSpec.getMode(heightMeasureSpec);
|
||||
int resultHeight;
|
||||
if (heightMode == MeasureSpec.EXACTLY) {
|
||||
resultHeight = heightSize;
|
||||
} else {
|
||||
int selfExpectedResultHeight = (int) (resultWidth * RATIO_ASPECT) + getPaddingTop() + getPaddingBottom();
|
||||
resultHeight = selfExpectedResultHeight;
|
||||
if (heightMode == MeasureSpec.AT_MOST) {
|
||||
resultHeight = Math.min(resultHeight, heightSize);
|
||||
}
|
||||
}
|
||||
setMeasuredDimension(resultWidth, resultHeight);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
||||
super.onSizeChanged(w, h, oldw, oldh);
|
||||
mWidth = w;
|
||||
mHeight = h;
|
||||
isCanVisibleDrawing = mWidth > getPaddingLeft() + getPaddingRight() && mHeight > getPaddingTop() + getPaddingBottom();
|
||||
|
||||
if (isCanVisibleDrawing) {
|
||||
int actuallyDrawingAreaWidth = mWidth - getPaddingLeft() - getPaddingRight();
|
||||
int actuallyDrawingAreaHeight = mHeight - getPaddingTop() - getPaddingBottom();
|
||||
|
||||
if (actuallyDrawingAreaWidth * RATIO_ASPECT < actuallyDrawingAreaHeight) {
|
||||
actuallyDrawingAreaLeft = getPaddingLeft();
|
||||
actuallyDrawingAreaRight = mWidth - getPaddingRight();
|
||||
int heightExtraSize = (int) (actuallyDrawingAreaHeight - actuallyDrawingAreaWidth * RATIO_ASPECT);
|
||||
actuallyDrawingAreaTop = getPaddingTop() + heightExtraSize / 2;
|
||||
actuallyDrawingAreaBottom = getHeight() - getPaddingBottom() - heightExtraSize / 2;
|
||||
} else {
|
||||
int widthExtraSize = (int) (actuallyDrawingAreaWidth - actuallyDrawingAreaHeight / RATIO_ASPECT);
|
||||
actuallyDrawingAreaLeft = getPaddingLeft() + widthExtraSize / 2;
|
||||
actuallyDrawingAreaRight = getWidth() - getPaddingRight() - widthExtraSize / 2;
|
||||
actuallyDrawingAreaTop = getPaddingTop();
|
||||
actuallyDrawingAreaBottom = getHeight() - getPaddingBottom();
|
||||
}
|
||||
|
||||
shadowReservedHeight = (int) ((actuallyDrawingAreaBottom - actuallyDrawingAreaTop) * 0.09f);
|
||||
sLeft = actuallyDrawingAreaLeft;
|
||||
sTop = actuallyDrawingAreaTop + shadowReservedHeight;
|
||||
sRight = actuallyDrawingAreaRight;
|
||||
sBottom = actuallyDrawingAreaBottom - shadowReservedHeight;
|
||||
|
||||
sWidth = sRight - sLeft;
|
||||
sHeight = sBottom - sTop;
|
||||
sCenterX = (sRight + sLeft) / 2;
|
||||
sCenterY = (sBottom + sTop) / 2;
|
||||
|
||||
bLeft = sLeft;
|
||||
bTop = sTop;
|
||||
bBottom = sBottom;
|
||||
bWidth = sBottom - sTop;
|
||||
bRight = sLeft + bWidth;
|
||||
final float halfHeightOfS = bWidth / 2; // OfB
|
||||
bRadius = halfHeightOfS * 0.95f;
|
||||
bOffset = bRadius * 0.2f; // offset of switching
|
||||
bStrokeWidth = (halfHeightOfS - bRadius) * 2;
|
||||
bOnLeftX = sRight - bWidth;
|
||||
bOn2LeftX = bOnLeftX - bOffset;
|
||||
bOffLeftX = sLeft;
|
||||
bOff2LeftX = bOffLeftX + bOffset;
|
||||
sScale = 1 - bStrokeWidth / sHeight;
|
||||
|
||||
sPath.reset();
|
||||
RectF sRectF = new RectF();
|
||||
sRectF.top = sTop;
|
||||
sRectF.bottom = sBottom;
|
||||
sRectF.left = sLeft;
|
||||
sRectF.right = sLeft + sHeight;
|
||||
sPath.arcTo(sRectF, 90, 180);
|
||||
sRectF.left = sRight - sHeight;
|
||||
sRectF.right = sRight;
|
||||
sPath.arcTo(sRectF, 270, 180);
|
||||
sPath.close();
|
||||
|
||||
bRectF.left = bLeft;
|
||||
bRectF.right = bRight;
|
||||
bRectF.top = bTop + bStrokeWidth / 2;
|
||||
bRectF.bottom = bBottom - bStrokeWidth / 2;
|
||||
float bCenterX = (bRight + bLeft) / 2;
|
||||
float bCenterY = (bBottom + bTop) / 2;
|
||||
|
||||
shadowGradient = new RadialGradient(bCenterX, bCenterY, bRadius, 0xff000000, 0x00000000, Shader.TileMode.CLAMP);
|
||||
}
|
||||
}
|
||||
|
||||
private void calcBPath(float percent) {
|
||||
bPath.reset();
|
||||
bRectF.left = bLeft + bStrokeWidth / 2;
|
||||
bRectF.right = bRight - bStrokeWidth / 2;
|
||||
bPath.arcTo(bRectF, 90, 180);
|
||||
bRectF.left = bLeft + percent * bOffset + bStrokeWidth / 2;
|
||||
bRectF.right = bRight + percent * bOffset - bStrokeWidth / 2;
|
||||
bPath.arcTo(bRectF, 270, 180);
|
||||
bPath.close();
|
||||
}
|
||||
|
||||
private float calcBTranslate(float percent) {
|
||||
float result = 0;
|
||||
switch (state - lastState) {
|
||||
case 1:
|
||||
if (state == STATE_SWITCH_OFF2) {
|
||||
result = bOffLeftX; // off -> off2
|
||||
} else if (state == STATE_SWITCH_ON) {
|
||||
result = bOnLeftX - (bOnLeftX - bOn2LeftX) * percent; // on2 -> on
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (state == STATE_SWITCH_ON) {
|
||||
result = bOnLeftX - (bOnLeftX - bOffLeftX) * percent; // off2 -> on
|
||||
} else if (state == STATE_SWITCH_ON) {
|
||||
result = bOn2LeftX - (bOn2LeftX - bOffLeftX) * percent; // off -> on2
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
result = bOnLeftX - (bOnLeftX - bOffLeftX) * percent; // off -> on
|
||||
break;
|
||||
case -1:
|
||||
if (state == STATE_SWITCH_ON2) {
|
||||
result = bOn2LeftX + (bOnLeftX - bOn2LeftX) * percent; // on -> on2
|
||||
} else if (state == STATE_SWITCH_OFF) {
|
||||
result = bOffLeftX; // off2 -> off
|
||||
}
|
||||
break;
|
||||
case -2:
|
||||
if (state == STATE_SWITCH_OFF) {
|
||||
result = bOffLeftX + (bOn2LeftX - bOffLeftX) * percent; // on2 -> off
|
||||
} else if (state == STATE_SWITCH_OFF2) {
|
||||
result = bOff2LeftX + (bOnLeftX - bOff2LeftX) * percent; // on -> off2
|
||||
}
|
||||
break;
|
||||
case -3:
|
||||
result = bOffLeftX + (bOnLeftX - bOffLeftX) * percent; // on -> off
|
||||
break;
|
||||
default: // init
|
||||
case 0:
|
||||
if (state == STATE_SWITCH_OFF) {
|
||||
result = bOffLeftX; // off -> off
|
||||
} else if (state == STATE_SWITCH_ON) {
|
||||
result = bOnLeftX; // on -> on
|
||||
}
|
||||
break;
|
||||
}
|
||||
return result - bOffLeftX;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
super.onDraw(canvas);
|
||||
if (!isCanVisibleDrawing) return;
|
||||
|
||||
paint.setAntiAlias(true);
|
||||
final boolean isOn = (state == STATE_SWITCH_ON || state == STATE_SWITCH_ON2);
|
||||
// Draw background
|
||||
paint.setStyle(Paint.Style.FILL);
|
||||
paint.setColor(isOn ? colorPrimary : 0xffE3E3E3);
|
||||
canvas.drawPath(sPath, paint);
|
||||
|
||||
sAnim = sAnim - ANIMATION_SPEED > 0 ? sAnim - ANIMATION_SPEED : 0;
|
||||
bAnim = bAnim - ANIMATION_SPEED > 0 ? bAnim - ANIMATION_SPEED : 0;
|
||||
|
||||
final float dsAnim = interpolator.getInterpolation(sAnim);
|
||||
final float dbAnim = interpolator.getInterpolation(bAnim);
|
||||
// Draw background animation
|
||||
final float scale = sScale * (isOn ? dsAnim : 1 - dsAnim);
|
||||
final float scaleOffset = (sRight - sCenterX - bRadius) * (isOn ? 1 - dsAnim : dsAnim);
|
||||
canvas.save();
|
||||
canvas.scale(scale, scale, sCenterX + scaleOffset, sCenterY);
|
||||
paint.setColor(0xFFFFFFFF);
|
||||
canvas.drawPath(sPath, paint);
|
||||
canvas.restore();
|
||||
// To prepare center bar path
|
||||
canvas.save();
|
||||
canvas.translate(calcBTranslate(dbAnim), shadowReservedHeight);
|
||||
final boolean isState2 = (state == STATE_SWITCH_ON2 || state == STATE_SWITCH_OFF2);
|
||||
calcBPath(isState2 ? 1 - dbAnim : dbAnim);
|
||||
// Use center bar path to draw shadow
|
||||
if (hasShadow) {
|
||||
paint.setStyle(Paint.Style.FILL);
|
||||
paint.setColor(0xFF333333);
|
||||
paint.setShader(shadowGradient);
|
||||
canvas.drawPath(bPath, paint);
|
||||
paint.setShader(null);
|
||||
}
|
||||
canvas.translate(0, -shadowReservedHeight);
|
||||
// draw bar
|
||||
canvas.scale(0.98f, 0.98f, bWidth / 2, bWidth / 2);
|
||||
paint.setStyle(Paint.Style.FILL);
|
||||
paint.setColor(0xffffffff);
|
||||
canvas.drawPath(bPath, paint);
|
||||
paint.setStyle(Paint.Style.STROKE);
|
||||
paint.setStrokeWidth(bStrokeWidth * 0.5f);
|
||||
paint.setColor(isOn ? colorPrimaryDark : 0xFFBFBFBF);
|
||||
canvas.drawPath(bPath, paint);
|
||||
canvas.restore();
|
||||
|
||||
paint.reset();
|
||||
if (sAnim > 0 || bAnim > 0) invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
if ((state == STATE_SWITCH_ON || state == STATE_SWITCH_OFF) && (sAnim * bAnim == 0)) {
|
||||
switch (event.getAction()) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
return true;
|
||||
case MotionEvent.ACTION_UP:
|
||||
lastState = state;
|
||||
|
||||
bAnim = 1;
|
||||
if (state == STATE_SWITCH_OFF) {
|
||||
refreshState(STATE_SWITCH_OFF2);
|
||||
listener.toggleToOn(this);
|
||||
} else if (state == STATE_SWITCH_ON) {
|
||||
refreshState(STATE_SWITCH_ON2);
|
||||
listener.toggleToOff(this);
|
||||
}
|
||||
|
||||
if (mOnClickListener != null) {
|
||||
mOnClickListener.onClick(this);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return super.onTouchEvent(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOnClickListener(OnClickListener l) {
|
||||
super.setOnClickListener(l);
|
||||
mOnClickListener = l;
|
||||
}
|
||||
|
||||
public interface OnStateChangedListener {
|
||||
void toggleToOn(SwitchView view);
|
||||
|
||||
void toggleToOff(SwitchView view);
|
||||
}
|
||||
|
||||
private OnStateChangedListener listener = new OnStateChangedListener() {
|
||||
@Override
|
||||
public void toggleToOn(SwitchView view) {
|
||||
toggleSwitch(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toggleToOff(SwitchView view) {
|
||||
toggleSwitch(false);
|
||||
}
|
||||
};
|
||||
|
||||
public void setOnStateChangedListener(OnStateChangedListener listener) {
|
||||
if (listener == null) throw new IllegalArgumentException("empty listener");
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Parcelable onSaveInstanceState() {
|
||||
Parcelable superState = super.onSaveInstanceState();
|
||||
SavedState ss = new SavedState(superState);
|
||||
ss.isOpened = isOpened;
|
||||
return ss;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRestoreInstanceState(Parcelable state) {
|
||||
SavedState ss = (SavedState) state;
|
||||
super.onRestoreInstanceState(ss.getSuperState());
|
||||
this.isOpened = ss.isOpened;
|
||||
this.state = this.isOpened ? STATE_SWITCH_ON : STATE_SWITCH_OFF;
|
||||
invalidate();
|
||||
}
|
||||
|
||||
@SuppressLint("ParcelCreator")
|
||||
static final class SavedState extends BaseSavedState {
|
||||
private boolean isOpened;
|
||||
|
||||
SavedState(Parcelable superState) {
|
||||
super(superState);
|
||||
}
|
||||
|
||||
private SavedState(Parcel in) {
|
||||
super(in);
|
||||
isOpened = 1 == in.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel out, int flags) {
|
||||
super.writeToParcel(out, flags);
|
||||
out.writeInt(isOpened ? 1 : 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
Binary file not shown.
@ -1,148 +0,0 @@
|
||||
package com.gizwits.opensource.appkit.wxapi;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.Message;
|
||||
import android.util.Log;
|
||||
|
||||
import com.gizwits.gizwifisdk.enumration.GizThirdAccountType;
|
||||
import com.gizwits.opensource.appkit.CommonModule.GosBaseActivity;
|
||||
import com.gizwits.opensource.appkit.CommonModule.GosDeploy;
|
||||
import com.gizwits.opensource.appkit.UserModule.GosUserLoginActivity;
|
||||
import com.tencent.mm.sdk.modelbase.BaseReq;
|
||||
import com.tencent.mm.sdk.modelbase.BaseResp;
|
||||
import com.tencent.mm.sdk.modelmsg.SendAuth;
|
||||
import com.tencent.mm.sdk.openapi.IWXAPI;
|
||||
import com.tencent.mm.sdk.openapi.IWXAPIEventHandler;
|
||||
import com.tencent.mm.sdk.openapi.WXAPIFactory;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
|
||||
public class WXEntryActivity extends GosBaseActivity implements IWXAPIEventHandler {
|
||||
|
||||
private static final String TAG = "WXEntryActivity";
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
IWXAPI api = WXAPIFactory.createWXAPI(this, GosDeploy.appConfig_WechatAppID(), true);
|
||||
api.handleIntent(getIntent(), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReq(BaseReq req) {
|
||||
Log.i(TAG, "onReq...");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResp(BaseResp resp) {
|
||||
Log.i(TAG, "onResp: " + resp);
|
||||
String code = null;
|
||||
switch (resp.errCode) {
|
||||
case BaseResp.ErrCode.ERR_OK:// 用户同意,只有这种情况的时候code是有效的
|
||||
code = ((SendAuth.Resp) resp).code;
|
||||
Log.i("Apptest", code);
|
||||
try {
|
||||
requesUserInfo(code);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
break;
|
||||
case BaseResp.ErrCode.ERR_AUTH_DENIED:// 用户拒绝授权
|
||||
Log.i("Apptest", "用户拒绝授权");
|
||||
break;
|
||||
case BaseResp.ErrCode.ERR_USER_CANCEL:// 用户取消
|
||||
Log.i("Apptest", "用户取消");
|
||||
break;
|
||||
|
||||
default:// 发送返回
|
||||
|
||||
break;
|
||||
}
|
||||
finish();
|
||||
}
|
||||
|
||||
public void requesUserInfo(final String code) throws Exception {
|
||||
final String path = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + GosDeploy.appConfig_WechatAppID()
|
||||
+ "&secret=" + GosDeploy.appConfig_WechatAppSecret() + "&code=" + code
|
||||
+ "&grant_type=authorization_code";
|
||||
final android.os.Handler handler = new android.os.Handler() {
|
||||
public void handleMessage(Message msg) {
|
||||
super.handleMessage(msg);
|
||||
Bundle b = msg.getData();
|
||||
String newsTemp = b.getString("msg");
|
||||
try {
|
||||
JSONObject jsonObject = new JSONObject(newsTemp);
|
||||
if (null != jsonObject) {
|
||||
String openid = jsonObject.getString("openid").toString().trim();
|
||||
String access_token = jsonObject.getString("access_token").toString().trim();
|
||||
|
||||
GosUserLoginActivity.gizThirdAccountType = GizThirdAccountType.GizThirdWeChat;
|
||||
GosUserLoginActivity.thirdToken = access_token;
|
||||
GosUserLoginActivity.thirdUid = openid;
|
||||
|
||||
Message msg1 = new Message();
|
||||
msg1.what = GosUserLoginActivity.handler_key.THRED_LOGIN.ordinal();
|
||||
baseHandler.sendMessage(msg1);
|
||||
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
BufferedReader br = null;
|
||||
try {
|
||||
URL url = new URL(path);
|
||||
HttpURLConnection httpconn = (HttpURLConnection) url.openConnection();
|
||||
httpconn.setRequestProperty("accept", "*/*");
|
||||
httpconn.setDoInput(true);
|
||||
httpconn.setDoOutput(true);
|
||||
httpconn.setConnectTimeout(5000);
|
||||
httpconn.connect();
|
||||
int stat = 200;
|
||||
String msg = "";
|
||||
if (stat == 200) {
|
||||
br = new BufferedReader(new InputStreamReader(httpconn.getInputStream()));
|
||||
msg = br.readLine();
|
||||
Bundle b = new Bundle();
|
||||
b.putString("msg", msg);
|
||||
Message m = new Message();
|
||||
m.setData(b);
|
||||
handler.sendMessage(m);
|
||||
} else {
|
||||
msg = "请求失败";
|
||||
Log.i(TAG, msg);
|
||||
}
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (br != null) {
|
||||
try {
|
||||
br.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,443 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2008 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package zxing;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.util.Log;
|
||||
import android.view.SurfaceHolder;
|
||||
import android.view.SurfaceView;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.view.animation.Animation;
|
||||
import android.view.animation.TranslateAnimation;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.gizwits.opensource.appkit.R;
|
||||
import com.gizwits.opensource.appkit.CommonModule.GosBaseActivity;
|
||||
import com.gizwits.opensource.appkit.DeviceModule.GosDeviceListFragment;
|
||||
import com.google.zxing.Result;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import zxing.camera.CameraManager;
|
||||
import zxing.decoding.DecodeThread;
|
||||
import zxing.utils.CaptureActivityHandler;
|
||||
import zxing.utils.InactivityTimer;
|
||||
|
||||
/**
|
||||
* This activity opens the camera and does the actual scanning on a background
|
||||
* thread. It draws a viewfinder to help the user place the barcode correctly,
|
||||
* shows feedback as the image processing is happening, and then overlays the
|
||||
* results when a scan is successful.
|
||||
*
|
||||
* @author dswitkin@google.com (Daniel Switkin)
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class CaptureActivity extends GosBaseActivity implements SurfaceHolder.Callback {
|
||||
|
||||
private static final String TAG = CaptureActivity.class.getSimpleName();
|
||||
|
||||
private CameraManager cameraManager;
|
||||
private CaptureActivityHandler handler;
|
||||
private InactivityTimer inactivityTimer;
|
||||
|
||||
private SurfaceView scanPreview = null;
|
||||
private RelativeLayout scanContainer;
|
||||
private RelativeLayout scanCropView;
|
||||
private ImageView scanLine;
|
||||
private Button btnCancel;
|
||||
private ImageView ivReturn;
|
||||
// private String uid, token, mac, productKey, productSecret;
|
||||
private String did, passcode, product_key;
|
||||
private TextView tvDeviceCode;
|
||||
private boolean isSetting = false;
|
||||
|
||||
/**
|
||||
* ClassName: Enum handler_key. <br/>
|
||||
* <br/>
|
||||
* date: 2014-11-26 17:51:10 <br/>
|
||||
*
|
||||
* @author Lien
|
||||
*/
|
||||
private enum handler_key {
|
||||
|
||||
START_BIND,
|
||||
SEND_CODE
|
||||
}
|
||||
|
||||
/**
|
||||
* The handler.
|
||||
*/
|
||||
@SuppressLint("HandlerLeak")
|
||||
Handler mHandler = new Handler() {
|
||||
public void handleMessage(Message msg) {
|
||||
super.handleMessage(msg);
|
||||
handler_key key = handler_key.values()[msg.what];
|
||||
switch (key) {
|
||||
|
||||
case START_BIND:
|
||||
String[] strings = (String[]) msg.obj;
|
||||
for (String string : strings) {
|
||||
GosDeviceListFragment.boundMessage.add(string);
|
||||
}
|
||||
finish();
|
||||
break;
|
||||
case SEND_CODE:
|
||||
String s = (String) msg.obj;
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra("code", s);
|
||||
setResult(33, intent);
|
||||
finish();
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private Rect mCropRect = null;
|
||||
|
||||
public Handler getHandler() {
|
||||
return handler;
|
||||
}
|
||||
|
||||
public CameraManager getCameraManager() {
|
||||
return cameraManager;
|
||||
}
|
||||
|
||||
private boolean isHasSurface = false;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
/**
|
||||
* 设置为竖屏
|
||||
*/
|
||||
if (getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
|
||||
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
||||
}
|
||||
|
||||
Window window = getWindow();
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
setContentView(R.layout.activity_gos_capture);
|
||||
|
||||
scanPreview = (SurfaceView) findViewById(R.id.capture_preview);
|
||||
scanContainer = (RelativeLayout) findViewById(R.id.capture_container);
|
||||
scanCropView = (RelativeLayout) findViewById(R.id.capture_crop_view);
|
||||
scanLine = (ImageView) findViewById(R.id.capture_scan_line);
|
||||
tvDeviceCode = (TextView) findViewById(R.id.tvDeviceCode);
|
||||
|
||||
inactivityTimer = new InactivityTimer(this);
|
||||
|
||||
TranslateAnimation animation = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.0f,
|
||||
Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, -1.0f, Animation.RELATIVE_TO_PARENT,
|
||||
0.0f);
|
||||
animation.setDuration(4500);
|
||||
animation.setRepeatCount(-1);
|
||||
animation.setRepeatMode(Animation.RESTART);
|
||||
scanLine.startAnimation(animation);
|
||||
|
||||
btnCancel = (Button) findViewById(R.id.btn_cancel);
|
||||
ivReturn = (ImageView) findViewById(R.id.iv_return);
|
||||
OnClickListener myClick = new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
CaptureActivity.this.finish();
|
||||
}
|
||||
};
|
||||
btnCancel.setOnClickListener(myClick);
|
||||
ivReturn.setOnClickListener(myClick);
|
||||
isSetting = getIntent().getBooleanExtra("isSetting", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
// CameraManager must be initialized here, not in onCreate(). This is
|
||||
// necessary because we don't
|
||||
// want to open the camera driver and measure the screen size if we're
|
||||
// going to show the help on
|
||||
// first launch. That led to bugs where the scanning rectangle was the
|
||||
// wrong size and partially
|
||||
// off screen.
|
||||
cameraManager = new CameraManager(getApplication());
|
||||
|
||||
handler = null;
|
||||
|
||||
if (isHasSurface) {
|
||||
// The activity was paused but not stopped, so the surface still
|
||||
// exists. Therefore
|
||||
// surfaceCreated() won't be called, so init the camera here.
|
||||
initCamera(scanPreview.getHolder());
|
||||
} else {
|
||||
// Install the callback and wait for surfaceCreated() to init the
|
||||
// camera.
|
||||
scanPreview.getHolder().addCallback(this);
|
||||
}
|
||||
|
||||
inactivityTimer.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
if (handler != null) {
|
||||
handler.quitSynchronously();
|
||||
handler = null;
|
||||
}
|
||||
inactivityTimer.onPause();
|
||||
cameraManager.closeDriver();
|
||||
if (!isHasSurface) {
|
||||
scanPreview.getHolder().removeCallback(this);
|
||||
}
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
inactivityTimer.shutdown();
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
super.onBackPressed();
|
||||
overridePendingTransition(R.anim.in_from_left, R.anim.out_to_right);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void surfaceCreated(SurfaceHolder holder) {
|
||||
if (holder == null) {
|
||||
Log.i(TAG, "*** WARNING *** surfaceCreated() gave us a null surface!");
|
||||
}
|
||||
if (!isHasSurface) {
|
||||
isHasSurface = true;
|
||||
initCamera(holder);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void surfaceDestroyed(SurfaceHolder holder) {
|
||||
isHasSurface = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* A valid barcode has been found, so give an indication of success and show
|
||||
* the results.
|
||||
*
|
||||
* @param rawResult The contents of the barcode.
|
||||
* @param bundle The extras
|
||||
*/
|
||||
public void handleDecode(Result rawResult, Bundle bundle) {
|
||||
String text = rawResult.getText();
|
||||
boolean isJson = false;
|
||||
try {
|
||||
JSONObject jsonObject = new JSONObject(text);
|
||||
isJson = true;
|
||||
} catch(JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Message msg = new Message();
|
||||
if (isSetting) {
|
||||
if (isJson) {
|
||||
msg.what = handler_key.SEND_CODE.ordinal();
|
||||
msg.obj = text;
|
||||
mHandler.sendMessage(msg);
|
||||
} else {
|
||||
Toast.makeText(this, getString(R.string.code_invalid), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
} else {
|
||||
if (text.contains("product_key=") && text.contains("did=") && text.contains("passcode=")) {
|
||||
inactivityTimer.onActivity();
|
||||
product_key = getParamFomeUrl(text, "product_key");
|
||||
did = getParamFomeUrl(text, "did");
|
||||
passcode = getParamFomeUrl(text, "passcode");
|
||||
String[] strings = {did, passcode};
|
||||
msg.what = handler_key.START_BIND.ordinal();
|
||||
msg.obj = strings;
|
||||
mHandler.sendMessage(msg);
|
||||
Log.e(TAG, "handleDecode-------: " + strings);
|
||||
} else if (text.contains("type=") && text.contains("code=")) {
|
||||
//type=xxx & code=xxx
|
||||
String[] split = text.split("&");
|
||||
String[] split2 = split[1].split("=");
|
||||
final String code = split2[1];
|
||||
String[] strings = {"", "", code};
|
||||
|
||||
msg.what = handler_key.START_BIND.ordinal();
|
||||
msg.obj = strings;
|
||||
mHandler.sendMessage(msg);
|
||||
} else {
|
||||
// handler = new CaptureActivityHandler(this, cameraManager,
|
||||
// DecodeThread.ALL_MODE);
|
||||
String[] strings = {text};
|
||||
msg.what = handler_key.START_BIND.ordinal();
|
||||
msg.obj = strings;
|
||||
mHandler.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private String getParamFomeUrl(String url, String param) {
|
||||
String product_key = "";
|
||||
int startindex = url.indexOf(param + "=");
|
||||
startindex += (param.length() + 1);
|
||||
String subString = url.substring(startindex);
|
||||
int endindex = subString.indexOf("&");
|
||||
if (endindex == -1) {
|
||||
product_key = subString;
|
||||
} else {
|
||||
product_key = subString.substring(0, endindex);
|
||||
}
|
||||
return product_key;
|
||||
}
|
||||
|
||||
private void initCamera(SurfaceHolder surfaceHolder) {
|
||||
if (surfaceHolder == null) {
|
||||
throw new IllegalStateException("No SurfaceHolder provided");
|
||||
}
|
||||
if (cameraManager.isOpen()) {
|
||||
Log.w(TAG, "initCamera() while already open -- late SurfaceView callback?");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
cameraManager.openDriver(surfaceHolder);
|
||||
// Creating the handler starts the preview, which can also throw a
|
||||
// RuntimeException.
|
||||
if (handler == null) {
|
||||
handler = new CaptureActivityHandler(this, cameraManager, DecodeThread.ALL_MODE);
|
||||
}
|
||||
|
||||
initCrop();
|
||||
} catch(IOException ioe) {
|
||||
Log.w(TAG, ioe);
|
||||
displayFrameworkBugMessageAndExit();
|
||||
} catch(RuntimeException e) {
|
||||
// Barcode Scanner has seen crashes in the wild of this variety:
|
||||
// java.?lang.?RuntimeException: Fail to connect to camera service
|
||||
Log.w(TAG, "Unexpected error initializing camera", e);
|
||||
displayFrameworkBugMessageAndExit();
|
||||
}
|
||||
}
|
||||
|
||||
private void displayFrameworkBugMessageAndExit() {
|
||||
// camera error
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle(getString(R.string.app_name));
|
||||
String camera_error = getText(R.string.camera_error).toString();
|
||||
builder.setMessage(camera_error);
|
||||
String shure = getText(R.string.besure).toString();
|
||||
builder.setPositiveButton(shure, new DialogInterface.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
finish();
|
||||
}
|
||||
|
||||
});
|
||||
builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
|
||||
|
||||
@Override
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
finish();
|
||||
}
|
||||
});
|
||||
builder.show();
|
||||
}
|
||||
|
||||
public void restartPreviewAfterDelay(long delayMS) {
|
||||
if (handler != null) {
|
||||
handler.sendEmptyMessageDelayed(R.id.restart_preview, delayMS);
|
||||
}
|
||||
}
|
||||
|
||||
public Rect getCropRect() {
|
||||
return mCropRect;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化截取的矩形区域
|
||||
*/
|
||||
private void initCrop() {
|
||||
int cameraWidth = cameraManager.getCameraResolution().y;
|
||||
int cameraHeight = cameraManager.getCameraResolution().x;
|
||||
|
||||
/** 获取布局中扫描框的位置信息 */
|
||||
int[] location = new int[2];
|
||||
scanCropView.getLocationInWindow(location);
|
||||
|
||||
int cropLeft = location[0];
|
||||
int cropTop = location[1] - getStatusBarHeight();
|
||||
|
||||
int cropWidth = scanCropView.getWidth();
|
||||
int cropHeight = scanCropView.getHeight();
|
||||
|
||||
/** 获取布局容器的宽高 */
|
||||
int containerWidth = scanContainer.getWidth();
|
||||
int containerHeight = scanContainer.getHeight();
|
||||
|
||||
/** 计算最终截取的矩形的左上角顶点x坐标 */
|
||||
int x = cropLeft * cameraWidth / containerWidth;
|
||||
/** 计算最终截取的矩形的左上角顶点y坐标 */
|
||||
int y = cropTop * cameraHeight / containerHeight;
|
||||
|
||||
/** 计算最终截取的矩形的宽度 */
|
||||
int width = cropWidth * cameraWidth / containerWidth;
|
||||
/** 计算最终截取的矩形的高度 */
|
||||
int height = cropHeight * cameraHeight / containerHeight;
|
||||
|
||||
/** 生成最终的截取的矩形 */
|
||||
mCropRect = new Rect(x, y, width + x, height + y);
|
||||
}
|
||||
|
||||
private int getStatusBarHeight() {
|
||||
try {
|
||||
Class<?> c = Class.forName("com.android.internal.R$dimen");
|
||||
Object obj = c.newInstance();
|
||||
Field field = c.getField("status_bar_height");
|
||||
int x = Integer.parseInt(field.get(obj).toString());
|
||||
return getResources().getDimensionPixelSize(x);
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
@ -1,134 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2012 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package zxing.camera;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.concurrent.RejectedExecutionException;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.hardware.*;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
|
||||
public class AutoFocusManager implements Camera.AutoFocusCallback {
|
||||
|
||||
private static final String TAG = AutoFocusManager.class.getSimpleName();
|
||||
|
||||
private static final long AUTO_FOCUS_INTERVAL_MS = 2000L;
|
||||
private static final Collection<String> FOCUS_MODES_CALLING_AF;
|
||||
|
||||
static {
|
||||
FOCUS_MODES_CALLING_AF = new ArrayList<String>(2);
|
||||
FOCUS_MODES_CALLING_AF.add(Camera.Parameters.FOCUS_MODE_AUTO);
|
||||
FOCUS_MODES_CALLING_AF.add(Camera.Parameters.FOCUS_MODE_MACRO);
|
||||
}
|
||||
|
||||
private boolean stopped;
|
||||
private boolean focusing;
|
||||
private final boolean useAutoFocus;
|
||||
private final Camera camera;
|
||||
private AsyncTask<?, ?, ?> outstandingTask;
|
||||
|
||||
public AutoFocusManager(Context context, Camera camera) {
|
||||
this.camera = camera;
|
||||
String currentFocusMode = camera.getParameters().getFocusMode();
|
||||
useAutoFocus = FOCUS_MODES_CALLING_AF.contains(currentFocusMode);
|
||||
Log.i(TAG, "Current focus mode '" + currentFocusMode + "'; use auto focus? " + useAutoFocus);
|
||||
start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void onAutoFocus(boolean success, Camera theCamera) {
|
||||
focusing = false;
|
||||
autoFocusAgainLater();
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
private synchronized void autoFocusAgainLater() {
|
||||
if (!stopped && outstandingTask == null) {
|
||||
AutoFocusTask newTask = new AutoFocusTask();
|
||||
try {
|
||||
if (Build.VERSION.SDK_INT >= 11) {
|
||||
newTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
} else {
|
||||
newTask.execute();
|
||||
}
|
||||
outstandingTask = newTask;
|
||||
} catch (RejectedExecutionException ree) {
|
||||
Log.w(TAG, "Could not request auto focus", ree);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void start() {
|
||||
if (useAutoFocus) {
|
||||
outstandingTask = null;
|
||||
if (!stopped && !focusing) {
|
||||
try {
|
||||
camera.autoFocus(this);
|
||||
focusing = true;
|
||||
} catch (RuntimeException re) {
|
||||
// Have heard RuntimeException reported in Android 4.0.x+;
|
||||
// continue?
|
||||
Log.w(TAG, "Unexpected exception while focusing", re);
|
||||
// Try again later to keep cycle going
|
||||
autoFocusAgainLater();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void cancelOutstandingTask() {
|
||||
if (outstandingTask != null) {
|
||||
if (outstandingTask.getStatus() != AsyncTask.Status.FINISHED) {
|
||||
outstandingTask.cancel(true);
|
||||
}
|
||||
outstandingTask = null;
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void stop() {
|
||||
stopped = true;
|
||||
if (useAutoFocus) {
|
||||
cancelOutstandingTask();
|
||||
// Doesn't hurt to call this even if not focusing
|
||||
try {
|
||||
camera.cancelAutoFocus();
|
||||
} catch (RuntimeException re) {
|
||||
// Have heard RuntimeException reported in Android 4.0.x+;
|
||||
// continue?
|
||||
Log.w(TAG, "Unexpected exception while cancelling focusing", re);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final class AutoFocusTask extends AsyncTask<Object, Object, Object> {
|
||||
@Override
|
||||
protected Object doInBackground(Object... voids) {
|
||||
try {
|
||||
Thread.sleep(AUTO_FOCUS_INTERVAL_MS);
|
||||
} catch (InterruptedException e) {
|
||||
// continue
|
||||
}
|
||||
start();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,220 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2008 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package zxing.camera;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.graphics.Point;
|
||||
import android.hardware.Camera;
|
||||
import android.util.Log;
|
||||
import android.view.Display;
|
||||
import android.view.WindowManager;
|
||||
|
||||
public final class CameraConfigurationManager {
|
||||
|
||||
private static final String TAG = "CameraConfiguration";
|
||||
|
||||
private static final int MIN_PREVIEW_PIXELS = 480 * 320;
|
||||
private static final double MAX_ASPECT_DISTORTION = 0.15;
|
||||
|
||||
private final Context context;
|
||||
|
||||
// 屏幕分辨率
|
||||
private Point screenResolution;
|
||||
// 相机分辨率
|
||||
private Point cameraResolution;
|
||||
|
||||
public CameraConfigurationManager(Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public void initFromCameraParameters(Camera camera) {
|
||||
Camera.Parameters parameters = camera.getParameters();
|
||||
WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
|
||||
Display display = manager.getDefaultDisplay();
|
||||
Point theScreenResolution = new Point();
|
||||
theScreenResolution = getDisplaySize(display);
|
||||
|
||||
screenResolution = theScreenResolution;
|
||||
Log.i(TAG, "Screen resolution: " + screenResolution);
|
||||
|
||||
/** 因为换成了竖屏显示,所以不替换屏幕宽高得出的预览图是变形的 */
|
||||
Point screenResolutionForCamera = new Point();
|
||||
screenResolutionForCamera.x = screenResolution.x;
|
||||
screenResolutionForCamera.y = screenResolution.y;
|
||||
|
||||
if (screenResolution.x < screenResolution.y) {
|
||||
screenResolutionForCamera.x = screenResolution.y;
|
||||
screenResolutionForCamera.y = screenResolution.x;
|
||||
}
|
||||
|
||||
cameraResolution = findBestPreviewSizeValue(parameters, screenResolutionForCamera);
|
||||
Log.i(TAG, "Camera resolution x: " + cameraResolution.x);
|
||||
Log.i(TAG, "Camera resolution y: " + cameraResolution.y);
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
private Point getDisplaySize(final Display display) {
|
||||
final Point point = new Point();
|
||||
try {
|
||||
display.getSize(point);
|
||||
} catch (NoSuchMethodError ignore) {
|
||||
point.x = display.getWidth();
|
||||
point.y = display.getHeight();
|
||||
}
|
||||
return point;
|
||||
}
|
||||
|
||||
public void setDesiredCameraParameters(Camera camera, boolean safeMode) {
|
||||
Camera.Parameters parameters = camera.getParameters();
|
||||
|
||||
if (parameters == null) {
|
||||
Log.w(TAG, "Device error: no camera parameters are available. Proceeding without configuration.");
|
||||
return;
|
||||
}
|
||||
|
||||
Log.i(TAG, "Initial camera parameters: " + parameters.flatten());
|
||||
|
||||
if (safeMode) {
|
||||
Log.w(TAG, "In camera config safe mode -- most settings will not be honored");
|
||||
}
|
||||
|
||||
parameters.setPreviewSize(cameraResolution.x, cameraResolution.y);
|
||||
camera.setParameters(parameters);
|
||||
|
||||
Camera.Parameters afterParameters = camera.getParameters();
|
||||
Camera.Size afterSize = afterParameters.getPreviewSize();
|
||||
if (afterSize != null && (cameraResolution.x != afterSize.width || cameraResolution.y != afterSize.height)) {
|
||||
Log.w(TAG, "Camera said it supported preview size " + cameraResolution.x + 'x' + cameraResolution.y + ", but after setting it, preview size is " + afterSize.width + 'x' + afterSize.height);
|
||||
cameraResolution.x = afterSize.width;
|
||||
cameraResolution.y = afterSize.height;
|
||||
}
|
||||
|
||||
/** 设置相机预览为竖屏 */
|
||||
String model=android.os.Build.MODEL;
|
||||
if("Nexus 5X".equals(model)){
|
||||
camera.setDisplayOrientation(270);
|
||||
}else{
|
||||
camera.setDisplayOrientation(90);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Point getCameraResolution() {
|
||||
return cameraResolution;
|
||||
}
|
||||
|
||||
public Point getScreenResolution() {
|
||||
return screenResolution;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从相机支持的分辨率中计算出最适合的预览界面尺寸
|
||||
*
|
||||
* @param parameters
|
||||
* @param screenResolution
|
||||
* @return
|
||||
*/
|
||||
private Point findBestPreviewSizeValue(Camera.Parameters parameters, Point screenResolution) {
|
||||
List<Camera.Size> rawSupportedSizes = parameters.getSupportedPreviewSizes();
|
||||
if (rawSupportedSizes == null) {
|
||||
Log.w(TAG, "Device returned no supported preview sizes; using default");
|
||||
Camera.Size defaultSize = parameters.getPreviewSize();
|
||||
return new Point(defaultSize.width, defaultSize.height);
|
||||
}
|
||||
|
||||
// Sort by size, descending
|
||||
List<Camera.Size> supportedPreviewSizes = new ArrayList<Camera.Size>(rawSupportedSizes);
|
||||
Collections.sort(supportedPreviewSizes, new Comparator<Camera.Size>() {
|
||||
@Override
|
||||
public int compare(Camera.Size a, Camera.Size b) {
|
||||
int aPixels = a.height * a.width;
|
||||
int bPixels = b.height * b.width;
|
||||
if (bPixels < aPixels) {
|
||||
return -1;
|
||||
}
|
||||
if (bPixels > aPixels) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
|
||||
if (Log.isLoggable(TAG, Log.INFO)) {
|
||||
StringBuilder previewSizesString = new StringBuilder();
|
||||
for (Camera.Size supportedPreviewSize : supportedPreviewSizes) {
|
||||
previewSizesString.append(supportedPreviewSize.width).append('x').append(supportedPreviewSize.height).append(' ');
|
||||
}
|
||||
Log.i(TAG, "Supported preview sizes: " + previewSizesString);
|
||||
}
|
||||
|
||||
double screenAspectRatio = (double) screenResolution.x / (double) screenResolution.y;
|
||||
|
||||
// Remove sizes that are unsuitable
|
||||
Iterator<Camera.Size> it = supportedPreviewSizes.iterator();
|
||||
while (it.hasNext()) {
|
||||
Camera.Size supportedPreviewSize = it.next();
|
||||
int realWidth = supportedPreviewSize.width;
|
||||
int realHeight = supportedPreviewSize.height;
|
||||
if (realWidth * realHeight < MIN_PREVIEW_PIXELS) {
|
||||
it.remove();
|
||||
continue;
|
||||
}
|
||||
|
||||
boolean isCandidatePortrait = realWidth < realHeight;
|
||||
int maybeFlippedWidth = isCandidatePortrait ? realHeight : realWidth;
|
||||
int maybeFlippedHeight = isCandidatePortrait ? realWidth : realHeight;
|
||||
|
||||
double aspectRatio = (double) maybeFlippedWidth / (double) maybeFlippedHeight;
|
||||
double distortion = Math.abs(aspectRatio - screenAspectRatio);
|
||||
if (distortion > MAX_ASPECT_DISTORTION) {
|
||||
it.remove();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (maybeFlippedWidth == screenResolution.x && maybeFlippedHeight == screenResolution.y) {
|
||||
Point exactPoint = new Point(realWidth, realHeight);
|
||||
Log.i(TAG, "Found preview size exactly matching screen size: " + exactPoint);
|
||||
return exactPoint;
|
||||
}
|
||||
}
|
||||
|
||||
// If no exact match, use largest preview size. This was not a great
|
||||
// idea on older devices because
|
||||
// of the additional computation needed. We're likely to get here on
|
||||
// newer Android 4+ devices, where
|
||||
// the CPU is much more powerful.
|
||||
if (!supportedPreviewSizes.isEmpty()) {
|
||||
Camera.Size largestPreview = supportedPreviewSizes.get(0);
|
||||
Point largestSize = new Point(largestPreview.width, largestPreview.height);
|
||||
Log.i(TAG, "Using largest suitable preview size: " + largestSize);
|
||||
return largestSize;
|
||||
}
|
||||
|
||||
// If there is nothing at all suitable, return current preview size
|
||||
Camera.Size defaultPreview = parameters.getPreviewSize();
|
||||
Point defaultSize = new Point(defaultPreview.width, defaultPreview.height);
|
||||
Log.i(TAG, "No suitable preview sizes, using default: " + defaultSize);
|
||||
|
||||
return defaultSize;
|
||||
}
|
||||
}
|
@ -1,209 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2008 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package zxing.camera;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import zxing.camera.open.OpenCameraInterface;
|
||||
import android.content.Context;
|
||||
import android.graphics.Point;
|
||||
import android.hardware.Camera;
|
||||
import android.hardware.Camera.Size;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
import android.view.SurfaceHolder;
|
||||
|
||||
|
||||
/**
|
||||
* This object wraps the Camera service object and expects to be the only one
|
||||
* talking to it. The implementation encapsulates the steps needed to take
|
||||
* preview-sized images, which are used for both preview and decoding.
|
||||
*
|
||||
* @author dswitkin@google.com (Daniel Switkin)
|
||||
*/
|
||||
public class CameraManager {
|
||||
|
||||
private static final String TAG = CameraManager.class.getSimpleName();
|
||||
|
||||
private final Context context;
|
||||
private final CameraConfigurationManager configManager;
|
||||
private Camera camera;
|
||||
private AutoFocusManager autoFocusManager;
|
||||
|
||||
private boolean initialized;
|
||||
private boolean previewing;
|
||||
private int requestedCameraId = -1;
|
||||
/**
|
||||
* Preview frames are delivered here, which we pass on to the registered
|
||||
* handler. Make sure to clear the handler so it will only receive one
|
||||
* message.
|
||||
*/
|
||||
private final PreviewCallback previewCallback;
|
||||
|
||||
public CameraManager(Context context) {
|
||||
this.context = context;
|
||||
this.configManager = new CameraConfigurationManager(context);
|
||||
previewCallback = new PreviewCallback(configManager);
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the camera driver and initializes the hardware parameters.
|
||||
*
|
||||
* @param holder
|
||||
* The surface object which the camera will draw preview frames
|
||||
* into.
|
||||
* @throws IOException
|
||||
* Indicates the camera driver failed to open.
|
||||
*/
|
||||
public synchronized void openDriver(SurfaceHolder holder) throws IOException {
|
||||
Camera theCamera = camera;
|
||||
if (theCamera == null) {
|
||||
|
||||
if (requestedCameraId >= 0) {
|
||||
theCamera = OpenCameraInterface.open(requestedCameraId);
|
||||
} else {
|
||||
theCamera = OpenCameraInterface.open();
|
||||
}
|
||||
|
||||
if (theCamera == null) {
|
||||
throw new IOException();
|
||||
}
|
||||
camera = theCamera;
|
||||
}
|
||||
theCamera.setPreviewDisplay(holder);
|
||||
|
||||
if (!initialized) {
|
||||
initialized = true;
|
||||
configManager.initFromCameraParameters(theCamera);
|
||||
}
|
||||
|
||||
Camera.Parameters parameters = theCamera.getParameters();
|
||||
String parametersFlattened = parameters == null ? null : parameters.flatten(); // Save
|
||||
// these,
|
||||
// temporarily
|
||||
try {
|
||||
configManager.setDesiredCameraParameters(theCamera, false);
|
||||
} catch (RuntimeException re) {
|
||||
// Driver failed
|
||||
Log.w(TAG, "Camera rejected parameters. Setting only minimal safe-mode parameters");
|
||||
Log.i(TAG, "Resetting to saved camera params: " + parametersFlattened);
|
||||
// Reset:
|
||||
if (parametersFlattened != null) {
|
||||
parameters = theCamera.getParameters();
|
||||
parameters.unflatten(parametersFlattened);
|
||||
try {
|
||||
theCamera.setParameters(parameters);
|
||||
configManager.setDesiredCameraParameters(theCamera, true);
|
||||
} catch (RuntimeException re2) {
|
||||
// Well, darn. Give up
|
||||
Log.w(TAG, "Camera rejected even safe-mode parameters! No configuration");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public synchronized boolean isOpen() {
|
||||
return camera != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the camera driver if still in use.
|
||||
*/
|
||||
public synchronized void closeDriver() {
|
||||
if (camera != null) {
|
||||
camera.release();
|
||||
camera = null;
|
||||
// Make sure to clear these each time we close the camera, so that
|
||||
// any scanning rect
|
||||
// requested by intent is forgotten.
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Asks the camera hardware to begin drawing preview frames to the screen.
|
||||
*/
|
||||
public synchronized void startPreview() {
|
||||
Camera theCamera = camera;
|
||||
if (theCamera != null && !previewing) {
|
||||
theCamera.startPreview();
|
||||
previewing = true;
|
||||
autoFocusManager = new AutoFocusManager(context, camera);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells the camera to stop drawing preview frames.
|
||||
*/
|
||||
public synchronized void stopPreview() {
|
||||
if (autoFocusManager != null) {
|
||||
autoFocusManager.stop();
|
||||
autoFocusManager = null;
|
||||
}
|
||||
if (camera != null && previewing) {
|
||||
camera.stopPreview();
|
||||
previewCallback.setHandler(null, 0);
|
||||
previewing = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A single preview frame will be returned to the handler supplied. The data
|
||||
* will arrive as byte[] in the message.obj field, with width and height
|
||||
* encoded as message.arg1 and message.arg2, respectively.
|
||||
*
|
||||
* @param handler
|
||||
* The handler to send the message to.
|
||||
* @param message
|
||||
* The what field of the message to be sent.
|
||||
*/
|
||||
public synchronized void requestPreviewFrame(Handler handler, int message) {
|
||||
Camera theCamera = camera;
|
||||
if (theCamera != null && previewing) {
|
||||
previewCallback.setHandler(handler, message);
|
||||
theCamera.setOneShotPreviewCallback(previewCallback);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows third party apps to specify the camera ID, rather than determine
|
||||
* it automatically based on available cameras and their orientation.
|
||||
*
|
||||
* @param cameraId
|
||||
* camera ID of the camera to use. A negative value means
|
||||
* "no preference".
|
||||
*/
|
||||
public synchronized void setManualCameraId(int cameraId) {
|
||||
requestedCameraId = cameraId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取相机分辨率
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Point getCameraResolution() {
|
||||
return configManager.getCameraResolution();
|
||||
}
|
||||
|
||||
public Size getPreviewSize() {
|
||||
if (null != camera) {
|
||||
return camera.getParameters().getPreviewSize();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2010 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package zxing.camera;
|
||||
|
||||
import android.graphics.Point;
|
||||
import android.hardware.Camera;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.util.Log;
|
||||
|
||||
public class PreviewCallback implements Camera.PreviewCallback {
|
||||
|
||||
private static final String TAG = PreviewCallback.class.getSimpleName();
|
||||
|
||||
private final CameraConfigurationManager configManager;
|
||||
private Handler previewHandler;
|
||||
private int previewMessage;
|
||||
|
||||
public PreviewCallback(CameraConfigurationManager configManager) {
|
||||
this.configManager = configManager;
|
||||
}
|
||||
|
||||
public void setHandler(Handler previewHandler, int previewMessage) {
|
||||
this.previewHandler = previewHandler;
|
||||
this.previewMessage = previewMessage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPreviewFrame(byte[] data, Camera camera) {
|
||||
Point cameraResolution = configManager.getCameraResolution();
|
||||
Handler thePreviewHandler = previewHandler;
|
||||
if (cameraResolution != null && thePreviewHandler != null) {
|
||||
Message message = thePreviewHandler.obtainMessage(previewMessage, cameraResolution.x, cameraResolution.y,
|
||||
data);
|
||||
message.sendToTarget();
|
||||
previewHandler = null;
|
||||
} else {
|
||||
Log.d(TAG, "Got preview callback, but no handler or resolution available");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,86 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2012 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package zxing.camera.open;
|
||||
|
||||
import android.hardware.Camera;
|
||||
import android.util.Log;
|
||||
|
||||
public class OpenCameraInterface {
|
||||
|
||||
private static final String TAG = OpenCameraInterface.class.getName();
|
||||
|
||||
/**
|
||||
* Opens the requested camera with {@link Camera#open(int)}, if one exists.
|
||||
*
|
||||
* @param cameraId
|
||||
* camera ID of the camera to use. A negative value means
|
||||
* "no preference"
|
||||
* @return handle to {@link Camera} that was opened
|
||||
*/
|
||||
public static Camera open(int cameraId) {
|
||||
|
||||
int numCameras = Camera.getNumberOfCameras();
|
||||
if (numCameras == 0) {
|
||||
Log.w(TAG, "No cameras!");
|
||||
return null;
|
||||
}
|
||||
|
||||
boolean explicitRequest = cameraId >= 0;
|
||||
|
||||
if (!explicitRequest) {
|
||||
// Select a camera if no explicit camera requested
|
||||
int index = 0;
|
||||
while (index < numCameras) {
|
||||
Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
|
||||
Camera.getCameraInfo(index, cameraInfo);
|
||||
if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK) {
|
||||
break;
|
||||
}
|
||||
index++;
|
||||
}
|
||||
|
||||
cameraId = index;
|
||||
}
|
||||
|
||||
Camera camera;
|
||||
if (cameraId < numCameras) {
|
||||
Log.i(TAG, "Opening camera #" + cameraId);
|
||||
camera = Camera.open(cameraId);
|
||||
} else {
|
||||
if (explicitRequest) {
|
||||
Log.w(TAG, "Requested camera does not exist: " + cameraId);
|
||||
camera = null;
|
||||
} else {
|
||||
Log.i(TAG, "No camera facing back; returning camera #0");
|
||||
camera = Camera.open(0);
|
||||
}
|
||||
}
|
||||
|
||||
return camera;
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens a rear-facing camera with {@link Camera#open(int)}, if one exists,
|
||||
* or opens camera 0.
|
||||
*
|
||||
* @return handle to {@link Camera} that was opened
|
||||
*/
|
||||
public static Camera open() {
|
||||
return open(-1);
|
||||
}
|
||||
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2010 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package zxing.decoding;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
|
||||
public class DecodeFormatManager {
|
||||
|
||||
// 1D解码
|
||||
private static final Set<BarcodeFormat> PRODUCT_FORMATS;
|
||||
private static final Set<BarcodeFormat> INDUSTRIAL_FORMATS;
|
||||
private static final Set<BarcodeFormat> ONE_D_FORMATS;
|
||||
|
||||
// 二维码解码
|
||||
private static final Set<BarcodeFormat> QR_CODE_FORMATS;
|
||||
|
||||
static {
|
||||
PRODUCT_FORMATS = EnumSet.of(BarcodeFormat.UPC_A, BarcodeFormat.UPC_E, BarcodeFormat.EAN_13, BarcodeFormat.EAN_8, BarcodeFormat.RSS_14, BarcodeFormat.RSS_EXPANDED);
|
||||
INDUSTRIAL_FORMATS = EnumSet.of(BarcodeFormat.CODE_39, BarcodeFormat.CODE_93, BarcodeFormat.CODE_128, BarcodeFormat.ITF, BarcodeFormat.CODABAR);
|
||||
ONE_D_FORMATS = EnumSet.copyOf(PRODUCT_FORMATS);
|
||||
ONE_D_FORMATS.addAll(INDUSTRIAL_FORMATS);
|
||||
|
||||
QR_CODE_FORMATS = EnumSet.of(BarcodeFormat.QR_CODE);
|
||||
}
|
||||
|
||||
public static Collection<BarcodeFormat> getQrCodeFormats() {
|
||||
return QR_CODE_FORMATS;
|
||||
}
|
||||
|
||||
public static Collection<BarcodeFormat> getBarCodeFormats() {
|
||||
return ONE_D_FORMATS;
|
||||
}
|
||||
}
|
@ -1,98 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2008 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package zxing.decoding;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.EnumMap;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import zxing.CaptureActivity;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.DecodeHintType;
|
||||
|
||||
/**
|
||||
* This thread does all the heavy lifting of decoding the images.
|
||||
*
|
||||
* @author dswitkin@google.com (Daniel Switkin)
|
||||
*/
|
||||
public class DecodeThread extends Thread {
|
||||
|
||||
public static final String BARCODE_BITMAP = "barcode_bitmap";
|
||||
|
||||
public static final int BARCODE_MODE = 0X100;
|
||||
public static final int QRCODE_MODE = 0X200;
|
||||
public static final int ALL_MODE = 0X300;
|
||||
|
||||
private final CaptureActivity activity;
|
||||
private final Map<DecodeHintType, Object> hints;
|
||||
private Handler handler;
|
||||
private final CountDownLatch handlerInitLatch;
|
||||
|
||||
public DecodeThread(CaptureActivity activity, int decodeMode) {
|
||||
|
||||
this.activity = activity;
|
||||
handlerInitLatch = new CountDownLatch(1);
|
||||
|
||||
hints = new EnumMap<DecodeHintType, Object>(DecodeHintType.class);
|
||||
|
||||
Collection<BarcodeFormat> decodeFormats = new ArrayList<BarcodeFormat>();
|
||||
decodeFormats.addAll(EnumSet.of(BarcodeFormat.AZTEC));
|
||||
decodeFormats.addAll(EnumSet.of(BarcodeFormat.PDF_417));
|
||||
|
||||
switch (decodeMode) {
|
||||
case BARCODE_MODE:
|
||||
decodeFormats.addAll(DecodeFormatManager.getBarCodeFormats());
|
||||
break;
|
||||
|
||||
case QRCODE_MODE:
|
||||
decodeFormats.addAll(DecodeFormatManager.getQrCodeFormats());
|
||||
break;
|
||||
|
||||
case ALL_MODE:
|
||||
decodeFormats.addAll(DecodeFormatManager.getBarCodeFormats());
|
||||
decodeFormats.addAll(DecodeFormatManager.getQrCodeFormats());
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
hints.put(DecodeHintType.POSSIBLE_FORMATS, decodeFormats);
|
||||
}
|
||||
|
||||
public Handler getHandler() {
|
||||
try {
|
||||
handlerInitLatch.await();
|
||||
} catch (InterruptedException ie) {
|
||||
// continue?
|
||||
}
|
||||
return handler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Looper.prepare();
|
||||
handler = new DecodeHandler(activity, hints);
|
||||
handlerInitLatch.countDown();
|
||||
Looper.loop();
|
||||
}
|
||||
|
||||
}
|
@ -1,112 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2008 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package zxing.utils;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
|
||||
import com.gizwits.opensource.appkit.R;
|
||||
import com.google.zxing.Result;
|
||||
|
||||
import zxing.CaptureActivity;
|
||||
import zxing.camera.CameraManager;
|
||||
import zxing.decoding.DecodeThread;
|
||||
|
||||
|
||||
/**
|
||||
* This class handles all the messaging which comprises the state machine for
|
||||
* capture.
|
||||
*
|
||||
* @author dswitkin@google.com (Daniel Switkin)
|
||||
*/
|
||||
public class CaptureActivityHandler extends Handler {
|
||||
|
||||
private final CaptureActivity activity;
|
||||
private final DecodeThread decodeThread;
|
||||
private final CameraManager cameraManager;
|
||||
private State state;
|
||||
|
||||
private enum State {
|
||||
PREVIEW, SUCCESS, DONE
|
||||
}
|
||||
|
||||
public CaptureActivityHandler(CaptureActivity activity, CameraManager cameraManager, int decodeMode) {
|
||||
this.activity = activity;
|
||||
decodeThread = new DecodeThread(activity, decodeMode);
|
||||
decodeThread.start();
|
||||
state = State.SUCCESS;
|
||||
|
||||
// Start ourselves capturing previews and decoding.
|
||||
this.cameraManager = cameraManager;
|
||||
cameraManager.startPreview();
|
||||
restartPreviewAndDecode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMessage(Message message) {
|
||||
switch (message.what) {
|
||||
case R.id.restart_preview:
|
||||
restartPreviewAndDecode();
|
||||
break;
|
||||
case R.id.decode_succeeded:
|
||||
state = State.SUCCESS;
|
||||
Bundle bundle = message.getData();
|
||||
|
||||
activity.handleDecode((Result) message.obj, bundle);
|
||||
break;
|
||||
case R.id.decode_failed:
|
||||
// We're decoding as fast as possible, so when one decode fails,
|
||||
// start another.
|
||||
state = State.PREVIEW;
|
||||
cameraManager.requestPreviewFrame(decodeThread.getHandler(), R.id.decode);
|
||||
break;
|
||||
case R.id.return_scan_result:
|
||||
activity.setResult(Activity.RESULT_OK, (Intent) message.obj);
|
||||
activity.finish();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void quitSynchronously() {
|
||||
state = State.DONE;
|
||||
cameraManager.stopPreview();
|
||||
Message quit = Message.obtain(decodeThread.getHandler(), R.id.quit);
|
||||
quit.sendToTarget();
|
||||
try {
|
||||
// Wait at most half a second; should be enough time, and onPause()
|
||||
// will timeout quickly
|
||||
decodeThread.join(500L);
|
||||
} catch (InterruptedException e) {
|
||||
// continue
|
||||
}
|
||||
|
||||
// Be absolutely sure we don't send any queued up messages
|
||||
removeMessages(R.id.decode_succeeded);
|
||||
removeMessages(R.id.decode_failed);
|
||||
}
|
||||
|
||||
private void restartPreviewAndDecode() {
|
||||
if (state == State.SUCCESS) {
|
||||
state = State.PREVIEW;
|
||||
cameraManager.requestPreviewFrame(decodeThread.getHandler(), R.id.decode);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue