tuttelikz

Result Activity

Oct 31st, 2017
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.21 KB | None | 0 0
  1. package com.example.iptea.audio22;
  2.  
  3. import android.content.Intent;
  4. import android.graphics.Color;
  5. import android.support.v7.app.AppCompatActivity;
  6. import android.os.Bundle;
  7. import android.view.View;
  8. import android.widget.Button;
  9. import android.widget.ImageView;
  10.  
  11. import com.github.mikephil.charting.charts.BarChart;
  12. import com.github.mikephil.charting.charts.HorizontalBarChart;
  13. import com.github.mikephil.charting.components.Legend;
  14. import com.github.mikephil.charting.components.XAxis;
  15. import com.github.mikephil.charting.components.YAxis;
  16. import com.github.mikephil.charting.data.BarData;
  17. import com.github.mikephil.charting.data.BarDataSet;
  18. import com.github.mikephil.charting.data.BarEntry;
  19.  
  20. import java.sql.Array;
  21. import java.sql.Date;
  22. import java.text.ParseException;
  23. import java.text.SimpleDateFormat;
  24. import java.util.ArrayList;
  25. import java.util.Calendar;
  26. import java.util.Random;
  27.  
  28. public class ResultActivity extends AppCompatActivity {
  29.     Button btShare;
  30.     HorizontalBarChart barChart;
  31.  
  32.     ArrayList<String> dates;
  33.     Random random;
  34.     ArrayList<BarEntry> barEntries;
  35.  
  36.     @Override
  37.     protected void onCreate(Bundle savedInstanceState) {
  38.         super.onCreate(savedInstanceState);
  39.         setContentView(R.layout.activity_result);
  40.         btShare = (Button)findViewById(R.id.shareButton);
  41.         barChart = (HorizontalBarChart) findViewById(R.id.barGraph);
  42.  
  43.         createRandomBarGraph("2017/10/21", "2017/10/30");
  44.         barChart.setTouchEnabled(true);
  45.         barChart.setDragEnabled(true);
  46.         barChart.setScaleEnabled(true);
  47.  
  48.         /*createRandomBarGraph(String date1, String date2);*/
  49.  
  50. /*        ArrayList<BarEntry> barEntries = new ArrayList<>();
  51.         barEntries.add(new BarEntry(44f,0));
  52.         barEntries.add(new BarEntry(88f,1));
  53.         barEntries.add(new BarEntry(66f,2));
  54.         barEntries.add(new BarEntry(12f,3));
  55.         barEntries.add(new BarEntry(19f,4));
  56.         barEntries.add(new BarEntry(91f,5));
  57.         BarDataSet barDataSet = new BarDataSet(barEntries,"Dates");
  58.  
  59.         ArrayList<String> theDates = new ArrayList<>();
  60.         theDates.add("April");
  61.         theDates.add("May");
  62.         theDates.add("June");
  63.         theDates.add("July");
  64.         theDates.add("August");
  65.         theDates.add("September");
  66.  
  67.         BarData theData = new BarData(theDates,barDataSet);
  68.         barChart.setData(theData);
  69.         barChart.setTouchEnabled(true);
  70.         barChart.setDragEnabled(true);
  71.         barChart.setScaleEnabled(true);*/
  72.  
  73.  
  74.         btShare.setOnClickListener(new View.OnClickListener() {
  75.             @Override
  76.             public void onClick(View view) {
  77.                 Intent myIntent = new Intent(Intent.ACTION_SEND);
  78.                 myIntent.setType("text/plain");
  79.                 String shareBody = "Your body";
  80.                 String shareSub = "Your subject";
  81.                 myIntent.putExtra(Intent.EXTRA_SUBJECT,shareSub);
  82.                 myIntent.putExtra(Intent.EXTRA_SUBJECT,shareBody);
  83.                 startActivity(Intent.createChooser(myIntent,"Share using"));
  84.             }
  85.         });
  86.     }
  87.  
  88.  
  89.     public void createRandomBarGraph(String Date1, String Date2){
  90.  
  91.         SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd");
  92.  
  93.         try {
  94.             java.util.Date date1 = simpleDateFormat.parse(Date1);
  95.             java.util.Date date2 = simpleDateFormat.parse(Date2);
  96.  
  97.             Calendar mDate1 = Calendar.getInstance();
  98.             Calendar mDate2 = Calendar.getInstance();
  99.             mDate1.clear();
  100.             mDate2.clear();
  101.  
  102.             mDate1.setTime(date1);
  103.             mDate2.setTime(date2);
  104.  
  105.  
  106.             dates = new ArrayList<>();
  107.             dates = getList(mDate1,mDate2);
  108.  
  109.             barEntries = new ArrayList<>();
  110.             float max = 0f;
  111.             float value = 0f;
  112.             random = new Random();
  113.             for(int j = 0; j< dates.size();j++){
  114.                 //max = 100f;
  115.                 max = 20000f;
  116.                 value = random.nextFloat()*max;
  117.                 barEntries.add(new BarEntry(value,j));
  118.             }
  119.  
  120.         }catch(ParseException e){
  121.             e.printStackTrace();
  122.         }
  123.  
  124.         BarDataSet barDataSet = new BarDataSet(barEntries,"Hearing Range");
  125.         BarData barData = new BarData(dates,barDataSet);
  126.         barDataSet.setColor(Color.rgb(255, 102, 153));
  127.         barDataSet.setValueTextColor(Color.rgb(255,255,255));
  128.         barDataSet.setHighlightEnabled(true);
  129.         barDataSet.setHighLightColor(Color.rgb(255,255,255));
  130.         barDataSet.setValueTextSize(14);
  131.  
  132.         barChart.setData(barData);
  133.         barChart.setDescription("");
  134.         Legend legend = barChart.getLegend();
  135.         legend.setTextColor(Color.rgb(255,255,255));
  136.         legend.setTextSize(14);
  137.  
  138.         XAxis xAxis = barChart.getXAxis();
  139.         xAxis.setTextColor(Color.rgb(255,255,255));
  140.         xAxis.setTextSize(14);
  141.  
  142.         YAxis yAxisUp = barChart.getAxisLeft();
  143.         yAxisUp.setTextColor(Color.rgb(255,255,255));
  144.         yAxisUp.setTextSize(14);
  145.  
  146.         YAxis yAxisBot = barChart.getAxisRight();
  147.         yAxisUp.setTextColor(Color.rgb(255,255,255));
  148.         yAxisUp.setTextSize(14);
  149.  
  150.     }
  151.  
  152.     public ArrayList<String> getList(Calendar startDate, Calendar endDate){
  153.         ArrayList<String> list = new ArrayList<String>();
  154.         while(startDate.compareTo(endDate)<=0){
  155.             list.add(getDate(startDate));
  156.             startDate.add(Calendar.DAY_OF_MONTH,1);
  157.         }
  158.         return list;
  159.     }
  160.  
  161.     public String getDate(Calendar cld){
  162.         /*String curDate = cld.get(Calendar.YEAR) + "/" + (cld.get(Calendar.MONTH) + 1) + "/"
  163.                 +cld.get(Calendar.DAY_OF_MONTH);*/
  164.         String curDate = (cld.get(Calendar.MONTH) + 1) + "/"
  165.                 +cld.get(Calendar.DAY_OF_MONTH);
  166.         try{
  167.             /*java.util.Date date = new SimpleDateFormat("yy/MM/dd").parse(curDate);
  168.             curDate =  new SimpleDateFormat("yy/MM/dd").format(date);*/
  169.             java.util.Date date = new SimpleDateFormat("MM/dd").parse(curDate);
  170.             curDate =  new SimpleDateFormat("MM/dd").format(date);
  171.         }catch(ParseException e){
  172.             e.printStackTrace();
  173.         }
  174.         return curDate;
  175.     }
  176.  
  177. }
Advertisement
Add Comment
Please, Sign In to add comment