Skip to content
This repository has been archived by the owner on Oct 5, 2019. It is now read-only.

Commit

Permalink
Add dark theme
Browse files Browse the repository at this point in the history
  • Loading branch information
Grarak committed Mar 14, 2015
1 parent dbe532b commit 615c9bf
Show file tree
Hide file tree
Showing 30 changed files with 168 additions and 77 deletions.
30 changes: 15 additions & 15 deletions app/app.iml
Expand Up @@ -12,9 +12,9 @@
<option name="SELECTED_TEST_ARTIFACT" value="_android_test_" />
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
<option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugTest" />
<option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugAndroidTest" />
<option name="SOURCE_GEN_TASK_NAME" value="generateDebugSources" />
<option name="TEST_SOURCE_GEN_TASK_NAME" value="generateDebugTestSources" />
<option name="TEST_SOURCE_GEN_TASK_NAME" value="generateDebugAndroidTestSources" />
<option name="ALLOW_USER_CONFIGURATION" value="false" />
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
Expand All @@ -25,7 +25,7 @@
</component>
<component name="NewModuleRootManager" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
<output-test url="file://$MODULE_DIR$/build/intermediates/classes/test/debug" />
<output-test url="file://$MODULE_DIR$/build/intermediates/classes/androidTest/debug" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
Expand All @@ -34,12 +34,12 @@
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/debug" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/test/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/test/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/test/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/test/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/test/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/test/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/androidTest/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
Expand Down Expand Up @@ -85,13 +85,13 @@
</content>
<orderEntry type="jdk" jdkName="Android API 22 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="appcompat-v7-21.0.3" level="project" />
<orderEntry type="library" exported="" name="recyclerview-v7-21.0.3" level="project" />
<orderEntry type="library" exported="" name="support-v4-21.0.3" level="project" />
<orderEntry type="library" exported="" name="support-annotations-21.0.3" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-22.0.0" level="project" />
<orderEntry type="library" exported="" name="RootShell" level="project" />
<orderEntry type="library" exported="" name="floatingactionbutton-1.8.0" level="project" />
<orderEntry type="library" exported="" name="cardview-v7-21.0.3" level="project" />
<orderEntry type="library" exported="" name="recyclerview-v7-22.0.0" level="project" />
<orderEntry type="library" exported="" name="floatingactionbutton-1.9.0" level="project" />
<orderEntry type="library" exported="" name="support-v4-22.0.0" level="project" />
<orderEntry type="library" exported="" name="cardview-v7-22.0.0" level="project" />
<orderEntry type="library" exported="" name="support-annotations-22.0.0" level="project" />
</component>
</module>

10 changes: 5 additions & 5 deletions app/src/main/AndroidManifest.xml
Expand Up @@ -9,7 +9,7 @@
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
android:theme="@style/AppThemeLight">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
Expand All @@ -22,12 +22,12 @@
</activity>
<activity
android:name=".TextActivity"
android:theme="@style/AppThemeActionBar"
android:configChanges="keyboardHidden|orientation|screenSize" />
android:theme="@style/AppThemeActionBarLight"
android:configChanges="locale|keyboardHidden|orientation|screenSize" />
<activity
android:name=".PathReaderActivity"
android:theme="@style/AppThemeActionBar"
android:configChanges="keyboardHidden|orientation|screenSize" />
android:theme="@style/AppThemeActionBarLight"
android:configChanges="locale|keyboardHidden|orientation|screenSize" />

<receiver android:name=".BootReceiver">
<intent-filter>
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/com/grarak/cardview/BaseCardView.java
Expand Up @@ -27,6 +27,7 @@
import android.widget.TextView;

import com.grarak.kerneladiutor.R;
import com.grarak.kerneladiutor.utils.Utils;

/**
* Created by willi on 23.12.14.
Expand Down Expand Up @@ -65,7 +66,8 @@ public BaseCardView(Context context, AttributeSet attributeSet, int layout) {
setLayoutParams(layoutParams);
setRadius(0);

setCardBackgroundColor(getResources().getColor(R.color.card_background));
setCardBackgroundColor(getResources().getColor(Utils.DARKTHEME ?
R.color.card_background_dark : R.color.card_background_light));
TypedArray ta = getContext().obtainStyledAttributes(new int[]{R.attr.selectableItemBackground});
Drawable d = ta.getDrawable(0);
ta.recycle();
Expand Down
9 changes: 8 additions & 1 deletion app/src/main/java/com/grarak/cardview/HeaderCardView.java
Expand Up @@ -17,6 +17,7 @@
package com.grarak.cardview;

import android.content.Context;
import android.content.res.Resources;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
Expand All @@ -30,6 +31,8 @@ public class HeaderCardView {

private static final int DEFAULT_LAYOUT = R.layout.header_cardview;

private final Context context;

private TextView textView;
private String title;
private View view;
Expand All @@ -39,7 +42,7 @@ public HeaderCardView(Context context) {
}

public HeaderCardView(Context context, int layout) {

this.context = context;
view = LayoutInflater.from(context).inflate(layout, null, false);

if (layout == DEFAULT_LAYOUT) {
Expand All @@ -63,4 +66,8 @@ public View getView() {
return view;
}

public Resources getResources() {
return context.getResources();
}

}
12 changes: 11 additions & 1 deletion app/src/main/java/com/grarak/kerneladiutor/MainActivity.java
Expand Up @@ -103,13 +103,14 @@ public class MainActivity extends ActionBarActivity implements Constants {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (context != null) {
RootUtils.closeSU();
((Activity) context).finish();
}
context = this;
Utils.DARKTHEME = Utils.getBoolean("darktheme", false, this);

if (Utils.DARKTHEME) super.setTheme(R.style.AppThemeDark);
if (Utils.getBoolean("forceenglish", false, this)) Utils.setLocale("en", this);
try {
LAUNCH_NAME = getIntent().getStringExtra(LAUNCH_INTENT);
Expand All @@ -125,7 +126,9 @@ public void onClick(DialogInterface dialog, int which) {
e.printStackTrace();
}

setContentView(R.layout.activity_main);
toolbar = (Toolbar) findViewById(R.id.toolbar);
if (Utils.DARKTHEME) toolbar.setPopupTheme(R.style.ThemeOverlay_AppCompat_Dark);
setSupportActionBar(toolbar);

progressBar = new ProgressBar(this);
Expand All @@ -136,6 +139,9 @@ public void onClick(DialogInterface dialog, int which) {
actionBar.setCustomView(progressBar, new ActionBar.LayoutParams(ActionBar.LayoutParams.WRAP_CONTENT,
ActionBar.LayoutParams.WRAP_CONTENT, Gravity.CENTER_VERTICAL | Gravity.END));

if (mDrawerLayout != null && mScrimInsetsFrameLayout != null)
mDrawerLayout.closeDrawer(mScrimInsetsFrameLayout);

new Task().execute();
}

Expand Down Expand Up @@ -208,6 +214,8 @@ private void setView() {

private void setInterface() {
mScrimInsetsFrameLayout.setLayoutParams(getDrawerParams());
if (Utils.DARKTHEME)
mScrimInsetsFrameLayout.setBackgroundColor(getResources().getColor(R.color.navigationdrawer_background_dark));
mDrawerList.setAdapter(new ListAdapter.Adapter(this, mList));
mDrawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
Expand All @@ -219,6 +227,8 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
mDrawerToggle = new ActionBarDrawerToggle(MainActivity.this, mDrawerLayout, toolbar, 0, 0) {
};
mDrawerLayout.setDrawerListener(mDrawerToggle);
if (Utils.DARKTHEME)
mDrawerLayout.setBackgroundColor(getResources().getColor(R.color.black));

mDrawerLayout.post(new Runnable() {
@Override
Expand Down
Expand Up @@ -55,9 +55,12 @@ public enum PATH_TYPE {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (Utils.DARKTHEME) super.setTheme(R.style.AppThemeActionBarDark);
overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right);
setContentView(R.layout.fragment_layout);

if (Utils.DARKTHEME)
findViewById(R.id.content_frame).setBackgroundColor(getResources().getColor(R.color.black));
getSupportActionBar().setTitle(getIntent().getExtras().getString(ARG_TITLE));
String path = getIntent().getExtras().getString(ARG_PATH);
String error = getIntent().getExtras().getString(ARG_ERROR);
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/com/grarak/kerneladiutor/TextActivity.java
Expand Up @@ -21,15 +21,19 @@
import android.view.Gravity;
import android.widget.TextView;

import com.grarak.kerneladiutor.utils.Utils;

public class TextActivity extends ActionBarActivity {

public static final String ARG_TEXT = "text";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (Utils.DARKTHEME) super.setTheme(R.style.AppThemeActionBarDark);

TextView text = new TextView(this);
if (Utils.DARKTHEME) text.setBackgroundColor(getResources().getColor(R.color.black));
setContentView(text);

text.setTextSize(20);
Expand Down
Expand Up @@ -25,6 +25,7 @@
import android.widget.TextView;

import com.grarak.kerneladiutor.R;
import com.grarak.kerneladiutor.utils.Utils;

import java.util.List;

Expand Down Expand Up @@ -79,6 +80,8 @@ public Fragment getFragment() {
@Override
public View getView(LayoutInflater inflater, ViewGroup parent) {
TextView text = (TextView) inflater.inflate(R.layout.list_item, parent, false);
if (!Utils.DARKTHEME)
text.setTextColor(parent.getContext().getResources().getColorStateList(R.color.item_textcolor_light));
text.setText(title);
return text;
}
Expand Down Expand Up @@ -108,6 +111,7 @@ public View getView(LayoutInflater inflater, ViewGroup parent) {
View view = inflater.inflate(R.layout.list_header, parent, false);
TextView text = (TextView) view.findViewById(R.id.text);
text.setText(title);
if (Utils.DARKTHEME) view.setBackgroundResource(R.drawable.no_highlight_dark);
return view;
}

Expand Down
Expand Up @@ -30,6 +30,7 @@
import android.view.animation.AnimationUtils;

import com.grarak.kerneladiutor.R;
import com.grarak.kerneladiutor.utils.Utils;

/**
* Created by willi on 09.03.15.
Expand Down Expand Up @@ -90,6 +91,8 @@ public void run() {
}

public void finish() {
if (Utils.DARKTHEME)
mPaintCircle.setColor(getResources().getColor(R.color.navigationdrawer_background_dark));
new Thread(new Runnable() {
@Override
public void run() {
Expand Down
Expand Up @@ -252,7 +252,7 @@ private View generateStateRow(CpuStateMonitor.CpuState state, ViewGroup parent)
freqText.setText(sFreq);
perText.setText(sPer);
durText.setText(sDur);
bar.setProgress((int) per);
bar.setProgress(Math.round(per));

// add it to parent and return
parent.addView(layout);
Expand Down
Expand Up @@ -127,9 +127,12 @@ public boolean onOptionsItemSelected(MenuItem item) {
View view = inflater.inflate(R.layout.global_offset_view, container, false);

final TextView textView = (TextView) view.findViewById(R.id.offset_text);
if (Utils.DARKTHEME)
textView.setTextColor(getResources().getColor(R.color.textcolor_dark));
textView.setText("0");

Button minus = (Button) view.findViewById(R.id.button_minus);
if (!Utils.DARKTHEME) minus.setTextColor(getResources().getColor(R.color.black));
minus.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Expand All @@ -142,6 +145,7 @@ public void onClick(View v) {
});

Button plus = (Button) view.findViewById(R.id.button_plus);
if (!Utils.DARKTHEME) plus.setTextColor(getResources().getColor(R.color.black));
plus.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Expand Down
Expand Up @@ -48,12 +48,29 @@ public boolean showApplyOnBoot() {
public void init(Bundle savedInstanceState) {
super.init(savedInstanceState);

forceenglishlanguageInit();
darkthemeInit();
if (!Resources.getSystem().getConfiguration().locale.getLanguage().equals("en"))
forceenglishlanguageInit();
betainfoInit();
applyonbootInit();
debuggingInit();
}

private void darkthemeInit() {
SwitchCompatCardItem.DSwitchCompatCard mDarkthemeCard = new SwitchCompatCardItem.DSwitchCompatCard();
mDarkthemeCard.setDescription(getString(R.string.dark_theme));
mDarkthemeCard.setChecked(Utils.DARKTHEME);
mDarkthemeCard.setOnDSwitchCompatCardListener(new SwitchCompatCardItem.DSwitchCompatCard.OnDSwitchCompatCardListener() {
@Override
public void onChecked(SwitchCompatCardItem.DSwitchCompatCard dSwitchCompatCard, boolean checked) {
Utils.saveBoolean("darktheme", checked, getActivity());
startActivity(new Intent(getActivity(), MainActivity.class));
}
});

addView(mDarkthemeCard);
}

private void forceenglishlanguageInit() {
SwitchCompatCardItem.DSwitchCompatCard mForceEnglishLanguageCard = new SwitchCompatCardItem.DSwitchCompatCard();
mForceEnglishLanguageCard.setDescription(getString(R.string.force_english_language));
Expand Down
13 changes: 8 additions & 5 deletions app/src/main/java/com/grarak/kerneladiutor/utils/Utils.java
Expand Up @@ -19,8 +19,10 @@
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.net.Uri;
import android.util.DisplayMetrics;
import android.util.Log;
import android.widget.Toast;

Expand Down Expand Up @@ -54,13 +56,14 @@ public class Utils implements Constants {

// Saving Profile Apply here
public static boolean PROFILE_APPLY = false;
public static boolean DARKTHEME = false;

public static void setLocale(String lang, Context context) {
Locale locale = new Locale(lang);
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
context.getResources().updateConfiguration(config, null);
Resources res = context.getResources();
DisplayMetrics dm = res.getDisplayMetrics();
android.content.res.Configuration conf = res.getConfiguration();
conf.locale = new Locale(lang);
res.updateConfiguration(conf, dm);
}

public static void vibrate(int duration) {
Expand Down
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_activated="true" android:color="@color/white" />
<item android:state_focused="false" android:state_pressed="true" android:color="@color/white" />
<item android:color="@android:color/black" />
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_activated="true" android:color="@color/white" />
<item android:state_focused="false" android:state_pressed="true" android:color="@color/black" />
<item android:color="@color/black" />
</selector>
6 changes: 0 additions & 6 deletions app/src/main/res/drawable-v21/item_bg.xml

This file was deleted.

4 changes: 0 additions & 4 deletions app/src/main/res/drawable-v21/no_highlight.xml

This file was deleted.

4 changes: 4 additions & 0 deletions app/src/main/res/drawable-v21/no_highlight_dark.xml
@@ -0,0 +1,4 @@
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/navigationdrawer_background_dark">
<item android:drawable="@color/navigationdrawer_background_dark" />
</ripple>
4 changes: 4 additions & 0 deletions app/src/main/res/drawable-v21/no_highlight_light.xml
@@ -0,0 +1,4 @@
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/navigationdrawer_background_light">
<item android:drawable="@color/navigationdrawer_background_light" />
</ripple>

0 comments on commit 615c9bf

Please sign in to comment.