use of android.support.v7.widget.helper.ItemTouchHelper.START in project RecyclerViewSnap by rubensousa.
the class GravityDelegate method findEndView.
@Nullable
private View findEndView(RecyclerView.LayoutManager layoutManager, @NonNull OrientationHelper helper) {
if (layoutManager instanceof LinearLayoutManager) {
LinearLayoutManager linearLayoutManager = (LinearLayoutManager) layoutManager;
boolean reverseLayout = linearLayoutManager.getReverseLayout();
int lastChild = reverseLayout ? linearLayoutManager.findFirstVisibleItemPosition() : linearLayoutManager.findLastVisibleItemPosition();
int offset = 1;
if (layoutManager instanceof GridLayoutManager) {
offset += ((GridLayoutManager) layoutManager).getSpanCount() - 1;
}
if (lastChild == RecyclerView.NO_POSITION) {
return null;
}
View child = layoutManager.findViewByPosition(lastChild);
float visibleWidth;
if (isRtlHorizontal) {
visibleWidth = (float) helper.getDecoratedEnd(child) / helper.getDecoratedMeasurement(child);
} else {
visibleWidth = (float) (helper.getTotalSpace() - helper.getDecoratedStart(child)) / helper.getDecoratedMeasurement(child);
}
// If we're at the start of the list, we shouldn't snap
// to avoid having the first item not completely visible.
boolean startOfList;
if (!reverseLayout) {
startOfList = ((LinearLayoutManager) layoutManager).findFirstCompletelyVisibleItemPosition() == 0;
} else {
startOfList = ((LinearLayoutManager) layoutManager).findLastCompletelyVisibleItemPosition() == layoutManager.getItemCount() - 1;
}
if (visibleWidth > 0.5f && !startOfList) {
return child;
} else if (snapLastItem && startOfList) {
return child;
} else if (startOfList) {
return null;
} else {
// If the child wasn't returned, we need to return the previous view
return reverseLayout ? layoutManager.findViewByPosition(lastChild + offset) : layoutManager.findViewByPosition(lastChild - offset);
}
}
return null;
}
use of android.support.v7.widget.helper.ItemTouchHelper.START in project android by nextcloud.
the class ShareFileFragment method initEditPermissionListener.
/**
* Binds listener for user actions that start any update the edit permissions
* for the public link to the views receiving the user events.
*
* @param shareView Root view in the fragment.
*/
private void initEditPermissionListener(View shareView) {
mOnEditPermissionInteractionListener = new OnEditPermissionInteractionListener();
SwitchCompat permissionSwitch = (SwitchCompat) shareView.findViewById(R.id.shareViaLinkEditPermissionSwitch);
permissionSwitch.setOnCheckedChangeListener(mOnEditPermissionInteractionListener);
ThemeUtils.tintSwitch(permissionSwitch, ThemeUtils.primaryAccentColor());
}
use of android.support.v7.widget.helper.ItemTouchHelper.START in project orgzly-android by orgzly.
the class MainActivity method onBookRenameRequest.
@Override
public void onBookRenameRequest(final long bookId) {
final Book book = BooksClient.get(this, bookId);
if (book == null) {
return;
}
final View dialogView = View.inflate(this, R.layout.dialog_book_rename, null);
final TextInputLayout nameInputLayout = dialogView.findViewById(R.id.name_input_layout);
final EditText name = dialogView.findViewById(R.id.name);
DialogInterface.OnClickListener dialogClickListener = (dialog, which) -> {
switch(which) {
case DialogInterface.BUTTON_POSITIVE:
doRenameBook(book, name.getText().toString(), nameInputLayout);
break;
case DialogInterface.BUTTON_NEGATIVE:
break;
}
};
AlertDialog.Builder builder = new AlertDialog.Builder(this).setTitle(getString(R.string.rename_book, MiscUtils.quotedString(book.getName()))).setPositiveButton(R.string.rename, dialogClickListener).setNegativeButton(R.string.cancel, dialogClickListener).setView(dialogView);
name.setText(book.getName());
final AlertDialog dialog = builder.create();
/* Finish on keyboard action press. */
name.setOnEditorActionListener((v, actionId, event) -> {
dialog.getButton(DialogInterface.BUTTON_POSITIVE).performClick();
return true;
});
final Activity activity = this;
dialog.setOnShowListener(d -> ActivityUtils.INSTANCE.openSoftKeyboard(activity, name));
dialog.setOnDismissListener(d -> ActivityUtils.INSTANCE.closeSoftKeyboard(activity));
name.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void afterTextChanged(Editable str) {
/* Disable the button is nothing is entered. */
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(!TextUtils.isEmpty(str));
}
});
dialog.show();
}
use of android.support.v7.widget.helper.ItemTouchHelper.START in project boilerplate by koush.
the class ScrollingToolbarLayout method enableToolbarScrollOff.
public void enableToolbarScrollOff(final IHeaderRecyclerView headerRecyclerView, final Fragment fragment) {
scrollOffEnabled = true;
int extra;
View paddingView;
if (getChildCount() == 3)
paddingView = getChildAt(0);
else
paddingView = getChildAt(getChildCount() - 1);
if (paddingView.getLayoutParams().height > 0) {
extra = paddingView.getLayoutParams().height;
} else {
// apparently this is the max size allowed
final int SIZE_MAX = 1073741823;
paddingView.measure(MeasureSpec.makeMeasureSpec(SIZE_MAX, MeasureSpec.AT_MOST), MeasureSpec.makeMeasureSpec(SIZE_MAX, MeasureSpec.AT_MOST));
extra = paddingView.getMeasuredHeight();
}
AbsListView.LayoutParams lp = new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, extra);
FrameLayout frameLayout = new FrameLayout(getContext());
frameLayout.setLayoutParams(lp);
headerRecyclerView.addHeaderView(0, frameLayout);
headerRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView absListView, int scrollState) {
// when scrolling stops, and the toolbar is only partially scrolled off, force to scroll bar in completely
if (scrollState != RecyclerView.SCROLL_STATE_IDLE)
return;
if (absListView.getChildCount() < 1)
return;
int firstVisibleItem = headerRecyclerView.findFirstVisibleItemPosition();
if (firstVisibleItem != 0)
return;
final View toolbarContainer = getChildAt(getChildCount() - 1);
if (toolbarContainer.getTranslationY() <= -toolbarContainer.getHeight() || (existingToolbarYAnimation != null && existingToolbarYEnd <= toolbarContainer.getHeight()))
return;
toolbarScrollIn();
}
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
if (recyclerView.getChildCount() < 1)
return;
if (fragment != null && !fragment.getUserVisibleHint())
return;
// cancelToolbarScroll();
final View firstView = recyclerView.getChildAt(0);
final View toolbarContainer = getChildAt(getChildCount() - 1);
final View backdrop;
if (getChildCount() == 3)
backdrop = getChildAt(0);
else
backdrop = null;
final int toolbarHeight = toolbarContainer.getHeight();
int firstVisibleItem = headerRecyclerView.findFirstVisibleItemPosition();
if (backdrop != null) {
int newBackdropHeight;
int backdropHeight = getResources().getDimensionPixelSize(R.dimen.icon_list_drawer_activity_backdrop_height);
if (firstVisibleItem >= 1) {
newBackdropHeight = toolbarHeight;
} else {
newBackdropHeight = firstView.getTop() + backdropHeight;
}
newBackdropHeight = Math.max(newBackdropHeight, toolbarHeight);
FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) backdrop.getLayoutParams();
lp.height = newBackdropHeight;
// another option is to use y translation to not do parallax
backdrop.setLayoutParams(lp);
if (newBackdropHeight / (float) backdropHeight < .5f) {
toolbarFadeToPrimary();
} else {
toolbarFadeToTranslucent();
}
}
if (firstVisibleItem == 0) {
int remainder = firstView.getHeight() + firstView.getTop();
// if there's less than toolbar height left, start scrolling off.
if (remainder < toolbarHeight) {
remainder = toolbarHeight - remainder;
if (existingToolbarYAnimation == null) {
float diff = -remainder - toolbarContainer.getTranslationY();
if (false && Math.abs(diff) > toolbarHeight / 4) {
if (toolbarContainer.getTranslationY() < -remainder) {
// scrolling down
toolbarScrollIn();
} else {
// scrolling up
toolbarScrollOut();
}
} else {
toolbarContainer.setTranslationY(-remainder);
}
}
if (backdrop != null)
backdrop.setTranslationY(-remainder);
} else {
cancelToolbarScroll();
toolbarContainer.setTranslationY(0);
// toolbarScrollIn();
if (backdrop != null)
backdrop.setTranslationY(0);
}
return;
}
if (firstVisibleItem == 1) {
cancelToolbarScroll();
toolbarContainer.setTranslationY(-toolbarHeight);
} else {
toolbarScrollOut();
}
if (backdrop != null)
backdrop.setTranslationY(-toolbarHeight);
}
});
if (getChildCount() == 3)
toolbarFadeToTranslucent();
}
use of android.support.v7.widget.helper.ItemTouchHelper.START in project twicalico by moko256.
the class PostActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_post);
model = PostTweetModelCreator.getInstance(GlobalApplication.twitter, getContentResolver());
subscription = new CompositeSubscription();
rootViewGroup = findViewById(R.id.activity_tweet_send_layout_root);
toolbar = findViewById(R.id.activity_tweet_send_toolbar);
setSupportActionBar(toolbar);
actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeAsUpIndicator(R.drawable.ic_clear_white_24dp);
userIcon = findViewById(R.id.activity_tweet_send_user_icon);
GlideApp.with(this).load(GlobalApplication.userCache.get(GlobalApplication.userId).get400x400ProfileImageURLHttps()).circleCrop().into(userIcon);
counterTextView = findViewById(R.id.tweet_text_edit_counter);
editText = findViewById(R.id.tweet_text_edit);
editText.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) {
model.setTweetText(s.toString());
counterTextView.setText(String.valueOf(model.getTweetLength()) + " / " + String.valueOf(model.getMaxTweetLength()));
counterTextView.setTextColor(model.isValidTweet() ? Color.GRAY : Color.RED);
}
@Override
public void afterTextChanged(Editable s) {
}
});
editText.setImageAddedListener(imageUri -> {
if (model.getUriList().size() < model.getUriListSizeLimit()) {
addedImagesAdapter.getImagesList().add(imageUri);
model.getUriList().add(imageUri);
addedImagesAdapter.notifyItemChanged(addedImagesAdapter.getImagesList().size() - 1);
possiblySensitiveSwitch.setEnabled(true);
return true;
} else {
return false;
}
});
editText.setHint(model.isReply() ? R.string.reply : R.string.post);
imagesRecyclerView = findViewById(R.id.activity_tweet_send_images_recycler_view);
addedImagesAdapter = new AddedImagesAdapter(this);
imagesRecyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
imagesRecyclerView.addItemDecoration(new RecyclerView.ItemDecoration() {
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
outRect.right = Math.round(getResources().getDisplayMetrics().density);
}
});
addedImagesAdapter.setLimit(model.getUriListSizeLimit());
addedImagesAdapter.setOnAddButtonClickListener(v -> startActivityForResult(Intent.createChooser(new Intent(Intent.ACTION_GET_CONTENT).addCategory(Intent.CATEGORY_OPENABLE).putExtra(Intent.EXTRA_MIME_TYPES, new String[] { "image/*", "video/*" }).putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true).setType("*/*"), getString(R.string.add_image)), REQUEST_GET_IMAGE));
addedImagesAdapter.setOnDeleteButtonListener(position -> {
addedImagesAdapter.getImagesList().remove(position);
model.getUriList().remove(position);
addedImagesAdapter.notifyDataSetChanged();
boolean enabled = model.getUriList().size() > 0;
possiblySensitiveSwitch.setEnabled(enabled);
possiblySensitiveSwitch.setChecked(possiblySensitiveSwitch.isChecked() && enabled);
});
addedImagesAdapter.setOnImageClickListener(position -> {
Intent open = new Intent(Intent.ACTION_VIEW).setData(model.getUriList().get(position)).addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(open, getString(R.string.open_image)));
});
imagesRecyclerView.setAdapter(addedImagesAdapter);
possiblySensitiveSwitch = findViewById(R.id.activity_tweet_possibly_sensitive_switch);
possiblySensitiveSwitch.setEnabled(addedImagesAdapter.getImagesList().size() > 0);
possiblySensitiveSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> model.setPossiblySensitive(isChecked));
addLocationSwitch = findViewById(R.id.activity_tweet_location_switch);
addLocationSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
if (isChecked) {
if (PermissionChecker.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PermissionChecker.PERMISSION_GRANTED) {
subscription.add(getLocation().subscribe(it -> {
model.setLocation(new GeoLocation(it.getLatitude(), it.getLongitude()));
locationText.setVisibility(View.VISIBLE);
locationText.setText(getString(R.string.lat_and_lon, it.getLatitude(), it.getLongitude()));
}, Throwable::printStackTrace));
} else {
ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, 400);
}
} else {
locationText.setVisibility(View.GONE);
}
});
locationText = findViewById(R.id.activity_tweet_location_result);
locationText.setVisibility(View.GONE);
if (getIntent() != null) {
if (!model.isReply()) {
model.setInReplyToStatusId(getIntent().getLongExtra(INTENT_EXTRA_IN_REPLY_TO_STATUS_ID, -1));
}
String text = getIntent().getStringExtra(INTENT_EXTRA_TWEET_TEXT);
if (text != null) {
editText.setText(text);
editText.setSelection(text.length());
} else {
editText.setText("");
}
ArrayList<Uri> uris = getIntent().getParcelableArrayListExtra(INTENT_EXTRA_IMAGE_URI);
if (uris != null) {
addedImagesAdapter.getImagesList().addAll(uris);
model.getUriList().addAll(uris);
possiblySensitiveSwitch.setEnabled(true);
}
}
}
Aggregations