Пример #1
0
 private static void a(List<Asset> arrayList, DataMap dataMap, String string, pd.a.a object) {
   int n = object.type;
   if (n == 14) {
     dataMap.putString(string, null);
     return;
   }
   pd.a[] arra = object.awh;
   if (n == 1) {
     dataMap.putByteArray(string, arra.awi);
     return;
   }
   if (n == 11) {
     dataMap.putStringArray(string, arra.aws);
     return;
   }
   if (n == 12) {
     dataMap.putLongArray(string, arra.awt);
     return;
   }
   if (n == 15) {
     dataMap.putFloatArray(string, arra.awu);
     return;
   }
   if (n == 2) {
     dataMap.putString(string, arra.awj);
     return;
   }
   if (n == 3) {
     dataMap.putDouble(string, arra.awk);
     return;
   }
   if (n == 4) {
     dataMap.putFloat(string, arra.awl);
     return;
   }
   if (n == 5) {
     dataMap.putLong(string, arra.awm);
     return;
   }
   if (n == 6) {
     dataMap.putInt(string, arra.awn);
     return;
   }
   if (n == 7) {
     dataMap.putByte(string, (byte) arra.awo);
     return;
   }
   if (n == 8) {
     dataMap.putBoolean(string, arra.awp);
     return;
   }
   if (n == 13) {
     if (arrayList == null) {
       throw new RuntimeException("populateBundle: unexpected type for: " + string);
     }
     dataMap.putAsset(string, arrayList.get((int) arra.awv));
     return;
   }
   if (n == 9) {
     object = new DataMap();
     for (pd.a a : arra.awq) {
       pc.a(arrayList, (DataMap) object, a.name, a.awf);
     }
     dataMap.putDataMap(string, (DataMap) object);
     return;
   }
   if (n == 10) {
     n = pc.a(string, arra.awr);
     arrayList = pc.a(arrayList, (pd.a.a.a) arra, n);
     if (n == 14) {
       dataMap.putStringArrayList(string, arrayList);
       return;
     }
     if (n == 9) {
       dataMap.putDataMapArrayList(string, arrayList);
       return;
     }
     if (n == 2) {
       dataMap.putStringArrayList(string, arrayList);
       return;
     }
     if (n == 6) {
       dataMap.putIntegerArrayList(string, arrayList);
       return;
     }
     throw new IllegalStateException("Unexpected typeOfArrayList: " + n);
   }
   throw new RuntimeException("populateBundle: unexpected type " + n);
 }
    @Override
    protected Void doInBackground(Void... params) {
      Dexcom dexcom = new Dexcom();

      try {
        String token =
            dexcom.login(
                PreferenceManager.getDefaultSharedPreferences(context).getString("username", ""),
                PreferenceManager.getDefaultSharedPreferences(context).getString("password", ""));
        if (token != null && token.length() > 0 && token.startsWith("\"")) {
          token = token.substring(1, token.length() - 2); // Strip the "s
          SharedPreferences.Editor editor =
              PreferenceManager.getDefaultSharedPreferences(context).edit();
          editor.putString("token", token);
          editor.apply();
          JSONArray a = dexcom.latestGlucoseValues(token, 1440, 1);
          if (a != null && a.length() > 0) {
            JSONObject o = a.getJSONObject(0);
            final int trend = o.getInt("Trend");
            final int value = o.getInt("Value");
            String WT = o.getString("WT");
            final long time = Long.valueOf(WT.substring(6, WT.length() - 2));
            Log.i("DexcomShareDashclock", "Latest glucose reading: " + value + " mg/dL");

            editor.putInt("Trend", trend);
            editor.putInt("Value", value);
            editor.putLong("Time", time);
            editor.apply();

            final GoogleApiClient googleApiClient =
                new GoogleApiClient.Builder(context).addApi(Wearable.API).build();

            ConnectionResult connectionResult =
                googleApiClient.blockingConnect(30, TimeUnit.SECONDS);

            if (!connectionResult.isSuccess()) {
              Log.e("DexcomShareDashclock", "Failed to connect to GoogleApiClient.");
              return null;
            }

            DataMap map = new DataMap();
            map.putInt("trend", trend);
            map.putInt("value", value);
            map.putLong("time", time);

            NodeApi.GetConnectedNodesResult nodes =
                Wearable.NodeApi.getConnectedNodes(googleApiClient).await();
            for (Node node : nodes.getNodes()) {
              Wearable.MessageApi.sendMessage(
                      googleApiClient, node.getId(), "/latest_glucose", map.toByteArray())
                  .await();
            }

            googleApiClient.disconnect();
          }
        } else {
          Log.e("Dexcom", "Response: " + token);
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
      return null;
    }