Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/358.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 数据库操作需要一个生命周期来处理_Java_Android_File_Sqlite - Fatal编程技术网

Java 数据库操作需要一个生命周期来处理

Java 数据库操作需要一个生命周期来处理,java,android,file,sqlite,Java,Android,File,Sqlite,好吧,这更像是速度问题。问题是我从不同的来源获取了三个字段,比如Contacts、Facebook和Google plus。这三个字段是日期、姓名和联系人图像URi。逻辑是这样的,每个源都写入一个文件,联系人——文件,Facebook——附加到同一个文件,Google Plus——附加到同一个文件。此操作非常快,需要正常时间执行。这将创建我的原始数据源。然后从这个文件中,我分别获取每个记录(包含三个字段的行),并进行一些计算,并将与每个记录相关的数据写入三个不同的数据库表中。虽然这在四核手机上运

好吧,这更像是速度问题。问题是我从不同的来源获取了三个字段,比如Contacts、Facebook和Google plus。这三个字段是日期、姓名和联系人图像URi。逻辑是这样的,每个源都写入一个文件,联系人——文件,Facebook——附加到同一个文件,Google Plus——附加到同一个文件。此操作非常快,需要正常时间执行。这将创建我的原始数据源。然后从这个文件中,我分别获取每个记录(包含三个字段的行),并进行一些计算,并将与每个记录相关的数据写入三个不同的数据库表中。虽然这在四核手机上运行得很快,但在双核手机上的处理速度太慢。在双核上处理150条记录大约需要10分钟,在四核上处理150条记录需要4分钟。我困惑于如何提高速度?我是否应该放弃将文件作为原始数据源的想法,转而切换到数据库表?最快的是什么

代码如下:

    private class MagicCall extends AsyncTask<Void, String, String> {

        int years; 
        long secon; 
        long min; 
        int hours;
        int mon; 
        int days;
        int weeks;
        String CONTACT_ID,CONTACT_NAME,CONTACT_IMAGE_URI; 

        ProgressDialog Asycdialog = new ProgressDialog(LoaderClass.this);

        @Override
        protected void onPreExecute() {
            boolean DIALOG_SHOW = true;
            try{
                BufferedReader br = null; 
                if(FLAG ==1){
                    br = new BufferedReader(new FileReader(getApplicationContext().getFilesDir()+"/xxxinders/fileone.txt"));    
                }else{
                    br = new BufferedReader(new FileReader(getApplicationContext().getFilesDir()+"/xxxinders/output.txt"));  
                }
                if (br.readLine() == null) {
                    Toast.makeText(getApplicationContext(),"There are no contacts with Birthday details, try syncing with Facebook and/or Google", Toast.LENGTH_LONG).show(); 
                    DIALOG_SHOW = false; 
                }
            }catch(Exception e){
                System.out.println(e);
            }
            if(DIALOG_SHOW){
                //Init the LoaderDialog 
                Asycdialog.setMessage("Working");
                Asycdialog.getWindow().setGravity(Gravity.CENTER_VERTICAL);
                Asycdialog.getWindow().setGravity(Gravity.CENTER_HORIZONTAL);
                Asycdialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
                Asycdialog.setCancelable(false);
                //Dialog Show
                Asycdialog.show();

            }

            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
            Editor editor = prefs.edit();
            editor.putBoolean("async", true);
            editor.commit();
            super.onPreExecute();
        }

        protected void onPostExecute(String result) {
            // hide the dialog

            DateFormat df = new SimpleDateFormat("EEE, d MMM yyyy, h:mm a");
            String date = df.format(Calendar.getInstance().getTime());
            SharedPreferences prefsx = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
            Editor editorx = prefsx.edit();
            editorx.putString("refresh", date);
            editorx.commit();



            dbHelper.close();
            Asycdialog.dismiss();
            startActivity(new Intent(LoaderClass.this, MainActivity.class));
            finish();

            super.onPostExecute(result);
        }

        @Override
        protected String doInBackground(Void... args) {

            dbHelper = new DBAdapter(getApplicationContext());
            dbHelper.open(); 
            int i=0;
            int lines = 0;
            //  int prog = fetchAdhoc();
            String progress = null; 
            String dateToInsert;
            try{
                BufferedReader reader;
                if(FLAG ==1){
                    reader = new BufferedReader(new FileReader(getApplicationContext().getFilesDir()+"/xxxinders/fileone.txt"));
                }else{
                    reader = new BufferedReader(new FileReader(getApplicationContext().getFilesDir()+"/xxxinders/output.txt"));
                }
                while (reader.readLine() != null) lines++;
                reader.close();
            }catch(Exception e){

            }

            Cursor c = dbHelper.fetchAdhoc(); 
            ADHOC_COUNT = (c.getCount());
            lines=lines+ADHOC_COUNT;
            dbHelper.NotificationDrop(); 
            if (c.moveToFirst()) {
                do {
                    try{
                        String name = c.getString(c.getColumnIndexOrThrow("Name"));
                        String displayBirthday = c.getString(c.getColumnIndexOrThrow("DOB"));
                        String imageData = c.getString(c.getColumnIndexOrThrow("ImageData"));
                        String primaryAdhoc = c.getString(c.getColumnIndexOrThrow("_id"));
                        //CONTACT_ID,CONTACT_NAME,CONTACT_IMAGE_URI

                        CONTACT_ID = primaryAdhoc;
                        CONTACT_NAME = toTitleCase(name); 
                        CONTACT_IMAGE_URI = imageData; 
                        dateToInsert = displayBirthday; 

                        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
                        Date date = format.parse(dateToInsert);
                        java.sql.Date dx = new java.sql.Date(date.getTime());
                        Date key = dx;

                        years = getDiffYear(key);               // For years elapsed
                        secon = seconds(key);                   // for seconds elapsed
                        min = seconds(key) / 60;                // For minutes elapsed
                        hours = (int) (seconds(key) / 60) / 60; // For hours elapsed
                        mon = months(String.valueOf(key));      // for months elapsed

                        days = daysElapsed(key);                // Days elapsed
                        weeks = daysElapsed(key) / 7;           // For weeks


                        System.out.println(lines);
                        progress = ("" + (CONTACT_NAME) + "\n"+ i + " of " + lines + " Contacts");
                        dbHelper.insert(dateToInsert, CONTACT_NAME, String.valueOf(days), String.valueOf(hours), CONTACT_IMAGE_URI, String.valueOf(min),String.valueOf(mon), String.valueOf(secon), CONTACT_ID, String.valueOf(weeks), String.valueOf(years));

                        int PRIMARY_ID = dbHelper.getPrimaryId(); // Fetch the PrimaryId (_id) of the above inserted row, its the Foreign key for Notification and SpecialNotifications Table. 
                        String FOREIGN_KEY = dbHelper.getHighestID(PRIMARY_ID); // Same as above, but fetches the Name field of the last inserted row. 



                        //=========================================================================
                        //**Database Insertions Notifications Table/ SpecialNotifications Table**
                        //=========================================================================



                        //=======================================================================================//
                        //Regular intervals DB Insertions: 
                        //======================================================================================//
                        //Notification Types:
                        //1 for months
                        //2 for weeks
                        //3 for days
                        //4 for minutes
                        //5 for years
                        //6 for seconds
                        //7 for hours
                        //======================================================================================//

                        //==============================
                        //For Months 
                        //==============================
                        intCal.monthsNotify(mon, dateToInsert);
                        int monSpecial =  intCal.getMonthRegular(); 
                        Date dateMonReg = intCal.getMonRegDate(); 


                        dbHelper.insertNotifications(1, convertDate(dateMonReg), 0, monSpecial,FOREIGN_KEY,PRIMARY_ID);


                        //===============================
                        //For Weeks 
                        //===============================
                        intCal.weeksToNotify(weeks,dateToInsert); 
                        int weekSpecial = intCal.getWeekRegular();
                        Date dateWeekReg =intCal.getWeekRegDate(); 

                        dbHelper.insertNotifications(2, convertDate(dateWeekReg), 0, weekSpecial,FOREIGN_KEY,PRIMARY_ID);


                        //===============================
                        //For Days
                        //===============================
                        intCal.daysToNotify(days, dateToInsert); 
                        int daysSpecial= intCal.getDaysRegular();  
                        Date dateDaysReg = intCal.getDaysRegDate(); 

                        dbHelper.insertNotifications(3, convertDate(dateDaysReg), 0, daysSpecial,FOREIGN_KEY,PRIMARY_ID);


                        //===============================
                        //For minutes
                        //===============================
                        intCal.minutesToNotify(min,dateToInsert);
                        long minutesSpecial= intCal.getMinutesRegular();
                        Date dateMinsReg = intCal.getMinutesRegDate(); 

                        dbHelper.insertNotifications(4, convertDate(dateMinsReg), 0,(int) minutesSpecial,FOREIGN_KEY,PRIMARY_ID);


                        //==============================
                        //For Years
                        //==============================
                        intCal.yearsToNotify(years, dateToInsert); 
                        int yearsSpecial = intCal.getYearsRegular();
                        Date dateYearsReg = intCal.getYearsRegDate();

                        dbHelper.insertNotifications(5, convertDate(dateYearsReg), 0, yearsSpecial,FOREIGN_KEY,PRIMARY_ID);


                        //=============================
                        //For Seconds
                        //=============================
                        intCal.secondsToNotify(secon, dateToInsert);
                        long secondsSpecial= intCal.getSecondsRegular(); 
                        Date dateSecondsReg = intCal.getSecondsRegDate(); 

                        dbHelper.insertNotifications(6, convertDate(dateSecondsReg), 0, secondsSpecial,FOREIGN_KEY,PRIMARY_ID);


                        //=============================
                        //For Hours
                        //=============================
                        intCal.hoursToNotify(hours, dateToInsert); 
                        int hoursSpecial= intCal.getHoursRegular();
                        Date dateHoursReg= intCal.getHoursRegDate(); 

                        dbHelper.insertNotifications(7, convertDate(dateHoursReg), 0, hoursSpecial,FOREIGN_KEY,PRIMARY_ID);



                        //============================================================================================//
                        //Special Intervals
                        //============================================================================================//
                        //Notification Types:
                        //1 for months
                        //2 for weeks
                        //3 for days
                        //4 for minutes
                        //5 for years
                        //6 for seconds
                        //7 for hours
                        //For Years
                        intCal.specialIntervalYears(years, dateToInsert); 
                        int yearsOnceSpecial =intCal.getYearsSpecial();
                        Date dateYearsSpecial = intCal.getYearsSpDate(); 
                        dbHelper.insertSpecialNotifications(5, convertDate(dateYearsSpecial), yearsOnceSpecial,FOREIGN_KEY,PRIMARY_ID);


                        //For Months
                        intCal.specialIntervalMonths(mon,dateToInsert); 
                        int monthsOnceSpecial= intCal.getMonthsSpecial();
                        Date dateMonthsSpecial = intCal.getMonthsSpDate();
                        dbHelper.insertSpecialNotifications(1, convertDate(dateMonthsSpecial), monthsOnceSpecial,FOREIGN_KEY,PRIMARY_ID);


                        //For Weeks
                        intCal.specialIntervalsWeeks(weeks,dateToInsert); 
                        int weeksOnceSpecial= intCal.getWeeksSpecial(); 
                        Date dateWeeksSpecial = intCal.getWeeksSpDate(); 
                        dbHelper.insertSpecialNotifications(2, convertDate(dateWeeksSpecial), weeksOnceSpecial,FOREIGN_KEY,PRIMARY_ID);

                        //For Days
                        intCal.specialIntervalsDays(days, dateToInsert); 
                        int daysOnceSpecial= intCal.getDaysSpecial(); 
                        Date dateDaysSpecial = intCal.getDaysSpDate(); 
                        dbHelper.insertSpecialNotifications(3, convertDate(dateDaysSpecial), daysOnceSpecial,FOREIGN_KEY,PRIMARY_ID);

                        //For Hours
                        intCal.specialIntervalsHours(hours,dateToInsert); 
                        int hoursOnceSpecial= intCal.getHoursSpecial();  
                        Date dateHoursSpecial = intCal.getHoursSpDate(); 
                        dbHelper.insertSpecialNotifications(7, convertDate(dateHoursSpecial), hoursOnceSpecial,FOREIGN_KEY,PRIMARY_ID);

                        //For Minutes
                        intCal.specialIntervalMinutes(min,dateToInsert); 
                        long minutesOnceSpecial= intCal.getMinutesSpecial(); 
                        Date dateMinutesSpecial= intCal.getMinutesSpDate(); 
                        dbHelper.insertSpecialNotifications(4, convertDate(dateMinutesSpecial), (int)minutesOnceSpecial,FOREIGN_KEY,PRIMARY_ID);

                        //For Seconds
                        intCal.specialIntervalsSeconds(secon,dateToInsert); 
                        long secondsOnceSpecial= intCal.getSecondsSpecial(); 
                        Date dateSecondsSpecial= intCal.getSecondsSpDate(); 
                        dbHelper.insertSpecialNotifications(6, convertDate(dateSecondsSpecial), secondsOnceSpecial,FOREIGN_KEY,PRIMARY_ID); 
                        i++; 
                    }catch(Exception e){

                    }
                    publishProgress(progress);
                    Asycdialog.setMax(lines);
                    Asycdialog.incrementProgressBy(1);
                }while(c.moveToNext()); 
            }









            // 
            // Dear maintainer:
            // 
            // Once you are done trying to 'optimise' this routine,
            // and have realized what a terrible mistake that was,
            // please increment the following counter as a warning
            // to the next guy:
            // 
            // total_hours_wasted_here = 0;
            //




            //int i=0;
            File toRead = null;
            try{
                if(FLAG ==1){
                    toRead=new File(getApplicationContext().getFilesDir()+"/xxxinders/fileone.txt");
                }else{
                    toRead=new File(getApplicationContext().getFilesDir()+"/xxxinders/output.txt");
                }
                FileInputStream fis=new FileInputStream(toRead);

                Scanner sc=new Scanner(fis);


                String currentLine;
                while(sc.hasNextLine()){


                    currentLine=sc.nextLine();

                    StringTokenizer st=new StringTokenizer(currentLine,"=",false);


                    CONTACT_NAME = toTitleCase(st.nextToken());
                    if(CONTACT_NAME.contains("'")){
                        CONTACT_NAME = CONTACT_NAME.replace("'", "");
                    }

                    // *********
                    String listStr = st.nextToken();

                    String cut = listStr.substring(1, listStr.length() - 1);

                    String[] array = cut.split(",");
                    CONTACT_ID = (array[0].trim());

                    String dateStr = (array[1].trim());
                    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
                    Date date = format.parse(dateStr);
                    java.sql.Date dx = new java.sql.Date(date.getTime());
                    Date key = dx;
                    dateToInsert = String.valueOf(dx); 

                    CONTACT_IMAGE_URI = (array[2].trim());


                    if (isCancelled()) {
                        break;
                    }
                    progress = ("" + Character.toUpperCase(CONTACT_NAME.charAt(0)) + CONTACT_NAME.substring(1) + "\n"+i + " of " + lines + " Contacts"); // Progress displayed here. 



                    years = getDiffYear(key);               // For years elapsed
                    secon = seconds(key);                   // for seconds elapsed
                    min = seconds(key) / 60;                // For minutes elapsed
                    hours = (int) (seconds(key) / 60) / 60; // For hours elapsed
                    mon = months(String.valueOf(key));      // for months elapsed

                    days = daysElapsed(key);                // Days elapsed
                    weeks = daysElapsed(key) / 7;           // For weeks

                    //===============================================================================================================
                    if (dateToInsert.contains("0001-") == true){ //Special Case, we added 0001 to Birthdays Which Have NO Year field. 
                        //===========================================================================================================

                        dbHelper.insert(dateToInsert, CONTACT_NAME, "","", CONTACT_IMAGE_URI, "", "", "", CONTACT_ID, "", ""); // All other fields will be empty, because we don't have a Year. 
                        int PRIMARY_ID = dbHelper.getPrimaryId();
                        String FOREIGN_KEY = dbHelper.getHighestID(PRIMARY_ID); 


                        //=====================================================================================================
                        //In this case we are only interested in fetching the year alert for next birthday of this contact -->
                        //=====================================================================================================

                        intCal.yearsToNotify(years, dateToInsert); 
                        int yearsSpecial = intCal.getYearsRegular();
                        Date dateYearsReg = intCal.getYearsRegDate();

                        dbHelper.insertNotifications(5, convertDate(dateYearsReg), 0, yearsSpecial,FOREIGN_KEY,PRIMARY_ID); 

                    }
                    //=========================================================================
                    //Case when all the Date fields exist and we set up notifications  --->
                    //=========================================================================
                    else if(dateToInsert != "null" && dateToInsert.contains("0001-") != true){

                        dbHelper.insert(dateToInsert, CONTACT_NAME, String.valueOf(days), String.valueOf(hours), CONTACT_IMAGE_URI, String.valueOf(min),String.valueOf(mon), String.valueOf(secon), CONTACT_ID, String.valueOf(weeks), String.valueOf(years));

                        int PRIMARY_ID = dbHelper.getPrimaryId(); // Fetch the PrimaryId (_id) of the above inserted row, its the Foreign key for Notification and SpecialNotifications Table. 
                        String FOREIGN_KEY = dbHelper.getHighestID(PRIMARY_ID); // Same as above, but fetches the Name field of the last inserted row. 



                        //=========================================================================
                        //**Database Insertions Notifications Table/ SpecialNotifications Table**
                        //=========================================================================



                        //=======================================================================================//
                        //Regular intervals DB Insertions: 
                        //======================================================================================//
                        //Notification Types:
                        //1 for months
                        //2 for weeks
                        //3 for days
                        //4 for minutes
                        //5 for years
                        //6 for seconds
                        //7 for hours
                        //======================================================================================//

                        //==============================
                        //For Months 
                        //==============================
                        intCal.monthsNotify(mon, dateToInsert);
                        int monSpecial =  intCal.getMonthRegular(); 
                        Date dateMonReg = intCal.getMonRegDate(); 


                        dbHelper.insertNotifications(1, convertDate(dateMonReg), 0, monSpecial,FOREIGN_KEY,PRIMARY_ID);


                        //===============================
                        //For Weeks 
                        //===============================
                        intCal.weeksToNotify(weeks,dateToInsert); 
                        int weekSpecial = intCal.getWeekRegular();
                        Date dateWeekReg =intCal.getWeekRegDate(); 

                        dbHelper.insertNotifications(2, convertDate(dateWeekReg), 0, weekSpecial,FOREIGN_KEY,PRIMARY_ID);


                        //===============================
                        //For Days
                        //===============================
                        intCal.daysToNotify(days, dateToInsert); 
                        int daysSpecial= intCal.getDaysRegular();  
                        Date dateDaysReg = intCal.getDaysRegDate(); 

                        dbHelper.insertNotifications(3, convertDate(dateDaysReg), 0, daysSpecial,FOREIGN_KEY,PRIMARY_ID);


                        //===============================
                        //For minutes
                        //===============================
                        intCal.minutesToNotify(min,dateToInsert);
                        long minutesSpecial= intCal.getMinutesRegular();
                        Date dateMinsReg = intCal.getMinutesRegDate(); 

                        dbHelper.insertNotifications(4, convertDate(dateMinsReg), 0,(int) minutesSpecial,FOREIGN_KEY,PRIMARY_ID);


                        //==============================
                        //For Years
                        //==============================
                        intCal.yearsToNotify(years, dateToInsert); 
                        int yearsSpecial = intCal.getYearsRegular();
                        Date dateYearsReg = intCal.getYearsRegDate();

                        dbHelper.insertNotifications(5, convertDate(dateYearsReg), 0, yearsSpecial,FOREIGN_KEY,PRIMARY_ID);


                        //=============================
                        //For Seconds
                        //=============================
                        intCal.secondsToNotify(secon, dateToInsert);
                        long secondsSpecial= intCal.getSecondsRegular(); 
                        Date dateSecondsReg = intCal.getSecondsRegDate(); 

                        dbHelper.insertNotifications(6, convertDate(dateSecondsReg), 0, secondsSpecial,FOREIGN_KEY,PRIMARY_ID);


                        //=============================
                        //For Hours
                        //=============================
                        intCal.hoursToNotify(hours, dateToInsert); 
                        int hoursSpecial= intCal.getHoursRegular();
                        Date dateHoursReg= intCal.getHoursRegDate(); 

                        dbHelper.insertNotifications(7, convertDate(dateHoursReg), 0, hoursSpecial,FOREIGN_KEY,PRIMARY_ID);



                        //============================================================================================//
                        //Special Intervals
                        //============================================================================================//
                        //Notification Types:
                        //1 for months
                        //2 for weeks
                        //3 for days
                        //4 for minutes
                        //5 for years
                        //6 for seconds
                        //7 for hours
                        //For Years
                        
                        
                        intCal.specialIntervalYears(years, dateToInsert); 
                        int yearsOnceSpecial =intCal.getYearsSpecial();
                        Date dateYearsSpecial = intCal.getYearsSpDate(); 
                        dbHelper.insertSpecialNotifications(5, convertDate(dateYearsSpecial), yearsOnceSpecial,FOREIGN_KEY,PRIMARY_ID);


                        //For Months
                        intCal.specialIntervalMonths(mon,dateToInsert); 
                        int monthsOnceSpecial= intCal.getMonthsSpecial();
                        Date dateMonthsSpecial = intCal.getMonthsSpDate();
                        dbHelper.insertSpecialNotifications(1, convertDate(dateMonthsSpecial), monthsOnceSpecial,FOREIGN_KEY,PRIMARY_ID);


                        //For Weeks
                        intCal.specialIntervalsWeeks(weeks,dateToInsert); 
                        int weeksOnceSpecial= intCal.getWeeksSpecial(); 
                        Date dateWeeksSpecial = intCal.getWeeksSpDate(); 
                        dbHelper.insertSpecialNotifications(2, convertDate(dateWeeksSpecial), weeksOnceSpecial,FOREIGN_KEY,PRIMARY_ID);

                        //For Days
                        intCal.specialIntervalsDays(days, dateToInsert); 
                        int daysOnceSpecial= intCal.getDaysSpecial(); 
                        Date dateDaysSpecial = intCal.getDaysSpDate(); 
                        dbHelper.insertSpecialNotifications(3, convertDate(dateDaysSpecial), daysOnceSpecial,FOREIGN_KEY,PRIMARY_ID);

                        //For Hours
                        intCal.specialIntervalsHours(hours,dateToInsert); 
                        int hoursOnceSpecial= intCal.getHoursSpecial();  
                        Date dateHoursSpecial = intCal.getHoursSpDate(); 
                        dbHelper.insertSpecialNotifications(7, convertDate(dateHoursSpecial), hoursOnceSpecial,FOREIGN_KEY,PRIMARY_ID);

                        //For Minutes
                        intCal.specialIntervalMinutes(min,dateToInsert); 
                        long minutesOnceSpecial= intCal.getMinutesSpecial(); 
                        Date dateMinutesSpecial= intCal.getMinutesSpDate(); 
                        dbHelper.insertSpecialNotifications(4, convertDate(dateMinutesSpecial), (int)minutesOnceSpecial,FOREIGN_KEY,PRIMARY_ID);

                        //For Seconds
                        intCal.specialIntervalsSeconds(secon,dateToInsert); 
                        long secondsOnceSpecial= intCal.getSecondsSpecial(); 
                        Date dateSecondsSpecial= intCal.getSecondsSpDate(); 
                        dbHelper.insertSpecialNotifications(6, convertDate(dateSecondsSpecial), secondsOnceSpecial,FOREIGN_KEY,PRIMARY_ID); 
                        writeToSD();
                    }
                    publishProgress(progress);
                    Asycdialog.setMax(lines);
                    Asycdialog.incrementProgressBy(1);
                    i++;
                }
                writeToSD();
            }catch (Exception e){
                System.out.println(e);
            } finally{
                dbHelper.close();
            }
            return "";

        }

        protected void onProgressUpdate(String... values) {

            super.onProgressUpdate(values);
            Asycdialog.setMessage("" + values[0]);
        }


    }
私有类MagicCall扩展异步任务{
整数年;
龙秒;
龙敏;
整小时;
国际货币基金组织;
国际日;
整数周;
字符串CONTACT\u ID、CONTACT\u NAME、CONTACT\u IMAGE\u URI;
ProgressDialog Asycdialog=新建ProgressDialog(LoaderClass.this);
@凌驾
受保护的void onPreExecute(){
布尔对话框_SHOW=true;
试一试{
BufferedReader br=null;
如果(标志==1){
br=新的BufferedReader(新的文件读取器(getApplicationContext().getFileDir()+“/xxxinders/fileone.txt”);
}否则{
br=新的BufferedReader(新的文件读取器(getApplicationContext().getFileDir()+“/xxxinders/output.txt”);
}
if(br.readLine()==null){
Toast.makeText(getApplicationContext(),“没有包含生日详细信息的联系人,请尝试与Facebook和/或谷歌同步”,Toast.LENGTH_LONG.show();
DIALOG_SHOW=false;
}
}捕获(例外e){
系统输出打印ln(e);
}
如果(显示对话框){
//初始化LoaderDialog
Asycdialog.setMessage(“工作”);
Asycdialog.getWindow().setGravity(重力、重心和垂直);
Asycdialog.getWindow().setGravity(重力、中心和水平);
Asycdialog.setProgressStyle(ProgressDialog.STYLE_水平);
Asycdialog.setCancelable(假);
//对话节目
Asycdialog.show();
}
SharedReferences prefs=PreferenceManager.GetDefaultSharedReferences(getApplicationContext());
编辑器编辑器=prefs.edit();
putBoolean(“异步”,true);
commit();
super.onPreExecute();
}
受保护的void onPostExecute(字符串结果){
//隐藏对话框
DateFormat df=新的SimpleDataFormat(“EEE,d MMM yyyy,h:mm a”);
字符串date=df.format(Calendar.getInstance().getTime());
SharedReferences prefsx=PreferenceManager.GetDefaultSharedReferences(getApplicationContext());
Editor editorx=prefsx.edit();
editorx.putString(“刷新”,日期);
commit();
dbHelper.close();
Asycdialog.disclose();
startActivity(新意图(LoaderClass.this、MainActivity.class));
完成();
super.onPostExecute(结果);
}
@凌驾
受保护字符串doInBackground(无效…参数){
dbHelper=newdbadapter(getApplicationContext());
dbHelper.open();
int i=0;
int行=0;
//int prog=fetchAdhoc();
字符串进度=空;
字符串dateToInsert;
试一试{
缓冲读取器;
如果(标志==1){
reader=new BufferedReader(新文件读取器(getApplicationContext().getFileDir()+“/xxxinders/fileone.txt”);
}否则{
reader=new BufferedReader(新文件读取器(getApplicationContext().getFileDir()+“/xxxinders/output.txt”);
}
而(reader.readLine()!=null)行++;
reader.close();
}捕获(例外e){
}
游标c=dbHelper.fetchAdhoc();
临时计数=(c.getCount());
行=行+临时计数;
dbHelper.NotificationDrop();
if(c.moveToFirst()){
做{
试一试{
字符串名称=c.getString(c.getColumnIndexOrThrow(“名称”);
String displayBirthy=c.getString(c.getColumnIndexOrThrow(“DOB”));
字符串imageData=c.getString(c.getColumnIndexOrThrow(“imageData”);
String primaryAdhoc=c.getString(c.getColumnIndexOrThrow(“_id”);
//联系人ID、联系人姓名、联系人图像URI
联系人ID=主要临时联系人;
联系人姓名=toTitleCase(姓名);
CONTACT_IMAGE_URI=imageData;
dateToInsert=显示生日;
SimpleDateFormat=新的SimpleDateFormat(“yyyy-MM-dd”);
Date-Date=format.parse(dateToInsert);
java.sql.Date dx=new java.sql.Date(Date.getTime());
日期键=dx;
years=getDiffYear(键);//已过去的年数
秒=秒(键);//秒
分钟=秒(键)/60;//分钟elap