use of android.support.v7.widget.helper.ItemTouchHelper.END in project material-components-android by material-components.
the class TextInputLayout method updatePasswordToggleView.
private void updatePasswordToggleView() {
if (mEditText == null) {
// If there is no EditText, there is nothing to update
return;
}
if (shouldShowPasswordIcon()) {
if (mPasswordToggleView == null) {
mPasswordToggleView = (CheckableImageButton) LayoutInflater.from(getContext()).inflate(R.layout.design_text_input_password_icon, mInputFrame, false);
mPasswordToggleView.setImageDrawable(mPasswordToggleDrawable);
mPasswordToggleView.setContentDescription(mPasswordToggleContentDesc);
mInputFrame.addView(mPasswordToggleView);
mPasswordToggleView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
passwordVisibilityToggleRequested();
}
});
}
if (mEditText != null && ViewCompat.getMinimumHeight(mEditText) <= 0) {
// We should make sure that the EditText has the same min-height as the password toggle
// view. This ensures focus works properly, and there is no visual jump if the password
// toggle is enabled/disabled.
mEditText.setMinimumHeight(ViewCompat.getMinimumHeight(mPasswordToggleView));
}
mPasswordToggleView.setVisibility(VISIBLE);
mPasswordToggleView.setChecked(mPasswordToggledVisible);
// indented and doesn't display below the toggle view
if (mPasswordToggleDummyDrawable == null) {
mPasswordToggleDummyDrawable = new ColorDrawable();
}
mPasswordToggleDummyDrawable.setBounds(0, 0, mPasswordToggleView.getMeasuredWidth(), 1);
final Drawable[] compounds = TextViewCompat.getCompoundDrawablesRelative(mEditText);
// Store the user defined end compound drawable so that we can restore it later
if (compounds[2] != mPasswordToggleDummyDrawable) {
mOriginalEditTextEndDrawable = compounds[2];
}
TextViewCompat.setCompoundDrawablesRelative(mEditText, compounds[0], compounds[1], mPasswordToggleDummyDrawable, compounds[3]);
// Copy over the EditText's padding so that we match
mPasswordToggleView.setPadding(mEditText.getPaddingLeft(), mEditText.getPaddingTop(), mEditText.getPaddingRight(), mEditText.getPaddingBottom());
} else {
if (mPasswordToggleView != null && mPasswordToggleView.getVisibility() == VISIBLE) {
mPasswordToggleView.setVisibility(View.GONE);
}
if (mPasswordToggleDummyDrawable != null) {
// Make sure that we remove the dummy end compound drawable if it exists, and then
// clear it
final Drawable[] compounds = TextViewCompat.getCompoundDrawablesRelative(mEditText);
if (compounds[2] == mPasswordToggleDummyDrawable) {
TextViewCompat.setCompoundDrawablesRelative(mEditText, compounds[0], compounds[1], mOriginalEditTextEndDrawable, compounds[3]);
mPasswordToggleDummyDrawable = null;
}
}
}
}
use of android.support.v7.widget.helper.ItemTouchHelper.END in project RecyclerViewSnap by rubensousa.
the class GravitySnapHelper method findStartView.
/**
* Returns the first view that we should snap to.
*
* @param layoutManager the recyclerview's layout manager
* @param helper orientation helper to calculate view sizes
* @return the first view in the LayoutManager to snap to
*/
private View findStartView(RecyclerView.LayoutManager layoutManager, OrientationHelper helper) {
if (layoutManager instanceof LinearLayoutManager) {
int firstChild = ((LinearLayoutManager) layoutManager).findFirstVisibleItemPosition();
if (firstChild == RecyclerView.NO_POSITION) {
return null;
}
View child = layoutManager.findViewByPosition(firstChild);
float visibleWidth;
// In a RTL configuration, we need to check the start point and in LTR the end point
if (mIsRtlHorizontal) {
visibleWidth = (float) (helper.getTotalSpace() - helper.getDecoratedStart(child)) / helper.getDecoratedMeasurement(child);
} else {
visibleWidth = (float) helper.getDecoratedEnd(child) / helper.getDecoratedMeasurement(child);
}
// If we're at the end of the list, we shouldn't snap
// to avoid having the last item not completely visible.
boolean endOfList = ((LinearLayoutManager) layoutManager).findLastCompletelyVisibleItemPosition() == layoutManager.getItemCount() - 1;
if (visibleWidth > 0.5f && !endOfList) {
return child;
} else if (mSnapLastItemEnabled && endOfList) {
return child;
} else if (endOfList) {
return null;
} else {
// the next view close to the start.
return layoutManager.findViewByPosition(firstChild + 1);
}
}
return null;
}
use of android.support.v7.widget.helper.ItemTouchHelper.END in project android by owncloud.
the class UploadFilesActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
Log_OC.d(TAG, "onCreate() start");
super.onCreate(savedInstanceState);
if (savedInstanceState != null) {
mCurrentDir = new File(savedInstanceState.getString(UploadFilesActivity.KEY_DIRECTORY_PATH));
} else {
mCurrentDir = Environment.getExternalStorageDirectory();
}
mAccountOnCreation = getAccount();
/// USER INTERFACE
// Drop-down navigation
mDirectories = new CustomArrayAdapter<String>(this, R.layout.support_simple_spinner_dropdown_item);
File currDir = mCurrentDir;
while (currDir != null && currDir.getParentFile() != null) {
mDirectories.add(currDir.getName());
currDir = currDir.getParentFile();
}
mDirectories.add(File.separator);
// Inflate and set the layout view
setContentView(R.layout.upload_files_layout);
mFileListFragment = (LocalFileListFragment) getSupportFragmentManager().findFragmentById(R.id.local_files_list);
// Set input controllers
mCancelBtn = (Button) findViewById(R.id.upload_files_btn_cancel);
mCancelBtn.setOnClickListener(this);
mUploadBtn = (Button) findViewById(R.id.upload_files_btn_upload);
mUploadBtn.setOnClickListener(this);
SharedPreferences appPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
Integer localBehaviour = appPreferences.getInt("prefs_uploader_behaviour", FileUploader.LOCAL_BEHAVIOUR_COPY);
mRadioBtnMoveFiles = (RadioButton) findViewById(R.id.upload_radio_move);
if (localBehaviour == FileUploader.LOCAL_BEHAVIOUR_MOVE) {
mRadioBtnMoveFiles.setChecked(true);
}
mRadioBtnCopyFiles = (RadioButton) findViewById(R.id.upload_radio_copy);
if (localBehaviour == FileUploader.LOCAL_BEHAVIOUR_COPY) {
mRadioBtnCopyFiles.setChecked(true);
}
// setup the toolbar
setupToolbar();
// Action bar setup
ActionBar actionBar = getSupportActionBar();
// mandatory since Android ICS, according to the
actionBar.setHomeButtonEnabled(true);
// official documentation
actionBar.setDisplayHomeAsUpEnabled(mCurrentDir != null && mCurrentDir.getName() != null);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
actionBar.setListNavigationCallbacks(mDirectories, this);
// wait dialog
if (mCurrentDialog != null) {
mCurrentDialog.dismiss();
mCurrentDialog = null;
}
Log_OC.d(TAG, "onCreate() end");
}
use of android.support.v7.widget.helper.ItemTouchHelper.END in project plaid by nickbutcher.
the class HomeActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
ButterKnife.bind(this);
drawer.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
setActionBar(toolbar);
if (savedInstanceState == null) {
animateToolbar();
}
setExitSharedElementCallback(FeedAdapter.createSharedElementReenterCallback(this));
dribbblePrefs = DribbblePrefs.get(this);
designerNewsPrefs = DesignerNewsPrefs.get(this);
filtersAdapter = new FilterAdapter(this, SourceManager.getSources(this), new FilterAdapter.FilterAuthoriser() {
@Override
public void requestDribbbleAuthorisation(View sharedElement, Source forSource) {
Intent login = new Intent(HomeActivity.this, DribbbleLogin.class);
MorphTransform.addExtras(login, ContextCompat.getColor(HomeActivity.this, R.color.background_dark), sharedElement.getHeight() / 2);
ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(HomeActivity.this, sharedElement, getString(R.string.transition_dribbble_login));
startActivityForResult(login, getAuthSourceRequestCode(forSource), options.toBundle());
}
});
dataManager = new DataManager(this, filtersAdapter) {
@Override
public void onDataLoaded(List<? extends PlaidItem> data) {
adapter.addAndResort(data);
checkEmptyState();
}
};
adapter = new FeedAdapter(this, dataManager, columns, PocketUtils.isPocketInstalled(this));
grid.setAdapter(adapter);
layoutManager = new GridLayoutManager(this, columns);
layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
return adapter.getItemColumnSpan(position);
}
});
grid.setLayoutManager(layoutManager);
grid.addOnScrollListener(toolbarElevation);
grid.addOnScrollListener(new InfiniteScrollListener(layoutManager, dataManager) {
@Override
public void onLoadMore() {
dataManager.loadAllDataSources();
}
});
grid.setHasFixedSize(true);
grid.addItemDecoration(new GridItemDividerDecoration(adapter.getDividedViewHolderClasses(), this, R.dimen.divider_height, R.color.divider));
grid.setItemAnimator(new HomeGridItemAnimator());
// drawer layout treats fitsSystemWindows specially so we have to handle insets ourselves
drawer.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
@Override
public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
// inset the toolbar down by the status bar height
ViewGroup.MarginLayoutParams lpToolbar = (ViewGroup.MarginLayoutParams) toolbar.getLayoutParams();
lpToolbar.topMargin += insets.getSystemWindowInsetTop();
lpToolbar.leftMargin += insets.getSystemWindowInsetLeft();
lpToolbar.rightMargin += insets.getSystemWindowInsetRight();
toolbar.setLayoutParams(lpToolbar);
// inset the grid top by statusbar+toolbar & the bottom by the navbar (don't clip)
grid.setPadding(// landscape
grid.getPaddingLeft() + insets.getSystemWindowInsetLeft(), insets.getSystemWindowInsetTop() + ViewUtils.getActionBarSize(HomeActivity.this), // landscape
grid.getPaddingRight() + insets.getSystemWindowInsetRight(), grid.getPaddingBottom() + insets.getSystemWindowInsetBottom());
// inset the fab for the navbar
ViewGroup.MarginLayoutParams lpFab = (ViewGroup.MarginLayoutParams) fab.getLayoutParams();
// portrait
lpFab.bottomMargin += insets.getSystemWindowInsetBottom();
// landscape
lpFab.rightMargin += insets.getSystemWindowInsetRight();
fab.setLayoutParams(lpFab);
View postingStub = findViewById(R.id.stub_posting_progress);
ViewGroup.MarginLayoutParams lpPosting = (ViewGroup.MarginLayoutParams) postingStub.getLayoutParams();
// portrait
lpPosting.bottomMargin += insets.getSystemWindowInsetBottom();
// landscape
lpPosting.rightMargin += insets.getSystemWindowInsetRight();
postingStub.setLayoutParams(lpPosting);
// we place a background behind the status bar to combine with it's semi-transparent
// color to get the desired appearance. Set it's height to the status bar height
View statusBarBackground = findViewById(R.id.status_bar_background);
FrameLayout.LayoutParams lpStatus = (FrameLayout.LayoutParams) statusBarBackground.getLayoutParams();
lpStatus.height = insets.getSystemWindowInsetTop();
statusBarBackground.setLayoutParams(lpStatus);
// inset the filters list for the status bar / navbar
// need to set the padding end for landscape case
final boolean ltr = filtersList.getLayoutDirection() == View.LAYOUT_DIRECTION_LTR;
filtersList.setPaddingRelative(filtersList.getPaddingStart(), filtersList.getPaddingTop() + insets.getSystemWindowInsetTop(), filtersList.getPaddingEnd() + (ltr ? insets.getSystemWindowInsetRight() : 0), filtersList.getPaddingBottom() + insets.getSystemWindowInsetBottom());
// clear this listener so insets aren't re-applied
drawer.setOnApplyWindowInsetsListener(null);
return insets.consumeSystemWindowInsets();
}
});
setupTaskDescription();
filtersList.setAdapter(filtersAdapter);
filtersList.setItemAnimator(new FilterAdapter.FilterAnimator());
filtersAdapter.registerFilterChangedCallback(filtersChangedCallbacks);
dataManager.loadAllDataSources();
ItemTouchHelper.Callback callback = new FilterTouchHelperCallback(filtersAdapter);
ItemTouchHelper itemTouchHelper = new ItemTouchHelper(callback);
itemTouchHelper.attachToRecyclerView(filtersList);
checkEmptyState();
}
use of android.support.v7.widget.helper.ItemTouchHelper.END in project FastAdapter by mikepenz.
the class EndlessRecyclerOnScrollListener method findOneVisibleChild.
private View findOneVisibleChild(int fromIndex, int toIndex, boolean completelyVisible, boolean acceptPartiallyVisible) {
if (mLayoutManager.canScrollVertically() != mIsOrientationHelperVertical || mOrientationHelper == null) {
mIsOrientationHelperVertical = mLayoutManager.canScrollVertically();
mOrientationHelper = mIsOrientationHelperVertical ? OrientationHelper.createVerticalHelper(mLayoutManager) : OrientationHelper.createHorizontalHelper(mLayoutManager);
}
final int start = mOrientationHelper.getStartAfterPadding();
final int end = mOrientationHelper.getEndAfterPadding();
final int next = toIndex > fromIndex ? 1 : -1;
View partiallyVisible = null;
for (int i = fromIndex; i != toIndex; i += next) {
final View child = mLayoutManager.getChildAt(i);
if (child != null) {
final int childStart = mOrientationHelper.getDecoratedStart(child);
final int childEnd = mOrientationHelper.getDecoratedEnd(child);
if (childStart < end && childEnd > start) {
if (completelyVisible) {
if (childStart >= start && childEnd <= end) {
return child;
} else if (acceptPartiallyVisible && partiallyVisible == null) {
partiallyVisible = child;
}
} else {
return child;
}
}
}
}
return partiallyVisible;
}
Aggregations