| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316 |
- package com.jiaju.utils;
- import java.io.ByteArrayInputStream;
- import java.io.ByteArrayOutputStream;
- import java.io.File;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.ObjectInputStream;
- import java.io.ObjectOutputStream;
- import java.math.BigDecimal;
- import java.text.DateFormat;
- import java.text.DecimalFormat;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Calendar;
- import java.util.Date;
- import java.util.List;
- import java.util.Locale;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- import com.jiaju.activity.LoginActivity;
- import com.jiaju.activity.MakeBilletActivity;
- import com.jiaju.activity.R;
- import com.jiaju.model.BatchNoModel;
- import com.jiaju.model.CartInfo;
- import com.jiaju.model.DefectAndDefectDeductionRelation;
- import com.jiaju.model.DefectAndDefectFinesRelation;
- import com.jiaju.model.DefectDeduction;
- import com.jiaju.model.DefectFines;
- import com.jiaju.model.DefectLocation;
- import com.jiaju.model.DefectNo;
- import com.jiaju.model.DutyPerson;
- import com.jiaju.model.GlazeModel;
- import com.jiaju.model.KilnModel;
- import com.jiaju.model.Logo;
- import com.jiaju.model.NoGroutingReasonModel;
- import com.jiaju.model.PrinterModel;
- import com.jiaju.model.ProcedureJobs;
- import com.jiaju.model.ProductClassifyInfo;
- import com.jiaju.model.ProductDefectInfo;
- import com.jiaju.model.ResponsibilityProcedure;
- import com.jiaju.model.ReworkProcedureInfo;
- import com.jiaju.model.ScrapReason;
- import com.jiaju.model.SemiCheckStatus;
- import com.jiaju.model.WorkNo;
- import com.jiaju.model.WorkType;
- import android.annotation.SuppressLint;
- import android.annotation.TargetApi;
- import android.app.Activity;
- import android.app.AlertDialog;
- import android.app.Dialog;
- import android.app.Notification;
- import android.app.NotificationManager;
- import android.content.Context;
- import android.content.DialogInterface;
- import android.content.Intent;
- import android.content.pm.PackageInfo;
- import android.content.pm.PackageManager;
- import android.media.AudioFormat;
- import android.media.AudioManager;
- import android.media.AudioTrack;
- import android.media.MediaPlayer;
- import android.net.ConnectivityManager;
- import android.net.NetworkInfo;
- import android.net.Uri;
- import android.net.NetworkInfo.State;
- import android.net.wifi.WifiInfo;
- import android.net.wifi.WifiManager;
- import android.os.Build;
- import android.os.Environment;
- import android.os.IBinder;
-
- import android.os.Vibrator;
- import android.text.InputFilter;
- import android.text.Spanned;
- import android.view.MotionEvent;
- import android.view.View;
- import android.view.WindowManager;
- import android.view.inputmethod.InputMethodManager;
- import android.widget.EditText;
- @SuppressLint("NewApi")
- public class CommonUtil {
- static MediaPlayer mp;
- public static boolean isBlank(String str) {
- if (str == null || str.length() == 0
- || str.toLowerCase().equals("null")) {
- return true;
- }
- return false;
- }
- public static void deleteAllFiles(File root) {
- File files[] = root.listFiles();
- if (files != null)
- for (File f : files) {
- if (f.isDirectory()) { // 判断是否为文件夹
- deleteAllFiles(f);
- try {
- f.delete();
- } catch (Exception e) {
- }
- } else {
- if (f.exists()) { // 判断是否存在
- deleteAllFiles(f);
- try {
- f.delete();
- } catch (Exception e) {
- }
- }
- }
- }
- }
-
-
-
- public static String parseMoney(String pattern,BigDecimal bd){
- DecimalFormat df=new DecimalFormat(pattern);
- return df.format(bd);
- }
-
- public static String isContainsEnterCharacter(String txt){
- String code="";
- if(txt.contains("\n")){
- code = txt.trim().replaceAll("\\n", "");
- }
- else if(txt.contains("\r\n")){
- code = txt.trim().replaceAll("\\r\\n", "");
- }
- else if(txt.endsWith("\t")){
- code = txt.trim().replaceAll("\\t", "");
- }
- return code;
- }
-
- public static void hideKeyboard(MotionEvent event, View view,
- Activity activity) {
- try {
- if (view != null && view instanceof EditText) {
- int[] location = { 0, 0 };
- view.getLocationInWindow(location);
- int left = location[0], top = location[1], right = left
- + view.getWidth(), bootom = top + view.getHeight();
- // 判断焦点位置坐标是否在空间内,如果位置在控件外,则隐藏键盘
- if (event.getRawX() < left || event.getRawX() > right
- || event.getY() < top || event.getRawY() > bootom) {
- // 隐藏键盘
- IBinder token = view.getWindowToken();
- InputMethodManager inputMethodManager = (InputMethodManager) activity
- .getSystemService(Context.INPUT_METHOD_SERVICE);
- inputMethodManager.hideSoftInputFromWindow(token,
- InputMethodManager.HIDE_NOT_ALWAYS);
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public static ResponsibilityProcedure getResponsibilityProcedureByProcedureId(
- List<ResponsibilityProcedure> procedureList, int procedureId) {
- ResponsibilityProcedure rp = null;
- for (ResponsibilityProcedure procedure : procedureList) {
- if (procedure.getDutyProcedureId() == procedureId) {
- rp = procedure;
- break;
- }
- }
- return rp;
- }
- public static DefectNo CompareDefectNo(List<DefectNo> defectNoList,
- String defectNo) {
- DefectNo localdefect = null;
- for (DefectNo defect : defectNoList) {
- String code = defect.getDefectCode();
- if (code.equals(defectNo)) {
- localdefect = defect;
- break;
- }
- }
- return localdefect;
- }
- public static DefectLocation CompareDefectLocation(
- List<DefectLocation> defectLocationList, String defectLocation) {
- DefectLocation location = null;
- for (DefectLocation defectlocation : defectLocationList) {
- String loccode = defectlocation.getDefectPositionCode();
- if (loccode.equals(defectLocation)) {
- location = defectlocation;
- break;
- }
- }
- return location;
- }
-
-
- public static String addSpecifiedDay(String today,int days){
- SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd");
- Date d;
- try {
- d = new Date(f.parse(today).getTime()+days*24*3600*1000);
- return f.format(d);
- } catch (ParseException e) {
- e.printStackTrace();
- return "";
- }
-
- }
-
- public static String dateStringConverter(String datestr) {
- Date date = null;
- String dateString = null;
- DateFormat format1 = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
- DateFormat format2 = new SimpleDateFormat("yyyy-MM-dd");
- try {
- date = format1.parse(datestr);
- dateString = format2.format(date);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return dateString;
- }
-
- public static Date stringDateConverter(String dateStr) {
- Date date = null;
-
- DateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
- try {
- date = format1.parse(dateStr);
-
- } catch (Exception e) {
- e.printStackTrace();
- }
- return date;
- }
- public static String commonDateConverter(String datestr) {
- Date date = null;
- String dateString = null;
- DateFormat format1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- DateFormat format2 = new SimpleDateFormat("yyyy-MM-dd");
- try {
- date = format1.parse(datestr);
- dateString = format2.format(date);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return dateString;
- }
-
- public static String dateFormatConverter(String datestr) {
- Date date = null;
- String dateString = null;
- DateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
- DateFormat format2 = new SimpleDateFormat("yyyyMMdd");
- try {
- date = format1.parse(datestr);
- dateString = format2.format(date);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return dateString;
- }
-
- public static boolean checkDate(String date,String format) {
- DateFormat df = new SimpleDateFormat(format);
- Date d = null;
- try{
- d = df.parse(date);
- }catch(Exception e){
- //如果不能转换,肯定是错误格式
- return false;
- }
- String s1 = df.format(d);
-
- return date.equals(s1);
- }
-
- public static <T> List<T> deepCopy(List<T> src) throws IOException, ClassNotFoundException {
- ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
- ObjectOutputStream out = new ObjectOutputStream(byteOut);
- out.writeObject(src);
- ByteArrayInputStream byteIn = new ByteArrayInputStream(byteOut.toByteArray());
- ObjectInputStream in = new ObjectInputStream(byteIn);
- @SuppressWarnings("unchecked")
- List<T> dest = (List<T>) in.readObject();
- return dest;
- }
-
- public static KilnModel GetKilncode(String kilncode,
- List<KilnModel> kilncodelist) {
- KilnModel kilnmodel = null;
- for (KilnModel kiln : kilncodelist) {
- String currentKilnCode= kiln.getKilinCode();
- if (currentKilnCode.equalsIgnoreCase(kilncode)) {
- kilnmodel = kiln;
- break;
- }
- }
- return kilnmodel;
- }
- public static String dateConverter(String datestr) {
- Date date = null;
- String dateString = null;
- DateFormat format1 = new SimpleDateFormat("dd-MMM-yy HH:mm:ss",
- Locale.ENGLISH);
- DateFormat format2 = new SimpleDateFormat("yyyy-MM-dd");
- try {
- date = format1.parse(datestr);
- dateString = format2.format(date);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return dateString;
- }
- public static int getDefectProductionDataIdByUserId(
- List<WorkNo> worknolist, int userId) {
- int defectProductionDataId = 0;
- for (int i = 0; i < worknolist.size(); i++) {
- WorkNo wn = worknolist.get(i);
- if (wn.getUserId() == userId) {
- defectProductionDataId = (int) wn.getProductionDataId();
- break;
- }
- }
- return defectProductionDataId;
- }
- public static boolean compareStaffInfo(List<DutyPerson> dutyPersonList,
- DutyPerson dp) {
- boolean result = false;
- for (int i = 0; i < dutyPersonList.size(); i++) {
- DutyPerson dutyperson = dutyPersonList.get(i);
- if (dp.getuJobsId() == dutyperson.getuJobsId()
- && dp.getStaffCode().equals(dutyperson.getStaffCode())) {
- result = true;
- }
- }
- return result;
- }
- public static void BarcodeMaxLength(EditText edt, int maxLength) {
- edt.setFilters(new InputFilter[] { new InputFilter.LengthFilter(
- maxLength) });
- }
- public static String getSpecifiedDayAfter(String specifiedDay) {
- Calendar c = Calendar.getInstance();
- Date date = null;
- try {
- date = new SimpleDateFormat("yyyy-MM-dd").parse(specifiedDay);
- } catch (ParseException e) {
- e.printStackTrace();
- }
- c.setTime(date);
- int day = c.get(Calendar.DATE);
- c.set(Calendar.DATE, day + 1);
- String dayAfter = new SimpleDateFormat("yyyy-MM-dd")
- .format(c.getTime());
- return dayAfter;
- }
- public static void removeDuplicateCartList(List<CartInfo> cartlist) {
- for (int i = cartlist.size() - 1; i > 0; i--) {
- CartInfo item = cartlist.get(i);
- for (int j = i - 1; j >= 0; j--) {
- if (cartlist.get(j).getBarcode().equals(item.getBarcode())) {
- cartlist.remove(i);
- break;
- }
- }
- }
- }
- public static boolean CompareDate(String systemDate, String currentDate) {
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
- Date system;
- boolean compareresult = false;
- try {
- system = sdf.parse(systemDate);
- Date current = sdf.parse(currentDate);
- if (current.before(system)) {
- compareresult = false;
- } else {
- compareresult = true;
- }
- } catch (ParseException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return compareresult;
- }
- public static void playSound(Context context) {
- try {
- mp = MediaPlayer.create(context, R.raw.sound);
- final AudioManager audioMgr = (AudioManager) context
- .getSystemService(Context.AUDIO_SERVICE);
- // final int
- // currentVolume=audioMgr.getStreamVolume(AudioManager.STREAM_SYSTEM);
- int maxVolume = audioMgr
- .getStreamMaxVolume(AudioManager.STREAM_MUSIC);
- audioMgr.setStreamVolume(AudioManager.STREAM_MUSIC, maxVolume,
- AudioManager.FLAG_PLAY_SOUND);
- mp.start();
- mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
- // @Override
- /* 覆盖文件播出完毕事件 */
- public void onCompletion(MediaPlayer arg0) {
- mp.release();
- // audioMgr.setStreamVolume(AudioManager.STREAM_SYSTEM,currentVolume,AudioManager.FLAG_PLAY_SOUND);
- }
- });
- mp.setOnErrorListener(new MediaPlayer.OnErrorListener() {
- @Override
- /* 覆盖错误处理事件 */
- public boolean onError(MediaPlayer arg0, int arg1, int arg2) {
- /* 发生错误时也解除资源与MediaPlayer的赋值 */
- mp.release();
- return false;
- }
- });
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- public static void playAlertSound(Context context) {
- try {
- mp = MediaPlayer.create(context, R.raw.alert);
- final AudioManager audioMgr = (AudioManager) context
- .getSystemService(Context.AUDIO_SERVICE);
- // final int
- // currentVolume=audioMgr.getStreamVolume(AudioManager.STREAM_SYSTEM);
- int maxVolume = audioMgr
- .getStreamMaxVolume(AudioManager.STREAM_MUSIC);
- audioMgr.setStreamVolume(AudioManager.STREAM_MUSIC, maxVolume,
- AudioManager.FLAG_PLAY_SOUND);
- mp.start();
- mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
- // @Override
- /* 覆盖文件播出完毕事件 */
- public void onCompletion(MediaPlayer arg0) {
- mp.release();
- // audioMgr.setStreamVolume(AudioManager.STREAM_SYSTEM,currentVolume,AudioManager.FLAG_PLAY_SOUND);
- }
- });
- mp.setOnErrorListener(new MediaPlayer.OnErrorListener() {
- @Override
- /* 覆盖错误处理事件 */
- public boolean onError(MediaPlayer arg0, int arg1, int arg2) {
- /* 发生错误时也解除资源与MediaPlayer的赋值 */
- mp.release();
- return false;
- }
- });
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public static byte[] getFromAssets(Context context, String fileName) {
- byte[] buffer = null;
- try {
- InputStream in = context.getResources().getAssets().open(fileName);
- // 获取文件的字节数
- int lenght = in.available();
- // 创建byte数组
- buffer = new byte[lenght];
- // 将文件中的数据读到byte数组中
- in.read(buffer);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return buffer;
- }
- public static byte[] getFromRaw(Context context, int fileName) {
- byte[] buffer = null;
- try {
- InputStream in = context.getResources().openRawResource(fileName);
- // 获取文件的字节数
- int length = in.available();
- // 创建byte数组
- buffer = new byte[length];
- // 将文件中的数据读到byte数组中
- in.read(buffer);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return buffer;
- }
- public static String getVersionName(Context context) throws Exception {
- // 获取packagemanager的实例
- PackageManager packageManager = context.getPackageManager();
- // getPackageName()是你当前类的包名,0代表是获取版本信息
- PackageInfo packInfo = packageManager.getPackageInfo(
- context.getPackageName(), 0);
- String version = packInfo.versionName;
- return version;
- }
- public static void playSound(Context context, byte[] soundData) {
- int index = 0;
- int offset = 0;
- final int minBufsize = AudioTrack.getMinBufferSize(44100,
- AudioFormat.CHANNEL_OUT_STEREO,// The channel
- AudioFormat.ENCODING_PCM_16BIT);
- AudioTrack aAudioTrack01 = new AudioTrack(AudioManager.STREAM_MUSIC,
- 44100, AudioFormat.CHANNEL_OUT_STEREO,
- AudioFormat.ENCODING_PCM_16BIT, minBufsize,
- AudioTrack.MODE_STREAM);
- AudioManager am = (AudioManager) context
- .getSystemService(Context.AUDIO_SERVICE);
- // am.setStreamVolume(AudioManager.STREAM_MUSIC,
- // am.getStreamMaxVolume(AudioManager.STREAM_MUSIC),
- // AudioManager.FLAG_PLAY_SOUND);
- aAudioTrack01.play();
- while (true) {
- try {
- offset = index * minBufsize;
- if (offset >= soundData.length) {
- break;
- }
- aAudioTrack01.write(soundData, offset, minBufsize);
- } catch (Exception e) {
- break;
- }
- index++;
- }
- aAudioTrack01.release();
- }
- public static String getRootFilePath() {
- if (hasSDCard()) {
- return Environment.getExternalStorageDirectory().getAbsolutePath()
- + "";
- } else {
- return Environment.getDataDirectory().getAbsolutePath() + "/data";
- }
- }
- public static int getTrademarkIndex(String trademarkCode,
- List<Logo> trademarkList) {
- int newposition = -1;
- for (int position = 0; position < trademarkList.size(); position++) {
- if (trademarkCode.equalsIgnoreCase((trademarkList.get(position)
- .getLogoCode()))) {
- newposition = position;
- break;
- }
- }
- return newposition;
- }
-
- public static int getGlazeIndex(String glazeName,
- List<GlazeModel> glazeList) {
- int newposition = -1;
- for (int position = 0; position < glazeList.size(); position++) {
- if (glazeName.equals(glazeList.get(position).getGlazeName())) {
- newposition = position;
- break;
- }
- }
- return newposition;
- }
-
- public static int getPrinterIndex(String printerName,List<PrinterModel> printerList){
- int newposition=-1;
- for(int position=0;position<printerList.size();position++) {
- if(printerName.equalsIgnoreCase(printerList.get(position).getPrinterName())){
- newposition=position;
- break;
- }
- }
- return newposition;
-
- }
-
- public static int getNoGroutingReasonIndex(int noGroutingReasonId,List<NoGroutingReasonModel> noGroutingReasonList){
- int newposition=-1;
- for(int position=0;position<noGroutingReasonList.size();position++) {
- if(noGroutingReasonId==Integer.parseInt(noGroutingReasonList.get(position).getReasonId())){
- newposition=position;
- break;
- }
- }
- return newposition;
-
- }
- public static int getWorkNoIndex(WorkNo updateWorkno,
- List<WorkNo> worknolist) {
- int newposition = 0;
- for (int position = 0; position < worknolist.size(); position++) {
- if (updateWorkno.getUserId() == (worknolist.get(position)
- .getUserId())) {
- newposition = position;
- }
- }
- return newposition;
- }
- public static int getSemiCheckStatusIndex(int semiCheckStatusId,
- List<SemiCheckStatus> semiCheckStatusList) {
- int newposition = 0;
- for (int position = 0; position < semiCheckStatusList.size(); position++) {
- if (semiCheckStatusId == Integer.parseInt(semiCheckStatusList.get(
- position).getSemiCheckTypeId())) {
- newposition = position;
- }
- }
- return newposition;
- }
- public static int getResponsibilityProcedureIndex(
- ResponsibilityProcedure updateProcedure,
- List<ResponsibilityProcedure> procedurelist) {
- int newposition = 0;
- for (int position = 0; position < procedurelist.size(); position++) {
- if (updateProcedure.getDutyProcedureId() == (procedurelist
- .get(position).getDutyProcedureId())) {
- newposition = position;
- }
- }
- return newposition;
- }
- public static int getResponsibilityProcedureIndexById(int procedureId,
- List<ResponsibilityProcedure> procedurelist) {
- int newposition = 0;
- for (int position = 0; position < procedurelist.size(); position++) {
- if (procedureId == (procedurelist.get(position)
- .getDutyProcedureId())) {
- newposition = position;
- }
- }
- return newposition;
- }
- public static ResponsibilityProcedure getResponsibilityProcedureById(
- int procedureId, List<ResponsibilityProcedure> procedurelist) {
- ResponsibilityProcedure rp = null;
- for (int position = 0; position < procedurelist.size(); position++) {
- if (procedureId == (procedurelist.get(position)
- .getDutyProcedureId())) {
- rp = procedurelist.get(position);
- break;
- }
- }
- return rp;
- }
- public static ResponsibilityProcedure getCompleteResonsibilityProcedureById(
- int procedureId, List<ResponsibilityProcedure> procedurelist) {
- ResponsibilityProcedure rp = null;
- for (ResponsibilityProcedure proc : procedurelist) {
- if (procedureId == proc.getDutyProcedureId()) {
- rp = proc;
- break;
- }
- }
- return rp;
- }
- public static String getIpAddress(Context con) {
- // TODO Auto-generated method stub
- // 获取wifi服务
- WifiManager wifiManager = (WifiManager) con
- .getSystemService(Context.WIFI_SERVICE);
- // 判断wifi是否开启
- if (!wifiManager.isWifiEnabled()) {
- wifiManager.setWifiEnabled(true);
- }
- WifiInfo wifiInfo = wifiManager.getConnectionInfo();
- int ipAddress = wifiInfo.getIpAddress();
- String ip = intToIp(ipAddress);
- return ip;
- }
- public static void installApk(String installFilePath, Context context) {
- File apkfile = new File(installFilePath);
- if (!apkfile.exists()) {
- return;
- }
- Intent i = new Intent(Intent.ACTION_VIEW);
- i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- i.setDataAndType(Uri.parse("file://" + apkfile.toString()),
- "application/vnd.android.package-archive");
- context.startActivity(i);
- android.os.Process.killProcess(android.os.Process.myPid());
- }
- private static String intToIp(int i) {
- return (i & 0xFF) + "." + ((i >> 8) & 0xFF) + "." + ((i >> 16) & 0xFF)
- + "." + (i >> 24 & 0xFF);
- }
- public static int getWorktypeIndexByJobsId(int jobsId,
- List<WorkType> worktypeList) {
- int position = 0;
- for (int i = 0; i < worktypeList.size(); i++) {
- if (jobsId == worktypeList.get(i).getJobsID()) {
- position = i;
- break;
- }
- }
- return position;
- }
- public static WorkType getWorktypeByJobsId(int jobsId,
- List<WorkType> worktypeList) {
- WorkType wt = null;
- for (int i = 0; i < worktypeList.size(); i++) {
- if (jobsId == worktypeList.get(i).getJobsID()) {
- wt = worktypeList.get(i);
- break;
- }
- }
- return wt;
- }
- public static ReworkProcedureInfo getReworkProcedureInfoByName(
- String reworkProcedureName,
- List<ReworkProcedureInfo> reworkProcedureList) {
- ReworkProcedureInfo reworkProcedureInfo = null;
- for (int i = 0; i < reworkProcedureList.size(); i++) {
- if (reworkProcedureName.equals(reworkProcedureList.get(i)
- .getReworkProcedureName())) {
- reworkProcedureInfo = reworkProcedureList.get(i);
- break;
- }
- }
- return reworkProcedureInfo;
- }
- public static int getScrapReasonIndex(String sr,
- List<ScrapReason> scrapReasonList) {
- int newposition = 0;
- for (int i = 0; i < scrapReasonList.size(); i++) {
- if (sr.equals(scrapReasonList.get(i).getDictionaryValue())) {
- newposition = i;
- }
- }
- return newposition;
- }
- public static boolean CompareKilncode(String kilncode,
- List<String> kilncodelist) {
- boolean kilnflag = false;
- for (String kiln : kilncodelist) {
- if (kiln.equalsIgnoreCase(kilncode)) {
- kilnflag = true;
- }
- }
- return kilnflag;
- }
- public static List<DefectFines> CompareDefectFinesResult(
- List<DefectFines> orgDefectFinesList,
- List<DefectFines> destDefectFinesList) {
- List<DefectFines> defectFinesResultList = new ArrayList<DefectFines>();
- if (orgDefectFinesList == null) {
- defectFinesResultList.addAll(destDefectFinesList);
- } else {
- for (DefectFines defectFines : orgDefectFinesList) {
- if (destDefectFinesList.contains(defectFines)) {
- defectFinesResultList.add(defectFines);
- }
- }
- if (defectFinesResultList.size() == 0) {
- defectFinesResultList.addAll(destDefectFinesList);
- } else {
- DefectFines df1 = new DefectFines();
- df1.setDefectFinesId(0);
- df1.setDefectFinesName("请选择缺陷扣罚");
- defectFinesResultList.add(0, df1);
- }
- }
- return defectFinesResultList;
- }
- public static List<DefectDeduction> CompareDefectDeductionResult(
- List<DefectDeduction> orgDefectDeductionList,
- List<DefectDeduction> destDefectDeductionList) {
- List<DefectDeduction> defectDeductionResultList = new ArrayList<DefectDeduction>();
- if (orgDefectDeductionList == null) {
- defectDeductionResultList.addAll(destDefectDeductionList);
- } else {
- for (DefectDeduction defectDeduction : orgDefectDeductionList) {
- if (destDefectDeductionList.contains(defectDeduction)) {
- defectDeductionResultList.add(defectDeduction);
- }
- }
- if (defectDeductionResultList.size() == 0) {
- defectDeductionResultList.addAll(destDefectDeductionList);
- } else {
- DefectDeduction df4 = new DefectDeduction();
- df4.setDefectDeductionId(0);
- df4.setDefectDeductionNum("请选择缺陷扣除数");
- defectDeductionResultList.add(0, df4);
- }
- }
- return defectDeductionResultList;
- }
- public static boolean isCurrency(String s) {
- Pattern p = Pattern.compile(
- "^(([1-9]{1}\\d{0,4})|([0]{1}))(\\.(\\d){0,2})?$",
- Pattern.CASE_INSENSITIVE);
- Matcher m = p.matcher(s);
- return m.matches();
- }
-
- public static boolean isInteger(String s) {
- Pattern p = Pattern.compile(
- "^([1-9]{1}\\d{0,5})?$",
- Pattern.CASE_INSENSITIVE);
- Matcher m = p.matcher(s);
- return m.matches();
- }
- public static boolean isPositveInteger(String s) {
- Pattern p = Pattern.compile("^([1-9]{1}\\d{0,1})|([0]{1})?$",
- Pattern.CASE_INSENSITIVE);
- Matcher m = p.matcher(s);
- return m.matches();
- }
- public static String getMacFromWifi(Context context) {
- ConnectivityManager connectivityManager = (ConnectivityManager) context
- .getSystemService(Context.CONNECTIVITY_SERVICE);
- State wifiState = connectivityManager.getNetworkInfo(
- ConnectivityManager.TYPE_WIFI).getState();
- if (wifiState == NetworkInfo.State.CONNECTED) {// 判断当前是否使用wifi连接
- WifiManager wifiManager = (WifiManager) context
- .getSystemService(Context.WIFI_SERVICE);
- if (!wifiManager.isWifiEnabled()) { // 如果当前wifi不可用
- wifiManager.setWifiEnabled(true);
- }
- WifiInfo wifiInfo = wifiManager.getConnectionInfo();
- return wifiInfo.getMacAddress();
- }
- return null;
- }
- public static boolean isNumber(String s) {
- Pattern p = Pattern.compile("[0-9]*");
- Matcher m = p.matcher(s);
- return m.matches();
- }
- public static List<DutyPerson> CompareDutyPersonList(
- List<DutyPerson> originalList, List<DutyPerson> newDutyPersonList) {
- List<DutyPerson> dutyPersonList = null;
- for (int i = 0; i < originalList.size(); i++) {
- int originalstaffId = originalList.get(i).getStaffId();
- for (int j = 0; j < newDutyPersonList.size(); j++) {
- DutyPerson newdp = newDutyPersonList.get(j);
- int newdpId = newdp.getStaffId();
- if (originalstaffId == newdpId) {
- newdp.setCheckStatus(true);
- newDutyPersonList.set(j, newdp);
- }
- }
- }
- dutyPersonList = newDutyPersonList;
- return dutyPersonList;
- }
- public static int getAuditStatusIndexById(int auditStatusId,
- List<DefectFines> auditList) {
- int newposition = 0;
- for (int position = 0; position < auditList.size(); position++) {
- if (auditStatusId == (auditList.get(position).getDefectFinesId())) {
- newposition = position;
- }
- }
- return newposition;
- }
- public static int getJobsIdByProcedureId(int procedureId,
- List<ProcedureJobs> procedureJobList) {
- int jobsId = 0;
- for (ProcedureJobs pj : procedureJobList) {
- if (pj.getProcedureId() == procedureId) {
- jobsId = pj.getJobsId();
- break;
- }
- }
- return jobsId;
- }
- public static int getReworkProcedureId(int reworkProcedureId,
- List<ReworkProcedureInfo> reworkProcedureList) {
- int newposition = 0;
- for (int position = 0; position < reworkProcedureList.size(); position++) {
- if (reworkProcedureId == Integer.parseInt(reworkProcedureList.get(
- position).getReworkProcedureID())) {
- newposition = position;
- }
- }
- return newposition;
- }
- public static void showRepeatDialog(String message, final Context con) {
- Dialog alertDialog = new AlertDialog.Builder(con).setMessage(message)
- .setPositiveButton("确定", new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- return;
- }
- }).create();
- alertDialog.show();
- }
- public static int getWorkTypeIndex(WorkType updateWorkType,
- List<WorkType> worktypelist) {
- int newposition = 0;
- for (int position = 0; position < worktypelist.size(); position++) {
- if (updateWorkType.getJobsID() == (worktypelist.get(position)
- .getJobsID())) {
- newposition = position;
- }
- }
- return newposition;
- }
-
- public static int getGroutingBatchNoIndex(String batchNo,List<BatchNoModel> batchNoList)
- {
- int position=-1;
- if(batchNoList!=null&&batchNoList.size()>0)
- {
- for(int i=0;i<batchNoList.size();i++)
- {
- BatchNoModel batchNoModel=batchNoList.get(i);
- if(Double.parseDouble(batchNo)==Double.parseDouble(batchNoModel.getBatchNo()))
- {
- position=i;
- break;
-
- }
- }
- }
-
- return position;
-
- }
- public static int getProductClassifyIndex(int goodsLevelTypeId,
- List<ProductClassifyInfo> productClassifyList) {
- int newposition = 0;
- for (int position = 0; position < productClassifyList.size(); position++) {
- if (goodsLevelTypeId == productClassifyList.get(position)
- .getGoodsLevelTypeID()) {
- newposition = position;
- }
- }
- return newposition;
- }
- public static boolean compareProductDefectInfoList(
- List<ProductDefectInfo> originalProductDefectInfoList,
- ProductDefectInfo newProductDefectInfo) {
- boolean isEquals = false;
- for (ProductDefectInfo original : originalProductDefectInfoList) {
- if (newProductDefectInfo.getDefectNo().getDefectId() == original
- .getDefectNo().getDefectId()
- && newProductDefectInfo.getDefectLocation()
- .getDefectPositionId() == original
- .getDefectLocation().getDefectPositionId()
- && newProductDefectInfo.getResponsibilityProcedure()
- .getDutyProcedureId() == original
- .getResponsibilityProcedure().getDutyProcedureId()
- && newProductDefectInfo.getWorkno().getUserId() == original
- .getWorkno().getUserId()
- && newProductDefectInfo.getWorkType().getJobsID() == original
- .getWorkType().getJobsID()) {
- isEquals = true;
- }
- }
- return isEquals;
- }
- public static boolean compareCheckCollectDefectInfoList(
- List<ProductDefectInfo> originalProductDefectInfoList,
- ProductDefectInfo newProductDefectInfo) {
- boolean isEquals = false;
- for (ProductDefectInfo original : originalProductDefectInfoList) {
- if (newProductDefectInfo.getDefectNo().getDefectId() == original
- .getDefectNo().getDefectId()
- && newProductDefectInfo.getDefectLocation()
- .getDefectPositionId() == original
- .getDefectLocation().getDefectPositionId()
- && newProductDefectInfo.getWorkno().getUserId() == original
- .getWorkno().getUserId()) {
- isEquals = true;
- }
- }
- return isEquals;
- }
- public static boolean hasSDCard() {
- String status = Environment.getExternalStorageState();
- if (!status.equals(Environment.MEDIA_MOUNTED)) {
- return false;
- }
- return true;
- }
- public static boolean CompareServerVersion(String localVersion,
- String ServerVersion) {
- boolean b = false;
- String localVersionNo = localVersion.replace(".", "");
- String serverVersionNo = ServerVersion.replace(".", "");
- if (localVersionNo.startsWith("0")) {
- localVersionNo = localVersionNo.replaceFirst("^0*", "");
- }
- if (serverVersionNo.startsWith("0"))
- {
- serverVersionNo = serverVersionNo.replaceFirst("^0*", "");
- }
- if (Long.parseLong(serverVersionNo) > Long.parseLong(localVersionNo)) {
- b = true;
- }
- return b;
- }
- public static void setDefault(int defaults, Context context) {
- int NOTIFICATIONS_ID = 1;
- NotificationManager mNotificationManager;
- final Notification notification = new Notification();
- notification.defaults = defaults;
- mNotificationManager = (NotificationManager) context
- .getSystemService(context.NOTIFICATION_SERVICE);
- mNotificationManager.notify(NOTIFICATIONS_ID, notification);
- }
-
-
- //
- // @SuppressLint("NewApi") 警告去掉
- // public static void setDefault(int defaults,Context context) {
- // Vibrator v = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
- // if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
- // v.vibrate(VibrationEffect.createOneShot(500, VibrationEffect.DEFAULT_AMPLITUDE));
- // }
- // else
- // {
- //
- // int NOTIFICATIONS_ID = 1;
- // NotificationManager mNotificationManager;
- // final Notification notification = new Notification();
- // notification.defaults = defaults;
- // mNotificationManager = (NotificationManager) context
- // .getSystemService(context.NOTIFICATION_SERVICE);
- // mNotificationManager.notify(NOTIFICATIONS_ID, notification);
- // //deprecated in API 26
- // // v.vibrate(500);
- // }
- //
- // }
- public static void showAlertDialog(final int status, String message,
- final Context con) {
- Dialog alertDialog = new AlertDialog.Builder(con).setMessage(message)
- .setPositiveButton("确定", new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- if (status == -1 || status == -2 || status == -3) {
- ExitUtil eu = new ExitUtil(con);
- eu.exit();
- }
- else if (status == 0) {
- return;
- } else {
- return;
- }
- }
- }).create();
- alertDialog.setCanceledOnTouchOutside(false);
- alertDialog.show();
- }
- public static void showWorkNoAlertDialog(final int status, String message,
- final Context con, final EditText worknotxt,
- final EditText barcodeEdt, final EditText bugnoEdt,
- final EditText buglocEdt, final int collectType) {
-
-
- Dialog alertDialog = new AlertDialog.Builder(con).setMessage(message)
- .setPositiveButton("确定", new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- if (status == -1 || status == -2 || status == -3) {
- ExitUtil eu = new ExitUtil(con);
- eu.exit();
- }
- else if (status == 0) {
- if (collectType == 1) {
- worknotxt.setEnabled(true);
- worknotxt.setText("");
- worknotxt.setFocusable(true);
- worknotxt.setFocusableInTouchMode(true);
- worknotxt.requestFocus();
- worknotxt.findFocus();
- worknotxt
- .setFilters(new InputFilter[] { new InputFilter() {
- @Override
- public CharSequence filter(
- CharSequence source,
- int start, int end,
- Spanned dest, int dstart,
- int dend) {
- return null;
- }
- } });
- barcodeEdt.setEnabled(true);
- barcodeEdt.setText("");
- barcodeEdt.setFocusable(true);
- barcodeEdt.setFocusableInTouchMode(true);
- barcodeEdt
- .setFilters(new InputFilter[] { new InputFilter() {
- @Override
- public CharSequence filter(
- CharSequence source,
- int start, int end,
- Spanned dest, int dstart,
- int dend) {
- return null;
- }
- } });
- //CommonUtil.BarcodeMaxLength(barcodeEdt, 50);
- if (bugnoEdt != null) {
- bugnoEdt.setEnabled(true);
- bugnoEdt.setText("");
- bugnoEdt.setFocusable(true);
- bugnoEdt.setFocusableInTouchMode(true);
- bugnoEdt.setFilters(new InputFilter[] { new InputFilter() {
- @Override
- public CharSequence filter(
- CharSequence source, int start,
- int end, Spanned dest,
- int dstart, int dend) {
- return null;
- }
- } });
- }
- if (buglocEdt != null) {
- buglocEdt.setEnabled(true);
- buglocEdt.setText("");
- buglocEdt.setFocusable(true);
- buglocEdt.setFocusableInTouchMode(true);
- buglocEdt
- .setFilters(new InputFilter[] { new InputFilter() {
- @Override
- public CharSequence filter(
- CharSequence source,
- int start, int end,
- Spanned dest,
- int dstart, int dend) {
- return null;
- }
- } });
- }
- } else {
- Activity activity = (Activity) con;
- activity.finish();
- }
- return;
- }
- else {
- if (collectType == 1) {
- worknotxt.setEnabled(true);
- worknotxt.setText("");
- worknotxt.setFocusable(true);
- worknotxt.setFocusableInTouchMode(true);
- worknotxt.requestFocus();
- worknotxt.findFocus();
- worknotxt
- .setFilters(new InputFilter[] { new InputFilter() {
- @Override
- public CharSequence filter(
- CharSequence source,
- int start, int end,
- Spanned dest, int dstart,
- int dend) {
- return null;
- }
- } });
- InputMethodManager im = (InputMethodManager) worknotxt
- .getContext().getSystemService(
- Context.INPUT_METHOD_SERVICE);
- im.hideSoftInputFromWindow(
- worknotxt.getWindowToken(),
- InputMethodManager.HIDE_NOT_ALWAYS);
- barcodeEdt.setEnabled(true);
- barcodeEdt.setText("");
- barcodeEdt.setFocusable(true);
- barcodeEdt.setFocusableInTouchMode(true);
- barcodeEdt
- .setFilters(new InputFilter[] { new InputFilter() {
- @Override
- public CharSequence filter(
- CharSequence source,
- int start, int end,
- Spanned dest, int dstart,
- int dend) {
- return null;
- }
- } });
- //CommonUtil.BarcodeMaxLength(barcodeEdt, 50);
- if (bugnoEdt != null) {
- bugnoEdt.setEnabled(true);
- bugnoEdt.setText("");
- bugnoEdt.setFocusable(true);
- bugnoEdt.setFocusableInTouchMode(true);
- bugnoEdt.setFilters(new InputFilter[] { new InputFilter() {
- @Override
- public CharSequence filter(
- CharSequence source, int start,
- int end, Spanned dest,
- int dstart, int dend) {
- return null;
- }
- } });
- }
- if (buglocEdt != null) {
- buglocEdt.setEnabled(true);
- buglocEdt.setText("");
- buglocEdt.setFocusable(true);
- buglocEdt.setFocusableInTouchMode(true);
- buglocEdt
- .setFilters(new InputFilter[] { new InputFilter() {
- @Override
- public CharSequence filter(
- CharSequence source,
- int start, int end,
- Spanned dest,
- int dstart, int dend) {
- return null;
- }
- } });
- }
- } else {
- Activity activity = (Activity) con;
- activity.finish();
- }
- return;
- }
- }
- }).create();
- alertDialog.setCanceledOnTouchOutside(false);
- alertDialog.show();
- }
- public static void showKilncarWorkNoAlertDialog(final int status,
- String message, final Context con, final EditText worknotxt,
- final EditText barcodeEdt, final EditText kilnEdt,
- final EditText kilncarEdt, final int collectType) {
- Dialog alertDialog = new AlertDialog.Builder(con).setMessage(message)
- .setPositiveButton("确定", new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- if (status == -1 || status == -2 || status == -3) {
- ExitUtil eu = new ExitUtil(con);
- eu.exit();
- }
- else if (status == 0) {
- if (collectType == 1) {
- worknotxt.setEnabled(true);
- worknotxt.setText("");
- worknotxt.setFocusable(true);
- worknotxt.setFocusableInTouchMode(true);
- worknotxt.requestFocus();
- worknotxt.findFocus();
- worknotxt
- .setFilters(new InputFilter[] { new InputFilter() {
- @Override
- public CharSequence filter(
- CharSequence source,
- int start, int end,
- Spanned dest, int dstart,
- int dend) {
- return null;
- }
- } });
- kilnEdt.setEnabled(true);
- kilnEdt.setFocusable(true);
- kilnEdt.setFocusableInTouchMode(true);
- kilncarEdt.setEnabled(true);
- kilncarEdt.setText("");
- kilncarEdt.setFocusable(true);
- kilncarEdt.setFocusableInTouchMode(true);
- kilncarEdt
- .setFilters(new InputFilter[] { new InputFilter() {
- @Override
- public CharSequence filter(
- CharSequence source,
- int start, int end,
- Spanned dest, int dstart,
- int dend) {
- return null;
- }
- } });
- if (barcodeEdt != null) {
- barcodeEdt.setEnabled(true);
- barcodeEdt.setText("");
- barcodeEdt.setFocusable(true);
- barcodeEdt.setFocusableInTouchMode(true);
- }
- } else {
- Activity activity = (Activity) con;
- activity.finish();
- }
- return;
- } else {
- if (collectType == 1) {
- worknotxt.setEnabled(true);
- worknotxt.setText("");
- worknotxt.setFocusable(true);
- worknotxt.setFocusableInTouchMode(true);
- worknotxt.requestFocus();
- worknotxt.findFocus();
- worknotxt
- .setFilters(new InputFilter[] { new InputFilter() {
- @Override
- public CharSequence filter(
- CharSequence source,
- int start, int end,
- Spanned dest, int dstart,
- int dend) {
- return null;
- }
- } });
- InputMethodManager im = (InputMethodManager) worknotxt
- .getContext().getSystemService(
- Context.INPUT_METHOD_SERVICE);
- im.hideSoftInputFromWindow(
- worknotxt.getWindowToken(),
- InputMethodManager.HIDE_NOT_ALWAYS);
- kilnEdt.setEnabled(true);
- kilnEdt.setFocusable(true);
- kilnEdt.setFocusableInTouchMode(true);
- kilncarEdt.setEnabled(true);
- kilncarEdt.setText("");
- kilncarEdt.setFocusable(true);
- kilncarEdt.setFocusableInTouchMode(true);
- kilncarEdt
- .setFilters(new InputFilter[] { new InputFilter() {
- @Override
- public CharSequence filter(
- CharSequence source,
- int start, int end,
- Spanned dest, int dstart,
- int dend) {
- return null;
- }
- } });
- if (barcodeEdt != null) {
- barcodeEdt.setEnabled(true);
- barcodeEdt.setText("");
- barcodeEdt.setFocusable(true);
- barcodeEdt.setFocusableInTouchMode(true);
- }
- } else {
- Activity activity = (Activity) con;
- activity.finish();
- }
- return;
- }
- }
- }).create();
- alertDialog.setCanceledOnTouchOutside(false);
- alertDialog.show();
- }
- public static void showBarCodeAlertDialog(final int status, String message,
- final Context con, final EditText barcodeEdt,
- final EditText bugnoEdt, final EditText buglocEdt) {
- Dialog alertDialog = new AlertDialog.Builder(con).setMessage(message)
- .setPositiveButton("确定", new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- if (status == -1 || status == -2 || status == -3) {
- ExitUtil eu = new ExitUtil(con);
- eu.exit();
- }
- else if (status == 0) {
- if (barcodeEdt != null) {
- barcodeEdt.setEnabled(true);
- barcodeEdt.setText("");
- barcodeEdt.setFocusable(true);
- barcodeEdt.setFocusableInTouchMode(true);
- barcodeEdt.requestFocus();
- barcodeEdt.findFocus();
- barcodeEdt
- .setFilters(new InputFilter[] { new InputFilter() {
- @Override
- public CharSequence filter(
- CharSequence source,
- int start, int end,
- Spanned dest, int dstart,
- int dend) {
- return null;
- }
- } });
- //CommonUtil.BarcodeMaxLength(barcodeEdt, 50);
- InputMethodManager im = (InputMethodManager) barcodeEdt
- .getContext().getSystemService(
- Context.INPUT_METHOD_SERVICE);
- im.hideSoftInputFromWindow(
- barcodeEdt.getWindowToken(),
- InputMethodManager.HIDE_NOT_ALWAYS);
- }
- if (bugnoEdt != null) {
- bugnoEdt.setEnabled(true);
- bugnoEdt.setFocusable(true);
- bugnoEdt.setFocusableInTouchMode(true);
- bugnoEdt.setFilters(new InputFilter[] { new InputFilter() {
- @Override
- public CharSequence filter(
- CharSequence source, int start,
- int end, Spanned dest, int dstart,
- int dend) {
- return null;
- }
- } });
- }
- if (buglocEdt != null) {
- buglocEdt.setEnabled(true);
- buglocEdt.setFocusable(true);
- buglocEdt.setFocusableInTouchMode(true);
- buglocEdt
- .setFilters(new InputFilter[] { new InputFilter() {
- @Override
- public CharSequence filter(
- CharSequence source,
- int start, int end,
- Spanned dest, int dstart,
- int dend) {
- return null;
- }
- } });
- }
- return;
- }
- else {
- if (barcodeEdt != null) {
- barcodeEdt.setEnabled(true);
- barcodeEdt.setText("");
- barcodeEdt.setFocusable(true);
- barcodeEdt.setFocusableInTouchMode(true);
- barcodeEdt.requestFocus();
- barcodeEdt.findFocus();
- barcodeEdt
- .setFilters(new InputFilter[] { new InputFilter() {
- @Override
- public CharSequence filter(
- CharSequence source,
- int start, int end,
- Spanned dest, int dstart,
- int dend) {
- return null;
- }
- } });
- //CommonUtil.BarcodeMaxLength(barcodeEdt, 50);
- InputMethodManager im = (InputMethodManager) barcodeEdt
- .getContext().getSystemService(
- Context.INPUT_METHOD_SERVICE);
- im.hideSoftInputFromWindow(
- barcodeEdt.getWindowToken(),
- InputMethodManager.HIDE_NOT_ALWAYS);
- }
- if (bugnoEdt != null) {
- bugnoEdt.setEnabled(true);
- bugnoEdt.setFocusable(true);
- bugnoEdt.setFocusableInTouchMode(true);
- bugnoEdt.setFilters(new InputFilter[] { new InputFilter() {
- @Override
- public CharSequence filter(
- CharSequence source, int start,
- int end, Spanned dest, int dstart,
- int dend) {
- return null;
- }
- } });
- }
- if (buglocEdt != null) {
- buglocEdt.setEnabled(true);
- buglocEdt.setFocusable(true);
- buglocEdt.setFocusableInTouchMode(true);
- buglocEdt
- .setFilters(new InputFilter[] { new InputFilter() {
- @Override
- public CharSequence filter(
- CharSequence source,
- int start, int end,
- Spanned dest, int dstart,
- int dend) {
- return null;
- }
- } });
- }
- return;
- }
- }
- }).create();
- alertDialog.setCanceledOnTouchOutside(false);
- alertDialog.show();
- }
- public static void showScrapBarCodeAlertDialog(final int status,
- String message, final Context con, final EditText barcodeEdt,
- final EditText worknoEdt, final EditText scrapFinesEdt,
- final EditText memoEdt) {
- Dialog alertDialog = new AlertDialog.Builder(con).setMessage(message)
- .setPositiveButton("确定", new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- if (status == -1 || status == -2 || status == -3) {
- ExitUtil eu = new ExitUtil(con);
- eu.exit();
- }
- else if (status == 0) {
- barcodeEdt.setEnabled(true);
- barcodeEdt.setText("");
- barcodeEdt.setFocusable(true);
- barcodeEdt.setFocusableInTouchMode(true);
- barcodeEdt.requestFocus();
- barcodeEdt.findFocus();
- barcodeEdt
- .setFilters(new InputFilter[] { new InputFilter() {
- @Override
- public CharSequence filter(
- CharSequence source, int start,
- int end, Spanned dest,
- int dstart, int dend) {
- return null;
- }
- } });
- //CommonUtil.BarcodeMaxLength(barcodeEdt, 50);
- InputMethodManager im = (InputMethodManager) barcodeEdt
- .getContext().getSystemService(
- Context.INPUT_METHOD_SERVICE);
- im.hideSoftInputFromWindow(
- barcodeEdt.getWindowToken(),
- InputMethodManager.HIDE_NOT_ALWAYS);
- if (scrapFinesEdt != null) {
- scrapFinesEdt.setEnabled(true);
- scrapFinesEdt.setText("");
- scrapFinesEdt.setFocusable(true);
- scrapFinesEdt.setFocusableInTouchMode(true);
- scrapFinesEdt
- .setFilters(new InputFilter[] { new InputFilter() {
- @Override
- public CharSequence filter(
- CharSequence source,
- int start, int end,
- Spanned dest, int dstart,
- int dend) {
- return null;
- }
- } });
- }
- if (worknoEdt != null) {
- worknoEdt.setEnabled(true);
- worknoEdt.setFocusable(true);
- worknoEdt.setFocusableInTouchMode(true);
- }
- if (memoEdt != null) {
- memoEdt.setEnabled(true);
- memoEdt.setFocusable(true);
- memoEdt.setFocusableInTouchMode(true);
- }
- return;
- }
- else {
- barcodeEdt.setEnabled(true);
- barcodeEdt.setText("");
- barcodeEdt.setFocusable(true);
- barcodeEdt.setFocusableInTouchMode(true);
- barcodeEdt.requestFocus();
- barcodeEdt.findFocus();
- barcodeEdt
- .setFilters(new InputFilter[] { new InputFilter() {
- @Override
- public CharSequence filter(
- CharSequence source, int start,
- int end, Spanned dest,
- int dstart, int dend) {
- return null;
- }
- } });
- //CommonUtil.BarcodeMaxLength(barcodeEdt, 50);
- InputMethodManager im = (InputMethodManager) barcodeEdt
- .getContext().getSystemService(
- Context.INPUT_METHOD_SERVICE);
- im.hideSoftInputFromWindow(
- barcodeEdt.getWindowToken(),
- InputMethodManager.HIDE_NOT_ALWAYS);
- if (scrapFinesEdt != null) {
- scrapFinesEdt.setEnabled(true);
- scrapFinesEdt.setText("");
- scrapFinesEdt.setFocusable(true);
- scrapFinesEdt.setFocusableInTouchMode(true);
- scrapFinesEdt
- .setFilters(new InputFilter[] { new InputFilter() {
- @Override
- public CharSequence filter(
- CharSequence source,
- int start, int end,
- Spanned dest, int dstart,
- int dend) {
- return null;
- }
- } });
- }
- if (worknoEdt != null) {
- worknoEdt.setEnabled(true);
- worknoEdt.setFocusable(true);
- worknoEdt.setFocusableInTouchMode(true);
- }
- if (memoEdt != null) {
- memoEdt.setEnabled(true);
- memoEdt.setFocusable(true);
- memoEdt.setFocusableInTouchMode(true);
- }
- return;
- }
- }
- }).create();
- alertDialog.setCanceledOnTouchOutside(false);
- alertDialog.show();
- }
- public static void showSaveAlertDialog(final int status, String message,
- final Context con, final EditText worknoEdt,
- final EditText barcodeEdt, final int collectType) {
- Dialog alertDialog = new AlertDialog.Builder(con).setMessage(message)
- .setPositiveButton("确定", new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- if (status == -1 || status == -2 || status == -3) {
- ExitUtil eu = new ExitUtil(con);
- eu.exit();
- }
- else if (status == 0) {
- if (collectType == 1) {
- worknoEdt.setEnabled(true);
- worknoEdt.setText("");
- worknoEdt.setFocusable(true);
- worknoEdt.setFocusableInTouchMode(true);
- worknoEdt.requestFocus();
- worknoEdt.findFocus();
- worknoEdt
- .setFilters(new InputFilter[] { new InputFilter() {
- @Override
- public CharSequence filter(
- CharSequence source,
- int start, int end,
- Spanned dest, int dstart,
- int dend) {
- return null;
- }
- } });
- } else {
- barcodeEdt.setEnabled(true);
- barcodeEdt.setText("");
- barcodeEdt.setFocusable(true);
- barcodeEdt.setFocusableInTouchMode(true);
- barcodeEdt.requestFocus();
- barcodeEdt.findFocus();
- barcodeEdt
- .setFilters(new InputFilter[] { new InputFilter() {
- @Override
- public CharSequence filter(
- CharSequence source,
- int start, int end,
- Spanned dest, int dstart,
- int dend) {
- return null;
- }
- } });
- //CommonUtil.BarcodeMaxLength(barcodeEdt, 50);
- }
- return;
- }
- else {
- if (collectType == 1) {
- worknoEdt.setEnabled(true);
- worknoEdt.setText("");
- worknoEdt.setFocusable(true);
- worknoEdt.setFocusableInTouchMode(true);
- worknoEdt.requestFocus();
- worknoEdt.findFocus();
- worknoEdt
- .setFilters(new InputFilter[] { new InputFilter() {
- @Override
- public CharSequence filter(
- CharSequence source,
- int start, int end,
- Spanned dest, int dstart,
- int dend) {
- return null;
- }
- } });
- } else {
- barcodeEdt.setEnabled(true);
- barcodeEdt.setText("");
- barcodeEdt.setFocusable(true);
- barcodeEdt.setFocusableInTouchMode(true);
- barcodeEdt.requestFocus();
- barcodeEdt.findFocus();
- barcodeEdt
- .setFilters(new InputFilter[] { new InputFilter() {
- @Override
- public CharSequence filter(
- CharSequence source,
- int start, int end,
- Spanned dest, int dstart,
- int dend) {
- return null;
- }
- } });
- //CommonUtil.BarcodeMaxLength(barcodeEdt, 50);
- }
- return;
- }
- }
- }).create();
- alertDialog.setCanceledOnTouchOutside(false);
- alertDialog.show();
- }
- public static void showSaveBilletAlertDialog(final int deliveryType,
- final int status, String message, final Context con,
- final EditText worknoEdt, final EditText barcodeEdt,
- final int collectType) {
- Dialog alertDialog = new AlertDialog.Builder(con).setMessage(message)
- .setPositiveButton("确定", new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- if (status == -1 || status == -2 || status == -3) {
- ExitUtil eu = new ExitUtil(con);
- eu.exit();
- }
- else if (status == 0) {
- if (deliveryType == 0) {
- if (collectType == 1) {
- worknoEdt.setEnabled(true);
- worknoEdt.setText("");
- worknoEdt.setFocusable(true);
- worknoEdt.setFocusableInTouchMode(true);
- worknoEdt.requestFocus();
- worknoEdt.findFocus();
- worknoEdt
- .setFilters(new InputFilter[] { new InputFilter() {
- @Override
- public CharSequence filter(
- CharSequence source,
- int start, int end,
- Spanned dest,
- int dstart, int dend) {
- return null;
- }
- } });
- } else {
- barcodeEdt.setEnabled(true);
- barcodeEdt.setText("");
- barcodeEdt.setFocusable(true);
- barcodeEdt.setFocusableInTouchMode(true);
- barcodeEdt.requestFocus();
- barcodeEdt.findFocus();
- barcodeEdt
- .setFilters(new InputFilter[] { new InputFilter() {
- @Override
- public CharSequence filter(
- CharSequence source,
- int start, int end,
- Spanned dest,
- int dstart, int dend) {
- return null;
- }
- } });
- //CommonUtil.BarcodeMaxLength(barcodeEdt, 50);
- }
- }
- else if (deliveryType == 1) {
- barcodeEdt.setEnabled(true);
- barcodeEdt.setText("");
- barcodeEdt.setFocusable(true);
- barcodeEdt.setFocusableInTouchMode(true);
- barcodeEdt.requestFocus();
- barcodeEdt.findFocus();
- barcodeEdt
- .setFilters(new InputFilter[] { new InputFilter() {
- @Override
- public CharSequence filter(
- CharSequence source,
- int start, int end,
- Spanned dest, int dstart,
- int dend) {
- return null;
- }
- } });
- //CommonUtil.BarcodeMaxLength(barcodeEdt, 50);
- }
- return;
- }
- else {
- if (deliveryType == 0) {
- if (collectType == 1) {
- worknoEdt.setEnabled(true);
- worknoEdt.setText("");
- worknoEdt.setFocusable(true);
- worknoEdt.setFocusableInTouchMode(true);
- worknoEdt.requestFocus();
- worknoEdt.findFocus();
- worknoEdt
- .setFilters(new InputFilter[] { new InputFilter() {
- @Override
- public CharSequence filter(
- CharSequence source,
- int start, int end,
- Spanned dest,
- int dstart, int dend) {
- return null;
- }
- } });
- } else {
- barcodeEdt.setEnabled(true);
- barcodeEdt.setText("");
- barcodeEdt.setFocusable(true);
- barcodeEdt.setFocusableInTouchMode(true);
- barcodeEdt.requestFocus();
- barcodeEdt.findFocus();
- barcodeEdt
- .setFilters(new InputFilter[] { new InputFilter() {
- @Override
- public CharSequence filter(
- CharSequence source,
- int start, int end,
- Spanned dest,
- int dstart, int dend) {
- return null;
- }
- } });
- //CommonUtil.BarcodeMaxLength(barcodeEdt, 50);
- }
- } else if (deliveryType == 1) {
- barcodeEdt.setEnabled(true);
- barcodeEdt.setText("");
- barcodeEdt.setFocusable(true);
- barcodeEdt.setFocusableInTouchMode(true);
- barcodeEdt.requestFocus();
- barcodeEdt.findFocus();
- barcodeEdt
- .setFilters(new InputFilter[] { new InputFilter() {
- @Override
- public CharSequence filter(
- CharSequence source,
- int start, int end,
- Spanned dest, int dstart,
- int dend) {
- return null;
- }
- } });
- //CommonUtil.BarcodeMaxLength(barcodeEdt, 50);
- }
- return;
- }
- }
- }).create();
- alertDialog.setCanceledOnTouchOutside(false);
- alertDialog.show();
- }
- public static void showSaveKilncarAlertDialog(final int status,
- String message, final Context con, final EditText worknoEdt,
- final EditText kilnEdt, final EditText kilncarnoEdt,
- final int collectType) {
- Dialog alertDialog = new AlertDialog.Builder(con).setMessage(message)
- .setPositiveButton("确定", new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- if (status == -1 || status == -2 || status == -3) {
- ExitUtil eu = new ExitUtil(con);
- eu.exit();
- }
- else if (status == 0) {
- kilnEdt.setEnabled(true);
- kilnEdt.setFocusable(true);
- kilnEdt.setFocusableInTouchMode(true);
- if (collectType == 1) {
- worknoEdt.setEnabled(true);
- worknoEdt.setText("");
- worknoEdt.setFocusable(true);
- worknoEdt.setFocusableInTouchMode(true);
- worknoEdt.requestFocus();
- worknoEdt.findFocus();
- worknoEdt
- .setFilters(new InputFilter[] { new InputFilter() {
- @Override
- public CharSequence filter(
- CharSequence source,
- int start, int end,
- Spanned dest, int dstart,
- int dend) {
- return null;
- }
- } });
- kilncarnoEdt.setEnabled(true);
- kilncarnoEdt.setText("");
- kilncarnoEdt.setFocusable(true);
- kilncarnoEdt.setFocusableInTouchMode(true);
- } else {
- kilncarnoEdt.setEnabled(true);
- kilncarnoEdt.setText("");
- kilncarnoEdt.setFocusable(true);
- kilncarnoEdt.setFocusableInTouchMode(true);
- kilncarnoEdt.requestFocus();
- kilncarnoEdt.findFocus();
- }
- return;
- }
- else {
- kilnEdt.setEnabled(true);
- kilnEdt.setFocusable(true);
- kilnEdt.setFocusableInTouchMode(true);
- if (collectType == 1) {
- worknoEdt.setEnabled(true);
- worknoEdt.setText("");
- worknoEdt.setFocusable(true);
- worknoEdt.setFocusableInTouchMode(true);
- worknoEdt.requestFocus();
- worknoEdt.findFocus();
- worknoEdt
- .setFilters(new InputFilter[] { new InputFilter() {
- @Override
- public CharSequence filter(
- CharSequence source,
- int start, int end,
- Spanned dest, int dstart,
- int dend) {
- return null;
- }
- } });
- kilncarnoEdt.setEnabled(true);
- kilncarnoEdt.setText("");
- kilncarnoEdt.setFocusable(true);
- kilncarnoEdt.setFocusableInTouchMode(true);
- } else {
- kilncarnoEdt.setEnabled(true);
- kilncarnoEdt.setText("");
- kilncarnoEdt.setFocusable(true);
- kilncarnoEdt.setFocusableInTouchMode(true);
- kilncarnoEdt.requestFocus();
- kilncarnoEdt.findFocus();
- }
- return;
- }
- }
- }).create();
- alertDialog.setCanceledOnTouchOutside(false);
- alertDialog.show();
- }
- public static void showStaffWorknoAlertDialog(final int status,
- String message, final Context con, final EditText worknoEdt) {
- Dialog alertDialog = new AlertDialog.Builder(con).setMessage(message)
- .setPositiveButton("确定", new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- if (status == -1 || status == -2 || status == -3) {
- ExitUtil eu = new ExitUtil(con);
- eu.exit();
- }
- else if (status == 0) {
- worknoEdt.setEnabled(true);
- worknoEdt.setText("");
- worknoEdt.setFocusable(true);
- worknoEdt.setFocusableInTouchMode(true);
- worknoEdt.requestFocus();
- worknoEdt.findFocus();
- worknoEdt
- .setFilters(new InputFilter[] { new InputFilter() {
- @Override
- public CharSequence filter(
- CharSequence source, int start,
- int end, Spanned dest,
- int dstart, int dend) {
- return null;
- }
- } });
- return;
- }
- else {
- worknoEdt.setEnabled(true);
- worknoEdt.setText("");
- worknoEdt.setFocusable(true);
- worknoEdt.setFocusableInTouchMode(true);
- worknoEdt.requestFocus();
- worknoEdt.findFocus();
- worknoEdt
- .setFilters(new InputFilter[] { new InputFilter() {
- @Override
- public CharSequence filter(
- CharSequence source, int start,
- int end, Spanned dest,
- int dstart, int dend) {
- return null;
- }
- } });
- return;
- }
- }
- }).create();
- alertDialog.setCanceledOnTouchOutside(false);
- alertDialog.show();
- }
- public static String getCurrentDate() {
- Calendar c = Calendar.getInstance();
- SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
- String formattedDate = df.format(c.getTime());
- return formattedDate;
- }
- public static Date ParseStringToDateTime(String s) {
- Date date = null;
- SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- try {
- date = formatter.parse(s);
- }
- catch (ParseException e) {
- e.printStackTrace();
- }
- return date;
- }
- public static Date ParseStringToDate(String s) {
- java.sql.Date d = null;
- d = java.sql.Date.valueOf(s);
- return d;
- }
- public static boolean CheckedDutyPersonStatus(
- List<DutyPerson> dutypersonList) {
- boolean checkedStatus = false;
- for (DutyPerson dp : dutypersonList) {
- if (dp.isCheckStatus()) {
- checkedStatus = true;
- break;
- }
- }
- return checkedStatus;
- }
- public static List<DefectFines> getDefectFinesListByDefectId(
- String orgDefectId,
- List<DefectAndDefectFinesRelation> defectFineRelationList) {
- List<DefectFines> tempDefectFinesList = null;
- for (DefectAndDefectFinesRelation relation : defectFineRelationList) {
- String defectId = relation.getDefectId();
- if (defectId.equals(orgDefectId)) {
- tempDefectFinesList = relation.getDefectFinesList();
- break;
- }
- }
- return tempDefectFinesList;
- }
- public static List<DefectDeduction> getDefectDeductionListByDefectId(
- String orgDefectId,
- List<DefectAndDefectDeductionRelation> defectDeductionRelationList) {
- List<DefectDeduction> tempDefectDeductionList = null;
- for (DefectAndDefectDeductionRelation relation : defectDeductionRelationList) {
- String defectId = relation.getDefectId();
- if (defectId.equals(orgDefectId)) {
- tempDefectDeductionList = relation.getDefectDeductionList();
- break;
- }
- }
- return tempDefectDeductionList;
- }
- public static List<DutyPerson> getCheckedDutyPersonList(
- List<DutyPerson> dutypersonList) {
- List<DutyPerson> checkedDutyPersonList = new ArrayList<DutyPerson>();
- for (DutyPerson dp : dutypersonList) {
- if (dp.isCheckStatus()) {
- checkedDutyPersonList.add(dp);
- }
- }
- return checkedDutyPersonList;
- }
- public static boolean IsIntValue(String s) {
- boolean bCheckResult = true;
- try {
- Integer iCheckValue = Integer.parseInt(s);
- if (iCheckValue instanceof Integer == false) {
- bCheckResult = false;
- }
- } catch (NumberFormatException e) {
- bCheckResult = false;
- }
- return bCheckResult;
- }
- public static boolean IsDoubleValue(String s) {
- boolean bCheckResult = true;
- try {
- Double iCheckValue = Double.parseDouble(s);
- if (iCheckValue instanceof Double == false) {
- bCheckResult = false;
- }
- } catch (NumberFormatException e) {
- bCheckResult = false;
- }
- return bCheckResult;
- }
- }
|