diff --git a/app/src/main/java/fr/gaulupeau/apps/Poche/ui/ReadArticleActivity.java b/app/src/main/java/fr/gaulupeau/apps/Poche/ui/ReadArticleActivity.java index 2b58c2d69..1931f2b40 100644 --- a/app/src/main/java/fr/gaulupeau/apps/Poche/ui/ReadArticleActivity.java +++ b/app/src/main/java/fr/gaulupeau/apps/Poche/ui/ReadArticleActivity.java @@ -11,8 +11,6 @@ import android.net.Uri; import android.os.Build; import android.os.Bundle; -import androidx.appcompat.app.ActionBar; -import androidx.appcompat.app.AlertDialog; import android.text.TextUtils; import android.util.Log; import android.view.GestureDetector; @@ -20,11 +18,13 @@ import android.view.Menu; import android.view.MenuItem; import android.view.MotionEvent; +import android.view.ScaleGestureDetector; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.view.Window; import android.view.WindowManager; +import android.view.animation.ScaleAnimation; import android.webkit.ConsoleMessage; import android.webkit.HttpAuthHandler; import android.webkit.WebChromeClient; @@ -38,6 +38,9 @@ import android.widget.TextView; import android.widget.Toast; +import androidx.appcompat.app.ActionBar; +import androidx.appcompat.app.AlertDialog; + import com.di72nn.stuff.wallabag.apiwrapper.WallabagService; import org.greenrobot.eventbus.EventBus; @@ -45,11 +48,6 @@ import org.greenrobot.eventbus.ThreadMode; import org.greenrobot.greendao.query.QueryBuilder; -import fr.gaulupeau.apps.InThePoche.BuildConfig; -import fr.gaulupeau.apps.Poche.events.ArticlesChangedEvent; -import fr.gaulupeau.apps.Poche.events.FeedsChangedEvent; -import fr.gaulupeau.apps.Poche.network.ImageCacheUtils; - import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; @@ -60,6 +58,7 @@ import java.util.EnumSet; import java.util.List; +import fr.gaulupeau.apps.InThePoche.BuildConfig; import fr.gaulupeau.apps.InThePoche.R; import fr.gaulupeau.apps.Poche.App; import fr.gaulupeau.apps.Poche.data.DbConnection; @@ -68,6 +67,9 @@ import fr.gaulupeau.apps.Poche.data.dao.ArticleDao; import fr.gaulupeau.apps.Poche.data.dao.DaoSession; import fr.gaulupeau.apps.Poche.data.dao.entities.Article; +import fr.gaulupeau.apps.Poche.events.ArticlesChangedEvent; +import fr.gaulupeau.apps.Poche.events.FeedsChangedEvent; +import fr.gaulupeau.apps.Poche.network.ImageCacheUtils; import fr.gaulupeau.apps.Poche.service.ServiceHelper; import fr.gaulupeau.apps.Poche.tts.TtsFragment; @@ -76,17 +78,13 @@ public class ReadArticleActivity extends BaseActionBarActivity { public static final String EXTRA_ID = "ReadArticleActivity.id"; public static final String EXTRA_LIST_ARCHIVED = "ReadArticleActivity.archived"; public static final String EXTRA_LIST_FAVORITES = "ReadArticleActivity.favorites"; - private static final String TAG = ReadArticleActivity.class.getSimpleName(); - private static final String TAG_TTS_FRAGMENT = "ttsFragment"; - private static final EnumSet CHANGE_SET_ACTIONS = EnumSet.of( ArticlesChangedEvent.ChangeType.FAVORITED, ArticlesChangedEvent.ChangeType.UNFAVORITED, ArticlesChangedEvent.ChangeType.ARCHIVED, ArticlesChangedEvent.ChangeType.UNARCHIVED); - private static final EnumSet CHANGE_SET_CONTENT = EnumSet.of( ArticlesChangedEvent.ChangeType.CONTENT_CHANGED, ArticlesChangedEvent.ChangeType.TITLE_CHANGED, @@ -96,7 +94,6 @@ public class ReadArticleActivity extends BaseActionBarActivity { ArticlesChangedEvent.ChangeType.URL_CHANGED, ArticlesChangedEvent.ChangeType.ESTIMATED_READING_TIME_CHANGED, ArticlesChangedEvent.ChangeType.FETCHED_IMAGES_CHANGED); - private static final EnumSet CHANGE_SET_PREV_NEXT = EnumSet.of( ArticlesChangedEvent.ChangeType.UNSPECIFIED, ArticlesChangedEvent.ChangeType.ADDED, @@ -106,7 +103,9 @@ public class ReadArticleActivity extends BaseActionBarActivity { ArticlesChangedEvent.ChangeType.FAVORITED, ArticlesChangedEvent.ChangeType.UNFAVORITED, ArticlesChangedEvent.ChangeType.CREATED_DATE_CHANGED); - + GestureDetector gestureDetector; + private float mscale = 1f; + private ScaleGestureDetector mScaleDetector; private Boolean contextFavorites; private Boolean contextArchived; @@ -154,37 +153,56 @@ public void onCreate(Bundle savedInstanceState) { settings = App.getInstance().getSettings(); - if(settings.isFullscreenArticleView()) { + if (settings.isFullscreenArticleView()) { requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags( WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN - ); + ); ActionBar actionBar = super.getSupportActionBar(); - if(actionBar != null) actionBar.hide(); + if (actionBar != null) actionBar.hide(); } - if(settings.isKeepScreenOn()) { + if (settings.isKeepScreenOn()) { getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); } + super.onCreate(savedInstanceState); setContentView(R.layout.article); - + gestureDetector = new GestureDetector(this, new GesturerListener()); + mScaleDetector = new ScaleGestureDetector(this, new ScaleGestureDetector.SimpleOnScaleGestureListener() { + public boolean onScale(ScaleGestureDetector detector) { + float scale = 1 - detector.getScaleFactor(); + float prevscale = mscale; + mscale += scale; + if (mscale < 0.1f) + mscale = 0.1f; + if (mscale > 10f) + mscale = 10f; + ScaleAnimation scaleAnimation = new ScaleAnimation(1f / prevscale, 1f / mscale, 1f / prevscale, 1f / mscale, detector.getFocusX(), detector.getFocusY()); + scaleAnimation.setDuration(1000); + //1second after return original size + scrollView.startAnimation(scaleAnimation); + + scaleAnimation.setFillAfter(false); + return true; + } + }); Intent intent = getIntent(); long articleID = intent.getLongExtra(EXTRA_ID, -1); Log.d(TAG, "onCreate() articleId: " + articleID); - if(intent.hasExtra(EXTRA_LIST_FAVORITES)) { + if (intent.hasExtra(EXTRA_LIST_FAVORITES)) { contextFavorites = intent.getBooleanExtra(EXTRA_LIST_FAVORITES, false); } - if(intent.hasExtra(EXTRA_LIST_ARCHIVED)) { + if (intent.hasExtra(EXTRA_LIST_ARCHIVED)) { contextArchived = intent.getBooleanExtra(EXTRA_LIST_ARCHIVED, false); } DaoSession session = DbConnection.getSession(); articleDao = session.getArticleDao(); - if(!loadArticle(articleID)) { + if (!loadArticle(articleID)) { Log.e(TAG, "onCreate: Did not find article with ID: " + articleID); finish(); return; @@ -206,37 +224,44 @@ public void onCreate(Bundle savedInstanceState) { // article is loaded - update menu invalidateOptionsMenu(); - scrollView = (ScrollView)findViewById(R.id.scroll); + scrollView = findViewById(R.id.scroll); scrollViewLastChild = scrollView.getChildAt(scrollView.getChildCount() - 1); - webViewContent = (WebView)findViewById(R.id.webViewContent); - loadingPlaceholder = (TextView)findViewById(R.id.tv_loading_article); - bottomTools = (LinearLayout)findViewById(R.id.bottomTools); + webViewContent = findViewById(R.id.webViewContent); + webViewContent.getSettings().setDisplayZoomControls(true); + webViewContent.getSettings().setSupportZoom(true); + loadingPlaceholder = findViewById(R.id.tv_loading_article); + bottomTools = findViewById(R.id.bottomTools); hrBar = findViewById(R.id.view1); initWebView(); - if(ttsFragment != null) { + if (ttsFragment != null) { // is it ever executed? ttsFragment.onDocumentLoadStart(articleDomain, articleTitle, articleLanguage); } loadArticleToWebView(); - + webViewContent.getSettings().setSupportZoom(true); + webViewContent.getSettings().getTextZoom(); + webViewContent.getSettings().setDisplayZoomControls(true); + webViewContent.getSettings().getDisplayZoomControls(); + webViewContent.getSettings().supportZoom(); initButtons(); - if(settings.isTtsVisible() && ttsFragment == null) { - ttsFragment = (TtsFragment)getSupportFragmentManager() + if (settings.isTtsVisible() && ttsFragment == null) { + ttsFragment = (TtsFragment) getSupportFragmentManager() .findFragmentByTag(TAG_TTS_FRAGMENT); - if(ttsFragment == null) { + if (ttsFragment == null) { toggleTTS(false); } } - if(disableTouch) { + if (disableTouch) { showDisableTouchToast(); } + EventBus.getDefault().register(this); } @@ -245,7 +270,7 @@ public void onResume() { super.onResume(); isResumed = true; - if(onPageFinishedCallPostponedUntilResume) { + if (onPageFinishedCallPostponedUntilResume) { onPageFinishedCallPostponedUntilResume = false; onPageFinished(); @@ -261,7 +286,7 @@ public void onPause() { @Override public void onStop() { - if(loadingFinished && article != null) { + if (loadingFinished && article != null) { cancelPositionRestoration(); OperationsHelper.setArticleProgress(this, article.getArticleId(), getReadingPosition()); @@ -285,7 +310,7 @@ public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.option_article, menu); - if(article != null) { + if (article != null) { boolean unread = article.getArchive() != null && !article.getArchive(); menu.findItem(R.id.menuArticleMarkAsRead).setVisible(unread); menu.findItem(R.id.menuArticleMarkAsUnread).setVisible(!unread); @@ -302,7 +327,7 @@ public boolean onCreateOptionsMenu(Menu menu) { @Override public boolean onOptionsItemSelected(MenuItem item) { - switch(item.getItemId()) { + switch (item.getItemId()) { case R.id.menuArticleMarkAsRead: case R.id.menuArticleMarkAsUnread: markAsReadAndClose(); @@ -352,7 +377,6 @@ public boolean onOptionsItemSelected(MenuItem item) { case R.id.menuTTS: toggleTTS(true); break; - default: return super.onOptionsItemSelected(item); } @@ -360,6 +384,14 @@ public boolean onOptionsItemSelected(MenuItem item) { return true; } + public boolean dispatchTouchEvent(MotionEvent ev) { + super.dispatchTouchEvent(ev); + mScaleDetector.onTouchEvent(ev); + gestureDetector.onTouchEvent(ev); + + return gestureDetector.onTouchEvent(ev); + } + @Override public boolean dispatchKeyEvent(KeyEvent event) { int code = event.getKeyCode(); @@ -371,7 +403,7 @@ public boolean dispatchKeyEvent(KeyEvent event) { } if (triggerAction) { - if(code == disableTouchKeyCode && (disableTouch || disableTouchOptionEnabled)) { + if (code == disableTouchKeyCode && (disableTouch || disableTouchOptionEnabled)) { disableTouch = !disableTouch; settings.setDisableTouchLastState(disableTouch); @@ -416,23 +448,19 @@ public boolean dispatchKeyEvent(KeyEvent event) { return super.dispatchKeyEvent(event); } - @Override - public boolean dispatchTouchEvent(MotionEvent ev) { - return disableTouch || super.dispatchTouchEvent(ev); - } @Subscribe(threadMode = ThreadMode.MAIN) public void onArticlesChangedEvent(ArticlesChangedEvent event) { Log.d(TAG, "onArticlesChangedEvent() started"); boolean updatePrevNext = false; - if(!Collections.disjoint(event.getInvalidateAllChanges(), CHANGE_SET_PREV_NEXT)) { + if (!Collections.disjoint(event.getInvalidateAllChanges(), CHANGE_SET_PREV_NEXT)) { updatePrevNext = true; } else { EnumSet changes; - if(contextArchived != null) { + if (contextArchived != null) { changes = contextArchived ? event.getArchiveFeedChanges() : event.getMainFeedChanges(); - } else if(contextFavorites != null && contextFavorites) { + } else if (contextFavorites != null && contextFavorites) { changes = event.getFavoriteFeedChanges(); } else { changes = EnumSet.copyOf(event.getMainFeedChanges()); @@ -440,19 +468,19 @@ public void onArticlesChangedEvent(ArticlesChangedEvent event) { changes.addAll(event.getFavoriteFeedChanges()); } - if(!Collections.disjoint(changes, CHANGE_SET_PREV_NEXT)) { + if (!Collections.disjoint(changes, CHANGE_SET_PREV_NEXT)) { updatePrevNext = true; } } - if(updatePrevNext) { + if (updatePrevNext) { Log.d(TAG, "onArticleChangedEvent() prev/next buttons changed"); updatePrevNextButtons(); } EnumSet changes = event.getArticleChanges(article); - if(changes == null) return; + if (changes == null) return; Log.d(TAG, "onArticlesChangedEvent() changes: " + changes); @@ -461,7 +489,7 @@ public void onArticlesChangedEvent(ArticlesChangedEvent event) { boolean updateTitle; boolean updateURL; - if(changes.contains(FeedsChangedEvent.ChangeType.UNSPECIFIED)) { + if (changes.contains(FeedsChangedEvent.ChangeType.UNSPECIFIED)) { updateActions = true; updateContent = true; updateTitle = true; @@ -473,7 +501,7 @@ public void onArticlesChangedEvent(ArticlesChangedEvent event) { updateURL = changes.contains(FeedsChangedEvent.ChangeType.URL_CHANGED); } - if(updateActions) { + if (updateActions) { Log.d(TAG, "onArticleChangedEvent() actions changed"); updateMarkAsReadButtonView(); @@ -481,20 +509,20 @@ public void onArticlesChangedEvent(ArticlesChangedEvent event) { invalidateOptionsMenu(); } - if(updateTitle) { + if (updateTitle) { Log.d(TAG, "onArticleChangedEvent() title changed"); articleTitle = article.getTitle(); setTitle(articleTitle); } - if(updateURL) { + if (updateURL) { Log.d(TAG, "onArticleChangedEvent() URL changed"); articleUrl = article.getUrl(); } - if(updateContent) { + if (updateContent) { Log.d(TAG, "onArticleChangedEvent() content changed"); // prepareToRestorePosition(true); @@ -522,10 +550,10 @@ private void initWebView() { @Override public boolean onConsoleMessage(ConsoleMessage cm) { boolean result = false; - if(ttsFragment != null) { + if (ttsFragment != null) { result = ttsFragment.onWebViewConsoleMessage(cm); } - if(!result) { + if (!result) { Log.d("WebView.onCM", String.format("%s @ %d: %s", cm.message(), cm.lineNumber(), cm.sourceId())); } @@ -571,7 +599,7 @@ public void onPageFinished(WebView view, String url) { @Override public boolean shouldOverrideUrlLoading(WebView webView, String url) { // If we try to open current URL, do not propose to save it, directly open browser - if(url.equals(articleUrl)) { + if (url.equals(articleUrl)) { openURL(url); } else { handleUrlClicked(url); @@ -585,13 +613,14 @@ public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm) { Log.d(TAG, "onReceivedHttpAuthRequest() host: " + host + ", realm: " + realm); - if(!TextUtils.isEmpty(host)) { + if (!TextUtils.isEmpty(host)) { String httpAuthHost = settings.getUrl(); try { httpAuthHost = new URL(httpAuthHost).getHost(); - } catch(Exception ignored) {} + } catch (Exception ignored) { + } - if(host.contains(httpAuthHost)) { + if (host.contains(httpAuthHost)) { Log.d(TAG, "onReceivedHttpAuthRequest() host match"); handler.proceed(settings.getHttpAuthUsername(), settings.getHttpAuthPassword()); return; @@ -603,7 +632,7 @@ public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, }); - if(fontSize != 100) setFontSize(webViewContent, fontSize); + if (fontSize != 100) setFontSize(webViewContent, fontSize); GestureDetector.SimpleOnGestureListener gestureListener = new GestureDetector.SimpleOnGestureListener() { @@ -612,33 +641,33 @@ public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float ve // note: e1 - previous event, e2 - current event // velocity* - velocity in pixels per second - if(!swipeArticles) return false; - if(e1 == null || e2 == null) return false; - if(e1.getPointerCount() > 1 || e2.getPointerCount() > 1) return false; + if (!swipeArticles) return false; + if (e1 == null || e2 == null) return false; + if (e1.getPointerCount() > 1 || e2.getPointerCount() > 1) return false; // if(Math.abs(e1.getY() - e2.getY()) > 150) { // Log.d("FLING", "not a horizontal fling (distance)"); // return false; // not a horizontal move (distance) // } - if(Math.abs(velocityX) < 80) { + if (Math.abs(velocityX) < 80) { Log.v("FLING", "too slow"); return false; // too slow } - if(Math.abs(velocityX / velocityY) < 3) { + if (Math.abs(velocityX / velocityY) < 3) { Log.v("FLING", "not a horizontal fling"); return false; // not a horizontal fling } float diff = e1.getX() - e2.getX(); - if(Math.abs(diff) < 80) { // configurable + if (Math.abs(diff) < 80) { // configurable Log.v("FLING", "too small distance"); return false; // too small distance } - if(diff > 0) { // right-to-left: next + if (diff > 0) { // right-to-left: next Log.v("FLING", "right-to-left: next"); openNextArticle(); } else { // left-to-right: prev @@ -650,20 +679,20 @@ public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float ve @Override public boolean onSingleTapConfirmed(MotionEvent e) { - if(!tapToScroll) return false; + if (!tapToScroll) return false; - if(e.getPointerCount() > 1) return false; + if (e.getPointerCount() > 1) return false; int viewHeight = scrollView.getHeight(); float y = e.getY() - scrollView.getScrollY(); - if(y > viewHeight * 0.25 && y < viewHeight * 0.75) { + if (y > viewHeight * 0.25 && y < viewHeight * 0.75) { int viewWidth = scrollView.getWidth(); float x = e.getX(); - if(x < viewWidth * 0.3) { // left part + if (x < viewWidth * 0.3) { // left part scroll(true, screenScrollingPercent, smoothScrolling, false); - } else if(x > viewWidth * 0.7) { // right part + } else if (x > viewWidth * 0.7) { // right part scroll(false, screenScrollingPercent, smoothScrolling, false); } } @@ -691,7 +720,7 @@ private String getHtmlPage() { String cssName; boolean highContrast = false; boolean weightedFont = false; - switch(Themes.getCurrentTheme()) { + switch (Themes.getCurrentTheme()) { case E_INK: weightedFont = true; case LIGHT_CONTRAST: @@ -714,18 +743,18 @@ private String getHtmlPage() { } List additionalClasses = new ArrayList<>(1); - if(highContrast) additionalClasses.add("high-contrast"); - if(weightedFont) additionalClasses.add("weighted-font"); - if(settings.isArticleFontSerif()) additionalClasses.add("serif-font"); - if(settings.isArticleTextAlignmentJustify()) additionalClasses.add("text-align-justify"); + if (highContrast) additionalClasses.add("high-contrast"); + if (weightedFont) additionalClasses.add("weighted-font"); + if (settings.isArticleFontSerif()) additionalClasses.add("serif-font"); + if (settings.isArticleTextAlignmentJustify()) additionalClasses.add("text-align-justify"); additionalClasses.add(settings.getHandlePreformattedTextOption()); String classAttr; - if(!additionalClasses.isEmpty()) { + if (!additionalClasses.isEmpty()) { StringBuilder sb = new StringBuilder(); sb.append(" class=\""); - for(String cl: additionalClasses) { + for (String cl : additionalClasses) { sb.append(cl).append(' '); } sb.append('"'); @@ -738,17 +767,17 @@ private String getHtmlPage() { String htmlBase; try { htmlBase = readRawString(R.raw.webview_htmlbase); - } catch(Exception e) { + } catch (Exception e) { // should not happen throw new RuntimeException("Couldn't load raw resource", e); } String htmlContent = getHtmlContent(); List imgURLs = ImageCacheUtils.findImageUrlsInHtml(htmlContent); - if(imgURLs != null && imgURLs.size() > 0) { + if (imgURLs != null && imgURLs.size() > 0) { String wbgURL = ImageCacheUtils.getWallabagUrl(); - for(String imageURL: imgURLs) { - if(imageURL.startsWith(ImageCacheUtils.WALLABAG_RELATIVE_URL_PATH)) { + for (String imageURL : imgURLs) { + if (imageURL.startsWith(ImageCacheUtils.WALLABAG_RELATIVE_URL_PATH)) { htmlContent = htmlContent.replace(imageURL, wbgURL + imageURL); Log.d(TAG, "getHtmlPage() prefixing wallabag server URL " + wbgURL + " to the image path " + imageURL); } @@ -777,14 +806,14 @@ private String getHtmlContent() { estimatedReadingTime > 0 ? estimatedReadingTime : "< 1"); String previewPicture = ""; - if(settings.isPreviewImageEnabled() && !TextUtils.isEmpty(article.getPreviewPictureURL())) { + if (settings.isPreviewImageEnabled() && !TextUtils.isEmpty(article.getPreviewPictureURL())) { previewPicture = "
"; } htmlContent = estimatedReadingTimeString + previewPicture + htmlContent; - if(BuildConfig.DEBUG) Log.d(TAG, "getHtmlContent() htmlContent: " + htmlContent); + if (BuildConfig.DEBUG) Log.d(TAG, "getHtmlContent() htmlContent: " + htmlContent); - if(settings.isImageCacheEnabled()) { + if (settings.isImageCacheEnabled()) { Log.d(TAG, "getHtmlContent() replacing image links to cached versions in htmlContent"); htmlContent = ImageCacheUtils.replaceImagesInHtmlContent( htmlContent, article.getArticleId().longValue()); @@ -799,12 +828,12 @@ private void initButtons() { } private void updateMarkAsReadButtonView() { - Button buttonMarkRead = (Button)findViewById(R.id.btnMarkRead); - Button buttonMarkUnread = (Button)findViewById(R.id.btnMarkUnread); + Button buttonMarkRead = findViewById(R.id.btnMarkRead); + Button buttonMarkUnread = findViewById(R.id.btnMarkUnread); boolean archived = article.getArchive(); - buttonMarkRead.setVisibility(!archived ? View.VISIBLE: View.GONE); - buttonMarkUnread.setVisibility(archived ? View.VISIBLE: View.GONE); + buttonMarkRead.setVisibility(!archived ? View.VISIBLE : View.GONE); + buttonMarkUnread.setVisibility(archived ? View.VISIBLE : View.GONE); OnClickListener onClickListener = new OnClickListener() { @@ -826,8 +855,8 @@ private void updatePrevNextButtons() { } private void updatePrevNextButtonViews() { - ImageButton buttonGoPrevious = (ImageButton)findViewById(R.id.btnGoPrevious); - ImageButton buttonGoNext = (ImageButton)findViewById(R.id.btnGoNext); + ImageButton buttonGoPrevious = findViewById(R.id.btnGoPrevious); + ImageButton buttonGoNext = findViewById(R.id.btnGoNext); buttonGoPrevious.setVisibility(previousArticleID == null ? View.GONE : View.VISIBLE); buttonGoNext.setVisibility(nextArticleID == null ? View.GONE : View.VISIBLE); @@ -857,22 +886,22 @@ private void loadingFinished() { restoreReadingPosition(); - if(ttsFragment != null) { + if (ttsFragment != null) { ttsFragment.onDocumentLoadFinished(webViewContent, scrollView); } } private void handleUrlClicked(final String url) { Log.d(TAG, "handleUrlClicked() url: " + url); - if(TextUtils.isEmpty(url)) return; + if (TextUtils.isEmpty(url)) return; // TODO: fancy dialog AlertDialog.Builder builder = new AlertDialog.Builder(this); @SuppressLint("InflateParams") // it's ok to inflate with null for AlertDialog - View v = getLayoutInflater().inflate(R.layout.dialog_title_url, null); + View v = getLayoutInflater().inflate(R.layout.dialog_title_url, null); - TextView tv = (TextView)v.findViewById(R.id.tv_dialog_title_url); + TextView tv = v.findViewById(R.id.tv_dialog_title_url); tv.setText(url); builder.setCustomTitle(v); @@ -908,10 +937,10 @@ public void onClick(DialogInterface dialog, int which) { private void openURL(String url) { Log.d(TAG, "openURL() url: " + url); - if(TextUtils.isEmpty(url)) return; + if (TextUtils.isEmpty(url)) return; Uri uri = Uri.parse(url); - if(uri.getScheme() == null) { + if (uri.getScheme() == null) { Log.i(TAG, "openURL() scheme is null, appending default scheme"); uri = Uri.parse("http://" + url); } @@ -920,7 +949,7 @@ private void openURL(String url) { Intent intent = new Intent(Intent.ACTION_VIEW, uri); try { startActivity(intent); - } catch(ActivityNotFoundException e) { + } catch (ActivityNotFoundException e) { Log.w(TAG, "openURL() failed to open URL", e); Toast.makeText(this, R.string.message_couldNotOpenUrl, Toast.LENGTH_SHORT).show(); } @@ -937,21 +966,21 @@ private void toggleFavorite() { } private void shareArticle() { - shareArticle(articleTitle, articleUrl); + shareArticle(articleTitle, articleUrl); } - private void shareArticle(String articleTitle , String articleUrl) { + private void shareArticle(String articleTitle, String articleUrl) { String shareText = articleUrl; - if(!TextUtils.isEmpty(articleTitle)) shareText = articleTitle + " " + shareText; + if (!TextUtils.isEmpty(articleTitle)) shareText = articleTitle + " " + shareText; - if(settings.isAppendWallabagMentionEnabled()) { + if (settings.isAppendWallabagMentionEnabled()) { shareText += getString(R.string.share_text_extra); } Intent send = new Intent(Intent.ACTION_SEND); send.setType("text/plain"); - if(!TextUtils.isEmpty(articleTitle)) send.putExtra(Intent.EXTRA_SUBJECT, articleTitle); + if (!TextUtils.isEmpty(articleTitle)) send.putExtra(Intent.EXTRA_SUBJECT, articleTitle); send.putExtra(Intent.EXTRA_TEXT, shareText); startActivity(Intent.createChooser(send, getString(R.string.share_article_title))); @@ -982,14 +1011,14 @@ private void showChangeTitleDialog() { @SuppressLint("InflateParams") // ok for dialogs final View view = getLayoutInflater().inflate(R.layout.dialog_change_title, null); - ((TextView)view.findViewById(R.id.editText_title)).setText(articleTitle); + ((TextView) view.findViewById(R.id.editText_title)).setText(articleTitle); builder.setView(view); builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - TextView textView = (TextView)view.findViewById(R.id.editText_title); + TextView textView = view.findViewById(R.id.editText_title); changeTitle(textView.getText().toString()); } }); @@ -1014,7 +1043,7 @@ private void openOriginal() { } private void copyURLToClipboard() { - copyURLToClipboard(articleUrl); + copyURLToClipboard(articleUrl); } private void copyURLToClipboard(String url) { @@ -1029,23 +1058,23 @@ private void showDownloadFileDialog() { builder.setTitle(R.string.dialog_title_downloadFileFormat) .setItems(R.array.options_downloadFormat_values, new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - String selectedFormat = getResources() - .getStringArray(R.array.options_downloadFormat_values)[which]; - - WallabagService.ResponseFormat format; - try { - format = WallabagService.ResponseFormat.valueOf(selectedFormat); - } catch(IllegalArgumentException e) { - Log.e(TAG, "showDownloadFileDialog() unknown selected format: " - + selectedFormat); - format = WallabagService.ResponseFormat.PDF; - } - - ServiceHelper.downloadArticleAsFile(getApplicationContext(), - article.getArticleId(), format, null); - } - }); + public void onClick(DialogInterface dialog, int which) { + String selectedFormat = getResources() + .getStringArray(R.array.options_downloadFormat_values)[which]; + + WallabagService.ResponseFormat format; + try { + format = WallabagService.ResponseFormat.valueOf(selectedFormat); + } catch (IllegalArgumentException e) { + Log.e(TAG, "showDownloadFileDialog() unknown selected format: " + + selectedFormat); + format = WallabagService.ResponseFormat.PDF; + } + + ServiceHelper.downloadArticleAsFile(getApplicationContext(), + article.getArticleId(), format, null); + } + }); builder.show(); } @@ -1054,7 +1083,7 @@ private void changeFontSize(boolean increase) { int step = 5; fontSize += step * (increase ? 1 : -1); - if(!increase && fontSize < 5) fontSize = 5; + if (!increase && fontSize < 5) fontSize = 5; setFontSize(webViewContent, fontSize); @@ -1064,21 +1093,21 @@ private void changeFontSize(boolean increase) { } private void openArticle(Long id) { - if(ttsFragment != null) { + if (ttsFragment != null) { ttsFragment.onOpenNewArticle(); } Intent intent = new Intent(this, ReadArticleActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.putExtra(ReadArticleActivity.EXTRA_ID, id); - if(contextFavorites != null) intent.putExtra(EXTRA_LIST_FAVORITES, contextFavorites); - if(contextArchived != null) intent.putExtra(EXTRA_LIST_ARCHIVED, contextArchived); + if (contextFavorites != null) intent.putExtra(EXTRA_LIST_FAVORITES, contextFavorites); + if (contextArchived != null) intent.putExtra(EXTRA_LIST_ARCHIVED, contextArchived); startActivity(intent); } public boolean openPreviousArticle() { - if(previousArticleID != null) { + if (previousArticleID != null) { openArticle(previousArticleID); return true; } @@ -1088,7 +1117,7 @@ public boolean openPreviousArticle() { } public boolean openNextArticle() { - if(nextArticleID != null) { + if (nextArticleID != null) { openArticle(nextArticleID); return true; } @@ -1098,29 +1127,29 @@ public boolean openNextArticle() { } private void scroll(boolean up, float percent, boolean smooth, boolean keyUsed) { - if(scrollView == null) return; + if (scrollView == null) return; int viewHeight = scrollView.getHeight(); int yOffset = scrollView.getScrollY(); int newYOffset = yOffset; - int step = (int)(viewHeight * percent / 100); - if(up) { + int step = (int) (viewHeight * percent / 100); + if (up) { newYOffset -= step; } else { newYOffset += step; } - if(newYOffset != yOffset) { - if(smooth) { + if (newYOffset != yOffset) { + if (smooth) { scrollView.smoothScrollTo(scrollView.getScrollX(), newYOffset); } else { scrollView.scrollTo(scrollView.getScrollX(), newYOffset); } } - if(!up && keyUsed && newYOffset + viewHeight > scrollViewLastChild.getBottom()) { - if(scrolledOverBottom > 1) { + if (!up && keyUsed && newYOffset + viewHeight > scrollViewLastChild.getBottom()) { + if (scrolledOverBottom > 1) { scrolledOverBottom--; Toast.makeText(this, getString(R.string.scrolledOverBottom, scrolledOverBottom), Toast.LENGTH_SHORT).show(); @@ -1144,7 +1173,7 @@ private double getReadingPosition() { totalHeight -= viewHeight; double position = totalHeight >= 0 ? yOffset * 1. / totalHeight : 0; - if(position > 100) position = 100; + if (position > 100) position = 100; Log.d(TAG, "getReadingPosition() position: " + position); @@ -1154,7 +1183,7 @@ private double getReadingPosition() { private void restoreReadingPosition() { Log.d(TAG, "restoreReadingPosition() articleProgress: " + articleProgress); - if(articleProgress != null) { + if (articleProgress != null) { int viewHeight = scrollView.getHeight(); int totalHeight = scrollView.getChildAt(0).getHeight(); @@ -1163,7 +1192,7 @@ private void restoreReadingPosition() { totalHeight -= viewHeight; - int yOffset = totalHeight > 0 ? ((int)Math.round(articleProgress * totalHeight)) : 0; + int yOffset = totalHeight > 0 ? ((int) Math.round(articleProgress * totalHeight)) : 0; Log.v(TAG, "restoreReadingPosition() yOffset: " + yOffset); @@ -1173,18 +1202,18 @@ private void restoreReadingPosition() { public boolean toggleTTS(boolean autoPlay) { boolean result; - if(ttsFragment == null) { + if (ttsFragment == null) { ttsFragment = TtsFragment.newInstance(autoPlay); getSupportFragmentManager() - .beginTransaction() - .add(R.id.viewMain, ttsFragment, TAG_TTS_FRAGMENT) - .commit(); + .beginTransaction() + .add(R.id.viewMain, ttsFragment, TAG_TTS_FRAGMENT) + .commit(); settings.setTtsVisible(true); ttsFragment.onDocumentLoadStart(articleDomain, articleTitle, articleLanguage); - if(loadingFinished) { + if (loadingFinished) { ttsFragment.onDocumentLoadFinished(webViewContent, scrollView); } @@ -1210,7 +1239,7 @@ public boolean toggleTTS(boolean autoPlay) { private boolean loadArticle(long id) { article = getArticle(id); - if(article == null) return false; + if (article == null) return false; articleTitle = article.getTitle(); Log.d(TAG, "loadArticle() articleTitle: " + articleTitle); @@ -1233,17 +1262,17 @@ private Article getArticle(long articleID) { private Long getAdjacentArticle(boolean previous) { QueryBuilder
qb = articleDao.queryBuilder(); - if(previous) qb.where(ArticleDao.Properties.ArticleId.gt(article.getArticleId())); + if (previous) qb.where(ArticleDao.Properties.ArticleId.gt(article.getArticleId())); else qb.where(ArticleDao.Properties.ArticleId.lt(article.getArticleId())); - if(contextFavorites != null) qb.where(ArticleDao.Properties.Favorite.eq(contextFavorites)); - if(contextArchived != null) qb.where(ArticleDao.Properties.Archive.eq(contextArchived)); + if (contextFavorites != null) qb.where(ArticleDao.Properties.Favorite.eq(contextFavorites)); + if (contextArchived != null) qb.where(ArticleDao.Properties.Archive.eq(contextArchived)); - if(previous) qb.orderAsc(ArticleDao.Properties.ArticleId); + if (previous) qb.orderAsc(ArticleDao.Properties.ArticleId); else qb.orderDesc(ArticleDao.Properties.ArticleId); List
l = qb.limit(1).list(); - if(!l.isEmpty()) { + if (!l.isEmpty()) { return l.get(0).getId(); } @@ -1257,16 +1286,17 @@ private String readRawString(int id) throws IOException { StringBuilder sb = new StringBuilder(); String s; - while((s = reader.readLine()) != null) { + while ((s = reader.readLine()) != null) { sb.append(s).append('\n'); } return sb.toString(); } finally { - if(reader != null) { + if (reader != null) { try { reader.close(); - } catch(IOException ignored) {} + } catch (IOException ignored) { + } } } } @@ -1274,10 +1304,10 @@ private String readRawString(int id) throws IOException { private void onPageFinished() { Log.d(TAG, "onPageFinished() started"); - if(!isResumed) { + if (!isResumed) { onPageFinishedCallPostponedUntilResume = true; - if(ttsFragment != null) { + if (ttsFragment != null) { ttsFragment.onDocumentLoadFinished(webViewContent, scrollView); } return; @@ -1290,8 +1320,8 @@ private void onPageFinished() { @Override public void run() { // "< 50" is workaround for https://github.com/wallabag/android-app/issues/178 - if(webViewContent.getHeight() < 50) { - if(++counter > 1000) { + if (webViewContent.getHeight() < 50) { + if (++counter > 1000) { Log.d(TAG, "onPageFinished() exiting by counter" + "; calling loadingFinished() anyway"); loadingFinished(); @@ -1309,7 +1339,7 @@ public void run() { } private void prepareToRestorePosition(boolean savePosition) { - if(savePosition) articleProgress = getReadingPosition(); + if (savePosition) articleProgress = getReadingPosition(); webViewHeightBeforeUpdate = webViewContent.getHeight(); } @@ -1322,8 +1352,8 @@ private void restorePositionAfterUpdate() { @Override public void run() { - if(webViewContent.getHeight() == webViewHeightBeforeUpdate) { - if(++counter > 1000) { + if (webViewContent.getHeight() == webViewHeightBeforeUpdate) { + if (++counter > 1000) { Log.d(TAG, "restorePositionAfterUpdate() giving up"); return; } @@ -1340,15 +1370,15 @@ public void run() { } private void cancelPositionRestoration() { - if(positionRestorationRunnable != null) { + if (positionRestorationRunnable != null) { Log.d(TAG, "cancelPositionRestoration() trying to cancel previous task"); - if(webViewContent != null) webViewContent.removeCallbacks(positionRestorationRunnable); + if (webViewContent != null) webViewContent.removeCallbacks(positionRestorationRunnable); positionRestorationRunnable = null; } } private void setFontSize(WebView view, int size) { - if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { setFontSizeNew(view, size); } else { setFontSizeOld(view, size); @@ -1365,4 +1395,11 @@ private void setFontSizeOld(WebView view, int size) { view.getSettings().setDefaultFontSize(size); } + private class GesturerListener extends GestureDetector.SimpleOnGestureListener { + public boolean onDown(MotionEvent e) { + return true; + } + } + } + diff --git a/app/src/main/res/menu/option_article.xml b/app/src/main/res/menu/option_article.xml index 0dbcd417e..4081b37fa 100644 --- a/app/src/main/res/menu/option_article.xml +++ b/app/src/main/res/menu/option_article.xml @@ -58,4 +58,5 @@ android:id="@+id/menuTTS" android:checkable="true" android:title="@string/menuTTS"/> + diff --git a/app/src/main/res/values-en/strings.xml b/app/src/main/res/values-en/strings.xml deleted file mode 120000 index c2d3f2bde..000000000 --- a/app/src/main/res/values-en/strings.xml +++ /dev/null @@ -1 +0,0 @@ -../values/strings.xml \ No newline at end of file