Browse Source

rebase test for main settings screen

master
DF1E 9 years ago
parent
commit
a03444f4d0
  1. 421
      app/src/main/java/acr/browser/lightning/activity/SettingsActivity.java
  2. 262
      app/src/main/java/acr/browser/lightning/fragment/SettingsFragment.java
  3. 53
      app/src/main/java/acr/browser/lightning/utils/Utils.java
  4. 405
      app/src/main/res/layout/settings.xml
  5. 74
      app/src/main/res/xml/main_preferences.xml

421
app/src/main/java/acr/browser/lightning/activity/SettingsActivity.java

@ -3,441 +3,28 @@ @@ -3,441 +3,28 @@
*/
package acr.browser.lightning.activity;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import acr.browser.lightning.R;
import acr.browser.lightning.constant.Constants;
import acr.browser.lightning.preference.PreferenceManager;
import acr.browser.lightning.utils.ProxyUtils;
import acr.browser.lightning.utils.Utils;
public class SettingsActivity extends ThemableSettingsActivity {
private static final int API = android.os.Build.VERSION.SDK_INT;
private PreferenceManager mPreferences;
private Context mContext;
private Activity mActivity;
private CharSequence[] mProxyChoices;
private TextView mProxyChoiceName;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.settings);
mContext = this;
mActivity = this;
init();
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
finish();
return true;
}
@SuppressLint("NewApi")
private void init() {
// set up ActionBar
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
// mPreferences storage
mPreferences = PreferenceManager.getInstance();
// initialize UI
RelativeLayout layoutFlash = (RelativeLayout) findViewById(R.id.layoutFlash);
RelativeLayout layoutBlockAds = (RelativeLayout) findViewById(R.id.layoutAdBlock);
layoutBlockAds.setEnabled(Constants.FULL_VERSION);
RelativeLayout layoutImages = (RelativeLayout) findViewById(R.id.layoutImages);
RelativeLayout layoutEnableJS = (RelativeLayout) findViewById(R.id.layoutEnableJS);
LinearLayout layoutProxyChoice = (LinearLayout) findViewById(R.id.layoutProxyChoice);
RelativeLayout layoutColor = (RelativeLayout) findViewById(R.id.layoutColorMode);
RelativeLayout layoutBookmarks = (RelativeLayout) findViewById(R.id.layoutBookmarks);
layoutBookmarks.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(mContext, BookmarkActivity.class));
}
});
if (API >= 19) {
mPreferences.setFlashSupport(0);
}
int flashNum = mPreferences.getFlashSupport();
boolean imagesBool = mPreferences.getBlockImagesEnabled();
boolean enableJSBool = mPreferences.getJavaScriptEnabled();
mProxyChoiceName = (TextView) findViewById(R.id.proxyChoiceName);
mProxyChoices = this.getResources().getStringArray(R.array.proxy_choices_array);
int choice = mPreferences.getProxyChoice();
if (choice == Constants.PROXY_MANUAL)
mProxyChoiceName.setText(mPreferences.getProxyHost() + ":" + mPreferences.getProxyPort());
else
mProxyChoiceName.setText(mProxyChoices[choice]);
CheckBox flash = (CheckBox) findViewById(R.id.cbFlash);
CheckBox adblock = (CheckBox) findViewById(R.id.cbAdblock);
adblock.setEnabled(Constants.FULL_VERSION);
CheckBox images = (CheckBox) findViewById(R.id.cbImageBlock);
CheckBox enablejs = (CheckBox) findViewById(R.id.cbJavascript);
CheckBox color = (CheckBox) findViewById(R.id.cbColorMode);
images.setChecked(imagesBool);
enablejs.setChecked(enableJSBool);
if (flashNum > 0) {
flash.setChecked(true);
} else {
flash.setChecked(false);
}
adblock.setChecked(mPreferences.getAdBlockEnabled());
color.setChecked(mPreferences.getColorModeEnabled());
initCheckBox(flash, adblock, images, enablejs, color);
clickListenerForCheckBoxes(layoutFlash, layoutBlockAds, layoutImages, layoutEnableJS,
layoutProxyChoice, layoutColor, flash, adblock, images, enablejs, color);
RelativeLayout general = (RelativeLayout) findViewById(R.id.layoutGeneral);
RelativeLayout display = (RelativeLayout) findViewById(R.id.layoutDisplay);
RelativeLayout privacy = (RelativeLayout) findViewById(R.id.layoutPrivacy);
RelativeLayout advanced = (RelativeLayout) findViewById(R.id.layoutAdvanced);
RelativeLayout about = (RelativeLayout) findViewById(R.id.layoutAbout);
general(general);
display(display);
privacy(privacy);
advanced(advanced);
about(about);
}
public void clickListenerForCheckBoxes(RelativeLayout layoutFlash,
RelativeLayout layoutBlockAds, RelativeLayout layoutImages,
RelativeLayout layoutEnableJS, LinearLayout layoutProxyChoice, RelativeLayout layoutColor,
final CheckBox flash, final CheckBox adblock, final CheckBox images,
final CheckBox enablejs, final CheckBox color) {
layoutFlash.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (API < 19) {
flash.setChecked(!flash.isChecked());
} else {
Utils.createInformativeDialog(mContext,
getResources().getString(R.string.title_warning), getResources()
.getString(R.string.dialog_adobe_dead));
}
}
});
layoutBlockAds.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
adblock.setChecked(!adblock.isChecked());
}
});
layoutImages.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
images.setChecked(!images.isChecked());
}
});
layoutEnableJS.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
enablejs.setChecked(!enablejs.isChecked());
}
});
if (Constants.FULL_VERSION == false) {
layoutProxyChoice.setEnabled(false);
}
layoutProxyChoice.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
proxyChoicePicker();
}
});
layoutColor.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
color.setChecked(!color.isChecked());
}
});
}
public void initCheckBox(CheckBox flash, CheckBox adblock, CheckBox images, CheckBox enablejs,
CheckBox color) {
flash.setEnabled(API < 19);
flash.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
getFlashChoice();
} else {
mPreferences.setFlashSupport(0);
}
boolean flashInstalled = false;
try {
PackageManager pm = getPackageManager();
ApplicationInfo ai = pm.getApplicationInfo("com.adobe.flashplayer", 0);
if (ai != null) {
flashInstalled = true;
}
} catch (NameNotFoundException e) {
flashInstalled = false;
}
if (!flashInstalled && isChecked) {
Utils.createInformativeDialog(SettingsActivity.this,
getResources().getString(R.string.title_warning), getResources()
.getString(R.string.dialog_adobe_not_installed));
buttonView.setChecked(false);
mPreferences.setFlashSupport(0);
} else if ((API >= 17) && isChecked) {
Utils.createInformativeDialog(SettingsActivity.this,
getResources().getString(R.string.title_warning), getResources()
.getString(R.string.dialog_adobe_unsupported));
}
}
});
adblock.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mPreferences.setAdBlockEnabled(isChecked);
}
});
images.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mPreferences.setBlockImagesEnabled(isChecked);
}
});
enablejs.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mPreferences.setJavaScriptEnabled(isChecked);
}
});
color.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mPreferences.setColorModeEnabled(isChecked);
}
});
}
private void getFlashChoice() {
AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
builder.setTitle(mContext.getResources().getString(R.string.title_flash));
builder.setMessage(getResources().getString(R.string.flash))
.setCancelable(true)
.setPositiveButton(getResources().getString(R.string.action_manual),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
mPreferences.setFlashSupport(1);
}
})
.setNegativeButton(getResources().getString(R.string.action_auto),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
mPreferences.setFlashSupport(2);
}
}).setOnCancelListener(new OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
mPreferences.setFlashSupport(0);
}
});
AlertDialog alert = builder.create();
alert.show();
}
private void proxyChoicePicker() {
AlertDialog.Builder picker = new AlertDialog.Builder(mContext);
picker.setTitle(getResources().getString(R.string.http_proxy));
picker.setSingleChoiceItems(mProxyChoices, mPreferences.getProxyChoice(),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
setProxyChoice(which);
}
});
picker.setNeutralButton(getResources().getString(R.string.action_ok),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
picker.show();
}
private void setProxyChoice(int choice) {
ProxyUtils utils = ProxyUtils.getInstance(this);
switch (choice) {
case Constants.PROXY_ORBOT:
choice = utils.setProxyChoice(choice, this);
break;
case Constants.PROXY_I2P:
choice = utils.setProxyChoice(choice, this);
break;
case Constants.PROXY_MANUAL:
manualProxyPicker();
break;
}
mPreferences.setProxyChoice(choice);
if (choice < mProxyChoices.length)
mProxyChoiceName.setText(mProxyChoices[choice]);
}
public void manualProxyPicker() {
View v = getLayoutInflater().inflate(R.layout.picker_manual_proxy, null);
final EditText eProxyHost = (EditText) v.findViewById(R.id.proxyHost);
final EditText eProxyPort = (EditText) v.findViewById(R.id.proxyPort);
eProxyHost.setText(mPreferences.getProxyHost());
eProxyPort.setText(Integer.toString(mPreferences.getProxyPort()));
new AlertDialog.Builder(mActivity)
.setTitle(R.string.manual_proxy)
.setView(v)
.setPositiveButton(R.string.action_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
String proxyHost = eProxyHost.getText().toString();
int proxyPort = Integer.parseInt(eProxyPort.getText().toString());
mPreferences.setProxyHost(proxyHost);
mPreferences.setProxyPort(proxyPort);
mProxyChoiceName.setText(proxyHost + ":" + proxyPort);
}
})
.show();
}
public void agentPicker() {
final AlertDialog.Builder agentStringPicker = new AlertDialog.Builder(mActivity);
agentStringPicker.setTitle(getResources().getString(R.string.title_user_agent));
final EditText getAgent = new EditText(this);
getAgent.append(mPreferences.getUserAgentString(""));
agentStringPicker.setView(getAgent);
agentStringPicker.setPositiveButton(getResources().getString(R.string.action_ok),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String text = getAgent.getText().toString();
mPreferences.setUserAgentString(text);
getAgent.setText(getResources().getString(R.string.agent_custom));
}
});
agentStringPicker.show();
}
public void general(RelativeLayout view) {
view.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(mContext, GeneralSettingsActivity.class));
}
});
}
public void display(RelativeLayout view) {
view.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(mContext, DisplaySettingsActivity.class));
}
});
}
public void privacy(RelativeLayout view) {
view.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(mContext, PrivacySettingsActivity.class));
}
});
}
public void advanced(RelativeLayout view) {
view.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(mContext, AdvancedSettingsActivity.class));
}
});
}
public void about(RelativeLayout view) {
view.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(mContext, AboutSettingsActivity.class));
}
});
@Override
public boolean onOptionsItemSelected(MenuItem item) {
finish();
return true;
}
}

262
app/src/main/java/acr/browser/lightning/fragment/SettingsFragment.java

@ -0,0 +1,262 @@ @@ -0,0 +1,262 @@
/*
* Copyright 2014 A.C.R. Development
*/
package acr.browser.lightning.fragment;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.view.View;
import android.widget.EditText;
import acr.browser.lightning.R;
import acr.browser.lightning.constant.Constants;
import acr.browser.lightning.preference.PreferenceManager;
import acr.browser.lightning.utils.ProxyUtils;
import acr.browser.lightning.utils.Utils;
public class SettingsFragment extends PreferenceFragment implements Preference.OnPreferenceClickListener, Preference.OnPreferenceChangeListener {
// TODO: - fix toast on flash cb click
// - test proxy settings
// - test flash settings
private Activity mActivity;
private static final int API = android.os.Build.VERSION.SDK_INT;
private PreferenceManager mPreferences;
private CharSequence[] mProxyChoices;
private Preference proxy, version;
private CheckBoxPreference cbFlash, cbAds, cbImages, cbJsScript, cbColorMode;
private static final String SETTINGS_PROXY = "proxy";
private static final String SETTINGS_FLASH = "cb_flash";
private static final String SETTINGS_ADS = "cb_ads";
private static final String SETTINGS_IMAGES = "cb_images";
private static final String SETTINGS_JAVASCRIPT = "cb_javascript";
private static final String SETTINGS_COLORMODE = "cb_colormode";
private static final String SETTINGS_VERSION = "pref_version";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Load the preferences from an XML resource
addPreferencesFromResource(R.xml.main_preferences);
mActivity = getActivity();
initPrefs();
}
private void initPrefs() {
// mPreferences storage
mPreferences = PreferenceManager.getInstance();
proxy = findPreference(SETTINGS_PROXY);
version = findPreference(SETTINGS_VERSION);
cbFlash = (CheckBoxPreference) findPreference(SETTINGS_FLASH);
cbAds = (CheckBoxPreference) findPreference(SETTINGS_ADS);
cbImages = (CheckBoxPreference) findPreference(SETTINGS_IMAGES);
cbJsScript = (CheckBoxPreference) findPreference(SETTINGS_JAVASCRIPT);
cbColorMode = (CheckBoxPreference) findPreference(SETTINGS_COLORMODE);
proxy.setOnPreferenceChangeListener(this);
cbFlash.setOnPreferenceChangeListener(this);
cbAds.setOnPreferenceChangeListener(this);
cbImages.setOnPreferenceChangeListener(this);
cbJsScript.setOnPreferenceChangeListener(this);
cbColorMode.setOnPreferenceChangeListener(this);
version.setSummary(getVersion());
mProxyChoices = getResources().getStringArray(R.array.proxy_choices_array);
int choice = mPreferences.getProxyChoice();
if (choice == Constants.PROXY_MANUAL) {
proxy.setSummary(mPreferences.getProxyHost() + ":" + mPreferences.getProxyPort());
} else {
proxy.setSummary(mProxyChoices[choice]);
}
if (API >= 19) {
mPreferences.setFlashSupport(0);
}
int flashNum = mPreferences.getFlashSupport();
boolean imagesBool = mPreferences.getBlockImagesEnabled();
boolean enableJSBool = mPreferences.getJavaScriptEnabled();
proxy.setEnabled(Constants.FULL_VERSION);
cbAds.setEnabled(Constants.FULL_VERSION);
cbFlash.setEnabled(API < 19);
cbImages.setChecked(imagesBool);
cbJsScript.setChecked(enableJSBool);
cbFlash.setChecked(flashNum > 0);
cbAds.setChecked(Constants.FULL_VERSION && mPreferences.getAdBlockEnabled());
cbColorMode.setChecked(mPreferences.getColorModeEnabled());
}
private void getFlashChoice() {
AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
builder.setTitle(mActivity.getResources().getString(R.string.title_flash));
builder.setMessage(getResources().getString(R.string.flash))
.setCancelable(true)
.setPositiveButton(getResources().getString(R.string.action_manual),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
mPreferences.setFlashSupport(1);
}
})
.setNegativeButton(getResources().getString(R.string.action_auto),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
mPreferences.setFlashSupport(2);
}
}).setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
mPreferences.setFlashSupport(0);
}
});
AlertDialog alert = builder.create();
alert.show();
}
private void proxyChoicePicker() {
AlertDialog.Builder picker = new AlertDialog.Builder(mActivity);
picker.setTitle(getResources().getString(R.string.http_proxy));
picker.setSingleChoiceItems(mProxyChoices, mPreferences.getProxyChoice(),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
setProxyChoice(which);
}
});
picker.setNeutralButton(getResources().getString(R.string.action_ok),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
picker.show();
}
private void setProxyChoice(int choice) {
ProxyUtils utils = ProxyUtils.getInstance(mActivity);
switch (choice) {
case Constants.PROXY_ORBOT:
choice = utils.setProxyChoice(choice, mActivity);
break;
case Constants.PROXY_I2P:
choice = utils.setProxyChoice(choice, mActivity);
break;
case Constants.PROXY_MANUAL:
manualProxyPicker();
break;
}
mPreferences.setProxyChoice(choice);
if (choice < mProxyChoices.length)
proxy.setSummary(mProxyChoices[choice]);
}
public void manualProxyPicker() {
View v = mActivity.getLayoutInflater().inflate(R.layout.picker_manual_proxy, null);
final EditText eProxyHost = (EditText) v.findViewById(R.id.proxyHost);
final EditText eProxyPort = (EditText) v.findViewById(R.id.proxyPort);
eProxyHost.setText(mPreferences.getProxyHost());
eProxyPort.setText(Integer.toString(mPreferences.getProxyPort()));
new AlertDialog.Builder(mActivity)
.setTitle(R.string.manual_proxy)
.setView(v)
.setPositiveButton(R.string.action_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
String proxyHost = eProxyHost.getText().toString();
int proxyPort = Integer.parseInt(eProxyPort.getText().toString());
mPreferences.setProxyHost(proxyHost);
mPreferences.setProxyPort(proxyPort);
proxy.setSummary(proxyHost + ":" + proxyPort);
}
})
.show();
}
private String getVersion() {
try {
PackageInfo p = mActivity.getPackageManager().getPackageInfo(mActivity.getPackageName(), 0);
return p.versionName;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return "1.0";
}
@Override
public boolean onPreferenceClick(Preference preference) {
switch (preference.getKey()) {
case SETTINGS_PROXY:
proxyChoicePicker();
return true;
default:
return false;
}
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
// switch preferences
switch (preference.getKey()) {
case SETTINGS_FLASH:
if (cbFlash.isChecked()) {
getFlashChoice();
} else {
mPreferences.setFlashSupport(0);
}
if (!Utils.isFlashInstalled(mActivity) && cbFlash.isChecked()) {
Utils.createInformativeDialog(mActivity,
mActivity.getResources().getString(R.string.title_warning),
mActivity.getResources().getString(R.string.dialog_adobe_not_installed));
cbFlash.setEnabled(false);
mPreferences.setFlashSupport(0);
} else if ((API >= 17) && cbFlash.isChecked()) {
Utils.createInformativeDialog(mActivity,
mActivity.getResources().getString(R.string.title_warning),
mActivity.getResources().getString(R.string.dialog_adobe_unsupported));
}
cbFlash.setChecked((Boolean) newValue);
return true;
case SETTINGS_ADS:
mPreferences.setAdBlockEnabled((Boolean) newValue);
cbAds.setChecked((Boolean) newValue);
return true;
case SETTINGS_IMAGES:
mPreferences.setBlockImagesEnabled((Boolean) newValue);
cbImages.setChecked((Boolean) newValue);
return true;
case SETTINGS_JAVASCRIPT:
mPreferences.setJavaScriptEnabled((Boolean) newValue);
cbJsScript.setChecked((Boolean) newValue);
return true;
case SETTINGS_COLORMODE:
mPreferences.setColorModeEnabled((Boolean) newValue);
cbColorMode.setChecked((Boolean) newValue);
return true;
default:
return false;
}
}
}

53
app/src/main/java/acr/browser/lightning/utils/Utils.java

@ -9,6 +9,8 @@ import android.app.AlertDialog; @@ -9,6 +9,8 @@ import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
@ -20,17 +22,15 @@ import android.util.Log; @@ -20,17 +22,15 @@ import android.util.Log;
import android.webkit.URLUtil;
import android.widget.Toast;
import java.io.*;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import acr.browser.lightning.constant.Constants;
import acr.browser.lightning.database.HistoryItem;
import acr.browser.lightning.R;
import acr.browser.lightning.constant.Constants;
import acr.browser.lightning.download.DownloadHandler;
public final class Utils {
@ -63,11 +63,11 @@ public final class Utils { @@ -63,11 +63,11 @@ public final class Utils {
builder.setMessage(message)
.setCancelable(true)
.setPositiveButton(context.getResources().getString(R.string.action_ok),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
}
});
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
}
});
AlertDialog alert = builder.create();
alert.show();
}
@ -114,26 +114,6 @@ public final class Utils { @@ -114,26 +114,6 @@ public final class Utils {
return url.substring(0, index + 2);
}
public static List<HistoryItem> getOldBookmarks(Context context) {
List<HistoryItem> bookmarks = new ArrayList<>();
File bookUrl = new File(context.getFilesDir(), "bookurl");
File book = new File(context.getFilesDir(), "bookmarks");
try {
BufferedReader readUrl = new BufferedReader(new FileReader(bookUrl));
BufferedReader readBook = new BufferedReader(new FileReader(book));
String u, t;
while ((u = readUrl.readLine()) != null && (t = readBook.readLine()) != null) {
HistoryItem map = new HistoryItem(u, t, R.drawable.ic_bookmark);
bookmarks.add(map);
}
readBook.close();
readUrl.close();
} catch (IOException e) {
e.printStackTrace();
}
return bookmarks;
}
public static String[] getArray(String input) {
return input.split(Constants.SEPARATOR);
}
@ -227,6 +207,19 @@ public final class Utils { @@ -227,6 +207,19 @@ public final class Utils {
);
}
public static boolean isFlashInstalled(Context context) {
try {
PackageManager pm = context.getPackageManager();
ApplicationInfo ai = pm.getApplicationInfo("com.adobe.flashplayer", 0);
if (ai != null) {
return true;
}
} catch (PackageManager.NameNotFoundException e) {
return false;
}
return false;
}
public static Bitmap getWebpageBitmap(Resources resources, boolean dark) {
if (dark) {
if (mWebIconDark == null) {

405
app/src/main/res/layout/settings.xml

@ -1,411 +1,14 @@ @@ -1,411 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/toolbar_settings" />
<ScrollView
android:id="@+id/scrollView1"
<fragment
android:name="acr.browser.lightning.fragment.SettingsFragment"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/layoutFlash"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/listChoiceBackgroundIndicator"
android:minHeight="60dp"
android:paddingBottom="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:paddingLeft="16dp"
android:paddingRight="60dp"
android:text="@string/flash"
android:textAppearance="?android:attr/textAppearanceMedium" />
<CheckBox
android:id="@+id/cbFlash"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="?attr/dividerColor" />
<RelativeLayout
android:id="@+id/layoutAdBlock"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/listChoiceBackgroundIndicator"
android:minHeight="60dp"
android:paddingBottom="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:paddingLeft="16dp"
android:paddingRight="60dp"
android:text="@string/block_ads"
android:textAppearance="?android:attr/textAppearanceMedium" />
<CheckBox
android:id="@+id/cbAdblock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="?attr/dividerColor" />
<RelativeLayout
android:id="@+id/layoutImages"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/listChoiceBackgroundIndicator"
android:minHeight="60dp"
android:paddingBottom="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:paddingLeft="16dp"
android:paddingRight="60dp"
android:text="@string/block"
android:textAppearance="?android:attr/textAppearanceMedium" />
<CheckBox
android:id="@+id/cbImageBlock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="?attr/dividerColor" />
<RelativeLayout
android:id="@+id/layoutEnableJS"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/listChoiceBackgroundIndicator"
android:minHeight="60dp"
android:paddingBottom="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp">
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:paddingLeft="16dp"
android:paddingRight="60dp"
android:text="@string/java"
android:textAppearance="?android:attr/textAppearanceMedium" />
<CheckBox
android:id="@+id/cbJavascript"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="?attr/dividerColor" />
<RelativeLayout
android:id="@+id/layoutColorMode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/listChoiceBackgroundIndicator"
android:minHeight="60dp"
android:paddingBottom="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:paddingLeft="16dp"
android:paddingRight="60dp"
android:text="@string/color_mode"
android:textAppearance="?android:attr/textAppearanceMedium" />
<CheckBox
android:id="@+id/cbColorMode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="?attr/dividerColor" />
<LinearLayout
android:id="@+id/layoutProxyChoice"
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/http_proxy"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/proxyChoiceName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="16dp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/light"
tools:text="Disabled" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="?attr/dividerColor" />
<RelativeLayout
android:id="@+id/layoutGeneral"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/listChoiceBackgroundIndicator"
android:minHeight="60dp"
android:paddingBottom="10dp"
android:paddingTop="10dp">
<TextView
android:id="@+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:paddingLeft="16dp"
android:text="@string/settings_general"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="?attr/dividerColor" />
<RelativeLayout
android:id="@+id/layoutBookmarks"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/listChoiceBackgroundIndicator"
android:minHeight="60dp"
android:paddingBottom="10dp"
android:paddingTop="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:paddingLeft="16dp"
android:text="@string/bookmark_settings"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="?attr/dividerColor" />
<RelativeLayout
android:id="@+id/layoutDisplay"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/listChoiceBackgroundIndicator"
android:minHeight="60dp"
android:paddingBottom="10dp"
android:paddingTop="10dp">
<TextView
android:id="@+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:paddingLeft="16dp"
android:text="@string/settings_display"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="?attr/dividerColor" />
<RelativeLayout
android:id="@+id/layoutPrivacy"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/listChoiceBackgroundIndicator"
android:minHeight="60dp"
android:paddingBottom="10dp"
android:paddingTop="10dp">
<TextView
android:id="@+id/textView9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:paddingLeft="16dp"
android:text="@string/settings_privacy"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="?attr/dividerColor" />
<RelativeLayout
android:id="@+id/layoutAdvanced"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/listChoiceBackgroundIndicator"
android:minHeight="60dp"
android:paddingBottom="10dp"
android:paddingTop="10dp">
<TextView
android:id="@+id/textView10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:paddingLeft="16dp"
android:text="@string/settings_advanced"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="?attr/dividerColor" />
<RelativeLayout
android:id="@+id/layoutAbout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/listChoiceBackgroundIndicator"
android:minHeight="60dp"
android:paddingBottom="10dp"
android:paddingTop="10dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:orientation="vertical">
<TextView
android:id="@+id/textView11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="16dp"
android:text="@string/settings_about"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/isImportAvailable"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="16dp"
android:text="@string/settings_about_explain"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/light" />
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="?attr/dividerColor" />
</LinearLayout>
</ScrollView>
android:layout_height="match_parent"
android:tag="settingsFragment" />
</LinearLayout>

74
app/src/main/res/xml/main_preferences.xml

@ -0,0 +1,74 @@ @@ -0,0 +1,74 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="@string/settings">
<CheckBoxPreference
android:defaultValue="false"
android:key="cb_flash"
android:title="@string/flash" />
<CheckBoxPreference
android:defaultValue="false"
android:key="cb_ads"
android:title="@string/block_ads" />
<CheckBoxPreference
android:defaultValue="false"
android:key="cb_images"
android:title="@string/block" />
<CheckBoxPreference
android:defaultValue="true"
android:key="cb_javascript"
android:title="@string/java" />
<Preference
android:key="proxy"
android:title="@string/http_proxy" />
<CheckBoxPreference
android:defaultValue="true"
android:key="cb_colormode"
android:title="@string/color_mode" />
</PreferenceCategory>
<Preference android:title="@string/settings_general">
<intent
android:targetPackage="acr.browser.lightning"
android:targetClass="acr.browser.lightning.activity.GeneralSettingsActivity" />
</Preference>
<Preference android:title="@string/bookmark_settings">
<intent
android:targetPackage="acr.browser.lightning"
android:targetClass="acr.browser.lightning.activity.BookmarkSettingsActivity" />
</Preference>
<Preference android:title="@string/settings_display">
<intent
android:targetPackage="acr.browser.lightning"
android:targetClass="acr.browser.lightning.activity.DisplaySettingsActivity" />
</Preference>
<Preference android:title="@string/settings_privacy">
<intent
android:targetPackage="acr.browser.lightning"
android:targetClass="acr.browser.lightning.activity.PrivacySettingsActivity" />
</Preference>
<Preference android:title="@string/settings_advanced">
<intent
android:targetPackage="acr.browser.lightning"
android:targetClass="acr.browser.lightning.activity.AdvancedSettingsActivity" />
</Preference>
<PreferenceScreen
android:title="@string/settings_about"
android:summary="@string/settings_about_explain"
android:persistent="false">
<Preference
android:title="@string/action_follow_me"
android:summary="@string/url_twitter">
<intent
android:action="android.intent.action.VIEW"
android:data="http://twitter.com/RestainoAnthony" />
</Preference>
<Preference android:title="@string/licenses">
<intent
android:targetPackage="acr.browser.lightning"
android:targetClass="acr.browser.lightning.activity.LicenseActivity" />
</Preference>
<Preference
android:title="@string/version"
android:key="pref_version" />
</PreferenceScreen>
</PreferenceScreen>
Loading…
Cancel
Save