コード例 #1
0
  @Override
  public Dialog onCreateDialog(int i) {

    WPEntry entry = entries.get(i);

    Dialog dialog = new Dialog(this);
    //		dialog.setOwnerActivity(this);

    dialog.setContentView(R.layout.entry_dialog);
    dialog.setTitle(entry.getSportInt());

    TextView dateView = (TextView) dialog.findViewById(R.id.date);
    dateView.setText(entry.date.toString()); // TODO: Formatieren

    TextView durationView = (TextView) dialog.findViewById(R.id.duration);
    durationView.setText("Dauer: " + entry.duration + " min");

    TextView pointsView = (TextView) dialog.findViewById(R.id.points);
    pointsView.setText(entry.getPoints() + " Punkte");

    TextView notesView = (TextView) dialog.findViewById(R.id.notes);
    notesView.setText(entry.notes);

    return dialog;
  }
コード例 #2
0
 // Device constructor. Automatically call the YAPI functin to reindex device
 YDevice(YGenericHub hub, WPEntry wpRec, HashMap<String, ArrayList<YPEntry>> ypRecs)
     throws YAPI_Exception {
   // private attributes
   _hub = hub;
   _wpRec = wpRec;
   _cache_expiration = 0;
   _cache_json = "";
   _moduleYPEntry = new YPEntry(wpRec.getSerialNumber(), "module", YPEntry.BaseClass.Function);
   _moduleYPEntry.setLogicalName(wpRec.getLogicalName());
   _ypRecs = new HashMap<Integer, YPEntry>();
   Set<String> keySet = ypRecs.keySet();
   for (String categ : keySet) {
     for (YPEntry rec : ypRecs.get(categ)) {
       if (rec.getSerial().equals(wpRec.getSerialNumber())) {
         int funydx = rec.getIndex();
         _ypRecs.put(funydx, rec);
       }
     }
   }
 }
コード例 #3
0
 private String formatRequest(String request) throws YAPI_Exception {
   String[] words = request.split(" ");
   if (words.length < 2) {
     throw new YAPI_Exception(
         YAPI.INVALID_ARGUMENT,
         "Invalid request, not enough words; expected a method name and a URL");
   }
   String relativeUrl = words[1];
   if (relativeUrl.charAt(0) != '/') {
     relativeUrl = "/" + relativeUrl;
   }
   return String.format("%s %s%s", words[0], _wpRec.getNetworkUrl(), relativeUrl);
 }
コード例 #4
0
  // Reload a device API (store in cache), and update YAPI function lists accordingly
  // Intended to be called within UpdateDeviceList only
  public int refresh() throws YAPI_Exception {
    String result = this.requestAPI();
    JSONObject loadval;
    Boolean reindex = false;
    try {
      loadval = new JSONObject(result);

      _cache_expiration = YAPI.GetTickCount() + YAPI.DefaultCacheValidity;
      _cache_json = result;

      // parse module and refresh names if needed
      Iterator<?> keys = loadval.keys();
      while (keys.hasNext()) {
        String key = (String) keys.next();
        if (key.equals("module")) {
          JSONObject module = loadval.getJSONObject("module");
          if (!_wpRec.getLogicalName().equals(module.getString("logicalName"))) {
            _wpRec.setLogicalName(module.getString("logicalName"));
            _moduleYPEntry.setLogicalName(_wpRec.getLogicalName());
            reindex = true;
          }
          _wpRec.setBeacon(module.getInt("beacon"));
        } else if (!key.equals("services")) {
          JSONObject func = loadval.getJSONObject(key);
          String name;
          if (func.has("logicalName")) {
            name = func.getString("logicalName");
          } else {
            name = _wpRec.getLogicalName();
          }
          if (func.has("advertisedValue")) {
            String pubval = func.getString("advertisedValue");
            SafeYAPI()._yHash.setFunctionValue(_wpRec.getSerialNumber(), pubval);
          }
          for (int f = 0; f < _ypRecs.size(); f++) {
            if (_ypRecs.get(f).getFuncId().equals(key)) {
              if (!_ypRecs.get(f).getLogicalName().equals(name)) {
                _ypRecs.get(f).setLogicalName(name);
                reindex = true;
              }
              break;
            }
          }
        }
      }
    } catch (JSONException e) {
      throw new YAPI_Exception(YAPI.IO_ERROR, "Request failed, could not parse API result");
    }

    if (reindex) {
      SafeYAPI()._yHash.reindexDevice(this);
    }
    return YAPI.SUCCESS;
  }
コード例 #5
0
public class UserStatsActivity extends ListActivity {

  // TODO: Diese Variablen muessen natuerlich mit den ausgelesenen Werten belegt werden.
  String userName = "******";
  String teamName = "Heinzelmaennchen";
  int nEntries = 10;
  int minutes = 876;
  int points = 123;
  int rank = 74;

  ArrayList<WPEntry> entries = WPEntry.createTestEntries();

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    ListAdapter adapter = new ArrayAdapter<WPEntry>(this, R.layout.list_item, entries);

    ListView lv = getListView();
    lv.setTextFilterEnabled(true);

    TextView header = new TextView(this);
    header.setText(
        userName
            + " ist Mitglied im Team "
            + teamName
            + ".\n"
            + userName
            + " hat "
            + " Einheiten mit einer Gesamtdauer von "
            + minutes
            + " Minuten eingetragen.\n"
            + "Diese Einträge sind insgesamt "
            + points
            + " Punkte wert.\n"
            + userName
            + " befindet sich damit momentan auf dem "
            + rank
            + ". Platz des Gesamtrankings.");
    lv.addHeaderView(header);
    setListAdapter(adapter);
    lv.setOnItemClickListener(
        new OnItemClickListener() {

          @Override
          public void onItemClick(AdapterView<?> parent, View view, int pos, long id) {
            // Dialog mit den Details eines Eintrages anzeigen
            // Achtung: pos geht hier nicht bei 0 los, liegt das an dem header?
            showDialog(pos - 1);
          }
        });
    //        innerContainer.addView(textview);
    //        innerContainer.addView(createList(WPEntry.createTestEntries()));
    //        setContentView(innerContainer);
  }

  //	private ListView createList(ArrayList<WPEntry> entries) {
  //		ListAdapter adapter = new ArrayAdapter<WPEntry>(this, R.layout.list_item, entries);
  //		ListView listView = new ListView(this);
  //		listView.setAdapter(adapter);
  //		return listView;
  //	}

  @Override
  public Dialog onCreateDialog(int i) {

    WPEntry entry = entries.get(i);

    Dialog dialog = new Dialog(this);
    //		dialog.setOwnerActivity(this);

    dialog.setContentView(R.layout.entry_dialog);
    dialog.setTitle(entry.getSportInt());

    TextView dateView = (TextView) dialog.findViewById(R.id.date);
    dateView.setText(entry.date.toString()); // TODO: Formatieren

    TextView durationView = (TextView) dialog.findViewById(R.id.duration);
    durationView.setText("Dauer: " + entry.duration + " min");

    TextView pointsView = (TextView) dialog.findViewById(R.id.points);
    pointsView.setText(entry.getPoints() + " Punkte");

    TextView notesView = (TextView) dialog.findViewById(R.id.notes);
    notesView.setText(entry.notes);

    return dialog;
  }
}
コード例 #6
0
 // Return the serial number of the device, as found during discovery
 public String getSerialNumber() {
   return _wpRec.getSerialNumber();
 }
コード例 #7
0
 // Return the beacon state of the device, as found during discovery
 public int getBeacon() {
   return _wpRec.getBeacon();
 }
コード例 #8
0
 String getRelativePath() {
   return _wpRec.getNetworkUrl();
 }
コード例 #9
0
 // Return the product Id of the device, as found during discovery
 public int getProductId() {
   return _wpRec.getProductId();
 }
コード例 #10
0
 // Return the product name of the device, as found during discovery
 public String getProductName() {
   return _wpRec.getProductName();
 }
コード例 #11
0
 // Return the logical name of the device, as found during discovery
 public String getLogicalName() {
   return _wpRec.getLogicalName();
 }