aboutsummaryrefslogtreecommitdiff
path: root/wearable/wear/WearMessagingApp
diff options
context:
space:
mode:
authorBenjamin Baxter <benbaxter@google.com>2017-04-26 09:10:00 -0700
committerBenjamin Baxter <benbaxter@google.com>2017-04-27 15:12:45 -0700
commit1533dd4161fc1d00795c0bfc77a68d16efd9556a (patch)
tree6fe75324901306fe8395c721f541c192ebec0e67 /wearable/wear/WearMessagingApp
parent702ed2be6088823bcb3ff791248991db9e5c773e (diff)
downloadandroid-1533dd4161fc1d00795c0bfc77a68d16efd9556a.tar.gz
Removed circle image view library and replaced with a function from Glide.
Bug: 34841755 Change-Id: I3c4bd8e84916c4713bc244fa83246d9c77cce907
Diffstat (limited to 'wearable/wear/WearMessagingApp')
-rw-r--r--wearable/wear/WearMessagingApp/Wearable/build.gradle1
-rw-r--r--wearable/wear/WearMessagingApp/Wearable/src/main/java/com/example/android/wearable/wear/messaging/chat/ChatAdapter.java32
-rw-r--r--wearable/wear/WearMessagingApp/Wearable/src/main/java/com/example/android/wearable/wear/messaging/chatlist/ChatListActivity.java2
-rw-r--r--wearable/wear/WearMessagingApp/Wearable/src/main/java/com/example/android/wearable/wear/messaging/chatlist/ChatListAdapter.java48
-rw-r--r--wearable/wear/WearMessagingApp/Wearable/src/main/java/com/example/android/wearable/wear/messaging/contacts/ContactsListAdapter.java30
-rw-r--r--wearable/wear/WearMessagingApp/Wearable/src/main/java/com/example/android/wearable/wear/messaging/model/Profile.java14
-rw-r--r--wearable/wear/WearMessagingApp/Wearable/src/main/java/com/example/android/wearable/wear/messaging/util/SchedulerHelper.java13
-rw-r--r--wearable/wear/WearMessagingApp/Wearable/src/main/res/layout/chat_list_item.xml4
-rw-r--r--wearable/wear/WearMessagingApp/Wearable/src/main/res/layout/chat_message.xml4
-rw-r--r--wearable/wear/WearMessagingApp/Wearable/src/main/res/layout/contacts_list_item.xml2
10 files changed, 107 insertions, 43 deletions
diff --git a/wearable/wear/WearMessagingApp/Wearable/build.gradle b/wearable/wear/WearMessagingApp/Wearable/build.gradle
index b01c1706..eb0615dd 100644
--- a/wearable/wear/WearMessagingApp/Wearable/build.gradle
+++ b/wearable/wear/WearMessagingApp/Wearable/build.gradle
@@ -17,7 +17,6 @@ dependencies {
compile 'com.fasterxml.jackson.core:jackson-databind:2.7.0'
compile 'com.github.bumptech.glide:glide:3.7.0'
- compile 'de.hdodenhof:circleimageview:1.3.0'
}
// The sample build uses multiple directories to
diff --git a/wearable/wear/WearMessagingApp/Wearable/src/main/java/com/example/android/wearable/wear/messaging/chat/ChatAdapter.java b/wearable/wear/WearMessagingApp/Wearable/src/main/java/com/example/android/wearable/wear/messaging/chat/ChatAdapter.java
index 6e2831b8..86140fc2 100644
--- a/wearable/wear/WearMessagingApp/Wearable/src/main/java/com/example/android/wearable/wear/messaging/chat/ChatAdapter.java
+++ b/wearable/wear/WearMessagingApp/Wearable/src/main/java/com/example/android/wearable/wear/messaging/chat/ChatAdapter.java
@@ -16,8 +16,11 @@
package com.example.android.wearable.wear.messaging.chat;
import android.content.Context;
+import android.graphics.Bitmap;
import android.support.percent.PercentRelativeLayout;
import android.support.v4.content.ContextCompat;
+import android.support.v4.graphics.drawable.RoundedBitmapDrawable;
+import android.support.v4.graphics.drawable.RoundedBitmapDrawableFactory;
import android.support.v7.util.SortedList;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.util.SortedListAdapterCallback;
@@ -25,13 +28,15 @@ import android.support.wearable.view.WearableRecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
+import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
+import com.bumptech.glide.request.animation.GlideAnimation;
+import com.bumptech.glide.request.target.SimpleTarget;
import com.example.android.wearable.wear.messaging.R;
import com.example.android.wearable.wear.messaging.model.Chat;
import com.example.android.wearable.wear.messaging.model.Message;
import com.example.android.wearable.wear.messaging.model.Profile;
-import de.hdodenhof.circleimageview.CircleImageView;
import java.util.Calendar;
import java.util.Collection;
import java.util.Locale;
@@ -89,7 +94,7 @@ class ChatAdapter extends WearableRecyclerView.Adapter<ChatAdapter.MessageViewHo
}
@Override
- public void onBindViewHolder(MessageViewHolder holder, int position) {
+ public void onBindViewHolder(final MessageViewHolder holder, int position) {
Message message = mMessages.get(position);
Profile sender = mChat.getParticipants().get(mMessages.get(position).getSenderId());
if (sender == null) {
@@ -97,9 +102,22 @@ class ChatAdapter extends WearableRecyclerView.Adapter<ChatAdapter.MessageViewHo
}
Glide.with(mContext)
- .load(sender.getProfileImageUri())
+ .load(sender.getProfileImageSource())
+ .asBitmap()
.placeholder(R.drawable.ic_face_white_24dp)
- .into(holder.profileImage);
+ .into(
+ new SimpleTarget<Bitmap>(100, 100) {
+ @Override
+ public void onResourceReady(
+ Bitmap resource,
+ GlideAnimation<? super Bitmap> glideAnimation) {
+ RoundedBitmapDrawable circularBitmapDrawable =
+ RoundedBitmapDrawableFactory.create(
+ mContext.getResources(), resource);
+ circularBitmapDrawable.setCircular(true);
+ holder.profileImage.setImageDrawable(circularBitmapDrawable);
+ }
+ });
// Convert to just the first name of the sender or short hand it if the sender is you.
String name;
@@ -143,7 +161,7 @@ class ChatAdapter extends WearableRecyclerView.Adapter<ChatAdapter.MessageViewHo
}
/**
- * Converts time since epoch to Month Date Time
+ * Converts time since epoch to Month Date Time.
*
* @param time since epoch
* @return String formatted in Month Date HH:MM
@@ -169,7 +187,7 @@ class ChatAdapter extends WearableRecyclerView.Adapter<ChatAdapter.MessageViewHo
final ViewGroup parentLayout;
final TextView textContent;
final TextView textName;
- final CircleImageView profileImage;
+ final ImageView profileImage;
final TextView textTime;
public MessageViewHolder(View itemView) {
@@ -179,7 +197,7 @@ class ChatAdapter extends WearableRecyclerView.Adapter<ChatAdapter.MessageViewHo
textContent = (TextView) itemView.findViewById(R.id.text_content);
textName = (TextView) itemView.findViewById(R.id.text_name);
textTime = (TextView) itemView.findViewById(R.id.text_time);
- profileImage = (CircleImageView) itemView.findViewById(R.id.profile_img);
+ profileImage = (ImageView) itemView.findViewById(R.id.profile_img);
}
}
}
diff --git a/wearable/wear/WearMessagingApp/Wearable/src/main/java/com/example/android/wearable/wear/messaging/chatlist/ChatListActivity.java b/wearable/wear/WearMessagingApp/Wearable/src/main/java/com/example/android/wearable/wear/messaging/chatlist/ChatListActivity.java
index 56727d8d..0cdf637b 100644
--- a/wearable/wear/WearMessagingApp/Wearable/src/main/java/com/example/android/wearable/wear/messaging/chatlist/ChatListActivity.java
+++ b/wearable/wear/WearMessagingApp/Wearable/src/main/java/com/example/android/wearable/wear/messaging/chatlist/ChatListActivity.java
@@ -39,7 +39,7 @@ import java.util.ArrayList;
*
* <p>Uses a simple mocked backend solution with shared preferences.
*
- * TODO: Processes database activities on the UI thread, move to async.
+ * <p>TODO: Processes database activities on the UI thread, move to async.
*/
public class ChatListActivity extends GoogleSignedInActivity {
diff --git a/wearable/wear/WearMessagingApp/Wearable/src/main/java/com/example/android/wearable/wear/messaging/chatlist/ChatListAdapter.java b/wearable/wear/WearMessagingApp/Wearable/src/main/java/com/example/android/wearable/wear/messaging/chatlist/ChatListAdapter.java
index 7fb8edb4..fce4a819 100644
--- a/wearable/wear/WearMessagingApp/Wearable/src/main/java/com/example/android/wearable/wear/messaging/chatlist/ChatListAdapter.java
+++ b/wearable/wear/WearMessagingApp/Wearable/src/main/java/com/example/android/wearable/wear/messaging/chatlist/ChatListAdapter.java
@@ -16,19 +16,24 @@
package com.example.android.wearable.wear.messaging.chatlist;
import android.content.Context;
+import android.graphics.Bitmap;
+import android.support.v4.graphics.drawable.RoundedBitmapDrawable;
+import android.support.v4.graphics.drawable.RoundedBitmapDrawableFactory;
import android.support.v7.util.SortedList;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
+import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
+import com.bumptech.glide.request.animation.GlideAnimation;
+import com.bumptech.glide.request.target.SimpleTarget;
import com.example.android.wearable.wear.messaging.R;
import com.example.android.wearable.wear.messaging.model.Chat;
import com.example.android.wearable.wear.messaging.model.Message;
import com.example.android.wearable.wear.messaging.model.Profile;
-import de.hdodenhof.circleimageview.CircleImageView;
import java.util.Collection;
/**
@@ -49,13 +54,13 @@ public class ChatListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
private static final int INDEX_OFFSET = 1;
- private final Context context;
- private final ChatAdapterListener listener;
+ private final Context mContext;
+ private final ChatAdapterListener mListener;
private final SortedList<Chat> mChats;
public ChatListAdapter(Context context, ChatAdapterListener listener) {
- this.context = context;
- this.listener = listener;
+ this.mContext = context;
+ this.mListener = listener;
mChats =
new SortedList<>(
Chat.class,
@@ -108,9 +113,8 @@ public class ChatListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
}
/**
- * A listener for a client to receive events about which actionable items occurred in the
- * adapter; i.e., either the user wants a brand new chat started or they are opening an existing
- * chat.
+ * Listens for actions that occur in the adapter; i.e., either the user wants a new chat started
+ * or they are opening an existing chat.
*/
public interface ChatAdapterListener {
void newChatSelected();
@@ -149,7 +153,7 @@ public class ChatListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
@Override
public void onClick(View v) {
Log.d(TAG, "New chat has been selected");
- listener.newChatSelected();
+ mListener.newChatSelected();
}
});
} else if (holder instanceof ChatItemViewHolder) {
@@ -162,7 +166,7 @@ public class ChatListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
new View.OnClickListener() {
@Override
public void onClick(View v) {
- listener.openChat(chat);
+ mListener.openChat(chat);
}
});
@@ -187,10 +191,24 @@ public class ChatListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
chatItemViewHolder.lastMessage.setText(messageString);
- Glide.with(context)
- .load(lastMessageSender.getProfileImageUri())
+ Glide.with(mContext)
+ .load(lastMessageSender.getProfileImageSource())
+ .asBitmap()
.placeholder(R.drawable.ic_face_white_24dp)
- .into(chatItemViewHolder.aliasImage);
+ .into(
+ new SimpleTarget<Bitmap>(100, 100) {
+ @Override
+ public void onResourceReady(
+ Bitmap resource,
+ GlideAnimation<? super Bitmap> glideAnimation) {
+ RoundedBitmapDrawable circularBitmapDrawable =
+ RoundedBitmapDrawableFactory.create(
+ mContext.getResources(), resource);
+ circularBitmapDrawable.setCircular(true);
+ chatItemViewHolder.aliasImage.setImageDrawable(
+ circularBitmapDrawable);
+ }
+ });
}
}
@@ -234,7 +252,7 @@ public class ChatListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
private ViewGroup row;
private final TextView alias;
- private final CircleImageView aliasImage;
+ private final ImageView aliasImage;
private final TextView lastMessage;
ChatItemViewHolder(View itemView) {
@@ -242,7 +260,7 @@ public class ChatListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
row = (ViewGroup) itemView.findViewById(R.id.layout_chat_list_item);
alias = (TextView) itemView.findViewById(R.id.text_alias);
- aliasImage = (CircleImageView) itemView.findViewById(R.id.profile);
+ aliasImage = (ImageView) itemView.findViewById(R.id.profile);
lastMessage = (TextView) itemView.findViewById(R.id.text_last_message);
}
}
diff --git a/wearable/wear/WearMessagingApp/Wearable/src/main/java/com/example/android/wearable/wear/messaging/contacts/ContactsListAdapter.java b/wearable/wear/WearMessagingApp/Wearable/src/main/java/com/example/android/wearable/wear/messaging/contacts/ContactsListAdapter.java
index 144b0811..b9a26752 100644
--- a/wearable/wear/WearMessagingApp/Wearable/src/main/java/com/example/android/wearable/wear/messaging/contacts/ContactsListAdapter.java
+++ b/wearable/wear/WearMessagingApp/Wearable/src/main/java/com/example/android/wearable/wear/messaging/contacts/ContactsListAdapter.java
@@ -16,7 +16,10 @@
package com.example.android.wearable.wear.messaging.contacts;
import android.content.Context;
+import android.graphics.Bitmap;
import android.support.annotation.NonNull;
+import android.support.v4.graphics.drawable.RoundedBitmapDrawable;
+import android.support.v4.graphics.drawable.RoundedBitmapDrawableFactory;
import android.support.v7.util.SortedList;
import android.support.v7.widget.RecyclerView;
import android.support.wearable.view.WearableRecyclerView;
@@ -25,11 +28,13 @@ import android.util.SparseBooleanArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
+import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
+import com.bumptech.glide.request.animation.GlideAnimation;
+import com.bumptech.glide.request.target.SimpleTarget;
import com.example.android.wearable.wear.messaging.R;
import com.example.android.wearable.wear.messaging.model.Profile;
-import de.hdodenhof.circleimageview.CircleImageView;
import java.util.ArrayList;
import java.util.List;
@@ -160,10 +165,23 @@ public class ContactsListAdapter extends WearableRecyclerView.Adapter<RecyclerVi
viewHolderContent.name.setText(contact.getName());
Glide.with(mContext)
- .load(contact.getProfileImageResource())
+ .load(contact.getProfileImageSource())
+ .asBitmap()
.placeholder(R.drawable.ic_face_white_24dp)
- .dontAnimate()
- .into(viewHolderContent.profileImage);
+ .into(
+ new SimpleTarget<Bitmap>(100, 100) {
+ @Override
+ public void onResourceReady(
+ Bitmap resource,
+ GlideAnimation<? super Bitmap> glideAnimation) {
+ RoundedBitmapDrawable circularBitmapDrawable =
+ RoundedBitmapDrawableFactory.create(
+ mContext.getResources(), resource);
+ circularBitmapDrawable.setCircular(true);
+ viewHolderContent.profileImage.setImageDrawable(
+ circularBitmapDrawable);
+ }
+ });
viewHolderContent.itemView.setOnClickListener(
new View.OnClickListener() {
@@ -245,13 +263,13 @@ public class ContactsListAdapter extends WearableRecyclerView.Adapter<RecyclerVi
/** Holds references each contact layout element. */
public static class ViewHolderContent extends RecyclerView.ViewHolder {
- protected final CircleImageView profileImage;
+ protected final ImageView profileImage;
protected final TextView name;
public ViewHolderContent(View itemView) {
super(itemView);
- profileImage = (CircleImageView) itemView.findViewById(R.id.profile_img);
+ profileImage = (ImageView) itemView.findViewById(R.id.profile_img);
name = (TextView) itemView.findViewById(R.id.text_contact_name);
}
}
diff --git a/wearable/wear/WearMessagingApp/Wearable/src/main/java/com/example/android/wearable/wear/messaging/model/Profile.java b/wearable/wear/WearMessagingApp/Wearable/src/main/java/com/example/android/wearable/wear/messaging/model/Profile.java
index 7a687496..f2796aee 100644
--- a/wearable/wear/WearMessagingApp/Wearable/src/main/java/com/example/android/wearable/wear/messaging/model/Profile.java
+++ b/wearable/wear/WearMessagingApp/Wearable/src/main/java/com/example/android/wearable/wear/messaging/model/Profile.java
@@ -18,6 +18,7 @@ package com.example.android.wearable.wear.messaging.model;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.NonNull;
+import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.android.gms.auth.api.signin.GoogleSignInAccount;
/** Represents a user profile. Parcelable to pass between activities. */
@@ -88,6 +89,17 @@ public class Profile implements Parcelable {
return profileImageUri;
}
+ @JsonIgnore
+ public Object getProfileImageSource() {
+ if (profileImageUri != null) {
+ return profileImageResource;
+ }
+ if (profileImageResource > 0) {
+ return profileImageResource;
+ }
+ return null;
+ }
+
public String getEmail() {
return email;
}
@@ -204,6 +216,7 @@ public class Profile implements Parcelable {
dest.writeString(this.email);
dest.writeString(this.name);
dest.writeString(this.profileImageUri);
+ dest.writeInt(this.profileImageResource);
dest.writeValue(this.lastUpdatedTime);
}
@@ -212,6 +225,7 @@ public class Profile implements Parcelable {
this.email = in.readString();
this.name = in.readString();
this.profileImageUri = in.readString();
+ this.profileImageResource = in.readInt();
this.lastUpdatedTime = (Long) in.readValue(Long.class.getClassLoader());
}
diff --git a/wearable/wear/WearMessagingApp/Wearable/src/main/java/com/example/android/wearable/wear/messaging/util/SchedulerHelper.java b/wearable/wear/WearMessagingApp/Wearable/src/main/java/com/example/android/wearable/wear/messaging/util/SchedulerHelper.java
index 208054a8..2a6e5b09 100644
--- a/wearable/wear/WearMessagingApp/Wearable/src/main/java/com/example/android/wearable/wear/messaging/util/SchedulerHelper.java
+++ b/wearable/wear/WearMessagingApp/Wearable/src/main/java/com/example/android/wearable/wear/messaging/util/SchedulerHelper.java
@@ -21,11 +21,12 @@ import android.content.Context;
import android.content.Intent;
import android.os.SystemClock;
import android.util.Log;
-
import com.example.android.wearable.wear.messaging.chat.MockIncomingMessageReceiver;
import com.example.android.wearable.wear.messaging.model.Chat;
import com.example.android.wearable.wear.messaging.model.Message;
+import java.util.concurrent.TimeUnit;
+
/**
* Manage an alarm manager to trigger a notification after 5 seconds.
*
@@ -41,14 +42,14 @@ public class SchedulerHelper {
PendingIntent alarmIntent = createPendingIntentToNotifyMessage(context, chat, message);
Log.d(TAG, "Setting up alarm to be triggered shortly.");
- alarmManger.set(AlarmManager.ELAPSED_REALTIME_WAKEUP,
- SystemClock.elapsedRealtime() + (5 * 1000), alarmIntent);
+ alarmManger.set(
+ AlarmManager.ELAPSED_REALTIME_WAKEUP,
+ SystemClock.elapsedRealtime() + TimeUnit.SECONDS.toMillis(5),
+ alarmIntent);
}
private static PendingIntent createPendingIntentToNotifyMessage(
- Context context,
- Chat chat,
- Message message) {
+ Context context, Chat chat, Message message) {
Intent intent = new Intent(context, MockIncomingMessageReceiver.class);
intent.setAction(Constants.ACTION_RECEIVE_MESSAGE);
intent.putExtra(Constants.EXTRA_CHAT, chat.getId());
diff --git a/wearable/wear/WearMessagingApp/Wearable/src/main/res/layout/chat_list_item.xml b/wearable/wear/WearMessagingApp/Wearable/src/main/res/layout/chat_list_item.xml
index 8135586a..dc7e7c8c 100644
--- a/wearable/wear/WearMessagingApp/Wearable/src/main/res/layout/chat_list_item.xml
+++ b/wearable/wear/WearMessagingApp/Wearable/src/main/res/layout/chat_list_item.xml
@@ -32,15 +32,13 @@
android:layout_centerVertical="true"
app:layout_marginStartPercent="@dimen/padding_15">
- <de.hdodenhof.circleimageview.CircleImageView
+ <ImageView
android:id="@+id/profile"
android:layout_width="@dimen/circle_image_diameter"
android:layout_height="@dimen/circle_image_diameter"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
tools:src="@drawable/ic_face_white_24dp"
- app:circle_border_color="@color/blue_15"
- app:circle_border_width="2dp"
app:layout_marginStartPercent="@dimen/padding_15"
android:layout_centerInParent="true" />
diff --git a/wearable/wear/WearMessagingApp/Wearable/src/main/res/layout/chat_message.xml b/wearable/wear/WearMessagingApp/Wearable/src/main/res/layout/chat_message.xml
index fcad1646..0dcfec24 100644
--- a/wearable/wear/WearMessagingApp/Wearable/src/main/res/layout/chat_message.xml
+++ b/wearable/wear/WearMessagingApp/Wearable/src/main/res/layout/chat_message.xml
@@ -34,14 +34,12 @@
app:layout_marginEndPercent="@dimen/padding_10"
app:layout_marginStartPercent="@dimen/padding_10">
- <de.hdodenhof.circleimageview.CircleImageView
+ <ImageView
android:id="@+id/profile_img"
android:layout_width="@dimen/chat_profile_diameter"
android:layout_height="@dimen/chat_profile_diameter"
android:contentDescription="@string/profile_image"
tools:src="@drawable/ic_face_white_24dp"
- app:circle_border_color="@color/blue_15"
- app:circle_border_width="2dp"
app:layout_marginStartPercent="@dimen/padding_15" />
<TextView
diff --git a/wearable/wear/WearMessagingApp/Wearable/src/main/res/layout/contacts_list_item.xml b/wearable/wear/WearMessagingApp/Wearable/src/main/res/layout/contacts_list_item.xml
index 48ffe364..ecc89c07 100644
--- a/wearable/wear/WearMessagingApp/Wearable/src/main/res/layout/contacts_list_item.xml
+++ b/wearable/wear/WearMessagingApp/Wearable/src/main/res/layout/contacts_list_item.xml
@@ -25,7 +25,7 @@
android:paddingBottom="@dimen/vertical_spacing"
android:paddingTop="@dimen/vertical_spacing">
- <de.hdodenhof.circleimageview.CircleImageView
+ <ImageView
android:id="@+id/profile_img"
android:layout_width="@dimen/circle_image_diameter"
android:layout_height="@dimen/circle_image_diameter"