-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
4 changed files
with
87 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
29 changes: 29 additions & 0 deletions
29
pinentryedittext/src/main/java/com/lamonjush/pinentryedittext/BackgroundShape.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,29 @@ | ||
package com.lamonjush.pinentryedittext; | ||
|
||
import android.graphics.drawable.Drawable; | ||
import android.graphics.drawable.GradientDrawable; | ||
|
||
class BackgroundShape { | ||
private int fillColor, strokeWidth; | ||
private float cornerRadius; | ||
|
||
void setFillColor(int fillColor) { | ||
this.fillColor = fillColor; | ||
} | ||
|
||
void setCornerRadius(float cornerRadius) { | ||
this.cornerRadius = cornerRadius; | ||
} | ||
|
||
void setStrokeWidth(int strokeWidth) { | ||
this.strokeWidth = strokeWidth; | ||
} | ||
|
||
Drawable getDrawable(int strokeColor) { | ||
GradientDrawable gradientDrawable = new GradientDrawable(); | ||
gradientDrawable.setColor(fillColor); | ||
gradientDrawable.setCornerRadius(cornerRadius); | ||
gradientDrawable.setStroke(strokeWidth, strokeColor); | ||
return gradientDrawable; | ||
} | ||
} |
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
32 changes: 32 additions & 0 deletions
32
pinentryedittext/src/main/java/com/lamonjush/pinentryedittext/Utils.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,32 @@ | ||
package com.lamonjush.pinentryedittext; | ||
|
||
import android.content.Context; | ||
import android.util.DisplayMetrics; | ||
|
||
class Utils { | ||
|
||
|
||
/** | ||
* This method converts dp unit to equivalent pixels, depending on device density. | ||
* | ||
* @param dp A value in dp (density independent pixels) unit. Which we need to convert into pixels | ||
* @param context Context to get resources and device specific display metrics | ||
* @return A float value to represent px equivalent to dp depending on device density | ||
*/ | ||
static float convertDpToPixel(float dp, Context context){ | ||
return dp * ((float) context.getResources().getDisplayMetrics().densityDpi / DisplayMetrics.DENSITY_DEFAULT); | ||
} | ||
|
||
/** | ||
* This method converts device specific pixels to density independent pixels. | ||
* | ||
* @param px A value in px (pixels) unit. Which we need to convert into db | ||
* @param context Context to get resources and device specific display metrics | ||
* @return A float value to represent dp equivalent to px value | ||
*/ | ||
static float convertPixelsToDp(float px, Context context){ | ||
return px / ((float) context.getResources().getDisplayMetrics().densityDpi / DisplayMetrics.DENSITY_DEFAULT); | ||
} | ||
|
||
|
||
} |