List of usage examples for android.webkit WebView addJavascriptInterface
public void addJavascriptInterface(Object object, String name)
From source file:com.phonegap.DroidGap.java
/** * Bind PhoneGap objects to JavaScript.// w w w .j ava2 s.c om * * @param appView */ private void bindBrowser(WebView appView) { this.callbackServer = new CallbackServer(); this.pluginManager = new PluginManager(appView, this); this.mKey = new BrowserKey(appView, this); // This creates the new javascript interfaces for PhoneGap appView.addJavascriptInterface(this.pluginManager, "PluginManager"); appView.addJavascriptInterface(this.mKey, "BackButton"); appView.addJavascriptInterface(this.callbackServer, "CallbackServer"); this.addService("App", "com.phonegap.App"); this.addService("Geolocation", "com.phonegap.GeoBroker"); this.addService("Device", "com.phonegap.Device"); this.addService("Accelerometer", "com.phonegap.AccelListener"); this.addService("Compass", "com.phonegap.CompassListener"); this.addService("Media", "com.phonegap.AudioHandler"); this.addService("Camera", "com.phonegap.CameraLauncher"); this.addService("Contacts", "com.phonegap.ContactManager"); this.addService("Crypto", "com.phonegap.CryptoHandler"); this.addService("File", "com.phonegap.FileUtils"); this.addService("Location", "com.phonegap.GeoBroker"); // Always add Location, even though it is built-in on 2.x devices. Let JavaScript decide which one to use. this.addService("Network Status", "com.phonegap.NetworkManager"); this.addService("Notification", "com.phonegap.Notification"); this.addService("Storage", "com.phonegap.Storage"); this.addService("Temperature", "com.phonegap.TempListener"); this.addService("FileTransfer", "com.phonegap.FileTransfer"); }
From source file:it.angrydroids.epub3reader.BookView.java
@Override public void onActivityCreated(Bundle saved) { super.onActivityCreated(saved); view = (WebView) getView().findViewById(R.id.Viewport); // enable JavaScript for cool things to happen! view.getSettings().setJavaScriptEnabled(true); // ----- SWIPE PAGE view.setOnTouchListener(new OnTouchListener() { @Override/*ww w. j a va 2 s . com*/ public boolean onTouch(View v, MotionEvent event) { if (state == ViewStateEnum.books) swipePage(v, event, 0); WebView view = (WebView) v; return view.onTouchEvent(event); } }); // ----- NOTE & LINK view.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { Message msg = new Message(); msg.setTarget(new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); String url = msg.getData().getString(getString(R.string.url)); if (url != null) navigator.setNote(url, index); } }); view.requestFocusNodeHref(msg); return false; } }); view.setWebViewClient(new WebViewClient() { public boolean shouldOverrideUrlLoading(WebView view, String url) { try { navigator.setBookPage(url, index); } catch (Exception e) { errorMessage(getString(R.string.error_LoadPage)); } return true; } }); view.addJavascriptInterface(new MyJavaScriptInterface(), "INTERFACE"); view.setWebViewClient(new WebViewClient() { @Override public void onPageFinished(WebView view, String url) { view.loadUrl( "javascript:window.INTERFACE.processContent(document.getElementsByTagName('body')[0].innerText);"); } }); PreButton = (Button) getView().findViewById(R.id.btn_prev_chunk); TopButton = (Button) getView().findViewById(R.id.btn_display_from_top); FwdButton = (Button) getView().findViewById(R.id.btn_fwd_chunk); PreButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { BtnPrevChunkOnClickListner(v); } }); TopButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { BtnDisplayTopOnClickListner(v); } }); FwdButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { BtnFwdChunkOnClickListner(v); } }); loadPage(viewedPage); }
From source file:com.juick.android.Utils.java
public static void setupWebView(final WebView wv, String content) { try {/*from w ww . jav a2 s. co m*/ if (skipWeb) return; SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(wv.getContext()); File file = new File(wv.getContext().getCacheDir(), "temp.html"); String PREFIX = "#prefs.checked."; while (true) { int ix = content.indexOf(PREFIX); if (ix == -1) break; int ix2 = content.indexOf("#", ix + 1); if (ix2 == -1) break; String key = content.substring(ix + PREFIX.length(), ix2); boolean def = false; if (key.endsWith("!")) { def = true; key = key.substring(0, key.length() - 1); } boolean checked = sp.getBoolean(key, def); content = content.substring(0, ix) + (checked ? "checked" : "") + content.substring(ix2 + 1); } FileWriter fileWriter = new FileWriter(file); fileWriter.write(content); fileWriter.close(); wv.getSettings().setJavaScriptEnabled(true); // wv.getSettings().setBlockNetworkImage(false); // wv.getSettings().setBlockNetworkLoads(false); wv.getSettings().setLoadsImagesAutomatically(true); Uri uri = Uri.fromFile(file); wv.addJavascriptInterface(new Object() { public void onFormData(String str) { wv.setTag(str); } }, "EXT"); wv.loadUrl(uri.toString()); } catch (IOException e) { // } }
From source file:bolts.WebViewAppLinkResolver.java
@Override public Task<AppLink> getAppLinkFromUrlInBackground(final Uri url) { final Capture<String> content = new Capture<String>(); final Capture<String> contentType = new Capture<String>(); return Task.callInBackground(new Callable<Void>() { @Override//from ww w . java 2 s . c o m public Void call() throws Exception { URL currentURL = new URL(url.toString()); URLConnection connection = null; while (currentURL != null) { // Fetch the content at the given URL. connection = currentURL.openConnection(); if (connection instanceof HttpURLConnection) { // Unfortunately, this doesn't actually follow redirects if they go from http->https, // so we have to do that manually. ((HttpURLConnection) connection).setInstanceFollowRedirects(true); } connection.setRequestProperty(PREFER_HEADER, META_TAG_PREFIX); connection.connect(); if (connection instanceof HttpURLConnection) { HttpURLConnection httpConnection = (HttpURLConnection) connection; if (httpConnection.getResponseCode() >= 300 && httpConnection.getResponseCode() < 400) { currentURL = new URL(httpConnection.getHeaderField("Location")); httpConnection.disconnect(); } else { currentURL = null; } } else { currentURL = null; } } try { content.set(readFromConnection(connection)); contentType.set(connection.getContentType()); } finally { if (connection instanceof HttpURLConnection) { ((HttpURLConnection) connection).disconnect(); } } return null; } }).onSuccessTask(new Continuation<Void, Task<JSONArray>>() { @Override public Task<JSONArray> then(Task<Void> task) throws Exception { // Load the content in a WebView and use JavaScript to extract the meta tags. final TaskCompletionSource<JSONArray> tcs = new TaskCompletionSource<>(); final WebView webView = new WebView(context); webView.getSettings().setJavaScriptEnabled(true); webView.setNetworkAvailable(false); webView.setWebViewClient(new WebViewClient() { private boolean loaded = false; private void runJavaScript(WebView view) { if (!loaded) { // After the first resource has been loaded (which will be the pre-populated data) // run the JavaScript meta tag extraction script loaded = true; view.loadUrl(TAG_EXTRACTION_JAVASCRIPT); } } @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); runJavaScript(view); } @Override public void onLoadResource(WebView view, String url) { super.onLoadResource(view, url); runJavaScript(view); } }); // Inject an object that will receive the JSON for the extracted JavaScript tags webView.addJavascriptInterface(new Object() { @JavascriptInterface public void setValue(String value) { try { tcs.trySetResult(new JSONArray(value)); } catch (JSONException e) { tcs.trySetError(e); } } }, "boltsWebViewAppLinkResolverResult"); String inferredContentType = null; if (contentType.get() != null) { inferredContentType = contentType.get().split(";")[0]; } webView.loadDataWithBaseURL(url.toString(), content.get(), inferredContentType, null, null); return tcs.getTask(); } }, Task.UI_THREAD_EXECUTOR).onSuccess(new Continuation<JSONArray, AppLink>() { @Override public AppLink then(Task<JSONArray> task) throws Exception { Map<String, Object> alData = parseAlData(task.getResult()); AppLink appLink = makeAppLinkFromAlData(alData, url); return appLink; } }); }
From source file:com.mparticle.MParticle.java
/** * Instrument a WebView so that the mParticle Javascript SDK may be used within the given website or web app * * @param webView/* ww w .j a v a2 s. com*/ */ @SuppressLint("AddJavascriptInterface") public void registerWebView(WebView webView) { if (webView != null) { webView.addJavascriptInterface(new MParticleJSInterface(), MParticleJSInterface.INTERFACE_NAME); } }
From source file:org.botlibre.sdk.activity.ChatActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_chat); // Remove flag button if a single bot app. if (MainActivity.launchType == LaunchType.Bot) { //findViewById(R.id.flagButton).setVisibility(View.GONE); }/*w w w .jav a 2 s . c o m*/ //permission required. ActivityCompat.requestPermissions(ChatActivity.this, new String[] { Manifest.permission.RECORD_AUDIO }, 1); //set/Save the current volume from the device. setStreamVolume(); //Music Volume is Enabled. muteMicBeep(false); //For "scream" issue micLastStat = MainActivity.listenInBackground; getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); this.instance = (InstanceConfig) MainActivity.instance; if (this.instance == null) { return; } /*if (MainActivity.showAds) { AdView mAdView = (AdView) findViewById(R.id.adView); AdRequest adRequest = new AdRequest.Builder().build(); mAdView.loadAd(adRequest); } else { AdView mAdView = (AdView) findViewById(R.id.adView); mAdView.setVisibility(View.GONE); }*/ setTitle(this.instance.name); ((TextView) findViewById(R.id.title)).setText(this.instance.name); HttpGetImageAction.fetchImage(this, this.instance.avatar, findViewById(R.id.icon)); ttsInit = false; tts = new TextToSpeech(this, this); if (!MainActivity.handsFreeSpeech) { setMicIcon(false, false); } else if (!MainActivity.listenInBackground) { setMicIcon(false, false); } //Last time will be saved for the MIC. if (MainActivity.listenInBackground && MainActivity.handsFreeSpeech) { microphoneThread(thread); } speech = SpeechRecognizer.createSpeechRecognizer(this); speech.setRecognitionListener(this); //scrollVie added and stuff scrollView = findViewById(R.id.chatList); menuMLayout = (LinearLayout) findViewById(R.id.menuMLayout); chatCLayout = (LinearLayout) findViewById(R.id.chatCLayout); responseLayout = (LinearLayout) findViewById(R.id.responseLayout); chatToolBar = (LinearLayout) findViewById(R.id.chatToolBar); videoView = (VideoView) findViewById(R.id.videoView); resetVideoErrorListener(); videoError = false; imageView = (ImageView) findViewById(R.id.imageView); videoLayout = findViewById(R.id.videoLayout); textView = (EditText) findViewById(R.id.messageText); textView.setOnEditorActionListener(new OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { submitChat(); return false; } }); if (MainActivity.translate) { findViewById(R.id.yandex).setVisibility(View.VISIBLE); } else { findViewById(R.id.yandex).setVisibility(View.GONE); } Spinner emoteSpin = (Spinner) findViewById(R.id.emoteSpin); emoteSpin.setAdapter( new EmoteSpinAdapter(this, R.layout.emote_list, Arrays.asList(EmotionalState.values()))); ListView list = (ListView) findViewById(R.id.chatList); list.setAdapter(new ChatListAdapter(this, R.layout.chat_list, this.messages)); list.setTranscriptMode(ListView.TRANSCRIPT_MODE_ALWAYS_SCROLL); ImageButton button = (ImageButton) findViewById(R.id.speakButton); button.setOnClickListener(new View.OnClickListener() { @TargetApi(23) @Override public void onClick(View v) { if (MainActivity.handsFreeSpeech) { //set the current volume to the setting. setStreamVolume(); //if its ON Or OFF - Switching back and forth MainActivity.listenInBackground = !MainActivity.listenInBackground; //saving the boolean data of MainActivity.listeningInBackground SharedPreferences.Editor cookies = MainActivity.current.getPreferences(Context.MODE_PRIVATE) .edit(); cookies.putBoolean("listenInBackground", MainActivity.listenInBackground); cookies.commit(); if (MainActivity.listenInBackground) { micLastStat = true; try { microphoneThread(thread); } catch (Exception ignore) { } beginListening(); } else { micLastStat = false; microphoneThread(thread); stopListening(); } } else { Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, MainActivity.voice.language); try { startActivityForResult(intent, RESULT_SPEECH); textView.setText(""); } catch (ActivityNotFoundException a) { Toast t = Toast.makeText(getApplicationContext(), "Your device doesn't support Speech to Text", Toast.LENGTH_SHORT); t.show(); } } } }); //adding functionality on clicking the image imageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (stateLayouts == 4) { stateLayouts = 0; } switch (stateLayouts) { case 0: scrollView.setVisibility(View.VISIBLE); chatCLayout.setVisibility(View.VISIBLE); menuMLayout.setVisibility(View.VISIBLE); responseLayout.setVisibility(View.VISIBLE); chatToolBar.setVisibility(View.VISIBLE); break; case 1: scrollView.setVisibility(View.GONE); break; case 2: responseLayout.setVisibility(View.GONE); chatToolBar.setVisibility(View.GONE); break; case 3: menuMLayout.setVisibility(View.GONE); chatCLayout.setVisibility(View.GONE); break; } stateLayouts++; } }); //adding functionality on clicking the image videoLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (stateLayouts == 4) { stateLayouts = 0; } switch (stateLayouts) { case 0: scrollView.setVisibility(View.VISIBLE); chatCLayout.setVisibility(View.VISIBLE); menuMLayout.setVisibility(View.VISIBLE); responseLayout.setVisibility(View.VISIBLE); chatToolBar.setVisibility(View.VISIBLE); break; case 1: scrollView.setVisibility(View.GONE); break; case 2: responseLayout.setVisibility(View.GONE); chatToolBar.setVisibility(View.GONE); break; case 3: menuMLayout.setVisibility(View.GONE); chatCLayout.setVisibility(View.GONE); break; } stateLayouts++; } }); GestureDetector.SimpleOnGestureListener listener = new GestureDetector.SimpleOnGestureListener() { @Override public boolean onDoubleTapEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_UP) { boolean isVideo = !MainActivity.disableVideo && !videoError && response != null && response.isVideo(); View imageView = findViewById(R.id.imageView); View videoLayout = findViewById(R.id.videoLayout); if (imageView.getVisibility() == View.VISIBLE) { imageView.setVisibility(View.GONE); } else if (!isVideo) { imageView.setVisibility(View.VISIBLE); } if (videoLayout.getVisibility() == View.VISIBLE) { videoLayout.setVisibility(View.GONE); } else if (isVideo) { videoLayout.setVisibility(View.VISIBLE); } return true; } return false; } }; final GestureDetector detector = new GestureDetector(this, listener); findViewById(R.id.chatList).setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return detector.onTouchEvent(event); } }); listener = new GestureDetector.SimpleOnGestureListener() { @Override public boolean onDoubleTapEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_UP) { View avatarLayout = findViewById(R.id.avatarLayout); if (avatarLayout.getVisibility() == View.VISIBLE) { avatarLayout.setVisibility(View.GONE); } else { avatarLayout.setVisibility(View.VISIBLE); } return true; } return false; } }; final GestureDetector detector2 = new GestureDetector(this, listener); /*findViewById(R.id.responseText).setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return detector2.onTouchEvent(event); } });*/ WebView responseView = (WebView) findViewById(R.id.responseText); responseView.getSettings().setJavaScriptEnabled(true); responseView.getSettings().setDomStorageEnabled(true); responseView.addJavascriptInterface(new WebAppInterface(this), "Android"); findViewById(R.id.responseImageView).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { View avatarLayout = findViewById(R.id.avatarLayout); if (avatarLayout.getVisibility() == View.VISIBLE) { avatarLayout.setVisibility(View.GONE); } else { avatarLayout.setVisibility(View.VISIBLE); } } }); HttpGetImageAction.fetchImage(this, instance.avatar, this.imageView); HttpGetImageAction.fetchImage(this, instance.avatar, (ImageView) findViewById(R.id.responseImageView)); final ChatConfig config = new ChatConfig(); config.instance = instance.id; config.avatar = this.avatarId; if (MainActivity.translate && MainActivity.voice != null) { config.language = MainActivity.voice.language; } if (MainActivity.disableVideo) { config.avatarFormat = "image"; } else { config.avatarFormat = MainActivity.webm ? "webm" : "mp4"; } config.avatarHD = MainActivity.hd; config.speak = !MainActivity.deviceVoice; // This is required because of a bug in TextToSpeech that prevents onInit being called if an AsynchTask is called... Thread thread1 = new Thread() { public void run() { for (int count = 0; count < 5; count++) { if (ttsInit) { break; } try { Thread.sleep(1000); } catch (Exception exception) { } } HttpAction action = new HttpChatAction(ChatActivity.this, config); action.execute(); } }; thread1.start(); }
From source file:com.ichi2.anki2.Reviewer.java
private WebView createWebView() { WebView webView = new MyWebView(this); webView.setWillNotCacheDrawing(true); webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); if (mZoomEnabled) { webView.getSettings().setBuiltInZoomControls(true); }//from w w w.j a v a2s .co m webView.getSettings().setJavaScriptEnabled(true); webView.setWebChromeClient(new AnkiDroidWebChromeClient()); webView.addJavascriptInterface(new JavaScriptInterface(this), "ankidroid"); if (AnkiDroidApp.SDK_VERSION > 7) { webView.setFocusableInTouchMode(false); } AnkiDroidApp.getCompat().setScrollbarFadingEnabled(webView, mPrefFadeScrollbars); Log.i(AnkiDroidApp.TAG, "Focusable = " + webView.isFocusable() + ", Focusable in touch mode = " + webView.isFocusableInTouchMode()); return webView; }
From source file:com.hichinaschool.flashcards.anki.Reviewer.java
private WebView createWebView() { WebView webView = new MyWebView(this); webView.setWillNotCacheDrawing(true); webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); if (mZoomEnabled) { webView.getSettings().setBuiltInZoomControls(true); }/*from w w w. j a v a2s . com*/ webView.getSettings().setJavaScriptEnabled(true); webView.setWebChromeClient(new AnkiDroidWebChromeClient()); webView.addJavascriptInterface(new JavaScriptInterface(this), "ankidroid"); if (AnkiDroidApp.SDK_VERSION > 7) { webView.setFocusableInTouchMode(false); } AnkiDroidApp.getCompat().setScrollbarFadingEnabled(webView, mPrefFadeScrollbars); // Log.i(AnkiDroidApp.TAG, "Focusable = " + webView.isFocusable() + ", Focusable in touch mode = " + webView.isFocusableInTouchMode()); return webView; }
From source file:ar.com.tristeslostrestigres.diasporanativewebapp.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); progressBar = findViewById(R.id.progressBar); pm = new PrefManager(MainActivity.this); SharedPreferences config = getSharedPreferences("PodSettings", MODE_PRIVATE); podDomain = config.getString("podDomain", null); fab = findViewById(R.id.multiple_actions); fab.setVisibility(View.GONE); Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar);/*from w w w . j a v a 2s . c o m*/ getSupportActionBar().setTitle(null); txtTitle = (TextView) findViewById(R.id.toolbar_title); txtTitle.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (Helpers.isOnline(MainActivity.this)) { txtTitle.setText(R.string.jb_stream); webView.loadUrl("https://" + podDomain + "/stream"); } else { Snackbar.make(v, R.string.no_internet, Snackbar.LENGTH_SHORT).show(); } } }); webView = findViewById(R.id.webView); webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); webView.addJavascriptInterface(new JavaScriptInterface(), "NotificationCounter"); if (savedInstanceState != null) { webView.restoreState(savedInstanceState); } wSettings = webView.getSettings(); wSettings.setJavaScriptEnabled(true); wSettings.setUseWideViewPort(true); wSettings.setLoadWithOverviewMode(true); wSettings.setDomStorageEnabled(true); wSettings.setMinimumFontSize(pm.getMinimumFontSize()); wSettings.setLoadsImagesAutomatically(pm.getLoadImages()); if (android.os.Build.VERSION.SDK_INT >= 21) wSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW); /* * WebViewClient */ webView.setWebViewClient(new WebViewClient() { public boolean shouldOverrideUrlLoading(WebView view, String url) { if (!url.contains(podDomain)) { Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); startActivity(i); return true; } return false; } public void onPageFinished(WebView view, String url) { if (url.contains("/new") || url.contains("/sign_in")) { fab.setVisibility(View.GONE); } else { fab.setVisibility(View.VISIBLE); } } public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { new AlertDialog.Builder(MainActivity.this).setIcon(android.R.drawable.ic_dialog_alert) .setMessage(description).setPositiveButton("CLOSE", null).show(); } }); /* * WebChromeClient */ webView.setWebChromeClient(new WebChromeClient() { public void onProgressChanged(WebView wv, int progress) { progressBar.setProgress(progress); if (progress > 0 && progress <= 60) { Helpers.getNotificationCount(wv); } if (progress > 60) { Helpers.hideTopBar(wv); fab.setVisibility(View.VISIBLE); } if (progress == 100) { fab.collapse(); progressBar.setVisibility(View.GONE); } else { progressBar.setVisibility(View.VISIBLE); } } @Override public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, FileChooserParams fileChooserParams) { if (mFilePathCallback != null) mFilePathCallback.onReceiveValue(null); mFilePathCallback = filePathCallback; Intent 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 Snackbar.make(getWindow().findViewById(R.id.drawer), "Unable to get image", Snackbar.LENGTH_SHORT).show(); } // 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); contentSelectionIntent.setType("image/*"); 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); return true; } public boolean onJsAlert(WebView view, String url, String message, JsResult result) { return super.onJsAlert(view, url, message, result); } }); /* * NavigationView */ NavigationView navigationView = findViewById(R.id.navigation_view); navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) { if (menuItem.isChecked()) menuItem.setChecked(false); else menuItem.setChecked(true); drawerLayout.closeDrawers(); switch (menuItem.getItemId()) { default: Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet, Snackbar.LENGTH_SHORT).show(); return true; case R.id.jb_stream: if (Helpers.isOnline(MainActivity.this)) { txtTitle.setText(R.string.jb_stream); webView.loadUrl("https://" + podDomain + "/stream"); return true; } else { Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet, Snackbar.LENGTH_SHORT).show(); return false; } case R.id.jb_public: setTitle(R.string.jb_public); if (Helpers.isOnline(MainActivity.this)) { webView.loadUrl("https://" + podDomain + "/public"); return true; } else { Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet, Snackbar.LENGTH_SHORT).show(); return false; } case R.id.jb_liked: txtTitle.setText(R.string.jb_liked); if (Helpers.isOnline(MainActivity.this)) { webView.loadUrl("https://" + podDomain + "/liked"); return true; } else { Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet, Snackbar.LENGTH_SHORT).show(); return false; } case R.id.jb_commented: txtTitle.setText(R.string.jb_commented); if (Helpers.isOnline(MainActivity.this)) { webView.loadUrl("https://" + podDomain + "/commented"); return true; } else { Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet, Snackbar.LENGTH_SHORT).show(); return false; } case R.id.jb_contacts: txtTitle.setText(R.string.jb_contacts); if (Helpers.isOnline(MainActivity.this)) { webView.loadUrl("https://" + podDomain + "/contacts"); return true; } else { Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet, Snackbar.LENGTH_SHORT).show(); return false; } case R.id.jb_mentions: txtTitle.setText(R.string.jb_mentions); if (Helpers.isOnline(MainActivity.this)) { webView.loadUrl("https://" + podDomain + "/mentions"); return true; } else { Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet, Snackbar.LENGTH_SHORT).show(); return false; } case R.id.jb_activities: txtTitle.setText(R.string.jb_activities); if (Helpers.isOnline(MainActivity.this)) { webView.loadUrl("https://" + podDomain + "/activity"); return true; } else { Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet, Snackbar.LENGTH_SHORT).show(); return false; } case R.id.jb_followed_tags: txtTitle.setText(R.string.jb_followed_tags); if (Helpers.isOnline(MainActivity.this)) { webView.loadUrl("https://" + podDomain + "/followed_tags"); return true; } else { Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet, Snackbar.LENGTH_SHORT).show(); return false; } case R.id.jb_manage_tags: txtTitle.setText(R.string.jb_manage_tags); if (Helpers.isOnline(MainActivity.this)) { webView.loadUrl("https://" + podDomain + "/tag_followings/manage"); return true; } else { Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet, Snackbar.LENGTH_SHORT).show(); return false; } case R.id.jb_license: txtTitle.setText(R.string.jb_license); new AlertDialog.Builder(MainActivity.this).setTitle(getString(R.string.license_title)) .setMessage(getString(R.string.license_text)) .setPositiveButton(getString(R.string.license_yes), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/mdev88/Diaspora-Native-WebApp")); startActivity(i); dialog.cancel(); } }) .setNegativeButton(getString(R.string.license_no), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }) .show(); return true; case R.id.jb_aspects: txtTitle.setText(R.string.jb_aspects); if (Helpers.isOnline(MainActivity.this)) { webView.loadUrl("https://" + podDomain + "/aspects"); return true; } else { Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet, Snackbar.LENGTH_SHORT).show(); return false; } case R.id.jb_settings: txtTitle.setText(R.string.jb_settings); if (Helpers.isOnline(MainActivity.this)) { webView.loadUrl("https://" + podDomain + "/user/edit"); return true; } else { Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet, Snackbar.LENGTH_SHORT).show(); return false; } case R.id.jb_pod: txtTitle.setText(R.string.jb_pod); if (Helpers.isOnline(MainActivity.this)) { new AlertDialog.Builder(MainActivity.this).setTitle(getString(R.string.confirmation)) .setMessage(getString(R.string.change_pod_warning)) .setPositiveButton(getString(R.string.yes), new DialogInterface.OnClickListener() { @TargetApi(11) public void onClick(DialogInterface dialog, int id) { webView.clearCache(true); dialog.cancel(); Intent i = new Intent(MainActivity.this, PodsActivity.class); startActivity(i); finish(); } }).setNegativeButton(getString(R.string.no), new DialogInterface.OnClickListener() { @TargetApi(11) public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }).show(); return true; } else { Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet, Snackbar.LENGTH_SHORT).show(); return false; } } } }); /* * DrawerLayout */ drawerLayout = findViewById(R.id.drawer); ActionBarDrawerToggle actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.openDrawer, R.string.closeDrawer); drawerLayout.setDrawerListener(actionBarDrawerToggle); //calling sync state is necessary or else your hamburger icon wont show up actionBarDrawerToggle.syncState(); if (savedInstanceState == null) { if (Helpers.isOnline(MainActivity.this)) { webView.loadData("", "text/html", null); webView.loadUrl("https://" + podDomain); } else { Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet, Snackbar.LENGTH_SHORT) .show(); } } }