diff --git a/app/build.gradle b/app/build.gradle index 183fc90..0c0f70b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -5,15 +5,17 @@ android { buildToolsVersion "25.0.0" defaultConfig { applicationId "telegra.ph" - minSdkVersion 9 + minSdkVersion 13 targetSdkVersion 25 versionCode 1 - versionName "0.1 beta" + versionName "0.2 beta" } buildTypes { debug { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + applicationIdSuffix '.debug' + versionNameSuffix ' debug' } release { minifyEnabled true @@ -24,4 +26,5 @@ android { dependencies { compile 'com.android.support:appcompat-v7:25.0.1' + compile 'com.afollestad.material-dialogs:core:0.9.1.0' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 3410428..01e09a2 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,21 +1,28 @@ + package="telegra.ph"> + android:allowBackup="false" + android:icon="@drawable/telegraph" + android:label="@string/app_name" + android:supportsRtl="true" + android:theme="@style/AppTheme"> - + + + + + + + + diff --git a/app/src/main/java/telegra/ph/MainActivity.java b/app/src/main/java/telegra/ph/MainActivity.java index 1a4fba1..38fb1d3 100644 --- a/app/src/main/java/telegra/ph/MainActivity.java +++ b/app/src/main/java/telegra/ph/MainActivity.java @@ -8,16 +8,15 @@ import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.Menu; import android.view.MenuItem; -import android.webkit.WebChromeClient; -import android.webkit.WebResourceRequest; -import android.webkit.WebSettings; -import android.webkit.WebView; -import android.webkit.WebViewClient; +import android.webkit.*; public class MainActivity extends AppCompatActivity { private WebView webView; - private WebSettings webSettings; + private WebViewClient webViewClient; + private WebChromeClient webChromeClient; + + private static final String TELEGRAPH = "http://telegra.ph/"; @SuppressLint("SetJavaScriptEnabled") @Override @@ -25,35 +24,50 @@ public class MainActivity extends AppCompatActivity { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - webView = (WebView) findViewById(R.id.webView); - webSettings = webView.getSettings(); + WebSettings webSettings = webView.getSettings(); // Enable Javascript webSettings.setJavaScriptEnabled(true); + // Allow File Access + webSettings.setAllowFileAccess(true); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + webSettings.setAllowFileAccessFromFileURLs(true); + } + // Add Database support + webSettings.setDatabaseEnabled(true); + webSettings.setDomStorageEnabled(true); + // Add Cache support + webSettings.setAppCacheEnabled(true); // Set WebViewClient - webView.setWebViewClient(new WebViewClient() { + webViewClient = new WebViewClient() { @SuppressWarnings("deprecation") @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { - return handleUrl(url); + return urlAllowed(url); } @TargetApi(Build.VERSION_CODES.N) @Override public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) { - return handleUrl(request.getUrl().toString()); + return urlAllowed(request.getUrl().toString()); } - }); + }; + webView.setWebViewClient(webViewClient); // Set WebChromeClient - webView.setWebChromeClient(new WebChromeClient() { + webChromeClient = new WebChromeClient() { + }; + webView.setWebChromeClient(webChromeClient); - }); + // Check if app is opened to show special page + String urlToLoad = TELEGRAPH; + if (getIntent() != null && getIntent().getAction().equals(Intent.ACTION_VIEW) && getIntent().getDataString() != null && getIntent().getDataString().contains("telegra.ph")) + urlToLoad = getIntent().getDataString(); - // Load Telegra.ph - webView.loadUrl("http://telegra.ph"); + // Load URL + webView.loadUrl(urlToLoad); } @@ -80,8 +94,8 @@ public class MainActivity extends AppCompatActivity { } } - // Own methods - private boolean handleUrl(String url) { + // Extra methods + private boolean urlAllowed(String url) { return url.contains("telegra.ph"); }