diff --git a/README.md b/README.md index 58d71f7..06d03cb 100644 --- a/README.md +++ b/README.md @@ -205,7 +205,7 @@ public class Main2Activity extends AppCompatActivity { } ``` -The sample project can be found [here](https://github.com/ImaginativeShohag/Oops-No-Internet-Sample). +The sample project can be found [here](https://github.com/ImaginativeShohag/Oops-No-Internet/tree/master/sample). ## Credits diff --git a/sample/.gitignore b/sample/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/sample/.gitignore @@ -0,0 +1 @@ +/build diff --git a/sample/build.gradle b/sample/build.gradle new file mode 100644 index 0000000..9fe2b12 --- /dev/null +++ b/sample/build.gradle @@ -0,0 +1,51 @@ +apply plugin: 'com.android.application' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' + +android { + signingConfigs { + debug { + storeFile file('/home/shohag/.android/debug.keystore') + storePassword 'android' + keyPassword 'android' + keyAlias = 'androiddebugkey' + } + } + compileSdkVersion 29 + buildToolsVersion "29.0.3" + + defaultConfig { + applicationId "org.imaginativeworld.oopsnointernet.sample" + minSdkVersion 21 + targetSdkVersion 29 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + minifyEnabled true + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + signingConfig signingConfigs.debug + } + } + +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation 'androidx.appcompat:appcompat:1.1.0' + implementation 'androidx.core:core-ktx:1.2.0' + implementation 'androidx.constraintlayout:constraintlayout:1.1.3' + testImplementation 'junit:junit:4.13' + androidTestImplementation 'androidx.test.ext:junit:1.1.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' + + // Material Components for Android + implementation 'com.google.android.material:material:1.1.0' + + implementation project(":oopsnointernet") +} diff --git a/sample/proguard-rules.pro b/sample/proguard-rules.pro new file mode 100644 index 0000000..f1b4245 --- /dev/null +++ b/sample/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# 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 *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/sample/src/androidTest/java/org/imaginativeworld/oopsnointernet/sample/ExampleInstrumentedTest.kt b/sample/src/androidTest/java/org/imaginativeworld/oopsnointernet/sample/ExampleInstrumentedTest.kt new file mode 100644 index 0000000..5440cc0 --- /dev/null +++ b/sample/src/androidTest/java/org/imaginativeworld/oopsnointernet/sample/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package org.imaginativeworld.oopsnointernet.sample + +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.ext.junit.runners.AndroidJUnit4 + +import org.junit.Test +import org.junit.runner.RunWith + +import org.junit.Assert.* + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("org.imaginativeworld.oopsnointernet.sample", appContext.packageName) + } +} diff --git a/sample/src/main/AndroidManifest.xml b/sample/src/main/AndroidManifest.xml new file mode 100644 index 0000000..5f7a623 --- /dev/null +++ b/sample/src/main/AndroidManifest.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sample/src/main/java/org/imaginativeworld/oopsnointernet/sample/JavaActivity.java b/sample/src/main/java/org/imaginativeworld/oopsnointernet/sample/JavaActivity.java new file mode 100644 index 0000000..2efa97a --- /dev/null +++ b/sample/src/main/java/org/imaginativeworld/oopsnointernet/sample/JavaActivity.java @@ -0,0 +1,133 @@ +package org.imaginativeworld.oopsnointernet.sample; + + +import android.os.Bundle; +import android.view.ViewGroup; +import android.widget.RadioGroup; + +import androidx.appcompat.app.AppCompatActivity; + +import org.imaginativeworld.oopsnointernet.ConnectionCallback; +import org.imaginativeworld.oopsnointernet.NoInternetDialog; +import org.imaginativeworld.oopsnointernet.NoInternetSnackbar; + +public class JavaActivity extends AppCompatActivity { + + // No Internet Dialog + NoInternetDialog noInternetDialog; + + // No Internet Snackbar + NoInternetSnackbar noInternetSnackbar; + + RadioGroup radio_group; + + int selectedRadioId = R.id.radio_dialog; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_java); + + radio_group = findViewById(R.id.radio_group); + + radio_group.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(RadioGroup group, int checkedId) { + + selectedRadioId = checkedId; + + init(); + + } + }); + } + + @Override + protected void onResume() { + super.onResume(); + + init(); + } + + private void init() { + + switch (selectedRadioId) { + + case R.id.radio_dialog: + + if (noInternetSnackbar != null) { + noInternetSnackbar.destroy(); + } + + // No Internet Dialog + NoInternetDialog.Builder builder1 = new NoInternetDialog.Builder(this); + + builder1.setConnectionCallback(new ConnectionCallback() { // Optional + @Override + public void hasActiveConnection(boolean hasActiveConnection) { + // ... + } + }); + builder1.setCancelable(false); // Optional + builder1.setNoInternetConnectionTitle("No Internet"); // Optional + builder1.setNoInternetConnectionMessage("Check your Internet connection and try again"); // Optional + builder1.setShowInternetOnButtons(true); // Optional + builder1.setPleaseTurnOnText("Please turn on"); // Optional + builder1.setWifiOnButtonText("Wifi"); // Optional + builder1.setMobileDataOnButtonText("Mobile data"); // Optional + + builder1.setOnAirplaneModeTitle("No Internet"); // Optional + builder1.setOnAirplaneModeMessage("You have turned on the airplane mode."); // Optional + builder1.setPleaseTurnOffText("Please turn off"); // Optional + builder1.setAirplaneModeOffButtonText("Airplane mode"); // Optional + builder1.setShowAirplaneModeOffButtons(true); // Optional + + noInternetDialog = builder1.build(); + + break; + + case R.id.radio_snackbar: + + if (noInternetDialog != null) { + noInternetDialog.destroy(); + } + + // No Internet Snackbar + NoInternetSnackbar.Builder builder2 = new NoInternetSnackbar.Builder(this, (ViewGroup) findViewById(android.R.id.content)); + + builder2.setConnectionCallback(new ConnectionCallback() { // Optional + @Override + public void hasActiveConnection(boolean hasActiveConnection) { + // ... + } + }); + builder2.setIndefinite(true); // Optional + builder2.setNoInternetConnectionMessage("No active Internet connection!"); // Optional + builder2.setOnAirplaneModeMessage("You have turned on the airplane mode!"); // Optional + builder2.setSnackbarActionText("Settings"); + builder2.setShowActionToDismiss(false); + builder2.setSnackbarDismissActionText("OK"); + + noInternetSnackbar = builder2.build(); + + break; + + } + + } + + @Override + protected void onPause() { + super.onPause(); + + // No Internet Dialog + if (noInternetDialog != null) { + noInternetDialog.destroy(); + } + + // No Internet Snackbar + if (noInternetSnackbar != null) { + noInternetSnackbar.destroy(); + } + } +} diff --git a/sample/src/main/java/org/imaginativeworld/oopsnointernet/sample/MainActivity.kt b/sample/src/main/java/org/imaginativeworld/oopsnointernet/sample/MainActivity.kt new file mode 100644 index 0000000..11c6dac --- /dev/null +++ b/sample/src/main/java/org/imaginativeworld/oopsnointernet/sample/MainActivity.kt @@ -0,0 +1,119 @@ +package org.imaginativeworld.oopsnointernet.sample + + +import android.content.Intent +import android.os.Bundle +import androidx.appcompat.app.AppCompatActivity +import kotlinx.android.synthetic.main.activity_main.* +import org.imaginativeworld.oopsnointernet.ConnectionCallback +import org.imaginativeworld.oopsnointernet.NoInternetDialog +import org.imaginativeworld.oopsnointernet.NoInternetSnackbar + +class MainActivity : AppCompatActivity() { + + // No Internet Dialog + private var noInternetDialog: NoInternetDialog? = null + + // No Internet Snackbar + private var noInternetSnackbar: NoInternetSnackbar? = null + + private var selectedRadioId = R.id.radio_dialog + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main) + + radio_group.setOnCheckedChangeListener { _, checkedId -> + + selectedRadioId = checkedId + + init() + + } + + btn_go_to_java_activity.setOnClickListener { + + startActivity(Intent(this, JavaActivity::class.java)) + + } + } + + override fun onResume() { + super.onResume() + + init() + } + + private fun init() { + when (selectedRadioId) { + + R.id.radio_dialog -> { + + noInternetSnackbar?.destroy() + + // No Internet Dialog + noInternetDialog = NoInternetDialog.Builder(this) + .apply { + connectionCallback = object : ConnectionCallback { // Optional + override fun hasActiveConnection(hasActiveConnection: Boolean) { + // ... + } + } + cancelable = false // Optional + noInternetConnectionTitle = "No Internet" // Optional + noInternetConnectionMessage = + "Check your Internet connection and try again." // Optional + showInternetOnButtons = true // Optional + pleaseTurnOnText = "Please turn on" // Optional + wifiOnButtonText = "Wifi" // Optional + mobileDataOnButtonText = "Mobile data" // Optional + + onAirplaneModeTitle = "No Internet" // Optional + onAirplaneModeMessage = "You have turned on the airplane mode." // Optional + pleaseTurnOffText = "Please turn off" // Optional + airplaneModeOffButtonText = "Airplane mode" // Optional + showAirplaneModeOffButtons = true // Optional + } + .build() + + } + + R.id.radio_snackbar -> { + + noInternetDialog?.destroy() + + // No Internet Snackbar + noInternetSnackbar = + NoInternetSnackbar.Builder(this, findViewById(android.R.id.content)) + .apply { + connectionCallback = object : ConnectionCallback { // Optional + override fun hasActiveConnection(hasActiveConnection: Boolean) { + // ... + } + } + indefinite = true // Optional + noInternetConnectionMessage = + "No active Internet connection!" // Optional + onAirplaneModeMessage = + "You have turned on the airplane mode!" // Optional + snackbarActionText = "Settings" // Optional + showActionToDismiss = false // Optional + snackbarDismissActionText = "OK" // Optional + } + .build() + + } + + } + } + + override fun onPause() { + super.onPause() + + // No Internet Dialog + noInternetDialog?.destroy() + + // No Internet Snackbar + noInternetSnackbar?.destroy() + } +} diff --git a/sample/src/main/res/drawable-v24/ic_launcher_foreground.xml b/sample/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/sample/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/sample/src/main/res/drawable/ic_launcher_background.xml b/sample/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..07d5da9 --- /dev/null +++ b/sample/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sample/src/main/res/layout/activity_java.xml b/sample/src/main/res/layout/activity_java.xml new file mode 100644 index 0000000..7f9ae3f --- /dev/null +++ b/sample/src/main/res/layout/activity_java.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/sample/src/main/res/layout/activity_main.xml b/sample/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..21c9175 --- /dev/null +++ b/sample/src/main/res/layout/activity_main.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sample/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/sample/src/main/res/mipmap-anydpi-v26/ic_launcher.xml new file mode 100644 index 0000000..eca70cf --- /dev/null +++ b/sample/src/main/res/mipmap-anydpi-v26/ic_launcher.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/sample/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/sample/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml new file mode 100644 index 0000000..eca70cf --- /dev/null +++ b/sample/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/sample/src/main/res/mipmap-hdpi/ic_launcher.png b/sample/src/main/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 0000000..a571e60 Binary files /dev/null and b/sample/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/sample/src/main/res/mipmap-hdpi/ic_launcher_round.png b/sample/src/main/res/mipmap-hdpi/ic_launcher_round.png new file mode 100644 index 0000000..61da551 Binary files /dev/null and b/sample/src/main/res/mipmap-hdpi/ic_launcher_round.png differ diff --git a/sample/src/main/res/mipmap-mdpi/ic_launcher.png b/sample/src/main/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 0000000..c41dd28 Binary files /dev/null and b/sample/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/sample/src/main/res/mipmap-mdpi/ic_launcher_round.png b/sample/src/main/res/mipmap-mdpi/ic_launcher_round.png new file mode 100644 index 0000000..db5080a Binary files /dev/null and b/sample/src/main/res/mipmap-mdpi/ic_launcher_round.png differ diff --git a/sample/src/main/res/mipmap-xhdpi/ic_launcher.png b/sample/src/main/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 0000000..6dba46d Binary files /dev/null and b/sample/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/sample/src/main/res/mipmap-xhdpi/ic_launcher_round.png b/sample/src/main/res/mipmap-xhdpi/ic_launcher_round.png new file mode 100644 index 0000000..da31a87 Binary files /dev/null and b/sample/src/main/res/mipmap-xhdpi/ic_launcher_round.png differ diff --git a/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png b/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 0000000..15ac681 Binary files /dev/null and b/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/sample/src/main/res/mipmap-xxhdpi/ic_launcher_round.png b/sample/src/main/res/mipmap-xxhdpi/ic_launcher_round.png new file mode 100644 index 0000000..b216f2d Binary files /dev/null and b/sample/src/main/res/mipmap-xxhdpi/ic_launcher_round.png differ diff --git a/sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png new file mode 100644 index 0000000..f25a419 Binary files /dev/null and b/sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/sample/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png b/sample/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png new file mode 100644 index 0000000..e96783c Binary files /dev/null and b/sample/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png differ diff --git a/sample/src/main/res/values/colors.xml b/sample/src/main/res/values/colors.xml new file mode 100644 index 0000000..030098f --- /dev/null +++ b/sample/src/main/res/values/colors.xml @@ -0,0 +1,6 @@ + + + #6200EE + #3700B3 + #03DAC5 + diff --git a/sample/src/main/res/values/strings.xml b/sample/src/main/res/values/strings.xml new file mode 100644 index 0000000..d1e4515 --- /dev/null +++ b/sample/src/main/res/values/strings.xml @@ -0,0 +1,5 @@ + + Oops! No Internet! Sample + Dialog + Snackbar + diff --git a/sample/src/main/res/values/styles.xml b/sample/src/main/res/values/styles.xml new file mode 100644 index 0000000..f303d30 --- /dev/null +++ b/sample/src/main/res/values/styles.xml @@ -0,0 +1,9 @@ + + + + + diff --git a/sample/src/test/java/org/imaginativeworld/oopsnointernet/sample/ExampleUnitTest.kt b/sample/src/test/java/org/imaginativeworld/oopsnointernet/sample/ExampleUnitTest.kt new file mode 100644 index 0000000..21bba20 --- /dev/null +++ b/sample/src/test/java/org/imaginativeworld/oopsnointernet/sample/ExampleUnitTest.kt @@ -0,0 +1,17 @@ +package org.imaginativeworld.oopsnointernet.sample + +import org.junit.Test + +import org.junit.Assert.* + +/** + * Example local unit test, which will execute on the development machine (host). + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +class ExampleUnitTest { + @Test + fun addition_isCorrect() { + assertEquals(4, 2 + 2) + } +} diff --git a/settings.gradle b/settings.gradle index 728c7d8..f97648f 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,2 +1,3 @@ include ':oopsnointernet' rootProject.name='Oops! No Internet!' +include ':sample'