예제 #1
0
  public void onDestroy() {
    super.onDestroy();
    long var1 = ViewConfiguration.getZoomControlsTimeout();
    (new Timer())
        .schedule(
            new TimerTask() {
              public void run() {
                try {
                  CRWebViewFragment.this
                      .getActivity()
                      .runOnUiThread(
                          new Runnable() {
                            public void run() {
                              try {
                                if (CRWebViewFragment.this.getWebView() != null) {
                                  CRWebViewFragment.this.getWebView().removeAllViews();
                                }

                                if (CRWebViewFragment.this.getWebView() != null) {
                                  CRWebViewFragment.this.getWebView().destroy();
                                }

                              } catch (Exception var2) {
                                Log.e("WebView", "Error destroying the webview: " + var2);
                              }
                            }
                          });
                } catch (Exception var2) {
                  Log.e("WebView", "Error destroying the webview: " + var2);
                }
              }
            },
            var1);
  }
  @Test
  public void methodsShouldReturnAndroidConstants() {
    Activity context = new Activity();
    ViewConfiguration viewConfiguration = ViewConfiguration.get(context);

    assertEquals(10, ViewConfiguration.getScrollBarSize());
    assertEquals(250, ViewConfiguration.getScrollBarFadeDuration());
    assertEquals(300, ViewConfiguration.getScrollDefaultDelay());
    assertEquals(12, ViewConfiguration.getFadingEdgeLength());
    assertEquals(125, ViewConfiguration.getPressedStateDuration());
    assertEquals(500, ViewConfiguration.getLongPressTimeout());
    assertEquals(115, ViewConfiguration.getTapTimeout());
    assertEquals(500, ViewConfiguration.getJumpTapTimeout());
    assertEquals(300, ViewConfiguration.getDoubleTapTimeout());
    assertEquals(12, ViewConfiguration.getEdgeSlop());
    assertEquals(16, ViewConfiguration.getTouchSlop());
    assertEquals(16, ViewConfiguration.getWindowTouchSlop());
    assertEquals(50, ViewConfiguration.getMinimumFlingVelocity());
    assertEquals(4000, ViewConfiguration.getMaximumFlingVelocity());
    assertEquals(320 * 480 * 4, ViewConfiguration.getMaximumDrawingCacheSize());
    assertEquals(3000, ViewConfiguration.getZoomControlsTimeout());
    assertEquals(500, ViewConfiguration.getGlobalActionKeyTimeout());
    assertEquals(0.015f, ViewConfiguration.getScrollFriction());

    assertEquals(1f, context.getResources().getDisplayMetrics().density);

    assertEquals(10, viewConfiguration.getScaledScrollBarSize());
    assertEquals(12, viewConfiguration.getScaledFadingEdgeLength());
    assertEquals(12, viewConfiguration.getScaledEdgeSlop());
    assertEquals(16, viewConfiguration.getScaledTouchSlop());
    assertEquals(32, viewConfiguration.getScaledPagingTouchSlop());
    assertEquals(100, viewConfiguration.getScaledDoubleTapSlop());
    assertEquals(16, viewConfiguration.getScaledWindowTouchSlop());
    assertEquals(50, viewConfiguration.getScaledMinimumFlingVelocity());
    assertEquals(4000, viewConfiguration.getScaledMaximumFlingVelocity());
  }
예제 #3
0
/** A MapZoomControls instance displays buttons for zooming in and out in a map. */
public class MapZoomControls implements Observer {
  private static class ZoomControlsHideHandler extends Handler {
    private final ZoomControls zoomControls;

    ZoomControlsHideHandler(ZoomControls zoomControls) {
      super();
      this.zoomControls = zoomControls;
    }

    @Override
    public void handleMessage(Message message) {
      this.zoomControls.hide();
    }
  }

  private static class ZoomInClickListener implements View.OnClickListener {
    private final MapViewPosition mapViewPosition;

    ZoomInClickListener(MapViewPosition mapViewPosition) {
      this.mapViewPosition = mapViewPosition;
    }

    @Override
    public void onClick(View view) {
      this.mapViewPosition.zoomIn();
    }
  }

  private static class ZoomOutClickListener implements View.OnClickListener {
    private final MapViewPosition mapViewPosition;

    ZoomOutClickListener(MapViewPosition mapViewPosition) {
      this.mapViewPosition = mapViewPosition;
    }

    @Override
    public void onClick(View view) {
      this.mapViewPosition.zoomOut();
    }
  }

  /** Default {@link Gravity} of the zoom controls. */
  private static final int DEFAULT_ZOOM_CONTROLS_GRAVITY = Gravity.BOTTOM | Gravity.RIGHT;

  /** Default maximum zoom level. */
  private static final byte DEFAULT_ZOOM_LEVEL_MAX = 22;

  /** Default minimum zoom level. */
  private static final byte DEFAULT_ZOOM_LEVEL_MIN = 0;

  /** Message code for the handler to hide the zoom controls. */
  private static final int MSG_ZOOM_CONTROLS_HIDE = 0;

  /** Horizontal padding for the zoom controls. */
  private static final int ZOOM_CONTROLS_HORIZONTAL_PADDING = 5;

  /** Delay in milliseconds after which the zoom controls disappear. */
  private static final long ZOOM_CONTROLS_TIMEOUT = ViewConfiguration.getZoomControlsTimeout();

  private boolean gravityChanged;
  private final MapView mapView;
  private boolean showMapZoomControls;
  private final ZoomControls zoomControls;
  private int zoomControlsGravity;
  private final Handler zoomControlsHideHandler;
  private byte zoomLevelMax;
  private byte zoomLevelMin;

  public MapZoomControls(Context context, final MapView mapView) {
    this.mapView = mapView;
    this.zoomControls = new ZoomControls(context);
    this.showMapZoomControls = true;
    this.zoomLevelMax = DEFAULT_ZOOM_LEVEL_MAX;
    this.zoomLevelMin = DEFAULT_ZOOM_LEVEL_MIN;
    this.zoomControls.setVisibility(View.GONE);
    this.zoomControlsGravity = DEFAULT_ZOOM_CONTROLS_GRAVITY;

    this.zoomControls.setOnZoomInClickListener(
        new ZoomInClickListener(mapView.getModel().mapViewPosition));
    this.zoomControls.setOnZoomOutClickListener(
        new ZoomOutClickListener(mapView.getModel().mapViewPosition));
    this.zoomControlsHideHandler = new ZoomControlsHideHandler(this.zoomControls);
    this.mapView.getModel().mapViewPosition.addObserver(this);
    int wrapContent = android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
    LayoutParams layoutParams = new LayoutParams(wrapContent, wrapContent);
    this.mapView.addView(this.zoomControls, layoutParams);
  }

  public int getMeasuredHeight() {
    return this.zoomControls.getMeasuredHeight();
  }

  public int getMeasuredWidth() {
    return this.zoomControls.getMeasuredWidth();
  }

  /**
   * @return the current gravity for the placing of the zoom controls.
   * @see Gravity
   */
  public int getZoomControlsGravity() {
    return this.zoomControlsGravity;
  }

  /** @return the maximum zoom level of the map. */
  public byte getZoomLevelMax() {
    return this.zoomLevelMax;
  }

  /** @return the minimum zoom level of the map. */
  public byte getZoomLevelMin() {
    return this.zoomLevelMin;
  }

  /** @return true if the zoom controls are visible, false otherwise. */
  public boolean isShowMapZoomControls() {
    return this.showMapZoomControls;
  }

  public void layout(boolean changed, int left, int top, int right, int bottom) {
    if (!changed && !this.gravityChanged) {
      return;
    }

    int zoomControlsWidth = this.zoomControls.getMeasuredWidth();
    int zoomControlsHeight = this.zoomControls.getMeasuredHeight();

    int positionLeft = calculatePositionLeft(left, right, zoomControlsWidth);
    int positionTop = calculatePositionTop(top, bottom, zoomControlsHeight);
    int positionRight = positionLeft + zoomControlsWidth;
    int positionBottom = positionTop + zoomControlsHeight;

    this.zoomControls.layout(positionLeft, positionTop, positionRight, positionBottom);
    this.gravityChanged = false;
  }

  public void measure(int widthMeasureSpec, int heightMeasureSpec) {
    this.zoomControls.measure(widthMeasureSpec, heightMeasureSpec);
  }

  public void onChange() {
    this.onZoomLevelChange(this.mapView.getModel().mapViewPosition.getZoomLevel());
  }

  public void onMapViewTouchEvent(MotionEvent event) {
    if (event.getPointerCount() > 1) {
      // no multitouch
      return;
    }
    if (this.showMapZoomControls) {
      switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
          showZoomControls();
          break;
        case MotionEvent.ACTION_CANCEL:
          showZoomControlsWithTimeout();
          break;
        case MotionEvent.ACTION_UP:
          showZoomControlsWithTimeout();
          break;
      }
    }
  }

  public void onZoomLevelChange(final int newZoomLevel) {
    // to allow changing zoom level programmatically, i.e. not just
    // by user interaction
    if (AndroidUtil.currentThreadIsUiThread()) {
      changeZoomControls(newZoomLevel);
    } else {
      this.mapView.post(
          new Runnable() {
            @Override
            public void run() {
              changeZoomControls(newZoomLevel);
            }
          });
    }
  }

  /** @param showMapZoomControls true if the zoom controls should be visible, false otherwise. */
  public void setShowMapZoomControls(boolean showMapZoomControls) {
    this.showMapZoomControls = showMapZoomControls;
  }

  /**
   * Sets the gravity for the placing of the zoom controls. Supported values are {@link
   * Gravity#TOP}, {@link Gravity#CENTER_VERTICAL}, {@link Gravity#BOTTOM}, {@link Gravity#LEFT},
   * {@link Gravity#CENTER_HORIZONTAL} and {@link Gravity#RIGHT}.
   *
   * @param zoomControlsGravity a combination of {@link Gravity} constants describing the desired
   *     placement.
   */
  public void setZoomControlsGravity(int zoomControlsGravity) {
    if (this.zoomControlsGravity != zoomControlsGravity) {
      this.zoomControlsGravity = zoomControlsGravity;
      this.gravityChanged = true;
    }
  }

  /**
   * Sets the maximum zoom level of the map.
   *
   * <p>The maximum possible zoom level of the MapView depends also on other elements. For example,
   * downloading map tiles may only be possible up to a certain zoom level. Setting a higher maximum
   * zoom level has no effect in this case.
   *
   * @param zoomLevelMax the maximum zoom level.
   * @throws IllegalArgumentException if the maximum zoom level is smaller than the current minimum
   *     zoom level.
   */
  public void setZoomLevelMax(byte zoomLevelMax) {
    if (zoomLevelMax < this.zoomLevelMin) {
      throw new IllegalArgumentException();
    }
    this.zoomLevelMax = zoomLevelMax;
  }

  /**
   * Sets the minimum zoom level of the map.
   *
   * @param zoomLevelMin the minimum zoom level.
   * @throws IllegalArgumentException if the minimum zoom level is larger than the current maximum
   *     zoom level.
   */
  public void setZoomLevelMin(byte zoomLevelMin) {
    if (zoomLevelMin > this.zoomLevelMax) {
      throw new IllegalArgumentException();
    }
    this.zoomLevelMin = zoomLevelMin;
  }

  private int calculatePositionLeft(int left, int right, int zoomControlsWidth) {
    int gravity = this.zoomControlsGravity & Gravity.HORIZONTAL_GRAVITY_MASK;
    switch (gravity) {
      case Gravity.LEFT:
        return ZOOM_CONTROLS_HORIZONTAL_PADDING;

      case Gravity.CENTER_HORIZONTAL:
        return (right - left - zoomControlsWidth) / 2;

      case Gravity.RIGHT:
        return right - left - zoomControlsWidth - ZOOM_CONTROLS_HORIZONTAL_PADDING;
    }

    throw new IllegalArgumentException("unknown horizontal gravity: " + gravity);
  }

  private int calculatePositionTop(int top, int bottom, int zoomControlsHeight) {
    int gravity = this.zoomControlsGravity & Gravity.VERTICAL_GRAVITY_MASK;
    switch (gravity) {
      case Gravity.TOP:
        return 0;

      case Gravity.CENTER_VERTICAL:
        return (bottom - top - zoomControlsHeight) / 2;

      case Gravity.BOTTOM:
        return bottom - top - zoomControlsHeight;
    }

    throw new IllegalArgumentException("unknown vertical gravity: " + gravity);
  }

  private void changeZoomControls(int newZoomLevel) {
    boolean zoomInEnabled = newZoomLevel < this.zoomLevelMax;
    boolean zoomOutEnabled = newZoomLevel > this.zoomLevelMin;
    this.zoomControls.setIsZoomInEnabled(zoomInEnabled);
    this.zoomControls.setIsZoomOutEnabled(zoomOutEnabled);
  }

  private void showZoomControls() {
    this.zoomControlsHideHandler.removeMessages(MSG_ZOOM_CONTROLS_HIDE);
    if (this.zoomControls.getVisibility() != View.VISIBLE) {
      this.zoomControls.show();
    }
  }

  private void showZoomControlsWithTimeout() {
    showZoomControls();
    this.zoomControlsHideHandler.sendEmptyMessageDelayed(
        MSG_ZOOM_CONTROLS_HIDE, ZOOM_CONTROLS_TIMEOUT);
  }
}
public class CouponDetailActivity extends Activity {
  public static final String tag = "StoreDetailActivity";
  int index;
  ImageView iv;
  ImageView ivBar;
  TextView tv;
  TextView tv2;
  ZoomControls zc;
  HashMap<Integer, Boolean> needRefresh =
      new HashMap<Integer, Boolean>(); // 因可能某index的图片放大后,此时后台通知刷新,如果不记录,放大图片将被刷成原始的。
  private Runnable mZoomControlRunnable;
  private static final long ZOOM_CONTROLS_TIMEOUT = ViewConfiguration.getZoomControlsTimeout();

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.coupon_detail);
    // set title
    TextView title = (TextView) findViewById(R.id.title);
    title.setText(R.string.coupon_list_title);
    // end title

    Intent intent = getIntent();
    index = intent.getIntExtra("coupon_index", 0);
    final int sid = intent.getIntExtra("sid", 0);

    iv = (ImageView) findViewById(R.id.coupon_detail_img);
    ivBar = (ImageView) findViewById(R.id.coupon_bar_img);
    tv = (TextView) findViewById(R.id.cbrief);
    tv2 = (TextView) findViewById(R.id.expiry);

    showDetail(sid, index);
    if (CouponListActivity.mCouponList.get(index).getBigImg() == null) {
      needRefresh.put(index, true);
      // 先用小图片显示,等大图片下载完再更新
      iv.setImageBitmap(CouponListActivity.mCouponList.get(index).getImg());
    }
    final Button preBt = (Button) findViewById(R.id.pre_coupon);
    final Button nextBt = (Button) findViewById(R.id.next_coupon);
    final Button curr_total = (Button) findViewById(R.id.curr_total);
    if (index == 0) {
      preBt.setEnabled(false);
      preBt.setVisibility(View.INVISIBLE);
    } else if (index == CouponListActivity.mCouponList.size() - 1) {
      nextBt.setEnabled(false);
      nextBt.setVisibility(View.INVISIBLE);
    }
    preBt.setOnClickListener(
        new OnClickListener() {

          public void onClick(View v) {
            // TODO Auto-generated method stub
            if (index > 0) {
              index--;
              showDetail(sid, index);
              if (CouponListActivity.mCouponList.get(index).getBigImg() == null) {
                needRefresh.put(index, true);
                iv.setImageBitmap(CouponListActivity.mCouponList.get(index).getImg());
              }
            }
            if (index == 0) {
              preBt.setEnabled(false);
              preBt.setVisibility(View.INVISIBLE);
            }
            if (nextBt.isEnabled() == false) {
              nextBt.setEnabled(true);
              nextBt.setVisibility(View.VISIBLE);
            }
            curr_total.setText((index + 1) + "/" + CouponListActivity.mCouponList.size());
          }
        });
    nextBt.setOnClickListener(
        new OnClickListener() {

          public void onClick(View v) {
            // TODO Auto-generated method stub
            if (index < CouponListActivity.mCouponList.size() - 1) {
              index++;
              showDetail(sid, index);
              if (CouponListActivity.mCouponList.get(index).getBigImg() == null) {
                needRefresh.put(index, true);
                iv.setImageBitmap(CouponListActivity.mCouponList.get(index).getImg());
              }
            }
            if (index == CouponListActivity.mCouponList.size() - 1) {
              nextBt.setEnabled(false);
              nextBt.setVisibility(View.INVISIBLE);
            }
            if (preBt.isEnabled() == false) {
              preBt.setEnabled(true);
              preBt.setVisibility(View.VISIBLE);
            }
            curr_total.setText((index + 1) + "/" + CouponListActivity.mCouponList.size());
          }
        });
    ///////////////////////////////////////////////////////////////////////////////
    String[] arr = new String[CouponListActivity.mCouponList.size()];
    for (int i = 0; i < arr.length; i++) {
      arr[i] = "  No." + String.valueOf(i + 1);
    }
    final EfficientAdapter adapter = new EfficientAdapter(this, arr, index);
    curr_total.setOnClickListener(
        new OnClickListener() {
          public void onClick(View v) {

            adapter.mDisabledIndex = index;

            new AlertDialog.Builder(CouponDetailActivity.this)
                //                 .setItems(arr, new DialogInterface.OnClickListener() {
                //                    public void onClick(DialogInterface dialog, int which) {
                //                    	showDetail(sid,which);
                //                    	index=which;
                //
                //	curr_total.setText((which+1)+"/"+CouponListActivity.mCouponList.size());
                //
                //
                //        				nextBt.setEnabled(true);
                //        				nextBt.setVisibility(View.VISIBLE);
                //        				preBt.setEnabled(true);
                //        				preBt.setVisibility(View.VISIBLE);
                //
                //        				if(index==0){
                //        					preBt.setEnabled(false);
                //        					preBt.setVisibility(View.INVISIBLE);
                //        				}
                //        				if(index==CouponListActivity.mCouponList.size()-1){
                //        					nextBt.setEnabled(false);
                //        					nextBt.setVisibility(View.INVISIBLE);
                //        				}
                //                    }
                //                 })
                .setAdapter(
                    adapter,
                    new DialogInterface.OnClickListener() {
                      public void onClick(DialogInterface dialog, int which) {

                        showDetail(sid, which);
                        index = which;
                        curr_total.setText(
                            (which + 1) + "/" + CouponListActivity.mCouponList.size());

                        nextBt.setEnabled(true);
                        nextBt.setVisibility(View.VISIBLE);
                        preBt.setEnabled(true);
                        preBt.setVisibility(View.VISIBLE);

                        if (index == 0) {
                          preBt.setEnabled(false);
                          preBt.setVisibility(View.INVISIBLE);
                        }
                        if (index == CouponListActivity.mCouponList.size() - 1) {
                          nextBt.setEnabled(false);
                          nextBt.setVisibility(View.INVISIBLE);
                        }
                      }
                    })
                .show();
          }
        });

    curr_total.setText((index + 1) + "/" + CouponListActivity.mCouponList.size());
    //////////////////////////////////////////////////////////////////////

    // 放缩图片
    zc = (ZoomControls) findViewById(R.id.zoomControls);
    class PrivateHandler extends Handler {
      @Override
      public void handleMessage(Message msg) {

        switch (msg.what) {
          default:
            super.handleMessage(msg);
            break;
        }
      }
    }
    final Handler mPrivateHandler = new PrivateHandler();
    mZoomControlRunnable =
        new Runnable() {
          public void run() {

            /* Don't dismiss the controls if the user has
             * focus on them. Wait and check again later.
             */
            if (!zc.hasFocus()) {
              zc.hide();
            } else {
              mPrivateHandler.removeCallbacks(mZoomControlRunnable);
              mPrivateHandler.postDelayed(mZoomControlRunnable, ZOOM_CONTROLS_TIMEOUT);
            }
          }
        };
    zc.setOnZoomInClickListener(
        new OnClickListener() {

          public void onClick(View v) {
            // TODO Auto-generated method stub
            iv.setImageBitmap(
                Helper.scaleBitmap(CouponListActivity.mCouponList.get(index).getBigImg(), 2.0f));
            Log.d(tag, "ZoomIn");
            mPrivateHandler.removeCallbacks(mZoomControlRunnable);
            mPrivateHandler.postDelayed(mZoomControlRunnable, ZOOM_CONTROLS_TIMEOUT);
          }
        });
    zc.setOnZoomOutClickListener(
        new OnClickListener() {

          public void onClick(View v) {
            // TODO Auto-generated method stub
            iv.setImageBitmap(
                Helper.scaleBitmap(CouponListActivity.mCouponList.get(index).getBigImg(), 1f));
            Log.d(tag, "ZoomOut");
            mPrivateHandler.removeCallbacks(mZoomControlRunnable);
            mPrivateHandler.postDelayed(mZoomControlRunnable, ZOOM_CONTROLS_TIMEOUT);
          }
        });
    zc.setVisibility(View.INVISIBLE);

    // 手势
    final GestureDetector gestureDetector =
        new GestureDetector(
            new OnGestureListener() {

              public boolean onDown(MotionEvent arg0) {
                // TODO Auto-generated method stub
                System.out.println("dddddddddddddddddd onDown");
                zc.setVisibility(View.VISIBLE);
                mPrivateHandler.removeCallbacks(mZoomControlRunnable);
                mPrivateHandler.postDelayed(mZoomControlRunnable, ZOOM_CONTROLS_TIMEOUT);
                return false;
              }

              public boolean onFling(MotionEvent arg0, MotionEvent arg1, float arg2, float arg3) {
                // TODO Auto-generated method stub
                // System.out.println("dddddddddddddddddd onFling");
                return false;
              }

              public void onLongPress(MotionEvent arg0) {
                // TODO Auto-generated method stub
                // System.out.println("ddddddddddddddddddx onLongPress");
              }

              public boolean onScroll(MotionEvent arg0, MotionEvent arg1, float arg2, float arg3) {
                // TODO Auto-generated method stub
                // System.out.println("dddddddddddddd onScroll");
                return false;
              }

              public void onShowPress(MotionEvent arg0) {
                // TODO Auto-generated method stub
                // System.out.println("dddddddddddddd onShowPress");
              }

              public boolean onSingleTapUp(MotionEvent arg0) {
                // TODO Auto-generated method stub
                // System.out.println("dddddddddddddd onSingleTapUp");
                return false;
              }
            });
    iv.setOnTouchListener(
        new OnTouchListener() {

          public boolean onTouch(View v, MotionEvent event) {
            // TODO Auto-generated method stub
            gestureDetector.onTouchEvent(event);

            return false;
          }
        });
    // iv.setScrollbarFadingEnabled(true);
    // iv.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
    // iv.setScrollContainer(true);
    //////////////////////
    Helper.setOnInfoAndHome(this);
  }

  public void showDetail(int sid, int index) {
    iv.setImageBitmap(CouponListActivity.mCouponList.get(index).getBigImg());
    ivBar.setImageBitmap(CouponListActivity.mCouponList.get(index).getBarImg());
    tv.setText(CouponListActivity.mCouponList.get(index).getCbrief());
    // ---------------------------
    String date = CouponListActivity.mCouponList.get(index).getCvdate();
    date = date.substring(date.indexOf(',') + 1, date.indexOf('|'));
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); // mm一定要大写!
    String dateStr = "";
    try {
      Date d = df.parse(date);
      DateFormat fullDateFormat =
          DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.DEFAULT, new Locale("en"));
      dateStr = fullDateFormat.format(d);
      dateStr = dateStr.substring(0, dateStr.indexOf(':') - 2).replaceFirst(" ", "");

    } catch (ParseException e) {
      e.printStackTrace();
      Log.e(tag, "transfer date fail" + e);
    }
    tv2.setText("Expiry:" + dateStr);
  }

  /*
  	public void showDetail(int sid,int index){
  		BmpAsyncTask afs = new BmpAsyncTask(this);
  		BaCoupon bc = CouponListActivity.mCouponList.get(index);
  		int cid =bc.getCid();
  		//注意,调用的是getcoupondetail2,而不是getcoupondetail,该返回值会覆盖原来的type=icon,但没关系,只是图片大小而已,况且当返回时,是缓存的icon图片,这么处理的原因是节省内存。

  		afs.execute(BrandedConstants.getcoupondetail2, "1",String.valueOf(sid),String.valueOf(cid),"","240","240");

  //		try {
  //			Bitmap bmp = (Bitmap)afs.get();
  //			if(bmp!=null){
  //				bc.setImg(bmp);
  //			}else{
  //				bc.setImg(BitmapFactory.decodeResource(getResources(), R.drawable.coupon_icon));
  //			}
  //
  //		} catch (InterruptedException e) {
  //			// TODO Auto-generated catch block
  //			e.printStackTrace();
  //		} catch (ExecutionException e) {
  //			// TODO Auto-generated catch block
  //			e.printStackTrace();
  //		}


  	}
  	//这里单独写是因为需要在onPostExecute处理结果,才能有进度条,否则直接调用.get()会同步等待,导致几乎看不到进度条,
  	private class BmpAsyncTask extends AsyncTask<String, Void, Bitmap> {
  		Context context;
  		private String error = null;
  		private boolean isFatalError = false;
  		private ProgressDialog dialog = null;
  		ImageView iv;
  		TextView tv ;
  		TextView tv2 ;

  		public BmpAsyncTask(Context ctx) {
  			context = ctx;
  			iv = (ImageView)findViewById(R.id.coupon_detail_img);
  			tv = (TextView)findViewById(R.id.cbrief);
  			tv2 = (TextView)findViewById(R.id.expiry);
  		}
  		@Override
  		protected Bitmap doInBackground(String... urls) {
  			return RestClient.getCouponDetail(urls[1], urls[2],urls[3], urls[4],urls[5], urls[6]);
  		}
  		protected void onPostExecute(Bitmap unused) {// 运行于UI线程,
  			// //跟extends后面的泛型(参数,进度值,返回值)中的返回值要匹配
  			// returnValue = unused; 可以通过调用类的get方法,取得结果

  				dialog.dismiss();
  				dialog = null;

  			if (error != null) {
  				Toast.makeText(context, error, Toast.LENGTH_LONG).show();
  				if (isFatalError) {
  					new AlertDialog.Builder(context)
  							.setIcon(android.R.drawable.ic_dialog_alert)
  							.setTitle("Fatal Error")
  							.setMessage(
  									"Network or other fatal error,Please try again later.")
  							.setPositiveButton(R.string.BUTTON_OK,
  									new DialogInterface.OnClickListener() {
  										public void onClick(
  												DialogInterface dialog,
  												int whichButton) {
  											System.exit(1);
  										}
  									}).show();

  				}

  			}else{
  				//iv.setImageBitmap(CouponListActivity.mCouponList.get(index).getImg());
  				if(unused!=null){
  					iv.setImageBitmap(unused);//只有图片,需要从网上取大图片(原来list中的是小图标),其他字段从list里面就有。
  				}else{
  					iv.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.coupon_icon));
  				}

  				tv.setText(CouponListActivity.mCouponList.get(index).getCbrief());

  		        //---------------------------
  		        String date = CouponListActivity.mCouponList.get(index).getCvdate();
  		        date =date.substring(date.indexOf(',')+1,date.indexOf('|'));
  		        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); //mm一定要大写!
  		   		String dateStr="";
  				 try {
  					 Date d = df.parse(date);
  					 DateFormat fullDateFormat =
  						 DateFormat.getDateTimeInstance(
  						 DateFormat.FULL,
  						 DateFormat.DEFAULT,
  						 new Locale("en"));
  					 dateStr = fullDateFormat.format(d);
  					 dateStr = dateStr.substring(0,dateStr.indexOf(':')-2).replaceFirst(" ", "");

  				} catch (ParseException e) {
  					e.printStackTrace();
  					Log.e(tag, "transfer date fail"+e);
  				}
  				tv2.setText("Expiry:"+dateStr);
  		        //------------------------------
  			}
  		}

  		// private Object returnValue = null;
  		protected void onPreExecute() {// 执行预处理,它运行于UI线程,
  				dialog = new ProgressDialog(context);
  				dialog.setMessage("get from network, please wait..");
  				dialog.show();
  		}

  	}

  	*/
  @Override
  protected void onResume() {
    IntentFilter filter = new IntentFilter();
    filter.addAction(CouponListActivity.BROADCAST_FOR_COUPONS_DETAIL);
    this.registerReceiver(mBr, filter);

    super.onResume();
  }

  @Override
  protected void onPause() {
    this.unregisterReceiver(mBr);

    super.onPause();
  }

  public BroadcastReceiver mBr =
      new BroadcastReceiver() {

        @Override
        public void onReceive(Context arg0, Intent arg1) {
          Boolean isNeedRefresh = needRefresh.get(index);
          if (isNeedRefresh != null
              && isNeedRefresh
              && CouponListActivity.mCouponList.get(index).getBigImg() != null) {
            iv.setImageBitmap(CouponListActivity.mCouponList.get(index).getBigImg());
            needRefresh.put(index, false);
          }
          ivBar.setImageBitmap(CouponListActivity.mCouponList.get(index).getBarImg());

          Log.d("adapter", "notifyDataSetChanged");
        }
      };

  private static class EfficientAdapter extends BaseAdapter {

    private LayoutInflater mInflater;
    String[] mStrArr;
    int mDisabledIndex;

    public EfficientAdapter(Context context, String[] strArr, int disabledIndex) {
      mInflater = LayoutInflater.from(context);
      mStrArr = strArr;
      mDisabledIndex = disabledIndex;
    }

    public int getCount() {
      return CouponListActivity.mCouponList.size();
    }

    public Object getItem(int position) {
      return position;
    }

    public long getItemId(int position) {
      return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
      ViewHolder holder;
      if (convertView == null) {
        convertView = mInflater.inflate(R.layout.list_forward, null);
        holder = new ViewHolder();
        holder.text_1 = (TextView) convertView.findViewById(R.id.text_1);
        holder.couponOrFlyerIcon = (ImageView) convertView.findViewById(R.id.couponOrFlyer_icon);
        convertView.setTag(holder);

      } else {
        holder = (ViewHolder) convertView.getTag();
      }
      // Odd/Even use different color
      //	            if(position%2==0){
      //	            	convertView.setBackgroundColor(Color.parseColor("#FFFFFF"));
      //	            }
      //	            else{
      //	            	convertView.setBackgroundColor(Color.parseColor("#EEEEEE"));
      //	            }

      holder.text_1.setText(mStrArr[position]);
      holder.couponOrFlyerIcon.setImageBitmap(
          CouponListActivity.mCouponList.get(position).getImg());
      if (position == mDisabledIndex) {
        // holder.text_1.setEnabled(false);
        holder.text_1.setTextColor(Color.GRAY);
      } else {
        // holder.text_1.setEnabled(true);
        holder.text_1.setTextColor(Color.BLACK);
      }
      parent.setLayoutParams(new LinearLayout.LayoutParams(150, LayoutParams.WRAP_CONTENT));
      return convertView;
    }

    static class ViewHolder {
      TextView text_1;
      ImageView couponOrFlyerIcon;
    }
  }
}