private void optionCancel(View view) {
   if (view.getId() == ID_BACK) {
     ((ImageView) view)
         .setImageResource(Global.getResourceId(getContext(), "exit_normal", "drawable"));
   }
   if (view.getId() == ID_PRE_PAGE) {
     ((ImageView) view)
         .setImageResource(Global.getResourceId(getContext(), "forward_normal", "drawable"));
   }
   if (view.getId() == ID_NEXT_PAGE) {
     ((ImageView) view)
         .setImageResource(Global.getResourceId(getContext(), "back_normal", "drawable"));
   }
   if (view.getId() == ID_FLASH) {
     ((ImageView) view)
         .setImageResource(Global.getResourceId(getContext(), "reflash_normal", "drawable"));
   }
 }
public class SwitchButton extends CompoundButton {
  private final int SWITCH_BOUND = Global.ScaleSize(2);
  private Paint paint = null;
  private RectF oval = null;

  private OnClickListener onClickListener;

  public SwitchButton(Context context) {
    this(context, null);
    init(context);
  }

  public SwitchButton(Context context, AttributeSet attrs) {
    super(context, attrs);
    init(context);
  }

  public SwitchButton(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    init(context);
  }

  private void init(Context context) {
    paint = new Paint();
    paint.setAntiAlias(true);
    oval = new RectF();
  }

  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int measuredHeight = measureHeight(heightMeasureSpec);
    int measuredWidth = measureWidth(widthMeasureSpec);
    setMeasuredDimension(measuredWidth, measuredHeight);
  }

  private int measureHeight(int measureSpec) {
    int nResult = 80; // default
    int nSpecMode = MeasureSpec.getMode(measureSpec);
    int nSpecSize = MeasureSpec.getSize(measureSpec);

    if (MeasureSpec.AT_MOST == nSpecMode) // when layout set wrap_content
    {
      nResult = nSpecSize;
    } else if (MeasureSpec.EXACTLY == nSpecMode) // when layout set match_parent or exactly size
    {
      nResult = nSpecSize;
    }

    return nResult;
  }

  private int measureWidth(int measureSpec) {
    int nResult = 80; // default
    int nSpecMode = MeasureSpec.getMode(measureSpec);
    int nSpecSize = MeasureSpec.getSize(measureSpec);

    if (MeasureSpec.AT_MOST == nSpecMode) // when layout set wrap_content
    {
      nResult = nSpecSize;
    } else if (MeasureSpec.EXACTLY == nSpecMode) // when layout set match_parent or exactly size
    {
      nResult = nSpecSize;
    }

    return nResult;
  }

  @Override
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    // calculate the left and right values
    float right = this.getWidth() - this.getPaddingRight();
    float left = right - this.getWidth() + this.getPaddingLeft();
    float height = this.getHeight() - this.getPaddingTop() - this.getPaddingBottom();
    float radius = height / 2; // εœ“εŠεΎ‘

    oval.set(left, 0, right, height);
    if (this.isChecked()) {
      paint.setColor(Color.parseColor("#4B96C2"));
      // paint.setColor(Color.parseColor("#5a7fc0"));
      canvas.drawRoundRect(oval, radius, radius, paint);
      paint.setColor(Color.WHITE);
      canvas.drawCircle(right - radius, radius, radius - SWITCH_BOUND, paint);
    } else {
      paint.setColor(Color.GRAY);
      canvas.drawRoundRect(oval, radius, radius, paint);
      paint.setColor(Color.WHITE);
      canvas.drawCircle(left + radius, radius, radius - SWITCH_BOUND, paint);
    }

    canvas.save();
  }

  @Override
  public void setOnClickListener(OnClickListener l) {
    super.setOnClickListener(l);

    this.onClickListener = l;
  }

  @Override
  public boolean onTouchEvent(MotionEvent event) {
    switch (event.getAction()) {
      case MotionEvent.ACTION_DOWN:
        this.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
        this.setChecked(!this.isChecked());
        invalidate();

        // call the onClickListener
        if (this.onClickListener != null) this.onClickListener.onClick(this);
        return false;
    }

    return super.onTouchEvent(event);
  }
}
  @SuppressLint("SetJavaScriptEnabled")
  private void init(Context context) {
    this.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    int nBtnSize = Global.ScaleSize(27);

    /** create option bar */
    RelativeLayout rlLayout = new RelativeLayout(context);
    rlLayout.setId(ID_OPTION_BAR);
    RelativeLayout.LayoutParams layoutParams =
        new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, Global.ScaleSize(44));
    layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
    rlLayout.setLayoutParams(layoutParams);
    rlLayout.setBackgroundColor(Color.parseColor("#f4f4f4f2"));
    rlLayout.setPadding(
        Global.ScaleSize(30), Global.ScaleSize(7), Global.ScaleSize(30), Global.ScaleSize(10));
    this.addView(rlLayout);

    webView = new WebView(context);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.setWebViewClient(new WebViewClient());
    webView.setInitialScale(1);
    webView.getSettings().setBuiltInZoomControls(true);
    webView.getSettings().setUseWideViewPort(true);

    RelativeLayout.LayoutParams webLayoutParams =
        new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    webLayoutParams.addRule(RelativeLayout.BELOW, rlLayout.getId());
    webView.setLayoutParams(webLayoutParams);
    webView.setWebViewClient(new myWebViewClient());
    this.addView(webView);

    ImageView imageReflash = new ImageView(context);
    ImageView imageBack = new ImageView(context);
    ImageView imagePrePage = new ImageView(context);
    ImageView imageNextPage = new ImageView(context);

    RelativeLayout.LayoutParams reflashLayoutParams =
        new RelativeLayout.LayoutParams(nBtnSize, nBtnSize);
    reflashLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
    imageReflash.setId(ID_FLASH);
    imageReflash.setLayoutParams(reflashLayoutParams);
    imageReflash.setImageResource(Global.getResourceId(context, "reflash_normal", "drawable"));
    imageReflash.setScaleType(ScaleType.CENTER_INSIDE);
    rlLayout.addView(imageReflash);

    RelativeLayout.LayoutParams backLayoutParams =
        new RelativeLayout.LayoutParams(nBtnSize, nBtnSize);
    backLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
    imageBack.setId(ID_BACK);
    imageBack.setLayoutParams(backLayoutParams);
    imageBack.setImageResource(Global.getResourceId(context, "exit_normal", "drawable"));
    imageBack.setScaleType(ScaleType.CENTER_INSIDE);
    rlLayout.addView(imageBack);

    RelativeLayout.LayoutParams nextPageLayoutParams =
        new RelativeLayout.LayoutParams(nBtnSize, nBtnSize);
    nextPageLayoutParams.addRule(RelativeLayout.LEFT_OF, imageReflash.getId());
    nextPageLayoutParams.setMargins(0, 0, Global.ScaleSize(65), 0);
    imageNextPage.setId(ID_NEXT_PAGE);
    imageNextPage.setLayoutParams(nextPageLayoutParams);
    imageNextPage.setImageResource(Global.getResourceId(context, "back_normal", "drawable"));
    imageNextPage.setScaleType(ScaleType.CENTER_INSIDE);
    rlLayout.addView(imageNextPage);

    RelativeLayout.LayoutParams prePageLayoutParams =
        new RelativeLayout.LayoutParams(nBtnSize, nBtnSize);
    prePageLayoutParams.addRule(RelativeLayout.LEFT_OF, imageNextPage.getId());
    prePageLayoutParams.setMargins(0, 0, Global.ScaleSize(50), 0);
    imagePrePage.setId(ID_PRE_PAGE);
    imagePrePage.setLayoutParams(prePageLayoutParams);
    imagePrePage.setImageResource(Global.getResourceId(context, "forward_normal", "drawable"));
    imagePrePage.setScaleType(ScaleType.CENTER_INSIDE);
    rlLayout.addView(imagePrePage);

    imageReflash.setOnTouchListener(onTouchListener);
    imageBack.setOnTouchListener(onTouchListener);
    imagePrePage.setOnTouchListener(onTouchListener);
    imageNextPage.setOnTouchListener(onTouchListener);

    progressBar = new ProgressBar(getContext());
    RelativeLayout.LayoutParams progressParams = new RelativeLayout.LayoutParams(80, 80);
    progressParams.addRule(RelativeLayout.CENTER_IN_PARENT);
    progressBar.setLayoutParams(progressParams);
    progressBar
        .getIndeterminateDrawable()
        .setColorFilter(0xFF309FD6, android.graphics.PorterDuff.Mode.MULTIPLY);
  }