-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jay
committed
Aug 17, 2017
1 parent
a53bb6d
commit 4326ed7
Showing
5 changed files
with
277 additions
and
2 deletions.
There are no files selected for viewing
133 changes: 133 additions & 0 deletions
133
FresherSpecial/src/main/java/com/mredrock/freshmanspecial/view/BarGraphView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
package com.mredrock.freshmanspecial.view; | ||
|
||
import android.content.Context; | ||
import android.graphics.Canvas; | ||
import android.graphics.Color; | ||
import android.graphics.Paint; | ||
import android.graphics.RectF; | ||
import android.support.annotation.Nullable; | ||
import android.util.AttributeSet; | ||
import android.util.DisplayMetrics; | ||
import android.util.TypedValue; | ||
import android.view.View; | ||
|
||
/** | ||
* Created by Jay on 2017/8/17. | ||
*/ | ||
|
||
public class BarGraphView extends View { | ||
private static final int COLOR_FILL = Color.parseColor("#9efcee"); | ||
private static final int COLOR_STROKE = Color.parseColor("#6cead5"); | ||
private static final int COLOR_TEXT = Color.parseColor("#666666"); | ||
|
||
private static final int MIN_VALUE = 10; | ||
private static final int MAX_VALUE = 300; | ||
private static final int GAP_VALUE = 10; | ||
|
||
private final int DEFAULT_RADIUS = (int) dp2px(80); | ||
private final int STROKE_WIDTH = dp2px(2); | ||
|
||
private int mValue; | ||
private int mRadius; | ||
private Paint mFillPaint; | ||
private Paint mStrokePaint; | ||
private Paint mTextPaint; | ||
|
||
public BarGraphView(Context context) { | ||
this(context, null); | ||
} | ||
|
||
public BarGraphView(Context context, @Nullable AttributeSet attrs) { | ||
super(context, attrs); | ||
init(); | ||
} | ||
|
||
private void init() { | ||
mFillPaint = new Paint(); | ||
mFillPaint.setAntiAlias(true); | ||
mFillPaint.setDither(true); | ||
mFillPaint.setColor(COLOR_FILL); | ||
mFillPaint.setStyle(Paint.Style.FILL); | ||
|
||
mStrokePaint = new Paint(); | ||
mStrokePaint.setAntiAlias(true); | ||
mStrokePaint.setDither(true); | ||
mStrokePaint.setColor(COLOR_STROKE); | ||
mStrokePaint.setStrokeWidth(STROKE_WIDTH); | ||
mStrokePaint.setStyle(Paint.Style.STROKE); | ||
|
||
// TODO: 2017/8/17 textPaint | ||
mTextPaint = new Paint(); | ||
mTextPaint.setTextSize(dp2px(14)); | ||
mTextPaint.setColor(COLOR_TEXT); | ||
} | ||
|
||
@Override | ||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { | ||
/*int width = 0; | ||
int height = 0; | ||
switch (MeasureSpec.getMode(widthMeasureSpec)) { | ||
case MeasureSpec.UNSPECIFIED: | ||
height = DEFAULT_RADIUS; | ||
mRadius = height / 2; | ||
width = value2px(MAX_VALUE); | ||
break; | ||
case MeasureSpec.AT_MOST: | ||
int leftWidth = MeasureSpec.getSize(widthMeasureSpec); | ||
width = Math.min(leftWidth, value2px(MAX_VALUE, DEFAULT_RADIUS)); | ||
mRadius = width / (MAX_VALUE / GAP_VALUE); | ||
height = mRadius * 2; | ||
break; | ||
case MeasureSpec.EXACTLY: | ||
width = MeasureSpec.getSize(widthMeasureSpec); | ||
mRadius = width / (MAX_VALUE / GAP_VALUE); | ||
height = mRadius * 2; | ||
break; | ||
} | ||
widthMeasureSpec = MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY); | ||
heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY);*/ | ||
super.onMeasure(widthMeasureSpec, heightMeasureSpec); | ||
mRadius = getMeasuredHeight() / 2; | ||
} | ||
|
||
@Override | ||
protected void onDraw(Canvas canvas) { | ||
super.onDraw(canvas); | ||
RectF rect = new RectF(0, 0, value2px(mValue), mRadius * 2); | ||
canvas.drawRoundRect(rect, mRadius, mRadius, mFillPaint); | ||
Paint.FontMetricsInt fontMetrics = mTextPaint.getFontMetricsInt(); | ||
int baseline = (int) ((rect.bottom + rect.top - fontMetrics.bottom - fontMetrics.top) / 2); | ||
canvas.drawText(mValue + "人", rect.right + dp2px(10), baseline, mTextPaint); | ||
} | ||
|
||
private int dp2px(int dp) { | ||
DisplayMetrics metrics = getResources().getDisplayMetrics(); | ||
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, metrics); | ||
} | ||
|
||
private int value2px(int value) { | ||
return value2px(value, mRadius); | ||
} | ||
|
||
private int value2px(int value, int size) { | ||
if (value <= MIN_VALUE) { | ||
return size * 2; | ||
} else if (value >= MAX_VALUE) { | ||
return size * 2 + size * (MAX_VALUE - MIN_VALUE) / GAP_VALUE; | ||
} else { | ||
return size * 2 + size * (value - MIN_VALUE) / GAP_VALUE; | ||
} | ||
} | ||
|
||
public void setValue(int value) { | ||
mValue = value; | ||
postInvalidate(); | ||
} | ||
|
||
public int getValue() { | ||
return mValue; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
...src/main/java/com/mredrock/freshmanspecial/view/dataFragments/EmploymentDataFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
FresherSpecial/src/main/res/layout/special_2017_fragment_employment_data.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<ScrollView | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content"> | ||
|
||
<LinearLayout | ||
android:id="@+id/container" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:orientation="vertical"> | ||
|
||
</LinearLayout> | ||
</ScrollView> |
25 changes: 25 additions & 0 deletions
25
FresherSpecial/src/main/res/layout/special_2017_item_fragment_employment_data.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:gravity="center_vertical" | ||
android:orientation="horizontal" | ||
android:paddingTop="30dp"> | ||
|
||
<TextView | ||
android:id="@+id/commpany" | ||
android:layout_width="0dp" | ||
android:layout_height="wrap_content" | ||
android:layout_weight="1" | ||
android:gravity="center" | ||
android:text="猪八戒" | ||
android:textColor="#000000" | ||
android:textSize="14sp"/> | ||
|
||
<com.mredrock.freshmanspecial.view.BarGraphView | ||
android:id="@+id/bar" | ||
android:layout_width="0dp" | ||
android:layout_height="18dp" | ||
android:layout_weight="3.37"/> | ||
</LinearLayout> |