2323
2424import java .util .concurrent .atomic .AtomicInteger ;
2525
26+ /**
27+ * See <a href="http://getbootstrap.com/components/#badges>http://getbootstrap.com/components/#alerts</a>
28+ */
2629public class BootstrapAlert extends RelativeLayout {
2730
2831 private ImageView closeButton ;
@@ -78,12 +81,15 @@ private void initialise(AttributeSet attrs) {
7881 if (messageText == null ) {
7982 messageText = "" ;
8083 }
81- } finally {
84+ }
85+ finally {
8286 a .recycle ();
8387 }
8488
85- baselineFontSize = DimenUtils .pixelsFromSpResource (getContext (), R .dimen .bootstrap_button_default_font_size );
86- baselinePadding = DimenUtils .pixelsFromDpResource (getContext (), R .dimen .bootstrap_alert_paddings );
89+ baselineFontSize = DimenUtils .pixelsFromSpResource (getContext (),
90+ R .dimen .bootstrap_button_default_font_size );
91+ baselinePadding = DimenUtils .pixelsFromDpResource (getContext (),
92+ R .dimen .bootstrap_alert_paddings );
8793
8894 updateBootstrapState ();
8995 }
@@ -94,7 +100,8 @@ private void updateBootstrapState() {
94100 if (Build .VERSION .SDK_INT < Build .VERSION_CODES .JELLY_BEAN_MR1 ) {
95101 alertText .setId (generateViewUniqueId ());
96102 closeButton .setId (generateViewUniqueId ());
97- } else {
103+ }
104+ else {
98105 alertText .setId (View .generateViewId ());
99106 closeButton .setId (View .generateViewId ());
100107 }
@@ -106,48 +113,60 @@ private void updateBootstrapState() {
106113 fadeOutAnimation .setInterpolator (new AccelerateInterpolator ());
107114
108115 fadeInAnimation .setAnimationListener (new Animation .AnimationListener () {
109- @ Override public void onAnimationStart (Animation animation ) {setVisibility (VISIBLE );}
110- @ Override public void onAnimationEnd (Animation animation ) {}
111- @ Override public void onAnimationRepeat (Animation animation ) {}
116+ @ Override
117+ public void onAnimationStart (Animation animation ) {setVisibility (VISIBLE );}
118+
119+ @ Override
120+ public void onAnimationEnd (Animation animation ) {}
121+
122+ @ Override
123+ public void onAnimationRepeat (Animation animation ) {}
112124 });
113125
114126 fadeOutAnimation .setAnimationListener (new Animation .AnimationListener () {
115- @ Override public void onAnimationStart (Animation animation ) {}
116- @ Override public void onAnimationEnd (Animation animation ) {
127+ @ Override
128+ public void onAnimationStart (Animation animation ) {}
129+
130+ @ Override
131+ public void onAnimationEnd (Animation animation ) {
117132 setVisibility (GONE );
118- if (onDismissListener != null ) onDismissListener .onDismiss ();
133+ if (onDismissListener != null ) { onDismissListener .onDismiss (); }
119134 }
120- @ Override public void onAnimationRepeat (Animation animation ) {}
135+
136+ @ Override
137+ public void onAnimationRepeat (Animation animation ) {}
121138 });
122139
123- LayoutParams textParams = new LayoutParams (LayoutParams .MATCH_PARENT , LayoutParams .WRAP_CONTENT );
124- LayoutParams closeParams = new LayoutParams (LayoutParams .WRAP_CONTENT , LayoutParams .WRAP_CONTENT );
140+ LayoutParams textParams = new LayoutParams (LayoutParams .MATCH_PARENT ,
141+ LayoutParams .WRAP_CONTENT );
142+ LayoutParams closeParams = new LayoutParams (LayoutParams .WRAP_CONTENT ,
143+ LayoutParams .WRAP_CONTENT );
125144 textParams .addRule (RelativeLayout .LEFT_OF , closeButton .getId ());
126145 closeParams .addRule (RelativeLayout .ALIGN_PARENT_RIGHT , RelativeLayout .TRUE );
127146
128147 alertText .setLayoutParams (textParams );
129148 alertText .setTextSize (baselineFontSize );
130149 alertText .setGravity (Gravity .LEFT );
131- alertText .setTextColor (BootstrapDrawableFactory .bootstrapButtonText (
132- getContext (),
133- true ,
134- bootstrapBrand ));
135- alertText .setText (Html .fromHtml (String .format ("<b>%s</b>%s" , strongText , (strongText .length () > 0 ? " " + messageText : messageText ))));
150+ alertText .setTextColor (
151+ BootstrapDrawableFactory .bootstrapButtonText (getContext (), true , bootstrapBrand ));
152+ alertText .setText (Html .fromHtml (String .format ("<b>%s</b>%s" , strongText ,
153+ (strongText .length () > 0 ?
154+ " " + messageText :
155+ messageText ))));
136156
137157 closeButton .setLayoutParams (closeParams );
138- closeButton .setBackgroundDrawable (BootstrapDrawableFactory . bootstrapAlertCloseIcon (
139- getContext (),
140- (int ) baselineFontSize ,
141- (int ) baselineFontSize ,
142- DimenUtils .dpToPixels (6 )));
158+ closeButton .setBackgroundDrawable (
159+ BootstrapDrawableFactory . bootstrapAlertCloseIcon ( getContext (),
160+ (int ) baselineFontSize ,
161+ (int ) baselineFontSize ,
162+ DimenUtils .dpToPixels (6 )));
143163
144- Drawable bg = BootstrapDrawableFactory .bootstrapAlert (
145- getContext (),
146- bootstrapBrand );
164+ Drawable bg = BootstrapDrawableFactory .bootstrapAlert (getContext (), bootstrapBrand );
147165
148166 if (Build .VERSION .SDK_INT >= 16 ) {
149167 setBackground (bg );
150- } else {
168+ }
169+ else {
151170 setBackgroundDrawable (bg );
152171 }
153172 addView (alertText );
@@ -158,23 +177,22 @@ private void updateBootstrapState() {
158177 public void run () {
159178 Rect bounds = new Rect ();
160179 closeButton .getHitRect (bounds );
161- bounds .top -= DimenUtils .dpToPixels (6 );
180+ bounds .top -= DimenUtils .dpToPixels (6 );
162181 bounds .bottom += DimenUtils .dpToPixels (6 );
163- bounds .left -= DimenUtils .dpToPixels (6 );
164- bounds .right += DimenUtils .dpToPixels (6 );
182+ bounds .left -= DimenUtils .dpToPixels (6 );
183+ bounds .right += DimenUtils .dpToPixels (6 );
165184 TouchDelegate touchDelegate = new TouchDelegate (bounds , closeButton );
166185 if (View .class .isInstance (closeButton .getParent ())) {
167186 ((View ) closeButton .getParent ()).setTouchDelegate (touchDelegate );
168187 }
169188 }
170189 });
171- closeButton .setOnClickListener (
172- new OnClickListener () {
173- @ Override public void onClick (View v ) {
174- hide ();
175- }
176- }
177- );
190+ closeButton .setOnClickListener (new OnClickListener () {
191+ @ Override
192+ public void onClick (View v ) {
193+ hide ();
194+ }
195+ });
178196 }
179197
180198 int vert = (int ) (baselinePadding * 1.5 );
@@ -201,11 +219,13 @@ public void setOnDismissListener(OnDismissListener onDismissListener) {
201219 }
202220
203221 private int generateViewUniqueId () {
204- for (;; ) {
222+ for (; ; ) {
205223 final int result = nextGeneratedId .get ();
206224 // aapt-generated IDs have the high byte nonzero; clamp to the range under that.
207225 int newValue = result + 1 ;
208- if (newValue > 0x00FFFFFF ) newValue = 1 ; // Roll over to 1, not 0.
226+ if (newValue > 0x00FFFFFF ) {
227+ newValue = 1 ; // Roll over to 1, not 0.
228+ }
209229 if (nextGeneratedId .compareAndSet (result , newValue )) {
210230 return result ;
211231 }
0 commit comments