Browse Source

new Settings 1/3

master
DF1E 10 years ago
parent
commit
d47a86d9b5
  1. 22
      app/src/main/AndroidManifest.xml
  2. 89
      app/src/main/java/acr/browser/lightning/activity/AboutSettingsActivity.java
  3. 112
      app/src/main/java/acr/browser/lightning/activity/AppCompatPreferenceActivity.java
  4. 167
      app/src/main/java/acr/browser/lightning/activity/BookmarkActivity.java
  5. 23
      app/src/main/java/acr/browser/lightning/activity/SettingsActivity.java
  6. 3
      app/src/main/java/acr/browser/lightning/activity/ThemableSettingsActivity.java
  7. 42
      app/src/main/java/acr/browser/lightning/fragment/AboutSettingsFragment.java
  8. 24
      app/src/main/java/acr/browser/lightning/fragment/AdvancedSettingsFragment.java
  9. 168
      app/src/main/java/acr/browser/lightning/fragment/BookmarkSettingsFragment.java
  10. 24
      app/src/main/java/acr/browser/lightning/fragment/DisplaySettingsFragment.java
  11. 41
      app/src/main/java/acr/browser/lightning/fragment/GeneralSettingsFragment.java
  12. 24
      app/src/main/java/acr/browser/lightning/fragment/PrivacySettingsFragment.java
  13. 137
      app/src/main/res/layout/about_settings.xml
  14. 93
      app/src/main/res/layout/bookmark_settings.xml
  15. 2
      app/src/main/res/layout/settings.xml
  16. 21
      app/src/main/res/xml/preference_about.xml
  17. 7
      app/src/main/res/xml/preference_advanced.xml
  18. 16
      app/src/main/res/xml/preference_bookmarks.xml
  19. 7
      app/src/main/res/xml/preference_display.xml
  20. 27
      app/src/main/res/xml/preference_general.xml
  21. 7
      app/src/main/res/xml/preference_privacy.xml
  22. 22
      app/src/main/res/xml/preferences_headers.xml

22
app/src/main/AndroidManifest.xml

@ -151,17 +151,6 @@
<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.DEFAULT" />
</intent-filter> </intent-filter>
</activity> </activity>
<activity
android:name=".activity.AboutSettingsActivity"
android:configChanges="orientation|screenSize|keyboardHidden|keyboard"
android:label="@string/settings_about"
android:theme="@style/Theme.SettingsTheme" >
<intent-filter>
<action android:name="android.intent.action.ABOUT_SETTINGS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity <activity
android:name=".activity.IncognitoActivity" android:name=".activity.IncognitoActivity"
android:alwaysRetainTaskState="true" android:alwaysRetainTaskState="true"
@ -187,17 +176,6 @@
<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.DEFAULT" />
</intent-filter> </intent-filter>
</activity> </activity>
<activity
android:name=".activity.BookmarkActivity"
android:configChanges="orientation|screenSize|keyboardHidden|keyboard"
android:label="@string/bookmark_settings"
android:theme="@style/Theme.SettingsTheme" >
<intent-filter>
<action android:name="android.intent.action.BOOKMARK" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity <activity
android:name=".activity.ReadingActivity" android:name=".activity.ReadingActivity"
android:configChanges="orientation|screenSize|keyboardHidden|keyboard" android:configChanges="orientation|screenSize|keyboardHidden|keyboard"

89
app/src/main/java/acr/browser/lightning/activity/AboutSettingsActivity.java

@ -1,89 +0,0 @@
/*
* Copyright 2014 A.C.R. Development
*/
package acr.browser.lightning.activity;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.net.Uri;
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.RelativeLayout;
import android.widget.TextView;
import acr.browser.lightning.R;
public class AboutSettingsActivity extends ThemableSettingsActivity implements OnClickListener {
private int mEasterEggCounter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.about_settings);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
initialize();
}
private void initialize() {
String code = "1.0";
try {
PackageInfo p = getPackageManager().getPackageInfo(getPackageName(), 0);
code = p.versionName;
} catch (NameNotFoundException e) {
e.printStackTrace();
}
TextView versionCode = (TextView) findViewById(R.id.versionCode);
versionCode.setText(code);
RelativeLayout licenses = (RelativeLayout) findViewById(R.id.layoutLicense);
RelativeLayout source = (RelativeLayout) findViewById(R.id.layoutSource);
RelativeLayout version = (RelativeLayout) findViewById(R.id.layoutVersion);
licenses.setOnClickListener(this);
source.setOnClickListener(this);
version.setOnClickListener(this);
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.layoutLicense:
// NOTE: In order to comply legally with open source licenses,
// it is advised that you leave this code so that the License
// Activity may be viewed by the user.
startActivity(new Intent(this, LicenseActivity.class));
break;
case R.id.layoutSource:
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("http://twitter.com/RestainoAnthony"), this, MainActivity.class));
finish();
break;
case R.id.layoutVersion:
mEasterEggCounter++;
if (mEasterEggCounter == 10) {
startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("http://imgs.xkcd.com/comics/compiling.png"), this,
MainActivity.class));
finish();
mEasterEggCounter = 0;
}
break;
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
finish();
return true;
}
}

112
app/src/main/java/acr/browser/lightning/activity/AppCompatPreferenceActivity.java

@ -0,0 +1,112 @@
package acr.browser.lightning.activity;
import android.content.res.Configuration;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatDelegate;
import android.support.v7.widget.Toolbar;
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;
/**
* A {@link android.preference.PreferenceActivity} which implements and proxies the necessary calls
* to be used with AppCompat.
* <p/>
* This technique can be used with an {@link android.app.Activity} class, not just
* {@link android.preference.PreferenceActivity}.
*/
public abstract class AppCompatPreferenceActivity extends PreferenceActivity {
private AppCompatDelegate mDelegate;
@Override
protected void onCreate(Bundle savedInstanceState) {
getDelegate().installViewFactory();
getDelegate().onCreate(savedInstanceState);
super.onCreate(savedInstanceState);
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
getDelegate().onPostCreate(savedInstanceState);
}
public ActionBar getSupportActionBar() {
return getDelegate().getSupportActionBar();
}
public void setSupportActionBar(@Nullable Toolbar toolbar) {
getDelegate().setSupportActionBar(toolbar);
}
@Override
public MenuInflater getMenuInflater() {
return getDelegate().getMenuInflater();
}
@Override
public void setContentView(@LayoutRes int layoutResID) {
getDelegate().setContentView(layoutResID);
}
@Override
public void setContentView(View view) {
getDelegate().setContentView(view);
}
@Override
public void setContentView(View view, ViewGroup.LayoutParams params) {
getDelegate().setContentView(view, params);
}
@Override
public void addContentView(View view, ViewGroup.LayoutParams params) {
getDelegate().addContentView(view, params);
}
@Override
protected void onPostResume() {
super.onPostResume();
getDelegate().onPostResume();
}
@Override
protected void onTitleChanged(CharSequence title, int color) {
super.onTitleChanged(title, color);
getDelegate().setTitle(title);
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
getDelegate().onConfigurationChanged(newConfig);
}
@Override
protected void onStop() {
super.onStop();
getDelegate().onStop();
}
@Override
protected void onDestroy() {
super.onDestroy();
getDelegate().onDestroy();
}
public void invalidateOptionsMenu() {
getDelegate().invalidateOptionsMenu();
}
private AppCompatDelegate getDelegate() {
if (mDelegate == null) {
mDelegate = AppCompatDelegate.create(this, null);
}
return mDelegate;
}
}

167
app/src/main/java/acr/browser/lightning/activity/BookmarkActivity.java

@ -1,167 +0,0 @@
package acr.browser.lightning.activity;
import java.io.File;
import java.util.Arrays;
import java.util.Comparator;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Environment;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.TextView;
import acr.browser.lightning.database.BookmarkManager;
import acr.browser.lightning.preference.PreferenceManager;
import acr.browser.lightning.R;
public class BookmarkActivity extends ThemableSettingsActivity implements OnClickListener {
private BookmarkManager mBookmarkManager;
private File[] mFileList;
private String[] mFileNameList;
private static final File mPath = new File(Environment.getExternalStorageDirectory().toString());
private static final int DIALOG_LOAD_FILE = 1000;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.bookmark_settings);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
LinearLayout exportBackup = (LinearLayout) findViewById(R.id.exportBackup);
LinearLayout importBackup = (LinearLayout) findViewById(R.id.importBackup);
LinearLayout importFromBrowser = (LinearLayout) findViewById(R.id.importFromBrowser);
TextView importBookmarks = (TextView) findViewById(R.id.isImportBrowserAvailable);
mBookmarkManager = BookmarkManager.getInstance(getApplicationContext());
PreferenceManager mPreferences = PreferenceManager.getInstance();
boolean systemBrowser = mPreferences.getSystemBrowserPresent();
exportBackup.setOnClickListener(this);
importBackup.setOnClickListener(this);
importFromBrowser.setOnClickListener(this);
if (systemBrowser) {
importBookmarks.setText(getResources().getString(R.string.stock_browser_available));
} else {
importBookmarks.setText(getResources().getString(R.string.stock_browser_unavailable));
}
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.importBackup:
loadFileList(null);
onCreateDialog(DIALOG_LOAD_FILE);
break;
case R.id.importFromBrowser:
mBookmarkManager.importBookmarksFromBrowser(BookmarkActivity.this);
break;
case R.id.exportBackup:
mBookmarkManager.exportBookmarks();
break;
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
finish();
return true;
}
private void loadFileList(File path) {
File file;
if (path != null) {
file = path;
} else {
file = mPath;
}
try {
file.mkdirs();
} catch (SecurityException e) {
e.printStackTrace();
}
if (file.exists()) {
mFileList = file.listFiles();
} else {
mFileList = new File[0];
}
Arrays.sort(mFileList, new SortName());
if (mFileList == null) {
mFileNameList = new String[0];
mFileList = new File[0];
} else {
mFileNameList = new String[mFileList.length];
}
for (int n = 0; n < mFileList.length; n++) {
mFileNameList[n] = mFileList[n].getName();
}
}
private class SortName implements Comparator<File> {
@Override
public int compare(File a, File b) {
if (a.isDirectory() && b.isDirectory())
return a.getName().compareTo(b.getName());
if (a.isDirectory())
return -1;
if (b.isDirectory())
return 1;
if (a.isFile() && b.isFile())
return a.getName().compareTo(b.getName());
else
return 1;
}
}
protected Dialog onCreateDialog(int id) {
Dialog dialog;
final AlertDialog.Builder builder = new Builder(this);
switch (id) {
case DIALOG_LOAD_FILE:
builder.setTitle(R.string.title_chooser);
if (mFileList == null) {
dialog = builder.create();
return dialog;
}
builder.setItems(mFileNameList, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (mFileList[which].isDirectory()) {
loadFileList(mFileList[which]);
builder.setItems(mFileNameList, this);
builder.show();
} else {
mBookmarkManager.importBookmarksFromFile(mFileList[which], BookmarkActivity.this);
}
}
});
break;
}
dialog = builder.show();
return dialog;
}
}

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

@ -4,22 +4,35 @@
package acr.browser.lightning.activity; package acr.browser.lightning.activity;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem; import android.view.MenuItem;
import java.util.ArrayList;
import java.util.List;
import acr.browser.lightning.R; import acr.browser.lightning.R;
public class SettingsActivity extends ThemableSettingsActivity { public class SettingsActivity extends ThemableSettingsActivity {
private static List<String> fragments = new ArrayList<>();
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.settings); // TODO: set up ToolBar
}
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); @Override
setSupportActionBar(toolbar); public void onBuildHeaders(List<Header> target) {
loadHeadersFromResource(R.xml.preferences_headers, target);
fragments.clear();
for (Header header : target) {
fragments.add(header.fragment);
}
}
getSupportActionBar().setDisplayHomeAsUpEnabled(true); @Override
protected boolean isValidFragment(String fragmentName) {
return fragments.contains(fragmentName);
} }
@Override @Override

3
app/src/main/java/acr/browser/lightning/activity/ThemableSettingsActivity.java

@ -3,12 +3,11 @@ package acr.browser.lightning.activity;
import android.content.Intent; import android.content.Intent;
import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.ColorDrawable;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import acr.browser.lightning.R; import acr.browser.lightning.R;
import acr.browser.lightning.preference.PreferenceManager; import acr.browser.lightning.preference.PreferenceManager;
public abstract class ThemableSettingsActivity extends AppCompatActivity { public abstract class ThemableSettingsActivity extends AppCompatPreferenceActivity {
private int mTheme; private int mTheme;

42
app/src/main/java/acr/browser/lightning/fragment/AboutSettingsFragment.java

@ -0,0 +1,42 @@
/*
* Copyright 2014 A.C.R. Development
*/
package acr.browser.lightning.fragment;
import android.app.Activity;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import acr.browser.lightning.R;
public class AboutSettingsFragment extends PreferenceFragment {
private Activity mActivity;
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.preference_about);
mActivity = getActivity();
Preference version = findPreference(SETTINGS_VERSION);
version.setSummary(getVersion());
}
private String getVersion() {
try {
PackageInfo p = mActivity.getPackageManager().getPackageInfo(mActivity.getPackageName(), 0);
return p.versionName;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
return "1.0";
}
}
}

24
app/src/main/java/acr/browser/lightning/fragment/AdvancedSettingsFragment.java

@ -0,0 +1,24 @@
/*
* Copyright 2014 A.C.R. Development
*/
package acr.browser.lightning.fragment;
import android.app.Activity;
import android.os.Bundle;
import android.preference.PreferenceFragment;
import acr.browser.lightning.R;
public class AdvancedSettingsFragment extends PreferenceFragment {
private Activity mActivity;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Load the preferences from an XML resource
addPreferencesFromResource(R.xml.preference_advanced);
mActivity = getActivity();
}
}

168
app/src/main/java/acr/browser/lightning/fragment/BookmarkSettingsFragment.java

@ -0,0 +1,168 @@
/*
* Copyright 2014 A.C.R. Development
*/
package acr.browser.lightning.fragment;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Environment;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import java.io.File;
import java.util.Arrays;
import java.util.Comparator;
import acr.browser.lightning.R;
import acr.browser.lightning.database.BookmarkManager;
import acr.browser.lightning.preference.PreferenceManager;
public class BookmarkSettingsFragment extends PreferenceFragment implements Preference.OnPreferenceClickListener {
private static final String SETTINGS_EXPORT = "export_bookmark";
private static final String SETTINGS_IMPORT = "import_bookmark";
private static final String SETTINGS_BROWSER_IMPORT = "import_browser_bookmark";
private Activity mActivity;
private PreferenceManager mPreferences;
private BookmarkManager mBookmarkManager;
private File[] mFileList;
private String[] mFileNameList;
private static final File mPath = new File(Environment.getExternalStorageDirectory().toString());
private static final int DIALOG_LOAD_FILE = 1000;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Load the preferences from an XML resource
addPreferencesFromResource(R.xml.preference_bookmarks);
mActivity = getActivity();
mBookmarkManager = BookmarkManager.getInstance(mActivity);
initPrefs();
}
private void initPrefs() {
// mPreferences storage
mPreferences = PreferenceManager.getInstance();
Preference exportpref = findPreference(SETTINGS_EXPORT);
Preference importpref = findPreference(SETTINGS_IMPORT);
Preference importBrowserpref = findPreference(SETTINGS_BROWSER_IMPORT);
exportpref.setOnPreferenceClickListener(this);
importpref.setOnPreferenceClickListener(this);
importBrowserpref.setOnPreferenceClickListener(this);
if (mPreferences.getSystemBrowserPresent()) {
importBrowserpref.setSummary(getResources().getString(R.string.stock_browser_available));
} else {
importBrowserpref.setSummary(getResources().getString(R.string.stock_browser_unavailable));
}
}
@Override
public boolean onPreferenceClick(Preference preference) {
switch (preference.getKey()) {
case SETTINGS_EXPORT:
mBookmarkManager.exportBookmarks();
return true;
case SETTINGS_IMPORT:
loadFileList(null);
onCreateDialog(DIALOG_LOAD_FILE);
return true;
case SETTINGS_BROWSER_IMPORT:
mBookmarkManager.importBookmarksFromBrowser(mActivity);
return true;
default:
return false;
}
}
private void loadFileList(File path) {
File file;
if (path != null) {
file = path;
} else {
file = mPath;
}
try {
file.mkdirs();
} catch (SecurityException e) {
e.printStackTrace();
}
if (file.exists()) {
mFileList = file.listFiles();
} else {
mFileList = new File[0];
}
Arrays.sort(mFileList, new SortName());
if (mFileList == null) {
mFileNameList = new String[0];
mFileList = new File[0];
} else {
mFileNameList = new String[mFileList.length];
}
for (int n = 0; n < mFileList.length; n++) {
mFileNameList[n] = mFileList[n].getName();
}
}
private class SortName implements Comparator<File> {
@Override
public int compare(File a, File b) {
if (a.isDirectory() && b.isDirectory())
return a.getName().compareTo(b.getName());
if (a.isDirectory())
return -1;
if (b.isDirectory())
return 1;
if (a.isFile() && b.isFile())
return a.getName().compareTo(b.getName());
else
return 1;
}
}
protected Dialog onCreateDialog(int id) {
Dialog dialog;
final AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
switch (id) {
case DIALOG_LOAD_FILE:
builder.setTitle(R.string.title_chooser);
if (mFileList == null) {
dialog = builder.create();
return dialog;
}
builder.setItems(mFileNameList, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (mFileList[which].isDirectory()) {
loadFileList(mFileList[which]);
builder.setItems(mFileNameList, this);
builder.show();
} else {
mBookmarkManager.importBookmarksFromFile(mFileList[which], mActivity);
}
}
});
break;
}
dialog = builder.show();
return dialog;
}
}

24
app/src/main/java/acr/browser/lightning/fragment/DisplaySettingsFragment.java

@ -0,0 +1,24 @@
/*
* Copyright 2014 A.C.R. Development
*/
package acr.browser.lightning.fragment;
import android.app.Activity;
import android.os.Bundle;
import android.preference.PreferenceFragment;
import acr.browser.lightning.R;
public class DisplaySettingsFragment extends PreferenceFragment {
private Activity mActivity;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Load the preferences from an XML resource
addPreferencesFromResource(R.xml.preference_display);
mActivity = getActivity();
}
}

41
app/src/main/java/acr/browser/lightning/fragment/SettingsFragment.java → app/src/main/java/acr/browser/lightning/fragment/GeneralSettingsFragment.java

@ -6,8 +6,6 @@ package acr.browser.lightning.fragment;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle; import android.os.Bundle;
import android.preference.CheckBoxPreference; import android.preference.CheckBoxPreference;
import android.preference.Preference; import android.preference.Preference;
@ -21,18 +19,7 @@ import acr.browser.lightning.preference.PreferenceManager;
import acr.browser.lightning.utils.ProxyUtils; import acr.browser.lightning.utils.ProxyUtils;
import acr.browser.lightning.utils.Utils; import acr.browser.lightning.utils.Utils;
public class SettingsFragment extends PreferenceFragment implements Preference.OnPreferenceClickListener, Preference.OnPreferenceChangeListener { public class GeneralSettingsFragment 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_PROXY = "proxy";
private static final String SETTINGS_FLASH = "cb_flash"; private static final String SETTINGS_FLASH = "cb_flash";
@ -40,13 +27,19 @@ public class SettingsFragment extends PreferenceFragment implements Preference.O
private static final String SETTINGS_IMAGES = "cb_images"; private static final String SETTINGS_IMAGES = "cb_images";
private static final String SETTINGS_JAVASCRIPT = "cb_javascript"; private static final String SETTINGS_JAVASCRIPT = "cb_javascript";
private static final String SETTINGS_COLORMODE = "cb_colormode"; private static final String SETTINGS_COLORMODE = "cb_colormode";
private static final String SETTINGS_VERSION = "pref_version";
private Activity mActivity;
private static final int API = android.os.Build.VERSION.SDK_INT;
private PreferenceManager mPreferences;
private CharSequence[] mProxyChoices;
private Preference proxy;
private CheckBoxPreference cbFlash, cbAds, cbImages, cbJsScript, cbColorMode;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
// Load the preferences from an XML resource // Load the preferences from an XML resource
addPreferencesFromResource(R.xml.main_preferences); addPreferencesFromResource(R.xml.preference_general);
mActivity = getActivity(); mActivity = getActivity();
@ -58,22 +51,19 @@ public class SettingsFragment extends PreferenceFragment implements Preference.O
mPreferences = PreferenceManager.getInstance(); mPreferences = PreferenceManager.getInstance();
proxy = findPreference(SETTINGS_PROXY); proxy = findPreference(SETTINGS_PROXY);
version = findPreference(SETTINGS_VERSION);
cbFlash = (CheckBoxPreference) findPreference(SETTINGS_FLASH); cbFlash = (CheckBoxPreference) findPreference(SETTINGS_FLASH);
cbAds = (CheckBoxPreference) findPreference(SETTINGS_ADS); cbAds = (CheckBoxPreference) findPreference(SETTINGS_ADS);
cbImages = (CheckBoxPreference) findPreference(SETTINGS_IMAGES); cbImages = (CheckBoxPreference) findPreference(SETTINGS_IMAGES);
cbJsScript = (CheckBoxPreference) findPreference(SETTINGS_JAVASCRIPT); cbJsScript = (CheckBoxPreference) findPreference(SETTINGS_JAVASCRIPT);
cbColorMode = (CheckBoxPreference) findPreference(SETTINGS_COLORMODE); cbColorMode = (CheckBoxPreference) findPreference(SETTINGS_COLORMODE);
proxy.setOnPreferenceChangeListener(this); proxy.setOnPreferenceClickListener(this);
cbFlash.setOnPreferenceChangeListener(this); cbFlash.setOnPreferenceChangeListener(this);
cbAds.setOnPreferenceChangeListener(this); cbAds.setOnPreferenceChangeListener(this);
cbImages.setOnPreferenceChangeListener(this); cbImages.setOnPreferenceChangeListener(this);
cbJsScript.setOnPreferenceChangeListener(this); cbJsScript.setOnPreferenceChangeListener(this);
cbColorMode.setOnPreferenceChangeListener(this); cbColorMode.setOnPreferenceChangeListener(this);
version.setSummary(getVersion());
mProxyChoices = getResources().getStringArray(R.array.proxy_choices_array); mProxyChoices = getResources().getStringArray(R.array.proxy_choices_array);
int choice = mPreferences.getProxyChoice(); int choice = mPreferences.getProxyChoice();
if (choice == Constants.PROXY_MANUAL) { if (choice == Constants.PROXY_MANUAL) {
@ -194,16 +184,6 @@ public class SettingsFragment extends PreferenceFragment implements Preference.O
.show(); .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 @Override
public boolean onPreferenceClick(Preference preference) { public boolean onPreferenceClick(Preference preference) {
switch (preference.getKey()) { switch (preference.getKey()) {
@ -226,6 +206,7 @@ public class SettingsFragment extends PreferenceFragment implements Preference.O
mPreferences.setFlashSupport(0); mPreferences.setFlashSupport(0);
} }
// TODO: fix toast on flash cb click
if (!Utils.isFlashInstalled(mActivity) && cbFlash.isChecked()) { if (!Utils.isFlashInstalled(mActivity) && cbFlash.isChecked()) {
Utils.createInformativeDialog(mActivity, Utils.createInformativeDialog(mActivity,
mActivity.getResources().getString(R.string.title_warning), mActivity.getResources().getString(R.string.title_warning),

24
app/src/main/java/acr/browser/lightning/fragment/PrivacySettingsFragment.java

@ -0,0 +1,24 @@
/*
* Copyright 2014 A.C.R. Development
*/
package acr.browser.lightning.fragment;
import android.app.Activity;
import android.os.Bundle;
import android.preference.PreferenceFragment;
import acr.browser.lightning.R;
public class PrivacySettingsFragment extends PreferenceFragment {
private Activity mActivity;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Load the preferences from an XML resource
addPreferencesFromResource(R.xml.preference_privacy);
mActivity = getActivity();
}
}

137
app/src/main/res/layout/about_settings.xml

@ -1,137 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<include layout="@layout/toolbar_settings" />
<ScrollView
android:id="@+id/scrollView1"
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/layoutSource"
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/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="16dp"
android:text="@string/action_follow_me"
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/url_twitter"
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" />
<RelativeLayout
android:id="@+id/layoutLicense"
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/textView12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="16dp"
android:text="@string/licenses"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</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/layoutVersion"
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:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="16dp"
android:text="@string/version"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/versionCode"
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>
</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>
</LinearLayout>

93
app/src/main/res/layout/bookmark_settings.xml

@ -1,93 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<include layout="@layout/toolbar_settings" />
<LinearLayout
android:id="@+id/exportBackup"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="?attr/listChoiceBackgroundIndicator"
android:gravity="center_vertical"
android:orientation="vertical"
android:paddingBottom="10dp"
android:paddingTop="10dp" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="16dp"
android:text="@string/export_bookmarks"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<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/importBackup"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="?attr/listChoiceBackgroundIndicator"
android:gravity="center_vertical"
android:orientation="vertical"
android:paddingBottom="10dp"
android:paddingTop="10dp" >
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="16dp"
android:text="@string/import_backup"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<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/importFromBrowser"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="?attr/listChoiceBackgroundIndicator"
android:gravity="center_vertical"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="16dp"
android:text="@string/importbookmarks"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/isImportBrowserAvailable"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="16dp"
android:text="@string/recommended"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/light" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="?attr/dividerColor" />
</LinearLayout>

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

@ -7,7 +7,7 @@
<include layout="@layout/toolbar_settings" /> <include layout="@layout/toolbar_settings" />
<fragment <fragment
android:name="acr.browser.lightning.fragment.SettingsFragment" android:name="acr.browser.lightning.fragment.GeneralSettingsFragment"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:tag="settingsFragment" /> android:tag="settingsFragment" />

21
app/src/main/res/xml/preference_about.xml

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="@string/settings_about">
<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" />
</PreferenceCategory>
</PreferenceScreen>

7
app/src/main/res/xml/preference_advanced.xml

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="@string/settings_advanced">
</PreferenceCategory>
</PreferenceScreen>

16
app/src/main/res/xml/preference_bookmarks.xml

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="@string/bookmark_settings">
<Preference
android:key="export_bookmark"
android:title="@string/export_bookmarks" />
<Preference
android:key="import_bookmark"
android:title="@string/import_backup" />
<Preference
android:key="import_browser_bookmark"
android:title="@string/importbookmarks"
android:summary="@string/recommended" />
</PreferenceCategory>
</PreferenceScreen>

7
app/src/main/res/xml/preference_display.xml

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="@string/settings_display">
</PreferenceCategory>
</PreferenceScreen>

27
app/src/main/res/xml/main_preferences.xml → app/src/main/res/xml/preference_general.xml

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="@string/settings"> <PreferenceCategory android:title="@string/settings_general">
<CheckBoxPreference <CheckBoxPreference
android:defaultValue="false" android:defaultValue="false"
android:key="cb_flash" android:key="cb_flash"
@ -31,11 +31,6 @@
android:targetPackage="acr.browser.lightning" android:targetPackage="acr.browser.lightning"
android:targetClass="acr.browser.lightning.activity.GeneralSettingsActivity" /> android:targetClass="acr.browser.lightning.activity.GeneralSettingsActivity" />
</Preference> </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"> <Preference android:title="@string/settings_display">
<intent <intent
android:targetPackage="acr.browser.lightning" android:targetPackage="acr.browser.lightning"
@ -51,24 +46,4 @@
android:targetPackage="acr.browser.lightning" android:targetPackage="acr.browser.lightning"
android:targetClass="acr.browser.lightning.activity.AdvancedSettingsActivity" /> android:targetClass="acr.browser.lightning.activity.AdvancedSettingsActivity" />
</Preference> </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> </PreferenceScreen>

7
app/src/main/res/xml/preference_privacy.xml

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="@string/settings_privacy">
</PreferenceCategory>
</PreferenceScreen>

22
app/src/main/res/xml/preferences_headers.xml

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<preference-headers xmlns:android="http://schemas.android.com/apk/res/android">
<header
android:fragment="acr.browser.lightning.fragment.GeneralSettingsFragment"
android:title="@string/settings_general" />
<header
android:fragment="acr.browser.lightning.fragment.BookmarkSettingsFragment"
android:title="@string/bookmark_settings" />
<header
android:fragment="acr.browser.lightning.fragment.DisplaySettingsFragment"
android:title="@string/settings_display" />
<header
android:fragment="acr.browser.lightning.fragment.PrivacySettingsFragment"
android:title="@string/settings_privacy" />
<header
android:fragment="acr.browser.lightning.fragment.AdvancedSettingsFragment"
android:title="@string/settings_advanced" />
<header
android:fragment="acr.browser.lightning.fragment.AboutSettingsFragment"
android:title="@string/settings_about"
android:summary="@string/settings_about_explain" />
</preference-headers>
Loading…
Cancel
Save