Skip to content
This repository was archived by the owner on Dec 5, 2017. It is now read-only.

Commit 354b4e0

Browse files
committed
Cleanup
1 parent 55f6318 commit 354b4e0

6 files changed

Lines changed: 248 additions & 196 deletions

File tree

lib/src/main/java/com/nhaarman/supertooltips/ToolTip.java

Lines changed: 56 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -26,35 +26,35 @@ public enum AnimationType {
2626
NONE
2727
}
2828

29-
private CharSequence text;
30-
private int textResId;
31-
private int color;
32-
private int textColor;
33-
private View contentView;
34-
private AnimationType animationType;
35-
private boolean shadow;
36-
private Typeface typeface;
29+
private CharSequence mText;
30+
private int mTextResId;
31+
private int mColor;
32+
private int mTextColor;
33+
private View mContentView;
34+
private AnimationType mAnimationType;
35+
private boolean mShouldShowShadow;
36+
private Typeface mTypeface;
3737

3838
/**
3939
* Creates a new ToolTip without any values.
4040
*/
4141
public ToolTip() {
42-
text = null;
43-
typeface = null;
44-
textResId = 0;
45-
color = 0;
46-
contentView = null;
47-
animationType = AnimationType.FROM_MASTER_VIEW;
42+
mText = null;
43+
mTypeface = null;
44+
mTextResId = 0;
45+
mColor = 0;
46+
mContentView = null;
47+
mAnimationType = AnimationType.FROM_MASTER_VIEW;
4848
}
4949

5050
/**
5151
* Set the text to show. Has no effect when a content View is set using setContentView().
5252
*
5353
* @return this ToolTip to build upon.
5454
*/
55-
public ToolTip withText(CharSequence text) {
56-
this.text = text;
57-
this.textResId = 0;
55+
public ToolTip withText(final CharSequence text) {
56+
mText = text;
57+
mTextResId = 0;
5858
return this;
5959
}
6060

@@ -63,9 +63,9 @@ public ToolTip withText(CharSequence text) {
6363
*
6464
* @return this ToolTip to build upon.
6565
*/
66-
public ToolTip withText(int resId) {
67-
this.textResId = resId;
68-
this.text = null;
66+
public ToolTip withText(final int resId) {
67+
mTextResId = resId;
68+
mText = null;
6969
return this;
7070
}
7171

@@ -74,10 +74,10 @@ public ToolTip withText(int resId) {
7474
*
7575
* @return this ToolTip to build upon.
7676
*/
77-
public ToolTip withText(int resId, Typeface tf) {
78-
this.textResId = resId;
79-
this.text = null;
80-
this.withTypeface(tf);
77+
public ToolTip withText(final int resId, final Typeface tf) {
78+
mTextResId = resId;
79+
mText = null;
80+
withTypeface(tf);
8181
return this;
8282
}
8383

@@ -86,8 +86,8 @@ public ToolTip withText(int resId, Typeface tf) {
8686
*
8787
* @return this ToolTip to build upon.
8888
*/
89-
public ToolTip withColor(int color) {
90-
this.color = color;
89+
public ToolTip withColor(final int color) {
90+
mColor = color;
9191
return this;
9292
}
9393

@@ -96,8 +96,8 @@ public ToolTip withColor(int color) {
9696
*
9797
* @return this ToolTip to build upon.
9898
*/
99-
public ToolTip withTextColor(int color){
100-
this.textColor = color;
99+
public ToolTip withTextColor(final int color) {
100+
mTextColor = color;
101101
return this;
102102
}
103103

@@ -106,8 +106,8 @@ public ToolTip withTextColor(int color){
106106
*
107107
* @return this ToolTip to build upon.
108108
*/
109-
public ToolTip withContentView(View view) {
110-
this.contentView = view;
109+
public ToolTip withContentView(final View view) {
110+
mContentView = view;
111111
return this;
112112
}
113113

@@ -116,60 +116,70 @@ public ToolTip withContentView(View view) {
116116
*
117117
* @return this ToolTip to build upon.
118118
*/
119-
public ToolTip withAnimationType(AnimationType animationType) {
120-
this.animationType = animationType;
119+
public ToolTip withAnimationType(final AnimationType animationType) {
120+
mAnimationType = animationType;
121121
return this;
122122
}
123123

124124
/**
125-
* Set whether to show a shadow below the ToolTip.
125+
* Set to show a shadow below the ToolTip.
126126
*
127127
* @return this ToolTip to build upon.
128128
*/
129-
public ToolTip withShadow(boolean shadow) {
130-
this.shadow = shadow;
129+
public ToolTip withShadow() {
130+
mShouldShowShadow = true;
131+
return this;
132+
}
133+
134+
/**
135+
* Set to NOT show a shadow below the ToolTip.
136+
*
137+
* @return this ToolTip to build upon.
138+
*/
139+
public ToolTip withoutShadow() {
140+
mShouldShowShadow = false;
131141
return this;
132142
}
133143

134144
/**
135145
* @param typeface the typeface to set
136146
*/
137-
public void withTypeface(Typeface typeface) {
138-
this.typeface = typeface;
147+
public void withTypeface(final Typeface typeface) {
148+
mTypeface = typeface;
139149
}
140150

141151
public CharSequence getText() {
142-
return text;
152+
return mText;
143153
}
144154

145155
public int getTextResId() {
146-
return textResId;
156+
return mTextResId;
147157
}
148158

149159
public int getColor() {
150-
return color;
160+
return mColor;
151161
}
152162

153163
public int getTextColor() {
154-
return textColor;
164+
return mTextColor;
155165
}
156166

157167
public View getContentView() {
158-
return contentView;
168+
return mContentView;
159169
}
160170

161171
public AnimationType getAnimationType() {
162-
return animationType;
172+
return mAnimationType;
163173
}
164174

165-
public boolean getShadow() {
166-
return shadow;
175+
public boolean shouldShowShadow() {
176+
return mShouldShowShadow;
167177
}
168178

169179
/**
170180
* @return the typeface
171181
*/
172182
public Typeface getTypeface() {
173-
return typeface;
183+
return mTypeface;
174184
}
175185
}

lib/src/main/java/com/nhaarman/supertooltips/ToolTipRelativeLayout.java

Lines changed: 23 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,28 @@
2525
import android.view.ViewGroup;
2626
import android.widget.RelativeLayout;
2727

28+
import com.nhaarman.supertooltips.exception.NoOverflowMenuRuntimeException;
29+
import com.nhaarman.supertooltips.exception.NoTitleViewRuntimeException;
30+
import com.nhaarman.supertooltips.exception.ViewNotFoundRuntimeException;
31+
2832
public class ToolTipRelativeLayout extends RelativeLayout {
2933

30-
public ToolTipRelativeLayout(Context context) {
34+
public static final String ACTION_BAR_TITLE = "action_bar_title";
35+
public static final String ID = "id";
36+
public static final String ANDROID = "android";
37+
public static final String ACTION_BAR = "action_bar";
38+
public static final String ACTION_MENU_VIEW = "ActionMenuView";
39+
public static final String OVERFLOW_MENU_BUTTON = "OverflowMenuButton";
40+
41+
public ToolTipRelativeLayout(final Context context) {
3142
super(context);
3243
}
3344

34-
public ToolTipRelativeLayout(Context context, AttributeSet attrs) {
45+
public ToolTipRelativeLayout(final Context context, final AttributeSet attrs) {
3546
super(context, attrs);
3647
}
3748

38-
public ToolTipRelativeLayout(Context context, AttributeSet attrs, int defStyle) {
49+
public ToolTipRelativeLayout(final Context context, final AttributeSet attrs, final int defStyle) {
3950
super(context, attrs, defStyle);
4051
}
4152

@@ -123,7 +134,7 @@ public ToolTipView showToolTipForActionBarHome(final Activity activity, final To
123134
*/
124135
@TargetApi(11)
125136
public ToolTipView showToolTipForActionBarTitle(final Activity activity, final ToolTip toolTip) {
126-
final int titleResId = Resources.getSystem().getIdentifier("action_bar_title", "id", "android");
137+
final int titleResId = Resources.getSystem().getIdentifier(ACTION_BAR_TITLE, ID, ANDROID);
127138
if (titleResId == 0) {
128139
throw new NoTitleViewRuntimeException();
129140
}
@@ -153,15 +164,16 @@ public ToolTipView showToolTipForActionBarOverflowMenu(final Activity activity,
153164
}
154165

155166
@TargetApi(11)
156-
private View findActionBarOverflowMenuView(final Activity activity) {
167+
private static View findActionBarOverflowMenuView(final Activity activity) {
157168
final ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
158169

159-
final int actionBarViewResId = Resources.getSystem().getIdentifier("action_bar", "id", "android");
170+
final int actionBarViewResId = Resources.getSystem().getIdentifier(ACTION_BAR, ID, ANDROID);
160171
final ViewGroup actionBarView = (ViewGroup) decorView.findViewById(actionBarViewResId);
161172

162173
ViewGroup actionMenuView = null;
163-
for (int i = 0; i < actionBarView.getChildCount(); ++i) {
164-
if (actionBarView.getChildAt(i).getClass().getSimpleName().equals("ActionMenuView")) {
174+
int actionBarViewChildCount = actionBarView.getChildCount();
175+
for (int i = 0; i < actionBarViewChildCount; ++i) {
176+
if (actionBarView.getChildAt(i).getClass().getSimpleName().equals(ACTION_MENU_VIEW)) {
165177
actionMenuView = (ViewGroup) actionBarView.getChildAt(i);
166178
}
167179
}
@@ -170,9 +182,10 @@ private View findActionBarOverflowMenuView(final Activity activity) {
170182
throw new NoOverflowMenuRuntimeException();
171183
}
172184

185+
int actionMenuChildCount = actionMenuView.getChildCount();
173186
View overflowMenuButton = null;
174-
for (int i = 0; i < actionMenuView.getChildCount(); ++i) {
175-
if (actionMenuView.getChildAt(i).getClass().getSimpleName().equals("OverflowMenuButton")) {
187+
for (int i = 0; i < actionMenuChildCount; ++i) {
188+
if (actionMenuView.getChildAt(i).getClass().getSimpleName().equals(OVERFLOW_MENU_BUTTON)) {
176189
overflowMenuButton = actionMenuView.getChildAt(i);
177190
}
178191
}
@@ -183,38 +196,4 @@ private View findActionBarOverflowMenuView(final Activity activity) {
183196

184197
return overflowMenuButton;
185198
}
186-
187-
/**
188-
* A {@link RuntimeException} that is thrown if there is no {@link View}
189-
* found with given resource id. You can choose to ignore this by catching
190-
* the ViewNotFoundRuntimeException.
191-
*/
192-
public class ViewNotFoundRuntimeException extends RuntimeException {
193-
public ViewNotFoundRuntimeException() {
194-
super("View not found for this resource id. Are you sure it exists?");
195-
}
196-
}
197-
198-
/**
199-
* A {@link RuntimeException} that is thrown if the title view in the
200-
* {@link ActionBar} is not found. You can choose to ignore this by catching
201-
* the NoTitleViewRuntimeException.
202-
*/
203-
public class NoTitleViewRuntimeException extends RuntimeException {
204-
public NoTitleViewRuntimeException() {
205-
super("No title View found. Are you sure it exists?");
206-
}
207-
}
208-
209-
/**
210-
* A {@link RuntimeException} that is thrown if the overflow menu is not
211-
* found. This happens when there simply is no overflow menu button, or the
212-
* menu isn't initialised yet. You can choose to ignore this by catching the
213-
* NoOverflowMenuRuntimeException.
214-
*/
215-
public class NoOverflowMenuRuntimeException extends RuntimeException {
216-
public NoOverflowMenuRuntimeException() {
217-
super("No overflow menu found. Are you sure the overflow menu button is visible? Check the docs for showToolTipForActionBarOverflowMenu(Activity, ToolTip) again!");
218-
}
219-
}
220199
}

0 commit comments

Comments
 (0)