예제 #1
0
  public static void startLocalActivity(
      final ActivityGroup activityGroup,
      final Intent intent,
      final String identifier,
      final int regionId,
      final int anim) {
    final LocalActivityManager activityManager = activityGroup.getLocalActivityManager();
    final View paneView = activityManager.startActivity(identifier, intent).getDecorView();

    final ViewParent parent = paneView.getParent();
    if ((parent != null) && (parent instanceof ViewGroup)) {
      throw new IllegalStateException("should not happen - currently we don't recycle activities");
    }

    final ViewGroup region = (ViewGroup) activityGroup.findViewById(regionId);
    if ((anim != ANIM_NONE) && (region instanceof ViewSwitcher)) {
      final ViewSwitcher animator = (ViewSwitcher) region;

      if (anim == ANIM_NEXT) {
        animator.setInAnimation(activityGroup, R.anim.sl_next_in);
        animator.setOutAnimation(activityGroup, R.anim.sl_next_out);
      } else {
        animator.setInAnimation(activityGroup, R.anim.sl_previous_in);
        animator.setOutAnimation(activityGroup, R.anim.sl_previous_out);
      }

      final int numChilds = animator.getChildCount();
      if (numChilds == 0) {
        animator.addView(
            paneView,
            0,
            new ViewGroup.LayoutParams(
                ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
      } else if (numChilds == 1) {
        animator.addView(
            paneView,
            1,
            new ViewGroup.LayoutParams(
                ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
        animator.showNext();
      } else {
        animator.removeViewAt(0);
        animator.addView(
            paneView,
            1,
            new ViewGroup.LayoutParams(
                ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
        animator.showNext();
      }
    } else {
      region.removeAllViews();
      region.addView(
          paneView,
          new ViewGroup.LayoutParams(
              ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
    }
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_action);

    // Set the action to null, this indicates that it has not been fetched
    mAction = null;

    // Fetch UI components
    RelativeLayout circleView = (RelativeLayout) findViewById(R.id.action_circle_view);
    mActionImage = (ImageView) findViewById(R.id.action_image);
    mActionTitle = (TextView) findViewById(R.id.action_title);
    mActionDescription = (TextView) findViewById(R.id.action_description);
    mExternalResourceHeader = (TextView) findViewById(R.id.action_external_resource_header);
    mExternalResource = (TextView) findViewById(R.id.action_external_resource);
    mMoreInfoHeader = (TextView) findViewById(R.id.action_more_info_header);
    mMoreInfo = (TextView) findViewById(R.id.action_more_info);
    mTickSwitcher = (ViewSwitcher) findViewById(R.id.action_tick_switcher);

    // Animate the switcher.
    mTickSwitcher.setInAnimation(this, R.anim.action_switcher_fade_in);
    mTickSwitcher.setOutAnimation(this, R.anim.action_switcher_fade_out);

    // Listeners
    findViewById(R.id.action_later).setOnClickListener(this);
    findViewById(R.id.action_did_it).setOnClickListener(this);

    // Circle view
    GradientDrawable gradientDrawable = (GradientDrawable) circleView.getBackground();
    gradientDrawable.setColor(Color.WHITE);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
      circleView.setBackground(gradientDrawable);
    } else {
      circleView.setBackgroundDrawable(gradientDrawable);
    }

    mActionComplete = false;

    fetchAction(getIntent().getIntExtra(ACTION_ID_KEY, -1));
  }
예제 #3
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {
    ViewPager viewPager = (ViewPager) container;

    final ViewSwitcher viewSwitcher = new ViewSwitcher(container.getContext());

    questionView =
        new QuestionView(container.getContext(), stepInfo, viewPager) {

          @Override
          protected void onCorrectAnswer() {
            stepInfo.setRevealed(true);
            viewSwitcher.showNext();
          }

          protected void onIncorrectAnswer() {
            stepInfo.setRevealed(true);
            stepInfo.setMistake(true);
            knotStepView.hideAnswer();
            viewSwitcher.showNext();
          }
        };

    knotStepView = new KnotStepView(container.getContext(), stepInfo, viewPager);

    viewSwitcher.addView(questionView);
    viewSwitcher.addView(knotStepView);

    viewSwitcher.setInAnimation(container.getContext(), android.R.anim.fade_in);
    viewSwitcher.setOutAnimation(container.getContext(), android.R.anim.fade_out);

    if (stepInfo.isRevealed()) {
      viewSwitcher.showNext();
    }

    return viewSwitcher;
  }