From a03444f4d03e1df8039a0def7f0b4606dbf84c99 Mon Sep 17 00:00:00 2001 From: DF1E Date: Thu, 11 Jun 2015 18:48:24 +0200 Subject: [PATCH] rebase test for main settings screen --- .../lightning/activity/SettingsActivity.java | 421 +----------------- .../lightning/fragment/SettingsFragment.java | 262 +++++++++++ .../acr/browser/lightning/utils/Utils.java | 53 +-- app/src/main/res/layout/settings.xml | 405 +---------------- app/src/main/res/xml/main_preferences.xml | 74 +++ 5 files changed, 367 insertions(+), 848 deletions(-) create mode 100644 app/src/main/java/acr/browser/lightning/fragment/SettingsFragment.java create mode 100644 app/src/main/res/xml/main_preferences.xml diff --git a/app/src/main/java/acr/browser/lightning/activity/SettingsActivity.java b/app/src/main/java/acr/browser/lightning/activity/SettingsActivity.java index cfb2e44..d4e094f 100644 --- a/app/src/main/java/acr/browser/lightning/activity/SettingsActivity.java +++ b/app/src/main/java/acr/browser/lightning/activity/SettingsActivity.java @@ -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; } } diff --git a/app/src/main/java/acr/browser/lightning/fragment/SettingsFragment.java b/app/src/main/java/acr/browser/lightning/fragment/SettingsFragment.java new file mode 100644 index 0000000..f5b59c8 --- /dev/null +++ b/app/src/main/java/acr/browser/lightning/fragment/SettingsFragment.java @@ -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; + } + } +} diff --git a/app/src/main/java/acr/browser/lightning/utils/Utils.java b/app/src/main/java/acr/browser/lightning/utils/Utils.java index 2dd93ef..da74107 100644 --- a/app/src/main/java/acr/browser/lightning/utils/Utils.java +++ b/app/src/main/java/acr/browser/lightning/utils/Utils.java @@ -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; 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 { 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 { return url.substring(0, index + 2); } - public static List getOldBookmarks(Context context) { - List 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 { ); } + 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) { diff --git a/app/src/main/res/layout/settings.xml b/app/src/main/res/layout/settings.xml index cdf4351..cefe459 100644 --- a/app/src/main/res/layout/settings.xml +++ b/app/src/main/res/layout/settings.xml @@ -1,411 +1,14 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:layout_height="match_parent" + android:tag="settingsFragment" /> \ No newline at end of file diff --git a/app/src/main/res/xml/main_preferences.xml b/app/src/main/res/xml/main_preferences.xml new file mode 100644 index 0000000..163398a --- /dev/null +++ b/app/src/main/res/xml/main_preferences.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file