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 17 package com.android.incallui.answer.impl.answermethod; 18 19 import android.app.Activity; 20 import android.support.annotation.NonNull; 21 import android.support.annotation.Nullable; 22 import android.support.v4.app.Fragment; 23 import com.android.dialer.compat.ActivityCompat; 24 import com.android.incallui.util.AccessibilityUtil; 25 26 /** Creates the appropriate {@link AnswerMethod} for the circumstances. */ 27 public class AnswerMethodFactory { 28 29 @NonNull createAnswerMethod(@onNull Activity activity)30 public static AnswerMethod createAnswerMethod(@NonNull Activity activity) { 31 if (needTwoButton(activity)) { 32 return new TwoButtonMethod(); 33 } else { 34 return new FlingUpDownMethod(); 35 } 36 } 37 needsReplacement(@ullable Fragment answerMethod)38 public static boolean needsReplacement(@Nullable Fragment answerMethod) { 39 //noinspection SimplifiableIfStatement 40 if (answerMethod == null) { 41 return true; 42 } 43 // If we have already started showing TwoButtonMethod, we should keep showing TwoButtonMethod. 44 // Otherwise check if we need to change to TwoButtonMethod 45 return !(answerMethod instanceof TwoButtonMethod) && needTwoButton(answerMethod.getActivity()); 46 } 47 needTwoButton(@onNull Activity activity)48 private static boolean needTwoButton(@NonNull Activity activity) { 49 return AccessibilityUtil.isTouchExplorationEnabled(activity) 50 || ActivityCompat.isInMultiWindowMode(activity); 51 } 52 } 53