From fb9680e60be306809ce42908861a8dd085990b6f Mon Sep 17 00:00:00 2001 From: Syed Zahid Date: Tue, 30 Jan 2018 02:20:53 +0500 Subject: [PATCH] Adding style, minor code change & updating gradle --- RELEASING.md | 2 +- SignatureView-Example/build.gradle | 8 +-- .../com/kyanogen/signature/Signature.java | 54 ++++++++----------- .../main/res/layout/activity_signature.xml | 2 +- .../src/main/res/values/colors.xml | 6 +++ .../src/main/res/values/styles.xml | 5 +- build.gradle | 9 ++-- gradle/wrapper/gradle-wrapper.properties | 2 +- gradlew | 0 signature-view/build.gradle | 3 +- .../kyanogen/signatureview/SignatureView.java | 21 ++------ .../kyanogen/signatureview/model/Point.java | 4 +- 12 files changed, 51 insertions(+), 65 deletions(-) create mode 100644 SignatureView-Example/src/main/res/values/colors.xml mode change 100644 => 100755 gradlew diff --git a/RELEASING.md b/RELEASING.md index de67b2d..75acd8e 100644 --- a/RELEASING.md +++ b/RELEASING.md @@ -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 diff --git a/SignatureView-Example/build.gradle b/SignatureView-Example/build.gradle index fd79392..2cd4025 100644 --- a/SignatureView-Example/build.gradle +++ b/SignatureView-Example/build.gradle @@ -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' } \ No newline at end of file diff --git a/SignatureView-Example/src/main/java/com/kyanogen/signature/Signature.java b/SignatureView-Example/src/main/java/com/kyanogen/signature/Signature.java index 11d2832..f7618e3 100644 --- a/SignatureView-Example/src/main/java/com/kyanogen/signature/Signature.java +++ b/SignatureView-Example/src/main/java/com/kyanogen/signature/Signature.java @@ -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; @@ -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 @@ -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) { @@ -74,9 +77,10 @@ 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 { @@ -84,7 +88,8 @@ public boolean onOptionsItemSelected(MenuItem item) { 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); } } } @@ -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); @@ -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) diff --git a/SignatureView-Example/src/main/res/layout/activity_signature.xml b/SignatureView-Example/src/main/res/layout/activity_signature.xml index cd14af1..0732057 100644 --- a/SignatureView-Example/src/main/res/layout/activity_signature.xml +++ b/SignatureView-Example/src/main/res/layout/activity_signature.xml @@ -7,4 +7,4 @@ sign:enableSignature="true" sign:penSize="3dp" sign:backgroundColor="#ffffff" - sign:penColor="#000000"/> \ No newline at end of file + sign:penColor="@color/colorAccent"/> \ No newline at end of file diff --git a/SignatureView-Example/src/main/res/values/colors.xml b/SignatureView-Example/src/main/res/values/colors.xml new file mode 100644 index 0000000..398afa8 --- /dev/null +++ b/SignatureView-Example/src/main/res/values/colors.xml @@ -0,0 +1,6 @@ + + + #ff4caf50 + #4c8e68 + #2195F2 + diff --git a/SignatureView-Example/src/main/res/values/styles.xml b/SignatureView-Example/src/main/res/values/styles.xml index 766ab99..173741b 100644 --- a/SignatureView-Example/src/main/res/values/styles.xml +++ b/SignatureView-Example/src/main/res/values/styles.xml @@ -3,6 +3,9 @@ - + \ No newline at end of file diff --git a/build.gradle b/build.gradle index 837859e..5afbc0e 100644 --- a/build.gradle +++ b/build.gradle @@ -2,7 +2,9 @@ buildscript { repositories { - jcenter() + maven { + url "https://maven.google.com" + } maven { url "https://plugins.gradle.org/m2/" } @@ -20,8 +22,7 @@ buildscript { allprojects { repositories { jcenter() - maven { - url "https://maven.google.com" - } + google() + maven { url "https://jitpack.io" } } } \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index b5a0d93..47c3984 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -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 \ No newline at end of file diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 diff --git a/signature-view/build.gradle b/signature-view/build.gradle index 1e24c19..c8105b7 100644 --- a/signature-view/build.gradle +++ b/signature-view/build.gradle @@ -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' } diff --git a/signature-view/src/main/java/com/kyanogen/signatureview/SignatureView.java b/signature-view/src/main/java/com/kyanogen/signatureview/SignatureView.java index 1987ad8..e2dbdd1 100644 --- a/signature-view/src/main/java/com/kyanogen/signatureview/SignatureView.java +++ b/signature-view/src/main/java/com/kyanogen/signatureview/SignatureView.java @@ -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; @@ -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(), @@ -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; } } diff --git a/signature-view/src/main/java/com/kyanogen/signatureview/model/Point.java b/signature-view/src/main/java/com/kyanogen/signatureview/model/Point.java index 50e5f5c..9cde6b2 100644 --- a/signature-view/src/main/java/com/kyanogen/signatureview/model/Point.java +++ b/signature-view/src/main/java/com/kyanogen/signatureview/model/Point.java @@ -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))); }