示例#1
0
  // --------------------------------------------------------------------------------------------------------------------------
  private void showBeans() {
    // Read all the beans from the channel
    MobileBean[] beans = MobileBean.readAll("cloud_channel");
    if (MobileBean.isBooted("cloud_channel")) {
      // Populate the List View
      ListView view = (ListView) findViewById(R.id.list);

      // Prepare the data for the adapter. Data is read from the ticket bean instances
      ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
      if (beans != null && beans.length > 0) {
        for (MobileBean local : beans) {
          HashMap<String, String> map = new HashMap<String, String>();

          String name = local.getValue("name");
          String value = local.getValue("value");

          if (name.length() > 25) {
            name = name.substring(0, 22) + "...";
          }

          if (value.length() > 25) {
            value = value.substring(0, 22) + "...";
          }

          map.put("name", name);
          map.put("value", value);
          mylist.add(map);
        }
      }

      SimpleAdapter beanAdapter =
          new SimpleAdapter(
              this,
              mylist,
              R.layout.bean_row,
              new String[] {"name", "value"},
              new int[] {R.id.name, R.id.value});
      view.setAdapter(beanAdapter);

      // List Listener...used to respond to selecting a ticket instance
      OnItemClickListener clickListener = new ClickListener(beans);
      view.setOnItemClickListener(clickListener);
    } else {
      // Tickets not found...put up a Sync in progress message and wait for data to be downloaded
      // from the Backend
      if (!HomeScreen.syncInProgress && !HomeScreen.syncComplete) {
        HomeScreen.syncInProgress = true;
        SyncInProgressAsyncTask task = new SyncInProgressAsyncTask();
        task.execute();
      }
    }
  }
示例#2
0
  public void runTest() {
    try {
      this.startBootSync();
      this.waitForBeans();

      MobileBean instance1 = MobileBean.readById(this.service, "unique-1");
      assertTrue(instance1.isInitialized(), this.getInfo() + "://Bean_must_be_initialized");

      instance1.delete();

      instance1 = MobileBean.readById(this.service, "unique-1");
      assertNull(instance1, this.getInfo() + "://Bean_must_not_be_found");
    } catch (Exception e) {
      e.printStackTrace(System.out);
      throw new RuntimeException(e.toString());
    }
  }
示例#3
0
  @Override
  protected Void doInBackground(Void... arg0) {
    message = handler.obtainMessage();
    try {
      mobileBean.save();
      message.what = 1;
    } catch (Exception ex) {

    }
    return null;
  }
 public void doAction(CommandContext commandContext) {
   try {
     int counter = 5;
     while (!MobileBean.isBooted(Constants.channel)) {
       Thread.currentThread().sleep(1000);
       if (counter-- == 0) {
         throw new RuntimeException();
       }
     }
   } catch (Exception e) {
     throw new AppException();
   }
 }
示例#5
0
    @Override
    protected String doInBackground(Void... arg0) {
      try {
        // Check if the CRM Ticket channel has data to be read
        boolean isBooted = MobileBean.isBooted("cloud_channel");
        int counter = 20;
        while (!isBooted) {
          Thread.sleep(2000);

          if (counter > 0) {
            isBooted = MobileBean.isBooted("cloud_channel");
            counter--;
          } else {
            break;
          }
        }

        return "" + isBooted;
      } catch (Exception e) {
        return "failure";
      }
    }
示例#6
0
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

      // Get the ticket bean selected by the user
      int selectedIndex = position;
      final MobileBean selectedBean = activeBeans[selectedIndex];

      String name = selectedBean.getValue("name");
      String value = selectedBean.getValue("value");

      AlertDialog.Builder builder = new AlertDialog.Builder(HomeScreen.this).setCancelable(false);
      View dialogView = LayoutInflater.from(HomeScreen.this).inflate(R.layout.dialog, null);

      // Setup the Name Value
      int nameEditPointer = R.id.nameEdit;
      final EditText nameEdit = (EditText) dialogView.findViewById(nameEditPointer);
      nameEdit.setText(name);

      // Setup the Value Value
      int valueEditPointer = R.id.valueEdit;
      final EditText valueEdit = (EditText) dialogView.findViewById(valueEditPointer);
      valueEdit.setText(value);

      // Setup the buttons on the dialog box
      builder.setPositiveButton(
          "Update",
          new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
              String name = nameEdit.getText().toString();
              String value = valueEdit.getText().toString();

              if (name == null || name.trim().length() == 0) {
                Toast.makeText(HomeScreen.this, "'Name' is required", 1).show();
                return;
              }
              if (value == null || value.trim().length() == 0) {
                Toast.makeText(HomeScreen.this, "'Value' is required", 1).show();
                return;
              }

              selectedBean.setValue("name", name);
              selectedBean.setValue("value", value);
              try {
                selectedBean.save();
              } catch (CommitException se) {
                try {
                  selectedBean.refresh();
                  selectedBean.setValue("name", name);
                  selectedBean.setValue("value", value);
                  selectedBean.save();
                } catch (Exception e) {
                  // we tried, put up an error message
                  Toast.makeText(HomeScreen.this, "Error", 1).show();
                }
              }

              showBeans();
            }
          });

      builder.setNegativeButton(
          "Delete",
          new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
              try {
                selectedBean.delete();
              } catch (CommitException se) {
                Toast.makeText(HomeScreen.this, "Error : " + se.getMessage(), 1).show();
                return;
              }
              showBeans();
            }
          });

      builder.setNeutralButton(
          "Cancel",
          new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
              showBeans();
            }
          });

      AlertDialog beanDialog = builder.create();
      beanDialog.setView(dialogView);
      beanDialog.show();
    }