/** * Formats an instruction string, updates it on the screen, and passes it to the parent activity * to be spoken. * * @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...) */ protected void addInstruction(int resId, boolean repeat, Object... formatArgs) { final String text = mParentTutorial.getString(resId, formatArgs); mInstructions.setVisibility(View.VISIBLE); mInstructions.setText(text); mParentTutorial.speakInstruction(resId, repeat, formatArgs); }
/** * 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); }
@Override public void onClick(View v) { if (v.getId() == R.id.skip_button) { mParentTutorial.finish(); } else if (v.getId() == R.id.back_button) { mParentTutorial.previous(); } else if (v.getId() == R.id.next_button) { mParentTutorial.next(); } else if (v.getId() == R.id.finish_button) { mParentTutorial.finish(); } }
/** * Constructs a new tutorial module for the given tutorial activity context with the specified * layout and title. * * @param parentTutorial The tutorial activity containing this module. * @param layoutResId The resource identifier for this module's layout. * @param titleResId The resource identifier for this module's title string. */ public TutorialModule( AccessibilityTutorialActivity parentTutorial, int layoutResId, int titleResId) { super(parentTutorial); mParentTutorial = parentTutorial; mTitleResId = titleResId; final LayoutInflater inflater = mParentTutorial.getLayoutInflater(); final View container = inflater.inflate(R.layout.tutorial_container, this, true); mInstructions = (TextView) container.findViewById(R.id.instructions); mSkip = (Button) container.findViewById(R.id.skip_button); mSkip.setOnClickListener(this); mBack = (Button) container.findViewById(R.id.back_button); mBack.setOnClickListener(this); mNext = (Button) container.findViewById(R.id.next_button); mNext.setOnClickListener(this); mFinish = (Button) container.findViewById(R.id.finish_button); mFinish.setOnClickListener(this); final TextView title = (TextView) container.findViewById(R.id.title); if (title != null) { title.setText(titleResId); } if (layoutResId != -1) { final ViewGroup contentHolder = (ViewGroup) container.findViewById(R.id.content); // Inflate the tutorial module content while dropping certain accessibility events contentHolder.setAccessibilityDelegate(mDropEventsDelegate); inflater.inflate(layoutResId, contentHolder, true); contentHolder.setAccessibilityDelegate(null); } }
@Override public void handleMessage(Message msg, AccessibilityTutorialActivity parent) { switch (msg.what) { case MSG_REPEAT: parent.repeatInstruction(); break; } }
/** * Determines the shortcut gesture direction for performing the given action based on user * preferences, raising an alert and exiting the tutorial if there is no corresponding gesture. * * @param action The action for which to find a gesture direction. * @return A resource ID of the user-facing String describing the direction of a swipe gesture * corresponding to the requested action. If multiple gestures correspond to the action, only * one of them will be returned. If there is no gesture for the action, a negative value will * be returned. */ protected int getGestureDirectionForRequiredAction(ShortcutGestureAction action) { final AccessibilityTutorialActivity parentActivity = getParentTutorial(); final int direction = GesturePreferenceUtils.getDirectionForAction(parentActivity, action); if (direction < 0) { parentActivity.stopRepeating(); final String title = parentActivity.getString(R.string.accessibility_tutorial_missing_assignment_title); final String actionLabel = action.getLabel(parentActivity); final String message = parentActivity.getString( R.string.accessibility_tutorial_missing_assignment_message, actionLabel); parentActivity.showAlertDialogAndFinish(title, message); } return direction; }
/** * Called when the tutorial module is shown in its initial state. * * <p>Any overriding methods should call {@code super.onStart()}. */ public void onStart() { mInstructions.setVisibility(View.GONE); mParentTutorial.setTitle(mTitleResId); }
/** * Runs the given trigger after a delay, giving the user immediate auditory feedback that a * trigger occurred. * * @param trigger The trigger that should be run after the delay. */ protected void installTriggerDelayedWithFeedback(Runnable trigger) { installTriggerDelayed(trigger); mParentTutorial.playTriggerSound(); }