Esempio n. 1
0
  /**
   * Runs the given trigger after a delay.
   *
   * <p>Assumes that the resulting trigger will add an instruction, thus lowering the touch guard
   * when the instruction speech output finishes.
   *
   * @param trigger The trigger that should be run after the delay.
   */
  protected void installTriggerDelayed(Runnable trigger) {
    // Stop repeating any previous instruction between when the touch guard
    // raises and when the next instruction is spoken.
    mParentTutorial.stopRepeating();

    mParentTutorial.setTouchGuardActive(true);
    mParentTutorial.lockOrientation();
    mHandler.postDelayed(trigger, TRIGGER_DELAY);
  }
  /**
   * Speaks the previously stored instruction text again.
   *
   * <p>Assumes that {@code mTextToRepeat} is non-null.
   */
  private void repeatInstruction() {
    if (!sTutorialIsActive) {
      mRepeatHandler.removeMessages(RepeatHandler.MSG_REPEAT);
      return;
    }

    lockOrientation();
    setTouchGuardActive(true);

    speakInternal(mResourceIdToRepeat, mRepeatedFormatArgs);
  }
  /**
   * Speaks a new tutorial instruction.
   *
   * @param resId The resource value of the instruction string.
   * @param repeat Whether the instruction should be repeated indefinitely.
   * @param formatArgs Optional formatting arguments.
   * @see String#format(String, Object...)
   */
  public void speakInstruction(int resId, boolean repeat, Object... formatArgs) {
    stopRepeating();

    lockOrientation();
    setTouchGuardActive(true);

    speakInternal(resId, formatArgs);

    if (repeat) {
      mResourceIdToRepeat = resId;
      mRepeatedFormatArgs = formatArgs;
    } else {
      mResourceIdToRepeat = 0;
    }
  }
  @SuppressWarnings("deprecation")
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mSavedInstanceState = savedInstanceState;

    final Animation inAnimation = AnimationUtils.loadAnimation(this, android.R.anim.slide_in_left);
    inAnimation.setAnimationListener(mInAnimationListener);

    final Animation outAnimation = AnimationUtils.loadAnimation(this, android.R.anim.slide_in_left);

    mRepeatHandler = new RepeatHandler(this);

    mFeedbackController = new FeedbackController(this);

    mViewAnimator = new ViewAnimator(this);
    mViewAnimator.setInAnimation(inAnimation);
    mViewAnimator.setOutAnimation(outAnimation);
    mViewAnimator.addView(new TouchTutorialModule1(this));
    mViewAnimator.addView(new TouchTutorialModule2(this));
    mViewAnimator.addView(new TouchTutorialModule3(this));
    mViewAnimator.addView(new TouchTutorialModule4(this));

    // Module 5 (text editing) requires JellyBean MR2 (API 18) features.
    if (Build.VERSION.SDK_INT >= TouchTutorialModule5.MIN_API_LEVEL) {
      mViewAnimator.addView(new TouchTutorialModule5(this));
    }

    // Ensure the screen stays on and doesn't change orientation.
    final Window window = getWindow();
    final WindowManager.LayoutParams params = window.getAttributes();
    params.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
    params.flags |= WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
    window.setAttributes(params);

    setContentView(mViewAnimator);

    mAccessibilityManager = (AccessibilityManager) getSystemService(ACCESSIBILITY_SERVICE);

    // Lock the screen orientation until the first instruction is read.
    lockOrientation();

    mFirstTimeResume = true;
  }