修改eclipse项目为as项目

This commit is contained in:
2020-11-10 01:45:14 +08:00
commit b2c8455a6c
217 changed files with 25818 additions and 0 deletions

View File

@ -0,0 +1,37 @@
package com.util;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
public class BitMapUtil {
public static Bitmap generateBitMap(String url) throws IOException {
URL myFileUrl = null;
Bitmap bitmap = null;
myFileUrl = new URL(url);
HttpURLConnection conn = (HttpURLConnection) myFileUrl.openConnection();
conn.setDoInput(true);
conn.connect();
InputStream is = conn.getInputStream();
bitmap = BitmapFactory.decodeStream(is);
is.close();
conn.disconnect();
return bitmap;
}
public static Bitmap byteToBitmap(byte[] b){
if(b==null){
return null;
}
int len=b.length;
if(len!=0){
return BitmapFactory.decodeByteArray(b, 0,len);
}else{
return null;
}
}
}

View File

@ -0,0 +1,61 @@
package com.util;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class DateUtil {
/*
* 得到当前日期
*/
public static String getDate() {
Date now = new Date();
// Calendar cal = Calendar.getInstance();
// DateFormat d1 = DateFormat.getDateInstance(); //默认语言汉语下的默认风格MEDIUM风格比如2008-6-16 20:54:53
SimpleDateFormat dateFormat = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss");
return dateFormat.format(now);
}
public static Date getDate(String s) throws ParseException {
SimpleDateFormat dateformat2=new SimpleDateFormat("yyyy-MM-dd");
return dateformat2.parse(s);
}
/*
* 得到当前日期
*/
public static String getDate1() {
Date now = new Date();
SimpleDateFormat dateformat2=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return dateformat2.format(now);
}
/*
* 得到当前时间
*/
public static String getTime() {
Date now = new Date();
Calendar cal = Calendar.getInstance();
DateFormat d3 = DateFormat.getTimeInstance();
return d3.format(now);
}
/*
* 得到当前日期和时间
*/
public static String getDateAndTime() {
Date now = new Date();
Calendar cal = Calendar.getInstance();
DateFormat d1 = DateFormat.getDateTimeInstance(); //默认语言汉语下的默认风格MEDIUM风格比如2008-6-16 20:54:53
return d1.format(now);
}
// 天数相加减
public static Date getDate(Date date, int amount) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.DATE, amount);
return calendar.getTime();
}
public static void main(String[] args) {
System.out.println(DateUtil.getDateAndTime()+"---"+DateUtil.getTime());
}
}

View File

@ -0,0 +1,84 @@
package com.util;
import com.chaoran.entiry.SelfEditText;
import com.example.chaoran.DjActivity;
import com.example.chaoran.MainActivity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.style.AbsoluteSizeSpan;
import android.util.Log;
import android.widget.ListView;
import android.widget.RelativeLayout;
public class DialogUtil {
// 错误消息对话框
public static void builder(final Context context, String title, String message,
int fontSize) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
SpannableStringBuilder ssBuilser = new SpannableStringBuilder(message);
builder.setTitle(title);
if (fontSize > 0) {
AbsoluteSizeSpan span = new AbsoluteSizeSpan(fontSize);
ssBuilser.setSpan(span, 0, message.length(),
Spannable.SPAN_INCLUSIVE_INCLUSIVE);
builder.setMessage(ssBuilser);
} else {
builder.setMessage(message);
}
builder.setPositiveButton("确定", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
if (DjActivity.cr5wScanControl != null && "DjActivity".equals(context.getClass().getSimpleName())) {
DjActivity.cr5wScanControl.setIsOpen(true);
DjActivity.cr5wScanControl.start(context);
} else if (DjActivity.nr510ScanControl != null && "DjActivity".equals(context.getClass().getSimpleName())) {
DjActivity.nr510ScanControl.start(context);
} else if (DjActivity.barcodeReader != null && "DjActivity".equals(context.getClass().getSimpleName())) {
try {
// DjActivity.triggerState = true;
DjActivity.barcodeReader.light(true); //turn on/off backlight
DjActivity.barcodeReader.aim(true); //开关瞄准线
DjActivity.barcodeReader.decode(true); //开关解码功能
} catch (Exception ex) {
ex.printStackTrace();
}
}
if (DjActivity.m_view != null) {
if (DjActivity.m_view instanceof SelfEditText) {
((SelfEditText)DjActivity.m_view).selectAll();
}
DjActivity.m_view = null;
}
}
});
builder.create();
builder.show();
if (DjActivity.cr5wScanControl != null && "DjActivity".equals(context.getClass().getSimpleName()))
DjActivity.cr5wScanControl.setIsOpen(false);
}
public static void builderCancel(Context context, String title,
String message, OnClickListener okListener) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(title);
builder.setMessage(message);
builder.setPositiveButton("确定", okListener);
builder.setNegativeButton("取消", null);
builder.create();
builder.show();
}
public static void setDialog(ProgressDialog pd, String title, String message) {
pd.setTitle(title);
pd.setMessage(message);
pd.show();
}
}

View File

@ -0,0 +1,185 @@
package com.util;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Map;
import java.text.DateFormat;
import map.baidu.com.BDMapActivity;
import org.kobjects.base64.Base64;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.view.View;
import com.chaoran.imp.InputInterface;
import com.example.chaoran.DjActivity;
import com.example.chaoran.ExitThread;
import com.example.chaoran.MipcaActivityCapture;
import com.example.chaoran.NetWorkSet;
import com.example.chaoran.RunYmupThread;
import com.sys.SysData;
public class DjMenuFun {
public void Msave_dj(final DjActivity djActivity) throws Exception {
// if(djActivity.pd.isShowing()){
// return;
// }
new AlertDialog.Builder(djActivity).setTitle("确定取消框")
.setMessage("确定保存单据")
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Map map = new HashMap();
Object ob=DjUtil.saveOrganizationHzData(djActivity.hzTab,djActivity.pageMap.get("GZID"));
Map hzData=null;
if(ob instanceof Map){
hzData=(Map)ob;
}else{
View view=(View)ob;
if(view.isEnabled()){
((View)ob).requestFocus();
}
DialogUtil.builder(djActivity, "错误信息", ((InputInterface)ob).getLabel().concat("不能为空"),0);
djActivity.pd.dismiss();
return;
}
// Map hzData = DjUtil.organizationHzData(djActivity.layout);
((HashMap)hzData.get("hzData")).putAll(djActivity.pageMap);
map.put("hzData", hzData);
// if (djActivity.mxData.size() > 0) {
// map.put("mxSql", djActivity.mxSql);
// map.put("mxData", DjUtil.organizationMxData(djActivity.mxData,
// djActivity.pageMap.get("GZID")));
// } else {
// map.put("mxSql", "");
// map.put("mxData", null);
// }
map.put("gzid", djActivity.pageMap.get("GZID"));
map.put("mxTempTable", djActivity.mxTempTable);
map.put("djlx", djActivity.pageMap.get("DJLX"));
map.put("djbs", djActivity.pageMap.get("DJBS"));
byte[] b;
try {
b = IoUtil.getbyte(map);
String paramString = Base64.encode(b);
DialogUtil.setDialog(djActivity.pd, "消息提示", "单据保存……");
new RunYmupThread(paramString, djActivity.runHandler, "saveDj",0).start();
} catch (Exception e) {
DialogUtil.setDialog(djActivity.pd, "消息提示", "参数转换成流失败……");
}
}
})
.setNegativeButton("取消", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
}).show();
}
public void Mdj_over(final DjActivity djActivity) {
new AlertDialog.Builder(djActivity).setTitle("确定取消框").setMessage("确定退出")
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
exitDj(djActivity);
}})
.setNegativeButton("取消", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
}).show();
}
public void exitDj(DjActivity djActivity){
DialogUtil.setDialog(djActivity.pd, "消息提示", "单据退出……");
new ExitThread(djActivity.pageMap.get("GZID"), djActivity.mxTempTable,
djActivity.runHandler,"exitDj").start();
}
public String getusername(DjActivity djActivity) {
return SysData.lgnname;
}
public String getjigid(DjActivity djActivity) {
return SysData.jigid;
}
public String getclientid(DjActivity djActivity) {
return SysData.clientid.replaceAll(":", "");
}
public String getdate(DjActivity djActivity) throws ParseException {
SimpleDateFormat dateFormat = new SimpleDateFormat(
"yyyy-MM-dd");
Date date1 = dateFormat.parse(djActivity.pageMap.get("RQ"));
// java.text.DateFormat d3 = DateFormat.getDateInstance();
return dateFormat.format(date1);
}
public String getdatetime(DjActivity djActivity) {
return djActivity.pageMap.get("RQ");
}
/*
* -取得当前月份
*/
public int getmonth(DjActivity djActivity) throws ParseException {
SimpleDateFormat dateFormat = new SimpleDateFormat(
"yyyy-MM-dd kk:mm:ss");
Date date1 = dateFormat.parse(djActivity.pageMap.get("RQ"));
Calendar calendar = GregorianCalendar.getInstance();
calendar.setTime(date1);
return calendar.get(Calendar.MONTH) + 1;
}
/*
* -取得当前年份
*/
public int getyear(DjActivity djActivity) throws ParseException {
SimpleDateFormat dateFormat = new SimpleDateFormat(
"yyyy-MM-dd kk:mm:ss");
Date date1 = dateFormat.parse(djActivity.pageMap.get("RQ"));
Calendar calendar = GregorianCalendar.getInstance();
calendar.setTime(date1);
return calendar.get(Calendar.YEAR);
}
/*
* -取得当前天数
*/
public int getday(DjActivity djActivity) throws ParseException {
SimpleDateFormat dateFormat = new SimpleDateFormat(
"yyyy-MM-dd kk:mm:ss");
Date date1 = dateFormat.parse(djActivity.pageMap.get("RQ"));
Calendar calendar = GregorianCalendar.getInstance();
calendar.setTime(date1);
return calendar.get(Calendar.DATE);
}
/*
* 定位当前位置
*/
public void Mlocation(DjActivity djActivity){
Intent intent = new Intent();
intent.setClass(djActivity,BDMapActivity.class);
djActivity.startActivityForResult(intent,3);
}
/*
* 调用摄像头扫描条码
*/
public void scan(DjActivity djActivity,String funName){
String uiId=funName.substring(5, funName.length()-1);
Intent intent = new Intent();
intent.setClass(djActivity,MipcaActivityCapture.class);
intent.putExtra("uiId", uiId);
djActivity.startActivityForResult(intent,4);
}
public static void main(String[] args) {
String funName="scan(ckname)";
String uiId=funName.substring(5, funName.length()-6);
System.out.println(funName+"----"+uiId);
}
}

View File

@ -0,0 +1,391 @@
package com.util;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.chaoran.entiry.PhotographUi;
import com.chaoran.entiry.SelfCheckBox;
import com.chaoran.entiry.SelfEditText;
import com.chaoran.entiry.SelfImage;
import com.chaoran.entiry.SelfTextBut;
import com.chaoran.imp.InputInterface;
import com.chaoran.thread.ImageUrl;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.os.Handler;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TabHost;
import android.widget.TextView;
/*
* 单据工具类
*/
public class DjUtil {
public static void setUiValue(TabHost layout, Map map, Map pageMap,
Handler imgHandler) {
Set<String> set = map.keySet();
View view = null;
String name = null;
Object value = null;
int fcolor = -1;
int bcolor = -1;
if (map.containsKey("__FCOLOR")) {
String __fcolor = map.get("__FCOLOR").toString().trim();
if (__fcolor.length() > 0) {
fcolor = Integer.decode(__fcolor);
}
}
if (map.containsKey("__BCOLOR")) {
String __bcolor = map.get("__BCOLOR").toString().trim();
if (__bcolor.length() > 0) {
bcolor = Integer.decode(__bcolor);
}
}
for (String s : set) {
name = s.toUpperCase().trim();
value = map.get(s).toString().trim();
view = layout.findViewWithTag(name);
if (view != null) {
setText(view, value, imgHandler, fcolor, bcolor);
} else if (pageMap.containsKey(name)) {
if (!pageMap.get(name).equals(value)) {
pageMap.put(name, value);
}
}
}
}
private static void setText(View view, Object value, Handler imgHandler,
int fcolor, int bcolor) {
// if (view instanceof SelfEditText) {
// System.out.println(value+"=============");
// ((EditText) view).setText(value);
// }else if(view instanceof CheckBox){
// boolean b=false;
// if(value.trim().equals("是")){
// b=true;
// }
// ((CheckBox) view).setChecked(b);
// }else if(view instanceof SelfTextBut){
// ((SelfTextBut) view).setText(value);
// }
// System.out.println(view.toString()+"---"+value);
if (view instanceof InputInterface) {
InputInterface iiView = (InputInterface) view;
if (fcolor > -1) {
iiView.setTextColor(SysUtil.toColor(fcolor));
}
if (bcolor > -1) {
iiView.setBackgroundDrawable(SysUtil.GradientDrawable(SysUtil
.toColor(bcolor)));
}
if(value==null){
value="";
}
iiView.setText(value.toString());
if (iiView.getIsTextChange()) {
iiView.setIsTextChange(false);
}
} else if (view instanceof CheckBox) {
boolean b = false;
if (value.equals("")) {
b = true;
}
((CheckBox) view).setChecked(b);
} else if (view instanceof ImageView) {
// Bitmap bmp =(Bitmap)view.getDrawingCache();
SelfImage img = (SelfImage) view;
if (img.getBitmap() != null) {
img.getBitmap().recycle();
}
img.setBitmap(null);
String val=value.toString();
if (val.length() > 0) {
new Thread(new ImageUrl(img, val, imgHandler)).start();
}
}else if(view instanceof PhotographUi){
PhotographUi photo=(PhotographUi)view;
photo.setImageBitmap(BitMapUtil.byteToBitmap((byte[])value));
}
}
public static void setUiValue(TabHost layout, List list, Map pageMap,
Handler imgHandler) {
int len = list.size();
Map map = null;
String name = null;
Object value = null;
View view = null;
// Object ob = null;
int fcolor = -1;
int bcolor = -1;
for (int i = 0; i < len; i++) {
map = (Map) list.get(i);
name = map.get("fieldname").toString().trim();
value = map.get("fieldValue");
view = layout.findViewWithTag(name);
if (view != null) {
if (view instanceof InputInterface) {
if (map.containsKey("__FCOLOR")) {
String __fcolor = map.get("__FCOLOR").toString().trim();
if (__fcolor.length() > 0) {
fcolor = Integer.decode(__fcolor);
}
}
if (map.containsKey("__BCOLOR")) {
String __bcolor = map.get("__BCOLOR").toString().trim();
if (__bcolor.length() > 0) {
bcolor = Integer.decode(__bcolor);
}
}
}
setText(view, value, imgHandler, fcolor, bcolor);
} else if (pageMap.containsKey(name)) {
if (!pageMap.get(name).equals(value)) {
pageMap.put(name, value);
}
}
}
}
public static void setUiValue2(TabHost layout, Map map, Handler imgHandler) {
Set<String> set = map.keySet();
View view = null;
ArrayList list = new ArrayList();
for (String s : set) {
view = layout.findViewWithTag(s);
if (view != null) {
// if (view instanceof SelfEditText) {
// ((SelfEditText) view).setText(map.get(s).toString().trim());
// } else if (view instanceof TextView) {
// ((TextView) view).setText(map.get(s).toString().trim());
// }
setText(view, map.get(s).toString().trim(), imgHandler, -1, -1);
list.add(s);
}
}
for (int i = 0; i < list.size(); i++) {
map.remove(list.get(i));
}
}
public static Map organizationHzData(TabHost hzhost, String gzid) {
FrameLayout fl = hzhost.getTabContentView();
int count = fl.getChildCount();
MxTabHostContent layout = null;
// System.out.println(count + "------------------------总量");
Map<String, String> hzData = new HashMap<String, String>();
ArrayList pzImgList = null;
for (int i = 0; i < count; i++) {
layout = (MxTabHostContent) fl.getChildAt(i);
// System.out.println(layout+"=========");
int len = layout.getChildCount();
View view = null;
String value = null;
// System.out.println(len+"---------");
for (int j = 0; j < len; j++) {
view = layout.getChildAt(j);
if (view.getTag() == null) {
continue;
}
if (view instanceof PhotographUi) {
if (pzImgList == null) {
pzImgList = new ArrayList();
}
PhotographUi pu = (PhotographUi) view;
if (pu.getImageBitmap() != null) {
HashMap imgMap = new HashMap();
imgMap.put("photo",SysUtil.bitmapToByte(pu.getImageBitmap()));
imgMap.put("fieldname", pu.getTag().toString());
imgMap.put("gzid", gzid);
pzImgList.add(imgMap);
}
} else {
if (view instanceof InputInterface) {
InputInterface et = (InputInterface) view;
value = et.getText().toString();
if (value == null) {
value = "";
}
hzData.put(et.getTag().toString(), value.trim());
} else if (view instanceof SelfCheckBox) {
SelfCheckBox sfb = (SelfCheckBox) view;
boolean b = sfb.isChecked();
if (b) {
hzData.put(sfb.getTag().toString(), "");
} else {
hzData.put(sfb.getTag().toString(), "");
}
}
}
}
}
HashMap map = new HashMap();
map.put("hzData", hzData);
if (pzImgList != null) {
map.put("pzImgList", pzImgList);
}
return map;
}
/* 保存方案组织汇总数据 */
public static Object saveOrganizationHzData(TabHost hzhost,String gzid) {
FrameLayout fl = hzhost.getTabContentView();
int count = fl.getChildCount();
MxTabHostContent layout = null;
ArrayList pzImgList = null;
// System.out.println(count + "------------------------总量");
Map<String, String> hzData = new HashMap<String, String>();
for (int i = 0; i < count; i++) {
layout = (MxTabHostContent) fl.getChildAt(i);
int len = layout.getChildCount();
View view = null;
String value = null;
for (int j = 0; j < len; j++) {
view = layout.getChildAt(j);
if (view.getTag() == null) {
continue;
}
if (view instanceof PhotographUi) {
PhotographUi pu = (PhotographUi) view;
if (pu.getImageBitmap() != null) {
HashMap imgMap = new HashMap();
imgMap.put("photo",SysUtil.bitmapToByte(pu.getImageBitmap()));
imgMap.put("fieldname", pu.getTag().toString());
imgMap.put("gzid", gzid);
if (pzImgList == null) {
pzImgList = new ArrayList();
}
pzImgList.add(imgMap);
}
} else {
if (view instanceof InputInterface) {
InputInterface et = (InputInterface) view;
value = et.getText().toString();
if (et.getIsNull()) {
if (value == null || value.length() < 1) {
return et;
}
}
if (value == null) {
value = "";
}
hzData.put(et.getTag().toString(), value.trim());
} else if (view instanceof SelfCheckBox) {
SelfCheckBox sfb = (SelfCheckBox) view;
boolean b = sfb.isChecked();
if (b) {
hzData.put(sfb.getTag().toString(), "");
} else {
hzData.put(sfb.getTag().toString(), "");
}
}
}
}
}
HashMap map = new HashMap();
map.put("hzData", hzData);
if (pzImgList != null) {
map.put("pzImgList", pzImgList);
}
return map;
}
/* 组织明细数据插入sql */
public static String createMxSql(ArrayList mxFieldList, String mxTempTable) {
int len = mxFieldList.size();
if (len < 1) {
return null;
}
StringBuilder mxInsertSql = new StringBuilder();
StringBuilder fieldName = new StringBuilder("gzid,dj_sn,dj_sort");// 列名
StringBuilder paramName = new StringBuilder(":gzid,:dj_sn,:dj_sort");// 参数名
String fdname = null;
Map column = null;
for (int i = 0; i < len; i++) {
column = (Map) mxFieldList.get(i);
if (!fieldName.equals("")) {
fieldName.append(",");
paramName.append(",");
}
fdname = column.get("fdname").toString().trim();
fieldName.append(fdname);
paramName.append(":").append(fdname);
}
mxInsertSql.append("insert ").append(mxTempTable).append("(")
.append(fieldName).append(")").append("values(")
.append(paramName).append(")");
return mxInsertSql.toString();
}
/* 组织明细数据查询sql */
public static String createMxQuerySql(ArrayList mxFieldList,
String mxTempTable) {
int len = mxFieldList.size();
if (len < 1) {
return null;
}
StringBuilder mxInsertSql = new StringBuilder();
StringBuilder fieldName = new StringBuilder("gzid,dj_sn,dj_sort");// 列名
String fdname = null;
Map column = null;
for (int i = 0; i < len; i++) {
column = (Map) mxFieldList.get(i);
if (!fieldName.equals("")) {
fieldName.append(",");
}
fdname = column.get("fdname").toString().trim();
fieldName.append(fdname);
}
mxInsertSql.append("select ").append(fieldName).append(" from ")
.append(mxTempTable);
return mxInsertSql.toString();
}
/* 组织明细数据 */
public static ArrayList organizationMxData(List list, String gzid) {
ArrayList mxData = new ArrayList();
int len = list.size();
Map map = null;
for (int i = 0; i < len; i++) {
map = (Map) list.get(i);
map.put("gzid", gzid);
map.put("dj_sn", i + 1);
map.put("dj_sort", i + 1);
mxData.add(map);
}
return mxData;
}
public static void setFocus(TabHost layout, String focus) {
View view = layout.findViewWithTag(focus.toUpperCase().trim());
if (view != null) {
view.requestFocus();
}
}
public static void assembleFangA(HashMap map, ArrayList list) {
// if (list != null) {
int len = list.size();
HashMap tempObMap = null;
for (int i = 0; i < len; i++) {
tempObMap = (HashMap) list.get(i);
map.put(tempObMap.get("funName"), tempObMap);
}
// }
}
}

View File

@ -0,0 +1,591 @@
package com.util;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import com.chaoran.component.AntLine;
import com.chaoran.component.SelfHRule;
import com.chaoran.entiry.PhotographUi;
import com.chaoran.entiry.SelfButton;
import com.chaoran.entiry.SelfCheckBox;
import com.chaoran.entiry.SelfDateField;
import com.chaoran.entiry.SelfEditText;
import com.chaoran.entiry.SelfImage;
import com.chaoran.entiry.SelfTextBut;
import com.chaoran.entiry.UpdataInfo;
import com.chaoran.imp.InputInterface;
import com.chaoran.thread.ImageUrl;
import com.example.chaoran.DjActivity;
import com.sys.SysData;
import com.example.chaoran.R;
import android.app.Activity;
import android.graphics.Color;
import android.os.Build.VERSION;
import android.text.InputType;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
public class Dom4jUtil {
public static void testParseXMLData(InputStream in, DjActivity aa)
throws DocumentException {
// 产生一个解析器对象
SAXReader reader = new SAXReader();
// 将xml文档转换为Document的对象
Document document = reader.read(in);
// 获取文档的根元素
Element root = document.getRootElement();
Iterator i_pe = root.elementIterator();
MxTabHostContent layout;
int i = 0;
String title = null;
while (i_pe.hasNext()) {
Element e_pe = (Element) i_pe.next();
Iterator i_pe1 = e_pe.elementIterator();
if (!i_pe1.hasNext()) {
continue;
}
layout = new MxTabHostContent(aa);
layout.setFocusable(true);
layout.setFocusableInTouchMode(true);
if (e_pe.attributeValue("title") != null) {
title = e_pe.attributeValue("title").trim();
} else {
title = "汇总";
}
if (title.equals("")) {
title = "汇总";
}
aa.hzTab.addTab(aa.hzTab.newTabSpec("hzchild" + i)
.setIndicator(title).setContent(layout));
aa.hzTab.setCurrentTab(i);
i++;
while (i_pe1.hasNext()) {
Element e_pe1 = (Element) i_pe1.next();
String name = e_pe1.attributeValue("name");
name = name.substring(name.indexOf("::") + 2, name.length());
int w = (int) (Double.parseDouble(e_pe1
.elementText("width_attribute")));
int h = (int) (Double.parseDouble(e_pe1
.elementText("height_attribute")));
int x = (int) (Double.parseDouble(e_pe1
.elementText("x_attribute")));
int y = (int) (Double.parseDouble(e_pe1
.elementText("y_attribute")));
w = (int) (TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP, w, aa.getResources()
.getDisplayMetrics()) * SysData.t_scale);
h = (int) (TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP, h, aa.getResources()
.getDisplayMetrics()) * SysData.t_scale);
x = (int) (TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP, x, aa.getResources()
.getDisplayMetrics()) * SysData.t_scale);
y = (int) (TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP, y, aa.getResources()
.getDisplayMetrics()) * SysData.t_scale);
// int w = UnitConversionUtil.convertDIP2PX(Double
// .parseDouble(e_pe1.elementText("width_attribute")));
// int h = UnitConversionUtil.convertDIP2PX(Double
// .parseDouble(e_pe1.elementText("height_attribute")));
// int x = UnitConversionUtil.convertDIP2PX(Double
// .parseDouble(e_pe1.elementText("x_attribute")));
// int y = UnitConversionUtil.convertDIP2PX(Double
// .parseDouble(e_pe1.elementText("y_attribute")));
// System.out.println(h+"================"+name);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
w, h);
layoutParams.topMargin = y;
layoutParams.leftMargin = x;
if (name.equals("SelfButton")) {
if (isVisible(e_pe1)) {
continue;
}
SelfButton but = new SelfButton(aa);
if (SysData.t_scale < 1) {
but.setPadding((int) (but.getPaddingLeft() * SysData.t_scale * 0.2f), (int) (but.getPaddingTop() * SysData.t_scale * 0.2f),
(int) (but.getPaddingRight() * SysData.t_scale * 0.2f), (int) (but.getPaddingBottom() * SysData.t_scale * 0.2f));
}
// but.setFocusableInTouchMode(true);
but.setText(e_pe1.elementText("label_attribute"));
if (e_pe1.element("click_function") != null) {
but.setOnClickListener(aa.clickEvent);
but.clickFun = e_pe1.elementText("click_function")
.toString();
}
if (e_pe1.element("enterKey_attribute") != null) {
but.nextFocus = e_pe1.elementText("enterKey_attribute")
.toString().toUpperCase();
}
if (e_pe1.element("fontSize_style") != null) {
but.setTextSize(Float.parseFloat(e_pe1.elementText(
"fontSize_style").toString()) * SysData.t_scale);
}
if (e_pe1.element("key_value") != null) {
but.setTag(e_pe1.elementText("key_value").toString()
.trim().toUpperCase());
}
// but.setLayoutParams(new
// AbsoluteLayout.LayoutParams(w,h,x,y));
layout.addView(but, layoutParams);
} else if (name.equals("SelfLabel")) {
if (isVisible(e_pe1)) {
continue;
}
TextView tv = new TextView(aa);
// tv.setBackgroundColor(Color.GRAY);
tv.setGravity(Gravity.CENTER_VERTICAL);
if (e_pe1.element("fontSize_style") != null) {
tv.setTextSize(Float.parseFloat(e_pe1.elementText(
"fontSize_style").toString()) * SysData.t_scale);
}
tv.setText(e_pe1.elementText("text_attribute"));
// tv.setLayoutParams(new
// AbsoluteLayout.LayoutParams(w,h,x,y));
layout.addView(tv, layoutParams);
} else if (name.equals("SelfTextInput")) {
if (!isVisible_attribute(e_pe1, aa)) {
continue;
}
if (e_pe1.attributeValue("isDouble").equals("yes")) {
SelfTextBut stb = new SelfTextBut(aa);
if (e_pe1.element("doubleClick_function") != null) {
stb.setOnClickListener(aa.clickEvent);
stb.setClickFun(e_pe1
.elementText("doubleClick_function")
.toString().toUpperCase());
}
// setTextButAtt(stb, e_pe1, aa);
setTextButAtt((InputInterface) stb, e_pe1, aa);
layout.addView(stb, layoutParams);
} else {
SelfEditText et = new SelfEditText(aa);
if (e_pe1.element("borderStyle_style") != null) {
et.showBorder = e_pe1.elementText(
"borderStyle_style").toString();
}
et.setSingleLine(true);
setTextButAtt((InputInterface) et, e_pe1, aa);
layout.addView(et, layoutParams);
}
} else if (name.equals("SelfTextArea")) {
if (!isVisible_attribute(e_pe1, aa)) {
continue;
}
SelfEditText area = new SelfEditText(aa);
if (e_pe1.element("borderStyle_style") != null) {
area.showBorder = e_pe1
.elementText("borderStyle_style").toString();
}
// setEditTextAtt(area, e_pe1, aa);
setTextButAtt((InputInterface) area, e_pe1, aa);
area.setSingleLine(false);
// if(e_pe1.element("backgroundColor_style") !=
// null){//backgroundColor_style
// area.setBackgroundColor(SysUtil.toHex(e_pe1.elementText("backgroundColor_style")
// .toString()));
// }
// if(e_pe1.element("color_style") !=
// null){//backgroundColor_style
// area.setTextColor(SysUtil.toHex(e_pe1.elementText("color_style")
// .toString()));
// }
layout.addView(area, layoutParams);
} else if (name.equals("SelfCheckBox")) {
// if (isVisible(e_pe1)) {
// continue;
// }
if (!isVisible_attribute(e_pe1, aa)) {
continue;
}
SelfCheckBox box = new SelfCheckBox(aa);
if (SysData.t_scale < 1) {
box.setPadding((int)(box.getPaddingLeft() * SysData.t_scale * 0.2f), box.getPaddingTop(), box.getPaddingRight(), box.getPaddingBottom());
}
if (e_pe1.element("name_attribute") != null) {
box.setTag(e_pe1.elementText("name_attribute")
.toString().trim().toUpperCase());
}
if (e_pe1.element("label_attribute") != null) {
box.setText(e_pe1.elementText("label_attribute")
.toString());
}
if (e_pe1.element("fontSize_style") != null) {
box.setTextSize(Float.parseFloat(e_pe1.elementText(
"fontSize_style").toString()) * SysData.t_scale); //checkbox + 5会变大
}
if (e_pe1.element("enabled_attribute") != null) {
String enabled = e_pe1.elementText("enabled_attribute")
.toString();
box.setEnabled(Boolean.parseBoolean(enabled));
}
if (e_pe1.element("text_attribute") != null) {
String funName = e_pe1.elementText("text_attribute")
.toString().trim().toLowerCase();
if (dyhs(funName, aa).equals("")) {
box.setChecked(true);
}
}
layout.addView(box, layoutParams);
} else if (name.equals("SelfImage")) {
if (isVisible(e_pe1)) {
continue;
}
SelfImage imageView = new SelfImage(aa);
if (e_pe1.element("source_attribute") != null) {
String url = e_pe1.elementText("source_attribute")
.toString().trim();
if (url.substring(0, 7).equals("http://")) {
new Thread(new ImageUrl(imageView, url,
aa.imgHandler)).start();
} else if (url.indexOf(".") > 0) {
new Thread(new ImageUrl(imageView, SysData.url
.substring(0, SysData.url.lastIndexOf("/"))
.concat("/").concat(url), aa.imgHandler))
.start();
} else if (url.length() > 0) {
imageView.setTag(url.toUpperCase());
}
}
imageView.setOnClickListener(aa.imgClickEvent);
layout.addView(imageView, layoutParams);
} else if (name.equals("SelfHRule") || name.equals("SelfVRule")) {
if (isVisible(e_pe1)) {
continue;
}
SelfHRule hrule = new SelfHRule(aa);
if (e_pe1.element("strokeColor_style") != null) {
// System.out.println();
hrule.setColor(SysUtil.toHex(e_pe1.elementText(
"strokeColor_style").toString()));
}
layout.addView(hrule, layoutParams);
} else if (name.equals("AntLine")) {
if (isVisible(e_pe1)) {
continue;
}
AntLine al = new AntLine(aa);
if (e_pe1.element("lineColor_attribute") != null) {
al.setColor(SysUtil.toHex(e_pe1.elementText(
"lineColor_attribute").toString()));
}
if (e_pe1.element("lineThickness_attribute") != null) {
al.setSize(Integer.parseInt(e_pe1
.elementText("lineThickness_attribute")) * 2);
}
layout.addView(al, layoutParams);
} else if (name.equals("SelfDateField")) {
SelfDateField df = new SelfDateField(aa);
if (e_pe1.element("formatString_attribute") != null) {
df.formatString = e_pe1
.elementText("formatString_attribute")
.toString().trim().toLowerCase();
if (df.formatString.length() < 1) {
df.formatString = "yyyy-mm-dd";
}
df.formatString = df.formatString.replace("mm", "MM");
}
setTextButAtt((InputInterface) df, e_pe1, aa);
layout.addView(df, layoutParams);
} else if (name.equals("PhotographUi")) {
if (isVisible(e_pe1)) {
continue;
}
int hh = (int) (TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP, 36, aa.getResources()
.getDisplayMetrics()) * SysData.t_scale);
PhotographUi pu = new PhotographUi(aa, h - hh);
layout.addView(pu, layoutParams);
pu.setOnClickListener(aa.pzClickEvent);
pu.setImageOnClickListener(aa.imgClickEvent);
if (e_pe1.element("name_attribute") != null) {
pu.setTag(e_pe1.elementText("name_attribute")
.toString().trim().toUpperCase());
}
}
}
aa.setTabwidgetAtt(aa.hzTab.getTabWidget());
aa.hzTab.setCurrentTab(0);
// break;
}
}
// /* 设置属性 */
// public static void setEditTextAtt(SelfEditText et, Element e_pe1,
// DjActivity djActivity) {
// et.setPadding(0, 0, 0, 0);
// et.setGravity(Gravity.CENTER_VERTICAL);
// if (e_pe1.element("name_attribute") != null) {
// et.setTag(e_pe1.elementText("name_attribute").toString().trim()
// .toUpperCase());
// }
// if (e_pe1.element("enterKey") != null) {
// et.nextFocus = e_pe1.elementText("enterKey").toString()
// .toUpperCase();
// }
// if (e_pe1.element("fontSize_style") != null) {
// et.setTextSize(Float.parseFloat(e_pe1.elementText("fontSize_style")
// .toString()) + 5);
// }
// // et.setText(e_pe1.elementText("text_attribute"));
// boolean b = false;// 判断是否需要加焦点事件
// if (e_pe1.element("focusOut_function") != null) {
// et.focusOutFun = e_pe1.elementText("focusOut_function").toString();
// if (!b) {
// b = true;
// }
// }
// if (e_pe1.element("focusIn_function") != null) {
// et.focusInFun = e_pe1.elementText("focusIn_function").toString();
// if (!b) {
// b = true;
// }
// }
// if (b) {
// et.setOnFocusChangeListener(djActivity.focusEvent);
// }
// if (e_pe1.element("enabled_attribute") != null) {
// Boolean enabled = Boolean.parseBoolean(e_pe1.elementText(
// "enabled_attribute").toString());
// et.setEnabled(enabled);
// if (!enabled) {
// if (e_pe1.element("backgroundColor_style") != null) {//
// backgroundColor_style
// et.setBackgroundDrawable(SysUtil.GradientDrawable(e_pe1
// .elementText("backgroundColor_style").toString()));
// }
// }
// }
// if (e_pe1.element("text_attribute") != null) {
// String funName = e_pe1.elementText("text_attribute").toString()
// .trim();
// DjMenuFun menufun = new DjMenuFun();
// Class cla = menufun.getClass();
// try {
// Method method = cla.getDeclaredMethod(funName);
// if (method != null) {
// et.setText(method.invoke(menufun).toString());
// }
// } catch (Exception e) {
// et.setText(funName);
// }
// }
// }
public static boolean isVisible(Element e_pe1) {
boolean b = false;
if (e_pe1.element("visible_attribute") != null) {
if (e_pe1.elementText("visible_attribute").toString().trim()
.equals("false")) {
b = true;
} else {
b = false;
}
}
return b;
}
/* 设置属性 */
public static void setTextButAtt(InputInterface et, Element e_pe1,
DjActivity djActivity) {
et.setPadding(0, 0, 0, 0);
et.setGravity(Gravity.CENTER_VERTICAL);
if (e_pe1.element("name_attribute") != null) {
et.setTag(e_pe1.elementText("name_attribute").toString().trim()
.toUpperCase());
}
if (e_pe1.element("enterKey") != null) {
et.setNextFocus(e_pe1.elementText("enterKey").toString()
.toUpperCase());
}
if (e_pe1.element("fontSize_style") != null) {
et.setTextSize(Float.parseFloat(e_pe1.elementText("fontSize_style")
.toString()) * SysData.t_scale + 5);
}
if (e_pe1.element("closeKeyBoard") != null) {
boolean closeKeyBoard = Boolean.parseBoolean(e_pe1
.elementText("closeKeyBoard"));
et.setCloseKeyBoard(closeKeyBoard);
if (closeKeyBoard) {
et.setInputType(InputType.TYPE_NULL);
}
}
// if(e_pe1.element("doubleClick_function") != null){
// et.setOnClickListener(djActivity.clickEvent);
// et.setClickFun(e_pe1.elementText("doubleClick_function").toString().toUpperCase());
// }
// et.setText(e_pe1.elementText("text_attribute"));
// boolean b = false;// 判断是否需要加焦点事件
if (e_pe1.element("focusOut_function") != null) {
et.setFocusOutFun(e_pe1.elementText("focusOut_function").toString());
// if (!b) {
// b = true;
// }
}
if (e_pe1.element("focusIn_function") != null) {
et.setFocusInFun(e_pe1.elementText("focusIn_function").toString());
// if (!b) {
// b = true;
// }
}
// if (b) {
et.setOnFocusChangeListener(djActivity.focusEvent);
// }
if (e_pe1.element("enabled_attribute") != null) {
Boolean enabled = Boolean.parseBoolean(e_pe1.elementText(
"enabled_attribute").toString());
et.setEnabled(enabled);
// if (!enabled) {
// }
}
if (e_pe1.element("backgroundColor_style") != null) {// backgroundColor_style
et.setBackgroundDrawable(SysUtil.GradientDrawable(e_pe1
.elementText("backgroundColor_style").toString()));
} else {
et.setBackgroundDrawable(SysUtil.GradientDrawable());
}
if (e_pe1.element("text_attribute") != null) {
String funName = e_pe1.elementText("text_attribute").toString()
.trim().toLowerCase();
et.setText(dyhs(funName, djActivity));
}
if (e_pe1.element("isValue_attribute") != null) {
et.setIsNull(Boolean.parseBoolean(e_pe1
.elementText("isValue_attribute")));
}
if (e_pe1.element("label_attribute") != null) {
et.setLabel(e_pe1.elementText("label_attribute").toString().trim());
}
if (e_pe1.element("label_attribute") != null) {
et.setLabel(e_pe1.elementText("label_attribute").toString().trim());
}
if (e_pe1.element("color_style") != null) {
et.setTextColor(SysUtil.toHex(e_pe1.elementText("color_style")
.toString().trim()));
}
// if (e_pe1.element("fdtype")!= null) {
// String fdtype=e_pe1.elementText("fdtype").toString().trim();
// if(fdtype.equals("整数")){
// et.setDefaultValue("0");
// }else if(fdtype.equals("实数")||fdtype.equals("浮点")){
// et.setDefaultValue("0.00");
// }
// }
}
public static String dyhs(String funName, DjActivity activity) {
String val = "";
DjMenuFun menufun = new DjMenuFun();
Class cla = menufun.getClass();
try {
Method method = cla.getDeclaredMethod(funName, DjActivity.class);
if (method != null) {
// if(method.getGenericParameterTypes().length>0){
val = method.invoke(menufun, new Object[] { activity })
.toString();
// }else{
// val = method.invoke(menufun).toString();
// }
} else {
val = funName;
}
} catch (Exception e) {
// e.printStackTrace();
val = funName;
}
return val;
}
/* 解析更新xml */
public static UpdataInfo parserXml(InputStream in, String version)
throws DocumentException {
version = version.substring(0, 1).toUpperCase();
// 产生一个解析器对象
SAXReader reader = new SAXReader();
reader.setEncoding("UTF-8");
// 将xml文档转换为Document的对象
Document document = reader.read(in);
// 获取文档的根元素
Element root = document.getRootElement();
UpdataInfo info = null;
List<Element> list = root.elements();
if (list != null) {
for (int i = 0; i < list.size(); i++) {
root = list.get(i);
if (root.getName().toUpperCase().equals("PDA")) {
Iterator i_pe = root.elementIterator();
if (root.attributeValue("model").toUpperCase()
.equals(version)) {
info = gerUpdataInfo(i_pe);
break;
}
}
}
}
return info;
}
public static UpdataInfo gerUpdataInfo(Iterator i_pe) {
String name = null;
UpdataInfo info = new UpdataInfo();// 实体
while (i_pe.hasNext()) {
Element e_pe = (Element) i_pe.next();
name = e_pe.getName();
if ("version".equals(name)) {
info.setVersion(e_pe.getText()); // 获取版本号
} else if ("url".equals(name)) {
info.setUrl(e_pe.getText()); // 获取要升级的APK文件
} else if ("description".equals(name)) {
info.setDescription(e_pe.getText()); // 获取该文件的信息
}
}
return info;
}
public static boolean isVisible_attribute(Element e_pe11,
DjActivity djActivity) {
boolean isVisible = true;
if (e_pe11.element("visible_attribute") != null) {
if (e_pe11.elementText("visible_attribute").toString().trim()
.equals("false")) {
isVisible = false;
String val = "";
if (e_pe11.element("text_attribute") != null) {
String funName = e_pe11.elementText("text_attribute")
.toString().trim();
val = dyhs(funName, djActivity);
}
// if(val==null||val.length()==0){
// if (e_pe11.element("fdtype")!= null) {
// String fdtype=e_pe11.elementText("fdtype").toString().trim();
// if(fdtype.equals("整数")){
// val="0";
// }else if(fdtype.equals("实数")||fdtype.equals("浮点")){
// val="0.00";
// }else{
// val="";
// }
// }
// }
if (e_pe11.element("name_attribute") != null) {
djActivity.pageMap.put(e_pe11.elementText("name_attribute")
.toString().trim().toUpperCase(), val);
}
}
}
return isVisible;
}
}

View File

@ -0,0 +1,48 @@
package com.util;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import android.app.ProgressDialog;
import android.content.Context;
public class DownloadManager {
public static File getFileFromServer(String path, ProgressDialog pd,Context context)
throws Exception {
// 如果相等的话表示当前的sdcard挂载在手机上并且是可用的
// if (Environment.getExternalStorageState().equals(
// Environment.MEDIA_MOUNTED)) {
URL url = new URL(path);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setConnectTimeout(5000);
// 获取到文件的大小
pd.setMax(conn.getContentLength()/1000);
InputStream is = conn.getInputStream();
// File file = new File(Environment.getExternalStorageDirectory(),
// "updata.apk");//得到sd卡的目录
File file = new File(context.getCacheDir().getParentFile(),
"updata.apk"); //放到当前应用程序所在的目录下
FileOutputStream fos = new FileOutputStream(file);
BufferedInputStream bis = new BufferedInputStream(is);
byte[] buffer = new byte[1024];
int len;
int total = 0;
while ((len = bis.read(buffer)) != -1) {
fos.write(buffer, 0, len);
total += len;
// 获取当前下载量
pd.setProgress(total/1000);
}
fos.close();
bis.close();
is.close();
return file;
// } else {
// return null;
// }
}
}

View File

@ -0,0 +1,33 @@
package com.util;
import java.io.File;
import java.io.IOException;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
public class InstallUtil {
// 安装apk
public void installApk(File file,Activity activity) {
chmod("777", file.getPath());
Intent intent = new Intent();
// 执行动作
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setAction(Intent.ACTION_VIEW);
// 执行的数据类型
intent.setDataAndType(Uri.fromFile(file),
"application/vnd.android.package-archive");
activity.startActivity(intent);
}
// 修改apk权限
public static void chmod(String permission, String path) {
try {
String command = "chmod " + permission + " " + path;
Runtime runtime = Runtime.getRuntime();
runtime.exec(command);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,102 @@
package com.util;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.StreamCorruptedException;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import org.kobjects.base64.Base64;
public class IoUtil {
/*zip解压缩*/
public static Object byte_obj(byte[] b) throws StreamCorruptedException,
IOException, ClassNotFoundException {
ByteArrayInputStream bin = null;
GZIPInputStream gzip = null;
ObjectInputStream oin = null;
try {
bin = new ByteArrayInputStream(b);
gzip = new GZIPInputStream(bin);
oin = new ObjectInputStream(gzip);
return oin.readObject();
} finally {
if (oin != null) {
oin.close();
}
if (gzip != null) {
gzip.close();
}
if (bin != null) {
bin.close();
}
System.out.println("留关闭---");
}
}
public static Object byte_obj2(byte[] b) throws StreamCorruptedException,
IOException, ClassNotFoundException {
ByteArrayInputStream bin = null;
ObjectInputStream oin = null;
try {
bin = new ByteArrayInputStream(b);
oin = new ObjectInputStream(bin);
return oin.readObject();
} finally {
if (oin != null) {
oin.close();
}
if (bin != null) {
bin.close();
}
System.out.println("留关闭");
}
}
/*gzip压缩*/
public static byte[] getbyte(Object ob) throws Exception {
ByteArrayOutputStream byteOut = null;
GZIPOutputStream gziOut = null;
ObjectOutputStream objectOut = null;
try {
byteOut = new ByteArrayOutputStream();
gziOut = new GZIPOutputStream(byteOut);
objectOut = new ObjectOutputStream(gziOut);
objectOut.writeObject(ob);
objectOut.flush();
objectOut.close();
gziOut.close();
byteOut.close();
return byteOut.toByteArray();
} finally {
// if(objectOut!=null){
// objectOut.close();
// }
// if(gziOut!=null){
//// gziOut.finish();
// gziOut.close();
// }
// if(byteOut!=null){
// byteOut.close();
// }
}
}
public static String ob_base64(Object ob) throws IOException {
ByteArrayOutputStream bOut = null;
ObjectOutputStream objOut = null;
try {
bOut = new ByteArrayOutputStream();
objOut = new ObjectOutputStream(bOut);
objOut.writeObject(ob);
return Base64.encode(bOut.toByteArray());
} finally {
objOut.flush();
objOut.close();
bOut.flush();
bOut.close();
}
}
}

View File

@ -0,0 +1,265 @@
package com.util;
import java.io.InputStream;
import java.util.Iterator;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import android.app.Activity;
import android.text.InputType;
import android.util.TypedValue;
import android.view.Gravity;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.chaoran.component.AntLine;
import com.chaoran.component.SelfHRule;
import com.chaoran.entiry.PhotographUi;
import com.chaoran.entiry.SelfButton;
import com.chaoran.entiry.SelfCheckBox;
import com.chaoran.entiry.SelfDateField;
import com.chaoran.entiry.SelfEditText;
import com.chaoran.entiry.SelfImage;
import com.chaoran.entiry.SelfTextBut;
import com.chaoran.imp.InputInterface;
import com.chaoran.thread.ImageUrl;
import com.example.chaoran.DjActivity;
import com.sys.SysData;
public class LxParamPageCreate {
public static void lxParamPageCreate(InputStream in, Activity activity, RelativeLayout layout) throws DocumentException {
SAXReader reader = new SAXReader();
// 将xml文档转换为Document的对象
Document document = reader.read(in);
// 获取文档的根元素
Element root = document.getRootElement();
Iterator i_pe = root.elementIterator();
while (i_pe.hasNext()) {
Element e_pe = (Element) i_pe.next();
Iterator i_pe1 = e_pe.elementIterator();
if (!i_pe1.hasNext()) {
continue;
}
while (i_pe1.hasNext()) {
Element e_pe1 = (Element) i_pe1.next();
String name = e_pe1.attributeValue("name");
name = name.substring(name.indexOf("::") + 2, name.length());
int w = (int) (Double.parseDouble(e_pe1.elementText("width_attribute")));
int h = (int) (Double.parseDouble(e_pe1.elementText("height_attribute")));
int x = (int) (Double.parseDouble(e_pe1.elementText("x_attribute")));
int y = (int) (Double.parseDouble(e_pe1.elementText("y_attribute")));
w = (int) (TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, w, activity.getResources().getDisplayMetrics()) * SysData.t_scale);
h = (int) (TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, h, activity.getResources().getDisplayMetrics()) * SysData.t_scale);
x = (int) (TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, x, activity.getResources().getDisplayMetrics()) * SysData.t_scale);
y = (int) (TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, y, activity.getResources().getDisplayMetrics()) * SysData.t_scale);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(w, h);
layoutParams.topMargin = y;
layoutParams.leftMargin = x;
if (name.equals("SelfButton")) {
if (Dom4jUtil.isVisible(e_pe1)) {
continue;
}
SelfButton but = new SelfButton(activity);
if (SysData.t_scale < 1) {
but.setPadding((int) (but.getPaddingLeft() * SysData.t_scale * 0.2f), (int) (but.getPaddingTop() * SysData.t_scale * 0.2f),
(int) (but.getPaddingRight() * SysData.t_scale * 0.2f), (int) (but.getPaddingBottom() * SysData.t_scale * 0.2f));
}
// but.setFocusableInTouchMode(true);
but.setText(e_pe1.elementText("label_attribute"));
if (e_pe1.element("click_function") != null) {
but.clickFun = e_pe1.elementText("click_function").toString();
}
if (e_pe1.element("enterKey_attribute") != null) {
but.nextFocus = e_pe1.elementText("enterKey_attribute").toString().toUpperCase();
}
if (e_pe1.element("fontSize_style") != null) {
but.setTextSize(Float.parseFloat(e_pe1.elementText("fontSize_style").toString()) * SysData.t_scale);
}
if (e_pe1.element("key_value") != null) {
but.setTag(e_pe1.elementText("key_value").toString().trim().toUpperCase());
}
// but.setLayoutParams(new
// AbsoluteLayout.LayoutParams(w,h,x,y));
layout.addView(but, layoutParams);
} else if (name.equals("SelfLabel")) {
if (Dom4jUtil.isVisible(e_pe1)) {
continue;
}
TextView tv = new TextView(activity);
tv.setGravity(Gravity.CENTER_VERTICAL);
if (e_pe1.element("fontSize_style") != null) {
tv.setTextSize(Float.parseFloat(e_pe1.elementText("fontSize_style").toString()) * SysData.t_scale);
}
tv.setText(e_pe1.elementText("text_attribute"));
layout.addView(tv, layoutParams);
} else if (name.equals("SelfTextInput")) {
if (Dom4jUtil.isVisible(e_pe1)) {
continue;
}
if (e_pe1.attributeValue("isDouble").equals("yes")) {
SelfTextBut stb = new SelfTextBut(activity);
if (e_pe1.element("doubleClick_function") != null) {
stb.setClickFun(e_pe1.elementText("doubleClick_function").toString().toUpperCase());
}
// setTextButAtt(stb, e_pe1, aa);
setTextButAtt((InputInterface) stb, e_pe1);
layout.addView(stb, layoutParams);
} else {
SelfEditText et = new SelfEditText(activity);
if (e_pe1.element("borderStyle_style") != null) {
et.showBorder = e_pe1.elementText("borderStyle_style").toString();
}
et.setSingleLine(true);
setTextButAtt((InputInterface) et, e_pe1);
layout.addView(et, layoutParams);
}
} else if (name.equals("SelfTextArea")) {
if (Dom4jUtil.isVisible(e_pe1)) {
continue;
}
SelfEditText area = new SelfEditText(activity);
if (e_pe1.element("borderStyle_style") != null) {
area.showBorder = e_pe1.elementText("borderStyle_style").toString();
}
// setEditTextAtt(area, e_pe1, aa);
setTextButAtt((InputInterface) area, e_pe1);
area.setSingleLine(false);
// if(e_pe1.element("backgroundColor_style") !=
// null){//backgroundColor_style
// area.setBackgroundColor(SysUtil.toHex(e_pe1.elementText("backgroundColor_style")
// .toString()));
// }
// if(e_pe1.element("color_style") !=
// null){//backgroundColor_style
// area.setTextColor(SysUtil.toHex(e_pe1.elementText("color_style")
// .toString()));
// }
layout.addView(area, layoutParams);
} else if (name.equals("SelfCheckBox")) {
// if (isVisible(e_pe1)) {
// continue;
// }
if (Dom4jUtil.isVisible(e_pe1)) {
continue;
}
SelfCheckBox box = new SelfCheckBox(activity);
if (SysData.t_scale < 1) {
box.setPadding((int) (box.getPaddingLeft() * SysData.t_scale * 0.2f), box.getPaddingTop(), box.getPaddingRight(), box.getPaddingBottom());
}
if (e_pe1.element("name_attribute") != null) {
box.setTag(e_pe1.elementText("name_attribute").toString().trim().toUpperCase());
}
if (e_pe1.element("label_attribute") != null) {
box.setText(e_pe1.elementText("label_attribute").toString());
}
if (e_pe1.element("fontSize_style") != null) {
box.setTextSize(Float.parseFloat(e_pe1.elementText("fontSize_style").toString()) * SysData.t_scale); // checkbox
// +
// 5会变大
}
if (e_pe1.element("enabled_attribute") != null) {
String enabled = e_pe1.elementText("enabled_attribute").toString();
box.setEnabled(Boolean.parseBoolean(enabled));
}
if (e_pe1.element("text_attribute") != null) {
String funName = e_pe1.elementText("text_attribute").toString().trim().toLowerCase();
if (funName.equals("")) {
box.setChecked(true);
}
}
layout.addView(box, layoutParams);
} else if (name.equals("SelfHRule") || name.equals("SelfVRule")) {
if (Dom4jUtil.isVisible(e_pe1)) {
continue;
}
SelfHRule hrule = new SelfHRule(activity);
if (e_pe1.element("strokeColor_style") != null) {
// System.out.println();
hrule.setColor(SysUtil.toHex(e_pe1.elementText("strokeColor_style").toString()));
}
layout.addView(hrule, layoutParams);
} else if (name.equals("AntLine")) {
if (Dom4jUtil.isVisible(e_pe1)) {
continue;
}
AntLine al = new AntLine(activity);
if (e_pe1.element("lineColor_attribute") != null) {
al.setColor(SysUtil.toHex(e_pe1.elementText("lineColor_attribute").toString()));
}
if (e_pe1.element("lineThickness_attribute") != null) {
al.setSize(Integer.parseInt(e_pe1.elementText("lineThickness_attribute")) * 2);
}
layout.addView(al, layoutParams);
} else if (name.equals("SelfDateField")) {
SelfDateField df = new SelfDateField(activity);
if (e_pe1.element("formatString_attribute") != null) {
df.formatString = e_pe1.elementText("formatString_attribute").toString().trim().toLowerCase();
if (df.formatString.length() < 1) {
df.formatString = "yyyy-mm-dd";
}
df.formatString = df.formatString.replace("mm", "MM");
}
setTextButAtt((InputInterface) df, e_pe1);
layout.addView(df, layoutParams);
}
}
break;
}
}
/* 设置属性 */
public static void setTextButAtt(InputInterface et, Element e_pe1) {
et.setPadding(0, 0, 0, 0);
et.setGravity(Gravity.CENTER_VERTICAL);
if (e_pe1.element("name_attribute") != null) {
et.setTag(e_pe1.elementText("name_attribute").toString().trim().toUpperCase());
}
if (e_pe1.element("enterKey") != null) {
et.setNextFocus(e_pe1.elementText("enterKey").toString().toUpperCase());
}
if (e_pe1.element("fontSize_style") != null) {
et.setTextSize(Float.parseFloat(e_pe1.elementText("fontSize_style").toString()) * SysData.t_scale + 5);
}
if (e_pe1.element("closeKeyBoard") != null) {
boolean closeKeyBoard = Boolean.parseBoolean(e_pe1.elementText("closeKeyBoard"));
et.setCloseKeyBoard(closeKeyBoard);
if (closeKeyBoard) {
et.setInputType(InputType.TYPE_NULL);
}
}
if (e_pe1.element("focusOut_function") != null) {
et.setFocusOutFun(e_pe1.elementText("focusOut_function").toString());
}
if (e_pe1.element("focusIn_function") != null) {
et.setFocusInFun(e_pe1.elementText("focusIn_function").toString());
}
if (e_pe1.element("enabled_attribute") != null) {
Boolean enabled = Boolean.parseBoolean(e_pe1.elementText("enabled_attribute").toString());
et.setEnabled(enabled);
}
if (e_pe1.element("backgroundColor_style") != null) {// backgroundColor_style
et.setBackgroundDrawable(SysUtil.GradientDrawable(e_pe1.elementText("backgroundColor_style").toString()));
} else {
et.setBackgroundDrawable(SysUtil.GradientDrawable());
}
if (e_pe1.element("text_attribute") != null) {
String funName = e_pe1.elementText("text_attribute").toString().trim().toLowerCase();
et.setText(funName);
}
if (e_pe1.element("isValue_attribute") != null) {
et.setIsNull(Boolean.parseBoolean(e_pe1.elementText("isValue_attribute")));
}
if (e_pe1.element("label_attribute") != null) {
et.setLabel(e_pe1.elementText("label_attribute").toString().trim());
}
if (e_pe1.element("label_attribute") != null) {
et.setLabel(e_pe1.elementText("label_attribute").toString().trim());
}
if (e_pe1.element("color_style") != null) {
et.setTextColor(SysUtil.toHex(e_pe1.elementText("color_style").toString().trim()));
}
}
}

View File

@ -0,0 +1,24 @@
package com.util;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TabHost.TabContentFactory;
public class MxTabHostContent extends RelativeLayout implements TabContentFactory{
public MxTabHostContent(Context context) {
super(context);
}
public MxTabHostContent(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public View createTabContent(String tag) {
// TODO Auto-generated method stub
return this;
}
}

View File

@ -0,0 +1,213 @@
package com.util;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.chaoran.entiry.SelfCheckBox;
import com.chaoran.entiry.SelfEditText;
import com.chaoran.entiry.SelfTextBut;
import com.chaoran.imp.InputInterface;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TabHost;
import android.widget.TextView;
public class SqlUtil {
public static HashMap regSql(String sql, TabHost layout, Map pageMap) {
System.out.println("------------------===============================");
// System.out.println(sql);
// String regEx=":[\\w|.]*[\\s]{0}";
String regEx = "[:|\\&]([\\w\\.]+)";
Pattern p = Pattern.compile(regEx);
Matcher m = p.matcher(sql);
String paramName = null;
String oldParam = null;
HashMap paramMap = new HashMap();
String paramValue = null;
String sqlCopy = sql;
String paramType = null;
while (m.find()) {
oldParam = m.group();
System.out.println(oldParam+"--------------------");
paramType = oldParam.substring(0, 1);
paramName = oldParam.toUpperCase();
if (paramName.indexOf("MX.") > -1) {
paramName = paramName.substring(4, paramName.length());
} else if (paramName.indexOf("HZ.") > -1) {
paramName = paramName.substring(4, paramName.length());
} else {
paramName = paramName.substring(1, paramName.length());
}
sqlCopy = sqlCopy.replaceFirst(oldParam,
paramType.concat(paramName));
View view = layout.findViewWithTag(paramName);
if (view != null) {
// if (view instanceof SelfEditText) {
// paramValue = ((SelfEditText) view).getText().toString()
// .trim();
// } else if (view instanceof SelfCheckBox) {
// SelfCheckBox sfb = (SelfCheckBox) view;
// boolean b = sfb.isChecked();
// if (b) {
// paramValue = "是";
// } else {
// paramValue = "否";
// }
// } else if (view instanceof TextView) {
// paramValue = ((TextView) view).getText().toString().trim();
// }else if(view instanceof SelfTextBut){
// paramValue = ((SelfTextBut)
// view).getText().toString().trim();
// }
if (view instanceof InputInterface) {
InputInterface inView = (InputInterface) view;
paramValue = inView.getText().toString();
} else if (view instanceof SelfCheckBox) {
SelfCheckBox sfb = (SelfCheckBox) view;
boolean b = sfb.isChecked();
if (b) {
paramValue = "";
} else {
paramValue = "";
}
} else if (view instanceof TextView) {
paramValue = ((TextView) view).getText().toString();
}
} else if (pageMap.containsKey(paramName)) {
paramValue = pageMap.get(paramName).toString();
}
if (paramValue == null) {
paramValue = "";
} else {
paramValue = paramValue.trim();
}
if (paramType.equals(":")) {
paramMap.put(paramName, paramValue);
} else {
paramValue = paramValue.replace("$", "\\$");
sqlCopy = sqlCopy.replaceFirst(paramType.concat(paramName),
paramValue);
}
if (paramValue != null) {
paramValue = null;
}
}
HashMap map = new HashMap();
System.out.println("============="+sqlCopy+"------------------------sqlCopy");
map.put("sql", sqlCopy);
map.put("param", paramMap);
return map;
}
public static HashMap regSql(String sql, Map item) {
// String regEx=":[\\w|.]*[\\s]{0}";
String regEx = "[:|\\&]([\\w\\.]+)";
Pattern p = Pattern.compile(regEx);
Matcher m = p.matcher(sql);
String paramName = null;
String oldParam = null;
HashMap paramMap = new HashMap();
String paramValue = "";
String sqlCopy = sql;
String paramType = null;
while (m.find()) {
oldParam = m.group();
System.out.println(oldParam + "--------------------");
paramType = oldParam.substring(0, 1);
paramName = oldParam.toUpperCase();
if (paramName.indexOf("MX.") > -1) {
paramName = paramName.substring(4, paramName.length());
} else if (paramName.indexOf("HZ.") > -1) {
paramName = paramName.substring(4, paramName.length());
} else {
paramName = paramName.substring(1, paramName.length());
}
sqlCopy = sqlCopy.replaceFirst(oldParam,
paramType.concat(paramName));
if (item.containsKey(paramName)) {
paramValue = item.get(paramName).toString();
}
if (paramType.equals(":")) {
paramMap.put(paramName, paramValue);
} else {
paramValue = paramValue.replace("$", "\\$");
sqlCopy = sqlCopy.replaceFirst(paramType.concat(paramName),
paramValue);
}
if (!paramValue.equals("")) {
paramValue = "";
}
}
HashMap map = new HashMap();
map.put("sql", sqlCopy);
map.put("param", paramMap);
return map;
}
public static HashMap regSql(String sql, RelativeLayout layout) {
System.out.println(sql);
String regEx = "[:|\\&]([\\w\\.]+)";
Pattern p = Pattern.compile(regEx);
Matcher m = p.matcher(sql);
String paramName = null;
String oldParam = null;
HashMap paramMap = new HashMap();
String paramValue = null;
String sqlCopy = sql;
String paramType = null;
while (m.find()) {
oldParam = m.group();
paramType = oldParam.substring(0, 1);
paramName = oldParam.toUpperCase();
if (paramName.indexOf("MX.") > -1) {
paramName = paramName.substring(4, paramName.length());
} else if (paramName.indexOf("HZ.") > -1) {
paramName = paramName.substring(4, paramName.length());
} else {
paramName = paramName.substring(1, paramName.length());
}
sqlCopy = sqlCopy.replaceFirst(oldParam,
paramType.concat(paramName));
View view = layout.findViewWithTag(paramName);
if (view != null) {
if (view instanceof InputInterface) {
InputInterface inView = (InputInterface) view;
paramValue = inView.getText().toString();
} else if (view instanceof SelfCheckBox) {
SelfCheckBox sfb = (SelfCheckBox) view;
boolean b = sfb.isChecked();
if (b) {
paramValue = "";
} else {
paramValue = "";
}
} else if (view instanceof TextView) {
paramValue = ((TextView) view).getText().toString();
}
}
if (paramValue == null) {
paramValue = "";
} else {
paramValue = paramValue.trim();
}
if (paramType.equals(":")) {
paramMap.put(paramName, paramValue);
} else {
paramValue = paramValue.replace("$", "\\$");
sqlCopy = sqlCopy.replaceFirst(paramType.concat(paramName),
paramValue);
}
if (paramValue != null) {
paramValue = null;
}
}
HashMap map = new HashMap();
map.put("sql", sqlCopy);
map.put("param", paramMap);
return map;
}
}

View File

@ -0,0 +1,329 @@
package com.util;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.lang.reflect.Method;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.ActivityManager.RunningTaskInfo;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.drawable.GradientDrawable;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Environment;
public class SysUtil {
private static String mac = "";
/* 把数字转换成颜色 */
public static int toHex(String value) {
int color = (int) Long.parseLong("ff" + Integer.toHexString(Integer.parseInt(value)), 16);
if (color == 4080)
color = Color.BLACK;
return color;
}
/* 把6位颜色直(0xff0000) 转换成颜色 */
public static int toColor(int color) {
int red = (color & 0xff0000) >> 16;
int green = (color & 0x00ff00) >> 8;
int blue = (color & 0x0000ff);
return Color.rgb(red, green, blue);
}
public static GradientDrawable GradientDrawable(String color) {
GradientDrawable gd = new GradientDrawable();
gd.setCornerRadius(3);
gd.setColor(toHex(color));// 设置颜色
// gd.setStroke(3, toHex("14079443"));
return gd;
}
public static GradientDrawable GradientDrawable(int color) {
GradientDrawable gd = new GradientDrawable();
gd.setCornerRadius(3);
gd.setColor(color);// 设置颜色
// gd.setStroke(3, toHex("14079443"));
return gd;
}
public static GradientDrawable GradientDrawable() {
GradientDrawable gd = new GradientDrawable();
gd.setCornerRadius(3);
gd.setColor(Color.WHITE);// 设置颜色
// gd.setStroke(3, toHex("14079443"));
return gd;
}
public static boolean isTopApp(Context context) {
ActivityManager activityManager = (ActivityManager) context.getSystemService(context.ACTIVITY_SERVICE);
List<RunningTaskInfo> tasks = activityManager.getRunningTasks(1);
if (tasks == null || tasks.isEmpty()) {
return false;
}
RunningTaskInfo task = tasks.get(0);
String className = task.topActivity.getClassName();
System.out.println(className + "-----------------------------");
return className.equals(((Activity) context).getComponentName().getClassName());
}
// public static String getMac() {
// String macSerial = null;
// String str = "";
// try {
// Process pp = Runtime.getRuntime().exec(
// "cat /sys/class/net/wlan0/address ");
// InputStreamReader ir = new InputStreamReader(pp.getInputStream());
// LineNumberReader input = new LineNumberReader(ir);
//
// for (; null != str;) {
// str = input.readLine();
// if (str != null) {
// macSerial = str.trim();// 去空格
// break;
// }
// }
// } catch (IOException ex) {
// // 赋予默认值
// ex.printStackTrace();
// }
// return macSerial;
//
// }
public static boolean isNetworkConnected(Context context) {
if (context != null) {
ConnectivityManager mConnectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo mNetworkInfo = mConnectivityManager.getActiveNetworkInfo();
if (mNetworkInfo != null) {
return mNetworkInfo.isAvailable();
}
}
return false;
}
/* *//**
* 获取移动设备本地IP
*
* @return
*//*
private static InetAddress getLocalInetAddress() {
InetAddress ip = null;
try {
// 列举
Enumeration<NetworkInterface> en_netInterface = NetworkInterface
.getNetworkInterfaces();
while (en_netInterface.hasMoreElements()) {// 是否还有元素
NetworkInterface ni = (NetworkInterface) en_netInterface
.nextElement();// 得到下一个元素
Enumeration<InetAddress> en_ip = ni.getInetAddresses();// 得到一个ip地址的列举
while (en_ip.hasMoreElements()) {
ip = en_ip.nextElement();
if (!ip.isLoopbackAddress()
&& ip.getHostAddress().indexOf(":") == -1)
break;
else
ip = null;
}
if (ip != null) {
break;
}
}
} catch (SocketException e) {
e.printStackTrace();
}
return ip;
}*/
public static String getLocalMacAddress(Activity activity) {
WifiManager wifi = (WifiManager) activity.getSystemService(Context.WIFI_SERVICE);
WifiInfo info = wifi.getConnectionInfo();
mac = info.getMacAddress();
if (mac == null || mac.length() < 1 || mac.startsWith("02:00:00:00:00:"))
mac = getMacAddress();
mac = mac.toUpperCase();
return mac;
}
@SuppressLint("NewApi")
public static String getMacAddress() {
/*
* 获取mac地址有一点需要注意的就是android
* 6.0版本后,以下注释方法不再适用,不管任何手机都会返回"02:00:00:00:00:00"
* 这个默认的mac地址这是googel官方为了加强权限管理而禁用了getSYstemService
* (Context.WIFI_SERVICE)方法来获得mac地址。
*/
// String macAddress= "";
// WifiManager wifiManager = (WifiManager)
// MyApp.getContext().getSystemService(Context.WIFI_SERVICE);
// WifiInfo wifiInfo = wifiManager.getConnectionInfo();
// macAddress = wifiInfo.getMacAddress();
// return macAddress;
String macAddress = null;
StringBuffer buf = new StringBuffer();
NetworkInterface networkInterface = null;
try {
networkInterface = NetworkInterface.getByName("eth1");
if (networkInterface == null) {
networkInterface = NetworkInterface.getByName("wlan0");
}
if (networkInterface == null) {
return "02:00:00:00:00:02";
}
byte[] addr = networkInterface.getHardwareAddress();
for (byte b : addr) {
buf.append(String.format("%02X:", b));
}
if (buf.length() > 0) {
buf.deleteCharAt(buf.length() - 1);
}
macAddress = buf.toString();
} catch (SocketException e) {
e.printStackTrace();
return "02:00:00:00:00:02";
}
return macAddress;
}
public static String mapFirst(List list) {
String filedName = null;
Set<String> set = ((HashMap) list.get(0)).keySet();
for (String s : set) {
filedName = s;
break;
}
return filedName;
}
@SuppressLint({ "NewApi", "NewApi" })
public static String getSerialNum() {
// String serialNum = null;
// try {
// Class<?> classZ = Class.forName("android.os.SystemProperties");
// Method get = classZ.getMethod("get", String.class);
// serialNum = (String) get.invoke(classZ, "ro.serialno");
// } catch (Exception e) {
// }
String serialNum = android.os.Build.SERIAL;
return serialNum;
}
/* 东集pda专用获取SN */
public static String getSn() {
//return mac.toLowerCase().replace(":", "");
String sn = getSn0("data/data/sn");
if (sn == null || sn.trim().length() < 1)
sn = getSn1();
if (sn.length() >= 15) {
sn = getSn0("/sys/class/net/wlan0/address");
sn = sn.replace(":", "");
}
if (sn != null && sn.trim().length() > 0)
return sn;
else
return mac.toLowerCase().replace(":", "");
}
public static String getSn0(String fileName) {
String SN_FILE = fileName;
InputStreamReader isr = null;
FileInputStream inputStream = null;
byte[] buffer = new byte[64];
File file = new File(SN_FILE);
int code = 0;
try {
inputStream = new FileInputStream(file);
inputStream.read(buffer, 0, buffer.length);
String str = new String(buffer).toString();
return str.trim().length() > 0 ? str.trim() : "";
} catch (IOException e) {
return "";
} finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
public static String getSn1() {
try {
Method systemProperties_get = Class.forName("android.os.SystemProperties").getMethod("get", String.class);
// String []propertys = {"ro.boot.serialno", "ro.serialno"};
String rtn = (String) systemProperties_get.invoke(null, "ro.boot.serialno");
if (rtn == null || rtn.trim().length() < 1)
rtn = (String) systemProperties_get.invoke(null, "ro.serialno");
return rtn == null ? "" : rtn;
} catch (Exception e) {
e.printStackTrace();
return "";
}
}
/*
* 检查存储卡是否插入
*
* @return
*/
public static boolean isHasSdcard() {
String status = Environment.getExternalStorageState();
if (status.equals(Environment.MEDIA_MOUNTED)) {
return true;
} else {
return false;
}
}
/*
* 拍照图片文件名
*/
private static String getPhotoFileName() {
Date date = new Date(System.currentTimeMillis());
SimpleDateFormat dateFormat = new SimpleDateFormat("'IMG'_yyyyMMdd_HHmmss");
return dateFormat.format(date) + ".jpg";
}
public static byte[] bitmapToByte(Bitmap bitmap) {
ByteArrayOutputStream output = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.JPEG, 60, output);
byte[] result = output.toByteArray();
try {
output.close();
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
}

View File

@ -0,0 +1,19 @@
package com.util;
import com.sys.SysData;
import android.content.Context;
public class UnitConversionUtil {
//转换dip为px
public static int convertDIP2PX(Double dip) {
return (int)(dip*SysData.scale + 0.5f*(dip>=0?1:-1));
}
//转换px为dip
public static int convertPX2DIP(int px) {
return (int)(px/SysData.scale + 0.5f*(px>=0?1:-1));
}
}

View File

@ -0,0 +1,51 @@
package com.util;
import android.app.Activity;
import android.content.Context;
import android.net.wifi.WifiManager;
import android.net.wifi.WifiManager.WifiLock;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
public class WakeLockUtil {
private static WifiLock wifiLock;
public static void acquireWakeLock(Activity activity, WakeLock wakeLock) {
if (wakeLock == null) {
PowerManager pm = (PowerManager) activity
.getSystemService(Context.POWER_SERVICE);
wakeLock = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK
| PowerManager.ACQUIRE_CAUSES_WAKEUP, "crtech");
}
if (wifiLock == null) {
WifiManager manager = (WifiManager) activity
.getSystemService(Context.WIFI_SERVICE);
wifiLock = manager.createWifiLock("SwiFTP");
wifiLock.setReferenceCounted(false);
}
if (wakeLock != null) {
System.out.println(wakeLock+"------------------锁定");
wakeLock.acquire();
System.out.println(wakeLock+"----------==--------锁定");
}
if (wifiLock != null) {
System.out.println("------------------wifi锁定");
wifiLock.acquire();
}
}
// 释放设备电源锁
public static void releaseWakeLock(WakeLock wakeLock) {
System.out.println("------------------解除锁定=====================");
if (wakeLock != null) {
wakeLock.release();
System.out.println("------------------解除锁定");
wakeLock = null;
}
if (wifiLock != null) {
wifiLock.release();
wifiLock = null;
}
}
}