Exemplo n.º 1
0
  @Override
  public void onSelects(final List<EntitySelect> entitySelects) {
    if (mWaitfor != null) {
      mWaitfor.close();
      mWaitfor = null;
    }

    if (entitySelects != null) {
      mSelectObject = new PopWindowSelectObject(this, mEntityRelation, entitySelects, this);
      mSelectObject.show();
    }
  }
Exemplo n.º 2
0
  @Override
  public boolean onOptionsItemSelected(final MenuItem item) {
    final int id = item.getItemId();
    switch (id) {
      case Menu.FIRST + 1:
        {
          if (mHandler != null) mHandler.removeCallbacks(this);

          request(false);
          final Toast toast =
              Toast.makeText(this, R.string.request_relation_refresh, Toast.LENGTH_LONG);
          toast.show();
        }
        break;

      case Menu.FIRST + 2:
        {
          if (mStatus) mStatus = false;
          else mStatus = true;

          final EntityRelation entityRelation = EntityRelation.getRelation();
          if (entityRelation != null) {
            entityRelation.setStatus(mStatus);
            EntityRelation.writeRelation(entityRelation);
          }
        }
        break;

      case Menu.FIRST + 3:
        {
          if (mLocationClient == null) mLocationClient = EntityLocation.initLocation(this, 0, this);

          final Toast toast =
              Toast.makeText(this, R.string.location_my_location, Toast.LENGTH_LONG);
          toast.show();
        }
        break;

      case Menu.FIRST + 4:
        {
          mWaitfor = new PopWindowWaitfor(this);
          mWaitfor.start();

          final RequestSelects request = new RequestSelects(this, mThreadPool, this);
          request.request();
        }
        break;
    }

    return super.onOptionsItemSelected(item);
  }
Exemplo n.º 3
0
  @Override
  public void onClick(final View view) {
    final Object object = view.getTag();
    final int id = view.getId();
    switch (id) {
      case R.id.tv_time:
        {
          if (object != null) {
            final EntityLocations entityLocations = (EntityLocations) object;
            final double latitude = entityLocations.getLatitude();
            final double longitude = entityLocations.getLongitude();
            mapViewRefresh(latitude, longitude, 17.0f, 800);
          }
        }
        break;

      case R.id.rl_item:
        {
          if (mSelectObject != null) {
            mSelectObject.close();
            mSelectObject = null;
          }

          if (mEntityRelation == null) mEntityRelation = EntityRelation.getRelation();

          if (mEntityRelation != null) {
            mWaitfor = new PopWindowWaitfor(this);
            mWaitfor.start();

            final EntitySelect entitySelect = (EntitySelect) object;
            final String name = entitySelect.getName();
            mEntityRelation.setTo(name);
            mRequestSelect = new RequestSelect(this, mThreadPool, this);
            mRequestSelect.request(name);
          }
        }
        break;
    }
  }
Exemplo n.º 4
0
  @Override
  public void onRelation(final EntityLocation entityLocation, final boolean auto) {
    if (mWaitfor != null) {
      mWaitfor.close();
      mWaitfor = null;
    }

    if (!auto) {
      int id = R.string.request_relation_success;
      if (entityLocation == null) id = R.string.request_relation_fail;

      final Toast toast = Toast.makeText(this, id, Toast.LENGTH_LONG);
      toast.show();
    }

    if (mHandler == null) mHandler = new Handler();

    final int delayed = 2 * 60 * 1000;
    mHandler.postDelayed(this, delayed);

    if (mEntityRelation == null || entityLocation == null) {
      mapViewRefresh(mLatitude, mLongitude, mZoom);
      return;
    }

    final String to = mEntityRelation.getTo();
    if (to == null) {
      mapViewRefresh(mLatitude, mLongitude, mZoom);
      return;
    }

    final String sColor = entityLocation.getColor();
    final List<EntityLocations> locations = entityLocation.getLocations();
    if (locations == null) {
      mapViewRefresh(mLatitude, mLongitude, mZoom);
      return;
    }

    int color = 0, alpha = 20;

    try {
      color = Color.parseColor(sColor);
    } catch (Exception e) {
      color = Color.argb(alpha, 255, 0, 0);
    }

    color = Color.argb(alpha, Color.red(color), Color.green(color), Color.blue(color));

    if (locations.size() > 0) {
      mBaiduMap.clear();

      int i = 0;
      for (final EntityLocations entityLocations : locations) {
        addTime(sColor, entityLocations, i);
        final int j = i + 1;
        final String name = to.toLowerCase(Locale.ENGLISH) + j;

        final double latitude = entityLocations.getLatitude();
        final double longitude = entityLocations.getLongitude();
        final double accuracy = entityLocations.getRadius();

        if (i == 0) {
          mLatitude = latitude;
          mLongitude = longitude;
        }

        final MarkerOptions markerOptions = new MarkerOptions();
        final CircleOptions circleOptions = new CircleOptions();
        final LatLng latLng = new LatLng(latitude, longitude);
        markerOptions.position(latLng);
        circleOptions.center(latLng);
        circleOptions.radius((int) accuracy);
        circleOptions.fillColor(color);
        circleOptions.stroke(new Stroke(1, color));

        if (mBitmapDescriptor.containsKey(name)) {
          final BitmapDescriptor bitmapDescriptor = mBitmapDescriptor.get(name);
          markerOptions.icon(bitmapDescriptor);
          mBaiduMap.addOverlay(markerOptions);
        } else {
          final BitmapDescriptor bitmapDescriptor = Images.getIcon(name);
          if (bitmapDescriptor != null) {
            markerOptions.icon(bitmapDescriptor);
            mBitmapDescriptor.put(name, bitmapDescriptor);
            mBaiduMap.addOverlay(markerOptions);
          }
        }

        mBaiduMap.addOverlay(circleOptions);
        i++;
      }

      mapViewRefresh(mLatitude, mLongitude, 17.0f, 800);
    }
  }