コード例 #1
0
  public void readPostalCodeList() {
    ContentResolver resolver = getContentResolver();
    Cursor cursor = null;
    Uri uri = Uri.parse(POSTALCODE_URI);

    // 先清空mPoscalCodList
    mPoscalCodList.clear();

    String selection;
    selection = PostalCodeEntity.USER_ID + "=" + "'0'";
    cursor = resolver.query(uri, PostalCodeEntity.projection, selection, null, null);

    if (cursor != null) {
      if (cursor.moveToFirst()) {
        do {
          PostalCodeEntity mPostalCodeEntity;
          mPostalCodeEntity = new PostalCodeEntity();
          mPostalCodeEntity.setPostalCode(cursor.getString(0));
          mPostalCodeEntity.setUserId(cursor.getString(1));

          mPoscalCodList.add(mPostalCodeEntity.getPostalCode());
          mapDate.put(mPostalCodeEntity.getPostalCode(), new weatherdataentity());
          readData(mPostalCodeEntity.getPostalCode());
          Log.v(TAG, "mPostalCodeEntity.getPostalCode() = " + mPostalCodeEntity.getPostalCode());
        } while (cursor.moveToNext());
      }

      cursor.close();
    }
  }
コード例 #2
0
 /** function addWedgetIDs ����������UserId */
 public static void addWidgetIDs(int[] widgetIDs) {
   //   synchronized (sLock) {
   for (int id : widgetIDs) {
     Log.d(TAG, "add widget ID:" + id);
     requestWidgetIDs.add(id);
   }
   //   }
 }
コード例 #3
0
 public void allSendBroadcast() {
   if (weatherwebservice.Update_Result_Flag == FLAG_UPDATE.UPDATE_SUCCES) {
     Log.v(TAG, "allSendBroadcast:FLAG_UPDATE.UPDATE_SUCCES");
     Intent intent = new Intent();
     intent.setAction(UPDATE_RESULT);
     intent.putExtra("cooee.weather.updateResult", "UPDATE_SUCCESED");
     intent.putExtra("cooee.weather.updateResult.postalcode", allPostalCode);
     intent.putExtra("cooee.weather.updateResult.userId", allUserId);
     sendBroadcast(intent);
   } else {
     Log.v(TAG, "allSendBroadcast:FLAG_UPDATE.UPDATE_FAILED");
     Intent intent = new Intent();
     intent.setAction(UPDATE_RESULT);
     intent.putExtra("cooee.weather.updateResult", "UPDATE_FAILED");
     intent.putExtra("cooee.weather.updateResult.postalcode", allPostalCode);
     intent.putExtra("cooee.weather.updateResult.userId", allUserId);
     sendBroadcast(intent);
   }
 }
コード例 #4
0
 public void mySendBroadcast() {
   Log.v(TAG, "mySendBroadcast");
   Intent intent = new Intent();
   intent.setAction(UPDATE_RESULT);
   intent.putExtra("cooee.weather.updateResult.postalcode", mPostalCode);
   intent.putExtra("cooee.weather.updateResult.userId", mUserId);
   if (weatherwebservice.Update_Result_Flag == FLAG_UPDATE.UPDATE_SUCCES) {
     intent.putExtra("cooee.weather.updateResult", "UPDATE_SUCCESED");
   } else if (weatherwebservice.Update_Result_Flag == FLAG_UPDATE.AVAILABLE_DATA) {
     intent.putExtra("cooee.weather.updateResult", "AVAILABLE_DATA");
   } else if (weatherwebservice.Update_Result_Flag == FLAG_UPDATE.INVILIDE_VALUE) {
     intent.putExtra("cooee.weather.updateResult", "INVILIDE_DATA");
   } else {
     intent.putExtra("cooee.weather.updateResult", "UPDATE_FAILED");
   }
   sendBroadcast(intent);
 }
コード例 #5
0
  @Override
  public int onStartCommand(Intent intent, int flags, int startId) {
    super.onStartCommand(intent, flags, startId);
    Log.v(TAG, "weather data service Intent action = " + intent.getAction());

    if (ACTION_UPDATE_ALL.equals(intent.getAction())) {

    } else {

    }

    // Only start processing thread if not already running
    //      synchronized (sLock) {
    // if (!isThreadRun) {

    //   }
    return START_REDELIVER_INTENT;
  }
コード例 #6
0
  public boolean readData(String cityname) {
    ContentResolver resolver = getContentResolver();
    Cursor cursor = null;
    Uri uri;
    String selection;
    weatherdataentity weatherdate = null;
    uri = Uri.parse(WEATHER_URI + "/" + cityname);
    selection = weatherdataentity.POSTALCODE + "=" + "'" + cityname + "'";
    cursor = resolver.query(uri, weatherdataentity.projection, selection, null, null);
    if (cursor != null) {
      weatherdate = mapDate.get(cityname);
      if (weatherdate == null) weatherdate = new weatherdataentity();
      if (cursor.moveToFirst()) {
        weatherdate.setUpdateMilis(cursor.getInt(0));
        weatherdate.setCity(cursor.getString(1));
        weatherdate.setPostalCode(cursor.getString(2));
        weatherdate.setForecastDate(cursor.getLong(3));
        weatherdate.setCondition(cursor.getString(4));
        weatherdate.setTempF(cursor.getInt(5));
        weatherdate.setTempC(cursor.getInt(6));

        weatherdate.setHumidity(cursor.getString(7));
        weatherdate.setIcon(cursor.getString(8));
        weatherdate.setWindCondition(cursor.getString(9));
        weatherdate.setLastUpdateTime(cursor.getLong(10));
        weatherdate.setIsConfigured(cursor.getInt(11));
      }

      int count = 0;
      while (cursor.moveToNext()) {
        Log.v(TAG, "updateMilis[" + count + "] = " + cursor.getInt(0));
        Log.v(TAG, "city[" + count + "] = " + cursor.getString(1));
        Log.v(TAG, "postcalCode[" + count + "] = " + cursor.getString(2));
        count++;
      }

      cursor.close();
    }

    int details_count = 0;
    if (weatherdate != null) {
      uri = Uri.parse(WEATHER_URI + "/" + cityname + "/detail");
      selection = weatherforecastentity.CITY + "=" + "'" + cityname + "'";
      cursor = resolver.query(uri, weatherforecastentity.forecastProjection, selection, null, null);
      if (cursor != null) {
        weatherforecastentity forecast;
        while (cursor.moveToNext()) {
          forecast = new weatherforecastentity();
          forecast.setDayOfWeek(cursor.getInt(2));
          forecast.setLow(cursor.getInt(3));
          forecast.setHight(cursor.getInt(4));
          forecast.setIcon(cursor.getString(5));
          forecast.setCondition(cursor.getString(6));
          // forecast.setWidgetId(cursor.getInt(6));

          weatherdate.getDetails().add(forecast);

          details_count = details_count + 1;
        }
        cursor.close();
      }
    }

    Log.v(TAG, "details_count = " + details_count);
    if (details_count < 4) {
      weatherdate = null;
    }
    return true;
  }
コード例 #7
0
  @Override
  protected void onHandleIntent(Intent arg0) {

    //     synchronized (sLock) {
    long now = System.currentTimeMillis();

    readSetting();

    if (true) {
      mPostalCode = arg0.getStringExtra("postalCode");
      mUserId = arg0.getIntExtra("userId", 0);
      mForcedUpdate = arg0.getIntExtra("forcedUpdate", 0);

      if (mPostalCode == null) {
        mPostalCode = "all";
      }

      Log.v(TAG, "onStartCommand mPostalCode = " + mPostalCode + ", mUserId = " + mUserId);

      isThreadRun = true;
      // new Thread(this).start();
    }

    if (mPostalCode.equals("bootup")) {
    } else if (mPostalCode.equals("all")) {
      ContentResolver resolver = this.getContentResolver();
      Cursor cursor = null;
      int i = 0;
      String[] postalcode = null;
      int[] id = null;
      Uri uri = Uri.parse("content://com.cooee.app.cooeejewelweather3D.dataprovider/postalCode");
      cursor = resolver.query(uri, PostalCodeEntity.projection, null, null, null);
      if (cursor != null) {
        int count = cursor.getCount();
        postalcode = new String[count];
        id = new int[count];
        while (cursor != null && cursor.moveToNext()) {
          postalcode[i] = cursor.getString(0);
          id[i] = cursor.getInt(1);
          i++;
        }
        addWidgetIDs(id);
        i = 0;
        while (hasMoreWidgetIDs()) {
          int widgetid = nextWidgetIDs();
          boolean ignored = false;
          allUserId = id[i];
          allPostalCode = postalcode[i];
          Log.v(
              TAG,
              "allUserId = "
                  + id[i]
                  + " allPostalCode = "
                  + postalcode[i]
                  + " WidgetIDs = "
                  + widgetid);
          for (int j = 0; j < i; j++) {
            if (postalcode[i].equals(postalcode[j])) {
              ignored = true;
              break;
            }
          }
          if (!ignored) {
            Uri data_uri =
                Uri.parse(
                    "content://com.cooee.app.cooeejewelweather3D.dataprovider/weather/"
                        + postalcode[i]);
            weatherwebservice.updateWeatherData(this, data_uri);
            allSendBroadcast();
          }
          i++;
        }
      }
      cursor.close();
    } else {
      boolean needUpdate = true;
      if (mForcedUpdate == 0) {
        ContentResolver resolver = this.getContentResolver();
        Cursor cursor = null;
        String selection = null;
        Uri uri =
            Uri.parse("content://" + weatherdataprovider.AUTHORITY + "/weather/" + mPostalCode);
        selection = weatherdataentity.POSTALCODE + "=" + "'" + mPostalCode + "'";
        cursor = resolver.query(uri, weatherdataentity.projection, selection, null, null);
        if (cursor != null) {
          if (cursor.moveToFirst()) {
            long lastUpdateTime = cursor.getLong(10);
            if (now - lastUpdateTime < mSettingEntity.getUpdateInterval()) {
              needUpdate = false;
            }
          }
          cursor.close();
        }
      }

      Log.v(TAG, "needUpdate = " + needUpdate);
      if (needUpdate) {
        Uri uri =
            Uri.parse("content://" + weatherdataprovider.AUTHORITY + "/weather/" + mPostalCode);
        weatherwebservice.updateWeatherData(this, uri);
      } else {
        weatherwebservice.Update_Result_Flag = FLAG_UPDATE.AVAILABLE_DATA;
      }

      mySendBroadcast();
    }

    if (mSettingEntity.getUpdateRegularly() != 0) {
      Time time = new Time();
      long interval = mSettingEntity.getUpdateInterval();
      if (interval < 60 * 1000 * 60 * 6) interval = 60 * 1000 * 60 * 6;

      if (weatherwebservice.Update_Result_Flag != FLAG_UPDATE.UPDATE_SUCCES) {
        interval = 60 * 1000 * 10;
      }
      time.set(now + interval);
      // time.set(now + 2 * 60 * 1000);
      long nextUpdate = time.toMillis(true);

      Intent updateIntent = new Intent(ACTION_UPDATE_ALL);
      updateIntent.setClass(this, weatherDataService.class);

      PendingIntent pendingIntent = PendingIntent.getService(this, 0, updateIntent, 0);

      // Schedule alarm, and force the device awake for this update
      AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
      alarmManager.set(AlarmManager.RTC_WAKEUP, nextUpdate, pendingIntent);
    }

    isThreadRun = false;

    // No updates remaining, so stop service
    stopSelf();
    //     }

  }