forked from JavaNoober/BackgroundLibrary
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
xiaoqi01
committed
Aug 17, 2022
1 parent
c64b686
commit 633f81b
Showing
14 changed files
with
282 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
library/src/main/java/com/noober/background/drawable/ITextViewOperator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.noober.background.drawable; | ||
|
||
import android.content.Context; | ||
import android.util.AttributeSet; | ||
import android.widget.TextView; | ||
|
||
/** | ||
* Author: xiaoqi | ||
* Date: 2022/8/17 3:13 下午 | ||
* Description: | ||
*/ | ||
public interface ITextViewOperator { | ||
void invoke(Context context, AttributeSet attrs, TextView textView); | ||
} |
17 changes: 17 additions & 0 deletions
17
library/src/main/java/com/noober/background/drawable/TextViewFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.noober.background.drawable; | ||
|
||
import android.content.Context; | ||
import android.util.AttributeSet; | ||
import android.widget.TextView; | ||
|
||
/** | ||
* Author: xiaoqi | ||
* Date: 2022/8/17 3:11 下午 | ||
* Description: | ||
*/ | ||
public class TextViewFactory { | ||
|
||
public static void setTextGradientColor(Context context, AttributeSet attrs, final TextView textView){ | ||
new TextViewGradientColor().invoke(context, attrs, textView); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
library/src/main/java/com/noober/background/drawable/TextViewGradientColor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.noober.background.drawable; | ||
|
||
import android.content.Context; | ||
import android.content.res.TypedArray; | ||
import android.graphics.LinearGradient; | ||
import android.graphics.Shader; | ||
import android.util.AttributeSet; | ||
import android.widget.TextView; | ||
|
||
import com.noober.background.R; | ||
|
||
/** | ||
* Author: xiaoqi | ||
* Date: 2022/8/17 3:14 下午 | ||
* Description: | ||
*/ | ||
public class TextViewGradientColor implements ITextViewOperator{ | ||
private int endColor = -1; | ||
private int startColor = -1; | ||
private int orientation = 0; | ||
|
||
@Override | ||
public void invoke(Context context, AttributeSet attrs, final TextView textView) { | ||
TypedArray textTa = context.obtainStyledAttributes(attrs, R.styleable.bl_text); | ||
try { | ||
if(textTa.getIndexCount() == 0){ | ||
return; | ||
} | ||
for (int i = 0; i < textTa.getIndexCount(); i++) { | ||
int attr = textTa.getIndex(i); | ||
if(attr == R.styleable.bl_text_bl_text_gradient_endColor){ | ||
endColor = textTa.getColor(attr, -1); | ||
}else if(attr == R.styleable.bl_text_bl_text_gradient_startColor){ | ||
startColor = textTa.getColor(attr, -1); | ||
}else if(attr == R.styleable.bl_text_bl_text_gradient_orientation){ | ||
orientation = textTa.getInt(attr, 0); | ||
} | ||
} | ||
|
||
if(endColor == -1 && startColor != -1){ | ||
textView.setTextColor(startColor); | ||
}else if(startColor == -1 && endColor != -1){ | ||
textView.setTextColor(endColor); | ||
}else if(endColor != -1 && startColor != -1){ | ||
if(orientation == 0){ | ||
textView.post(new Runnable() { | ||
@Override | ||
public void run() { | ||
textView.getPaint().setShader(new LinearGradient(0f, 0f, 0f, textView.getPaint().descent() - textView.getPaint().ascent(), | ||
startColor, endColor, Shader.TileMode.REPEAT)); | ||
textView.invalidate(); | ||
} | ||
}); | ||
|
||
}else { | ||
textView.post(new Runnable() { | ||
@Override | ||
public void run() { | ||
textView.getPaint().setShader(new LinearGradient(0, 0f, textView.getMeasuredWidth(), 0f, startColor, endColor, Shader.TileMode.REPEAT)); | ||
textView.invalidate(); | ||
} | ||
}); | ||
} | ||
} | ||
}catch (Exception e){ | ||
|
||
}finally { | ||
textTa.recycle(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
libraryx/src/main/java/com/noober/background/drawable/ITextViewOperator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.noober.background.drawable; | ||
|
||
import android.content.Context; | ||
import android.util.AttributeSet; | ||
import android.widget.TextView; | ||
|
||
/** | ||
* Author: xiaoqi | ||
* Date: 2022/8/17 3:13 下午 | ||
* Description: | ||
*/ | ||
public interface ITextViewOperator { | ||
void invoke(Context context, AttributeSet attrs, TextView textView); | ||
} |
17 changes: 17 additions & 0 deletions
17
libraryx/src/main/java/com/noober/background/drawable/TextViewFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.noober.background.drawable; | ||
|
||
import android.content.Context; | ||
import android.util.AttributeSet; | ||
import android.widget.TextView; | ||
|
||
/** | ||
* Author: xiaoqi | ||
* Date: 2022/8/17 3:11 下午 | ||
* Description: | ||
*/ | ||
public class TextViewFactory { | ||
|
||
public static void setTextGradientColor(Context context, AttributeSet attrs, final TextView textView){ | ||
new TextViewGradientColor().invoke(context, attrs, textView); | ||
} | ||
} |
Oops, something went wrong.