Android Open Source - drive-android-svg Stroke Width Dialog






From Project

Back to project page drive-android-svg.

License

The source code is released under:

Apache License

If you think the Android project drive-android-svg listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.goodow.drive.android.svg.view;
/* ww  w  .  ja  va 2 s . c  o m*/
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.view.View;
import android.widget.ImageView;
import android.widget.NumberPicker;

import com.goodow.drive.android.svg.R;
import com.goodow.drive.android.svg.SvgMainActivity;
import com.google.inject.Inject;
import com.google.inject.Singleton;

/**
 * Created by liudenghui on 14-7-12.
 */
@Singleton
public class StrokeWidthDialog {
  private AlertDialog alertDialog;
  private NumberPicker numberPicker;
  private ImageView sample;
  private Paint mPaint;
  private Canvas canvas;
  private Bitmap bitmap;
  private Path path;

  @Inject
  public StrokeWidthDialog(Context context) {
    init(context);
    initPaint();
    addListener();
  }

  private void init(Context context) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    View view = View.inflate(context, R.layout.dialog_stroke_width, null);
    numberPicker = (NumberPicker) view.findViewById(R.id.bp_numpicker);
    sample = (ImageView) view.findViewById(R.id.iv_sample);
    numberPicker.setMaxValue(20);
    numberPicker.setMinValue(1);
    builder.setTitle("????");
    builder.setPositiveButton("??", new DialogInterface.OnClickListener() {
      @Override
      public void onClick(DialogInterface dialog, int which) {
        SvgMainActivity.defaultStrokeWidth = numberPicker.getValue();
      }
    });
    builder.setNegativeButton("????", new DialogInterface.OnClickListener() {
      @Override
      public void onClick(DialogInterface dialog, int which) {
        alertDialog.dismiss();
      }
    });
    builder.setView(view);
    alertDialog = builder.create();

  }

  public void show() {
    alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {
      @Override
      public void onShow(DialogInterface dialog) {
        if (bitmap == null) {
          bitmap = Bitmap.createBitmap(sample.getWidth(), sample.getHeight(), Bitmap.Config.ARGB_8888);
          canvas = new Canvas(bitmap);
          path.addCircle(sample.getWidth() / 2, sample.getHeight() / 2, sample.getWidth() > sample.getHeight() ? sample.getHeight() / 2 - 30 : sample.getWidth() / 2 - 30, Path.Direction.CW);
        }
        mPaint.setColor(SvgMainActivity.defaultStrokeColor);
        mPaint.setStrokeWidth(SvgMainActivity.defaultStrokeWidth);
        bitmap.eraseColor(Color.TRANSPARENT);
        canvas.drawPath(path, mPaint);
        sample.setImageBitmap(bitmap);
      }
    });
    alertDialog.show();
    numberPicker.setValue(SvgMainActivity.defaultStrokeWidth);
  }

  private void initPaint() {
    mPaint = new Paint();
    mPaint.setAntiAlias(true);
    mPaint.setStyle(Paint.Style.STROKE);
    mPaint.setStrokeWidth(numberPicker.getValue());// ????
    mPaint.setColor(Color.RED);
    path = new Path();
  }

  private void addListener() {
    numberPicker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
      @Override
      public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
        mPaint.setStrokeWidth(newVal);
        bitmap.eraseColor(Color.TRANSPARENT);
        canvas.drawPath(path, mPaint);
        sample.setImageBitmap(bitmap);
      }
    });
  }


}




Java Source Code List

com.goodow.drive.android.svg.DriveAndroidSvgModule.java
com.goodow.drive.android.svg.OnRemoteChangeListener.java
com.goodow.drive.android.svg.OnShowPopupListener.java
com.goodow.drive.android.svg.SvgMainActivity.java
com.goodow.drive.android.svg.SvgModule.java
com.goodow.drive.android.svg.graphics.MyBaseShape.java
com.goodow.drive.android.svg.graphics.MyEllipse.java
com.goodow.drive.android.svg.graphics.MyLine.java
com.goodow.drive.android.svg.graphics.MyPath.java
com.goodow.drive.android.svg.graphics.MyRect.java
com.goodow.drive.android.svg.samples.demo.MainActivity.java
com.goodow.drive.android.svg.utils.CoordinateUtil.java
com.goodow.drive.android.svg.utils.DrawUtil.java
com.goodow.drive.android.svg.utils.ParseUtil.java
com.goodow.drive.android.svg.utils.SwitchUtil.java
com.goodow.drive.android.svg.view.FillColorDialog.java
com.goodow.drive.android.svg.view.LeftMenuLayout.java
com.goodow.drive.android.svg.view.MyDrawable.java
com.goodow.drive.android.svg.view.MySurfaceView.java
com.goodow.drive.android.svg.view.MyViewGroup.java
com.goodow.drive.android.svg.view.MyView.java
com.goodow.drive.android.svg.view.StrokeColorDialog.java
com.goodow.drive.android.svg.view.StrokeWidthDialog.java