summaryrefslogtreecommitdiff
path: root/src/com/android/dialer/calllog/CallTypeIconsView.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/dialer/calllog/CallTypeIconsView.java')
-rw-r--r--src/com/android/dialer/calllog/CallTypeIconsView.java93
1 files changed, 48 insertions, 45 deletions
diff --git a/src/com/android/dialer/calllog/CallTypeIconsView.java b/src/com/android/dialer/calllog/CallTypeIconsView.java
index 31d4f4b0e..14748433c 100644
--- a/src/com/android/dialer/calllog/CallTypeIconsView.java
+++ b/src/com/android/dialer/calllog/CallTypeIconsView.java
@@ -23,13 +23,13 @@ import android.graphics.Canvas;
import android.graphics.PorterDuff;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
-import android.provider.CallLog.Calls;
import android.util.AttributeSet;
import android.view.View;
import com.android.contacts.common.testing.NeededForTesting;
import com.android.contacts.common.util.BitmapUtil;
import com.android.dialer.R;
+import com.android.dialer.util.AppCompatConstants;
import com.google.common.collect.Lists;
import java.util.List;
@@ -42,17 +42,20 @@ import java.util.List;
public class CallTypeIconsView extends View {
private List<Integer> mCallTypes = Lists.newArrayListWithCapacity(3);
private boolean mShowVideo = false;
- private Resources mResources;
private int mWidth;
private int mHeight;
+ private static Resources sResources;
+
public CallTypeIconsView(Context context) {
this(context, null);
}
public CallTypeIconsView(Context context, AttributeSet attrs) {
super(context, attrs);
- mResources = new Resources(context);
+ if (sResources == null) {
+ sResources = new Resources(context);
+ }
}
public void clear() {
@@ -66,7 +69,7 @@ public class CallTypeIconsView extends View {
mCallTypes.add(callType);
final Drawable drawable = getCallTypeDrawable(callType);
- mWidth += drawable.getIntrinsicWidth() + mResources.iconMargin;
+ mWidth += drawable.getIntrinsicWidth() + sResources.iconMargin;
mHeight = Math.max(mHeight, drawable.getIntrinsicHeight());
invalidate();
}
@@ -79,8 +82,8 @@ public class CallTypeIconsView extends View {
public void setShowVideo(boolean showVideo) {
mShowVideo = showVideo;
if (showVideo) {
- mWidth += mResources.videoCall.getIntrinsicWidth();
- mHeight = Math.max(mHeight, mResources.videoCall.getIntrinsicHeight());
+ mWidth += sResources.videoCall.getIntrinsicWidth();
+ mHeight = Math.max(mHeight, sResources.videoCall.getIntrinsicHeight());
invalidate();
}
}
@@ -106,20 +109,22 @@ public class CallTypeIconsView extends View {
private Drawable getCallTypeDrawable(int callType) {
switch (callType) {
- case Calls.INCOMING_TYPE:
- return mResources.incoming;
- case Calls.OUTGOING_TYPE:
- return mResources.outgoing;
- case Calls.MISSED_TYPE:
- return mResources.missed;
- case Calls.VOICEMAIL_TYPE:
- return mResources.voicemail;
+ case AppCompatConstants.CALLS_INCOMING_TYPE:
+ return sResources.incoming;
+ case AppCompatConstants.CALLS_OUTGOING_TYPE:
+ return sResources.outgoing;
+ case AppCompatConstants.CALLS_MISSED_TYPE:
+ return sResources.missed;
+ case AppCompatConstants.CALLS_VOICEMAIL_TYPE:
+ return sResources.voicemail;
+ case AppCompatConstants.CALLS_BLOCKED_TYPE:
+ return sResources.blocked;
default:
// It is possible for users to end up with calls with unknown call types in their
// call history, possibly due to 3rd party call log implementations (e.g. to
// distinguish between rejected and missed calls). Instead of crashing, just
// assume that all unknown call types are missed calls.
- return mResources.missed;
+ return sResources.missed;
}
}
@@ -136,43 +141,36 @@ public class CallTypeIconsView extends View {
final int right = left + drawable.getIntrinsicWidth();
drawable.setBounds(left, 0, right, drawable.getIntrinsicHeight());
drawable.draw(canvas);
- left = right + mResources.iconMargin;
+ left = right + sResources.iconMargin;
}
// If showing the video call icon, draw it scaled appropriately.
if (mShowVideo) {
- final Drawable drawable = mResources.videoCall;
- final int right = left + mResources.videoCall.getIntrinsicWidth();
- drawable.setBounds(left, 0, right, mResources.videoCall.getIntrinsicHeight());
+ final Drawable drawable = sResources.videoCall;
+ final int right = left + sResources.videoCall.getIntrinsicWidth();
+ drawable.setBounds(left, 0, right, sResources.videoCall.getIntrinsicHeight());
drawable.draw(canvas);
}
}
private static class Resources {
- /**
- * Drawable representing an incoming answered call.
- */
+ // Drawable representing an incoming answered call.
public final Drawable incoming;
- /**
- * Drawable respresenting an outgoing call.
- */
+ // Drawable respresenting an outgoing call.
public final Drawable outgoing;
- /**
- * Drawable representing an incoming missed call.
- */
+ // Drawable representing an incoming missed call.
public final Drawable missed;
- /**
- * Drawable representing a voicemail.
- */
+ // Drawable representing a voicemail.
public final Drawable voicemail;
- /**
- * Drawable repesenting a video call.
- */
+ // Drawable representing a blocked call.
+ public final Drawable blocked;
+
+ // Drawable repesenting a video call.
public final Drawable videoCall;
/**
@@ -204,21 +202,26 @@ public class CallTypeIconsView extends View {
voicemail = r.getDrawable(R.drawable.ic_call_voicemail_holo_dark);
- // Get the video call icon, scaled to match the height of the call arrows.
- // We want the video call icon to be the same height as the call arrows, while keeping
- // the same width aspect ratio.
- Bitmap videoIcon = BitmapFactory.decodeResource(context.getResources(),
- R.drawable.ic_videocam_24dp);
- int scaledHeight = missed.getIntrinsicHeight();
- int scaledWidth = (int) ((float) videoIcon.getWidth() *
- ((float) missed.getIntrinsicHeight() /
- (float) videoIcon.getHeight()));
- Bitmap scaled = Bitmap.createScaledBitmap(videoIcon, scaledWidth, scaledHeight, false);
- videoCall = new BitmapDrawable(context.getResources(), scaled);
+ blocked = getScaledBitmap(context, R.drawable.ic_block_24dp);
+ blocked.setColorFilter(r.getColor(R.color.blocked_call), PorterDuff.Mode.MULTIPLY);
+
+ videoCall = getScaledBitmap(context, R.drawable.ic_videocam_24dp);
videoCall.setColorFilter(r.getColor(R.color.dialtacts_secondary_text_color),
PorterDuff.Mode.MULTIPLY);
iconMargin = r.getDimensionPixelSize(R.dimen.call_log_icon_margin);
}
+
+ // Gets the icon, scaled to the height of the call type icons. This helps display all the
+ // icons to be the same height, while preserving their width aspect ratio.
+ private Drawable getScaledBitmap(Context context, int resourceId) {
+ Bitmap icon = BitmapFactory.decodeResource(context.getResources(), resourceId);
+ int scaledHeight =
+ context.getResources().getDimensionPixelSize(R.dimen.call_type_icon_size);
+ int scaledWidth = (int) ((float) icon.getWidth()
+ * ((float) scaledHeight / (float) icon.getHeight()));
+ Bitmap scaledIcon = Bitmap.createScaledBitmap(icon, scaledWidth, scaledHeight, false);
+ return new BitmapDrawable(context.getResources(), scaledIcon);
+ }
}
}