-
Notifications
You must be signed in to change notification settings - Fork 5
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
32b72d3
commit eed5a9f
Showing
25 changed files
with
294 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
*/build | ||
*/*.iml | ||
*.iml | ||
.gradle | ||
.idea | ||
.idea/** | ||
/local.properties | ||
/.idea/workspace.xml | ||
/.idea/libraries | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild |
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
150 changes: 150 additions & 0 deletions
150
app/src/main/java/com/referendum/uoctubre/fragments/WebFragment.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,150 @@ | ||
package com.referendum.uoctubre.fragments; | ||
|
||
import android.annotation.SuppressLint; | ||
import android.content.Intent; | ||
import android.graphics.Bitmap; | ||
import android.net.Uri; | ||
import android.net.http.SslError; | ||
import android.os.Bundle; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.webkit.SslErrorHandler; | ||
import android.webkit.WebSettings; | ||
import android.webkit.WebView; | ||
import android.webkit.WebViewClient; | ||
|
||
import com.google.firebase.remoteconfig.FirebaseRemoteConfig; | ||
import com.referendum.uoctubre.R; | ||
import com.referendum.uoctubre.main.Constants; | ||
|
||
import im.delight.android.webview.AdvancedWebView; | ||
|
||
public class WebFragment extends BaseFragment implements AdvancedWebView.Listener { | ||
|
||
public static final String TAG = "web_fragment"; | ||
|
||
public static WebFragment newInstance() { | ||
Bundle args = new Bundle(); | ||
WebFragment fragment = new WebFragment(); | ||
fragment.setArguments(args); | ||
return fragment; | ||
} | ||
|
||
private AdvancedWebView mWebView; | ||
private View loadingLayout; | ||
private View errorLayout; | ||
|
||
@SuppressLint("SetJavaScriptEnabled") | ||
@Override | ||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | ||
final View view = inflater.inflate(R.layout.fragment_web, container, false); | ||
|
||
mWebView = view.findViewById(R.id.webview); | ||
loadingLayout = view.findViewById(R.id.loading_layout); | ||
errorLayout = view.findViewById(R.id.error_layout); | ||
|
||
errorLayout.findViewById(R.id.error_retry_button).setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View view) { | ||
errorLayout.setVisibility(View.GONE); | ||
loadingLayout.setVisibility(View.VISIBLE); | ||
mWebView.setVisibility(View.VISIBLE); | ||
mWebView.loadUrl("about:blank"); | ||
|
||
//Allow to change URL via Firebase | ||
FirebaseRemoteConfig firebaseRemoteConfig = FirebaseRemoteConfig.getInstance(); | ||
firebaseRemoteConfig.setDefaults(R.xml.remote_config_defaults); | ||
String webUrl = firebaseRemoteConfig.getString(Constants.FIREBASE_CONFIG_WEB_URL); | ||
|
||
mWebView.loadUrl(webUrl); | ||
} | ||
}); | ||
|
||
mWebView.setListener(getActivity(), this); | ||
mWebView.setGeolocationEnabled(false); | ||
mWebView.setMixedContentAllowed(true); | ||
mWebView.setCookiesEnabled(true); | ||
mWebView.setThirdPartyCookiesEnabled(true); | ||
|
||
mWebView.setWebViewClient(new WebViewClient(){ | ||
@Override | ||
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) { | ||
if (view.getUrl()==null || view.getUrl().startsWith("https://")) { | ||
handler.proceed(); | ||
} | ||
else{ | ||
handler.cancel(); | ||
} | ||
} | ||
}); | ||
|
||
// Enable Javascript | ||
WebSettings webSettings = mWebView.getSettings(); | ||
webSettings.setJavaScriptEnabled(true); | ||
|
||
//Allow to change URL via Firebase | ||
FirebaseRemoteConfig firebaseRemoteConfig = FirebaseRemoteConfig.getInstance(); | ||
firebaseRemoteConfig.setDefaults(R.xml.remote_config_defaults); | ||
String webUrl = firebaseRemoteConfig.getString(Constants.FIREBASE_CONFIG_WEB_URL); | ||
|
||
mWebView.loadUrl(webUrl); | ||
|
||
return view; | ||
} | ||
|
||
@Override | ||
public void onResume() { | ||
super.onResume(); | ||
mWebView.onResume(); | ||
} | ||
|
||
@Override | ||
public void onPause() { | ||
mWebView.onPause(); | ||
super.onPause(); | ||
} | ||
|
||
@Override | ||
public void onDestroy() { | ||
mWebView.onDestroy(); | ||
super.onDestroy(); | ||
} | ||
|
||
@Override | ||
public void onActivityResult(int requestCode, int resultCode, Intent intent) { | ||
super.onActivityResult(requestCode, resultCode, intent); | ||
mWebView.onActivityResult(requestCode, resultCode, intent); | ||
} | ||
|
||
@Override | ||
public void onPageStarted(String url, Bitmap favicon) { | ||
loadingLayout.setVisibility(View.VISIBLE); | ||
} | ||
|
||
@Override | ||
public void onPageFinished(String url) { | ||
loadingLayout.setVisibility(View.GONE); | ||
} | ||
|
||
@Override | ||
public void onPageError(int errorCode, String description, String failingUrl) { | ||
errorLayout.setVisibility(View.VISIBLE); | ||
loadingLayout.setVisibility(View.GONE); | ||
mWebView.setVisibility(View.GONE); | ||
} | ||
|
||
@Override | ||
public void onDownloadRequested(String url, String suggestedFilename, String mimeType, long contentLength, String contentDisposition, String userAgent) { | ||
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url))); | ||
} | ||
|
||
@Override | ||
public void onExternalPageRequest(String url) { | ||
//Nothing | ||
} | ||
|
||
public boolean onBackPressed() { | ||
return !mWebView.onBackPressed(); | ||
} | ||
} |
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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<selector xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<item android:drawable="@drawable/ic_vector_poi_cluster" /> | ||
</selector> |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:viewportWidth="24.0" | ||
android:viewportHeight="24.0"> | ||
<path | ||
android:fillColor="#FF000000" | ||
android:pathData="M20,4L4,4c-1.1,0 -1.99,0.9 -1.99,2L2,18c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2L22,6c0,-1.1 -0.9,-2 -2,-2zM15,18L4,18v-4h11v4zM15,13L4,13L4,9h11v4zM20,18h-4L16,9h4v9z"/> | ||
</vector> |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<selector xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<item android:drawable="@drawable/ic_vector_poi_cluster" /> | ||
<item android:drawable="@drawable/ic_legacy_poi_cluster" /> | ||
</selector> |
Oops, something went wrong.