use of android.support.v7.widget.StaggeredGridLayoutManager in project PhotoPicker by donglua.
the class PhotoPickerFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View rootView = inflater.inflate(R.layout.__picker_fragment_photo_picker, container, false);
RecyclerView recyclerView = (RecyclerView) rootView.findViewById(R.id.rv_photos);
StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(column, OrientationHelper.VERTICAL);
layoutManager.setGapStrategy(StaggeredGridLayoutManager.GAP_HANDLING_MOVE_ITEMS_BETWEEN_SPANS);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setAdapter(photoGridAdapter);
recyclerView.setItemAnimator(new DefaultItemAnimator());
final Button btSwitchDirectory = (Button) rootView.findViewById(R.id.button);
listPopupWindow = new ListPopupWindow(getActivity());
listPopupWindow.setWidth(ListPopupWindow.MATCH_PARENT);
listPopupWindow.setAnchorView(btSwitchDirectory);
listPopupWindow.setAdapter(listAdapter);
listPopupWindow.setModal(true);
listPopupWindow.setDropDownGravity(Gravity.BOTTOM);
listPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
listPopupWindow.dismiss();
PhotoDirectory directory = directories.get(position);
btSwitchDirectory.setText(directory.getName());
photoGridAdapter.setCurrentDirectoryIndex(position);
photoGridAdapter.notifyDataSetChanged();
}
});
photoGridAdapter.setOnPhotoClickListener(new OnPhotoClickListener() {
@Override
public void onClick(View v, int position, boolean showCamera) {
final int index = showCamera ? position - 1 : position;
List<String> photos = photoGridAdapter.getCurrentPhotoPaths();
ImagePagerFragment imagePagerFragment = ImagePagerFragment.newInstance(photos, index);
((PhotoPickerActivity) getActivity()).addImagePagerFragment(imagePagerFragment);
}
});
photoGridAdapter.setOnCameraClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
if (!PermissionsUtils.checkCameraPermission(PhotoPickerFragment.this))
return;
if (!PermissionsUtils.checkWriteStoragePermission(PhotoPickerFragment.this))
return;
openCamera();
}
});
btSwitchDirectory.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (listPopupWindow.isShowing()) {
listPopupWindow.dismiss();
} else if (!getActivity().isFinishing()) {
adjustHeight();
listPopupWindow.show();
}
}
});
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
// Log.d(">>> Picker >>>", "dy = " + dy);
if (Math.abs(dy) > SCROLL_THRESHOLD) {
mGlideRequestManager.pauseRequests();
} else {
resumeRequestsIfNotDestroyed();
}
}
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
resumeRequestsIfNotDestroyed();
}
}
});
return rootView;
}
use of android.support.v7.widget.StaggeredGridLayoutManager in project SherlockAdapter by EvilBT.
the class ExpandableActivity method initView.
private void initView() {
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
mRecyclerView = (RecyclerView) findViewById(R.id.list);
mGridLayoutManager = new GridLayoutManager(this, 2);
mStaggeredGridLayoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
mRecyclerView.setLayoutManager(mStaggeredGridLayoutManager);
mAdapter = new MyExpandableAdapter();
// mAdapter.setAlwaysShowFoot(true);
// mAdapter.setAlwaysShowHead(true);
mAdapter.addHeadLayout(R.layout.item_head);
mAdapter.addFootLayout(R.layout.item_foot2);
// 设置DiffUtil效果
mAdapter.setCallback(new DiffUtilCallback<IMultiItem>() {
@Override
public boolean areItemsTheSame(IMultiItem oldItem, IMultiItem newItem) {
if (oldItem instanceof ImageLabel && newItem instanceof ImageLabel) {
return TextUtils.equals(((ImageLabel) oldItem).getData(), ((ImageLabel) newItem).getData());
}
if (oldItem instanceof Card && newItem instanceof Card) {
return ((Card) oldItem).getData().mImageResId == ((Card) newItem).getData().mImageResId;
}
return false;
}
@Override
public boolean areContentsTheSame(IMultiItem oldItem, IMultiItem newItem) {
if (oldItem instanceof ImageLabel && newItem instanceof ImageLabel) {
return true;
}
if (oldItem instanceof Card && newItem instanceof Card) {
return TextUtils.equals(((Card) oldItem).getData().mImageTitle, ((Card) newItem).getData().mImageTitle);
}
return false;
}
});
mRecyclerView.setAdapter(mAdapter);
// 屏障默认的Change动画
((SimpleItemAnimator) mRecyclerView.getItemAnimator()).setSupportsChangeAnimations(false);
// 点击展开/折叠事件
mAdapter.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(@NonNull View view, int adapterPosition) {
if (view.getId() == R.id.label_root) {
IMultiItem item = mAdapter.getData(adapterPosition);
if (item instanceof IExpandable) {
IExpandable expandable = (IExpandable) item;
if (expandable.isExpandable()) {
// 修复issue#2
// 这个支持包的bug: https://issuetracker.google.com/issues/37034096
mStaggeredGridLayoutManager.invalidateSpanAssignments();
mAdapter.collapseAll(adapterPosition);
} else {
mAdapter.expandAll(adapterPosition);
}
}
}
}
});
mAdapter.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(@NonNull View view, int adapterPosition) {
mAdapter.removeData(adapterPosition);
return true;
}
});
final SwipeRefreshLayout refresh = (SwipeRefreshLayout) findViewById(R.id.refresh);
refresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
refreshData();
refresh.setRefreshing(false);
}
});
findViewById(R.id.fab).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
refreshData();
}
});
initData();
}
use of android.support.v7.widget.StaggeredGridLayoutManager in project SherlockAdapter by EvilBT.
the class BasicActivity method initView.
private void initView() {
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
mFullSpan1 = (CheckBox) findViewById(R.id.cb_head1);
mFullSpan2 = (CheckBox) findViewById(R.id.cb_head2);
mSpanSize1 = (EditText) findViewById(R.id.et_span_count1);
mSpanSize2 = (EditText) findViewById(R.id.et_span_count2);
mGridLayoutManager = new GridLayoutManager(this, 3);
mStaggeredGridLayoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
final SwipeRefreshLayout refreshLayout = (SwipeRefreshLayout) findViewById(R.id.refresh);
mRecyclerView = (RecyclerView) findViewById(R.id.list);
mRecyclerView.setLayoutManager(mGridLayoutManager);
mIsGrid = true;
mAdapter = new MyMultiAdapter();
mRecyclerView.setAdapter(mAdapter);
mAdapter.addHeadLayout(R.layout.item_head1, false, 0);
mAdapter.addHeadLayout(R.layout.item_head2, false, 0);
// mAdapter.addFootLayout(R.layout.item_head1,false,0);
// mAdapter.addFootLayout(R.layout.item_head2,false,0);
mAdapter.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(@NonNull View view, final int adapterPosition) {
new AlertDialog.Builder(BasicActivity.this).setTitle("是否删除第" + adapterPosition + "项").setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
mAdapter.removeData(adapterPosition);
}
}).setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
}).create().show();
return true;
}
});
mData = new ArrayList<>();
initGridData();
refreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
refreshLayout.postDelayed(new Runnable() {
@Override
public void run() {
mAdapter.setData(mData);
refreshLayout.setRefreshing(false);
}
}, 500);
}
});
mFullSpan1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
changeHead();
}
});
mFullSpan2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
changeHead();
}
});
mSpanSize1.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) {
changeHead();
}
@Override
public void afterTextChanged(Editable s) {
}
});
mSpanSize2.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) {
changeHead();
}
@Override
public void afterTextChanged(Editable s) {
}
});
}
use of android.support.v7.widget.StaggeredGridLayoutManager in project SherlockAdapter by EvilBT.
the class MultiSelectItemActivity method onCreate.
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.act_multi_select_item);
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 view) {
getSelectedList();
}
});
findViewById(R.id.selectAll).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// 全选
adapter.selectAll();
}
});
findViewById(R.id.unselectAll).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// 全不选
adapter.clearSelectAll();
}
});
adapter = new MyMultiSelectAdapter();
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.list);
recyclerView.setLayoutManager(new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL));
recyclerView.setAdapter(adapter);
// 屏障默认的Change动画,默认的Change动画会闪烁一下
((SimpleItemAnimator) recyclerView.getItemAnimator()).setSupportsChangeAnimations(false);
adapter.setOnItemCheckedChangeListener(new OnItemCheckedChangeListener() {
@Override
public void onItemCheck(@NonNull View view, boolean isChecked, int adapterPosition) {
final int id = view.getId();
if (id == R.id.checkbox) {
IMultiSelectItem selectorItem = adapter.getData(adapterPosition);
if (selectorItem != null) {
final int selectedSize = adapter.getSelectedItems().size();
if (isChecked && selectedSize > 9) {
Toast.makeText(MultiSelectItemActivity.this, "您最多只能选择9个", Toast.LENGTH_SHORT).show();
selectorItem.setChecked(false);
adapter.notifyItemChanged(adapterPosition);
}
}
}
}
});
List<IMultiSelectItem> data = new ArrayList<>(20);
for (int i = 0; i < 40; i++) {
SelectorCard card = new SelectorCard(i);
data.add(card);
}
// 添加一个不可选中的数据在列表上
NoSelectCard card = new NoSelectCard("我跟他们不一样");
data.add(0, card);
adapter.setData(data);
}
use of android.support.v7.widget.StaggeredGridLayoutManager in project Moneycim by volkansahin45.
the class SpendingListFragment method onCreateView.
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_spending_list, container, false);
ButterKnife.bind(this, view);
adapter = new SpendingRecyclerViewAdapter(getActivity(), spendingList, this);
layoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
spendingRecyclerView.setAdapter(adapter);
spendingRecyclerView.setLayoutManager(layoutManager);
return view;
}
Aggregations