2018-09-02 19:00:45 +02:00
|
|
|
package org.disroot.disrootapp.ui;
|
|
|
|
|
2018-09-13 14:38:45 +02:00
|
|
|
import android.Manifest;
|
2018-09-09 17:41:03 +02:00
|
|
|
import android.annotation.SuppressLint;
|
2018-09-13 14:38:45 +02:00
|
|
|
import android.annotation.TargetApi;
|
2018-09-02 19:00:45 +02:00
|
|
|
import android.app.AlertDialog;
|
2018-09-13 14:38:45 +02:00
|
|
|
import android.app.DownloadManager;
|
2018-09-09 18:52:57 +02:00
|
|
|
import android.content.DialogInterface;
|
2018-09-02 19:00:45 +02:00
|
|
|
import android.content.Intent;
|
2018-09-09 17:41:03 +02:00
|
|
|
import android.content.SharedPreferences;
|
2018-09-13 14:38:45 +02:00
|
|
|
import android.content.pm.PackageManager;
|
|
|
|
import android.graphics.Bitmap;
|
2018-09-02 19:00:45 +02:00
|
|
|
import android.net.Uri;
|
2018-09-13 14:38:45 +02:00
|
|
|
import android.os.Build;
|
2018-09-02 19:00:45 +02:00
|
|
|
import android.os.Bundle;
|
2018-09-13 14:38:45 +02:00
|
|
|
import android.os.Environment;
|
|
|
|
import android.os.Parcelable;
|
|
|
|
import android.preference.PreferenceManager;
|
|
|
|
import android.provider.MediaStore;
|
|
|
|
import android.support.v4.app.ActivityCompat;
|
|
|
|
import android.support.v4.content.ContextCompat;
|
2018-09-02 19:00:45 +02:00
|
|
|
import android.support.v7.app.AppCompatActivity;
|
|
|
|
import android.support.v7.widget.Toolbar;
|
|
|
|
import android.util.Log;
|
|
|
|
import android.view.KeyEvent;
|
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuInflater;
|
|
|
|
import android.view.MenuItem;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
2018-09-08 03:39:01 +02:00
|
|
|
import android.view.animation.TranslateAnimation;
|
2018-09-13 14:38:45 +02:00
|
|
|
import android.webkit.DownloadListener;
|
|
|
|
import android.webkit.GeolocationPermissions;
|
|
|
|
import android.webkit.URLUtil;
|
|
|
|
import android.webkit.ValueCallback;
|
|
|
|
import android.webkit.WebChromeClient;
|
|
|
|
import android.webkit.WebResourceRequest;
|
|
|
|
import android.webkit.WebSettings;
|
2018-09-02 19:00:45 +02:00
|
|
|
import android.webkit.WebView;
|
2018-09-13 14:38:45 +02:00
|
|
|
import android.webkit.WebViewClient;
|
2018-09-07 20:22:31 +02:00
|
|
|
import android.widget.Button;
|
2018-09-02 19:00:45 +02:00
|
|
|
import android.widget.FrameLayout;
|
2018-09-13 14:38:45 +02:00
|
|
|
import android.widget.ProgressBar;
|
2018-09-08 03:39:01 +02:00
|
|
|
import android.widget.ScrollView;
|
2018-09-02 19:00:45 +02:00
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
|
import com.example.webview.R;
|
|
|
|
|
|
|
|
import org.disroot.disrootapp.utils.Constants;
|
|
|
|
import org.disroot.disrootapp.webviews.DisWebChromeClient;
|
|
|
|
import org.disroot.disrootapp.webviews.DisWebViewClient;
|
|
|
|
|
2018-09-13 14:38:45 +02:00
|
|
|
import java.io.File;
|
|
|
|
import java.io.IOException;
|
2018-09-02 19:00:45 +02:00
|
|
|
import java.lang.reflect.Method;
|
2018-09-13 14:38:45 +02:00
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
2018-09-02 19:00:45 +02:00
|
|
|
|
|
|
|
public class MainActivity extends AppCompatActivity implements View.OnLongClickListener {
|
|
|
|
|
|
|
|
private static final String TAG = MainActivity.class.getSimpleName();
|
|
|
|
private WebView webView;
|
|
|
|
private DisWebChromeClient disWebChromeClient;
|
2018-09-07 20:22:31 +02:00
|
|
|
Button button;
|
2018-09-09 17:41:03 +02:00
|
|
|
SharedPreferences firstStart = null;//first start
|
2018-09-13 14:38:45 +02:00
|
|
|
private static final int INPUT_FILE_REQUEST_CODE = 1;//file upload
|
|
|
|
private static final int FILECHOOSER_RESULTCODE = 1;
|
|
|
|
String loadUrl;
|
|
|
|
private WebSettings webSettings;
|
|
|
|
private ValueCallback<Uri> mUploadMessage;
|
|
|
|
private Uri mCapturedImageURI = null;
|
|
|
|
private ValueCallback<Uri[]> mFilePathCallback;
|
|
|
|
private String mCameraPhotoPath;
|
|
|
|
ValueCallback<Uri[]> chooserPathUri;
|
|
|
|
private ProgressBar progressBar;
|
|
|
|
|
|
|
|
public static final int REQUEST_ID_MULTIPLE_PERMISSIONS = 1;
|
|
|
|
|
|
|
|
WebView chooserWV;
|
|
|
|
WebChromeClient.FileChooserParams chooserParams;
|
|
|
|
|
|
|
|
public static final String CONTENT_HASHTAG = "content://org.disroot.disrootapp.ui.mainactivity/";
|
2018-09-09 17:41:03 +02:00
|
|
|
|
|
|
|
|
2018-09-02 19:00:45 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
setContentView(R.layout.activity_main);
|
|
|
|
FrameLayout frameLayoutContainer = (FrameLayout) findViewById(R.id.framelayout_container);
|
|
|
|
ViewGroup viewLoading = (ViewGroup) findViewById(R.id.linearlayout_view_loading_container);
|
2018-09-13 14:38:45 +02:00
|
|
|
setupWebView(savedInstanceState, frameLayoutContainer);
|
2018-09-09 17:41:03 +02:00
|
|
|
firstStart = getSharedPreferences("org.disroot.disrootap", MODE_PRIVATE);//fisrt start
|
2018-09-02 19:00:45 +02:00
|
|
|
// enables the activity icon as a 'home' button. required if "android:targetSdkVersion" > 14
|
|
|
|
//getActionBar().setHomeButtonEnabled(true);
|
2018-09-07 20:22:31 +02:00
|
|
|
|
2018-09-08 03:39:01 +02:00
|
|
|
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
|
|
|
setSupportActionBar(toolbar);
|
|
|
|
final ScrollView dashboard = (ScrollView)findViewById(R.id.dashboard);
|
2018-09-07 20:22:31 +02:00
|
|
|
|
2018-09-13 14:38:45 +02:00
|
|
|
|
|
|
|
progressBar = (ProgressBar)findViewById(R.id.progressbarLoading);
|
2018-09-07 20:22:31 +02:00
|
|
|
//Set buttons
|
|
|
|
// Locate the button in activity_main.xml
|
2018-09-08 03:39:01 +02:00
|
|
|
button = (Button) findViewById(R.id.MailBtn);//MailBtn
|
2018-09-07 20:22:31 +02:00
|
|
|
button.setOnLongClickListener(new View.OnLongClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onLongClick(View v) {
|
|
|
|
showMailInfo();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
2018-09-13 14:38:45 +02:00
|
|
|
|
2018-09-07 20:22:31 +02:00
|
|
|
// Capture button clicks
|
|
|
|
button.setOnClickListener(new View.OnClickListener() {
|
|
|
|
public void onClick(View arg0) {
|
|
|
|
// Start NewActivity.class
|
|
|
|
String k9 = "com.fsck.k9";
|
|
|
|
Intent mail = getPackageManager().getLaunchIntentForPackage(k9);
|
2018-09-13 14:38:45 +02:00
|
|
|
if(mail == null&&(firstStart.getBoolean("firsttap", false))) {
|
2018-09-07 20:22:31 +02:00
|
|
|
mail = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id="+k9));
|
2018-09-13 14:38:45 +02:00
|
|
|
}//first time tap check
|
|
|
|
if (firstStart.getBoolean("firsttap", true)){
|
|
|
|
showFirstTap();
|
|
|
|
firstStart.edit().putBoolean("firsttap", false).apply();
|
2018-09-07 20:22:31 +02:00
|
|
|
}
|
2018-09-13 14:38:45 +02:00
|
|
|
else startActivity(mail);
|
2018-09-07 20:22:31 +02:00
|
|
|
}
|
|
|
|
});
|
2018-09-08 03:39:01 +02:00
|
|
|
|
|
|
|
button = (Button) findViewById(R.id.CloudBtn);//CloudBtn
|
|
|
|
button.setOnLongClickListener(new View.OnLongClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onLongClick(View v) {
|
|
|
|
showCloudInfo();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
2018-09-07 20:22:31 +02:00
|
|
|
button.setOnClickListener(new View.OnClickListener() {
|
|
|
|
public void onClick(View arg0) {
|
2018-09-08 03:39:01 +02:00
|
|
|
String nc = "com.nextcloud.client";
|
|
|
|
Intent cloud = getPackageManager().getLaunchIntentForPackage(nc);
|
|
|
|
if(cloud == null) {
|
|
|
|
cloud = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id="+nc));
|
2018-09-13 14:38:45 +02:00
|
|
|
}//first time tap check
|
|
|
|
if (firstStart.getBoolean("firsttap", true)){
|
|
|
|
showFirstTap();
|
|
|
|
firstStart.edit().putBoolean("firsttap", false).apply();
|
2018-09-08 03:39:01 +02:00
|
|
|
}
|
2018-09-13 14:38:45 +02:00
|
|
|
else startActivity(cloud);
|
2018-09-08 03:39:01 +02:00
|
|
|
}
|
2018-09-07 20:22:31 +02:00
|
|
|
|
2018-09-08 03:39:01 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
button = (Button) findViewById(R.id.DiasporaBtn);//DiasporaBtn
|
|
|
|
button.setOnClickListener(new View.OnClickListener() {
|
|
|
|
public void onClick(View arg0) {
|
2018-09-07 20:22:31 +02:00
|
|
|
String Diaspora = "com.github.dfa.diaspora_android";
|
|
|
|
Intent pod = getPackageManager().getLaunchIntentForPackage(Diaspora);
|
|
|
|
if(pod == null) {
|
|
|
|
pod = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id="+Diaspora));
|
2018-09-13 14:38:45 +02:00
|
|
|
}//first time tap check
|
|
|
|
if (firstStart.getBoolean("firsttap", true)){
|
|
|
|
showFirstTap();
|
|
|
|
firstStart.edit().putBoolean("firsttap", false).apply();
|
2018-09-07 20:22:31 +02:00
|
|
|
}
|
2018-09-13 14:38:45 +02:00
|
|
|
else startActivity(pod);
|
2018-09-07 20:22:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2018-09-08 03:39:01 +02:00
|
|
|
button = (Button) findViewById(R.id.ForumBtn);//ForumBtn
|
2018-09-07 20:22:31 +02:00
|
|
|
button.setOnClickListener(new View.OnClickListener() {
|
|
|
|
public void onClick(View arg0) {
|
2018-09-13 14:38:45 +02:00
|
|
|
//first time tap check
|
|
|
|
if (firstStart.getBoolean("firsttap", true)){
|
|
|
|
showFirstTap();
|
|
|
|
firstStart.edit().putBoolean("firsttap", false).apply();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
2018-09-08 03:39:01 +02:00
|
|
|
webView.loadUrl(Constants.URL_DisApp_FORUM);
|
|
|
|
webView.setVisibility(View.VISIBLE);
|
|
|
|
dashboard.setVisibility(View.GONE);
|
|
|
|
}
|
2018-09-07 20:22:31 +02:00
|
|
|
|
2018-09-08 03:39:01 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
button = (Button) findViewById(R.id.ChatBtn);//ChatBtn
|
|
|
|
button.setOnClickListener(new View.OnClickListener() {
|
|
|
|
public void onClick(View arg0) {
|
|
|
|
String Conversations = "eu.siacs.conversations";
|
2018-09-09 20:16:07 +02:00
|
|
|
Intent xmpp1 = getPackageManager().getLaunchIntentForPackage(Conversations);
|
|
|
|
String PixArt = "de.pixart.messenger";
|
|
|
|
Intent xmpp2 = getPackageManager().getLaunchIntentForPackage(PixArt);
|
|
|
|
if((xmpp1 == null)&&(xmpp2 == null)) {
|
|
|
|
xmpp1 = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id="+Conversations));
|
2018-09-08 03:39:01 +02:00
|
|
|
}
|
2018-09-09 20:16:07 +02:00
|
|
|
if((xmpp1 == null)&&(xmpp2 != null)) {
|
|
|
|
startActivity(xmpp2);
|
|
|
|
}
|
|
|
|
//need to change to give user choise
|
|
|
|
if((xmpp1 != null)&&(xmpp2 != null)) {
|
|
|
|
startActivity(xmpp2);
|
|
|
|
}
|
2018-09-13 14:38:45 +02:00
|
|
|
//first time tap check
|
|
|
|
if (firstStart.getBoolean("firsttap", true)){
|
|
|
|
showFirstTap();
|
|
|
|
firstStart.edit().putBoolean("firsttap", false).apply();
|
|
|
|
}
|
|
|
|
else
|
2018-09-09 20:16:07 +02:00
|
|
|
startActivity(xmpp1);
|
2018-09-08 03:39:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
button = (Button) findViewById(R.id.PadBtn);//PadBtn
|
|
|
|
button.setOnClickListener(new View.OnClickListener() {
|
|
|
|
public void onClick(View arg0) {
|
|
|
|
String Padland = "com.mikifus.padland";
|
|
|
|
Intent pad = getPackageManager().getLaunchIntentForPackage(Padland);
|
|
|
|
if(pad == null) {
|
|
|
|
pad = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id="+Padland));
|
|
|
|
}
|
2018-09-13 14:38:45 +02:00
|
|
|
//first time tap check
|
|
|
|
if (firstStart.getBoolean("firsttap", true)){
|
|
|
|
showFirstTap();
|
|
|
|
firstStart.edit().putBoolean("firsttap", false).apply();
|
|
|
|
}
|
|
|
|
else startActivity(pad);
|
2018-09-08 03:39:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
button = (Button) findViewById(R.id.CalcBtn);//CalcBtn
|
|
|
|
button.setOnClickListener(new View.OnClickListener() {
|
|
|
|
public void onClick(View arg0) {
|
2018-09-13 14:38:45 +02:00
|
|
|
//first time tap check
|
|
|
|
if (firstStart.getBoolean("firsttap", true)){
|
|
|
|
showFirstTap();
|
|
|
|
firstStart.edit().putBoolean("firsttap", false).apply();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
2018-09-08 03:39:01 +02:00
|
|
|
webView.loadUrl(Constants.URL_DisApp_CALC);
|
2018-09-07 20:22:31 +02:00
|
|
|
webView.setVisibility(View.VISIBLE);
|
|
|
|
dashboard.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2018-09-08 03:39:01 +02:00
|
|
|
button = (Button) findViewById(R.id.BinBtn);//BinBtn
|
2018-09-07 20:22:31 +02:00
|
|
|
button.setOnClickListener(new View.OnClickListener() {
|
|
|
|
public void onClick(View arg0) {
|
2018-09-13 14:38:45 +02:00
|
|
|
//first time tap check
|
|
|
|
if (firstStart.getBoolean("firsttap", true)){
|
|
|
|
showFirstTap();
|
|
|
|
firstStart.edit().putBoolean("firsttap", false).apply();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
2018-09-08 03:39:01 +02:00
|
|
|
webView.loadUrl(Constants.URL_DisApp_BIN);
|
|
|
|
webView.setVisibility(View.VISIBLE);
|
|
|
|
dashboard.setVisibility(View.GONE);
|
|
|
|
}
|
2018-09-07 20:22:31 +02:00
|
|
|
|
2018-09-08 03:39:01 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
button = (Button) findViewById(R.id.UploadBtn);//UploadBtn
|
|
|
|
button.setOnClickListener(new View.OnClickListener() {
|
|
|
|
public void onClick(View arg0) {
|
2018-09-13 14:38:45 +02:00
|
|
|
//first time tap check
|
|
|
|
if (firstStart.getBoolean("firsttap", true)){
|
|
|
|
showFirstTap();
|
|
|
|
firstStart.edit().putBoolean("firsttap", false).apply();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
2018-09-08 03:39:01 +02:00
|
|
|
webView.loadUrl(Constants.URL_DisApp_UPLOAD);
|
|
|
|
webView.setVisibility(View.VISIBLE);
|
|
|
|
dashboard.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
button = (Button) findViewById(R.id.SearxBtn);//SearxBtn
|
|
|
|
button.setOnClickListener(new View.OnClickListener() {
|
|
|
|
public void onClick(View arg0) {
|
2018-09-13 14:38:45 +02:00
|
|
|
//first time tap check
|
|
|
|
if (firstStart.getBoolean("firsttap", true)){
|
|
|
|
showFirstTap();
|
|
|
|
firstStart.edit().putBoolean("firsttap", false).apply();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
2018-09-08 03:39:01 +02:00
|
|
|
webView.loadUrl(Constants.URL_DisApp_SEARX);
|
|
|
|
webView.setVisibility(View.VISIBLE);
|
|
|
|
dashboard.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
button = (Button) findViewById(R.id.PollsBtn);//PollsBtn
|
|
|
|
button.setOnClickListener(new View.OnClickListener() {
|
|
|
|
public void onClick(View arg0) {
|
2018-09-13 14:38:45 +02:00
|
|
|
//first time tap check
|
|
|
|
if (firstStart.getBoolean("firsttap", true)){
|
|
|
|
showFirstTap();
|
|
|
|
firstStart.edit().putBoolean("firsttap", false).apply();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
2018-09-08 03:39:01 +02:00
|
|
|
webView.loadUrl(Constants.URL_DisApp_POLL);
|
|
|
|
webView.setVisibility(View.VISIBLE);
|
|
|
|
dashboard.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
button = (Button) findViewById(R.id.BoardBtn);//BoardBtn
|
|
|
|
button.setOnClickListener(new View.OnClickListener() {
|
|
|
|
public void onClick(View arg0) {
|
2018-09-13 14:38:45 +02:00
|
|
|
//first time tap check
|
|
|
|
if (firstStart.getBoolean("firsttap", true)){
|
|
|
|
showFirstTap();
|
|
|
|
firstStart.edit().putBoolean("firsttap", false).apply();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
2018-09-08 03:39:01 +02:00
|
|
|
webView.loadUrl(Constants.URL_DisApp_BOARD);
|
|
|
|
webView.setVisibility(View.VISIBLE);
|
|
|
|
dashboard.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
button = (Button) findViewById(R.id.UserBtn);//UserBtn
|
|
|
|
button.setOnClickListener(new View.OnClickListener() {
|
|
|
|
public void onClick(View arg0) {
|
2018-09-13 14:38:45 +02:00
|
|
|
//first time tap check
|
|
|
|
if (firstStart.getBoolean("firsttap", true)){
|
|
|
|
showFirstTap();
|
|
|
|
firstStart.edit().putBoolean("firsttap", false).apply();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
2018-09-08 03:39:01 +02:00
|
|
|
webView.loadUrl(Constants.URL_DisApp_USER);
|
|
|
|
webView.setVisibility(View.VISIBLE);
|
|
|
|
dashboard.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
button = (Button) findViewById(R.id.StateBtn);//UserBtn
|
|
|
|
button.setOnClickListener(new View.OnClickListener() {
|
|
|
|
public void onClick(View arg0) {
|
2018-09-13 14:38:45 +02:00
|
|
|
//first time tap check
|
|
|
|
if (firstStart.getBoolean("firsttap", true)){
|
|
|
|
showFirstTap();
|
|
|
|
firstStart.edit().putBoolean("firsttap", false).apply();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
2018-09-08 03:39:01 +02:00
|
|
|
webView.loadUrl(Constants.URL_DisApp_STATE);
|
|
|
|
webView.setVisibility(View.VISIBLE);
|
|
|
|
dashboard.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2018-09-09 17:41:03 +02:00
|
|
|
button = (Button) findViewById(R.id.HowtoBtn);//AboutBtn
|
|
|
|
button.setOnClickListener(new View.OnClickListener() {
|
|
|
|
public void onClick(View arg0) {
|
2018-09-13 14:38:45 +02:00
|
|
|
//first time tap check
|
|
|
|
if (firstStart.getBoolean("firsttap", true)){
|
|
|
|
showFirstTap();
|
|
|
|
firstStart.edit().putBoolean("firsttap", false).apply();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
2018-09-09 17:41:03 +02:00
|
|
|
webView.loadUrl(Constants.URL_DisApp_HOWTO);
|
|
|
|
webView.setVisibility(View.VISIBLE);
|
|
|
|
dashboard.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2018-09-08 03:39:01 +02:00
|
|
|
button = (Button) findViewById(R.id.AboudBtn);//AboutBtn
|
|
|
|
button.setOnClickListener(new View.OnClickListener() {
|
|
|
|
public void onClick(View arg0) {
|
2018-09-07 20:22:31 +02:00
|
|
|
Intent goAbout = new Intent(MainActivity.this, AboutActivity.class);
|
2018-09-13 14:38:45 +02:00
|
|
|
//first time tap check
|
|
|
|
if (firstStart.getBoolean("firsttap", true)){
|
|
|
|
showFirstTap();
|
|
|
|
firstStart.edit().putBoolean("firsttap", false).apply();
|
|
|
|
}
|
|
|
|
else
|
2018-09-07 20:22:31 +02:00
|
|
|
MainActivity.this.startActivity(goAbout);
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
2018-09-02 19:00:45 +02:00
|
|
|
}
|
|
|
|
|
2018-09-13 14:38:45 +02:00
|
|
|
private void showFirstTap() {
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
|
|
|
|
builder.setTitle(R.string.FirstTitle);
|
|
|
|
builder.setMessage(getString(R.string.FirstInfo));
|
|
|
|
builder.setPositiveButton(R.string.global_ok, null);
|
|
|
|
builder.show();
|
|
|
|
}
|
|
|
|
|
2018-09-08 03:39:01 +02:00
|
|
|
private void showCloudInfo() {
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
|
2018-09-09 17:41:03 +02:00
|
|
|
builder.setTitle(R.string.CloudInfoTitle);
|
2018-09-08 03:39:01 +02:00
|
|
|
//builder.setMessage(getString(R.string.activity_main_manteiners, DeviceProvider.getAppVersion(this)));
|
2018-09-09 17:41:03 +02:00
|
|
|
builder.setMessage(getString(R.string.CloudInfo));
|
2018-09-08 03:39:01 +02:00
|
|
|
builder.setPositiveButton(R.string.global_ok, null);
|
|
|
|
builder.show();
|
|
|
|
}
|
|
|
|
|
2018-09-02 19:00:45 +02:00
|
|
|
@Override
|
|
|
|
protected void onSaveInstanceState(Bundle outState) {
|
|
|
|
super.onSaveInstanceState(outState);
|
|
|
|
webView.saveState(outState);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onRestoreInstanceState(Bundle savedInstanceState) {
|
|
|
|
super.onRestoreInstanceState(savedInstanceState);
|
|
|
|
webView.restoreState(savedInstanceState);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onPause() {
|
|
|
|
super.onPause();
|
|
|
|
webView.onPause();
|
2018-09-07 20:22:31 +02:00
|
|
|
webView.pauseTimers();
|
2018-09-02 19:00:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onResume() {
|
|
|
|
super.onResume();
|
2018-09-07 20:22:31 +02:00
|
|
|
webView.resumeTimers();
|
2018-09-02 19:00:45 +02:00
|
|
|
webView.onResume();
|
2018-09-09 17:41:03 +02:00
|
|
|
//inetnt filter get url from external
|
|
|
|
final ScrollView dashboard = (ScrollView)findViewById(R.id.dashboard);
|
|
|
|
Uri url = getIntent().getData();
|
|
|
|
if (url != null) {
|
|
|
|
Log.d("TAG", "URL Foud");
|
|
|
|
Log.d("TAG", "Url is :" + url);
|
|
|
|
webView.setVisibility(View.VISIBLE);
|
|
|
|
dashboard.setVisibility(View.GONE);
|
|
|
|
webView.loadUrl(url.toString());
|
|
|
|
}
|
|
|
|
//first start
|
|
|
|
if (firstStart.getBoolean("firstrun", true)) {
|
|
|
|
// Do first run stuff here then set 'firstrun' as false
|
2018-09-09 18:52:57 +02:00
|
|
|
Intent welcome = new Intent(MainActivity.this, WelcomeActivity.class);
|
|
|
|
MainActivity.this.startActivity(welcome);
|
2018-09-09 17:41:03 +02:00
|
|
|
// using the following line to edit/commit prefs
|
|
|
|
firstStart.edit().putBoolean("firstrun", false).apply();
|
|
|
|
}
|
2018-09-02 19:00:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onStop() {
|
|
|
|
super.onStop();
|
|
|
|
disWebChromeClient.hideCustomView();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
|
|
|
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
|
|
|
if (disWebChromeClient.hideCustomView()) {
|
|
|
|
return true;
|
|
|
|
} else if (!disWebChromeClient.hideCustomView() && webView.canGoBack()) {
|
|
|
|
webView.goBack();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return super.onKeyDown(keyCode, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onCreateOptionsMenu(Menu menu) {
|
|
|
|
// Inflate the menu items for use in the action bar
|
|
|
|
MenuInflater inflater = getMenuInflater();
|
|
|
|
inflater.inflate(R.menu.menu_main, menu);
|
|
|
|
|
|
|
|
// To show icons in the actionbar's overflow menu:
|
|
|
|
// http://stackoverflow.com/questions/18374183/how-to-show-icons-in-overflow-menu-in-actionbar
|
|
|
|
//if(featureId == Window.FEATURE_ACTION_BAR && menu != null){
|
|
|
|
if(menu.getClass().getSimpleName().equals("MenuBuilder")){
|
|
|
|
try{
|
2018-09-09 17:41:03 +02:00
|
|
|
@SuppressLint("PrivateApi") Method m = menu.getClass().getDeclaredMethod(
|
2018-09-02 19:00:45 +02:00
|
|
|
"setOptionalIconsVisible", Boolean.TYPE);
|
|
|
|
m.setAccessible(true);
|
|
|
|
m.invoke(menu, true);
|
|
|
|
}
|
|
|
|
catch(NoSuchMethodException e){
|
|
|
|
Log.e(TAG, "onMenuOpened", e);
|
|
|
|
}
|
|
|
|
catch(Exception e){
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//}
|
|
|
|
|
|
|
|
return super.onCreateOptionsMenu(menu);
|
|
|
|
}
|
|
|
|
|
2018-09-09 17:41:03 +02:00
|
|
|
|
2018-09-02 19:00:45 +02:00
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
2018-09-08 03:39:01 +02:00
|
|
|
ScrollView dashboard = (ScrollView)findViewById(R.id.dashboard);
|
|
|
|
TranslateAnimation animateup = new TranslateAnimation(0,0,-2*dashboard.getHeight(),0);
|
|
|
|
TranslateAnimation animatedown = new TranslateAnimation(0,0,0,-dashboard.getHeight());
|
2018-09-02 19:00:45 +02:00
|
|
|
switch (item.getItemId()) {
|
|
|
|
case R.id.action_share:
|
|
|
|
shareCurrentPage();
|
|
|
|
return true;
|
|
|
|
case R.id.action_home:
|
2018-09-08 03:39:01 +02:00
|
|
|
if(webView.getVisibility()==View.VISIBLE){
|
|
|
|
//animation
|
|
|
|
animateup.setDuration(500);
|
|
|
|
animateup.setFillAfter(false);
|
|
|
|
dashboard.startAnimation(animateup);
|
|
|
|
dashboard.setVisibility(View.VISIBLE);
|
|
|
|
webView.setVisibility(View.GONE);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (webView.getVisibility()==View.GONE && webView.getUrl()!=null){
|
|
|
|
//animation
|
|
|
|
animatedown.setDuration(500);
|
|
|
|
animatedown.setFillAfter(false);
|
|
|
|
dashboard.startAnimation(animatedown);
|
|
|
|
dashboard.setVisibility(View.GONE);
|
|
|
|
webView.setVisibility(View.VISIBLE);
|
2018-09-02 19:00:45 +02:00
|
|
|
return true;
|
2018-09-08 03:39:01 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
return true;
|
2018-09-09 17:41:03 +02:00
|
|
|
case R.id.action_reload: {
|
|
|
|
String url = webView.getUrl();
|
|
|
|
webView.loadUrl(url);
|
2018-09-02 19:00:45 +02:00
|
|
|
return true;
|
2018-09-09 17:41:03 +02:00
|
|
|
}
|
2018-09-02 19:00:45 +02:00
|
|
|
case R.id.action_about:
|
2018-09-07 20:22:31 +02:00
|
|
|
Intent goAbout = new Intent(MainActivity.this, AboutActivity.class);
|
|
|
|
MainActivity.this.startActivity(goAbout);
|
2018-09-02 19:00:45 +02:00
|
|
|
return true;
|
2018-09-09 17:41:03 +02:00
|
|
|
case R.id.action_exit: {
|
|
|
|
moveTaskToBack(true);
|
|
|
|
finish();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
case R.id.action_mail:
|
|
|
|
String k9 = "com.fsck.k9";
|
|
|
|
Intent mail = getPackageManager().getLaunchIntentForPackage(k9);
|
|
|
|
if(mail == null) {
|
|
|
|
mail = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id="+k9));
|
|
|
|
}
|
|
|
|
startActivity(mail);
|
|
|
|
return true;
|
|
|
|
case R.id.action_cloud:
|
|
|
|
String nc = "com.nextcloud.client";
|
|
|
|
Intent cloud = getPackageManager().getLaunchIntentForPackage(nc);
|
|
|
|
if(cloud == null) {
|
|
|
|
cloud = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id="+nc));
|
|
|
|
}
|
|
|
|
startActivity(cloud);
|
|
|
|
return true;
|
|
|
|
case R.id.action_diaspora:
|
|
|
|
String Diaspora = "com.github.dfa.diaspora_android";
|
|
|
|
Intent pod = getPackageManager().getLaunchIntentForPackage(Diaspora);
|
|
|
|
if(pod == null) {
|
|
|
|
pod = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id="+Diaspora));
|
|
|
|
}
|
|
|
|
startActivity(pod);
|
|
|
|
return true;
|
|
|
|
case R.id.action_forum:
|
|
|
|
webView.loadUrl(Constants.URL_DisApp_FORUM);
|
|
|
|
animatedown.setDuration(500);
|
|
|
|
animatedown.setFillAfter(true);
|
|
|
|
dashboard.startAnimation(animatedown);
|
|
|
|
dashboard.setVisibility(View.GONE);
|
|
|
|
webView.setVisibility(View.VISIBLE);
|
|
|
|
return true;
|
|
|
|
case R.id.action_chat:
|
|
|
|
String Conversations = "eu.siacs.conversations";
|
|
|
|
Intent xmpp = getPackageManager().getLaunchIntentForPackage(Conversations);
|
|
|
|
if(xmpp == null) {
|
|
|
|
xmpp = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id="+Conversations));
|
|
|
|
}
|
|
|
|
startActivity(xmpp);
|
|
|
|
return true;
|
|
|
|
case R.id.action_pad:
|
|
|
|
webView.loadUrl(Constants.URL_DisApp_PAD);
|
|
|
|
animatedown.setDuration(500);
|
|
|
|
animatedown.setFillAfter(true);
|
|
|
|
dashboard.startAnimation(animatedown);
|
|
|
|
dashboard.setVisibility(View.GONE);
|
|
|
|
webView.setVisibility(View.VISIBLE);
|
|
|
|
return true;
|
|
|
|
case R.id.action_calc:
|
|
|
|
webView.loadUrl(Constants.URL_DisApp_CALC);
|
|
|
|
animatedown.setDuration(500);
|
|
|
|
animatedown.setFillAfter(true);
|
|
|
|
dashboard.startAnimation(animatedown);
|
|
|
|
dashboard.setVisibility(View.GONE);
|
|
|
|
webView.setVisibility(View.VISIBLE);
|
|
|
|
return true;
|
|
|
|
case R.id.action_bin:
|
|
|
|
webView.loadUrl(Constants.URL_DisApp_BIN);
|
|
|
|
animatedown.setDuration(500);
|
|
|
|
animatedown.setFillAfter(true);
|
|
|
|
dashboard.startAnimation(animatedown);
|
|
|
|
dashboard.setVisibility(View.GONE);
|
|
|
|
webView.setVisibility(View.VISIBLE);
|
|
|
|
return true;
|
|
|
|
case R.id.action_upload:
|
|
|
|
webView.loadUrl(Constants.URL_DisApp_UPLOAD);
|
|
|
|
animatedown.setDuration(500);
|
|
|
|
animatedown.setFillAfter(true);
|
|
|
|
dashboard.startAnimation(animatedown);
|
|
|
|
dashboard.setVisibility(View.GONE);
|
|
|
|
webView.setVisibility(View.VISIBLE);
|
|
|
|
return true;
|
|
|
|
case R.id.action_searx:
|
|
|
|
webView.loadUrl(Constants.URL_DisApp_SEARX);
|
|
|
|
animatedown.setDuration(500);
|
|
|
|
animatedown.setFillAfter(true);
|
|
|
|
dashboard.startAnimation(animatedown);
|
|
|
|
dashboard.setVisibility(View.GONE);
|
|
|
|
webView.setVisibility(View.VISIBLE);
|
|
|
|
return true;
|
|
|
|
case R.id.action_poll:
|
|
|
|
webView.loadUrl(Constants.URL_DisApp_POLL);
|
|
|
|
webView.setVisibility(View.VISIBLE);
|
|
|
|
dashboard.setVisibility(View.GONE);
|
|
|
|
return true;
|
|
|
|
case R.id.action_board:
|
|
|
|
webView.loadUrl(Constants.URL_DisApp_BOARD);
|
|
|
|
animatedown.setDuration(500);
|
|
|
|
animatedown.setFillAfter(true);
|
|
|
|
dashboard.startAnimation(animatedown);
|
|
|
|
dashboard.setVisibility(View.GONE);
|
|
|
|
webView.setVisibility(View.VISIBLE);
|
|
|
|
return true;
|
|
|
|
case R.id.action_user:
|
|
|
|
webView.loadUrl(Constants.URL_DisApp_USER);
|
|
|
|
animatedown.setDuration(500);
|
|
|
|
animatedown.setFillAfter(true);
|
|
|
|
dashboard.startAnimation(animatedown);
|
|
|
|
dashboard.setVisibility(View.GONE);
|
|
|
|
webView.setVisibility(View.VISIBLE);
|
|
|
|
return true;
|
|
|
|
**/
|
2018-09-02 19:00:45 +02:00
|
|
|
default:
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
}
|
|
|
|
}
|
2018-09-08 03:39:01 +02:00
|
|
|
/**
|
|
|
|
* public void setupToolbar() {
|
|
|
|
* Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
|
|
|
* ((TextView) toolbar.findViewById(R.id.textview_toolbar_title)).setText(R.string.app_name);
|
|
|
|
* setSupportActionBar(toolbar);
|
|
|
|
* ActionBar actionBar = getSupportActionBar();
|
|
|
|
* if (actionBar != null)
|
|
|
|
* actionBar.setTitle("");
|
|
|
|
}*/
|
2018-09-09 17:41:03 +02:00
|
|
|
@SuppressLint("SetJavaScriptEnabled")
|
2018-09-13 14:38:45 +02:00
|
|
|
private void setupWebView(Bundle savedInstanceState, FrameLayout customViewContainer) {
|
2018-09-02 19:00:45 +02:00
|
|
|
disWebChromeClient = new DisWebChromeClient(this, webView, customViewContainer);
|
2018-09-13 14:38:45 +02:00
|
|
|
progressBar = (ProgressBar)findViewById(R.id.progressbarLoading);
|
2018-09-02 19:00:45 +02:00
|
|
|
webView = (WebView) findViewById(R.id.webView_content);
|
2018-09-13 14:38:45 +02:00
|
|
|
webView.setWebViewClient(new DisWebViewClient(savedInstanceState));
|
2018-09-02 19:00:45 +02:00
|
|
|
webView.setWebChromeClient(disWebChromeClient);
|
|
|
|
webView.getSettings().setJavaScriptEnabled(true);
|
2018-09-07 20:22:31 +02:00
|
|
|
webView.getSettings().setDomStorageEnabled(true);//solves taiga board \o/
|
2018-09-08 03:39:01 +02:00
|
|
|
webView.setVerticalScrollBarEnabled(true);
|
2018-09-02 19:00:45 +02:00
|
|
|
webView.getSettings().setAppCacheEnabled(true);
|
|
|
|
webView.getSettings().setBuiltInZoomControls(true);
|
|
|
|
webView.getSettings().setSaveFormData(true);
|
2018-09-13 14:38:45 +02:00
|
|
|
webView.getSettings().setAllowFileAccess(true);
|
|
|
|
webView.getSettings().setLoadWithOverviewMode(true);
|
|
|
|
webView.getSettings().setUseWideViewPort(true);
|
2018-09-07 20:22:31 +02:00
|
|
|
// webView.loadUrl(Constants.URL_DisApp_MAIN_PAGE);
|
2018-09-02 19:00:45 +02:00
|
|
|
webView.setOnLongClickListener(this);
|
2018-09-09 17:41:03 +02:00
|
|
|
// webView.setVisibility(View.GONE);;
|
2018-09-13 14:38:45 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Make download possible
|
|
|
|
webView.setDownloadListener(new DownloadListener() {
|
|
|
|
public void onDownloadStart(String url, String userAgent,
|
|
|
|
String contentDisposition, String mimetype,
|
|
|
|
long contentLength) {
|
|
|
|
final String filename= URLUtil.guessFileName(url, contentDisposition, mimetype);
|
|
|
|
DownloadManager.Request request = new DownloadManager.Request(
|
|
|
|
Uri.parse(url));
|
|
|
|
request.allowScanningByMediaScanner();
|
|
|
|
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
|
|
|
|
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, filename);
|
|
|
|
DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
|
|
|
|
dm.enqueue(request);
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
//check permissions
|
|
|
|
if (Build.VERSION.SDK_INT >= 19) {
|
|
|
|
webView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
|
|
|
|
}
|
|
|
|
else if(Build.VERSION.SDK_INT >=11 && Build.VERSION.SDK_INT < 19) {
|
|
|
|
webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
|
|
|
|
}
|
|
|
|
webView.setWebChromeClient(new ChromeClient());
|
|
|
|
webView.loadUrl(loadUrl); //change with your website
|
|
|
|
|
|
|
|
this.webView.setWebViewClient(new WebViewClient(){
|
|
|
|
@Override
|
|
|
|
public void onPageFinished(WebView view, String url) {
|
|
|
|
super.onPageFinished(view, url);
|
|
|
|
progressBar.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPageStarted(WebView view, String url, Bitmap favicon) {
|
|
|
|
super.onPageStarted(view, url, favicon);
|
|
|
|
progressBar.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings("deprecation")
|
|
|
|
@Override
|
|
|
|
public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
|
|
|
return handleUrl(url);
|
|
|
|
}
|
|
|
|
|
|
|
|
@TargetApi(Build.VERSION_CODES.N)
|
|
|
|
@Override
|
|
|
|
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
|
|
|
|
final Uri uri = request.getUrl();
|
|
|
|
return handleUrl(request.getUrl().toString());
|
|
|
|
}
|
|
|
|
});
|
2018-09-02 19:00:45 +02:00
|
|
|
}
|
|
|
|
|
2018-09-13 14:38:45 +02:00
|
|
|
public boolean handleUrl(String url){
|
|
|
|
|
|
|
|
if (url.startsWith("geo:") || url.startsWith("mailto:") || url.startsWith("tel:") || url.startsWith("sms:")|| url.startsWith("xmpp:")) {
|
|
|
|
Intent searchAddress = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
|
|
|
|
startActivity(searchAddress);
|
|
|
|
}else
|
|
|
|
webView.loadUrl(url);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean checkAndRequestPermissions() {
|
|
|
|
int permissionCamera = ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA);
|
|
|
|
int permissionStorage = ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
|
|
|
List<String> listPermissionsNeeded = new ArrayList<>();
|
|
|
|
if (permissionStorage != PackageManager.PERMISSION_GRANTED) {
|
|
|
|
listPermissionsNeeded.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
|
|
|
}
|
|
|
|
if (permissionCamera != PackageManager.PERMISSION_GRANTED) {
|
|
|
|
listPermissionsNeeded.add(Manifest.permission.CAMERA);
|
|
|
|
}
|
|
|
|
if (!listPermissionsNeeded.isEmpty()) {
|
|
|
|
ActivityCompat.requestPermissions(this, listPermissionsNeeded.toArray(new String[listPermissionsNeeded.size()]),REQUEST_ID_MULTIPLE_PERMISSIONS);
|
|
|
|
Log.e(TAG, "Returned falseeeee-------");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Log.d(TAG, "Permission returned trueeeee-------");
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
|
|
|
|
Log.d(TAG, "Permission callback called-------");
|
|
|
|
switch (requestCode) {
|
|
|
|
case REQUEST_ID_MULTIPLE_PERMISSIONS: {
|
|
|
|
|
|
|
|
Map<String, Integer> perms = new HashMap<>();
|
|
|
|
// Initialize the map with both permissions
|
|
|
|
perms.put(Manifest.permission.CAMERA, PackageManager.PERMISSION_GRANTED);
|
|
|
|
perms.put(Manifest.permission.WRITE_EXTERNAL_STORAGE, PackageManager.PERMISSION_GRANTED);
|
|
|
|
// Fill with actual results from user
|
|
|
|
if (grantResults.length > 0) {
|
|
|
|
for (int i = 0; i < permissions.length; i++)
|
|
|
|
perms.put(permissions[i], grantResults[i]);
|
|
|
|
// Check for both permissions
|
|
|
|
if (perms.get(Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED
|
|
|
|
&& perms.get(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
|
|
|
|
Log.d(TAG, "camera & Storage permission granted");
|
|
|
|
Toast.makeText(this, "Permissions granted! Try now.", Toast.LENGTH_SHORT).show();
|
|
|
|
//chromClt.openChooser(chooserWV, chooserPathUri, chooserParams);
|
|
|
|
// process the normal flow
|
|
|
|
//else any one or both the permissions are not granted
|
|
|
|
} else {
|
|
|
|
Log.d(TAG, "Some permissions are not granted ask again ");
|
|
|
|
//permission is denied (this is the first time, when "never ask again" is not checked) so ask again explaining the usage of permission
|
|
|
|
// shouldShowRequestPermissionRationale will return true
|
|
|
|
//show the dialog or snackbar saying its necessary and try again otherwise proceed with setup.
|
|
|
|
if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.CAMERA) || ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
|
|
|
|
showDialogOK("Camera and Storage Permission required for this app",
|
|
|
|
new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
switch (which) {
|
|
|
|
case DialogInterface.BUTTON_POSITIVE:
|
|
|
|
checkAndRequestPermissions();
|
|
|
|
break;
|
|
|
|
case DialogInterface.BUTTON_NEGATIVE:
|
|
|
|
// proceed with logic by disabling the related features or quit the app.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
//permission is denied (and never ask again is checked)
|
|
|
|
//shouldShowRequestPermissionRationale will return false
|
|
|
|
else {
|
|
|
|
Toast.makeText(this, "Go to settings and enable permissions", Toast.LENGTH_LONG).show();
|
|
|
|
// //proceed with logic by disabling the related features or quit the app.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void showDialogOK(String message, DialogInterface.OnClickListener okListener) {
|
|
|
|
new AlertDialog.Builder(this)
|
|
|
|
.setMessage(message)
|
|
|
|
.setPositiveButton("OK", okListener)
|
|
|
|
.setNegativeButton("Cancel", okListener)
|
|
|
|
.create()
|
|
|
|
.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
|
|
if (requestCode != INPUT_FILE_REQUEST_CODE || mFilePathCallback == null) {
|
|
|
|
super.onActivityResult(requestCode, resultCode, data);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Uri[] results = null;
|
|
|
|
// Check that the response is a good one
|
|
|
|
if (resultCode == MainActivity.RESULT_OK) {
|
|
|
|
if (data == null) {
|
|
|
|
// If there is not data, then we may have taken a photo
|
|
|
|
if (mCameraPhotoPath != null) {
|
|
|
|
results = new Uri[]{Uri.parse(mCameraPhotoPath)};
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
String dataString = data.getDataString();
|
|
|
|
if (dataString != null) {
|
|
|
|
results = new Uri[]{Uri.parse(dataString)};
|
|
|
|
}else {
|
|
|
|
if (Build.VERSION.SDK_INT >= 16) {
|
|
|
|
if (data.getClipData() != null) {
|
|
|
|
final int numSelectedFiles = data.getClipData().getItemCount();
|
|
|
|
|
|
|
|
results = new Uri[numSelectedFiles];
|
|
|
|
|
|
|
|
for (int i = 0; i < numSelectedFiles; i++) {
|
|
|
|
results[i] = data.getClipData().getItemAt(i).getUri();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mFilePathCallback.onReceiveValue(results);
|
|
|
|
mFilePathCallback = null;
|
|
|
|
} else if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
|
|
|
|
if (requestCode != FILECHOOSER_RESULTCODE || mUploadMessage == null) {
|
|
|
|
super.onActivityResult(requestCode, resultCode, data);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (requestCode == FILECHOOSER_RESULTCODE) {
|
|
|
|
if (null == this.mUploadMessage) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Uri result = null;
|
|
|
|
try {
|
|
|
|
if (resultCode != RESULT_OK) {
|
|
|
|
result = null;
|
|
|
|
} else {
|
|
|
|
// retrieve from the private variable if the intent is null
|
|
|
|
result = data == null ? mCapturedImageURI : data.getData();
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
Toast.makeText(getApplicationContext(), "activity :" + e,
|
|
|
|
Toast.LENGTH_LONG).show();
|
|
|
|
}
|
|
|
|
mUploadMessage.onReceiveValue(result);
|
|
|
|
mUploadMessage = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (Build.VERSION.SDK_INT >= 23) {
|
|
|
|
if (checkSelfPermission(android.Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
|
|
|
== PackageManager.PERMISSION_GRANTED) {
|
|
|
|
Log.e("Permission error","You have permission");
|
|
|
|
} else {
|
|
|
|
|
|
|
|
Log.e("Permission error","You have asked for permission");
|
|
|
|
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else { //you dont need to worry about these stuff below api level 23
|
|
|
|
Log.e("Permission error","You already have the permission");
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
private File createImageFile() throws IOException {
|
|
|
|
// Create an image file name
|
|
|
|
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
|
|
|
|
String imageFileName = "JPEG_" + timeStamp + "_";
|
|
|
|
File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
|
|
|
|
File imageFile = File.createTempFile(
|
|
|
|
imageFileName, /* prefix */
|
|
|
|
".jpg", /* suffix */
|
|
|
|
storageDir /* directory */
|
|
|
|
);
|
|
|
|
return imageFile;
|
|
|
|
}
|
|
|
|
|
|
|
|
public class ChromeClient extends WebChromeClient {
|
|
|
|
|
|
|
|
public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) {
|
|
|
|
// callback.invoke(String origin, boolean allow, boolean remember);
|
|
|
|
Log.e(TAG, "onGeolocationPermissionsShowPrompt: " );
|
|
|
|
callback.invoke(origin, true, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
// For Android 5.0
|
|
|
|
public boolean onShowFileChooser(WebView view, ValueCallback<Uri[]> filePath, WebChromeClient.FileChooserParams fileChooserParams) {
|
|
|
|
|
|
|
|
chooserWV = view;
|
|
|
|
chooserPathUri = filePath;
|
|
|
|
chooserParams = fileChooserParams;
|
|
|
|
|
|
|
|
if(checkAndRequestPermissions()){
|
|
|
|
openChooser(chooserWV, chooserPathUri, chooserParams);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void openChooser(WebView view, ValueCallback<Uri[]> filePath, WebChromeClient.FileChooserParams fileChooserParams){
|
|
|
|
|
|
|
|
// Double check that we don't have any existing callbacks
|
|
|
|
if (mFilePathCallback != null) {
|
|
|
|
mFilePathCallback.onReceiveValue(null);
|
|
|
|
}
|
|
|
|
mFilePathCallback = filePath;
|
|
|
|
Intent takePictureIntent;
|
|
|
|
|
|
|
|
takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
|
|
|
|
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
|
|
|
|
// Create the File where the photo should go
|
|
|
|
File photoFile = null;
|
|
|
|
try {
|
|
|
|
photoFile = createImageFile();
|
|
|
|
takePictureIntent.putExtra("PhotoPath", mCameraPhotoPath);
|
|
|
|
} catch (IOException ex) {
|
|
|
|
// Error occurred while creating the File
|
|
|
|
Log.e(TAG, "Unable to create Image File", ex);
|
|
|
|
}
|
|
|
|
// Continue only if the File was successfully created
|
|
|
|
if (photoFile != null) {
|
|
|
|
mCameraPhotoPath = "file:" + photoFile.getAbsolutePath();
|
|
|
|
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
|
|
|
|
} else {
|
|
|
|
takePictureIntent = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT);
|
|
|
|
contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE);
|
|
|
|
if (Build.VERSION.SDK_INT >= 18) {
|
|
|
|
contentSelectionIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
|
|
|
|
}
|
|
|
|
contentSelectionIntent.setType("*/*");
|
|
|
|
Intent[] intentArray;
|
|
|
|
if (takePictureIntent != null) {
|
|
|
|
intentArray = new Intent[]{takePictureIntent};
|
|
|
|
} else {
|
|
|
|
intentArray = new Intent[0];
|
|
|
|
}
|
|
|
|
Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER);
|
|
|
|
chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent);
|
|
|
|
chooserIntent.putExtra(Intent.EXTRA_TITLE, "Image Chooser");
|
|
|
|
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray);
|
|
|
|
startActivityForResult(chooserIntent, INPUT_FILE_REQUEST_CODE);
|
|
|
|
}
|
|
|
|
|
|
|
|
// openFileChooser for Android 3.0+
|
|
|
|
public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType) {
|
|
|
|
|
|
|
|
mUploadMessage = uploadMsg;
|
|
|
|
// Create AndroidExampleFolder at sdcard
|
|
|
|
// Create AndroidExampleFolder at sdcard
|
|
|
|
File imageStorageDir = new File(Environment.getExternalStoragePublicDirectory(
|
|
|
|
Environment.DIRECTORY_PICTURES)
|
|
|
|
, "AndroidExampleFolder");
|
|
|
|
if (!imageStorageDir.exists()) {
|
|
|
|
// Create AndroidExampleFolder at sdcard
|
|
|
|
imageStorageDir.mkdirs();
|
|
|
|
}
|
|
|
|
// Create camera captured image file path and name
|
|
|
|
File file = new File(
|
|
|
|
imageStorageDir + File.separator + "IMG_"
|
|
|
|
+ String.valueOf(System.currentTimeMillis())
|
|
|
|
+ ".jpg");
|
|
|
|
mCapturedImageURI = Uri.fromFile(file);
|
|
|
|
// Camera capture image intent
|
|
|
|
final Intent captureIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
|
|
|
|
captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mCapturedImageURI);
|
|
|
|
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
|
|
|
|
i.addCategory(Intent.CATEGORY_OPENABLE);
|
|
|
|
i.setType("image/*");
|
|
|
|
// Create file chooser intent
|
|
|
|
Intent chooserIntent = Intent.createChooser(i, "Image Chooser");
|
|
|
|
// Set camera intent to file chooser
|
|
|
|
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Parcelable[]{captureIntent});
|
|
|
|
// On select image call onActivityResult method of activity
|
|
|
|
|
|
|
|
chooserIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
|
|
|
|
startActivityForResult(chooserIntent, FILECHOOSER_RESULTCODE);
|
|
|
|
}
|
|
|
|
|
|
|
|
// openFileChooser for Android < 3.0
|
|
|
|
public void openFileChooser(ValueCallback<Uri> uploadMsg) {
|
|
|
|
openFileChooser(uploadMsg, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
//openFileChooser for other Android versions
|
|
|
|
public void openFileChooser(ValueCallback<Uri> uploadMsg,
|
|
|
|
String acceptType,
|
|
|
|
String capture) {
|
|
|
|
openFileChooser(uploadMsg, acceptType);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
2018-09-02 19:00:45 +02:00
|
|
|
public void shareCurrentPage() {
|
|
|
|
Intent intent = new Intent(Intent.ACTION_SEND);
|
|
|
|
intent.setAction(Intent.ACTION_SEND);
|
|
|
|
intent.putExtra(Intent.EXTRA_TEXT, webView.getUrl());
|
|
|
|
intent.setType("text/plain");
|
|
|
|
startActivity(intent);
|
|
|
|
}
|
|
|
|
|
2018-09-07 20:22:31 +02:00
|
|
|
private void showMailInfo() {
|
2018-09-09 18:52:57 +02:00
|
|
|
final ScrollView dashboard = (ScrollView)findViewById(R.id.dashboard);
|
2018-09-02 19:00:45 +02:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
|
2018-09-07 20:22:31 +02:00
|
|
|
builder.setTitle(R.string.MailInfoTitle);
|
|
|
|
//builder.setMessage(getString(R.string.activity_main_manteiners, DeviceProvider.getAppVersion(this)));
|
|
|
|
builder.setMessage(getString(R.string.MailInfo));
|
2018-09-02 19:00:45 +02:00
|
|
|
builder.setPositiveButton(R.string.global_ok, null);
|
2018-09-09 18:52:57 +02:00
|
|
|
builder.setNegativeButton(R.string.more_help, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
webView.loadUrl(Constants.URL_DisApp_K9HELP);
|
|
|
|
webView.setVisibility(View.VISIBLE);
|
|
|
|
dashboard.setVisibility(View.GONE);
|
2018-09-02 19:00:45 +02:00
|
|
|
|
2018-09-09 18:52:57 +02:00
|
|
|
}
|
|
|
|
});
|
2018-09-09 17:41:03 +02:00
|
|
|
builder.show();
|
|
|
|
}
|
|
|
|
|
2018-09-02 19:00:45 +02:00
|
|
|
@Override
|
|
|
|
public boolean onLongClick(View view) {
|
|
|
|
Toast.makeText(view.getContext(), R.string.activity_main_share_info, Toast.LENGTH_LONG).show();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|