forked from Sav22999/common-voice-android
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- WebBrowser ForTests added - README.md
- Loading branch information
Showing
9 changed files
with
165 additions
and
27 deletions.
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
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
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
104 changes: 104 additions & 0 deletions
104
app/src/main/java/org/commonvoice/saverio/WebBrowser.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,104 @@ | ||
package org.commonvoice.saverio | ||
|
||
import android.content.Context | ||
import android.content.Intent | ||
import android.content.SharedPreferences | ||
import android.graphics.Bitmap | ||
import android.net.ConnectivityManager | ||
import android.os.Bundle | ||
import android.view.animation.Animation | ||
import android.view.animation.AnimationUtils | ||
import android.webkit.CookieManager | ||
import android.webkit.WebView | ||
import android.webkit.WebViewClient | ||
import android.widget.ImageView | ||
import android.widget.TextView | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.core.view.isGone | ||
|
||
class WebBrowser : AppCompatActivity() { | ||
|
||
private lateinit var webView: WebView | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_webbrowser) | ||
|
||
if (checkConnection()) { | ||
navigateWebBrowser() | ||
} else { | ||
finish() | ||
} | ||
} | ||
|
||
fun checkConnection(): Boolean { | ||
if (LoginActivity.checkInternet(this)) | ||
{ | ||
return true | ||
} else { | ||
openNoConnection() | ||
return false | ||
} | ||
} | ||
|
||
companion object { | ||
fun checkInternet(context: Context):Boolean { | ||
val cm = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager | ||
val networkInfo = cm.activeNetworkInfo | ||
if (networkInfo != null && networkInfo.isConnected) { | ||
//Connection OK | ||
return true | ||
} | ||
else { | ||
//No connection | ||
return false | ||
} | ||
|
||
} | ||
} | ||
|
||
fun openNoConnection() { | ||
val intent = Intent(this, NoConnectionActivity::class.java).also { | ||
startActivity(it) | ||
} | ||
} | ||
|
||
fun startAnimation(img: ImageView) { | ||
var animation: Animation = | ||
AnimationUtils.loadAnimation(applicationContext, R.anim.login) | ||
img.startAnimation(animation) | ||
} | ||
|
||
fun stopAnimation(img: ImageView) { | ||
img.clearAnimation() | ||
} | ||
|
||
fun navigateWebBrowser() { | ||
var txtLoading: TextView = findViewById(R.id.txtLoadingWebBrowser) | ||
var bgLoading: ImageView = findViewById(R.id.imgBackgroundWebBrowser) | ||
var imgLoading: ImageView = findViewById(R.id.imgRobotWebBrowser) | ||
|
||
webView = findViewById(R.id.webViewBrowser) | ||
|
||
webView.settings.javaScriptEnabled = true | ||
webView.settings.domStorageEnabled = true | ||
webView.webViewClient = object : WebViewClient() { | ||
override fun onPageStarted(view: WebView, url: String, favicon: Bitmap?) { | ||
// Loading started | ||
txtLoading.isGone = false | ||
bgLoading.isGone = false | ||
imgLoading.isGone = false | ||
startAnimation(imgLoading) | ||
} | ||
|
||
override fun onPageFinished(view: WebView?, url: String?) { | ||
// Loading finished | ||
txtLoading.isGone = true | ||
bgLoading.isGone = true | ||
imgLoading.isGone = true | ||
stopAnimation(imgLoading) | ||
} | ||
} | ||
webView.loadUrl("https://voice.allizom.org/it") | ||
} | ||
} |
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
File renamed without changes.
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