/*
 * Copyright (C) 2017 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package com.google.android.mobly.snippet.bundled;

import android.content.Context;
import android.os.Handler;
import android.support.test.InstrumentationRegistry;
import android.widget.Toast;
import com.google.android.mobly.snippet.Snippet;
import com.google.android.mobly.snippet.rpc.Rpc;

/** Snippet class exposing Android APIs related to creating notification on screen. */
public class NotificationSnippet implements Snippet {

    private final Context mContext;
    /**
     * Since the APIs here deal with UI, most of them have to be called in a thread that has called
     * looper.
     */
    private final Handler mHandler;

    public NotificationSnippet() {
        mContext = InstrumentationRegistry.getContext();
        mHandler = new Handler(mContext.getMainLooper());
    }

    @Rpc(description = "Make a toast on screen.")
    public void makeToast(String message) {
        mHandler.post(() -> Toast.makeText(mContext, message, Toast.LENGTH_LONG).show());
    }

    @Override
    public void shutdown() {}
}

@@ -644,67 +644,8 @@
 d;%0A%0A
-import android.content.Context;%0Aimport android.os.Handler;%0A
 impo
@@ -819,16 +819,75 @@
 rpc.Rpc;
+%0Aimport com.google.android.mobly.snippet.rpc.RunOnUiThread;
 %0A%0A/** Sn
@@ -1030,364 +1030,22 @@
     
-private final Context mContext;%0A    /**%0A     * Since the APIs here deal with UI, most of them have to be called in a thread that has called%0A     * looper.%0A     */%0A    private final Handler mHandler;%0A%0A    public NotificationSnippet() %7B%0A        mContext = InstrumentationRegistry.getContext();%0A        mHandler = new Handler(mContext.getMainLooper());%0A    %7D%0A
+@RunOnUiThread
 %0A   
@@ -1147,51 +1147,59 @@
     
-mHandler.post(() -%3E Toast.makeText(m
+Toast.makeText(InstrumentationRegistry.get
 Context
+()
 , me
@@ -1230,17 +1230,16 @@
 ).show()
-)
 ;%0A    %7D%0A

Use annotation instead of executor for `makeToast`. (#93)