/*
* Copyright (C) 2012 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.google.android.apps.markers;
import java.util.ArrayList;
import android.annotation.SuppressLint;
import android.app.ActivityManager;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Path;
import android.graphics.PathMeasure;
import android.graphics.Point;
import android.graphics.PointF;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Region;
import android.graphics.Region.Op;
import android.os.Build;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import org.dsandler.apps.markers.R;
public class Slate extends View {
static final boolean DEBUG = false;
static final String TAG = "Slate";
public static final boolean HWLAYER = true;
public static final boolean SWLAYER = false;
public static final boolean FANCY_INVALIDATES = false; // doesn't work
public static final boolean INVALIDATE_ALL_THE_THINGS = true; // invalidate() every frame
public static final int FLAG_DEBUG_STROKES = 1;
public static final int FLAG_DEBUG_PRESSURE = 1 << 1;
public static final int FLAG_DEBUG_INVALIDATES = 1 << 2;
public static final int FLAG_DEBUG_TILES = 1 << 3;
public static final int FLAG_DEBUG_EVERYTHING = ~0;
public static final int MAX_POINTERS = 10;
static final int DENSITY = 1;
private static final int SMOOTHING_FILTER_WLEN = 6;
private static final float SMOOTHING_FILTER_POS_DECAY = 0.65f;
private static final float SMOOTHING_FILTER_PRESSURE_DECAY = 0.9f;
private static final int FIXED_DIMENSION = 0; // 1024;
private static final float INVALIDATE_PADDING = 4.0f;
public static final boolean ASSUME_STYLUS_CALIBRATED = true;
// keep these in sync with penType in values/attrs.xml
public static final int TYPE_WHITEBOARD = 0;
public static final int TYPE_FELTTIP = 1;
public static final int TYPE_AIRBRUSH = 2;
public static final int TYPE_FOUNTAIN_PEN = 3;
public static final int SHAPE_CIRCLE = 0;
public static final int SHAPE_SQUARE = 1;
// public static final int SHAPE_BITMAP_CIRCLE = 2;
public static final int SHAPE_BITMAP_AIRBRUSH = 3;
public static final int SHAPE_FOUNTAIN_PEN = 4;
private float mPressureExponent = 2.0f;
private float mRadiusMin;
private float mRadiusMax;
int mDebugFlags = 0;
private TiledBitmapCanvas mTiledCanvas;
private final Paint mDebugPaints[] = new Paint[10];
private Bitmap mPendingPaintBitmap;
// private Bitmap mCircleBits;
// private Rect mCircleBitsFrame;
private Bitmap mAirbrushBits;
private Rect mAirbrushBitsFrame;
private Bitmap mFountainPenBits;
private Rect mFountainPenBitsFrame;
private PressureCooker mPressureCooker;
private boolean mZoomMode;
private boolean mEmpty;
private Region mDirtyRegion = new Region();
private Paint mBlitPaint;
private Paint mWorkspacePaint;
private Matrix mZoomMatrix = new Matrix();
private Matrix mZoomMatrixInv = new Matrix();
private float mPanX = 0f, mPanY = 0f;
private int mMemClass;
private boolean mLowMem;
public interface SlateListener {
void strokeStarted();
void strokeEnded();
}
private class MarkersPlotter implements SpotFilter.Plotter {
// Plotter receives pointer coordinates and draws them.
// It implements the necessary interface to receive filtered Spots from the SpotFilter.
// It hands off the drawing command to the renderer.
private SpotFilter mCoordBuffer;
private SmoothStroker mRenderer;
private float mLastPressure = -1f;
private int mLastTool = 0;
final float[] mTmpPoint = new float[2];
public MarkersPlotter() {
mCoordBuffer = new SpotFilter(SMOOTHING_FILTER_WLEN, SMOOTHING_FILTER_POS_DECAY, SMOOTHING_FILTER_PRESSURE_DECAY, this);
mRenderer = new SmoothStroker();
}
// final Rect tmpDirtyRect = new Rect();
@Override
public void plot(Spot s) {
final float pressureNorm;
if (ASSUME_STYLUS_CALIBRATED && s.tool == MotionEvent.TOOL_TYPE_STYLUS) {
pressureNorm = s.pressure;
} else {
pressureNorm = mPressureCooker.getAdjustedPressure(s.pressure);
}
final float radius = lerp(mRadiusMin, mRadiusMax,
(float) Math.pow(pressureNorm, mPressureExponent));
mTmpPoint[0] = s.x - mPanX;
mTmpPoint[1] = s.y - mPanY;
mZoomMatrixInv.mapPoints(mTmpPoint);
final RectF dirtyF = mRenderer.strokeTo(mTiledCanvas,
mTmpPoint[0],
mTmpPoint[1], radius);
dirty(dirtyF);
// dirtyF.roundOut(tmpDirtyRect);
// tmpDirtyRect.inset((int)-INVALIDATE_PADDING,(int)-INVALIDATE_PADDING);
// invalidate(tmpDirtyRect);
}
public void setPenColor(int color) {
mRenderer.setPenColor(color);
}
public void finish(long time) {
mLastPressure = -1f;
mCoordBuffer.finish();
mRenderer.reset();
}
// public void addCoords(MotionEvent.PointerCoords pt, long time) {
// mCoordBuffer.add(pt, time);
// mLastPressure = pt.pressure;
// }
public void add(Spot s) {
mCoordBuffer.add(s);
mLastPressure = s.pressure;
mLastTool = s.tool;
}
// public float getRadius() {
// return mRenderer.getRadius();
// }
public float getLastPressure() {
return mLastPressure;
}
public int getLastTool() {
return mLastTool;
}
public void setPenType(int shape) {
mRenderer.setPenType(shape);
}
}
private class SmoothStroker {
// The renderer. Given a stream of filtered points, converts it into draw calls.
private float mLastX = 0, mLastY = 0, mLastLen = 0, mLastR = -1;
private float mTan[] = new float[2];
private int mPenColor;
private int mPenType;
private int mShape = SHAPE_CIRCLE; // SHAPE_BITMAP_AIRBRUSH;
private Path mWorkPath = new Path();
private PathMeasure mWorkPathMeasure = new PathMeasure();
private Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
int mInkDensity = 0xff; // set to 0x20 or so for a felt-tip look, 0xff for traditional Markers
public SmoothStroker() {
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
android 画图软件源码 markers-for-android (100个子文件)
proguard.cfg 1KB
config 258B
COPYING 11KB
FETCH_HEAD 121B
HEAD 131B
HEAD 23B
about.html 1KB
license.html 695B
pack-08919bd242d09e365d3dd77a81edcaae9cb8cfa9.idx 60KB
index 8KB
Slate.java 36KB
MarkersActivity.java 35KB
TiledBitmapCanvas.java 16KB
ToolButton.java 16KB
PenWidthEditorView.java 8KB
ZoomTouchView.java 8KB
PressureCooker.java 6KB
About.java 4KB
SpotFilter.java 3KB
Spot.java 3KB
DecorTracker.java 2KB
QrCode.java 1KB
LogoView.java 1KB
CanvasLite.java 891B
master 145B
master 131B
master 41B
master 41B
pack-08919bd242d09e365d3dd77a81edcaae9cb8cfa9.pack 1.17MB
airbrush_dark.png 145KB
markers_green_rr.png 66KB
large_launcher_icon.png 66KB
uncledan_save.png 46KB
1296228064632.png 42KB
icon-512.png 41KB
grabber.png 34KB
orig-icon.png 32KB
uncledan.png 19KB
airbrush_light.png 12KB
icon-144.png 11KB
launcher_icon.png 8KB
markers.png 7KB
fountainpen.png 6KB
icon-72.png 6KB
icon-48.png 4KB
icon.png 4KB
scribble.png 4KB
launcher_icon.png 4KB
doodlebug.png 4KB
gallery.png 4KB
markers.png 4KB
circle.png 3KB
newpage.png 3KB
icon-36.png 2KB
load.png 2KB
check.png 2KB
undo.png 2KB
share.png 2KB
circle_1bpp.png 2KB
qr.png 2KB
overflow.png 1KB
divider.png 861B
checks_light.png 129B
checks_small_dark.png 121B
build.properties 766B
default.properties 374B
project.properties 372B
markers_green_rr.psd 595KB
markers_green.psd 567KB
markers.psd 477KB
gen-circle.sh 192B
colors_vertical.xml 15KB
colors_horizontal.xml 15KB
tools.xml 5KB
actionbar.xml 4KB
build.xml 4KB
styles.xml 3KB
main.xml 2KB
overflow_menu.xml 2KB
AndroidManifest.xml 2KB
about_box.xml 2KB
main.xml 1KB
attrs.xml 1KB
dimens.xml 1KB
colors.xml 1KB
dimens.xml 1KB
action_button_bg.xml 1KB
pentool_bg.xml 988B
pentool_bg.xml 988B
pentool_fg.xml 988B
dimens.xml 975B
strings.xml 905B
dimens.xml 888B
transparent_tool.xml 826B
transparent.xml 821B
config.xml 743B
config.xml 741B
config.xml 740B
config.xml 740B
pen_editor.xml 544B
共 100 条
- 1
william_ycyh
- 粉丝: 14
- 资源: 11
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 自动驾驶-状态估计和定位之Error State EKF.pdf
- STM32F103ZET6+北斗
- 程序流程图的说明及图形示例
- FDN5618P-NL-VB一款SOT23封装P-Channel场效应MOS管
- Go语言基础(变量和基本类型).zip
- 基于CYCLONE2 (EP2C8Q) FPGA 设计PLL锁相环设置时钟Verilog源码Quartus工程文件.zip
- FDN372S-NL-VB一款SOT23封装N-Channel场效应MOS管
- date0425111111111111111111111
- 包含贪心算法的定义及python代码部分实现
- 自动驾驶-状态估计和定位之扩展卡尔曼滤波.pdf
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
前往页