1 /* 2 * Copyright (C) 2011 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 androidx.media.filterpacks.text; 18 19 import android.view.View; 20 import android.widget.TextView; 21 22 import androidx.media.filterfw.FrameType; 23 import androidx.media.filterfw.FrameValue; 24 import androidx.media.filterfw.MffContext; 25 import androidx.media.filterfw.Signature; 26 import androidx.media.filterfw.ViewFilter; 27 28 public class TextViewTarget extends ViewFilter { 29 30 private TextView mTextView = null; 31 32 public TextViewTarget(MffContext context, String name) { 33 super(context, name); 34 } 35 36 @Override 37 public void onBindToView(View view) { 38 if (view instanceof TextView) { 39 mTextView = (TextView)view; 40 } else { 41 throw new IllegalArgumentException("View must be a TextView!"); 42 } 43 } 44 45 @Override 46 public Signature getSignature() { 47 return new Signature() 48 .addInputPort("text", Signature.PORT_REQUIRED, FrameType.single(String.class)) 49 .disallowOtherPorts(); 50 } 51 52 @Override 53 protected void onProcess() { 54 FrameValue textFrame = getConnectedInputPort("text").pullFrame().asFrameValue(); 55 final String text = (String)textFrame.getValue(); 56 if (mTextView != null) { 57 mTextView.post(new Runnable() { 58 @Override 59 public void run() { 60 mTextView.setText(text); 61 } 62 }); 63 } 64 } 65 } 66 67