-
Notifications
You must be signed in to change notification settings - Fork 2
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
1 parent
a64457e
commit 5eacb5d
Showing
13 changed files
with
369 additions
and
114 deletions.
There are no files selected for viewing
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
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,24 @@ | ||
package jie.com.funnel; | ||
|
||
import android.os.Bundle; | ||
import android.support.annotation.Nullable; | ||
import android.support.v7.app.AppCompatActivity; | ||
|
||
import jie.com.funnellib.FunnelView; | ||
|
||
/** | ||
* Created by hj on 2019/2/25. | ||
* 说明: | ||
*/ | ||
public abstract class BaseFunnelActivity extends AppCompatActivity { | ||
|
||
@Override | ||
protected void onCreate(@Nullable Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_default); | ||
FunnelView funnelVie = findViewById(R.id.funnelView); | ||
initEvent(funnelVie); | ||
} | ||
|
||
abstract void initEvent(FunnelView funnelView); | ||
} |
42 changes: 42 additions & 0 deletions
42
app/src/main/java/jie/com/funnel/CustomHalfWidthActivity.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,42 @@ | ||
package jie.com.funnel; | ||
|
||
import android.util.TypedValue; | ||
|
||
import jie.com.funnellib.FunnelView; | ||
import jie.com.funnellib.HalfWidthCallback; | ||
|
||
/** | ||
* Created by hj on 2019/2/25. | ||
* 说明:自定义宽度策略 | ||
*/ | ||
public class CustomHalfWidthActivity extends BaseFunnelActivity { | ||
|
||
@Override | ||
void initEvent(FunnelView funnelView) { | ||
/** | ||
* 自定义宽度策略,也就是漏斗每一层宽度增加多少,这都是可以自定义的,这样有利于适配的灵活性,也可以自定义出 | ||
* 很多的效果出来 | ||
* 注意事项:绘制是从下往上绘制的,halfWidth返回的当前的下面那个漏斗的宽度,需要注意一下 | ||
* | ||
*/ | ||
funnelView.setChartData(FunnelData.getTenCountData(), new HalfWidthCallback() { | ||
@Override | ||
public float getHalfStrategy(float halfWidth, int count, int i) { | ||
/** | ||
* 这里定义的策略是前4个宽度不变,后面的逐渐增加10dp,所以呈现了一个真正的漏斗形状 | ||
*/ | ||
if (i <= 3) { | ||
halfWidth = dp2px(5); | ||
return halfWidth; | ||
} else { | ||
halfWidth += dp2px(10); | ||
return halfWidth; | ||
} | ||
} | ||
}); | ||
} | ||
|
||
private float dp2px(int dip) { | ||
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dip, this.getResources().getDisplayMetrics()); | ||
} | ||
} |
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,45 @@ | ||
package jie.com.funnel; | ||
|
||
import android.graphics.Canvas; | ||
import android.graphics.Color; | ||
import android.graphics.Paint; | ||
import android.os.Bundle; | ||
import android.support.annotation.Nullable; | ||
import android.support.v7.app.AppCompatActivity; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import jie.com.funnellib.CustomLabelCallback; | ||
import jie.com.funnellib.FunnelView; | ||
import jie.com.funnellib.Util; | ||
|
||
/** | ||
* Created by hj on 2019/2/25. | ||
* 说明:此Activity演示自定义描述文字 | ||
*/ | ||
public class CustomLabelActivity extends BaseFunnelActivity { | ||
|
||
@Override | ||
void initEvent(FunnelView funnelView) { | ||
final List<FunnelData> data = FunnelData.getFourCountData(); | ||
|
||
funnelView.addCustomLabelCallback(new CustomLabelCallback() { | ||
@Override | ||
public void drawText(Canvas canvas, Paint mPaintLabel, float labelX, float labelY, int index) { | ||
FunnelData funnelData = data.get(index); | ||
//先画前面的文字 | ||
mPaintLabel.setColor(funnelData.color); | ||
mPaintLabel.setFakeBoldText(false); | ||
canvas.drawText(funnelData.getLabel()+":", labelX, labelY, mPaintLabel); | ||
//计算前面文字的长度 | ||
float labelWidth = Util.getTextWidth(mPaintLabel,funnelData.getLabel()+":"); | ||
mPaintLabel.setColor(Color.parseColor("#333333")); | ||
mPaintLabel.setFakeBoldText(true); | ||
//画后面的文字 | ||
canvas.drawText(funnelData.num+"个", labelX + labelWidth, labelY, mPaintLabel); | ||
} | ||
}); | ||
funnelView.setChartData(data); | ||
} | ||
} |
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,16 @@ | ||
package jie.com.funnel; | ||
|
||
|
||
import jie.com.funnellib.FunnelView; | ||
|
||
/** | ||
* Created by hj on 2019/2/25. | ||
* 说明:使用默认方式创建一个漏斗 | ||
*/ | ||
public class DefaultActivity extends BaseFunnelActivity { | ||
|
||
@Override | ||
void initEvent(FunnelView funnelView) { | ||
funnelView.setChartData(FunnelData.getTenCountData()); | ||
} | ||
} |
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
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
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
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
Oops, something went wrong.