Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
avishekdas128 committed Jan 30, 2021
0 parents commit 27cfb85
Show file tree
Hide file tree
Showing 48 changed files with 1,065 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .gitignore
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
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Language Drawable/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
38 changes: 38 additions & 0 deletions Language Drawable/build.gradle
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.
21 changes: 21 additions & 0 deletions Language Drawable/proguard-rules.pro
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
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());
}
}
5 changes: 5 additions & 0 deletions Language Drawable/src/main/AndroidManifest.xml
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>
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;
}
}
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;
}
}
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);
}
}
1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
Loading

0 comments on commit 27cfb85

Please sign in to comment.