Skip to content

Commit

Permalink
preparing for 1st release
Browse files Browse the repository at this point in the history
* added screenshots;
* update build.gradle;
* update README.md
* update the sample layout
  • Loading branch information
kishannareshpal committed Dec 8, 2018
1 parent 03d4895 commit 500e71e
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 24 deletions.
6 changes: 6 additions & 0 deletions .idea/vcs.xml

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

Binary file added 1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This library allows you to show a set of data over a horizontal bar. Just like t



![](https://github.com/kishannareshpal/StorageDetailsView/raw/master/screenshot.png)
![Screenshot](https://github.com/kishannareshpal/StorageDetailsView/raw/master/1.png)



Expand Down Expand Up @@ -77,6 +77,8 @@ dependencies {
android:layout_height="12dp" />
```

![Default look](https://github.com/kishannareshpal/StorageDetailsView/raw/master/2.png)

The view by default, will have a grey colored background and round corners. In order to customize it, you can use the attributes listed on the table below:

#### Optional customizations
Expand Down Expand Up @@ -110,9 +112,9 @@ The `addData()` arguments:

- **dataId** - An arbitrary id, so you can query it's information later, such as it's percentage via the `getDataPercentage()` method.

- **percentage** - How much of the bar this data will fill, starting from the last added data. The total percentage of the added data *should not exceed 100%*. E.g: `float 42F | int 42`
- **percentage** - How much of the bar this data will fill, starting from the last added data. The total percentage of the added data *should not exceed 100%*. E.g: *`float 42F | int 42`.*

- **colorRes** - the background color of this new detail. E.g: `getResources().getColor(R.color.blue)`;
- **colorRes** - the background color of this new detail. E.g: *I recommend using these two methods for retrieving the colors: `ContextCompat.getColor(getContext(), R.color.blue)` or `getResources().getColor()`.*


:egg:Example:
Expand All @@ -123,19 +125,21 @@ HorizontalBarChartView hbcv = findViewById(R.id.hbcv);

// Add the data.
int percent = 12;
int color = getResources().getColor(R.color.blue);
int color = ContextCompat.getColor(getContext(), R.color.blue);
hbcv.addData(MEDIA_ID, percent, color);

int percent = 35;
int color = getResources().getColor(R.color.green);
int color = ContextCompat.getColor(getContext(), R.color.green);
hbcv.addData(APPS_ID, percent, color);

...
// And finally call the .show() to update the bar.
sdv.show();
```

![](/Users/kishan/AndroidStudioProjects/StorageDetailsView/images/2.png)
![Screenshot 2](https://github.com/kishannareshpal/StorageDetailsView/raw/master/3.png)



##### 2. Getter methods

Expand Down
1 change: 0 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.kishannareshpal.horizontalbarchartview;

import android.content.Context;
import android.os.Build;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
Expand All @@ -12,13 +15,17 @@ public class MainActivity extends AppCompatActivity {
private static final int MAIL_DETAILID = 3;
private static final int OTHERS_DETAILID = 4;


// Utils
private Context ctx;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

// Init utils
ctx = this;

// Init the component
final HorizontalBarChartView hbcv = findViewById(R.id.sdv_details);
Button btn = findViewById(R.id.button);
Expand All @@ -27,10 +34,10 @@ protected void onCreate(Bundle savedInstanceState) {
@Override
public void onClick(View v) {
// Add as many details as you'd like...
hbcv.addData(APPS_DETAILID, 12, getResources().getColor(R.color.red));
hbcv.addData(MEDIA_DETAILID, 14, getResources().getColor(R.color.yellow));
hbcv.addData(MAIL_DETAILID, 5, getResources().getColor(R.color.blue));
hbcv.addData(OTHERS_DETAILID, 42, getResources().getColor(R.color.grey));
hbcv.addData(APPS_DETAILID, 12, ContextCompat.getColor(ctx, R.color.red));
hbcv.addData(MEDIA_DETAILID, 23, ContextCompat.getColor(ctx, R.color.yellow));
hbcv.addData(MAIL_DETAILID, 17, ContextCompat.getColor(ctx, R.color.blue));
hbcv.addData(OTHERS_DETAILID, 42, ContextCompat.getColor(ctx, R.color.green));
// ...

// Call .show() to draw the details on the view.
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:layout_marginTop="12dp"
android:text="Apps"
android:textColor="@color/red" />
android:textStyle="bold"
android:textColor="@color/red"
android:text="Apps" />

<TextView
android:layout_width="match_parent"
Expand All @@ -63,7 +63,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Others"
android:textColor="@color/grey"
android:textColor="@color/green"
android:textStyle="bold" />

<Button
Expand Down
3 changes: 0 additions & 3 deletions horizontalbarchartview/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ apply plugin: 'com.android.library'

android {
compileSdkVersion 28



defaultConfig {
minSdkVersion 14
targetSdkVersion 28
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.graphics.RectF;
import android.graphics.drawable.GradientDrawable;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
Expand Down Expand Up @@ -46,6 +47,8 @@ public class HorizontalBarChartView extends View {

private float currentPercentage;

private Context ctx;

private int fullWidth; // the max canvas width.
private int fullHeight; // the max canvas height.

Expand All @@ -57,6 +60,7 @@ public class HorizontalBarChartView extends View {
*/
public HorizontalBarChartView(Context ctx, @Nullable AttributeSet attrs) {
super(ctx, attrs);
this.ctx = ctx;
init(attrs);
}

Expand All @@ -67,7 +71,7 @@ public void init(@Nullable AttributeSet set){
// if custom attributes were set.
TypedArray ta = getContext().obtainStyledAttributes(set, R.styleable.HorizontalBarChartView);
corner_radius = ta.getFloat(R.styleable.HorizontalBarChartView_hbcv_cornerRadius, corner_radius);
background_color = ta.getColor(R.styleable.HorizontalBarChartView_hbcv_color, getResources().getColor(R.color.default_bar_color));
background_color = ta.getColor(R.styleable.HorizontalBarChartView_hbcv_color, ContextCompat.getColor(ctx, R.color.default_bar_color));
ta.recycle();
}

Expand All @@ -80,7 +84,7 @@ public void init(@Nullable AttributeSet set){
dataList = new ArrayList<>();

tb_left_radius = new float[]{corner_radius, corner_radius, 0, 0, 0, 0, corner_radius, corner_radius}; // Is only round on top-bottom left.
flat_radius = new float[]{corner_radius, corner_radius, 0, 0, 0, 0, 0, 0}; // A flat square. Without rounded corners.
flat_radius = new float[]{0, 0, 0, 0, 0, 0, 0, 0}; // A flat square. Without rounded corners.
tb_right_radius = new float[]{0, 0, corner_radius, corner_radius, corner_radius, corner_radius, 0, 0}; // Is only round on top-bottom right.

newDrawable = new GradientDrawable(); // the individual detail path.
Expand Down
3 changes: 0 additions & 3 deletions horizontalbarchartview/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="amarelo">#00FFFF</color>
<color name="blue">#0000FF</color>
<color name="red">#FF0000</color>
<color name="default_bar_color">#F5F5F5</color>
</resources>

0 comments on commit 500e71e

Please sign in to comment.