Skip to content

Commit

Permalink
Make the UI compatible with the devices with OS version below 5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rayworks committed Sep 26, 2018
1 parent e5ac107 commit 033a583
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 30 deletions.
17 changes: 15 additions & 2 deletions app/src/main/java/com/rayworks/droidweekly/MyViewHolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.os.Build;
import android.support.v4.view.ViewCompat;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
Expand Down Expand Up @@ -42,8 +44,19 @@ public void bind(ArticleItem item) {
String imageUrl = item.getImageUrl();
if (!TextUtils.isEmpty(imageUrl)) {
imageParent.setVisibility(View.VISIBLE);
ViewCompat.setBackgroundTintList(
imageParent, ColorStateList.valueOf(item.getImgFrameColor()));

int frameColor = item.getImgFrameColor();

View targetView = imageParent;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
// apply a different layout
// ref: https://stackoverflow.com/questions/4772537/i-need-to-change-the-stroke-color-to-a-user-defined-color-nothing-to-do-with-th
targetView = itemView.findViewById(R.id.frame_view);
GradientDrawable drawable = (GradientDrawable) targetView.getBackground();
drawable.setStroke(1, frameColor);
} else {
ViewCompat.setBackgroundTintList(targetView, ColorStateList.valueOf(frameColor));
}

Glide.with(itemView).load(imageUrl).into(imageView);
} else {
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/res/drawable/rect_image_frame.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke
android:width="0.5dp"
android:color="@color/light_blue" />
<solid android:color="@android:color/transparent" />
</shape>
53 changes: 53 additions & 0 deletions app/src/main/res/layout-v21/view_news_item.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tool="http://schemas.android.com/tools"
android:id="@+id/item_parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackgroundBorderless"
android:descendantFocusability="beforeDescendants">

<FrameLayout
android:layout_width="72.5dp"
android:layout_height="72.5dp"
android:id="@+id/image_parent"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginStart="16dp"
android:background="@drawable/rect_image_frame">

<ImageView
android:layout_gravity="center"
android:id="@+id/imageView"
android:layout_width="72dp"
android:layout_height="72dp"
android:translationZ="3dp"
app:srcCompat="@mipmap/ic_launcher" />
</FrameLayout>


<TextView
android:id="@+id/textViewTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:layout_toEndOf="@id/image_parent"
android:ellipsize="end"
android:textColor="@android:color/black"
android:textSize="14sp"
tool:text="TextView" />

<TextView
android:id="@+id/textViewDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/textViewTitle"
android:layout_marginBottom="16dp"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_toEndOf="@id/image_parent"
android:textColor="@android:color/black"
android:textSize="18sp"
tool:text="TextView123" />
</RelativeLayout>
62 changes: 35 additions & 27 deletions app/src/main/res/layout/view_news_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,45 +9,53 @@
android:descendantFocusability="beforeDescendants">

<FrameLayout
android:layout_width="72.5dp"
android:layout_height="72.5dp"
android:id="@+id/image_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginStart="16dp"
android:background="@drawable/rect_image_frame">
android:layout_marginStart="16dp">

<ImageView
android:layout_gravity="center"
android:id="@+id/imageView"
android:layout_width="72dp"
android:layout_height="72dp"
android:translationZ="3dp"
android:layout_gravity="center"
app:srcCompat="@mipmap/ic_launcher" />
</FrameLayout>

<View
android:id="@+id/frame_view"
android:layout_width="72dp"
android:layout_height="72dp"
android:background="@drawable/rect_image_frame" />
</FrameLayout>

<TextView
android:id="@+id/textViewTitle"
android:layout_width="wrap_content"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:layout_toEndOf="@id/image_parent"
android:ellipsize="end"
android:textColor="@android:color/black"
android:textSize="14sp"
tool:text="TextView" />
android:orientation="vertical">

<TextView
android:id="@+id/textViewTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:ellipsize="end"
android:textColor="@android:color/black"
android:textSize="14sp"
tool:text="TextView" />

<TextView
android:id="@+id/textViewDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:textColor="@android:color/black"
android:textSize="12sp"
tool:text="TextView123" />
</LinearLayout>

<TextView
android:id="@+id/textViewDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/textViewTitle"
android:layout_marginBottom="16dp"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_toEndOf="@id/image_parent"
android:textColor="@android:color/black"
android:textSize="18sp"
tool:text="TextView123" />
</RelativeLayout>

0 comments on commit 033a583

Please sign in to comment.