Labeled separator view styling refactoring.

This commit is contained in:
Anton Chekulaev 2020-08-21 17:10:49 +10:00
parent a5408fa4f4
commit 9d7d7689e2
8 changed files with 40 additions and 33 deletions

View File

@ -10,8 +10,7 @@
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:textColor="@color/text"
android:alpha="0.6"
android:textColor="?android:textColorTertiary"
android:textSize="@dimen/small_font_size"
android:text="@string/your_session_id" />

View File

@ -4,9 +4,11 @@
<!-- Session -->
<color name="accent">#00E97B</color>
<color name="text">#000000</color>
<color name="unimportant">#606060</color>
<color name="cell_background">#FCFCFC</color>
<color name="cell_selected">#DFDFDF</color>
<color name="navigation_bar_background">#FCFCFC</color>
<color name="separator">#B0B0B0</color>
<color name="unimportant_button_background">@color/transparent</color>
<color name="dialog_background">#FCFCFC</color>
<color name="dialog_border">#212121</color>

View File

@ -4,7 +4,6 @@
<style name="Session.DarkTheme" parent="Session.BaseDarkTheme">
<item name="android:navigationBarColor">@color/gray65</item>
<item name="android:statusBarColor">@color/accent</item>
<item name="titleTextColor">@color/text</item>
<item name="android:textColorHint">@color/gray50</item>
<item name="home_gradient_start">#00FFFFFF</item>

View File

@ -67,12 +67,10 @@
<item name="tabBackground">@color/action_bar_background</item>
<item name="tabRippleColor">@color/cell_selected</item>
<item name="tabTextAppearance">@style/Session.DarkTabLayout.TextAppearance</item>
<item name="tabSelectedTextColor">@color/text</item>
</style>
<style name="Session.DarkTabLayout.TextAppearance" parent="TextAppearance.Design.Tab">
<item name="android:textSize">@dimen/medium_font_size</item>
<item name="android:textColor">@color/unimportant</item>"
<item name="textAllCaps">false</item>
</style>

View File

@ -7,6 +7,11 @@
<item name="colorPrimary">@color/action_bar_background</item>
<item name="colorPrimaryDark">@color/action_bar_background</item>
<item name="colorAccent">@color/accent</item>
<item name="android:textColorPrimary">@color/text</item>
<item name="android:textColorSecondary">?android:textColorPrimary</item>
<item name="android:textColorTertiary">@color/unimportant</item>
<item name="android:textColor">?android:textColorPrimary</item>
<item name="android:textColorHint">@color/gray27</item>
<item name="android:windowBackground">@drawable/default_session_background</item>
<item name="android:colorBackground">@color/default_background_start</item>
<item name="android:navigationBarColor">@color/compose_view_background</item>
@ -19,15 +24,16 @@
<item name="actionModeBackground">@color/compose_view_background</item>
<item name="statusBarBackground">@color/accent</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="titleTextColor">@color/text</item>
<item name="colorControlNormal">@color/text</item>
<item name="titleTextColor">?android:textColorPrimary</item>
<item name="colorControlNormal">?android:textColorPrimary</item>
<item name="appBarLayoutStyle">@style/Widget.Design.AppBarLayout</item>
<item name="android:textColor">@color/text</item>
<item name="android:textColorHint">#9FFF</item>
<item name="windowActionModeOverlay">true</item>
<item name="actionModeCloseDrawable">@drawable/ic_baseline_clear_24</item>
<item name="dividerVertical">@color/separator</item>
<item name="dividerHorizontal">?dividerVertical</item>
<!-- App specific attributes -->
<item name="dialog_background_color">@color/dialog_background</item>

View File

@ -2,13 +2,10 @@ package org.thoughtcrime.securesms.components;
import android.content.Context;
import androidx.annotation.AttrRes;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.AppCompatImageButton;
import android.util.AttributeSet;
import android.util.Log;
import android.util.TypedValue;
import android.view.View;
import org.thoughtcrime.securesms.TransportOption;
@ -116,7 +113,7 @@ public class SendButton extends AppCompatImageButton
case SMS:
case TEXTSECURE:
default: {
sendDrawable = ThemeUtil.getDrawableResWithAttribute(
sendDrawable = ThemeUtil.getThemedDrawableResId(
getContext(), R.attr.conversation_transport_sms_indicator);
}
}

View File

@ -9,21 +9,21 @@ import android.view.LayoutInflater
import android.widget.RelativeLayout
import kotlinx.android.synthetic.main.view_separator.view.*
import network.loki.messenger.R
import org.thoughtcrime.securesms.loki.utilities.getColorWithID
import org.thoughtcrime.securesms.loki.utilities.toPx
import org.thoughtcrime.securesms.util.ThemeUtil
class LabeledSeparatorView : RelativeLayout {
private val path = Path()
private val paint: Paint = {
private val paint: Paint by lazy{
val result = Paint()
result.style = Paint.Style.STROKE
result.color = resources.getColorWithID(R.color.separator, context.theme)
result.color = ThemeUtil.getThemedColor(context, R.attr.dividerHorizontal)
result.strokeWidth = toPx(1, resources).toFloat()
result.isAntiAlias = true
result
}()
}
// region Lifecycle
constructor(context: Context) : super(context) {
@ -43,7 +43,7 @@ class LabeledSeparatorView : RelativeLayout {
}
private fun setUpViewHierarchy() {
val inflater = context.applicationContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
val contentView = inflater.inflate(R.layout.view_separator, null)
val layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)
addView(contentView, layoutParams)
@ -56,7 +56,7 @@ class LabeledSeparatorView : RelativeLayout {
super.onDraw(c)
val w = width.toFloat()
val h = height.toFloat()
val hMargin = toPx(10, resources).toFloat()
val hMargin = toPx(16, resources).toFloat()
path.reset()
path.moveTo(0.0f, h / 2)
path.lineTo(titleTextView.left - hMargin, h / 2)

View File

@ -4,6 +4,7 @@ import android.content.Context;
import android.content.res.Resources;
import android.graphics.Color;
import androidx.annotation.AttrRes;
import androidx.annotation.ColorInt;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.StyleRes;
@ -19,25 +20,41 @@ public class ThemeUtil {
private static final String TAG = ThemeUtil.class.getSimpleName();
public static boolean isDarkTheme(@NonNull Context context) {
return getAttribute(context, R.attr.theme_type, "light").equals("dark");
return getAttributeText(context, R.attr.theme_type, "light").equals("dark");
}
@ColorInt
public static int getThemedColor(@NonNull Context context, @AttrRes int attr) {
TypedValue typedValue = new TypedValue();
Resources.Theme theme = context.getTheme();
if (theme.resolveAttribute(attr, typedValue, true)) {
return typedValue.data;
}
} else {
Log.e(TAG, "Couldn't find a color attribute with id: " + attr);
return Color.RED;
}
}
@DrawableRes
public static int getThemedDrawableResId(@NonNull Context context, @AttrRes int attr) {
TypedValue typedValue = new TypedValue();
Resources.Theme theme = context.getTheme();
if (theme.resolveAttribute(attr, typedValue, true)) {
return typedValue.resourceId;
} else {
Log.e(TAG, "Couldn't find a drawable attribute with id: " + attr);
return 0;
}
}
public static LayoutInflater getThemedInflater(@NonNull Context context, @NonNull LayoutInflater inflater, @StyleRes int theme) {
Context contextThemeWrapper = new ContextThemeWrapper(context, theme);
return inflater.cloneInContext(contextThemeWrapper);
}
private static String getAttribute(Context context, int attribute, String defaultValue) {
private static String getAttributeText(Context context, int attribute, String defaultValue) {
TypedValue outValue = new TypedValue();
if (context.getTheme().resolveAttribute(attribute, outValue, true)) {
@ -49,15 +66,4 @@ public class ThemeUtil {
return defaultValue;
}
@DrawableRes
public static int getDrawableResWithAttribute(Context context, @AttrRes int attributeId) {
TypedValue resolvedValue = new TypedValue();
context.getTheme().resolveAttribute(attributeId, resolvedValue, true);
if (resolvedValue.type != TypedValue.TYPE_STRING) {
Log.e(TAG, "Cannot resolve a drawable resource from an attribute ID: " + attributeId);
return 0;
}
return resolvedValue.resourceId;
}
}