/** 反射实现注解功能 */
  public void initAnnotations() throws Exception {
    Logger.i(TAG, "[=============================================");
    long start = System.nanoTime();
    RealizeTypeAnnotation.getInstance(present).processAnnotation();
    Logger.i(TAG, clazz.getSimpleName() + ", realize type takes: " + (System.nanoTime() - start));

    start = System.nanoTime();
    RealizeFieldAnnotation.getInstance(present).processAnnotation();
    Logger.i(TAG, clazz.getSimpleName() + ", realize field takes: " + (System.nanoTime() - start));

    start = System.nanoTime();
    RealizeMethodAnnotation.getInstance(present).processAnnotation();
    Logger.i(TAG, clazz.getSimpleName() + ", realize method takes: " + (System.nanoTime() - start));
    Logger.i(TAG, "=============================================]");
  }
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    super.onTouchEvent(event);
    //        Logger.d(TAG, "onTouchEvent: " + event);
    switch (event.getAction()) {
      case MotionEvent.ACTION_DOWN:
        isTouched = true;
        this.setLayoutParams(newLp);
        endPoint.x = (int) downX;
        endPoint.y = (int) downY;

        changeViewHeight(
            this, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        postInvalidate();

        downX = event.getX() + location[0];
        downY = event.getY() + location[1];
        //                Logger.d(TAG, String.format("downX: %f, downY: %f", downX, downY));

        break;
      case MotionEvent.ACTION_MOVE:
        // 计算直角边和斜边(用于计算绘制两圆之间的填充去)
        triangle.deltaX = event.getX() - downX;
        triangle.deltaY = -1 * (event.getY() - downY); // y轴方向相反,所有需要取反
        double distance =
            Math.sqrt(triangle.deltaX * triangle.deltaX + triangle.deltaY * triangle.deltaY);
        triangle.hypotenuse = distance;
        //                Logger.d(TAG, "triangle: " + triangle);
        refreshCurRadiusByMoveDistance((int) distance);

        endPoint.x = (int) event.getX();
        endPoint.y = (int) event.getY();

        postInvalidate();

        break;
      case MotionEvent.ACTION_UP:
        isTouched = false;
        this.setLayoutParams(originLp);

        if (isArrivedMaxMoved) { // 触发事件
          changeViewHeight(this, originWidth, originHeight);
          postInvalidate();
          if (null != onDraggableFlagViewListener) {
            onDraggableFlagViewListener.onFlagDismiss(this);
          }
          Logger.d(TAG, "触发事件...");
          resetAfterDismiss();
        } else { // 还原
          changeViewHeight(this, originWidth, originHeight);
          startRollBackAnimation(500 /*ms*/);
        }

        downX = Float.MAX_VALUE;
        downY = Float.MAX_VALUE;
        break;
    }

    return true;
  }
  /**
   * 执行网络请求加载图片
   *
   * @param url
   * @param requiredSize
   * @return
   */
  private Bitmap getBitmap(String url, int requiredSize, PhotoToLoad photoToLoad) {
    File f = fileCache.getFile(url);
    // 先从文件缓存中查找是否有
    Bitmap b = decodeFile(f, requiredSize);
    if (b != null) return b;

    // 最后从指定的url中下载图片
    try {
      Bitmap bitmap = null;
      URL imageUrl = new URL(url);
      HttpURLConnection conn = (HttpURLConnection) imageUrl.openConnection();
      conn.setConnectTimeout(30000);
      conn.setReadTimeout(30000);
      conn.setInstanceFollowRedirects(true);
      InputStream is = conn.getInputStream();
      OutputStream os = new FileOutputStream(f);
      //            CopyStream(is, os, conn.getContentLength(), photoToLoad);

      photoToLoad.totalSize = conn.getContentLength();
      int buffer_size = 1024;
      byte[] bytes = new byte[buffer_size];
      for (; ; ) {
        int count = is.read(bytes, 0, buffer_size);

        if (count == -1) {
          break;
        }
        os.write(bytes, 0, count);

        if (null != photoToLoad.onImageLoaderListener) { // 如果设置了图片加载监听,则回调
          Message msg = rHandler.obtainMessage();
          photoToLoad.currentSize += count;
          msg.arg1 = IMAGE_LOADER_PROCESS;
          msg.obj = photoToLoad;
          rHandler.sendMessage(msg);
        }
      }

      is.close();
      os.close();
      bitmap = decodeFile(f, requiredSize);
      return bitmap;
    } catch (Exception ex) {
      Logger.w(TAG, ex);
      return null;
    }
  }
Exemple #4
0
 public static String md5(String str) {
   String result = null;
   try {
     MessageDigest md = MessageDigest.getInstance("MD5");
     md.update(str.getBytes());
     byte b[] = md.digest();
     int i;
     StringBuffer buf = new StringBuffer("");
     for (int offset = 0; offset < b.length; offset++) {
       i = b[offset];
       if (i < 0) i += 256;
       if (i < 16) buf.append("0");
       buf.append(Integer.toHexString(i));
     }
     result = buf.toString(); // md5 32bit
     // result = buf.toString().substring(8, 24))); //md5 16bit
   } catch (NoSuchAlgorithmException e) {
     Logger.e(TAG, "MD5加密失败, ", e);
   }
   return result;
 }