android.support.v4.app.SharedElementCallback源码实例Demo

类android.support.v4.app.SharedElementCallback源码实例Demo

下面列出了android.support.v4.app.SharedElementCallback 类实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: SETransitionDemo   文件: SourceActivity.java
@TargetApi(21)
private void setCallback(final int enterPosition) {
    this.enterPosition = enterPosition;
    setExitSharedElementCallback(new SharedElementCallback() {
        @Override
        public void onMapSharedElements(List<String> names, Map<String, View> sharedElements) {
            if (exitPosition != enterPosition &&
                    names.size() > 0 && exitPosition < sharedViews.length) {
                names.clear();
                sharedElements.clear();
                View view = sharedViews[exitPosition];
                names.add(view.getTransitionName());
                sharedElements.put(view.getTransitionName(), view);
            }
            setExitSharedElementCallback((SharedElementCallback) null);
            sharedViews = null;
        }
    });
}
 
源代码2 项目: SETransitionDemo   文件: DestinationActivity.java
@TargetApi(21)
private void setSharedElementCallback(final View view) {
    setEnterSharedElementCallback(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);
        }
    });
}
 
源代码3 项目: NewsMe   文件: AboutActivity.java
private void initEnterSharedElement() {
    ActivityCompat.setEnterSharedElementCallback(this, new SharedElementCallback() {
        @Override
        public void onMapSharedElements(List<String> names, Map<String, View> sharedElements) {
            sharedElements.clear();
            sharedElements.put(SHARE_IMAGE, getBinding().image);
        }
    });
}
 
源代码4 项目: NewsMe   文件: ViewerActivity.java
private void initEnterSharedElement() {
    ActivityCompat.setEnterSharedElementCallback(this, new SharedElementCallback() {
        @Override
        public void onMapSharedElements(List<String> names, Map<String, View> sharedElements) {
            Image image = mImages[getBinding().pager.getCurrentItem()];
            sharedElements.clear();
            sharedElements.put(String.format("%s.image", image.url), getCurrent().getSharedElement());
        }
    });
}
 
源代码5 项目: MoeQuest   文件: GankMeiziFragment.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public void initViews() {

  showProgress();
  realm = Realm.getDefaultInstance();
  gankMeizis = realm.where(GankMeizi.class).findAll();
  initRecycleView();

  RxBus.getInstance().toObserverable(Intent.class)
      .compose(this.bindToLifecycle())
      .subscribe(intent -> {

        imageIndex = intent.getIntExtra("index", -1);
        scrollIndex();
        finishTask();
      }, throwable -> {

        LogUtil.all(throwable.getMessage());
      });

  setEnterSharedElementCallback(new SharedElementCallback() {

    @Override
    public void onMapSharedElements(List<String> names, Map<String, View> sharedElements) {

      super.onMapSharedElements(names, sharedElements);
      String newTransitionName = gankMeizis.get(imageIndex).getUrl();
      View newSharedView = mRecyclerView.findViewWithTag(newTransitionName);
      if (newSharedView != null) {
        names.clear();
        names.add(newTransitionName);
        sharedElements.clear();
        sharedElements.put(newTransitionName, newSharedView);
      }
    }
  });
}
 
源代码6 项目: CompositeAndroid   文件: FragmentPlugin.java
void setEnterSharedElementCallback(final CallVoid1<SharedElementCallback> superCall,
        SharedElementCallback callback) {
    synchronized (mSuperListeners) {
        mSuperListeners.push(superCall);
        setEnterSharedElementCallback(callback);
    }
}
 
源代码7 项目: CompositeAndroid   文件: FragmentPlugin.java
void setExitSharedElementCallback(final CallVoid1<SharedElementCallback> superCall,
        SharedElementCallback callback) {
    synchronized (mSuperListeners) {
        mSuperListeners.push(superCall);
        setExitSharedElementCallback(callback);
    }
}
 
源代码8 项目: GankMeizhi   文件: ViewerActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    supportPostponeEnterTransition();

    setContentView(R.layout.activity_viewer);
    ButterKnife.bind(this);

    index = getIntent().getIntExtra("index", 0);

    realm = Realm.getDefaultInstance();
    realm.addChangeListener(this);

    images = Image.all(realm);

    puller.setCallback(this);

    adapter = new PagerAdapter();

    pager.setAdapter(adapter);
    pager.setCurrentItem(index);

    // 避免图片在进行 Shared Element Transition 时盖过 Toolbar
    if (Build.VERSION.SDK_INT >= 21) {
        getWindow().setSharedElementsUseOverlay(false);
    }

    setEnterSharedElementCallback(new SharedElementCallback() {
        @Override
        public void onMapSharedElements(List<String> names, Map<String, View> sharedElements) {
            Image image = images.get(pager.getCurrentItem());
            sharedElements.clear();
            sharedElements.put(image.getUrl(), adapter.getCurrent().getSharedElement());
        }
    });
}
 
源代码9 项目: MoeQuest   文件: MeiziTuSimpleFragment.java
@Override
public void initViews() {

  type = getArguments().getString(EXTRA_TYPE);

  showProgress();
  realm = Realm.getDefaultInstance();
  meizis = realm.where(MeiziTu.class)
      .equalTo("type", type)
      .findAll();

  initRecycleView();

  RxBus.getInstance().toObserverable(Intent.class)
      .compose(this.bindToLifecycle())
      .subscribe(intent -> {

        imageIndex = intent.getIntExtra("index", -1);
        scrollIndex();
        finishTask();
      }, throwable -> {

        LogUtil.all(throwable.getMessage());
      });

  setEnterSharedElementCallback(new SharedElementCallback() {

    @Override
    public void onMapSharedElements(List<String> names, Map<String, View> sharedElements) {

      super.onMapSharedElements(names, sharedElements);
      String newTransitionName = meizis.get(imageIndex).getImageurl();
      View newSharedView = mRecyclerView.findViewWithTag(newTransitionName);
      if (newSharedView != null) {
        names.clear();
        names.add(newTransitionName);
        sharedElements.clear();
        sharedElements.put(newTransitionName, newSharedView);
      }
    }
  });
}
 
源代码10 项目: MoeQuest   文件: DoubanSimpleMeiziFragment.java
@Override
public void initViews() {

  cid = getArguments().getInt(EXTRA_CID);
  type = getArguments().getInt(EXTRA_TYPE);

  showProgress();
  realm = Realm.getDefaultInstance();
  doubanMeizis = realm.where(DoubanMeizi.class)
      .equalTo("type", type)
      .findAll();

  initRecycleView();

  RxBus.getInstance().toObserverable(Intent.class)
      .compose(this.bindToLifecycle())
      .subscribe(intent -> {

        imageIndex = intent.getIntExtra("index", -1);
        scrollIndex();
        finishTask();
      }, throwable -> {

        LogUtil.all(throwable.getMessage());
      });

  setEnterSharedElementCallback(new SharedElementCallback() {

    @Override
    public void onMapSharedElements(List<String> names, Map<String, View> sharedElements) {

      super.onMapSharedElements(names, sharedElements);
      String newTransitionName = doubanMeizis.get(imageIndex).getUrl();
      View newSharedView = mRecyclerView.findViewWithTag(newTransitionName);
      if (newSharedView != null) {
        names.clear();
        names.add(newTransitionName);
        sharedElements.clear();
        sharedElements.put(newTransitionName, newSharedView);
      }
    }
  });
}
 
源代码11 项目: CompositeAndroid   文件: BlueprintActivity.java
@Override
public void setEnterSharedElementCallback(SharedElementCallback callback) {
    super.setEnterSharedElementCallback(callback);
}
 
源代码12 项目: CompositeAndroid   文件: BlueprintActivity.java
@Override
public void setExitSharedElementCallback(SharedElementCallback listener) {
    super.setExitSharedElementCallback(listener);
}
 
源代码13 项目: CompositeAndroid   文件: BlueprintFragment.java
@Override
public void setEnterSharedElementCallback(SharedElementCallback callback) {
    super.setEnterSharedElementCallback(callback);
}
 
源代码14 项目: CompositeAndroid   文件: BlueprintFragment.java
@Override
public void setExitSharedElementCallback(SharedElementCallback callback) {
    super.setExitSharedElementCallback(callback);
}
 
源代码15 项目: CompositeAndroid   文件: FragmentPlugin.java
public void setEnterSharedElementCallback(SharedElementCallback callback) {
    verifyMethodCalledFromDelegate("setEnterSharedElementCallback(SharedElementCallback)");
    ((CallVoid1<SharedElementCallback>) mSuperListeners.pop()).call(callback);
}
 
源代码16 项目: CompositeAndroid   文件: FragmentPlugin.java
public void setExitSharedElementCallback(SharedElementCallback callback) {
    verifyMethodCalledFromDelegate("setExitSharedElementCallback(SharedElementCallback)");
    ((CallVoid1<SharedElementCallback>) mSuperListeners.pop()).call(callback);
}
 
源代码17 项目: CompositeAndroid   文件: DialogFragmentDelegate.java
public void setEnterSharedElementCallback(SharedElementCallback callback) {
    mFragmentDelegate.setEnterSharedElementCallback(callback);
}
 
源代码18 项目: CompositeAndroid   文件: DialogFragmentDelegate.java
public void setExitSharedElementCallback(SharedElementCallback callback) {
    mFragmentDelegate.setExitSharedElementCallback(callback);
}
 
源代码19 项目: CompositeAndroid   文件: CompositeFragment.java
@Override
public void setEnterSharedElementCallback(SharedElementCallback callback) {
    delegate.setEnterSharedElementCallback(callback);
}
 
源代码20 项目: CompositeAndroid   文件: CompositeFragment.java
@Override
public void setExitSharedElementCallback(SharedElementCallback callback) {
    delegate.setExitSharedElementCallback(callback);
}
 
源代码21 项目: CompositeAndroid   文件: CompositeFragment.java
@Override
public void super_setEnterSharedElementCallback(SharedElementCallback callback) {
    super.setEnterSharedElementCallback(callback);
}
 
源代码22 项目: CompositeAndroid   文件: CompositeFragment.java
@Override
public void super_setExitSharedElementCallback(SharedElementCallback callback) {
    super.setExitSharedElementCallback(callback);
}
 
源代码23 项目: CompositeAndroid   文件: CompositeDialogFragment.java
@Override
public void setEnterSharedElementCallback(SharedElementCallback callback) {
    delegate.setEnterSharedElementCallback(callback);
}
 
源代码24 项目: CompositeAndroid   文件: CompositeDialogFragment.java
@Override
public void setExitSharedElementCallback(SharedElementCallback callback) {
    delegate.setExitSharedElementCallback(callback);
}
 
源代码25 项目: CompositeAndroid   文件: CompositeDialogFragment.java
@Override
public void super_setEnterSharedElementCallback(SharedElementCallback callback) {
    super.setEnterSharedElementCallback(callback);
}
 
源代码26 项目: CompositeAndroid   文件: CompositeDialogFragment.java
@Override
public void super_setExitSharedElementCallback(SharedElementCallback callback) {
    super.setExitSharedElementCallback(callback);
}
 
源代码27 项目: auid2   文件: ToolListActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_tool_list);

    final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    mToolType = (ToolType) getIntent().getSerializableExtra(EXTRA_TOOL_TYPE);
    if (mToolType == null) {
        throw new IllegalStateException("ToolType not available as extra; use startActivity");
    }
    setTitle(mToolType.getToolNameResourceId());

    // Set up tabs
    mViewPager = (ViewPager) findViewById(R.id.viewpager);
    final TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
    final ToolPagerAdapter toolPagerAdapter = new ToolPagerAdapter(getSupportFragmentManager(), getResources(), mToolType);
    tabLayout.setTabsFromPagerAdapter(toolPagerAdapter);
    mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
    mViewPager.setAdapter(toolPagerAdapter);
    tabLayout.setOnTabSelectedListener(this);

    // Handle animation from previous activity
    postponeEnterTransition();
    mViewPager.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
        @Override
        public boolean onPreDraw() {
            mViewPager.getViewTreeObserver().removeOnPreDrawListener(this);
            startPostponedEnterTransition();
            return true;
        }
    });

    setEnterSharedElementCallback(new SharedElementCallback() {
        @Override
        public void onMapSharedElements(List<String> names, Map<String, View> sharedElements) {
            if (mViewPager.getCurrentItem() != 0) {
                // Not displaying the about page, which has the hero image
                names.clear();
                sharedElements.clear();
            }
        }
    });


}
 
源代码28 项目: auid2   文件: ToolListActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_tool_list);

    final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    mToolType = (ToolType) getIntent().getSerializableExtra(EXTRA_TOOL_TYPE);
    if (mToolType == null) {
        throw new IllegalStateException("ToolType not available as extra; use startActivity");
    }
    setTitle(mToolType.getToolNameResourceId());

    // Set up tabs
    mViewPager = (ViewPager) findViewById(R.id.viewpager);
    final TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
    final ToolPagerAdapter toolPagerAdapter = new ToolPagerAdapter(getSupportFragmentManager(), getResources(), mToolType);
    tabLayout.setTabsFromPagerAdapter(toolPagerAdapter);
    mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
    mViewPager.setAdapter(toolPagerAdapter);
    tabLayout.setOnTabSelectedListener(this);

    // Handle animation from previous activity
    postponeEnterTransition();
    mViewPager.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
        @Override
        public boolean onPreDraw() {
            mViewPager.getViewTreeObserver().removeOnPreDrawListener(this);
            startPostponedEnterTransition();
            return true;
        }
    });

    setEnterSharedElementCallback(new SharedElementCallback() {
        @Override
        public void onMapSharedElements(List<String> names, Map<String, View> sharedElements) {
            if (mViewPager.getCurrentItem() != 0) {
                // Not displaying the about page, which has the hero image
                names.clear();
                sharedElements.clear();
            }
        }
    });


}
 
源代码29 项目: mr-mantou-android   文件: MainActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    MiuiStatusBarCompat.enableLightStatusBar(getWindow());

    binding = DataBindingUtil.setContentView(this, R.layout.main_activity);

    setSupportActionBar(binding.toolbar);

    images = MrSharedState.getInstance().getImages();

    Glide.get(this).setMemoryCategory(MemoryCategory.HIGH);
    binding.content.setAdapter(new MainAdapter(this, images, Glide.with(this), this));

    setExitSharedElementCallback(new SharedElementCallback() {
        @Override
        public void onMapSharedElements(List<String> names, Map<String, View> sharedElements) {
            if (reenterState != null) {
                int index = reenterState.getInt("index", 0);

                Image image = images.get(index);

                MainAdapter.ViewHolder holder = (MainAdapter.ViewHolder) binding.content
                        .findViewHolderForLayoutPosition(index);

                sharedElements.clear();

                if (holder != null && holder.binding != null) {
                    sharedElements.put(String.format("%s.image", image.getObjectId()), holder.binding.image);
                }

                reenterState = null;
            }
        }
    });

    Observable<List<Image>> load = Observable.just(images)
            .doOnSubscribe(() -> binding.refresher.setRefreshing(true))
            .doOnCompleted(() -> binding.refresher.setRefreshing(false))
            .map(whatever -> images.isEmpty() ? Image.all() : Image.since(images.get(0)))
            .observeOn(Schedulers.io())
            .flatMap(RxAVQuery::find)
            .observeOn(AndroidSchedulers.mainThread())
            .doOnNext(RxList.prependTo(images));

    RxSwipeRefreshLayout.refreshes(binding.refresher)
            .compose(bindToLifecycle())
            .flatMap(whatever -> load)
            .retry((count, tr) -> {
                Log.e(TAG, "An error occurred while fetching images", tr);
                ToastUtil.shorts(this, tr.getMessage());
                binding.refresher.setRefreshing(false);
                return true;
            })
            .filter(loaded -> !loaded.isEmpty())
            .subscribe(loaded -> binding.content.smoothScrollToPosition(0));

    load.compose(bindToLifecycle())
            .onErrorReturn(tr -> {
                Log.e(TAG, "An error occurred while fetching images", tr);
                ToastUtil.shorts(this, tr.getMessage());
                binding.refresher.setRefreshing(false);
                return null;
            })
            .subscribe();

    UpdateUtil.checkForUpdate(version -> UpdateUtil.promptUpdate(this, version));
}
 
public SharedElementCallback getSharedElementCallback() {
    return mSharedElementCallback;
}
 
如果文章对您有帮助,请点击页面广告。以鼓励作者做出的努力。
 类所在包