Beispiel #1
0
  private void _onStart() {

    String myLocation = db.mapSetting.get(db.MY_LOCATION);
    String permitsLocation = db.mapSetting.get(db.LICENCE);

    if (isNetworkAvailable()) {
      if (myLocation != null && !myLocation.equals("0")) {
        loader.show();
        new LocationFromAsset(activity, this, myLocation);
      } else {
        if (permitsLocation == null || permitsLocation.equals("0")) {
          toast.show("Set agree licence first");
          return;
        }
        locationManagerNet = (LocationManager) activity.getSystemService(Context.LOCATION_SERVICE);
        if (locationManagerNet.getAllProviders().contains(LocationManager.NETWORK_PROVIDER)
            && locationManagerNet.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
          locationListenerNet = new MyLocationListenerNet(this);
          loader.show();
          if (ActivityCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_FINE_LOCATION)
                  != PackageManager.PERMISSION_GRANTED
              && ActivityCompat.checkSelfPermission(
                      activity, Manifest.permission.ACCESS_COARSE_LOCATION)
                  != PackageManager.PERMISSION_GRANTED) {
            // TODO: Consider calling
            //    ActivityCompat#requestPermissions
            // here to request the missing permissions, and then overriding
            //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
            //                                          int[] grantResults)
            // to handle the case where the user grants the permission. See the documentation
            // for ActivityCompat#requestPermissions for more details.
            return;
          }
          locationManagerNet.requestLocationUpdates(
              LocationManager.NETWORK_PROVIDER, 0, 0, locationListenerNet);
        } else {
          /** Локация недоступна */
          // locationManagerNet.removeUpdates(locationListenerNet);
          toast.show("Location is not available in setting");
        }
      }
    } else {
      toast.show("Network is not available");
    }
  }
Beispiel #2
0
  @Override
  public void accept(List<HashMap> list, String cityName, int statusCode) {
    //  Log.d(TAG, "diid"+list);
    if (statusCode != 200) {
      toast.show("Open weather map say Error!");
      loader.hide(100);
      return;
    }
    if (0 < list.size()) {
      this.list = list;

      inflateDay(list);
      db.mapSetting.put(db.TIMESTAMP_FORECAST, db.getTimeStamp());
      db.saveSetting();
    } else {
      toast.show("City not found");
    }
    loader.hide(100);
  }