Skip to content

Commit

Permalink
update gradle - allow left aligned text
Browse files Browse the repository at this point in the history
  • Loading branch information
Dean Wild committed Sep 26, 2016
1 parent c2a073a commit b9d0f26
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 23 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
classpath 'com.android.tools.build:gradle:2.2.0'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class MarqueeTextView extends View {
boolean animationRunning = false;
boolean paused = false;
boolean wrapped = false;
boolean centerText = true; // only applies to "unwrapped" text

TextPaint textPaint;
Paint leftPaint;
Expand Down Expand Up @@ -96,7 +97,8 @@ void readAttrs(AttributeSet attrs) {
R.attr.edgeEffectWidth,
R.attr.edgeEffectColor,
R.attr.pauseDuration,
R.attr.forceMarquee
R.attr.forceMarquee,
R.attr.centerText,
};

TypedArray ta = getContext().obtainStyledAttributes(attrs, attrsArray);
Expand All @@ -110,6 +112,7 @@ void readAttrs(AttributeSet attrs) {
edgeEffectColor = ta.getColor(6, edgeEffectColor);
pauseDuration = ta.getInt(7, pauseDuration);
forceMarquee = ta.getBoolean(8, forceMarquee);
centerText = ta.getBoolean(9, centerText);

ta.recycle();
}
Expand All @@ -128,7 +131,12 @@ protected void onDraw(Canvas canvas) {

animationRunning = false;

float leftMargin = (viewWidth - textWidth) / 2;
float leftMargin = 0;

if(centerText){
leftMargin = (viewWidth - textWidth) / 2;
}

canvas.drawText(text.toString(), leftMargin, topOffset, textPaint);

} else { // not enough room, we must animate it
Expand Down
1 change: 1 addition & 0 deletions marqueetextview/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
<attr name="edgeEffectColor" format="color" />
<attr name="pauseDuration" format="integer" />
<attr name="forceMarquee" format="boolean" />
<attr name="centerText" format="boolean" />
</declare-styleable>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

/*final MarqueeTextView tv = (MarqueeTextView) findViewById(R.id.tv1);
/* final MarqueeTextView tv = (MarqueeTextView) findViewById(R.id.tv1);
Button buttonChangeColour = (Button) findViewById(R.id.button_change_colour);
buttonChangeColour.setOnClickListener(new View.OnClickListener() {
Expand Down
36 changes: 17 additions & 19 deletions sample/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
android:textColor="#fff"
android:textSize="42sp"
app:edgeEffectColor="@color/red"
app:pauseDuration="3000"
app:edgeEffectEnabled="true" />
app:edgeEffectEnabled="true"
app:pauseDuration="3000" />-->


<TextView
Expand All @@ -36,35 +36,35 @@
android:background="#999"
android:orientation="horizontal">

<!--
<uk.co.deanwild.marqueetextview.MarqueeTextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Karting"
android:text="Karting is th ebest in the eworld"
android:textColor="#fff"
android:textSize="24sp"
app:edgeEffectColor="#fff"
app:edgeEffectEnabled="true"
app:edgeEffectWidth="20"
app:pauseDuration="3000"
app:edgeEffectEnabled="true" />
app:pauseDuration="3000" />-->


<uk.co.deanwild.marqueetextview.MarqueeTextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Football"
android:textColor="#fff"
android:textSize="24sp"
android:layout_marginLeft="5dp"
app:centerText="false"
app:edgeEffectColor="#fff"
app:edgeEffectEnabled="true"
app:edgeEffectWidth="20"
app:pauseDuration="3000"
app:edgeEffectEnabled="true" />
app:pauseDuration="3000" />


</LinearLayout>
Expand Down Expand Up @@ -96,33 +96,31 @@
android:textSize="24sp" />


</LinearLayout>-->
</LinearLayout>


<LinearLayout
android:layout_width="100px"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#009"
android:orientation="horizontal">

<uk.co.deanwild.marqueetextview.MarqueeTextView
<!-- <uk.co.deanwild.marqueetextview.MarqueeTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Football"
android:textColor="#fff"
android:textColor="#000"
android:textSize="24sp"
app:edgeEffectColor="#fff"
app:edgeEffectColor="#000"
app:edgeEffectEnabled="true"
app:edgeEffectWidth="20"
app:pauseDuration="3000"
app:edgeEffectEnabled="true" />
app:pauseDuration="3000" />-->


</LinearLayout>



<Button
android:id="@+id/button_change_colour"
android:layout_width="wrap_content"
Expand Down

0 comments on commit b9d0f26

Please sign in to comment.