1 /* 2 * Copyright (c) 2016, The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.car.stream.telecom; 17 18 import android.app.PendingIntent; 19 import android.content.Context; 20 import android.content.Intent; 21 import android.graphics.Bitmap; 22 import android.graphics.drawable.VectorDrawable; 23 import android.net.Uri; 24 import com.android.car.stream.BitmapUtils; 25 import com.android.car.stream.R; 26 import com.android.car.stream.StreamCard; 27 import com.android.car.stream.StreamConstants; 28 29 public class RecentCallConverter { 30 31 /** 32 * Creates a StreamCard of type {@link StreamConstants#CARD_TYPE_RECENT_CALL} 33 * @return 34 */ createStreamCard(Context context, String number, long timestamp)35 public StreamCard createStreamCard(Context context, String number, long timestamp) { 36 StreamCard.Builder builder = new StreamCard.Builder(StreamConstants.CARD_TYPE_RECENT_CALL, 37 Long.parseLong(number), timestamp); 38 String displayName = TelecomUtils.getDisplayName(context, number); 39 40 builder.setPrimaryText(displayName); 41 builder.setSecondaryText(context.getString(R.string.recent_call)); 42 builder.setDescription(context.getString(R.string.recent_call)); 43 Bitmap phoneIcon = BitmapUtils.getBitmap( 44 (VectorDrawable) context.getDrawable(R.drawable.ic_phone)); 45 46 builder.setPrimaryIcon(phoneIcon); 47 builder.setSecondaryIcon(TelecomUtils.createStreamCardSecondaryIcon(context, number)); 48 builder.setClickAction(createCallPendingIntent(context, number)); 49 return builder.build(); 50 } 51 createCallPendingIntent(Context context, String number)52 private PendingIntent createCallPendingIntent(Context context, String number) { 53 Intent callIntent = new Intent(Intent.ACTION_DIAL); 54 callIntent.setData(Uri.parse("tel: " + number)); 55 callIntent.addFlags(Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT); 56 return PendingIntent.getActivity(context, 0, callIntent, 57 PendingIntent.FLAG_UPDATE_CURRENT); 58 } 59 } 60