1 package com.xtremelabs.robolectric.shadows; 2 3 4 import com.xtremelabs.robolectric.Robolectric; 5 import com.xtremelabs.robolectric.internal.Implementation; 6 import com.xtremelabs.robolectric.internal.Implements; 7 import com.xtremelabs.robolectric.internal.RealObject; 8 9 import android.os.Bundle; 10 import android.os.Handler; 11 import android.os.Message; 12 13 @Implements(Message.class) 14 public class ShadowMessage { 15 private Bundle data; 16 private Handler target; 17 private long when; 18 19 @RealObject 20 private Message message; 21 22 @Implementation setData(Bundle data)23 public void setData(Bundle data) { 24 this.data = data; 25 } 26 27 @Implementation setTarget(Handler target)28 public void setTarget(Handler target) { 29 this.target = target; 30 } 31 32 @Implementation peekData()33 public Bundle peekData() { 34 return data; 35 } 36 37 @Implementation getData()38 public Bundle getData() { 39 if (data == null) { 40 data = new Bundle(); 41 } 42 return data; 43 } 44 45 @Implementation getTarget()46 public Handler getTarget() { 47 return target; 48 } 49 50 @Implementation copyFrom(Message m)51 public void copyFrom(Message m) { 52 message.arg1 = m.arg1; 53 message.arg2 = m.arg2; 54 message.obj = m.obj; 55 message.what = m.what; 56 message.setData(m.getData()); 57 } 58 59 @Implementation obtain()60 public static Message obtain() { 61 return new Message(); 62 } 63 64 @Implementation obtain(Handler h)65 public static Message obtain(Handler h) { 66 Message m = new Message(); 67 m.setTarget(h); 68 return m; 69 } 70 71 @Implementation obtain(Handler h, int what)72 public static Message obtain(Handler h, int what) { 73 Message m = obtain(h); 74 m.what = what; 75 return m; 76 } 77 78 @Implementation obtain(Handler h, int what, Object obj)79 public static Message obtain(Handler h, int what, Object obj) { 80 Message m = obtain(h, what); 81 m.obj = obj; 82 return m; 83 } 84 85 @Implementation obtain(Handler h, int what, int arg1, int arg2)86 public static Message obtain(Handler h, int what, int arg1, int arg2) { 87 Message m = obtain(h, what); 88 m.arg1 = arg1; 89 m.arg2 = arg2; 90 return m; 91 } 92 93 @Implementation obtain(Handler h, int what, int arg1, int arg2, Object obj)94 public static Message obtain(Handler h, int what, int arg1, int arg2, Object obj) { 95 Message m = obtain(h, what, arg1, arg2); 96 m.obj = obj; 97 return m; 98 } 99 100 @Implementation obtain(Message msg)101 public static Message obtain(Message msg) { 102 Message m = new Message(); 103 m.copyFrom(msg); 104 m.setTarget(msg.getTarget()); 105 return m; 106 } 107 108 @Implementation sendToTarget()109 public void sendToTarget() { 110 target.sendMessage(message); 111 } 112 113 @Implementation getWhen()114 public long getWhen() { 115 return when; 116 } 117 setWhen(long when)118 public void setWhen(long when) { 119 this.when = when; 120 } 121 } 122