-
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
571e31f
commit fa6f3e1
Showing
29 changed files
with
696 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
24 changes: 24 additions & 0 deletions
24
...rc/androidTest/java/org/imaginativeworld/oopsnointernet/sample/ExampleInstrumentedTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="org.imaginativeworld.oopsnointernet.sample"> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme"> | ||
<activity android:name=".JavaActivity"></activity> | ||
<activity android:name=".MainActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
133 changes: 133 additions & 0 deletions
133
sample/src/main/java/org/imaginativeworld/oopsnointernet/sample/JavaActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} | ||
} |
119 changes: 119 additions & 0 deletions
119
sample/src/main/java/org/imaginativeworld/oopsnointernet/sample/MainActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
} | ||
} |
Oops, something went wrong.