Skip to content

Commit

Permalink
Adding style, minor code change & updating gradle
Browse files Browse the repository at this point in the history
  • Loading branch information
zahid-ali-shah committed Jan 29, 2018
1 parent 6bce69a commit fb9680e
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 65 deletions.
2 changes: 1 addition & 1 deletion RELEASING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SignatureView Release Process

1. Make sure it builds! and gradle sync doesn’t produce any errors.
1. Make sure it builds! and gradle sync does not produce any errors.

2. gradlew install

Expand Down
8 changes: 4 additions & 4 deletions SignatureView-Example/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ android {
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:27.0.2'
// compile project(":signature-view")
compile 'com.kyanogen.signatureview:signature-view:1.1@aar'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.0.2'
// implementation project(":signature-view")
implementation 'com.kyanogen.signatureview:signature-view:1.1@aar'
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.media.MediaScannerConnection;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
import com.kyanogen.signatureview.SignatureView;

import com.kyanogen.signatureview.*;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
Expand All @@ -33,7 +33,10 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_signature);//see xml layout
signatureView = findViewById(R.id.signature_view);
signatureView.setPenColor(Color.RED);

int colorPrimary = ContextCompat.getColor(this, R.color.colorAccent);
signatureView.setPenColor(colorPrimary);
// or like signatureView.setPenColor(Color.RED);
}

@Override
Expand All @@ -51,19 +54,19 @@ public boolean onOptionsItemSelected(MenuItem item) {
case R.id.action_clear:
signatureView.clearCanvas();//Clear SignatureView
Toast.makeText(getApplicationContext(),
"Clear canvas",Toast.LENGTH_SHORT).show();
"Clear canvas", Toast.LENGTH_SHORT).show();
return true;
case R.id.action_download:
File directory = Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
File file = new File(directory, System.currentTimeMillis()+".png");
File file = new File(directory, System.currentTimeMillis() + ".png");
FileOutputStream out = null;
Bitmap bitmap = signatureView.getSignatureBitmap();
try {
out = new FileOutputStream(file);
if(bitmap!=null){
if (bitmap != null) {
bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
}else{
} else {
throw new FileNotFoundException();
}
} catch (Exception e) {
Expand All @@ -74,17 +77,19 @@ public boolean onOptionsItemSelected(MenuItem item) {
out.flush();
out.close();

if(bitmap!=null){
if (bitmap != null) {
Toast.makeText(getApplicationContext(),
"Image saved successfully at "+ file.getPath(),Toast.LENGTH_LONG).show();
"Image saved successfully at " + file.getPath(),
Toast.LENGTH_LONG).show();
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
new MyMediaScanner(this, file);
} else {
ArrayList<String> toBeScanned = new ArrayList<String>();
toBeScanned.add(file.getAbsolutePath());
String[] toBeScannedStr = new String[toBeScanned.size()];
toBeScannedStr = toBeScanned.toArray(toBeScannedStr);
MediaScannerConnection.scanFile(this, toBeScannedStr, null, null);
MediaScannerConnection.scanFile(this, toBeScannedStr, null,
null);
}
}
}
Expand All @@ -95,7 +100,8 @@ public boolean onOptionsItemSelected(MenuItem item) {
return true;
case R.id.action_has_signature:
Toast.makeText(getApplicationContext(),
"SignatureView is empty: "+signatureView.isBitmapEmpty(),Toast.LENGTH_SHORT).show();
"SignatureView is empty: " + signatureView.isBitmapEmpty(),
Toast.LENGTH_SHORT).show();
return true;
default:
return super.onOptionsItemSelected(item);
Expand Down Expand Up @@ -125,24 +131,10 @@ public void onScanCompleted(String path, Uri uri) {
}
}

public void InfoDialog(){
String infoMessage = "";
PackageInfo pInfo = null;
try {
pInfo = getPackageManager()
.getPackageInfo(getPackageName(), 0);
if(pInfo!=null){
infoMessage = "App Version : "+pInfo.versionName;
}
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}

String svInfo = signatureView.getVersionInfo();
if(svInfo!=null){
infoMessage = infoMessage +"\n\n"+svInfo;
}

public void InfoDialog() {
String infoMessage = "App version : " + BuildConfig.VERSION_NAME;
infoMessage = infoMessage + "\n\n" + "SignatureView library version : " +
com.kyanogen.signatureview.BuildConfig.VERSION_NAME;
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.vInfo)
.setMessage(infoMessage)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
sign:enableSignature="true"
sign:penSize="3dp"
sign:backgroundColor="#ffffff"
sign:penColor="#000000"/>
sign:penColor="@color/colorAccent"/>
6 changes: 6 additions & 0 deletions SignatureView-Example/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#ff4caf50</color>
<color name="colorPrimaryDark">#4c8e68</color>
<color name="colorAccent">#2195F2</color>
</resources>
5 changes: 4 additions & 1 deletion SignatureView-Example/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>

</resources>
</resources>
9 changes: 5 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

buildscript {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
maven {
url "https://plugins.gradle.org/m2/"
}
Expand All @@ -20,8 +22,7 @@ buildscript {
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
google()
maven { url "https://jitpack.io" }
}
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.3-rc-2-all.zip
Empty file modified gradlew
100644 → 100755
Empty file.
3 changes: 1 addition & 2 deletions signature-view/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ configurations {
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:support-annotations:27.0.2'
compile fileTree(dir: 'libs', include: ['*.jar'])
javadocDeps 'com.android.support:support-annotations:27.0.2'
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package com.kyanogen.signatureview;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
Expand Down Expand Up @@ -371,7 +367,6 @@ public void setBitmap(Bitmap bitmap) {
*
* @return boolean
*/
@RequiresApi(api = Build.VERSION_CODES.HONEYCOMB_MR1)
public boolean isBitmapEmpty() {
if (bmp != null) {
Bitmap emptyBitmap = Bitmap.createBitmap(bmp.getWidth(), bmp.getHeight(),
Expand All @@ -386,21 +381,11 @@ public boolean isBitmapEmpty() {
}

/**
* Get version info related to library
* Get library version name
*
* @return String
*/
public String getVersionInfo() {
String versionInfo = null;
PackageInfo pInfo = null;
try {
pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
if (pInfo != null) {
versionInfo = "SignatureView Version : " + pInfo.versionName;
}
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return versionInfo;
public String getVersionName() {
return BuildConfig.VERSION_NAME;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ public class Point {
public final float y;
public final long time;

public Point(float x, float y, long time){
public Point(float x, float y, long time) {
this.x = x;
this.y = y;
this.time = time;
}

private float distanceTo(Point start){
private float distanceTo(Point start) {
return (float) (Math.sqrt(Math.pow((x - start.x), 2) + Math.pow((y - start.y), 2)));
}

Expand Down

0 comments on commit fb9680e

Please sign in to comment.