net.hockeyapp.android.views.PaintView Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of HockeySDK Show documentation
Show all versions of HockeySDK Show documentation
HockeySDK-Android implements support for using HockeyApp in your Android application. The following features are currently supported:
Collect crash reports:If your app crashes, a crash log is written to the device's storage. If the user starts the app again, they will be asked asked to submit the crash report to HockeyApp. This works for both beta and live apps, i.e. those submitted to Google Play or other app stores. Crash logs contain viable information for you to help resolve the issue. Furthermore, you as a developer can add additional information to the report as well.
Update Alpha/Beta apps: The app will check with HockeyApp if a new version for your alpha/beta build is available. If yes, it will show a dialog to users and let them see the release notes, the version history and start the installation process right away. You can even force the installation of certain updates.
User Metrics: Understand user behavior to improve your app. Track usage through daily and monthly active users. Monitor crash impacted users. Measure customer engagement through session count. Add custom tracking calls to learn which features your users are actually using. This feature requires a minimum API level of 14 (Android 4.x Ice Cream Sandwich).
Feedback: Besides crash reports, collecting feedback from your users from within your app is a great option to help with improving your app. You act on and answer feedback directly from the HockeyApp backend.
Authenticate: Identify and authenticate users against your registered testers with the HockeyApp backend.
package net.hockeyapp.android.views;
import android.content.ContentResolver;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.graphics.*;
import android.net.Uri;
import android.os.AsyncTask;
import android.util.Log;
import android.view.MotionEvent;
import android.widget.ImageView;
import net.hockeyapp.android.Constants;
import java.io.IOException;
import java.io.InputStream;
import java.util.Stack;
/**
* Description
*
* The PaintView for showing the image and drawing on it.
*
* License
*
*
* Copyright (c) 2011-2014 Bit Stadium GmbH
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
*
* @author Patrick Eschenbach
*/
public class PaintView extends ImageView {
private static final float TOUCH_TOLERANCE = 4;
/**
* Determines the orientation of the image based on its ratio and returns the orientation the activity
* should have.
*
* @param resolver a content resolver
* @param imageUri the URI for the image
* @return the desired activity orientation
*/
public static int determineOrientation(ContentResolver resolver, Uri imageUri) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
try {
InputStream in = resolver.openInputStream(imageUri);
BitmapFactory.decodeStream(in, null, options);
/* Choose orientation based on image ratio. */
float ratio = ((float) options.outWidth) / ((float) options.outHeight);
return ratio > 1 ? ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE : ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
} catch (IOException e) {
Log.e(Constants.TAG, "Unable to determine necessary screen orientation.", e);
return ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
}
}
/**
* Calculates the scale factor to scale down the image as much as possible while preserving a minimum size
* defined by the given reqWidth and reqHeight.
*
* See: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html
*
* @param options options that describe the image
* @param reqWidth required height
* @param reqHeight required width
* @return the scale factor
*/
private static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) {
/* Raw height and width of image */
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;
if (height > reqHeight || width > reqWidth) {
final int halfHeight = height / 2;
final int halfWidth = width / 2;
/* Calculate the largest inSampleSize value that is a power of 2 and keeps both
height and width larger than the requested height and width */
while ((halfHeight / inSampleSize) > reqHeight && (halfWidth / inSampleSize) > reqWidth) {
inSampleSize *= 2;
}
}
return inSampleSize;
}
/**
* Decodes the image as a bitmap with a size as small as possible but with a minimum size of given reqWidth
* and reqHeight.
*
* Based on: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html
*
* @param resolver a content resolver
* @param imageUri the URI for the image
* @param reqWidth required height
* @param reqHeight required width
* @return the decoded bitmap
*/
private static Bitmap decodeSampledBitmapFromResource(ContentResolver resolver, Uri imageUri, int reqWidth, int reqHeight) throws IOException {
/* First decode with inJustDecodeBounds=true to check dimensions */
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
InputStream inputBounds = resolver.openInputStream(imageUri);
BitmapFactory.decodeStream(inputBounds, null, options);
/* Calculate inSampleSize */
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
/* Decode bitmap with inSampleSize set */
options.inJustDecodeBounds = false;
InputStream inputBitmap = resolver.openInputStream(imageUri);
Bitmap bitmap = BitmapFactory.decodeStream(inputBitmap, null, options);
return bitmap;
}
private Path path;
private Stack paths;
private Paint paint;
private float mX, mY;
public PaintView(Context context, Uri imageUri, int displayWidth, int displayHeight) {
super(context);
path = new Path();
paths = new Stack();
paint = new Paint();
paint.setAntiAlias(true);
paint.setDither(true);
paint.setColor(0xFFFF0000);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeJoin(Paint.Join.ROUND);
paint.setStrokeCap(Paint.Cap.ROUND);
paint.setStrokeWidth(12);
new AsyncTask