示例#1
1
 /**
  * Launch activity using custom animations. Uses ActivityOptions if on JellyBean, otherwise
  * overrides transition
  *
  * @param parent parent activity
  * @param intent intent to launch
  * @param animIn In animation
  * @param animOut Out animation
  */
 public static void launchActivity(Activity parent, Intent intent, int animIn, int animOut) {
   if (isJellyBean())
     parent.startActivity(
         intent, ActivityOptions.makeCustomAnimation(parent, animIn, animOut).toBundle());
   else {
     parent.startActivity(intent);
     parent.overridePendingTransition(animIn, animOut);
   }
 }
示例#2
0
  @SuppressLint("NewApi")
  private void initialiseTabHost() {
    mTabHost.setup();

    // TODO Put here your Tabs
    AddTab(
        getActivity(),
        mTabHost,
        mTabHost.newTabSpec("All Categories").setIndicator("All Categories"));
    try {
      for (int i = 0; i < categories.size(); i++) {
        final CategoriesBean lb = categories.get(i);

        category_id.add(lb.categoryId);
        AddTab(
            getActivity(),
            mTabHost,
            mTabHost.newTabSpec(lb.categoryName).setIndicator(lb.categoryName));
      }
    } catch (Exception e) {
      e.printStackTrace();
      Intent intent = new Intent(new Intent(getActivity(), SplashActivity.class));

      if (Build.VERSION.SDK_INT > 11) {
        Bundle bundle =
            ActivityOptions.makeCustomAnimation(
                    getActivity(), R.anim.trans_left_in, R.anim.trans_left_out)
                .toBundle();
        getActivity().startActivity(intent, bundle);
      } else {
        startActivity(intent);
      }
    }
    mTabHost.setOnTabChangedListener(this);
  }
示例#3
0
  @SuppressLint("NewApi")
  private List<Fragment> getFragments() {
    List<Fragment> fList = new ArrayList<Fragment>();

    AllEventsFragment f1 = AllEventsFragment.newInstance("");
    fList.add(f1);
    try {
      for (int i = 0; i < categories.size(); i++) {
        final CategoriesBean lb = categories.get(i);

        ArtTheatreFragment categoryName = ArtTheatreFragment.newInstance("" + lb.categoryId);
        fList.add(categoryName);
      }
    } catch (Exception e) {
      e.printStackTrace();
      Intent intent = new Intent(new Intent(getActivity(), SplashActivity.class));

      if (Build.VERSION.SDK_INT > 11) {
        Bundle bundle =
            ActivityOptions.makeCustomAnimation(
                    getActivity(), R.anim.trans_left_in, R.anim.trans_left_out)
                .toBundle();
        getActivity().startActivity(intent, bundle);
      } else {
        startActivity(intent);
      }
    }
    return fList;
  }
 /** Creates the activity options for a home->recents transition. */
 ActivityOptions getHomeTransitionActivityOptions(boolean fromSearchHome) {
   mStartAnimationTriggered = false;
   if (fromSearchHome) {
     return ActivityOptions.makeCustomAnimation(
         mContext,
         R.anim.recents_from_search_launcher_enter,
         R.anim.recents_from_search_launcher_exit,
         mHandler,
         this);
   }
   return ActivityOptions.makeCustomAnimation(
       mContext,
       R.anim.recents_from_launcher_enter,
       R.anim.recents_from_launcher_exit,
       mHandler,
       this);
 }
 /** Creates the activity options for a unknown state->recents transition. */
 ActivityOptions getUnknownTransitionActivityOptions() {
   mStartAnimationTriggered = false;
   return ActivityOptions.makeCustomAnimation(
       mContext,
       R.anim.recents_from_unknown_enter,
       R.anim.recents_from_unknown_exit,
       mHandler,
       this);
 }
  /**
   * Launches the said intent for the current foreground user.
   *
   * @param intent
   * @param showsWhileLocked true if the activity can be run on top of keyguard. See {@link
   *     WindowManager#FLAG_SHOW_WHEN_LOCKED}
   * @param useDefaultAnimations true if default transitions should be used, else suppressed.
   * @param worker if supplied along with onStarted, used to launch the blocking activity call.
   * @param onStarted if supplied along with worker, called after activity is started.
   */
  public void launchActivity(
      final Intent intent,
      boolean showsWhileLocked,
      boolean useDefaultAnimations,
      final Handler worker,
      final Runnable onStarted) {

    final Context context = getContext();
    final Bundle animation =
        useDefaultAnimations ? null : ActivityOptions.makeCustomAnimation(context, 0, 0).toBundle();
    launchActivityWithAnimation(intent, showsWhileLocked, animation, worker, onStarted);
  }
  @Test
  public void shouldUseAnimationOverride() {
    Activity activity = buildActivity(Activity.class).create().get();
    Intent intent = new Intent(activity, OptionsMenuActivity.class);

    Bundle animationBundle =
        ActivityOptions.makeCustomAnimation(activity, R.anim.test_anim_1, R.anim.test_anim_1)
            .toBundle();
    activity.startActivity(intent, animationBundle);
    assertThat(shadowOf(activity).getNextStartedActivityForResult().options)
        .isSameAs(animationBundle);
  }
  private void startAssistActivity(Bundle args) {
    if (!mBar.isDeviceProvisioned()) {
      return;
    }

    // Close Recent Apps if needed
    mBar.animateCollapsePanels(
        CommandQueue.FLAG_EXCLUDE_SEARCH_PANEL | CommandQueue.FLAG_EXCLUDE_RECENTS_PANEL);

    boolean structureEnabled =
        Settings.Secure.getIntForUser(
                mContext.getContentResolver(),
                Settings.Secure.ASSIST_STRUCTURE_ENABLED,
                1,
                UserHandle.USER_CURRENT)
            != 0;

    final Intent intent =
        ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
            .getAssistIntent(structureEnabled);
    if (intent == null) {
      return;
    }
    if (mAssistComponent != null) {
      intent.setComponent(mAssistComponent);
    }
    intent.putExtras(args);

    if (structureEnabled) {
      showDisclosure();
    }

    try {
      final ActivityOptions opts =
          ActivityOptions.makeCustomAnimation(
              mContext, R.anim.search_launch_enter, R.anim.search_launch_exit);
      intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      AsyncTask.execute(
          new Runnable() {
            @Override
            public void run() {
              mContext.startActivityAsUser(
                  intent, opts.toBundle(), new UserHandle(UserHandle.USER_CURRENT));
            }
          });
    } catch (ActivityNotFoundException e) {
      Log.w(TAG, "Activity not found for " + intent.getAction());
    }
  }
 @Override
 public boolean doPreviousAction() {
   Intent intent = new Intent(ACTION_EMERGENCY_DIAL);
   intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
   ActivityOptions options =
       ActivityOptions.makeCustomAnimation(
           mContext, android.R.anim.fade_in, android.R.anim.fade_out);
   SetupStats.addEvent(SetupStats.Categories.BUTTON_CLICK, SetupStats.Label.EMERGENCY_CALL);
   SetupStats.addEvent(
       SetupStats.Categories.EXTERNAL_PAGE_LOAD,
       SetupStats.Action.EXTERNAL_PAGE_LAUNCH,
       SetupStats.Label.PAGE,
       SetupStats.Label.EMERGENCY_CALL);
   mContext.startActivity(intent, options.toBundle());
   return true;
 }
 private void startAssistActivity() {
   // Close Recent Apps if needed
   mBar.animateCollapse(CommandQueue.FLAG_EXCLUDE_SEARCH_PANEL);
   // Launch Assist
   Intent intent = SearchManager.getAssistIntent(mContext);
   if (intent == null) return;
   try {
     ActivityOptions opts =
         ActivityOptions.makeCustomAnimation(
             mContext, R.anim.search_launch_enter, R.anim.search_launch_exit, getHandler(), this);
     intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
     mContext.startActivity(intent, opts.toBundle());
   } catch (ActivityNotFoundException e) {
     Slog.w(TAG, "Activity not found for " + intent.getAction());
     onAnimationStarted();
   }
 }
 protected void startActivityIfNeed() {
   /** if alarm boot , do not start activity */
   boolean isKeyguardShow = mViewMediatorCallback.isShowingAndNotOccluded();
   boolean isAlarmBoot = AmigoKeyguardUtils.isAlarmBoot();
   boolean isAlarmOrIncallTop = AmigoKeyguardUtils.isAlarmOrInCallActivityTop(mContext);
   if (isKeyguardShow && !isAlarmBoot && !isAlarmOrIncallTop) {
     if (mActivitys.size() == 0) {
       Intent intent = new Intent(mContext, SkylightActivity.class);
       intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
       if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
         Bundle opts = ActivityOptions.makeCustomAnimation(mContext, 0, 0).toBundle();
         mContext.startActivity(intent, opts);
       } else {
         mContext.startActivity(intent);
       }
     }
   }
 }
示例#12
0
 @Override
 public void onBackPressed() {
   // TODO Auto-generated method stub
   Intent i = new Intent(this, ListMembreActivity.class);
   if (tontineId != null) {
     i.putExtra("TONTINE_ID", tontineId);
     if (android.os.Build.VERSION.SDK_INT >= 16) {
       Bundle bndlanimation =
           ActivityOptions.makeCustomAnimation(
                   this, R.anim.anim_right_left, R.anim.anim_left_right)
               .toBundle();
       startActivity(i, bndlanimation);
       finish();
     } else {
       startActivity(i);
       finish();
     }
   } else {
     Toast.makeText(this, "Oups... internet error. please retry!", Toast.LENGTH_LONG).show();
   }
 }
示例#13
0
  private static boolean switchToLastAppInternal(Context context, int userId)
      throws RemoteException {
    ActivityManager.RecentTaskInfo lastTask = getLastTask(context, userId);

    if (lastTask == null || lastTask.id < 0) {
      return false;
    }

    final String packageName = lastTask.baseIntent.getComponent().getPackageName();
    final IActivityManager am = ActivityManagerNative.getDefault();
    final ActivityOptions opts =
        ActivityOptions.makeCustomAnimation(
            context,
            com.android.internal.R.anim.last_app_in,
            com.android.internal.R.anim.last_app_out);

    if (DEBUG) Log.d(TAG, "switching to " + packageName);
    sendCloseSystemWindows(context, null);
    am.moveTaskToFront(lastTask.id, ActivityManager.MOVE_TASK_NO_USER_ACTION, opts.toBundle());

    return true;
  }
        @Override
        public void onDrawerClosed(View drawerView) {
          if (mDrawerToggle != null) mDrawerToggle.onDrawerClosed(drawerView);
          if (mItemToOpenWhenDrawerCloses >= 0) {
            Bundle extras =
                ActivityOptions.makeCustomAnimation(
                        ActionBarCastActivity.this, R.anim.fade_in, R.anim.fade_out)
                    .toBundle();

            Class activityClass = null;
            switch (mItemToOpenWhenDrawerCloses) {
              case R.id.navigation_allmusic:
                activityClass = MusicPlayerActivity.class;
                break;
              case R.id.navigation_playlists:
                activityClass = PlaceholderActivity.class;
                break;
            }
            if (activityClass != null) {
              startActivity(new Intent(ActionBarCastActivity.this, activityClass), extras);
              finish();
            }
          }
        }
 public void fadeAnimation(View view) {
   ActivityOptions opts =
       ActivityOptions.makeCustomAnimation(MainActivity.this, R.anim.fade_in, R.anim.fade_out);
   // Request the activity be started, using the custom animation options.
   startActivity(new Intent(MainActivity.this, AnimationActivity.class), opts.toBundle());
 }
  void showRelativeAffiliatedTask(boolean showNextTask) {
    // Return early if there is no focused stack
    int focusedStackId = mSystemServicesProxy.getFocusedStack();
    TaskStack focusedStack = null;
    RecentsTaskLoader loader = RecentsTaskLoader.getInstance();
    RecentsTaskLoadPlan plan = loader.createLoadPlan(mContext);
    loader.preloadTasks(plan, true /* isTopTaskHome */);
    if (mConfig.multiStackEnabled) {
      if (focusedStackId < 0) return;
      focusedStack = plan.getTaskStack(focusedStackId);
    } else {
      focusedStack = plan.getAllTaskStacks().get(0);
    }

    // Return early if there are no tasks in the focused stack
    if (focusedStack == null || focusedStack.getTaskCount() == 0) return;

    ActivityManager.RunningTaskInfo runningTask = mSystemServicesProxy.getTopMostTask();
    // Return early if there is no running task (can't determine affiliated tasks in this case)
    if (runningTask == null) return;
    // Return early if the running task is in the home stack (optimization)
    if (mSystemServicesProxy.isInHomeStack(runningTask.id)) return;

    // Find the task in the recents list
    ArrayList<Task> tasks = focusedStack.getTasks();
    Task toTask = null;
    ActivityOptions launchOpts = null;
    int taskCount = tasks.size();
    int numAffiliatedTasks = 0;
    for (int i = 0; i < taskCount; i++) {
      Task task = tasks.get(i);
      if (task.key.id == runningTask.id) {
        TaskGrouping group = task.group;
        Task.TaskKey toTaskKey;
        if (showNextTask) {
          toTaskKey = group.getNextTaskInGroup(task);
          launchOpts =
              ActivityOptions.makeCustomAnimation(
                  mContext,
                  R.anim.recents_launch_next_affiliated_task_target,
                  R.anim.recents_launch_next_affiliated_task_source);
        } else {
          toTaskKey = group.getPrevTaskInGroup(task);
          launchOpts =
              ActivityOptions.makeCustomAnimation(
                  mContext,
                  R.anim.recents_launch_prev_affiliated_task_target,
                  R.anim.recents_launch_prev_affiliated_task_source);
        }
        if (toTaskKey != null) {
          toTask = focusedStack.findTaskWithId(toTaskKey.id);
        }
        numAffiliatedTasks = group.getTaskCount();
        break;
      }
    }

    // Return early if there is no next task
    if (toTask == null) {
      if (numAffiliatedTasks > 1) {
        if (showNextTask) {
          mSystemServicesProxy.startInPlaceAnimationOnFrontMostApplication(
              ActivityOptions.makeCustomInPlaceAnimation(
                  mContext, R.anim.recents_launch_next_affiliated_task_bounce));
        } else {
          mSystemServicesProxy.startInPlaceAnimationOnFrontMostApplication(
              ActivityOptions.makeCustomInPlaceAnimation(
                  mContext, R.anim.recents_launch_prev_affiliated_task_bounce));
        }
      }
      return;
    }

    // Keep track of actually launched affiliated tasks
    MetricsLogger.count(mContext, "overview_affiliated_task_launch", 1);

    // Launch the task
    if (toTask.isActive) {
      // Bring an active task to the foreground
      mSystemServicesProxy.moveTaskToFront(toTask.key.id, launchOpts);
    } else {
      mSystemServicesProxy.startActivityFromRecents(
          mContext, toTask.key.id, toTask.activityLabel, launchOpts);
    }
  }
示例#17
0
  /** ** TaskStackView.TaskStackCallbacks Implementation *** */
  @Override
  public void onTaskViewClicked(
      final TaskStackView stackView,
      final TaskView tv,
      final TaskStack stack,
      final Task task,
      final boolean lockToTask) {
    Log.d(TAG, "onTaskViewClicked: ");
    // Notify any callbacks of the launching of a new task
    if (mCb != null) {
      mCb.onTaskViewClicked();
    }

    // Upfront the processing of the thumbnail
    TaskViewTransform transform = new TaskViewTransform();
    View sourceView;
    int offsetX = 0;
    int offsetY = 0;
    float stackScroll = stackView.getScroller().getStackScroll();
    if (tv == null) {
      // If there is no actual task view, then use the stack view as the source view
      // and then offset to the expected transform rect, but bound this to just
      // outside the display rect (to ensure we don't animate from too far away)
      sourceView = stackView;
      transform =
          stackView.getStackAlgorithm().getStackTransform(task, stackScroll, transform, null);
      offsetX = transform.rect.left;
      offsetY = mConfig.displayRect.height();
    } else {
      sourceView = tv.mThumbnailView;
      transform =
          stackView.getStackAlgorithm().getStackTransform(task, stackScroll, transform, null);
    }

    // Compute the thumbnail to scale up from
    final SystemServicesProxy ssp = RecentsTaskLoader.getInstance().getSystemServicesProxy();
    ActivityOptions opts = null;
    if (task.thumbnail != null && task.thumbnail.getWidth() > 0 && task.thumbnail.getHeight() > 0) {
      ActivityOptions.OnAnimationStartedListener animStartedListener = null;
      if (lockToTask) {
        animStartedListener =
            new ActivityOptions.OnAnimationStartedListener() {
              boolean mTriggered = false;

              @Override
              public void onAnimationStarted() {
                if (!mTriggered) {
                  postDelayed(
                      new Runnable() {
                        @Override
                        public void run() {
                          mCb.onScreenPinningRequest();
                        }
                      },
                      350);
                  mTriggered = true;
                }
              }
            };
      }
      if (tv != null) {
        postDrawHeaderThumbnailTransitionRunnable(
            tv, offsetX, offsetY, transform, animStartedListener);
      }
      if (mConfig.multiStackEnabled) {
        opts =
            ActivityOptions.makeCustomAnimation(
                sourceView.getContext(),
                R.anim.recents_from_unknown_enter,
                R.anim.recents_from_unknown_exit,
                sourceView.getHandler(),
                animStartedListener);
      } else {
        opts =
            ActivityOptions.makeThumbnailAspectScaleUpAnimation(
                sourceView,
                Bitmap.createBitmap(1, 1, Bitmap.Config.ALPHA_8).createAshmemBitmap(),
                offsetX,
                offsetY,
                transform.rect.width(),
                transform.rect.height(),
                sourceView.getHandler(),
                animStartedListener);
      }
    }

    final ActivityOptions launchOpts = opts;
    final Runnable launchRunnable =
        new Runnable() {
          @Override
          public void run() {
            if (task.isActive) {
              // Bring an active task to the foreground
              ssp.moveTaskToFront(task.key.id, launchOpts);
            } else {
              if (ssp.startActivityFromRecents(
                  getContext(), task.key.id, task.activityLabel, launchOpts)) {
                if (launchOpts == null && lockToTask) {
                  mCb.onScreenPinningRequest();
                }
              } else {
                // Dismiss the task and return the user to home if we fail to
                // launch the task
                onTaskViewDismissed(task);
                if (mCb != null) {
                  mCb.onTaskLaunchFailed();
                }

                // Keep track of failed launches
                MetricsLogger.count(getContext(), "overview_task_launch_failed", 1);
              }
            }
          }
        };

    // Keep track of the index of the task launch
    int taskIndexFromFront = 0;
    int taskIndex = stack.indexOfTask(task);
    if (taskIndex > -1) {
      taskIndexFromFront = stack.getTaskCount() - taskIndex - 1;
    }
    MetricsLogger.histogram(getContext(), "overview_task_launch_index", taskIndexFromFront);

    // Launch the app right away if there is no task view, otherwise, animate the icon out first
    if (tv == null) {
      launchRunnable.run();
    } else {
      if (task.group != null && !task.group.isFrontMostTask(task)) {
        // For affiliated tasks that are behind other tasks, we must animate the front cards
        // out of view before starting the task transition
        stackView.startLaunchTaskAnimation(tv, launchRunnable, lockToTask);
      } else {
        // Otherwise, we can start the task transition immediately
        stackView.startLaunchTaskAnimation(tv, null, lockToTask);
        launchRunnable.run();
      }
    }
  }
 public static ActivityOptionsCompatJB makeCustomAnimation(
     Context paramContext, int paramInt1, int paramInt2) {
   return new ActivityOptionsCompatJB(
       ActivityOptions.makeCustomAnimation(paramContext, paramInt1, paramInt2));
 }