Skip to content

Commit

Permalink
Merge pull request #61 from k0shk0sh/master
Browse files Browse the repository at this point in the history
Custom CardView background color
  • Loading branch information
daniel-stoneuk committed Jun 17, 2017
2 parents 5c7de58 + e033ca5 commit f2f08b5
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 23 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -197,6 +197,7 @@ Check out a working example in [`Demo.java`][3].
- [ComicsDB Client](https://play.google.com/store/apps/details?id=cz.kutner.comicsdbclient.comicsdbclient), code available on [GitHub](https://github.com/tukak/comicsdbclient)
- [Android About Box](https://github.com/eggheadgames/android-about-box) (library) - an opinionated About Box for Android
- [Skin Widget for Minecraft](https://play.google.com/store/apps/details?id=com.rabross.android.minecraftskinwidget)
- [FastHub for GitHub](https://play.google.com/store/apps/details?id=com.fastaccess.github&hl=en)

## License

Expand Down
Expand Up @@ -30,6 +30,7 @@ public class ExampleMaterialAboutActivity extends MaterialAboutActivity {
public static final int THEME_LIGHT_DARKBAR = 1;
public static final int THEME_DARK_LIGHTBAR = 2;
public static final int THEME_DARK_DARKBAR = 3;
public static final int THEME_CUSTOM_CARDVIEW = 4;

protected int colorIcon = R.color.mal_color_icon_light_theme;

Expand Down Expand Up @@ -120,6 +121,10 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
setTheme(R.style.AppTheme_MaterialAboutActivity_Dark_DarkActionBar);
colorIcon = R.color.mal_color_icon_dark_theme;
break;
case THEME_CUSTOM_CARDVIEW:
setTheme(R.style.AppTheme_MaterialAboutActivity_Light_CustomCardView);
colorIcon = R.color.mal_color_icon_dark_theme;
break;
}

super.onCreate(savedInstanceState);
Expand Down
9 changes: 8 additions & 1 deletion app/src/main/res/layout/content_main.xml
Expand Up @@ -55,5 +55,12 @@
android:tag="3"
android:text="Launch Activity - Dark with Dark Action Bar" />


<Button
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/mal_baseline"
android:onClick="onActivityButtonPressed"
android:tag="4"
android:text="Launch Activity - Custom CardView Background" />
</LinearLayout>
16 changes: 14 additions & 2 deletions app/src/main/res/values/styles.xml
Expand Up @@ -20,6 +20,7 @@
<item name="colorAccent">@color/colorAccent</item>
</style>


<style name="AppTheme.MaterialAboutActivity.Fragment" parent="Theme.Mal.Dark.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
Expand All @@ -41,15 +42,26 @@
<item name="colorAccent">@color/colorAccent</item>
</style>

<style name="AppTheme.MaterialAboutActivity.Light.CustomCardView" parent="Theme.Mal.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="mal_card_background">@color/colorPrimaryDark</item>
<item name="android:textColorPrimary">#eee</item>
<item name="mal_color_primary">#eee</item>
<item name="mal_color_secondary">#ffe0e0e0</item>
</style>

<style name="AppTheme.MaterialAboutActivity.Light.LightActionBar" parent="Theme.Mal.Light.LightActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorLightBar</item>
<item name="colorPrimaryDark">@color/colorLightStatus</item>
<item name="colorAccent">@color/colorAccent</item>
</style>

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar"/>

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light"/>

</resources>
Expand Up @@ -24,6 +24,8 @@
import com.danielstone.materialaboutlibrary.util.DefaultViewTypeManager;
import com.danielstone.materialaboutlibrary.util.ViewTypeManager;

import java.lang.ref.WeakReference;

public abstract class MaterialAboutActivity extends AppCompatActivity {

private MaterialAboutList list = new MaterialAboutList.Builder().build();
Expand Down Expand Up @@ -173,22 +175,22 @@ protected void setScrollToolbar(boolean scrollToolbar) {

private static class ListTask extends AsyncTask<String, String, MaterialAboutList> {

private MaterialAboutActivity context;
private WeakReference<MaterialAboutActivity> context;

ListTask(MaterialAboutActivity context) {
this.context = context;
this.context = new WeakReference<>(context);
}

@Override
protected MaterialAboutList doInBackground(String... params) {
return isCancelled() ? null : context.getMaterialAboutList(context);
return isCancelled() || context.get() == null ? null : context.get().getMaterialAboutList(context.get());
}

@Override
protected void onPostExecute(MaterialAboutList materialAboutList) {
super.onPostExecute(materialAboutList);
if (!context.isFinishing()) {
context.onTaskFinished(materialAboutList);
if (!context.get().isFinishing()) {
context.get().onTaskFinished(materialAboutList);
}
context = null;
}
Expand Down
30 changes: 15 additions & 15 deletions library/src/main/res/layout/mal_material_about_list_card.xml
@@ -1,25 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_marginEnd="@dimen/mal_baseline_half"
android:layout_marginLeft="@dimen/mal_baseline_half"
android:layout_marginStart="@dimen/mal_baseline_half"
android:layout_marginRight="@dimen/mal_baseline_half"
android:layout_marginEnd="@dimen/mal_baseline_half"
android:layout_marginStart="@dimen/mal_baseline_half"
android:layout_marginTop="@dimen/mal_baseline_half"
android:paddingBottom="@dimen/mal_baseline"
android:paddingEnd="@dimen/mal_baseline_half"
android:paddingLeft="@dimen/mal_baseline_half"
android:paddingStart="@dimen/mal_baseline_half"
android:paddingRight="@dimen/mal_baseline_half"
android:paddingEnd="@dimen/mal_baseline_half"
android:paddingStart="@dimen/mal_baseline_half"
android:paddingTop="@dimen/mal_baseline"
android:paddingBottom="@dimen/mal_baseline"
app:cardBackgroundColor="?mal_card_background"
app:cardCornerRadius="@dimen/mal_card_radius"
app:cardElevation="@dimen/mal_card_elevation"
app:cardPreventCornerOverlap="false"
app:cardUseCompatPadding="true"
>
app:cardUseCompatPadding="true">

<LinearLayout
android:layout_width="match_parent"
Expand All @@ -30,24 +31,23 @@
android:id="@+id/mal_list_card_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/mal_baseline_half"
android:layout_marginEnd="@dimen/mal_baseline"
android:layout_marginLeft="@dimen/mal_baseline"
android:layout_marginStart="@dimen/mal_baseline"
android:layout_marginRight="@dimen/mal_baseline"
android:layout_marginEnd="@dimen/mal_baseline"
android:layout_marginStart="@dimen/mal_baseline"
android:layout_marginTop="@dimen/mal_baseline"
android:layout_marginBottom="@dimen/mal_baseline_half"
android:textAppearance="@style/TextAppearance.AppCompat.Body2"
android:textColor="?mal_color_primary"
tools:text="Author" />
tools:text="Author"/>

<android.support.v7.widget.RecyclerView
android:id="@+id/mal_card_recyclerview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:paddingTop="@dimen/mal_baseline_half"
android:paddingBottom="@dimen/mal_baseline_half"
/>
android:paddingTop="@dimen/mal_baseline_half"/>

</LinearLayout>

Expand Down
1 change: 1 addition & 0 deletions library/src/main/res/values/attrs.xml
Expand Up @@ -5,4 +5,5 @@

<attr name="mal_color_primary" format="reference|color" />
<attr name="mal_color_secondary" format="reference|color" />
<attr name="mal_card_background" format="reference|color" />
</resources>
5 changes: 5 additions & 0 deletions library/src/main/res/values/styles.xml
Expand Up @@ -8,6 +8,7 @@
<item name="mal_popupOverlay">@style/Theme.Mal.Light.PopupOverlay</item>
<item name="mal_color_primary">@color/mal_text_primary</item>
<item name="mal_color_secondary">@color/mal_text_secondary</item>
<item name="mal_card_background">@color/cardview_light_background</item>
</style>

<style name="Theme.Mal.Light.DarkActionBar" parent="Theme.AppCompat.Light.NoActionBar">
Expand All @@ -17,6 +18,7 @@
<item name="mal_popupOverlay">@style/Theme.Mal.Light.PopupOverlay</item>
<item name="mal_color_primary">@color/mal_text_primary</item>
<item name="mal_color_secondary">@color/mal_text_secondary</item>
<item name="mal_card_background">@color/cardview_light_background</item>
</style>

<style name="Theme.Mal.Light.LightActionBar" parent="Theme.AppCompat.Light.NoActionBar">
Expand All @@ -26,6 +28,7 @@
<item name="mal_popupOverlay">@style/Theme.Mal.Light.PopupOverlay</item>
<item name="mal_color_primary">@color/mal_text_primary</item>
<item name="mal_color_secondary">@color/mal_text_secondary</item>
<item name="mal_card_background">@color/cardview_light_background</item>
</style>

<style name="Theme.Mal.Dark.DarkActionBar" parent="Theme.AppCompat.NoActionBar">
Expand All @@ -35,6 +38,7 @@
<item name="mal_popupOverlay">@style/Theme.Mal.Dark.PopupOverlay</item>
<item name="mal_color_primary">@color/mal_text_primary_dark</item>
<item name="mal_color_secondary">@color/mal_text_secondary_dark</item>
<item name="mal_card_background">@color/cardview_dark_background</item>
</style>

<style name="Theme.Mal.Dark.LightActionBar" parent="Theme.AppCompat.NoActionBar">
Expand All @@ -44,6 +48,7 @@
<item name="mal_popupOverlay">@style/Theme.Mal.Dark.PopupOverlay</item>
<item name="mal_color_primary">@color/mal_text_primary_dark</item>
<item name="mal_color_secondary">@color/mal_text_secondary_dark</item>
<item name="mal_card_background">@color/cardview_dark_background</item>
</style>

<style name="Theme.Mal.Light.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
Expand Down

0 comments on commit f2f08b5

Please sign in to comment.