Skip to content

Commit 6de0eff

Browse files
committed
add annotation class
1 parent d8fb74e commit 6de0eff

File tree

4 files changed

+108
-12
lines changed

4 files changed

+108
-12
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package cn.leancloud.annotation;
2+
3+
import java.lang.annotation.Retention;
4+
import java.lang.annotation.Target;
5+
6+
import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
7+
import static java.lang.annotation.ElementType.CONSTRUCTOR;
8+
import static java.lang.annotation.ElementType.FIELD;
9+
import static java.lang.annotation.ElementType.METHOD;
10+
import static java.lang.annotation.ElementType.PACKAGE;
11+
import static java.lang.annotation.ElementType.TYPE;
12+
import static java.lang.annotation.RetentionPolicy.CLASS;
13+
14+
/**
15+
* Denotes that the annotated element should only be accessed from within a
16+
* specific scope (as defined by {@link Scope}).
17+
* <p>
18+
* Example of restricting usage within a library (based on gradle group ID):
19+
* <pre><code>
20+
* &#64;RestrictTo(GROUP_ID)
21+
* public void resetPaddingToInitialValues() { ...
22+
* </code></pre>
23+
* Example of restricting usage to tests:
24+
* <pre><code>
25+
* &#64;RestrictScope(TESTS)
26+
* public abstract int getUserId();
27+
* </code></pre>
28+
* Example of restricting usage to subclasses:
29+
* <pre><code>
30+
* &#64;RestrictScope(SUBCLASSES)
31+
* public void onDrawForeground(Canvas canvas) { ...
32+
* </code></pre>
33+
*/
34+
@Retention(CLASS)
35+
@Target({ANNOTATION_TYPE,TYPE,METHOD,CONSTRUCTOR,FIELD,PACKAGE})
36+
public @interface RestrictTo {
37+
/**
38+
* The scope to which usage should be restricted.
39+
*/
40+
Scope[] value();
41+
enum Scope {
42+
/**
43+
* Restrict usage to code within the same group ID (based on gradle
44+
* group ID).
45+
*/
46+
GROUP_ID,
47+
/**
48+
* Restrict usage to tests.
49+
*/
50+
TESTS,
51+
/**
52+
* Restrict usage to subclasses of the enclosing class.
53+
* <p>
54+
* <strong>Note:</strong> This scope should not be used to annotate
55+
* packages.
56+
*/
57+
SUBCLASSES,
58+
}
59+
}

android-sdk/realtime-android/src/main/java/cn/leancloud/utils/BuildCompat.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package cn.leancloud.utils;
22

33
import android.os.Build.VERSION;
4-
import android.text.TextUtils;
54

65
/**
76
* BuildCompat contains additional platform version checking methods for

android-sdk/realtime-android/src/main/java/cn/leancloud/utils/NotificationCompat.java

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
import java.util.Collections;
2020
import java.util.List;
2121

22+
import cn.leancloud.annotation.RestrictTo;
23+
24+
import static cn.leancloud.annotation.RestrictTo.Scope.GROUP_ID;
25+
2226
/**
2327
* Helper for accessing features in {@link android.app.Notification}
2428
* introduced after API level 4 in a backwards compatible fashion.
@@ -425,6 +429,7 @@ NotificationCompatBase.UnreadConversation getUnreadConversationFromBundle(
425429
*
426430
* @hide
427431
*/
432+
@RestrictTo(GROUP_ID)
428433
protected static class BuilderExtender {
429434
public Notification build(Builder b, NotificationBuilderWithBuilderAccessor builder) {
430435
Notification n = builder.build();
@@ -846,29 +851,39 @@ public static class Builder {
846851
// All these variables are declared public/hidden so they can be accessed by a builder
847852
// extender.
848853
/** @hide */
854+
@RestrictTo(GROUP_ID)
849855
public Context mContext;
850856
/** @hide */
857+
@RestrictTo(GROUP_ID)
851858
public CharSequence mContentTitle;
852859
/** @hide */
860+
@RestrictTo(GROUP_ID)
853861
public CharSequence mContentText;
854862
PendingIntent mContentIntent;
855863
PendingIntent mFullScreenIntent;
856864
RemoteViews mTickerView;
857865
/** @hide */
866+
@RestrictTo(GROUP_ID)
858867
public Bitmap mLargeIcon;
859868
/** @hide */
869+
@RestrictTo(GROUP_ID)
860870
public CharSequence mContentInfo;
861871
/** @hide */
872+
@RestrictTo(GROUP_ID)
862873
public int mNumber;
863874
int mPriority;
864875
boolean mShowWhen = true;
865876
/** @hide */
877+
@RestrictTo(GROUP_ID)
866878
public boolean mUseChronometer;
867879
/** @hide */
880+
@RestrictTo(GROUP_ID)
868881
public Style mStyle;
869882
/** @hide */
883+
@RestrictTo(GROUP_ID)
870884
public CharSequence mSubText;
871885
/** @hide */
886+
@RestrictTo(GROUP_ID)
872887
public CharSequence[] mRemoteInputHistory;
873888
int mProgressMax;
874889
int mProgress;
@@ -877,6 +892,7 @@ public static class Builder {
877892
boolean mGroupSummary;
878893
String mSortKey;
879894
/** @hide */
895+
@RestrictTo(GROUP_ID)
880896
public ArrayList<Action> mActions = new ArrayList<Action>();
881897
boolean mLocalOnly = false;
882898
String mCategory;
@@ -888,6 +904,7 @@ public static class Builder {
888904
RemoteViews mBigContentView;
889905
RemoteViews mHeadsUpContentView;
890906
/** @hide */
907+
@RestrictTo(GROUP_ID)
891908
public Notification mNotification = new Notification();
892909
public ArrayList<String> mPeople;
893910
/**
@@ -1537,6 +1554,7 @@ public Notification build() {
15371554
/**
15381555
* @hide
15391556
*/
1557+
@RestrictTo(GROUP_ID)
15401558
protected BuilderExtender getExtender() {
15411559
return new BuilderExtender();
15421560
}
@@ -1550,20 +1568,21 @@ protected static CharSequence limitCharSequenceLength(CharSequence cs) {
15501568
/**
15511569
* @hide
15521570
*/
1571+
@RestrictTo(GROUP_ID)
15531572
public RemoteViews getContentView() {
15541573
return mContentView;
15551574
}
15561575
/**
15571576
* @hide
15581577
*/
1559-
1578+
@RestrictTo(GROUP_ID)
15601579
public RemoteViews getBigContentView() {
15611580
return mBigContentView;
15621581
}
15631582
/**
15641583
* @hide
15651584
*/
1566-
1585+
@RestrictTo(GROUP_ID)
15671586
public RemoteViews getHeadsUpContentView() {
15681587
return mHeadsUpContentView;
15691588
}
@@ -1572,7 +1591,7 @@ public RemoteViews getHeadsUpContentView() {
15721591
*
15731592
* @hide
15741593
*/
1575-
1594+
@RestrictTo(GROUP_ID)
15761595
public long getWhenIfShowing() {
15771596
return mShowWhen ? mNotification.when : 0;
15781597
}
@@ -1581,7 +1600,7 @@ public long getWhenIfShowing() {
15811600
*
15821601
* @hide
15831602
*/
1584-
1603+
@RestrictTo(GROUP_ID)
15851604
public int getPriority() {
15861605
return mPriority;
15871606
}
@@ -1590,7 +1609,7 @@ public int getPriority() {
15901609
*
15911610
* @hide
15921611
*/
1593-
1612+
@RestrictTo(GROUP_ID)
15941613
public int getColor() {
15951614
return mColor;
15961615
}
@@ -1599,7 +1618,7 @@ public int getColor() {
15991618
*
16001619
* @hide
16011620
*/
1602-
1621+
@RestrictTo(GROUP_ID)
16031622
protected CharSequence resolveText() {
16041623
return mContentText;
16051624
}
@@ -1608,7 +1627,7 @@ protected CharSequence resolveText() {
16081627
*
16091628
* @hide
16101629
*/
1611-
1630+
@RestrictTo(GROUP_ID)
16121631
protected CharSequence resolveTitle() {
16131632
return mContentTitle;
16141633
}
@@ -1643,14 +1662,14 @@ public Notification build() {
16431662
/**
16441663
* @hide
16451664
*/
1646-
1665+
@RestrictTo(GROUP_ID)
16471666
// TODO: implement for all styles
16481667
public void addCompatExtras(Bundle extras) {
16491668
}
16501669
/**
16511670
* @hide
16521671
*/
1653-
1672+
@RestrictTo(GROUP_ID)
16541673
// TODO: implement for all styles
16551674
protected void restoreFromCompatExtras(Bundle extras) {
16561675
}
@@ -1914,7 +1933,7 @@ public void addCompatExtras(Bundle extras) {
19141933
/**
19151934
* @hide
19161935
*/
1917-
1936+
@RestrictTo(GROUP_ID)
19181937
@Override
19191938
protected void restoreFromCompatExtras(Bundle extras) {
19201939
mMessages.clear();
@@ -2532,7 +2551,7 @@ public boolean getHintDisplayActionInline() {
25322551
}
25332552
}
25342553
/** @hide */
2535-
2554+
@RestrictTo(GROUP_ID)
25362555
public static final Factory FACTORY = new Factory() {
25372556
@Override
25382557
public NotificationCompatBase.Action build(int icon, CharSequence title,

android-sdk/realtime-android/src/main/java/cn/leancloud/utils/NotificationCompatBase.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,21 @@
33
import android.app.Notification;
44
import android.app.PendingIntent;
55
import android.content.Context;
6+
import android.os.Build;
67
import android.os.Bundle;
8+
9+
import java.lang.reflect.Method;
10+
11+
import cn.leancloud.annotation.RestrictTo;
12+
13+
import static cn.leancloud.annotation.RestrictTo.Scope.GROUP_ID;
14+
715
/**
816
* @hide
917
*
1018
* copy from android-25 / android / support / v4 / app /
1119
*/
20+
@RestrictTo(GROUP_ID)
1221
public class NotificationCompatBase {
1322
public static abstract class Action {
1423
public abstract int getIcon();
@@ -43,6 +52,16 @@ public static Notification add(Notification notification, Context context,
4352
CharSequence contentTitle, CharSequence contentText, PendingIntent contentIntent,
4453
PendingIntent fullScreenIntent) {
4554
// notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
55+
try {
56+
Method setLatestEventInfoMethod
57+
= Notification.class.getMethod("setLatestEventInfo", CharSequence.class, CharSequence.class, PendingIntent.class);
58+
if (null != setLatestEventInfoMethod) {
59+
setLatestEventInfoMethod.invoke(notification, contentTitle, contentText, contentIntent);
60+
}
61+
} catch (Exception ex) {
62+
;
63+
}
64+
4665
notification.fullScreenIntent = fullScreenIntent;
4766
return notification;
4867
}

0 commit comments

Comments
 (0)