Skip to content

Commit

Permalink
reformat code and fixed codacy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
LuGO0 committed Apr 16, 2020
1 parent 1196fd3 commit af52bbb
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 169 deletions.
55 changes: 25 additions & 30 deletions app/src/main/java/in/krharsh17/barview_sample/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@

import static in.krharsh17.barview.BarView.getRandomColor;


public class MainActivity extends AppCompatActivity {

BarView barView;
int cornerRadius = 20;//in dp

Expand All @@ -27,48 +25,48 @@ protected void onCreate(Bundle savedInstanceState) {
ArrayList<BarModel> barModels = new ArrayList<>();

barModels.add(new BarModel(
"Samsung",
"30.91",
getRandomColor(),
0.31f,0,0
"Samsung",
"30.91",
getRandomColor(),
0.31f, 0, 0
));

barModels.add(new BarModel(
"Apple",
"25.89",
getRandomColor(),
1f,5,5
"Apple",
"25.89",
getRandomColor(),
1f, 5, 5
));

barModels.add(new BarModel(
"Huawei",
"10.98",
getRandomColor(),
0.11f,8,4
"Huawei",
"10.98",
getRandomColor(),
0.11f, 8, 4
));

barModels.add(new BarModel(
"Xiaomi",
"7.8",
getRandomColor(),
0.07f,12,7
"Xiaomi",
"7.8",
getRandomColor(),
0.07f, 12, 7
));

barModels.add(new BarModel(
"Oppo",
"4.31",
getRandomColor(),
0.04f,7,18
"Oppo",
"4.31",
getRandomColor(),
0.04f, 7, 18
));

barModels.add(new BarModel(
"Others",
"20.11",
getRandomColor(),
0.20f,8,10
"Others",
"20.11",
getRandomColor(),
0.20f, 8, 10
));
barView.setData(barModels);

barView.setCornerRadius(cornerRadius);

barView.setOnBarClickListener(new BarView.OnBarClickListener() {
Expand All @@ -77,8 +75,5 @@ public void onBarClicked(int pos) {
Toast.makeText(MainActivity.this, "Bar at position " + pos, Toast.LENGTH_SHORT).show();
}
});

}


}
7 changes: 3 additions & 4 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/main_layout"
tools:context=".MainActivity">

<in.krharsh17.barview.BarView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/barview"
/>
android:layout_width="match_parent"
android:layout_height="match_parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
10 changes: 4 additions & 6 deletions library/src/main/java/in/krharsh17/barview/Bar.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import android.view.animation.DecelerateInterpolator;

class Bar extends View {

/**
* It can be called by anyone directly from code to create a new instance of the view.
* This constructor doesn’t have access to XML attributes, so you have to fill the parameters manually, using setters.
Expand All @@ -30,12 +29,11 @@ class Bar extends View {
* @param progress
*/
//increaseWidth is used to give some extra width to bar so that this extra width is used by shadow
public void setProgress(float progress,int increaseWidth,int animationType,int animationDuration) {
public void setProgress(float progress, int increaseWidth, int animationType, int animationDuration) {
ViewGroup.LayoutParams params = this.getLayoutParams();
if(animationType == BarView.INTRO_ANIM_EXPAND){
expand(this,animationDuration,Math.round(params.width * (progress)));
}
else if (animationType == BarView.INTRO_ANIM_NONE){
if (animationType == BarView.INTRO_ANIM_EXPAND) {
expand(this, animationDuration, Math.round(params.width * (progress)));
} else if (animationType == BarView.INTRO_ANIM_NONE) {
this.setVisibility(VISIBLE);
params.width = Math.round(params.width * (progress)) + increaseWidth;
this.setLayoutParams(params);
Expand Down
Loading

0 comments on commit af52bbb

Please sign in to comment.