public void execute(BaseActivity activity) throws InterruptedException {
    YADroneApplication app = (YADroneApplication) activity.getApplication();
    ARDrone drone = app.getARDrone();

    final CommandManager cm = drone.getCommandManager();
    final NavDataManager nm = drone.getNavDataManager();

    if (mSound.length() > 0) {
      int resId = activity.getResources().getIdentifier(mSound, "raw", activity.getPackageName());
      if (resId != 0) {
        activity.setVolumeControlStream(AudioManager.STREAM_MUSIC);
        activity.soundPlayer.loadAndPlaySound(resId);
      }
    }
    int repetitions = mRepetitions > 0 ? mRepetitions : 1;
    for (int i = 0; i < repetitions; i++) {
      Log.d("FlyRoute", mCommand.toString());

      nm.setStateListener(
          new StateListener() {
            private boolean done = false;

            @Override
            public synchronized void stateChanged(DroneState state) {
              if (!done && state.isEmergency()) {
                cm.emergency();
              }
              nm.setStateListener(null);
              done = true;
            }

            @Override
            public void controlStateChanged(ControlState state) {
              // ignore
            }
          });

      cm.setCommand(mCommand);
      Thread.sleep(mDuration / repetitions);
    }
  }
示例#2
0
  public TOCDlg(BaseActivity coolReader, ReaderView readerView, TOCItem toc, int currentPage) {
    super(coolReader, coolReader.getResources().getString(R.string.win_title_toc), false, false);
    setCancelable(true);
    //		this.mCoolReader = coolReader;
    this.mReaderView = readerView;
    this.mTOC = toc;
    this.mCurrentPage = currentPage;
    this.mListView = new BaseListView(getContext(), true);
    mListView.setOnItemClickListener(
        new OnItemClickListener() {

          @Override
          public void onItemClick(AdapterView<?> listview, View view, int position, long id) {
            TOCItem item = mItems.get(position);
            if (item.getChildCount() == 0 || item.getExpanded()) {
              mReaderView.goToPage(item.getPage() + 1);
              dismiss();
            } else {
              expand(item);
            }
          }
        });
    mListView.setOnItemLongClickListener(
        new OnItemLongClickListener() {

          @Override
          public boolean onItemLongClick(
              AdapterView<?> listview, View view, int position, long id) {
            TOCItem item = mItems.get(position);
            if (item.getChildCount() == 0) {
              mReaderView.goToPage(item.getPage() + 1);
              dismiss();
            } else {
              if (item.getExpanded()) collapse(item);
              else expand(item);
            }
            return true;
          }
        });
    mListView.setLongClickable(true);
    mListView.setClickable(true);
    mListView.setFocusable(true);
    mListView.setFocusableInTouchMode(true);
    mListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    setView(mListView);
    setFlingHandlers(
        mListView,
        new Runnable() {
          @Override
          public void run() {
            // cancel
            TOCDlg.this.dismiss();
          }
        },
        new Runnable() {
          @Override
          public void run() {
            //
            TOCDlg.this.dismiss();
          }
        });
  }