Browse Source

Added in option to change URL display (url, domain, title), and other minor changes

Additional changes include removing useless code and making some utility
methods not reliant on Context
master
Anthony Restaino 10 years ago
parent
commit
5fb00c08c2
  1. 34
      res/layout/advanced_settings.xml
  2. 6
      res/values/strings.xml
  3. 2
      src/acr/browser/lightning/AboutSettingsActivity.java
  4. 188
      src/acr/browser/lightning/AdvancedSettingsActivity.java
  5. 106
      src/acr/browser/lightning/BrowserActivity.java
  6. 2
      src/acr/browser/lightning/GeneralSettingsActivity.java
  7. 76
      src/acr/browser/lightning/LightningView.java
  8. 1
      src/acr/browser/lightning/PreferenceConstants.java
  9. 53
      src/acr/browser/lightning/SpaceTokenizer.java
  10. 12
      src/acr/browser/lightning/Utils.java

34
res/layout/advanced_settings.xml

@ -221,6 +221,40 @@
android:textColor="@color/light" /> android:textColor="@color/light" />
</LinearLayout> </LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#cdcdcd" />
<LinearLayout
android:id="@+id/rUrlBarContents"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/listChoiceBackgroundIndicator"
android:minHeight="60dp"
android:orientation="vertical"
android:paddingBottom="10dp"
android:paddingTop="10dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="16dp"
android:text="@string/url_contents"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/urlText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="16dp"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/light" />
</LinearLayout>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="1dp" android:layout_height="1dp"

6
res/values/strings.xml

@ -204,4 +204,10 @@
<string name="snacktory">Snacktory</string> <string name="snacktory">Snacktory</string>
<string name="jsoup">jsoup: Java HTML Parser</string> <string name="jsoup">jsoup: Java HTML Parser</string>
<string name="mit_license">MIT License</string> <string name="mit_license">MIT License</string>
<string name="url_contents">URL Box Contents</string>
<string-array name="url_content_array">
<item >Domain (default)</item>
<item >URL</item>
<item >Title</item>
</string-array>
</resources> </resources>

2
src/acr/browser/lightning/AboutSettingsActivity.java

@ -55,7 +55,7 @@ public class AboutSettingsActivity extends ActionBarActivity {
private void initialize() { private void initialize() {
String code = "HOLO"; String code = "1.0";
try { try {
PackageInfo p = getPackageManager().getPackageInfo(getPackageName(), 0); PackageInfo p = getPackageManager().getPackageInfo(getPackageName(), 0);

188
src/acr/browser/lightning/AdvancedSettingsActivity.java

@ -25,11 +25,12 @@ import android.widget.TextView;
public class AdvancedSettingsActivity extends ActionBarActivity { public class AdvancedSettingsActivity extends ActionBarActivity {
private SharedPreferences mPreferences; private SharedPreferences mPreferences;
private SharedPreferences.Editor mEditPrefs;
private CheckBox cbAllowPopups, cbAllowCookies, cbAllowIncognitoCookies, cbRestoreTabs; private CheckBox cbAllowPopups, cbAllowCookies, cbAllowIncognitoCookies, cbRestoreTabs;
private Context mContext; private Context mContext;
private TextView mRenderText; private TextView mRenderText;
private TextView mUrlText;
private Activity mActivity; private Activity mActivity;
private CharSequence[] mUrlOptions;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -48,10 +49,6 @@ public class AdvancedSettingsActivity extends ActionBarActivity {
WindowManager.LayoutParams.FLAG_FULLSCREEN); WindowManager.LayoutParams.FLAG_FULLSCREEN);
} }
// TODO WARNING: SharedPreferences.edit() without a corresponding
// commit() or apply() call
mEditPrefs = mPreferences.edit();
mContext = this; mContext = this;
mActivity = this; mActivity = this;
initialize(); initialize();
@ -66,11 +63,14 @@ public class AdvancedSettingsActivity extends ActionBarActivity {
private void initialize() { private void initialize() {
RelativeLayout rAllowPopups, rAllowCookies, rAllowIncognitoCookies, rRestoreTabs; RelativeLayout rAllowPopups, rAllowCookies, rAllowIncognitoCookies, rRestoreTabs;
LinearLayout lRenderPicker, lUrlContent;
rAllowPopups = (RelativeLayout) findViewById(R.id.rAllowPopups); rAllowPopups = (RelativeLayout) findViewById(R.id.rAllowPopups);
rAllowCookies = (RelativeLayout) findViewById(R.id.rAllowCookies); rAllowCookies = (RelativeLayout) findViewById(R.id.rAllowCookies);
rAllowIncognitoCookies = (RelativeLayout) findViewById(R.id.rAllowIncognitoCookies); rAllowIncognitoCookies = (RelativeLayout) findViewById(R.id.rAllowIncognitoCookies);
rRestoreTabs = (RelativeLayout) findViewById(R.id.rRestoreTabs); rRestoreTabs = (RelativeLayout) findViewById(R.id.rRestoreTabs);
lRenderPicker = (LinearLayout) findViewById(R.id.layoutRendering);
lUrlContent = (LinearLayout) findViewById(R.id.rUrlBarContents);
cbAllowPopups = (CheckBox) findViewById(R.id.cbAllowPopups); cbAllowPopups = (CheckBox) findViewById(R.id.cbAllowPopups);
cbAllowCookies = (CheckBox) findViewById(R.id.cbAllowCookies); cbAllowCookies = (CheckBox) findViewById(R.id.cbAllowCookies);
@ -81,9 +81,11 @@ public class AdvancedSettingsActivity extends ActionBarActivity {
cbAllowCookies.setChecked(mPreferences.getBoolean(PreferenceConstants.COOKIES, true)); cbAllowCookies.setChecked(mPreferences.getBoolean(PreferenceConstants.COOKIES, true));
cbAllowIncognitoCookies.setChecked(mPreferences.getBoolean( cbAllowIncognitoCookies.setChecked(mPreferences.getBoolean(
PreferenceConstants.INCOGNITO_COOKIES, false)); PreferenceConstants.INCOGNITO_COOKIES, false));
cbRestoreTabs.setChecked(mPreferences.getBoolean(PreferenceConstants.RESTORE_LOST_TABS, true)); cbRestoreTabs.setChecked(mPreferences.getBoolean(PreferenceConstants.RESTORE_LOST_TABS,
true));
mRenderText = (TextView) findViewById(R.id.renderText); mRenderText = (TextView) findViewById(R.id.renderText);
mUrlText = (TextView) findViewById(R.id.urlText);
switch (mPreferences.getInt(PreferenceConstants.RENDERING_MODE, 0)) { switch (mPreferences.getInt(PreferenceConstants.RENDERING_MODE, 0)) {
case 0: case 0:
@ -100,119 +102,81 @@ public class AdvancedSettingsActivity extends ActionBarActivity {
break; break;
} }
rAllowPopups(rAllowPopups); mUrlOptions = this.getResources().getStringArray(R.array.url_content_array);
rAllowCookies(rAllowCookies); int option = mPreferences.getInt(PreferenceConstants.URL_BOX_CONTENTS, 0);
rAllowIncognitoCookies(rAllowIncognitoCookies); mUrlText.setText(mUrlOptions[option]);
rRestoreTabs(rRestoreTabs);
cbAllowPopups(cbAllowPopups);
cbAllowCookies(cbAllowCookies);
cbAllowIncognitoCookies(cbAllowIncognitoCookies);
cbRestoreTabs(cbRestoreTabs);
renderPicker();
}
private void cbAllowPopups(CheckBox view) {
view.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mEditPrefs.putBoolean(PreferenceConstants.POPUPS, isChecked);
mEditPrefs.apply();
}
});
}
private void cbAllowCookies(CheckBox view) {
view.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mEditPrefs.putBoolean(PreferenceConstants.COOKIES, isChecked);
mEditPrefs.apply();
}
});
}
private void cbAllowIncognitoCookies(CheckBox view) {
view.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mEditPrefs.putBoolean(PreferenceConstants.INCOGNITO_COOKIES, isChecked);
mEditPrefs.apply();
}
}); LayoutClickListener listener = new LayoutClickListener();
} CheckListener cListener = new CheckListener();
private void cbRestoreTabs(CheckBox view) { rAllowPopups.setOnClickListener(listener);
view.setOnCheckedChangeListener(new OnCheckedChangeListener() { rAllowCookies.setOnClickListener(listener);
rAllowIncognitoCookies.setOnClickListener(listener);
rRestoreTabs.setOnClickListener(listener);
lRenderPicker.setOnClickListener(listener);
lUrlContent.setOnClickListener(listener);
@Override cbAllowPopups.setOnCheckedChangeListener(cListener);
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { cbAllowCookies.setOnCheckedChangeListener(cListener);
mEditPrefs.putBoolean(PreferenceConstants.RESTORE_LOST_TABS, isChecked); cbAllowIncognitoCookies.setOnCheckedChangeListener(cListener);
mEditPrefs.apply(); cbRestoreTabs.setOnCheckedChangeListener(cListener);
}
});
} }
private void rAllowPopups(RelativeLayout view) { private class LayoutClickListener implements OnClickListener {
view.setOnClickListener(new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
// TODO Auto-generated method stub switch (v.getId()) {
case R.id.rAllowPopups:
cbAllowPopups.setChecked(!cbAllowPopups.isChecked()); cbAllowPopups.setChecked(!cbAllowPopups.isChecked());
} break;
case R.id.rAllowIncognitoCookies:
}); cbAllowIncognitoCookies.setChecked(!cbAllowIncognitoCookies.isChecked());
} break;
case R.id.rAllowCookies:
private void rAllowCookies(RelativeLayout view) {
view.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
cbAllowCookies.setChecked(!cbAllowCookies.isChecked()); cbAllowCookies.setChecked(!cbAllowCookies.isChecked());
break;
case R.id.rRestoreTabs:
cbRestoreTabs.setChecked(!cbRestoreTabs.isChecked());
break;
case R.id.layoutRendering:
renderPicker();
break;
case R.id.rUrlBarContents:
urlBoxPicker();
break;
} }
});
}
private void rAllowIncognitoCookies(RelativeLayout view) {
view.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
cbAllowIncognitoCookies.setChecked(!cbAllowIncognitoCookies.isChecked());
} }
});
} }
private void rRestoreTabs(RelativeLayout view) { private class CheckListener implements OnCheckedChangeListener {
view.setOnClickListener(new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
cbRestoreTabs.setChecked(!cbRestoreTabs.isChecked()); switch (buttonView.getId()) {
case R.id.cbAllowPopups:
mPreferences.edit().putBoolean(PreferenceConstants.POPUPS, isChecked).apply();
break;
case R.id.cbAllowCookies:
mPreferences.edit().putBoolean(PreferenceConstants.COOKIES, isChecked).apply();
break;
case R.id.cbAllowIncognitoCookies:
mPreferences.edit()
.putBoolean(PreferenceConstants.INCOGNITO_COOKIES, isChecked).apply();
break;
case R.id.cbRestoreTabs:
mPreferences.edit()
.putBoolean(PreferenceConstants.RESTORE_LOST_TABS, isChecked).apply();
break;
}
} }
});
} }
public void renderPicker() { public void renderPicker() {
LinearLayout layout = (LinearLayout) findViewById(R.id.layoutRendering);
layout.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder picker = new AlertDialog.Builder(mActivity); AlertDialog.Builder picker = new AlertDialog.Builder(mActivity);
picker.setTitle(getResources().getString(R.string.rendering_mode)); picker.setTitle(getResources().getString(R.string.rendering_mode));
CharSequence[] chars = { mContext.getString(R.string.name_normal), CharSequence[] chars = { mContext.getString(R.string.name_normal),
@ -226,7 +190,7 @@ public class AdvancedSettingsActivity extends ActionBarActivity {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
mEditPrefs.putInt(PreferenceConstants.RENDERING_MODE, which).apply(); mPreferences.edit().putInt(PreferenceConstants.RENDERING_MODE, which).apply();
switch (which) { switch (which) {
case 0: case 0:
mRenderText.setText(mContext.getString(R.string.name_normal)); mRenderText.setText(mContext.getString(R.string.name_normal));
@ -238,8 +202,7 @@ public class AdvancedSettingsActivity extends ActionBarActivity {
mRenderText.setText(mContext.getString(R.string.name_grayscale)); mRenderText.setText(mContext.getString(R.string.name_grayscale));
break; break;
case 3: case 3:
mRenderText.setText(mContext mRenderText.setText(mContext.getString(R.string.name_inverted_grayscale));
.getString(R.string.name_inverted_grayscale));
break; break;
} }
} }
@ -255,11 +218,32 @@ public class AdvancedSettingsActivity extends ActionBarActivity {
picker.show(); picker.show();
} }
}); public void urlBoxPicker() {
AlertDialog.Builder picker = new AlertDialog.Builder(mActivity);
picker.setTitle(getResources().getString(R.string.url_contents));
int n = mPreferences.getInt(PreferenceConstants.URL_BOX_CONTENTS, 0);
picker.setSingleChoiceItems(mUrlOptions, n, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
mPreferences.edit().putInt(PreferenceConstants.URL_BOX_CONTENTS, which).apply();
if (which < mUrlOptions.length) {
mUrlText.setText(mUrlOptions[which]);
} }
}
});
picker.setNeutralButton(getResources().getString(R.string.action_ok),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
public void importFromStockBrowser() {
BookmarkManager manager = new BookmarkManager(this);
manager.importBookmarksFromBrowser();
} }
});
picker.show();
}
} }

106
src/acr/browser/lightning/BrowserActivity.java

@ -11,8 +11,7 @@ import android.annotation.SuppressLint;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.content.*; import android.content.*;
import android.content.res.Resources.Theme; import android.content.res.Configuration;
import android.content.res.TypedArray;
import android.database.Cursor; import android.database.Cursor;
import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteException;
import android.graphics.Bitmap; import android.graphics.Bitmap;
@ -37,7 +36,6 @@ import android.support.v4.widget.DrawerLayout;
import android.support.v4.widget.DrawerLayout.DrawerListener; import android.support.v4.widget.DrawerLayout.DrawerListener;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.util.TypedValue;
import android.view.*; import android.view.*;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener; import android.view.View.OnFocusChangeListener;
@ -97,7 +95,6 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl
private ValueCallback<Uri> mUploadMessage; private ValueCallback<Uri> mUploadMessage;
private View mCustomView; private View mCustomView;
private int mOriginalOrientation; private int mOriginalOrientation;
private int mActionBarSize;
private ActionBar mActionBar; private ActionBar mActionBar;
private boolean mFullScreen; private boolean mFullScreen;
private boolean mColorMode; private boolean mColorMode;
@ -113,10 +110,10 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl
private LinearLayout mToolbarLayout; private LinearLayout mToolbarLayout;
private HistoryDatabaseHandler mHistoryHandler; private HistoryDatabaseHandler mHistoryHandler;
private SharedPreferences mPreferences; private SharedPreferences mPreferences;
private SharedPreferences.Editor mEditPrefs;
private Context mContext; private Context mContext;
private Bitmap mWebpageBitmap; private Bitmap mWebpageBitmap;
private String mSearchText; private String mSearchText;
private String mUntitledTitle;
private Activity mActivity; private Activity mActivity;
private final int API = android.os.Build.VERSION.SDK_INT; private final int API = android.os.Build.VERSION.SDK_INT;
private Drawable mDeleteIcon; private Drawable mDeleteIcon;
@ -144,11 +141,7 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl
mToolbar = (Toolbar) findViewById(R.id.toolbar); mToolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(mToolbar); setSupportActionBar(mToolbar);
TypedValue typedValue = new TypedValue();
Theme theme = getTheme();
theme.resolveAttribute(R.attr.numberColor, typedValue, true);
mPreferences = getSharedPreferences(PreferenceConstants.PREFERENCES, 0); mPreferences = getSharedPreferences(PreferenceConstants.PREFERENCES, 0);
mEditPrefs = mPreferences.edit();
mContext = this; mContext = this;
if (mWebViews != null) { if (mWebViews != null) {
mWebViews.clear(); mWebViews.clear();
@ -159,7 +152,8 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl
if (!mPreferences.getBoolean(PreferenceConstants.OLD_BOOKMARKS_IMPORTED, false)) { if (!mPreferences.getBoolean(PreferenceConstants.OLD_BOOKMARKS_IMPORTED, false)) {
List<HistoryItem> old = Utils.getOldBookmarks(this); List<HistoryItem> old = Utils.getOldBookmarks(this);
mBookmarkManager.addBookmarkList(old); mBookmarkManager.addBookmarkList(old);
mEditPrefs.putBoolean(PreferenceConstants.OLD_BOOKMARKS_IMPORTED, true).apply(); mPreferences.edit().putBoolean(PreferenceConstants.OLD_BOOKMARKS_IMPORTED, true)
.apply();
} }
mActivity = this; mActivity = this;
mClickHandler = new ClickHandler(this); mClickHandler = new ClickHandler(this);
@ -168,8 +162,6 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl
mPageLayout = (LinearLayout) findViewById(R.id.main_layout); mPageLayout = (LinearLayout) findViewById(R.id.main_layout);
mUiLayout = (LinearLayout) findViewById(R.id.ui_layout); mUiLayout = (LinearLayout) findViewById(R.id.ui_layout);
mProgressBar = (AnimatedProgressBar) findViewById(R.id.progress_view); mProgressBar = (AnimatedProgressBar) findViewById(R.id.progress_view);
// mProgressBar.setVisibility(View.GONE);
// TODO
mNewTab = (RelativeLayout) findViewById(R.id.new_tab_button); mNewTab = (RelativeLayout) findViewById(R.id.new_tab_button);
mDrawerLeft = (LinearLayout) findViewById(R.id.left_drawer); mDrawerLeft = (LinearLayout) findViewById(R.id.left_drawer);
mDrawerLeft.setLayerType(View.LAYER_TYPE_HARDWARE, null); // Drawer mDrawerLeft.setLayerType(View.LAYER_TYPE_HARDWARE, null); // Drawer
@ -190,13 +182,6 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl
mWebpageBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_webpage); mWebpageBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_webpage);
mActionBar = getSupportActionBar(); mActionBar = getSupportActionBar();
final TypedArray styledAttributes = mContext.getTheme().obtainStyledAttributes(
new int[] { android.R.attr.actionBarSize });
mActionBarSize = (int) styledAttributes.getDimension(0, 0);
if (pixelsToDp(mActionBarSize) < 48) {
mActionBarSize = Utils.convertDpiToPixels(mContext, 48);
}
styledAttributes.recycle();
mHomepage = mPreferences.getString(PreferenceConstants.HOMEPAGE, Constants.HOMEPAGE); mHomepage = mPreferences.getString(PreferenceConstants.HOMEPAGE, Constants.HOMEPAGE);
@ -211,9 +196,7 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl
mDrawerListRight.setOnItemClickListener(new BookmarkItemClickListener()); mDrawerListRight.setOnItemClickListener(new BookmarkItemClickListener());
mDrawerListRight.setOnItemLongClickListener(new BookmarkItemLongClickListener()); mDrawerListRight.setOnItemLongClickListener(new BookmarkItemLongClickListener());
if (mHistoryHandler == null) { if (mHistoryHandler == null || !mHistoryHandler.isOpen()) {
mHistoryHandler = new HistoryDatabaseHandler(this);
} else if (!mHistoryHandler.isOpen()) {
mHistoryHandler = new HistoryDatabaseHandler(this); mHistoryHandler = new HistoryDatabaseHandler(this);
} }
@ -293,15 +276,16 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl
// create the search EditText in the ToolBar // create the search EditText in the ToolBar
mSearch = (AutoCompleteTextView) mActionBar.getCustomView().findViewById(R.id.search); mSearch = (AutoCompleteTextView) mActionBar.getCustomView().findViewById(R.id.search);
mUntitledTitle = (String) this.getString(R.string.untitled);
mDeleteIcon = getResources().getDrawable(R.drawable.ic_action_delete); mDeleteIcon = getResources().getDrawable(R.drawable.ic_action_delete);
mDeleteIcon.setBounds(0, 0, Utils.convertDpiToPixels(mContext, 24), mDeleteIcon.setBounds(0, 0, Utils.convertDpToPixels(24),
Utils.convertDpiToPixels(mContext, 24)); Utils.convertDpToPixels(24));
mRefreshIcon = getResources().getDrawable(R.drawable.ic_action_refresh); mRefreshIcon = getResources().getDrawable(R.drawable.ic_action_refresh);
mRefreshIcon.setBounds(0, 0, Utils.convertDpiToPixels(mContext, 24), mRefreshIcon.setBounds(0, 0, Utils.convertDpToPixels(24),
Utils.convertDpiToPixels(mContext, 24)); Utils.convertDpToPixels(24));
mCopyIcon = getResources().getDrawable(R.drawable.ic_action_copy); mCopyIcon = getResources().getDrawable(R.drawable.ic_action_copy);
mCopyIcon.setBounds(0, 0, Utils.convertDpiToPixels(mContext, 24), mCopyIcon.setBounds(0, 0, Utils.convertDpToPixels(24),
Utils.convertDpiToPixels(mContext, 24)); Utils.convertDpToPixels(24));
mIcon = mRefreshIcon; mIcon = mRefreshIcon;
SearchClass search = new SearchClass(); SearchClass search = new SearchClass();
mSearch.setCompoundDrawables(null, null, mRefreshIcon, null); mSearch.setCompoundDrawables(null, null, mRefreshIcon, null);
@ -339,7 +323,7 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl
newTab(url, true); newTab(url, true);
Toast.makeText(mContext, R.string.deleted_tab, Toast.LENGTH_SHORT).show(); Toast.makeText(mContext, R.string.deleted_tab, Toast.LENGTH_SHORT).show();
} }
mEditPrefs.putString(PreferenceConstants.SAVE_URL, null).apply(); mPreferences.edit().putString(PreferenceConstants.SAVE_URL, null).apply();
return true; return true;
} }
@ -641,8 +625,7 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl
OrbotHelper oh = new OrbotHelper(this); OrbotHelper oh = new OrbotHelper(this);
if (oh.isOrbotInstalled() if (oh.isOrbotInstalled()
&& !mPreferences.getBoolean(PreferenceConstants.INITIAL_CHECK_FOR_TOR, false)) { && !mPreferences.getBoolean(PreferenceConstants.INITIAL_CHECK_FOR_TOR, false)) {
mEditPrefs.putBoolean(PreferenceConstants.INITIAL_CHECK_FOR_TOR, true); mPreferences.edit().putBoolean(PreferenceConstants.INITIAL_CHECK_FOR_TOR, true).apply();
mEditPrefs.apply();
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
@ -671,8 +654,7 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl
initializeTor(); initializeTor();
return true; return true;
} else { } else {
mEditPrefs.putBoolean(PreferenceConstants.USE_PROXY, false); mPreferences.edit().putBoolean(PreferenceConstants.USE_PROXY, false).apply();
mEditPrefs.apply();
return false; return false;
} }
} }
@ -697,9 +679,19 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl
} }
public void setNavigationDrawerWidth() { private boolean isTablet() {
int width = getResources().getDisplayMetrics().widthPixels * 3 / 4; return (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE;
int maxWidth = Utils.convertDpiToPixels(mContext, 300); }
private void setNavigationDrawerWidth() {
int width = getResources().getDisplayMetrics().widthPixels
- Utils.convertDpToPixels(56);
int maxWidth;
if(isTablet()){
maxWidth = Utils.convertDpToPixels(320);
} else {
maxWidth = Utils.convertDpToPixels(300);
}
if (width > maxWidth) { if (width > maxWidth) {
DrawerLayout.LayoutParams params = (android.support.v4.widget.DrawerLayout.LayoutParams) mDrawerLeft DrawerLayout.LayoutParams params = (android.support.v4.widget.DrawerLayout.LayoutParams) mDrawerLeft
.getLayoutParams(); .getLayoutParams();
@ -747,7 +739,7 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl
} }
if (mPreferences.getBoolean(PreferenceConstants.RESTORE_LOST_TABS, true)) { if (mPreferences.getBoolean(PreferenceConstants.RESTORE_LOST_TABS, true)) {
String mem = mPreferences.getString(PreferenceConstants.URL_MEMORY, ""); String mem = mPreferences.getString(PreferenceConstants.URL_MEMORY, "");
mEditPrefs.putString(PreferenceConstants.URL_MEMORY, "").apply(); mPreferences.edit().putString(PreferenceConstants.URL_MEMORY, "").apply();
String[] array = Utils.getArray(mem); String[] array = Utils.getArray(mem);
int count = 0; int count = 0;
for (int n = 0; n < array.length; n++) { for (int n = 0; n < array.length; n++) {
@ -1198,6 +1190,7 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl
} }
mCurrentView = view; mCurrentView = view;
mCurrentView.setForegroundTab(true); mCurrentView.setForegroundTab(true);
mCurrentView.requestFocus();
if (mCurrentView.getWebView() != null) { if (mCurrentView.getWebView() != null) {
updateUrl(mCurrentView.getUrl(), true); updateUrl(mCurrentView.getUrl(), true);
updateProgress(mCurrentView.getProgress()); updateProgress(mCurrentView.getProgress());
@ -1309,7 +1302,7 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl
return; return;
} }
if (reference.getUrl() != null && !reference.getUrl().startsWith(Constants.FILE)) { if (reference.getUrl() != null && !reference.getUrl().startsWith(Constants.FILE)) {
mEditPrefs.putString(PreferenceConstants.SAVE_URL, reference.getUrl()).apply(); mPreferences.edit().putString(PreferenceConstants.SAVE_URL, reference.getUrl()).apply();
} }
boolean isShown = reference.isShown(); boolean isShown = reference.isShown();
if (current > position) { if (current > position) {
@ -1455,7 +1448,9 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl
} else { } else {
if (mCurrentView != null) { if (mCurrentView != null) {
Log.d(Constants.TAG, "onBackPressed"); Log.d(Constants.TAG, "onBackPressed");
if (mCurrentView.canGoBack()) { if (!mCurrentView.getWebView().hasFocus()) {
mCurrentView.requestFocus();
} else if (mCurrentView.canGoBack()) {
if (!mCurrentView.isShown()) { if (!mCurrentView.isShown()) {
onHideCustomView(); onHideCustomView();
} else { } else {
@ -1495,7 +1490,7 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl
s = s + mWebViews.get(n).getUrl() + "|$|SEPARATOR|$|"; s = s + mWebViews.get(n).getUrl() + "|$|SEPARATOR|$|";
} }
} }
mEditPrefs.putString(PreferenceConstants.URL_MEMORY, s).commit(); mPreferences.edit().putString(PreferenceConstants.URL_MEMORY, s).apply();
} }
} }
@ -1588,11 +1583,6 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl
} }
} }
private int pixelsToDp(int num) {
float scale = getResources().getDisplayMetrics().density;
return (int) ((num - 0.5f) / scale);
}
public class LightningViewAdapter extends ArrayAdapter<LightningView> { public class LightningViewAdapter extends ArrayAdapter<LightningView> {
Context context; Context context;
@ -1852,7 +1842,7 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl
} }
protected void onPostExecute(Bitmap result) { protected void onPostExecute(Bitmap result) {
Bitmap fav = Utils.padFavicon(result, mContext); Bitmap fav = Utils.padFavicon(result);
bmImage.setImageBitmap(fav); bmImage.setImageBitmap(fav);
mWeb.setBitmap(fav); mWeb.setBitmap(fav);
notifyBookmarkDataSetChanged(); notifyBookmarkDataSetChanged();
@ -1873,13 +1863,25 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl
if (url == null || mSearch == null || mSearch.hasFocus()) { if (url == null || mSearch == null || mSearch.hasFocus()) {
return; return;
} }
if (shortUrl) { if (shortUrl && !url.startsWith(Constants.FILE)) {
switch (mPreferences.getInt(PreferenceConstants.URL_BOX_CONTENTS, 0)) {
case 0: // Default, show only the domain
url = url.replaceFirst(Constants.HTTP, ""); url = url.replaceFirst(Constants.HTTP, "");
if (url.startsWith(Constants.FILE)) {
url = "";
}
url = Utils.getDomainName(url); url = Utils.getDomainName(url);
mSearch.setText(url); mSearch.setText(url);
break;
case 1: // URL, show the entire URL
mSearch.setText(url);
break;
case 2: // Title, show the page's title
if (mCurrentView != null && !mCurrentView.getTitle().isEmpty()) {
mSearch.setText(mCurrentView.getTitle());
} else {
mSearch.setText(mUntitledTitle);
}
break;
}
} else { } else {
if (url.startsWith(Constants.FILE)) { if (url.startsWith(Constants.FILE)) {
url = ""; url = "";
@ -1978,8 +1980,8 @@ public class BrowserActivity extends ActionBarActivity implements BrowserControl
c.close(); c.close();
c = null; c = null;
} }
mEditPrefs.putBoolean("SystemBrowser", browserFlag); mPreferences.edit().putBoolean(PreferenceConstants.SYSTEM_BROWSER_PRESENT, browserFlag)
mEditPrefs.commit(); .apply();
return browserFlag; return browserFlag;
} }

2
src/acr/browser/lightning/GeneralSettingsActivity.java

@ -431,7 +431,7 @@ public class GeneralSettingsActivity extends ActionBarActivity {
getDownload.setBackgroundResource(0); getDownload.setBackgroundResource(0);
mDownloadLocation = mPreferences.getString(PreferenceConstants.DOWNLOAD_DIRECTORY, mDownloadLocation = mPreferences.getString(PreferenceConstants.DOWNLOAD_DIRECTORY,
Environment.DIRECTORY_DOWNLOADS); Environment.DIRECTORY_DOWNLOADS);
int padding = Utils.convertDpiToPixels(this, 10); int padding = Utils.convertDpToPixels(10);
LinearLayout.LayoutParams lparams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams lparams = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT); LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);

76
src/acr/browser/lightning/LightningView.java

@ -70,7 +70,7 @@ public class LightningView {
mWebView = new WebView(activity); mWebView = new WebView(activity);
mTitle = new Title(activity); mTitle = new Title(activity);
mAdBlock = new AdBlock(activity); mAdBlock = new AdBlock(activity);
activity.getPackageName();
mWebpageBitmap = BitmapFactory.decodeResource(activity.getResources(), mWebpageBitmap = BitmapFactory.decodeResource(activity.getResources(),
R.drawable.ic_webpage); R.drawable.ic_webpage);
@ -101,41 +101,7 @@ public class LightningView {
mWebView.setWebViewClient(new LightningWebClient(activity)); mWebView.setWebViewClient(new LightningWebClient(activity));
mWebView.setDownloadListener(new LightningDownloadListener(activity)); mWebView.setDownloadListener(new LightningDownloadListener(activity));
mGestureDetector = new GestureDetector(activity, new CustomGestureListener()); mGestureDetector = new GestureDetector(activity, new CustomGestureListener());
mWebView.setOnTouchListener(new OnTouchListener() { mWebView.setOnTouchListener(new TouchListener());
float mLocation;
float mY;
int mAction;
@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouch(View view, MotionEvent arg1) {
if (view != null && !view.hasFocus()) {
view.requestFocus();
}
mAction = arg1.getAction();
mY = arg1.getY();
if (mAction == MotionEvent.ACTION_DOWN) {
mLocation = mY;
} else if (mAction == MotionEvent.ACTION_UP) {
if ((mY - mLocation) > 10) {
if (mWebView.getScrollY() != 0) {
mBrowserController.showActionBar();
} else {
mBrowserController.toggleActionBar();
}
} else if ((mY - mLocation) < -10) {
mBrowserController.hideActionBar();
}
mLocation = 0;
}
mGestureDetector.onTouchEvent(arg1);
return false;
}
});
mDefaultUserAgent = mWebView.getSettings().getUserAgentString(); mDefaultUserAgent = mWebView.getSettings().getUserAgentString();
mSettings = mWebView.getSettings(); mSettings = mWebView.getSettings();
initializeSettings(mWebView.getSettings(), activity); initializeSettings(mWebView.getSettings(), activity);
@ -1129,7 +1095,7 @@ public class LightningView {
if (favicon == null) { if (favicon == null) {
mFavicon = mDefaultIcon; mFavicon = mDefaultIcon;
} else { } else {
mFavicon = Utils.padFavicon(favicon, mActivity); mFavicon = Utils.padFavicon(favicon);
} }
} }
@ -1147,7 +1113,7 @@ public class LightningView {
if (favicon == null) { if (favicon == null) {
mFavicon = mDefaultIcon; mFavicon = mDefaultIcon;
} else { } else {
mFavicon = Utils.padFavicon(favicon, mActivity); mFavicon = Utils.padFavicon(favicon);
} }
} }
@ -1161,6 +1127,40 @@ public class LightningView {
} }
private class TouchListener implements OnTouchListener {
float mLocation;
float mY;
int mAction;
@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouch(View view, MotionEvent arg1) {
if (view != null && !view.hasFocus()) {
view.requestFocus();
}
mAction = arg1.getAction();
mY = arg1.getY();
if (mAction == MotionEvent.ACTION_DOWN) {
mLocation = mY;
} else if (mAction == MotionEvent.ACTION_UP) {
if ((mY - mLocation) > 10) {
if (mWebView.getScrollY() != 0) {
mBrowserController.showActionBar();
} else {
mBrowserController.toggleActionBar();
}
} else if ((mY - mLocation) < -10) {
mBrowserController.hideActionBar();
}
mLocation = 0;
}
mGestureDetector.onTouchEvent(arg1);
return false;
}
}
private class CustomGestureListener extends SimpleOnGestureListener { private class CustomGestureListener extends SimpleOnGestureListener {
/** /**

1
src/acr/browser/lightning/PreferenceConstants.java

@ -42,6 +42,7 @@ public final class PreferenceConstants {
public static final String SYNC_HISTORY = "syncHistory"; public static final String SYNC_HISTORY = "syncHistory";
public static final String BLOCK_THIRD_PARTY = "thirdParty"; public static final String BLOCK_THIRD_PARTY = "thirdParty";
public static final String ENABLE_COLOR_MODE = "colorMode"; public static final String ENABLE_COLOR_MODE = "colorMode";
public static final String URL_BOX_CONTENTS = "urlContent";
public static final String USE_PROXY = "useProxy"; public static final String USE_PROXY = "useProxy";
public static final String USE_PROXY_HOST = "useProxyHost"; public static final String USE_PROXY_HOST = "useProxyHost";

53
src/acr/browser/lightning/SpaceTokenizer.java

@ -1,53 +0,0 @@
/*
* Copyright 2014 A.C.R. Development
*/
package acr.browser.lightning;
import android.widget.MultiAutoCompleteTextView.Tokenizer;
public class SpaceTokenizer implements Tokenizer {
@Override
public int findTokenEnd(CharSequence text, int cursor) {
// int i = cursor;
// int len = text.length();
/*
* while (i < len) { if (text.charAt(i) == ' ') { return i; } else {
* i++; } }
*/
return text.length();
}
@Override
public int findTokenStart(CharSequence text, int cursor) {
int i = cursor;
while (i > 0 && text.charAt(i - 1) != ' ') {
i--;
}
while (i < cursor && text.charAt(i) == ' ') {
i++;
}
return i;
}
@Override
public CharSequence terminateToken(CharSequence text) {
// int i = text.length();
if (text.charAt(text.length() - 1) != ' ') {
text = text + " ";
}
return text;
/*
* while (i > 0 && text.charAt(i - 1) == ' ') { i--; }
*
* if (i > 0 && text.charAt(i - 1) == ' ') { return text; } else { if
* (text instanceof Spanned) { SpannableString sp = new
* SpannableString(text + " "); TextUtils.copySpansFrom((Spanned) text,
* 0, text.length(), Object.class, sp, 0); return sp; } else { return
* text + " "; } }
*/
}
}

12
src/acr/browser/lightning/Utils.java

@ -8,9 +8,11 @@ import android.app.AlertDialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Paint; import android.graphics.Paint;
import android.util.DisplayMetrics;
import android.util.Log; import android.util.Log;
import android.webkit.URLUtil; import android.webkit.URLUtil;
import android.widget.Toast; import android.widget.Toast;
@ -67,9 +69,9 @@ public final class Utils {
/** /**
* Returns the number of pixels corresponding to the passed density pixels * Returns the number of pixels corresponding to the passed density pixels
*/ */
public static int convertDpiToPixels(Context context, int densityPixels) { public static int convertDpToPixels(int dp) {
float scale = context.getResources().getDisplayMetrics().density; DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics();
return (int) (densityPixels * scale + 0.5f); return (int) (dp * metrics.density + 0.5f);
} }
public static String getDomainName(String url) { public static String getDomainName(String url) {
@ -160,8 +162,8 @@ public final class Utils {
* is the bitmap to pad. * is the bitmap to pad.
* @return the padded bitmap. * @return the padded bitmap.
*/ */
public static Bitmap padFavicon(Bitmap bitmap, Context context) { public static Bitmap padFavicon(Bitmap bitmap) {
int padding = Utils.convertDpiToPixels(context, 4); int padding = Utils.convertDpToPixels(4);
Bitmap paddedBitmap = Bitmap.createBitmap(bitmap.getWidth() + padding, bitmap.getHeight() Bitmap paddedBitmap = Bitmap.createBitmap(bitmap.getWidth() + padding, bitmap.getHeight()
+ padding, Bitmap.Config.ARGB_8888); + padding, Bitmap.Config.ARGB_8888);

Loading…
Cancel
Save