Coder Social home page Coder Social logo

drawableview's People

Contributors

panavtec avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

drawableview's Issues

Maven Central artifact is dirty

The artifact in maven central for 0.6.0 has additional .class files in it. This causes Android Lint to fail when compiling an application as these classes reference other classes that are not there.

For example, the maven artifact includes me.panavtec.drawableview.gestures.DrawerDelegate which references me.panavtec.drawableview.internal.SerializablePath, a class that does not exist in the sources of the 0.6.0 release. It'd be great to have a 0.6.1 release that contains a clean artifact of the 0.6.0 sources.

how to save drawing to bitmap?

I don't see this implemented in the sample.

or

outlined in the readme

Can you give an example of saving the artwork to bmp?

Thanks for this lib!

Parcelable protocol requires that the class implements Parcelable

When the onRestoreInstanceState function callbacks, a BadParcelableException is thrown. I tried to solve it in the following way.
in DrawableView,

@Override
 protected Parcelable onSaveInstanceState() {
     Parcelable parcelable = super.onSaveInstanceState();
     Bundle bundle = new Bundle();
     bundle.putParcelable("super_data", parcelable);
     DrawableViewSaveState state = new DrawableViewSaveState();
     state.setPaths(paths);
     bundle.putParcelable("path_data", state);
     return bundle;
 }

@Override
 protected void onRestoreInstanceState(Parcelable state) {
     if (state instanceof Bundle) {
         Bundle bundle = (Bundle) state;
         DrawableViewSaveState saveState = bundle.getParcelable("path_data");
         if (saveState != null) {
             paths.addAll(saveState.getPaths());
             for (SerializablePath p : paths) {
                 p.loadPathPointsAsQuadTo();
             }
         }
         Parcelable superData = bundle.getParcelable("super_data");
         super.onRestoreInstanceState(superData);
     } else {
         super.onRestoreInstanceState(state);
     }
 }

new DrawableViewSaveState,

public class DrawableViewSaveState implements Parcelable {

    private ArrayList<SerializablePath> paths;

    public ArrayList<SerializablePath> getPaths() {
        return paths;
    }

    public void setPaths(ArrayList<SerializablePath> paths) {
        this.paths = paths;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeList(this.paths);
    }

    public DrawableViewSaveState() {
    }

    protected DrawableViewSaveState(Parcel in) {
        this.paths = new ArrayList<SerializablePath>();
        in.readList(this.paths, SerializablePath.class.getClassLoader());
    }

    public static final Creator<DrawableViewSaveState> CREATOR = new Creator<DrawableViewSaveState>() {
        @Override
        public DrawableViewSaveState createFromParcel(Parcel source) {
            return new DrawableViewSaveState(source);
        }

        @Override
        public DrawableViewSaveState[] newArray(int size) {
            return new DrawableViewSaveState[size];
        }
    };
}

Setting canvas height

Hi again! I cannot seem to find a way to limit the height of where the user can draw on the view. I've set the height of the drawable view to be wrap content and match parent both allow drawing height to be the height of the device. What I need to do is allowing drawing only over the height of a picture that I have loaded onto the same view and I have the height of that picture and I've set it to canvasHeight of the config but I am still able to draw all along the height of the whole device. I have also tried manually setting the canvasHeight to be 200 for example of 50, still able to draw all over the height.

Check this code please, this is just inside an Activity that has an imageView and a drawableView inside it, nothing else. setting canvasWidth works just fine by the way, I am not able to move the canvas to the right because the width is as just as the width of the device

        DisplayMetrics displaymetrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
        int width = displaymetrics.widthPixels;

        final DrawableViewConfig config = new DrawableViewConfig();
        config.setStrokeColor(getResources().getColor(android.R.color.white));
        config.setStrokeWidth(20.0f);
        config.setMinZoom(1.0f);
        config.setMaxZoom(1.0f);
        config.setCanvasWidth(width);

bookmarkIMG.getViewTreeObserver().addOnPreDrawListener(
                new ViewTreeObserver.OnPreDrawListener() {
                    public boolean onPreDraw() {

                        int height = bookmarkIMG.getMeasuredHeight();

                        config.setCanvasHeight(height);

                        Log.d("SIZE", "Canvas size set to " + height); 

                        return true;
                    }
                });

        drawableView.setConfig(config);

Thanks so much for your help so far!

appear android.os.BadParcelableException error

Caused by: android.os.BadParcelableException: Parcelable protocol requires a Parcelable.Creator object called CREATOR on class java.util.ArrayList
at android.os.Parcel.readParcelableCreator(Parcel.java:2114)
at android.os.Parcel.readParcelable(Parcel.java:2055)
at android.view.AbsSavedState.(AbsSavedState.java:57)
at android.view.View$BaseSavedState.(View.java:19038)

Drawableview no track

Hello.When the drawableview is in the fragment, if the fragment is in an invisible state and then drawableview is initialized, there is no trace on the drawableview. If I set the initialize when the fragment is visible, then drawableview is normal.

obtainBitmap() not returning the drawn image

I use the drawableView to draw something and it works fine and everything but when I want to grab the bitmap from the drawableView I do not get the bitmap back correctly.

I have verified this by saving the bitmap from obtainBitmap() into a file on the device and uploaded to dropbox to see the picture. The file always has the size of 0.91 KB and consists of a rectangular, background-less area.

If you want, here's a link to the image, it's empty of course but you can save it and check the size and how the predefined rectangular shape is there: http://i.imgur.com/0EZn7Gz.png

Any ideas? Thanks!

[SOLVED] Black Image in saved bitmap

Hey, the method obtaindBitmap() returns Bitmap. But, when I try save file, his saved such as whole black image. In some google searches, I discovered which background color android to JPG file is black and the default color stroke is black too.

So, to show image correctly, the way was change JPG background color. The code below ""fixes"" this.

I hope help someone.

Bitmap bitmap = drawableView.obtainBitmap();
Canvas canvas = new Canvas(bitmap);
canvas.drawColor(Color.WHITE);
canvas.drawBitmap(drawableView.obtainBitmap(), 0, 0, null);
FileOutputStream fOut = null;
try {
          String timeStamp = new SimpleDateFormat("ddMMyyyy_HHmm").format(new Date());
          String mImageName = "MI_" + timeStamp + ".jpg";
          fOut = new FileOutputStream (new File(getGalleryPath(), mImageName), true);
          bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fOut);
          fOut.flush();
          fOut.close();
} catch (FileNotFoundException e) {
          e.printStackTrace();
} catch (IOException e) {
           e.printStackTrace();
}

private static String getGalleryPath() {
        return Environment.getExternalStorageDirectory() + "/" + Environment.DIRECTORY_DCIM + "/Camera";
}

Ability to center canvas on w/h of the view

The following values will be allowed:

drawableView.setGravity(Gravity.CENTER_HORIZONTAL);
drawableView.setGravity(Gravity.CENTER_VERTICAL);
drawableView.setGravity(Gravity.LEFT);
drawableView.setGravity(Gravity.RIGHT);
drawableView.setGravity(Gravity.TOP);
drawableView.setGravity(Gravity.BOTTOM);

Or combinations like drawableView.setGravity(Gravity.LEFT | Gravity.BOTTOM);

:(

Caused by: android.os.BadParcelableException:
at android.os.Parcel.readParcelableCreator(Parcel.java:2511)
at android.os.Parcel.readParcelable(Parcel.java:2462)
at android.view.AbsSavedState.(AbsSavedState.java:67)
at android.view.View$BaseSavedState.(View.java:22761)
at android.view.View$BaseSavedState.(View.java:22750)
at me.panavtec.drawableview.DrawableViewSaveState.(DrawableViewSaveState.java:14)
at me.panavtec.drawableview.DrawableViewSaveState$1.createFromParcel(DrawableViewSaveState.java:40)
at me.panavtec.drawableview.DrawableViewSaveState$1.createFromParcel(DrawableViewSaveState.java:38)
at android.os.Parcel.readParcelable(Parcel.java:2471)
at android.os.Parcel.readValue(Parcel.java:2365)
at android.os.Parcel.readSparseArrayInternal(Parcel.java:2813)
at android.os.Parcel.readSparseArray(Parcel.java:2068)
at android.os.Parcel.readValue(Parcel.java:2422)
at android.os.Parcel.readArrayMapInternal(Parcel.java:2732)
at android.os.BaseBundle.unparcel(BaseBundle.java:269)
at android.os.Bundle.getSparseParcelableArray(Bundle.java:934)
at com.android.internal.policy.PhoneWindow.restoreHierarchyState(PhoneWindow.java:2104)
at android.app.Activity.onRestoreInstanceState(Activity.java:1074)
at android.app.Activity.performRestoreInstanceState(Activity.java:1029)
at android.app.Instrumentation.callActivityOnRestoreInstanceState(Instrumentation.java:1175)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2638)

Saving Background bitmap with drawn paint causes the app to crash?

Hi Chris, Sorry to bother you did not know have you read my previous post to you in another thread here #6. Anyway, have been getting weird errors (double paint on the canvas and crashing the app) occurring when i press the save button that runs this code drawableView.obtainBitmap(bitmap); where i want to save the drawn paint together with the background image. Rather a newbie in android please tell me how I can solve this problem? Thank You

 java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap@c6e04c3
                                                                                               at android.graphics.Canvas.throwIfCannotDraw(Canvas.java:1270)
                                                                                               at android.graphics.Canvas.drawBitmap(Canvas.java:1404)
                                                                                               at android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:544)
                                                                                               at android.view.View.getDrawableRenderNode(View.java:16513)
                                                                                               at android.view.View.drawBackground(View.java:16449)
                                                                                               at android.view.View.draw(View.java:16261)

Can't draw if dragging finger horizontally

Tested this on Galaxy S3 and Nexus 5. I cannot seem to be able to draw if I start dragging my finger horizontally when trying to draw anything, the line barely starts and then it cuts off every time. I can draw just fine if I drag diagonally or vertically and that's perfectly fine.

Configuration while facing this (I have 1 and 1 set for Min/Max zoom because I don't want to enable any zoom ability):

config.setStrokeColor(getResources().getColor(android.R.color.white));
            config.setStrokeWidth(20.0f);
            config.setMinZoom(1.0f);
            config.setMaxZoom(1.0f);
            config.setCanvasWidth(4000);
            config.setCanvasHeight(4000);

supporting adding text

I have a suggestion for feature. If draw text can be added. For example, asking user to enter a text in popup and on pressing done text get drawn on canvas. user should be able to move and re-size the text.

Disable Touch Listener

I'm using this Gradel in photo editor type app. I'm inflating this view above image view. is it possible to handle setConfig. I want that it will work when I click on the particular button and it will be disabled when I click on another view.

support importing a background to canvas

Is there any way to support importing a background to canvas. I tried to put an imageview behind deawableview and then get both bitmaps and overlay each other. How ever problem happens when image and canvas of drawableview are bigger than screen.

Referenced class is missing

DrawerDelegate references a class which is not present causing following exception: me.panavtec.drawableview.gestures.DrawerDelegate: can't find referenced class me.panavtec.drawableview.internal.SerializablePath

Pinch-zoom on view makes drawing disappear

As the title suggests, when you've drawn some things on the view and then you pinch to zoom, if the Max/Min Zoom levels are set to 0 and 0, the view instantly disappears and you cannot get it back or draw anymore.

If the levels are set to 3.0 and 1.0 as you provided in the example, the view zooms in for a second and then disappears and you cannot get it back or draw anymore.

Also, when beginning to draw, sometimes the draw command doesn't go through and only leaves a little scratch drawn, then you have to press again and also does the same thing. Until you rapidly move your finger and then the thing starts to work fine, but also mid-drawing you can cause it to do that scratch issue again.

Any suggestions? This is just from the first 10 minutes of me trying this library, really great work by the way, much needed and so easy to use!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.