use of android.support.v4.widget.SwipeRefreshLayout in project Ency by xiarunhao123.
the class WebActivity method initialize.
@Override
protected void initialize() {
daoManager = EncyApplication.getAppComponent().getGreenDaoManager();
sharePrefManager = EncyApplication.getAppComponent().getSharePrefManager();
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
swipeRefreshLayout.setColorSchemeColors(getResources().getColor(R.color.colorPrimary));
swipeRefreshLayout.setOnRefreshListener(this);
swipeRefreshLayout.setOnChildScrollUpCallback(new SwipeRefreshLayout.OnChildScrollUpCallback() {
@Override
public boolean canChildScrollUp(SwipeRefreshLayout parent, @Nullable View child) {
if (child.getScrollY() > 0)
return true;
return false;
}
});
Bundle bundle = getIntent().getExtras();
if (null != bundle) {
guid = bundle.getString("guid");
imageUrl = bundle.getString("imageUrl");
type = bundle.getInt("type");
url = bundle.getString("url");
title = bundle.getString("title");
isShowLikeIcon = bundle.getBoolean("isshow");
}
setTitle(title);
initWebView();
}
use of android.support.v4.widget.SwipeRefreshLayout in project JustAndroid by chinaltz.
the class SwipeRefreshLayoutActivity method onCreate.
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_swiperefreshlayout);
ButterKnife.bind(this);
final SwipeRefreshView swipeRefreshView = (SwipeRefreshView) findViewById(R.id.srl);
ListView listView = (ListView) findViewById(R.id.swipe_listView);
// 设置适配器数据
mList = new ArrayList<>();
for (int i = 0; i < 30; i++) {
mList.add("测试数据" + i + "号");
mCount++;
}
mAdapter = new StringAdapter();
listView.setAdapter(mAdapter);
// 不能在onCreate中设置,这个表示当前是刷新状态,如果一进来就是刷新状态,SwipeRefreshLayout会屏蔽掉下拉事件
// swipeRefreshLayout.setRefreshing(true);
// 设置颜色属性的时候一定要注意是引用了资源文件还是直接设置16进制的颜色,因为都是int值容易搞混
// 设置下拉进度的背景颜色,默认就是白色的
swipeRefreshView.setProgressBackgroundColorSchemeResource(android.R.color.white);
// 设置下拉进度的主题颜色
swipeRefreshView.setColorSchemeResources(R.color.colorAccent, R.color.colorPrimary, R.color.colorPrimaryDark);
// 下拉时触发SwipeRefreshLayout的下拉动画,动画完毕之后就会回调这个方法
swipeRefreshView.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
// TODO 获取数据
final Random random = new Random();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
mList.add(0, "测试数据" + random.nextInt(100) + "号");
mAdapter.notifyDataSetChanged();
Toast.makeText(SwipeRefreshLayoutActivity.this, "刷新了一条数据", Toast.LENGTH_SHORT).show();
// 加载完数据设置为不刷新状态,将下拉进度收起来
swipeRefreshView.setRefreshing(false);
}
}, 1200);
}
});
// 设置下拉加载更多
swipeRefreshView.setOnLoadListener(new SwipeRefreshView.OnLoadListener() {
@Override
public void onLoad() {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
// 添加数据
for (int i = 30; i < 35; i++) {
mList.add("测试数据" + i + "号");
// 这里要放在里面刷新,放在外面会导致刷新的进度条卡住
mAdapter.notifyDataSetChanged();
}
Toast.makeText(SwipeRefreshLayoutActivity.this, "加载了" + 5 + "条数据", Toast.LENGTH_SHORT).show();
// 加载完数据设置为不加载状态,将加载进度收起来
swipeRefreshView.setLoading(false);
}
}, 1200);
}
});
}
use of android.support.v4.widget.SwipeRefreshLayout in project vlayout by alibaba.
the class VLayoutActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container);
;
mFirstText = (TextView) findViewById(R.id.first);
mLastText = (TextView) findViewById(R.id.last);
mCountText = (TextView) findViewById(R.id.count);
mTotalOffsetText = (TextView) findViewById(R.id.total_offset);
final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.main_view);
final VirtualLayoutManager layoutManager = new VirtualLayoutManager(this);
layoutManager.setPerformanceMonitor(new PerformanceMonitor() {
long start;
long end;
@Override
public void recordStart(String phase, View view) {
start = System.currentTimeMillis();
}
@Override
public void recordEnd(String phase, View view) {
end = System.currentTimeMillis();
Log.d("VLayoutActivity", view.getClass().getName() + " " + (end - start));
}
});
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int scrollState) {
}
@Override
public void onScrolled(RecyclerView recyclerView, int i, int i2) {
mFirstText.setText("First: " + layoutManager.findFirstVisibleItemPosition());
mLastText.setText("Existing: " + MainViewHolder.existing + " Created: " + MainViewHolder.createdTimes);
mCountText.setText("Count: " + recyclerView.getChildCount());
mTotalOffsetText.setText("Total Offset: " + layoutManager.getOffsetToStart());
}
});
recyclerView.setLayoutManager(layoutManager);
// layoutManager.setReverseLayout(true);
RecyclerView.ItemDecoration itemDecoration = new RecyclerView.ItemDecoration() {
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
int position = ((LayoutParams) view.getLayoutParams()).getViewPosition();
outRect.set(4, 4, 4, 4);
}
};
final RecyclerView.RecycledViewPool viewPool = new RecyclerView.RecycledViewPool();
recyclerView.setRecycledViewPool(viewPool);
// recyclerView.addItemDecoration(itemDecoration);
viewPool.setMaxRecycledViews(0, 20);
layoutManager.setRecycleOffset(300);
// viewLifeCycleListener should be used with setRecycleOffset()
layoutManager.setViewLifeCycleListener(new ViewLifeCycleListener() {
@Override
public void onAppearing(View view) {
// Log.e("ViewLifeCycleTest", "onAppearing: " + view);
}
@Override
public void onDisappearing(View view) {
// Log.e("ViewLifeCycleTest", "onDisappearing: " + view);
}
@Override
public void onAppeared(View view) {
// Log.e("ViewLifeCycleTest", "onAppeared: " + view);
}
@Override
public void onDisappeared(View view) {
// Log.e("ViewLifeCycleTest", "onDisappeared: " + view);
}
});
layoutManager.setLayoutManagerCanScrollListener(new LayoutManagerCanScrollListener() {
@Override
public boolean canScrollVertically() {
Log.i("vlayout", "canScrollVertically: ");
return true;
}
@Override
public boolean canScrollHorizontally() {
Log.i("vlayout", "canScrollHorizontally: ");
return true;
}
});
final DelegateAdapter delegateAdapter = new DelegateAdapter(layoutManager, true);
recyclerView.setAdapter(delegateAdapter);
final List<DelegateAdapter.Adapter> adapters = new LinkedList<>();
if (BANNER_LAYOUT) {
adapters.add(new SubAdapter(this, new LinearLayoutHelper(), 1) {
@Override
public void onViewRecycled(MainViewHolder holder) {
if (holder.itemView instanceof ViewPager) {
((ViewPager) holder.itemView).setAdapter(null);
}
}
@Override
public MainViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
if (viewType == 1)
return new MainViewHolder(LayoutInflater.from(VLayoutActivity.this).inflate(R.layout.view_pager, parent, false));
return super.onCreateViewHolder(parent, viewType);
}
@Override
public int getItemViewType(int position) {
return 1;
}
@Override
protected void onBindViewHolderWithOffset(MainViewHolder holder, int position, int offsetTotal) {
}
@Override
public void onBindViewHolder(MainViewHolder holder, int position) {
if (holder.itemView instanceof ViewPager) {
ViewPager viewPager = (ViewPager) holder.itemView;
viewPager.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 200));
// from position to get adapter
viewPager.setAdapter(new PagerAdapter(this, viewPool));
}
}
});
}
if (FLOAT_LAYOUT) {
FloatLayoutHelper layoutHelper = new FloatLayoutHelper();
layoutHelper.setAlignType(FixLayoutHelper.BOTTOM_RIGHT);
layoutHelper.setDefaultLocation(100, 400);
LayoutParams layoutParams = new LayoutParams(150, 150);
adapters.add(new SubAdapter(this, layoutHelper, 1, layoutParams));
}
if (LINEAR_LAYOUT) {
LinearLayoutHelper layoutHelper1 = new LinearLayoutHelper();
layoutHelper1.setBgColor(Color.YELLOW);
layoutHelper1.setAspectRatio(2.0f);
layoutHelper1.setMargin(10, 10, 10, 10);
layoutHelper1.setPadding(10, 10, 10, 10);
LinearLayoutHelper layoutHelper2 = new LinearLayoutHelper();
layoutHelper2.setAspectRatio(4.0f);
layoutHelper2.setDividerHeight(10);
layoutHelper2.setMargin(10, 0, 10, 10);
layoutHelper2.setPadding(10, 0, 10, 10);
layoutHelper2.setBgColor(0xFFF5A623);
final Handler mainHandler = new Handler(Looper.getMainLooper());
adapters.add(new SubAdapter(this, layoutHelper1, 1) {
@Override
public void onBindViewHolder(final MainViewHolder holder, int position) {
super.onBindViewHolder(holder, position);
final SubAdapter subAdapter = this;
// mainHandler.postDelayed(new Runnable() {
// @Override
// public void run() {
// //delegateAdapter.removeAdapter(subAdapter);
// //notifyItemRemoved(1);
// holder.itemView.setVisibility(View.GONE);
// notifyItemChanged(1);
// layoutManager.runAdjustLayout();
// }
// }, 2000L);
}
});
adapters.add(new SubAdapter(this, layoutHelper2, 6) {
@Override
public void onBindViewHolder(MainViewHolder holder, int position) {
if (position % 2 == 0) {
LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 300);
layoutParams.mAspectRatio = 5;
holder.itemView.setLayoutParams(layoutParams);
}
}
});
}
// {
// RangeGridLayoutHelper layoutHelper = new RangeGridLayoutHelper(4);
// layoutHelper.setBgColor(Color.GREEN);
// layoutHelper.setWeights(new float[]{20f, 26.665f});
// layoutHelper.setPadding(15, 15, 15, 15);
// layoutHelper.setMargin(15, 50, 15, 150);
// layoutHelper.setHGap(10);
// layoutHelper.setVGap(10);
// GridRangeStyle rangeStyle = new GridRangeStyle();
// rangeStyle.setBgColor(Color.RED);
// rangeStyle.setSpanCount(2);
// rangeStyle.setWeights(new float[]{46.665f});
// rangeStyle.setPadding(15, 15, 15, 15);
// rangeStyle.setMargin(15, 15, 15, 15);
// rangeStyle.setHGap(5);
// rangeStyle.setVGap(5);
// layoutHelper.addRangeStyle(0, 7, rangeStyle);
//
// GridRangeStyle rangeStyle1 = new GridRangeStyle();
// rangeStyle1.setBgColor(Color.YELLOW);
// rangeStyle1.setSpanCount(2);
// rangeStyle1.setWeights(new float[]{46.665f});
// rangeStyle1.setPadding(15, 15, 15, 15);
// rangeStyle1.setMargin(15, 15, 15, 15);
// rangeStyle1.setHGap(5);
// rangeStyle1.setVGap(5);
// layoutHelper.addRangeStyle(8, 15, rangeStyle1);
//
// GridRangeStyle rangeStyle2 = new GridRangeStyle();
// rangeStyle2.setBgColor(Color.CYAN);
// rangeStyle2.setSpanCount(2);
// rangeStyle2.setWeights(new float[]{46.665f});
// rangeStyle2.setPadding(15, 15, 15, 15);
// rangeStyle2.setMargin(15, 15, 15, 15);
// rangeStyle2.setHGap(5);
// rangeStyle2.setVGap(5);
// layoutHelper.addRangeStyle(16, 22, rangeStyle2);
// GridRangeStyle rangeStyle3 = new GridRangeStyle();
// rangeStyle3.setBgColor(Color.DKGRAY);
// rangeStyle3.setSpanCount(1);
// rangeStyle3.setWeights(new float[]{46.665f});
// rangeStyle3.setPadding(15, 15, 15, 15);
// rangeStyle3.setMargin(15, 15, 15, 15);
// rangeStyle3.setHGap(5);
// rangeStyle3.setVGap(5);
// rangeStyle2.addChildRangeStyle(0, 2, rangeStyle3);
// GridRangeStyle rangeStyle4 = new GridRangeStyle();
// rangeStyle4.setBgColor(Color.BLUE);
// rangeStyle4.setSpanCount(2);
// rangeStyle4.setWeights(new float[]{46.665f});
// rangeStyle4.setPadding(15, 15, 15, 15);
// rangeStyle4.setMargin(15, 15, 15, 15);
// rangeStyle4.setHGap(5);
// rangeStyle4.setVGap(5);
// rangeStyle2.addChildRangeStyle(3, 6, rangeStyle4);
//
// GridRangeStyle rangeStyle5 = new GridRangeStyle();
// rangeStyle5.setBgColor(Color.RED);
// rangeStyle5.setSpanCount(2);
// rangeStyle5.setPadding(15, 15, 15, 15);
// rangeStyle5.setMargin(15, 15, 15, 15);
// rangeStyle5.setHGap(5);
// rangeStyle5.setVGap(5);
// layoutHelper.addRangeStyle(23, 30, rangeStyle5);
// GridRangeStyle rangeStyle6 = new GridRangeStyle();
// rangeStyle6.setBgColor(Color.MAGENTA);
// rangeStyle6.setSpanCount(2);
// rangeStyle6.setPadding(15, 15, 15, 15);
// rangeStyle6.setMargin(15, 15, 15, 15);
// rangeStyle6.setHGap(5);
// rangeStyle6.setVGap(5);
// rangeStyle5.addChildRangeStyle(0, 7, rangeStyle6);
//
// adapters.add(new SubAdapter(this, layoutHelper, 23));
// }
{
SingleLayoutHelper layoutHelper = new SingleLayoutHelper();
layoutHelper.setBgColor(Color.BLUE);
layoutHelper.setMargin(0, 30, 0, 200);
adapters.add(new SubAdapter(this, layoutHelper, 1, new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 100)));
}
if (STICKY_LAYOUT) {
StickyLayoutHelper layoutHelper = new StickyLayoutHelper();
// layoutHelper.setOffset(100);
layoutHelper.setAspectRatio(4);
adapters.add(new SubAdapter(this, layoutHelper, 1, new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 100)));
}
// {
// final StaggeredGridLayoutHelper helper = new StaggeredGridLayoutHelper(3, 10);
// helper.setBgColor(0xFF86345A);
// adapters.add(new SubAdapter(this, helper, 4) {
//
// @Override
// public void onBindViewHolder(MainViewHolder holder, int position) {
// super.onBindViewHolder(holder, position);
// LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 300);
// if (position % 2 == 0) {
// layoutParams.mAspectRatio = 1.0f;
// } else {
// layoutParams.height = 340 + position % 7 * 20;
// }
// holder.itemView.setLayoutParams(layoutParams);
// }
// });
// }
{
final GridLayoutHelper helper = new GridLayoutHelper(3, 4);
helper.setBgColor(0xFF86345A);
adapters.add(new SubAdapter(this, helper, 4) {
@Override
public void onBindViewHolder(MainViewHolder holder, int position) {
super.onBindViewHolder(holder, position);
LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 300);
holder.itemView.setLayoutParams(layoutParams);
}
});
}
{
RangeGridLayoutHelper layoutHelper = new RangeGridLayoutHelper(4);
layoutHelper.setBgColor(Color.GREEN);
layoutHelper.setWeights(new float[] { 20f, 26.665f });
layoutHelper.setPadding(15, 15, 15, 15);
layoutHelper.setMargin(15, 15, 15, 15);
layoutHelper.setHGap(10);
layoutHelper.setVGap(10);
GridRangeStyle rangeStyle = new GridRangeStyle();
rangeStyle.setBgColor(Color.RED);
rangeStyle.setSpanCount(2);
rangeStyle.setWeights(new float[] { 46.665f });
rangeStyle.setPadding(15, 15, 15, 15);
rangeStyle.setMargin(15, 15, 15, 15);
rangeStyle.setHGap(5);
rangeStyle.setVGap(5);
layoutHelper.addRangeStyle(4, 7, rangeStyle);
GridRangeStyle rangeStyle1 = new GridRangeStyle();
rangeStyle1.setBgColor(Color.YELLOW);
rangeStyle1.setSpanCount(2);
rangeStyle1.setWeights(new float[] { 46.665f });
rangeStyle1.setPadding(15, 15, 15, 15);
rangeStyle1.setMargin(15, 15, 15, 15);
rangeStyle1.setHGap(5);
rangeStyle1.setVGap(5);
layoutHelper.addRangeStyle(8, 11, rangeStyle1);
adapters.add(new SubAdapter(this, layoutHelper, 16));
}
if (SINGLE_LAYOUT) {
SingleLayoutHelper layoutHelper = new SingleLayoutHelper();
layoutHelper.setBgColor(Color.rgb(135, 225, 90));
layoutHelper.setAspectRatio(4);
layoutHelper.setMargin(10, 20, 10, 20);
layoutHelper.setPadding(10, 10, 10, 10);
adapters.add(new SubAdapter(this, layoutHelper, 1, new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 100)));
}
if (COLUMN_LAYOUT) {
ColumnLayoutHelper layoutHelper = new ColumnLayoutHelper();
layoutHelper.setBgColor(0xff00f0f0);
layoutHelper.setWeights(new float[] { 40.0f, Float.NaN, 40 });
adapters.add(new SubAdapter(this, layoutHelper, 5) {
@Override
public void onBindViewHolder(MainViewHolder holder, int position) {
if (position == 0) {
LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 300);
layoutParams.mAspectRatio = 4;
holder.itemView.setLayoutParams(layoutParams);
} else {
LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 300);
layoutParams.mAspectRatio = Float.NaN;
holder.itemView.setLayoutParams(layoutParams);
}
}
});
}
if (ONEN_LAYOUT) {
OnePlusNLayoutHelper helper = new OnePlusNLayoutHelper();
helper.setBgColor(0xff876384);
helper.setAspectRatio(4.0f);
helper.setColWeights(new float[] { 40f, 45f });
helper.setMargin(10, 20, 10, 20);
helper.setPadding(10, 10, 10, 10);
adapters.add(new SubAdapter(this, helper, 2));
}
if (ONEN_LAYOUT) {
OnePlusNLayoutHelper helper = new OnePlusNLayoutHelper();
helper.setBgColor(0xffef8ba3);
helper.setAspectRatio(2.0f);
helper.setColWeights(new float[] { 40f });
helper.setRowWeight(30f);
helper.setMargin(10, 20, 10, 20);
helper.setPadding(10, 10, 10, 10);
adapters.add(new SubAdapter(this, helper, 4) {
@Override
public void onBindViewHolder(MainViewHolder holder, int position) {
super.onBindViewHolder(holder, position);
LayoutParams lp = (LayoutParams) holder.itemView.getLayoutParams();
if (position == 0) {
lp.rightMargin = 1;
} else if (position == 1) {
} else if (position == 2) {
lp.topMargin = 1;
lp.rightMargin = 1;
}
}
});
}
if (ONEN_LAYOUT) {
adapters.add(new SubAdapter(this, new OnePlusNLayoutHelper(), 0));
OnePlusNLayoutHelper helper = new OnePlusNLayoutHelper();
helper.setBgColor(0xff87e543);
helper.setAspectRatio(1.8f);
helper.setColWeights(new float[] { 33.33f, 50f, 40f });
helper.setMargin(10, 20, 10, 20);
helper.setPadding(10, 10, 10, 10);
LayoutParams lp = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
adapters.add(new SubAdapter(this, helper, 3, lp) {
@Override
public void onBindViewHolder(MainViewHolder holder, int position) {
super.onBindViewHolder(holder, position);
LayoutParams lp = (LayoutParams) holder.itemView.getLayoutParams();
if (position == 0) {
lp.rightMargin = 1;
}
}
});
}
if (COLUMN_LAYOUT) {
adapters.add(new SubAdapter(this, new ColumnLayoutHelper(), 0));
adapters.add(new SubAdapter(this, new ColumnLayoutHelper(), 4));
}
if (FIX_LAYOUT) {
FixLayoutHelper layoutHelper = new FixLayoutHelper(10, 10);
adapters.add(new SubAdapter(this, layoutHelper, 0));
layoutHelper = new FixLayoutHelper(FixLayoutHelper.TOP_RIGHT, 20, 20);
adapters.add(new SubAdapter(this, layoutHelper, 1) {
@Override
public void onBindViewHolder(MainViewHolder holder, int position) {
super.onBindViewHolder(holder, position);
LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 200);
holder.itemView.setLayoutParams(layoutParams);
}
});
}
if (GRID_LAYOUT) {
GridLayoutHelper layoutHelper = new GridLayoutHelper(2);
layoutHelper.setMargin(7, 0, 7, 0);
layoutHelper.setWeights(new float[] { 46.665f });
layoutHelper.setHGap(3);
adapters.add(new SubAdapter(this, layoutHelper, 2));
layoutHelper = new GridLayoutHelper(4);
layoutHelper.setWeights(new float[] { 20f, 26.665f });
layoutHelper.setMargin(7, 0, 7, 0);
layoutHelper.setHGap(3);
adapters.add(new SubAdapter(this, layoutHelper, 8));
}
if (GRID_LAYOUT) {
adapters.add(new SubAdapter(this, new GridLayoutHelper(4), 0));
GridLayoutHelper helper = new GridLayoutHelper(4);
helper.setAspectRatio(4f);
// helper.setColWeights(new float[]{40, 20, 30, 30});
// helper.setMargin(0, 10, 0, 10);
helper.setGap(10);
adapters.add(new SubAdapter(this, helper, 80) {
@Override
public void onBindViewHolder(MainViewHolder holder, int position) {
super.onBindViewHolder(holder, position);
LayoutParams lp = (LayoutParams) holder.itemView.getLayoutParams();
// lp.bottomMargin = 1;
// lp.rightMargin = 1;
}
});
}
if (FIX_LAYOUT) {
adapters.add(new SubAdapter(this, new ScrollFixLayoutHelper(20, 20), 1) {
@Override
public void onBindViewHolder(MainViewHolder holder, int position) {
super.onBindViewHolder(holder, position);
LayoutParams layoutParams = new LayoutParams(200, 200);
holder.itemView.setLayoutParams(layoutParams);
}
});
}
if (LINEAR_LAYOUT)
adapters.add(new SubAdapter(this, new LinearLayoutHelper(), 10));
if (GRID_LAYOUT) {
GridLayoutHelper helper = new GridLayoutHelper(3);
helper.setMargin(0, 10, 0, 10);
adapters.add(new SubAdapter(this, helper, 3));
}
if (STAGGER_LAYOUT) {
// adapters.add(new SubAdapter(this, new StaggeredGridLayoutHelper(2, 0), 0));
final StaggeredGridLayoutHelper helper = new StaggeredGridLayoutHelper(2, 10);
helper.setMargin(20, 10, 10, 10);
helper.setPadding(10, 10, 20, 10);
helper.setBgColor(0xFF86345A);
adapters.add(new SubAdapter(this, helper, 27) {
@Override
public void onBindViewHolder(MainViewHolder holder, int position) {
super.onBindViewHolder(holder, position);
LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 200);
if (position % 2 == 0) {
layoutParams.mAspectRatio = 1.0f;
} else {
layoutParams.height = 340 + position % 7 * 20;
}
holder.itemView.setLayoutParams(layoutParams);
}
});
}
if (COLUMN_LAYOUT) {
// adapters.add(new SubAdapter(this, new ColumnLayoutHelper(), 3));
}
if (GRID_LAYOUT) {
// adapters.add(new SubAdapter(this, new GridLayoutHelper(4), 24));
}
adapters.add(new FooterAdapter(recyclerView, VLayoutActivity.this, new GridLayoutHelper(1), 1));
delegateAdapter.setAdapters(adapters);
final Handler mainHandler = new Handler(Looper.getMainLooper());
trigger = new Runnable() {
@Override
public void run() {
// recyclerView.scrollToPosition(22);
// recyclerView.getAdapter().notifyDataSetChanged();
// mainHandler.postDelayed(trigger, 1000);
// List<DelegateAdapter.Adapter> newAdapters = new ArrayList<>();
// newAdapters.add((new SubAdapter(VLayoutActivity.this, new ColumnLayoutHelper(), 3)));
// newAdapters.add((new SubAdapter(VLayoutActivity.this, new GridLayoutHelper(4), 24)));
// delegateAdapter.addAdapter(0, new SubAdapter(VLayoutActivity.this, new ColumnLayoutHelper(), 3));
// delegateAdapter.addAdapter(1, new SubAdapter(VLayoutActivity.this, new GridLayoutHelper(4), 24));
// delegateAdapter.notifyDataSetChanged();
}
};
findViewById(R.id.jump).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
EditText position = (EditText) findViewById(R.id.position);
if (!TextUtils.isEmpty(position.getText())) {
try {
int pos = Integer.parseInt(position.getText().toString());
recyclerView.scrollToPosition(pos);
} catch (Exception e) {
Log.e("VlayoutActivity", e.getMessage(), e);
}
} else {
recyclerView.requestLayout();
}
// FooterAdapter footer = (FooterAdapter)adapters.get(adapters.size() - 1);
// footer.toggleFoot();
}
});
mainHandler.postDelayed(trigger, 1000);
mSwipeRefreshLayout.setOnRefreshListener(new OnRefreshListener() {
@Override
public void onRefresh() {
mainHandler.postDelayed(new Runnable() {
@Override
public void run() {
mSwipeRefreshLayout.setRefreshing(false);
}
}, 2000L);
}
});
setListenerToRootView();
}
use of android.support.v4.widget.SwipeRefreshLayout in project Reader by TheKeeperOfPie.
the class FragmentProfile method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_profile, container, false);
layoutCoordinator = (CoordinatorLayout) view.findViewById(R.id.layout_coordinator);
layoutAppBar = (AppBarLayout) view.findViewById(R.id.layout_app_bar);
listener = new ControllerProfile.Listener() {
@Override
public void setSortAndTime(Sort sort, Time time) {
menu.findItem(sort.getMenuId()).setChecked(true);
menu.findItem(time.getMenuId()).setChecked(true);
itemSortTime.setTitle(getString(R.string.time_description, menu.findItem(controllerProfile.getTime().getMenuId()).toString()));
}
@Override
public void setPage(Page page) {
spinnerPage.setSelection(adapterProfilePage.getPages().indexOf(page));
if (page.getPage().equals(ControllerProfile.PAGE_HIDDEN)) {
callback.setDrawable(getResources().getDrawable(R.drawable.ic_visibility_white_24dp));
} else {
callback.setDrawable(getResources().getDrawable(R.drawable.ic_visibility_off_white_24dp));
}
}
@Override
public void setIsUser(boolean isUser) {
// TODO: Fix set page for Profile view
adapterProfilePage.setIsUser(isUser);
}
@Override
public void loadLink(Comment comment) {
Log.d(TAG, "Link ID: " + comment.getLinkId());
Intent intent = new Intent(activity, ActivityMain.class);
intent.setAction(Intent.ACTION_VIEW);
intent.putExtra(ActivityMain.REDDIT_PAGE, Reddit.BASE_URL + "/r/" + comment.getSubreddit() + "/comments/" + comment.getLinkId().replace("t3_", ""));
startActivity(intent);
}
@Override
public RecyclerView.Adapter getAdapter() {
return adapterProfile;
}
@Override
public void setToolbarTitle(CharSequence title) {
toolbar.setTitle(title);
}
@Override
public void setRefreshing(boolean refreshing) {
swipeRefreshProfile.setRefreshing(refreshing);
}
@Override
public void post(Runnable runnable) {
recyclerProfile.post(runnable);
}
};
int styleColorBackground = AppSettings.THEME_DARK.equals(mListener.getThemeBackground()) ? R.style.MenuDark : R.style.MenuLight;
ContextThemeWrapper contextThemeWrapper = new ContextThemeWrapper(new ThemeWrapper(activity, UtilsColor.getThemeForColor(getResources(), themer.getColorPrimary(), mListener)), styleColorBackground);
toolbar = (Toolbar) activity.getLayoutInflater().cloneInContext(contextThemeWrapper).inflate(R.layout.toolbar, layoutAppBar, false);
layoutAppBar.addView(toolbar);
((AppBarLayout.LayoutParams) toolbar.getLayoutParams()).setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS);
if (getFragmentManager().getBackStackEntryCount() <= 1) {
toolbar.setNavigationIcon(R.drawable.ic_menu_white_24dp);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mListener.openDrawer();
}
});
} else {
toolbar.setNavigationIcon(R.drawable.ic_arrow_back_white_24dp);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mListener.onNavigationBackClick();
}
});
}
toolbar.getNavigationIcon().mutate().setColorFilter(themer.getColorFilterPrimary());
toolbar.setTitleTextColor(themer.getColorFilterPrimary().getColor());
setUpOptionsMenu();
adapterProfilePage = new AdapterProfilePage(activity);
spinnerPage = new AppCompatSpinner(contextThemeWrapper);
toolbar.addView(spinnerPage);
((Toolbar.LayoutParams) spinnerPage.getLayoutParams()).setMarginEnd((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, getResources().getDisplayMetrics()));
spinnerPage.setAdapter(adapterProfilePage);
spinnerPage.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
controllerProfile.setPage(adapterProfilePage.getItem(position)).subscribe(getReloadObserver());
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
swipeRefreshProfile = (SwipeRefreshLayout) view.findViewById(R.id.swipe_refresh_profile);
swipeRefreshProfile.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
controllerProfile.reload().subscribe(getReloadObserver());
}
});
linearLayoutManager = new LinearLayoutManager(activity);
recyclerProfile = (RecyclerView) view.findViewById(R.id.recycler_profile);
recyclerProfile.setHasFixedSize(true);
recyclerProfile.setItemAnimator(null);
recyclerProfile.setLayoutManager(linearLayoutManager);
recyclerProfile.addItemDecoration(new ItemDecorationDivider(activity, ItemDecorationDivider.VERTICAL_LIST));
AdapterListener adapterListener = new AdapterListener() {
@Override
public void scrollAndCenter(int position, int height) {
UtilsAnimation.scrollToPositionWithCentering(position, recyclerProfile, false);
}
@Override
public void hideToolbar() {
AppBarLayout.Behavior behaviorAppBar = (AppBarLayout.Behavior) ((CoordinatorLayout.LayoutParams) layoutAppBar.getLayoutParams()).getBehavior();
behaviorAppBar.onNestedFling(layoutCoordinator, layoutAppBar, null, 0, 1000, true);
}
@Override
public void clearDecoration() {
AppBarLayout.Behavior behaviorAppBar = (AppBarLayout.Behavior) ((CoordinatorLayout.LayoutParams) layoutAppBar.getLayoutParams()).getBehavior();
behaviorAppBar.onNestedFling(layoutCoordinator, layoutAppBar, null, 0, 1000, true);
}
@Override
public void requestMore() {
controllerProfile.loadMoreLinks().observeOn(AndroidSchedulers.mainThread()).subscribe(new ObserverError<Listing>() {
@Override
public void onError(Throwable e) {
Toast.makeText(getContext(), getString(R.string.error_loading_links), Toast.LENGTH_SHORT).show();
}
});
}
@Override
public void requestDisallowInterceptTouchEventVertical(boolean disallow) {
recyclerProfile.requestDisallowInterceptTouchEvent(disallow);
swipeRefreshProfile.requestDisallowInterceptTouchEvent(disallow);
itemTouchHelper.select(null, CustomItemTouchHelper.ACTION_STATE_IDLE);
}
@Override
public void requestDisallowInterceptTouchEventHorizontal(boolean disallow) {
itemTouchHelper.setDisallow(disallow);
}
};
AdapterLink.ViewHolderLink.Listener listenerLink = new AdapterLink.ViewHolderLink.Listener() {
@Override
public void onSubmitComment(Link link, String text) {
}
@Override
public void onDownloadImage(Link link) {
}
@Override
public void onDownloadImage(Link link, String title, String fileName, String url) {
}
@Override
public void onLoadUrl(Link link, boolean forceExternal) {
}
@Override
public void onShowFullEditor(Link link) {
}
@Override
public void onVote(Link link, AdapterLink.ViewHolderLink viewHolderLink, Likes vote) {
}
@Override
public void onCopyText(Link link) {
}
@Override
public void onEdit(Link link) {
}
@Override
public void onDelete(Link link) {
}
@Override
public void onReport(Link link) {
}
@Override
public void onSave(Link link) {
}
@Override
public void onShowComments(Link link, AdapterLink.ViewHolderLink viewHolderLink, Source source) {
}
@Override
public void onShowError(String error) {
}
@Override
public void onMarkNsfw(Link link) {
}
};
AdapterCommentList.ViewHolderComment.Listener listenerComments = new AdapterCommentList.ViewHolderComment.Listener() {
@Override
public void onToggleComment(Comment comment) {
}
@Override
public void onShowReplyEditor(Comment comment) {
}
@Override
public void onEditComment(Comment comment, String text) {
}
@Override
public void onSendComment(Comment comment, String text) {
}
@Override
public void onMarkRead(Comment comment) {
}
@Override
public void onLoadNestedComments(Comment comment) {
}
@Override
public void onJumpToParent(Comment comment) {
}
@Override
public void onViewProfile(Comment comment) {
}
@Override
public void onCopyText(Comment comment) {
}
@Override
public void onDeleteComment(Comment comment) {
}
@Override
public void onReport(Comment comment) {
}
@Override
public void onVoteComment(Comment comment, AdapterCommentList.ViewHolderComment viewHolderComment, Likes vote) {
}
@Override
public void onSave(Comment comment) {
}
};
if (adapterProfile == null) {
adapterProfile = new AdapterProfile(getActivity(), controllerProfile, adapterListener, listenerLink, listenerComments, listener);
}
recyclerProfile.setAdapter(adapterProfile);
callback = new CustomItemTouchHelper.SimpleCallback(activity, R.drawable.ic_delete_white_24dp, ItemTouchHelper.START | ItemTouchHelper.END, ItemTouchHelper.START | ItemTouchHelper.END) {
@Override
public int getSwipeDirs(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
int position = viewHolder.getAdapterPosition();
if (position == 2 || (position >= 6 && controllerProfile.getViewType(position - 6) == ControllerProfile.VIEW_TYPE_LINK)) {
return super.getSwipeDirs(recyclerView, viewHolder);
}
return 0;
}
@Override
public boolean isLongPressDragEnabled() {
return false;
}
@Override
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
return false;
}
@Override
public void onSwiped(final RecyclerView.ViewHolder viewHolder, int direction) {
Log.d(TAG, "onSwiped: " + viewHolder.getAdapterPosition());
final int adapterPosition = viewHolder.getAdapterPosition();
final int position = adapterPosition == 2 ? -1 : adapterPosition - 6;
final Link link = adapterPosition == 2 ? controllerProfile.remove(-1) : controllerProfile.remove(position);
mListener.getEventListenerBase().hide(link);
if (snackbar != null) {
snackbar.dismiss();
}
SpannableString text = new SpannableString(link.isHidden() ? getString(R.string.link_hidden) : getString(R.string.link_shown));
text.setSpan(new ForegroundColorSpan(themer.getColorFilterPrimary().getColor()), 0, text.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
// noinspection ResourceType
snackbar = Snackbar.make(recyclerProfile, text, UtilsAnimation.SNACKBAR_DURATION).setActionTextColor(themer.getColorFilterPrimary().getColor()).setAction(R.string.undo, new View.OnClickListener() {
@Override
public void onClick(View v) {
mListener.getEventListenerBase().hide(link);
if (adapterPosition == 2) {
controllerProfile.setTopLink(link);
adapterProfile.notifyItemChanged(2);
} else {
controllerProfile.add(position, link);
}
recyclerProfile.invalidate();
}
});
snackbar.getView().setBackgroundColor(themer.getColorPrimary());
snackbar.show();
}
};
itemTouchHelper = new CustomItemTouchHelper(callback);
itemTouchHelper.attachToRecyclerView(recyclerProfile);
return view;
}
use of android.support.v4.widget.SwipeRefreshLayout in project BleLiteLib4android by afunx.
the class ScanActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scan);
mHandler = new Handler();
mListView = (ListView) findViewById(R.id.lv_devices);
mBleDeviceAdapter = new BleDeviceAdapter(this);
mListView.setAdapter(mBleDeviceAdapter);
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
BleDevice bleDevice = (BleDevice) mBleDeviceAdapter.getItem(position);
// ServiceListActivity.startActivity(ScanActivity.this, bleDevice.getBluetoothDevice());
TestActivity.startActivity(ScanActivity.this, bleDevice.getBluetoothDevice());
}
});
mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipeRefreshLayout);
mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
doRefresh();
}
});
mLeScanCallback = new BluetoothAdapter.LeScanCallback() {
private long timestamp = 0;
private final long interval = 200;
@Override
public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) {
BleDevice bleDevice = new BleDevice();
bleDevice.setBluetoothDevice(device);
bleDevice.setRssi(rssi);
bleDevice.setScanRecord(scanRecord);
if (mBleDeviceAdapter.addOrUpdateDevice(bleDevice)) {
timestamp = System.currentTimeMillis();
mBleDeviceAdapter.notifyDataSetChanged();
} else {
if (System.currentTimeMillis() - timestamp > interval) {
timestamp = System.currentTimeMillis();
mBleDeviceAdapter.notifyDataSetChanged();
}
}
}
};
BleUtils.enableBluetooth();
BleProxy.getInstance().init(getApplicationContext());
requestBleAuthority();
}
Aggregations