Browse Source

Refactored/Cleaned up some settings activities

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

4
AndroidManifest.xml

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

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

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

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

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

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

@ -24,7 +24,7 @@ public class BookmarkActivity extends ThemableSettingsActivity implements OnClic @@ -24,7 +24,7 @@ public class BookmarkActivity extends ThemableSettingsActivity implements OnClic
private boolean mSystemBrowser;
private File[] mFileList;
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;
@Override
@ -32,7 +32,6 @@ public class BookmarkActivity extends ThemableSettingsActivity implements OnClic @@ -32,7 +32,6 @@ public class BookmarkActivity extends ThemableSettingsActivity implements OnClic
super.onCreate(savedInstanceState);
setContentView(R.layout.bookmark_settings);
// set up ActionBar
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

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

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

Loading…
Cancel
Save