Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.iptea.audio22;
- import android.content.Intent;
- import android.graphics.Color;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- import android.widget.ImageView;
- import com.github.mikephil.charting.charts.BarChart;
- import com.github.mikephil.charting.charts.HorizontalBarChart;
- import com.github.mikephil.charting.components.Legend;
- import com.github.mikephil.charting.components.XAxis;
- import com.github.mikephil.charting.components.YAxis;
- import com.github.mikephil.charting.data.BarData;
- import com.github.mikephil.charting.data.BarDataSet;
- import com.github.mikephil.charting.data.BarEntry;
- import java.sql.Array;
- import java.sql.Date;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Calendar;
- import java.util.Random;
- public class ResultActivity extends AppCompatActivity {
- Button btShare;
- HorizontalBarChart barChart;
- ArrayList<String> dates;
- Random random;
- ArrayList<BarEntry> barEntries;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_result);
- btShare = (Button)findViewById(R.id.shareButton);
- barChart = (HorizontalBarChart) findViewById(R.id.barGraph);
- createRandomBarGraph("2017/10/21", "2017/10/30");
- barChart.setTouchEnabled(true);
- barChart.setDragEnabled(true);
- barChart.setScaleEnabled(true);
- /*createRandomBarGraph(String date1, String date2);*/
- /* ArrayList<BarEntry> barEntries = new ArrayList<>();
- barEntries.add(new BarEntry(44f,0));
- barEntries.add(new BarEntry(88f,1));
- barEntries.add(new BarEntry(66f,2));
- barEntries.add(new BarEntry(12f,3));
- barEntries.add(new BarEntry(19f,4));
- barEntries.add(new BarEntry(91f,5));
- BarDataSet barDataSet = new BarDataSet(barEntries,"Dates");
- ArrayList<String> theDates = new ArrayList<>();
- theDates.add("April");
- theDates.add("May");
- theDates.add("June");
- theDates.add("July");
- theDates.add("August");
- theDates.add("September");
- BarData theData = new BarData(theDates,barDataSet);
- barChart.setData(theData);
- barChart.setTouchEnabled(true);
- barChart.setDragEnabled(true);
- barChart.setScaleEnabled(true);*/
- btShare.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- Intent myIntent = new Intent(Intent.ACTION_SEND);
- myIntent.setType("text/plain");
- String shareBody = "Your body";
- String shareSub = "Your subject";
- myIntent.putExtra(Intent.EXTRA_SUBJECT,shareSub);
- myIntent.putExtra(Intent.EXTRA_SUBJECT,shareBody);
- startActivity(Intent.createChooser(myIntent,"Share using"));
- }
- });
- }
- public void createRandomBarGraph(String Date1, String Date2){
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd");
- try {
- java.util.Date date1 = simpleDateFormat.parse(Date1);
- java.util.Date date2 = simpleDateFormat.parse(Date2);
- Calendar mDate1 = Calendar.getInstance();
- Calendar mDate2 = Calendar.getInstance();
- mDate1.clear();
- mDate2.clear();
- mDate1.setTime(date1);
- mDate2.setTime(date2);
- dates = new ArrayList<>();
- dates = getList(mDate1,mDate2);
- barEntries = new ArrayList<>();
- float max = 0f;
- float value = 0f;
- random = new Random();
- for(int j = 0; j< dates.size();j++){
- //max = 100f;
- max = 20000f;
- value = random.nextFloat()*max;
- barEntries.add(new BarEntry(value,j));
- }
- }catch(ParseException e){
- e.printStackTrace();
- }
- BarDataSet barDataSet = new BarDataSet(barEntries,"Hearing Range");
- BarData barData = new BarData(dates,barDataSet);
- barDataSet.setColor(Color.rgb(255, 102, 153));
- barDataSet.setValueTextColor(Color.rgb(255,255,255));
- barDataSet.setHighlightEnabled(true);
- barDataSet.setHighLightColor(Color.rgb(255,255,255));
- barDataSet.setValueTextSize(14);
- barChart.setData(barData);
- barChart.setDescription("");
- Legend legend = barChart.getLegend();
- legend.setTextColor(Color.rgb(255,255,255));
- legend.setTextSize(14);
- XAxis xAxis = barChart.getXAxis();
- xAxis.setTextColor(Color.rgb(255,255,255));
- xAxis.setTextSize(14);
- YAxis yAxisUp = barChart.getAxisLeft();
- yAxisUp.setTextColor(Color.rgb(255,255,255));
- yAxisUp.setTextSize(14);
- YAxis yAxisBot = barChart.getAxisRight();
- yAxisUp.setTextColor(Color.rgb(255,255,255));
- yAxisUp.setTextSize(14);
- }
- public ArrayList<String> getList(Calendar startDate, Calendar endDate){
- ArrayList<String> list = new ArrayList<String>();
- while(startDate.compareTo(endDate)<=0){
- list.add(getDate(startDate));
- startDate.add(Calendar.DAY_OF_MONTH,1);
- }
- return list;
- }
- public String getDate(Calendar cld){
- /*String curDate = cld.get(Calendar.YEAR) + "/" + (cld.get(Calendar.MONTH) + 1) + "/"
- +cld.get(Calendar.DAY_OF_MONTH);*/
- String curDate = (cld.get(Calendar.MONTH) + 1) + "/"
- +cld.get(Calendar.DAY_OF_MONTH);
- try{
- /*java.util.Date date = new SimpleDateFormat("yy/MM/dd").parse(curDate);
- curDate = new SimpleDateFormat("yy/MM/dd").format(date);*/
- java.util.Date date = new SimpleDateFormat("MM/dd").parse(curDate);
- curDate = new SimpleDateFormat("MM/dd").format(date);
- }catch(ParseException e){
- e.printStackTrace();
- }
- return curDate;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment