tuttelikz

Result Activity [v2] with One Color

Oct 31st, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 9.86 KB | None | 0 0
  1. package com.example.iptea.audio22;
  2.  
  3. import android.content.Intent;
  4. import android.graphics.Color;
  5. import android.graphics.Paint;
  6. import android.support.v7.app.AppCompatActivity;
  7. import android.os.Bundle;
  8. import android.view.View;
  9. import android.widget.Button;
  10. import android.widget.ImageView;
  11.  
  12. import com.github.mikephil.charting.charts.BarChart;
  13. import com.github.mikephil.charting.charts.CandleStickChart;
  14. import com.github.mikephil.charting.charts.HorizontalBarChart;
  15. import com.github.mikephil.charting.components.Legend;
  16. import com.github.mikephil.charting.components.XAxis;
  17. import com.github.mikephil.charting.components.YAxis;
  18. import com.github.mikephil.charting.data.BarData;
  19. import com.github.mikephil.charting.data.BarDataSet;
  20. import com.github.mikephil.charting.data.BarEntry;
  21. import com.github.mikephil.charting.data.CandleData;
  22. import com.github.mikephil.charting.data.CandleDataSet;
  23. import com.github.mikephil.charting.data.CandleEntry;
  24. import com.github.mikephil.charting.utils.ColorTemplate;
  25.  
  26. import java.sql.Array;
  27. import java.sql.Date;
  28. import java.text.ParseException;
  29. import java.text.SimpleDateFormat;
  30. import java.util.ArrayList;
  31. import java.util.Calendar;
  32. import java.util.List;
  33. import java.util.Random;
  34.  
  35. public class ResultActivity extends AppCompatActivity {
  36.     Button btShare;
  37.     /*HorizontalBarChart barChart;*/
  38.     CandleStickChart barChart;
  39.  
  40.     ArrayList<String> dates;
  41.     Random random;
  42.     ArrayList<BarEntry> barEntries;
  43.  
  44.     @Override
  45.     protected void onCreate(Bundle savedInstanceState) {
  46.         super.onCreate(savedInstanceState);
  47.         setContentView(R.layout.activity_result);
  48.         btShare = (Button)findViewById(R.id.shareButton);
  49.         /*barChart = (HorizontalBarChart) findViewById(R.id.barGraph);*/
  50.  
  51.  
  52.  
  53.  
  54. /*        barChart = (CandleStickChart) findViewById(R.id.barGraph);
  55.  
  56.         *//*createRandomBarGraph("2017/10/21", "2017/10/30");*//*
  57.         barChart.setTouchEnabled(true);
  58.         barChart.setDragEnabled(true);
  59.         barChart.setScaleEnabled(true);
  60.  
  61.  
  62.         List<CandleEntry> ceList = new ArrayList<>();
  63.         ceList.add(new CandleEntry(0, 4.62f, 2.02f, 2.70f, 4.13f));
  64.         ceList.add(new CandleEntry(1, 5.50f, 2.70f, 3.35f, 4.96f));
  65.         ceList.add(new CandleEntry(2, 5.25f, 3.02f, 3.50f, 4.50f));
  66.         ceList.add(new CandleEntry(3, 6f,    3.25f, 4.40f, 5.0f));
  67.         ceList.add(new CandleEntry(4, 5.57f, 2f,    2.80f, 4.5f));
  68.  
  69.  
  70.         CandleDataSet cds = new CandleDataSet(ceList, "Entries");
  71.         cds.setColor(Color.rgb(80, 80, 80));
  72.         cds.setShadowColor(Color.DKGRAY);
  73.         cds.setShadowWidth(0.7f);
  74.         cds.setDecreasingColor(Color.RED);
  75.         cds.setDecreasingPaintStyle(Paint.Style.FILL);
  76.         cds.setIncreasingColor(Color.rgb(122, 242, 84));
  77.         cds.setIncreasingPaintStyle(Paint.Style.STROKE);
  78.         cds.setNeutralColor(Color.BLUE);
  79.         cds.setValueTextColor(Color.RED);
  80.         *//*CandleData cd = new CandleData(cds);*//*
  81.         CandleData cd = new CandleDataSet(cds);
  82.         barChart.setData(cd);
  83.         barChart.invalidate();*/
  84.  
  85.  
  86.  
  87.  
  88.         CandleStickChart candleStickChart = (CandleStickChart) findViewById(R.id.barGraph);
  89.  
  90.  
  91.         ArrayList<CandleEntry> entries = new ArrayList<>();
  92.  
  93.         /*entries.add(new CandleEntry(0, 4.62f, 2.02f, 2.70f, 4.13f));*/
  94.         entries.add(new CandleEntry(0, 15000, 100, 100, 15000));
  95. /*        entries.add(new CandleEntry(1, 5.50f, 2.70f, 3.35f, 4.96f));
  96.         entries.add(new CandleEntry(2, 5.25f, 3.02f, 3.50f, 4.50f));
  97.         entries.add(new CandleEntry(3, 6f,    3.25f, 4.40f, 5.0f));
  98.         entries.add(new CandleEntry(4, 5.57f, 2f,    2.80f, 4.5f));*/
  99.  
  100.         CandleDataSet dataset = new CandleDataSet(entries, "Hearing Range");
  101.  
  102.         ArrayList<String> labels = new ArrayList<String>();
  103.         labels.add("January");
  104. /*        labels.add("February");
  105.         labels.add("March");
  106.         labels.add("April");
  107.         labels.add("May");
  108.         labels.add("June");*/
  109.  
  110.         CandleData data = new CandleData(labels, dataset);
  111.  
  112.  
  113.         candleStickChart.setData(data);
  114.         dataset.setColors(ColorTemplate.COLORFUL_COLORS); //
  115.         candleStickChart.setDescription("Radar Chart");
  116.         candleStickChart.animateY(5000);
  117.         dataset.setColor(Color.rgb(255,255,255));
  118.         data.setValueTextColor(Color.rgb(255,255,255));
  119.  
  120.  
  121.         candleStickChart.setDescription("");
  122.         Legend legend = candleStickChart.getLegend();
  123.         legend.setTextColor(Color.rgb(255,255,255));
  124.         legend.setTextSize(14);
  125.  
  126.         XAxis xAxis = candleStickChart.getXAxis();
  127.         xAxis.setTextColor(Color.rgb(255,255,255));
  128.         xAxis.setTextSize(14);
  129.  
  130.         YAxis yAxisLeft = candleStickChart.getAxisLeft();
  131.         yAxisLeft.setTextColor(Color.rgb(255,255,255));
  132.         yAxisLeft.setTextSize(14);
  133.  
  134.         YAxis yAxisRight = candleStickChart.getAxisRight();
  135.         yAxisRight.setTextColor(Color.rgb(255,255,255));
  136.         yAxisRight.setTextSize(14);
  137.  
  138.         yAxisRight.setAxisMaxValue(20000); // start at zero
  139.         yAxisRight.setAxisMinValue(0); // the axis maximum is 100
  140.         yAxisLeft.setAxisMaxValue(20000); // start at zero
  141.         yAxisLeft.setAxisMinValue(0); // the axis maximum is 100
  142.  
  143.         /*createRandomBarGraph(String date1, String date2);*/
  144.  
  145. /*        ArrayList<BarEntry> barEntries = new ArrayList<>();
  146.         barEntries.add(new BarEntry(44f,0));
  147.         barEntries.add(new BarEntry(88f,1));
  148.         barEntries.add(new BarEntry(66f,2));
  149.         barEntries.add(new BarEntry(12f,3));
  150.         barEntries.add(new BarEntry(19f,4));
  151.         barEntries.add(new BarEntry(91f,5));
  152.         BarDataSet barDataSet = new BarDataSet(barEntries,"Dates");
  153.  
  154.         ArrayList<String> theDates = new ArrayList<>();
  155.         theDates.add("April");
  156.         theDates.add("May");
  157.         theDates.add("June");
  158.         theDates.add("July");
  159.         theDates.add("August");
  160.         theDates.add("September");
  161.  
  162.         BarData theData = new BarData(theDates,barDataSet);
  163.         barChart.setData(theData);
  164.         barChart.setTouchEnabled(true);
  165.         barChart.setDragEnabled(true);
  166.         barChart.setScaleEnabled(true);*/
  167.  
  168.  
  169.         btShare.setOnClickListener(new View.OnClickListener() {
  170.             @Override
  171.             public void onClick(View view) {
  172.                 Intent myIntent = new Intent(Intent.ACTION_SEND);
  173.                 myIntent.setType("text/plain");
  174.                 String shareBody = "Your body";
  175.                 String shareSub = "Your subject";
  176.                 myIntent.putExtra(Intent.EXTRA_SUBJECT,shareSub);
  177.                 myIntent.putExtra(Intent.EXTRA_SUBJECT,shareBody);
  178.                 startActivity(Intent.createChooser(myIntent,"Share using"));
  179.             }
  180.         });
  181.     }
  182.  
  183.  
  184.     /*public void createRandomBarGraph(String Date1, String Date2){
  185.  
  186.         SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd");
  187.  
  188.         try {
  189.             java.util.Date date1 = simpleDateFormat.parse(Date1);
  190.             java.util.Date date2 = simpleDateFormat.parse(Date2);
  191.  
  192.             Calendar mDate1 = Calendar.getInstance();
  193.             Calendar mDate2 = Calendar.getInstance();
  194.             mDate1.clear();
  195.             mDate2.clear();
  196.  
  197.             mDate1.setTime(date1);
  198.             mDate2.setTime(date2);
  199.  
  200.  
  201.             dates = new ArrayList<>();
  202.             dates = getList(mDate1,mDate2);
  203.  
  204.             barEntries = new ArrayList<>();
  205.             float max = 0f;
  206.             float value = 0f;
  207.             random = new Random();
  208.             for(int j = 0; j< dates.size();j++){
  209.                 //max = 100f;
  210.                 max = 20000f;
  211.                 value = random.nextFloat()*max;
  212.                 barEntries.add(new BarEntry(value,j));
  213.             }
  214.  
  215.         }catch(ParseException e){
  216.             e.printStackTrace();
  217.         }
  218.  
  219.         BarDataSet barDataSet = new BarDataSet(barEntries,"Hearing Range");
  220.         BarData barData = new BarData(dates,barDataSet);
  221.         barDataSet.setColor(Color.rgb(255, 102, 153));
  222.         barDataSet.setValueTextColor(Color.rgb(255,255,255));
  223.         barDataSet.setHighlightEnabled(true);
  224.         barDataSet.setHighLightColor(Color.rgb(255,255,255));
  225.         barDataSet.setValueTextSize(14);
  226.  
  227.         barChart.setData(barData);
  228.         barChart.setDescription("");
  229.         Legend legend = barChart.getLegend();
  230.         legend.setTextColor(Color.rgb(255,255,255));
  231.         legend.setTextSize(14);
  232.  
  233.         XAxis xAxis = barChart.getXAxis();
  234.         xAxis.setTextColor(Color.rgb(255,255,255));
  235.         xAxis.setTextSize(14);
  236.  
  237.         YAxis yAxisUp = barChart.getAxisLeft();
  238.         yAxisUp.setTextColor(Color.rgb(255,255,255));
  239.         yAxisUp.setTextSize(14);
  240.  
  241.         YAxis yAxisBot = barChart.getAxisRight();
  242.         yAxisUp.setTextColor(Color.rgb(255,255,255));
  243.         yAxisUp.setTextSize(14);
  244.  
  245.     }
  246.  
  247.     public ArrayList<String> getList(Calendar startDate, Calendar endDate){
  248.         ArrayList<String> list = new ArrayList<String>();
  249.         while(startDate.compareTo(endDate)<=0){
  250.             list.add(getDate(startDate));
  251.             startDate.add(Calendar.DAY_OF_MONTH,1);
  252.         }
  253.         return list;
  254.     }
  255.  
  256.     public String getDate(Calendar cld){
  257.         *//*String curDate = cld.get(Calendar.YEAR) + "/" + (cld.get(Calendar.MONTH) + 1) + "/"
  258.                 +cld.get(Calendar.DAY_OF_MONTH);*//*
  259.         String curDate = (cld.get(Calendar.MONTH) + 1) + "/"
  260.                 +cld.get(Calendar.DAY_OF_MONTH);
  261.         try{
  262.             *//*java.util.Date date = new SimpleDateFormat("yy/MM/dd").parse(curDate);
  263.             curDate =  new SimpleDateFormat("yy/MM/dd").format(date);*//*
  264.             java.util.Date date = new SimpleDateFormat("MM/dd").parse(curDate);
  265.             curDate =  new SimpleDateFormat("MM/dd").format(date);
  266.         }catch(ParseException e){
  267.             e.printStackTrace();
  268.         }
  269.         return curDate;
  270.     }*/
  271.  
  272. }
Advertisement
Add Comment
Please, Sign In to add comment