You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
925 lines
27 KiB
925 lines
27 KiB
11 years ago
|
/*
|
||
|
* Copyright 2014 A.C.R. Development
|
||
|
*/
|
||
|
package acr.browser.lightning;
|
||
11 years ago
|
|
||
|
import android.net.Uri;
|
||
|
import android.os.Bundle;
|
||
|
import android.os.Environment;
|
||
|
import android.annotation.SuppressLint;
|
||
|
import android.app.Activity;
|
||
|
import android.app.AlertDialog;
|
||
11 years ago
|
import android.content.Context;
|
||
11 years ago
|
import android.content.DialogInterface;
|
||
11 years ago
|
import android.content.DialogInterface.OnCancelListener;
|
||
11 years ago
|
import android.content.Intent;
|
||
|
import android.content.SharedPreferences;
|
||
11 years ago
|
import android.content.pm.ApplicationInfo;
|
||
11 years ago
|
import android.content.pm.PackageInfo;
|
||
11 years ago
|
import android.content.pm.PackageManager;
|
||
11 years ago
|
import android.content.pm.PackageManager.NameNotFoundException;
|
||
11 years ago
|
import android.graphics.Color;
|
||
11 years ago
|
import android.util.Log;
|
||
11 years ago
|
import android.util.TypedValue;
|
||
11 years ago
|
import android.view.MenuItem;
|
||
11 years ago
|
import android.view.View;
|
||
11 years ago
|
import android.view.WindowManager;
|
||
11 years ago
|
import android.view.View.OnClickListener;
|
||
|
import android.widget.CheckBox;
|
||
|
import android.widget.CompoundButton;
|
||
|
import android.widget.CompoundButton.OnCheckedChangeListener;
|
||
|
import android.widget.EditText;
|
||
11 years ago
|
import android.widget.LinearLayout;
|
||
11 years ago
|
import android.widget.RelativeLayout;
|
||
|
import android.widget.Switch;
|
||
|
import android.widget.TextView;
|
||
|
|
||
|
public class SettingsActivity extends Activity {
|
||
11 years ago
|
|
||
|
private static int API = android.os.Build.VERSION.SDK_INT;
|
||
|
private static SharedPreferences.Editor mEditPrefs;
|
||
|
private static int mAgentChoice;
|
||
|
private static String mHomepage;
|
||
|
private static TextView mAgentTextView;
|
||
|
private static TextView mDownloadTextView;
|
||
|
private static int mEasterEggCounter = 0;
|
||
|
private static String mSearchUrl;
|
||
|
private static String mDownloadLocation;
|
||
|
private static TextView mHomepageText;
|
||
|
private static SharedPreferences mPreferences;
|
||
|
private static TextView mSearchText;
|
||
|
private Context mContext;
|
||
|
private Activity mActivity;
|
||
11 years ago
|
|
||
|
@Override
|
||
|
protected void onCreate(Bundle savedInstanceState) {
|
||
|
super.onCreate(savedInstanceState);
|
||
|
setContentView(R.layout.settings);
|
||
11 years ago
|
mContext = this;
|
||
|
mActivity = this;
|
||
11 years ago
|
init();
|
||
|
}
|
||
|
|
||
11 years ago
|
@Override
|
||
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||
|
finish();
|
||
|
return true;
|
||
|
}
|
||
|
|
||
11 years ago
|
@SuppressLint("NewApi")
|
||
|
public void init() {
|
||
11 years ago
|
// mPreferences storage
|
||
|
getActionBar().setHomeButtonEnabled(true);
|
||
|
getActionBar().setDisplayHomeAsUpEnabled(true);
|
||
|
mPreferences = getSharedPreferences(PreferenceConstants.PREFERENCES, 0);
|
||
|
if (mPreferences.getBoolean(PreferenceConstants.HIDE_STATUS_BAR, false)) {
|
||
11 years ago
|
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
||
|
WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||
|
}
|
||
11 years ago
|
|
||
|
mEditPrefs = mPreferences.edit();
|
||
11 years ago
|
|
||
|
// initialize UI
|
||
|
RelativeLayout layoutLocation = (RelativeLayout) findViewById(R.id.layoutLocation);
|
||
|
RelativeLayout layoutFullScreen = (RelativeLayout) findViewById(R.id.layoutFullScreen);
|
||
|
RelativeLayout layoutFlash = (RelativeLayout) findViewById(R.id.layoutFlash);
|
||
11 years ago
|
RelativeLayout layoutBlockAds = (RelativeLayout) findViewById(R.id.layoutAdBlock);
|
||
11 years ago
|
|
||
11 years ago
|
mSearchText = (TextView) findViewById(R.id.searchText);
|
||
11 years ago
|
|
||
11 years ago
|
switch (mPreferences.getInt(PreferenceConstants.SEARCH, 1)) {
|
||
11 years ago
|
case 0:
|
||
11 years ago
|
mSearchText.setText(getResources().getString(R.string.custom_url));
|
||
11 years ago
|
break;
|
||
11 years ago
|
case 1:
|
||
11 years ago
|
mSearchText.setText("Google");
|
||
11 years ago
|
break;
|
||
|
case 2:
|
||
11 years ago
|
mSearchText.setText("Android Search");
|
||
11 years ago
|
break;
|
||
|
case 3:
|
||
11 years ago
|
mSearchText.setText("Bing");
|
||
11 years ago
|
break;
|
||
|
case 4:
|
||
11 years ago
|
mSearchText.setText("Yahoo");
|
||
11 years ago
|
break;
|
||
|
case 5:
|
||
11 years ago
|
mSearchText.setText("StartPage");
|
||
11 years ago
|
break;
|
||
11 years ago
|
case 6:
|
||
11 years ago
|
mSearchText.setText("StartPage (Mobile)");
|
||
11 years ago
|
break;
|
||
11 years ago
|
case 7:
|
||
11 years ago
|
mSearchText.setText("DuckDuckGo");
|
||
11 years ago
|
break;
|
||
11 years ago
|
case 8:
|
||
11 years ago
|
mSearchText.setText("DuckDuckGo Lite");
|
||
11 years ago
|
break;
|
||
11 years ago
|
case 9:
|
||
|
mSearchText.setText("Baidu");
|
||
|
break;
|
||
|
case 10:
|
||
|
mSearchText.setText("Yandex");
|
||
11 years ago
|
}
|
||
|
|
||
11 years ago
|
mAgentTextView = (TextView) findViewById(R.id.agentText);
|
||
|
mHomepageText = (TextView) findViewById(R.id.homepageText);
|
||
|
mDownloadTextView = (TextView) findViewById(R.id.downloadText);
|
||
|
if (API >= 19) {
|
||
|
mEditPrefs.putInt(PreferenceConstants.ADOBE_FLASH_SUPPORT, 0);
|
||
|
mEditPrefs.commit();
|
||
|
}
|
||
|
boolean locationBool = mPreferences.getBoolean(PreferenceConstants.LOCATION, false);
|
||
|
int flashNum = mPreferences.getInt(PreferenceConstants.ADOBE_FLASH_SUPPORT, 0);
|
||
|
boolean fullScreenBool = mPreferences.getBoolean(PreferenceConstants.FULL_SCREEN, false);
|
||
|
mAgentChoice = mPreferences.getInt(PreferenceConstants.USER_AGENT, 1);
|
||
|
mHomepage = mPreferences.getString(PreferenceConstants.HOMEPAGE, Constants.HOMEPAGE);
|
||
|
mDownloadLocation = mPreferences.getString(PreferenceConstants.DOWNLOAD_DIRECTORY,
|
||
11 years ago
|
Environment.DIRECTORY_DOWNLOADS);
|
||
11 years ago
|
|
||
11 years ago
|
mDownloadTextView.setText(Constants.EXTERNAL_STORAGE + "/" + mDownloadLocation);
|
||
11 years ago
|
|
||
11 years ago
|
String code = "HOLO";
|
||
11 years ago
|
|
||
|
try {
|
||
|
PackageInfo p = getPackageManager().getPackageInfo(
|
||
|
getPackageName(), 0);
|
||
11 years ago
|
code = p.versionName;
|
||
11 years ago
|
} catch (NameNotFoundException e) {
|
||
|
// TODO Auto-generated catch block
|
||
|
e.printStackTrace();
|
||
|
}
|
||
|
|
||
|
TextView version = (TextView) findViewById(R.id.versionCode);
|
||
|
version.setText(code + "");
|
||
|
|
||
11 years ago
|
if (mHomepage.contains("about:home")) {
|
||
|
mHomepageText.setText(getResources().getString(
|
||
11 years ago
|
R.string.action_homepage));
|
||
11 years ago
|
} else if (mHomepage.contains("about:blank")) {
|
||
|
mHomepageText.setText(getResources()
|
||
11 years ago
|
.getString(R.string.action_blank));
|
||
11 years ago
|
} else if (mHomepage.contains("about:bookmarks")) {
|
||
|
mHomepageText.setText(getResources().getString(
|
||
|
R.string.action_bookmarks));
|
||
11 years ago
|
} else {
|
||
11 years ago
|
mHomepageText.setText(mHomepage);
|
||
11 years ago
|
}
|
||
|
|
||
11 years ago
|
switch (mAgentChoice) {
|
||
11 years ago
|
case 1:
|
||
11 years ago
|
mAgentTextView.setText(getResources().getString(R.string.agent_default));
|
||
11 years ago
|
break;
|
||
|
case 2:
|
||
11 years ago
|
mAgentTextView.setText(getResources().getString(R.string.agent_desktop));
|
||
11 years ago
|
break;
|
||
|
case 3:
|
||
11 years ago
|
mAgentTextView.setText(getResources().getString(R.string.agent_mobile));
|
||
11 years ago
|
break;
|
||
11 years ago
|
case 4:
|
||
11 years ago
|
mAgentTextView.setText(getResources().getString(R.string.agent_custom));
|
||
11 years ago
|
}
|
||
11 years ago
|
RelativeLayout r1, r2, r3, r4, licenses;
|
||
11 years ago
|
r1 = (RelativeLayout) findViewById(R.id.setR1);
|
||
|
r2 = (RelativeLayout) findViewById(R.id.setR2);
|
||
|
r3 = (RelativeLayout) findViewById(R.id.setR3);
|
||
11 years ago
|
r4 = (RelativeLayout) findViewById(R.id.setR4);
|
||
|
licenses = (RelativeLayout) findViewById(R.id.layoutLicense);
|
||
|
|
||
|
licenses.setOnClickListener(new OnClickListener(){
|
||
11 years ago
|
|
||
11 years ago
|
@Override
|
||
|
public void onClick(View arg0) {
|
||
|
//NOTE: In order to comply with the open source license,
|
||
|
//it is advised that you leave this code so that the License
|
||
|
//Activity may be viewed by the user.
|
||
|
startActivity(new Intent(Constants.LICENSE_INTENT));
|
||
11 years ago
|
}
|
||
11 years ago
|
|
||
|
});
|
||
|
|
||
|
Switch location = new Switch(this);
|
||
|
Switch fullScreen = new Switch(this);
|
||
|
Switch flash = new Switch(this);
|
||
|
Switch adblock = new Switch(this);
|
||
|
|
||
|
r1.addView(location);
|
||
|
r2.addView(fullScreen);
|
||
|
r3.addView(flash);
|
||
|
r4.addView(adblock);
|
||
|
location.setChecked(locationBool);
|
||
|
fullScreen.setChecked(fullScreenBool);
|
||
|
if (flashNum > 0) {
|
||
|
flash.setChecked(true);
|
||
|
} else {
|
||
|
flash.setChecked(false);
|
||
11 years ago
|
}
|
||
11 years ago
|
adblock.setChecked(mPreferences.getBoolean(PreferenceConstants.BLOCK_ADS, false));
|
||
|
|
||
|
initSwitch(location, fullScreen, flash, adblock);
|
||
|
clickListenerForSwitches(layoutLocation, layoutFullScreen, layoutFlash, layoutBlockAds,
|
||
|
location, fullScreen, flash, adblock);
|
||
11 years ago
|
|
||
|
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);
|
||
|
|
||
|
agent(agent);
|
||
|
download(download);
|
||
|
homepage(homepage);
|
||
|
advanced(advanced);
|
||
|
source(source);
|
||
|
search();
|
||
|
easterEgg();
|
||
|
}
|
||
|
|
||
11 years ago
|
public void search() {
|
||
|
RelativeLayout search = (RelativeLayout) findViewById(R.id.layoutSearch);
|
||
|
search.setOnClickListener(new OnClickListener() {
|
||
11 years ago
|
|
||
|
@Override
|
||
|
public void onClick(View v) {
|
||
11 years ago
|
AlertDialog.Builder picker = new AlertDialog.Builder(mActivity);
|
||
11 years ago
|
picker.setTitle(getResources().getString(
|
||
|
R.string.title_search_engine));
|
||
11 years ago
|
CharSequence[] chars = {
|
||
|
getResources().getString(R.string.custom_url),
|
||
|
"Google", "Android Search", "Bing", "Yahoo", "StartPage", "StartPage (Mobile)",
|
||
|
"DuckDuckGo (Privacy)", "DuckDuckGo Lite (Privacy)", "Baidu (Chinese)",
|
||
|
"Yandex (Russian)" };
|
||
11 years ago
|
|
||
11 years ago
|
int n = mPreferences.getInt(PreferenceConstants.SEARCH, 1);
|
||
11 years ago
|
|
||
11 years ago
|
picker.setSingleChoiceItems(chars, n,
|
||
11 years ago
|
new DialogInterface.OnClickListener() {
|
||
|
|
||
|
@Override
|
||
|
public void onClick(DialogInterface dialog,
|
||
|
int which) {
|
||
11 years ago
|
mEditPrefs.putInt(PreferenceConstants.SEARCH, which);
|
||
11 years ago
|
mEditPrefs.commit();
|
||
11 years ago
|
switch (which) {
|
||
|
case 0:
|
||
|
searchUrlPicker();
|
||
|
break;
|
||
11 years ago
|
case 1:
|
||
11 years ago
|
mSearchText.setText("Google");
|
||
11 years ago
|
break;
|
||
|
case 2:
|
||
11 years ago
|
mSearchText.setText("Android Search");
|
||
11 years ago
|
break;
|
||
|
case 3:
|
||
11 years ago
|
mSearchText.setText("Bing");
|
||
11 years ago
|
break;
|
||
|
case 4:
|
||
11 years ago
|
mSearchText.setText("Yahoo");
|
||
11 years ago
|
break;
|
||
|
case 5:
|
||
11 years ago
|
mSearchText.setText("StartPage");
|
||
11 years ago
|
break;
|
||
11 years ago
|
case 6:
|
||
11 years ago
|
mSearchText.setText("StartPage (Mobile)");
|
||
11 years ago
|
break;
|
||
11 years ago
|
case 7:
|
||
11 years ago
|
mSearchText.setText("DuckDuckGo");
|
||
11 years ago
|
break;
|
||
11 years ago
|
case 8:
|
||
11 years ago
|
mSearchText.setText("DuckDuckGo Lite");
|
||
|
break;
|
||
|
case 9:
|
||
|
mSearchText.setText("Baidu");
|
||
11 years ago
|
break;
|
||
11 years ago
|
case 10:
|
||
|
mSearchText.setText("Yandex");
|
||
11 years ago
|
}
|
||
11 years ago
|
}
|
||
11 years ago
|
});
|
||
11 years ago
|
picker.setNeutralButton(
|
||
|
getResources().getString(R.string.action_ok),
|
||
11 years ago
|
new DialogInterface.OnClickListener() {
|
||
|
|
||
|
@Override
|
||
|
public void onClick(DialogInterface dialog,
|
||
|
int which) {
|
||
|
|
||
|
}
|
||
|
});
|
||
|
picker.show();
|
||
|
}
|
||
11 years ago
|
|
||
11 years ago
|
});
|
||
|
}
|
||
11 years ago
|
|
||
11 years ago
|
public void searchUrlPicker() {
|
||
|
final AlertDialog.Builder urlPicker = new AlertDialog.Builder(
|
||
|
SettingsActivity.this);
|
||
11 years ago
|
|
||
|
urlPicker.setTitle(getResources().getString(R.string.custom_url));
|
||
11 years ago
|
final EditText getSearchUrl = new EditText(SettingsActivity.this);
|
||
|
|
||
11 years ago
|
mSearchUrl = mPreferences
|
||
|
.getString(PreferenceConstants.SEARCH_URL, Constants.GOOGLE_SEARCH);
|
||
|
getSearchUrl.setText(mSearchUrl);
|
||
11 years ago
|
urlPicker.setView(getSearchUrl);
|
||
11 years ago
|
urlPicker.setPositiveButton(getResources()
|
||
|
.getString(R.string.action_ok),
|
||
11 years ago
|
new DialogInterface.OnClickListener() {
|
||
|
|
||
|
@Override
|
||
|
public void onClick(DialogInterface dialog, int which) {
|
||
|
String text = getSearchUrl.getText().toString();
|
||
11 years ago
|
mEditPrefs.putString(PreferenceConstants.SEARCH_URL, text);
|
||
11 years ago
|
mEditPrefs.commit();
|
||
11 years ago
|
mSearchText.setText(getResources().getString(
|
||
|
R.string.custom_url)
|
||
|
+ ": " + text);
|
||
11 years ago
|
}
|
||
|
});
|
||
|
urlPicker.show();
|
||
|
}
|
||
|
|
||
11 years ago
|
public void clickListenerForSwitches(RelativeLayout one,
|
||
|
RelativeLayout two, RelativeLayout three, RelativeLayout layoutBlockAds, final Switch loc,
|
||
|
final Switch full, final Switch flash, final Switch adblock) {
|
||
|
layoutBlockAds.setOnClickListener(new OnClickListener(){
|
||
11 years ago
|
|
||
|
@Override
|
||
|
public void onClick(View v) {
|
||
11 years ago
|
adblock.setChecked(!adblock.isChecked());
|
||
11 years ago
|
}
|
||
11 years ago
|
|
||
11 years ago
|
});
|
||
11 years ago
|
one.setOnClickListener(new OnClickListener() {
|
||
11 years ago
|
|
||
|
@Override
|
||
|
public void onClick(View v) {
|
||
|
loc.setChecked(!loc.isChecked());
|
||
|
}
|
||
11 years ago
|
|
||
11 years ago
|
});
|
||
11 years ago
|
two.setOnClickListener(new OnClickListener() {
|
||
11 years ago
|
|
||
|
@Override
|
||
|
public void onClick(View v) {
|
||
|
full.setChecked(!full.isChecked());
|
||
|
}
|
||
11 years ago
|
|
||
11 years ago
|
});
|
||
11 years ago
|
three.setOnClickListener(new OnClickListener() {
|
||
11 years ago
|
|
||
|
@Override
|
||
|
public void onClick(View v) {
|
||
11 years ago
|
if (API < 19) {
|
||
|
flash.setChecked(!flash.isChecked());
|
||
|
} else {
|
||
|
Utils.createInformativeDialog(mContext, getResources()
|
||
|
.getString(R.string.title_warning), getResources()
|
||
|
.getString(R.string.dialog_adobe_dead));
|
||
|
}
|
||
11 years ago
|
}
|
||
11 years ago
|
|
||
11 years ago
|
});
|
||
|
}
|
||
|
|
||
|
public void easterEgg() {
|
||
|
RelativeLayout easter = (RelativeLayout) findViewById(R.id.layoutVersion);
|
||
|
easter.setOnClickListener(new OnClickListener() {
|
||
|
|
||
|
@Override
|
||
|
public void onClick(View v) {
|
||
11 years ago
|
mEasterEggCounter++;
|
||
|
if (mEasterEggCounter == 10) {
|
||
11 years ago
|
startActivity(new Intent(Intent.ACTION_VIEW, Uri
|
||
|
.parse("http://imgs.xkcd.com/comics/compiling.png")));
|
||
11 years ago
|
finish();
|
||
11 years ago
|
mEasterEggCounter = 0;
|
||
11 years ago
|
}
|
||
|
}
|
||
|
|
||
|
});
|
||
|
}
|
||
|
|
||
11 years ago
|
public void initSwitch(Switch location, Switch fullscreen, Switch flash, Switch adblock) {
|
||
|
adblock.setOnCheckedChangeListener(new OnCheckedChangeListener(){
|
||
|
|
||
|
@Override
|
||
|
public void onCheckedChanged(CompoundButton buttonView,
|
||
|
boolean isChecked) {
|
||
|
mEditPrefs.putBoolean(PreferenceConstants.BLOCK_ADS, isChecked);
|
||
|
mEditPrefs.commit();
|
||
|
}
|
||
|
|
||
|
});
|
||
11 years ago
|
location.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
||
|
|
||
|
@Override
|
||
|
public void onCheckedChanged(CompoundButton buttonView,
|
||
|
boolean isChecked) {
|
||
11 years ago
|
mEditPrefs.putBoolean(PreferenceConstants.LOCATION, isChecked);
|
||
11 years ago
|
mEditPrefs.commit();
|
||
11 years ago
|
|
||
|
}
|
||
|
|
||
|
});
|
||
11 years ago
|
flash.setEnabled(API < 19);
|
||
11 years ago
|
flash.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
||
|
|
||
|
@Override
|
||
|
public void onCheckedChanged(CompoundButton buttonView,
|
||
|
boolean isChecked) {
|
||
|
if (isChecked) {
|
||
11 years ago
|
getFlashChoice();
|
||
|
} else {
|
||
|
mEditPrefs.putInt(PreferenceConstants.ADOBE_FLASH_SUPPORT, 0);
|
||
|
mEditPrefs.commit();
|
||
11 years ago
|
}
|
||
11 years ago
|
|
||
11 years ago
|
boolean flashInstalled = false;
|
||
|
try {
|
||
11 years ago
|
PackageManager pm = getPackageManager();
|
||
|
ApplicationInfo ai = pm.getApplicationInfo(
|
||
|
"com.adobe.flashplayer", 0);
|
||
|
if (ai != null)
|
||
|
flashInstalled = true;
|
||
11 years ago
|
} catch (NameNotFoundException e) {
|
||
11 years ago
|
flashInstalled = false;
|
||
11 years ago
|
}
|
||
11 years ago
|
if (!flashInstalled && isChecked) {
|
||
11 years ago
|
Utils.createInformativeDialog(
|
||
|
SettingsActivity.this,
|
||
|
getResources().getString(R.string.title_warning),
|
||
|
getResources().getString(
|
||
|
R.string.dialog_adobe_not_installed));
|
||
11 years ago
|
buttonView.setChecked(false);
|
||
11 years ago
|
mEditPrefs.putInt(PreferenceConstants.ADOBE_FLASH_SUPPORT, 0);
|
||
11 years ago
|
mEditPrefs.commit();
|
||
11 years ago
|
|
||
11 years ago
|
} else if ((API >= 17) && isChecked) {
|
||
11 years ago
|
Utils.createInformativeDialog(
|
||
|
SettingsActivity.this,
|
||
11 years ago
|
getResources().getString(R.string.title_warning),
|
||
|
getResources().getString(
|
||
|
R.string.dialog_adobe_unsupported));
|
||
11 years ago
|
}
|
||
11 years ago
|
}
|
||
|
|
||
|
});
|
||
|
fullscreen.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
||
|
|
||
|
@Override
|
||
|
public void onCheckedChanged(CompoundButton buttonView,
|
||
|
boolean isChecked) {
|
||
11 years ago
|
mEditPrefs.putBoolean(PreferenceConstants.FULL_SCREEN, isChecked);
|
||
11 years ago
|
mEditPrefs.commit();
|
||
11 years ago
|
|
||
|
}
|
||
|
|
||
|
});
|
||
|
}
|
||
11 years ago
|
|
||
11 years ago
|
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) {
|
||
|
mEditPrefs.putInt(PreferenceConstants.ADOBE_FLASH_SUPPORT, 1);
|
||
|
mEditPrefs.commit();
|
||
|
}
|
||
|
})
|
||
|
.setNegativeButton(
|
||
|
getResources().getString(R.string.action_auto),
|
||
|
new DialogInterface.OnClickListener() {
|
||
|
|
||
|
@Override
|
||
|
public void onClick(DialogInterface dialog,
|
||
|
int which) {
|
||
|
mEditPrefs.putInt(PreferenceConstants.ADOBE_FLASH_SUPPORT, 2);
|
||
|
mEditPrefs.commit();
|
||
|
}
|
||
|
}).setOnCancelListener(new OnCancelListener() {
|
||
|
|
||
|
@Override
|
||
|
public void onCancel(DialogInterface dialog) {
|
||
|
mEditPrefs.putInt(PreferenceConstants.ADOBE_FLASH_SUPPORT, 0);
|
||
|
mEditPrefs.commit();
|
||
|
}
|
||
|
|
||
|
});
|
||
|
AlertDialog alert = builder.create();
|
||
|
alert.show();
|
||
|
}
|
||
|
|
||
11 years ago
|
public void initCheckBox(CheckBox location, CheckBox fullscreen,
|
||
|
CheckBox flash) {
|
||
11 years ago
|
location.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
||
|
|
||
|
@Override
|
||
|
public void onCheckedChanged(CompoundButton buttonView,
|
||
|
boolean isChecked) {
|
||
11 years ago
|
mEditPrefs.putBoolean(PreferenceConstants.LOCATION, isChecked);
|
||
11 years ago
|
mEditPrefs.commit();
|
||
11 years ago
|
|
||
|
}
|
||
|
|
||
|
});
|
||
|
flash.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
||
|
|
||
|
@Override
|
||
|
public void onCheckedChanged(CompoundButton buttonView,
|
||
|
boolean isChecked) {
|
||
|
int n = 0;
|
||
|
if (isChecked) {
|
||
|
n = 1;
|
||
|
}
|
||
11 years ago
|
mEditPrefs.putInt(PreferenceConstants.ADOBE_FLASH_SUPPORT, n);
|
||
11 years ago
|
mEditPrefs.commit();
|
||
11 years ago
|
boolean flashInstalled = false;
|
||
|
try {
|
||
11 years ago
|
PackageManager pm = getPackageManager();
|
||
|
ApplicationInfo ai = pm.getApplicationInfo(
|
||
|
"com.adobe.flashplayer", 0);
|
||
|
if (ai != null)
|
||
|
flashInstalled = true;
|
||
11 years ago
|
} catch (NameNotFoundException e) {
|
||
11 years ago
|
flashInstalled = false;
|
||
11 years ago
|
}
|
||
11 years ago
|
if (!flashInstalled && isChecked) {
|
||
11 years ago
|
Utils.createInformativeDialog(
|
||
|
SettingsActivity.this,
|
||
|
getResources().getString(R.string.title_warning),
|
||
|
getResources().getString(
|
||
|
R.string.dialog_adobe_not_installed));
|
||
11 years ago
|
buttonView.setChecked(false);
|
||
11 years ago
|
mEditPrefs.putInt(PreferenceConstants.ADOBE_FLASH_SUPPORT, 0);
|
||
11 years ago
|
mEditPrefs.commit();
|
||
11 years ago
|
|
||
|
} else if ((API > 17) && isChecked) {
|
||
|
Utils.createInformativeDialog(
|
||
|
SettingsActivity.this,
|
||
11 years ago
|
getResources().getString(R.string.title_warning),
|
||
|
getResources().getString(
|
||
|
R.string.dialog_adobe_unsupported));
|
||
11 years ago
|
}
|
||
11 years ago
|
}
|
||
|
|
||
|
});
|
||
|
fullscreen.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
||
|
|
||
|
@Override
|
||
|
public void onCheckedChanged(CompoundButton buttonView,
|
||
|
boolean isChecked) {
|
||
11 years ago
|
mEditPrefs.putBoolean(PreferenceConstants.FULL_SCREEN, isChecked);
|
||
11 years ago
|
mEditPrefs.commit();
|
||
11 years ago
|
|
||
|
}
|
||
|
|
||
|
});
|
||
|
}
|
||
|
|
||
|
public void agent(RelativeLayout view) {
|
||
|
view.setOnClickListener(new OnClickListener() {
|
||
|
|
||
|
@Override
|
||
|
public void onClick(View v) {
|
||
|
AlertDialog.Builder agentPicker = new AlertDialog.Builder(
|
||
11 years ago
|
mActivity);
|
||
11 years ago
|
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) };
|
||
11 years ago
|
mAgentChoice = mPreferences.getInt(PreferenceConstants.USER_AGENT, 1);
|
||
|
agentPicker.setSingleChoiceItems(chars, mAgentChoice - 1,
|
||
11 years ago
|
new DialogInterface.OnClickListener() {
|
||
|
|
||
|
@Override
|
||
|
public void onClick(DialogInterface dialog,
|
||
|
int which) {
|
||
11 years ago
|
mEditPrefs.putInt(PreferenceConstants.USER_AGENT, which + 1);
|
||
11 years ago
|
mEditPrefs.commit();
|
||
11 years ago
|
switch (which + 1) {
|
||
|
case 1:
|
||
11 years ago
|
mAgentTextView.setText(getResources().getString(
|
||
11 years ago
|
R.string.agent_default));
|
||
11 years ago
|
break;
|
||
|
case 2:
|
||
11 years ago
|
mAgentTextView.setText(getResources().getString(
|
||
11 years ago
|
R.string.agent_desktop));
|
||
11 years ago
|
break;
|
||
|
case 3:
|
||
11 years ago
|
mAgentTextView.setText(getResources().getString(
|
||
11 years ago
|
R.string.agent_mobile));
|
||
11 years ago
|
break;
|
||
|
case 4:
|
||
11 years ago
|
mAgentTextView.setText(getResources().getString(
|
||
11 years ago
|
R.string.agent_custom));
|
||
11 years ago
|
agentPicker();
|
||
11 years ago
|
break;
|
||
|
}
|
||
|
}
|
||
|
});
|
||
11 years ago
|
agentPicker.setNeutralButton(
|
||
|
getResources().getString(R.string.action_ok),
|
||
11 years ago
|
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();
|
||
|
|
||
|
}
|
||
|
|
||
|
});
|
||
|
}
|
||
11 years ago
|
|
||
11 years ago
|
public void agentPicker() {
|
||
|
final AlertDialog.Builder agentStringPicker = new AlertDialog.Builder(
|
||
11 years ago
|
mActivity);
|
||
|
|
||
11 years ago
|
agentStringPicker.setTitle(getResources().getString(
|
||
|
R.string.title_user_agent));
|
||
11 years ago
|
final EditText getAgent = new EditText(SettingsActivity.this);
|
||
|
agentStringPicker.setView(getAgent);
|
||
11 years ago
|
agentStringPicker.setPositiveButton(
|
||
|
getResources().getString(R.string.action_ok),
|
||
11 years ago
|
new DialogInterface.OnClickListener() {
|
||
|
|
||
|
@Override
|
||
|
public void onClick(DialogInterface dialog, int which) {
|
||
|
String text = getAgent.getText().toString();
|
||
11 years ago
|
mEditPrefs.putString(PreferenceConstants.USER_AGENT_STRING, text);
|
||
11 years ago
|
mEditPrefs.commit();
|
||
11 years ago
|
mAgentTextView.setText(getResources().getString(
|
||
11 years ago
|
R.string.agent_custom));
|
||
11 years ago
|
}
|
||
|
});
|
||
|
agentStringPicker.show();
|
||
|
}
|
||
11 years ago
|
|
||
|
public void download(RelativeLayout view) {
|
||
|
view.setOnClickListener(new OnClickListener() {
|
||
|
|
||
|
@Override
|
||
|
public void onClick(View v) {
|
||
|
|
||
11 years ago
|
AlertDialog.Builder picker = new AlertDialog.Builder(mActivity);
|
||
11 years ago
|
picker.setTitle(getResources().getString(
|
||
|
R.string.title_download_location));
|
||
|
CharSequence[] chars = {
|
||
|
getResources().getString(R.string.agent_default),
|
||
|
getResources().getString(R.string.agent_custom) };
|
||
11 years ago
|
mDownloadLocation = mPreferences.getString(PreferenceConstants.DOWNLOAD_DIRECTORY,
|
||
11 years ago
|
Environment.DIRECTORY_DOWNLOADS);
|
||
11 years ago
|
int n = -1;
|
||
11 years ago
|
if (mDownloadLocation.contains(Environment.DIRECTORY_DOWNLOADS)) {
|
||
11 years ago
|
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:
|
||
11 years ago
|
mEditPrefs.putString(PreferenceConstants.DOWNLOAD_DIRECTORY,
|
||
11 years ago
|
Environment.DIRECTORY_DOWNLOADS);
|
||
11 years ago
|
mEditPrefs.commit();
|
||
11 years ago
|
mDownloadTextView.setText(Constants.EXTERNAL_STORAGE
|
||
11 years ago
|
+ "/"
|
||
|
+ Environment.DIRECTORY_DOWNLOADS);
|
||
11 years ago
|
break;
|
||
|
case 2:
|
||
|
downPicker();
|
||
|
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
});
|
||
11 years ago
|
picker.setNeutralButton(
|
||
|
getResources().getString(R.string.action_ok),
|
||
11 years ago
|
new DialogInterface.OnClickListener() {
|
||
|
|
||
|
@Override
|
||
|
public void onClick(DialogInterface dialog,
|
||
|
int which) {
|
||
|
|
||
|
}
|
||
|
});
|
||
|
picker.show();
|
||
|
}
|
||
|
|
||
|
});
|
||
|
}
|
||
|
|
||
|
public void homePicker() {
|
||
|
final AlertDialog.Builder homePicker = new AlertDialog.Builder(
|
||
11 years ago
|
mActivity);
|
||
11 years ago
|
homePicker.setTitle(getResources().getString(
|
||
|
R.string.title_custom_homepage));
|
||
11 years ago
|
final EditText getHome = new EditText(SettingsActivity.this);
|
||
11 years ago
|
mHomepage = mPreferences.getString(PreferenceConstants.HOMEPAGE, Constants.HOMEPAGE);
|
||
|
if (!mHomepage.startsWith("about:")) {
|
||
|
getHome.setText(mHomepage);
|
||
11 years ago
|
} else {
|
||
|
getHome.setText("http://www.google.com");
|
||
|
}
|
||
|
homePicker.setView(getHome);
|
||
11 years ago
|
homePicker.setPositiveButton(
|
||
|
getResources().getString(R.string.action_ok),
|
||
11 years ago
|
new DialogInterface.OnClickListener() {
|
||
|
|
||
|
@Override
|
||
|
public void onClick(DialogInterface dialog, int which) {
|
||
|
String text = getHome.getText().toString();
|
||
11 years ago
|
mEditPrefs.putString(PreferenceConstants.HOMEPAGE, text);
|
||
11 years ago
|
mEditPrefs.commit();
|
||
11 years ago
|
mHomepageText.setText(text);
|
||
11 years ago
|
}
|
||
|
});
|
||
|
homePicker.show();
|
||
|
}
|
||
|
|
||
11 years ago
|
@SuppressWarnings("deprecation")
|
||
11 years ago
|
public void downPicker() {
|
||
|
final AlertDialog.Builder downLocationPicker = new AlertDialog.Builder(
|
||
11 years ago
|
mActivity);
|
||
11 years ago
|
LinearLayout layout = new LinearLayout(this);
|
||
11 years ago
|
downLocationPicker.setTitle(getResources().getString(
|
||
|
R.string.title_download_location));
|
||
11 years ago
|
final EditText getDownload = new EditText(SettingsActivity.this);
|
||
11 years ago
|
getDownload.setBackgroundResource(0);
|
||
11 years ago
|
mDownloadLocation = mPreferences.getString(PreferenceConstants.DOWNLOAD_DIRECTORY,
|
||
11 years ago
|
Environment.DIRECTORY_DOWNLOADS);
|
||
11 years ago
|
int padding = Utils.convertToDensityPixels(this, 10);
|
||
11 years ago
|
|
||
|
LinearLayout.LayoutParams lparams = new LinearLayout.LayoutParams(
|
||
|
LinearLayout.LayoutParams.MATCH_PARENT,
|
||
|
LinearLayout.LayoutParams.MATCH_PARENT);
|
||
|
|
||
|
getDownload.setLayoutParams(lparams);
|
||
|
getDownload.setTextColor(Color.DKGRAY);
|
||
11 years ago
|
getDownload.setText(mDownloadLocation);
|
||
11 years ago
|
getDownload.setPadding(0, padding, padding, padding);
|
||
|
|
||
|
TextView v = new TextView(this);
|
||
|
v.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
|
||
|
v.setTextColor(Color.DKGRAY);
|
||
11 years ago
|
v.setText(Constants.EXTERNAL_STORAGE + "/");
|
||
11 years ago
|
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);
|
||
11 years ago
|
downLocationPicker.setPositiveButton(
|
||
|
getResources().getString(R.string.action_ok),
|
||
11 years ago
|
new DialogInterface.OnClickListener() {
|
||
|
|
||
|
@Override
|
||
|
public void onClick(DialogInterface dialog, int which) {
|
||
|
String text = getDownload.getText().toString();
|
||
11 years ago
|
mEditPrefs.putString(PreferenceConstants.DOWNLOAD_DIRECTORY, text);
|
||
11 years ago
|
mEditPrefs.commit();
|
||
11 years ago
|
mDownloadTextView.setText(Constants.EXTERNAL_STORAGE + "/"
|
||
11 years ago
|
+ text);
|
||
11 years ago
|
}
|
||
|
});
|
||
|
downLocationPicker.show();
|
||
|
}
|
||
|
|
||
|
public void homepage(RelativeLayout view) {
|
||
|
view.setOnClickListener(new OnClickListener() {
|
||
|
|
||
|
@Override
|
||
|
public void onClick(View v) {
|
||
11 years ago
|
AlertDialog.Builder picker = new AlertDialog.Builder(mActivity);
|
||
|
picker.setTitle(getResources().getString(R.string.home));
|
||
|
CharSequence[] chars = {
|
||
|
getResources().getString(R.string.action_homepage),
|
||
|
getResources().getString(R.string.action_blank),
|
||
|
getResources().getString(R.string.action_bookmarks),
|
||
|
getResources().getString(R.string.action_webpage) };
|
||
|
mHomepage = mPreferences.getString(PreferenceConstants.HOMEPAGE, Constants.HOMEPAGE);
|
||
11 years ago
|
int n = -1;
|
||
11 years ago
|
if (mHomepage.contains("about:home")) {
|
||
11 years ago
|
n = 1;
|
||
11 years ago
|
} else if (mHomepage.contains("about:blank")) {
|
||
11 years ago
|
n = 2;
|
||
11 years ago
|
} else if (mHomepage.contains("about:bookmarks")) {
|
||
11 years ago
|
n = 3;
|
||
11 years ago
|
} else {
|
||
|
n = 4;
|
||
11 years ago
|
}
|
||
|
|
||
|
picker.setSingleChoiceItems(chars, n - 1,
|
||
|
new DialogInterface.OnClickListener() {
|
||
|
|
||
|
@Override
|
||
|
public void onClick(DialogInterface dialog,
|
||
|
int which) {
|
||
|
|
||
|
switch (which + 1) {
|
||
|
case 1:
|
||
11 years ago
|
mEditPrefs.putString(PreferenceConstants.HOMEPAGE, "about:home");
|
||
11 years ago
|
mEditPrefs.commit();
|
||
11 years ago
|
mHomepageText
|
||
|
.setText(getResources().getString(
|
||
|
R.string.action_homepage));
|
||
11 years ago
|
break;
|
||
|
case 2:
|
||
11 years ago
|
mEditPrefs.putString(PreferenceConstants.HOMEPAGE, "about:blank");
|
||
11 years ago
|
mEditPrefs.commit();
|
||
11 years ago
|
mHomepageText.setText(getResources()
|
||
|
.getString(R.string.action_blank));
|
||
11 years ago
|
break;
|
||
|
case 3:
|
||
11 years ago
|
mEditPrefs.putString(PreferenceConstants.HOMEPAGE,
|
||
|
"about:bookmarks");
|
||
|
mEditPrefs.commit();
|
||
|
mHomepageText.setText(getResources()
|
||
|
.getString(
|
||
|
R.string.action_bookmarks));
|
||
|
|
||
|
break;
|
||
|
case 4:
|
||
11 years ago
|
homePicker();
|
||
|
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
});
|
||
11 years ago
|
picker.setNeutralButton(
|
||
|
getResources().getString(R.string.action_ok),
|
||
11 years ago
|
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) {
|
||
11 years ago
|
startActivity(new Intent(Constants.ADVANCED_SETTINGS_INTENT));
|
||
11 years ago
|
}
|
||
|
|
||
|
});
|
||
|
}
|
||
|
|
||
|
public void source(RelativeLayout view) {
|
||
|
view.setOnClickListener(new OnClickListener() {
|
||
|
|
||
|
@Override
|
||
|
public void onClick(View v) {
|
||
|
startActivity(new Intent(Intent.ACTION_VIEW, Uri
|
||
11 years ago
|
.parse("http://twitter.com/ACRDevelopment")));
|
||
11 years ago
|
finish();
|
||
|
}
|
||
|
|
||
|
});
|
||
|
}
|
||
|
}
|