Fully implement a dark theme

Closes #3
This commit is contained in:
Jakob Nixdorf 2017-07-31 23:17:42 +02:00
parent e9b33edb1a
commit 69e68aa94b
No known key found for this signature in database
GPG key ID: BE99BF86574A7DBC
10 changed files with 174 additions and 55 deletions

View file

@ -25,11 +25,13 @@ package org.shadowice.flocke.andotp;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.ColorFilter;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.ViewStub;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
@ -48,6 +50,11 @@ public class AboutActivity extends BaseActivity {
private static final String BUGREPORT_URI = GITHUB_URI + "/issues";
int[] imageResources = {
R.id.aboutImgVersion, R.id.aboutImgLicense, R.id.aboutImgChangelog, R.id.aboutImgSource,
R.id.aboutImgOpenSource, R.id.aboutImgAuthor1, R.id.aboutImgAuthor2, R.id.aboutImgBugs
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -62,6 +69,12 @@ public class AboutActivity extends BaseActivity {
stub.setLayoutResource(R.layout.content_about);
View v = stub.inflate();
ColorFilter filter = ThemeHelper.getThemeColorFilter(this, android.R.attr.textColorSecondary);
for (int i : imageResources) {
ImageView imgView = (ImageView) v.findViewById(i);
imgView.getDrawable().setColorFilter(filter);
}
String versionName = "";
try {
PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0);

View file

@ -28,6 +28,7 @@ import android.content.ClipboardManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.graphics.ColorFilter;
import android.preference.PreferenceManager;
import android.support.v7.widget.CardView;
import android.support.v7.widget.PopupMenu;
@ -43,6 +44,7 @@ import android.widget.Filter;
import android.widget.Filterable;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
@ -296,7 +298,6 @@ public class EntriesCardAdapter extends RecyclerView.Adapter<EntriesCardAdapter.
protected void publishResults(CharSequence constraint, FilterResults results) {
displayedEntries = (ArrayList<Integer>) results.values;
notifyDataSetChanged();
}
}
@ -306,26 +307,44 @@ public class EntriesCardAdapter extends RecyclerView.Adapter<EntriesCardAdapter.
private ViewHolderEventCallback eventCallback;
private CardView card;
private TextView OTPValue;
private TextView OTPValueCover;
private TextView OTPLabel;
private TextView value;
private LinearLayout valueLayout;
private ImageView visibleImg;
private LinearLayout coverLayout;
private TextView label;
private LinearLayout customPeriodLayout;
private TextView customPeriod;
private ImageButton menuButton;
private ImageButton copyButton;
public EntryViewHolder(final View v) {
super(v);
card = (CardView) v.findViewById(R.id.card_view);
OTPValue = (TextView) v.findViewById(R.id.textViewOTP);
OTPValueCover = (TextView) v.findViewById(R.id.textViewOTPCover);
OTPLabel = (TextView) v.findViewById(R.id.textViewLabel);
value = (TextView) v.findViewById(R.id.valueText);
valueLayout = (LinearLayout) v.findViewById(R.id.valueLayout);
visibleImg = (ImageView) v.findViewById(R.id.valueImg);
coverLayout = (LinearLayout) v.findViewById(R.id.coverLayout);
label = (TextView) v.findViewById(R.id.textViewLabel);
customPeriodLayout = (LinearLayout) v.findViewById(R.id.customPeriodLayout);
customPeriod = (TextView) v.findViewById(R.id.customPeriod);
menuButton = (ImageButton) v.findViewById(R.id.menuButton);
copyButton = (ImageButton) v.findViewById(R.id.copyButton);
ImageButton menuButton = (ImageButton) v.findViewById(R.id.menuButton);
ImageButton copyButton = (ImageButton) v.findViewById(R.id.copyButton);
ImageView invisibleImg = (ImageView) v.findViewById(R.id.coverImg);
// Style the buttons in the current theme colors
ColorFilter colorFilter = ThemeHelper.getThemeColorFilter(context, android.R.attr.textColorSecondary);
menuButton.getDrawable().setColorFilter(colorFilter);
copyButton.getDrawable().setColorFilter(colorFilter);
visibleImg.getDrawable().setColorFilter(colorFilter);
invisibleImg.getDrawable().setColorFilter(colorFilter);
// Setup onClickListeners
menuButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
@ -336,14 +355,14 @@ public class EntriesCardAdapter extends RecyclerView.Adapter<EntriesCardAdapter.
copyButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
copyToClipboard(OTPValue.getText().toString());
copyToClipboard(value.getText().toString());
}
});
}
public void updateValues(String label, String token) {
OTPLabel.setText(label);
OTPValue.setText(token);
this.label.setText(label);
value.setText(token);
}
public void showCustomPeriod(int period) {
@ -356,32 +375,32 @@ public class EntriesCardAdapter extends RecyclerView.Adapter<EntriesCardAdapter.
}
public void setLabelSize(int size) {
OTPLabel.setTextSize(TypedValue.COMPLEX_UNIT_PT, size);
label.setTextSize(TypedValue.COMPLEX_UNIT_PT, size);
}
public void enableTapToReveal() {
OTPValue.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_visibility_visible, 0, 0, 0);
OTPValue.setVisibility(View.GONE);
OTPValueCover.setVisibility(View.VISIBLE);
valueLayout.setVisibility(View.GONE);
coverLayout.setVisibility(View.VISIBLE);
visibleImg.setVisibility(View.VISIBLE);
card.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (OTPValue.getVisibility() == View.GONE && OTPValueCover.getVisibility() == View.VISIBLE) {
OTPValue.setVisibility(View.VISIBLE);
OTPValueCover.setVisibility(View.GONE);
if (valueLayout.getVisibility() == View.GONE && coverLayout.getVisibility() == View.VISIBLE) {
valueLayout.setVisibility(View.VISIBLE);
coverLayout.setVisibility(View.GONE);
} else {
OTPValue.setVisibility(View.GONE);
OTPValueCover.setVisibility(View.VISIBLE);
valueLayout.setVisibility(View.GONE);
coverLayout.setVisibility(View.VISIBLE);
}
}
});
}
public void disableTapToReveal() {
OTPValue.setCompoundDrawables(null, null, null, null);
OTPValue.setVisibility(View.VISIBLE);
OTPValueCover.setVisibility(View.GONE);
valueLayout.setVisibility(View.VISIBLE);
coverLayout.setVisibility(View.GONE);
visibleImg.setVisibility(View.GONE);
card.setOnClickListener(null);
}

View file

@ -0,0 +1,46 @@
/*
* Copyright (C) 2017 Jakob Nixdorf
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.shadowice.flocke.andotp;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.ColorFilter;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
public class ThemeHelper {
public static int getThemeColor(Context context, int colorAttr) {
Resources.Theme theme = context.getTheme();
TypedArray arr = theme.obtainStyledAttributes(new int[]{colorAttr});
int colorValue = arr.getColor(0, -1);
arr.recycle();
return colorValue;
}
public static ColorFilter getThemeColorFilter(Context context, int colorAttr) {
return new PorterDuffColorFilter(getThemeColor(context, colorAttr), PorterDuff.Mode.SRC_IN);
}
}

View file

@ -4,6 +4,6 @@
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="@color/primary_light"
android:fillColor="#FF727272"
android:pathData="M12,7c2.76,0 5,2.24 5,5 0,0.65 -0.13,1.26 -0.36,1.83l2.92,2.92c1.51,-1.26 2.7,-2.89 3.43,-4.75 -1.73,-4.39 -6,-7.5 -11,-7.5 -1.4,0 -2.74,0.25 -3.98,0.7l2.16,2.16C10.74,7.13 11.35,7 12,7zM2,4.27l2.28,2.28 0.46,0.46C3.08,8.3 1.78,10.02 1,12c1.73,4.39 6,7.5 11,7.5 1.55,0 3.03,-0.3 4.38,-0.84l0.42,0.42L19.73,22 21,20.73 3.27,3 2,4.27zM7.53,9.8l1.55,1.55c-0.05,0.21 -0.08,0.43 -0.08,0.65 0,1.66 1.34,3 3,3 0.22,0 0.44,-0.03 0.65,-0.08l1.55,1.55c-0.67,0.33 -1.41,0.53 -2.2,0.53 -2.76,0 -5,-2.24 -5,-5 0,-0.79 0.2,-1.53 0.53,-2.2zM11.84,9.02l3.15,3.15 0.02,-0.16c0,-1.66 -1.34,-3 -3,-3l-0.17,0.01z"/>
</vector>

View file

@ -4,6 +4,6 @@
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="@color/secondary_text"
android:fillColor="#FF727272"
android:pathData="M12,4.5C7,4.5 2.73,7.61 1,12c1.73,4.39 6,7.5 11,7.5s9.27,-3.11 11,-7.5c-1.73,-4.39 -6,-7.5 -11,-7.5zM12,17c-2.76,0 -5,-2.24 -5,-5s2.24,-5 5,-5 5,2.24 5,5 -2.24,5 -5,5zM12,9c-1.66,0 -3,1.34 -3,3s1.34,3 3,3 3,-1.34 3,-3 -1.34,-3 -3,-3z"/>
</vector>

View file

@ -23,7 +23,7 @@
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:navigationIcon="?homeAsUpIndicator"
app:popupTheme="@style/AppTheme.PopupOverlay" />
app:popupTheme="?attr/actionBarPopupTheme" />
</RelativeLayout>

View file

@ -24,31 +24,55 @@
android:layout_weight="1">
<LinearLayout
android:id="@+id/textViewOTPLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textViewOTP"
<LinearLayout
android:id="@+id/valueLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableStart="@drawable/ic_visibility_visible"
android:drawablePadding="@dimen/activity_margin_small"
android:visibility="gone"
android:textSize="28sp"
android:textStyle="bold" />
android:visibility="gone">
<TextView
android:id="@+id/textViewOTPCover"
<ImageView
android:id="@+id/valueImg"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginEnd="@dimen/activity_margin_small"
android:src="@drawable/ic_visibility_visible"/>
<TextView
android:id="@+id/valueText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="?android:attr/textColorSecondary"
android:textSize="28sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:id="@+id/coverLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableStart="@drawable/ic_visibility_invisible"
android:drawablePadding="@dimen/activity_margin_small"
android:visibility="visible"
android:textSize="28sp"
android:textStyle="bold"
android:textColor="@color/primary_light"
android:text="@string/label_tap_to_reveal" />
android:layout_height="wrap_content">
<ImageView
android:id="@+id/coverImg"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginEnd="@dimen/activity_margin_small"
android:alpha="0.4"
android:src="@drawable/ic_visibility_invisible"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:alpha="0.4"
android:textColor="?android:attr/textColorSecondary"
android:textSize="28sp"
android:textStyle="bold"
android:text="@string/label_tap_to_reveal" />
</LinearLayout>
</LinearLayout>
<TextView

View file

@ -86,6 +86,7 @@
android:gravity="center_vertical" >
<ImageView
android:id="@+id/aboutImgVersion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/activity_margin"
@ -125,6 +126,7 @@
android:gravity="center_vertical" >
<ImageView
android:id="@+id/aboutImgLicense"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/activity_margin"
@ -164,6 +166,7 @@
android:gravity="center_vertical" >
<ImageView
android:id="@+id/aboutImgChangelog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/activity_margin"
@ -190,6 +193,7 @@
android:gravity="center_vertical" >
<ImageView
android:id="@+id/aboutImgSource"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/activity_margin"
@ -216,6 +220,7 @@
android:gravity="center_vertical" >
<ImageView
android:id="@+id/aboutImgOpenSource"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/activity_margin"
@ -263,6 +268,7 @@
android:gravity="center_vertical" >
<ImageView
android:id="@+id/aboutImgAuthor1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/activity_margin"
@ -302,7 +308,7 @@
android:background="?android:attr/selectableItemBackground"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold"
android:textColor="@color/github_gray"
android:textColor="?attr/colorGithub"
android:text="@string/about_label_github" />
<TextView
@ -313,7 +319,7 @@
android:background="?android:attr/selectableItemBackground"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold"
android:textColor="@color/paypal_blue"
android:textColor="?attr/colorPaypal"
android:text="@string/about_label_donate" />
</LinearLayout>
</LinearLayout>
@ -336,6 +342,7 @@
android:gravity="center_vertical" >
<ImageView
android:id="@+id/aboutImgAuthor2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/activity_margin"
@ -375,7 +382,7 @@
android:background="?android:attr/selectableItemBackground"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold"
android:textColor="@color/github_gray"
android:textColor="?attr/colorGithub"
android:text="@string/about_label_github" />
<TextView
@ -386,7 +393,7 @@
android:background="?android:attr/selectableItemBackground"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold"
android:textColor="@color/github_gray"
android:textColor="?attr/colorGithub"
android:text="@string/about_label_original_app" />
</LinearLayout>
</LinearLayout>
@ -426,6 +433,7 @@
android:gravity="center_vertical" >
<ImageView
android:id="@+id/aboutImgBugs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/activity_margin"

View file

@ -4,12 +4,12 @@
<color name="colorPrimaryDark">#00600F</color>
<color name="colorAccent">#FFCC00</color>
<color name="primary_light">#CFD8DC</color>
<color name="secondary_text">#727272</color>
<color name="divider">#B6B6B6</color>
<color name="github_gray">#333333</color>
<color name="paypal_blue">#003087</color>
<color name="github_dark">#333333</color>
<color name="github_light">#f5f5f5</color>
<color name="paypal_dark">#003087</color>
<color name="paypal_light">#009cde</color>
<color name="fab_small_label_background">#212121</color>
</resources>

View file

@ -1,4 +1,7 @@
<resources>
<attr name="colorGithub" format="reference" />
<attr name="colorPaypal" format="reference" />
<!-- Light application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
@ -7,6 +10,9 @@
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="colorGithub">@color/github_dark</item>
<item name="colorPaypal">@color/paypal_dark</item>
<item name="actionBarPopupTheme">@style/AppTheme.PopupOverlay</item>
</style>
@ -26,6 +32,9 @@
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="colorGithub">@color/github_light</item>
<item name="colorPaypal">@color/paypal_light</item>
<item name="actionBarPopupTheme">@style/AppTheme.Dark.PopupOverlay</item>
</style>