-
Notifications
You must be signed in to change notification settings - Fork 8
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
1 parent
eb42887
commit e90e0a1
Showing
3 changed files
with
230 additions
and
20 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
65 changes: 65 additions & 0 deletions
65
library/src/main/java/com/flyjingfish/gradienttextviewlib/ViewUtils.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,65 @@ | ||
package com.flyjingfish.gradienttextviewlib; | ||
|
||
import android.util.LayoutDirection; | ||
import android.view.View; | ||
|
||
import androidx.core.text.TextUtilsCompat; | ||
|
||
import java.util.Locale; | ||
|
||
public class ViewUtils { | ||
|
||
public static int getViewPaddingLeft(View view){ | ||
boolean isRtl = false; | ||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) { | ||
isRtl = TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getDefault()) == LayoutDirection.RTL; | ||
} | ||
int paddingStart = view.getPaddingStart(); | ||
int paddingEnd = view.getPaddingEnd(); | ||
int paddingLeft = view.getPaddingLeft(); | ||
int paddingLeftMax; | ||
|
||
if (isRtl){ | ||
if (paddingEnd != 0){ | ||
paddingLeftMax = paddingEnd; | ||
}else { | ||
paddingLeftMax = paddingLeft; | ||
} | ||
}else { | ||
if (paddingStart != 0){ | ||
paddingLeftMax = paddingStart; | ||
}else { | ||
paddingLeftMax = paddingLeft; | ||
} | ||
|
||
} | ||
|
||
return paddingLeftMax; | ||
} | ||
|
||
public static int getViewPaddingRight(View view){ | ||
boolean isRtl = false; | ||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) { | ||
isRtl = TextUtilsCompat.getLayoutDirectionFromLocale(Locale.getDefault()) == LayoutDirection.RTL; | ||
} | ||
int paddingStart = view.getPaddingStart(); | ||
int paddingEnd = view.getPaddingEnd(); | ||
int paddingRight = view.getPaddingRight(); | ||
int paddingRightMax; | ||
if (isRtl){ | ||
if (paddingStart != 0){ | ||
paddingRightMax = paddingStart; | ||
}else { | ||
paddingRightMax = paddingRight; | ||
} | ||
}else { | ||
if (paddingEnd != 0){ | ||
paddingRightMax = paddingEnd; | ||
}else { | ||
paddingRightMax = paddingRight; | ||
} | ||
|
||
} | ||
return paddingRightMax; | ||
} | ||
} |