2013-07-30 00:39:47 +00:00
|
|
|
package acr.browser.barebones.activities;
|
|
|
|
|
|
|
|
import acr.browser.barebones.R;
|
2013-08-03 00:08:52 +00:00
|
|
|
import acr.browser.barebones.utilities.FinalVariables;
|
|
|
|
import acr.browser.barebones.utilities.Utils;
|
2013-07-30 00:39:47 +00:00
|
|
|
import android.net.Uri;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.os.Environment;
|
|
|
|
import android.annotation.SuppressLint;
|
|
|
|
import android.app.Activity;
|
|
|
|
import android.app.AlertDialog;
|
|
|
|
import android.content.DialogInterface;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.SharedPreferences;
|
2013-07-31 00:25:14 +00:00
|
|
|
import android.content.pm.ApplicationInfo;
|
2013-07-30 00:39:47 +00:00
|
|
|
import android.content.pm.PackageInfo;
|
2013-07-31 00:25:14 +00:00
|
|
|
import android.content.pm.PackageManager;
|
2013-07-30 00:39:47 +00:00
|
|
|
import android.content.pm.PackageManager.NameNotFoundException;
|
2013-08-14 00:32:58 +00:00
|
|
|
import android.graphics.Color;
|
2013-07-30 00:39:47 +00:00
|
|
|
import android.util.Log;
|
2013-08-14 00:32:58 +00:00
|
|
|
import android.util.TypedValue;
|
2013-07-30 00:39:47 +00:00
|
|
|
import android.view.View;
|
2013-08-14 00:32:58 +00:00
|
|
|
import android.view.WindowManager;
|
2013-07-30 00:39:47 +00:00
|
|
|
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.ImageView;
|
2013-08-14 00:32:58 +00:00
|
|
|
import android.widget.LinearLayout;
|
2013-07-30 00:39:47 +00:00
|
|
|
import android.widget.RelativeLayout;
|
|
|
|
import android.widget.Switch;
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
|
|
public class SettingsActivity extends Activity {
|
|
|
|
static int API = FinalVariables.API;
|
|
|
|
static final String preferences = "settings";
|
2014-01-20 19:14:07 +00:00
|
|
|
static SharedPreferences.Editor mEditPrefs;
|
2013-07-30 00:39:47 +00:00
|
|
|
static int agentChoice;
|
|
|
|
static String homepage;
|
2014-03-07 05:28:54 +00:00
|
|
|
static String searchurl;
|
2013-07-30 00:39:47 +00:00
|
|
|
static TextView agentText;
|
2013-08-14 00:32:58 +00:00
|
|
|
static String agent;
|
2013-07-30 00:39:47 +00:00
|
|
|
static TextView download;
|
|
|
|
static int egg = 0;
|
|
|
|
static String downloadLocation;
|
|
|
|
static TextView homepageText;
|
|
|
|
static SharedPreferences settings;
|
|
|
|
static TextView searchText;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
setContentView(R.layout.settings);
|
2013-08-14 00:32:58 +00:00
|
|
|
|
2013-07-30 00:39:47 +00:00
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressLint("NewApi")
|
|
|
|
public void init() {
|
|
|
|
// settings storage
|
|
|
|
settings = getSharedPreferences(preferences, 0);
|
2013-08-14 00:32:58 +00:00
|
|
|
if (settings.getBoolean("hidestatus", false)) {
|
|
|
|
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
|
|
|
WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
|
|
|
}
|
2014-01-20 19:14:07 +00:00
|
|
|
mEditPrefs= settings.edit();
|
2013-07-30 00:39:47 +00:00
|
|
|
|
|
|
|
// initialize UI
|
|
|
|
RelativeLayout layoutLocation = (RelativeLayout) findViewById(R.id.layoutLocation);
|
|
|
|
RelativeLayout layoutFullScreen = (RelativeLayout) findViewById(R.id.layoutFullScreen);
|
|
|
|
RelativeLayout layoutFlash = (RelativeLayout) findViewById(R.id.layoutFlash);
|
|
|
|
ImageView back = (ImageView) findViewById(R.id.back);
|
|
|
|
|
|
|
|
searchText = (TextView) findViewById(R.id.searchText);
|
|
|
|
|
|
|
|
switch (settings.getInt("search", 1)) {
|
2014-03-07 05:28:54 +00:00
|
|
|
case 0:
|
|
|
|
searchText.setText("Custom URL");
|
|
|
|
break;
|
2013-07-30 00:39:47 +00:00
|
|
|
case 1:
|
|
|
|
searchText.setText("Google");
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
searchText.setText("Bing");
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
searchText.setText("Yahoo");
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
searchText.setText("StartPage");
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
searchText.setText("DuckDuckGo");
|
|
|
|
break;
|
2013-08-09 00:27:55 +00:00
|
|
|
case 6:
|
|
|
|
searchText.setText("Baidu");
|
|
|
|
break;
|
2013-08-14 00:32:58 +00:00
|
|
|
case 7:
|
|
|
|
searchText.setText("Yandex");
|
|
|
|
break;
|
2013-09-07 03:24:47 +00:00
|
|
|
case 8:
|
|
|
|
searchText.setText("DuckDuckGo Lite");
|
|
|
|
break;
|
2013-07-30 00:39:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
back.setBackgroundResource(R.drawable.button);
|
|
|
|
agentText = (TextView) findViewById(R.id.agentText);
|
|
|
|
homepageText = (TextView) findViewById(R.id.homepageText);
|
|
|
|
download = (TextView) findViewById(R.id.downloadText);
|
|
|
|
|
|
|
|
boolean locationBool = settings.getBoolean("location", false);
|
|
|
|
int flashNum = settings.getInt("enableflash", 0);
|
|
|
|
boolean fullScreenBool = settings.getBoolean("fullscreen", false);
|
|
|
|
agentChoice = settings.getInt("agentchoose", 1);
|
|
|
|
homepage = settings.getString("home", FinalVariables.HOMEPAGE);
|
|
|
|
downloadLocation = settings.getString("download",
|
2013-08-14 00:32:58 +00:00
|
|
|
Environment.DIRECTORY_DOWNLOADS);
|
2013-07-30 00:39:47 +00:00
|
|
|
|
2013-08-14 00:32:58 +00:00
|
|
|
download.setText(FinalVariables.EXTERNAL_STORAGE + "/"
|
|
|
|
+ downloadLocation);
|
2013-07-30 00:39:47 +00:00
|
|
|
|
2013-08-04 01:25:50 +00:00
|
|
|
String code = "HOLO";
|
2013-07-30 00:39:47 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
PackageInfo p = getPackageManager().getPackageInfo(
|
|
|
|
getPackageName(), 0);
|
2013-08-04 01:25:50 +00:00
|
|
|
code = p.versionName;
|
2013-07-30 00:39:47 +00:00
|
|
|
} catch (NameNotFoundException e) {
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
TextView version = (TextView) findViewById(R.id.versionCode);
|
|
|
|
version.setText(code + "");
|
|
|
|
|
|
|
|
if (homepage.contains("about:home")) {
|
2014-01-20 19:14:07 +00:00
|
|
|
homepageText.setText(getResources().getString(
|
|
|
|
R.string.action_homepage));
|
2013-07-30 00:39:47 +00:00
|
|
|
} else if (homepage.contains("about:blank")) {
|
2014-01-20 19:14:07 +00:00
|
|
|
homepageText.setText(getResources()
|
|
|
|
.getString(R.string.action_blank));
|
2013-07-30 00:39:47 +00:00
|
|
|
} else {
|
|
|
|
homepageText.setText(homepage);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (agentChoice) {
|
|
|
|
case 1:
|
2014-01-20 19:14:07 +00:00
|
|
|
agentText.setText(getResources().getString(R.string.agent_default));
|
2013-07-30 00:39:47 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2014-01-20 19:14:07 +00:00
|
|
|
agentText.setText(getResources().getString(R.string.agent_desktop));
|
2013-07-30 00:39:47 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
2014-01-20 19:14:07 +00:00
|
|
|
agentText.setText(getResources().getString(R.string.agent_mobile));
|
2013-07-30 00:39:47 +00:00
|
|
|
break;
|
2013-08-14 00:32:58 +00:00
|
|
|
case 4:
|
2014-01-20 19:14:07 +00:00
|
|
|
agentText.setText(getResources().getString(R.string.agent_custom));
|
2013-07-30 00:39:47 +00:00
|
|
|
}
|
|
|
|
RelativeLayout r1, r2, r3;
|
2013-08-01 02:01:53 +00:00
|
|
|
r1 = (RelativeLayout) findViewById(R.id.setR1);
|
|
|
|
r2 = (RelativeLayout) findViewById(R.id.setR2);
|
|
|
|
r3 = (RelativeLayout) findViewById(R.id.setR3);
|
2013-07-30 00:39:47 +00:00
|
|
|
if (API >= 14) {
|
|
|
|
Switch location = new Switch(this);
|
|
|
|
Switch fullScreen = new Switch(this);
|
|
|
|
Switch flash = new Switch(this);
|
|
|
|
|
|
|
|
r1.addView(location);
|
|
|
|
r2.addView(fullScreen);
|
|
|
|
r3.addView(flash);
|
|
|
|
location.setChecked(locationBool);
|
|
|
|
fullScreen.setChecked(fullScreenBool);
|
|
|
|
if (flashNum > 0) {
|
|
|
|
flash.setChecked(true);
|
|
|
|
} else {
|
|
|
|
flash.setChecked(false);
|
|
|
|
}
|
2013-08-01 02:01:53 +00:00
|
|
|
|
2013-07-30 00:39:47 +00:00
|
|
|
initSwitch(location, fullScreen, flash);
|
2013-08-01 02:01:53 +00:00
|
|
|
clickListenerForSwitches(layoutLocation, layoutFullScreen,
|
|
|
|
layoutFlash, location, fullScreen, flash);
|
2013-07-30 00:39:47 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
CheckBox location = new CheckBox(this);
|
|
|
|
CheckBox fullScreen = new CheckBox(this);
|
|
|
|
CheckBox flash = new CheckBox(this);
|
|
|
|
|
|
|
|
r1.addView(location);
|
|
|
|
r2.addView(fullScreen);
|
|
|
|
r3.addView(flash);
|
|
|
|
|
|
|
|
location.setChecked(locationBool);
|
|
|
|
fullScreen.setChecked(fullScreenBool);
|
|
|
|
if (flashNum > 0) {
|
|
|
|
flash.setChecked(true);
|
|
|
|
} else {
|
|
|
|
flash.setChecked(false);
|
|
|
|
}
|
|
|
|
initCheckBox(location, fullScreen, flash);
|
2013-08-01 02:01:53 +00:00
|
|
|
clickListenerForCheckBoxes(layoutLocation, layoutFullScreen,
|
|
|
|
layoutFlash, location, fullScreen, flash);
|
2013-07-30 00:39:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RelativeLayout agent = (RelativeLayout) findViewById(R.id.layoutUserAgent);
|
|
|
|
RelativeLayout download = (RelativeLayout) findViewById(R.id.layoutDownload);
|
|
|
|
RelativeLayout homepage = (RelativeLayout) findViewById(R.id.layoutHomepage);
|
|
|
|
RelativeLayout advanced = (RelativeLayout) findViewById(R.id.layoutAdvanced);
|
|
|
|
RelativeLayout source = (RelativeLayout) findViewById(R.id.layoutSource);
|
|
|
|
RelativeLayout license = (RelativeLayout) findViewById(R.id.layoutLicense);
|
|
|
|
|
|
|
|
back(back);
|
|
|
|
agent(agent);
|
|
|
|
download(download);
|
|
|
|
homepage(homepage);
|
|
|
|
advanced(advanced);
|
|
|
|
source(source);
|
|
|
|
license(license);
|
|
|
|
search();
|
|
|
|
easterEgg();
|
|
|
|
}
|
|
|
|
|
2013-08-01 02:01:53 +00:00
|
|
|
public void search() {
|
|
|
|
RelativeLayout search = (RelativeLayout) findViewById(R.id.layoutSearch);
|
|
|
|
search.setOnClickListener(new OnClickListener() {
|
2013-07-30 00:39:47 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
AlertDialog.Builder picker = new AlertDialog.Builder(
|
|
|
|
SettingsActivity.this);
|
2014-01-20 19:14:07 +00:00
|
|
|
picker.setTitle(getResources().getString(
|
|
|
|
R.string.title_search_engine));
|
2014-03-07 05:28:54 +00:00
|
|
|
CharSequence[] chars = { getResources().getString(R.string.custom_url),
|
|
|
|
"Google", "Bing", "Yahoo",
|
2013-09-07 03:24:47 +00:00
|
|
|
"StartPage", "DuckDuckGo (Privacy)" , "Baidu (Chinese)", "Yandex (Russian)", "DuckDuckGo Lite (Privacy)"};
|
2013-08-01 02:01:53 +00:00
|
|
|
|
2013-07-30 00:39:47 +00:00
|
|
|
int n = settings.getInt("search", 1);
|
|
|
|
|
2014-03-07 05:28:54 +00:00
|
|
|
picker.setSingleChoiceItems(chars, n,
|
2013-07-30 00:39:47 +00:00
|
|
|
new DialogInterface.OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog,
|
|
|
|
int which) {
|
2014-03-07 05:28:54 +00:00
|
|
|
mEditPrefs.putInt("search", which);
|
2014-01-20 19:14:07 +00:00
|
|
|
mEditPrefs.commit();
|
2014-03-07 05:28:54 +00:00
|
|
|
switch (which) {
|
|
|
|
case 0:
|
|
|
|
searchUrlPicker();
|
|
|
|
break;
|
2013-07-30 00:39:47 +00:00
|
|
|
case 1:
|
|
|
|
searchText.setText("Google");
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
searchText.setText("Bing");
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
searchText.setText("Yahoo");
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
searchText.setText("StartPage");
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
searchText.setText("DuckDuckGo");
|
|
|
|
break;
|
2013-08-09 00:27:55 +00:00
|
|
|
case 6:
|
|
|
|
searchText.setText("Baidu");
|
|
|
|
break;
|
2013-08-14 00:32:58 +00:00
|
|
|
case 7:
|
|
|
|
searchText.setText("Yandex");
|
|
|
|
break;
|
2013-09-07 03:24:47 +00:00
|
|
|
case 8:
|
|
|
|
searchText.setText("DuckDuckGo Lite");
|
|
|
|
break;
|
2013-07-30 00:39:47 +00:00
|
|
|
}
|
2013-08-01 02:01:53 +00:00
|
|
|
}
|
2013-07-30 00:39:47 +00:00
|
|
|
});
|
2014-01-20 19:14:07 +00:00
|
|
|
picker.setNeutralButton(getResources().getString(R.string.action_ok),
|
2013-07-30 00:39:47 +00:00
|
|
|
new DialogInterface.OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog,
|
|
|
|
int which) {
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
picker.show();
|
|
|
|
}
|
2013-08-01 02:01:53 +00:00
|
|
|
|
2013-07-30 00:39:47 +00:00
|
|
|
});
|
|
|
|
}
|
2013-08-01 02:01:53 +00:00
|
|
|
|
2014-03-07 05:28:54 +00:00
|
|
|
public void searchUrlPicker() {
|
|
|
|
final AlertDialog.Builder urlPicker = new AlertDialog.Builder(
|
|
|
|
SettingsActivity.this);
|
|
|
|
|
|
|
|
urlPicker.setTitle(getResources().getString(
|
|
|
|
R.string.custom_url));
|
|
|
|
final EditText getSearchUrl = new EditText(SettingsActivity.this);
|
|
|
|
|
|
|
|
searchurl = settings.getString("searchurl", FinalVariables.GOOGLE_SEARCH);
|
|
|
|
getSearchUrl.setText(searchurl);
|
|
|
|
urlPicker.setView(getSearchUrl);
|
|
|
|
urlPicker.setPositiveButton(
|
|
|
|
getResources().getString(R.string.action_ok),
|
|
|
|
new DialogInterface.OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
String text = getSearchUrl.getText().toString();
|
|
|
|
mEditPrefs.putString("searchurl", text);
|
|
|
|
mEditPrefs.commit();
|
|
|
|
searchText.setText( getResources().getString(R.string.custom_url) + ": " + text);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
urlPicker.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-01 02:01:53 +00:00
|
|
|
public void clickListenerForCheckBoxes(RelativeLayout one,
|
|
|
|
RelativeLayout two, RelativeLayout three, final CheckBox loc,
|
2013-07-30 00:39:47 +00:00
|
|
|
final CheckBox full, final CheckBox flash) {
|
2013-08-01 02:01:53 +00:00
|
|
|
one.setOnClickListener(new OnClickListener() {
|
2013-07-30 00:39:47 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
loc.setChecked(!loc.isChecked());
|
|
|
|
}
|
2013-08-01 02:01:53 +00:00
|
|
|
|
2013-07-30 00:39:47 +00:00
|
|
|
});
|
2013-08-01 02:01:53 +00:00
|
|
|
two.setOnClickListener(new OnClickListener() {
|
2013-07-30 00:39:47 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
full.setChecked(!full.isChecked());
|
|
|
|
}
|
2013-08-01 02:01:53 +00:00
|
|
|
|
2013-07-30 00:39:47 +00:00
|
|
|
});
|
2013-08-01 02:01:53 +00:00
|
|
|
three.setOnClickListener(new OnClickListener() {
|
2013-07-30 00:39:47 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
flash.setChecked(!flash.isChecked());
|
|
|
|
}
|
2013-08-01 02:01:53 +00:00
|
|
|
|
2013-07-30 00:39:47 +00:00
|
|
|
});
|
|
|
|
}
|
2013-08-01 02:01:53 +00:00
|
|
|
|
|
|
|
public void clickListenerForSwitches(RelativeLayout one,
|
|
|
|
RelativeLayout two, RelativeLayout three, final Switch loc,
|
2013-07-30 00:39:47 +00:00
|
|
|
final Switch full, final Switch flash) {
|
2013-08-01 02:01:53 +00:00
|
|
|
one.setOnClickListener(new OnClickListener() {
|
2013-07-30 00:39:47 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
loc.setChecked(!loc.isChecked());
|
|
|
|
}
|
2013-08-01 02:01:53 +00:00
|
|
|
|
2013-07-30 00:39:47 +00:00
|
|
|
});
|
2013-08-01 02:01:53 +00:00
|
|
|
two.setOnClickListener(new OnClickListener() {
|
2013-07-30 00:39:47 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
full.setChecked(!full.isChecked());
|
|
|
|
}
|
2013-08-01 02:01:53 +00:00
|
|
|
|
2013-07-30 00:39:47 +00:00
|
|
|
});
|
2013-08-01 02:01:53 +00:00
|
|
|
three.setOnClickListener(new OnClickListener() {
|
2013-07-30 00:39:47 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
flash.setChecked(!flash.isChecked());
|
|
|
|
}
|
2013-08-01 02:01:53 +00:00
|
|
|
|
2013-07-30 00:39:47 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public void easterEgg() {
|
|
|
|
RelativeLayout easter = (RelativeLayout) findViewById(R.id.layoutVersion);
|
|
|
|
easter.setOnClickListener(new OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
egg++;
|
|
|
|
if (egg == 10) {
|
2013-08-14 00:32:58 +00:00
|
|
|
startActivity(new Intent(Intent.ACTION_VIEW, Uri
|
|
|
|
.parse("http://imgs.xkcd.com/comics/compiling.png")));
|
2013-08-04 01:25:50 +00:00
|
|
|
finish();
|
2013-07-30 00:39:47 +00:00
|
|
|
egg = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public void initSwitch(Switch location, Switch fullscreen, Switch flash) {
|
|
|
|
location.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton buttonView,
|
|
|
|
boolean isChecked) {
|
2014-01-20 19:14:07 +00:00
|
|
|
mEditPrefs.putBoolean("location", isChecked);
|
|
|
|
mEditPrefs.commit();
|
2013-07-30 00:39:47 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
flash.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton buttonView,
|
|
|
|
boolean isChecked) {
|
|
|
|
int n = 0;
|
|
|
|
if (isChecked) {
|
|
|
|
n = 1;
|
|
|
|
}
|
2014-01-20 19:14:07 +00:00
|
|
|
mEditPrefs.putInt("enableflash", n);
|
|
|
|
mEditPrefs.commit();
|
2013-07-31 00:25:14 +00:00
|
|
|
boolean flashInstalled = false;
|
|
|
|
try {
|
2013-08-01 02:01:53 +00:00
|
|
|
PackageManager pm = getPackageManager();
|
|
|
|
ApplicationInfo ai = pm.getApplicationInfo(
|
|
|
|
"com.adobe.flashplayer", 0);
|
|
|
|
if (ai != null)
|
|
|
|
flashInstalled = true;
|
2013-07-31 00:25:14 +00:00
|
|
|
} catch (NameNotFoundException e) {
|
2013-08-01 02:01:53 +00:00
|
|
|
flashInstalled = false;
|
2013-07-31 00:25:14 +00:00
|
|
|
}
|
2013-08-01 02:01:53 +00:00
|
|
|
if (!flashInstalled && isChecked) {
|
2014-01-20 19:14:07 +00:00
|
|
|
Utils.createInformativeDialog(
|
|
|
|
SettingsActivity.this,
|
|
|
|
getResources().getString(R.string.title_warning),
|
|
|
|
getResources().getString(
|
|
|
|
R.string.dialog_adobe_not_installed));
|
2013-07-31 00:25:14 +00:00
|
|
|
buttonView.setChecked(false);
|
2014-01-20 19:14:07 +00:00
|
|
|
mEditPrefs.putInt("enableflash", 0);
|
|
|
|
mEditPrefs.commit();
|
2013-08-01 02:01:53 +00:00
|
|
|
|
2014-01-20 19:14:07 +00:00
|
|
|
} else if ((API >= 17) && isChecked) {
|
2013-08-01 02:01:53 +00:00
|
|
|
Utils.createInformativeDialog(
|
|
|
|
SettingsActivity.this,
|
2014-01-20 19:14:07 +00:00
|
|
|
getResources().getString(R.string.title_warning),
|
|
|
|
getResources().getString(
|
|
|
|
R.string.dialog_adobe_unsupported));
|
2013-07-31 00:25:14 +00:00
|
|
|
}
|
2013-07-30 00:39:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
fullscreen.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton buttonView,
|
|
|
|
boolean isChecked) {
|
2014-01-20 19:14:07 +00:00
|
|
|
mEditPrefs.putBoolean("fullscreen", isChecked);
|
|
|
|
mEditPrefs.commit();
|
2013-07-30 00:39:47 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
2013-08-01 02:01:53 +00:00
|
|
|
|
|
|
|
public void initCheckBox(CheckBox location, CheckBox fullscreen,
|
|
|
|
CheckBox flash) {
|
2013-07-30 00:39:47 +00:00
|
|
|
location.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton buttonView,
|
|
|
|
boolean isChecked) {
|
2014-01-20 19:14:07 +00:00
|
|
|
mEditPrefs.putBoolean("location", isChecked);
|
|
|
|
mEditPrefs.commit();
|
2013-07-30 00:39:47 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
flash.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton buttonView,
|
|
|
|
boolean isChecked) {
|
|
|
|
int n = 0;
|
|
|
|
if (isChecked) {
|
|
|
|
n = 1;
|
|
|
|
}
|
2014-01-20 19:14:07 +00:00
|
|
|
mEditPrefs.putInt("enableflash", n);
|
|
|
|
mEditPrefs.commit();
|
2013-07-31 00:25:14 +00:00
|
|
|
boolean flashInstalled = false;
|
|
|
|
try {
|
2013-08-01 02:01:53 +00:00
|
|
|
PackageManager pm = getPackageManager();
|
|
|
|
ApplicationInfo ai = pm.getApplicationInfo(
|
|
|
|
"com.adobe.flashplayer", 0);
|
|
|
|
if (ai != null)
|
|
|
|
flashInstalled = true;
|
2013-07-31 00:25:14 +00:00
|
|
|
} catch (NameNotFoundException e) {
|
2013-08-01 02:01:53 +00:00
|
|
|
flashInstalled = false;
|
2013-07-31 00:25:14 +00:00
|
|
|
}
|
2013-08-01 02:01:53 +00:00
|
|
|
if (!flashInstalled && isChecked) {
|
2014-01-20 19:14:07 +00:00
|
|
|
Utils.createInformativeDialog(
|
|
|
|
SettingsActivity.this,
|
|
|
|
getResources().getString(R.string.title_warning),
|
|
|
|
getResources().getString(
|
|
|
|
R.string.dialog_adobe_not_installed));
|
2013-07-31 00:25:14 +00:00
|
|
|
buttonView.setChecked(false);
|
2014-01-20 19:14:07 +00:00
|
|
|
mEditPrefs.putInt("enableflash", 0);
|
|
|
|
mEditPrefs.commit();
|
2013-08-01 02:01:53 +00:00
|
|
|
|
|
|
|
} else if ((API > 17) && isChecked) {
|
|
|
|
Utils.createInformativeDialog(
|
|
|
|
SettingsActivity.this,
|
2014-01-20 19:14:07 +00:00
|
|
|
getResources().getString(R.string.title_warning),
|
|
|
|
getResources().getString(
|
|
|
|
R.string.dialog_adobe_unsupported));
|
2013-07-31 00:25:14 +00:00
|
|
|
}
|
2013-07-30 00:39:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
fullscreen.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton buttonView,
|
|
|
|
boolean isChecked) {
|
2014-01-20 19:14:07 +00:00
|
|
|
mEditPrefs.putBoolean("fullscreen", isChecked);
|
|
|
|
mEditPrefs.commit();
|
2013-07-30 00:39:47 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public void back(ImageView view) {
|
|
|
|
view.setOnClickListener(new OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public void agent(RelativeLayout view) {
|
|
|
|
view.setOnClickListener(new OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
AlertDialog.Builder agentPicker = new AlertDialog.Builder(
|
|
|
|
SettingsActivity.this);
|
2014-01-20 19:14:07 +00:00
|
|
|
agentPicker.setTitle(getResources().getString(
|
|
|
|
R.string.title_user_agent));
|
|
|
|
CharSequence[] chars = {
|
|
|
|
getResources().getString(R.string.agent_default),
|
|
|
|
getResources().getString(R.string.agent_desktop),
|
|
|
|
getResources().getString(R.string.agent_mobile),
|
|
|
|
getResources().getString(R.string.agent_custom) };
|
2013-07-30 00:39:47 +00:00
|
|
|
agentChoice = settings.getInt("agentchoose", 1);
|
|
|
|
agentPicker.setSingleChoiceItems(chars, agentChoice - 1,
|
|
|
|
new DialogInterface.OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog,
|
|
|
|
int which) {
|
2014-01-20 19:14:07 +00:00
|
|
|
mEditPrefs.putInt("agentchoose", which + 1);
|
|
|
|
mEditPrefs.commit();
|
2013-07-30 00:39:47 +00:00
|
|
|
switch (which + 1) {
|
|
|
|
case 1:
|
2014-01-20 19:14:07 +00:00
|
|
|
agentText.setText(getResources().getString(
|
|
|
|
R.string.agent_default));
|
2013-07-30 00:39:47 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2014-01-20 19:14:07 +00:00
|
|
|
agentText.setText(getResources().getString(
|
|
|
|
R.string.agent_desktop));
|
2013-07-30 00:39:47 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
2014-01-20 19:14:07 +00:00
|
|
|
agentText.setText(getResources().getString(
|
|
|
|
R.string.agent_mobile));
|
2013-08-14 00:32:58 +00:00
|
|
|
break;
|
|
|
|
case 4:
|
2014-01-20 19:14:07 +00:00
|
|
|
agentText.setText(getResources().getString(
|
|
|
|
R.string.agent_custom));
|
2013-08-14 00:32:58 +00:00
|
|
|
agentPicker();
|
2013-07-30 00:39:47 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2014-01-20 19:14:07 +00:00
|
|
|
agentPicker.setNeutralButton(
|
|
|
|
getResources().getString(R.string.action_ok),
|
2013-07-30 00:39:47 +00:00
|
|
|
new DialogInterface.OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog,
|
|
|
|
int which) {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
agentPicker
|
|
|
|
.setOnCancelListener(new DialogInterface.OnCancelListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCancel(DialogInterface dialog) {
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
Log.i("Cancelled", "");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
agentPicker.show();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
2013-08-14 00:32:58 +00:00
|
|
|
|
|
|
|
public void agentPicker() {
|
|
|
|
final AlertDialog.Builder agentStringPicker = new AlertDialog.Builder(
|
|
|
|
SettingsActivity.this);
|
|
|
|
|
2014-01-20 19:14:07 +00:00
|
|
|
agentStringPicker.setTitle(getResources().getString(
|
|
|
|
R.string.title_user_agent));
|
2013-08-14 00:32:58 +00:00
|
|
|
final EditText getAgent = new EditText(SettingsActivity.this);
|
|
|
|
agentStringPicker.setView(getAgent);
|
2014-01-20 19:14:07 +00:00
|
|
|
agentStringPicker.setPositiveButton(
|
|
|
|
getResources().getString(R.string.action_ok),
|
2013-08-14 00:32:58 +00:00
|
|
|
new DialogInterface.OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
String text = getAgent.getText().toString();
|
2014-01-20 19:14:07 +00:00
|
|
|
mEditPrefs.putString("userAgentString", text);
|
|
|
|
mEditPrefs.commit();
|
|
|
|
agentText.setText(getResources().getString(
|
|
|
|
R.string.agent_custom));
|
2013-08-14 00:32:58 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
agentStringPicker.show();
|
|
|
|
}
|
2013-07-30 00:39:47 +00:00
|
|
|
|
|
|
|
public void download(RelativeLayout view) {
|
|
|
|
view.setOnClickListener(new OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
|
|
|
AlertDialog.Builder picker = new AlertDialog.Builder(
|
|
|
|
SettingsActivity.this);
|
2014-01-20 19:14:07 +00:00
|
|
|
picker.setTitle(getResources().getString(
|
|
|
|
R.string.title_download_location));
|
|
|
|
CharSequence[] chars = {
|
|
|
|
getResources().getString(R.string.agent_default),
|
|
|
|
getResources().getString(R.string.agent_custom) };
|
2013-07-30 00:39:47 +00:00
|
|
|
downloadLocation = settings.getString("download",
|
2013-08-14 00:32:58 +00:00
|
|
|
Environment.DIRECTORY_DOWNLOADS);
|
2013-07-30 00:39:47 +00:00
|
|
|
int n = -1;
|
2013-08-14 00:32:58 +00:00
|
|
|
if (downloadLocation.contains(Environment.DIRECTORY_DOWNLOADS)) {
|
2013-07-30 00:39:47 +00:00
|
|
|
n = 1;
|
|
|
|
} else {
|
|
|
|
n = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
picker.setSingleChoiceItems(chars, n - 1,
|
|
|
|
new DialogInterface.OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog,
|
|
|
|
int which) {
|
|
|
|
|
|
|
|
switch (which + 1) {
|
|
|
|
case 1:
|
2014-01-20 19:14:07 +00:00
|
|
|
mEditPrefs.putString("download",
|
2013-08-14 00:32:58 +00:00
|
|
|
Environment.DIRECTORY_DOWNLOADS);
|
2014-01-20 19:14:07 +00:00
|
|
|
mEditPrefs.commit();
|
2013-08-14 00:32:58 +00:00
|
|
|
download.setText(FinalVariables.EXTERNAL_STORAGE
|
|
|
|
+ "/"
|
|
|
|
+ Environment.DIRECTORY_DOWNLOADS);
|
2013-07-30 00:39:47 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
downPicker();
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2014-01-20 19:14:07 +00:00
|
|
|
picker.setNeutralButton(
|
|
|
|
getResources().getString(R.string.action_ok),
|
2013-07-30 00:39:47 +00:00
|
|
|
new DialogInterface.OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog,
|
|
|
|
int which) {
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
picker.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public void homePicker() {
|
|
|
|
final AlertDialog.Builder homePicker = new AlertDialog.Builder(
|
2014-01-20 19:14:07 +00:00
|
|
|
this);
|
|
|
|
homePicker.setTitle(getResources().getString(
|
|
|
|
R.string.title_custom_homepage));
|
2013-07-30 00:39:47 +00:00
|
|
|
final EditText getHome = new EditText(SettingsActivity.this);
|
|
|
|
homepage = settings.getString("home", FinalVariables.HOMEPAGE);
|
|
|
|
if (!homepage.startsWith("about:")) {
|
|
|
|
getHome.setText(homepage);
|
|
|
|
} else {
|
|
|
|
getHome.setText("http://www.google.com");
|
|
|
|
}
|
|
|
|
homePicker.setView(getHome);
|
2014-01-20 19:14:07 +00:00
|
|
|
homePicker.setPositiveButton(getResources().getString(R.string.action_ok),
|
2013-07-30 00:39:47 +00:00
|
|
|
new DialogInterface.OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
String text = getHome.getText().toString();
|
2014-01-20 19:14:07 +00:00
|
|
|
mEditPrefs.putString("home", text);
|
|
|
|
mEditPrefs.commit();
|
2013-07-30 00:39:47 +00:00
|
|
|
homepageText.setText(text);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
homePicker.show();
|
|
|
|
}
|
|
|
|
|
2013-08-14 00:32:58 +00:00
|
|
|
@SuppressWarnings("deprecation")
|
2013-07-30 00:39:47 +00:00
|
|
|
public void downPicker() {
|
|
|
|
final AlertDialog.Builder downLocationPicker = new AlertDialog.Builder(
|
2014-01-20 19:14:07 +00:00
|
|
|
this);
|
2013-08-14 00:32:58 +00:00
|
|
|
LinearLayout layout = new LinearLayout(this);
|
2014-01-20 19:14:07 +00:00
|
|
|
downLocationPicker.setTitle(getResources().getString(
|
|
|
|
R.string.title_download_location));
|
2013-07-30 00:39:47 +00:00
|
|
|
final EditText getDownload = new EditText(SettingsActivity.this);
|
2013-08-14 00:32:58 +00:00
|
|
|
getDownload.setBackgroundResource(0);
|
2013-07-30 00:39:47 +00:00
|
|
|
downloadLocation = settings.getString("download",
|
2013-08-14 00:32:58 +00:00
|
|
|
Environment.DIRECTORY_DOWNLOADS);
|
2014-01-20 19:14:07 +00:00
|
|
|
int padding = Utils.convertDensityPixels(this, 10);
|
2013-08-14 00:32:58 +00:00
|
|
|
|
|
|
|
LinearLayout.LayoutParams lparams = new LinearLayout.LayoutParams(
|
|
|
|
LinearLayout.LayoutParams.MATCH_PARENT,
|
|
|
|
LinearLayout.LayoutParams.MATCH_PARENT);
|
|
|
|
|
|
|
|
getDownload.setLayoutParams(lparams);
|
|
|
|
getDownload.setTextColor(Color.DKGRAY);
|
2013-07-30 00:39:47 +00:00
|
|
|
getDownload.setText(downloadLocation);
|
2013-08-14 00:32:58 +00:00
|
|
|
getDownload.setPadding(0, padding, padding, padding);
|
|
|
|
|
|
|
|
TextView v = new TextView(this);
|
|
|
|
v.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
|
|
|
|
v.setTextColor(Color.DKGRAY);
|
|
|
|
v.setText(FinalVariables.EXTERNAL_STORAGE + "/");
|
|
|
|
v.setPadding(padding, padding, 0, padding);
|
|
|
|
layout.addView(v);
|
|
|
|
layout.addView(getDownload);
|
|
|
|
if (API < 16) {
|
|
|
|
layout.setBackgroundDrawable(getResources().getDrawable(
|
|
|
|
android.R.drawable.edit_text));
|
|
|
|
} else {
|
|
|
|
layout.setBackground(getResources().getDrawable(
|
|
|
|
android.R.drawable.edit_text));
|
|
|
|
}
|
|
|
|
downLocationPicker.setView(layout);
|
2014-01-20 19:14:07 +00:00
|
|
|
downLocationPicker.setPositiveButton(
|
|
|
|
getResources().getString(R.string.action_ok),
|
2013-07-30 00:39:47 +00:00
|
|
|
new DialogInterface.OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
String text = getDownload.getText().toString();
|
2014-01-20 19:14:07 +00:00
|
|
|
mEditPrefs.putString("download", text);
|
|
|
|
mEditPrefs.commit();
|
2013-08-14 00:32:58 +00:00
|
|
|
download.setText(FinalVariables.EXTERNAL_STORAGE + "/"
|
|
|
|
+ text);
|
2013-07-30 00:39:47 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
downLocationPicker.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void homepage(RelativeLayout view) {
|
|
|
|
view.setOnClickListener(new OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
AlertDialog.Builder picker = new AlertDialog.Builder(
|
|
|
|
SettingsActivity.this);
|
|
|
|
picker.setTitle("Homepage");
|
|
|
|
CharSequence[] chars = { "Bookmarks", "Blank Page", "Webpage" };
|
|
|
|
homepage = settings.getString("home", FinalVariables.HOMEPAGE);
|
|
|
|
int n = -1;
|
|
|
|
if (homepage.contains("about:home")) {
|
|
|
|
n = 1;
|
|
|
|
} else if (homepage.contains("about:blank")) {
|
|
|
|
n = 2;
|
|
|
|
} else {
|
|
|
|
n = 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
picker.setSingleChoiceItems(chars, n - 1,
|
|
|
|
new DialogInterface.OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog,
|
|
|
|
int which) {
|
|
|
|
|
|
|
|
switch (which + 1) {
|
|
|
|
case 1:
|
2014-01-20 19:14:07 +00:00
|
|
|
mEditPrefs.putString("home", "about:home");
|
|
|
|
mEditPrefs.commit();
|
2013-07-30 00:39:47 +00:00
|
|
|
homepageText.setText("Bookmarks");
|
|
|
|
break;
|
|
|
|
case 2:
|
2014-01-20 19:14:07 +00:00
|
|
|
mEditPrefs.putString("home", "about:blank");
|
|
|
|
mEditPrefs.commit();
|
2013-07-30 00:39:47 +00:00
|
|
|
homepageText.setText("Blank Page");
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
homePicker();
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
picker.setNeutralButton("OK",
|
|
|
|
new DialogInterface.OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog,
|
|
|
|
int which) {
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
picker.show();
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public void advanced(RelativeLayout view) {
|
|
|
|
view.setOnClickListener(new OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
startActivity(new Intent(
|
2013-08-14 00:32:58 +00:00
|
|
|
FinalVariables.ADVANCED_SETTINGS_INTENT));
|
2013-07-30 00:39:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public void source(RelativeLayout view) {
|
|
|
|
view.setOnClickListener(new OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
startActivity(new Intent(
|
|
|
|
Intent.ACTION_VIEW,
|
|
|
|
Uri.parse("https://github.com/anthonycr/Lightning-Browser")));
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public void license(RelativeLayout view) {
|
|
|
|
view.setOnClickListener(new OnClickListener() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
startActivity(new Intent(Intent.ACTION_VIEW, Uri
|
|
|
|
.parse("http://www.apache.org/licenses/LICENSE-2.0")));
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|