use of android.support.v7.widget.helper.ItemTouchHelper.DOWN in project AndroidSlidingUpPanel by umano.
the class ScrollableViewHelper method getScrollableViewScrollPosition.
/**
* Returns the current scroll position of the scrollable view. If this method returns zero or
* less, it means at the scrollable view is in a position such as the panel should handle
* scrolling. If the method returns anything above zero, then the panel will let the scrollable
* view handle the scrolling
*
* @param scrollableView the scrollable view
* @param isSlidingUp whether or not the panel is sliding up or down
* @return the scroll position
*/
public int getScrollableViewScrollPosition(View scrollableView, boolean isSlidingUp) {
if (scrollableView == null)
return 0;
if (scrollableView instanceof ScrollView) {
if (isSlidingUp) {
return scrollableView.getScrollY();
} else {
ScrollView sv = ((ScrollView) scrollableView);
View child = sv.getChildAt(0);
return (child.getBottom() - (sv.getHeight() + sv.getScrollY()));
}
} else if (scrollableView instanceof ListView && ((ListView) scrollableView).getChildCount() > 0) {
ListView lv = ((ListView) scrollableView);
if (lv.getAdapter() == null)
return 0;
if (isSlidingUp) {
View firstChild = lv.getChildAt(0);
// Approximate the scroll position based on the top child and the first visible item
return lv.getFirstVisiblePosition() * firstChild.getHeight() - firstChild.getTop();
} else {
View lastChild = lv.getChildAt(lv.getChildCount() - 1);
// Approximate the scroll position based on the bottom child and the last visible item
return (lv.getAdapter().getCount() - lv.getLastVisiblePosition() - 1) * lastChild.getHeight() + lastChild.getBottom() - lv.getBottom();
}
} else if (scrollableView instanceof RecyclerView && ((RecyclerView) scrollableView).getChildCount() > 0) {
RecyclerView rv = ((RecyclerView) scrollableView);
RecyclerView.LayoutManager lm = rv.getLayoutManager();
if (rv.getAdapter() == null)
return 0;
if (isSlidingUp) {
View firstChild = rv.getChildAt(0);
// Approximate the scroll position based on the top child and the first visible item
return rv.getChildLayoutPosition(firstChild) * lm.getDecoratedMeasuredHeight(firstChild) - lm.getDecoratedTop(firstChild);
} else {
View lastChild = rv.getChildAt(rv.getChildCount() - 1);
// Approximate the scroll position based on the bottom child and the last visible item
return (rv.getAdapter().getItemCount() - 1) * lm.getDecoratedMeasuredHeight(lastChild) + lm.getDecoratedBottom(lastChild) - rv.getBottom();
}
} else {
return 0;
}
}
use of android.support.v7.widget.helper.ItemTouchHelper.DOWN in project NoteText by ViWu.
the class MainMenu method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_menu);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ActionBar actionbar = getSupportActionBar();
initializeToolbar(toolbar, actionbar);
// set up grid and insert new set
gvItems = (GridView) findViewById(R.id.gvItems);
// Represents each item in gridView
Names = new ArrayList<String>();
newSet = new Set();
// set up adapter for grid
itemsAdapter = new ArrayAdapter<String>(MainMenu.this, R.layout.grid_item, Names);
gvItems.setAdapter(itemsAdapter);
setupListViewListener();
// create a floating action button to help the user
FloatingActionButton help = (FloatingActionButton) findViewById(R.id.help);
assert help != null;
help.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Click on the name of the set to edit. Hold down to delete/rename. To add sets, tap the button to the left.", Snackbar.LENGTH_LONG).setAction("Action", null).show();
}
});
// add button: Creates a popup window to type in name of new set
FloatingActionButton add = (FloatingActionButton) findViewById(R.id.add);
assert add != null;
add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View view) {
AlertDialog.Builder alert = new AlertDialog.Builder(MainMenu.this);
final EditText setNameField = new EditText(MainMenu.this);
alert.setMessage("Enter Name of New Set");
alert.setTitle("Create New Set");
alert.setView(setNameField);
setNameField.requestFocus();
final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
setNameField.setFilters(new InputFilter[] { new InputFilter.LengthFilter(25) });
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String itemText = setNameField.getText().toString();
if (itemText.length() > 0) {
fileCreate(itemText, view);
newSet.setName(itemText);
Sets.add(newSet);
gvItems.smoothScrollToPosition(itemsAdapter.getCount() - 1);
setCount++;
} else {
String msg = "Create set failed! Set names need to be at least one character long!";
errorDialog(msg);
}
checkNoSetExists();
imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, InputMethodManager.RESULT_UNCHANGED_SHOWN);
}
});
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, InputMethodManager.RESULT_UNCHANGED_SHOWN);
}
});
alert.show();
}
});
loadInternalStorage();
checkNoSetExists();
}
use of android.support.v7.widget.helper.ItemTouchHelper.DOWN in project iNGAGE by davis123123.
the class ChatArrayAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(final ChatArrayAdapter.ChatViewHolder holder, final int position) {
final ChatMessageHelper chatMessageHelper = (ChatMessageHelper) this.getItem(position);
holder.bind(position);
String userVote = "";
userVote = chatMessageHelper.getUserVote();
// side = chatMessageHelper.getSide();
if (userVote != null) {
if (userVote.equals("up")) {
toggleVote(holder.bUpvote, selectedColorAgree, false);
toggleVote(holder.bDownvote, unselectedColor, true);
} else if (userVote.equals("down")) {
toggleVote(holder.bUpvote, unselectedColor, true);
toggleVote(holder.bDownvote, selectedColorDisagree, false);
}
} else {
toggleVote(holder.bUpvote, unselectedColor, true);
toggleVote(holder.bDownvote, unselectedColor, true);
}
if (holder.avatar.getDrawable() == null) {
Log.d("Upvote state: ", " no avatar");
holder.downloadAvatar();
}
holder.bUpvote.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
itemClickCallback.onUpvoteClick(position);
// MAKE boolean LOL
String prev_voted = "false", vote = "up";
// check if previously voted
if (chatMessageHelper.getUserVote() != null) {
if (chatMessageHelper.getUserVote().equals("down")) {
prev_voted = "true";
itemClickCallback.removeDownvote(position);
}
// remove previous downvote
}
// set user vote to up
chatMessageHelper.setUserVote(vote);
if (chatMessageHelper.getUserVote().equals(vote)) {
toggleVote(holder.bUpvote, selectedColorAgree, false);
toggleVote(holder.bDownvote, unselectedColor, true);
} else {
toggleVote(holder.bUpvote, unselectedColor, true);
toggleVote(holder.bDownvote, unselectedColor, true);
}
// insert into user profile
itemClickCallback.insertVote(position, prev_voted, vote);
}
});
holder.bDownvote.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
itemClickCallback.onDownvoteClick(position);
// MAKE boolean LOL
String prev_voted = "false", vote = "down";
// check if previously voted
if (chatMessageHelper.getUserVote() != null) {
if (chatMessageHelper.getUserVote().equals("up")) {
prev_voted = "true";
itemClickCallback.removeUpvote(position);
}
// remove previous downvote
}
chatMessageHelper.setUserVote(vote);
if (chatMessageHelper.getUserVote().equals(vote)) {
toggleVote(holder.bUpvote, unselectedColor, true);
toggleVote(holder.bDownvote, selectedColorDisagree, false);
} else {
toggleVote(holder.bUpvote, unselectedColor, true);
toggleVote(holder.bDownvote, unselectedColor, true);
}
// insert into user profile
itemClickCallback.insertVote(position, prev_voted, vote);
}
});
holder.avatar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
itemClickCallback.onAvatarClick(position);
}
});
}
use of android.support.v7.widget.helper.ItemTouchHelper.DOWN in project iNGAGE by davis123123.
the class ArchivedFragment method onViewCreated.
@Override
public void onViewCreated(final View view, final Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
threadListRecyclerView = (RecyclerView) rootView.findViewById(R.id.rv_posts);
final LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
threadListRecyclerView.setLayoutManager(layoutManager);
threadListRecyclerView.setAdapter(threadListAdapter);
Log.d("STATE", "serverstring" + json_string);
inflateThreads();
threadListAdapter.setOnLoadMoreListener(new ThreadListAdapter.OnLoadMoreListener() {
@Override
public void onLoadMore() {
Log.d("haint", "Load More");
// threadListAdapter.list.add(null);
// threadListAdapter.notifyItemInserted(threadListAdapter.list.size() - 1);
rowCount += 10;
Thread getJSON = new Thread(new Runnable() {
@Override
public void run() {
getThreadsJSON(rowCount);
while (true) {
if (!threadListAdapter.getLoadStat()) {
Log.d("haint", "Load More222");
break;
}
// no longer loading
}
}
});
getJSON.start();
try {
getJSON.join();
// threadListAdapter.list.remove(threadListAdapter.list.size() - 1);
// threadListAdapter.notifyItemRemoved(threadListAdapter.list.size());
inflateThreads();
} catch (InterruptedException e) {
e.printStackTrace();
}
// getThreadsJSON(rowCount);
// inflateThreads();
/*new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Log.e("haint", "Load More 2");
threadListAdapter.list.remove(threadListAdapter.list.size() - 1);
threadListAdapter.notifyItemRemoved(threadListAdapter.list.size());
rowCount += 10;
getThreadsJSON(rowCount);
inflateThreads();
threadListAdapter.setLoaded();
}
}, 10000);*/
}
});
threadListRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
Log.d("...", "Lastnot Item Wow !");
if (// check for scroll down
dy > 0) {
visibleItemCount = layoutManager.getChildCount();
totalItemCount = layoutManager.getItemCount();
pastVisiblesItems = layoutManager.findFirstVisibleItemPosition();
if (!threadListAdapter.isLoading && (visibleItemCount + pastVisiblesItems) >= totalItemCount) {
// if(mOnLoadMoreListener != null){
Log.d("...", "Last Item Wow !");
threadListAdapter.isLoading = true;
// threadListAdapter.list.add(null);
threadListAdapter.mOnLoadMoreListener.onLoadMore();
// }
// loading = false;
// rowCount += 10;
// getThreadsJSON(rowCount);
// inflateThreads();
// Do pagination.. i.e. fetch new data
}
}
}
});
}
use of android.support.v7.widget.helper.ItemTouchHelper.DOWN in project ChipsLayoutManager by BelooS.
the class VerticalScrollingController method createSmoothScroller.
@Override
public RecyclerView.SmoothScroller createSmoothScroller(@NonNull Context context, final int position, final int timeMs, final AnchorViewState anchor) {
return new LinearSmoothScroller(context) {
/*
* LinearSmoothScroller, at a minimum, just need to know the vector
* (x/y distance) to travel in order to get from the current positioning
* to the target.
*/
@Override
public PointF computeScrollVectorForPosition(int targetPosition) {
int visiblePosition = anchor.getPosition();
// determine scroll up or scroll down needed
return new PointF(0, position > visiblePosition ? 1 : -1);
}
@Override
protected void onTargetFound(View targetView, RecyclerView.State state, Action action) {
super.onTargetFound(targetView, state, action);
int desiredTop = lm.getPaddingTop();
int currentTop = lm.getDecoratedTop(targetView);
int dy = currentTop - desiredTop;
// perform fit animation to move target view at top of layout
action.update(0, dy, timeMs, new LinearInterpolator());
}
};
}
Aggregations