Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed code quality issues #85

Merged
merged 2 commits into from
Apr 18, 2020
Merged
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
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>
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() {
public void additionIsCorrect() {
assertEquals(4, 2 + 2);
}
}
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