From 177ff95f6afc638a1668dd5486c3c1405795de44 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 8 Apr 2016 16:51:33 +0700 Subject: [PATCH] Initial commit --- .gitignore | 8 + .idea/.name | 1 + .idea/compiler.xml | 22 ++ .idea/copyright/profiles_settings.xml | 3 + .idea/dictionaries/Samuele.xml | 3 + .idea/encodings.xml | 6 + .idea/gradle.xml | 20 ++ .idea/misc.xml | 65 ++++++ .idea/modules.xml | 10 + .idea/runConfigurations.xml | 12 + .idea/vcs.xml | 6 + README.md | 43 ++++ ScChecker.md | 61 +++++ app/.gitignore | 1 + app/build.gradle | 26 +++ app/proguard-rules.pro | 17 ++ .../utils/demo/ApplicationTest.java | 13 ++ app/src/main/AndroidManifest.xml | 20 ++ .../sccomponents/utils/demo/MainActivity.java | 72 ++++++ .../sccomponents/utils/demo/MyChecker.java | 30 +++ app/src/main/res/layout/activity_main.xml | 42 ++++ app/src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 3418 bytes app/src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 2206 bytes app/src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 4842 bytes .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 7718 bytes .../main/res/mipmap-xxxhdpi/ic_launcher.png | Bin 0 -> 10486 bytes app/src/main/res/values-w820dp/dimens.xml | 6 + app/src/main/res/values/colors.xml | 6 + app/src/main/res/values/dimens.xml | 5 + app/src/main/res/values/strings.xml | 3 + app/src/main/res/values/styles.xml | 11 + .../utils/demo/ExampleUnitTest.java | 15 ++ build.gradle | 24 ++ gradle.properties | 18 ++ gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 53637 bytes gradle/wrapper/gradle-wrapper.properties | 6 + gradlew | 160 +++++++++++++ gradlew.bat | 90 ++++++++ library/.gitignore | 1 + library/build.gradle | 27 +++ library/proguard-rules.pro | 17 ++ .../sccomponents/utils/ApplicationTest.java | 13 ++ library/src/main/AndroidManifest.xml | 11 + .../com/sccomponents/utils/ScChecker.java | 216 ++++++++++++++++++ .../sccomponents/utils/ExampleUnitTest.java | 15 ++ settings.gradle | 1 + 46 files changed, 1126 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/.name create mode 100644 .idea/compiler.xml create mode 100644 .idea/copyright/profiles_settings.xml create mode 100644 .idea/dictionaries/Samuele.xml create mode 100644 .idea/encodings.xml create mode 100644 .idea/gradle.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/runConfigurations.xml create mode 100644 .idea/vcs.xml create mode 100644 README.md create mode 100644 ScChecker.md create mode 100644 app/.gitignore create mode 100644 app/build.gradle create mode 100644 app/proguard-rules.pro create mode 100644 app/src/androidTest/java/com/sccomponents/utils/demo/ApplicationTest.java create mode 100644 app/src/main/AndroidManifest.xml create mode 100644 app/src/main/java/com/sccomponents/utils/demo/MainActivity.java create mode 100644 app/src/main/java/com/sccomponents/utils/demo/MyChecker.java create mode 100644 app/src/main/res/layout/activity_main.xml create mode 100644 app/src/main/res/mipmap-hdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-mdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-xhdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-xxhdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-xxxhdpi/ic_launcher.png create mode 100644 app/src/main/res/values-w820dp/dimens.xml create mode 100644 app/src/main/res/values/colors.xml create mode 100644 app/src/main/res/values/dimens.xml create mode 100644 app/src/main/res/values/strings.xml create mode 100644 app/src/main/res/values/styles.xml create mode 100644 app/src/test/java/com/sccomponents/utils/demo/ExampleUnitTest.java create mode 100644 build.gradle create mode 100644 gradle.properties create mode 100644 gradle/wrapper/gradle-wrapper.jar create mode 100644 gradle/wrapper/gradle-wrapper.properties create mode 100644 gradlew create mode 100644 gradlew.bat create mode 100644 library/.gitignore create mode 100644 library/build.gradle create mode 100644 library/proguard-rules.pro create mode 100644 library/src/androidTest/java/com/sccomponents/utils/ApplicationTest.java create mode 100644 library/src/main/AndroidManifest.xml create mode 100644 library/src/main/java/com/sccomponents/utils/ScChecker.java create mode 100644 library/src/test/java/com/sccomponents/utils/ExampleUnitTest.java create mode 100644 settings.gradle diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c6cbe56 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +*.iml +.gradle +/local.properties +/.idea/workspace.xml +/.idea/libraries +.DS_Store +/build +/captures diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..14c4c8c --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +Utils (Demo) \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..96cc43e --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000..e7bedf3 --- /dev/null +++ b/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/dictionaries/Samuele.xml b/.idea/dictionaries/Samuele.xml new file mode 100644 index 0000000..c9d9f74 --- /dev/null +++ b/.idea/dictionaries/Samuele.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..97626ba --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..9496544 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,20 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..deecda4 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + + + + + Spelling + + + + + SpellCheckingInspection + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..30eb396 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..7f68460 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..9f6be25 --- /dev/null +++ b/README.md @@ -0,0 +1,43 @@ +# ScUtils +This is a library of utilities classes + +- **[ScChecker](ScChecker.md)**
+This is very simple class that periodically repeat a check method. + +# Usage + +via Gradle: +```java +android { + ... + buildTypes { + ... + repositories { + ... + maven { url "https://jitpack.io" } + } + } +} +... +dependencies { + ... + compile 'com.github.paroca72:scutils:0.9-beta' +} +``` + +#License +
+ Copyright 2015 Samuele Carassai
+
+ 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.
+
diff --git a/ScChecker.md b/ScChecker.md new file mode 100644 index 0000000..a052e7f --- /dev/null +++ b/ScChecker.md @@ -0,0 +1,61 @@ +# ScChecker +This is very simple class utility that periodically repeat a check method. +This is an abstract class and cannot be instanced directly. +
+Through the listener implementation you can know when the status of check changed. +This can be very useful in some case. +For example when you must check the internet connection status or all kind of checks when the user must be advised only when some changed happen. + +#### Getter and Setter +- **get/setStartDelay()** -> long value, default: 100 milliseconds
+When start to check the delay in milliseconds +- **get/getCheckRate()** -> long value, default: 1000 milliseconds
+The waiting millisecond between a check and the next +- **get/getMode()** -> Modes value, default: FIXED_DELAY
+The waiting mode between a check and the next.
+Modes.FIXED_DELAY: start to wait once check is finished
+Modes.FIXED_RATE: check at fixed rate time + +#### Methods +- **boolean check()**
+Abstract method must be overridden. This method will be called periodically in according with the specified settings. +- **void start()**
+Start to check. +- **void stop()**
+- **void stop(boolean force)**
+Stop to check. If force the check will be interrupted even if not finished. +- **void setCheckerListener(CheckerListener listener)**
+Attach the listener. + +### Listener +```java + public interface CheckerListener { + + void onSuccess(); + + void onFail(); + + void onChangeState(boolean result); + + } +``` + +### Example +For an example please take a look the demo section in the project structure. + +#License +
+ Copyright 2015 Samuele Carassai
+
+ 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.
+
diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..8604f90 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,26 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 23 + buildToolsVersion "23.0.2" + + defaultConfig { + applicationId "com.sccomponents.utils.demo" + minSdkVersion 15 + targetSdkVersion 23 + versionCode 1 + versionName "1.0" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + compile fileTree(include: ['*.jar'], dir: 'libs') + compile 'com.android.support:appcompat-v7:23.2.1' + compile project(':library') +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..065b5ed --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in C:\Users\Samuele\AppData\Local\Android\sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/app/src/androidTest/java/com/sccomponents/utils/demo/ApplicationTest.java b/app/src/androidTest/java/com/sccomponents/utils/demo/ApplicationTest.java new file mode 100644 index 0000000..bfd7a41 --- /dev/null +++ b/app/src/androidTest/java/com/sccomponents/utils/demo/ApplicationTest.java @@ -0,0 +1,13 @@ +package com.sccomponents.utils.demo; + +import android.app.Application; +import android.test.ApplicationTestCase; + +/** + * Testing Fundamentals + */ +public class ApplicationTest extends ApplicationTestCase { + public ApplicationTest() { + super(Application.class); + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..deeeab4 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + diff --git a/app/src/main/java/com/sccomponents/utils/demo/MainActivity.java b/app/src/main/java/com/sccomponents/utils/demo/MainActivity.java new file mode 100644 index 0000000..b6f49cc --- /dev/null +++ b/app/src/main/java/com/sccomponents/utils/demo/MainActivity.java @@ -0,0 +1,72 @@ +package com.sccomponents.utils.demo; + +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.view.View; +import android.widget.Button; +import android.widget.TextView; + +import com.sccomponents.utils.ScChecker; + +public class MainActivity extends AppCompatActivity { + + // Holder + private MyChecker mChecker = null; + private TextView mText = null; + + @Override + protected void onCreate(Bundle savedInstanceState) { + // Init + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + // Get the text component + this.mText = (TextView) this.findViewById(R.id.text1); + + // Create the checker + this.mChecker = new MyChecker(this); + // Check every 3 seconds + this.mChecker.setCheckRate(3000); + // Listener + this.mChecker.setCheckerListener(new ScChecker.CheckerListener() { + @Override + public void onSuccess() { + // If the check return true + MainActivity.this.write("Still true"); + } + + @Override + public void onFail() { + // If the check return false + MainActivity.this.write("Still false"); + } + + @Override + public void onChangeState(boolean result) { + // If the check return true + MainActivity.this.write("Now changed to " + result); + } + }); + + // Apply on click event on the button + Button button = (Button) this.findViewById(R.id.button1); + assert button != null; + button.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + // Start to check + MainActivity.this.mChecker.start(); + } + }); + } + + // Write on screen + private void write(final String text) { + this.runOnUiThread(new Runnable() { + @Override + public void run() { + MainActivity.this.mText.setText(text); + } + }); + } +} diff --git a/app/src/main/java/com/sccomponents/utils/demo/MyChecker.java b/app/src/main/java/com/sccomponents/utils/demo/MyChecker.java new file mode 100644 index 0000000..5c6ecb9 --- /dev/null +++ b/app/src/main/java/com/sccomponents/utils/demo/MyChecker.java @@ -0,0 +1,30 @@ +package com.sccomponents.utils.demo; + +import android.app.Activity; +import android.content.Context; +import android.widget.Switch; + +import com.sccomponents.utils.ScChecker; + +/** + * This is a very simple example of ScChecker use + */ +public class MyChecker extends ScChecker { + + // Context holder + private Context mContext = null; + + // Constructor + public MyChecker(Context context) { + // Save the source context + this.mContext = context; + } + + @Override + public boolean check() { + // Get the component + Switch sw = (Switch) ((Activity) this.mContext).findViewById(R.id.switch1); + // Return true if checked + return sw.isChecked(); + } +} diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..53476a4 --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,42 @@ + + + +