Skip to content

Commit

Permalink
More work on 'night mode'
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasCz committed Feb 22, 2015
1 parent eaaa1ee commit 964c43c
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 26 deletions.
41 changes: 30 additions & 11 deletions app/src/main/java/jonas/tool/saveForOffline/DisplayAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class DisplayAdapter extends BaseAdapter
private String sqlStatement;

public int list_layout_type = 1;
private boolean darkMode;

public ArrayList<Integer> selectedViewsPositions = new ArrayList<Integer>();

Expand Down Expand Up @@ -77,8 +78,8 @@ public DisplayAdapter(Context c) {
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(mContext);

list_layout_type = Integer.parseInt(sharedPref.getString("layout" , "1"));
darkMode = sharedPref.getBoolean("dark_mode", false);


refreshData(null, 1, false);

placeHolder = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.placeholder);
Expand Down Expand Up @@ -113,12 +114,10 @@ public boolean isEmpty()
}

public int getCount() {
// TODO Auto-generated method stub
return dbCursor.getCount();
}

public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}

Expand Down Expand Up @@ -173,7 +172,13 @@ public View getView(int pos, View convertView, ViewGroup parent) {

if (selectedViewsPositions.contains(pos)) {
convertView.setBackgroundColor(Color.parseColor("#FFC107"));
} else if (convertView != null) {convertView.setBackgroundColor(Color.parseColor("#E2E2E2"));}
} else if (convertView != null) {
if (darkMode) {
convertView.setBackgroundColor(Color.BLACK);
} else {
convertView.setBackgroundColor(Color.parseColor("#E2E2E2"));
}
}

if (convertView == null) {
layoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
Expand All @@ -184,15 +189,29 @@ public View getView(int pos, View convertView, ViewGroup parent) {
case 5: convertView = layoutInflater.inflate(R.layout.listcell_list_details_small, null); break;
default: convertView = layoutInflater.inflate(R.layout.listcell_default, null);
}

mHolder = new Holder();
if (list_layout_type == 4 || list_layout_type == 5) {
mHolder.txt_date = (TextView) convertView.findViewById(R.id.txt_date);
if (darkMode) {
convertView.setBackgroundColor(Color.BLACK);
if (list_layout_type == 4 || list_layout_type == 5) {
mHolder.txt_date = (TextView) convertView.findViewById(R.id.txt_date);
mHolder.txt_date.setTextColor(Color.WHITE);
}
mHolder.txt_id = (TextView) convertView.findViewById(R.id.txt_id);
mHolder.txt_filelocation = (TextView) convertView.findViewById(R.id.txt_fileLocation);
mHolder.txt_orig_url = (TextView) convertView.findViewById(R.id.txt_orig_url);
mHolder.txt_orig_url.setTextColor(Color.WHITE);
mHolder.txt_title = (TextView) convertView.findViewById(R.id.txt_title);
mHolder.txt_title.setTextColor(Color.WHITE);
} else {
if (list_layout_type == 4 || list_layout_type == 5) {
mHolder.txt_date = (TextView) convertView.findViewById(R.id.txt_date);
}
mHolder.txt_id = (TextView) convertView.findViewById(R.id.txt_id);
mHolder.txt_filelocation = (TextView) convertView.findViewById(R.id.txt_fileLocation);
mHolder.txt_orig_url = (TextView) convertView.findViewById(R.id.txt_orig_url);
mHolder.txt_title = (TextView) convertView.findViewById(R.id.txt_title);
}
mHolder.txt_id = (TextView) convertView.findViewById(R.id.txt_id);
mHolder.txt_filelocation = (TextView) convertView.findViewById(R.id.txt_fileLocation);
mHolder.txt_orig_url = (TextView) convertView.findViewById(R.id.txt_orig_url);
mHolder.txt_title = (TextView) convertView.findViewById(R.id.txt_title);

if (list_layout_type != 5) {
mHolder.listimage = (ImageView) convertView.findViewById(R.id.listimage);
}
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/jonas/tool/saveForOffline/Preferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ public class Preferences extends PreferenceActivity implements OnSharedPreferenc
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
if (!preferences.getString("layout" , "1").equals(list_appearance)) {
setResult(RESULT_FIRST_USER);
} else if (key.equals("dark_mode")) {
setResult(RESULT_FIRST_USER);
} else { setResult(RESULT_OK);}

if (key.equals("save_in_background") && preferences.getBoolean("save_in_background" , true) == false) {

Preference advancedSavingOptions = getPreferenceScreen().findPreference("saving_advanced_opts");
advancedSavingOptions.setEnabled(false);
advancedSavingOptions.setSummary("Theese options are only available if 'Save in background' is enabled");
advancedSavingOptions.setSummary("These options are only available if 'Save in background' is enabled");

AlertDialog.Builder build = new AlertDialog.Builder(Preferences.this);
build.setTitle("Warning!");
Expand Down
35 changes: 21 additions & 14 deletions app/src/main/java/jonas/tool/saveForOffline/ViewActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class ViewActivity extends Activity
private WebView.HitTestResult result;

private boolean save_in_background;
private boolean invertedRendering;

@Override
public void onCreate(Bundle savedInstanceState)
Expand All @@ -46,7 +47,7 @@ public void onCreate(Bundle savedInstanceState)
String ua = sharedPref.getString("user_agent", "mobile");
save_in_background = sharedPref.getBoolean("save_in_background", true);
boolean jsEnabled = sharedPref.getBoolean("viewer_enable_javascript", true);
boolean invertedRendering = sharedPref.getBoolean("dark_mode", false);
invertedRendering = sharedPref.getBoolean("dark_mode", false);


registerForContextMenu(webview);
Expand All @@ -60,19 +61,7 @@ public void onCreate(Bundle savedInstanceState)
webview.getSettings().setUserAgentString("todo:iPad ua");
}

//set up inverted rendering, aka. night mode.
if (invertedRendering) {
float[] mNegativeColorArray = {
-1.0f, 0, 0, 0, 255, // red
0, -1.0f, 0, 0, 255, // green
0, 0, -1.0f, 0, 255, // blue
0, 0, 0, 1.0f, 0 // alpha
};
Paint mPaint = new Paint();
ColorMatrixColorFilter filterInvert = new ColorMatrixColorFilter(mNegativeColorArray);
mPaint.setColorFilter(filterInvert);
webview.setLayerType(View.LAYER_TYPE_HARDWARE, mPaint);
}

webview.getSettings().setLoadWithOverviewMode(true);
webview.getSettings().setUseWideViewPort(true);
webview.getSettings().setJavaScriptEnabled(jsEnabled);
Expand Down Expand Up @@ -109,6 +98,24 @@ public void onPageFinished(WebView view, String url) {
} else loadWebView();
}

@Override
protected void onResume() {
super.onResume();
//set up inverted rendering, aka. night mode.
if (invertedRendering) {
float[] mNegativeColorArray = {
-1.0f, 0, 0, 0, 255, // red
0, -1.0f, 0, 0, 255, // green
0, 0, -1.0f, 0, 255, // blue
0, 0, 0, 1.0f, 0 // alpha
};
Paint mPaint = new Paint();
ColorMatrixColorFilter filterInvert = new ColorMatrixColorFilter(mNegativeColorArray);
mPaint.setColorFilter(filterInvert);
webview.setLayerType(View.LAYER_TYPE_HARDWARE, mPaint);
}
}


private void loadWebView()
{
Expand Down

0 comments on commit 964c43c

Please sign in to comment.