1 /* 2 * Copyright (C) 2017 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 17 package com.android.dialer.historyitemactions; 18 19 import android.content.Context; 20 import android.content.Intent; 21 import android.support.annotation.DrawableRes; 22 import android.support.annotation.Nullable; 23 import android.support.annotation.StringRes; 24 import android.telecom.PhoneAccountHandle; 25 import com.android.dialer.callintent.CallInitiationType.Type; 26 import com.android.dialer.callintent.CallIntentBuilder; 27 import com.android.dialer.precall.PreCall; 28 import com.android.dialer.util.DialerUtils; 29 30 /** 31 * {@link HistoryItemActionModule} useful for making easy to build modules based on starting an 32 * intent. 33 */ 34 public class IntentModule implements HistoryItemActionModule { 35 36 private final Context context; 37 private final Intent intent; 38 private final @StringRes int text; 39 private final @DrawableRes int image; 40 IntentModule(Context context, Intent intent, @StringRes int text, @DrawableRes int image)41 public IntentModule(Context context, Intent intent, @StringRes int text, @DrawableRes int image) { 42 this.context = context; 43 this.intent = intent; 44 this.text = text; 45 this.image = image; 46 } 47 48 @Override getStringId()49 public int getStringId() { 50 return text; 51 } 52 53 @Override getDrawableId()54 public int getDrawableId() { 55 return image; 56 } 57 58 @Override onClick()59 public boolean onClick() { 60 DialerUtils.startActivityWithErrorToast(context, intent); 61 return true; 62 } 63 newCallModule( Context context, String number, @Nullable PhoneAccountHandle phoneAccountHandle, Type initiationType)64 public static IntentModule newCallModule( 65 Context context, 66 String number, 67 @Nullable PhoneAccountHandle phoneAccountHandle, 68 Type initiationType) { 69 // TODO(zachh): Support post-dial digits; consider using DialerPhoneNumber. 70 return new IntentModule( 71 context, 72 PreCall.getIntent( 73 context, 74 new CallIntentBuilder(number, initiationType) 75 .setPhoneAccountHandle(phoneAccountHandle)), 76 R.string.voice_call, 77 R.drawable.quantum_ic_call_white_24); 78 } 79 newVideoCallModule( Context context, String number, @Nullable PhoneAccountHandle phoneAccountHandle, Type initiationType)80 public static IntentModule newVideoCallModule( 81 Context context, 82 String number, 83 @Nullable PhoneAccountHandle phoneAccountHandle, 84 Type initiationType) { 85 // TODO(zachh): Support post-dial digits; consider using DialerPhoneNumber. 86 return new IntentModule( 87 context, 88 PreCall.getIntent( 89 context, 90 new CallIntentBuilder(number, initiationType) 91 .setPhoneAccountHandle(phoneAccountHandle) 92 .setIsVideoCall(true)), 93 R.string.video_call, 94 R.drawable.quantum_ic_videocam_white_24); 95 } 96 } 97