use of android.support.v7.widget.helper.ItemTouchHelper.END in project SuperSLiM by TonicArtos.
the class LayoutManager method scrollVerticallyBy.
@Override
public int scrollVerticallyBy(int dy, RecyclerView.Recycler recycler, RecyclerView.State state) {
int numChildren = getChildCount();
if (numChildren == 0) {
return 0;
}
LayoutState layoutState = new LayoutState(this, recycler, state);
final Direction direction = dy > 0 ? Direction.END : Direction.START;
final boolean isDirectionEnd = direction == Direction.END;
final int height = getHeight();
final int leadingEdge = isDirectionEnd ? height + dy : dy;
// from the bottom up.
if (isDirectionEnd) {
final View end = getAnchorAtEnd();
LayoutParams params = (LayoutParams) end.getLayoutParams();
SectionLayoutManager slm = getSlm(params);
final int endEdge = slm.getLowestEdge(params.getTestedFirstPosition(), getChildCount() - 1, getDecoratedBottom(end));
if (endEdge < height - getPaddingBottom() && getPosition(end) == (state.getItemCount() - 1)) {
return 0;
}
}
final int fillEdge = fillUntil(leadingEdge, direction, layoutState);
final int delta;
if (isDirectionEnd) {
// Add padding so we scroll to inset area at scroll end.
int fillDelta = fillEdge - height + getPaddingBottom();
delta = fillDelta < dy ? fillDelta : dy;
} else {
int fillDelta = fillEdge - getPaddingTop();
delta = fillDelta > dy ? fillDelta : dy;
}
if (delta != 0) {
offsetChildrenVertical(-delta);
trimTail(isDirectionEnd ? Direction.START : Direction.END, layoutState);
}
layoutState.recycleCache();
return delta;
}
use of android.support.v7.widget.helper.ItemTouchHelper.END in project SuperSLiM by TonicArtos.
the class Utils method doOverscrollTest.
/**
* Perform an overscroll test.
*
* @param offset Offset to apply to simulate overscroll; dx, dy.
* @param padding Padding values; l, t, r, b.
* @param expected Expected bounds; l, t, r, b.
* @param adapter Adapter to use.
* @param mLayoutManager Layout manager to use.
* @param mRecyclerView RecyclerView to use.
*/
public static void doOverscrollTest(int[] offset, int[] padding, boolean expected, RecyclerView.Adapter adapter, LayoutManagerWrapper mLayoutManager, RecyclerView mRecyclerView) throws Exception {
setupLayoutTest(padding, adapter, mLayoutManager, mRecyclerView);
// Shift so that bounds are after start and end.
adjustPosition(mRecyclerView, offset[0], offset[1]);
Method isOverscrolled = LayoutManager.class.getDeclaredMethod("isOverscrolled", LayoutState.class);
isOverscrolled.setAccessible(true);
LayoutState state = mock(LayoutState.class);
RecyclerView.State mRecyclerViewState = mock(RecyclerView.State.class);
when(state.getRecyclerState()).thenReturn(mRecyclerViewState);
when(mRecyclerViewState.getItemCount()).thenReturn(adapter.getItemCount());
boolean result = (Boolean) isOverscrolled.invoke(mLayoutManager, state);
assertEquals(expected, result);
}
use of android.support.v7.widget.helper.ItemTouchHelper.END in project CoCoin by Nightonke.
the class TodayViewFragment method onViewCreated.
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
mRecyclerView = (RecyclerView) view.findViewById(R.id.recyclerView);
layoutManager = new LinearLayoutManager(getActivity());
mRecyclerView.setLayoutManager(layoutManager);
mRecyclerView.setHasFixedSize(true);
Calendar now = Calendar.getInstance();
Calendar leftRange;
Calendar rightRange;
RecordManager recordManager = RecordManager.getInstance(mContext.getApplicationContext());
int start = -1;
int end = 0;
switch(position) {
case TODAY:
leftRange = CoCoinUtil.GetTodayLeftRange(now);
for (int i = recordManager.RECORDS.size() - 1; i >= 0; i--) {
if (recordManager.RECORDS.get(i).getCalendar().before(leftRange)) {
end = i + 1;
break;
}
if (start == -1) {
start = i;
}
}
break;
case YESTERDAY:
leftRange = CoCoinUtil.GetYesterdayLeftRange(now);
rightRange = CoCoinUtil.GetYesterdayRightRange(now);
for (int i = recordManager.RECORDS.size() - 1; i >= 0; i--) {
if (recordManager.RECORDS.get(i).getCalendar().before(leftRange)) {
end = i + 1;
break;
} else if (!recordManager.RECORDS.get(i).getCalendar().after(rightRange)) {
if (start == -1) {
start = i;
}
}
}
break;
case THIS_WEEK:
leftRange = CoCoinUtil.GetThisWeekLeftRange(now);
for (int i = recordManager.RECORDS.size() - 1; i >= 0; i--) {
if (recordManager.RECORDS.get(i).getCalendar().before(leftRange)) {
end = i + 1;
break;
}
if (start == -1) {
start = i;
}
}
break;
case LAST_WEEK:
leftRange = CoCoinUtil.GetLastWeekLeftRange(now);
rightRange = CoCoinUtil.GetLastWeekRightRange(now);
for (int i = recordManager.RECORDS.size() - 1; i >= 0; i--) {
if (recordManager.RECORDS.get(i).getCalendar().before(leftRange)) {
end = i + 1;
break;
} else if (recordManager.RECORDS.get(i).getCalendar().before(rightRange)) {
if (start == -1) {
start = i;
}
}
}
break;
case THIS_MONTH:
leftRange = CoCoinUtil.GetThisMonthLeftRange(now);
for (int i = recordManager.RECORDS.size() - 1; i >= 0; i--) {
if (recordManager.RECORDS.get(i).getCalendar().before(leftRange)) {
end = i + 1;
break;
}
if (start == -1) {
start = i;
}
}
break;
case LAST_MONTH:
leftRange = CoCoinUtil.GetLastMonthLeftRange(now);
rightRange = CoCoinUtil.GetLastMonthRightRange(now);
for (int i = recordManager.RECORDS.size() - 1; i >= 0; i--) {
if (recordManager.RECORDS.get(i).getCalendar().before(leftRange)) {
end = i + 1;
break;
} else if (recordManager.RECORDS.get(i).getCalendar().before(rightRange)) {
if (start == -1) {
start = i;
}
}
}
break;
case THIS_YEAR:
leftRange = CoCoinUtil.GetThisYearLeftRange(now);
for (int i = recordManager.RECORDS.size() - 1; i >= 0; i--) {
if (recordManager.RECORDS.get(i).getCalendar().before(leftRange)) {
end = i + 1;
break;
}
if (start == -1) {
start = i;
}
}
break;
case LAST_YEAR:
leftRange = CoCoinUtil.GetLastYearLeftRange(now);
rightRange = CoCoinUtil.GetLastYearRightRange(now);
for (int i = recordManager.RECORDS.size() - 1; i >= 0; i--) {
if (recordManager.RECORDS.get(i).getCalendar().before(leftRange)) {
end = i + 1;
break;
} else if (recordManager.RECORDS.get(i).getCalendar().before(rightRange)) {
if (start == -1) {
start = i;
}
}
}
break;
}
adapter = new TodayViewRecyclerViewAdapter(start, end, mContext, position);
mAdapter = new RecyclerViewMaterialAdapter(adapter);
mRecyclerView.setAdapter(mAdapter);
MaterialViewPagerHelper.registerRecyclerView(getActivity(), mRecyclerView, null);
}
use of android.support.v7.widget.helper.ItemTouchHelper.END in project Tusky by Vavassor.
the class ComposeActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_compose);
ButterKnife.bind(this);
// Setup the toolbar.
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setTitle(null);
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
Drawable closeIcon = AppCompatResources.getDrawable(this, R.drawable.ic_close_24dp);
ThemeUtils.setDrawableTint(this, closeIcon, R.attr.compose_close_button_tint);
actionBar.setHomeAsUpIndicator(closeIcon);
}
// Setup the interface buttons.
floatingBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onSendClicked();
}
});
pickBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onMediaPick();
}
});
takeBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
initiateCameraApp();
}
});
nsfwBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
toggleNsfw();
}
});
visibilityBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showComposeOptions();
}
});
/* Initialise all the state, or restore it from a previous run, to determine a "starting"
* state. */
SharedPreferences preferences = getPrivatePreferences();
String startingVisibility;
boolean startingHideText;
String startingContentWarning = null;
ArrayList<SavedQueuedMedia> savedMediaQueued = null;
if (savedInstanceState != null) {
showMarkSensitive = savedInstanceState.getBoolean("showMarkSensitive");
startingVisibility = savedInstanceState.getString("statusVisibility");
statusMarkSensitive = savedInstanceState.getBoolean("statusMarkSensitive");
startingHideText = savedInstanceState.getBoolean("statusHideText");
// Keep these until everything needed to put them in the queue is finished initializing.
savedMediaQueued = savedInstanceState.getParcelableArrayList("savedMediaQueued");
// These are for restoring an in-progress commit content operation.
InputContentInfoCompat previousInputContentInfo = InputContentInfoCompat.wrap(savedInstanceState.getParcelable("commitContentInputContentInfo"));
int previousFlags = savedInstanceState.getInt("commitContentFlags");
if (previousInputContentInfo != null) {
onCommitContentInternal(previousInputContentInfo, previousFlags);
}
} else {
showMarkSensitive = false;
startingVisibility = preferences.getString("rememberedVisibility", "public");
statusMarkSensitive = false;
startingHideText = false;
}
/* If the composer is started up as a reply to another post, override the "starting" state
* based on what the intent from the reply request passes. */
Intent intent = getIntent();
String[] mentionedUsernames = null;
inReplyToId = null;
if (intent != null) {
inReplyToId = intent.getStringExtra("in_reply_to_id");
String replyVisibility = intent.getStringExtra("reply_visibility");
if (replyVisibility != null && startingVisibility != null) {
// Lowest possible visibility setting in response
if (startingVisibility.equals("direct") || replyVisibility.equals("direct")) {
startingVisibility = "direct";
} else if (startingVisibility.equals("private") || replyVisibility.equals("private")) {
startingVisibility = "private";
} else if (startingVisibility.equals("unlisted") || replyVisibility.equals("unlisted")) {
startingVisibility = "unlisted";
} else {
startingVisibility = replyVisibility;
}
}
mentionedUsernames = intent.getStringArrayExtra("mentioned_usernames");
if (inReplyToId != null) {
startingHideText = !intent.getStringExtra("content_warning").equals("");
if (startingHideText) {
startingContentWarning = intent.getStringExtra("content_warning");
}
}
}
/* If the currently logged in account is locked, its posts should default to private. This
* should override even the reply settings, so this must be done after those are set up. */
if (preferences.getBoolean("loggedInAccountLocked", false)) {
startingVisibility = "private";
}
// After the starting state is finalised, the interface can be set to reflect this state.
setStatusVisibility(startingVisibility);
postProgress.setVisibility(View.INVISIBLE);
updateNsfwButtonColor();
final ParserUtils parser = new ParserUtils(this);
// Setup the main text field.
// new String[] { "image/gif", "image/webp" }
setEditTextMimeTypes(null);
final int mentionColour = ThemeUtils.getColor(this, R.attr.compose_mention_color);
SpanUtils.highlightSpans(textEditor.getText(), mentionColour);
textEditor.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
updateVisibleCharactersLeft();
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void afterTextChanged(Editable editable) {
SpanUtils.highlightSpans(editable, mentionColour);
}
});
textEditor.addOnPasteListener(new EditTextTyped.OnPasteListener() {
@Override
public void onPaste() {
parser.getPastedURLText(ComposeActivity.this);
}
});
// Add any mentions to the text field when a reply is first composed.
if (mentionedUsernames != null) {
StringBuilder builder = new StringBuilder();
for (String name : mentionedUsernames) {
builder.append('@');
builder.append(name);
builder.append(' ');
}
textEditor.setText(builder);
textEditor.setSelection(textEditor.length());
}
// Initialise the content warning editor.
contentWarningEditor.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
updateVisibleCharactersLeft();
}
@Override
public void afterTextChanged(Editable s) {
}
});
showContentWarning(startingHideText);
if (startingContentWarning != null) {
contentWarningEditor.setText(startingContentWarning);
}
// Initialise the empty media queue state.
mediaQueued = new ArrayList<>();
waitForMediaLatch = new CountUpDownLatch();
statusAlreadyInFlight = false;
// These can only be added after everything affected by the media queue is initialized.
if (savedMediaQueued != null) {
for (SavedQueuedMedia item : savedMediaQueued) {
addMediaToQueue(item.type, item.preview, item.uri, item.mediaSize);
}
} else if (intent != null && savedInstanceState == null) {
/* Get incoming images being sent through a share action from another app. Only do this
* when savedInstanceState is null, otherwise both the images from the intent and the
* instance state will be re-queued. */
String type = intent.getType();
if (type != null) {
if (type.startsWith("image/")) {
List<Uri> uriList = new ArrayList<>();
switch(intent.getAction()) {
case Intent.ACTION_SEND:
{
Uri uri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
if (uri != null) {
uriList.add(uri);
}
break;
}
case Intent.ACTION_SEND_MULTIPLE:
{
ArrayList<Uri> list = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
if (list != null) {
for (Uri uri : list) {
if (uri != null) {
uriList.add(uri);
}
}
}
break;
}
}
for (Uri uri : uriList) {
long mediaSize = getMediaSize(getContentResolver(), uri);
pickMedia(uri, mediaSize);
}
} else if (type.equals("text/plain")) {
String action = intent.getAction();
if (action != null && action.equals(Intent.ACTION_SEND)) {
String text = intent.getStringExtra(Intent.EXTRA_TEXT);
if (text != null) {
int start = Math.max(textEditor.getSelectionStart(), 0);
int end = Math.max(textEditor.getSelectionEnd(), 0);
int left = Math.min(start, end);
int right = Math.max(start, end);
textEditor.getText().replace(left, right, text, 0, text.length());
parser.putInClipboardManager(this, text);
textEditor.onPaste();
}
}
}
}
}
}
use of android.support.v7.widget.helper.ItemTouchHelper.END in project EasyRecyclerView by Jude95.
the class DividerDecoration method onDrawOver.
public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
if (parent.getAdapter() == null) {
return;
}
int orientation = 0;
int headerCount = 0, footerCount = 0, dataCount;
if (parent.getAdapter() instanceof RecyclerArrayAdapter) {
headerCount = ((RecyclerArrayAdapter) parent.getAdapter()).getHeaderCount();
footerCount = ((RecyclerArrayAdapter) parent.getAdapter()).getFooterCount();
dataCount = ((RecyclerArrayAdapter) parent.getAdapter()).getCount();
} else {
dataCount = parent.getAdapter().getItemCount();
}
int dataStartPosition = headerCount;
int dataEndPosition = headerCount + dataCount;
RecyclerView.LayoutManager layoutManager = parent.getLayoutManager();
if (layoutManager instanceof StaggeredGridLayoutManager) {
orientation = ((StaggeredGridLayoutManager) layoutManager).getOrientation();
} else if (layoutManager instanceof GridLayoutManager) {
orientation = ((GridLayoutManager) layoutManager).getOrientation();
} else if (layoutManager instanceof LinearLayoutManager) {
orientation = ((LinearLayoutManager) layoutManager).getOrientation();
}
int start, end;
if (orientation == OrientationHelper.VERTICAL) {
start = parent.getPaddingLeft() + mPaddingLeft;
end = parent.getWidth() - parent.getPaddingRight() - mPaddingRight;
} else {
start = parent.getPaddingTop() + mPaddingLeft;
end = parent.getHeight() - parent.getPaddingBottom() - mPaddingRight;
}
int childCount = parent.getChildCount();
for (int i = 0; i < childCount; i++) {
View child = parent.getChildAt(i);
int position = parent.getChildAdapterPosition(child);
if (//数据项除了最后一项
position >= dataStartPosition && position < dataEndPosition - 1 || //数据项最后一项
(position == dataEndPosition - 1 && mDrawLastItem) || //header&footer且可绘制
(!(position >= dataStartPosition && position < dataEndPosition) && mDrawHeaderFooter)) {
if (orientation == OrientationHelper.VERTICAL) {
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
int top = child.getBottom() + params.bottomMargin;
int bottom = top + mHeight;
mColorDrawable.setBounds(start, top, end, bottom);
mColorDrawable.draw(c);
} else {
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
int left = child.getRight() + params.rightMargin;
int right = left + mHeight;
mColorDrawable.setBounds(left, start, right, end);
mColorDrawable.draw(c);
}
}
}
}
Aggregations