Home | History | Annotate | Download | only in tests
      1 /*
      2  * Copyright (C) 2012 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.phone.tests;
     18 
     19 import android.app.IntentService;
     20 import android.content.Intent;
     21 import android.net.Uri;
     22 import android.os.Handler;
     23 import android.os.Message;
     24 import android.util.Log;
     25 import android.widget.Toast;
     26 
     27 /**
     28  * Service which receives instant text responses from in-call UI and shows the message using
     29  * {@link Toast}.
     30  */
     31 public class SendInstantTextTestService extends IntentService {
     32     private static final String TAG = SendInstantTextTestService.class.getSimpleName();
     33 
     34     private final Handler mHandler = new Handler() {
     35         @Override
     36         public void handleMessage(Message msg) {
     37             showMessageWithToast((Intent) msg.obj);
     38         }
     39     };
     40 
     41     public SendInstantTextTestService() {
     42         super("send_instant_text_test_service");
     43     }
     44 
     45     @Override
     46     protected void onHandleIntent(Intent intent) {
     47         String action = intent.getAction();
     48         Uri uri = intent.getData();
     49         String message = intent.getStringExtra(Intent.EXTRA_TEXT);
     50         Log.i(TAG, "Received instant response message. action=" + action
     51                 + ", uri=" + uri + ", message=\"" + message + "\"");
     52         // Phone app uses Toast to show confirmation, which overlaps with this message.
     53         // Let's delay showing this one for 5sec.
     54         mHandler.sendMessageDelayed(Message.obtain(mHandler, 0, intent), 5 * 1000);
     55     }
     56 
     57     private void showMessageWithToast(Intent intent) {
     58         Uri uri = intent.getData();
     59         String message = intent.getStringExtra(Intent.EXTRA_TEXT);
     60         String toastText = getString(R.string.instant_text_back_content, message, uri.toString());
     61         Toast.makeText(this, toastText, Toast.LENGTH_LONG).show();
     62     }
     63 }