Browse Source

Refactored/Cleaned up some settings activities

master
Anthony Restaino 10 years ago
parent
commit
38d44b8c2f
  1. 4
      AndroidManifest.xml
  2. 81
      src/acr/browser/lightning/AboutSettingsActivity.java
  3. 8
      src/acr/browser/lightning/AdvancedSettingsActivity.java
  4. 3
      src/acr/browser/lightning/BookmarkActivity.java
  5. 203
      src/acr/browser/lightning/DisplaySettingsActivity.java

4
AndroidManifest.xml

@ -3,8 +3,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="acr.browser.lightning" package="acr.browser.lightning"
android:versionCode="74" android:versionCode="75"
android:versionName="4.0.6a" > android:versionName="4.0.7a" >
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.android.browser.permission.READ_HISTORY_BOOKMARKS" /> <uses-permission android:name="com.android.browser.permission.READ_HISTORY_BOOKMARKS" />

81
src/acr/browser/lightning/AboutSettingsActivity.java

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

8
src/acr/browser/lightning/AdvancedSettingsActivity.java

@ -3,7 +3,6 @@
*/ */
package acr.browser.lightning; package acr.browser.lightning;
import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
@ -25,7 +24,6 @@ public class AdvancedSettingsActivity extends ThemableSettingsActivity {
private Context mContext; private Context mContext;
private TextView mRenderText; private TextView mRenderText;
private TextView mUrlText; private TextView mUrlText;
private Activity mActivity;
private CharSequence[] mUrlOptions; private CharSequence[] mUrlOptions;
private PreferenceManager mPreferences; private PreferenceManager mPreferences;
@ -34,14 +32,12 @@ public class AdvancedSettingsActivity extends ThemableSettingsActivity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.advanced_settings); setContentView(R.layout.advanced_settings);
// set up ActionBar
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mContext = this; mContext = this;
mActivity = this;
initialize(); initialize();
} }
@ -166,7 +162,7 @@ public class AdvancedSettingsActivity extends ThemableSettingsActivity {
public void renderPicker() { public void renderPicker() {
AlertDialog.Builder picker = new AlertDialog.Builder(mActivity); AlertDialog.Builder picker = new AlertDialog.Builder(mContext);
picker.setTitle(getResources().getString(R.string.rendering_mode)); picker.setTitle(getResources().getString(R.string.rendering_mode));
CharSequence[] chars = { mContext.getString(R.string.name_normal), CharSequence[] chars = { mContext.getString(R.string.name_normal),
mContext.getString(R.string.name_inverted), mContext.getString(R.string.name_inverted),
@ -209,7 +205,7 @@ public class AdvancedSettingsActivity extends ThemableSettingsActivity {
public void urlBoxPicker() { public void urlBoxPicker() {
AlertDialog.Builder picker = new AlertDialog.Builder(mActivity); AlertDialog.Builder picker = new AlertDialog.Builder(mContext);
picker.setTitle(getResources().getString(R.string.url_contents)); picker.setTitle(getResources().getString(R.string.url_contents));
int n = mPreferences.getUrlBoxContentChoice(); int n = mPreferences.getUrlBoxContentChoice();

3
src/acr/browser/lightning/BookmarkActivity.java

@ -24,7 +24,7 @@ public class BookmarkActivity extends ThemableSettingsActivity implements OnClic
private boolean mSystemBrowser; private boolean mSystemBrowser;
private File[] mFileList; private File[] mFileList;
private String[] mFileNameList; private String[] mFileNameList;
private File mPath = new File(Environment.getExternalStorageDirectory().toString()); private static final File mPath = new File(Environment.getExternalStorageDirectory().toString());
private static final int DIALOG_LOAD_FILE = 1000; private static final int DIALOG_LOAD_FILE = 1000;
@Override @Override
@ -32,7 +32,6 @@ public class BookmarkActivity extends ThemableSettingsActivity implements OnClic
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.bookmark_settings); setContentView(R.layout.bookmark_settings);
// set up ActionBar
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar); setSupportActionBar(toolbar);

203
src/acr/browser/lightning/DisplaySettingsActivity.java

@ -27,14 +27,11 @@ public class DisplaySettingsActivity extends ThemableSettingsActivity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.display_settings); setContentView(R.layout.display_settings);
mPreferences = PreferenceManager.getInstance();
// set up ActionBar
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mPreferences = PreferenceManager.getInstance();
initialize(); initialize();
} }
@ -47,6 +44,8 @@ public class DisplaySettingsActivity extends ThemableSettingsActivity {
private void initialize() { private void initialize() {
RelativeLayout rHideStatusBar, rFullScreen, rWideViewPort, rOverView, rTextReflow, rTextSize, rDarkTheme; RelativeLayout rHideStatusBar, rFullScreen, rWideViewPort, rOverView, rTextReflow, rTextSize, rDarkTheme;
LayoutClickListener clickListener = new LayoutClickListener();
CheckBoxToggleListener toggleListener = new CheckBoxToggleListener();
rHideStatusBar = (RelativeLayout) findViewById(R.id.rHideStatusBar); rHideStatusBar = (RelativeLayout) findViewById(R.id.rHideStatusBar);
rFullScreen = (RelativeLayout) findViewById(R.id.rFullScreen); rFullScreen = (RelativeLayout) findViewById(R.id.rFullScreen);
@ -56,6 +55,14 @@ public class DisplaySettingsActivity extends ThemableSettingsActivity {
rTextSize = (RelativeLayout) findViewById(R.id.rTextSize); rTextSize = (RelativeLayout) findViewById(R.id.rTextSize);
rDarkTheme = (RelativeLayout) findViewById(R.id.rDarkTheme); rDarkTheme = (RelativeLayout) findViewById(R.id.rDarkTheme);
rHideStatusBar.setOnClickListener(clickListener);
rFullScreen.setOnClickListener(clickListener);
rWideViewPort.setOnClickListener(clickListener);
rOverView.setOnClickListener(clickListener);
rTextReflow.setOnClickListener(clickListener);
rTextSize.setOnClickListener(clickListener);
rDarkTheme.setOnClickListener(clickListener);
cbHideStatusBar = (CheckBox) findViewById(R.id.cbHideStatusBar); cbHideStatusBar = (CheckBox) findViewById(R.id.cbHideStatusBar);
cbFullScreen = (CheckBox) findViewById(R.id.cbFullScreen); cbFullScreen = (CheckBox) findViewById(R.id.cbFullScreen);
cbWideViewPort = (CheckBox) findViewById(R.id.cbWideViewPort); cbWideViewPort = (CheckBox) findViewById(R.id.cbWideViewPort);
@ -70,161 +77,75 @@ public class DisplaySettingsActivity extends ThemableSettingsActivity {
cbTextReflow.setChecked(mPreferences.getTextReflowEnabled()); cbTextReflow.setChecked(mPreferences.getTextReflowEnabled());
cbDarkTheme.setChecked(mPreferences.getUseDarkTheme()); cbDarkTheme.setChecked(mPreferences.getUseDarkTheme());
rHideStatusBar(rHideStatusBar); cbHideStatusBar.setOnCheckedChangeListener(toggleListener);
rFullScreen(rFullScreen); cbFullScreen.setOnCheckedChangeListener(toggleListener);
rWideViewPort(rWideViewPort); cbWideViewPort.setOnCheckedChangeListener(toggleListener);
rOverView(rOverView); cbOverView.setOnCheckedChangeListener(toggleListener);
rTextReflow(rTextReflow); cbTextReflow.setOnCheckedChangeListener(toggleListener);
rTextSize(rTextSize); cbDarkTheme.setOnCheckedChangeListener(toggleListener);
rDarkTheme(rDarkTheme);
cbHideStatusBar(cbHideStatusBar);
cbFullScreen(cbFullScreen);
cbWideViewPort(cbWideViewPort);
cbOverView(cbOverView);
cbTextReflow(cbTextReflow);
cbDarkTheme(cbDarkTheme);
}
private void cbHideStatusBar(CheckBox view) {
view.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mPreferences.setHideStatusBarEnabled(isChecked);
}
});
}
private void cbFullScreen(CheckBox view) {
view.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mPreferences.setFullScreenEnabled(isChecked);
}
});
}
private void cbDarkTheme(CheckBox view) {
view.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mPreferences.setUseDarkTheme(isChecked);
restart();
}
});
}
private void cbWideViewPort(CheckBox view) {
view.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mPreferences.setUseWideViewportEnabled(isChecked);
}
});
}
private void cbOverView(CheckBox view) {
view.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mPreferences.setOverviewModeEnabled(isChecked);
}
});
}
private void cbTextReflow(CheckBox view) {
view.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mPreferences.setTextReflowEnabled(isChecked);
}
});
} }
private void rHideStatusBar(RelativeLayout view) { private class LayoutClickListener implements OnClickListener {
view.setOnClickListener(new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
switch (v.getId()) {
case R.id.rHideStatusBar:
cbHideStatusBar.setChecked(!cbHideStatusBar.isChecked()); cbHideStatusBar.setChecked(!cbHideStatusBar.isChecked());
} break;
case R.id.rFullScreen:
});
}
private void rFullScreen(RelativeLayout view) {
view.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
cbFullScreen.setChecked(!cbFullScreen.isChecked()); cbFullScreen.setChecked(!cbFullScreen.isChecked());
} break;
case R.id.rWideViewPort:
}); cbWideViewPort.setChecked(!cbWideViewPort.isChecked());
} break;
case R.id.rOverView:
private void rDarkTheme(RelativeLayout view) { cbOverView.setChecked(!cbOverView.isChecked());
view.setOnClickListener(new OnClickListener() { break;
case R.id.rTextReflow:
@Override cbTextReflow.setChecked(!cbTextReflow.isChecked());
public void onClick(View v) { break;
case R.id.rTextSize:
textSizePicker();
break;
case R.id.rDarkTheme:
cbDarkTheme.setChecked(!cbDarkTheme.isChecked()); cbDarkTheme.setChecked(!cbDarkTheme.isChecked());
break;
} }
});
} }
private void rWideViewPort(RelativeLayout view) {
view.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
cbWideViewPort.setChecked(!cbWideViewPort.isChecked());
} }
}); private class CheckBoxToggleListener implements OnCheckedChangeListener {
}
private void rOverView(RelativeLayout view) {
view.setOnClickListener(new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub switch (buttonView.getId()) {
cbOverView.setChecked(!cbOverView.isChecked()); case R.id.cbHideStatusBar:
} mPreferences.setHideStatusBarEnabled(isChecked);
break;
}); case R.id.cbFullScreen:
mPreferences.setFullScreenEnabled(isChecked);
break;
case R.id.cbWideViewPort:
mPreferences.setUseWideViewportEnabled(isChecked);
break;
case R.id.cbOverView:
mPreferences.setOverviewModeEnabled(isChecked);
break;
case R.id.cbTextReflow:
mPreferences.setTextReflowEnabled(isChecked);
break;
case R.id.cbDarkTheme:
mPreferences.setUseDarkTheme(isChecked);
restart();
break;
} }
private void rTextReflow(RelativeLayout view) {
view.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
cbTextReflow.setChecked(!cbTextReflow.isChecked());
} }
});
} }
private void rTextSize(RelativeLayout view) { private void textSizePicker() {
view.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder picker = new AlertDialog.Builder(DisplaySettingsActivity.this); AlertDialog.Builder picker = new AlertDialog.Builder(DisplaySettingsActivity.this);
picker.setTitle(getResources().getString(R.string.title_text_size)); picker.setTitle(getResources().getString(R.string.title_text_size));
@ -236,7 +157,6 @@ public class DisplaySettingsActivity extends ThemableSettingsActivity {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
mPreferences.setTextSize(which + 1); mPreferences.setTextSize(which + 1);
} }
}); });
picker.setNeutralButton(getResources().getString(R.string.action_ok), picker.setNeutralButton(getResources().getString(R.string.action_ok),
@ -249,7 +169,4 @@ public class DisplaySettingsActivity extends ThemableSettingsActivity {
}); });
picker.show(); picker.show();
} }
});
}
} }

Loading…
Cancel
Save