├── bookmarks.png
├── homepage.png
├── navigation.png
├── app
├── src
│ └── main
│ │ ├── res
│ │ ├── drawable
│ │ │ ├── mouse.png
│ │ │ ├── next.png
│ │ │ ├── right.png
│ │ │ ├── star.png
│ │ │ ├── cancel.png
│ │ │ ├── history.png
│ │ │ ├── previous.png
│ │ │ ├── search.png
│ │ │ ├── squares.png
│ │ │ ├── tab_add.png
│ │ │ ├── tab_rem.png
│ │ │ ├── tab_undo.png
│ │ │ ├── checkmark.png
│ │ │ ├── smartphone.png
│ │ │ ├── tab_undo2.png
│ │ │ ├── ic_launcher.png
│ │ │ ├── menu_settings.png
│ │ │ ├── ic_settings_web.png
│ │ │ ├── google_logo_small.png
│ │ │ ├── notification_edit.png
│ │ │ ├── ic_add_black_24dp.xml
│ │ │ ├── ic_check_black_24dp.xml
│ │ │ ├── ic_keyboard_arrow_left_black_24dp.xml
│ │ │ ├── ic_keyboard_arrow_right_black_24dp.xml
│ │ │ ├── ic_view_carousel_black_24dp.xml
│ │ │ ├── ic_bookmark_black_24dp.xml
│ │ │ ├── ic_clear.xml
│ │ │ ├── ic_delete_black_24dp.xml
│ │ │ ├── circle_bkg_add.xml
│ │ │ ├── circle_bkg_clear.xml
│ │ │ ├── circle_bkg_undo.xml
│ │ │ ├── ic_clear_black_24dp.xml
│ │ │ ├── ic_bookmark_border_black_24dp.xml
│ │ │ ├── search_bar.xml
│ │ │ ├── search_bar_dark.xml
│ │ │ ├── ic_undo_black_24dp.xml
│ │ │ ├── ic_aspect_ratio_black_24dp.xml
│ │ │ ├── ic_search_black_24dp.xml
│ │ │ ├── ic_history_black_24dp.xml
│ │ │ └── ic_settings_black_24dp.xml
│ │ ├── values
│ │ │ ├── attrs.xml
│ │ │ ├── colors.xml
│ │ │ ├── styles.xml
│ │ │ └── strings.xml
│ │ ├── xml
│ │ │ ├── provider_paths.xml
│ │ │ └── preferences.xml
│ │ ├── anim
│ │ │ ├── nothing.xml
│ │ │ ├── zoom_in.xml
│ │ │ ├── enter_from_left.xml
│ │ │ ├── exit_to_left.xml
│ │ │ ├── exit_to_right.xml
│ │ │ ├── enter_from_right.xml
│ │ │ └── zoom_out.xml
│ │ └── layout
│ │ │ ├── row_bookmark.xml
│ │ │ ├── fragment_history.xml
│ │ │ ├── row_bookmarksort.xml
│ │ │ ├── row_bookmarkcard.xml
│ │ │ ├── row_tabmanager.xml
│ │ │ ├── row_thumbnail.xml
│ │ │ ├── activity_bookmark_sort.xml
│ │ │ ├── row_historyitem.xml
│ │ │ ├── activity_bookmark.xml
│ │ │ ├── activity_main.xml
│ │ │ ├── fragment_tabcards.xml
│ │ │ └── fragment_webview.xml
│ │ ├── java
│ │ └── com
│ │ │ └── gueg
│ │ │ └── browser
│ │ │ ├── thumbnails
│ │ │ ├── ItemTouchHelperListener.java
│ │ │ ├── Thumbnail.java
│ │ │ ├── ThumbnailFragmentsAdapter.java
│ │ │ ├── ThumbnailsSaver.java
│ │ │ └── ThumbnailsFragment.java
│ │ │ ├── update
│ │ │ ├── GenericFileProvider.java
│ │ │ └── UpdateTask.java
│ │ │ ├── web
│ │ │ ├── bookmarks
│ │ │ │ ├── BookmarkInterface.java
│ │ │ │ ├── DbBitmapUtility.java
│ │ │ │ ├── Bookmark.java
│ │ │ │ ├── utilities
│ │ │ │ │ ├── VerticalSpaceItemDecoration.java
│ │ │ │ │ └── RecyclerItemClickListener.java
│ │ │ │ ├── BookmarkSortAdapter.java
│ │ │ │ ├── BookmarksCardsAdapter.java
│ │ │ │ ├── BookmarkSortActivity.java
│ │ │ │ └── BookmarkDialog.java
│ │ │ ├── history
│ │ │ │ ├── sql
│ │ │ │ │ ├── SQLReaderContract.java
│ │ │ │ │ ├── SQLReader.java
│ │ │ │ │ └── SQLUtility.java
│ │ │ │ ├── HistoryItem.java
│ │ │ │ └── HistoryAdapter.java
│ │ │ ├── AdBlocker.java
│ │ │ └── WebFragment.java
│ │ │ ├── OnMainActivityCallListener.java
│ │ │ ├── ShortcutHandler.java
│ │ │ └── SettingsActivity.java
│ │ └── AndroidManifest.xml
├── proguard-rules.pro
├── build.gradle
└── app.iml
├── .idea
├── dictionaries
│ └── jackb.xml
├── vcs.xml
├── inspectionProfiles
│ ├── profiles_settings.xml
│ └── Project_Default.xml
└── codeStyles
│ └── Project.xml
└── README.md
/bookmarks.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eviallet/AdBlockingBrowser/HEAD/bookmarks.png
--------------------------------------------------------------------------------
/homepage.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eviallet/AdBlockingBrowser/HEAD/homepage.png
--------------------------------------------------------------------------------
/navigation.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eviallet/AdBlockingBrowser/HEAD/navigation.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/mouse.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eviallet/AdBlockingBrowser/HEAD/app/src/main/res/drawable/mouse.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/next.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eviallet/AdBlockingBrowser/HEAD/app/src/main/res/drawable/next.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/right.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eviallet/AdBlockingBrowser/HEAD/app/src/main/res/drawable/right.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/star.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eviallet/AdBlockingBrowser/HEAD/app/src/main/res/drawable/star.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/cancel.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eviallet/AdBlockingBrowser/HEAD/app/src/main/res/drawable/cancel.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/history.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eviallet/AdBlockingBrowser/HEAD/app/src/main/res/drawable/history.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/previous.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eviallet/AdBlockingBrowser/HEAD/app/src/main/res/drawable/previous.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/search.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eviallet/AdBlockingBrowser/HEAD/app/src/main/res/drawable/search.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/squares.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eviallet/AdBlockingBrowser/HEAD/app/src/main/res/drawable/squares.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/tab_add.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eviallet/AdBlockingBrowser/HEAD/app/src/main/res/drawable/tab_add.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/tab_rem.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eviallet/AdBlockingBrowser/HEAD/app/src/main/res/drawable/tab_rem.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/tab_undo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eviallet/AdBlockingBrowser/HEAD/app/src/main/res/drawable/tab_undo.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/checkmark.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eviallet/AdBlockingBrowser/HEAD/app/src/main/res/drawable/checkmark.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/smartphone.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eviallet/AdBlockingBrowser/HEAD/app/src/main/res/drawable/smartphone.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/tab_undo2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eviallet/AdBlockingBrowser/HEAD/app/src/main/res/drawable/tab_undo2.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eviallet/AdBlockingBrowser/HEAD/app/src/main/res/drawable/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/menu_settings.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eviallet/AdBlockingBrowser/HEAD/app/src/main/res/drawable/menu_settings.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_settings_web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eviallet/AdBlockingBrowser/HEAD/app/src/main/res/drawable/ic_settings_web.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/google_logo_small.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eviallet/AdBlockingBrowser/HEAD/app/src/main/res/drawable/google_logo_small.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/notification_edit.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eviallet/AdBlockingBrowser/HEAD/app/src/main/res/drawable/notification_edit.png
--------------------------------------------------------------------------------
/app/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/dictionaries/jackb.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | favs
5 |
6 |
7 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/provider_paths.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/java/com/gueg/browser/thumbnails/ItemTouchHelperListener.java:
--------------------------------------------------------------------------------
1 | package com.gueg.browser.thumbnails;
2 |
3 | public interface ItemTouchHelperListener {
4 | void onItemMove(int fromPosition, int toPosition);
5 | }
6 |
--------------------------------------------------------------------------------
/app/src/main/java/com/gueg/browser/update/GenericFileProvider.java:
--------------------------------------------------------------------------------
1 | package com.gueg.browser.update;
2 |
3 | import android.support.v4.content.FileProvider;
4 |
5 |
6 | public class GenericFileProvider extends FileProvider {
7 | }
8 |
--------------------------------------------------------------------------------
/app/src/main/java/com/gueg/browser/web/bookmarks/BookmarkInterface.java:
--------------------------------------------------------------------------------
1 | package com.gueg.browser.web.bookmarks;
2 |
3 | public interface BookmarkInterface {
4 | void onBookmarkAdded(Bookmark b);
5 | void onCancel();
6 | void onBookmarkRemoved();
7 | }
8 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_add_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/java/com/gueg/browser/thumbnails/Thumbnail.java:
--------------------------------------------------------------------------------
1 | package com.gueg.browser.thumbnails;
2 |
3 | import android.graphics.Bitmap;
4 |
5 | public class Thumbnail {
6 | public String title;
7 | public String url;
8 | public Bitmap image;
9 |
10 | public Thumbnail(String t, String u, Bitmap b) {
11 | title = t;
12 | url = u;
13 | image = b;
14 | }
15 |
16 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_check_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_keyboard_arrow_left_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_keyboard_arrow_right_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_view_carousel_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_bookmark_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_clear.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_delete_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/circle_bkg_add.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
7 |
10 |
15 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/circle_bkg_clear.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
7 |
10 |
15 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/circle_bkg_undo.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
7 |
10 |
15 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_clear_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_bookmark_border_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/search_bar.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
11 |
--------------------------------------------------------------------------------
/app/src/main/java/com/gueg/browser/OnMainActivityCallListener.java:
--------------------------------------------------------------------------------
1 | package com.gueg.browser;
2 |
3 |
4 | import com.gueg.browser.web.WebFragment;
5 |
6 | public interface OnMainActivityCallListener {
7 | void onRefresh();
8 | void onPageLoaded(String title, String url);
9 | void onSetCurrentFragment(int posFrag, int posLastFrag);
10 | void onNewTab(String url,int pos);
11 | void showManager();
12 | void onTabSwipe(boolean direction);
13 | void addToErrors(WebFragment frag);
14 | }
15 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/search_bar_dark.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_undo_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/anim/nothing.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
13 |
14 |
--------------------------------------------------------------------------------
/app/src/main/res/anim/zoom_in.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
9 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_aspect_ratio_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_search_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_history_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Browser
2 |
3 |
4 |
5 | To be superseded by [GoldfishBrowser](https://github.com/eviallet/GoldfishBrowser)
6 |
7 | # Working
8 | * Global navigation
9 | * Ads are hidden
10 | * Changing header bar color
11 | * Bookmarks & history (databases)
12 | * Smooth animations
13 |
14 | # TODO
15 | * Code cleanup (my first android/java project ever, so many complications/repetitions/errors)
16 | * Translations
17 | * Remove ads containers in page (requires some javascript)
18 | * Previews from webpages sometimes not updated
19 |
--------------------------------------------------------------------------------
/app/src/main/res/anim/enter_from_left.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
8 |
17 |
18 |
--------------------------------------------------------------------------------
/app/src/main/res/anim/exit_to_left.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
8 |
17 |
18 |
--------------------------------------------------------------------------------
/app/src/main/res/anim/exit_to_right.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
8 |
17 |
18 |
--------------------------------------------------------------------------------
/app/src/main/res/anim/enter_from_right.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
8 |
17 |
18 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #616161
4 | #455a64
5 | #2C434E
6 | #2e7d32
7 | #D8D8D8
8 | #C9C0BE
9 | #FFFFFF
10 | #545252
11 | #FFFFFF
12 | #FFFFFF
13 |
14 | #FFB71C1C
15 | #FF8BC34A
16 |
17 |
18 |
--------------------------------------------------------------------------------
/app/src/main/java/com/gueg/browser/web/bookmarks/DbBitmapUtility.java:
--------------------------------------------------------------------------------
1 | package com.gueg.browser.web.bookmarks;
2 |
3 |
4 | import android.graphics.Bitmap;
5 | import android.graphics.BitmapFactory;
6 | import java.io.ByteArrayOutputStream;
7 |
8 | public class DbBitmapUtility {
9 |
10 | // convert from bitmap to byte array
11 | public static byte[] getBytes(Bitmap bitmap) {
12 | ByteArrayOutputStream stream = new ByteArrayOutputStream();
13 | bitmap.compress(Bitmap.CompressFormat.PNG, 0, stream);
14 | return stream.toByteArray();
15 | }
16 |
17 | // convert from byte array to bitmap
18 | public static Bitmap getImage(byte[] image) {
19 | return BitmapFactory.decodeByteArray(image, 0, image.length);
20 | }
21 | }
--------------------------------------------------------------------------------
/app/src/main/res/anim/zoom_out.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
9 |
19 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/java/com/gueg/browser/web/history/sql/SQLReaderContract.java:
--------------------------------------------------------------------------------
1 | package com.gueg.browser.web.history.sql;
2 |
3 |
4 | import android.provider.BaseColumns;
5 |
6 | final class SQLReaderContract {
7 | // To prevent someone from accidentally instantiating the contract class,
8 | // make the constructor private.
9 | private SQLReaderContract() {
10 | }
11 |
12 | /* Inner class that defines the table contents */
13 | class SQLEntry implements BaseColumns {
14 | static final String _ID = "id";
15 | static final String DB_TABLE_NAME = "history";
16 | static final String DB_COLUMN_TITLE = "title";
17 | static final String DB_COLUMN_URL = "url";
18 | static final String DB_COLUMN_DATE = "date";
19 | }
20 |
21 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/row_bookmark.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/java/com/gueg/browser/web/bookmarks/Bookmark.java:
--------------------------------------------------------------------------------
1 | package com.gueg.browser.web.bookmarks;
2 |
3 |
4 | import android.graphics.Bitmap;
5 |
6 | public class Bookmark implements java.io.Serializable{
7 |
8 | public Bookmark(String name, String url, Bitmap pic) {
9 | mName = name;
10 | mUrl = url;
11 | mPic = pic;
12 | }
13 |
14 |
15 | private String mName;
16 | private String mUrl;
17 | private Bitmap mPic;
18 |
19 | public String getName() {
20 | return mName;
21 | }
22 |
23 | public String getUrl() {
24 | return mUrl;
25 | }
26 |
27 | public Bitmap getPic() {
28 | return mPic;
29 | }
30 |
31 | @Override
32 | public String toString() {
33 | return mName;
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_history.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
9 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
10 |
11 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/java/com/gueg/browser/web/bookmarks/utilities/VerticalSpaceItemDecoration.java:
--------------------------------------------------------------------------------
1 | package com.gueg.browser.web.bookmarks.utilities;
2 |
3 | import android.graphics.Rect;
4 | import android.support.v7.widget.RecyclerView;
5 | import android.view.View;
6 |
7 | public class VerticalSpaceItemDecoration extends RecyclerView.ItemDecoration {
8 |
9 | private final int verticalSpaceHeight;
10 | private boolean first = true;
11 |
12 | public VerticalSpaceItemDecoration(int verticalSpaceHeight) {
13 | this.verticalSpaceHeight = verticalSpaceHeight;
14 | }
15 |
16 | @Override
17 | public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
18 | if(first) {
19 | outRect.top = verticalSpaceHeight;
20 | first = false;
21 | }
22 | if (parent.getChildAdapterPosition(view) != parent.getAdapter().getItemCount() - 1) {
23 | outRect.bottom = verticalSpaceHeight;
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/row_bookmarksort.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in C:\Users\jackb\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_settings_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/row_bookmarkcard.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
20 |
21 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/row_tabmanager.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
20 |
21 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/app/src/main/java/com/gueg/browser/web/history/HistoryItem.java:
--------------------------------------------------------------------------------
1 | package com.gueg.browser.web.history;
2 |
3 | import java.text.SimpleDateFormat;
4 | import java.util.Calendar;
5 | import java.util.Locale;
6 | import java.util.concurrent.TimeUnit;
7 |
8 | public class HistoryItem {
9 |
10 | public String title;
11 | public String url;
12 | public Long date;
13 |
14 |
15 | public HistoryItem(String t, String u, Long d) {
16 | title = t;
17 | url = u;
18 | date = d;
19 | }
20 |
21 |
22 |
23 |
24 | String getFormattedDate() {
25 | String prox = getProximity(date);
26 | SimpleDateFormat formatter;
27 | if(prox==null) {
28 | formatter = new SimpleDateFormat("dd/MM'-'HH:mm", Locale.FRANCE);
29 | return formatter.format(date);
30 | }
31 | else {
32 | formatter = new SimpleDateFormat("HH:mm", Locale.FRANCE);
33 | return prox+'-'+formatter.format(date);
34 | }
35 | }
36 |
37 | private String getProximity(long date) {
38 | int p = Math.round(TimeUnit.MILLISECONDS.toDays(date)-TimeUnit.MILLISECONDS.toDays(Calendar.getInstance().getTimeInMillis()));
39 | switch(p) {
40 | case 0 :
41 | return "Auj";
42 | case -1 :
43 | return "Hier";
44 | case -2 :
45 | return "Av-hier";
46 | default :
47 | return null;
48 | }
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/app/src/main/java/com/gueg/browser/web/history/sql/SQLReader.java:
--------------------------------------------------------------------------------
1 | package com.gueg.browser.web.history.sql;
2 |
3 | import android.content.Context;
4 | import android.database.sqlite.SQLiteDatabase;
5 | import android.database.sqlite.SQLiteOpenHelper;
6 |
7 | import com.gueg.browser.web.history.sql.SQLReaderContract.SQLEntry;
8 |
9 |
10 | class SQLReader extends SQLiteOpenHelper {
11 |
12 | private static int DB_VERSION = 1;
13 |
14 | private static final String SQL_CREATE_ENTRIES =
15 | "CREATE TABLE " +
16 | SQLEntry.DB_TABLE_NAME + " (" +
17 | SQLEntry._ID + " INTEGER PRIMARY KEY," +
18 | SQLEntry.DB_COLUMN_TITLE + " TEXT," +
19 | SQLEntry.DB_COLUMN_URL + " TEXT," +
20 | SQLEntry.DB_COLUMN_DATE + " TEXT" +
21 | ")";
22 |
23 | private static final String SQL_DELETE_ENTRIES =
24 | "DROP TABLE IF EXISTS " + SQLEntry.DB_TABLE_NAME;
25 |
26 |
27 | SQLReader(Context context) {
28 | super(context, SQLEntry.DB_TABLE_NAME, null, DB_VERSION);
29 | }
30 | public void onCreate(SQLiteDatabase db) {
31 | db.execSQL(SQL_CREATE_ENTRIES);
32 | }
33 | public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
34 | db.execSQL(SQL_DELETE_ENTRIES);
35 | onCreate(db);
36 | }
37 | public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
38 | onUpgrade(db, oldVersion, newVersion);
39 | }
40 |
41 |
42 |
43 |
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/row_thumbnail.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
17 |
18 |
28 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_bookmark_sort.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
15 |
22 |
23 |
29 |
30 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 |
4 | android {
5 | compileSdkVersion 28
6 | defaultConfig {
7 | applicationId "com.gueg.browser"
8 | minSdkVersion 21
9 | targetSdkVersion 28
10 | renderscriptTargetApi 28
11 | renderscriptSupportModeEnabled true
12 | multiDexEnabled true
13 | versionCode 35
14 | versionName "build35"
15 | }
16 | signingConfigs {
17 | release {
18 | storeFile file("browserkey.keystore")
19 | storePassword "guegueforever"
20 | keyAlias "BrowserKey"
21 | keyPassword "DrHouse4ever"
22 | }
23 | }
24 | buildTypes {
25 | release {
26 | minifyEnabled false
27 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
28 | signingConfig signingConfigs.release
29 | }
30 | }
31 | productFlavors {
32 | }
33 | }
34 |
35 |
36 | dependencies {
37 | implementation fileTree(include: ['*.jar'], dir: 'libs')
38 | implementation fileTree(include: ['*.jar'], dir: 'libs')
39 | def VERSION = '28.0.0'
40 | implementation 'com.android.support:appcompat-v7:'+VERSION
41 | implementation 'com.android.support:cardview-v7:'+VERSION
42 | implementation 'com.android.support:recyclerview-v7:'+VERSION
43 | implementation 'com.android.support:design:'+VERSION
44 | implementation 'fr.tvbarthel.blurdialogfragment:lib:2.2.0'
45 | implementation 'com.github.yukuku:ambilwarna:2.0.1'
46 | implementation 'com.github.ybq:Android-SpinKit:1.1.0'
47 | implementation 'com.azoft.carousellayoutmanager:carousel:1.2.1'
48 | }
49 |
--------------------------------------------------------------------------------
/app/src/main/java/com/gueg/browser/web/history/HistoryAdapter.java:
--------------------------------------------------------------------------------
1 | package com.gueg.browser.web.history;
2 |
3 | import android.support.v7.widget.RecyclerView;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.TextView;
8 | import com.gueg.browser.R;
9 |
10 | import java.util.ArrayList;
11 |
12 |
13 | public class HistoryAdapter extends RecyclerView.Adapter {
14 |
15 | private ArrayList _history;
16 |
17 | static class ViewHolder extends RecyclerView.ViewHolder {
18 | TextView title;
19 | TextView url;
20 | TextView date;
21 |
22 | ViewHolder(View v) {
23 | super(v);
24 | title = v.findViewById(R.id.row_history_title);
25 | url = v.findViewById(R.id.row_history_url);
26 | date = v.findViewById(R.id.row_history_date);
27 | }
28 | }
29 |
30 | public HistoryAdapter(ArrayList items) {
31 | _history = items;
32 | }
33 |
34 | @Override
35 | public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
36 | View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.row_historyitem, parent, false);
37 | return new ViewHolder(v);
38 | }
39 |
40 | @Override
41 | public void onBindViewHolder(final ViewHolder holder, final int position) {
42 | final HistoryItem item = _history.get(position);
43 |
44 | holder.title.setText(item.title);
45 | holder.url.setText(item.url);
46 | holder.date.setText(item.getFormattedDate());
47 |
48 | }
49 |
50 |
51 | // Return the size of your dataset (invoked by the layout manager)
52 | @Override
53 | public int getItemCount() {
54 | return _history.size();
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/row_historyitem.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
10 |
11 |
20 |
30 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/app/src/main/java/com/gueg/browser/thumbnails/ThumbnailFragmentsAdapter.java:
--------------------------------------------------------------------------------
1 | package com.gueg.browser.thumbnails;
2 |
3 | import android.support.v7.widget.RecyclerView;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.ImageView;
8 | import android.widget.TextView;
9 | import com.gueg.browser.R;
10 |
11 | import java.util.ArrayList;
12 |
13 | public class ThumbnailFragmentsAdapter extends RecyclerView.Adapter {
14 |
15 | private ArrayList mList;
16 | private boolean theme;
17 |
18 |
19 | static class ViewHolder extends RecyclerView.ViewHolder {
20 | ImageView img;
21 | TextView txt;
22 | ViewHolder(View v) {
23 | super(v);
24 | img = v.findViewById(R.id.row_thumbnail_w);
25 | txt = v.findViewById(R.id.row_thumbnail_t);
26 | }
27 | }
28 |
29 | ThumbnailFragmentsAdapter(ArrayList list, boolean theme) {
30 | mList = list;
31 | this.theme = theme;
32 | }
33 |
34 | @Override
35 | public ThumbnailFragmentsAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
36 | View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.row_thumbnail, parent, false);
37 | return new ThumbnailFragmentsAdapter.ViewHolder(v);
38 | }
39 |
40 | @Override
41 | public void onBindViewHolder(final ThumbnailFragmentsAdapter.ViewHolder holder, final int position) {
42 | if(mList.get(position)!=null) {
43 | holder.img.setImageBitmap(mList.get(position).image);
44 | holder.txt.setText(mList.get(position).title);
45 | if(theme)
46 | holder.txt.setTextColor(0xffC9C0BE);
47 | }
48 | }
49 |
50 | @Override
51 | public int getItemCount() {
52 | return mList.size();
53 | }
54 |
55 | public void refresh(ArrayList list) {
56 | mList = list;
57 | notifyDataSetChanged();
58 | }
59 |
60 |
61 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/gueg/browser/ShortcutHandler.java:
--------------------------------------------------------------------------------
1 | package com.gueg.browser;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.graphics.Bitmap;
6 | import android.os.Bundle;
7 | import android.support.v4.app.FragmentActivity;
8 |
9 | import com.gueg.browser.web.bookmarks.DbBitmapUtility;
10 |
11 | public class ShortcutHandler extends FragmentActivity {
12 |
13 | private static final int ACTIVITY_SHORTCUT = 0;
14 |
15 | @Override
16 | public void onCreate(Bundle savedInstanceState) {
17 | super.onCreate(savedInstanceState);
18 | Intent intent = new Intent(this,MainActivity.class);
19 | intent.putExtra("SHORTCUT",true);
20 | startActivityForResult(intent,ACTIVITY_SHORTCUT);
21 | }
22 |
23 | @SuppressWarnings("unchecked")
24 | @Override
25 | protected void onActivityResult(int requestCode, int resultCode, Intent data) {
26 |
27 | if (requestCode == ACTIVITY_SHORTCUT) {
28 | if (resultCode == Activity.RESULT_OK) {
29 | Bundle results = data.getExtras();
30 | if(results!=null) {
31 | String title = results.getString("shortcut_title");
32 | String url = results.getString("shortcut_url");
33 | byte[] pic = results.getByteArray("shortcut_pic");
34 |
35 | new DbBitmapUtility();
36 | Bitmap icon = DbBitmapUtility.getImage(pic);
37 |
38 | Intent toLaunchOnShortcut = new Intent(getApplicationContext(), MainActivity.class);
39 | toLaunchOnShortcut.putExtra("LINK", url);
40 |
41 | Intent shortcut = new Intent();
42 | shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, toLaunchOnShortcut);
43 | shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, title);
44 | shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON, icon);
45 | setResult(Activity.RESULT_OK, shortcut);
46 | finishAndRemoveTask();
47 | }
48 | }
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/app/src/main/java/com/gueg/browser/web/bookmarks/BookmarkSortAdapter.java:
--------------------------------------------------------------------------------
1 | package com.gueg.browser.web.bookmarks;
2 |
3 | import android.support.v7.widget.RecyclerView;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.TextView;
8 |
9 | import com.gueg.browser.thumbnails.ItemTouchHelperListener;
10 | import com.gueg.browser.R;
11 |
12 | import java.util.ArrayList;
13 | import java.util.Collections;
14 |
15 | public class BookmarkSortAdapter extends RecyclerView.Adapter implements ItemTouchHelperListener {
16 |
17 | private ArrayList mList;
18 |
19 |
20 | static class ViewHolder extends RecyclerView.ViewHolder {
21 | TextView mTextView;
22 | ViewHolder(View v) {
23 | super(v);
24 | mTextView = (TextView) v.findViewById(R.id.bookmarkSortText);
25 | }
26 | }
27 |
28 |
29 | BookmarkSortAdapter(ArrayList list) {
30 | mList = list;
31 | }
32 |
33 | @Override
34 | public BookmarkSortAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
35 | View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.row_bookmarksort, parent, false);
36 | return new BookmarkSortAdapter.ViewHolder(v);
37 | }
38 |
39 | @Override
40 | public void onBindViewHolder(final BookmarkSortAdapter.ViewHolder holder, final int position) {
41 | holder.mTextView.setText(mList.get(position));
42 | }
43 |
44 | @Override
45 | public int getItemCount() {
46 | return mList.size();
47 | }
48 |
49 | @Override
50 | public void onItemMove(int fromPosition, int toPosition) {
51 | if (fromPosition < toPosition) {
52 | for (int i = fromPosition; i < toPosition; i++) {
53 | Collections.swap(mList, i, i + 1);
54 | }
55 | } else {
56 | for (int i = fromPosition; i > toPosition; i--) {
57 | Collections.swap(mList, i, i - 1);
58 | }
59 | }
60 | notifyItemMoved(fromPosition, toPosition);
61 | }
62 |
63 |
64 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/gueg/browser/web/bookmarks/utilities/RecyclerItemClickListener.java:
--------------------------------------------------------------------------------
1 | package com.gueg.browser.web.bookmarks.utilities;
2 |
3 | import android.content.Context;
4 | import android.support.v7.widget.RecyclerView;
5 | import android.view.GestureDetector;
6 | import android.view.MotionEvent;
7 | import android.view.View;
8 |
9 |
10 | public class RecyclerItemClickListener implements RecyclerView.OnItemTouchListener {
11 | private OnItemClickListener mListener;
12 |
13 | public interface OnItemClickListener {
14 | void onItemClick(View view, int position);
15 |
16 | void onLongItemClick(View view, int position);
17 | }
18 |
19 | private GestureDetector mGestureDetector;
20 |
21 | public RecyclerItemClickListener(Context context, final RecyclerView recyclerView, OnItemClickListener listener) {
22 | mListener = listener;
23 | mGestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
24 | @Override
25 | public boolean onSingleTapUp(MotionEvent e) {
26 | return true;
27 | }
28 |
29 | @Override
30 | public void onLongPress(MotionEvent e) {
31 | View child = recyclerView.findChildViewUnder(e.getX(), e.getY());
32 | if (child != null && mListener != null) {
33 | mListener.onLongItemClick(child, recyclerView.getChildAdapterPosition(child));
34 | }
35 | }
36 | });
37 | }
38 |
39 | @Override public boolean onInterceptTouchEvent(RecyclerView view, MotionEvent e) {
40 | View childView = view.findChildViewUnder(e.getX(), e.getY());
41 | if (childView != null && mListener != null && mGestureDetector.onTouchEvent(e)) {
42 | mListener.onItemClick(childView, view.getChildAdapterPosition(childView));
43 | return true;
44 | }
45 | return false;
46 | }
47 |
48 | @Override public void onTouchEvent(RecyclerView view, MotionEvent motionEvent) { }
49 |
50 | @Override
51 | public void onRequestDisallowInterceptTouchEvent (boolean disallowIntercept){}
52 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/gueg/browser/web/bookmarks/BookmarksCardsAdapter.java:
--------------------------------------------------------------------------------
1 | package com.gueg.browser.web.bookmarks;
2 |
3 |
4 | import android.support.v7.widget.RecyclerView;
5 | import android.view.LayoutInflater;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 | import android.widget.ImageView;
9 | import android.widget.TextView;
10 |
11 | import com.gueg.browser.R;
12 |
13 | import java.util.ArrayList;
14 |
15 | public class BookmarksCardsAdapter extends RecyclerView.Adapter{
16 |
17 | private ArrayList mList;
18 |
19 |
20 | static class ViewHolder extends RecyclerView.ViewHolder {
21 | ImageView mImageView;
22 | TextView mTextView;
23 | ViewHolder(View v) {
24 | super(v);
25 | mImageView = (ImageView) v.findViewById(R.id.bookmarkPic);
26 | mTextView = (TextView) v.findViewById(R.id.bookmarkText);
27 | }
28 | }
29 |
30 | // Provide a suitable constructor (depends on the kind of dataset)
31 | public BookmarksCardsAdapter(ArrayList list) {
32 | mList = list;
33 | }
34 |
35 | // Create new views (invoked by the layout manager)
36 | @Override
37 | public BookmarksCardsAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
38 | View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.row_bookmarkcard, parent, false);
39 | return new BookmarksCardsAdapter.ViewHolder(v);
40 | }
41 |
42 | // Replace the contents of a view (invoked by the layout manager)
43 | @Override
44 | public void onBindViewHolder(final BookmarksCardsAdapter.ViewHolder holder, final int position) {
45 | // - get element from your dataset at this position
46 | // - replace the contents of the view with that element
47 | holder.mTextView.setText(mList.get(position).getName());
48 | holder.mImageView.setImageBitmap(mList.get(position).getPic());
49 | }
50 |
51 | // Return the size of your dataset (invoked by the layout manager)
52 | @Override
53 | public int getItemCount() {
54 | return mList.size();
55 | }
56 |
57 |
58 |
59 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_bookmark.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
15 |
16 |
22 |
23 |
24 |
31 |
32 |
38 |
39 |
46 |
52 |
53 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Browser
3 | http://www.google.fr
4 |
5 | https://drive.google.com/open?id=0B0IkweJhZVSfd1lIVFZQalZabkk
6 |
7 |
8 |
9 | // BookmarkActivity
10 | Valider
11 | Annuler
12 | Titre
13 | URL
14 | Image
15 |
16 | // Settings
17 | Page d\'accueil
18 | Couleur du chargement
19 | Couleur de la barre d\'adresse
20 | Couleur du texte de la barre d\'adresse
21 | Trier les favoris
22 | Partager
23 | Vérifier les mises à jour
24 | Bloquer les pubs
25 | Bloquer facebook, twitter etc
26 | Cacher le clavier au démarrage
27 | Garder les onglets ouverts en mémoire
28 | Masquer automatiquement la barre
29 |
30 |
31 | Options générales
32 | Couleurs
33 |
34 |
35 | http://www.google.fr
36 |
37 |
38 |
39 | // SharedPref
40 | com.gueg.browser.BOOKMARKS_LIST
41 | com.gueg.browser.BOOKMARKS_LIST_SIZE
42 | com.gueg.browser.BOOKMARKS_LIST_ITEM_
43 |
44 | com.gueg.browser.URLS_LIST
45 | com.gueg.browser.URLS_LIST_SIZE
46 | com.gueg.browser.URLS_LIST_ITEM_
47 |
48 |
49 | - "Désactivé"
50 | - "Par session"
51 | - "Permanent"
52 |
53 |
54 |
55 |
56 |
57 |
58 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
17 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
45 |
48 |
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/app/src/main/java/com/gueg/browser/web/AdBlocker.java:
--------------------------------------------------------------------------------
1 | package com.gueg.browser.web;
2 |
3 |
4 | import android.content.Context;
5 | import android.os.AsyncTask;
6 | import android.text.TextUtils;
7 | import android.util.Log;
8 | import android.webkit.WebResourceResponse;
9 | import java.io.BufferedReader;
10 | import java.io.ByteArrayInputStream;
11 | import java.io.IOException;
12 | import java.io.InputStream;
13 | import java.io.InputStreamReader;
14 | import java.util.HashSet;
15 | import java.util.Set;
16 |
17 | public class AdBlocker {
18 | private static final String AD_HOSTS_FILE = "ad_hosts.txt";
19 | private static final Set AD_HOSTS = new HashSet<>();
20 |
21 | public static void init(final Context context) {
22 | new AsyncTask() {
23 | @Override
24 | protected Void doInBackground(Void... params) {
25 | try {
26 | loadFromAssets(context);
27 | } catch (IOException e) {
28 | // noop
29 | }
30 | return null;
31 | }
32 | }.execute();
33 | }
34 |
35 | public static void initTrackers() {
36 | AD_HOSTS.add("facebook.com");
37 | AD_HOSTS.add("twitter.com");
38 | AD_HOSTS.add("platform.twitter.com");
39 | AD_HOSTS.add("syndication.twitter.com");
40 | }
41 |
42 | private static void loadFromAssets(Context context) throws IOException {
43 | BufferedReader reader;
44 |
45 | InputStream file = context.getAssets().open(AD_HOSTS_FILE);
46 | reader = new BufferedReader(new InputStreamReader(file));
47 | String line;
48 | while((line = reader.readLine()) != null) {
49 | AD_HOSTS.add(line);
50 | }
51 | }
52 | static boolean isAd(String url) {
53 | return !TextUtils.isEmpty(url) && isAdHost(url);
54 | }
55 |
56 | private static boolean isAdHost(String url) {
57 | boolean domainFound = false;
58 | int i=0;
59 | StringBuilder domain = new StringBuilder();
60 | char c;
61 | while(!domainFound&&i
2 |
5 |
6 |
10 |
14 |
18 |
22 |
26 |
30 |
34 |
41 |
49 |
50 |
51 |
55 |
59 |
63 |
67 |
68 |
--------------------------------------------------------------------------------
/app/src/main/java/com/gueg/browser/thumbnails/ThumbnailsSaver.java:
--------------------------------------------------------------------------------
1 | package com.gueg.browser.thumbnails;
2 |
3 | import android.content.Context;
4 | import android.content.ContextWrapper;
5 | import android.graphics.Bitmap;
6 | import android.graphics.BitmapFactory;
7 | import java.io.File;
8 | import java.io.FileInputStream;
9 | import java.io.FileOutputStream;
10 | import java.util.ArrayList;
11 | import java.util.HashMap;
12 | import java.util.Set;
13 |
14 | public class ThumbnailsSaver {
15 |
16 | public static void saveToInternalSorage(Context context, ArrayList thumbnails){
17 | ContextWrapper cw = new ContextWrapper(context);
18 | File directory = cw.getDir("thumbnails", Context.MODE_PRIVATE);
19 | if (!directory.exists())
20 | //noinspection ResultOfMethodCallIgnored
21 | directory.mkdir();
22 |
23 | for(Thumbnail t : thumbnails) {
24 | if(t!=null) {
25 | File imgPath = new File(directory, t.title + ".png");
26 | File urlPath = new File(directory, t.title + ".url");
27 | FileOutputStream fos;
28 | try {
29 | fos = new FileOutputStream(imgPath);
30 | t.image.compress(Bitmap.CompressFormat.PNG, 30, fos);
31 | fos.close();
32 |
33 | fos = new FileOutputStream(urlPath);
34 | fos.write(t.url.getBytes("UTF-8"));
35 | fos.close();
36 | } catch (Exception e) {
37 | e.printStackTrace();
38 | }
39 | }
40 | }
41 | }
42 |
43 | public static ArrayList loadFromInternalSorage(Context context){
44 | ContextWrapper cw = new ContextWrapper(context);
45 | File directory = cw.getDir("thumbnails", Context.MODE_PRIVATE);
46 | File[] files = directory.listFiles();
47 |
48 | ArrayList thumbnails = new ArrayList<>();
49 |
50 | HashMap urls = new HashMap<>();
51 | HashMap imgs = new HashMap<>();
52 |
53 | for(File f : files) {
54 | if(f.getAbsolutePath().endsWith(".png")) {
55 | imgs.put(f.getName().replace(".png",""),BitmapFactory.decodeFile(f.getAbsolutePath()));
56 | } else if(f.getAbsolutePath().endsWith(".url")) {
57 | FileInputStream fis;
58 | try {
59 | fis = new FileInputStream(f.getAbsolutePath());
60 |
61 | StringBuilder fileContent = new StringBuilder("");
62 | byte[] buffer = new byte[1024];
63 | int n;
64 | while ((n = fis.read(buffer)) != -1)
65 | fileContent.append(new String(buffer, 0, n));
66 |
67 | urls.put(f.getName().replace(".url",""),fileContent.toString());
68 |
69 | fis.close();
70 | } catch (Exception e) {
71 | e.printStackTrace();
72 | }
73 | }
74 | }
75 |
76 | Set titles = urls.keySet();
77 | for(String title : titles) {
78 | if(imgs.containsKey(title)) {
79 | thumbnails.add(new Thumbnail(title, urls.get(title), imgs.get(title)));
80 | }
81 | else {
82 | thumbnails.add(new Thumbnail(title, urls.get(title), null));
83 | }
84 | }
85 |
86 | return thumbnails;
87 | }
88 |
89 | public static void clearStorage(Context context) {
90 | ContextWrapper cw = new ContextWrapper(context);
91 | File directory = cw.getDir("thumbnails", Context.MODE_PRIVATE);
92 | File[] files = directory.listFiles();
93 |
94 | for(File f : files) {
95 | //noinspection ResultOfMethodCallIgnored
96 | f.delete();
97 | }
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/app/src/main/java/com/gueg/browser/web/bookmarks/BookmarkSortActivity.java:
--------------------------------------------------------------------------------
1 | package com.gueg.browser.web.bookmarks;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.support.v7.widget.LinearLayoutManager;
7 | import android.support.v7.widget.RecyclerView;
8 | import android.support.v7.widget.helper.ItemTouchHelper;
9 | import android.view.View;
10 | import android.widget.Button;
11 |
12 | import com.gueg.browser.R;
13 | import com.gueg.browser.web.bookmarks.utilities.VerticalSpaceItemDecoration;
14 |
15 | import java.util.ArrayList;
16 |
17 | @SuppressWarnings("unchecked")
18 | public class BookmarkSortActivity extends Activity {
19 | private static final int VERTICAL_ITEM_SPACE = 15;
20 | @Override
21 | protected void onCreate(Bundle savedInstanceState) {
22 | super.onCreate(savedInstanceState);
23 | setContentView(R.layout.activity_bookmark_sort);
24 |
25 | Intent intent = getIntent();
26 | Bundle extras = intent.getExtras();
27 | final ArrayList bookmarksList = (ArrayList) extras.getSerializable("BOOKMARKS_LIST");
28 |
29 |
30 |
31 | RecyclerView recyclerView = findViewById(R.id.recycler_view_bookmarks_sort);
32 | recyclerView.setHasFixedSize(true);
33 | RecyclerView.LayoutManager mLayoutManager;
34 | mLayoutManager = new LinearLayoutManager(getApplicationContext());
35 | recyclerView.setLayoutManager(mLayoutManager);
36 | recyclerView.addItemDecoration(new VerticalSpaceItemDecoration(VERTICAL_ITEM_SPACE));
37 | final BookmarkSortAdapter mAdapter = new BookmarkSortAdapter(bookmarksList);
38 | recyclerView.setAdapter(mAdapter);
39 |
40 |
41 | ItemTouchHelper.SimpleCallback simpleCallback = new ItemTouchHelper.SimpleCallback(0,ItemTouchHelper.UP| ItemTouchHelper.DOWN) {
42 |
43 | @Override
44 | public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
45 | mAdapter.onItemMove(viewHolder.getAdapterPosition(), target.getAdapterPosition());
46 | return true;
47 | }
48 | @Override
49 | public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
50 | int dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN;
51 | int swipeFlags = ItemTouchHelper.START | ItemTouchHelper.END;
52 | return makeMovementFlags(dragFlags, swipeFlags);
53 | }
54 | @Override
55 | public boolean isLongPressDragEnabled() {
56 | return true;
57 | }
58 |
59 | @Override
60 | public void onSwiped(final RecyclerView.ViewHolder viewHolder, int direction) {
61 |
62 | }
63 | };
64 |
65 | ItemTouchHelper itemTouchHelper = new ItemTouchHelper(simpleCallback);
66 | itemTouchHelper.attachToRecyclerView(recyclerView);
67 |
68 |
69 |
70 | Button btnValider = (Button) findViewById(R.id.btn_bookmarksortActivity_valider);
71 | if (btnValider != null) {
72 | btnValider.setOnClickListener(new View.OnClickListener() {
73 | @Override
74 | public void onClick(View view) {
75 | Intent results = new Intent();
76 | Bundle extras = new Bundle();
77 | extras.putSerializable("BOOKMARKS_LIST",bookmarksList);
78 | results.putExtras(extras);
79 | setResult(Activity.RESULT_OK,results);
80 | finish();
81 | }
82 | });
83 | }
84 | Button btnAnnuler = (Button) findViewById(R.id.btn_bookmarksortActivity_annuler);
85 | assert btnAnnuler != null;
86 | btnAnnuler.setOnClickListener(new View.OnClickListener() {
87 | @Override
88 | public void onClick(View view) {
89 | Intent results = new Intent();
90 | setResult(Activity.RESULT_CANCELED,results);
91 | finish();
92 | }
93 | });
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/app/src/main/java/com/gueg/browser/web/bookmarks/BookmarkDialog.java:
--------------------------------------------------------------------------------
1 | package com.gueg.browser.web.bookmarks;
2 |
3 | import android.content.DialogInterface;
4 | import android.os.Bundle;
5 | import android.support.v4.app.DialogFragment;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.widget.Button;
10 | import android.widget.EditText;
11 | import android.widget.Toast;
12 | import com.gueg.browser.R;
13 |
14 | import fr.tvbarthel.lib.blurdialogfragment.BlurDialogEngine;
15 |
16 |
17 | public class BookmarkDialog extends DialogFragment {
18 |
19 | private BlurDialogEngine mBlurEngine;
20 |
21 | private BookmarkInterface _listener;
22 | View rootView;
23 |
24 | EditText title;
25 | EditText url;
26 |
27 | Bookmark b;
28 | boolean modif;
29 |
30 | @Override
31 | public void onCreate(Bundle savedInstanceState) {
32 | super.onCreate(savedInstanceState);
33 | setStyle(DialogFragment.STYLE_NO_TITLE, android.R.style.Theme_Material_Light_Dialog_Alert);
34 | }
35 | @Override
36 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
37 | rootView = inflater.inflate(R.layout.activity_bookmark, container, false);
38 | super.onCreateView(inflater, container, savedInstanceState);
39 |
40 | mBlurEngine = new BlurDialogEngine(getActivity());
41 | mBlurEngine.setBlurRadius(8);
42 | mBlurEngine.setDownScaleFactor(8f);
43 | mBlurEngine.debug(false);
44 | mBlurEngine.setBlurActionBar(true);
45 | mBlurEngine.setUseRenderScript(true);
46 |
47 |
48 | title = rootView.findViewById(R.id.editTextTitle);
49 | title.setText(b.getName());
50 | url = rootView.findViewById(R.id.editTextUrl);
51 | url.setText(b.getUrl());
52 |
53 | if(modif) {
54 | Button remove = rootView.findViewById(R.id.btn_bookmarkActivity_remove);
55 | remove.setVisibility(View.VISIBLE);
56 | remove.setOnClickListener(new View.OnClickListener() {
57 | @Override
58 | public void onClick(View v) {
59 | _listener.onBookmarkRemoved();
60 | dismiss();
61 | }
62 | });
63 | }
64 |
65 | rootView.findViewById(R.id.btn_bookmarkActivity_annuler).setOnClickListener(new View.OnClickListener() {
66 | @Override
67 | public void onClick(View v) {
68 | dismiss();
69 | }
70 | });
71 | rootView.findViewById(R.id.btn_bookmarkActivity_valider).setOnClickListener(new View.OnClickListener() {
72 | @Override
73 | public void onClick(View v) {
74 | if(!title.getText().toString().isEmpty()&&!url.getText().toString().isEmpty()) {
75 | _listener.onBookmarkAdded(new Bookmark(title.getText().toString(),url.getText().toString(),b.getPic()));
76 | dismiss();
77 | } else
78 | Toast.makeText(getActivity(), "Entrer un titre et une url", Toast.LENGTH_SHORT).show();
79 | }
80 | });
81 |
82 | return rootView;
83 | }
84 |
85 | public void setListener(BookmarkInterface listener) {
86 | _listener = listener;
87 | }
88 |
89 | public void setBookmark(Bookmark b, boolean modif) {
90 | this.b = b;
91 | this.modif = modif;
92 | }
93 |
94 | @Override
95 | public void onResume() {
96 | super.onResume();
97 | mBlurEngine.onResume(getRetainInstance());
98 | }
99 |
100 | @Override
101 | public void onDismiss(DialogInterface dialog) {
102 | super.onDismiss(dialog);
103 | _listener.onCancel();
104 | mBlurEngine.onDismiss();
105 | }
106 |
107 | @Override
108 | public void onDestroy() {
109 | super.onDestroy();
110 | mBlurEngine.onDetach();
111 | }
112 |
113 | @Override
114 | public void onDestroyView() {
115 | if (getDialog() != null) {
116 | getDialog().setDismissMessage(null);
117 | }
118 | super.onDestroyView();
119 | }
120 | }
121 |
--------------------------------------------------------------------------------
/app/src/main/java/com/gueg/browser/web/history/sql/SQLUtility.java:
--------------------------------------------------------------------------------
1 | package com.gueg.browser.web.history.sql;
2 |
3 |
4 | import android.content.ContentValues;
5 | import android.content.Context;
6 | import android.database.Cursor;
7 | import android.database.sqlite.SQLiteDatabase;
8 | import android.widget.Toast;
9 |
10 | import com.gueg.browser.web.history.HistoryItem;
11 | import com.gueg.browser.web.history.sql.SQLReaderContract.SQLEntry;
12 |
13 | import java.util.ArrayList;
14 |
15 | public class SQLUtility {
16 |
17 | private ArrayList savedHistory = new ArrayList<>();
18 | private Context context;
19 |
20 | private int lastPos = 0;
21 |
22 | private SQLReader helper;
23 | private static String[] projection = {
24 | SQLEntry._ID,
25 | SQLEntry.DB_COLUMN_TITLE,
26 | SQLEntry.DB_COLUMN_URL,
27 | SQLEntry.DB_COLUMN_DATE
28 | };
29 |
30 | public SQLUtility(Context context) {
31 | helper = new SQLReader(context);
32 | this.context = context;
33 | }
34 |
35 | public ArrayList read20HistoryItems() {
36 |
37 | SQLiteDatabase db = helper.getReadableDatabase();
38 |
39 | Cursor cursor = db.query(
40 | SQLEntry.DB_TABLE_NAME, // The table to query
41 | projection, // The columns to return
42 | null, // The columns for the WHERE clause
43 | null, // The values for the WHERE clause
44 | null, // don't group the rows
45 | null, // don't filter by row groups
46 | SQLEntry.DB_COLUMN_DATE +" DESC" // The sort order
47 | );
48 |
49 | ArrayList items = new ArrayList<>();
50 | while(cursor.moveToNext()&&cursor.getPosition() items) {
68 | for (HistoryItem item : items) {
69 | boolean found = false;
70 | for (HistoryItem i : savedHistory) {
71 | if (i.title.equals(item.title) && i.url.equals(item.url) && i.date.equals(item.date))
72 | found = true;
73 | }
74 | if (!found)
75 | write(item);
76 | }
77 | }
78 |
79 | private void write(HistoryItem item) {
80 | SQLiteDatabase db = helper.getWritableDatabase();
81 |
82 | ContentValues values = new ContentValues();
83 | values.put(SQLEntry.DB_COLUMN_TITLE, item.title);
84 | values.put(SQLEntry.DB_COLUMN_URL, item.url);
85 | values.put(SQLEntry.DB_COLUMN_DATE, item.date.toString());
86 |
87 | db.insert(SQLEntry.DB_TABLE_NAME, null, values);
88 |
89 | savedHistory.add(item);
90 | }
91 |
92 |
93 | public void removeItem(int pos) {
94 | SQLiteDatabase db = helper.getWritableDatabase();
95 | // Define 'where' part of query.
96 | String selection = SQLEntry.DB_COLUMN_TITLE + " LIKE ? AND " + SQLEntry.DB_COLUMN_URL + " LIKE ? AND " + SQLEntry.DB_COLUMN_DATE + " LIKE ?" ;
97 | // Specify arguments in placeholder order.
98 | if(pos
2 |
8 |
9 |
14 |
18 |
19 |
20 |
28 |
33 |
41 |
49 |
57 |
65 |
66 |
72 |
80 |
90 |
91 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_tabcards.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
11 |
12 |
21 |
24 |
35 |
48 |
49 |
50 |
51 |
60 |
64 |
73 |
77 |
86 |
90 |
99 |
103 |
104 |
114 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_webview.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
11 |
18 |
19 |
30 |
40 |
41 |
42 |
53 |
66 |
67 |
68 |
69 |
77 |
84 |
93 |
103 |
112 |
119 |
120 |
121 |
122 |
127 |
128 |
129 |
--------------------------------------------------------------------------------
/app/src/main/java/com/gueg/browser/SettingsActivity.java:
--------------------------------------------------------------------------------
1 | package com.gueg.browser;
2 |
3 | import android.content.Intent;
4 | import android.content.SharedPreferences;
5 | import android.content.pm.PackageInfo;
6 | import android.content.pm.PackageManager;
7 | import android.os.Bundle;
8 | import android.preference.Preference;
9 | import android.preference.PreferenceActivity;
10 | import android.preference.PreferenceManager;
11 | import android.support.v4.app.ActivityCompat;
12 | import android.support.v4.content.ContextCompat;
13 |
14 | import com.gueg.browser.update.UpdateTask;
15 |
16 | import static android.Manifest.permission.WRITE_EXTERNAL_STORAGE;
17 |
18 |
19 | @SuppressWarnings("deprecation")
20 | public class SettingsActivity extends PreferenceActivity {
21 |
22 | @Override
23 | public void onCreate(Bundle savedInstanceState) {
24 | super.onCreate(savedInstanceState);
25 | addPreferencesFromResource(R.xml.preferences);
26 |
27 | final Preference btn_share = findPreference("prefShare");
28 | btn_share.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
29 | @Override
30 | public boolean onPreferenceClick(Preference preference) {
31 | Intent i=new Intent(android.content.Intent.ACTION_SEND);
32 | i.setType("text/plain");
33 | i.putExtra(android.content.Intent.EXTRA_SUBJECT,"Partager");
34 | i.putExtra(android.content.Intent.EXTRA_TEXT, getResources().getString(R.string.share_link));
35 | startActivity(Intent.createChooser(i,"Partager avec"));
36 | return true;
37 | }
38 | });
39 |
40 | final Preference history = findPreference("prefHistory");
41 | history.setSummary(PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("prefHistory","Désactivé"));
42 | if(PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("prefHistory","Désactivé").equals("0"))
43 | history.setSummary("Désactivé");
44 | history.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
45 | @Override
46 | public boolean onPreferenceChange(Preference preference, Object newValue) {
47 | SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
48 | prefs.edit().putString("prefHistory",(String)newValue).apply();
49 | history.setSummary((String)newValue);
50 | return true;
51 | }
52 | });
53 |
54 | Preference homepage = findPreference("prefHomepage");
55 | SharedPreferences mainPref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
56 | homepage.setSummary(mainPref.getString("prefHomepage","http://www.google.fr"));
57 |
58 | /*
59 | final Preference btn_update = findPreference("prefUpdate");
60 |
61 | try {
62 | PackageInfo pInfo = this.getPackageManager().getPackageInfo(getPackageName(), 0);
63 | String version = pInfo.versionName;
64 | btn_update.setSummary(version);
65 | } catch (PackageManager.NameNotFoundException e) {
66 | e.printStackTrace();
67 | }
68 | btn_update.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
69 | @Override
70 | public boolean onPreferenceClick(Preference preference) {
71 | if(ContextCompat.checkSelfPermission(getApplicationContext(),WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
72 | UpdateTask update = new UpdateTask(SettingsActivity.this, UpdateTask.SHOW_TOAST);
73 | update.execute(UpdateTask.UPDATE_LINK);
74 | } else {
75 | if (!ActivityCompat.shouldShowRequestPermissionRationale(SettingsActivity.this, WRITE_EXTERNAL_STORAGE))
76 | ActivityCompat.requestPermissions(SettingsActivity.this, new String[]{WRITE_EXTERNAL_STORAGE}, 0);
77 | }
78 | return true;
79 | }
80 | });
81 | */
82 | Preference colorMain = findPreference("prefColorMain");
83 | Preference colorBarText = findPreference("prefColorBarText");
84 | Preference colorBar = findPreference("prefColorBar");
85 |
86 |
87 | colorMain.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
88 | @Override
89 | public boolean onPreferenceChange(Preference preference, Object newValue) {
90 | SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
91 | prefs.edit().putInt("prefColorMain",(int)newValue).apply();
92 | return true;
93 | }
94 | });
95 |
96 | colorBarText.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
97 | @Override
98 | public boolean onPreferenceChange(Preference preference, Object newValue) {
99 | SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
100 | prefs.edit().putBoolean("prefColorBarText",(boolean)newValue).apply();
101 | return true;
102 | }
103 | });
104 |
105 | colorBar.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
106 | @Override
107 | public boolean onPreferenceChange(Preference preference, Object newValue) {
108 | SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
109 | prefs.edit().putInt("prefColorBar",(int)newValue).apply();
110 | return true;
111 | }
112 | });
113 |
114 |
115 | }
116 |
117 | }
118 |
--------------------------------------------------------------------------------
/app/src/main/java/com/gueg/browser/update/UpdateTask.java:
--------------------------------------------------------------------------------
1 | package com.gueg.browser.update;
2 |
3 | import android.app.Activity;
4 | import android.app.ProgressDialog;
5 | import android.content.Intent;
6 | import android.content.pm.PackageInfo;
7 | import android.content.pm.PackageManager;
8 | import android.net.Uri;
9 | import android.os.AsyncTask;
10 | import android.os.Build;
11 | import android.os.Environment;
12 | import android.support.v4.BuildConfig;
13 | import android.support.v4.content.FileProvider;
14 | import android.widget.Toast;
15 | import com.gueg.browser.R;
16 | import java.io.BufferedInputStream;
17 | import java.io.BufferedReader;
18 | import java.io.File;
19 | import java.io.FileOutputStream;
20 | import java.io.FileReader;
21 | import java.io.IOException;
22 | import java.io.InputStream;
23 | import java.io.OutputStream;
24 | import java.net.URL;
25 | import java.net.URLConnection;
26 |
27 | @SuppressWarnings("ResultOfMethodCallIgnored")
28 | public class UpdateTask extends AsyncTask {
29 |
30 | public static final String UPDATE_LINK = "https://dl.dropboxusercontent.com/s/jbwi5eqjcvbod8g/update.txt?dl=0";
31 | public static final int SHOW_TOAST = 0;
32 | public static final int NO_TOAST = 1;
33 | private Activity context;
34 | private ProgressDialog dialog;
35 |
36 | private int toast;
37 |
38 | public UpdateTask(Activity c, int toast) {
39 | context = c;
40 | dialog = new ProgressDialog(c, R.style.ProgressDialogTheme);
41 | dialog.setTitle("Téléchargement de la mise à jour...");
42 | dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
43 | dialog.setCancelable(false);
44 | this.toast = toast;
45 | }
46 |
47 | protected String doInBackground(String... sUrl) {
48 | // PARSING MANIFEST
49 | String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/update.txt";
50 | try {
51 | URL url = new URL(UPDATE_LINK);
52 | URLConnection connection = url.openConnection();
53 | connection.connect();
54 |
55 | int fileLength = connection.getContentLength();
56 |
57 | // download the file
58 | InputStream input = new BufferedInputStream(url.openStream());
59 | OutputStream output = new FileOutputStream(path);
60 |
61 | byte data[] = new byte[1024];
62 | long total = 0;
63 | int count;
64 | while ((count = input.read(data)) != -1) {
65 | total += count;
66 | publishProgress((int) (total * 100 / fileLength));
67 | output.write(data, 0, count);
68 | }
69 |
70 | output.flush();
71 | output.close();
72 | input.close();
73 | } catch (Exception e) {
74 | e.printStackTrace();
75 | }
76 | StringBuilder manifest = new StringBuilder();
77 | try {
78 | BufferedReader br = new BufferedReader(new FileReader(path));
79 | String line;
80 |
81 | while ((line = br.readLine()) != null) {
82 | manifest.append(line);
83 | manifest.append("~");
84 | }
85 | br.close();
86 | }
87 | catch (IOException e) {
88 | //You'll need to add proper error handling here
89 | }
90 |
91 | // READING MANIFEST
92 | int latestVersion = Integer.decode(manifest.substring(0, manifest.indexOf("~")));
93 | manifest.substring(manifest.indexOf("~"));
94 | int currentVersion = 999;
95 | try {
96 | PackageInfo pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
97 | currentVersion = pInfo.versionCode;
98 | } catch (PackageManager.NameNotFoundException e) {
99 | e.printStackTrace();
100 | }
101 |
102 | new File(path).delete();
103 |
104 | // DOWNLOADING LATEST VERSION
105 | if (currentVersion < latestVersion) {
106 | context.runOnUiThread(new Runnable() {
107 | @Override
108 | public void run() {
109 | dialog.show();
110 | }
111 | });
112 | String path2 = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/browser.apk";
113 | try {
114 | URL url = new URL(manifest.substring(manifest.indexOf("~")).replace("~",""));
115 | URLConnection connection = url.openConnection();
116 | connection.connect();
117 |
118 | int fileLength = connection.getContentLength();
119 |
120 | // download the file
121 | InputStream input = new BufferedInputStream(url.openStream());
122 | OutputStream output = new FileOutputStream(path2);
123 |
124 | byte data[] = new byte[1024];
125 | long total = 0;
126 | int count;
127 | while ((count = input.read(data)) != -1) {
128 | total += count;
129 | publishProgress((int) (total * 100 / fileLength));
130 | output.write(data, 0, count);
131 | }
132 |
133 | output.flush();
134 | output.close();
135 | input.close();
136 | } catch (Exception e) {
137 | e.printStackTrace();
138 | }
139 | return path2;
140 | }
141 | Toast.makeText(context, "Aucune mise à jour disponible.", Toast.LENGTH_SHORT).show();
142 | return null;
143 | }
144 |
145 | // begin the installation by opening the resulting file
146 | @Override
147 | protected void onPostExecute(String path) {
148 | context.runOnUiThread(new Runnable() {
149 | @Override
150 | public void run() {
151 | dialog.dismiss();
152 | }
153 | });
154 | if(path!=null) {
155 | /*
156 | Intent i = new Intent();
157 | i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
158 | i.setAction(Intent.ACTION_VIEW);
159 | i.setDataAndType(Uri.fromFile(new File(path)), "application/vnd.android.package-archive");
160 | i.setData(FileProvider.getUriForFile(context, context.getApplicationContext().getPackageName() + ".com.gueg.browser.provider", new File(path)));
161 | i.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
162 | context.startActivity(i);
163 | */
164 | File toInstall = new File(path);
165 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
166 | Uri apkUri = FileProvider.getUriForFile(context, context.getApplicationContext().getPackageName() + ".com.gueg.browser.provider", toInstall);
167 | Intent intent = new Intent(Intent.ACTION_INSTALL_PACKAGE);
168 | intent.setData(apkUri);
169 | intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
170 | context.startActivity(intent);
171 | } else {
172 | Uri apkUri = Uri.fromFile(toInstall);
173 | Intent intent = new Intent(Intent.ACTION_VIEW);
174 | intent.setDataAndType(apkUri, "application/vnd.android.package-archive");
175 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
176 | context.startActivity(intent);
177 | }
178 | } else {
179 | if(toast==SHOW_TOAST)
180 | Toast.makeText(context, "Aucune mise à jour disponible.", Toast.LENGTH_SHORT).show();
181 | }
182 | }
183 |
184 |
185 | @Override
186 | protected void onProgressUpdate(Integer... values) {
187 | dialog.setProgress(values[0]);
188 | super.onProgressUpdate(values);
189 | }
190 | }
191 |
--------------------------------------------------------------------------------
/app/src/main/java/com/gueg/browser/thumbnails/ThumbnailsFragment.java:
--------------------------------------------------------------------------------
1 | package com.gueg.browser.thumbnails;
2 |
3 | import android.content.Context;
4 | import android.os.Bundle;
5 | import android.preference.PreferenceManager;
6 | import android.support.annotation.NonNull;
7 | import android.support.v4.app.Fragment;
8 | import android.support.v7.widget.LinearLayoutManager;
9 | import android.support.v7.widget.RecyclerView;
10 | import android.support.v7.widget.helper.ItemTouchHelper;
11 | import android.view.KeyEvent;
12 | import android.view.LayoutInflater;
13 | import android.view.View;
14 | import android.view.ViewGroup;
15 | import android.view.inputmethod.EditorInfo;
16 | import android.view.inputmethod.InputMethodManager;
17 | import android.widget.EditText;
18 | import android.widget.ImageButton;
19 | import android.widget.TextView;
20 |
21 | import com.azoft.carousellayoutmanager.CarouselLayoutManager;
22 | import com.azoft.carousellayoutmanager.CarouselZoomPostLayoutListener;
23 | import com.azoft.carousellayoutmanager.CenterScrollListener;
24 | import com.gueg.browser.R;
25 | import com.gueg.browser.MainActivity;
26 | import com.gueg.browser.web.bookmarks.utilities.RecyclerItemClickListener;
27 | import com.gueg.browser.web.bookmarks.utilities.VerticalSpaceItemDecoration;
28 |
29 | import java.util.ArrayList;
30 |
31 | public class ThumbnailsFragment extends Fragment implements View.OnFocusChangeListener {
32 |
33 | RecyclerView mRecyclerView;
34 | ThumbnailFragmentsAdapter mAdapter;
35 |
36 | private static final int VERTICAL_ITEM_SPACE = 25;
37 |
38 | View rootView;
39 | ArrayList list;
40 | EditText search;
41 |
42 |
43 |
44 | @Override
45 | public void onCreate(Bundle savedInstanceState) {
46 | super.onCreate(savedInstanceState);
47 | }
48 |
49 | @SuppressWarnings("deprecation")
50 | @Override
51 | public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
52 | rootView = inflater.inflate(R.layout.fragment_tabcards,container,false);
53 |
54 | list = ((MainActivity)getActivity()).getThumbnails();
55 | mRecyclerView = rootView.findViewById(R.id.recycler_view);
56 | ImageButton tab_add = rootView.findViewById(R.id.btn_tab_add);
57 | ImageButton tab_undo = rootView.findViewById(R.id.btn_tab_undo);
58 | search = rootView.findViewById(R.id.fragment_default_search);
59 |
60 | boolean theme = PreferenceManager.getDefaultSharedPreferences(getActivity()).getBoolean("prefDarkTheme",false);
61 | if(theme) {
62 | rootView.setBackgroundColor(0xff313335);
63 | //search.setBackgroundDrawable(getActivity().getDrawable(R.drawable.search_bar_dark));
64 | }
65 |
66 | search.setImeOptions(EditorInfo.IME_ACTION_DONE);
67 |
68 | search.setOnEditorActionListener(new TextView.OnEditorActionListener() {
69 | @Override
70 | public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
71 | if (actionId == EditorInfo.IME_ACTION_DONE) {
72 | if(search.getText().toString().toLowerCase().contains("http://")||search.getText().toString().toLowerCase().contains("https://")) {
73 | ((MainActivity)getActivity()).addTab(search.getText().toString());
74 | search.setText("");
75 | }
76 | else if(search.getText().toString().toLowerCase().contains("www")) {
77 | String display = "http://"+search.getText().toString();
78 | search.setText(display);
79 | ((MainActivity)getActivity()).addTab(display);
80 | search.setText("");
81 | }
82 | else if(search.getText().toString().toLowerCase().contains(".fr")||search.getText().toString().toLowerCase().contains(".com")) {
83 | String display = "http://www."+search.getText().toString();
84 | search.setText(display);
85 | ((MainActivity)getActivity()).addTab(display);
86 | search.setText("");
87 | }
88 | else {
89 | ((MainActivity) getActivity()).addTab("https://www.google.fr/search?q=" + search.getText().toString());
90 | search.setText("");
91 | }
92 |
93 | View view = getActivity().getCurrentFocus();
94 | if (view != null) {
95 | InputMethodManager imm = (InputMethodManager)getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
96 | imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
97 | }
98 | }
99 | return false;
100 | }
101 | });
102 |
103 | ImageButton im = rootView.findViewById(R.id.fragment_default_button);
104 | im.setOnClickListener(new View.OnClickListener() {
105 | @Override
106 | public void onClick(View v) {
107 | if(!search.getText().toString().isEmpty())
108 | {
109 | if(search.getText().toString().toLowerCase().contains("http://")||search.getText().toString().toLowerCase().contains("https://")) {
110 | ((MainActivity)getActivity()).addTab(search.getText().toString());
111 | search.setText("");
112 | }
113 | else if(search.getText().toString().toLowerCase().contains("www")) {
114 | String display = "http://"+search.getText().toString();
115 | search.setText(display);
116 | ((MainActivity)getActivity()).addTab(display);
117 | search.setText("");
118 | }
119 | else if(search.getText().toString().toLowerCase().contains(".fr")||search.getText().toString().toLowerCase().contains(".com")) {
120 | String display = "http://www."+search.getText().toString();
121 | search.setText(display);
122 | ((MainActivity)getActivity()).addTab(display);
123 | search.setText("");
124 | }
125 | else {
126 | ((MainActivity) getActivity()).addTab("https://www.google.fr/search?q=" + search.getText().toString());
127 | search.setText("");
128 | }
129 | View view = getActivity().getCurrentFocus();
130 | if (view != null) {
131 | InputMethodManager imm = (InputMethodManager)getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
132 | imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
133 | }
134 |
135 | }
136 | }
137 | });
138 |
139 |
140 | ItemTouchHelper.SimpleCallback simpleCallback = new ItemTouchHelper.SimpleCallback(0,ItemTouchHelper.RIGHT) {
141 | @Override
142 | public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
143 | return false;
144 | }
145 |
146 | @Override
147 | public void onSwiped(final RecyclerView.ViewHolder viewHolder, int direction) {
148 | final int position = viewHolder.getAdapterPosition(); //get position which is swiped
149 |
150 | if (direction == ItemTouchHelper.RIGHT) {
151 | ((MainActivity)getActivity()).closeTab(position);
152 | mRecyclerView.removeViewAt(position);
153 | mAdapter.notifyItemRemoved(position);
154 | mAdapter.notifyItemRangeChanged(position, list.size());
155 | mAdapter.notifyDataSetChanged();
156 | ((MainActivity)getActivity()).refreshTabs();
157 | }
158 |
159 | }
160 | };
161 | ItemTouchHelper itemTouchHelper = new ItemTouchHelper(simpleCallback);
162 | itemTouchHelper.attachToRecyclerView(mRecyclerView);
163 |
164 | //final CarouselLayoutManager layoutManager = new CarouselLayoutManager(CarouselLayoutManager.VERTICAL, false);
165 | //layoutManager.setPostLayoutListener(new CarouselZoomPostLayoutListener());
166 |
167 | mAdapter = new ThumbnailFragmentsAdapter(list,theme);
168 | mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
169 | mRecyclerView.setHasFixedSize(true);
170 | mRecyclerView.addItemDecoration(new VerticalSpaceItemDecoration(VERTICAL_ITEM_SPACE));
171 | mRecyclerView.setAdapter(mAdapter);
172 | mRecyclerView.addOnScrollListener(new CenterScrollListener());
173 | mRecyclerView.setOverScrollMode(View.OVER_SCROLL_NEVER);
174 |
175 |
176 | mRecyclerView.addOnItemTouchListener(
177 | new RecyclerItemClickListener(getActivity(), mRecyclerView ,new RecyclerItemClickListener.OnItemClickListener() {
178 | @Override public void onItemClick(View view, int position) {
179 | ((MainActivity)getActivity()).setCurrentFragment(position);
180 | ((MainActivity)getActivity()).refreshTabs();
181 | }
182 |
183 | @Override public void onLongItemClick(View view, int position) {
184 | //((MainActivity)getActivity()).newBookmark(position);
185 | }
186 | })
187 |
188 | );
189 |
190 | tab_undo.setOnClickListener(new View.OnClickListener() {
191 | @Override
192 | public void onClick(View v) {
193 | ((MainActivity)getActivity()).undoClose();
194 | ((MainActivity)getActivity()).setCurrentFragment(-1);
195 | list = ((MainActivity)getActivity()).getThumbnails();
196 | }
197 | });
198 |
199 |
200 |
201 |
202 | tab_add.setOnClickListener(new View.OnClickListener() {
203 | @Override
204 | public void onClick(View v) {
205 | ((MainActivity)getActivity()).addTab();
206 | ((MainActivity)getActivity()).refreshCurrentUrls();
207 | }
208 | });
209 |
210 | ImageButton tab_rem = rootView.findViewById(R.id.btn_tab_rem);
211 | tab_rem.setOnClickListener(new View.OnClickListener() {
212 | @Override
213 | public void onClick(View v) {
214 | ((MainActivity)getActivity()).closeAllTabs();
215 | list = ((MainActivity)getActivity()).getThumbnails();
216 | ((MainActivity)getActivity()).refreshCurrentUrls();
217 | }
218 | });
219 |
220 |
221 | return rootView;
222 | }
223 |
224 | public void moveToPosition(int pos) {
225 | mRecyclerView.scrollToPosition(pos);
226 | }
227 |
228 |
229 | @Override
230 | public void onFocusChange(View v, boolean hasFocus) {
231 | if(hasFocus) {
232 | if(!search.hasFocus())
233 | search.requestFocus();
234 | } else {
235 | InputMethodManager imm = (InputMethodManager)getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
236 | imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
237 | }
238 | }
239 |
240 | @Override
241 | public void onPause() {
242 | super.onPause();
243 | }
244 |
245 | public ThumbnailFragmentsAdapter getAdapter() {
246 | return mAdapter;
247 | }
248 | }
249 |
--------------------------------------------------------------------------------
/app/app.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | generateDebugSources
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
--------------------------------------------------------------------------------
/app/src/main/java/com/gueg/browser/web/WebFragment.java:
--------------------------------------------------------------------------------
1 | package com.gueg.browser.web;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.annotation.TargetApi;
5 | import android.app.DownloadManager;
6 | import android.content.ClipData;
7 | import android.content.ClipboardManager;
8 | import android.content.Context;
9 | import android.content.DialogInterface;
10 | import android.content.Intent;
11 | import android.content.SharedPreferences;
12 | import android.content.pm.PackageManager;
13 | import android.content.res.ColorStateList;
14 | import android.graphics.Bitmap;
15 | import android.graphics.Canvas;
16 | import android.net.Uri;
17 | import android.net.http.SslError;
18 | import android.os.Build;
19 | import android.os.Bundle;
20 | import android.os.Environment;
21 | import android.os.Handler;
22 | import android.preference.PreferenceManager;
23 | import android.support.annotation.NonNull;
24 | import android.support.v4.app.Fragment;
25 | import android.support.v7.app.AlertDialog;
26 | import android.support.v7.widget.ListPopupWindow;
27 | import android.text.InputType;
28 | import android.view.ContextMenu;
29 | import android.view.KeyEvent;
30 | import android.view.LayoutInflater;
31 | import android.view.Menu;
32 | import android.view.MenuItem;
33 | import android.view.MotionEvent;
34 | import android.view.View;
35 | import android.view.ViewGroup;
36 | import android.view.inputmethod.EditorInfo;
37 | import android.webkit.CookieManager;
38 | import android.webkit.DownloadListener;
39 | import android.webkit.JsPromptResult;
40 | import android.webkit.JsResult;
41 | import android.webkit.SslErrorHandler;
42 | import android.webkit.URLUtil;
43 | import android.webkit.WebChromeClient;
44 | import android.webkit.WebResourceRequest;
45 | import android.webkit.WebResourceResponse;
46 | import android.webkit.WebSettings;
47 | import android.webkit.WebView;
48 | import android.webkit.WebViewClient;
49 | import android.widget.AdapterView;
50 | import android.widget.ArrayAdapter;
51 | import android.widget.EditText;
52 | import android.widget.ImageButton;
53 | import android.widget.ImageView;
54 | import android.widget.ProgressBar;
55 | import android.widget.RelativeLayout;
56 | import android.widget.TextView;
57 | import android.widget.Toast;
58 |
59 | import com.gueg.browser.MainActivity;
60 | import com.gueg.browser.OnMainActivityCallListener;
61 | import com.gueg.browser.R;
62 | import com.gueg.browser.thumbnails.Thumbnail;
63 |
64 | import java.io.File;
65 | import java.net.URISyntaxException;
66 |
67 | import static android.Manifest.permission.WRITE_EXTERNAL_STORAGE;
68 | import static android.content.Context.DOWNLOAD_SERVICE;
69 |
70 |
71 | @SuppressWarnings("deprecation")
72 | public class WebFragment extends Fragment implements AdapterView.OnItemClickListener {
73 |
74 | private OnMainActivityCallListener mMainActivityListener;
75 |
76 | int MENU_CANCEL = 1;
77 | int MENU_NEWTABLINK = 2;
78 | int MENU_NEWTABIMAGE = 3;
79 | int MENU_DOWNLOADIMAGE = 4;
80 | int MENU_NEWTABLINK_BKG = 5;
81 | int MENU_COPY_LINK = 6;
82 |
83 | public boolean oneTabMode = false;
84 | String mainUrl = "";
85 |
86 | boolean userAgentMobile = true;
87 | String userAgentDefault;
88 |
89 | ListPopupWindow menu;
90 | String[] menuChoices={"Rafraichir la page", "Suivant", "Rechercher sur la page", "Voir le code source", "Dupliquer la page", "Copier le lien", "Partager le lien"};
91 | String[] menuChoicesOneTabMode={"Rafraichir la page", "Suivant", "Rechercher sur la page", "Voir le code source", "Ouvrir l'application complète", "Copier le lien", "Partager le lien"};
92 |
93 | //"(Ne pas bloquer les pubs ici)"
94 | //"(Rechercher un flux rss)"
95 |
96 | // Find on page
97 | String searching;
98 | RelativeLayout findOnPageLayout;
99 | EditText search;
100 | ImageButton findOnPagePrev;
101 | ImageButton findOnPageNext;
102 |
103 | boolean isBarHidden = false;
104 |
105 | Thumbnail tempThumbnail = null;
106 |
107 | WebSettings webSettings;
108 | SharedPreferences mainPref;
109 | View rootView;
110 | WebView web;
111 | EditText text;
112 | ImageView image;
113 | ImageButton btn_onglet;
114 | RelativeLayout rel;
115 | int posFrag;
116 | private String toLoad;
117 | String homepage;
118 | ProgressBar anim;
119 | ProgressBar progressBar;
120 | int colorMain;
121 | int colorBar;
122 | boolean textUrlShown = false;
123 | boolean loading = false;
124 |
125 | float bkpProgressBarPos = 0;
126 |
127 | static final int DOWN = 0;
128 | static final int UP = 0;
129 | int currentStatus;
130 |
131 | int margin;
132 | int pos;
133 | boolean canHideBar = false;
134 | Handler scrollHandler = new Handler();
135 |
136 | // TODO NEW TAB FROM IMG
137 |
138 | boolean fragHasBeenLoaded = false;
139 |
140 | @Override
141 | public void onAttach(Context context) {
142 | super.onAttach(context);
143 | try {
144 | mMainActivityListener = (OnMainActivityCallListener) context;
145 | } catch (ClassCastException castException) {
146 | // The activity does not implement the listener.
147 | }
148 | }
149 |
150 | @Override
151 | public void onCreate(Bundle savedInstanceState) {
152 | super.onCreate(savedInstanceState);
153 | }
154 |
155 | @SuppressLint("SetJavaScriptEnabled")
156 | @Override
157 | public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
158 | rootView = inflater.inflate(R.layout.fragment_webview, container, false);
159 | super.onCreateView(inflater,container,savedInstanceState);
160 | rootView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
161 |
162 | @TargetApi(Build.VERSION_CODES.LOLLIPOP)
163 | @Override
164 | public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
165 | v.removeOnLayoutChangeListener(this);
166 |
167 | RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)web.getLayoutParams();
168 | params.setMargins(0,rel.getHeight(),0,0);
169 | web.setLayoutParams(params);
170 |
171 | fragHasBeenLoaded = true;
172 | }
173 | });
174 |
175 | web = rootView.findViewById(R.id.webView);
176 | rel = rootView.findViewById(R.id.relatLayoutWeb);
177 | text = rootView.findViewById(R.id.webViewText);
178 | image = rootView.findViewById(R.id.imageViewWeb);
179 | btn_onglet = rootView.findViewById(R.id.cwvTabs);
180 | anim = rootView.findViewById(R.id.progressAnim);
181 |
182 | mainPref = PreferenceManager.getDefaultSharedPreferences(getActivity());
183 | refreshColor();
184 |
185 | anim.setOnClickListener(new View.OnClickListener() {
186 | @Override
187 | public void onClick(View v) {
188 | web.stopLoading();
189 | }
190 | });
191 |
192 |
193 | assert btn_onglet != null;
194 | btn_onglet.setOnClickListener(new View.OnClickListener() {
195 | @Override
196 | public void onClick(View v) {
197 | if(!oneTabMode) {
198 | mMainActivityListener.onRefresh();
199 | mMainActivityListener.onSetCurrentFragment(-1, posFrag);
200 | }
201 | }
202 | });
203 | btn_onglet.setLongClickable(true);
204 | menu = new ListPopupWindow(getContext());
205 | menu.setAdapter(new ArrayAdapter<>(getContext(),android.R.layout.simple_list_item_1,menuChoices));
206 | menu.setAnchorView(btn_onglet);
207 | menu.setWidth(600);
208 | menu.setOnItemClickListener(this);
209 | btn_onglet.setOnLongClickListener(new View.OnLongClickListener() {
210 | @Override
211 | public boolean onLongClick(View v) {
212 | menu.show();
213 | return true;
214 | }
215 | });
216 |
217 |
218 |
219 | web.setOnTouchListener(new View.OnTouchListener() {
220 | private float posY=0;
221 | @Override
222 | public boolean onTouch(View v, MotionEvent event) {
223 | switch(event.getAction()) {
224 | case MotionEvent.ACTION_DOWN:
225 | posY = event.getY();
226 | break;
227 | case MotionEvent.ACTION_UP:
228 | if(mainPref.getBoolean("prefHideBar",true)&&event.getY()-posY<-300&&!isBarHidden&&canHideBar) {
229 | if(currentStatus!=DOWN)
230 | scrollHandler.removeCallbacks(null);
231 | currentStatus=DOWN;
232 | margin=rel.getHeight();
233 | final float percentage = margin/10;
234 | rel.animate().translationYBy(-margin).setDuration(200).start();
235 | bkpProgressBarPos = progressBar.getY();
236 | progressBar.setY(-margin);
237 | scrollHandler.post(new Runnable() {
238 | @Override
239 | public void run() {
240 | RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)web.getLayoutParams();
241 | params.setMargins(0,margin-=percentage,0,0);
242 | web.setLayoutParams(params);
243 | if(margin>0)
244 | scrollHandler.postDelayed(this,2);
245 | else
246 | rel.setVisibility(View.INVISIBLE);
247 | }
248 | });
249 | if(!isBarHidden)
250 | isBarHidden = true;
251 | } else if(event.getY()>posY+200&&isBarHidden){
252 | if(currentStatus!=UP)
253 | scrollHandler.removeCallbacks(null);
254 | currentStatus=UP;
255 | rel.setY(-rel.getHeight());
256 | rel.setVisibility(View.VISIBLE);
257 | margin=rel.getHeight();
258 | progressBar.setY(bkpProgressBarPos);
259 | isBarHidden = false;
260 | final float percentage = margin/10;
261 | pos=0;
262 | scrollHandler.post(new Runnable() {
263 | @Override
264 | public void run() {
265 | RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)web.getLayoutParams();
266 | params.setMargins(0,pos+=percentage,0,0);
267 | web.setLayoutParams(params);
268 | if(pos 0 && searching == null) {
300 | searching = search.getText().toString();
301 | web.findAllAsync(searching);
302 | } else if (search.getText().length() == 0) {
303 | web.clearMatches();
304 | searching = null;
305 | } else if (search.getText().toString().equals(searching)) {
306 | web.findNext(true);
307 | } else if (!search.getText().toString().equals(searching)) {
308 | searching = search.getText().toString();
309 | web.findAllAsync(searching);
310 | }
311 | }
312 | });
313 | findOnPagePrev.setOnClickListener(new View.OnClickListener() {
314 | @Override
315 | public void onClick(View v) {
316 | if (search.getText().length() > 0 && searching == null) {
317 | searching = search.getText().toString();
318 | web.findAllAsync(searching);
319 | } else if (search.getText().length() == 0) {
320 | web.clearMatches();
321 | searching = null;
322 | } else if (search.getText().toString().equals(searching)) {
323 | web.findNext(false);
324 | } else if (!search.getText().toString().equals(searching)) {
325 | searching = search.getText().toString();
326 | web.findAllAsync(searching);
327 | }
328 | }
329 | });
330 |
331 |
332 | text.setOnClickListener(new View.OnClickListener() {
333 | @Override
334 | public void onClick(View v) {
335 | if(!textUrlShown){
336 | ((EditText) v).setText(web.getUrl());
337 | ((EditText) v).selectAll();
338 | textUrlShown = true;
339 | }
340 | }
341 | });
342 |
343 | text.setOnTouchListener(new View.OnTouchListener() {
344 | float mLastMotionX;
345 | @Override
346 | public boolean onTouch(View v, MotionEvent ev) {
347 | final int action = ev.getAction();
348 | final float x = ev.getX();
349 | switch (action) {
350 | case MotionEvent.ACTION_DOWN:
351 | if(((EditText)v).getInputType()==InputType.TYPE_NULL)
352 | ((EditText)v).setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
353 | mLastMotionX = x;
354 | break;
355 |
356 | case MotionEvent.ACTION_MOVE:
357 | final int deltaX = (int) (x - mLastMotionX);
358 | ((EditText) v).setInputType(InputType.TYPE_NULL);
359 |
360 | if (Math.abs(deltaX) >= 80) {
361 | mMainActivityListener.onTabSwipe(deltaX >= 0);
362 | mLastMotionX = x;
363 | }
364 |
365 | return true;
366 | }
367 | return false;
368 | }
369 | });
370 |
371 | text.setImeOptions(EditorInfo.IME_ACTION_DONE);
372 |
373 | text.setOnEditorActionListener(new TextView.OnEditorActionListener() {
374 | @Override
375 | public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
376 | if (actionId == EditorInfo.IME_ACTION_DONE) {
377 | if(text.getText().toString().toLowerCase().contains("http://")||text.getText().toString().toLowerCase().contains("https://")) {
378 | loadUrl(text.getText().toString());
379 | }
380 | else if(text.getText().toString().toLowerCase().contains("www")) {
381 | String display = "http://"+text.getText().toString();
382 | text.setText(display);
383 | loadUrl(display);
384 | }
385 | else if(text.getText().toString().toLowerCase().contains(".fr")||text.getText().toString().toLowerCase().contains(".com")) {
386 | String display = "http://www."+text.getText().toString();
387 | text.setText(display);
388 | loadUrl(display);
389 | }
390 | else
391 | loadUrl("https://www.google.fr/search?q="+text.getText().toString());
392 |
393 | }
394 | return false;
395 | }
396 | });
397 |
398 |
399 | CookieManager.getInstance().setAcceptCookie(true);
400 |
401 |
402 |
403 | web.setOverScrollMode(View.OVER_SCROLL_NEVER);
404 | progressBar = rootView.findViewById(R.id.progressBar);
405 | web.setWebChromeClient(new WebChromeClient() {
406 | @Override
407 | public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
408 | result.cancel();
409 | return true;
410 | }
411 |
412 | @Override
413 | public boolean onJsConfirm(WebView view, String url, String message, JsResult result) {
414 | result.cancel();
415 | return true;
416 | }
417 |
418 | @Override
419 | public boolean onJsPrompt(WebView view, String url, String message, String defaultValue, JsPromptResult result) {
420 | result.cancel();
421 | return true;
422 | }
423 | @Override
424 | public void onProgressChanged(WebView view, int progress) {
425 | progressBar.setMax(100);
426 | progressBar.setProgressTintList(ColorStateList.valueOf(colorMain));
427 | progressBar.setProgress(progress);
428 | if (progress == 100) {
429 | progressBar.setVisibility(View.GONE);
430 | } else {
431 | progressBar.setVisibility(View.VISIBLE);
432 | progressBar.bringToFront();
433 | }
434 |
435 | }
436 | @Override
437 | public void onReceivedTitle(WebView view, String title) {
438 | text.setText(title);
439 | if(!oneTabMode)
440 | mMainActivityListener.onRefresh();
441 | }
442 | @Override
443 | public void onReceivedIcon(WebView view, Bitmap icon) {
444 | image.setImageBitmap(icon);
445 | }
446 | });
447 |
448 | web.setAnimationCacheEnabled(false);
449 | web.setDrawingCacheEnabled(true);
450 | web.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_LOW);
451 |
452 | web.setDownloadListener(new DownloadListener() {
453 | @Override
454 | public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
455 | if (((MainActivity)getActivity()).checkPermission(WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
456 | DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
457 | final String filename = URLUtil.guessFileName(url, contentDisposition, mimetype);
458 | request.allowScanningByMediaScanner();
459 | request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
460 | request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, filename);
461 | DownloadManager dm = (DownloadManager) getActivity().getSystemService(DOWNLOAD_SERVICE);
462 | dm.enqueue(request);
463 | Toast.makeText(getActivity(), "Téléchargement en cours...", Toast.LENGTH_LONG).show();
464 | } else {
465 | ((MainActivity)getActivity()).requestPermission(WRITE_EXTERNAL_STORAGE);
466 | }
467 |
468 | }
469 | });
470 |
471 |
472 | if(savedInstanceState==null)
473 | web.loadUrl(homepage);
474 | webSettings = web.getSettings();
475 | web.requestFocus();
476 |
477 |
478 | // Enable Javascript
479 | if (webSettings != null) {
480 | webSettings.setJavaScriptEnabled(true);
481 | webSettings.setBuiltInZoomControls(true);
482 | webSettings.setDisplayZoomControls(false);
483 | webSettings.setSupportZoom(true);
484 | webSettings.setAppCacheEnabled(true);
485 | webSettings.setDatabaseEnabled(true);
486 | webSettings.setDomStorageEnabled(true);
487 | webSettings.setLoadWithOverviewMode(true);
488 | webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
489 | webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
490 | }
491 |
492 |
493 | web.setWebViewClient(new SSLTolerentWebViewClient());
494 |
495 |
496 | web.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() {
497 | @Override
498 | public void onCreateContextMenu(final ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
499 |
500 | final WebView.HitTestResult result = ((WebView)v).getHitTestResult();
501 |
502 | MenuItem.OnMenuItemClickListener handler = new MenuItem.OnMenuItemClickListener() {
503 | public boolean onMenuItemClick(MenuItem item) {
504 | if(item.getItemId()==MENU_CANCEL)
505 | menu.close();
506 | else if(item.getItemId()==MENU_NEWTABLINK) {
507 | mMainActivityListener.onNewTab(result.getExtra(),-1);
508 | }
509 | else if(item.getItemId()==MENU_NEWTABLINK_BKG) {
510 | mMainActivityListener.onNewTab(result.getExtra(),posFrag);
511 | }
512 | else if(item.getItemId()==MENU_NEWTABIMAGE) {
513 | mMainActivityListener.onNewTab(result.getExtra(),-1);
514 | }
515 | else if(item.getItemId()==MENU_DOWNLOADIMAGE) {
516 | downloadPicture(result.getExtra());
517 | }
518 | else if(item.getItemId()==MENU_COPY_LINK) {
519 | ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
520 | ClipData clip = ClipData.newPlainText("Lien", result.getExtra());
521 | clipboard.setPrimaryClip(clip);
522 | Toast.makeText(getContext(), "Lien copié", Toast.LENGTH_SHORT).show();
523 | }
524 | return true;
525 | }
526 | };
527 |
528 | if (result.getType() == WebView.HitTestResult.IMAGE_TYPE ||
529 | result.getType() == WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE) {
530 | if(!oneTabMode) {
531 | menu.add(Menu.NONE, MENU_NEWTABLINK, Menu.NONE, "Ouvrir dans un nouvel onglet").setOnMenuItemClickListener(handler);
532 | menu.add(Menu.NONE, MENU_NEWTABLINK_BKG, Menu.NONE, "Ouvrir en arrière plan").setOnMenuItemClickListener(handler);
533 | menu.add(Menu.NONE, MENU_NEWTABIMAGE, Menu.NONE, "Ouvrir l'image dans un nouvel onglet").setOnMenuItemClickListener(handler);
534 | }
535 | menu.add(Menu.NONE, MENU_DOWNLOADIMAGE, Menu.NONE, "Télécharger l'image").setOnMenuItemClickListener(handler);
536 | menu.add(Menu.NONE, MENU_COPY_LINK, Menu.NONE, "Copier le lien").setOnMenuItemClickListener(handler);
537 | menu.add(Menu.NONE, MENU_CANCEL, Menu.NONE, "Annuler").setOnMenuItemClickListener(handler);
538 | } else if (result.getType() == WebView.HitTestResult.ANCHOR_TYPE ||
539 | result.getType() == WebView.HitTestResult.SRC_ANCHOR_TYPE) {
540 | if(!oneTabMode) {
541 | menu.add(Menu.NONE, MENU_NEWTABLINK, Menu.NONE, "Ouvrir dans un nouvel onglet").setOnMenuItemClickListener(handler);
542 | menu.add(Menu.NONE, MENU_NEWTABLINK_BKG, Menu.NONE, "Ouvrir en arrière plan").setOnMenuItemClickListener(handler);
543 | }
544 | menu.add(Menu.NONE, MENU_COPY_LINK, Menu.NONE, "Copier le lien").setOnMenuItemClickListener(handler);
545 | menu.add(Menu.NONE, MENU_CANCEL, Menu.NONE, "Annuler").setOnMenuItemClickListener(handler);
546 | }
547 | }
548 |
549 | });
550 |
551 | userAgentDefault = web.getSettings().getUserAgentString();
552 | /*
553 | web.evaluateJavascript(
554 | "(function() { return (''+document.getElementsByTagName('html')[0].innerHTML+''); })();",
555 | new ValueCallback() {
556 | @Override
557 | public void onReceiveValue(String html) {
558 | Log.d("HTML", html);
559 | }
560 | });
561 | */
562 | return rootView;
563 | }
564 |
565 | public void setOneTabMode() {
566 | oneTabMode = true;
567 | menuChoices = menuChoicesOneTabMode;
568 | if(menu!=null)
569 | menu.setAdapter(new ArrayAdapter<>(getContext(),android.R.layout.simple_list_item_1,menuChoices));
570 | }
571 |
572 |
573 | public void onCurrentFragment() {
574 | if(rel!=null)
575 | rel.animate().translationZ(25).setDuration(500).start();
576 | if(btn_onglet!=null)
577 | btn_onglet.animate().translationZ(20).setDuration(500).start();
578 | }
579 |
580 | public boolean toggleUserAgent() {
581 | if (userAgentMobile) {
582 | web.getSettings().setUserAgentString("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36");
583 | userAgentMobile = false;
584 | webSettings.setLoadWithOverviewMode(true);
585 | webSettings.setUseWideViewPort(true);
586 | web.reload();
587 | } else {
588 | web.getSettings().setUserAgentString(userAgentDefault);
589 | userAgentMobile = true;
590 | webSettings.setUseWideViewPort(false);
591 | webSettings.setLoadWithOverviewMode(false);
592 | web.reload();
593 | }
594 | return userAgentMobile;
595 | }
596 |
597 | public boolean getUserAgent() {
598 | return userAgentMobile;
599 | }
600 |
601 |
602 |
603 | public void refreshColor() {
604 | homepage = mainPref.getString("prefHomepage","http://www.google.fr");
605 | assert getContext()!=null;
606 | colorBar = mainPref.getInt("prefColorBar",getContext().getResources().getColor(R.color.defaultHeaderColor));
607 | colorMain = mainPref.getInt("prefColorMain",getContext().getResources().getColor(R.color.defaultLoadingColor));
608 |
609 |
610 | rel.setBackgroundTintList(ColorStateList.valueOf(colorBar));
611 | text.setBackgroundTintList(ColorStateList.valueOf(colorBar));
612 | image.setBackgroundTintList(ColorStateList.valueOf(colorBar));
613 | btn_onglet.setBackgroundTintList(ColorStateList.valueOf(colorBar));
614 |
615 |
616 | boolean isChecked = mainPref.getBoolean("prefColorBarText",false);
617 |
618 | if(isChecked)
619 | text.setTextColor(ColorStateList.valueOf(0xff000000));
620 | else
621 | text.setTextColor(ColorStateList.valueOf(0xffffffff));
622 | }
623 |
624 |
625 | public void setPos(int pos) {
626 | posFrag=pos;
627 | }
628 |
629 |
630 | public void loadUrl(String url) {
631 | web.loadUrl(url);
632 | web.requestFocus();
633 | }
634 |
635 | public void setOnStartUrl(String url) {
636 | toLoad = url;
637 | }
638 |
639 |
640 |
641 |
642 | public boolean tryGoBack() {
643 | if(web.canGoBack()) {
644 | web.goBack();
645 | return true;
646 | } else
647 | return false;
648 | }
649 |
650 | public WebView getWeb() {
651 | return web;
652 | }
653 |
654 | @Override
655 | public void onPause() {
656 | web.onPause();
657 | super.onPause();
658 | }
659 |
660 | @Override
661 | public void onResume() {
662 | web.onResume();
663 | super.onResume();
664 | }
665 |
666 | @Override
667 | public void onActivityCreated(Bundle savedInstanceState) {
668 | web.loadUrl(toLoad);
669 | super.onActivityCreated(savedInstanceState);
670 | }
671 |
672 | @Override
673 | public void onDestroy() {
674 | web.onPause();
675 | super.onDestroy();
676 | }
677 |
678 |
679 | public void downloadPicture(String url) {
680 | if (((MainActivity)getActivity()).checkPermission(WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
681 | DownloadManager mdDownloadManager = (DownloadManager) getActivity().getSystemService(Context.DOWNLOAD_SERVICE);
682 | DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
683 | int indexOxHttp = url.indexOf("://");
684 | File destinationFile = new File(Environment.getExternalStorageDirectory(), url.substring(indexOxHttp + 2, indexOxHttp + 22));
685 | request.setDescription("Downloading ...");
686 | request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
687 | request.setDestinationUri(Uri.fromFile(destinationFile));
688 | mdDownloadManager.enqueue(request);
689 | } else {
690 | ((MainActivity)getActivity()).requestPermission(WRITE_EXTERNAL_STORAGE);
691 | }
692 | }
693 |
694 |
695 |
696 |
697 | @Override
698 | public void onItemClick(AdapterView> parent, View view, int position, long id) {
699 | switch(menuChoices[position]) {
700 | case "Rafraichir la page" :
701 | web.reload();
702 | break;
703 | case "Suivant":
704 | if(web.canGoForward())
705 | web.goForward();
706 | break;
707 | case "Ne pas bloquer les pubs ici" :
708 | break;
709 | case "Rechercher sur la page" :
710 | if(findOnPageLayout.getVisibility()==View.GONE) {
711 | findOnPageLayout.setVisibility(View.VISIBLE);
712 | findOnPageLayout.bringToFront();
713 | } else {
714 | findOnPageLayout.setVisibility(View.GONE);
715 | web.clearMatches();
716 | }
717 | break;
718 | case "Rechercher un flux rss" :
719 | break;
720 | case "Voir le code source" :
721 | web.loadUrl("view-source:"+web.getUrl());
722 | break;
723 | case "Dupliquer la page":
724 | mMainActivityListener.onNewTab(web.getUrl(),posFrag);
725 | break;
726 | case "Copier le lien" :
727 | ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
728 | ClipData clip = ClipData.newPlainText("Lien", web.getUrl());
729 | if(clipboard!=null) {
730 | clipboard.setPrimaryClip(clip);
731 | Toast.makeText(getContext(), "Lien copié", Toast.LENGTH_SHORT).show();
732 | }
733 | break;
734 | case "Partager le lien" :
735 | Intent i=new Intent(android.content.Intent.ACTION_SEND);
736 | i.setType("text/plain");
737 | //i.putExtra(android.content.Intent.EXTRA_SUBJECT,"Partager");
738 | i.putExtra(android.content.Intent.EXTRA_TEXT, web.getUrl());
739 | startActivity(Intent.createChooser(i,"Partager avec"));
740 | break;
741 | case "Ouvrir l'application complète" :
742 | Intent intent = getActivity().getPackageManager()
743 | .getLaunchIntentForPackage( getActivity().getPackageName() );
744 | intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
745 | intent.putExtra("COMPLETE",web.getUrl());
746 | startActivity(intent);
747 | break;
748 | }
749 | menu.dismiss();
750 | }
751 |
752 | public Thumbnail getThumbnail() {
753 | if(fragHasBeenLoaded) {
754 | //web.buildDrawingCache();
755 | return new Thumbnail(web.getTitle(), web.getUrl(), web.getFavicon());
756 | } else
757 | return tempThumbnail;
758 | }
759 |
760 | public void setTempThumbnail(Thumbnail t) {
761 | tempThumbnail = t;
762 | }
763 |
764 |
765 |
766 | private class SSLTolerentWebViewClient extends WebViewClient {
767 | @Override
768 | public boolean shouldOverrideUrlLoading(WebView view, String url) {
769 | if(!url.startsWith("http")) {
770 | Uri parsedUri = Uri.parse(url);
771 | PackageManager packageManager = getActivity().getPackageManager();
772 | Intent browseIntent = new Intent(Intent.ACTION_VIEW).setData(parsedUri);
773 | if (browseIntent.resolveActivity(packageManager) != null) {
774 | getActivity().startActivity(browseIntent);
775 | }
776 | // if no activity found, try to parse intent://
777 | else {
778 | try {
779 | Intent intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME);
780 | if (intent.resolveActivity(getActivity().getPackageManager()) != null) {
781 | getActivity().startActivity(intent);
782 | }
783 | //try to find fallback url
784 | String fallbackUrl = intent.getStringExtra("browser_fallback_url");
785 | if (fallbackUrl != null) {
786 | web.loadUrl(fallbackUrl);
787 | }
788 | //invite to install
789 | Intent marketIntent = new Intent(Intent.ACTION_VIEW).setData(
790 | Uri.parse("market://details?id=" + intent.getPackage()));
791 | if (marketIntent.resolveActivity(packageManager) != null) {
792 | getActivity().startActivity(marketIntent);
793 | }
794 | } catch (URISyntaxException e) {
795 | e.printStackTrace();
796 | }
797 | }
798 | return true;
799 | }
800 | web.loadUrl(url);
801 | return true;
802 | }
803 |
804 |
805 |
806 | @Override
807 | public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
808 | return mainPref.getBoolean("prefAdBlock",true)&&
809 | !request.getUrl().toString().equals(mainUrl)&&
810 | AdBlocker.isAd(request.getUrl().toString()) ?
811 | AdBlocker.createEmptyResource() :
812 | super.shouldInterceptRequest(view, request);
813 | }
814 |
815 | @Override
816 | public void onPageStarted(WebView view, String url, Bitmap favIcon) {
817 | mainUrl = url;
818 | if(textUrlShown)
819 | textUrlShown = false;
820 | anim.setVisibility(View.VISIBLE);
821 | image.setVisibility(View.INVISIBLE);
822 | loading = true;
823 | if(isBarHidden) {
824 | isBarHidden = false;
825 | rel.animate().translationY(0).setDuration(100).start();
826 | RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)web.getLayoutParams();
827 | params.setMargins(0,rel.getHeight(),0,0);
828 | web.setLayoutParams(params);
829 | rel.setVisibility(View.VISIBLE);
830 | progressBar.setY(bkpProgressBarPos);
831 | rel.animate().translationY(0).setDuration(100).start();
832 | }
833 | //view.requestFocus();
834 | scrollHandler.removeCallbacks(null);
835 | canHideBar = false;
836 | }
837 |
838 | @Override
839 | public void onPageFinished(WebView view, String url) {
840 | loading = false;
841 | anim.setVisibility(View.INVISIBLE);
842 | image.setVisibility(View.VISIBLE);
843 | final int animDuration = 150;
844 | image.setImageBitmap(web.getFavicon());
845 | image.animate().scaleX(1.25f).scaleY(1.25f).setDuration(animDuration).start();
846 | new Handler().postDelayed(new Runnable() {
847 | @Override
848 | public void run() {
849 | image.animate().scaleX(1).scaleY(1).setDuration(animDuration).start();
850 | }
851 | },animDuration+20);
852 | view.loadUrl("javascript:document.getElementsByName('viewport')[0].setAttribute('content', 'initial-scale=1.0,maximum-scale=10.0');");
853 | canHideBar = true;
854 | if(!oneTabMode) {
855 | web.buildDrawingCache();
856 | mMainActivityListener.onRefresh();
857 | mMainActivityListener.onPageLoaded(view.getTitle(), view.getUrl());
858 | }
859 | }
860 |
861 | @Override
862 | public void onReceivedSslError(WebView view, final SslErrorHandler handler, SslError error) {
863 | final AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
864 | String message = "Erreur de certificat SSL.";
865 | switch (error.getPrimaryError()) {
866 | case SslError.SSL_UNTRUSTED:
867 | message = "Le certificat est hors de confiance.";
868 | break;
869 | case SslError.SSL_EXPIRED:
870 | message = "Le certificat a expiré.";
871 | break;
872 | case SslError.SSL_IDMISMATCH:
873 | message = "Le certificat ne correspond pas à l'hôte.";
874 | break;
875 | case SslError.SSL_NOTYETVALID:
876 | message = "Le certificat n'est pas encore valide.";
877 | break;
878 | }
879 | message += " Continuer quand même?";
880 |
881 | builder.setTitle("Erreur de certificat SSL");
882 | builder.setMessage(message);
883 | builder.setPositiveButton("Continuer", new DialogInterface.OnClickListener() {
884 | @Override
885 | public void onClick(DialogInterface dialog, int which) {
886 | handler.proceed();
887 | }
888 | });
889 | builder.setNegativeButton("Annuler", new DialogInterface.OnClickListener() {
890 | @Override
891 | public void onClick(DialogInterface dialog, int which) {
892 | handler.cancel();
893 | }
894 | });
895 | final AlertDialog dialog = builder.create();
896 | dialog.show();
897 | }
898 |
899 |
900 | @Override
901 | public void onReceivedError(final WebView view, int errorCode, String description, final String failingUrl) {
902 | if(!oneTabMode)
903 | mMainActivityListener.addToErrors(WebFragment.this);
904 | super.onReceivedError(view, errorCode, description, failingUrl);
905 | }
906 |
907 | }
908 |
909 |
910 |
911 | }
--------------------------------------------------------------------------------