Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dark mode #108

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 9 additions & 15 deletions app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
<facet type="android" name="Android">
<configuration>
<option name="SELECTED_BUILD_VARIANT" value="debug" />
<option name="SELECTED_TEST_ARTIFACT" value="_android_test_" />
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
<afterSyncTasks>
Expand Down Expand Up @@ -47,46 +46,40 @@
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/shaders" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/shaders" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/builds" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-runtime-classes" />
Expand All @@ -101,6 +94,7 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/restart-dex" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/shaders" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/split-apk" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/transforms" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
Expand All @@ -110,6 +104,6 @@
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="core-3.3.0" level="project" />
<orderEntry type="library" exported="" name="picasso-2.5.2" level="project" />
<orderEntry type="library" exported="" name="gson-2.8.0" level="project" />
<orderEntry type="library" exported="" name="gson-2.8.1" level="project" />
</component>
</module>
39 changes: 39 additions & 0 deletions app/src/main/java/org/fedorahosted/freeotp/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,14 @@
import org.fedorahosted.freeotp.add.ScanActivity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.database.DataSetObserver;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MenuItem.OnMenuItemClickListener;
Expand All @@ -54,9 +58,20 @@
public class MainActivity extends Activity implements OnMenuItemClickListener {
private TokenAdapter mTokenAdapter;
private DataSetObserver mDataSetObserver;
boolean isNightMode;

@Override
protected void onCreate(Bundle savedInstanceState) {

//check last saved app mode(night/light) and set app to this mode
SharedPreferences sharedPref = this.getPreferences(Context.MODE_PRIVATE);
isNightMode = sharedPref.getBoolean("NIGHT_MODE", false);
if (isNightMode) {
setTheme(R.style.MainActivityThemeDark);
}else{
setTheme(R.style.MainActivityThemeLight);
}

super.onCreate(savedInstanceState);
onNewIntent(getIntent());
setContentView(R.layout.main);
Expand Down Expand Up @@ -104,6 +119,7 @@ public boolean onCreateOptionsMenu(Menu menu) {
menu.findItem(R.id.action_scan).setVisible(ScanActivity.haveCamera());
menu.findItem(R.id.action_scan).setOnMenuItemClickListener(this);
menu.findItem(R.id.action_add).setOnMenuItemClickListener(this);
menu.findItem(R.id.action_dark_mode).setOnMenuItemClickListener(this);
menu.findItem(R.id.action_about).setOnMenuItemClickListener(this);
return true;
}
Expand All @@ -120,6 +136,18 @@ public boolean onMenuItemClick(MenuItem item) {
startActivity(new Intent(this, AddActivity.class));
return true;

case R.id.action_dark_mode: //change app light/night mode
if (isNightMode) {
writeSharedPrefs(false);
}else{
writeSharedPrefs(true);
}
//refresh activity
finish();
startActivity(getIntent());

return true;

case R.id.action_about:
startActivity(new Intent(this, AboutActivity.class));
return true;
Expand All @@ -136,4 +164,15 @@ protected void onNewIntent(Intent intent) {
if (uri != null)
TokenPersistence.addWithToast(this, uri.toString());
}

/**
* save last used mode to SharedPreferences
* @param isDarkMode boolean value
*/
private void writeSharedPrefs(boolean isDarkMode){
SharedPreferences sharedPref = this.getPreferences(Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPref.edit();
editor.putBoolean("NIGHT_MODE", isDarkMode);
editor.commit();
}
}
Binary file added app/src/main/res/drawable-hdpi/ic_night_mode.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-mdpi/ic_night_mode.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xhdpi/ic_night_mode.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xxhdpi/ic_night_mode.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions app/src/main/res/drawable/token.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false">
<color android:color="#7FFFFFFF" />
<color android:color="?attr/backgroundCardColorEnabled" />
</item>
<item android:state_pressed="true">
<color android:color="@android:color/transparent" />
</item>
<item>
<color android:color="#FFFFFFFF" />
<color android:color="?attr/backgroundCardColor" />
</item>
</selector>
5 changes: 3 additions & 2 deletions app/src/main/res/layout/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
android:padding="8dp"
android:stretchMode="columnWidth"
android:verticalSpacing="8dp"
android:background="#E5E5E5"
/>
android:background="?attr/backgroundWindowColor"
/>

</LinearLayout>
4 changes: 2 additions & 2 deletions app/src/main/res/layout/titles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
android:gravity="left|center"
android:singleLine="true"
android:text="[email protected]"
android:textColor="@android:color/primary_text_light"
android:textColor="?attr/primaryTextColor"
android:textSize="16sp"
android:textStyle="bold" />

Expand All @@ -22,7 +22,7 @@
android:gravity="left|center"
android:singleLine="true"
android:text="eb40924b-1d13-4807-9a76-30eb7ffa7eba"
android:textColor="@android:color/secondary_text_light"
android:textColor="?attr/secondaryTextColor"
android:textSize="12sp"
android:textStyle="normal" />
</merge>
1 change: 1 addition & 0 deletions app/src/main/res/layout/token.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
- limitations under the License.
-->


<org.fedorahosted.freeotp.TokenLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:freeotp="http://schemas.android.com/apk/res-auto"
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/menu/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@
android:icon="@drawable/ic_action_new_account"
android:title="@string/add_token" />

<item
android:id="@+id/action_dark_mode"
android:showAsAction="ifRoom"
android:icon="@drawable/ic_night_mode"
android:title="@string/dark_mode" />

<item
android:id="@+id/action_about"
android:showAsAction="ifRoom"
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/res/values-v11/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
Base application theme for API 11+. This theme completely replaces
AppBaseTheme from res/values/styles.xml on API 11+ devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
<!-- API 11 theme customizations can go here. -->
<style name="ThemeLight" parent="android:Theme.Holo.Light">
</style>

</resources>
3 changes: 1 addition & 2 deletions app/src/main/res/values-v14/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
AppBaseTheme from BOTH res/values/styles.xml and
res/values-v11/styles.xml on API 14+ devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<!-- API 14 theme customizations can go here. -->
<style name="ThemeDark" parent="android:Theme.Holo.Light.DarkActionBar">
</style>

</resources>
9 changes: 9 additions & 0 deletions app/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,13 @@
<attr name="outer" format="boolean" />
<attr name="hollow" format="boolean" />
</declare-styleable>

<declare-styleable name="CTAppTheme">
<attr name="primaryTextColor" format="color"/>
<attr name="secondaryTextColor" format="color"/>
<attr name="dividerColor" format="color"/>
<attr name="backgroundCardColor" format="color"/>
<attr name="backgroundCardColorEnabled" format="color"/>
<attr name="backgroundWindowColor" format="color"/>
</declare-styleable>
</resources>
4 changes: 4 additions & 0 deletions app/src/main/res/values/color.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<string name="code_copied">Code copied to clipboard.</string>

<string name="about_freeotp">About FreeOTP</string>
<string name="dark_mode">Day/Night mode</string>
<string name="about_version">FreeOTP Version %1$s (%2$d)</string>
<string name="about_copyright">© 2013 - Red Hat, Inc., et al.</string>
<string name="about_license">FreeOTP is licensed under %1$s.</string>
Expand Down
28 changes: 28 additions & 0 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,34 @@
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>

<!-- Light mode colors. -->
<style name="ActivityTheme.Primary.Base.Light" parent="android:Theme.Holo">
<item name="primaryTextColor">#000000</item>
<item name="secondaryTextColor">@android:color/secondary_text_light</item>
<item name="backgroundCardColor">#FFFF</item>
<item name="backgroundCardColorEnabled">#7FFFFFFF</item>
<item name="backgroundWindowColor">#F4F4F6</item>
<item name="dividerColor">#F2F2F3</item>
</style>

<!-- Night mode colors. -->
<style name="ActivityTheme.Primary.Base.Dark" parent="android:Theme.Holo">
<item name="primaryTextColor">#F4F4F6</item>
<item name="secondaryTextColor">#7FFFFFFF</item>
<item name="backgroundCardColor">#28292e</item>
<item name="backgroundCardColorEnabled">#7FFFFFFF</item>
<item name="backgroundWindowColor">#33343B</item>
<item name="dividerColor">#F2F2F3</item>
</style>

<!-- Specific Feed activity theme -->
<style name="MainActivityThemeLight" parent="ActivityTheme.Primary.Base.Light">
<item name="android:windowBackground">?attr/backgroundWindowColor</item>
</style>
<style name="MainActivityThemeDark" parent="ActivityTheme.Primary.Base.Dark">
<item name="android:windowBackground">?attr/backgroundWindowColor</item>
</style>

<style name="Divider">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">1dp</item>
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.2'
classpath 'com.android.tools.build:gradle:2.3.3'
}
}

Expand Down
2 changes: 1 addition & 1 deletion freeotp-android.iml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue Nov 29 15:07:24 EST 2016
#Sat Jun 17 10:40:37 CEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip