温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

cc_美团 评论使用GitHut水平条开源项目事项

发布时间:2020-06-15 09:53:29 来源:网络 阅读:749 作者:愚人cc 栏目:移动开发

cc_美团 评论使用GitHut水平条开源项目事项


package com.chencheng.meituan.view;


import java.util.ArrayList;

import java.util.List;

import com.android.volley.VolleyError;

import com.chencheng.meituan.util.MeituanConstants;

import com.chencheng.model.detail.XComment;

import com.chencheng.model.detail.XItem;

import com.chencheng.model.detail.Xiangqing;

import com.github.mikephil.charting.charts.HorizontalBarChart;

import com.github.mikephil.charting.data.BarData;

import com.github.mikephil.charting.data.BarDataSet;

import com.github.mikephil.charting.data.BarEntry;

import com.github.mikephil.charting.utils.Legend;

import com.github.mikephil.charting.utils.Legend.LegendPosition;

import com.github.mikephil.charting.utils.XLabels;

import com.github.mikephil.charting.utils.XLabels.XLabelPosition;

import com.github.mikephil.charting.utils.YLabels;

import com.github.mikephil.charting.utils.YLabels.YLabelPosition;

import com.github.volley.MyVolley;

import com.github.volley.VolleyListener;

import com.xinbo.utils.GsonUtils;

import com.xinbo.widget.ListView4ScrollView;

import com.yuchen.meituan.R;

import com.yuchen.meituan.R.id;

import com.yuchen.meituan.R.layout;

import com.yuchen.meituan.R.menu;


import android.app.Activity;

import android.graphics.Color;

import android.os.Bundle;

import android.provider.SyncStateContract.Constants;

import android.view.Menu;

import android.view.MenuItem;

import android.view.View;

import android.view.View.OnClickListener;

import android.view.ViewGroup;

import android.widget.BaseAdapter;

import android.widget.TextView;


public class CommentActivity extends Activity implements OnClickListener {


protected String[] mLevels = new String[] { "1星", "2星", "3星", "4星", "5星", };

private List<XItem> mCommetnList = new ArrayList<XItem>();

private HorizontalBarChart mChart;

private MyListAdapter mAdapter;


@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_comment);

initUI();

initChart();

getJson();

}

private void getJson() {

MyVolley.get(this, MeituanConstants.UrlPath.XIANGQING, new VolleyListener() {

@Override

public void onErrorResponse(VolleyError arg0) {

arg0.getMessage();

}


@Override

public void onResponse(String arg0) {

parseJson(arg0);

}

});

}


protected void parseJson(String arg0) {

Xiangqing xiangqingInfo = GsonUtils.parseJSON(arg0, Xiangqing.class);

XComment comment = xiangqingInfo.getComment();

mCommetnList.addAll(comment.getItems());

mAdapter.notifyDataSetChanged();

}

private void initUI() {

findViewById(R.id.back_btn).setOnClickListener(this);

ListView4ScrollView mListView = (ListView4ScrollView) findViewById(R.id.listView1);

mAdapter = new MyListAdapter();

mListView.setAdapter(mAdapter);

}


class MyListAdapter extends BaseAdapter{


@Override

public View getView(int position, View convertView, ViewGroup parent) {

XItem item = mCommetnList.get(position);

View view = getLayoutInflater().inflate(

R.layout.listview_comment_item, null);

TextView tvUser = (TextView) view.findViewById(R.id.tv_user);

TextView tvTime = (TextView) view.findViewById(R.id.tv_time);

TextView tvContent = (TextView) view.findViewById(R.id.tv_content);

tvUser.setText(item.getUser_id());

tvTime.setText(item.getAdd_time());

tvContent.setText(item.getContent());

return view;

}

@Override

public int getCount() {

// TODO Auto-generated method stub

return mCommetnList.size();

}


@Override

public Object getItem(int position) {

// TODO Auto-generated method stub

return null;

}


@Override

public long getItemId(int position) {

// TODO Auto-generated method stub

return 0;

}

}

private void initChart() {

mChart = (HorizontalBarChart) findViewById(R.id.chart1);

mChart.setDrawBarShadow(false);

mChart.setDrawYValues(true);

mChart.setDrawValueAboveBar(false);


mChart.setDescription("");


mChart.setMaxVisibleValueCount(60);


mChart.set3DEnabled(false);


mChart.setPinchZoom(false);


mChart.setUnit(" ");


mChart.setDrawGridBackground(false);

mChart.setDrawHorizontalGrid(true);

mChart.setDrawVerticalGrid(false);


mChart.setValueTextSize(10f);


mChart.setDrawBorder(false);


//设置是否可以触摸,如为false,则不能拖动,缩放等  

        mChart.setTouchEnabled(false); 


// Typeface tf = Typeface.createFromAsset(getAssets(),

// "OpenSans-Regular.ttf");


XLabels xl = mChart.getXLabels();

xl.setPosition(XLabelPosition.BOTTOM);

xl.setCenterXLabelText(true);

// xl.setSpaceBetweenLabels(30); // 设置数据之间的间距  

// xl.setTypeface(tf);


YLabels yl = mChart.getYLabels();

// yl.setTypeface(tf);

yl.setLabelCount(8);

yl.setPosition(YLabelPosition.BOTH_SIDED);

// yl.setLabelCount(5); // 设置Y轴最多显示的数据个数  

// mChart.setValueTypeface(tf);


setData(5, 10);


Legend l = mChart.getLegend();

l.setPosition(LegendPosition.BELOW_CHART_LEFT);

l.setFormSize(8f);

l.setXEntrySpace(4f);

}


private void setData(int count, float range) {


ArrayList<String> xVals = new ArrayList<String>();

for (int i = 0; i < count; i++) {

xVals.add(mLevels[i]);

}


ArrayList<BarEntry> yVals1 = new ArrayList<BarEntry>();


for (int i = 0; i < count; i++) {

float mult = (range + 1);

float val = (float) (Math.random() * 40);

yVals1.add(new BarEntry(val, i));

}


BarDataSet set1 = new BarDataSet(yVals1, "水平分布图");

set1.setBarSpacePercent(35f);

set1.setColor(Color.rgb(252, 131, 2));//设置曲线的颜色


ArrayList<BarDataSet> dataSets = new ArrayList<BarDataSet>();

dataSets.add(set1);


BarData data = new BarData(xVals, dataSets);


mChart.setData(data);

}


@Override

public void onClick(View v) {

switch (v.getId()) {

case R.id.back_btn:

finish();

break;


default:

break;

}

}


@Override

protected void onDestroy() {

super.onDestroy();

}

@Override

public boolean onCreateOptionsMenu(Menu menu) {

getMenuInflater().inflate(R.menu.comment, menu);

return false;

}

}


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI