Ejemplo n.º 1
0
  @Override
  public void onClick(View v) {

    AlertDialog.Builder builderSingle = new AlertDialog.Builder(MainActivity.this);

    switch (v.getId()) {
      case R.id.btncity:
        builderSingle.setTitle("נא לבחור עיר:");
        final ArrayAdapter<String> cityArrayAdapter =
            new ArrayAdapter<String>(
                MainActivity.this, android.R.layout.select_dialog_singlechoice);
        for (City city : WelcomeActivity.PARSE_DATA.getData()) {
          cityArrayAdapter.add(city.getName());
        }

        builderSingle.setAdapter(
            cityArrayAdapter,
            new DialogInterface.OnClickListener() {

              @Override
              public void onClick(DialogInterface dialog, int which) {

                city.setText(WelcomeActivity.PARSE_DATA.getData().get(which).getName());

                Log.d("name", WelcomeActivity.PARSE_DATA.getData().get(which).getName());
                Log.d(
                    "shop center size ",
                    WelcomeActivity.PARSE_DATA.getData().get(which).getShopCenters().size() + "");

                if (WelcomeActivity.PARSE_DATA.getData().get(which).getShopCenters().size() > 0) {

                  center.setEnabled(true);

                  selectedCity.setName(WelcomeActivity.PARSE_DATA.getData().get(which).getName());
                  selectedCity.set_id(WelcomeActivity.PARSE_DATA.getData().get(which).get_id());
                  selectedCity.setCoordinates(
                      WelcomeActivity.PARSE_DATA.getData().get(which).getCoordinates());
                  selectedCity.setShopCenters(
                      WelcomeActivity.PARSE_DATA.getData().get(which).getShopCenters());

                  Log.d("selected name:", selectedCity.getName());
                  Log.d("ccity center:", selectedCity.getShopCenters().size() + "");
                } else {
                  center.setEnabled(false);
                  floor.setEnabled(false);
                }
              }
            });
        builderSingle.show();

        break;
      case R.id.btncenter:
        builderSingle.setTitle("נא לבחור מרכז קניות");
        final ArrayAdapter<String> shopCenterArrayAdapter =
            new ArrayAdapter<String>(
                MainActivity.this, android.R.layout.select_dialog_singlechoice);
        for (ShopCenter shopCenter : selectedCity.getShopCenters()) {
          shopCenterArrayAdapter.add(shopCenter.getName());
        }

        builderSingle.setAdapter(
            shopCenterArrayAdapter,
            new DialogInterface.OnClickListener() {

              @Override
              public void onClick(DialogInterface dialog, int which) {

                center.setText(selectedCity.getShopCenters().get(which).getName());

                if (selectedCity.getShopCenters().get(which).getFloors().size() < 1) {

                  floor.setEnabled(false);

                  fillSelectedShopCenter(which);

                  iv.setImageBitmap(selectedShopCenter.getCenterImage());

                } else {
                  floor.setEnabled(true);
                  fillSelectedShopCenter(which);
                  iv.setImageBitmap(selectedShopCenter.getCenterImage());
                }
              }

              private void fillSelectedShopCenter(int which) {
                selectedShopCenter.set_id(selectedCity.getShopCenters().get(which).get_id());
                selectedShopCenter.setName(selectedCity.getShopCenters().get(which).getName());
                selectedShopCenter.setCityId(selectedCity.getShopCenters().get(which).getCityId());
                selectedShopCenter.setCoordinates(
                    selectedCity.getShopCenters().get(which).getCoordinates());
                selectedShopCenter.setCenterImage(
                    selectedCity.getShopCenters().get(which).getCenterImage());
                selectedShopCenter.setFloors(selectedCity.getShopCenters().get(which).getFloors());
              }
            });
        builderSingle.show();

        break;
      case R.id.btnfloor:
        builderSingle.setTitle("floors:");
        final ArrayAdapter<String> floorsArrayAdapter =
            new ArrayAdapter<String>(
                MainActivity.this, android.R.layout.select_dialog_singlechoice);
        for (Floor floor : selectedShopCenter.getFloors()) {
          floorsArrayAdapter.add(floor.getName());
        }

        builderSingle.setAdapter(
            floorsArrayAdapter,
            new DialogInterface.OnClickListener() {

              @Override
              public void onClick(DialogInterface dialog, int which) {

                selectedFloor.set_id(selectedShopCenter.getFloors().get(which).get_id());
                selectedFloor.setName(selectedShopCenter.getFloors().get(which).getName());
                selectedFloor.setCityId(selectedShopCenter.getFloors().get(which).getCityId());
                selectedFloor.setShopCenterId(
                    selectedShopCenter.getFloors().get(which).getShopCenterId());
                selectedFloor.setFloorMapImage(
                    selectedShopCenter.getFloors().get(which).getFloorMapImage());
                selectedFloor.setFloorMaskImage(
                    selectedShopCenter.getFloors().get(which).getFloorMaskImage());
                selectedFloor.setShops(selectedShopCenter.getFloors().get(which).getShops());

                iv.setImageBitmap(selectedFloor.getFloorMapImage());
                ivMask.setImageBitmap(selectedFloor.getFloorMaskImage());
                floor.setText(selectedShopCenter.getFloors().get(which).getName());
                imageCrosserMethod();
              }
            });
        builderSingle.show();

        break;
    }
  }
Ejemplo n.º 2
0
  private void checkLocation(Location location) {

    double latNow = location.getLatitude();
    double lonNow = location.getLongitude();

    for (City thisCity : WelcomeActivity.PARSE_DATA.getData()) {

      if ((thisCity.getCoordinates().getLatMin() <= latNow)
          && (latNow <= thisCity.getCoordinates().getLatMax())
          && ((thisCity.getCoordinates().getLonMin() <= lonNow)
              && (lonNow <= thisCity.getCoordinates().getLonMax()))) {

        city.setText(thisCity.getName());

        Log.d("name", thisCity.getName());
        Log.d("shop center size ", thisCity.getShopCenters().size() + "");

        if (thisCity.getShopCenters().size() > 0) {

          center.setEnabled(true);

          selectedCity.setName(thisCity.getName());
          selectedCity.set_id(thisCity.get_id());
          selectedCity.setCoordinates(thisCity.getCoordinates());
          selectedCity.setShopCenters(thisCity.getShopCenters());

          Log.d("selected name:", selectedCity.getName());
          Log.d("ccity center:", selectedCity.getShopCenters().size() + "");

        } else {
          center.setEnabled(false);
          floor.setEnabled(false);
        }

        for (ShopCenter thisShopCenter : thisCity.getShopCenters()) {

          if ((thisShopCenter.getCoordinates().getLatMin() <= latNow)
              && (latNow <= thisShopCenter.getCoordinates().getLatMax())
              && ((thisShopCenter.getCoordinates().getLonMin() <= lonNow)
                  && (lonNow <= thisShopCenter.getCoordinates().getLonMax()))) {

            center.setText(thisShopCenter.getName());

            if (thisShopCenter.getFloors().size() < 1) {

              floor.setEnabled(false);

              fillSelectedShopCenter(thisShopCenter);

              iv.setImageBitmap(selectedShopCenter.getCenterImage());

            } else {
              floor.setEnabled(true);
              fillSelectedShopCenter(thisShopCenter);
              iv.setImageBitmap(selectedShopCenter.getCenterImage());
            }
          }
        }
      }
    }
  }