use of android.support.v7.widget.RecyclerView.ViewHolder in project bilibili-android-client by HotBitmapGG.
the class SectionedRecyclerViewAdapter method onCreateViewHolder.
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
RecyclerView.ViewHolder viewHolder = null;
View view = null;
for (Map.Entry<String, Integer> entry : sectionViewTypeNumbers.entrySet()) {
if (viewType >= entry.getValue() && viewType < entry.getValue() + VIEW_TYPE_QTY) {
Section section = sections.get(entry.getKey());
int sectionViewType = viewType - entry.getValue();
switch(sectionViewType) {
case VIEW_TYPE_HEADER:
{
Integer resId = section.getHeaderResourceId();
if (resId == null) {
throw new NullPointerException("Missing 'header' resource id");
}
view = LayoutInflater.from(parent.getContext()).inflate(resId, parent, false);
// get the header viewholder from the section
viewHolder = section.getHeaderViewHolder(view);
break;
}
case VIEW_TYPE_FOOTER:
{
Integer resId = section.getFooterResourceId();
if (resId == null) {
throw new NullPointerException("Missing 'footer' resource id");
}
view = LayoutInflater.from(parent.getContext()).inflate(resId, parent, false);
// get the footer viewholder from the section
viewHolder = section.getFooterViewHolder(view);
break;
}
case VIEW_TYPE_ITEM_LOADED:
{
view = LayoutInflater.from(parent.getContext()).inflate(section.getItemResourceId(), parent, false);
// get the item viewholder from the section
viewHolder = section.getItemViewHolder(view);
break;
}
case VIEW_TYPE_LOADING:
{
Integer resId = section.getLoadingResourceId();
if (resId == null) {
throw new NullPointerException("Missing 'loading state' resource id");
}
view = LayoutInflater.from(parent.getContext()).inflate(resId, parent, false);
// get the loading viewholder from the section
viewHolder = section.getLoadingViewHolder(view);
break;
}
case VIEW_TYPE_FAILED:
{
Integer resId = section.getFailedResourceId();
if (resId == null) {
throw new NullPointerException("Missing 'failed state' resource id");
}
view = LayoutInflater.from(parent.getContext()).inflate(resId, parent, false);
// get the failed load viewholder from the section
viewHolder = section.getFailedViewHolder(view);
break;
}
default:
throw new IllegalArgumentException("Invalid viewType");
}
}
}
return viewHolder;
}
use of android.support.v7.widget.RecyclerView.ViewHolder in project Gadgetbridge by Freeyourgadget.
the class ControlCenterv2 method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
if (GBApplication.isDarkThemeEnabled()) {
setTheme(R.style.GadgetbridgeThemeDark_NoActionBar);
} else {
setTheme(R.style.GadgetbridgeTheme_NoActionBar);
}
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_controlcenterv2);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
launchDiscoveryActivity();
}
});
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.controlcenter_navigation_drawer_open, R.string.controlcenter_navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
//end of material design boilerplate
deviceManager = ((GBApplication) getApplication()).getDeviceManager();
deviceListView = (RecyclerView) findViewById(R.id.deviceListView);
deviceListView.setHasFixedSize(true);
deviceListView.setLayoutManager(new LinearLayoutManager(this));
background = (ImageView) findViewById(R.id.no_items_bg);
deviceList = deviceManager.getDevices();
mGBDeviceAdapter = new GBDeviceAdapterv2(this, deviceList);
deviceListView.setAdapter(this.mGBDeviceAdapter);
ItemTouchHelper swipeToDismissTouchHelper = new ItemTouchHelper(new ItemTouchHelper.SimpleCallback(ItemTouchHelper.LEFT, ItemTouchHelper.RIGHT) {
@Override
public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
if (dX > 50)
dX = 50;
super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
}
@Override
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
GB.toast(getBaseContext(), "onMove", Toast.LENGTH_LONG, GB.ERROR);
return false;
}
@Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
GB.toast(getBaseContext(), "onSwiped", Toast.LENGTH_LONG, GB.ERROR);
}
@Override
public void onChildDrawOver(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
}
});
//uncomment to enable fixed-swipe to reveal more actions
//swipeToDismissTouchHelper.attachToRecyclerView(deviceListView);
registerForContextMenu(deviceListView);
IntentFilter filterLocal = new IntentFilter();
filterLocal.addAction(GBApplication.ACTION_QUIT);
filterLocal.addAction(DeviceManager.ACTION_DEVICES_CHANGED);
LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, filterLocal);
refreshPairedDevices();
/*
* Ask for permission to intercept notifications on first run.
*/
Prefs prefs = GBApplication.getPrefs();
if (prefs.getBoolean("firstrun", true)) {
prefs.getPreferences().edit().putBoolean("firstrun", false).apply();
Intent enableIntent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS");
startActivity(enableIntent);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
checkAndRequestPermissions();
}
ChangeLog cl = new ChangeLog(this);
if (cl.isFirstRun()) {
cl.getLogDialog().show();
}
GBApplication.deviceService().start();
if (GB.isBluetoothEnabled() && deviceList.isEmpty() && Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
startActivity(new Intent(this, DiscoveryActivity.class));
} else {
GBApplication.deviceService().requestDeviceInfo();
}
}
use of android.support.v7.widget.RecyclerView.ViewHolder in project AndroidChromium by JackyAndroid.
the class NewTabPageView method initialize.
/**
* Initializes the NTP. This must be called immediately after inflation, before this object is
* used in any other way.
*
* @param manager NewTabPageManager used to perform various actions when the user interacts
* with the page.
* @param searchProviderHasLogo Whether the search provider has a logo.
* @param scrollPosition The adapter scroll position to initialize to.
*/
public void initialize(NewTabPageManager manager, boolean searchProviderHasLogo, int scrollPosition) {
mManager = manager;
mUiConfig = new UiConfig(this);
ViewStub stub = (ViewStub) findViewById(R.id.new_tab_page_layout_stub);
mUseCardsUi = manager.getSuggestionsSource() != null;
if (mUseCardsUi) {
stub.setLayoutResource(R.layout.new_tab_page_recycler_view);
mRecyclerView = (NewTabPageRecyclerView) stub.inflate();
// Don't attach now, the recyclerView itself will determine when to do it.
mNewTabPageLayout = (NewTabPageLayout) LayoutInflater.from(getContext()).inflate(R.layout.new_tab_page_layout, mRecyclerView, false);
mNewTabPageLayout.setUseCardsUiEnabled(mUseCardsUi);
mRecyclerView.setAboveTheFoldView(mNewTabPageLayout);
// Tailor the LayoutParams for the snippets UI, as the configuration in the XML is
// made for the ScrollView UI.
ViewGroup.LayoutParams params = mNewTabPageLayout.getLayoutParams();
params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
mRecyclerView.setItemAnimator(new DefaultItemAnimator() {
@Override
public void onAnimationFinished(ViewHolder viewHolder) {
super.onAnimationFinished(viewHolder);
// When removing sections, because the animations are all translations, the
// scroll events don't fire and we can get in the situation where the toolbar
// buttons disappear.
updateSearchBoxOnScroll();
}
});
} else {
stub.setLayoutResource(R.layout.new_tab_page_scroll_view);
mScrollView = (NewTabPageScrollView) stub.inflate();
mScrollView.setBackgroundColor(NtpStyleUtils.getBackgroundColorResource(getResources(), false));
mScrollView.enableBottomShadow(SHADOW_COLOR);
mNewTabPageLayout = (NewTabPageLayout) findViewById(R.id.ntp_content);
}
mMostVisitedDesign = new MostVisitedDesign(getContext());
mMostVisitedLayout = (MostVisitedLayout) mNewTabPageLayout.findViewById(R.id.most_visited_layout);
mMostVisitedDesign.initMostVisitedLayout(searchProviderHasLogo);
mSearchProviderLogoView = (LogoView) mNewTabPageLayout.findViewById(R.id.search_provider_logo);
mSearchBoxView = (ViewGroup) mNewTabPageLayout.findViewById(R.id.search_box);
mNoSearchLogoSpacer = mNewTabPageLayout.findViewById(R.id.no_search_logo_spacer);
initializeSearchBoxTextView();
initializeVoiceSearchButton();
initializeBottomToolbar();
mNewTabPageLayout.addOnLayoutChangeListener(this);
setSearchProviderHasLogo(searchProviderHasLogo);
mPendingLoadTasks++;
mManager.setMostVisitedURLsObserver(this, mMostVisitedDesign.getNumberOfTiles(searchProviderHasLogo));
// Set up snippets
if (mUseCardsUi) {
mNewTabPageAdapter = NewTabPageAdapter.create(mManager, mNewTabPageLayout, mUiConfig);
mRecyclerView.setAdapter(mNewTabPageAdapter);
mRecyclerView.scrollToPosition(scrollPosition);
if (CardsVariationParameters.isScrollBelowTheFoldEnabled()) {
int searchBoxHeight = NtpStyleUtils.getSearchBoxHeight(getResources());
mRecyclerView.getLinearLayoutManager().scrollToPositionWithOffset(mNewTabPageAdapter.getFirstHeaderPosition(), searchBoxHeight);
}
// Set up swipe-to-dismiss
ItemTouchHelper helper = new ItemTouchHelper(mNewTabPageAdapter.getItemTouchCallbacks());
helper.attachToRecyclerView(mRecyclerView);
mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
private boolean mScrolledOnce = false;
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
if (newState != RecyclerView.SCROLL_STATE_DRAGGING)
return;
RecordUserAction.record("MobileNTP.Snippets.Scrolled");
if (mScrolledOnce)
return;
mScrolledOnce = true;
NewTabPageUma.recordSnippetAction(NewTabPageUma.SNIPPETS_ACTION_SCROLLED);
}
});
initializeSearchBoxRecyclerViewScrollHandling();
} else {
initializeSearchBoxScrollHandling();
}
}
use of android.support.v7.widget.RecyclerView.ViewHolder in project AndroidChromium by JackyAndroid.
the class NewTabPageRecyclerView method dismissItemWithAnimation.
/**
* Animates the card being swiped to the right as if the user had dismissed it. Any changes to
* the animation here should be reflected also in
* {@link #updateViewStateForDismiss(float, ViewHolder)} and reset in
* {@link CardViewHolder#onBindViewHolder()}.
* @param suggestion The item to be dismissed.
*/
public void dismissItemWithAnimation(SnippetArticle suggestion) {
// We need to recompute the position, as it might have changed.
final int position = getNewTabPageAdapter().getSuggestionPosition(suggestion);
if (position == RecyclerView.NO_POSITION) {
// The item does not exist anymore, so ignore.
return;
}
final View itemView = mLayoutManager.findViewByPosition(position);
if (itemView == null) {
// The view is not visible anymore, skip the animation.
getNewTabPageAdapter().dismissItem(position);
return;
}
final ViewHolder viewHolder = getChildViewHolder(itemView);
if (!((NewTabPageViewHolder) viewHolder).isDismissable()) {
// The item is not dismissable (anymore), so ignore.
return;
}
AnimatorSet animation = new AnimatorSet();
animation.playTogether(ObjectAnimator.ofFloat(itemView, View.ALPHA, 0f), ObjectAnimator.ofFloat(itemView, View.TRANSLATION_X, (float) itemView.getWidth()));
animation.setDuration(DISMISS_ANIMATION_TIME_MS);
animation.setInterpolator(DISMISS_INTERPOLATOR);
animation.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationStart(Animator animation) {
NewTabPageRecyclerView.this.onItemDismissStarted(viewHolder);
}
@Override
public void onAnimationEnd(Animator animation) {
getNewTabPageAdapter().dismissItem(position);
NewTabPageRecyclerView.this.onItemDismissFinished(viewHolder);
}
});
animation.start();
}
use of android.support.v7.widget.RecyclerView.ViewHolder in project AndroidChromium by JackyAndroid.
the class NewTabPageRecyclerView method onLayout.
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
int numberViews = getChildCount();
for (int i = 0; i < numberViews; ++i) {
View view = getChildAt(i);
NewTabPageViewHolder viewHolder = (NewTabPageViewHolder) getChildViewHolder(view);
if (viewHolder == null)
return;
viewHolder.updateLayoutParams();
}
super.onLayout(changed, l, t, r, b);
}
Aggregations