在哪里可以找到Android“Fingerpaint"演示?(Android Studio时代) [英] WHERE to find Android "Fingerpaint" demo? (Android Studio era)
问题描述
许多 Android 讨论都集中在(显然是著名的)Fingerpaint 示例上:
上的出色讨论整个文件Fingerpaint.java:(据我所知,这是整个样本:)
这来自 SDK11、17 或 19:
我仔细检查过,文件在 11、17、19 中是相同的.希望它可以帮助某人.
/** 版权所有 (C) 2007 安卓开源项目** 根据 Apache 许可,版本 2.0(许可")获得许可;* 除非遵守许可,否则您不得使用此文件.* 您可以在以下网址获得许可证副本** http://www.apache.org/licenses/LICENSE-2.0** 除非适用法律要求或书面同意,否则软件* 根据许可证分发是按原样"分发的;基础,* 没有任何形式的明示或暗示的保证或条件.* 请参阅许可证以了解管理权限的特定语言和* 许可下的限制.*/包 com.example.android.apis.graphics;导入 android.content.Context;导入 android.graphics.*;导入 android.os.Bundle;导入 android.view.Menu;导入 android.view.MenuItem;导入 android.view.MotionEvent;导入 android.view.View;公共类 FingerPaint 扩展了 GraphicsActivity实现 ColorPickerDialog.OnColorChangedListener {@覆盖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);}私人油漆 mPaint;私人面具过滤器 mEmboss;私人面具过滤器 mBlur;public void colorChanged(int color) {mPaint.setColor(颜色);}公共类 MyView 扩展视图 {私有静态最终浮动 MINP = 0.25f;私有静态最终浮动 MAXP = 0.75f;私有位图 mBitmap;私人画布 mCanvas;私有路径 mPath;私有油漆 mBitmapPaint;公共 MyView(上下文 c){超级(c);mPath = 新路径();mBitmapPaint = new Paint(Paint.DITHER_FLAG);}@覆盖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);}@覆盖受保护的无效 onDraw(画布画布){canvas.drawColor(0xFFAAAAAA);canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);canvas.drawPath(mPath, mPaint);}私人浮动 mX, my;私有静态最终浮动 TOUCH_TOLERANCE = 4;私人无效touch_start(浮动x,浮动y){mPath.reset();mPath.moveTo(x, y);mX = x;米 = y;}私人无效touch_move(浮动x,浮动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;米 = y;}}私人无效touch_up(){mPath.lineTo(mX, my);//提交到我们屏幕外的路径mCanvas.drawPath(mPath, mPaint);//杀死它,这样我们就不会重复绘制mPath.reset();}@覆盖公共布尔 onTouchEvent(MotionEvent 事件){浮动 x = event.getX();浮动 y = event.getY();开关(事件.getAction()){案例 MotionEvent.ACTION_DOWN:触摸开始(x,y);无效();休息;案例 MotionEvent.ACTION_MOVE:触摸移动(x,y);无效();休息;案例 MotionEvent.ACTION_UP:润色();无效();休息;}返回真;}}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;@覆盖公共布尔 onCreateOptionsMenu(菜单菜单){super.onCreateOptionsMenu(menu);menu.add(0, COLOR_MENU_ID, 0, 颜色").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');/**** 这是用滤镜效果扩展的机制吗?Intent intent = new Intent(null, getIntent().getData());intent.addCategory(Intent.CATEGORY_ALTERNATIVE);menu.addIntentOptions(Menu.ALTERNATIVE, 0,新的组件名称(这个,NotesList.class),空,意图,0,空);*****/返回真;}@覆盖公共布尔 onPrepareOptionsMenu(菜单菜单){super.onPrepareOptionsMenu(menu);返回真;}@覆盖公共布尔 onOptionsItemSelected(MenuItem item) {mPaint.setXfermode(null);mPaint.setAlpha(0xFF);开关(item.getItemId()){案例 COLOR_MENU_ID:new ColorPickerDialog(this, this, mPaint.getColor()).show();返回真;案例 EMBOSS_MENU_ID:如果(mPaint.getMaskFilter()!= mEmboss){mPaint.setMaskFilter(mEmboss);} 别的 {mPaint.setMaskFilter(null);}返回真;案例 BLUR_MENU_ID:如果(mPaint.getMaskFilter()!= mBlur){mPaint.setMaskFilter(mBlur);} 别的 {mPaint.setMaskFilter(null);}返回真;案例ERASE_MENU_ID:mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));返回真;案例 SRCATOP_MENU_ID:mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_ATOP));mPaint.setAlpha(0x80);返回真;}返回 super.onOptionsItemSelected(item);}}
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............
There's a possibility the beloved SDK Manager, on Mac - Studio, could help?
Would I have to go with the API11 folder?
The Android page does not seem to show Fingerpaint: here's what I see
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
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"
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);
}
}
这篇关于在哪里可以找到Android“Fingerpaint"演示?(Android Studio时代)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!