blob: 6d7eedc7d2e23f368c2b7bf1e584a99122afdaca [file] [log] [blame]
Tor Norbyef8b83362015-03-10 19:15:27 -07001/*
2 * Copyright (C) 2015 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 */
16package android.annotation;
17
Tor Norbyef8b83362015-03-10 19:15:27 -070018import static java.lang.annotation.ElementType.CONSTRUCTOR;
19import static java.lang.annotation.ElementType.METHOD;
Matthew Gharritycb436162017-07-17 17:18:00 -070020import static java.lang.annotation.ElementType.PARAMETER;
Tor Norbyef8b83362015-03-10 19:15:27 -070021import static java.lang.annotation.ElementType.TYPE;
22import static java.lang.annotation.RetentionPolicy.SOURCE;
23
Jeff Sharkey910e0812017-04-21 16:29:27 -060024import android.os.Looper;
25
26import java.lang.annotation.Retention;
27import java.lang.annotation.Target;
28
Tor Norbyef8b83362015-03-10 19:15:27 -070029/**
Jeff Sharkey910e0812017-04-21 16:29:27 -060030 * Denotes that the annotated method or constructor should only be called on the
31 * UI thread. If the annotated element is a class, then all methods in the class
32 * should be called on the UI thread.
Tor Norbyef8b83362015-03-10 19:15:27 -070033 * <p>
34 * Example:
Jeff Sharkey910e0812017-04-21 16:29:27 -060035 *
36 * <pre>
37 * <code>
Tor Norbyef8b83362015-03-10 19:15:27 -070038 * &#64;UiThread
Neil Fuller71fbb812015-11-30 09:51:33 +000039 * public abstract void setText(@NonNull String text) { ... }
Jeff Sharkey910e0812017-04-21 16:29:27 -060040 * </code>
41 * </pre>
Tor Norbyef8b83362015-03-10 19:15:27 -070042 *
Jeff Sharkey910e0812017-04-21 16:29:27 -060043 * @memberDoc This method must be called on the thread that originally created
44 * this UI element. This is typically the
45 * {@linkplain Looper#getMainLooper() main thread} of your app.
46 * @hide
Tor Norbyef8b83362015-03-10 19:15:27 -070047 */
48@Retention(SOURCE)
Matthew Gharritycb436162017-07-17 17:18:00 -070049@Target({METHOD,CONSTRUCTOR,TYPE,PARAMETER})
Tor Norbyef8b83362015-03-10 19:15:27 -070050public @interface UiThread {
Jeff Sharkey910e0812017-04-21 16:29:27 -060051}