本文整理汇总了Java中android.app.SharedElementCallback类的典型用法代码示例。如果您正苦于以下问题:Java SharedElementCallback类的具体用法?Java SharedElementCallback怎么用?Java SharedElementCallback使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SharedElementCallback类属于android.app包,在下文中一共展示了SharedElementCallback类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setupTransitions
import android.app.SharedElementCallback; //导入依赖的package包/类
private void setupTransitions() {
// grab the position that the search icon transitions in *from*
// & use it to configure the return transition
setEnterSharedElementCallback(new SharedElementCallback() {
@Override
public void onSharedElementStart(
List<String> sharedElementNames,
List<View> sharedElements,
List<View> sharedElementSnapshots) {
if (sharedElements != null && !sharedElements.isEmpty()) {
View searchIcon = sharedElements.get(0);
if (searchIcon.getId() != R.id.searchback) return;
int centerX = (searchIcon.getLeft() + searchIcon.getRight()) / 2;
CircularReveal hideResults = (CircularReveal) TransitionUtils.findTransition(
(TransitionSet) getWindow().getReturnTransition(),
CircularReveal.class, R.id.results_container);
if (hideResults != null) {
hideResults.setCenter(new Point(centerX, 0));
}
}
}
});
}
示例2: setCallback
import android.app.SharedElementCallback; //导入依赖的package包/类
@TargetApi(21)
private void setCallback(final int chosenPosition) {
DataManager.getInstance().setPosition(chosenPosition);
((AppCompatActivity) context).setExitSharedElementCallback(new SharedElementCallback() {
@Override
public void onMapSharedElements(List<String> names, Map<String, View> sharedElements) {
int pos = DataManager.getInstance().getPosition();
if (chosenPosition != pos && names.size() > 0) {
sharedElements.put(names.get(0), contentViewCache.get(pos));
}
((AppCompatActivity) context).setExitSharedElementCallback((SharedElementCallback) null);
}
});
}
示例3: setSharedElementCallback
import android.app.SharedElementCallback; //导入依赖的package包/类
@TargetApi(21)
private void setSharedElementCallback(final View view) {
SharedElementCallback callback = new SharedElementCallback() {
@Override
public void onMapSharedElements(List<String> names, Map<String, View> sharedElements) {
names.clear();
sharedElements.clear();
names.add(view.getTransitionName());
sharedElements.put(view.getTransitionName(), view);
}
};
setEnterSharedElementCallback(callback);
}
示例4: handleElementOnClick
import android.app.SharedElementCallback; //导入依赖的package包/类
@Override
void handleElementOnClick(final View view) {
final int itemPosition = getRecyclerView().getChildAdapterPosition(view);
VideoOnDemand item = getElements().get(itemPosition);
if (activity instanceof VODActivity) {
((VODActivity) activity).startNewVOD(item);
} else {
Intent intent = VODActivity.createVODIntent(item, getContext());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
intent.putExtra(getContext().getString(R.string.stream_preview_url), item.getMediumPreview());
intent.putExtra(getContext().getString(R.string.stream_preview_alpha), hasVodBeenWatched(item.getVideoId()) ? VOD_WATCHED_IMAGE_ALPHA : 1.0f);
final View sharedView = view.findViewById(R.id.image_stream_preview);
sharedView.setTransitionName(getContext().getString(R.string.stream_preview_transition));
final ActivityOptionsCompat options = ActivityOptionsCompat.
makeSceneTransitionAnimation(activity, sharedView, getContext().getString(R.string.stream_preview_transition));
activity.setExitSharedElementCallback(new SharedElementCallback() {
@SuppressLint("NewApi")
@Override
public void onSharedElementEnd(List<String> sharedElementNames, List<View> sharedElements, List<View> sharedElementSnapshots) {
super.onSharedElementEnd(sharedElementNames, sharedElements, sharedElementSnapshots);
sharedView.animate().alpha(VOD_WATCHED_IMAGE_ALPHA).setDuration(300).start();
activity.setExitSharedElementCallback(null);
}
});
activity.startActivity(intent, options.toBundle());
} else {
getContext().startActivity(intent);
activity.overridePendingTransition(R.anim.slide_in_bottom_anim, R.anim.fade_out_semi_anim);
}
}
}
示例5: setup
import android.app.SharedElementCallback; //导入依赖的package包/类
private void setup() {
String name = getIntent().getStringExtra(KEY_ID);
if (name != null) {
setEnterSharedElementCallback(new SharedElementCallback() {
@Override
public void onMapSharedElements(List<String> names,
Map<String, View> sharedElements) {
sharedElements.put(ELEMENT_NAME, mImageView);
}
});
}
}
示例6: onCreateView
import android.app.SharedElementCallback; //导入依赖的package包/类
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_rv, null);
mRecyclerView = (RecyclerView) v.findViewById(R.id.recycler_view);
int spacingInPixels = getResources().getDimensionPixelSize(R.dimen.spacing_card);
mRecyclerView.addItemDecoration(new SpacesItemDecoration(spacingInPixels));
mRecyclerView.setLayoutManager(new GridLayoutManager(getActivity(), 1));
mRecyclerView.setHasFixedSize(true);
setUpList();
getActivity().setExitSharedElementCallback(new SharedElementCallback() {
@Override
public Parcelable onCaptureSharedElementSnapshot(View sharedElement, Matrix viewToGlobalMatrix, RectF screenBounds) {
int bitmapWidth = Math.round(screenBounds.width());
int bitmapHeight = Math.round(screenBounds.height());
Bitmap bitmap = null;
if (bitmapWidth > 0 && bitmapHeight > 0) {
Matrix matrix = new Matrix();
matrix.set(viewToGlobalMatrix);
matrix.postTranslate(-screenBounds.left, -screenBounds.top);
bitmap = Bitmap.createBitmap(bitmapWidth, bitmapHeight, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
canvas.concat(matrix);
sharedElement.draw(canvas);
}
return bitmap;
}
});
return v;
}
示例7: onCreateView
import android.app.SharedElementCallback; //导入依赖的package包/类
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_rv, null);
mRecyclerView = (RecyclerView) v.findViewById(R.id.recycler_view);
int spacingInPixels = getResources().getDimensionPixelSize(R.dimen.spacing_card);
mRecyclerView.addItemDecoration(new SpacesItemDecoration(spacingInPixels));
mRecyclerView.setLayoutManager(new GridLayoutManager(getActivity(), 2));
mRecyclerView.setHasFixedSize(true);
setUpList();
getActivity().setExitSharedElementCallback(new SharedElementCallback() {
@Override
public Parcelable onCaptureSharedElementSnapshot(View sharedElement, Matrix viewToGlobalMatrix, RectF screenBounds) {
int bitmapWidth = Math.round(screenBounds.width());
int bitmapHeight = Math.round(screenBounds.height());
Bitmap bitmap = null;
if (bitmapWidth > 0 && bitmapHeight > 0) {
Matrix matrix = new Matrix();
matrix.set(viewToGlobalMatrix);
matrix.postTranslate(-screenBounds.left, -screenBounds.top);
bitmap = Bitmap.createBitmap(bitmapWidth, bitmapHeight, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
canvas.concat(matrix);
sharedElement.draw(canvas);
}
return bitmap;
}
});
return v;
}
示例8: createCallback
import android.app.SharedElementCallback; //导入依赖的package包/类
private static SharedElementCallback createCallback(SharedElementCallback21 callback) {
SharedElementCallback newListener = null;
if (callback != null) {
newListener = new SharedElementCallbackImpl(callback);
}
return newListener;
}
示例9: setupTransitions
import android.app.SharedElementCallback; //导入依赖的package包/类
private void setupTransitions() {
// grab the position that the search icon transitions in *from*
// & use it to configure the return transition
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
setEnterSharedElementCallback(new SharedElementCallback() {
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
public void onSharedElementStart(
List<String> sharedElementNames,
List<View> sharedElements,
List<View> sharedElementSnapshots) {
if (sharedElements != null && !sharedElements.isEmpty()) {
View searchIcon = sharedElements.get(0);
if (searchIcon.getId() != R.id.searchback) return;
int centerX = (searchIcon.getLeft() + searchIcon.getRight()) / 2;
CircularReveal hideResults = (CircularReveal) TransitionUtils.findTransition(
(TransitionSet) getWindow().getReturnTransition(),
CircularReveal.class, R.id.results_container);
if (hideResults != null) {
hideResults.setCenter(new Point(centerX, 0));
}
}
}
});
// focus the search view once the transition finishes
getWindow().getEnterTransition().addListener(
new TransitionUtils.TransitionListenerAdapter() {
@Override
public void onTransitionEnd(Transition transition) {
searchView.requestFocus();
ImeUtils.showIme(searchView);
}
});
} else {
searchView.requestFocus();
ImeUtils.showIme(searchView);
}
}
示例10: createSharedElementReenterCallback
import android.app.SharedElementCallback; //导入依赖的package包/类
public static SharedElementCallback createSharedElementReenterCallback(
@NonNull Context context) {
final String shotTransitionName = context.getString(R.string.transition_shot);
final String shotBackgroundTransitionName =
context.getString(R.string.transition_shot_background);
return new SharedElementCallback() {
/**
* We're performing a slightly unusual shared element transition i.e. from one view
* (image in the grid) to two views (the image & also the background of the details
* view, to produce the expand effect). After changing orientation, the transition
* system seems unable to map both shared elements (only seems to map the shot, not
* the background) so in this situation we manually map the background to the
* same view.
*/
@Override
public void onMapSharedElements(List<String> names, Map<String, View> sharedElements) {
if (sharedElements.size() != names.size()) {
// couldn't map all shared elements
final View sharedShot = sharedElements.get(shotTransitionName);
if (sharedShot != null) {
// has shot so add shot background, mapped to same view
sharedElements.put(shotBackgroundTransitionName, sharedShot);
}
}
}
};
}
示例11: clearSharedElementsOnReturn
import android.app.SharedElementCallback; //导入依赖的package包/类
static void clearSharedElementsOnReturn(@NonNull final BaseActivity activity) {
activity.setEnterSharedElementCallback(new SharedElementCallback() {
@Override
public void onMapSharedElements(final List<String> names,
final Map<String, View> sharedElements) {
super.onMapSharedElements(names, sharedElements);
if (activity.isFinishingAfterTransition()) {
names.clear();
sharedElements.clear();
}
}
});
}
示例12: initTransitions
import android.app.SharedElementCallback; //导入依赖的package包/类
private void initTransitions() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
postponeEnterTransition();
setEnterSharedElementCallback(new SharedElementCallback() {
@SuppressLint("NewApi")
@Override
public void onMapSharedElements(List<String> names, Map<String, View> sharedElements) {
super.onMapSharedElements(names, sharedElements);
if (mAdapter.getRegisteredFragment(mPosition) != null) {
names.clear();
sharedElements.clear();
View view = ((ImageFragment) mAdapter.getRegisteredFragment(mPosition)).mImage;
names.add(view.getTransitionName());
sharedElements.put(view.getTransitionName(), view);
}
}
});
}
// mPager.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
// @SuppressLint("NewApi")
// public boolean onPreDraw() {
// mPager.getViewTreeObserver().removeOnPreDrawListener(this);
// startPostponedEnterTransition();
// return true;
// }
// });
}
示例13: initTransitions
import android.app.SharedElementCallback; //导入依赖的package包/类
private void initTransitions() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
setExitSharedElementCallback(new SharedElementCallback() {
@SuppressLint("NewApi")
@Override
public void onMapSharedElements(List<String> names, Map<String, View> sharedElements) {
super.onMapSharedElements(names, sharedElements);
if (!isReenterTransition) {
return;
}
isReenterTransition = false;
names.clear();
sharedElements.clear();
final PostFragment postFragment = (PostFragment) mAdapter.getRegisteredFragment(mPager.getCurrentItem());
final RecyclerView recyclerView = postFragment.mRecyclerView;
View sharedView =
((PostImagesRecyclerViewAdapter.ViewHolder) recyclerView.findViewHolderForPosition(mImagePosition)).getImage();
names.add(sharedView.getTransitionName());
sharedElements.put(sharedView.getTransitionName(), sharedView);
}
});
Fade fadeExit = new Fade();
fadeExit.addTarget(R.id.text_post_title);
fadeExit.addTarget(R.id.button_show_gallery);
fadeExit.addTarget(R.id.recycler_post_images);
fadeExit.addTarget(R.id.image_post_author);
fadeExit.addTarget(R.id.bottom_shadow_post);
fadeExit.addTarget(R.id.toolbar);
getWindow().setExitTransition(fadeExit);
}
}
示例14: createSharedElementReenterCallback
import android.app.SharedElementCallback; //导入依赖的package包/类
static SharedElementCallback createSharedElementReenterCallback(
@NonNull Context context) {
final String shotTransitionName = context.getString(R.string.transition_shot);
final String shotBackgroundTransitionName =
context.getString(R.string.transition_shot_background);
return new SharedElementCallback() {
/**
* We're performing a slightly unusual shared element transition i.e. from one view
* (image in the grid) to two views (the image & also the background of the details
* view, to produce the expand effect). After changing orientation, the transition
* system seems unable to map both shared elements (only seems to map the shot, not
* the background) so in this situation we manually map the background to the
* same view.
*/
@Override
public void onMapSharedElements(List<String> names, Map<String, View> sharedElements) {
if (sharedElements.size() != names.size()) {
// couldn't map all shared elements
final View sharedShot = sharedElements.get(shotTransitionName);
if (sharedShot != null) {
// has shot so add shot background, mapped to same view
sharedElements.put(shotBackgroundTransitionName, sharedShot);
}
}
}
};
}
示例15: setupHero
import android.app.SharedElementCallback; //导入依赖的package包/类
private void setupHero() {
String name = getIntent().getStringExtra(KEY_ID);
mHero = null;
if (name != null) {
mHero = (ImageView) findViewById(getIdForKey(name));
setEnterSharedElementCallback(new SharedElementCallback() {
@Override
public void onMapSharedElements(List<String> names,
Map<String, View> sharedElements) {
sharedElements.put("hero", mHero);
}
});
}
}