动态曲线,K线
2019-04-28 本文已影响0人
it奔跑在路上
安卓大部分图库,如曲线,扇形图,矩形图,都是基于 MPAndroidChart 进行开发。此项目暂未采用。
GIF.gif单独lib包下载地址:https://share.weiyun.com/5iYKptT
整个项目下载地址:https://share.weiyun.com/5iFDH6V
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent"
tools:context="com.example.dynamicklinedemo.MainActivity">
<com.tophold.trade.view.kview.KView
android:id="@+id/fk_kv_kview"
android:layout_width="match_parent"
android:layout_height="278dp"
android:background="#1B314A" />
</LinearLayout>
public class MainActivity extends AppCompatActivity {
private KView mFkKvKview;
private Timer timerToRequest;
private ArrayList<Quotes> mQuotesList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
initData();
}
private void initData() {
mQuotesList = new ArrayList<>();
loadKLineData();
subKLineData();
}
private void initView() {
mFkKvKview = (KView) findViewById(R.id.fk_kv_kview);
mFkKvKview.setDigit(2);
mFkKvKview.setShowTimSharing(true);
mFkKvKview.setShowMinor(false);
mFkKvKview.setShowVol(false);
}
private void loadKLineData() {
adapterData();
runOnUiThread(new Runnable() {
@Override
public void run() {
drawKView(false);
}
});
}
private void adapterData() {
List<Quotes> quotesList = new ArrayList<>();
Random random = new Random();
//这里写一个随机数,模拟100条数据
for (int i = 0; i < 100; i++) {
double num = random.nextInt(100) + 33690;
Quotes quotes = new Quotes(num,num,num,num,System.currentTimeMillis());
quotesList.add(quotes);
}
mQuotesList.addAll(0, quotesList);
}
private void drawKView(boolean isLoadMore) {
if (!isLoadMore) {
mFkKvKview.setKViewData(mQuotesList, new KViewListener.MasterTouchListener() {
@Override
public void onLongTouch(Quotes preQuotes, Quotes currentQuotes) {
}
@Override
public void onUnLongTouch() {
}
@Override
public void needLoadMore() {
if (StringUtils.isEmpty(mQuotesList)) {
mFkKvKview.loadMoreNoData();
return;
}
}
});
} else {
mFkKvKview.loadKViewData(mQuotesList);
Log.d("6666666661", mQuotesList.toString());
}
}
private void subKLineData() {
//这里写一个随机数,模拟数据
timerToRequest = new Timer();
timerToRequest.schedule(new TimerTask() {
@Override
public void run() {
// loadKLineData(null, false,HttpManager.REQUEST_NAME_OPTION_KLINEINFO);
runOnUiThread(new Runnable() {
@Override
public void run() {
Random random = new Random();
double num = random.nextInt(100) + 33690;
double num1 = random.nextInt(100) + 33690;
double num2 = random.nextInt(100) + 33690;
double num3 = random.nextInt(100) + 33690;
// i++;
Quotes quotes = new Quotes(num, num1, num2, num3, System.currentTimeMillis());
mFkKvKview.pushKViewData(quotes, 500);
}
});
}
}, 0, 1000);
}
@Override
protected void onStop() {
super.onStop();
if (timerToRequest != null) {
timerToRequest.cancel();
}
}