1 /* 2 * Copyright (C) 2014 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 android.support.v4.app; 18 19 import android.app.RemoteInput; 20 import android.content.Intent; 21 import android.os.Bundle; 22 23 class RemoteInputCompatApi20 { toCompat(RemoteInput[] srcArray, RemoteInputCompatBase.RemoteInput.Factory factory)24 static RemoteInputCompatBase.RemoteInput[] toCompat(RemoteInput[] srcArray, 25 RemoteInputCompatBase.RemoteInput.Factory factory) { 26 if (srcArray == null) { 27 return null; 28 } 29 RemoteInputCompatBase.RemoteInput[] result = factory.newArray(srcArray.length); 30 for (int i = 0; i < srcArray.length; i++) { 31 RemoteInput src = srcArray[i]; 32 result[i] = factory.build(src.getResultKey(), src.getLabel(), src.getChoices(), 33 src.getAllowFreeFormInput(), src.getExtras()); 34 } 35 return result; 36 } 37 fromCompat(RemoteInputCompatBase.RemoteInput[] srcArray)38 static RemoteInput[] fromCompat(RemoteInputCompatBase.RemoteInput[] srcArray) { 39 if (srcArray == null) { 40 return null; 41 } 42 RemoteInput[] result = new RemoteInput[srcArray.length]; 43 for (int i = 0; i < srcArray.length; i++) { 44 RemoteInputCompatBase.RemoteInput src = srcArray[i]; 45 result[i] = new RemoteInput.Builder(src.getResultKey()) 46 .setLabel(src.getLabel()) 47 .setChoices(src.getChoices()) 48 .setAllowFreeFormInput(src.getAllowFreeFormInput()) 49 .addExtras(src.getExtras()) 50 .build(); 51 } 52 return result; 53 } 54 getResultsFromIntent(Intent intent)55 static Bundle getResultsFromIntent(Intent intent) { 56 return RemoteInput.getResultsFromIntent(intent); 57 } 58 addResultsToIntent(RemoteInputCompatBase.RemoteInput[] remoteInputs, Intent intent, Bundle results)59 static void addResultsToIntent(RemoteInputCompatBase.RemoteInput[] remoteInputs, 60 Intent intent, Bundle results) { 61 RemoteInput.addResultsToIntent(fromCompat(remoteInputs), intent, results); 62 } 63 } 64