Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions HorizontalBarGraphSample/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@
/.idea/libraries
.DS_Store
/build
.idea/
/captures
local.properties
.externalNativeBuild
19 changes: 0 additions & 19 deletions HorizontalBarGraphSample/.idea/gradle.xml

This file was deleted.

33 changes: 0 additions & 33 deletions HorizontalBarGraphSample/.idea/misc.xml

This file was deleted.

13 changes: 0 additions & 13 deletions HorizontalBarGraphSample/.idea/modules.xml

This file was deleted.

12 changes: 0 additions & 12 deletions HorizontalBarGraphSample/.idea/runConfigurations.xml

This file was deleted.

5 changes: 3 additions & 2 deletions HorizontalBarGraphSample/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ android {
compileSdkVersion 26
defaultConfig {
applicationId "br.com.felix.horizontalbargraphsample"
minSdkVersion 15
minSdkVersion 16
targetSdkVersion 26
versionCode 1
versionName "1.0"
Expand All @@ -17,6 +17,7 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
buildToolsVersion '27.0.2'
}

dependencies {
Expand All @@ -27,5 +28,5 @@ dependencies {
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'

compile project(":horizontalbargraph")
implementation project(":horizontalbargraph")
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ protected void onCreate(Bundle savedInstanceState) {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
horizontal.add(new BarItem("xxx", 500d));
horizontal.add(new BarItem("xxx", 500d).setRadius(40));

new Handler().postDelayed(new Runnable() {
@Override
public void run() {
horizontal.add(new BarItem("yyy", 1000d));
horizontal.add(new BarItem("yyy", 1000d).setRadius(40));
}
}, 5000);
}
Expand All @@ -42,7 +42,7 @@ private List<BarItem> itens() {
List<BarItem> items = new ArrayList<>();

int i = 0;
items.add(new BarItem("Teste " + i, 250d));
items.add(new BarItem("Teste " + i, 250d).setRadius(40));
i++;

items.add(new BarItem("Teste " + i, 800d, 550d));
Expand Down
2 changes: 1 addition & 1 deletion HorizontalBarGraphSample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.android.tools.build:gradle:7.4.2'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'

// NOTE: Do not place your application dependencies here; they belong
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#Tue Jan 16 17:22:33 BRST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
11 changes: 5 additions & 6 deletions HorizontalBarGraphSample/horizontalbargraph/build.gradle
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
//apply plugin: 'com.github.dcendents.android-maven'

group='com.github.felixsoares'

android {
compileSdkVersion 26
compileSdk 31



defaultConfig {
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
targetSdkVersion 31

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

Expand All @@ -24,6 +22,7 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
buildToolsVersion '27.0.2'

}

Expand All @@ -35,5 +34,5 @@ dependencies {
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'

compile 'com.android.support:design:27.0.2'
implementation 'com.android.support:design:26.1.0'
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
package br.com.felix.horizontalbargraph.adapter;

import android.animation.ValueAnimator;
import android.graphics.drawable.GradientDrawable;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.LinearInterpolator;
import android.widget.LinearLayout;
import android.widget.TextView;


import java.util.List;
import java.util.Locale;

import br.com.felix.horizontalbargraph.R;
import br.com.felix.horizontalbargraph.interfaces.OnItemClickListener;
import br.com.felix.horizontalbargraph.model.BarItem;
import br.com.felix.horizontalbargraph.util.Util;

/**
* Created by user on 12/01/2018.
Expand All @@ -25,12 +29,14 @@ public class BarItemRecycleViewAdapter extends RecyclerView.Adapter<BarItemRecyc
private List<BarItem> items;
private OnItemClickListener listener;
private Locale locale;
public int size;

public BarItemRecycleViewAdapter(List<BarItem> items, OnItemClickListener listener, Locale locale) {
this.items = items;
this.listener = listener;
this.locale = locale;
getBiggerValue(items);
size =Math.min(items.size(), 3);
}

private void getBiggerValue(List<BarItem> items) {
Expand All @@ -56,15 +62,15 @@ public void onBindViewHolder(ItemViewHolder holder, int position) {
BarItem viewModel = getItem(position);
holder.txtDesciption.setText(viewModel.getDescription());

holder.txtValue1.setText(Util.formatMoney(viewModel.getValue1(), locale));
holder.txtValue1.setText(viewModel.getValue1().intValue() + "");
chanceViewParam(holder.txtValue1, viewModel.getTextColorBar1());

int percent = getPercent(viewModel.getValue1());
double percent = getPercent(viewModel.getValue1());
changWidthBar(percent, holder.linearValue1, holder.linearValue1Margin);
chanceViewParam(holder.linearValue1, viewModel.getColorBar1());

if (viewModel.getValue2() != null && viewModel.getValue2() >= 0) {
holder.txtValue2.setText(Util.formatMoney(viewModel.getValue2(), locale));
holder.txtValue2.setText(viewModel.getValue2().intValue() + "");
chanceViewParam(holder.txtValue2, viewModel.getTextColorBar2());

percent = getPercent(viewModel.getValue2());
Expand All @@ -74,22 +80,34 @@ public void onBindViewHolder(ItemViewHolder holder, int position) {
holder.llValur1Root.setVisibility(View.VISIBLE);
holder.llValur2Root.setVisibility(View.GONE);
}

if (holder.linearValue1 != null &&viewModel.getRadius()!=0 ) {
GradientDrawable shape = new GradientDrawable();
shape.setCornerRadius(viewModel.getRadius());
shape.setColor(viewModel.getColorBar1());
(holder.linearValue1).setBackground(shape);
}

if (holder.linearValue2 != null &&viewModel.getRadius()!=0 ) {
GradientDrawable shape = new GradientDrawable();
shape.setCornerRadius(viewModel.getRadius());
shape.setColor(viewModel.getColorBar2());
(holder.linearValue2).setBackground(shape);
}
}

private void chanceViewParam(View view, int color) {
if (view instanceof TextView) {
((TextView) view).setTextColor(color);
} else if (view instanceof LinearLayout) {
(view).setBackgroundColor(color);
}
}

private void changWidthBar(int percent, LinearLayout layout1, LinearLayout layout2) {
LinearLayout.LayoutParams params1 = null, params2 = null;
private void changWidthBar(double percent, LinearLayout layout1, LinearLayout layout2) {
LinearLayout.LayoutParams params1, params2;

if (percent == 0) {
params1 = new LinearLayout.LayoutParams(
20,
0,
ViewGroup.LayoutParams.MATCH_PARENT
);

Expand All @@ -104,36 +122,51 @@ private void changWidthBar(int percent, LinearLayout layout1, LinearLayout layou
params1 = new LinearLayout.LayoutParams(
0,
ViewGroup.LayoutParams.MATCH_PARENT,
percent
(float) percent
);

params2 = new LinearLayout.LayoutParams(
0,
ViewGroup.LayoutParams.MATCH_PARENT,
value - percent
(float) (value - percent)
);
}

ValueAnimator m1 = ValueAnimator.ofFloat(0.0f, (float) percent); //fromWeight, toWeight
m1.setDuration(400);
m1.setStartDelay(100); //Optional Delay
m1.setInterpolator(new LinearInterpolator());
m1.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
((LinearLayout.LayoutParams) layout1.getLayoutParams()).weight = (float) animation.getAnimatedValue();
layout1.requestLayout();
}

});
m1.start();


layout1.setLayoutParams(params1);
layout2.setLayoutParams(params2);
}

private int getPercent(Double value) {
private double getPercent(Double value) {
Double percent = (value / biggerValue);
Double percentmAux = (value / biggerValue) * 100;

if (percentmAux.intValue() < 20) {
percent = 0D;
} else {
percent = percent < 1 ? percent * 10 : percent;
}

return percent.intValue();
// if (percentmAux.intValue() < 2) {
// percent = 0D;
// } else {
// percent = percent < 1 ? percent * 10 : percent;
// }
percent = percent < 1 ? percent * 10 : percent;
return percent;
}

@Override
public int getItemCount() {
return items.size();
return size;
}

public BarItem getItem(int position) {
Expand All @@ -152,6 +185,7 @@ public ItemViewHolder(View view) {
txtValue1 = view.findViewById(R.id.txtValorDespesa);
txtValue2 = view.findViewById(R.id.txtValorReceita);


linearValue1Margin = view.findViewById(R.id.linearDespesaMargin);
linearValue1 = view.findViewById(R.id.linearDespesa);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public class BarItem {
private int textColorBar1;
private int textColorBar2;

private int radius = 0;

public BarItem(String description, Double value1, int colorBar1, int textColorBar1) {
this.setDescription(description);
this.setValue1(value1);
Expand Down Expand Up @@ -49,6 +51,17 @@ public BarItem(String description, Double value1, Double value2, int colorBar1,
this.setTextColorBar2(textColorBar2);
}



public BarItem setRadius(int radius) {
this.radius = radius;
return this;
}

public int getRadius() {
return radius;
}

public void setDescription(String description) {
this.description = description;
}
Expand Down