@Override
 public void onConfigurationChanged(Configuration newConfig) {
   super.onConfigurationChanged(newConfig);
   mDrawerToggle.onConfigurationChanged(newConfig);
   hideSoftKeyboard();
   autoCompView.setFocusable(false);
   autoCompView.setFocusableInTouchMode(true);
 }
 public void onItemClick(AdapterView adapterView, View view, int position, long id) {
   String value = (String) adapterView.getItemAtPosition(position);
   try {
     userSelectedDestination = URLEncoder.encode(value, "UTF-8");
     autoCompView.setFocusable(false);
     autoCompView.setFocusableInTouchMode(true);
   } catch (UnsupportedEncodingException ex) {
     ex.printStackTrace();
   }
 }
Ejemplo n.º 3
0
  private void init(final Context context) {
    LayoutInflater mInflater =
        (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    mInflater.inflate(R.layout.jdb_expand_editext_layout, this);
    mProgressBar = (ProgressBar) findViewById(R.id.progress);
    mRightView = (ImageView) findViewById(R.id.icon_right);
    checkStatusOfIcon(mRightView, rightIconVisiable);
    mLeftView = (ImageView) findViewById(R.id.icon_left);
    checkStatusOfIcon(mLeftView, leftIconVisiable);
    mRightView.setOnClickListener(this);
    mTextView = (AutoCompleteTextView) findViewById(R.id.edittext);
    mTextView.setHint(this.hint);
    mTextView.setFocusableInTouchMode(enabled);
    if (this.password)
      mTextView.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
    mTextView.addTextChangedListener(
        new TextWatcher() {
          @Override
          public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {}

          @Override
          public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
            if (withProgress) {
              if (mCanLoad) {
                if (charSequence.length() >= threshold) {
                  if (onEditCompleted != null)
                    onEditCompleted.startSearch(ExpandEditText.this, charSequence.toString());
                } else {
                  if (onEditCompleted != null) onEditCompleted.endSearch(ExpandEditText.this);
                }
              } else {
                mCanLoad = !mCanLoad;
              }
            } else {
              // 有内容显示
              if (charSequence.length() >= 1) mRightView.setVisibility(View.VISIBLE);
              else mRightView.setVisibility(View.GONE);
            }
          }

          @Override
          public void afterTextChanged(Editable editable) {}
        });
  }
 @Override
 public void onResume() {
   super.onResume(); //  call the superclass method
   if (parking_listings == null) { // Means no results have been saved till now
     try {
       locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
       Location location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
       locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
       if (location != null) {
         onLocationChanged(location);
         locationManager.removeUpdates(MainActivity.this);
       }
     } catch (SecurityException e) {
       Log.e("PERMISSION_EXCEPTION", "PERMISSION_NOT_GRANTED");
     }
     hideSoftKeyboard();
     autoCompView.setFocusable(false);
     autoCompView.setFocusableInTouchMode(true);
   }
 }
  @Override
  public void onClick(final View v) {
    if (v == btnCalendarStart) {
      // Launch Date Picker Dialog
      DatePickerDialog dpdStart =
          new DatePickerDialog(
              this,
              new DatePickerDialog.OnDateSetListener() {

                @Override
                public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                  // Display Selected date in textbox
                  txtDateStart.setText(
                      String.format("%02d", dayOfMonth)
                          + "/"
                          + String.format("%02d", (monthOfYear + 1))
                          + "/"
                          + year);
                  startYear = year;
                  startMonth = monthOfYear;
                  startDay = dayOfMonth;
                }
              },
              startYear,
              startMonth,
              startDay);
      dpdStart.show();
    }
    if (v == btnCalendarEnd) {
      // Launch End Date Picker Dialog
      DatePickerDialog dpdEnd =
          new DatePickerDialog(
              this,
              new DatePickerDialog.OnDateSetListener() {

                @Override
                public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                  txtDateEnd.setText(
                      String.format("%02d", dayOfMonth)
                          + "/"
                          + String.format("%02d", (monthOfYear + 1))
                          + "/"
                          + year);
                  endYear = year;
                  endMonth = monthOfYear;
                  endDay = dayOfMonth;
                }
              },
              endYear,
              endMonth,
              endDay);
      dpdEnd.show();
    }
    if (v == btnTimeStart) {
      // Launch Time Picker Dialog
      TimePickerDialog tpdStart =
          new TimePickerDialog(
              this,
              new TimePickerDialog.OnTimeSetListener() {

                @Override
                public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                  startHour = hourOfDay;
                  startMinute = minute;

                  if (startMinute != 0) {
                    Date startDate =
                        convertStringToDate(
                            startDay, startMonth, startYear, startHour, startMinute);
                    Date startDateRoundedToNearestHour = roundToNearestHour(startDate);

                    SimpleDateFormat sdf =
                        new SimpleDateFormat("dd/MM/yyyy HH:mm"); // the format of your date
                    sdf.setTimeZone(
                        TimeZone.getTimeZone("GMT-5")); // give a timezone reference for formating
                    String formattedDate = sdf.format(startDateRoundedToNearestHour);

                    String[] formattedDateSeparated = formattedDate.split(" ");
                    String[] formatDate = formattedDateSeparated[0].split("/");
                    String[] formatTime = formattedDateSeparated[1].split(":");

                    startDay = Integer.parseInt(formatDate[0]);
                    startMonth = Integer.parseInt(formatDate[1]) - 1;
                    startYear = Integer.parseInt(formatDate[2]);
                    startHour = Integer.parseInt(formatTime[0]);
                    startMinute = Integer.parseInt(formatTime[1]);

                    txtDateStart.setText(
                        String.format("%02d", startDay)
                            + "/"
                            + String.format("%02d", (startMonth + 1))
                            + "/"
                            + startYear);
                  }

                  txtTimeStart.setText(
                      String.format("%02d", startHour) + ":" + String.format("%02d", startMinute));
                }
              },
              startHour,
              startMinute,
              false);
      tpdStart.show();
    }

    if (v == btnTimeEnd) {
      // Launch Time Picker Dialog
      TimePickerDialog tpdEnd =
          new TimePickerDialog(
              this,
              new TimePickerDialog.OnTimeSetListener() {

                @Override
                public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                  endHour = hourOfDay;
                  endMinute = minute;
                  if (endMinute != 0) {
                    Date endDate =
                        convertStringToDate(endDay, endMonth, endYear, endHour, endMinute);
                    Date endDateRoundedToNearestHour = roundToNearestHour(endDate);

                    SimpleDateFormat sdf =
                        new SimpleDateFormat("dd/MM/yyyy HH:mm"); // the format of your date
                    sdf.setTimeZone(
                        TimeZone.getTimeZone("GMT-5")); // give a timezone reference for formating
                    String formattedDate = sdf.format(endDateRoundedToNearestHour);

                    String[] formattedDateSeparated = formattedDate.split(" ");
                    String[] formatDate = formattedDateSeparated[0].split("/");
                    String[] formatTime = formattedDateSeparated[1].split(":");

                    endDay = Integer.parseInt(formatDate[0]);
                    endMonth = Integer.parseInt(formatDate[1]) - 1;
                    endYear = Integer.parseInt(formatDate[2]);
                    endHour = Integer.parseInt(formatTime[0]);
                    endMinute = Integer.parseInt(formatTime[1]);

                    txtDateEnd.setText(
                        String.format("%02d", endDay)
                            + "/"
                            + String.format("%02d", (endMonth + 1))
                            + "/"
                            + endYear);
                  }

                  txtTimeEnd.setText(
                      String.format("%02d", endHour) + ":" + String.format("%02d", endMinute));
                }
              },
              endHour,
              endMinute,
              false);
      tpdEnd.show();
    }

    if (v == submitUpdate) {
      if (userSelectedDestination == null) {
        if (apiResults.getListings() != null) {
          mMap = mapFragment.getMap();
          mMap.clear();
        }
        Toast.makeText(MainActivity.this, "Destination cannot be empty", Toast.LENGTH_SHORT).show();
      } else {
        if (doDateTimeValidation()) {
          spinner.setVisibility(View.VISIBLE);
          submitUpdate.setEnabled(false);
          autoCompView.setFocusable(false);
          autoCompView.setFocusableInTouchMode(true);
          submitUpdate.getBackground().setColorFilter(0xFFFFFFFF, PorterDuff.Mode.MULTIPLY);
          String sorting = "rating";
          int checked_restroom = 0;
          int checked_mobile = 0;
          int checked_indoor = 0;
          int checked_attended = 0;
          int checked_security = 0;
          int checked_valet = 0;
          long epoch_start = userSelectedStartDateTime;
          long epoch_end = userSelectedEndDateTime;
          String urlString =
              "http://api.parkwhiz.com/search?destination="
                  + userSelectedDestination
                  + "&key="
                  + getResources().getString(R.string.park_whiz_key)
                  + "&start="
                  + epoch_start
                  + "&end="
                  + epoch_end
                  + "&sort="
                  + sorting
                  + "&restroom="
                  + 0
                  + "&security="
                  + 0
                  + "&valet="
                  + 0
                  + "&indoor="
                  + 0
                  + "&eticket="
                  + 0
                  + "&attended="
                  + 0;

          Toast.makeText(MainActivity.this, "Sending your request", Toast.LENGTH_SHORT).show();
          mMap = mapFragment.getMap();
          mMap.clear();
          apiResults = new GetAPIResults(getBaseContext(), mapFragment, this);
          apiResults.execute(urlString);
          hideSoftKeyboard();
        }
      }
    }
  }