1

Many, many Android discussions focus on the (apparently, famous) Fingerpaint sample:

https://stackoverflow.com/a/16650524/294884

Where do I get it, to use with Android Studio? .. 2014

http://developer.android.com/samples/index.html

Or is it now just completely out of date and legacy? Thanks for any info

Android Studio: it has NO folders, samples/ or the like............

enter image description here

There's a possibility the beloved SDK Manager, on Mac - Studio, could help?

enter image description here

Would I have to go with the API11 folder?

The Android page does not seem to show Fingerpaint: here's what I see

enter image description here

Looking in each category, there is no Fingerpaint....

On a Mac, I did manage to download API11 Samples using the beloved ADKManager. Incerdibly, on Mac they are deeply hidden inside a package (screw Macs!) But that "sample" is not there...sad

enter image description here

Community
  • 1
  • 1
Fattie
  • 27,874
  • 70
  • 431
  • 719
  • 1
    Hi, Joe. Raghunandan (one of our famous members) answered that question on May 20 '13 at 13:21. So, I guess it's not so outdated. It's in your sdk folder, under samples/graphics. In my windows installation, I have it under: `[install path]\sdk\samples\android-19\legacy\ApiDemos\src\com\example\android\apis\graphics` You might notice the word **legacy** that's only for versions prior to 18 (7 to 17 don't put it in THAT folder). Oh, yes, it depends on if you download the samples in your SDK manager (does Android Studio have one? I guess so) - Or install Eclipse and just copy the files from it. – Phantômaxx Jun 11 '14 at 14:23
  • Calm down... you are much too emotional. I suggested you a method: Install Eclipse (I guess there's a Mac version, isn't it so?). Update the SDK to the latest version, selecting the "samples" folders. Now you have them on your Hard Disk (I don't believe in an OS without folders - it's Unix or Linux based like Android, isn't it?). It's just a matter of finding them (and importing them - you'll find a plenty of guides telling you how to move from Eclipse to Android Studio). And... enjoy! – Phantômaxx Jun 11 '14 at 16:03
  • @JoeBlow do you have the android sdk. if so you can manually check the folder under the sdk folder. Exmaple `android-sdk/samples/android-11/ApiDemos/src/com/example/android/apis/graphics/FingerPaint.java` – Raghunandan Jun 11 '14 at 16:06
  • Golem - You're right, I'm sorry! You know, it's **terrifying** to install Eclipse on a Mac with Android Studio: because, it can tend to completely screw-up the Studio installation. You can imagine how scary that is to a new Android dev...... – Fattie Jun 11 '14 at 16:07
  • What prevents me to use Android Studio is this warning from the Android Developer site: `Caution: Android Studio is currently available as an early access preview. Several features are either incomplete or not yet implemented and you may encounter bugs. If you are not comfortable using an unfinished product, you may want to instead download (or continue to use) the ADT Bundle (Eclipse with the ADT Plugin).` I feel more suited for a STABLE environment. – Phantômaxx Jun 11 '14 at 16:08
  • @JoeBlow I know that you, Mac users, have a fantasic tool called "Time Machine" - Backup your machine state at the current time. If something gets screwed, this will not be your ass. Because you have the backup and can go back to the original state (toast a backup of the SDK folders on a CD, before going back) – Phantômaxx Jun 11 '14 at 16:10
  • 1
    @JoeBlow http://developer.android.com/samples/index.html. – Raghunandan Jun 11 '14 at 16:11
  • @Rag -- the Fingerpaint demo is NO LONGER IN THAT LIST!!!! Can you believe it? – Fattie Jun 11 '14 at 16:11
  • @JoeBlow its still there for me – Raghunandan Jun 11 '14 at 16:12
  • 1
    @Rag -- Ahhhhh .. they must feed a different web page to Macs! Notice the 3rd image I added above. – Fattie Jun 11 '14 at 16:14
  • Do you guys think I would find it in the API11 samples? (Notice my image from SDKManager).... – Fattie Jun 11 '14 at 16:15
  • 1
    @JoeBlow: second image, beloved SDK Manager: **Samples for SDK** You have it in all API Levels from 7 to 19 (prior ones are **out of the market anyway**). Also 7, nowadays. So better download all from 8 to 19 - Lucky guy, you don't have to install Eclipse! – Phantômaxx Jun 11 '14 at 16:16
  • Ahh .. it was not in API11. OK, I'll go through them one by one, and find it THANKS !!!!!!!!!!!!!!!! – Fattie Jun 11 '14 at 16:20
  • If I'd be you, I'd check all the checkmarks in the SDK Manager, excluding only the GoogleTV addon (which isn't compatible with Windows as well, fyi). It may take a while. – Phantômaxx Jun 11 '14 at 16:28

1 Answers1

9

I found it! Thanks to Golem and Raghunandan

It is incredibly hard to find it on a Mac. Use SDKManager to download API11Samples.

Next you have to on a Mac "package contents" the Studio app itself,

and drill way down. try "ApiDemos"

enter image description here

I simply don't know if this is the latest version of the file.

Here is the whole file...

for any Mac users, to save you time:

As far as I know this is the latest version. Please also see the outstanding discussion at https://stackoverflow.com/a/16650524/294884

the entire file Fingerpaint.java: (as far as I know that is the whole sample:)

THIS IS FROM SDK11, 17 or 19:

I CAREFULLY CHECKED AND THE FILE IS IDENTICAL in 11,17,19. Hope it helps someone.

/*
 * Copyright (C) 2007 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.example.android.apis.graphics;

import android.content.Context;
import android.graphics.*;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;

public class FingerPaint extends GraphicsActivity
        implements ColorPickerDialog.OnColorChangedListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(new MyView(this));

        mPaint = new Paint();
        mPaint.setAntiAlias(true);
        mPaint.setDither(true);
        mPaint.setColor(0xFFFF0000);
        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setStrokeJoin(Paint.Join.ROUND);
        mPaint.setStrokeCap(Paint.Cap.ROUND);
        mPaint.setStrokeWidth(12);

        mEmboss = new EmbossMaskFilter(new float[] { 1, 1, 1 },
                                       0.4f, 6, 3.5f);

        mBlur = new BlurMaskFilter(8, BlurMaskFilter.Blur.NORMAL);
    }

    private Paint       mPaint;
    private MaskFilter  mEmboss;
    private MaskFilter  mBlur;

    public void colorChanged(int color) {
        mPaint.setColor(color);
    }

    public class MyView extends View {

        private static final float MINP = 0.25f;
        private static final float MAXP = 0.75f;

        private Bitmap  mBitmap;
        private Canvas  mCanvas;
        private Path    mPath;
        private Paint   mBitmapPaint;

        public MyView(Context c) {
            super(c);

            mPath = new Path();
            mBitmapPaint = new Paint(Paint.DITHER_FLAG);
        }

        @Override
        protected void onSizeChanged(int w, int h, int oldw, int oldh) {
            super.onSizeChanged(w, h, oldw, oldh);
            mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
            mCanvas = new Canvas(mBitmap);
        }

        @Override
        protected void onDraw(Canvas canvas) {
            canvas.drawColor(0xFFAAAAAA);

            canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);

            canvas.drawPath(mPath, mPaint);
        }

        private float mX, mY;
        private static final float TOUCH_TOLERANCE = 4;

        private void touch_start(float x, float y) {
            mPath.reset();
            mPath.moveTo(x, y);
            mX = x;
            mY = y;
        }
        private void touch_move(float x, float y) {
            float dx = Math.abs(x - mX);
            float dy = Math.abs(y - mY);
            if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE) {
                mPath.quadTo(mX, mY, (x + mX)/2, (y + mY)/2);
                mX = x;
                mY = y;
            }
        }
        private void touch_up() {
            mPath.lineTo(mX, mY);
            // commit the path to our offscreen
            mCanvas.drawPath(mPath, mPaint);
            // kill this so we don't double draw
            mPath.reset();
        }

        @Override
        public boolean onTouchEvent(MotionEvent event) {
            float x = event.getX();
            float y = event.getY();

            switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    touch_start(x, y);
                    invalidate();
                    break;
                case MotionEvent.ACTION_MOVE:
                    touch_move(x, y);
                    invalidate();
                    break;
                case MotionEvent.ACTION_UP:
                    touch_up();
                    invalidate();
                    break;
            }
            return true;
        }
    }

    private static final int COLOR_MENU_ID = Menu.FIRST;
    private static final int EMBOSS_MENU_ID = Menu.FIRST + 1;
    private static final int BLUR_MENU_ID = Menu.FIRST + 2;
    private static final int ERASE_MENU_ID = Menu.FIRST + 3;
    private static final int SRCATOP_MENU_ID = Menu.FIRST + 4;

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        super.onCreateOptionsMenu(menu);

        menu.add(0, COLOR_MENU_ID, 0, "Color").setShortcut('3', 'c');
        menu.add(0, EMBOSS_MENU_ID, 0, "Emboss").setShortcut('4', 's');
        menu.add(0, BLUR_MENU_ID, 0, "Blur").setShortcut('5', 'z');
        menu.add(0, ERASE_MENU_ID, 0, "Erase").setShortcut('5', 'z');
        menu.add(0, SRCATOP_MENU_ID, 0, "SrcATop").setShortcut('5', 'z');

        /****   Is this the mechanism to extend with filter effects?
        Intent intent = new Intent(null, getIntent().getData());
        intent.addCategory(Intent.CATEGORY_ALTERNATIVE);
        menu.addIntentOptions(
                              Menu.ALTERNATIVE, 0,
                              new ComponentName(this, NotesList.class),
                              null, intent, 0, null);
        *****/
        return true;
    }

    @Override
    public boolean onPrepareOptionsMenu(Menu menu) {
        super.onPrepareOptionsMenu(menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        mPaint.setXfermode(null);
        mPaint.setAlpha(0xFF);

        switch (item.getItemId()) {
            case COLOR_MENU_ID:
                new ColorPickerDialog(this, this, mPaint.getColor()).show();
                return true;
            case EMBOSS_MENU_ID:
                if (mPaint.getMaskFilter() != mEmboss) {
                    mPaint.setMaskFilter(mEmboss);
                } else {
                    mPaint.setMaskFilter(null);
                }
                return true;
            case BLUR_MENU_ID:
                if (mPaint.getMaskFilter() != mBlur) {
                    mPaint.setMaskFilter(mBlur);
                } else {
                    mPaint.setMaskFilter(null);
                }
                return true;
            case ERASE_MENU_ID:
                mPaint.setXfermode(new PorterDuffXfermode(
                                                        PorterDuff.Mode.CLEAR));
                return true;
            case SRCATOP_MENU_ID:
                mPaint.setXfermode(new PorterDuffXfermode(
                                                    PorterDuff.Mode.SRC_ATOP));
                mPaint.setAlpha(0x80);
                return true;
        }
        return super.onOptionsItemSelected(item);
    }
}
Community
  • 1
  • 1
Fattie
  • 27,874
  • 70
  • 431
  • 719
  • 1
    Maybe not the latest version, though... API Level 17 should be the last "non legacy" and API Level 19 the last "legacy" one. But they might all be the very same since version 7, afaik. So, 11 is a good compromise. – Phantômaxx Jun 11 '14 at 16:32
  • @gol Awesome - I carefully downloaded them all and checked, there is absolutely no change in the file since SDK11. Thank you!!! – Fattie Jun 12 '14 at 09:34
  • I think there's some free API around... Search on Google, you'll probably end up with a ton (10+) different github repositories to scavenge from and choose the one best fit to your needs. Cheers, man. – Phantômaxx Jun 12 '14 at 09:50
  • Hey @Der!!! You know, i searched and searched and searched, I asked questions here etc, http://stackoverflow.com/questions/24013595 -- there just seems to be NONE! I'm happy to write my own but it seems odd. Nevertheless, I remain an Android fan :) Damn iPhones! – Fattie Jun 12 '14 at 13:41
  • 1
    I did a QUICK search and found some interesting links: http://www.compiletimeerror.com/2013/09/introduction-to-2d-drawing-in-android.html, http://www.vogella.com/tutorials/AndroidTouch/article.html, http://www.java2s.com/Code/Android/2D-Graphics/GraphicsAPIsupportsbothOpenGLandAndroid2Drenderingtargetsefficientlythroughthesameinterface.htm - I must admit that I also found several copies of the **FingerPaint.java** source, though... ;) – Phantômaxx Jun 12 '14 at 13:49
  • (Damn macs!) Hmm, you know those are more "how to" articles; which is cool. I can write my own, no problem - I just want a full, complete, working library that already does it all to save me the bother! :O – Fattie Jun 12 '14 at 14:02