Example usage for android.app ProgressDialog show

List of usage examples for android.app ProgressDialog show

Introduction

In this page you can find the example usage for android.app ProgressDialog show.

Prototype

public static ProgressDialog show(Context context, CharSequence title, CharSequence message,
        boolean indeterminate) 

Source Link

Document

Creates and shows a ProgressDialog.

Usage

From source file:com.cssweb.android.trade.stock.StockTrading.java

private void buystock() {
    String gddm = stockHolder.getSelectedItem().toString();
    String zqdm = stkcode.getText().toString();
    String qty = number.getText().toString();
    String jg = price.getText().toString();

    if (zqdm == null || zqdm.equals("")) {
        toast("??!");
        return;//from w  w  w  .  j av a  2  s.c o m
    } else if (zqdm.length() != 6 || !TradeUtil.checkNumber(zqdm, false)) {
        toast("??!");
        return;
    }
    if (jg == null || jg.equals("")) {
        toast("!");
        return;
    } else if (!TradeUtil.checkNumber(jg, false)) {
        toast("!");
        return;
    }
    if (qty == null || qty.equals("")) {
        toast("?!");
        return;
    } else if (!TradeUtil.checkNumber(qty, true)) {
        toast("?!");
        return;
    }
    String flag = "";
    if (type == 0)
        flag = "";
    else if (type == 1)
        flag = "?";
    String mess = "?:" + zqdm + "\n";
    mess += "??:" + stkname.getText().toString() + "\n";
    if (queryMethod.getSelectedItemPosition() == 0) {
        mess += ":" + jg + "\n";
    }
    mess += "?:" + qty + "\n";
    mess += "?:" + queryMethod.getSelectedItem().toString() + "\n";
    mess += "?:" + gddm + "\n";
    //mess += "?:" + TradeUtil.getTradeName(quoteMethodVal[queryMethod.getSelectedItemPosition()].charAt(0)) + "\n";
    new AlertDialog.Builder(StockTrading.this).setTitle(flag).setMessage(mess)
            .setPositiveButton("", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    CharSequence title = "??...";
                    CharSequence message = "????...";
                    myDialog = ProgressDialog.show(StockTrading.this, title, message, true);

                    StringBuffer sb = new StringBuffer();

                    sb.append("FID_JYS=" + market + TradeUtil.SPLIT);
                    sb.append("FID_GDH=" + holder.get(stockHolder.getSelectedItemPosition()) + TradeUtil.SPLIT);
                    sb.append("FID_ZQDM=" + stkcode.getText() + TradeUtil.SPLIT);
                    if (queryMethod.getSelectedItemPosition() == 0) {
                        sb.append("FID_WTJG=" + price.getText() + TradeUtil.SPLIT);
                    } else {
                        sb.append("FID_WTJG=0.0" + TradeUtil.SPLIT);
                    }
                    if (type == 0) {
                        sb.append("FID_JYLB=" + 1 + TradeUtil.SPLIT);//                
                    } else if (type == 1) {
                        sb.append("FID_JYLB=" + 2 + TradeUtil.SPLIT);//?
                    }
                    sb.append("FID_WTSL=" + number.getText().toString() + TradeUtil.SPLIT);
                    String orderType = "";
                    if (queryMethod.getSelectedItemPosition() != 0) {
                        orderType = quoteMethodVal[queryMethod.getSelectedItemPosition()];
                    }
                    sb.append("FID_DDLX=" + orderType + TradeUtil.SPLIT);
                    sb.append("FID_WTPCH=" + TradeUtil.SPLIT);

                    try {
                        JSONObject quoteData = ConnPool.sendReq("BUY_STOCK", "204501", sb.toString());
                        String res = TradeUtil.checkResult(quoteData);
                        if (res != null) {
                            if (res.equals("-1")) {
                                Toast.makeText(StockTrading.this,
                                        "???",
                                        Toast.LENGTH_LONG).show();
                                //openDialog(R.string.network_error);
                            } else {
                                Toast.makeText(StockTrading.this, res, Toast.LENGTH_LONG).show();
                            }
                        } else {
                            JSONArray jArr = (JSONArray) quoteData.getJSONArray("item");
                            JSONObject j = (JSONObject) jArr.get(0);
                            toast("??" + j.getString("FID_WTH"));
                        }
                        clear();
                    } catch (JSONException e) {
                        e.printStackTrace();
                        CssLog.e(TAG, e.toString());
                    }

                    myDialog.dismiss();
                }
            }).setNegativeButton("?", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    //
                }
            }).show();
}

From source file:com.abeo.tia.noordin.AddCaseStep2of4.java

private void btnconfirm() {

    // Find the SharedPreferences pass Login value
    SharedPreferences prefLoginReturn = getSharedPreferences("LoginData", Context.MODE_PRIVATE);
    System.out.println("LOGIN DATA");
    String userName = prefLoginReturn.getString("sUserName", "");

    String category = prefLoginReturn.getString("sCategory", "");
    System.out.println(category);
    String CardCode = prefLoginReturn.getString("CardCode", "");
    System.out.println(CardCode);

    JSONObject jsonObject = new JSONObject();
    // jsonObject.put("Category", "SPA");
    try {/*from  ww w. j  a va  2  s . c om*/
        // Find confirmation message
        // messageResult = jsonObject.getString("Result").toString();

        jsonObject.put("CODE", "");
        jsonObject.put("CARDCODE", CardCode);
        jsonObject.put("TITLETYPE", titleValue);
        jsonObject.put("TITLENO", Title.getText().toString());
        jsonObject.put("LOTTYPE", LotType.getText().toString());
        jsonObject.put("LOTNO", LotNo.getText().toString());
        jsonObject.put("FORMERLY_KNOWN_AS", Knownas.getText().toString());
        jsonObject.put("BPM", Pekan.getText().toString());
        jsonObject.put("STATE", stateval);
        jsonObject.put("AREA", Nageri.getText().toString());
        jsonObject.put("LOTAREA", LotArea.getText().toString());

        jsonObject.put("LASTUPDATEDON", LastUpdate.getText().toString());
        jsonObject.put("DEVELOPER", developerValue);
        jsonObject.put("DVLPR_CODE", developerValue_id);
        jsonObject.put("PROJECT_CODE", ProjectValue_id);
        jsonObject.put("PROJECTNAME", ProjectValue);
        jsonObject.put("DEVLICNO", DevLicense.getText().toString());
        jsonObject.put("DEVSOLICTOR", solicitorValue);
        jsonObject.put("DVLPR_SOL_CODE", solicitorValue_id);
        jsonObject.put("DVLPR_LOC", SolicitorLoc.getText().toString());
        jsonObject.put("LSTCHG_BANKCODE", bankValue_id);
        jsonObject.put("LSTCHG_BANKNAME", bankValue);
        jsonObject.put("LSTCHG_BRANCH", Branch.getText().toString());

        jsonObject.put("LSTCHG_PANO", PAName.getText().toString());
        jsonObject.put("LSTCHG_PRSTNO", PresentaionNo.getText().toString());
        jsonObject.put("PurchasePrice", PurchasePrice.getText().toString());

        if (QryGroup13.isChecked())
            jsonObject.put("PROPERTYCHARGED", "Y");
        else
            jsonObject.put("PROPERTYCHARGED", "N");

        //arrOfJson.put(jsonObject);
        System.out.println("JsonArray:" + jsonObject.toString());

        //upDateList();

    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    RequestParams params = new RequestParams();
    params.put("sJsonInput", jsonObject.toString());
    System.out.println("params");
    System.out.println(params);
    dialog = ProgressDialog.show(AddCaseStep2of4.this, "", "Loading...", true);
    RestService.post(METHOD_ADD_CASE2, params, new BaseJsonHttpResponseHandler<String>() {

        @Override
        public void onFailure(int arg0, Header[] arg1, Throwable arg2, String arg3, String arg4) {
            // TODO Auto-generated method stub
            System.out.println(arg3);
            System.out.println("onFailure");
            dialog.dismiss();

        }

        @Override
        public void onSuccess(int arg0, Header[] arg1, String arg2, String arg3) {
            // TODO Auto-generated method stub
            System.out.println("onFailure");
            System.out.println("AddCase2 Details Add Confirmed");
            System.out.println(arg2);
            dialog.dismiss();

            // Find status Response
            try {
                StatusResult = jsonResponse.getString("Result").toString();
                messageDisplay = jsonResponse.getString("DisplayMessage").toString();

                if (StatusResult.equals("SUCCESS")) {
                    Intent iAddBack = new Intent(AddCaseStep2of4.this, AddCaseStep3of4.class);

                    startActivity(iAddBack);

                    Toast.makeText(AddCaseStep2of4.this, messageDisplay, Toast.LENGTH_SHORT).show();
                } else if (jsonResponse.getString("CaseFileNo").toString() != "") {
                    // Find Response for ListView
                    try {

                        jsonCaselist = new ArrayList<HashMap<String, String>>();

                        for (int i = 0; i < arrayResponse.length(); i++) {
                            jsonResponse = arrayResponse.getJSONObject(i);
                            /*
                             * [ { "CaseFileNo": "1500000006", "RelatedFileNo":
                             * "", "BranchCode": "", "FileOpenedDate":
                             * "8/1/2015 12:00:00 AM", "IC": "3", "CaseType":
                             * "SPA", "ClientName": "", "BankName": "",
                             * "Branch": "", "LOTNo": "", "CaseAmount": "",
                             * "UserCode": "", "Status": "OPEN",
                             * "FileClosedDate": "" } ]
                             */

                            CaseList_CaseFileNo = jsonResponse.getString("CaseFileNo").toString();
                            CaseList_RelatedFileNo = jsonResponse.getString("RelatedFileNo").toString();
                            CaseList_BranchCode = jsonResponse.getString("BranchCode").toString();
                            CaseList_FileOpenedDate = jsonResponse.getString("FileOpenedDate").toString();
                            CaseList_IC = jsonResponse.getString("IC").toString();
                            CaseList_CaseType = jsonResponse.getString("CaseType").toString();
                            CaseList_ClientName = jsonResponse.getString("ClientName").toString();
                            CaseList_BankName = jsonResponse.getString("BankName").toString();
                            // CaseList_Branch =
                            // jsonResponse.getString("Branch").toString();
                            CaseList_LOTNo = jsonResponse.getString("LOTNo").toString();
                            CaseList_CaseAmount = jsonResponse.getString("CaseAmount").toString();
                            CaseList_UserCode = jsonResponse.getString("UserCode").toString();
                            CaseList_Status = jsonResponse.getString("Status").toString();
                            CaseList_FileClosedDate = jsonResponse.getString("FileClosedDate").toString();

                            // SEND JSON DATA INTO CASELIST
                            HashMap<String, String> caseListProperty = new HashMap<String, String>();

                            // Send JSON Data to list activity
                            System.out.println("SEND JSON CASE LIST");

                            caseListProperty.put("CaseFileNo_List", CaseList_CaseFileNo);
                            System.out.println(CaseList_CaseFileNo);
                            caseListProperty.put("RelatedFileNo_List", CaseList_RelatedFileNo);
                            System.out.println(CaseList_RelatedFileNo);
                            caseListProperty.put("BranchCode_List", CaseList_BranchCode);
                            System.out.println(CaseList_BranchCode);
                            caseListProperty.put("FileOpenedDate_List", CaseList_FileOpenedDate);
                            System.out.println(CaseList_FileOpenedDate);
                            caseListProperty.put("IC_List", CaseList_IC);
                            System.out.println(CaseList_IC);
                            caseListProperty.put("CaseType_List", CaseList_CaseType);
                            System.out.println(CaseList_CaseType);
                            caseListProperty.put("ClientName_List", CaseList_ClientName);
                            System.out.println(CaseList_ClientName);
                            caseListProperty.put("BankName_List", CaseList_BankName);
                            System.out.println(CaseList_BankName);
                            // caseListProperty.put("Branch_List",CaseList_Branch);
                            // System.out.println(CaseList_Branch);
                            caseListProperty.put("LOTNo_List", CaseList_LOTNo);
                            System.out.println(CaseList_LOTNo);
                            caseListProperty.put("CaseAmount_List", CaseList_CaseAmount);
                            System.out.println(CaseList_CaseAmount);
                            caseListProperty.put("UserCode_List", CaseList_UserCode);
                            System.out.println(CaseList_UserCode);
                            caseListProperty.put("Status_List", CaseList_Status);
                            System.out.println(CaseList_Status);
                            caseListProperty.put("FileClosedDate", CaseList_FileClosedDate);
                            System.out.println(CaseList_FileClosedDate);
                            System.out.println(" END SEND JSON CASE LIST");

                            jsonCaselist.add(caseListProperty);
                            System.out.println("JSON CASELIST");
                            System.out.println(jsonCaselist);
                        }

                    } catch (JSONException e) { // TODO Auto-generated catc
                        // block
                        e.printStackTrace();
                    }
                    //Toast.makeText(PropertyActivity.this, "Case Item Found", Toast.LENGTH_SHORT).show();
                    Intent intentList = new Intent(AddCaseStep2of4.this, PropertyRelatedCaseListActivity.class);
                    intentList.putExtra("ProjectJsonList", jsonCaselist);
                    startActivity(intentList);
                    System.out.println(arg2);

                } else {
                    Toast.makeText(AddCaseStep2of4.this, messageDisplay, Toast.LENGTH_SHORT).show();

                }

            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        @Override
        protected String parseResponse(String arg0, boolean arg1) throws Throwable {

            // Get Json response
            arrayResponse = new JSONArray(arg0);
            jsonResponse = arrayResponse.getJSONObject(0);

            System.out.println("Addcase3 Details Add Response");
            System.out.println(arg0);
            return null;
        }
    });

}

From source file:com.guardtrax.ui.screens.HomeScreen.java

public void onCreate(Bundle savedInstanceState) {
    ctx = this.getApplicationContext();

    super.onCreate(savedInstanceState);

    //restore saved instances if necessary
    if (savedInstanceState != null) {
        Toast.makeText(HomeScreen.this, savedInstanceState.getString("message"), Toast.LENGTH_LONG).show();

        GTConstants.darfileName = savedInstanceState.getString("darfileName");
        GTConstants.tarfileName = savedInstanceState.getString("tarfileName");
        GTConstants.trpfilename = savedInstanceState.getString("trpfilename");
        GTConstants.srpfileName = savedInstanceState.getString("srpfileName");
        Utility.setcurrentState(savedInstanceState.getString("currentState"));
        Utility.setsessionStart(savedInstanceState.getString("getsessionStart"));
        selectedCode = savedInstanceState.getString("selectedCode");
        lunchTime = savedInstanceState.getString("lunchTime");
        breakTime = savedInstanceState.getString("breakTime");
        signaturefileName = savedInstanceState.getString("signaturefileName");
        GTConstants.tourName = savedInstanceState.getString("tourName");
        tourTime = savedInstanceState.getString("tourTime");
        tourEnd = savedInstanceState.getLong("tourEnd");
        lunchoutLocation = savedInstanceState.getInt("lunchoutLocation");
        breakoutLocation = savedInstanceState.getInt("breakoutLocation");
        touritemNumber = savedInstanceState.getInt("touritemNumber");
        chekUpdate = savedInstanceState.getBoolean("chekUpdate");
        GTConstants.sendData = savedInstanceState.getBoolean("send_data");
        GTConstants.isTour = savedInstanceState.getBoolean("isTour");
        GTConstants.isGeoFence = savedInstanceState.getBoolean("isGeoFence");
    } else {/*from w w w .ja  va2  s  .  co  m*/
        //set the current state
        Utility.setcurrentState(GTConstants.offShift);

        //set the default startup code to start shift
        selectedCode = "start_shift";
    }

    /*
    //Determine screen size
     if ((getResources().getConfiguration().screenLayout &      Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE) {     
         Toast.makeText(this, "Large screen",Toast.LENGTH_LONG).show();
     }
     else if ((getResources().getConfiguration().screenLayout &      Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_NORMAL) {     
         Toast.makeText(this, "Normal sized screen" , Toast.LENGTH_LONG).show();
     } 
     else if ((getResources().getConfiguration().screenLayout &      Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_SMALL) {     
         Toast.makeText(this, "Small sized screen" , Toast.LENGTH_LONG).show();
     }
     else {
         Toast.makeText(this, "Screen size is neither large, normal or small" , Toast.LENGTH_LONG).show();
     }
             
      //initialize receiver to monitor for screen on / off
    /*
      IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
      filter.addAction(Intent.ACTION_SCREEN_OFF);
      BroadcastReceiver mReceiver = new ScreenReceiver();
      registerReceiver(mReceiver, filter);
      */

    setContentView(R.layout.homescreen);

    //Create object to call the Database class
    myDatabase = new GuardTraxDB(this);
    preferenceDB = new PreferenceDB(this);
    ftpdatabase = new ftpDataBase(this);
    gtDB = new GTParams(this);
    aDB = new accountsDB(this);
    trafficDB = new trafficDataBase(this);
    tourDB = new tourDataBase(this);

    //check for updates
    if (chekUpdate) {
        //reset the preference value
        chekUpdate = false;

        //check for application updates
        checkUpdate();
    }

    //initialize the message timer
    //initializeOnModeTimerEvent();

    //get the version number and set it in constants
    String version_num = "";

    PackageManager manager = this.getPackageManager();
    try {
        PackageInfo info = manager.getPackageInfo(this.getPackageName(), 0);
        version_num = info.versionName.toString();

    } catch (NameNotFoundException e) {
        version_num = "0.00.00";
    }
    GTConstants.version = version_num;

    //final TextView version = (TextView) findViewById(R.id.textVersion);
    //version.setText(version_num);

    //set up the animation
    animation.setDuration(500); // duration - half a second
    animation.setInterpolator(new LinearInterpolator()); // do not alter animation rate
    animation.setRepeatCount(Animation.INFINITE); // Repeat animation infinitely
    animation.setRepeatMode(Animation.REVERSE); // Reverse animation at the end so the button will fade back in

    buttonClick.setDuration(50); // duration - half a second
    buttonClick.setInterpolator(new LinearInterpolator()); // do not alter animation rate
    buttonClick.setRepeatCount(1); // Repeat animation once
    buttonClick.setRepeatMode(Animation.REVERSE); // Reverse animation at the end so the button will fade back in

    textWarning = (TextView) findViewById(R.id.txtWarning);
    textWarning.setWidth(500);
    textWarning.setGravity(Gravity.CENTER);

    //allow the text to be clicked if necessary 
    textWarning.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (GTConstants.isTour && GTConstants.tourName.length() > 1)
                displaytourInfo();
        }
    });

    //goto scan page button
    btn_scan_screen = (Button) findViewById(R.id.btn_goto_scan);

    btn_scan_screen.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            btn_scan_screen.startAnimation(buttonClick);

            //Utility.showScan(HomeScreen.this);
            scan_click(false);
        }
    });

    //goto report page button
    btn_report_screen = (Button) findViewById(R.id.btn_goto_report);
    btn_report_screen.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            btn_report_screen.startAnimation(buttonClick);

            report_click();
        }
    });

    //goto dial page button
    btn_dial_screen = (Button) findViewById(R.id.btn_goto_dial);
    btn_dial_screen.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            btn_dial_screen.startAnimation(buttonClick);

            dial_click();
        }
    });

    //microphone button
    btn_mic = (Button) findViewById(R.id.btn_mic);
    btn_mic.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            btn_mic.startAnimation(buttonClick);

            voice_click();
        }

    });

    //camera button
    btn_camera = (Button) findViewById(R.id.btn_camera);
    btn_camera.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            btn_camera.startAnimation(buttonClick);

            camera_click();
        }
    });

    //video button
    btn_video = (Button) findViewById(R.id.btn_video);
    btn_video.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            btn_video.startAnimation(buttonClick);

            video_click();
        }

    });

    // Register a callback to be invoked when this view is clicked. If this view is not clickable, it becomes clickable.
    btn_send = (Button) findViewById(R.id.btn_Send);
    btn_send.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            //prevent multiple fast clicking
            if (SystemClock.elapsedRealtime() - mLastClickTime < 2000)
                return;

            mLastClickTime = SystemClock.elapsedRealtime();

            incidentcodeSent = true;

            btn_send.startAnimation(buttonClick);

            //if start shift has not been sent then the device is in do not send data mode.  Warn the user 
            if (Utility.getcurrentState().equals(GTConstants.offShift) && !selectedCode.equals("start_shift")) {
                show_alert_title = "Error";
                show_alert_message = "You must start your shift!";
                showAlert(show_alert_title, show_alert_message, true);

                //set spinner back to start shift
                spinner.setSelection(0);
            } else {
                if (Utility.deviceRegistered()) {
                    show_alert_title = "Success";
                    show_alert_message = "Action success";
                } else {
                    show_alert_title = "Warning";
                    show_alert_message = "You are NOT registered!";

                    showAlert(show_alert_title, show_alert_message, true);
                }

                if (selectedCode.equals("start_shift")) {
                    //if shift already started
                    if (Utility.getcurrentState().equals(GTConstants.onShift)) {
                        show_alert_title = "Warning";
                        show_alert_message = "You must end shift!";

                        showAlert(show_alert_title, show_alert_message, true);

                        //set spinner back to all clear
                        spinner.setSelection(2);
                    } else {
                        ToastMessage.displayToastFromResource(HomeScreen.this, 5, Gravity.CENTER,
                                (ViewGroup) findViewById(R.id.toast_layout_root));

                        pdialog = ProgressDialog.show(HomeScreen.this, "Please wait", "Starting shift ...",
                                true);

                        //set the current state
                        Utility.setcurrentState(GTConstants.onShift);
                        setuserBanner();

                        //wait for start shift actions to complete (or timeout occurs) before dismissing wait dialog
                        new CountDownTimer(5000, 1000) {
                            @Override
                            public void onTick(long millisUntilFinished) {
                                if (start_shift_wait)
                                    pdialog.dismiss();
                            }

                            @Override
                            public void onFinish() {
                                if (!(pdialog == null))
                                    pdialog.dismiss();
                            }
                        }.start();

                        //create dar file
                        try {
                            //create the dar file name
                            GTConstants.darfileName = GTConstants.LICENSE_ID.substring(7) + "_"
                                    + Utility.getUTCDate() + "_" + Utility.getUTCTime() + ".dar";

                            //write the version to the dar file
                            Utility.write_to_file(HomeScreen.this,
                                    GTConstants.dardestinationFolder + GTConstants.darfileName,
                                    "Version;" + GTConstants.version + "\r\n", false);

                            //write the start shift event to the dar file
                            Utility.write_to_file(HomeScreen.this,
                                    GTConstants.dardestinationFolder + GTConstants.darfileName,
                                    "Start shift;" + GTConstants.currentBatteryPercent + ";"
                                            + Utility.getLocalTime() + ";" + Utility.getLocalDate() + "\r\n",
                                    true);

                            //create the tar file name if module installed
                            if (GTConstants.isTimeandAttendance) {
                                GTConstants.tarfileName = GTConstants.LICENSE_ID.substring(7) + "_"
                                        + Utility.getUTCDate() + "_" + Utility.getUTCTime() + ".tar";

                                //write the start shift event to the tar file
                                Utility.write_to_file(HomeScreen.this,
                                        GTConstants.dardestinationFolder + GTConstants.tarfileName,
                                        "Name;" + GTConstants.report_name + "\r\n" + "Start shift;"
                                                + Utility.getLocalTime() + ";" + Utility.getLocalDate()
                                                + "\r\n",
                                        false);
                            }

                        } catch (Exception e) {
                            Toast.makeText(HomeScreen.this, "error = " + e, Toast.LENGTH_LONG).show();
                        }

                        GTConstants.sendData = true;

                        //if not time and attendance then send start shift event now, otherwise wait till after location scan
                        send_event("11");

                        //set the session start time
                        SimpleDateFormat sdf = new SimpleDateFormat("MM-dd-yy HH:mm:ss");
                        Utility.setsessionStart(sdf.format(new Date()));

                        //reset the server connection flag
                        Utility.resetisConnecting();

                        //start the GPS location service
                        MainService.openLocationListener();

                        //set spinner back to all clear
                        spinner.setSelection(2);

                        setwarningText("");

                        if (GTConstants.isTimeandAttendance) {
                            show_taa_scan(true, false);
                        }
                    }

                } else if (selectedCode.equals("end_shift")) {
                    if (!Utility.getcurrentState().equals(GTConstants.onShift)
                            && GTConstants.isTimeandAttendance) {
                        show_alert_title = "Error";
                        show_alert_message = "You must end your Lunch / Break!";
                        showAlert(show_alert_title, show_alert_message, true);

                        //set spinner back to start shift
                        spinner.setSelection(2);
                    } else {
                        btn_send.setEnabled(false);
                        if (GTConstants.isTimeandAttendance) {
                            show_taa_scan(false, true);
                        } else
                            endshiftCode();
                    }
                } else {
                    if (Utility.isselectionValid(HomeScreen.this, selectedCode)) {
                        //if time and attendance then write to file
                        if (selectedCode.equalsIgnoreCase(GTConstants.lunchin)
                                || selectedCode.equalsIgnoreCase(GTConstants.lunchout)
                                || selectedCode.equalsIgnoreCase(GTConstants.startbreak)
                                || selectedCode.equalsIgnoreCase(GTConstants.endbreak)) {
                            if (GTConstants.isTimeandAttendance)
                                Utility.write_to_file(HomeScreen.this,
                                        GTConstants.dardestinationFolder + GTConstants.tarfileName,
                                        spinner.getSelectedItem().toString() + ";" + Utility.getLocalTime()
                                                + ";" + Utility.getLocalDate() + "\r\n",
                                        true);

                            if (selectedCode.equalsIgnoreCase(GTConstants.lunchin)) {
                                Utility.setcurrentState(GTConstants.onLunch);
                                Utility.setlunchStart(true);
                                setuserBanner();
                            }

                            if (selectedCode.equalsIgnoreCase(GTConstants.startbreak)) {
                                Utility.setcurrentState(GTConstants.onBreak);
                                Utility.setbreakStart(true);
                                setuserBanner();
                            }

                            if (selectedCode.equalsIgnoreCase(GTConstants.lunchout)) {
                                Utility.setcurrentState(GTConstants.onShift);
                                lunchTime = Utility.gettimeDiff(Utility.getlunchStart(),
                                        Utility.getLocalDateTime());
                                setuserBanner();
                            }

                            if (selectedCode.equalsIgnoreCase(GTConstants.endbreak)) {
                                Utility.setcurrentState(GTConstants.onShift);
                                breakTime = Utility.gettimeDiff(Utility.getbreakStart(),
                                        Utility.getLocalDateTime());
                                setuserBanner();
                            }
                        }

                        ToastMessage.displayToastFromResource(HomeScreen.this, 5, Gravity.CENTER,
                                (ViewGroup) findViewById(R.id.toast_layout_root));

                        //save the event description as may be needed for incident report
                        incidentDescription = spinner.getSelectedItem().toString();

                        //write to dar
                        Utility.write_to_file(HomeScreen.this,
                                GTConstants.dardestinationFolder + GTConstants.darfileName,
                                "Event; " + incidentDescription + ";" + Utility.getLocalTime() + ";"
                                        + Utility.getLocalDate() + "\r\n",
                                true);

                        //write to srp
                        if (GTConstants.srpfileName.length() > 1)
                            Utility.write_to_file(HomeScreen.this,
                                    GTConstants.dardestinationFolder + GTConstants.srpfileName,
                                    "Event; " + incidentDescription + ";" + Utility.getLocalTime() + ";"
                                            + Utility.getLocalDate() + "\r\n",
                                    true);

                        //send the data
                        send_event(selectedCode);

                        //ask if user wants to create an incident report.  If the last character is a space, that indicates not to ask for report
                        if (!(incidentDescription.charAt(incidentDescription.length() - 1) == ' ')
                                && !trafficIncident)
                            showYesNoAlert("Report", "Create an Incident Report?", incidentreportScreen);
                        if (!(incidentDescription.charAt(incidentDescription.length() - 1) == ' ')
                                && trafficIncident)
                            showYesNoAlert("Report", "Create a Traffic Violation?", incidentreportScreen);

                        //if last two characters are spaces then ask to write a note
                        if (incidentDescription.charAt(incidentDescription.length() - 1) == ' '
                                && incidentDescription.charAt(incidentDescription.length() - 2) == ' ')
                            showYesNoAlert("Report", "Create a Note?", createNote);

                    }

                    //set spinner back to required state
                    if (selectedCode.equalsIgnoreCase(GTConstants.lunchin))
                        spinner.setSelection(lunchoutLocation);
                    else if (selectedCode.equalsIgnoreCase(GTConstants.startbreak))
                        spinner.setSelection(breakoutLocation);
                    else
                        spinner.setSelection(2);

                }
            }
        }

    });

    //Finds a view that was identified by the id attribute from the XML that was processed in onCreate(Bundle).
    spinner = (Spinner) findViewById(R.id.spinner_list);

    //method initialize the spinner action
    initializeSpinnerControl();

    if (GTConstants.service_intent == null) {
        //Condition to check whether the Database exist and if so load data into constants
        try {
            if (preferenceDB.checkDataBase()) {
                preferenceDB.open();

                Cursor cursor = preferenceDB.getRecordByRowID("1");

                preferenceDB.close();

                if (cursor == null)
                    loadPreferenceDataBase();
                else {
                    saveInConstants(cursor);
                    cursor.close();
                }
                syncDB();
                syncFTP();
                syncftpUpload();
            } else {
                preferenceDB.open();
                preferenceDB.close();
                //Toast.makeText(HomeScreen.this, "Path = " + preferenceDB.get_path(), Toast.LENGTH_LONG).show();
                //Toast.makeText(HomeScreen.this, "No database found", Toast.LENGTH_LONG).show();

                loadPreferenceDataBase();

                syncDB();
                syncFTP();
                syncftpUpload();
            }
        } catch (Exception e) {
            preferenceDB.createDataBase();
            loadPreferenceDataBase();
            Toast.makeText(HomeScreen.this, "Creating database", Toast.LENGTH_LONG).show();
        }

        //setup the auxiliary databases
        if (!aDB.checkDataBase()) {
            aDB.open();
            aDB.close();
        }

        if (!ftpdatabase.checkDataBase()) {
            ftpdatabase.open();
            ftpdatabase.close();
        }

        if (!gtDB.checkDataBase()) {
            gtDB.open();
            gtDB.close();
        }

        if (!trafficDB.checkDataBase()) {
            trafficDB.open();
            trafficDB.close();
        }

        if (!tourDB.checkDataBase()) {
            tourDB.open();
            tourDB.close();
        }

        //get the parameters from the parameter database
        loadGTParams();

        //this code starts the main service running which contains all the event timers
        if (Utility.deviceRegistered()) {
            //this is the application started event - sent once when application starts up
            if (savedInstanceState == null)
                send_event("PU");

            initService();
        }
    }

    //if device not registered than go straight to scan screen
    if (!Utility.deviceRegistered()) {
        newRegistration = true;
        //send_data = true;
        scan_click(false);
    }

    //setup the user banner
    setuserBanner();

    //set the warning text
    setwarningText("");

}

From source file:org.openhab.habdroid.ui.OpenHABMainActivity.java

public void onBonjourDiscoveryStarted() {
    mProgressDialog = ProgressDialog.show(this, "", getString(R.string.info_discovery), true);
}

From source file:eu.dirtyharry.androidopsiadmin.Main.java

public void event_opsisenddepotconfigchanges() {
    final ProgressDialog dialog = ProgressDialog.show(Main.this, getString(R.string.gen_title_pleasewait),
            String.format(getString(R.string.pd_senddepotchangesfor), choosendepot), true);
    final Handler handler = new Handler() {
        public void handleMessage(Message msg) {
            dialog.dismiss();//from ww w . j a va  2  s. com
            if (!GlobalVar.getInstance().getError().equals("null")) {
                new Functions().msgBox(Main.this, getString(R.string.gen_title_error),
                        GlobalVar.getInstance().getError(), false);
            }
        }
    };
    Thread checkUpdate = new Thread() {
        public void run() {
            Looper.prepare();
            JSONArray test = new JSONArray();
            JSONObject params = new JSONObject();
            try {
                params.put("id", choosendepot);
                params.put("type", "OpsiConfigserver");
                for (int i = 0; i < resultconfignames.size(); i++) {
                    params.put(resultconfignames.get(i), resultconfigvalues.get(i));
                }
            } catch (JSONException e1) {
                e1.printStackTrace();
            }

            test.put(params);
            opsiresult = new JSONObject();
            opsiresult = eu.dirtyharry.androidopsiadmin.Networking.opsiGetJSONObject("rpc", serverip,
                    serverport, "host_updateObject", test, serverusername, serverpasswd);
            try {
                if (!opsiresult.isNull("error")) {
                    GlobalVar.getInstance().setError(opsiresult.getString("error"));
                }

            } catch (JSONException e) {
                e.printStackTrace();
            }
            handler.sendEmptyMessage(0);
        }
    };
    checkUpdate.start();
}

From source file:net.reichholf.dreamdroid.fragment.TimerEditFragment.java

/**
 * Save the current timer on the target device
 *///  w  ww  .j a  v a 2s.  co  m
private void saveTimer() {
    Log.i(TAG, "saveTimer()");
    if (mProgress != null) {
        if (mProgress.isShowing()) {
            mProgress.dismiss();
        }
    }
    Activity activtiy = getAppCompatActivity();
    mProgress = ProgressDialog.show(activtiy, "", getText(R.string.saving), true);

    applyViewValues();
    ArrayList<NameValuePair> params = Timer.getSaveParams(mTimer, mTimerOld);
    execSimpleResultTask(new TimerChangeRequestHandler(), params);
}

From source file:net.reichholf.dreamdroid.activities.TimerEditActivity.java

/**
 * Save the current timer on the target device
 *///w  ww  .  j  av a2s.  c  o  m
private void saveTimer() {
    if (mProgress != null) {
        if (mProgress.isShowing()) {
            mProgress.dismiss();
        }
    }

    mProgress = ProgressDialog.show(this, "", getText(R.string.saving), true);

    applyViewValues();
    ArrayList<NameValuePair> params = Timer.getSaveParams(mTimer, mTimerOld);

    execSimpleResultTask(new TimerChangeRequestHandler(), params);
}

From source file:cgeo.geocaching.CacheDetailActivity.java

@Override
public boolean onContextItemSelected(final MenuItem item) {
    switch (item.getItemId()) {
    // waypoints//  www. ja  va2  s.c o  m
    case R.id.menu_waypoint_edit:
        if (selectedWaypoint != null) {
            ensureSaved();
            EditWaypointActivity.startActivityEditWaypoint(this, cache, selectedWaypoint.getId());
            refreshOnResume = true;
        }
        return true;
    case R.id.menu_waypoint_visited:
        if (selectedWaypoint != null) {
            ensureSaved();
            new AsyncTask<Void, Void, Boolean>() {
                @Override
                protected Boolean doInBackground(final Void... params) {
                    selectedWaypoint.setVisited(true);
                    DataStore.saveCache(cache, EnumSet.of(SaveFlag.DB));
                    return true;
                }

                @Override
                protected void onPostExecute(final Boolean result) {
                    if (result) {
                        notifyDataSetChanged();
                    }
                }
            }.execute();
        }
        return true;
    case R.id.menu_waypoint_copy_coordinates:
        if (selectedWaypoint != null) {
            final Geopoint coordinates = selectedWaypoint.getCoords();
            if (coordinates != null) {
                ClipboardUtils.copyToClipboard(GeopointFormatter.reformatForClipboard(coordinates.toString()));
                showToast(getString(R.string.clipboard_copy_ok));
            }
        }
        return true;
    case R.id.menu_waypoint_clear_coordinates:
        if (selectedWaypoint != null) {
            ensureSaved();
            new ClearCoordinatesCommand(this, cache, selectedWaypoint).execute();
        }
        return true;
    case R.id.menu_waypoint_duplicate:
        ensureSaved();
        new AsyncTask<Void, Void, Boolean>() {
            @Override
            protected Boolean doInBackground(final Void... params) {
                if (cache.duplicateWaypoint(selectedWaypoint) != null) {
                    DataStore.saveCache(cache, EnumSet.of(SaveFlag.DB));
                    return true;
                }
                return false;
            }

            @Override
            protected void onPostExecute(final Boolean result) {
                if (result) {
                    notifyDataSetChanged();
                }
            }
        }.execute();
        return true;
    case R.id.menu_waypoint_delete:
        ensureSaved();
        new AsyncTask<Void, Void, Boolean>() {
            @Override
            protected Boolean doInBackground(final Void... params) {
                if (cache.deleteWaypoint(selectedWaypoint)) {
                    DataStore.saveCache(cache, EnumSet.of(SaveFlag.DB));
                    return true;
                }
                return false;
            }

            @Override
            protected void onPostExecute(final Boolean result) {
                if (result) {
                    notifyDataSetChanged();
                }
            }
        }.execute();
        return true;
    case R.id.menu_waypoint_navigate_default:
        if (selectedWaypoint != null) {
            NavigationAppFactory.startDefaultNavigationApplication(1, this, selectedWaypoint);
        }
        return true;
    case R.id.menu_waypoint_navigate:
        if (selectedWaypoint != null) {
            NavigationAppFactory.showNavigationMenu(this, null, selectedWaypoint, null);
        }
        return true;
    case R.id.menu_waypoint_caches_around:
        if (selectedWaypoint != null) {
            final Geopoint coordinates = selectedWaypoint.getCoords();
            if (coordinates != null) {
                CacheListActivity.startActivityCoordinates(this, coordinates, selectedWaypoint.getName());
            }
        }
        return true;
    case R.id.menu_waypoint_reset_cache_coords:
        ensureSaved();
        if (ConnectorFactory.getConnector(cache).supportsOwnCoordinates()) {
            createResetCacheCoordinatesDialog(selectedWaypoint).show();
        } else {
            final ProgressDialog progressDialog = ProgressDialog.show(this, getString(R.string.cache),
                    getString(R.string.waypoint_reset), true);
            final HandlerResetCoordinates handler = new HandlerResetCoordinates(this, progressDialog, false);
            resetCoords(cache, handler, selectedWaypoint, true, false, progressDialog);
        }
        return true;
    case R.id.menu_calendar:
        CalendarAdder.addToCalendar(this, cache);
        return true;
    default:
        break;
    }
    if (imagesList != null && imagesList.onContextItemSelected(item)) {
        return true;
    }
    return onOptionsItemSelected(item);
}

From source file:au.com.wallaceit.reddinator.SubredditSelectActivity.java

private void refreshSubreddits() {

    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);/* w  w  w.  j  a va 2s  .c om*/
    final ProgressDialog sdialog = ProgressDialog.show(SubredditSelectActivity.this, "Refreshing Subreddits",
            "One moment...", true);
    Thread t = new Thread() {
        public void run() {

            final int listLength;
            try {
                listLength = global.loadAccountSubreddits();
            } catch (final RedditData.RedditApiException e) {
                e.printStackTrace();
                runOnUiThread(new Runnable() {
                    public void run() {
                        sdialog.dismiss();
                        // check login required
                        if (e.isAuthError())
                            global.mRedditData.initiateLogin(SubredditSelectActivity.this);
                        // show error
                        Toast.makeText(SubredditSelectActivity.this, e.getMessage(), Toast.LENGTH_LONG).show();
                    }
                });
                return;
            }
            runOnUiThread(new Runnable() {
                public void run() {
                    sdialog.dismiss();
                    if (listLength == 0) {
                        Toast.makeText(SubredditSelectActivity.this,
                                "No subscriptions in your account, \nSuscribe to some subreddits",
                                Toast.LENGTH_LONG).show();
                    }
                    refreshSubredditsList();
                }
            });
        }
    };
    t.start();
}

From source file:eu.dirtyharry.androidopsiadmin.Main.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == GET_QR && resultCode == RESULT_OK) {
        contents = data.getExtras().getString("la.droid.qr.result");
        if (checkQR(contents)) {
            try {
                pc = (JSONObject) new JSONTokener(contents).nextValue();
                hosttocheck = pc.getString("dns");
            } catch (JSONException e) {
                e.printStackTrace();/*from w w  w .j av  a  2s .c  o m*/
            }
            final ProgressDialog dialog = ProgressDialog.show(Main.this,
                    getString(R.string.gen_title_pleasewait),
                    String.format(getString(R.string.pd_checkifopsiclientexists), hosttocheck), true);
            final Handler handler = new Handler() {
                public void handleMessage(Message msg) {
                    if (hostexistsinopsi && doit.equals("true")) {
                        if (customtags) {
                            Intent i = new Intent(Main.this, ShowBarcodeData.class);
                            Bundle b = new Bundle();
                            b.putString("qrdata", contents);
                            i.putExtras(b);
                            startActivity(i);
                        } else {
                            Intent i = new Intent(Main.this, ShowOpsiClientOptions.class);
                            Bundle b = new Bundle();
                            b.putString("qrdata", contents);
                            i.putExtras(b);
                            startActivity(i);
                        }
                    } else if (!hostexistsinopsi) {
                        new Functions().msgBox(Main.this, getString(R.string.gen_title_error),
                                String.format(getString(R.string.general_noopsihost), hosttocheck), false);
                    } else {
                        Toast.makeText(Main.this,
                                String.format(getString(R.string.to_servernotrechable), serverip),
                                Toast.LENGTH_LONG).show();
                    }
                    dialog.dismiss();
                }
            };

            Thread checkUpdate = new Thread() {
                public void run() {
                    Looper.prepare();

                    if (eu.dirtyharry.androidopsiadmin.Networking.isServerUp(serverip, serverport,
                            serverusername, serverpasswd)) {
                        doit = "true";
                        if (eu.dirtyharry.androidopsiadmin.Networking.checkIfHostExistsInOpsi(hosttocheck,
                                serverip, serverport, serverusername, serverpasswd)) {
                            hostexistsinopsi = true;
                        } else {
                            hostexistsinopsi = false;
                        }
                    } else {
                        doit = "serverdown";
                    }
                    handler.sendEmptyMessage(0);

                }
            };
            checkUpdate.start();

        } else {
            new Functions().msgBox(Main.this, getString(R.string.gen_title_error),
                    getString(R.string.at_novalidqr), false);
        }
    } else if (requestCode == GET_OPSI_CLIENT_REQUEST && resultCode == Activity.RESULT_OK) {
        if (data.getStringExtra("message").equals("refresh")) {
            getOpsiClientsTask();
        }
        // } else if (requestCode == SHOW_OPSI_DEPOT_REQUEST
        // && resultCode == Activity.RESULT_OK) {
        // resultconfignames = data.getExtras().getStringArrayList(
        // "choosenones");
        // resultconfigvalues = data.getExtras().getStringArrayList(
        // "choosenonesvalues");
        // event_opsisenddepotconfigchanges();
    }
}