コード例 #1
0
  private void refresh() {
    partsArrayList.clear();
    if (((Alexandra) getApplicationContext()).getHome() != null) {
      partsArrayList.clear();
      partsArrayList.add(((Alexandra) getApplicationContext()).getHome().getName());
      partsArrayList.add("GADGETS:");
      for (Gadget gadget : ((Alexandra) getApplicationContext()).getHome().getGadgets()) {
        Log.i(TAG, gadget.getName());

        partsArrayList.add(gadget.getName() + " stan: " + gadget.getState().toString());
      }
      partsArrayList.add("ROOMS:");
      for (Room room : ((Alexandra) getApplicationContext()).getHome().getRooms()) {
        partsArrayList.add(room.getName());
      }
      partsArrayList.add("SCENES:");
      for (Scene scene : ((Alexandra) getApplicationContext()).getHome().getScenes()) {
        partsArrayList.add(scene.getName());
      }
      partsArrayList.add("SCHEDULES:");
      for (ScheduledScene schedule :
          ((Alexandra) getApplicationContext()).getHome().getSchedule()) {
        partsArrayList.add(
            schedule.getScene() + " -> " + schedule.getHour() + ":" + schedule.getMinutes());
      }
    }
    adapter.notifyDataSetChanged();
  }
コード例 #2
0
        @Override
        public void onLeScan(BluetoothDevice bluetoothDevice, int i, byte[] bytes) {
          Log.d(TAG, "discovered device: " + bluetoothDevice.getName());
          Log.d(TAG, "device MAC: " + bluetoothDevice.getAddress());
          Home home = ((Alexandra) getApplicationContext()).getHome();
          if (home != null) {
            for (Gadget gadget : home.getGadgets()) {
              Log.d(TAG, "gadget MAC: " + gadget.getMAC());

              if (gadget.getMAC().equals(bluetoothDevice.getAddress())) {
                Log.d(TAG, "trying to connect GATT");
                gadget.setBluetoothGatt(
                    bluetoothDevice.connectGatt(
                        getApplicationContext(), true, gadget.getBluetoothGattCallback()));
              }
            }
          }
        }