-
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
0 parents
commit 27cfb85
Showing
48 changed files
with
1,065 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/caches | ||
/.idea/libraries | ||
/.idea/modules.xml | ||
/.idea/workspace.xml | ||
/.idea/navEditor.xml | ||
/.idea/assetWizardSettings.xml | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild | ||
.cxx | ||
local.properties |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 @@ | ||
/build |
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,38 @@ | ||
plugins { | ||
id 'com.android.library' | ||
} | ||
|
||
android { | ||
compileSdkVersion 30 | ||
buildToolsVersion "29.0.3" | ||
|
||
defaultConfig { | ||
minSdkVersion 16 | ||
targetSdkVersion 30 | ||
versionCode 1 | ||
versionName "1.0" | ||
|
||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
consumerProguardFiles "consumer-rules.pro" | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
} | ||
|
||
dependencies { | ||
|
||
implementation 'androidx.appcompat:appcompat:1.2.0' | ||
implementation 'com.google.android.material:material:1.2.1' | ||
testImplementation 'junit:junit:4.+' | ||
androidTestImplementation 'androidx.test.ext:junit:1.1.2' | ||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' | ||
} |
Empty file.
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,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
26 changes: 26 additions & 0 deletions
26
...able/src/androidTest/java/com/avishekdas128/languageDrawable/ExampleInstrumentedTest.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,26 @@ | ||
package com.avishekdas128.languageDrawable; | ||
|
||
import android.content.Context; | ||
|
||
import androidx.test.platform.app.InstrumentationRegistry; | ||
import androidx.test.ext.junit.runners.AndroidJUnit4; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a> | ||
*/ | ||
@RunWith(AndroidJUnit4.class) | ||
public class ExampleInstrumentedTest { | ||
@Test | ||
public void useAppContext() { | ||
// Context of the app under test. | ||
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); | ||
assertEquals("com.avishekdas128.languageDrawable.test", appContext.getPackageName()); | ||
} | ||
} |
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,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.avishekdas128.languageDrawable"> | ||
|
||
</manifest> |
113 changes: 113 additions & 0 deletions
113
Language Drawable/src/main/java/com/avishekdas128/languageDrawable/LanguageDrawable.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,113 @@ | ||
package com.avishekdas128.languageDrawable; | ||
|
||
import android.graphics.Canvas; | ||
import android.graphics.ColorFilter; | ||
import android.graphics.Paint; | ||
import android.graphics.Path; | ||
import android.graphics.PixelFormat; | ||
import android.graphics.Rect; | ||
import android.graphics.drawable.Drawable; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
import java.util.List; | ||
|
||
public class LanguageDrawable extends Drawable { | ||
|
||
private final Paint mPaint; | ||
private final List<LanguageModel> codeColors; | ||
private float mFraction; | ||
|
||
public LanguageDrawable(List<LanguageModel> codeColors) { | ||
mPaint = new Paint(); | ||
this.codeColors = codeColors; | ||
setFraction(codeColors.get(0)); | ||
} | ||
|
||
public void setFraction(LanguageModel color) { | ||
mFraction = color.getFraction(); | ||
invalidateSelf(); | ||
} | ||
|
||
@Override | ||
public void draw(@NonNull Canvas canvas) { | ||
Rect b = getBounds(); | ||
for (int i = 0; i < codeColors.size(); i++) { | ||
mPaint.setColor(codeColors.get(i).getColor()); | ||
setFraction(codeColors.get(i)); | ||
float x = b.width() * mFraction; | ||
if (i == 0) { | ||
codeColors.get(i).setStart(0); | ||
codeColors.get(i).setEnd(x); | ||
if(codeColors.size() == 1) | ||
canvas.drawPath(RoundedRect(codeColors.get(i).getStart(), codeColors.get(i).getEnd(), b.height(), true, true, true, true), mPaint); | ||
else | ||
canvas.drawPath(RoundedRect(codeColors.get(i).getStart(), codeColors.get(i).getEnd(), b.height(), false, true, false, true), mPaint); | ||
} else if (i == codeColors.size() - 1) { | ||
codeColors.get(i).setStart(codeColors.get(i - 1).getEnd()); | ||
codeColors.get(i).setEnd(b.width()); | ||
canvas.drawPath(RoundedRect(codeColors.get(i).getStart() + 10, codeColors.get(i).getEnd(), b.height(), true, false, true, false), mPaint); | ||
} else { | ||
codeColors.get(i).setStart(codeColors.get(i - 1).getEnd()); | ||
codeColors.get(i).setEnd(codeColors.get(i).getStart() + x); | ||
canvas.drawPath(RoundedRect(codeColors.get(i).getStart() + 10, codeColors.get(i).getEnd(), b.height(), false, false, false, false), mPaint); | ||
} | ||
} | ||
} | ||
|
||
private Path RoundedRect(float left, float right, float bottom, boolean tr, boolean tl, boolean br, boolean bl) { | ||
float rx = bottom / 2; | ||
float ry = bottom / 2; | ||
Path path = new Path(); | ||
float width = right - left; | ||
float height = bottom - (float) 0; | ||
if (rx > width / 2) rx = width / 2; | ||
if (ry > height / 2) ry = height / 2; | ||
float widthMinusCorners = (width - (2 * rx)); | ||
float heightMinusCorners = (height - (2 * ry)); | ||
path.moveTo(right, (float) 0 + ry); | ||
if (tr) | ||
path.rQuadTo(0, -ry, -rx, -ry); //Top-Right corner | ||
else { | ||
path.rLineTo(0, -ry); | ||
path.rLineTo(-rx, 0); | ||
} | ||
path.rLineTo(-widthMinusCorners, 0); | ||
if (tl) | ||
path.rQuadTo(-rx, 0, -rx, ry); //Top-Left corner | ||
else { | ||
path.rLineTo(-rx, 0); | ||
path.rLineTo(0, ry); | ||
} | ||
path.rLineTo(0, heightMinusCorners); | ||
if (bl) | ||
path.rQuadTo(0, ry, rx, ry); //Bottom-Left corner | ||
else { | ||
path.rLineTo(0, ry); | ||
path.rLineTo(rx, 0); | ||
} | ||
path.rLineTo(widthMinusCorners, 0); | ||
if (br) | ||
path.rQuadTo(rx, 0, rx, -ry); //Bottom-Right corner | ||
else { | ||
path.rLineTo(rx, 0); | ||
path.rLineTo(0, -ry); | ||
} | ||
path.rLineTo(0, -heightMinusCorners); | ||
path.close(); | ||
return path; | ||
} | ||
|
||
@Override | ||
public void setAlpha(int alpha) { | ||
} | ||
|
||
@Override | ||
public void setColorFilter(ColorFilter cf) { | ||
} | ||
|
||
@Override | ||
public int getOpacity() { | ||
return PixelFormat.TRANSLUCENT; | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
Language Drawable/src/main/java/com/avishekdas128/languageDrawable/LanguageModel.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,44 @@ | ||
package com.avishekdas128.languageDrawable; | ||
|
||
public class LanguageModel { | ||
|
||
float fraction, start, end; | ||
int color; | ||
|
||
public LanguageModel(float fraction, int color) { | ||
this.fraction = fraction; | ||
this.color = color; | ||
} | ||
|
||
public float getFraction() { | ||
return fraction; | ||
} | ||
|
||
public void setFraction(float fraction) { | ||
this.fraction = fraction; | ||
} | ||
|
||
public int getColor() { | ||
return color; | ||
} | ||
|
||
public void setColor(int color) { | ||
this.color = color; | ||
} | ||
|
||
public float getStart() { | ||
return start; | ||
} | ||
|
||
public void setStart(float start) { | ||
this.start = start; | ||
} | ||
|
||
public float getEnd() { | ||
return end; | ||
} | ||
|
||
public void setEnd(float end) { | ||
this.end = end; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
Language Drawable/src/test/java/com/avishekdas128/languageDrawable/ExampleUnitTest.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.avishekdas128.languageDrawable; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* Example local unit test, which will execute on the development machine (host). | ||
* | ||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a> | ||
*/ | ||
public class ExampleUnitTest { | ||
@Test | ||
public void addition_isCorrect() { | ||
assertEquals(4, 2 + 2); | ||
} | ||
} |
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 @@ | ||
/build |
Oops, something went wrong.