package org.disroot.disrootapp.ui; import android.Manifest; import android.annotation.SuppressLint; import android.annotation.TargetApi; import android.app.AlertDialog; import android.app.DownloadManager; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.graphics.Bitmap; import android.graphics.Color; import android.net.Uri; import android.os.AsyncTask; import android.os.Build; import android.os.Bundle; import android.os.Environment; import android.os.Handler; import android.os.Parcelable; import android.os.PowerManager; import android.provider.MediaStore; import android.provider.Settings; import android.support.annotation.NonNull; import android.support.annotation.RequiresApi; import android.support.design.widget.Snackbar; import android.support.v4.app.ActivityCompat; import android.support.v4.app.FragmentManager; import android.support.v4.content.ContextCompat; import android.support.v4.widget.SwipeRefreshLayout; import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatDelegate; import android.support.v7.widget.Toolbar; import android.util.Log; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.view.animation.TranslateAnimation; import android.webkit.CookieManager; import android.webkit.CookieSyncManager; import android.webkit.DownloadListener; import android.webkit.GeolocationPermissions; import android.webkit.URLUtil; import android.webkit.ValueCallback; import android.webkit.WebChromeClient; import android.webkit.WebSettings; import android.webkit.WebView; import android.webkit.WebViewClient; import android.widget.Button; import android.widget.CheckBox; import android.widget.CompoundButton; import android.widget.FrameLayout; import android.widget.ImageButton; import android.widget.ProgressBar; import android.widget.ScrollView; import android.widget.Toast; import org.disroot.disrootapp.R; import org.disroot.disrootapp.StatusService; import org.disroot.disrootapp.utils.Constants; import org.disroot.disrootapp.utils.HttpHandler; import org.disroot.disrootapp.webviews.DisWebChromeClient; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import java.io.File; import java.io.IOException; import java.lang.reflect.Method; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import de.cketti.library.changelog.ChangeLog; import static android.support.constraint.Constraints.TAG; @SuppressWarnings("ALL") public class MainActivity extends AppCompatActivity implements View.OnLongClickListener,View.OnClickListener { SharedPreferences firstStart = null;//first start SharedPreferences check = null; SharedPreferences BtnPreference; WebChromeClient.FileChooserParams chooserParams; ValueCallback chooserPathUri; Button button; private Button MailBtn,CloudBtn,ForumBtn,ChatBtn,PadBtn, CryptpadBtn,BinBtn,UploadBtn,SearxBtn,BoardBtn,CallsBtn,NotesBtn,GitBtn,UserBtn,StateBtn,HowToBtn,AboutBtn;//all buttons private String email,cloud,forum,etherpad,bin,upload,searx,taiga,user,xmpp,notes,git,cryptpad; private CookieManager cookieManager; private WebView webView; private DisWebChromeClient disWebChromeClient; private ValueCallback mUploadMessage; private Uri mCapturedImageURI = null; private ValueCallback mFilePathCallback; private ProgressBar progressBar; private Handler handler = new Handler(); private Snackbar snackbarExitApp; private FragmentManager fm; private String mCameraPhotoPath; private String loadUrl; private int progressStatus = 0; ArrayList componentList; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); FrameLayout frameLayoutContainer = findViewById(R.id.framelayout_container); Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); toolbar.setNavigationIcon( R.drawable.ic_home ); toolbar.setNavigationOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { ScrollView dashboard = findViewById(R.id.dashboard); TranslateAnimation animateup = new TranslateAnimation(0,0,-2*dashboard.getHeight(),0); TranslateAnimation animatedown = new TranslateAnimation(0,0,0,-dashboard.getHeight()); if(webView.getVisibility()==View.VISIBLE){ //animation animateup.setDuration(500); animateup.setFillAfter(false); dashboard.startAnimation(animateup); dashboard.setVisibility(View.VISIBLE); webView.setVisibility(View.GONE); return; } if (webView.getVisibility()==View.GONE && webView.getUrl()!=null){ //animation animatedown.setDuration(500); animatedown.setFillAfter(false); dashboard.startAnimation(animatedown); hideDashboard(); return; } else return; } } ); componentList = new ArrayList<>(); new GetList().execute(); setupWebView(savedInstanceState, frameLayoutContainer); //settings firstStart = getSharedPreferences("org.disroot.disrootap", MODE_PRIVATE);//fisrt start check = getSharedPreferences("org.disroot.disrootapp", MODE_PRIVATE); //buttons visiblility preference BtnPreference = getSharedPreferences( "MailBtn", Context.MODE_PRIVATE );//mail BtnPreference = getSharedPreferences( "CloudBtn", Context.MODE_PRIVATE );//cloud BtnPreference = getSharedPreferences( "ForumBtn", Context.MODE_PRIVATE );//forum BtnPreference = getSharedPreferences( "ChatBtn", Context.MODE_PRIVATE );//chat BtnPreference = getSharedPreferences( "PadBtn", Context.MODE_PRIVATE );//pad BtnPreference = getSharedPreferences( "CryptpadBtn", Context.MODE_PRIVATE );//cryptpad BtnPreference = getSharedPreferences( "BinBtn", Context.MODE_PRIVATE );//bin BtnPreference = getSharedPreferences( "UploadBtn", Context.MODE_PRIVATE );//upload BtnPreference = getSharedPreferences( "SearxBtn", Context.MODE_PRIVATE );//search BtnPreference = getSharedPreferences( "BoardBtn", Context.MODE_PRIVATE );//board BtnPreference = getSharedPreferences( "CallsBtn", Context.MODE_PRIVATE );//calls BtnPreference = getSharedPreferences( "NotesBtn", Context.MODE_PRIVATE );//notes BtnPreference = getSharedPreferences( "GitBtn", Context.MODE_PRIVATE );//git BtnPreference = getSharedPreferences( "UserBtn", Context.MODE_PRIVATE );//user BtnPreference = getSharedPreferences( "HowToBtn", Context.MODE_PRIVATE );//howTo BtnPreference = getSharedPreferences( "AboutBtn", Context.MODE_PRIVATE );//about //Status service Intent intent = new Intent( MainActivity.this, StatusService.class); startService(intent); //progressbarLoading progressBar = findViewById(R.id.progressbarLoading); // Start long running operation in a background thread new Thread(new Runnable() { public void run() { while (progressStatus < 100) { progressStatus += 1; // Update the progress bar and display the //current value in the text view handler.post(new Runnable() { public void run() { progressBar.setProgress(progressStatus); } }); try { // Sleep for 200 milliseconds. Thread.sleep(200); } catch (InterruptedException e) { e.printStackTrace(); } } } }).start(); //ckCangelog library ChangeLog cl = new ChangeLog(this); if (cl.isFirstRun()) { cl.getLogDialog().show(); } //set booleans for checking Chat preference if (firstStart.getBoolean("firsttap", true)){ check.edit().putBoolean("checkConv",false).apply(); check.edit().putBoolean("checkPix",false).apply(); } //pull to refresh final SwipeRefreshLayout swipe = (SwipeRefreshLayout)findViewById(R.id.swipe); swipe.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh(){ swipe.setRefreshing( false ); String url = webView.getUrl(); webView.loadUrl(url); } }); //Setup snackbar snackbarExitApp = Snackbar .make(findViewById(R.id.framelayout_container), R.string.do_you_want_to_exit, Snackbar.LENGTH_LONG) .setActionTextColor( Color.LTGRAY ) .setAction(android.R.string.yes, new View.OnClickListener() { public void onClick(View view) { finish(); moveTaskToBack(true); } }); // Link the button in activity_main.xml MailBtn = findViewById( R.id.MailBtn ); CloudBtn = findViewById( R.id.CloudBtn ); //DiasporaBtn = findViewById( R.id.DiasporaBtn );//end of Disroot's Dandelion ForumBtn = findViewById( R.id.ForumBtn ); ChatBtn = findViewById( R.id.ChatBtn ); PadBtn = findViewById( R.id.PadBtn ); CryptpadBtn = findViewById( R.id.CryptpadBtn ); BinBtn = findViewById( R.id.BinBtn ); UploadBtn = findViewById( R.id.UploadBtn ); SearxBtn = findViewById( R.id.SearxBtn ); BoardBtn = findViewById( R.id.BoardBtn ); CallsBtn = findViewById( R.id.CallsBtn ); NotesBtn = findViewById( R.id.NotesBtn ); GitBtn = findViewById( R.id.GitBtn ); UserBtn = findViewById( R.id.UserBtn ); StateBtn = findViewById( R.id.StateBtn ); HowToBtn = findViewById( R.id.HowToBtn ); AboutBtn = findViewById( R.id.AboutBtn ); Map allEntries = BtnPreference.getAll(); for (Map.Entry entry : allEntries.entrySet()) { if (entry.getValue().equals( false )){ ViewGroup viewGroup =((ViewGroup)findViewById( R.id.StateBtn ).getParent()); for(int i=0; i 0) { super.onBackPressed(); } else { snackbarExitApp.show(); } return; } @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(); webView.pauseTimers(); } @Override protected void onResume() { super.onResume(); webView.resumeTimers(); webView.onResume(); //inetnt filter get url from external Uri url = getIntent().getData(); if (url != null) { Log.d("TAG", "URL Foud"); Log.d("TAG", "Url is :" + url); hideDashboard(); webView.loadUrl(url.toString()); } //first start if (firstStart.getBoolean("firstrun", true)) { Intent welcome = new Intent(MainActivity.this, WelcomeActivity.class); MainActivity.this.startActivity(welcome); firstStart.edit().putBoolean("firstrun", false).apply(); } } @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 onPrepareOptionsMenu(Menu menu) { MenuItem register = menu.findItem(R.id.action_forget); if(check.getBoolean("checkConv", true)||check.getBoolean("checkPix", true)) { register.setVisible(true); } else { register.setVisible(false); } return true; } @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(menu.getClass().getSimpleName().equals("MenuBuilder")) try { Method m = menu.getClass().getDeclaredMethod( "setOptionalIconsVisible", Boolean.TYPE); m.setAccessible(true); m.invoke(menu, true); } catch (NoSuchMethodException e) { Log.e(Constants.TAG, "onMenuOpened", e); } catch (Exception e) { throw new RuntimeException(e); } return super.onCreateOptionsMenu(menu); } @Override public boolean onOptionsItemSelected(MenuItem item) { ScrollView dashboard = findViewById(R.id.dashboard); TranslateAnimation animateup = new TranslateAnimation(0,0,-2*dashboard.getHeight(),0); TranslateAnimation animatedown = new TranslateAnimation(0,0,0,-dashboard.getHeight()); switch (item.getItemId()) { case R.id.action_share: shareCurrentPage(); return true; /*case R.id.action_home: 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); hideDashboard(); return true; } else return true;*/ case R.id.action_forget: showForget(); case R.id.action_reload: { String url = webView.getUrl(); webView.loadUrl(url); return true; } case R.id.action_optimization: showOptimzation(); return true; case R.id.action_about: Intent goAbout = new Intent(MainActivity.this, AboutActivity.class); MainActivity.this.startActivity(goAbout); return true; case R.id.action_set_icons: Intent goBtnSettings = new Intent(MainActivity.this, SettingsActivity.class); MainActivity.this.startActivity(goBtnSettings); return true; case R.id.action_clear_cookies: { if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){ CookieManager.getInstance().removeAllCookies(null); }else{ CookieManager.getInstance().removeAllCookie(); } } return false; case R.id.action_exit: { moveTaskToBack(true); finish(); return false; } default: return super.onOptionsItemSelected(item); } } private void setupWebView(Bundle savedInstanceState, FrameLayout customViewContainer) { disWebChromeClient = new DisWebChromeClient(webView, customViewContainer); progressBar = findViewById(R.id.progressbarLoading); webView = findViewById(R.id.webView_content); webView.setWebChromeClient(disWebChromeClient); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setDomStorageEnabled(true);//solves taiga board \o/ webView.setVerticalScrollBarEnabled(true); webView.getSettings().setAppCacheEnabled(true); webView.getSettings().setBuiltInZoomControls(true); webView.getSettings().setSaveFormData(true); webView.getSettings().setAllowFileAccess(true); webView.getSettings().setLoadWithOverviewMode(true); webView.getSettings().setUseWideViewPort(true); webView.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH); webView.getSettings().setAllowContentAccess(true); webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT); webView.getSettings().setDatabaseEnabled(true); webView.setOnLongClickListener(this); //enable cookies cookieManager = CookieManager.getInstance(); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { CookieSyncManager.createInstance(webView.getContext()); cookieManager.setAcceptCookie(true); cookieManager.setAcceptThirdPartyCookies(webView,false); AppCompatDelegate.setCompatVectorFromResourcesEnabled(true); } CookieSyncManager syncManager = CookieSyncManager.createInstance(webView.getContext()); CookieManager cookieManager = CookieManager.getInstance(); String cookieString = "cookie_name=cookie_value; path=/"; String baseUrl="disroot.org"; cookieManager.setCookie(baseUrl, cookieString); syncManager.sync(); String cookies = cookieManager.getCookie(baseUrl); if (cookies != null) { cookieManager.setCookie(baseUrl, cookies); for (String c : cookies.split(";")) { } } //Make download possible webView.setDownloadListener(new DownloadListener() { @TargetApi(Build.VERSION_CODES.M) public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) { //open dialog for permissions 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(MainActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1); } if (Uri.parse( url ).toString().startsWith( "blob" )){ webView.loadUrl(""); startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(Constants.URL_DisApp_UPLOAD))); } else { 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 ); assert dm != null; dm.enqueue( request ); } } }); //check permissions if (Build.VERSION.SDK_INT >= 19) { webView.setLayerType(View.LAYER_TYPE_HARDWARE, null); } else webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null); webView.setWebChromeClient(new ChromeClient()); webView.loadUrl(loadUrl); 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); } @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { if(url.startsWith("http")&&url.contains("disroot")&&!Uri.parse( url ).toString().startsWith( "blob" )) { view.loadUrl(url); return super.shouldOverrideUrlLoading(view, url); } else { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); view.getContext().startActivity(intent); return true; } } }); } 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 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()]),Constants.REQUEST_ID_MULTIPLE_PERMISSIONS); Log.e(Constants.TAG, "Returned falseeeee-------"); return false; } Log.d(Constants.TAG, "Permission returned trueeeee-------"); return true; } @Override public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) { Log.d(Constants.TAG, "Permission callback called-------"); switch (requestCode) { case Constants.REQUEST_ID_MULTIPLE_PERMISSIONS: { Map 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(Constants.TAG, "camera & Storage permission granted"); Toast.makeText(this, "Permissions granted! Try now.", Toast.LENGTH_SHORT).show(); //chromClt.openChooser(WebView, chooserPathUri, chooserParams); // process the normal flow //else any one or both the permissions are not granted } else { Log.d(Constants.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(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(DialogInterface.OnClickListener okListener) { new AlertDialog.Builder(this) .setMessage("Camera and Storage Permission required for this app") .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 != Constants.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 (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 != Constants.FILECHOOSER_RESULTCODE || mUploadMessage == null) { super.onActivityResult(requestCode, resultCode, data); 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"); } } 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); return File.createTempFile( imageFileName, /* prefix */ ".jpg", /* suffix */ storageDir /* directory */ ); } @SuppressWarnings("ResultOfMethodCallIgnored") public class ChromeClient extends WebChromeClient { public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) { // callback.invoke(String origin, boolean allow, boolean remember); Log.e(Constants.TAG, "onGeolocationPermissionsShowPrompt: " ); callback.invoke(origin, true, false); } // For Android 5.0 public boolean onShowFileChooser(WebView view, ValueCallback filePath, WebChromeClient.FileChooserParams fileChooserParams) { chooserPathUri = filePath; chooserParams = fileChooserParams; if(checkAndRequestPermissions()){ openChooser(chooserPathUri); return true; }else { return false; } } void openChooser(ValueCallback filePath){ // 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(Constants.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, Constants.INPUT_FILE_REQUEST_CODE); } /* openFileChooser for Android 3.0+ */ @SuppressWarnings("ResultOfMethodCallIgnored") @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2) public void openFileChooser(ValueCallback uploadMsg, String acceptType) { mUploadMessage = uploadMsg; // Create AndroidExampleFolder at sdcard File imageStorageDir = new File(Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_PICTURES) , "AndroidExampleFolder"); if (!imageStorageDir.exists()) { // Create AndroidExampleFolder at sdcard boolean mkdirs = 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, Constants.FILECHOOSER_RESULTCODE); } // openFileChooser for Android < 3.0 @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2) public void openFileChooser(ValueCallback uploadMsg) { openFileChooser(uploadMsg, ""); } //openFileChooser for other Android versions @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2) public void openFileChooser(ValueCallback uploadMsg, String acceptType, String capture) { openFileChooser(uploadMsg, acceptType); } } //components @SuppressLint("StaticFieldLeak") class GetList extends AsyncTask { protected Void doInBackground(Void... arg0) { HttpHandler sh = new HttpHandler(); String jsonStringcomponents = sh.makeServiceCall( Constants.components ); Log.e( TAG, "Response from url(Service): " + Constants.components ); if (jsonStringcomponents != null) {//components page try { JSONObject jsonObj = new JSONObject(jsonStringcomponents); // Getting JSON Array node JSONArray data = jsonObj.getJSONArray("systems"); // looping through All data for (int i = 0; i < data.length(); i++) { JSONObject c = data.getJSONObject(i); HashMap serviceDetails = new HashMap<>(); //String id = c.getString("id"); String name = c.getString("name"); //String description = c.getString("description"); // tmp hash map for single service // adding each child node to HashMap key => value //serviceDetails.put("id", id); serviceDetails.put("name", name); if (c.has("description")&&!c.isNull("description")){ String description = c.getString("description"); serviceDetails.put("description", description); } else { serviceDetails.put("description", "No Description"); } //serviceDetails.put("description", description); // adding service to service list componentList.add(serviceDetails); } } catch (final JSONException e) { Log.e(TAG, "Json parsing error: " + e.getMessage()); runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(getApplicationContext(), "Json parsing error: " + e.getMessage(), Toast.LENGTH_LONG) .show(); } }); } }else { Log.e(TAG, "Couldn't get json from server."); runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(getApplicationContext(), "Couldn't get json from server. Is your internet connection ok?", Toast.LENGTH_LONG) .show(); } }); } return null; } @Override protected void onPostExecute(Void result) { super.onPostExecute( result ); // Dismiss the progress dialog for (int a =0; a hashmap= (HashMap) componentList.get(a); String hash = hashmap.get("name"); String description = ""; if (hashmap.get("description")!=null &&!hashmap.isEmpty()){//.has("description")&&!hasmap.isNull("description") description = hashmap.get("description"); } else { description ="No Description"; } switch (hash) { case "Notes": notes = description; getNotes(notes); break; case "Mail Server": email = description; getEmail(email); break; case "Cloud": cloud = description; getCloud(cloud); break; case "Forum": forum = description; getForum(forum); break; case "Pad": etherpad = description; getEtherpad(etherpad); break; case "Bin": bin = description; getBin(bin); break; case "Upload": upload = description; getUpload(upload); break; case "Searx": searx = description; getSearx(searx); break; case "Project board": taiga = description; getTaiga(taiga); break; case "User Password management": user = description; getUser(user); break; case "XMPP Chat server": xmpp = description; getXmpp(xmpp); break; case "Git": git = description; getGit(git); break; case "Cryptpad": cryptpad = description; getCryptpad(cryptpad); break; } } } } private void getEmail(String string){ email = string; } private void getCloud(String string){ cloud = string; } private void getForum(String string){ forum = string; } private void getEtherpad(String string){ etherpad = string; } private void getBin(String string){ bin = string; } private void getUpload(String string){ upload = string; } private void getSearx(String string){ searx = string; } private void getTaiga(String string){ taiga = string; } private void getUser(String string){ user = string; } private void getXmpp(String string){ xmpp = string; } private void getNotes(String string){ notes = string; } private void getGit(String string){ git = string; } private void getCryptpad(String string){ cryptpad = string; } }