Added option to change rendering mode

This commit is contained in:
Anthony Restaino 2014-08-19 15:10:54 -04:00
parent d191bf151e
commit 52fcf8fdc0
4 changed files with 587 additions and 475 deletions

File diff suppressed because it is too large Load Diff

View File

@ -172,4 +172,10 @@
<string name="freeware">Freeware</string> <string name="freeware">Freeware</string>
<string name="android_open_source_project">Android Open Source Project</string> <string name="android_open_source_project">Android Open Source Project</string>
<string name="hphosts_ad_server_list">hpHosts Ad Server List</string> <string name="hphosts_ad_server_list">hpHosts Ad Server List</string>
<string name="deleted_tab">Reopened old tab</string>
<string name="rendering_mode">Rendering Mode</string>
<string name="name_inverted">Inverted</string>
<string name="name_grayscale">Grayscale</string>
<string name="name_inverted_grayscale">Inverted Grayscale</string>
<string name="name_normal">Normal</string>
</resources> </resources>

View File

@ -266,6 +266,9 @@ public class LightningView {
} else if (mSettings == null) { } else if (mSettings == null) {
return; return;
} }
setColorMode(mPreferences.getInt(PreferenceConstants.RENDERING_MODE, 0));
mSettings.setGeolocationEnabled(mPreferences mSettings.setGeolocationEnabled(mPreferences
.getBoolean(PreferenceConstants.LOCATION, false)); .getBoolean(PreferenceConstants.LOCATION, false));
if (API < 19) { if (API < 19) {
@ -355,7 +358,6 @@ public class LightningView {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@SuppressLint({ "SetJavaScriptEnabled", "NewApi" }) @SuppressLint({ "SetJavaScriptEnabled", "NewApi" })
public void initializeSettings(WebSettings settings, Context context) { public void initializeSettings(WebSettings settings, Context context) {
this.setNormalRendering();
if (API < 18) { if (API < 18) {
settings.setAppCacheMaxSize(Long.MAX_VALUE); settings.setAppCacheMaxSize(Long.MAX_VALUE);
} }
@ -432,7 +434,7 @@ public class LightningView {
public void setNormalRendering() { public void setNormalRendering() {
mWebView.setLayerType(View.LAYER_TYPE_NONE, mPaint); mWebView.setLayerType(View.LAYER_TYPE_NONE, mPaint);
} }
public void setSoftwareRendering() { public void setSoftwareRendering() {
mWebView.setLayerType(View.LAYER_TYPE_SOFTWARE, mPaint); mWebView.setLayerType(View.LAYER_TYPE_SOFTWARE, mPaint);
} }
@ -441,18 +443,33 @@ public class LightningView {
switch (mode) { switch (mode) {
case 0: case 0:
mPaint.setColorFilter(null); mPaint.setColorFilter(null);
setNormalRendering();
break; break;
case 1: case 1:
ColorMatrixColorFilter filterInvert = new ColorMatrixColorFilter( ColorMatrixColorFilter filterInvert = new ColorMatrixColorFilter(
mNegativeColorArray); mNegativeColorArray);
mPaint.setColorFilter(filterInvert); mPaint.setColorFilter(filterInvert);
setHardwareRendering();
break; break;
case 2: case 2:
ColorMatrix cm = new ColorMatrix(); ColorMatrix cm = new ColorMatrix();
cm.setSaturation(0); cm.setSaturation(0);
ColorMatrixColorFilter filterGray = new ColorMatrixColorFilter(cm); ColorMatrixColorFilter filterGray = new ColorMatrixColorFilter(cm);
mPaint.setColorFilter(filterGray); mPaint.setColorFilter(filterGray);
setHardwareRendering();
break; break;
case 3:
ColorMatrix matrix = new ColorMatrix();
matrix.set(mNegativeColorArray);
ColorMatrix matrixGray = new ColorMatrix();
matrixGray.setSaturation(0);
ColorMatrix concat = new ColorMatrix();
concat.setConcat(matrix, matrixGray);
ColorMatrixColorFilter filterInvertGray = new ColorMatrixColorFilter(concat);
mPaint.setColorFilter(filterInvertGray);
setHardwareRendering();
break;
} }
} }

View File

@ -33,29 +33,18 @@ import info.guardianproject.onionkit.ui.OrbotHelper;
public class SettingsActivity extends Activity { public class SettingsActivity extends Activity {
private static int API = android.os.Build.VERSION.SDK_INT; private static int API = android.os.Build.VERSION.SDK_INT;
private SharedPreferences.Editor mEditPrefs; private SharedPreferences.Editor mEditPrefs;
private int mAgentChoice; private int mAgentChoice;
private String mHomepage; private String mHomepage;
private TextView mAgentTextView; private TextView mAgentTextView;
private TextView mDownloadTextView; private TextView mDownloadTextView;
private int mEasterEggCounter; private int mEasterEggCounter;
private String mDownloadLocation; private String mDownloadLocation;
private TextView mHomepageText; private TextView mHomepageText;
private SharedPreferences mPreferences; private SharedPreferences mPreferences;
private TextView mSearchText; private TextView mSearchText;
private TextView mRenderText;
private Context mContext; private Context mContext;
private Activity mActivity; private Activity mActivity;
@Override @Override
@ -98,6 +87,7 @@ public class SettingsActivity extends Activity {
RelativeLayout layoutOrbot = (RelativeLayout) findViewById(R.id.layoutUseOrbot); RelativeLayout layoutOrbot = (RelativeLayout) findViewById(R.id.layoutUseOrbot);
mSearchText = (TextView) findViewById(R.id.searchText); mSearchText = (TextView) findViewById(R.id.searchText);
mRenderText = (TextView) findViewById(R.id.renderText);
switch (mPreferences.getInt(PreferenceConstants.SEARCH, 1)) { switch (mPreferences.getInt(PreferenceConstants.SEARCH, 1)) {
case 0: case 0:
@ -134,6 +124,21 @@ public class SettingsActivity extends Activity {
mSearchText.setText("Yandex"); mSearchText.setText("Yandex");
} }
switch (mPreferences.getInt(PreferenceConstants.RENDERING_MODE, 0)) {
case 0:
mRenderText.setText(mContext.getString(R.string.name_normal));
break;
case 1:
mRenderText.setText(mContext.getString(R.string.name_inverted));
break;
case 2:
mRenderText.setText(mContext.getString(R.string.name_grayscale));
break;
case 3:
mRenderText.setText(mContext.getString(R.string.name_inverted_grayscale));
break;
}
mAgentTextView = (TextView) findViewById(R.id.agentText); mAgentTextView = (TextView) findViewById(R.id.agentText);
mHomepageText = (TextView) findViewById(R.id.homepageText); mHomepageText = (TextView) findViewById(R.id.homepageText);
mDownloadTextView = (TextView) findViewById(R.id.downloadText); mDownloadTextView = (TextView) findViewById(R.id.downloadText);
@ -244,6 +249,7 @@ public class SettingsActivity extends Activity {
advanced(advanced); advanced(advanced);
source(source); source(source);
search(); search();
renderPicker();
easterEgg(); easterEgg();
} }
@ -318,6 +324,57 @@ public class SettingsActivity extends Activity {
}); });
} }
public void renderPicker() {
LinearLayout layout = (LinearLayout) findViewById(R.id.layoutRendering);
layout.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder picker = new AlertDialog.Builder(mActivity);
picker.setTitle(getResources().getString(R.string.rendering_mode));
CharSequence[] chars = { mContext.getString(R.string.name_normal),
mContext.getString(R.string.name_inverted),
mContext.getString(R.string.name_grayscale),
mContext.getString(R.string.name_inverted_grayscale) };
int n = mPreferences.getInt(PreferenceConstants.RENDERING_MODE, 0);
picker.setSingleChoiceItems(chars, n, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
mEditPrefs.putInt(PreferenceConstants.RENDERING_MODE, which).apply();
switch (which) {
case 0:
mRenderText.setText(mContext.getString(R.string.name_normal));
break;
case 1:
mRenderText.setText(mContext.getString(R.string.name_inverted));
break;
case 2:
mRenderText.setText(mContext.getString(R.string.name_grayscale));
break;
case 3:
mRenderText.setText(mContext
.getString(R.string.name_inverted_grayscale));
break;
}
}
});
picker.setNeutralButton(getResources().getString(R.string.action_ok),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
picker.show();
}
});
}
public void searchUrlPicker() { public void searchUrlPicker() {
final AlertDialog.Builder urlPicker = new AlertDialog.Builder(this); final AlertDialog.Builder urlPicker = new AlertDialog.Builder(this);