/**
   * Read location information from image.
   *
   * @param imagePath : image absolute path
   * @return : loation information
   */
  public Location readGeoTagImage(String imagePath) {
    Location loc = new Location("");
    try {
      ExifInterface exif = new ExifInterface(imagePath);
      float[] latlong = new float[2];
      if (exif.getLatLong(latlong)) {
        loc.setLatitude(latlong[0]);
        loc.setLongitude(latlong[1]);
      }
      String date = exif.getAttribute(ExifInterface.TAG_DATETIME);
      SimpleDateFormat fmt_Exif = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss");
      try {
        loc.setTime(fmt_Exif.parse(date).getTime());
      } catch (java.text.ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }

    } catch (IOException e) {
      e.printStackTrace();
    } catch (ParseException e) {
      e.printStackTrace();
    }
    return loc;
  }
  public String getTemp(String Sdate, String Stime) {
    for (int i = 0; i < list.length(); i++) {
      try {
        JSONObject listItem = list.getJSONObject(i);
        SimpleDateFormat form = new SimpleDateFormat("MMMM dd, yyyy.hh:mma");
        java.util.Date date = null;
        try {
          date = form.parse(Sdate + "." + Stime);
        } catch (ParseException e) {

          e.printStackTrace();
        }
        SimpleDateFormat postFormater = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        String newDateStr = postFormater.format(date);
        //				Log.d("OUT", "main: "+newDateStr+", owm: "+listItem.getString("dt_txt"));
        if (listItem.getString("dt_txt").equals(newDateStr)) {
          if (i > 0) {
            double d =
                Double.parseDouble(listItem.getJSONObject("main").getString("temp")) - 273.15;
            return String.valueOf(d);
          }
        }
      } catch (Exception e) {
      }
    }
    return null;
  }
 @Override
 protected void onPostExecute(final HttpResponse result) {
   if (dialog.isShowing()) {
     dialog.dismiss();
   }
   if (result != null) {
     int responseCode = result.getStatusLine().getStatusCode();
     String responseBody = "";
     switch (responseCode) {
       case 200:
         HttpEntity entity = result.getEntity();
         if (entity != null) {
           try {
             responseBody = EntityUtils.toString(entity);
           } catch (ParseException e) {
             e.printStackTrace();
           } catch (IOException e) {
             e.printStackTrace();
           }
         }
         break;
     }
     Log.v(TAG, "Response Code => " + responseCode);
     Log.i(TAG, "Response Body => " + responseBody);
   }
 }
 public String post(URI serverPage, List<BasicNameValuePair> ps) {
   try {
     HttpResponse response = this.doPost(serverPage, ps);
     return handleResponse(response);
   } catch (ParseException e) {
     e.printStackTrace();
   } catch (IOException e) {
     e.printStackTrace();
   } catch (Exception e) {
     e.printStackTrace();
   }
   return null;
 }
 public String get(URI serverPage) {
   try {
     HttpResponse response = this.doGet(serverPage);
     return handleResponse(response);
   } catch (ParseException e) {
     e.printStackTrace();
   } catch (IOException e) {
     e.printStackTrace();
   } catch (Exception e) {
     e.printStackTrace();
   }
   return null;
 }
示例#6
0
 /**
  * 从格式化时间获取time
  *
  * @param time
  * @param format
  * @return
  */
 public static String formatToTime(String time, String format) {
   Date date = null;
   SimpleDateFormat formatTime = new SimpleDateFormat(format, Locale.CHINA);
   try {
     try {
       date = formatTime.parse(time);
     } catch (java.text.ParseException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
     }
   } catch (ParseException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
   return String.valueOf(date.getTime());
 }
 /** Sets the current URL associated with this load. */
 void setUrl(String url) {
   if (url != null) {
     if (URLUtil.isDataUrl(url)) {
       // Don't strip anchor as that is a valid part of the URL
       mUrl = url;
     } else {
       mUrl = URLUtil.stripAnchor(url);
     }
     mUri = null;
     if (URLUtil.isNetworkUrl(mUrl)) {
       try {
         mUri = new WebAddress(mUrl);
       } catch (ParseException e) {
         e.printStackTrace();
       }
     }
   }
 }
示例#8
0
  private String convert_date(String date) {
    // convert date from text to timestamp using french locale
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd MMMMMMM yyyy", Locale.FRENCH);
    java.util.Date dateObj = null;
    java.sql.Date sqlDate = null;
    try {
      dateObj = simpleDateFormat.parse(date);

      sqlDate = new java.sql.Date(dateObj.getTime());
    } catch (ParseException e) {

      e.printStackTrace();
    } catch (java.text.ParseException e) {

      e.printStackTrace();
    }
    date = sqlDate.toString();
    return date;
  }
  public String execute(String id, String message, boolean paramBoolean) {
    String strEntity =
        "body="
            + message
            + "&tids=id."
            + id
            + /*"&fb_dtsg=" + AppBase.g() +*/ "&__user="******"&__ajax__=true&__metablock__=3";

    httpClient.getParams().setParameter("http.protocol.cookie-policy", "best-match");
    // httpClient.getCookieSpecs().register("lenient", new b(this));

    // HttpClientParams.setCookiePolicy(this.httpClient.getParams(), "lenient");

    httpPost =
        new HttpPost(
            "https://touch.facebook.com/messages/send/?refid=12&m_sess="
                + Session.getActiveSession().getAccessToken());
    httpPost.setHeader(
        "User-Agent", "mozilla/4.0 (mobilephone scp-3200/us/1.0) netfront/3.1 mmp/2.0");
    httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded");
    httpPost.setHeader("Cookie", f);

    httpResponse = null;

    String[] arrayOfString1;
    int i;
    StringEntity localStringEntity;

    /*if (!this.f.equals(""))
    {
    	this.cookieStore.clear();
    	arrayOfString1 = this.f.split(";");
    	i = 0;
    }

    if (i >= arrayOfString1.length)
    	this.httpContext.setAttribute("http.cookie-store", this.cookieStore);*/

    try {
      localStringEntity = new StringEntity(strEntity, "UTF-8");
      this.httpPost.setEntity(localStringEntity);
    } catch (UnsupportedEncodingException localUnsupportedEncodingException) {
      localUnsupportedEncodingException = localUnsupportedEncodingException;
      System.out.println(
          "HTTPHelp : UnsupportedEncodingException : " + localUnsupportedEncodingException);
      localStringEntity = null;
    }

    try {
      this.httpResponse = this.httpClient.execute(this.httpPost, this.httpContext);
      if (this.httpResponse == null) {
        /*//return "";
        String[] arrayOfString2 = arrayOfString1[i].split("=");
        BasicClientCookie localBasicClientCookie = new BasicClientCookie(arrayOfString2[0], arrayOfString2[1]);
        localBasicClientCookie.setDomain("facebook.com");
        this.cookieStore.addCookie(localBasicClientCookie);*/
        // i++;

      }
    } catch (ClientProtocolException localClientProtocolException) {
      System.out.println(
          "HTTPHelp : ClientProtocolException : " + localClientProtocolException.getMessage());
    } catch (IOException localIOException1) {
      System.out.println("HTTPHelp : IOException : " + localIOException1);

      HttpEntity localHttpEntity = this.httpResponse.getEntity();
      try {
        String str = EntityUtils.toString(localHttpEntity);
        return str;
      } catch (ParseException localParseException) {
        localParseException.printStackTrace();
        return "";
      } catch (IOException localIOException2) {
        localIOException2.printStackTrace();
      }
    }

    return "";
  }
示例#10
0
  private ArrayList<Tour> connectGetID() {
    String result = null;
    InputStream is = null;
    StringBuilder sb = null;
    try {
      HttpClient httpclient = new DefaultHttpClient();
      HttpPost httppost = new HttpPost("http://vikabelous.zz.mu/search_hotTours.php");
      HttpResponse response = httpclient.execute(httppost);
      HttpEntity entity = response.getEntity();
      is = entity.getContent();
    } catch (Exception e) {
      Log.e("log_tag", "Error in http connection" + e.toString());
    }
    try {
      BufferedReader reader = new BufferedReader(new InputStreamReader(is), 8);
      sb = new StringBuilder();
      sb.append(reader.readLine() + "\n");
      String line = "0";

      while ((line = reader.readLine()) != null) {
        sb.append(line + "\n");
      }

      is.close();
      result = sb.toString();

    } catch (Exception e) {
      Log.e("log_tag", "Error converting result " + e.toString());
    }

    ArrayList<Tour> TL = new ArrayList<Tour>();

    int id;
    String NameRus;
    String NameEn;
    String TypeEn;
    String TypeRus;
    int Price;
    int days;
    String Transport;
    String photo;
    String Date;

    try {
      JSONArray jArray = new JSONArray(result);
      JSONObject json_data = null;

      for (int i = 0; i < jArray.length(); i++) {
        json_data = jArray.getJSONObject(i);
        id = json_data.getInt("ID");
        NameRus = json_data.getString("TourNameRus");
        NameEn = json_data.getString("TourNameEN");
        TypeEn = json_data.getString("TypeEn");
        TypeRus = json_data.getString("TypeRus");
        Price = json_data.getInt("Price");
        days = json_data.getInt("Days");
        Transport = json_data.getString("Transport");
        photo = json_data.getString("Photo");
        Date = json_data.getString("Date");
        Bitmap B = null;
        try {
          B = BitmapFactory.decodeStream((InputStream) new URL(photo).getContent());
        } catch (MalformedURLException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }

        Tour T = new Tour(id, NameRus, NameEn, TypeEn, TypeRus, Price, days, Transport, B);
        T.Dates.add(Date);
        TL.add(T);
      }

    } catch (JSONException e1) {
      e1.printStackTrace();
    } catch (ParseException e1) {
      e1.printStackTrace();
    }
    return TL;
  }
示例#11
0
  public void stateUpdate(ObdCommandJob job) {

    initLocationManager();

    initDbAdapter();

    String cmdName = job.getCommand().getName();
    String cmdResult = job.getCommand().getFormattedResult();

    Log.d(TAG, FuelTrim.LONG_TERM_BANK_1.getBank() + " equals " + cmdName + "?");

    if (AvailableCommandNames.ENGINE_RPM.getValue().equals(cmdName)) {
      //			TextView tvRpm = (TextView) findViewById(R.id.rpm_text);
      //			tvRpm.setText(cmdResult + " rpm");
      rpmMeasurement = Integer.valueOf(cmdResult);
    } else if (AvailableCommandNames.SPEED.getValue().equals(cmdName)) {
      //			TextView tvSpeed = (TextView) findViewById(R.id.spd_text);
      //			tvSpeed.setText(cmdResult + " km/h");
      speed = ((SpeedObdCommand) job.getCommand()).getMetricSpeed();
      speedMeasurement = speed;
      // } else if
      // (AvailableCommandNames.MAF.getValue().equals(cmdName))
      // {
      // maf = ((MassAirFlowObdCommand)
      // job.getCommand()).getMAF();
      // addTableRow(cmdName, cmdResult);
    } else if (FuelTrim.SHORT_TERM_BANK_1.getBank().equals(cmdName)) {
      //			TextView shortTermTrimTextView = (TextView) findViewById(R.id.shortTrimText);
      String shortTermTrim = ((FuelTrimObdCommand) job.getCommand()).getFormattedResult();
      //			shortTermTrimTextView.setText("Short Term Trim: "
      //					+ shortTermTrim + " %");
      try {
        NumberFormat format = NumberFormat.getInstance(Locale.GERMAN);
        Number number;
        number = format.parse(shortTermTrim);
        shortTermTrimBank1Measurement = number.doubleValue();
      } catch (ParseException e) {
        Log.e("obd", "parse exception short term");
        e.printStackTrace();
      } catch (java.text.ParseException e) {
        Log.e("obd", "parse exception short term");
        e.printStackTrace();
      }
      // shortTermTrimBank1Measurement = Double
      // .valueOf(shortTermTrim);
    } else if (FuelTrim.LONG_TERM_BANK_1.getBank().equals(cmdName)) {
      //			TextView longTermTrimTextView = (TextView) findViewById(R.id.longTrimText);
      ltft = ((FuelTrimObdCommand) job.getCommand()).getValue();
      String longTermTrim = ((FuelTrimObdCommand) job.getCommand()).getFormattedResult();
      //			longTermTrimTextView.setText("Long Term Trim: "
      //					+ longTermTrim + " %");

      try {
        NumberFormat format = NumberFormat.getInstance(Locale.GERMAN);
        Number number;
        number = format.parse(longTermTrim);
        longTermTrimBank1Measurement = number.doubleValue();
      } catch (ParseException e) {
        Log.e("obd", "parse exception long term");
        e.printStackTrace();
      } catch (java.text.ParseException e) {
        Log.e("obd", "parse exception long term");
        e.printStackTrace();
      }
      // longTermTrimBank1Measurement =
      // Double.valueOf(longTermTrim);
    } else if (AvailableCommandNames.AIR_INTAKE_TEMP.getValue().equals(cmdName)) {
      //			TextView intakeTempTextView = (TextView) findViewById(R.id.intakeTempText);
      String intakeTemp = ((AirIntakeTemperatureObdCommand) job.getCommand()).getFormattedResult();
      //			intakeTempTextView.setText("Intake Temp: " + intakeTemp
      //					+ " C");
      try {
        intakeTemperatureMeasurement = Integer.valueOf(intakeTemp);
      } catch (NumberFormatException e) {
        Log.e("obd", "intake temp parse exception");
        e.printStackTrace();
      }

      // } else if
      // (AvailableCommandNames.EQUIV_RATIO.getValue().equals(
      // cmdName)) {
      // equivRatio = ((CommandEquivRatioObdCommand) job
      // .getCommand()).getRatio();
      // addTableRow(cmdName, cmdResult);
    } else if (AvailableCommandNames.THROTTLE_POS.getValue().equals(cmdName)) {
      //			TextView throttlePositionTextView = (TextView) findViewById(R.id.throttle);
      String throttlePos = ((ThrottlePositionObdCommand) job.getCommand()).getFormattedResult();
      //			throttlePositionTextView.setText("T. Pos: " + throttlePos);

      try {
        NumberFormat format = NumberFormat.getInstance(Locale.GERMAN);
        Number number;
        number = format.parse(throttlePos);
        throttlePositionMeasurement = number.doubleValue();
      } catch (ParseException e) {
        Log.e("obd", "parse exception throttle");
        e.printStackTrace();
      } catch (java.text.ParseException e) {
        Log.e("obd", "parse exception throttle");
        e.printStackTrace();
      }

      // try {
      // throttlePositionMeasurement = Double
      // .valueOf(throttlePos);
      // Log.e("obd", "cast successful");
      // } catch (NumberFormatException e) {
      // Log.e("obd2", "number format exception");
      // e.printStackTrace();
      // }

    } else if (AvailableCommandNames.FUEL_CONSUMPTION.getValue().equals(cmdName)) {
      //			TextView fuelConsumptionTextView = (TextView) findViewById(R.id.fuelconsumption);
      String fuelCon = ((FuelConsumptionObdCommand) job.getCommand()).getFormattedResult();
      //			fuelConsumptionTextView.setText(fuelCon + " l/h");
      Log.d(TAG, "Fuel consumption");
      Log.d(TAG, fuelCon);

      try {
        NumberFormat format = NumberFormat.getInstance(Locale.GERMAN);
        Number number;
        number = format.parse(fuelCon);
        fuelConsumptionMeasurement = number.doubleValue();
      } catch (ParseException e) {
        Log.e("obd", "parse exception fuelCon");
        e.printStackTrace();
      } catch (java.text.ParseException e) {
        Log.e("obd", "parse exception fuelCon");
        e.printStackTrace();
      }
      // fuelConsumptionMeasurement = Double.valueOf(fuelCon);
      // } else if (AvailableCommandNames.FUEL_ECONOMY.getValue()
      // .equals(cmdName)) {
      // TextView fuelEconomyTextView = (TextView)
      // findViewById(R.id.fueleconomy);
      // String fuelEco = ((FuelEconomyObdCommand)
      // job.getCommand())
      // .getFormattedResult();
      // fuelEconomyTextView.setText(fuelEco + " l/100km");

      // } else if
      // (AvailableCommandNames.FUEL_TYPE.getValue().equals(
      // cmdName)) {
      // TextView fuelTypeTextView = (TextView)
      // findViewById(R.id.fuelTypeTextDisplay);
      // String fuelType = ((FindFuelTypeObdCommand) job
      // .getCommand()).getFormattedResult();
      // try {
      // fuelTypeTextView.setText("Fuel Type: " + fuelType);
      // } catch (Exception e) {
      // Log.e("obd2", "fuel type exception");
      // e.printStackTrace();
      // }
    } else if (AvailableCommandNames.ENGINE_LOAD.getValue().equals(cmdName)) {
      //			TextView engineLoadTextView = (TextView) findViewById(R.id.engineLoadText);
      String engineLoad = ((EngineLoadObdCommand) job.getCommand()).getFormattedResult();
      Log.e("obd2", "Engine Load: " + engineLoad);
      //			engineLoadTextView.setText("Engine load: " + engineLoad);
      try {
        NumberFormat format = NumberFormat.getInstance(Locale.GERMAN);
        Number number;
        number = format.parse(engineLoad);
        engineLoadMeasurement = number.doubleValue();
      } catch (ParseException e) {
        Log.e("obd", "parse exception load");
        e.printStackTrace();
      } catch (java.text.ParseException e) {
        Log.e("obd", "parse exception load");
        e.printStackTrace();
      }
      // engineLoadMeasurement = Double.valueOf(engineLoad);
    } else if (AvailableCommandNames.MAF.getValue().equals(cmdName)) {
      //			TextView mafTextView = (TextView) findViewById(R.id.mafText);
      String maf = ((MassAirFlowObdCommand) job.getCommand()).getFormattedResult();
      //			mafTextView.setText("MAF: " + maf + " g/s");
      try {
        NumberFormat format = NumberFormat.getInstance(Locale.GERMAN);
        Number number;
        number = format.parse(maf);
        mafMeasurement = number.doubleValue();
      } catch (ParseException e) {
        Log.e("obd", "parse exception maf");
        e.printStackTrace();
      } catch (java.text.ParseException e) {
        Log.e("obd", "parse exception maf");
        e.printStackTrace();
      }
      // mafMeasurement = Double.valueOf(maf);
    } else if (AvailableCommandNames.INTAKE_MANIFOLD_PRESSURE.getValue().equals(cmdName)) {
      //			TextView intakePressureTextView = (TextView) findViewById(R.id.intakeText);
      String intakePressure =
          ((IntakeManifoldPressureObdCommand) job.getCommand()).getFormattedResult();
      //			intakePressureTextView.setText("Intake: " + intakePressure
      //					+ "kPa");
      try {
        intakePressureMeasurement = Integer.valueOf(intakePressure);
      } catch (NumberFormatException e) {
        Log.e("obd", "intake pressure parse exception");
        e.printStackTrace();
      }
    } else {
      // addTableRow(cmdName, cmdResult);
    }
    updateMeasurement();
  }