CommonUtil.java 65 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316
  1. package com.jiaju.utils;
  2. import java.io.ByteArrayInputStream;
  3. import java.io.ByteArrayOutputStream;
  4. import java.io.File;
  5. import java.io.IOException;
  6. import java.io.InputStream;
  7. import java.io.ObjectInputStream;
  8. import java.io.ObjectOutputStream;
  9. import java.math.BigDecimal;
  10. import java.text.DateFormat;
  11. import java.text.DecimalFormat;
  12. import java.text.ParseException;
  13. import java.text.SimpleDateFormat;
  14. import java.util.ArrayList;
  15. import java.util.Calendar;
  16. import java.util.Date;
  17. import java.util.List;
  18. import java.util.Locale;
  19. import java.util.regex.Matcher;
  20. import java.util.regex.Pattern;
  21. import com.jiaju.activity.LoginActivity;
  22. import com.jiaju.activity.MakeBilletActivity;
  23. import com.jiaju.activity.R;
  24. import com.jiaju.model.BatchNoModel;
  25. import com.jiaju.model.CartInfo;
  26. import com.jiaju.model.DefectAndDefectDeductionRelation;
  27. import com.jiaju.model.DefectAndDefectFinesRelation;
  28. import com.jiaju.model.DefectDeduction;
  29. import com.jiaju.model.DefectFines;
  30. import com.jiaju.model.DefectLocation;
  31. import com.jiaju.model.DefectNo;
  32. import com.jiaju.model.DutyPerson;
  33. import com.jiaju.model.GlazeModel;
  34. import com.jiaju.model.KilnModel;
  35. import com.jiaju.model.Logo;
  36. import com.jiaju.model.NoGroutingReasonModel;
  37. import com.jiaju.model.PrinterModel;
  38. import com.jiaju.model.ProcedureJobs;
  39. import com.jiaju.model.ProductClassifyInfo;
  40. import com.jiaju.model.ProductDefectInfo;
  41. import com.jiaju.model.ResponsibilityProcedure;
  42. import com.jiaju.model.ReworkProcedureInfo;
  43. import com.jiaju.model.ScrapReason;
  44. import com.jiaju.model.SemiCheckStatus;
  45. import com.jiaju.model.WorkNo;
  46. import com.jiaju.model.WorkType;
  47. import android.annotation.SuppressLint;
  48. import android.annotation.TargetApi;
  49. import android.app.Activity;
  50. import android.app.AlertDialog;
  51. import android.app.Dialog;
  52. import android.app.Notification;
  53. import android.app.NotificationManager;
  54. import android.content.Context;
  55. import android.content.DialogInterface;
  56. import android.content.Intent;
  57. import android.content.pm.PackageInfo;
  58. import android.content.pm.PackageManager;
  59. import android.media.AudioFormat;
  60. import android.media.AudioManager;
  61. import android.media.AudioTrack;
  62. import android.media.MediaPlayer;
  63. import android.net.ConnectivityManager;
  64. import android.net.NetworkInfo;
  65. import android.net.Uri;
  66. import android.net.NetworkInfo.State;
  67. import android.net.wifi.WifiInfo;
  68. import android.net.wifi.WifiManager;
  69. import android.os.Build;
  70. import android.os.Environment;
  71. import android.os.IBinder;
  72. import android.os.Vibrator;
  73. import android.text.InputFilter;
  74. import android.text.Spanned;
  75. import android.view.MotionEvent;
  76. import android.view.View;
  77. import android.view.WindowManager;
  78. import android.view.inputmethod.InputMethodManager;
  79. import android.widget.EditText;
  80. @SuppressLint("NewApi")
  81. public class CommonUtil {
  82. static MediaPlayer mp;
  83. public static boolean isBlank(String str) {
  84. if (str == null || str.length() == 0
  85. || str.toLowerCase().equals("null")) {
  86. return true;
  87. }
  88. return false;
  89. }
  90. public static void deleteAllFiles(File root) {
  91. File files[] = root.listFiles();
  92. if (files != null)
  93. for (File f : files) {
  94. if (f.isDirectory()) { // 判断是否为文件夹
  95. deleteAllFiles(f);
  96. try {
  97. f.delete();
  98. } catch (Exception e) {
  99. }
  100. } else {
  101. if (f.exists()) { // 判断是否存在
  102. deleteAllFiles(f);
  103. try {
  104. f.delete();
  105. } catch (Exception e) {
  106. }
  107. }
  108. }
  109. }
  110. }
  111. public static String parseMoney(String pattern,BigDecimal bd){
  112. DecimalFormat df=new DecimalFormat(pattern);
  113. return df.format(bd);
  114. }
  115. public static String isContainsEnterCharacter(String txt){
  116. String code="";
  117. if(txt.contains("\n")){
  118. code = txt.trim().replaceAll("\\n", "");
  119. }
  120. else if(txt.contains("\r\n")){
  121. code = txt.trim().replaceAll("\\r\\n", "");
  122. }
  123. else if(txt.endsWith("\t")){
  124. code = txt.trim().replaceAll("\\t", "");
  125. }
  126. return code;
  127. }
  128. public static void hideKeyboard(MotionEvent event, View view,
  129. Activity activity) {
  130. try {
  131. if (view != null && view instanceof EditText) {
  132. int[] location = { 0, 0 };
  133. view.getLocationInWindow(location);
  134. int left = location[0], top = location[1], right = left
  135. + view.getWidth(), bootom = top + view.getHeight();
  136. // 判断焦点位置坐标是否在空间内,如果位置在控件外,则隐藏键盘
  137. if (event.getRawX() < left || event.getRawX() > right
  138. || event.getY() < top || event.getRawY() > bootom) {
  139. // 隐藏键盘
  140. IBinder token = view.getWindowToken();
  141. InputMethodManager inputMethodManager = (InputMethodManager) activity
  142. .getSystemService(Context.INPUT_METHOD_SERVICE);
  143. inputMethodManager.hideSoftInputFromWindow(token,
  144. InputMethodManager.HIDE_NOT_ALWAYS);
  145. }
  146. }
  147. } catch (Exception e) {
  148. e.printStackTrace();
  149. }
  150. }
  151. public static ResponsibilityProcedure getResponsibilityProcedureByProcedureId(
  152. List<ResponsibilityProcedure> procedureList, int procedureId) {
  153. ResponsibilityProcedure rp = null;
  154. for (ResponsibilityProcedure procedure : procedureList) {
  155. if (procedure.getDutyProcedureId() == procedureId) {
  156. rp = procedure;
  157. break;
  158. }
  159. }
  160. return rp;
  161. }
  162. public static DefectNo CompareDefectNo(List<DefectNo> defectNoList,
  163. String defectNo) {
  164. DefectNo localdefect = null;
  165. for (DefectNo defect : defectNoList) {
  166. String code = defect.getDefectCode();
  167. if (code.equals(defectNo)) {
  168. localdefect = defect;
  169. break;
  170. }
  171. }
  172. return localdefect;
  173. }
  174. public static DefectLocation CompareDefectLocation(
  175. List<DefectLocation> defectLocationList, String defectLocation) {
  176. DefectLocation location = null;
  177. for (DefectLocation defectlocation : defectLocationList) {
  178. String loccode = defectlocation.getDefectPositionCode();
  179. if (loccode.equals(defectLocation)) {
  180. location = defectlocation;
  181. break;
  182. }
  183. }
  184. return location;
  185. }
  186. public static String addSpecifiedDay(String today,int days){
  187. SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd");
  188. Date d;
  189. try {
  190. d = new Date(f.parse(today).getTime()+days*24*3600*1000);
  191. return f.format(d);
  192. } catch (ParseException e) {
  193. e.printStackTrace();
  194. return "";
  195. }
  196. }
  197. public static String dateStringConverter(String datestr) {
  198. Date date = null;
  199. String dateString = null;
  200. DateFormat format1 = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
  201. DateFormat format2 = new SimpleDateFormat("yyyy-MM-dd");
  202. try {
  203. date = format1.parse(datestr);
  204. dateString = format2.format(date);
  205. } catch (Exception e) {
  206. e.printStackTrace();
  207. }
  208. return dateString;
  209. }
  210. public static Date stringDateConverter(String dateStr) {
  211. Date date = null;
  212. DateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
  213. try {
  214. date = format1.parse(dateStr);
  215. } catch (Exception e) {
  216. e.printStackTrace();
  217. }
  218. return date;
  219. }
  220. public static String commonDateConverter(String datestr) {
  221. Date date = null;
  222. String dateString = null;
  223. DateFormat format1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  224. DateFormat format2 = new SimpleDateFormat("yyyy-MM-dd");
  225. try {
  226. date = format1.parse(datestr);
  227. dateString = format2.format(date);
  228. } catch (Exception e) {
  229. e.printStackTrace();
  230. }
  231. return dateString;
  232. }
  233. public static String dateFormatConverter(String datestr) {
  234. Date date = null;
  235. String dateString = null;
  236. DateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
  237. DateFormat format2 = new SimpleDateFormat("yyyyMMdd");
  238. try {
  239. date = format1.parse(datestr);
  240. dateString = format2.format(date);
  241. } catch (Exception e) {
  242. e.printStackTrace();
  243. }
  244. return dateString;
  245. }
  246. public static boolean checkDate(String date,String format) {
  247. DateFormat df = new SimpleDateFormat(format);
  248. Date d = null;
  249. try{
  250. d = df.parse(date);
  251. }catch(Exception e){
  252. //如果不能转换,肯定是错误格式
  253. return false;
  254. }
  255. String s1 = df.format(d);
  256. return date.equals(s1);
  257. }
  258. public static <T> List<T> deepCopy(List<T> src) throws IOException, ClassNotFoundException {
  259. ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
  260. ObjectOutputStream out = new ObjectOutputStream(byteOut);
  261. out.writeObject(src);
  262. ByteArrayInputStream byteIn = new ByteArrayInputStream(byteOut.toByteArray());
  263. ObjectInputStream in = new ObjectInputStream(byteIn);
  264. @SuppressWarnings("unchecked")
  265. List<T> dest = (List<T>) in.readObject();
  266. return dest;
  267. }
  268. public static KilnModel GetKilncode(String kilncode,
  269. List<KilnModel> kilncodelist) {
  270. KilnModel kilnmodel = null;
  271. for (KilnModel kiln : kilncodelist) {
  272. String currentKilnCode= kiln.getKilinCode();
  273. if (currentKilnCode.equalsIgnoreCase(kilncode)) {
  274. kilnmodel = kiln;
  275. break;
  276. }
  277. }
  278. return kilnmodel;
  279. }
  280. public static String dateConverter(String datestr) {
  281. Date date = null;
  282. String dateString = null;
  283. DateFormat format1 = new SimpleDateFormat("dd-MMM-yy HH:mm:ss",
  284. Locale.ENGLISH);
  285. DateFormat format2 = new SimpleDateFormat("yyyy-MM-dd");
  286. try {
  287. date = format1.parse(datestr);
  288. dateString = format2.format(date);
  289. } catch (Exception e) {
  290. e.printStackTrace();
  291. }
  292. return dateString;
  293. }
  294. public static int getDefectProductionDataIdByUserId(
  295. List<WorkNo> worknolist, int userId) {
  296. int defectProductionDataId = 0;
  297. for (int i = 0; i < worknolist.size(); i++) {
  298. WorkNo wn = worknolist.get(i);
  299. if (wn.getUserId() == userId) {
  300. defectProductionDataId = (int) wn.getProductionDataId();
  301. break;
  302. }
  303. }
  304. return defectProductionDataId;
  305. }
  306. public static boolean compareStaffInfo(List<DutyPerson> dutyPersonList,
  307. DutyPerson dp) {
  308. boolean result = false;
  309. for (int i = 0; i < dutyPersonList.size(); i++) {
  310. DutyPerson dutyperson = dutyPersonList.get(i);
  311. if (dp.getuJobsId() == dutyperson.getuJobsId()
  312. && dp.getStaffCode().equals(dutyperson.getStaffCode())) {
  313. result = true;
  314. }
  315. }
  316. return result;
  317. }
  318. public static void BarcodeMaxLength(EditText edt, int maxLength) {
  319. edt.setFilters(new InputFilter[] { new InputFilter.LengthFilter(
  320. maxLength) });
  321. }
  322. public static String getSpecifiedDayAfter(String specifiedDay) {
  323. Calendar c = Calendar.getInstance();
  324. Date date = null;
  325. try {
  326. date = new SimpleDateFormat("yyyy-MM-dd").parse(specifiedDay);
  327. } catch (ParseException e) {
  328. e.printStackTrace();
  329. }
  330. c.setTime(date);
  331. int day = c.get(Calendar.DATE);
  332. c.set(Calendar.DATE, day + 1);
  333. String dayAfter = new SimpleDateFormat("yyyy-MM-dd")
  334. .format(c.getTime());
  335. return dayAfter;
  336. }
  337. public static void removeDuplicateCartList(List<CartInfo> cartlist) {
  338. for (int i = cartlist.size() - 1; i > 0; i--) {
  339. CartInfo item = cartlist.get(i);
  340. for (int j = i - 1; j >= 0; j--) {
  341. if (cartlist.get(j).getBarcode().equals(item.getBarcode())) {
  342. cartlist.remove(i);
  343. break;
  344. }
  345. }
  346. }
  347. }
  348. public static boolean CompareDate(String systemDate, String currentDate) {
  349. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  350. Date system;
  351. boolean compareresult = false;
  352. try {
  353. system = sdf.parse(systemDate);
  354. Date current = sdf.parse(currentDate);
  355. if (current.before(system)) {
  356. compareresult = false;
  357. } else {
  358. compareresult = true;
  359. }
  360. } catch (ParseException e) {
  361. // TODO Auto-generated catch block
  362. e.printStackTrace();
  363. }
  364. return compareresult;
  365. }
  366. public static void playSound(Context context) {
  367. try {
  368. mp = MediaPlayer.create(context, R.raw.sound);
  369. final AudioManager audioMgr = (AudioManager) context
  370. .getSystemService(Context.AUDIO_SERVICE);
  371. // final int
  372. // currentVolume=audioMgr.getStreamVolume(AudioManager.STREAM_SYSTEM);
  373. int maxVolume = audioMgr
  374. .getStreamMaxVolume(AudioManager.STREAM_MUSIC);
  375. audioMgr.setStreamVolume(AudioManager.STREAM_MUSIC, maxVolume,
  376. AudioManager.FLAG_PLAY_SOUND);
  377. mp.start();
  378. mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
  379. // @Override
  380. /* 覆盖文件播出完毕事件 */
  381. public void onCompletion(MediaPlayer arg0) {
  382. mp.release();
  383. // audioMgr.setStreamVolume(AudioManager.STREAM_SYSTEM,currentVolume,AudioManager.FLAG_PLAY_SOUND);
  384. }
  385. });
  386. mp.setOnErrorListener(new MediaPlayer.OnErrorListener() {
  387. @Override
  388. /* 覆盖错误处理事件 */
  389. public boolean onError(MediaPlayer arg0, int arg1, int arg2) {
  390. /* 发生错误时也解除资源与MediaPlayer的赋值 */
  391. mp.release();
  392. return false;
  393. }
  394. });
  395. } catch (Exception e) {
  396. e.printStackTrace();
  397. }
  398. }
  399. public static void playAlertSound(Context context) {
  400. try {
  401. mp = MediaPlayer.create(context, R.raw.alert);
  402. final AudioManager audioMgr = (AudioManager) context
  403. .getSystemService(Context.AUDIO_SERVICE);
  404. // final int
  405. // currentVolume=audioMgr.getStreamVolume(AudioManager.STREAM_SYSTEM);
  406. int maxVolume = audioMgr
  407. .getStreamMaxVolume(AudioManager.STREAM_MUSIC);
  408. audioMgr.setStreamVolume(AudioManager.STREAM_MUSIC, maxVolume,
  409. AudioManager.FLAG_PLAY_SOUND);
  410. mp.start();
  411. mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
  412. // @Override
  413. /* 覆盖文件播出完毕事件 */
  414. public void onCompletion(MediaPlayer arg0) {
  415. mp.release();
  416. // audioMgr.setStreamVolume(AudioManager.STREAM_SYSTEM,currentVolume,AudioManager.FLAG_PLAY_SOUND);
  417. }
  418. });
  419. mp.setOnErrorListener(new MediaPlayer.OnErrorListener() {
  420. @Override
  421. /* 覆盖错误处理事件 */
  422. public boolean onError(MediaPlayer arg0, int arg1, int arg2) {
  423. /* 发生错误时也解除资源与MediaPlayer的赋值 */
  424. mp.release();
  425. return false;
  426. }
  427. });
  428. } catch (Exception e) {
  429. e.printStackTrace();
  430. }
  431. }
  432. public static byte[] getFromAssets(Context context, String fileName) {
  433. byte[] buffer = null;
  434. try {
  435. InputStream in = context.getResources().getAssets().open(fileName);
  436. // 获取文件的字节数
  437. int lenght = in.available();
  438. // 创建byte数组
  439. buffer = new byte[lenght];
  440. // 将文件中的数据读到byte数组中
  441. in.read(buffer);
  442. } catch (Exception e) {
  443. e.printStackTrace();
  444. }
  445. return buffer;
  446. }
  447. public static byte[] getFromRaw(Context context, int fileName) {
  448. byte[] buffer = null;
  449. try {
  450. InputStream in = context.getResources().openRawResource(fileName);
  451. // 获取文件的字节数
  452. int length = in.available();
  453. // 创建byte数组
  454. buffer = new byte[length];
  455. // 将文件中的数据读到byte数组中
  456. in.read(buffer);
  457. } catch (Exception e) {
  458. e.printStackTrace();
  459. }
  460. return buffer;
  461. }
  462. public static String getVersionName(Context context) throws Exception {
  463. // 获取packagemanager的实例
  464. PackageManager packageManager = context.getPackageManager();
  465. // getPackageName()是你当前类的包名,0代表是获取版本信息
  466. PackageInfo packInfo = packageManager.getPackageInfo(
  467. context.getPackageName(), 0);
  468. String version = packInfo.versionName;
  469. return version;
  470. }
  471. public static void playSound(Context context, byte[] soundData) {
  472. int index = 0;
  473. int offset = 0;
  474. final int minBufsize = AudioTrack.getMinBufferSize(44100,
  475. AudioFormat.CHANNEL_OUT_STEREO,// The channel
  476. AudioFormat.ENCODING_PCM_16BIT);
  477. AudioTrack aAudioTrack01 = new AudioTrack(AudioManager.STREAM_MUSIC,
  478. 44100, AudioFormat.CHANNEL_OUT_STEREO,
  479. AudioFormat.ENCODING_PCM_16BIT, minBufsize,
  480. AudioTrack.MODE_STREAM);
  481. AudioManager am = (AudioManager) context
  482. .getSystemService(Context.AUDIO_SERVICE);
  483. // am.setStreamVolume(AudioManager.STREAM_MUSIC,
  484. // am.getStreamMaxVolume(AudioManager.STREAM_MUSIC),
  485. // AudioManager.FLAG_PLAY_SOUND);
  486. aAudioTrack01.play();
  487. while (true) {
  488. try {
  489. offset = index * minBufsize;
  490. if (offset >= soundData.length) {
  491. break;
  492. }
  493. aAudioTrack01.write(soundData, offset, minBufsize);
  494. } catch (Exception e) {
  495. break;
  496. }
  497. index++;
  498. }
  499. aAudioTrack01.release();
  500. }
  501. public static String getRootFilePath() {
  502. if (hasSDCard()) {
  503. return Environment.getExternalStorageDirectory().getAbsolutePath()
  504. + "";
  505. } else {
  506. return Environment.getDataDirectory().getAbsolutePath() + "/data";
  507. }
  508. }
  509. public static int getTrademarkIndex(String trademarkCode,
  510. List<Logo> trademarkList) {
  511. int newposition = -1;
  512. for (int position = 0; position < trademarkList.size(); position++) {
  513. if (trademarkCode.equalsIgnoreCase((trademarkList.get(position)
  514. .getLogoCode()))) {
  515. newposition = position;
  516. break;
  517. }
  518. }
  519. return newposition;
  520. }
  521. public static int getGlazeIndex(String glazeName,
  522. List<GlazeModel> glazeList) {
  523. int newposition = -1;
  524. for (int position = 0; position < glazeList.size(); position++) {
  525. if (glazeName.equals(glazeList.get(position).getGlazeName())) {
  526. newposition = position;
  527. break;
  528. }
  529. }
  530. return newposition;
  531. }
  532. public static int getPrinterIndex(String printerName,List<PrinterModel> printerList){
  533. int newposition=-1;
  534. for(int position=0;position<printerList.size();position++) {
  535. if(printerName.equalsIgnoreCase(printerList.get(position).getPrinterName())){
  536. newposition=position;
  537. break;
  538. }
  539. }
  540. return newposition;
  541. }
  542. public static int getNoGroutingReasonIndex(int noGroutingReasonId,List<NoGroutingReasonModel> noGroutingReasonList){
  543. int newposition=-1;
  544. for(int position=0;position<noGroutingReasonList.size();position++) {
  545. if(noGroutingReasonId==Integer.parseInt(noGroutingReasonList.get(position).getReasonId())){
  546. newposition=position;
  547. break;
  548. }
  549. }
  550. return newposition;
  551. }
  552. public static int getWorkNoIndex(WorkNo updateWorkno,
  553. List<WorkNo> worknolist) {
  554. int newposition = 0;
  555. for (int position = 0; position < worknolist.size(); position++) {
  556. if (updateWorkno.getUserId() == (worknolist.get(position)
  557. .getUserId())) {
  558. newposition = position;
  559. }
  560. }
  561. return newposition;
  562. }
  563. public static int getSemiCheckStatusIndex(int semiCheckStatusId,
  564. List<SemiCheckStatus> semiCheckStatusList) {
  565. int newposition = 0;
  566. for (int position = 0; position < semiCheckStatusList.size(); position++) {
  567. if (semiCheckStatusId == Integer.parseInt(semiCheckStatusList.get(
  568. position).getSemiCheckTypeId())) {
  569. newposition = position;
  570. }
  571. }
  572. return newposition;
  573. }
  574. public static int getResponsibilityProcedureIndex(
  575. ResponsibilityProcedure updateProcedure,
  576. List<ResponsibilityProcedure> procedurelist) {
  577. int newposition = 0;
  578. for (int position = 0; position < procedurelist.size(); position++) {
  579. if (updateProcedure.getDutyProcedureId() == (procedurelist
  580. .get(position).getDutyProcedureId())) {
  581. newposition = position;
  582. }
  583. }
  584. return newposition;
  585. }
  586. public static int getResponsibilityProcedureIndexById(int procedureId,
  587. List<ResponsibilityProcedure> procedurelist) {
  588. int newposition = 0;
  589. for (int position = 0; position < procedurelist.size(); position++) {
  590. if (procedureId == (procedurelist.get(position)
  591. .getDutyProcedureId())) {
  592. newposition = position;
  593. }
  594. }
  595. return newposition;
  596. }
  597. public static ResponsibilityProcedure getResponsibilityProcedureById(
  598. int procedureId, List<ResponsibilityProcedure> procedurelist) {
  599. ResponsibilityProcedure rp = null;
  600. for (int position = 0; position < procedurelist.size(); position++) {
  601. if (procedureId == (procedurelist.get(position)
  602. .getDutyProcedureId())) {
  603. rp = procedurelist.get(position);
  604. break;
  605. }
  606. }
  607. return rp;
  608. }
  609. public static ResponsibilityProcedure getCompleteResonsibilityProcedureById(
  610. int procedureId, List<ResponsibilityProcedure> procedurelist) {
  611. ResponsibilityProcedure rp = null;
  612. for (ResponsibilityProcedure proc : procedurelist) {
  613. if (procedureId == proc.getDutyProcedureId()) {
  614. rp = proc;
  615. break;
  616. }
  617. }
  618. return rp;
  619. }
  620. public static String getIpAddress(Context con) {
  621. // TODO Auto-generated method stub
  622. // 获取wifi服务
  623. WifiManager wifiManager = (WifiManager) con
  624. .getSystemService(Context.WIFI_SERVICE);
  625. // 判断wifi是否开启
  626. if (!wifiManager.isWifiEnabled()) {
  627. wifiManager.setWifiEnabled(true);
  628. }
  629. WifiInfo wifiInfo = wifiManager.getConnectionInfo();
  630. int ipAddress = wifiInfo.getIpAddress();
  631. String ip = intToIp(ipAddress);
  632. return ip;
  633. }
  634. public static void installApk(String installFilePath, Context context) {
  635. File apkfile = new File(installFilePath);
  636. if (!apkfile.exists()) {
  637. return;
  638. }
  639. Intent i = new Intent(Intent.ACTION_VIEW);
  640. i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  641. i.setDataAndType(Uri.parse("file://" + apkfile.toString()),
  642. "application/vnd.android.package-archive");
  643. context.startActivity(i);
  644. android.os.Process.killProcess(android.os.Process.myPid());
  645. }
  646. private static String intToIp(int i) {
  647. return (i & 0xFF) + "." + ((i >> 8) & 0xFF) + "." + ((i >> 16) & 0xFF)
  648. + "." + (i >> 24 & 0xFF);
  649. }
  650. public static int getWorktypeIndexByJobsId(int jobsId,
  651. List<WorkType> worktypeList) {
  652. int position = 0;
  653. for (int i = 0; i < worktypeList.size(); i++) {
  654. if (jobsId == worktypeList.get(i).getJobsID()) {
  655. position = i;
  656. break;
  657. }
  658. }
  659. return position;
  660. }
  661. public static WorkType getWorktypeByJobsId(int jobsId,
  662. List<WorkType> worktypeList) {
  663. WorkType wt = null;
  664. for (int i = 0; i < worktypeList.size(); i++) {
  665. if (jobsId == worktypeList.get(i).getJobsID()) {
  666. wt = worktypeList.get(i);
  667. break;
  668. }
  669. }
  670. return wt;
  671. }
  672. public static ReworkProcedureInfo getReworkProcedureInfoByName(
  673. String reworkProcedureName,
  674. List<ReworkProcedureInfo> reworkProcedureList) {
  675. ReworkProcedureInfo reworkProcedureInfo = null;
  676. for (int i = 0; i < reworkProcedureList.size(); i++) {
  677. if (reworkProcedureName.equals(reworkProcedureList.get(i)
  678. .getReworkProcedureName())) {
  679. reworkProcedureInfo = reworkProcedureList.get(i);
  680. break;
  681. }
  682. }
  683. return reworkProcedureInfo;
  684. }
  685. public static int getScrapReasonIndex(String sr,
  686. List<ScrapReason> scrapReasonList) {
  687. int newposition = 0;
  688. for (int i = 0; i < scrapReasonList.size(); i++) {
  689. if (sr.equals(scrapReasonList.get(i).getDictionaryValue())) {
  690. newposition = i;
  691. }
  692. }
  693. return newposition;
  694. }
  695. public static boolean CompareKilncode(String kilncode,
  696. List<String> kilncodelist) {
  697. boolean kilnflag = false;
  698. for (String kiln : kilncodelist) {
  699. if (kiln.equalsIgnoreCase(kilncode)) {
  700. kilnflag = true;
  701. }
  702. }
  703. return kilnflag;
  704. }
  705. public static List<DefectFines> CompareDefectFinesResult(
  706. List<DefectFines> orgDefectFinesList,
  707. List<DefectFines> destDefectFinesList) {
  708. List<DefectFines> defectFinesResultList = new ArrayList<DefectFines>();
  709. if (orgDefectFinesList == null) {
  710. defectFinesResultList.addAll(destDefectFinesList);
  711. } else {
  712. for (DefectFines defectFines : orgDefectFinesList) {
  713. if (destDefectFinesList.contains(defectFines)) {
  714. defectFinesResultList.add(defectFines);
  715. }
  716. }
  717. if (defectFinesResultList.size() == 0) {
  718. defectFinesResultList.addAll(destDefectFinesList);
  719. } else {
  720. DefectFines df1 = new DefectFines();
  721. df1.setDefectFinesId(0);
  722. df1.setDefectFinesName("请选择缺陷扣罚");
  723. defectFinesResultList.add(0, df1);
  724. }
  725. }
  726. return defectFinesResultList;
  727. }
  728. public static List<DefectDeduction> CompareDefectDeductionResult(
  729. List<DefectDeduction> orgDefectDeductionList,
  730. List<DefectDeduction> destDefectDeductionList) {
  731. List<DefectDeduction> defectDeductionResultList = new ArrayList<DefectDeduction>();
  732. if (orgDefectDeductionList == null) {
  733. defectDeductionResultList.addAll(destDefectDeductionList);
  734. } else {
  735. for (DefectDeduction defectDeduction : orgDefectDeductionList) {
  736. if (destDefectDeductionList.contains(defectDeduction)) {
  737. defectDeductionResultList.add(defectDeduction);
  738. }
  739. }
  740. if (defectDeductionResultList.size() == 0) {
  741. defectDeductionResultList.addAll(destDefectDeductionList);
  742. } else {
  743. DefectDeduction df4 = new DefectDeduction();
  744. df4.setDefectDeductionId(0);
  745. df4.setDefectDeductionNum("请选择缺陷扣除数");
  746. defectDeductionResultList.add(0, df4);
  747. }
  748. }
  749. return defectDeductionResultList;
  750. }
  751. public static boolean isCurrency(String s) {
  752. Pattern p = Pattern.compile(
  753. "^(([1-9]{1}\\d{0,4})|([0]{1}))(\\.(\\d){0,2})?$",
  754. Pattern.CASE_INSENSITIVE);
  755. Matcher m = p.matcher(s);
  756. return m.matches();
  757. }
  758. public static boolean isInteger(String s) {
  759. Pattern p = Pattern.compile(
  760. "^([1-9]{1}\\d{0,5})?$",
  761. Pattern.CASE_INSENSITIVE);
  762. Matcher m = p.matcher(s);
  763. return m.matches();
  764. }
  765. public static boolean isPositveInteger(String s) {
  766. Pattern p = Pattern.compile("^([1-9]{1}\\d{0,1})|([0]{1})?$",
  767. Pattern.CASE_INSENSITIVE);
  768. Matcher m = p.matcher(s);
  769. return m.matches();
  770. }
  771. public static String getMacFromWifi(Context context) {
  772. ConnectivityManager connectivityManager = (ConnectivityManager) context
  773. .getSystemService(Context.CONNECTIVITY_SERVICE);
  774. State wifiState = connectivityManager.getNetworkInfo(
  775. ConnectivityManager.TYPE_WIFI).getState();
  776. if (wifiState == NetworkInfo.State.CONNECTED) {// 判断当前是否使用wifi连接
  777. WifiManager wifiManager = (WifiManager) context
  778. .getSystemService(Context.WIFI_SERVICE);
  779. if (!wifiManager.isWifiEnabled()) { // 如果当前wifi不可用
  780. wifiManager.setWifiEnabled(true);
  781. }
  782. WifiInfo wifiInfo = wifiManager.getConnectionInfo();
  783. return wifiInfo.getMacAddress();
  784. }
  785. return null;
  786. }
  787. public static boolean isNumber(String s) {
  788. Pattern p = Pattern.compile("[0-9]*");
  789. Matcher m = p.matcher(s);
  790. return m.matches();
  791. }
  792. public static List<DutyPerson> CompareDutyPersonList(
  793. List<DutyPerson> originalList, List<DutyPerson> newDutyPersonList) {
  794. List<DutyPerson> dutyPersonList = null;
  795. for (int i = 0; i < originalList.size(); i++) {
  796. int originalstaffId = originalList.get(i).getStaffId();
  797. for (int j = 0; j < newDutyPersonList.size(); j++) {
  798. DutyPerson newdp = newDutyPersonList.get(j);
  799. int newdpId = newdp.getStaffId();
  800. if (originalstaffId == newdpId) {
  801. newdp.setCheckStatus(true);
  802. newDutyPersonList.set(j, newdp);
  803. }
  804. }
  805. }
  806. dutyPersonList = newDutyPersonList;
  807. return dutyPersonList;
  808. }
  809. public static int getAuditStatusIndexById(int auditStatusId,
  810. List<DefectFines> auditList) {
  811. int newposition = 0;
  812. for (int position = 0; position < auditList.size(); position++) {
  813. if (auditStatusId == (auditList.get(position).getDefectFinesId())) {
  814. newposition = position;
  815. }
  816. }
  817. return newposition;
  818. }
  819. public static int getJobsIdByProcedureId(int procedureId,
  820. List<ProcedureJobs> procedureJobList) {
  821. int jobsId = 0;
  822. for (ProcedureJobs pj : procedureJobList) {
  823. if (pj.getProcedureId() == procedureId) {
  824. jobsId = pj.getJobsId();
  825. break;
  826. }
  827. }
  828. return jobsId;
  829. }
  830. public static int getReworkProcedureId(int reworkProcedureId,
  831. List<ReworkProcedureInfo> reworkProcedureList) {
  832. int newposition = 0;
  833. for (int position = 0; position < reworkProcedureList.size(); position++) {
  834. if (reworkProcedureId == Integer.parseInt(reworkProcedureList.get(
  835. position).getReworkProcedureID())) {
  836. newposition = position;
  837. }
  838. }
  839. return newposition;
  840. }
  841. public static void showRepeatDialog(String message, final Context con) {
  842. Dialog alertDialog = new AlertDialog.Builder(con).setMessage(message)
  843. .setPositiveButton("确定", new DialogInterface.OnClickListener() {
  844. @Override
  845. public void onClick(DialogInterface dialog, int which) {
  846. return;
  847. }
  848. }).create();
  849. alertDialog.show();
  850. }
  851. public static int getWorkTypeIndex(WorkType updateWorkType,
  852. List<WorkType> worktypelist) {
  853. int newposition = 0;
  854. for (int position = 0; position < worktypelist.size(); position++) {
  855. if (updateWorkType.getJobsID() == (worktypelist.get(position)
  856. .getJobsID())) {
  857. newposition = position;
  858. }
  859. }
  860. return newposition;
  861. }
  862. public static int getGroutingBatchNoIndex(String batchNo,List<BatchNoModel> batchNoList)
  863. {
  864. int position=-1;
  865. if(batchNoList!=null&&batchNoList.size()>0)
  866. {
  867. for(int i=0;i<batchNoList.size();i++)
  868. {
  869. BatchNoModel batchNoModel=batchNoList.get(i);
  870. if(Double.parseDouble(batchNo)==Double.parseDouble(batchNoModel.getBatchNo()))
  871. {
  872. position=i;
  873. break;
  874. }
  875. }
  876. }
  877. return position;
  878. }
  879. public static int getProductClassifyIndex(int goodsLevelTypeId,
  880. List<ProductClassifyInfo> productClassifyList) {
  881. int newposition = 0;
  882. for (int position = 0; position < productClassifyList.size(); position++) {
  883. if (goodsLevelTypeId == productClassifyList.get(position)
  884. .getGoodsLevelTypeID()) {
  885. newposition = position;
  886. }
  887. }
  888. return newposition;
  889. }
  890. public static boolean compareProductDefectInfoList(
  891. List<ProductDefectInfo> originalProductDefectInfoList,
  892. ProductDefectInfo newProductDefectInfo) {
  893. boolean isEquals = false;
  894. for (ProductDefectInfo original : originalProductDefectInfoList) {
  895. if (newProductDefectInfo.getDefectNo().getDefectId() == original
  896. .getDefectNo().getDefectId()
  897. && newProductDefectInfo.getDefectLocation()
  898. .getDefectPositionId() == original
  899. .getDefectLocation().getDefectPositionId()
  900. && newProductDefectInfo.getResponsibilityProcedure()
  901. .getDutyProcedureId() == original
  902. .getResponsibilityProcedure().getDutyProcedureId()
  903. && newProductDefectInfo.getWorkno().getUserId() == original
  904. .getWorkno().getUserId()
  905. && newProductDefectInfo.getWorkType().getJobsID() == original
  906. .getWorkType().getJobsID()) {
  907. isEquals = true;
  908. }
  909. }
  910. return isEquals;
  911. }
  912. public static boolean compareCheckCollectDefectInfoList(
  913. List<ProductDefectInfo> originalProductDefectInfoList,
  914. ProductDefectInfo newProductDefectInfo) {
  915. boolean isEquals = false;
  916. for (ProductDefectInfo original : originalProductDefectInfoList) {
  917. if (newProductDefectInfo.getDefectNo().getDefectId() == original
  918. .getDefectNo().getDefectId()
  919. && newProductDefectInfo.getDefectLocation()
  920. .getDefectPositionId() == original
  921. .getDefectLocation().getDefectPositionId()
  922. && newProductDefectInfo.getWorkno().getUserId() == original
  923. .getWorkno().getUserId()) {
  924. isEquals = true;
  925. }
  926. }
  927. return isEquals;
  928. }
  929. public static boolean hasSDCard() {
  930. String status = Environment.getExternalStorageState();
  931. if (!status.equals(Environment.MEDIA_MOUNTED)) {
  932. return false;
  933. }
  934. return true;
  935. }
  936. public static boolean CompareServerVersion(String localVersion,
  937. String ServerVersion) {
  938. boolean b = false;
  939. String localVersionNo = localVersion.replace(".", "");
  940. String serverVersionNo = ServerVersion.replace(".", "");
  941. if (localVersionNo.startsWith("0")) {
  942. localVersionNo = localVersionNo.replaceFirst("^0*", "");
  943. }
  944. if (serverVersionNo.startsWith("0"))
  945. {
  946. serverVersionNo = serverVersionNo.replaceFirst("^0*", "");
  947. }
  948. if (Long.parseLong(serverVersionNo) > Long.parseLong(localVersionNo)) {
  949. b = true;
  950. }
  951. return b;
  952. }
  953. public static void setDefault(int defaults, Context context) {
  954. int NOTIFICATIONS_ID = 1;
  955. NotificationManager mNotificationManager;
  956. final Notification notification = new Notification();
  957. notification.defaults = defaults;
  958. mNotificationManager = (NotificationManager) context
  959. .getSystemService(context.NOTIFICATION_SERVICE);
  960. mNotificationManager.notify(NOTIFICATIONS_ID, notification);
  961. }
  962. //
  963. // @SuppressLint("NewApi") 警告去掉
  964. // public static void setDefault(int defaults,Context context) {
  965. // Vibrator v = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
  966. // if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
  967. // v.vibrate(VibrationEffect.createOneShot(500, VibrationEffect.DEFAULT_AMPLITUDE));
  968. // }
  969. // else
  970. // {
  971. //
  972. // int NOTIFICATIONS_ID = 1;
  973. // NotificationManager mNotificationManager;
  974. // final Notification notification = new Notification();
  975. // notification.defaults = defaults;
  976. // mNotificationManager = (NotificationManager) context
  977. // .getSystemService(context.NOTIFICATION_SERVICE);
  978. // mNotificationManager.notify(NOTIFICATIONS_ID, notification);
  979. // //deprecated in API 26
  980. // // v.vibrate(500);
  981. // }
  982. //
  983. // }
  984. public static void showAlertDialog(final int status, String message,
  985. final Context con) {
  986. Dialog alertDialog = new AlertDialog.Builder(con).setMessage(message)
  987. .setPositiveButton("确定", new DialogInterface.OnClickListener() {
  988. @Override
  989. public void onClick(DialogInterface dialog, int which) {
  990. if (status == -1 || status == -2 || status == -3) {
  991. ExitUtil eu = new ExitUtil(con);
  992. eu.exit();
  993. }
  994. else if (status == 0) {
  995. return;
  996. } else {
  997. return;
  998. }
  999. }
  1000. }).create();
  1001. alertDialog.setCanceledOnTouchOutside(false);
  1002. alertDialog.show();
  1003. }
  1004. public static void showWorkNoAlertDialog(final int status, String message,
  1005. final Context con, final EditText worknotxt,
  1006. final EditText barcodeEdt, final EditText bugnoEdt,
  1007. final EditText buglocEdt, final int collectType) {
  1008. Dialog alertDialog = new AlertDialog.Builder(con).setMessage(message)
  1009. .setPositiveButton("确定", new DialogInterface.OnClickListener() {
  1010. @Override
  1011. public void onClick(DialogInterface dialog, int which) {
  1012. if (status == -1 || status == -2 || status == -3) {
  1013. ExitUtil eu = new ExitUtil(con);
  1014. eu.exit();
  1015. }
  1016. else if (status == 0) {
  1017. if (collectType == 1) {
  1018. worknotxt.setEnabled(true);
  1019. worknotxt.setText("");
  1020. worknotxt.setFocusable(true);
  1021. worknotxt.setFocusableInTouchMode(true);
  1022. worknotxt.requestFocus();
  1023. worknotxt.findFocus();
  1024. worknotxt
  1025. .setFilters(new InputFilter[] { new InputFilter() {
  1026. @Override
  1027. public CharSequence filter(
  1028. CharSequence source,
  1029. int start, int end,
  1030. Spanned dest, int dstart,
  1031. int dend) {
  1032. return null;
  1033. }
  1034. } });
  1035. barcodeEdt.setEnabled(true);
  1036. barcodeEdt.setText("");
  1037. barcodeEdt.setFocusable(true);
  1038. barcodeEdt.setFocusableInTouchMode(true);
  1039. barcodeEdt
  1040. .setFilters(new InputFilter[] { new InputFilter() {
  1041. @Override
  1042. public CharSequence filter(
  1043. CharSequence source,
  1044. int start, int end,
  1045. Spanned dest, int dstart,
  1046. int dend) {
  1047. return null;
  1048. }
  1049. } });
  1050. //CommonUtil.BarcodeMaxLength(barcodeEdt, 50);
  1051. if (bugnoEdt != null) {
  1052. bugnoEdt.setEnabled(true);
  1053. bugnoEdt.setText("");
  1054. bugnoEdt.setFocusable(true);
  1055. bugnoEdt.setFocusableInTouchMode(true);
  1056. bugnoEdt.setFilters(new InputFilter[] { new InputFilter() {
  1057. @Override
  1058. public CharSequence filter(
  1059. CharSequence source, int start,
  1060. int end, Spanned dest,
  1061. int dstart, int dend) {
  1062. return null;
  1063. }
  1064. } });
  1065. }
  1066. if (buglocEdt != null) {
  1067. buglocEdt.setEnabled(true);
  1068. buglocEdt.setText("");
  1069. buglocEdt.setFocusable(true);
  1070. buglocEdt.setFocusableInTouchMode(true);
  1071. buglocEdt
  1072. .setFilters(new InputFilter[] { new InputFilter() {
  1073. @Override
  1074. public CharSequence filter(
  1075. CharSequence source,
  1076. int start, int end,
  1077. Spanned dest,
  1078. int dstart, int dend) {
  1079. return null;
  1080. }
  1081. } });
  1082. }
  1083. } else {
  1084. Activity activity = (Activity) con;
  1085. activity.finish();
  1086. }
  1087. return;
  1088. }
  1089. else {
  1090. if (collectType == 1) {
  1091. worknotxt.setEnabled(true);
  1092. worknotxt.setText("");
  1093. worknotxt.setFocusable(true);
  1094. worknotxt.setFocusableInTouchMode(true);
  1095. worknotxt.requestFocus();
  1096. worknotxt.findFocus();
  1097. worknotxt
  1098. .setFilters(new InputFilter[] { new InputFilter() {
  1099. @Override
  1100. public CharSequence filter(
  1101. CharSequence source,
  1102. int start, int end,
  1103. Spanned dest, int dstart,
  1104. int dend) {
  1105. return null;
  1106. }
  1107. } });
  1108. InputMethodManager im = (InputMethodManager) worknotxt
  1109. .getContext().getSystemService(
  1110. Context.INPUT_METHOD_SERVICE);
  1111. im.hideSoftInputFromWindow(
  1112. worknotxt.getWindowToken(),
  1113. InputMethodManager.HIDE_NOT_ALWAYS);
  1114. barcodeEdt.setEnabled(true);
  1115. barcodeEdt.setText("");
  1116. barcodeEdt.setFocusable(true);
  1117. barcodeEdt.setFocusableInTouchMode(true);
  1118. barcodeEdt
  1119. .setFilters(new InputFilter[] { new InputFilter() {
  1120. @Override
  1121. public CharSequence filter(
  1122. CharSequence source,
  1123. int start, int end,
  1124. Spanned dest, int dstart,
  1125. int dend) {
  1126. return null;
  1127. }
  1128. } });
  1129. //CommonUtil.BarcodeMaxLength(barcodeEdt, 50);
  1130. if (bugnoEdt != null) {
  1131. bugnoEdt.setEnabled(true);
  1132. bugnoEdt.setText("");
  1133. bugnoEdt.setFocusable(true);
  1134. bugnoEdt.setFocusableInTouchMode(true);
  1135. bugnoEdt.setFilters(new InputFilter[] { new InputFilter() {
  1136. @Override
  1137. public CharSequence filter(
  1138. CharSequence source, int start,
  1139. int end, Spanned dest,
  1140. int dstart, int dend) {
  1141. return null;
  1142. }
  1143. } });
  1144. }
  1145. if (buglocEdt != null) {
  1146. buglocEdt.setEnabled(true);
  1147. buglocEdt.setText("");
  1148. buglocEdt.setFocusable(true);
  1149. buglocEdt.setFocusableInTouchMode(true);
  1150. buglocEdt
  1151. .setFilters(new InputFilter[] { new InputFilter() {
  1152. @Override
  1153. public CharSequence filter(
  1154. CharSequence source,
  1155. int start, int end,
  1156. Spanned dest,
  1157. int dstart, int dend) {
  1158. return null;
  1159. }
  1160. } });
  1161. }
  1162. } else {
  1163. Activity activity = (Activity) con;
  1164. activity.finish();
  1165. }
  1166. return;
  1167. }
  1168. }
  1169. }).create();
  1170. alertDialog.setCanceledOnTouchOutside(false);
  1171. alertDialog.show();
  1172. }
  1173. public static void showKilncarWorkNoAlertDialog(final int status,
  1174. String message, final Context con, final EditText worknotxt,
  1175. final EditText barcodeEdt, final EditText kilnEdt,
  1176. final EditText kilncarEdt, final int collectType) {
  1177. Dialog alertDialog = new AlertDialog.Builder(con).setMessage(message)
  1178. .setPositiveButton("确定", new DialogInterface.OnClickListener() {
  1179. @Override
  1180. public void onClick(DialogInterface dialog, int which) {
  1181. if (status == -1 || status == -2 || status == -3) {
  1182. ExitUtil eu = new ExitUtil(con);
  1183. eu.exit();
  1184. }
  1185. else if (status == 0) {
  1186. if (collectType == 1) {
  1187. worknotxt.setEnabled(true);
  1188. worknotxt.setText("");
  1189. worknotxt.setFocusable(true);
  1190. worknotxt.setFocusableInTouchMode(true);
  1191. worknotxt.requestFocus();
  1192. worknotxt.findFocus();
  1193. worknotxt
  1194. .setFilters(new InputFilter[] { new InputFilter() {
  1195. @Override
  1196. public CharSequence filter(
  1197. CharSequence source,
  1198. int start, int end,
  1199. Spanned dest, int dstart,
  1200. int dend) {
  1201. return null;
  1202. }
  1203. } });
  1204. kilnEdt.setEnabled(true);
  1205. kilnEdt.setFocusable(true);
  1206. kilnEdt.setFocusableInTouchMode(true);
  1207. kilncarEdt.setEnabled(true);
  1208. kilncarEdt.setText("");
  1209. kilncarEdt.setFocusable(true);
  1210. kilncarEdt.setFocusableInTouchMode(true);
  1211. kilncarEdt
  1212. .setFilters(new InputFilter[] { new InputFilter() {
  1213. @Override
  1214. public CharSequence filter(
  1215. CharSequence source,
  1216. int start, int end,
  1217. Spanned dest, int dstart,
  1218. int dend) {
  1219. return null;
  1220. }
  1221. } });
  1222. if (barcodeEdt != null) {
  1223. barcodeEdt.setEnabled(true);
  1224. barcodeEdt.setText("");
  1225. barcodeEdt.setFocusable(true);
  1226. barcodeEdt.setFocusableInTouchMode(true);
  1227. }
  1228. } else {
  1229. Activity activity = (Activity) con;
  1230. activity.finish();
  1231. }
  1232. return;
  1233. } else {
  1234. if (collectType == 1) {
  1235. worknotxt.setEnabled(true);
  1236. worknotxt.setText("");
  1237. worknotxt.setFocusable(true);
  1238. worknotxt.setFocusableInTouchMode(true);
  1239. worknotxt.requestFocus();
  1240. worknotxt.findFocus();
  1241. worknotxt
  1242. .setFilters(new InputFilter[] { new InputFilter() {
  1243. @Override
  1244. public CharSequence filter(
  1245. CharSequence source,
  1246. int start, int end,
  1247. Spanned dest, int dstart,
  1248. int dend) {
  1249. return null;
  1250. }
  1251. } });
  1252. InputMethodManager im = (InputMethodManager) worknotxt
  1253. .getContext().getSystemService(
  1254. Context.INPUT_METHOD_SERVICE);
  1255. im.hideSoftInputFromWindow(
  1256. worknotxt.getWindowToken(),
  1257. InputMethodManager.HIDE_NOT_ALWAYS);
  1258. kilnEdt.setEnabled(true);
  1259. kilnEdt.setFocusable(true);
  1260. kilnEdt.setFocusableInTouchMode(true);
  1261. kilncarEdt.setEnabled(true);
  1262. kilncarEdt.setText("");
  1263. kilncarEdt.setFocusable(true);
  1264. kilncarEdt.setFocusableInTouchMode(true);
  1265. kilncarEdt
  1266. .setFilters(new InputFilter[] { new InputFilter() {
  1267. @Override
  1268. public CharSequence filter(
  1269. CharSequence source,
  1270. int start, int end,
  1271. Spanned dest, int dstart,
  1272. int dend) {
  1273. return null;
  1274. }
  1275. } });
  1276. if (barcodeEdt != null) {
  1277. barcodeEdt.setEnabled(true);
  1278. barcodeEdt.setText("");
  1279. barcodeEdt.setFocusable(true);
  1280. barcodeEdt.setFocusableInTouchMode(true);
  1281. }
  1282. } else {
  1283. Activity activity = (Activity) con;
  1284. activity.finish();
  1285. }
  1286. return;
  1287. }
  1288. }
  1289. }).create();
  1290. alertDialog.setCanceledOnTouchOutside(false);
  1291. alertDialog.show();
  1292. }
  1293. public static void showBarCodeAlertDialog(final int status, String message,
  1294. final Context con, final EditText barcodeEdt,
  1295. final EditText bugnoEdt, final EditText buglocEdt) {
  1296. Dialog alertDialog = new AlertDialog.Builder(con).setMessage(message)
  1297. .setPositiveButton("确定", new DialogInterface.OnClickListener() {
  1298. @Override
  1299. public void onClick(DialogInterface dialog, int which) {
  1300. if (status == -1 || status == -2 || status == -3) {
  1301. ExitUtil eu = new ExitUtil(con);
  1302. eu.exit();
  1303. }
  1304. else if (status == 0) {
  1305. if (barcodeEdt != null) {
  1306. barcodeEdt.setEnabled(true);
  1307. barcodeEdt.setText("");
  1308. barcodeEdt.setFocusable(true);
  1309. barcodeEdt.setFocusableInTouchMode(true);
  1310. barcodeEdt.requestFocus();
  1311. barcodeEdt.findFocus();
  1312. barcodeEdt
  1313. .setFilters(new InputFilter[] { new InputFilter() {
  1314. @Override
  1315. public CharSequence filter(
  1316. CharSequence source,
  1317. int start, int end,
  1318. Spanned dest, int dstart,
  1319. int dend) {
  1320. return null;
  1321. }
  1322. } });
  1323. //CommonUtil.BarcodeMaxLength(barcodeEdt, 50);
  1324. InputMethodManager im = (InputMethodManager) barcodeEdt
  1325. .getContext().getSystemService(
  1326. Context.INPUT_METHOD_SERVICE);
  1327. im.hideSoftInputFromWindow(
  1328. barcodeEdt.getWindowToken(),
  1329. InputMethodManager.HIDE_NOT_ALWAYS);
  1330. }
  1331. if (bugnoEdt != null) {
  1332. bugnoEdt.setEnabled(true);
  1333. bugnoEdt.setFocusable(true);
  1334. bugnoEdt.setFocusableInTouchMode(true);
  1335. bugnoEdt.setFilters(new InputFilter[] { new InputFilter() {
  1336. @Override
  1337. public CharSequence filter(
  1338. CharSequence source, int start,
  1339. int end, Spanned dest, int dstart,
  1340. int dend) {
  1341. return null;
  1342. }
  1343. } });
  1344. }
  1345. if (buglocEdt != null) {
  1346. buglocEdt.setEnabled(true);
  1347. buglocEdt.setFocusable(true);
  1348. buglocEdt.setFocusableInTouchMode(true);
  1349. buglocEdt
  1350. .setFilters(new InputFilter[] { new InputFilter() {
  1351. @Override
  1352. public CharSequence filter(
  1353. CharSequence source,
  1354. int start, int end,
  1355. Spanned dest, int dstart,
  1356. int dend) {
  1357. return null;
  1358. }
  1359. } });
  1360. }
  1361. return;
  1362. }
  1363. else {
  1364. if (barcodeEdt != null) {
  1365. barcodeEdt.setEnabled(true);
  1366. barcodeEdt.setText("");
  1367. barcodeEdt.setFocusable(true);
  1368. barcodeEdt.setFocusableInTouchMode(true);
  1369. barcodeEdt.requestFocus();
  1370. barcodeEdt.findFocus();
  1371. barcodeEdt
  1372. .setFilters(new InputFilter[] { new InputFilter() {
  1373. @Override
  1374. public CharSequence filter(
  1375. CharSequence source,
  1376. int start, int end,
  1377. Spanned dest, int dstart,
  1378. int dend) {
  1379. return null;
  1380. }
  1381. } });
  1382. //CommonUtil.BarcodeMaxLength(barcodeEdt, 50);
  1383. InputMethodManager im = (InputMethodManager) barcodeEdt
  1384. .getContext().getSystemService(
  1385. Context.INPUT_METHOD_SERVICE);
  1386. im.hideSoftInputFromWindow(
  1387. barcodeEdt.getWindowToken(),
  1388. InputMethodManager.HIDE_NOT_ALWAYS);
  1389. }
  1390. if (bugnoEdt != null) {
  1391. bugnoEdt.setEnabled(true);
  1392. bugnoEdt.setFocusable(true);
  1393. bugnoEdt.setFocusableInTouchMode(true);
  1394. bugnoEdt.setFilters(new InputFilter[] { new InputFilter() {
  1395. @Override
  1396. public CharSequence filter(
  1397. CharSequence source, int start,
  1398. int end, Spanned dest, int dstart,
  1399. int dend) {
  1400. return null;
  1401. }
  1402. } });
  1403. }
  1404. if (buglocEdt != null) {
  1405. buglocEdt.setEnabled(true);
  1406. buglocEdt.setFocusable(true);
  1407. buglocEdt.setFocusableInTouchMode(true);
  1408. buglocEdt
  1409. .setFilters(new InputFilter[] { new InputFilter() {
  1410. @Override
  1411. public CharSequence filter(
  1412. CharSequence source,
  1413. int start, int end,
  1414. Spanned dest, int dstart,
  1415. int dend) {
  1416. return null;
  1417. }
  1418. } });
  1419. }
  1420. return;
  1421. }
  1422. }
  1423. }).create();
  1424. alertDialog.setCanceledOnTouchOutside(false);
  1425. alertDialog.show();
  1426. }
  1427. public static void showScrapBarCodeAlertDialog(final int status,
  1428. String message, final Context con, final EditText barcodeEdt,
  1429. final EditText worknoEdt, final EditText scrapFinesEdt,
  1430. final EditText memoEdt) {
  1431. Dialog alertDialog = new AlertDialog.Builder(con).setMessage(message)
  1432. .setPositiveButton("确定", new DialogInterface.OnClickListener() {
  1433. @Override
  1434. public void onClick(DialogInterface dialog, int which) {
  1435. if (status == -1 || status == -2 || status == -3) {
  1436. ExitUtil eu = new ExitUtil(con);
  1437. eu.exit();
  1438. }
  1439. else if (status == 0) {
  1440. barcodeEdt.setEnabled(true);
  1441. barcodeEdt.setText("");
  1442. barcodeEdt.setFocusable(true);
  1443. barcodeEdt.setFocusableInTouchMode(true);
  1444. barcodeEdt.requestFocus();
  1445. barcodeEdt.findFocus();
  1446. barcodeEdt
  1447. .setFilters(new InputFilter[] { new InputFilter() {
  1448. @Override
  1449. public CharSequence filter(
  1450. CharSequence source, int start,
  1451. int end, Spanned dest,
  1452. int dstart, int dend) {
  1453. return null;
  1454. }
  1455. } });
  1456. //CommonUtil.BarcodeMaxLength(barcodeEdt, 50);
  1457. InputMethodManager im = (InputMethodManager) barcodeEdt
  1458. .getContext().getSystemService(
  1459. Context.INPUT_METHOD_SERVICE);
  1460. im.hideSoftInputFromWindow(
  1461. barcodeEdt.getWindowToken(),
  1462. InputMethodManager.HIDE_NOT_ALWAYS);
  1463. if (scrapFinesEdt != null) {
  1464. scrapFinesEdt.setEnabled(true);
  1465. scrapFinesEdt.setText("");
  1466. scrapFinesEdt.setFocusable(true);
  1467. scrapFinesEdt.setFocusableInTouchMode(true);
  1468. scrapFinesEdt
  1469. .setFilters(new InputFilter[] { new InputFilter() {
  1470. @Override
  1471. public CharSequence filter(
  1472. CharSequence source,
  1473. int start, int end,
  1474. Spanned dest, int dstart,
  1475. int dend) {
  1476. return null;
  1477. }
  1478. } });
  1479. }
  1480. if (worknoEdt != null) {
  1481. worknoEdt.setEnabled(true);
  1482. worknoEdt.setFocusable(true);
  1483. worknoEdt.setFocusableInTouchMode(true);
  1484. }
  1485. if (memoEdt != null) {
  1486. memoEdt.setEnabled(true);
  1487. memoEdt.setFocusable(true);
  1488. memoEdt.setFocusableInTouchMode(true);
  1489. }
  1490. return;
  1491. }
  1492. else {
  1493. barcodeEdt.setEnabled(true);
  1494. barcodeEdt.setText("");
  1495. barcodeEdt.setFocusable(true);
  1496. barcodeEdt.setFocusableInTouchMode(true);
  1497. barcodeEdt.requestFocus();
  1498. barcodeEdt.findFocus();
  1499. barcodeEdt
  1500. .setFilters(new InputFilter[] { new InputFilter() {
  1501. @Override
  1502. public CharSequence filter(
  1503. CharSequence source, int start,
  1504. int end, Spanned dest,
  1505. int dstart, int dend) {
  1506. return null;
  1507. }
  1508. } });
  1509. //CommonUtil.BarcodeMaxLength(barcodeEdt, 50);
  1510. InputMethodManager im = (InputMethodManager) barcodeEdt
  1511. .getContext().getSystemService(
  1512. Context.INPUT_METHOD_SERVICE);
  1513. im.hideSoftInputFromWindow(
  1514. barcodeEdt.getWindowToken(),
  1515. InputMethodManager.HIDE_NOT_ALWAYS);
  1516. if (scrapFinesEdt != null) {
  1517. scrapFinesEdt.setEnabled(true);
  1518. scrapFinesEdt.setText("");
  1519. scrapFinesEdt.setFocusable(true);
  1520. scrapFinesEdt.setFocusableInTouchMode(true);
  1521. scrapFinesEdt
  1522. .setFilters(new InputFilter[] { new InputFilter() {
  1523. @Override
  1524. public CharSequence filter(
  1525. CharSequence source,
  1526. int start, int end,
  1527. Spanned dest, int dstart,
  1528. int dend) {
  1529. return null;
  1530. }
  1531. } });
  1532. }
  1533. if (worknoEdt != null) {
  1534. worknoEdt.setEnabled(true);
  1535. worknoEdt.setFocusable(true);
  1536. worknoEdt.setFocusableInTouchMode(true);
  1537. }
  1538. if (memoEdt != null) {
  1539. memoEdt.setEnabled(true);
  1540. memoEdt.setFocusable(true);
  1541. memoEdt.setFocusableInTouchMode(true);
  1542. }
  1543. return;
  1544. }
  1545. }
  1546. }).create();
  1547. alertDialog.setCanceledOnTouchOutside(false);
  1548. alertDialog.show();
  1549. }
  1550. public static void showSaveAlertDialog(final int status, String message,
  1551. final Context con, final EditText worknoEdt,
  1552. final EditText barcodeEdt, final int collectType) {
  1553. Dialog alertDialog = new AlertDialog.Builder(con).setMessage(message)
  1554. .setPositiveButton("确定", new DialogInterface.OnClickListener() {
  1555. @Override
  1556. public void onClick(DialogInterface dialog, int which) {
  1557. if (status == -1 || status == -2 || status == -3) {
  1558. ExitUtil eu = new ExitUtil(con);
  1559. eu.exit();
  1560. }
  1561. else if (status == 0) {
  1562. if (collectType == 1) {
  1563. worknoEdt.setEnabled(true);
  1564. worknoEdt.setText("");
  1565. worknoEdt.setFocusable(true);
  1566. worknoEdt.setFocusableInTouchMode(true);
  1567. worknoEdt.requestFocus();
  1568. worknoEdt.findFocus();
  1569. worknoEdt
  1570. .setFilters(new InputFilter[] { new InputFilter() {
  1571. @Override
  1572. public CharSequence filter(
  1573. CharSequence source,
  1574. int start, int end,
  1575. Spanned dest, int dstart,
  1576. int dend) {
  1577. return null;
  1578. }
  1579. } });
  1580. } else {
  1581. barcodeEdt.setEnabled(true);
  1582. barcodeEdt.setText("");
  1583. barcodeEdt.setFocusable(true);
  1584. barcodeEdt.setFocusableInTouchMode(true);
  1585. barcodeEdt.requestFocus();
  1586. barcodeEdt.findFocus();
  1587. barcodeEdt
  1588. .setFilters(new InputFilter[] { new InputFilter() {
  1589. @Override
  1590. public CharSequence filter(
  1591. CharSequence source,
  1592. int start, int end,
  1593. Spanned dest, int dstart,
  1594. int dend) {
  1595. return null;
  1596. }
  1597. } });
  1598. //CommonUtil.BarcodeMaxLength(barcodeEdt, 50);
  1599. }
  1600. return;
  1601. }
  1602. else {
  1603. if (collectType == 1) {
  1604. worknoEdt.setEnabled(true);
  1605. worknoEdt.setText("");
  1606. worknoEdt.setFocusable(true);
  1607. worknoEdt.setFocusableInTouchMode(true);
  1608. worknoEdt.requestFocus();
  1609. worknoEdt.findFocus();
  1610. worknoEdt
  1611. .setFilters(new InputFilter[] { new InputFilter() {
  1612. @Override
  1613. public CharSequence filter(
  1614. CharSequence source,
  1615. int start, int end,
  1616. Spanned dest, int dstart,
  1617. int dend) {
  1618. return null;
  1619. }
  1620. } });
  1621. } else {
  1622. barcodeEdt.setEnabled(true);
  1623. barcodeEdt.setText("");
  1624. barcodeEdt.setFocusable(true);
  1625. barcodeEdt.setFocusableInTouchMode(true);
  1626. barcodeEdt.requestFocus();
  1627. barcodeEdt.findFocus();
  1628. barcodeEdt
  1629. .setFilters(new InputFilter[] { new InputFilter() {
  1630. @Override
  1631. public CharSequence filter(
  1632. CharSequence source,
  1633. int start, int end,
  1634. Spanned dest, int dstart,
  1635. int dend) {
  1636. return null;
  1637. }
  1638. } });
  1639. //CommonUtil.BarcodeMaxLength(barcodeEdt, 50);
  1640. }
  1641. return;
  1642. }
  1643. }
  1644. }).create();
  1645. alertDialog.setCanceledOnTouchOutside(false);
  1646. alertDialog.show();
  1647. }
  1648. public static void showSaveBilletAlertDialog(final int deliveryType,
  1649. final int status, String message, final Context con,
  1650. final EditText worknoEdt, final EditText barcodeEdt,
  1651. final int collectType) {
  1652. Dialog alertDialog = new AlertDialog.Builder(con).setMessage(message)
  1653. .setPositiveButton("确定", new DialogInterface.OnClickListener() {
  1654. @Override
  1655. public void onClick(DialogInterface dialog, int which) {
  1656. if (status == -1 || status == -2 || status == -3) {
  1657. ExitUtil eu = new ExitUtil(con);
  1658. eu.exit();
  1659. }
  1660. else if (status == 0) {
  1661. if (deliveryType == 0) {
  1662. if (collectType == 1) {
  1663. worknoEdt.setEnabled(true);
  1664. worknoEdt.setText("");
  1665. worknoEdt.setFocusable(true);
  1666. worknoEdt.setFocusableInTouchMode(true);
  1667. worknoEdt.requestFocus();
  1668. worknoEdt.findFocus();
  1669. worknoEdt
  1670. .setFilters(new InputFilter[] { new InputFilter() {
  1671. @Override
  1672. public CharSequence filter(
  1673. CharSequence source,
  1674. int start, int end,
  1675. Spanned dest,
  1676. int dstart, int dend) {
  1677. return null;
  1678. }
  1679. } });
  1680. } else {
  1681. barcodeEdt.setEnabled(true);
  1682. barcodeEdt.setText("");
  1683. barcodeEdt.setFocusable(true);
  1684. barcodeEdt.setFocusableInTouchMode(true);
  1685. barcodeEdt.requestFocus();
  1686. barcodeEdt.findFocus();
  1687. barcodeEdt
  1688. .setFilters(new InputFilter[] { new InputFilter() {
  1689. @Override
  1690. public CharSequence filter(
  1691. CharSequence source,
  1692. int start, int end,
  1693. Spanned dest,
  1694. int dstart, int dend) {
  1695. return null;
  1696. }
  1697. } });
  1698. //CommonUtil.BarcodeMaxLength(barcodeEdt, 50);
  1699. }
  1700. }
  1701. else if (deliveryType == 1) {
  1702. barcodeEdt.setEnabled(true);
  1703. barcodeEdt.setText("");
  1704. barcodeEdt.setFocusable(true);
  1705. barcodeEdt.setFocusableInTouchMode(true);
  1706. barcodeEdt.requestFocus();
  1707. barcodeEdt.findFocus();
  1708. barcodeEdt
  1709. .setFilters(new InputFilter[] { new InputFilter() {
  1710. @Override
  1711. public CharSequence filter(
  1712. CharSequence source,
  1713. int start, int end,
  1714. Spanned dest, int dstart,
  1715. int dend) {
  1716. return null;
  1717. }
  1718. } });
  1719. //CommonUtil.BarcodeMaxLength(barcodeEdt, 50);
  1720. }
  1721. return;
  1722. }
  1723. else {
  1724. if (deliveryType == 0) {
  1725. if (collectType == 1) {
  1726. worknoEdt.setEnabled(true);
  1727. worknoEdt.setText("");
  1728. worknoEdt.setFocusable(true);
  1729. worknoEdt.setFocusableInTouchMode(true);
  1730. worknoEdt.requestFocus();
  1731. worknoEdt.findFocus();
  1732. worknoEdt
  1733. .setFilters(new InputFilter[] { new InputFilter() {
  1734. @Override
  1735. public CharSequence filter(
  1736. CharSequence source,
  1737. int start, int end,
  1738. Spanned dest,
  1739. int dstart, int dend) {
  1740. return null;
  1741. }
  1742. } });
  1743. } else {
  1744. barcodeEdt.setEnabled(true);
  1745. barcodeEdt.setText("");
  1746. barcodeEdt.setFocusable(true);
  1747. barcodeEdt.setFocusableInTouchMode(true);
  1748. barcodeEdt.requestFocus();
  1749. barcodeEdt.findFocus();
  1750. barcodeEdt
  1751. .setFilters(new InputFilter[] { new InputFilter() {
  1752. @Override
  1753. public CharSequence filter(
  1754. CharSequence source,
  1755. int start, int end,
  1756. Spanned dest,
  1757. int dstart, int dend) {
  1758. return null;
  1759. }
  1760. } });
  1761. //CommonUtil.BarcodeMaxLength(barcodeEdt, 50);
  1762. }
  1763. } else if (deliveryType == 1) {
  1764. barcodeEdt.setEnabled(true);
  1765. barcodeEdt.setText("");
  1766. barcodeEdt.setFocusable(true);
  1767. barcodeEdt.setFocusableInTouchMode(true);
  1768. barcodeEdt.requestFocus();
  1769. barcodeEdt.findFocus();
  1770. barcodeEdt
  1771. .setFilters(new InputFilter[] { new InputFilter() {
  1772. @Override
  1773. public CharSequence filter(
  1774. CharSequence source,
  1775. int start, int end,
  1776. Spanned dest, int dstart,
  1777. int dend) {
  1778. return null;
  1779. }
  1780. } });
  1781. //CommonUtil.BarcodeMaxLength(barcodeEdt, 50);
  1782. }
  1783. return;
  1784. }
  1785. }
  1786. }).create();
  1787. alertDialog.setCanceledOnTouchOutside(false);
  1788. alertDialog.show();
  1789. }
  1790. public static void showSaveKilncarAlertDialog(final int status,
  1791. String message, final Context con, final EditText worknoEdt,
  1792. final EditText kilnEdt, final EditText kilncarnoEdt,
  1793. final int collectType) {
  1794. Dialog alertDialog = new AlertDialog.Builder(con).setMessage(message)
  1795. .setPositiveButton("确定", new DialogInterface.OnClickListener() {
  1796. @Override
  1797. public void onClick(DialogInterface dialog, int which) {
  1798. if (status == -1 || status == -2 || status == -3) {
  1799. ExitUtil eu = new ExitUtil(con);
  1800. eu.exit();
  1801. }
  1802. else if (status == 0) {
  1803. kilnEdt.setEnabled(true);
  1804. kilnEdt.setFocusable(true);
  1805. kilnEdt.setFocusableInTouchMode(true);
  1806. if (collectType == 1) {
  1807. worknoEdt.setEnabled(true);
  1808. worknoEdt.setText("");
  1809. worknoEdt.setFocusable(true);
  1810. worknoEdt.setFocusableInTouchMode(true);
  1811. worknoEdt.requestFocus();
  1812. worknoEdt.findFocus();
  1813. worknoEdt
  1814. .setFilters(new InputFilter[] { new InputFilter() {
  1815. @Override
  1816. public CharSequence filter(
  1817. CharSequence source,
  1818. int start, int end,
  1819. Spanned dest, int dstart,
  1820. int dend) {
  1821. return null;
  1822. }
  1823. } });
  1824. kilncarnoEdt.setEnabled(true);
  1825. kilncarnoEdt.setText("");
  1826. kilncarnoEdt.setFocusable(true);
  1827. kilncarnoEdt.setFocusableInTouchMode(true);
  1828. } else {
  1829. kilncarnoEdt.setEnabled(true);
  1830. kilncarnoEdt.setText("");
  1831. kilncarnoEdt.setFocusable(true);
  1832. kilncarnoEdt.setFocusableInTouchMode(true);
  1833. kilncarnoEdt.requestFocus();
  1834. kilncarnoEdt.findFocus();
  1835. }
  1836. return;
  1837. }
  1838. else {
  1839. kilnEdt.setEnabled(true);
  1840. kilnEdt.setFocusable(true);
  1841. kilnEdt.setFocusableInTouchMode(true);
  1842. if (collectType == 1) {
  1843. worknoEdt.setEnabled(true);
  1844. worknoEdt.setText("");
  1845. worknoEdt.setFocusable(true);
  1846. worknoEdt.setFocusableInTouchMode(true);
  1847. worknoEdt.requestFocus();
  1848. worknoEdt.findFocus();
  1849. worknoEdt
  1850. .setFilters(new InputFilter[] { new InputFilter() {
  1851. @Override
  1852. public CharSequence filter(
  1853. CharSequence source,
  1854. int start, int end,
  1855. Spanned dest, int dstart,
  1856. int dend) {
  1857. return null;
  1858. }
  1859. } });
  1860. kilncarnoEdt.setEnabled(true);
  1861. kilncarnoEdt.setText("");
  1862. kilncarnoEdt.setFocusable(true);
  1863. kilncarnoEdt.setFocusableInTouchMode(true);
  1864. } else {
  1865. kilncarnoEdt.setEnabled(true);
  1866. kilncarnoEdt.setText("");
  1867. kilncarnoEdt.setFocusable(true);
  1868. kilncarnoEdt.setFocusableInTouchMode(true);
  1869. kilncarnoEdt.requestFocus();
  1870. kilncarnoEdt.findFocus();
  1871. }
  1872. return;
  1873. }
  1874. }
  1875. }).create();
  1876. alertDialog.setCanceledOnTouchOutside(false);
  1877. alertDialog.show();
  1878. }
  1879. public static void showStaffWorknoAlertDialog(final int status,
  1880. String message, final Context con, final EditText worknoEdt) {
  1881. Dialog alertDialog = new AlertDialog.Builder(con).setMessage(message)
  1882. .setPositiveButton("确定", new DialogInterface.OnClickListener() {
  1883. @Override
  1884. public void onClick(DialogInterface dialog, int which) {
  1885. if (status == -1 || status == -2 || status == -3) {
  1886. ExitUtil eu = new ExitUtil(con);
  1887. eu.exit();
  1888. }
  1889. else if (status == 0) {
  1890. worknoEdt.setEnabled(true);
  1891. worknoEdt.setText("");
  1892. worknoEdt.setFocusable(true);
  1893. worknoEdt.setFocusableInTouchMode(true);
  1894. worknoEdt.requestFocus();
  1895. worknoEdt.findFocus();
  1896. worknoEdt
  1897. .setFilters(new InputFilter[] { new InputFilter() {
  1898. @Override
  1899. public CharSequence filter(
  1900. CharSequence source, int start,
  1901. int end, Spanned dest,
  1902. int dstart, int dend) {
  1903. return null;
  1904. }
  1905. } });
  1906. return;
  1907. }
  1908. else {
  1909. worknoEdt.setEnabled(true);
  1910. worknoEdt.setText("");
  1911. worknoEdt.setFocusable(true);
  1912. worknoEdt.setFocusableInTouchMode(true);
  1913. worknoEdt.requestFocus();
  1914. worknoEdt.findFocus();
  1915. worknoEdt
  1916. .setFilters(new InputFilter[] { new InputFilter() {
  1917. @Override
  1918. public CharSequence filter(
  1919. CharSequence source, int start,
  1920. int end, Spanned dest,
  1921. int dstart, int dend) {
  1922. return null;
  1923. }
  1924. } });
  1925. return;
  1926. }
  1927. }
  1928. }).create();
  1929. alertDialog.setCanceledOnTouchOutside(false);
  1930. alertDialog.show();
  1931. }
  1932. public static String getCurrentDate() {
  1933. Calendar c = Calendar.getInstance();
  1934. SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
  1935. String formattedDate = df.format(c.getTime());
  1936. return formattedDate;
  1937. }
  1938. public static Date ParseStringToDateTime(String s) {
  1939. Date date = null;
  1940. SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  1941. try {
  1942. date = formatter.parse(s);
  1943. }
  1944. catch (ParseException e) {
  1945. e.printStackTrace();
  1946. }
  1947. return date;
  1948. }
  1949. public static Date ParseStringToDate(String s) {
  1950. java.sql.Date d = null;
  1951. d = java.sql.Date.valueOf(s);
  1952. return d;
  1953. }
  1954. public static boolean CheckedDutyPersonStatus(
  1955. List<DutyPerson> dutypersonList) {
  1956. boolean checkedStatus = false;
  1957. for (DutyPerson dp : dutypersonList) {
  1958. if (dp.isCheckStatus()) {
  1959. checkedStatus = true;
  1960. break;
  1961. }
  1962. }
  1963. return checkedStatus;
  1964. }
  1965. public static List<DefectFines> getDefectFinesListByDefectId(
  1966. String orgDefectId,
  1967. List<DefectAndDefectFinesRelation> defectFineRelationList) {
  1968. List<DefectFines> tempDefectFinesList = null;
  1969. for (DefectAndDefectFinesRelation relation : defectFineRelationList) {
  1970. String defectId = relation.getDefectId();
  1971. if (defectId.equals(orgDefectId)) {
  1972. tempDefectFinesList = relation.getDefectFinesList();
  1973. break;
  1974. }
  1975. }
  1976. return tempDefectFinesList;
  1977. }
  1978. public static List<DefectDeduction> getDefectDeductionListByDefectId(
  1979. String orgDefectId,
  1980. List<DefectAndDefectDeductionRelation> defectDeductionRelationList) {
  1981. List<DefectDeduction> tempDefectDeductionList = null;
  1982. for (DefectAndDefectDeductionRelation relation : defectDeductionRelationList) {
  1983. String defectId = relation.getDefectId();
  1984. if (defectId.equals(orgDefectId)) {
  1985. tempDefectDeductionList = relation.getDefectDeductionList();
  1986. break;
  1987. }
  1988. }
  1989. return tempDefectDeductionList;
  1990. }
  1991. public static List<DutyPerson> getCheckedDutyPersonList(
  1992. List<DutyPerson> dutypersonList) {
  1993. List<DutyPerson> checkedDutyPersonList = new ArrayList<DutyPerson>();
  1994. for (DutyPerson dp : dutypersonList) {
  1995. if (dp.isCheckStatus()) {
  1996. checkedDutyPersonList.add(dp);
  1997. }
  1998. }
  1999. return checkedDutyPersonList;
  2000. }
  2001. public static boolean IsIntValue(String s) {
  2002. boolean bCheckResult = true;
  2003. try {
  2004. Integer iCheckValue = Integer.parseInt(s);
  2005. if (iCheckValue instanceof Integer == false) {
  2006. bCheckResult = false;
  2007. }
  2008. } catch (NumberFormatException e) {
  2009. bCheckResult = false;
  2010. }
  2011. return bCheckResult;
  2012. }
  2013. public static boolean IsDoubleValue(String s) {
  2014. boolean bCheckResult = true;
  2015. try {
  2016. Double iCheckValue = Double.parseDouble(s);
  2017. if (iCheckValue instanceof Double == false) {
  2018. bCheckResult = false;
  2019. }
  2020. } catch (NumberFormatException e) {
  2021. bCheckResult = false;
  2022. }
  2023. return bCheckResult;
  2024. }
  2025. }