Browse Source

Switched to RecyclerView, cleaned up some HTML generator methods

master
Anthony Restaino 9 years ago
parent
commit
85d92db738
  1. 4
      app/app.iml
  2. 2
      app/build.gradle
  3. 214
      app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java
  4. 56
      app/src/main/java/acr/browser/lightning/constant/BookmarkPage.java
  5. 110
      app/src/main/java/acr/browser/lightning/constant/StartPage.java
  6. 2
      app/src/main/java/acr/browser/lightning/controller/BrowserController.java
  7. 21
      app/src/main/java/acr/browser/lightning/utils/ThemeUtils.java
  8. 114
      app/src/main/java/acr/browser/lightning/view/LightningView.java
  9. 6
      app/src/main/res/layout/tab_drawer.xml
  10. 10
      app/src/main/res/layout/tab_list_item.xml
  11. 1
      app/src/main/res/layout/tab_list_item_horizontal.xml
  12. 7
      app/src/main/res/layout/toolbar.xml

4
app/app.iml

@ -95,9 +95,9 @@ @@ -95,9 +95,9 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/23.0.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/design/23.0.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/palette-v7/23.0.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/recyclerview-v7/23.0.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/23.0.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/net.i2p.android/client/0.7/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/org.lucasr.twowayview/twowayview/0.1.4/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaResources" />
@ -117,10 +117,10 @@ @@ -117,10 +117,10 @@
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="client-0.7" level="project" />
<orderEntry type="library" exported="" name="design-23.0.0" level="project" />
<orderEntry type="library" exported="" name="twowayview-0.1.4" level="project" />
<orderEntry type="library" exported="" name="palette-v7-23.0.0" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-23.0.0" level="project" />
<orderEntry type="library" exported="" name="jsoup-1.8.1" level="project" />
<orderEntry type="library" exported="" name="recyclerview-v7-23.0.0" level="project" />
<orderEntry type="library" exported="" name="support-v4-23.0.0" level="project" />
<orderEntry type="library" exported="" name="support-annotations-23.0.0" level="project" />
<orderEntry type="module" module-name="libnetcipher" exported="" />

2
app/build.gradle

@ -46,8 +46,8 @@ dependencies { @@ -46,8 +46,8 @@ dependencies {
compile 'com.android.support:palette-v7:23.0.0'
compile 'com.android.support:appcompat-v7:23.0.0'
compile 'com.android.support:design:23.0.0'
compile 'com.android.support:recyclerview-v7:23.0.0'
compile 'org.jsoup:jsoup:1.8.1'
compile 'org.lucasr.twowayview:twowayview:0.1.4'
// Only Lightning Plus needs the proxy libraries
lightningPlusCompile 'net.i2p.android:client:0.7'
lightningPlusCompile(project(':libnetcipher'))

214
app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java

@ -20,6 +20,7 @@ import android.graphics.Bitmap; @@ -20,6 +20,7 @@ import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.Paint;
@ -45,6 +46,8 @@ import android.support.v4.widget.DrawerLayout.DrawerListener; @@ -45,6 +46,8 @@ import android.support.v4.widget.DrawerLayout.DrawerListener;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AlertDialog;
import android.support.v7.graphics.Palette;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.KeyEvent;
@ -89,8 +92,6 @@ import android.widget.TextView; @@ -89,8 +92,6 @@ import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;
import android.widget.VideoView;
import org.lucasr.twowayview.TwoWayView;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
@ -134,7 +135,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -134,7 +135,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
private FrameLayout mBrowserFrame;
private FullscreenHolder mFullscreenContainer;
private ListView mDrawerListRight;
private TwoWayView mDrawerListLeft;
private RecyclerView mDrawerListLeft;
private LinearLayout mDrawerLeft, mDrawerRight, mUiLayout, mToolbarLayout;
private RelativeLayout mSearchBar;
@ -153,7 +154,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -153,7 +154,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
// Adapter
private BookmarkViewAdapter mBookmarkAdapter;
private LightningViewAdapter mTitleAdapter;
private LightningViewAdapter mTabAdapter;
private SearchAdapter mSearchAdapter;
// Callback
@ -261,23 +262,30 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -261,23 +262,30 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
mHomepage = mPreferences.getHomepage();
TwoWayView horizontalListView = (TwoWayView) findViewById(R.id.twv_list);
RecyclerView horizontalListView = (RecyclerView) findViewById(R.id.twv_list);
if (mShowTabsInDrawer) {
mTitleAdapter = new LightningViewAdapter(this, R.layout.tab_list_item, mWebViewList);
mDrawerListLeft = (TwoWayView) findViewById(R.id.left_drawer_list);
mTabAdapter = new LightningViewAdapter(this, R.layout.tab_list_item, mWebViewList);
mDrawerListLeft = (RecyclerView) findViewById(R.id.left_drawer_list);
mDrawerListLeft.setOverScrollMode(View.OVER_SCROLL_IF_CONTENT_SCROLLS);
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
mDrawerListLeft.setLayoutManager(layoutManager);
mDrawerListLeft.setHasFixedSize(true);
mToolbarLayout.removeView(horizontalListView);
} else {
mTitleAdapter = new LightningViewAdapter(this, R.layout.tab_list_item_horizontal, mWebViewList);
mTabAdapter = new LightningViewAdapter(this, R.layout.tab_list_item_horizontal, mWebViewList);
mDrawerListLeft = horizontalListView;
mDrawerListLeft.setOverScrollMode(View.OVER_SCROLL_NEVER);
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, mDrawerLeft);
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
mDrawerListLeft.setLayoutManager(layoutManager);
mDrawerListLeft.setHasFixedSize(true);
}
mDrawerListLeft.setAdapter(mTitleAdapter);
mDrawerListLeft.setOnItemClickListener(new DrawerItemClickListener());
mDrawerListLeft.setOnItemLongClickListener(new DrawerItemLongClickListener());
mDrawerListLeft.setAdapter(mTabAdapter);
// mDrawerListLeft.setOnItemClickListener(new DrawerItemClickListener());
// mDrawerListLeft.setOnItemLongClickListener(new DrawerItemLongClickListener());
mDrawerListRight.setOnItemClickListener(new BookmarkItemClickListener());
mDrawerListRight.setOnItemLongClickListener(new BookmarkItemLongClickListener());
@ -957,10 +965,11 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -957,10 +965,11 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
/**
* The click listener for ListView in the navigation drawer
*/
private class DrawerItemClickListener implements ListView.OnItemClickListener {
private class DrawerItemClickListener implements OnClickListener {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
public void onClick(View v) {
int position = mDrawerListLeft.getChildAdapterPosition(v);
if (mCurrentView != mWebViewList.get(position)) {
mIsNewIntent = false;
showTab(mWebViewList.get(position));
@ -971,10 +980,11 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -971,10 +980,11 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
/**
* long click listener for Navigation Drawer
*/
private class DrawerItemLongClickListener implements ListView.OnItemLongClickListener {
private class DrawerItemLongClickListener implements OnLongClickListener {
@Override
public boolean onItemLongClick(AdapterView<?> arg0, View arg1, final int position, long arg3) {
public boolean onLongClick(View v) {
int position = mDrawerListLeft.getChildAdapterPosition(v);
showCloseDialog(position);
return true;
}
@ -1253,11 +1263,10 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -1253,11 +1263,10 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
mIdGenerator++;
mWebViewList.add(startingTab);
mTitleAdapter.notifyDataSetChanged();
if (show) {
mDrawerListLeft.setItemChecked(mWebViewList.size() - 1, true);
showTab(startingTab);
}
updateTabs();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
@ -1290,13 +1299,15 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -1290,13 +1299,15 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
}
if (current > position) {
mWebViewList.remove(position);
mDrawerListLeft.setItemChecked(current - 1, true);
showTab(mWebViewList.get(current - 1));
updateTabs();
reference.onDestroy();
} else if (mWebViewList.size() > position + 1) {
if (current == position) {
showTab(mWebViewList.get(position + 1));
mWebViewList.remove(position);
mDrawerListLeft.setItemChecked(position, true);
showTab(mWebViewList.get(position));
updateTabs();
} else {
mWebViewList.remove(position);
}
@ -1306,7 +1317,8 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -1306,7 +1317,8 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
if (current == position) {
showTab(mWebViewList.get(position - 1));
mWebViewList.remove(position);
mDrawerListLeft.setItemChecked(position - 1, true);
showTab(mWebViewList.get(position - 1));
updateTabs();
} else {
mWebViewList.remove(position);
}
@ -1322,12 +1334,11 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -1322,12 +1334,11 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
reference.onDestroy();
mCurrentView = null;
mWebView = null;
mTitleAdapter.notifyDataSetChanged();
mTabAdapter.notifyDataSetChanged();
finish();
}
}
mTitleAdapter.notifyDataSetChanged();
mTabAdapter.notifyDataSetChanged();
if (mIsNewIntent && isShown) {
mIsNewIntent = false;
@ -1380,7 +1391,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -1380,7 +1391,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
}
}
mWebViewList.clear();
mTitleAdapter.notifyDataSetChanged();
mTabAdapter.notifyDataSetChanged();
finish();
}
@ -1510,26 +1521,33 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -1510,26 +1521,33 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
}
}
public class LightningViewAdapter extends ArrayAdapter<LightningView> {
public class LightningViewAdapter extends RecyclerView.Adapter<LightningViewAdapter.LightningViewHolder> {
final Context context;
ColorMatrix colorMatrix;
ColorMatrixColorFilter filter;
Paint paint;
final int layoutResourceId;
List<LightningView> data = null;
private final Context context;
private final int layoutResourceId;
private List<LightningView> data = null;
final CloseTabListener mExitListener;
private final Drawable mBackgroundTabDrawable;
private final Drawable mForegroundTabDrawable;
private final DrawerItemClickListener mClickListener;
private final DrawerItemLongClickListener mLongClickListener;
private ColorMatrix mColorMatrix;
private Paint mPaint;
private ColorFilter mFilter;
private static final float DESATURATED = 0.5f;
public LightningViewAdapter(Context context, int layoutResourceId, List<LightningView> data) {
super(context, layoutResourceId, data);
this.layoutResourceId = layoutResourceId;
this.context = context;
this.data = data;
this.mExitListener = new CloseTabListener();
this.mClickListener = new DrawerItemClickListener();
this.mLongClickListener = new DrawerItemLongClickListener();
if (mShowTabsInDrawer) {
mBackgroundTabDrawable = null;
mForegroundTabDrawable = ThemeUtils.getSelectedBackground(context, mDarkTheme);
} else {
int backgroundColor = Utils.mixTwoColors(ThemeUtils.getPrimaryColor(mActivity), Color.BLACK, 0.75f);
Bitmap backgroundTabBitmap = Bitmap.createBitmap(Utils.dpToPx(175), Utils.dpToPx(30), Bitmap.Config.ARGB_8888);
Utils.drawTrapezoid(new Canvas(backgroundTabBitmap), backgroundColor, true);
@ -1540,31 +1558,21 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -1540,31 +1558,21 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
Utils.drawTrapezoid(new Canvas(foregroundTabBitmap), foregroundColor, false);
mForegroundTabDrawable = new BitmapDrawable(getResources(), foregroundTabBitmap);
}
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View row = convertView;
LightningViewHolder holder;
if (row == null) {
LayoutInflater inflater = LayoutInflater.from(context);
row = inflater.inflate(layoutResourceId, parent, false);
holder = new LightningViewHolder();
holder.txtTitle = (TextView) row.findViewById(R.id.textTab);
holder.favicon = (ImageView) row.findViewById(R.id.faviconTab);
holder.exit = (ImageView) row.findViewById(R.id.deleteButton);
if (!mShowTabsInDrawer) {
holder.layout = (LinearLayout) row.findViewById(R.id.tab_item_background);
}
holder.exitButton = (FrameLayout) row.findViewById(R.id.deleteAction);
holder.exit.setColorFilter(mIconColor, PorterDuff.Mode.SRC_IN);
row.setTag(holder);
} else {
holder = (LightningViewHolder) row.getTag();
public LightningViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
LayoutInflater inflater = LayoutInflater.from(viewGroup.getContext());
View view = inflater.inflate(layoutResourceId, viewGroup, false);
return new LightningViewHolder(view);
}
@Override
public void onBindViewHolder(LightningViewHolder holder, int position) {
holder.exitButton.setTag(position);
holder.exitButton.setOnClickListener(mExitListener);
holder.layout.setOnClickListener(mClickListener);
holder.layout.setOnLongClickListener(mLongClickListener);
ViewCompat.jumpDrawablesToCurrentState(holder.exitButton);
@ -1573,47 +1581,70 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -1573,47 +1581,70 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
Bitmap favicon = web.getFavicon();
if (web.isForegroundTab()) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
holder.txtTitle.setTextAppearance(R.style.boldText);
} else {
holder.txtTitle.setTextAppearance(context, R.style.boldText);
holder.favicon.setImageBitmap(favicon);
if (!mShowTabsInDrawer) {
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
holder.layout.setBackground(mForegroundTabDrawable);
} else {
holder.layout.setBackgroundDrawable(mForegroundTabDrawable);
}
}
if (!isIncognito() && mColorMode) {
// TODO fix toolbar coloring
// changeToolbarBackground(favicon, mForegroundTabDrawable);
}
holder.favicon.setImageBitmap(favicon);
} else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
holder.txtTitle.setTextAppearance(R.style.normalText);
} else {
holder.txtTitle.setTextAppearance(context, R.style.normalText);
if (!mShowTabsInDrawer) {
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
holder.layout.setBackground(mBackgroundTabDrawable);
} else {
holder.layout.setBackgroundDrawable(mBackgroundTabDrawable);
}
holder.favicon.setImageBitmap(getDesaturatedBitmap(favicon));
}
}
@Override
public int getItemCount() {
return (data != null) ? data.size() : 0;
}
public Bitmap getDesaturatedBitmap(Bitmap favicon) {
Bitmap grayscaleBitmap = Bitmap.createBitmap(favicon.getWidth(),
favicon.getHeight(), Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(grayscaleBitmap);
if (colorMatrix == null || filter == null || paint == null) {
paint = new Paint();
colorMatrix = new ColorMatrix();
colorMatrix.setSaturation(0.5f);
filter = new ColorMatrixColorFilter(colorMatrix);
paint.setColorFilter(filter);
if (mColorMatrix == null || mFilter == null || mPaint == null) {
mPaint = new Paint();
mColorMatrix = new ColorMatrix();
mColorMatrix.setSaturation(DESATURATED);
mFilter = new ColorMatrixColorFilter(mColorMatrix);
mPaint.setColorFilter(mFilter);
}
c.drawBitmap(favicon, 0, 0, paint);
holder.favicon.setImageBitmap(grayscaleBitmap);
c.drawBitmap(favicon, 0, 0, mPaint);
return grayscaleBitmap;
}
return row;
public class LightningViewHolder extends RecyclerView.ViewHolder {
public LightningViewHolder(View view) {
super(view);
txtTitle = (TextView) view.findViewById(R.id.textTab);
favicon = (ImageView) view.findViewById(R.id.faviconTab);
exit = (ImageView) view.findViewById(R.id.deleteButton);
layout = (LinearLayout) view.findViewById(R.id.tab_item_background);
exitButton = (FrameLayout) view.findViewById(R.id.deleteAction);
exit.setColorFilter(mIconColor, PorterDuff.Mode.SRC_IN);
}
class LightningViewHolder {
TextView txtTitle;
ImageView favicon;
ImageView exit;
@ -2024,58 +2055,13 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -2024,58 +2055,13 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
}
File bookmarkWebPage = new File(mActivity.getFilesDir(), BookmarkPage.FILENAME);
buildBookmarkPage(null, mBookmarkManager.getBookmarksFromFolder(null, true));
BookmarkPage.buildBookmarkPage(this, null, mBookmarkManager.getBookmarksFromFolder(null, true));
view.loadUrl(Constants.FILE + bookmarkWebPage);
}
private void buildBookmarkPage(final String folder, final List<HistoryItem> list) {
File bookmarkWebPage;
if (folder == null || folder.isEmpty()) {
bookmarkWebPage = new File(mActivity.getFilesDir(), BookmarkPage.FILENAME);
} else {
bookmarkWebPage = new File(mActivity.getFilesDir(), folder + '-' + BookmarkPage.FILENAME);
}
final StringBuilder bookmarkBuilder = new StringBuilder(BookmarkPage.HEADING);
String folderIconPath = Constants.FILE + mActivity.getCacheDir() + "/folder.png";
for (int n = 0; n < list.size(); n++) {
final HistoryItem item = list.get(n);
bookmarkBuilder.append(BookmarkPage.PART1);
if (item.isFolder()) {
File folderPage = new File(mActivity.getFilesDir(), item.getTitle() + '-' + BookmarkPage.FILENAME);
bookmarkBuilder.append(Constants.FILE).append(folderPage);
bookmarkBuilder.append(BookmarkPage.PART2);
bookmarkBuilder.append(folderIconPath);
new Thread(new Runnable() {
@Override
public void run() {
buildBookmarkPage(item.getTitle(), mBookmarkManager.getBookmarksFromFolder(item.getTitle(), true));
}
}).run();
} else {
bookmarkBuilder.append(item.getUrl());
bookmarkBuilder.append(BookmarkPage.PART2).append(BookmarkPage.PART3);
bookmarkBuilder.append(item.getUrl());
}
bookmarkBuilder.append(BookmarkPage.PART4);
bookmarkBuilder.append(item.getTitle());
bookmarkBuilder.append(BookmarkPage.PART5);
}
bookmarkBuilder.append(BookmarkPage.END);
FileWriter bookWriter = null;
try {
bookWriter = new FileWriter(bookmarkWebPage, false);
bookWriter.write(bookmarkBuilder.toString());
} catch (IOException e) {
e.printStackTrace();
} finally {
Utils.close(bookWriter);
}
}
@Override
public void update() {
mTitleAdapter.notifyDataSetChanged();
public void updateTabs() {
mTabAdapter.notifyDataSetChanged();
}
/**

56
app/src/main/java/acr/browser/lightning/constant/BookmarkPage.java

@ -3,8 +3,18 @@ @@ -3,8 +3,18 @@
*/
package acr.browser.lightning.constant;
import android.app.Activity;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;
import acr.browser.lightning.R;
import acr.browser.lightning.activity.BrowserApp;
import acr.browser.lightning.database.BookmarkManager;
import acr.browser.lightning.database.HistoryItem;
import acr.browser.lightning.utils.Utils;
public class BookmarkPage {
@ -39,4 +49,50 @@ public class BookmarkPage { @@ -39,4 +49,50 @@ public class BookmarkPage {
public static final String END = "</div></body></html>";
public static void buildBookmarkPage(final Activity activity, final String folder, final List<HistoryItem> list) {
final BookmarkManager manager = BookmarkManager.getInstance(activity);
File bookmarkWebPage;
if (folder == null || folder.isEmpty()) {
bookmarkWebPage = new File(activity.getFilesDir(), BookmarkPage.FILENAME);
} else {
bookmarkWebPage = new File(activity.getFilesDir(), folder + '-' + BookmarkPage.FILENAME);
}
final StringBuilder bookmarkBuilder = new StringBuilder(BookmarkPage.HEADING);
String folderIconPath = Constants.FILE + activity.getCacheDir() + "/folder.png";
for (int n = 0; n < list.size(); n++) {
final HistoryItem item = list.get(n);
bookmarkBuilder.append(BookmarkPage.PART1);
if (item.isFolder()) {
File folderPage = new File(activity.getFilesDir(), item.getTitle() + '-' + BookmarkPage.FILENAME);
bookmarkBuilder.append(Constants.FILE).append(folderPage);
bookmarkBuilder.append(BookmarkPage.PART2);
bookmarkBuilder.append(folderIconPath);
new Thread(new Runnable() {
@Override
public void run() {
buildBookmarkPage(activity, item.getTitle(), manager.getBookmarksFromFolder(item.getTitle(), true));
}
}).run();
} else {
bookmarkBuilder.append(item.getUrl());
bookmarkBuilder.append(BookmarkPage.PART2).append(BookmarkPage.PART3);
bookmarkBuilder.append(item.getUrl());
}
bookmarkBuilder.append(BookmarkPage.PART4);
bookmarkBuilder.append(item.getTitle());
bookmarkBuilder.append(BookmarkPage.PART5);
}
bookmarkBuilder.append(BookmarkPage.END);
FileWriter bookWriter = null;
try {
bookWriter = new FileWriter(bookmarkWebPage, false);
bookWriter.write(bookmarkBuilder.toString());
} catch (IOException e) {
e.printStackTrace();
} finally {
Utils.close(bookWriter);
}
}
}

110
app/src/main/java/acr/browser/lightning/constant/StartPage.java

@ -3,8 +3,16 @@ @@ -3,8 +3,16 @@
*/
package acr.browser.lightning.constant;
import android.app.Activity;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import acr.browser.lightning.activity.BrowserApp;
import acr.browser.lightning.R;
import acr.browser.lightning.preference.PreferenceManager;
import acr.browser.lightning.utils.Utils;
public class StartPage {
@ -38,4 +46,106 @@ public class StartPage { @@ -38,4 +46,106 @@ public class StartPage {
+ "</span></form></br></br></div></div></div><script type=\"text/javascript\">function search(){if(document.getElementById(\"search_input\").value != \"\"){window.location.href = \"";
public static final String END = "\" + document.getElementById(\"search_input\").value;document.getElementById(\"search_input\").value = \"\";}return false;}</script></body></html>";
/**
* This method builds the homepage and returns the local URL to be loaded
* when it finishes building.
*
* @return the URL to load
*/
public static String getHomepage(Activity activity) {
StringBuilder homepageBuilder = new StringBuilder(StartPage.HEAD);
String icon;
String searchUrl;
switch (PreferenceManager.getInstance().getSearchChoice()) {
case 0:
// CUSTOM SEARCH
icon = "file:///android_asset/lightning.png";
searchUrl = PreferenceManager.getInstance().getSearchUrl();
break;
case 1:
// GOOGLE_SEARCH;
icon = "file:///android_asset/google.png";
// "https://www.google.com/images/srpr/logo11w.png";
searchUrl = Constants.GOOGLE_SEARCH;
break;
case 2:
// ANDROID SEARCH;
icon = "file:///android_asset/ask.png";
searchUrl = Constants.ASK_SEARCH;
break;
case 3:
// BING_SEARCH;
icon = "file:///android_asset/bing.png";
// "http://upload.wikimedia.org/wikipedia/commons/thumb/b/b1/Bing_logo_%282013%29.svg/500px-Bing_logo_%282013%29.svg.png";
searchUrl = Constants.BING_SEARCH;
break;
case 4:
// YAHOO_SEARCH;
icon = "file:///android_asset/yahoo.png";
// "http://upload.wikimedia.org/wikipedia/commons/thumb/2/24/Yahoo%21_logo.svg/799px-Yahoo%21_logo.svg.png";
searchUrl = Constants.YAHOO_SEARCH;
break;
case 5:
// STARTPAGE_SEARCH;
icon = "file:///android_asset/startpage.png";
// "https://startpage.com/graphics/startp_logo.gif";
searchUrl = Constants.STARTPAGE_SEARCH;
break;
case 6:
// STARTPAGE_MOBILE
icon = "file:///android_asset/startpage.png";
// "https://startpage.com/graphics/startp_logo.gif";
searchUrl = Constants.STARTPAGE_MOBILE_SEARCH;
break;
case 7:
// DUCK_SEARCH;
icon = "file:///android_asset/duckduckgo.png";
// "https://duckduckgo.com/assets/logo_homepage.normal.v101.png";
searchUrl = Constants.DUCK_SEARCH;
break;
case 8:
// DUCK_LITE_SEARCH;
icon = "file:///android_asset/duckduckgo.png";
// "https://duckduckgo.com/assets/logo_homepage.normal.v101.png";
searchUrl = Constants.DUCK_LITE_SEARCH;
break;
case 9:
// BAIDU_SEARCH;
icon = "file:///android_asset/baidu.png";
// "http://www.baidu.com/img/bdlogo.gif";
searchUrl = Constants.BAIDU_SEARCH;
break;
case 10:
// YANDEX_SEARCH;
icon = "file:///android_asset/yandex.png";
// "http://upload.wikimedia.org/wikipedia/commons/thumb/9/91/Yandex.svg/600px-Yandex.svg.png";
searchUrl = Constants.YANDEX_SEARCH;
break;
default:
// DEFAULT GOOGLE_SEARCH;
icon = "file:///android_asset/google.png";
searchUrl = Constants.GOOGLE_SEARCH;
break;
}
homepageBuilder.append(icon);
homepageBuilder.append(StartPage.MIDDLE);
homepageBuilder.append(searchUrl);
homepageBuilder.append(StartPage.END);
File homepage = new File(activity.getFilesDir(), StartPage.FILENAME);
FileWriter hWriter = null;
try {
hWriter = new FileWriter(homepage, false);
hWriter.write(homepageBuilder.toString());
} catch (IOException e) {
e.printStackTrace();
} finally {
Utils.close(hWriter);
}
return Constants.FILE + homepage;
}
}

2
app/src/main/java/acr/browser/lightning/controller/BrowserController.java

@ -24,7 +24,7 @@ public interface BrowserController { @@ -24,7 +24,7 @@ public interface BrowserController {
void openFileChooser(ValueCallback<Uri> uploadMsg);
void update();
void updateTabs();
void onLongPress();

21
app/src/main/java/acr/browser/lightning/utils/ThemeUtils.java

@ -1,6 +1,7 @@ @@ -1,6 +1,7 @@
package acr.browser.lightning.utils;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
@ -9,6 +10,7 @@ import android.graphics.ColorFilter; @@ -9,6 +10,7 @@ import android.graphics.ColorFilter;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.annotation.AttrRes;
@ -44,10 +46,16 @@ public class ThemeUtils { @@ -44,10 +46,16 @@ public class ThemeUtils {
}
public static int getIconLightThemeColor(@NonNull Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
return context.getResources().getColor(R.color.icon_light_theme, context.getTheme());
}
return context.getResources().getColor(R.color.icon_light_theme);
}
public static int getIconDarkThemeColor(@NonNull Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
return context.getResources().getColor(R.color.icon_dark_theme, context.getTheme());
}
return context.getResources().getColor(R.color.icon_dark_theme);
}
@ -99,4 +107,17 @@ public class ThemeUtils { @@ -99,4 +107,17 @@ public class ThemeUtils {
drawable.setColorFilter(getIconLightThemeColor(context), PorterDuff.Mode.SRC_IN);
return drawable;
}
public static ColorDrawable getSelectedBackground(@NonNull Context context, boolean dark) {
Resources res = context.getResources();
int color;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
color = (dark) ? res.getColor(R.color.divider_dark, context.getTheme()) :
res.getColor(R.color.divider_light, context.getTheme());
} else {
color = (dark) ? res.getColor(R.color.divider_dark) :
res.getColor(R.color.divider_light);
}
return new ColorDrawable(color);
}
}

114
app/src/main/java/acr/browser/lightning/view/LightningView.java

@ -160,7 +160,7 @@ public class LightningView { @@ -160,7 +160,7 @@ public class LightningView {
return;
}
if (mHomepage.startsWith("about:home")) {
mWebView.loadUrl(getHomepage());
mWebView.loadUrl(StartPage.getHomepage(mActivity));
} else if (mHomepage.startsWith("about:bookmarks")) {
mBrowserController.openBookmarkPage(mWebView);
} else {
@ -168,108 +168,6 @@ public class LightningView { @@ -168,108 +168,6 @@ public class LightningView {
}
}
/**
* This method builds the homepage and returns the local URL to be loaded
* when it finishes building.
*
* @return the URL to load
*/
private String getHomepage() {
StringBuilder homepageBuilder = new StringBuilder(StartPage.HEAD);
String icon;
String searchUrl;
switch (mPreferences.getSearchChoice()) {
case 0:
// CUSTOM SEARCH
icon = "file:///android_asset/lightning.png";
searchUrl = mPreferences.getSearchUrl();
break;
case 1:
// GOOGLE_SEARCH;
icon = "file:///android_asset/google.png";
// "https://www.google.com/images/srpr/logo11w.png";
searchUrl = Constants.GOOGLE_SEARCH;
break;
case 2:
// ANDROID SEARCH;
icon = "file:///android_asset/ask.png";
searchUrl = Constants.ASK_SEARCH;
break;
case 3:
// BING_SEARCH;
icon = "file:///android_asset/bing.png";
// "http://upload.wikimedia.org/wikipedia/commons/thumb/b/b1/Bing_logo_%282013%29.svg/500px-Bing_logo_%282013%29.svg.png";
searchUrl = Constants.BING_SEARCH;
break;
case 4:
// YAHOO_SEARCH;
icon = "file:///android_asset/yahoo.png";
// "http://upload.wikimedia.org/wikipedia/commons/thumb/2/24/Yahoo%21_logo.svg/799px-Yahoo%21_logo.svg.png";
searchUrl = Constants.YAHOO_SEARCH;
break;
case 5:
// STARTPAGE_SEARCH;
icon = "file:///android_asset/startpage.png";
// "https://startpage.com/graphics/startp_logo.gif";
searchUrl = Constants.STARTPAGE_SEARCH;
break;
case 6:
// STARTPAGE_MOBILE
icon = "file:///android_asset/startpage.png";
// "https://startpage.com/graphics/startp_logo.gif";
searchUrl = Constants.STARTPAGE_MOBILE_SEARCH;
break;
case 7:
// DUCK_SEARCH;
icon = "file:///android_asset/duckduckgo.png";
// "https://duckduckgo.com/assets/logo_homepage.normal.v101.png";
searchUrl = Constants.DUCK_SEARCH;
break;
case 8:
// DUCK_LITE_SEARCH;
icon = "file:///android_asset/duckduckgo.png";
// "https://duckduckgo.com/assets/logo_homepage.normal.v101.png";
searchUrl = Constants.DUCK_LITE_SEARCH;
break;
case 9:
// BAIDU_SEARCH;
icon = "file:///android_asset/baidu.png";
// "http://www.baidu.com/img/bdlogo.gif";
searchUrl = Constants.BAIDU_SEARCH;
break;
case 10:
// YANDEX_SEARCH;
icon = "file:///android_asset/yandex.png";
// "http://upload.wikimedia.org/wikipedia/commons/thumb/9/91/Yandex.svg/600px-Yandex.svg.png";
searchUrl = Constants.YANDEX_SEARCH;
break;
default:
// DEFAULT GOOGLE_SEARCH;
icon = "file:///android_asset/google.png";
searchUrl = Constants.GOOGLE_SEARCH;
break;
}
homepageBuilder.append(icon);
homepageBuilder.append(StartPage.MIDDLE);
homepageBuilder.append(searchUrl);
homepageBuilder.append(StartPage.END);
File homepage = new File(mActivity.getFilesDir(), StartPage.FILENAME);
FileWriter hWriter = null;
try {
hWriter = new FileWriter(homepage, false);
hWriter.write(homepageBuilder.toString());
} catch (IOException e) {
e.printStackTrace();
} finally {
Utils.close(hWriter);
}
return Constants.FILE + homepage;
}
/**
* Initialize the preference driven settings of the WebView
*
@ -493,7 +391,7 @@ public class LightningView { @@ -493,7 +391,7 @@ public class LightningView {
public void setForegroundTab(boolean isForeground) {
isForegroundTab = isForeground;
mBrowserController.update();
mBrowserController.updateTabs();
}
public boolean isForegroundTab() {
@ -758,7 +656,7 @@ public class LightningView { @@ -758,7 +656,7 @@ public class LightningView {
if (API >= android.os.Build.VERSION_CODES.KITKAT && mInvertPage) {
view.evaluateJavascript(Constants.JAVASCRIPT_INVERT_PAGE, null);
}
mBrowserController.update();
mBrowserController.updateTabs();
}
@Override
@ -769,7 +667,7 @@ public class LightningView { @@ -769,7 +667,7 @@ public class LightningView {
mBrowserController.showActionBar();
}
mTitle.setFavicon(mWebpageBitmap);
mBrowserController.update();
mBrowserController.updateTabs();
}
@Override
@ -958,7 +856,7 @@ public class LightningView { @@ -958,7 +856,7 @@ public class LightningView {
if (icon == null)
return;
mTitle.setFavicon(icon);
mBrowserController.update();
mBrowserController.updateTabs();
cacheFavicon(icon);
}
@ -969,7 +867,7 @@ public class LightningView { @@ -969,7 +867,7 @@ public class LightningView {
} else {
mTitle.setTitle(mActivity.getString(R.string.untitled));
}
mBrowserController.update();
mBrowserController.updateTabs();
if (view != null)
mBrowserController.updateHistory(title, view.getUrl());
}

6
app/src/main/res/layout/tab_drawer.xml

@ -44,15 +44,13 @@ @@ -44,15 +44,13 @@
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
<org.lucasr.twowayview.TwoWayView
<android.support.v7.widget.RecyclerView
android:id="@+id/left_drawer_list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:choiceMode="singleChoice"
android:divider="@null"
android:dividerHeight="0dp"
android:listSelector="?attr/listBackground" />
android:dividerHeight="0dp" />
<LinearLayout
android:layout_width="match_parent"

10
app/src/main/res/layout/tab_list_item.xml

@ -3,7 +3,14 @@ @@ -3,7 +3,14 @@
android:id="@+id/tab_item_background"
android:layout_width="match_parent"
android:layout_height="56dp"
android:background="?attr/selectedBackground"
android:clickable="true"
android:gravity="center_vertical"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/listBackground"
android:gravity="center_vertical"
android:orientation="horizontal"
android:weightSum="1">
@ -49,5 +56,6 @@ @@ -49,5 +56,6 @@
android:contentDescription="Delete Tab"
android:src="@drawable/ic_action_delete" />
</FrameLayout>
</LinearLayout>
</LinearLayout>

1
app/src/main/res/layout/tab_list_item_horizontal.xml

@ -5,6 +5,7 @@ @@ -5,6 +5,7 @@
android:layout_height="match_parent"
android:gravity="center_vertical"
android:orientation="horizontal"
android:clickable="false"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:weightSum="1">

7
app/src/main/res/layout/toolbar.xml

@ -8,18 +8,13 @@ @@ -8,18 +8,13 @@
android:elevation="2dp"
android:orientation="vertical">
<org.lucasr.twowayview.TwoWayView
<android.support.v7.widget.RecyclerView
android:id="@+id/twv_list"
style="@style/TwoWayView"
android:layout_width="match_parent"
android:layout_height="30dp"
android:background="@color/black"
android:listSelector="?attr/listBackground"
android:overScrollMode="never"
android:scrollbars="none" />
<!--
TODO fucking fix the list selector aka remove it
-->
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"

Loading…
Cancel
Save