Java Code Examples for android.support.v4.app.ActivityCompat#startActivity()

The following examples show how to use android.support.v4.app.ActivityCompat#startActivity() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PhotoFragment.java    From ZZShow with Apache License 2.0 6 votes vote down vote up
@Override
public void OnItemClickListener(View view, int position) {
    List<PhotoGirl> list = mAdapter.getList();
    Intent intent = PhotoDetailActivity.getPhotoDetailIntent(getContext(),list.get(position).getUrl());
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        ImageView animationIv = (ImageView) view.findViewById(R.id.photo_iv);
        ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(
                getActivity(),
                animationIv,
                Constants.TRANSITION_ANIMATION_NEWS_PHOTOS);
        startActivity(intent,options.toBundle());
    }else{
        ActivityOptionsCompat optionsCompat = ActivityOptionsCompat.makeScaleUpAnimation(
                view,
                view.getWidth() / 2,
                view.getHeight() / 2,
                0,
                0);
        ActivityCompat.startActivity(getActivity(),intent,optionsCompat.toBundle());
    }
}
 
Example 2
Source File: ImageAdapter.java    From Panoramic-Screenshot with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onClick(View v) {
	
	if (file == null) return;
	
	if (v == image) {
		Intent i = new Intent(mContext, PictureActivity.class);
		i.putExtra(PictureActivity.EXTRA_FILE, file.getAbsolutePath());
		
		if (mContext instanceof Activity) {
			ActivityOptionsCompat o = ActivityOptionsCompat.makeSceneTransitionAnimation(
				(Activity) mContext, image, PictureActivity.TRANSIT_PIC);
			ActivityCompat.startActivity((Activity) mContext, i, o.toBundle());
		} else {
			mContext.startActivity(i);
		}
	}
}
 
Example 3
Source File: MainActivity.java    From Advanced_Android_Development with Apache License 2.0 6 votes vote down vote up
@Override
public void onItemSelected(Uri contentUri, ForecastAdapter.ForecastAdapterViewHolder vh) {
    if (mTwoPane) {
        // In two-pane mode, show the detail view in this activity by
        // adding or replacing the detail fragment using a
        // fragment transaction.
        Bundle args = new Bundle();
        args.putParcelable(DetailFragment.DETAIL_URI, contentUri);

        DetailFragment fragment = new DetailFragment();
        fragment.setArguments(args);

        getSupportFragmentManager().beginTransaction()
                .replace(R.id.weather_detail_container, fragment, DETAILFRAGMENT_TAG)
                .commit();
    } else {
        Intent intent = new Intent(this, DetailActivity.class)
                .setData(contentUri);

        ActivityOptionsCompat activityOptions =
                ActivityOptionsCompat.makeSceneTransitionAnimation(this,
                        new Pair<View, String>(vh.mIconView, getString(R.string.detail_icon_transition_name)));
        ActivityCompat.startActivity(this, intent, activityOptions.toBundle());
    }
}
 
Example 4
Source File: NewsListFragment.java    From SimpleNews with Apache License 2.0 6 votes vote down vote up
@Override
public void onItemClick(View view, int position) {
    if (mData.size() <= 0) {
        return;
    }
    NewsBean news = mAdapter.getItem(position);
    Intent intent = new Intent(getActivity(), NewsDetailActivity.class);
    intent.putExtra("news", news);

    View transitionView = view.findViewById(R.id.ivNews);
    ActivityOptionsCompat options =
            ActivityOptionsCompat.makeSceneTransitionAnimation(getActivity(),
                    transitionView, getString(R.string.transition_news_img));

    ActivityCompat.startActivity(getActivity(), intent, options.toBundle());
}
 
Example 5
Source File: VideoBrowserFragment.java    From cast-videos-android with Apache License 2.0 5 votes vote down vote up
@Override
public void itemClicked(View view, MediaItem item, int position) {
    String transitionName = getString(R.string.transition_image);
    VideoListAdapter.ViewHolder viewHolder =
            (VideoListAdapter.ViewHolder) mRecyclerView.findViewHolderForPosition(position);
    Pair<View, String> imagePair = Pair
            .create((View) viewHolder.getImageView(), transitionName);
    ActivityOptionsCompat options = ActivityOptionsCompat
            .makeSceneTransitionAnimation(getActivity(), imagePair);

    Intent intent = new Intent(getActivity(), LocalPlayerActivity.class);
    intent.putExtra("media", item.toBundle());
    intent.putExtra("shouldStart", false);
    ActivityCompat.startActivity(getActivity(), intent, options.toBundle());
}
 
Example 6
Source File: MeiziAdapter.java    From gank with GNU General Public License v3.0 5 votes vote down vote up
@OnClick(R.id.iv_meizi)
void meiziClick() {
    ShareElement.shareDrawable = ivMeizi.getDrawable();
    Intent intent = new Intent(context, MeiZhiActivity.class);
    intent.putExtra(GankConfig.MEIZI, (Serializable) card.getTag());
    ActivityOptionsCompat optionsCompat = ActivityOptionsCompat
            .makeSceneTransitionAnimation((Activity) context, ivMeizi, GankConfig.TRANSLATE_GIRL_VIEW);
    ActivityCompat.startActivity((Activity) context, intent, optionsCompat.toBundle());
}
 
Example 7
Source File: Navigator.java    From yahnac with Apache License 2.0 5 votes vote down vote up
public void toNews() {
    Intent newsIntent = new Intent(activity, NewsActivity.class);
    newsIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
    ActivityCompat.startActivity(activity, newsIntent, null);
    activity.overridePendingTransition(0, 0);
    activity.finish();
}
 
Example 8
Source File: OptionsCompatDemoActivity.java    From AndroidStudyDemo with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 这里可以用多个元素或者是单个元素进行动画,这里用了多个元素。为了保证动画效果,这里进行了渐变操作,
 * 在handle中进行了恢复操作,这样让动画看起来平滑了很多
 * @param views
 */
private void screenTransitAnimByPair(Pair<View, Integer>... views) {
    sIsSceneAnim = true;
    if (mTestSwitch) {
        Pair<View, String>[] tViews = new Pair[views.length];
        int i = 0;
        for (Pair<View, Integer> view : views) {
            tViews[i] = new Pair<>(view.first, view.second.toString());
            i++;
        }
        ActivityOptionsCompat optionsCompat
                = ActivityOptionsCompat.makeSceneTransitionAnimation(
                OptionsCompatDemoActivity.this,
                tViews
        );
        ActivityCompat.startActivity(
                OptionsCompatDemoActivity.this,
                mIntent,
                optionsCompat.toBundle()
        );
    } else {
        ActivityOptionsCompatICS optionsCompatICS
                = ActivityOptionsCompatICS.makeSceneTransitionAnimation(
                OptionsCompatDemoActivity.this,
                views
        );
        ActivityCompatICS.startActivity(
                OptionsCompatDemoActivity.this,
                mIntent,
                optionsCompatICS.toBundle()
        );
    }
}
 
Example 9
Source File: NewsChannelFragment.java    From NewsMe with Apache License 2.0 5 votes vote down vote up
@Override
public void onImageClick(NewsAdapter.ViewHolder holder, ImageView iv, Image[] images, int index) {
    Intent intent = new Intent(getContext(), ViewerActivity.class);
    intent.putExtra(ViewerActivity.INTENT_POSTTION, holder.getAdapterPosition());
    intent.putExtra(ViewerActivity.INTENT_INDEX, index);
    intent.putExtra(ViewerActivity.INTENT_IMAGES, images);
    // 兼容旧版本
    ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(getActivity(), iv, String.format("%s.image", images[index].url));
    ActivityCompat.startActivity(getActivity(), intent, options.toBundle());
}
 
Example 10
Source File: MainActivity.java    From MaterialTransitionAnimation with Apache License 2.0 5 votes vote down vote up
@Override
public void onClick(View v, int position) {
    Intent intent = new Intent(MainActivity.this, DetailActivity.class);
    intent.putExtra("item", items.get(position));
    ActivityOptionsCompat options =

            ActivityOptionsCompat.makeSceneTransitionAnimation(this, v, getString(R.string.transition_item));
    ActivityCompat.startActivity(this, intent, options.toBundle());
}
 
Example 11
Source File: ActivityTransitionLauncher.java    From candybar-library with Apache License 2.0 5 votes vote down vote up
public void launch(Intent intent) {

        intent.putExtras(createBundle());
        if (Build.VERSION.SDK_INT >= 16) {
            ActivityCompat.startActivity(activity, intent, createOptions());
            return;
        }
        activity.startActivity(intent);
        activity.overridePendingTransition(0, 0);
    }
 
Example 12
Source File: BookDetailsActivity.java    From NHentai-android with GNU General Public License v3.0 5 votes vote down vote up
public static void launch(Activity activity, ImageView imageView, Book book) {
	ActivityOptionsCompat options = ActivityOptionsCompat
			.makeSceneTransitionAnimation(activity, imageView, TRANSITION_NAME_IMAGE);
	Intent intent = new Intent(activity, BookDetailsActivity.class);
	intent.setFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
	intent.putExtra(EXTRA_BOOK_DATA, book.toJSONString());
	ActivityCompat.startActivity(activity, intent, options.toBundle());
}
 
Example 13
Source File: BasePageJump.java    From Tok-Android with GNU General Public License v3.0 5 votes vote down vote up
protected static void jumpWithTransition(Context context, Intent intent,
    Pair<View, String>... sharedElements) {
    if (context instanceof Activity
        && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1
        && sharedElements != null
        && sharedElements.length > 0) {
        ActivityOptionsCompat compat =
            ActivityOptionsCompat.makeSceneTransitionAnimation((Activity) context,
                sharedElements);
        ActivityCompat.startActivity(context, intent, compat.toBundle());
    } else {
        jump(context, intent);
    }
}
 
Example 14
Source File: ImportFragment.java    From apkextractor with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onItemClicked(ImportItem importItem, RecyclerViewAdapter.ViewHolder viewHolder, int position) {
    if(getActivity()==null)return;
    Intent intent =new Intent(getActivity(), PackageDetailActivity.class);
    //intent.putExtra(PackageDetailActivity.EXTRA_IMPORT_ITEM_POSITION,position);
    intent.putExtra(PackageDetailActivity.EXTRA_IMPORT_ITEM_PATH,importItem.getFileItem().getPath());
    ActivityOptionsCompat compat = ActivityOptionsCompat.makeSceneTransitionAnimation(getActivity(),new Pair<View, String>(viewHolder.icon,"icon"));
    try{
        ActivityCompat.startActivity(getActivity(), intent, compat.toBundle());
    }catch (Exception e){e.printStackTrace();}
}
 
Example 15
Source File: AppListFragment.java    From AppPlus with MIT License 5 votes vote down vote up
@Override
public void onClickListItemContent(View view, AppEntity entity) {
    Intent intent = new Intent(getContext(), AppOperateActivity.class);
    intent.putExtra(AppOperateActivity.EXTRA_APP_ENTITY, entity);
    ActivityOptionsCompat activityOptions = ActivityOptionsCompat.makeSceneTransitionAnimation(
            getActivity(),
            new Pair<View, String>(view.findViewById(R.id.iv_icon),
                    AppOperateActivity.VIEW_NAME_HEADER_IMAGE));

    // Now we can start the Activity, providing the activity options as a bundle
    ActivityCompat.startActivity(getActivity(), intent, activityOptions.toBundle());
}
 
Example 16
Source File: Launcher.java    From materialup with Apache License 2.0 5 votes vote down vote up
public static void openPhoteView(Activity activity, Post shot, View view) {
    Intent intent = new Intent(activity, PhotoActivity.class);

    intent.putExtra(EXTRA_URL, shot.getImageUrl());
    intent.putExtra(EXTRA_TITLE, shot.getTitle());
    intent.putExtra(EXTRA_PRE_URL, shot.getTeaserUrl());
    String name = activity.getString(R.string.transition_shot);
    ViewCompat.setTransitionName(view, name);
    ActivityOptionsCompat options =
            ActivityOptionsCompat.makeSceneTransitionAnimation(activity,
                    Pair.create(view, name));

    ActivityCompat.startActivity(activity, intent, options.toBundle());
}
 
Example 17
Source File: OptionsCompatDemoActivity.java    From AndroidStudyDemo with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 当你需要当前界面中的某个元素和新界面中的元素有关时,你可以使用这个动画
 */
public void showSceneAnim(View view) {
    sIsSceneAnim = true;
    if (mTestSwitch) {
        ActivityOptionsCompat optionsCompat
                = ActivityOptionsCompat.makeSceneTransitionAnimation(
                OptionsCompatDemoActivity.this,
                view,
                view.toString()
        );
        ActivityCompat.startActivity(
                OptionsCompatDemoActivity.this,
                mIntent,
                optionsCompat.toBundle());
    } else {
        ActivityOptionsCompatICS optionsCompatICS
                = ActivityOptionsCompatICS.makeSceneTransitionAnimation(
                OptionsCompatDemoActivity.this,
                view,
                view.getId()
        );
        ActivityCompatICS.startActivity(
                OptionsCompatDemoActivity.this,
                mIntent,
                optionsCompatICS.toBundle());
    }
}
 
Example 18
Source File: HuaBanFragment.java    From v9porn with MIT License 5 votes vote down vote up
public void startOptionsActivity(Activity activity, View transitionView, int position, String url) {
    Intent intent = new Intent(activity, PhotoImageActivity.class);
    intent.putExtra("imgurl", url);
    // 这里指定了共享的视图元素
    ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(activity, transitionView, OPTION_IMAGE);
    ActivityCompat.startActivity(activity, intent, options.toBundle());
}
 
Example 19
Source File: BaseActionBarActivity.java    From Silence with GNU General Public License v3.0 4 votes vote down vote up
protected void startActivitySceneTransition(Intent intent, View sharedView, String transitionName) {
  Bundle bundle = ActivityOptionsCompat.makeSceneTransitionAnimation(this, sharedView, transitionName)
                                       .toBundle();
  ActivityCompat.startActivity(this, intent, bundle);
}
 
Example 20
Source File: VenvyRouterHelper.java    From VideoOS-Android-SDK with GNU General Public License v3.0 4 votes vote down vote up
private static void navigation(Context context, final ViewGroup viewGroup, @NonNull final String role, final Bundle bundle, final IRouterCallback callback) throws Exception {
    if (sFinders == null || sFinders.size() <= 0) {
        VenvyLog.d("Router", "begin navigation but sFinders is null");
    }
    for (IRouterFinder finder : sFinders) {
        String roleValue = finder.findRole(role);
        if (TextUtils.isEmpty(roleValue)) {
            continue;
        }
        if (TextUtils.isEmpty(roleValue)) {
            throw new RouteException("route result is not found");
        }
        RouteRoleCase routeRoleCase = parseJsonStringToCase(roleValue);
        if (routeRoleCase == null) {
            throw new RouteException("route result is not found");
        }
        if (TextUtils.isEmpty(routeRoleCase.className)) {
            throw new RouteException("route class not found");
        }
        if (routeRoleCase.type == RouteType.UNKNOWN) {
            throw new RouteException("route type is unknown");
        }
        Class tClass = VenvyReflectUtil.getClass(routeRoleCase.className);
        if (tClass == null) {
            throw new RouteException("route target class init error");
        }
        switch (routeRoleCase.type) {
            case ACTIVITY:
                Intent intent = new Intent(context, tClass);
                intent.putExtras(bundle);
                ActivityCompat.startActivity(context, intent, bundle);
                if (callback != null) {
                    callback.arrived();
                }
                break;
            case VIEW:
                View view = null;
                if (bundle != null && viewGroup != null) {
                    String viewID = bundle.getString("id");
                    if (!TextUtils.isEmpty(viewID)) {
                        View oldView = viewGroup.findViewWithTag(viewID);
                        if (oldView != null) {
                            oldView.setVisibility(View.VISIBLE);
                            oldView.bringToFront();
                            injectView(oldView, bundle);
                            invokeRunMethod(oldView);
                            VenvyLog.d("Router", "navigation running, but view has init and viewID is " + viewID);
                            return;
                        }
                    }
                }
                Constructor<? extends View> constructor = tClass.getDeclaredConstructor(Context.class);
                if (constructor != null) {
                    view = constructor.newInstance(context);
                }
                if (view == null) {
                    throw new RouteException("route target view init error");
                }
                //方法赋值
                injectView(view, bundle);
                invokeRunMethod(view);
                if (viewGroup != null) {
                    addViewByPriority(viewGroup, view);
                    VenvyLog.d("Router", "navigation running, init view and addView to viewGroup");
                }
                if (callback != null) {
                    callback.arrived();
                }
                break;
            case SERVICE:
                Intent intentService = new Intent(context, tClass);
                intentService.putExtras(bundle);
                context.startService(intentService);
                if (callback != null) {
                    callback.arrived();
                }
                break;

            case OBJECT:
                Object object = tClass.newInstance();
                if (object == null) {
                    return;
                }
                if (callback != null) {
                    callback.arrived();
                }
                //方法赋值
                injectView(object, bundle);
                invokeRunMethod(object);
                break;
        }
    }
    VenvyLog.d("Router", "navigation end and uri is " + role);
}