// 初始化每个页面的数据 private void initPageView(LinearLayout root, int i) { DayBean bean = data.getContent().get(i); int layoutIndex = lastDayTime != bean.getTime() ? 0 : (bean.getSrc().length == 1 ? 1 : 2); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ScreenUtils.getScreenW(), ScreenUtils.getScreenH()); View v = View.inflate(getContext(), layoutIds[layoutIndex], null); v.setLayoutParams(params); if (layoutIndex == 0) { initItem1(v, bean); lastDayTime = bean.getTime(); nowDay++; root.addView(v); pageViews.add(new PageView(v, pageSum, bean, true)); pageSum++; // 如果是日期页面,则继续加载 params = new LinearLayout.LayoutParams(ScreenUtils.getScreenW(), ScreenUtils.getScreenH()); layoutIndex = (bean.getSrc().length == 1 ? 1 : 2); v = View.inflate(getContext(), layoutIds[layoutIndex], null); v.setLayoutParams(params); } if (layoutIndex == 1) { initItem2(v, bean); } else { initItem3(v, bean); } root.addView(v); pageViews.add(new PageView(v, pageSum, bean, false)); pageSum++; }
/** * f**k!!!!!! * @param scrollY, 纵向滑动距离 */ @Override public void onScroll(int scrollY) { getTopDistance(); if (toolbar.getVisibility() == View.INVISIBLE) { stickyTop = stickyTop - ScreenUtils.getStatusBarHeight(this); } else if (toolbar.getVisibility() == View.VISIBLE) { stickyTop = stickyTop + ScreenUtils.getStatusBarHeight(this); } if (scrollY < showTop) { // 在长草理由没有到顶的时候是不显示vote栏的 if (linearLayout.getVisibility() == View.VISIBLE) { destoryFrame(); } } else if (scrollY >= showTop && scrollY < stickyTop && Math.abs(stickyTop - scrollY) > Math.abs(showTop - scrollY)) { // 位置在showTop和stickyTop之间,切处于靠近showTop的位置 if (linearLayout.getVisibility() == View.INVISIBLE) { showFrame(); } } else if (scrollY >= showTop && scrollY < stickyTop && Math.abs(stickyTop - scrollY) < Math.abs(showTop - scrollY)) { // 位置在showTop和stickyTop之间,且处于靠近stickyTop的位置 if (linearLayout.getVisibility() == View.INVISIBLE) { linearLayout.setVisibility(View.VISIBLE); } } else if (scrollY >= stickyTop) { // 如果滑动到了vote区域,就不显示vote栏,直观看上去就是固定在了scrollview上 linearLayout.setVisibility(View.INVISIBLE); } }
// 滚动停止 ,重置view private void resetView() { int dis = getScrollX() % ScreenUtils.getScreenW(); if (Math.abs(dis) >= ScreenUtils.getScreenW() / 2) { distance = ScreenUtils.getScreenW() - dis; } else { distance = dis * -1; } handler.sendEmptyMessageDelayed(autoScroll, SpaceTime); }
public static Bitmap cretaeBitmap(Context c, String str, Bitmap mBitmap) throws WriterException { // 生成二维矩阵,编码时指定大小,不要生成了图片以后再进行缩放,这样会模糊导致识别失败 int qr_width = ScreenUtils.getScreenWidth(c) * 2 / 3; int qr_height = qr_width; BitMatrix matrix = new MultiFormatWriter().encode(str, BarcodeFormat.QR_CODE, qr_width, qr_height); // BitMatrix matrix = new MultiFormatWriter().encode(str, BarcodeFormat.QR_CODE, 300, // 300);//如果要指定二维码的边框以及容错率,最好给encode方法增加一个参数:hints 一个Hashmap int width = matrix.getWidth(); int height = matrix.getHeight(); // 二维矩阵转为一维像素数组,也就是一直横着排了 int halfW = width / 2; int halfH = height / 2; int[] pixels = new int[width * height]; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { if (x > halfW - Const.IMAGE_HALFWIDTH && x < halfW + Const.IMAGE_HALFWIDTH && y > halfH - Const.IMAGE_HALFWIDTH && y < halfH + Const.IMAGE_HALFWIDTH) { pixels[y * width + x] = mBitmap.getPixel( x - halfW + Const.IMAGE_HALFWIDTH, y - halfH + Const.IMAGE_HALFWIDTH); } else { // 此处可以修改二维码的颜色,可以分别制定二维码和背景的颜色; pixels[y * width + x] = matrix.get(x, y) ? 0xff000000 : 0xfffffff; } } } Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); // 通过像素数组生成bitmap bitmap.setPixels(pixels, 0, width, 0, 0, width, height); return bitmap; }
@Override public void handleMessage(Message msg) { super.handleMessage(msg); switch (msg.what) { case -10086: if (lastX == getScrollX()) { resetView(); } else { if (Math.abs(getScrollX() - lastX) <= MINSPEED) { stopScroll(); } else { handler.sendMessageDelayed(handler.obtainMessage(ViewScrollTag), SpaceTime); } lastX = getScrollX(); } break; case 1: // 自动滚动 int add = distance > 0 ? 1 : -1; if (Math.abs(distance) > speed) { scrollTo(speed * add + getScrollX(), 0); sendEmptyMessageDelayed(autoScroll, SpaceTime); distance -= speed * add; } else { scrollTo(distance * add + getScrollX(), 0); distance = 0; nowPage = getScrollX() / ScreenUtils.getScreenW(); Log.e(TAG, nowPage + ""); if (onPageSelectItem != null) { onPageSelectItem.onSelect(pageViews.get(nowPage)); } } break; } }
public void actionListener(ActionEvent actionEvent) { try { Object instance = ScreenUtils.evaluate(getActionListenerObject()); if (instance != null) { MethodUtils.invokeExactMethod(instance, getActionListenerMethod(), actionEvent); } } catch (Exception e) { LOGGER.error("Ocurrio un error ejecutando actionListener", e); } }
public void create(int count) { for (int i = 0; i < count; i++) { ImageView imageView = new ImageView(getContext()); imageView.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); int padding = ScreenUtils.dp2px(3); imageView.setPadding(padding, 0, padding, 0); imageView.setImageResource( i == 0 ? R.drawable.ic_play_page_indicator_selected : R.drawable.ic_play_page_indicator_unselected); addView(imageView); } }
public static Bitmap Create2DCode(Context c, String str) throws WriterException { int qr_width = ScreenUtils.getScreenWidth(c) * 2 / 3; int qr_height = qr_width; BitMatrix matrix = new MultiFormatWriter().encode(str, BarcodeFormat.QR_CODE, qr_width, qr_height); int width = matrix.getWidth(); int height = matrix.getHeight(); int[] pixels = new int[width * height]; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { if (matrix.get(x, y)) { pixels[y * width + x] = 0xff000000; } } } Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); bitmap.setPixels(pixels, 0, width, 0, 0, width, height); return bitmap; }