Skip to content

Commit

Permalink
fix edgeEffectEnabled setter
Browse files Browse the repository at this point in the history
  • Loading branch information
Dean Wild committed Mar 16, 2016
1 parent e96a91e commit e2e4eee
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
public class MarqueeTextView extends View {

static final int DEFAULT_SPEED = 10;
static final int DEFAULT_SPEED = 5;
static int DEFAULT_PAUSE_DURATION = 10000;
static final int DEFAULT_EDGE_EFFECT_WIDTH = 10;
static final int DEFAULT_EDGE_EFFECT_COLOR = Color.WHITE;
Expand All @@ -29,7 +29,8 @@ public class MarqueeTextView extends View {
float textSize = getResources().getDisplayMetrics().scaledDensity * 20.0f;
int pauseDuration = DEFAULT_PAUSE_DURATION;
int speed = DEFAULT_SPEED;
boolean showEdgeEffect = false;

boolean edgeEffectEnabled = false;
int edgeEffectWidth = DEFAULT_EDGE_EFFECT_WIDTH;
int edgeEffectColor = DEFAULT_EDGE_EFFECT_COLOR;

Expand Down Expand Up @@ -90,7 +91,7 @@ void readAttrs(AttributeSet attrs) {
android.R.attr.textColor,
android.R.attr.text,
R.attr.marqueeEnabled,
R.attr.showEdgeEffect,
R.attr.edgeEffectEnabled,
R.attr.edgeEffectWidth,
R.attr.edgeEffectColor,
R.attr.pauseDuration,
Expand All @@ -103,7 +104,7 @@ void readAttrs(AttributeSet attrs) {
textColor = ta.getColor(1, textColor); // 3 is the index of the array of the textColor attribute
text = ta.getText(2);
marqueeEnabled = ta.getBoolean(3, marqueeEnabled);
showEdgeEffect = ta.getBoolean(4, showEdgeEffect);
edgeEffectEnabled = ta.getBoolean(4, edgeEffectEnabled);
edgeEffectWidth = ta.getInt(5, edgeEffectWidth);
edgeEffectColor = ta.getColor(6, edgeEffectColor);
pauseDuration = ta.getInt(7, pauseDuration);
Expand Down Expand Up @@ -143,7 +144,7 @@ protected void onDraw(Canvas canvas) {

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

if (showEdgeEffect) {
if (edgeEffectEnabled) {

if (xOffset < 0 || pauseDuration <= 0) {
canvas.drawRect(leftRect, leftPaint);
Expand Down Expand Up @@ -312,14 +313,29 @@ public void setTextSize(float textSize) {
requestLayout();
}

public int getEdgeEffectColor() {
return edgeEffectColor;

public void setEdgeEffectColorRes(int coloRes) {
setEdgeEffectColor(getContext().getColor(coloRes));
}

public void setEdgeEffectColor(int edgeEffectColor) {
this.edgeEffectColor = edgeEffectColor;

renewPaint();
invalidate();

if (paused)
invalidate();
}

public boolean isEdgeEffectEnabled() {
return edgeEffectEnabled;
}

public void setEdgeEffectEnabled(boolean edgeEffectEnabled) {
this.edgeEffectEnabled = edgeEffectEnabled;

if (paused)
invalidate();
}

}
2 changes: 1 addition & 1 deletion marqueetextview/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<resources>
<declare-styleable name="PieChart">
<attr name="marqueeEnabled" format="boolean" />
<attr name="showEdgeEffect" format="boolean" />
<attr name="edgeEffectEnabled" format="boolean" />
<attr name="edgeEffectWidth" format="integer" />
<attr name="edgeEffectColor" format="color" />
<attr name="pauseDuration" format="integer" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;

import uk.co.deanwild.marqueetextview.MarqueeTextView;

public class MainActivity extends AppCompatActivity {

Expand All @@ -10,6 +14,26 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

final MarqueeTextView tv = (MarqueeTextView) findViewById(R.id.tv1);

Button buttonChangeColour = (Button) findViewById(R.id.button_change_colour);
buttonChangeColour.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tv.setBackgroundResource(R.color.green);
tv.setEdgeEffectColorRes(R.color.green);
}
});

Button buttonToggleEdgeEffect = (Button) findViewById(R.id.toggleEdgeEffect);
buttonToggleEdgeEffect.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tv.setEdgeEffectEnabled(!tv.isEdgeEffectEnabled());
}
});


}

}
21 changes: 17 additions & 4 deletions sample/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@
tools:context="uk.co.deanwild.marqueetextviewsample.MainActivity">

<uk.co.deanwild.marqueetextview.MarqueeTextView
android:id="@+id/tv1"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#800"
android:background="@color/red"
android:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit."
android:textColor="#fff"
android:textSize="42sp"
app:edgeEffectColor="@color/red"
app:pauseDuration="3000"
app:showEdgeEffect="false" />
app:edgeEffectEnabled="true" />


<TextView
Expand Down Expand Up @@ -47,7 +49,7 @@
app:edgeEffectColor="#fff"
app:edgeEffectWidth="20"
app:pauseDuration="3000"
app:showEdgeEffect="true" />
app:edgeEffectEnabled="true" />


<uk.co.deanwild.marqueetextview.MarqueeTextView
Expand All @@ -62,7 +64,7 @@
app:edgeEffectColor="#fff"
app:edgeEffectWidth="20"
app:pauseDuration="3000"
app:showEdgeEffect="true" />
app:edgeEffectEnabled="true" />


</LinearLayout>
Expand Down Expand Up @@ -96,5 +98,16 @@

</LinearLayout>

<Button
android:id="@+id/button_change_colour"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Change colour" />


<Button
android:id="@+id/toggleEdgeEffect"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="toggle edge effect" />
</LinearLayout>
4 changes: 4 additions & 0 deletions sample/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>


<color name="red">#880000</color>
<color name="green">#008800</color>
</resources>

0 comments on commit e2e4eee

Please sign in to comment.