Skip to content

Commit 26c6ea6

Browse files
committed
1.0.7 - Long text will now marque
1 parent b0e1e51 commit 26c6ea6

5 files changed

Lines changed: 38 additions & 5 deletions

File tree

app/app.iml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
<orderEntry type="jdk" jdkName="Android API 22 Platform" jdkType="Android SDK" />
8989
<orderEntry type="sourceFolder" forTests="false" />
9090
<orderEntry type="library" exported="" name="library-2.4.0" level="project" />
91-
<orderEntry type="library" exported="" name="load-toast-1.0.6" level="project" />
91+
<orderEntry type="module" module-name="loadtoast" exported="" />
9292
</component>
9393
</module>
9494

app/src/main/java/net/steamcrafted/loadtoastlib/MainActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public void onCreate(Bundle savedInstanceState) {
1919
super.onCreate(savedInstanceState);
2020
setContentView(R.layout.activity_main);
2121

22-
final String text = "Sending reply...";
22+
final String text = "abcdefghijklmnopq";
2323
final LoadToast lt = new LoadToast(this).setText(text).setTranslationY(100).show();
2424
final ViewGroup root = (ViewGroup) findViewById(android.R.id.content);
2525
View v = new View(this);

loadtoast/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apply plugin: 'com.android.library'
33
ext {
44
PUBLISH_GROUP_ID = 'net.steamcrafted'
55
PUBLISH_ARTIFACT_ID = 'load-toast'
6-
PUBLISH_VERSION = '1.0.6'
6+
PUBLISH_VERSION = '1.0.7'
77
}
88

99
android {

loadtoast/src/main/java/net/steamcrafted/loadtoast/LoadToast.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ public LoadToast show(){
7979
return this;
8080
}
8181
mView.show();
82+
ViewHelper.setTranslationX(mView, (mParentView.getWidth() - mView.getWidth()) / 2);
8283
ViewHelper.setAlpha(mView, 0f);
8384
ViewHelper.setTranslationY(mView, -mView.getHeight() + mTranslationY);
8485
//mView.setVisibility(View.VISIBLE);

loadtoast/src/main/java/net/steamcrafted/loadtoast/LoadToastView.java

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import android.content.Context;
44
import android.content.res.TypedArray;
5+
import android.graphics.Bitmap;
56
import android.graphics.Canvas;
67
import android.graphics.Color;
78
import android.graphics.Paint;
@@ -43,6 +44,9 @@ public class LoadToastView extends View {
4344
private int IMAGE_WIDTH = 40;
4445
private int TOAST_HEIGHT = 48;
4546
private float WIDTH_SCALE = 0f;
47+
private int MARQUE_STEP = 1;
48+
49+
private long prevUpdate = 0;
4650

4751
private Drawable completeicon;
4852
private Drawable failedicon;
@@ -51,6 +55,7 @@ public class LoadToastView extends View {
5155
private ValueAnimator cmp;
5256

5357
private boolean success = true;
58+
private boolean outOfBounds = false;
5459

5560
private Path toastPath = new Path();
5661
private AccelerateDecelerateInterpolator easeinterpol = new AccelerateDecelerateInterpolator();
@@ -81,6 +86,7 @@ public LoadToastView(Context context) {
8186
BASE_TEXT_SIZE = dpToPx(BASE_TEXT_SIZE);
8287
IMAGE_WIDTH = dpToPx(IMAGE_WIDTH);
8388
TOAST_HEIGHT = dpToPx(TOAST_HEIGHT);
89+
MARQUE_STEP = dpToPx(MARQUE_STEP);
8490

8591
int padding = (TOAST_HEIGHT - IMAGE_WIDTH)/2;
8692
iconBounds = new Rect(TOAST_HEIGHT + MAX_TEXT_WIDTH - padding, padding, TOAST_HEIGHT + MAX_TEXT_WIDTH - padding + IMAGE_WIDTH, IMAGE_WIDTH + padding);
@@ -175,6 +181,9 @@ public void setText(String text) {
175181
}
176182

177183
private void calculateBounds() {
184+
outOfBounds = false;
185+
prevUpdate = 0;
186+
178187
textPaint.setTextSize(BASE_TEXT_SIZE);
179188
textPaint.getTextBounds(mText, 0, mText.length(), mTextBounds);
180189
if(mTextBounds.width() > MAX_TEXT_WIDTH){
@@ -186,11 +195,14 @@ private void calculateBounds() {
186195
textPaint.getTextBounds(mText, 0, mText.length(), mTextBounds);
187196
}
188197
if(mTextBounds.width() > MAX_TEXT_WIDTH){
198+
outOfBounds = true;
199+
/**
189200
float keep = (float)MAX_TEXT_WIDTH / (float)mTextBounds.width();
190201
int charcount = (int)(mText.length() * keep);
191202
//Log.d("calc", "keep " + charcount + " per " + keep + " len " + mText.length());
192203
mText = mText.substring(0, charcount);
193204
textPaint.getTextBounds(mText, 0, mText.length(), mTextBounds);
205+
**/
194206
}
195207
}
196208
}
@@ -232,8 +244,6 @@ protected void onDraw(Canvas c){
232244
c.drawCircle(spinnerRect.centerX(), spinnerRect.centerY(), iconBounds.height() / 1.9f, backPaint);
233245
//loadicon.draw(c);
234246
c.drawPath(toastPath, backPaint);
235-
int yPos = (int) ((th / 2) - ((textPaint.descent() + textPaint.ascent()) / 2)) ;
236-
c.drawText(mText, 0, mText.length(), th / 2 + (MAX_TEXT_WIDTH - mTextBounds.width()) / 2, yPos, textPaint);
237247

238248
float prog = va.getAnimatedFraction() * 6.0f;
239249
float progrot = prog % 2.0f;
@@ -262,6 +272,28 @@ protected void onDraw(Canvas c){
262272
c.rotate(90*(1f-circleProg), leftMargin + TOAST_HEIGHT/2, TOAST_HEIGHT/2);
263273
icon.draw(c);
264274
c.restore();
275+
276+
prevUpdate = 0;
277+
return;
278+
}
279+
280+
int yPos = (int) ((th / 2) - ((textPaint.descent() + textPaint.ascent()) / 2)) ;
281+
282+
if(outOfBounds){
283+
float shift = 0;
284+
if(prevUpdate == 0){
285+
prevUpdate = System.currentTimeMillis();
286+
}else{
287+
shift = ((float)(System.currentTimeMillis() - prevUpdate) / 16f) * MARQUE_STEP;
288+
289+
if(shift - MAX_TEXT_WIDTH > mTextBounds.width()){
290+
prevUpdate = 0;
291+
}
292+
}
293+
c.clipRect(th / 2, 0, th/2 + MAX_TEXT_WIDTH, TOAST_HEIGHT);
294+
c.drawText(mText, th / 2 - shift + MAX_TEXT_WIDTH, yPos, textPaint);
295+
}else{
296+
c.drawText(mText, 0, mText.length(), th / 2 + (MAX_TEXT_WIDTH - mTextBounds.width()) / 2, yPos, textPaint);
265297
}
266298
//c.drawArc(spinnerRect, 360 * progrot, 200 * proglength + 1, true, loaderPaint);
267299
}

0 commit comments

Comments
 (0)