Java 类android.support.v7.widget.LinearSnapHelper 实例源码
项目:RecyclerWheelPicker
文件:RecyclerWheelPicker.java
private void init(Context context) {
initSound();
setOverScrollMode(OVER_SCROLL_NEVER);
setHasFixedSize(true);
mDecorationPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mUnitTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
mDecorationRect = new Rect();
mDecoration = new DefaultDecoration();
mAdapter = new WheelAdapter(context);
super.setAdapter(mAdapter);
mLayoutManager = new WheelPickerLayoutManager(this);
super.setLayoutManager(mLayoutManager);
new LinearSnapHelper().attachToRecyclerView(this);
}
项目:ImageGallery
文件:ImageGallery.java
private void initGalleryWhenImagesAreAvailable() {
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.gallery);
recyclerView.setHasFixedSize(true);
CenterLayoutManager layoutManager = new CenterLayoutManager(context, CenterLayoutManager.HORIZONTAL, false);
SnapHelper snapHelper = new LinearSnapHelper();
if (recyclerView.getOnFlingListener() == null) {
snapHelper.attachToRecyclerView(recyclerView);
}
recyclerView.setLayoutManager(layoutManager);
PlacesGalleryAdapter adapter = new PlacesGalleryAdapter(context,
imageUrls,
(ImageView) findViewById(R.id.singleImage),
(TextView) findViewById(R.id.size),
recyclerView,
languageHelper);
if (this.onClickCallback != null) {
adapter.setCallback(this.onClickCallback);
}
recyclerView.setAdapter(adapter);
}
项目:GitHub
文件:SnapAdapter.java
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
Snap snap = mSnaps.get(position);
holder.snapTextView.setText(snap.getText());
if (snap.getGravity() == Gravity.START || snap.getGravity() == Gravity.END) {
holder.recyclerView.setLayoutManager(new LinearLayoutManager(holder
.recyclerView.getContext(), LinearLayoutManager.HORIZONTAL, false));
holder.recyclerView.setOnFlingListener(null);
new GravitySnapHelper(snap.getGravity(), false, this).attachToRecyclerView(holder.recyclerView);
} else if (snap.getGravity() == Gravity.CENTER_HORIZONTAL ||
snap.getGravity() == Gravity.CENTER_VERTICAL) {
holder.recyclerView.setLayoutManager(new LinearLayoutManager(holder
.recyclerView.getContext(), snap.getGravity() == Gravity.CENTER_HORIZONTAL ?
LinearLayoutManager.HORIZONTAL : LinearLayoutManager.VERTICAL, false));
holder.recyclerView.setOnFlingListener(null);
new LinearSnapHelper().attachToRecyclerView(holder.recyclerView);
} else if (snap.getGravity() == Gravity.CENTER) { // Pager snap
holder.recyclerView.setLayoutManager(new LinearLayoutManager(holder
.recyclerView.getContext(), LinearLayoutManager.HORIZONTAL, false));
holder.recyclerView.setOnFlingListener(null);
new GravityPagerSnapHelper(Gravity.START).attachToRecyclerView(holder.recyclerView);
} else { // Top / Bottom
holder.recyclerView.setLayoutManager(new LinearLayoutManager(holder
.recyclerView.getContext()));
holder.recyclerView.setOnFlingListener(null);
new GravitySnapHelper(snap.getGravity()).attachToRecyclerView(holder.recyclerView);
}
holder.recyclerView.setAdapter(new Adapter(snap.getGravity() == Gravity.START
|| snap.getGravity() == Gravity.END
|| snap.getGravity() == Gravity.CENTER_HORIZONTAL,
snap.getGravity() == Gravity.CENTER, snap.getApps()));
}
项目:android-study
文件:SnapAdapter.java
@Override public void onBindViewHolder(ViewHolder holder, int position) {
Snap snap = mSnaps.get(position);
holder.snapTextView.setText(snap.getText());
if (snap.getGravity() == Gravity.START || snap.getGravity() == Gravity.END) {
holder.recyclerView.setLayoutManager(
new LinearLayoutManager(holder.recyclerView.getContext(), LinearLayoutManager.HORIZONTAL,
false));
holder.recyclerView.setOnFlingListener(null);
new GravitySnapHelper(snap.getGravity()).attachToRecyclerView(holder.recyclerView);
} else if (snap.getGravity() == Gravity.CENTER_HORIZONTAL
|| snap.getGravity() == Gravity.CENTER_VERTICAL
|| snap.getGravity() == Gravity.CENTER) {
holder.recyclerView.setLayoutManager(new LinearLayoutManager(holder.recyclerView.getContext(),
snap.getGravity() == Gravity.CENTER_HORIZONTAL ? LinearLayoutManager.HORIZONTAL
: LinearLayoutManager.VERTICAL, false));
holder.recyclerView.setOnFlingListener(null);
new LinearSnapHelper().attachToRecyclerView(holder.recyclerView);
} else { // Top / Bottom
holder.recyclerView.setLayoutManager(
new LinearLayoutManager(holder.recyclerView.getContext()));
holder.recyclerView.setOnFlingListener(null);
new GravitySnapHelper(snap.getGravity()).attachToRecyclerView(holder.recyclerView);
}
holder.recyclerView.setAdapter(new Adapter(snap.getGravity() == Gravity.START
|| snap.getGravity() == Gravity.END
|| snap.getGravity() == Gravity.CENTER_HORIZONTAL, snap.getApps()));
}
项目:RetroMusicPlayer
文件:HomeAdapter.java
private void parseAllSections(int i, ViewHolder viewholder) {
if (viewholder.recyclerView != null) {
SnapHelper snapHelper = new LinearSnapHelper();
viewholder.recyclerView.setOnFlingListener(null);
snapHelper.attachToRecyclerView(viewholder.recyclerView);
ArrayList arrayList = (ArrayList) dataSet.get(i);
if (arrayList.isEmpty()) {
return;
}
Object something = arrayList.get(0);
if (something instanceof Artist) {
viewholder.recyclerView.setLayoutManager(new GridLayoutManager(activity, 1, GridLayoutManager.HORIZONTAL, false));
viewholder.recyclerView.setItemAnimator(new DefaultItemAnimator());
viewholder.recyclerView.setAdapter(new ArtistAdapter(activity, (ArrayList<Artist>) arrayList, R.layout.item_artist, false, null));
} else if (something instanceof Album) {
viewholder.recyclerView.setLayoutManager(new GridLayoutManager(activity, 1, GridLayoutManager.HORIZONTAL, false));
viewholder.recyclerView.setItemAnimator(new DefaultItemAnimator());
viewholder.recyclerView.setAdapter(new AlbumAdapter(activity, (ArrayList<Album>) arrayList, R.layout.pager_item, false, null));
} else if (something instanceof Playlist) {
viewholder.recyclerView.setLayoutManager(new LinearLayoutManager(activity));
viewholder.recyclerView.setItemAnimator(new DefaultItemAnimator());
viewholder.recyclerView.setAdapter(new PlaylistAdapter(activity, (ArrayList<Playlist>) arrayList, R.layout.item_list, null));
} else if (something instanceof Song) {
GridLayoutManager layoutManager = new GridLayoutManager(activity, 1, LinearLayoutManager.HORIZONTAL, false);
viewholder.recyclerView.setLayoutManager(layoutManager);
viewholder.recyclerView.setItemAnimator(new DefaultItemAnimator());
viewholder.recyclerView.setAdapter(new SongAdapter(activity, (ArrayList<Song>) arrayList, R.layout.item_image, false, null));
}
}
}
项目:Recyclerview-Gallery
文件:ScrollManager.java
/**
* 初始化SnapHelper
*
* @param helper
*/
public void initSnapHelper(int helper) {
switch (helper) {
case GalleryRecyclerView.LinearySnapHelper:
mLinearySnapHelper = new LinearSnapHelper();
mLinearySnapHelper.attachToRecyclerView(mGalleryRecyclerView);
break;
case GalleryRecyclerView.PagerSnapHelper:
mPagerSnapHelper = new PagerSnapHelper();
mPagerSnapHelper.attachToRecyclerView(mGalleryRecyclerView);
break;
}
}
项目:gamer-inside
文件:DiscoverGamesFragment.java
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_discover_games, container, false);
GridLayoutManager popularGamesLayoutManager = new GridLayoutManager(getContext(), 1, GridLayoutManager.HORIZONTAL, false);
GridLayoutManager mostAnticipatedGamesLayoutManager = new GridLayoutManager(getContext(), 1, GridLayoutManager.HORIZONTAL, false);
GridLayoutManager upcomingGamesLayoutManager = new GridLayoutManager(getContext(), 1, GridLayoutManager.HORIZONTAL, false);
RecyclerView popularGamesRecyclerView = (RecyclerView) view.findViewById(R.id.popular_games_list);
RecyclerView mostAnticipatedGamesRecyclerView = (RecyclerView) view.findViewById(R.id.most_anticipated_games_list);
RecyclerView upcomingGamesRecyclerView = (RecyclerView) view.findViewById(R.id.upcoming_games_list);
mContent = (RelativeLayout) view.findViewById(R.id.content);
mContentLoading = (RelativeLayout) view.findViewById(R.id.content_loading_progress);
// TODO: check https://github.com/rubensousa/RecyclerViewSnap
SnapHelper helper = new LinearSnapHelper();
helper.attachToRecyclerView(popularGamesRecyclerView);
helper.attachToRecyclerView(mostAnticipatedGamesRecyclerView);
helper.attachToRecyclerView(upcomingGamesRecyclerView);
popularGamesRecyclerView.setLayoutManager(popularGamesLayoutManager);
popularGamesRecyclerView.setAdapter(mPopularGamesAdapter);
mostAnticipatedGamesRecyclerView.setLayoutManager(mostAnticipatedGamesLayoutManager);
mostAnticipatedGamesRecyclerView.setAdapter(mMostAnticipatedGamesAdapter);
upcomingGamesRecyclerView.setLayoutManager(upcomingGamesLayoutManager);
upcomingGamesRecyclerView.setAdapter(mUpcomingGamesAdapter);
return view;
}
项目:Villains-and-Heroes
文件:CharacterActivity.java
private void setupSectionView(RecyclerView recyclerView, @SectionVO.Type int type) {
recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
recyclerView.setNestedScrollingEnabled(false);
recyclerView.setHasFixedSize(true);
SectionAdapter adapter = new SectionAdapter(this, type, this);
recyclerView.setAdapter(adapter);
SnapHelper snapHelper = new LinearSnapHelper();
snapHelper.attachToRecyclerView(recyclerView);
}
项目:GankLock
文件:DailyGankFragment.java
@Override
protected void initView() {
mActivity = (AppCompatActivity) mContext;
mToolbar = (Toolbar) mContext.findViewById(R.id.toolbar_daily_fragment);
mActivity.setSupportActionBar(mToolbar);
mActivity.setTitle(R.string.bottom_bar_gank);
mToolbar.inflateMenu(R.menu.main_menu);
mRecyclerView = (RecyclerView) mContext.findViewById(R.id.daily_recycler_view);
LinearLayoutManager manager = new LinearLayoutManager(mContext);
manager.setOrientation(LinearLayoutManager.HORIZONTAL);
mRecyclerView.setLayoutManager(manager);
mRecyclerView.setItemAnimator(new DefaultItemAnimator());
mSnapHelper = new LinearSnapHelper();
if (mRecyclerView.getOnFlingListener() == null) {
mSnapHelper.attachToRecyclerView(mRecyclerView);
}
mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
LinearLayoutManager layoutManager
= (LinearLayoutManager) recyclerView.getLayoutManager();
int totalItemCount = layoutManager.getItemCount();
int lastVisibleItem = layoutManager.findLastVisibleItemPosition();
if (totalItemCount <= lastVisibleItem + 1) {
loadDailyData(mPage+=1);
}
}
});
mProgressBar = (ProgressBar) mContext.findViewById(R.id.daily_loading_progress_bar);
mFailureTextView = (TextView) mContext.findViewById(R.id.daily_get_failure_tip);
}
项目:RecyclerViewSnap
文件:SnapAdapter.java
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
Snap snap = mSnaps.get(position);
holder.snapTextView.setText(snap.getText());
if (snap.getGravity() == Gravity.START || snap.getGravity() == Gravity.END) {
holder.recyclerView.setLayoutManager(new LinearLayoutManager(holder
.recyclerView.getContext(), LinearLayoutManager.HORIZONTAL, false));
new GravitySnapHelper(snap.getGravity(), false, this).attachToRecyclerView(holder.recyclerView);
} else if (snap.getGravity() == Gravity.CENTER_HORIZONTAL ||
snap.getGravity() == Gravity.CENTER_VERTICAL) {
holder.recyclerView.setLayoutManager(new LinearLayoutManager(holder
.recyclerView.getContext(), snap.getGravity() == Gravity.CENTER_HORIZONTAL ?
LinearLayoutManager.HORIZONTAL : LinearLayoutManager.VERTICAL, false));
new LinearSnapHelper().attachToRecyclerView(holder.recyclerView);
} else if (snap.getGravity() == Gravity.CENTER) { // Pager snap
holder.recyclerView.setLayoutManager(new LinearLayoutManager(holder
.recyclerView.getContext(), LinearLayoutManager.HORIZONTAL, false));
new GravityPagerSnapHelper(Gravity.START).attachToRecyclerView(holder.recyclerView);
} else { // Top / Bottom
holder.recyclerView.setLayoutManager(new LinearLayoutManager(holder
.recyclerView.getContext()));
new GravitySnapHelper(snap.getGravity()).attachToRecyclerView(holder.recyclerView);
}
holder.recyclerView.setAdapter(new Adapter(snap.getGravity() == Gravity.START
|| snap.getGravity() == Gravity.END
|| snap.getGravity() == Gravity.CENTER_HORIZONTAL,
snap.getGravity() == Gravity.CENTER, snap.getApps()));
}
项目:braintree-android-drop-in
文件:DropInActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.bt_drop_in_activity);
mBottomSheet = findViewById(R.id.bt_dropin_bottom_sheet);
mLoadingViewSwitcher = findViewById(R.id.bt_loading_view_switcher);
mSupportedPaymentMethodsHeader = findViewById(R.id.bt_supported_payment_methods_header);
mSupportedPaymentMethodListView = findViewById(R.id.bt_supported_payment_methods);
mVaultedPaymentMethodsContainer = findViewById(R.id.bt_vaulted_payment_methods_wrapper);
mVaultedPaymentMethodsView = findViewById(R.id.bt_vaulted_payment_methods);
mVaultedPaymentMethodsView.setLayoutManager(new LinearLayoutManager(this,
LinearLayoutManager.HORIZONTAL, false));
new LinearSnapHelper().attachToRecyclerView(mVaultedPaymentMethodsView);
try {
mBraintreeFragment = getBraintreeFragment();
} catch (InvalidArgumentException e) {
finish(e);
return;
}
if (savedInstanceState != null) {
mSheetSlideUpPerformed = savedInstanceState.getBoolean(EXTRA_SHEET_SLIDE_UP_PERFORMED,
false);
mDeviceData = savedInstanceState.getString(EXTRA_DEVICE_DATA);
}
slideUp();
}
项目:paged-cardview-android
文件:MainActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// 1
this.cardRecyclerView = (RecyclerView)findViewById(R.id.recycler_view);
this.cardRecyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
this.cardAdapter = new CardAdapter(this);
this.cardRecyclerView.setAdapter(this.cardAdapter);
// 4
LinearSnapHelper snapHelper = new LinearSnapHelper();
snapHelper.attachToRecyclerView(this.cardRecyclerView);
this.cardRecyclerView.setOnFlingListener(snapHelper);
this.cardRecyclerView.addItemDecoration(new VerticalOffsetDecoration(this)); // 9
// 2
List<LocationInformation> locations = new ArrayList<>();
locations.add(LocationInformation.create("Appvation Pty. Ltd.", "202/147 Pirie St, Adelaide"));
locations.add(LocationInformation.create("Appvation Pty. Ltd.", "202/147 Pirie St, Adelaide"));
locations.add(LocationInformation.create("Appvation Pty. Ltd.", "202/147 Pirie St, Adelaide"));
locations.add(LocationInformation.create("Appvation Pty. Ltd.", "202/147 Pirie St, Adelaide"));
// 3
this.cardAdapter.setItems(locations);
}
项目:Nearby-Shops-End-User-Android-app
文件:ShopMapFragment.java
void setupRecyclerView()
{
adapter = new AdapterHorizontal(dataset,getActivity(),this);
reviewsList.setAdapter(adapter);
linearLayoutManager = new LinearLayoutManager(getActivity(),LinearLayoutManager.HORIZONTAL,false);
reviewsList.setLayoutManager(linearLayoutManager);
SnapHelper helper = new LinearSnapHelper();
// helper.onFling(10,10);
helper.attachToRecyclerView(reviewsList);
reviewsList.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
if(dataset!=null && dataset.size()>0)
{
int position = linearLayoutManager.findFirstVisibleItemPosition();
if(position!=RecyclerView.NO_POSITION)
{
notifyListItemClick(position);
}
}
}
});
}
项目:CutoutViewIndicator
文件:VerticalDotsFragment.java
private void initRecycler(@NonNull RecyclerView recyclerView) {
LinearLayoutManager layoutManager = new LinearLayoutManager(recyclerView.getContext(), VERTICAL, false);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setAdapter(new MultiColoredAdapter(getChildQuantity(), getChildLayoutId()));
SnapHelper helper = new LinearSnapHelper();
helper.attachToRecyclerView(recyclerView);
}
项目:mapbox-android-demo
文件:DirectionsMatrixApiActivity.java
private void initRecyclerView() {
matrixApiLocationRecyclerViewAdapter = new MatrixApiLocationRecyclerViewAdapter(this,
matrixLocationList);
recyclerView.setLayoutManager(new LinearLayoutManager(getApplicationContext(),
LinearLayoutManager.HORIZONTAL, true));
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setAdapter(matrixApiLocationRecyclerViewAdapter);
SnapHelper snapHelper = new LinearSnapHelper();
snapHelper.attachToRecyclerView(recyclerView);
}
项目:mapbox-android-demo
文件:RecyclerViewOnMapActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Mapbox access token is configured here. This needs to be called either in your application
// object or in the same activity which contains the mapview.
Mapbox.getInstance(this, getString(R.string.access_token));
// This contains the MapView in XML and needs to be called after the access token is configured.
setContentView(R.layout.activity_lab_recycler_view_on_map);
recyclerView = (RecyclerView) findViewById(R.id.rv_on_top_of_map);
Toast.makeText(this, R.string.toast_instruction, Toast.LENGTH_SHORT).show();
// Initialize the map view
mapView = (MapView) findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(MapboxMap mapboxMap) {
RecyclerViewOnMapActivity.this.mapboxMap = mapboxMap;
setUpLists();
// Set up the recyclerView
locationAdapter = new LocationRecyclerViewAdapter(locationList, mapboxMap);
recyclerView.setLayoutManager(new LinearLayoutManager(getApplicationContext(),
LinearLayoutManager.HORIZONTAL, true));
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setAdapter(locationAdapter);
SnapHelper snapHelper = new LinearSnapHelper();
snapHelper.attachToRecyclerView(recyclerView);
}
});
}
项目:-Pod
文件:OptionFragment.java
private void initView() {
activity = (MainActivity) getActivity();
ArrayList<HashMap<String, Object>> maps = initData();
new LinearSnapHelper().attachToRecyclerView(optionRvMenu);
LinearLayoutManager layoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false);
optionRvMenu.setLayoutManager(layoutManager);
OptionRvAdapter adapter = new OptionRvAdapter(getContext(), maps);
optionRvMenu.setAdapter(adapter);
adapter.setOnItemClickListener(this);
register();
//如果在播放直接到播放
if (musicService.isPlay()) activity.showFragment(4);
handler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what) {
case 0: //Ok
itemClick(selPosition);
break;
case 1: //上一个
optionRvMenu.smoothScrollToPosition(0);
selPosition = 0;
break;
case 2: //下一个
optionRvMenu.smoothScrollToPosition(1);
selPosition = 1;
break;
case 3:
activity.showFragment(1);
break;
case 4:
musicService.pausePlay();
break;
}
}
};
}
项目:easyfilemanager
文件:HomeFragment.java
private void showRecents() {
final RootInfo root = roots.getRecentsRoot();
recents.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
openRoot(root);
}
});
mRecentsAdapter = new RecentsAdapter(getActivity(), null);
mRecentsAdapter.setOnItemClickListener(new RecentsAdapter.OnItemClickListener() {
@Override
public void onItemClick(RecentsAdapter.ViewHolder item, int position) {
openDocument(item.mDocumentInfo);
}
});
mRecentsRecycler.setAdapter(mRecentsAdapter);
LinearSnapHelper helper = new LinearSnapHelper();
helper.attachToRecyclerView(mRecentsRecycler);
final BaseActivity.State state = getDisplayState(this);
mCallbacks = new LoaderManager.LoaderCallbacks<DirectoryResult>() {
@Override
public Loader<DirectoryResult> onCreateLoader(int id, Bundle args) {
final RootsCache roots = DocumentsApplication.getRootsCache(getActivity());
return new RecentLoader(getActivity(), roots, state);
}
@Override
public void onLoadFinished(Loader<DirectoryResult> loader, DirectoryResult result) {
if (!isAdded())
return;
if(null == result.cursor || (null != result.cursor && result.cursor.getCount() == 0)) {
recents_container.setVisibility(View.GONE);
} else {
//recents_container.setVisibility(View.VISIBLE);
mRecentsAdapter.swapCursor(new LimitCursorWrapper(result.cursor, MAX_RECENT_COUNT));
}
}
@Override
public void onLoaderReset(Loader<DirectoryResult> loader) {
mRecentsAdapter.swapCursor(null);
}
};
getLoaderManager().restartLoader(mLoaderId, null, mCallbacks);
}
项目:PopCorn
文件:TVShowDetailActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tvshow_detail);
mToolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
setTitle("");
Intent receivedIntent = getIntent();
mTVShowId = receivedIntent.getIntExtra(Constant.TV_SHOW_ID, -1);
if (mTVShowId == -1) finish();
mCollapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.toolbar_layout);
mAppBarLayout = (AppBarLayout) findViewById(R.id.app_bar);
mPosterWidth = (int) (getResources().getDisplayMetrics().widthPixels * 0.25);
mPosterHeight = (int) (mPosterWidth / 0.66);
mBackdropWidth = getResources().getDisplayMetrics().widthPixels;
mBackdropHeight = (int) (mBackdropWidth / 1.77);
mTVShowTabLayout = (ConstraintLayout) findViewById(R.id.layout_toolbar_tv_show);
mTVShowTabLayout.getLayoutParams().height = mBackdropHeight + (int) (mPosterHeight * 0.9);
mPosterImageView = (ImageView) findViewById(R.id.image_view_poster);
mPosterImageView.getLayoutParams().width = mPosterWidth;
mPosterImageView.getLayoutParams().height = mPosterHeight;
mPosterProgressBar = (AVLoadingIndicatorView) findViewById(R.id.progress_bar_poster);
mPosterProgressBar.setVisibility(View.GONE);
mBackdropImageView = (ImageView) findViewById(R.id.image_view_backdrop);
mBackdropImageView.getLayoutParams().height = mBackdropHeight;
mBackdropProgressBar = (AVLoadingIndicatorView) findViewById(R.id.progress_bar_backdrop);
mBackdropProgressBar.setVisibility(View.GONE);
mTitleTextView = (TextView) findViewById(R.id.text_view_title_tv_show_detail);
mGenreTextView = (TextView) findViewById(R.id.text_view_genre_tv_show_detail);
mYearTextView = (TextView) findViewById(R.id.text_view_year_tv_show_detail);
mFavImageButton = (ImageButton) findViewById(R.id.image_button_fav_tv_show_detail);
mShareImageButton = (ImageButton) findViewById(R.id.image_button_share_tv_show_detail);
mRatingLayout = (LinearLayout) findViewById(R.id.layout_rating_tv_show_detail);
mRatingTextView = (TextView) findViewById(R.id.text_view_rating_tv_show_detail);
mOverviewTextView = (TextView) findViewById(R.id.text_view_overview_tv_show_detail);
mOverviewReadMoreTextView = (TextView) findViewById(R.id.text_view_read_more_tv_show_detail);
mDetailsLayout = (LinearLayout) findViewById(R.id.layout_details_tv_show_detail);
mDetailsTextView = (TextView) findViewById(R.id.text_view_details_tv_show_detail);
mVideosTextView = (TextView) findViewById(R.id.text_view_trailer_tv_show_detail);
mVideosRecyclerView = (RecyclerView) findViewById(R.id.recycler_view_trailers_tv_show_detail);
(new LinearSnapHelper()).attachToRecyclerView(mVideosRecyclerView);
mVideos = new ArrayList<>();
mVideosAdapter = new VideoAdapter(TVShowDetailActivity.this, mVideos);
mVideosRecyclerView.setAdapter(mVideosAdapter);
mVideosRecyclerView.setLayoutManager(new LinearLayoutManager(TVShowDetailActivity.this, LinearLayoutManager.HORIZONTAL, false));
mHorizontalLine = (View) findViewById(R.id.view_horizontal_line);
mCastTextView = (TextView) findViewById(R.id.text_view_cast_tv_show_detail);
mCastRecyclerView = (RecyclerView) findViewById(R.id.recycler_view_cast_tv_show_detail);
mCasts = new ArrayList<>();
mCastAdapter = new TVShowCastAdapter(TVShowDetailActivity.this, mCasts);
mCastRecyclerView.setAdapter(mCastAdapter);
mCastRecyclerView.setLayoutManager(new LinearLayoutManager(TVShowDetailActivity.this, LinearLayoutManager.HORIZONTAL, false));
mSimilarTVShowsTextView = (TextView) findViewById(R.id.text_view_similar_tv_show_detail);
mSimilarTVShowsRecyclerView = (RecyclerView) findViewById(R.id.recycler_view_similar_tv_show_detail);
mSimilarTVShows = new ArrayList<>();
mSimilarTVShowsAdapter = new TVShowBriefsSmallAdapter(TVShowDetailActivity.this, mSimilarTVShows);
mSimilarTVShowsRecyclerView.setAdapter(mSimilarTVShowsAdapter);
mSimilarTVShowsRecyclerView.setLayoutManager(new LinearLayoutManager(TVShowDetailActivity.this, LinearLayoutManager.HORIZONTAL, false));
if (NetworkConnection.isConnected(TVShowDetailActivity.this)) {
isActivityLoaded = true;
loadActivity();
}
}
项目:PopCorn
文件:MovieDetailActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_movie_detail);
mToolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
setTitle("");
Intent receivedIntent = getIntent();
mMovieId = receivedIntent.getIntExtra(Constant.MOVIE_ID, -1);
if (mMovieId == -1) finish();
mCollapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.toolbar_layout);
mAppBarLayout = (AppBarLayout) findViewById(R.id.app_bar);
mPosterWidth = (int) (getResources().getDisplayMetrics().widthPixels * 0.25);
mPosterHeight = (int) (mPosterWidth / 0.66);
mBackdropWidth = getResources().getDisplayMetrics().widthPixels;
mBackdropHeight = (int) (mBackdropWidth / 1.77);
mMovieTabLayout = (ConstraintLayout) findViewById(R.id.layout_toolbar_movie);
mMovieTabLayout.getLayoutParams().height = mBackdropHeight + (int) (mPosterHeight * 0.9);
mPosterImageView = (ImageView) findViewById(R.id.image_view_poster);
mPosterImageView.getLayoutParams().width = mPosterWidth;
mPosterImageView.getLayoutParams().height = mPosterHeight;
mPosterProgressBar = (AVLoadingIndicatorView) findViewById(R.id.progress_bar_poster);
mPosterProgressBar.setVisibility(View.GONE);
mBackdropImageView = (ImageView) findViewById(R.id.image_view_backdrop);
mBackdropImageView.getLayoutParams().height = mBackdropHeight;
mBackdropProgressBar = (AVLoadingIndicatorView) findViewById(R.id.progress_bar_backdrop);
mBackdropProgressBar.setVisibility(View.GONE);
mTitleTextView = (TextView) findViewById(R.id.text_view_title_movie_detail);
mGenreTextView = (TextView) findViewById(R.id.text_view_genre_movie_detail);
mYearTextView = (TextView) findViewById(R.id.text_view_year_movie_detail);
mFavImageButton = (ImageButton) findViewById(R.id.image_button_fav_movie_detail);
mShareImageButton = (ImageButton) findViewById(R.id.image_button_share_movie_detail);
mRatingLayout = (LinearLayout) findViewById(R.id.layout_rating_movie_detail);
mRatingTextView = (TextView) findViewById(R.id.text_view_rating_movie_detail);
mOverviewTextView = (TextView) findViewById(R.id.text_view_overview_movie_detail);
mOverviewReadMoreTextView = (TextView) findViewById(R.id.text_view_read_more_movie_detail);
mDetailsLayout = (LinearLayout) findViewById(R.id.layout_details_movie_detail);
mDetailsTextView = (TextView) findViewById(R.id.text_view_details_movie_detail);
mTrailerTextView = (TextView) findViewById(R.id.text_view_trailer_movie_detail);
mTrailerRecyclerView = (RecyclerView) findViewById(R.id.recycler_view_trailers_movie_detail);
(new LinearSnapHelper()).attachToRecyclerView(mTrailerRecyclerView);
mTrailers = new ArrayList<>();
mTrailerAdapter = new VideoAdapter(MovieDetailActivity.this, mTrailers);
mTrailerRecyclerView.setAdapter(mTrailerAdapter);
mTrailerRecyclerView.setLayoutManager(new LinearLayoutManager(MovieDetailActivity.this, LinearLayoutManager.HORIZONTAL, false));
mHorizontalLine = (View) findViewById(R.id.view_horizontal_line);
mCastTextView = (TextView) findViewById(R.id.text_view_cast_movie_detail);
mCastRecyclerView = (RecyclerView) findViewById(R.id.recycler_view_cast_movie_detail);
mCasts = new ArrayList<>();
mCastAdapter = new MovieCastsAdapter(MovieDetailActivity.this, mCasts);
mCastRecyclerView.setAdapter(mCastAdapter);
mCastRecyclerView.setLayoutManager(new LinearLayoutManager(MovieDetailActivity.this, LinearLayoutManager.HORIZONTAL, false));
mSimilarMoviesTextView = (TextView) findViewById(R.id.text_view_similar_movie_detail);
mSimilarMoviesRecyclerView = (RecyclerView) findViewById(R.id.recycler_view_similar_movie_detail);
mSimilarMovies = new ArrayList<>();
mSimilarMoviesAdapter = new MovieBriefsSmallAdapter(MovieDetailActivity.this, mSimilarMovies);
mSimilarMoviesRecyclerView.setAdapter(mSimilarMoviesAdapter);
mSimilarMoviesRecyclerView.setLayoutManager(new LinearLayoutManager(MovieDetailActivity.this, LinearLayoutManager.HORIZONTAL, false));
if (NetworkConnection.isConnected(MovieDetailActivity.this)) {
isActivityLoaded = true;
loadActivity();
}
}
项目:FireFiles
文件:HomeFragment.java
private void showRecents() {
final RootInfo root = roots.getRecentsRoot();
recents.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
openRoot(root);
}
});
mRecentsAdapter = new RecentsAdapter(getActivity(), null);
mRecentsAdapter.setOnItemClickListener(new RecentsAdapter.OnItemClickListener() {
@Override
public void onItemClick(RecentsAdapter.ViewHolder item, int position) {
openDocument(item.mDocumentInfo);
}
});
mRecentsRecycler.setAdapter(mRecentsAdapter);
LinearSnapHelper helper = new LinearSnapHelper();
helper.attachToRecyclerView(mRecentsRecycler);
final BaseActivity.State state = getDisplayState(this);
mCallbacks = new LoaderManager.LoaderCallbacks<DirectoryResult>() {
@Override
public Loader<DirectoryResult> onCreateLoader(int id, Bundle args) {
final RootsCache roots = DocumentsApplication.getRootsCache(getActivity());
return new RecentLoader(getActivity(), roots, state);
}
@Override
public void onLoadFinished(Loader<DirectoryResult> loader, DirectoryResult result) {
if (!isAdded())
return;
if(null == result.cursor || (null != result.cursor && result.cursor.getCount() == 0)) {
recents_container.setVisibility(View.GONE);
} else {
//recents_container.setVisibility(View.VISIBLE);
mRecentsAdapter.swapCursor(new LimitCursorWrapper(result.cursor, MAX_RECENT_COUNT));
}
}
@Override
public void onLoaderReset(Loader<DirectoryResult> loader) {
mRecentsAdapter.swapCursor(null);
}
};
getLoaderManager().restartLoader(mLoaderId, null, mCallbacks);
}
项目:simple-share-android
文件:HomeFragment.java
private void showRecents() {
final RootInfo root = roots.getRecentsRoot();
recents.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
openRoot(root);
}
});
mRecentsAdapter = new RecentsAdapter(getActivity(), null);
mRecentsAdapter.setOnItemClickListener(new RecentsAdapter.OnItemClickListener() {
@Override
public void onItemClick(RecentsAdapter.ViewHolder item, int position) {
openDocument(item.mDocumentInfo);
}
});
mRecentsRecycler.setAdapter(mRecentsAdapter);
LinearSnapHelper helper = new LinearSnapHelper();
helper.attachToRecyclerView(mRecentsRecycler);
final BaseActivity.State state = getDisplayState(this);
mCallbacks = new LoaderManager.LoaderCallbacks<DirectoryResult>() {
@Override
public Loader<DirectoryResult> onCreateLoader(int id, Bundle args) {
final RootsCache roots = DocumentsApplication.getRootsCache(getActivity());
return new RecentLoader(getActivity(), roots, state);
}
@Override
public void onLoadFinished(Loader<DirectoryResult> loader, DirectoryResult result) {
if (!isAdded())
return;
if(null == result.cursor || (null != result.cursor && result.cursor.getCount() == 0)) {
recents_container.setVisibility(View.GONE);
} else {
//recents_container.setVisibility(View.VISIBLE);
mRecentsAdapter.swapCursor(new LimitCursorWrapper(result.cursor, MAX_RECENT_COUNT));
}
}
@Override
public void onLoaderReset(Loader<DirectoryResult> loader) {
mRecentsAdapter.swapCursor(null);
}
};
getLoaderManager().restartLoader(mLoaderId, null, mCallbacks);
}
项目:MangoBloggerAndroidApp
文件:HomeBaseAdapter.java
@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
HomeGroup snap = mSnaps.get(position);
holder.snapTextView.setText(snap.getText());
if (snap.getGravity() == Gravity.START || snap.getGravity() == Gravity.END) {
holder.recyclerView.setLayoutManager(new LinearLayoutManager(holder
.recyclerView.getContext(), LinearLayoutManager.HORIZONTAL, false));
holder.recyclerView.setOnFlingListener(null);
new GravitySnapHelper(snap.getGravity(), false, this).attachToRecyclerView(holder.recyclerView);
} else if (snap.getGravity() == Gravity.CENTER_HORIZONTAL) {
holder.recyclerView.setLayoutManager(new LinearLayoutManager(holder
.recyclerView.getContext(), snap.getGravity() == Gravity.CENTER_HORIZONTAL ?
LinearLayoutManager.HORIZONTAL : LinearLayoutManager.VERTICAL, false));
holder.recyclerView.setOnFlingListener(null);
new LinearSnapHelper().attachToRecyclerView(holder.recyclerView);
} else if (snap.getGravity() == Gravity.CENTER) { // Pager snap
holder.recyclerView.setLayoutManager(new LinearLayoutManager(holder
.recyclerView.getContext(), LinearLayoutManager.HORIZONTAL, false));
holder.recyclerView.setOnFlingListener(null);
new PagerSnapHelper().attachToRecyclerView(holder.recyclerView);
} else { // Top / Bottom
holder.recyclerView.setLayoutManager(new LinearLayoutManager(holder
.recyclerView.getContext()));
holder.recyclerView.setOnFlingListener(null);
new GravitySnapHelper(snap.getGravity()).attachToRecyclerView(holder.recyclerView);
}
HomeItemAdapter itemAdapter = new HomeItemAdapter(mContext, snap.getCardSize(), snap.getApps());
holder.recyclerView.setAdapter(itemAdapter);
itemAdapter.setOnItemClickListener(new HomeItemAdapter.OnItemClickListener() {
@Override
public void itemClick(HomeItem item, int Position) {
if(mContext instanceof HomeActivity) {
if(item.isWebView()) {
((HomeActivity) mContext).attachFragment(WebFragment.newInstance(item.getUrl(), item.getName()), true);
} else {
((HomeActivity) mContext).attachFragment(FirebaseListFragment.newInstance(item.getUrl(), item.getExtra()), true);
}
}
}
});
}
项目:Carousel-Browsing-Example
文件:CarouselActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_carousel);
getSupportActionBar().setElevation(0);
// - Initialize carousel.
final RecyclerView carouselRecyclerView = (RecyclerView) findViewById(R.id.carousel);
final LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
carouselRecyclerView.setLayoutManager(linearLayoutManager);
new LinearSnapHelper().attachToRecyclerView(carouselRecyclerView);
final ItemAdapter itemAdapter = new ItemAdapter(this, ITEMS);
carouselRecyclerView.setAdapter(itemAdapter);
// - Center recycler view first item.
itemAdapter.setOnItemSizeListener(new ItemAdapter.OnItemSizeListener() {
@Override
public void onItemSize(final int size) {
itemAdapter.setOnItemSizeListener(null);
final int padding = (carouselRecyclerView.getMeasuredWidth() - size) / 2;
carouselRecyclerView.setPadding(padding, 0, padding, 0);
carouselRecyclerView.smoothScrollToPosition(0);
}
});
// - On item click...
itemAdapter.setOnItemClickListener(new ItemAdapter.OnItemClickListener() {
@Override
public void onClick(final int position, final ItemAdapter.ViewHolder viewHolder) {
// - If the clicked item is not centered, scroll to it.
final int currentPosition = (linearLayoutManager.findFirstVisibleItemPosition() + linearLayoutManager.findLastVisibleItemPosition()) / 2;
if (currentPosition != position) {
carouselRecyclerView.smoothScrollToPosition(position);
}
// - Else if collapsed, expand it.
else if (itemAdapter.isCollapsed(position)) {
itemAdapter.expandItem(position, viewHolder);
}
// - Else (item centered and expanded), navigate to details.
else {
final ActivityOptions options =
ActivityOptions.makeSceneTransitionAnimation(CarouselActivity.this, viewHolder.picture, viewHolder.picture.getTransitionName());
final Intent intent = new Intent(CarouselActivity.this, DetailsActivity.class);
intent.putExtra(DetailsActivity.EXTRA_ITEM, ITEMS[position]);
startActivity(intent, options.toBundle());
}
}
});
}