List of usage examples for java.util Date getMonth
@Deprecated public int getMonth()
From source file:mtis.CreateDisplayJson.java
public String getJson(String city, String duration) throws Exception { String finalReturn = ""; JSONArray list = new JSONArray(); JSONObject finalObj = new JSONObject(); ArrayList<String> month = new ArrayList<String>(); month.add("Jan"); month.add("Feb"); month.add("Mar"); month.add("Apr"); month.add("May"); month.add("Jun"); month.add("Jul"); month.add("Aug"); month.add("Sep"); month.add("Oct"); month.add("Nov"); month.add("Dec"); Date d = new Date(); int dayCount = Integer.parseInt(duration); Long dL = d.getTime();/*from www . j ava 2s .c o m*/ FileReader fr = new FileReader( "C:\\Users\\Server\\Documents\\twitterData\\" + city + "\\traffic_data_" + city + "_display.txt"); BufferedReader br = new BufferedReader(fr); String line = br.readLine(); StringBuffer text = new StringBuffer(); while (line != null) { text.append(line); line = br.readLine(); } String textData = text.toString(); textData = textData.replaceAll("\\n", " "); String fullTokens[] = textData.split("\\$\\$\\$"); for (int i = fullTokens.length - 1; i >= 1; i--) { StringTokenizer st = new StringTokenizer(fullTokens[i], "||"); String dateString = st.nextToken(); Date date = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy").parse(dateString); Long dateL = date.getTime(); //System.out.println(dateL); String name = st.nextToken(); name = name.replaceAll("'", " "); if (dL - ((dayCount + 1) * 86400 * 1000) <= dateL && dateL <= dL - ((dayCount) * 86400 * 1000)) { //System.out.println("i am in"); JSONObject js = new JSONObject(); js.put("userScreenName", name); System.out.println(name); js.put("userProfilePic", st.nextToken()); js.put("userId", st.nextToken()); js.put("statusId", st.nextToken()); js.put("username", st.nextToken()); js.put("text", st.nextToken()); SimpleDateFormat format = new SimpleDateFormat("hh:mm a "); //System.out.println(format.format(date)); //System.out.println(date.getDate()+"-"+month.get(date.getMonth())+" "+format.format(date)); //System.out.println(dateL); js.put("time", date.getDate() + "-" + month.get(date.getMonth()) + " " + format.format(date)); list.add(js); } line = br.readLine(); } finalObj.put("locations", list); br.close(); finalReturn = finalObj.toString(); System.out.println(finalReturn); return finalReturn; }
From source file:voldemort.store.cachestore.impl.CacheStore.java
public void backup(String path, int threshold) { packLock.lock();/* ww w. j ava 2s. com*/ try { checkPath(path); Date date = new Date(); String filename = path + "/" + getNamePrefix() + getCurIndex() + "." + date.getMonth() + "." + date.getDate() + "." + date.getHours() + "." + date.getMinutes(); backupTask = new BackupThread(this, curIndex, filename); backupTask.run(); //new BackupThread(this, curIndex, filename).start(threshold); } finally { packLock.unlock(); } }
From source file:org.ms123.common.data.query.JPASelectBuilderPostgresql.java
protected Object getDate(Object data, Map<String, Object> rule) { try {/*from w ww .j ava 2 s .c o m*/ Date d = new Date(); try { if (data instanceof Long) { d = new Date((Long) data); } else { d = new Date(Long.valueOf((String) rule.get("data"))); } } catch (Exception e) { try { if (data instanceof String) { d = new SimpleDateFormat( (((String) data).indexOf("T") > 0) ? "yyyy-MM-dd'T'HH:mm" : "yyyy-MM-dd") .parse((String) data, new ParsePosition(0)); if (d == null) d = new Date(); } } catch (Exception e1) { System.out.println("E:" + e); } } String op = (String) rule.get("op"); if (op.equals("eq") || op.equals("ceq") || op.equals("neq")) { String day = d.getDate() + ""; String month = d.getMonth() + ""; String year = (d.getYear() + 1900) + ""; data = day + "/" + month + "/" + year; } else if (op.equals("in") || op.equals("inn")) { } else { int paramCount = m_queryBuilder.getParamCount(); data = ":param" + paramCount; System.out.println("param" + paramCount + ":" + d); m_queryBuilder.getQueryParams().put("param" + paramCount, d); m_queryBuilder.incParamCount(); } } catch (Exception e) { e.printStackTrace(); data = "''"; } return data; }
From source file:palamarchuk.smartlife.app.RegisterActivity.java
@Override protected Dialog onCreateDialog(int id) { switch (id) { case DATE_PICKER: Date date = new Date(); return new DatePickerDialog(this, R.style.AppTheme, new DatePickerDialog.OnDateSetListener() { @Override/*from w w w . ja v a 2s . c om*/ public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy"); SimpleDateFormat toServer = new SimpleDateFormat("yyyy-MM-dd"); Calendar calendar = new GregorianCalendar(year, monthOfYear, dayOfMonth); birthDateToServer = toServer.format(calendar.getTime()); birthDate.setText(sdf.format(calendar.getTime())); } }, date.getYear() + 1900, date.getMonth(), date.getDate()); } return null; }
From source file:com.progym.custom.fragments.WaterProgressYearlyLineFragment.java
public void setLineData3(final Date date, final boolean isLeftIn) { final ProgressDialog ringProgressDialog = ProgressDialog.show(getActivity(), getResources().getString(R.string.please_wait), getResources().getString(R.string.populating_data), true);/*from w ww . ja va 2s . c o m*/ ringProgressDialog.setCancelable(true); new Thread(new Runnable() { @Override public void run() { try { int yMaxAxisValue = 0; getActivity().runOnUiThread(new Runnable() { @Override public void run() { try { rlRootGraphLayout.removeView(mChartView); } catch (Exception edsx) { edsx.printStackTrace(); } } }); DATE = date; // 31 - Amount of days in a month int daysInMonth = Utils.getDaysInMonth(date.getMonth(), Integer.valueOf(Utils.formatDate(date, DataBaseUtils.DATE_PATTERN_YYYY))); // set January as first month date.setMonth(0); date.setDate(1); int[] x = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; // Creating an XYSeries for Consumed water XYSeries consumedSeries = new XYSeries("Consumed"); List<WaterConsumed> list; // int userShouldConsume = (int) DataBaseUtils.getWaterUserShouldConsumePerDay(); Date dt = date; // * // Adding data to Income and Expense Series for (int i = 0; i < x.length; i++) { // get all water records consumed per this month list = DataBaseUtils.getAllWaterConsumedInMonth( Utils.formatDate(dt, DataBaseUtils.DATE_PATTERN_YYYY_MM)); // init "average" data int averageWaterConsumedOnYaxis = 0; for (int j = 0; j < list.size(); j++) { // calculate sum of all water consumed by user in a month averageWaterConsumedOnYaxis += list.get(j).volumeConsumed; } averageWaterConsumedOnYaxis = averageWaterConsumedOnYaxis / daysInMonth; consumedSeries.add(i, averageWaterConsumedOnYaxis); // normaSeries.add(i, userShouldConsume); dt = DateUtils.addMonths(dt, 1); yMaxAxisValue = Math.max(yMaxAxisValue, averageWaterConsumedOnYaxis); } // Creating a dataset to hold each series final XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset(); // Adding Expense Series to dataset // dataset.addSeries(normaSeries); // Adding Income Series to the dataset dataset.addSeries(consumedSeries); // Creating XYSeriesRenderer to customize incomeSeries XYSeriesRenderer incomeRenderer = new XYSeriesRenderer(); incomeRenderer.setColor(Color.rgb(50, 255, 50)); incomeRenderer.setFillPoints(true); incomeRenderer.setLineWidth(2); incomeRenderer.setDisplayChartValues(true); /* * // Creating XYSeriesRenderer to customize expenseSeries * XYSeriesRenderer expenseRenderer = new XYSeriesRenderer(); * expenseRenderer.setColor(Color.rgb(80, 220, 80)); * expenseRenderer.setFillPoints(true); * expenseRenderer.setLineWidth(2); * expenseRenderer.setDisplayChartValues(true); */ // Creating a XYMultipleSeriesRenderer to customize the whole chart final XYMultipleSeriesRenderer multiRenderer = new XYMultipleSeriesRenderer(); multiRenderer.setXLabels(0); for (int i = 0; i < x.length; i++) { multiRenderer.addXTextLabel(i, ActivityWaterProgress.months_short[i]); } // Adding incomeRenderer and expenseRenderer to multipleRenderer // Note: The order of adding dataseries to dataset and renderers to multipleRenderer // should be same multiRenderer.setChartTitle(String.format("Water statistic for %s year", Utils.formatDate(DATE, DataBaseUtils.DATE_PATTERN_YYYY))); multiRenderer.setXTitle("Months"); multiRenderer.setYTitle("Water volume (ml)"); multiRenderer.setAxesColor(Color.WHITE); multiRenderer.setShowLegend(true); multiRenderer.addSeriesRenderer(incomeRenderer); multiRenderer.setShowGrid(true); multiRenderer.setClickEnabled(true); // multiRenderer.addSeriesRenderer(expenseRenderer); multiRenderer.setXLabelsAngle(30); // multiRenderer.setBackgroundColor(Color.parseColor("#B3FFFFFF")); // multiRenderer.setApplyBackgroundColor(true); multiRenderer.setXLabelsColor(Color.WHITE); multiRenderer.setZoomButtonsVisible(false); // configure visible area multiRenderer.setXAxisMax(11.5); multiRenderer.setXAxisMin(-0.5); multiRenderer.setYAxisMax(yMaxAxisValue + (yMaxAxisValue / 5)); multiRenderer.setYAxisMin(-0.1); multiRenderer.setAxisTitleTextSize(15); multiRenderer.setBarSpacing(0.1); multiRenderer.setZoomEnabled(true); getActivity().runOnUiThread(new Runnable() { @Override public void run() { mChartView = ChartFactory.getBarChartView(getActivity(), dataset, multiRenderer, Type.DEFAULT); rlRootGraphLayout.addView(mChartView, 0); if (isLeftIn) { rightIn.setDuration(1000); mChartView.startAnimation(rightIn); } else { leftIn.setDuration(1000); mChartView.startAnimation(leftIn); } } }); } catch (Exception e) { e.printStackTrace(); } ringProgressDialog.dismiss(); } }).start(); }
From source file:com.progym.custom.fragments.CalloriesProgressMonthlyLineFragment.java
public void setLineData3(final Date date, final boolean isLeftIn) { final ProgressDialog ringProgressDialog = ProgressDialog.show(getActivity(), getResources().getString(R.string.please_wait), getResources().getString(R.string.populating_data), true);/*ww w. ja va2 s. com*/ ringProgressDialog.setCancelable(true); new Thread(new Runnable() { @Override public void run() { try { int yMaxAxisValue = 0; try { getActivity().runOnUiThread(new Runnable() { @Override public void run() { rlRootGraphLayout.removeView(mChartView); } }); } catch (Exception edsx) { edsx.printStackTrace(); } date.setDate(1); DATE = date; // Get amount of days in a month to find out average int daysInMonth = Utils.getDaysInMonth(date.getMonth(), Integer.valueOf(Utils.formatDate(date, DataBaseUtils.DATE_PATTERN_YYYY))); // set First day of the month as first month int[] x = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 }; // Creating an XYSeries for Consumed water XYSeries callories = new XYSeries("Callories"); List<Ingridient> list; Date dt = date; // ** // Adding data to Income and Expense Series for (int i = 1; i <= daysInMonth; i++) { // get all water records consumed per this month list = DataBaseUtils.getAllFoodConsumedInMonth( Utils.formatDate(dt, DataBaseUtils.DATE_PATTERN_YYYY_MM_DD)); // init "average" data int totalCallories = 0; for (Ingridient ingridient : list) { totalCallories += ingridient.kkal; } callories.add(i, totalCallories); dt = DateUtils.addDays(dt, 1); yMaxAxisValue = Math.max(yMaxAxisValue, totalCallories); } // Creating a dataset to hold each series final XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset(); // Adding Income Series to the dataset dataset.addSeries(callories); // Creating XYSeriesRenderer to customize protein series XYSeriesRenderer calloriesRenderer = new XYSeriesRenderer(); calloriesRenderer.setColor(Color.rgb(220, 255, 110)); calloriesRenderer.setFillPoints(true); calloriesRenderer.setLineWidth(3); calloriesRenderer.setDisplayChartValues(true); // Creating a XYMultipleSeriesRenderer to customize the whole chart final XYMultipleSeriesRenderer multiRenderer = new XYMultipleSeriesRenderer(); // multiRenderer.setXLabels(0); for (int i = 0; i < x.length; i++) { multiRenderer.addXTextLabel(i, String.valueOf(x[i])); } // Adding incomeRenderer and expenseRenderer to multipleRenderer // Note: The order of adding dataseries to dataset and renderers to multipleRenderer // should be same multiRenderer.setChartTitle(String.format("Callories statistic")); multiRenderer.setXTitle(Utils.getSpecificDateValue(DATE, "MMM") + " of " + Utils.formatDate(DATE, DataBaseUtils.DATE_PATTERN_YYYY)); multiRenderer.setYTitle(getActivity().getResources().getString(R.string.callories_consumption)); multiRenderer.setAxesColor(Color.WHITE); multiRenderer.setShowLegend(true); multiRenderer.addSeriesRenderer(calloriesRenderer); multiRenderer.setShowGrid(true); multiRenderer.setClickEnabled(true); multiRenderer.setXLabelsAngle(20); multiRenderer.setYAxisMax(yMaxAxisValue + 200); multiRenderer.setXLabelsColor(Color.WHITE); multiRenderer.setZoomButtonsVisible(false); // configure visible area multiRenderer.setXAxisMax(31); multiRenderer.setXAxisMin(1); multiRenderer.setAxisTitleTextSize(15); multiRenderer.setZoomEnabled(true); getActivity().runOnUiThread(new Runnable() { @Override public void run() { mChartView = ChartFactory.getLineChartView(getActivity(), dataset, multiRenderer); rlRootGraphLayout.addView(mChartView, 0); if (isLeftIn) { rightIn.setDuration(1000); mChartView.startAnimation(rightIn); } else { leftIn.setDuration(1000); mChartView.startAnimation(leftIn); } } }); } catch (Exception e) { e.printStackTrace(); } ringProgressDialog.dismiss(); } }).start(); }
From source file:com.progym.custom.fragments.CalloriesProgressYearlyLineFragment.java
public void setYearProgressData(final Date date, final boolean isLeftIn) { final ProgressDialog ringProgressDialog = ProgressDialog.show(getActivity(), getResources().getString(R.string.please_wait), getResources().getString(R.string.populating_data), true);//w w w .ja v a 2s . c o m ringProgressDialog.setCancelable(true); new Thread(new Runnable() { @Override public void run() { try { int yMaxAxisValue = 0; getActivity().runOnUiThread(new Runnable() { @Override public void run() { try { rlRootGraphLayout.removeView(viewChart); } catch (Exception edsx) { edsx.printStackTrace(); } } }); DATE = date; // Get amount of days in a month to find out average int daysInMonth = Utils.getDaysInMonth(date.getMonth(), Integer.valueOf(Utils.formatDate(date, DataBaseUtils.DATE_PATTERN_YYYY))); // set January as first month date.setMonth(0); date.setDate(1); int[] x = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; final XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset(); CategorySeries seriesCallories = new CategorySeries("Callories"); List<Ingridient> list; Date dt = date; // * for (int element : x) { list = DataBaseUtils.getAllFoodConsumedInMonth( Utils.formatDate(dt, DataBaseUtils.DATE_PATTERN_YYYY_MM)); // init "average" data int totalCallories = 0; for (Ingridient ingridient : list) { totalCallories += ingridient.kkal; } // add value to series seriesCallories.add(totalCallories / daysInMonth); // calculate maximum Y axis values yMaxAxisValue = Math.max(yMaxAxisValue, totalCallories / daysInMonth); // increment month dt = DateUtils.addMonths(dt, 1); } int[] colors = new int[] { getActivity().getResources().getColor(R.color.purple) }; final XYMultipleSeriesRenderer renderer = buildBarRenderer(colors); setChartSettings(renderer, String.format("Callories statistic for %s year", Utils.getSpecificDateValue(DATE, "yyyy")), "Months", "Calories consumption", 0.7, 12.3, 0, yMaxAxisValue + 30, Color.GRAY, Color.LTGRAY); renderer.getSeriesRendererAt(0).setDisplayChartValues(true); renderer.getSeriesRendererAt(0).setChartValuesTextSize(15f); renderer.setXLabels(0); renderer.setClickEnabled(false); renderer.setZoomEnabled(false); renderer.setPanEnabled(false, false); renderer.setZoomButtonsVisible(false); renderer.setPanLimits(new double[] { 1, 11 }); renderer.setShowGrid(true); renderer.setShowLegend(true); renderer.setFitLegend(true); for (int i = 0; i < ActivityWaterProgress.months_short.length; i++) { renderer.addXTextLabel(i + 1, ActivityWaterProgress.months_short[i]); } dataset.addSeries(seriesCallories.toXYSeries()); getActivity().runOnUiThread(new Runnable() { @Override public void run() { viewChart = ChartFactory.getBarChartView(getActivity(), dataset, renderer, Type.DEFAULT); rlRootGraphLayout.addView(viewChart, 0); if (isLeftIn) { rightIn.setDuration(1000); viewChart.startAnimation(rightIn); } else { leftIn.setDuration(1000); viewChart.startAnimation(leftIn); } } }); } catch (Exception e) { } ringProgressDialog.dismiss(); } }).start(); }
From source file:org.pentaho.platform.dataaccess.datasource.wizard.service.agile.CsvTransformGeneratorIT.java
public void testLoadTable1() throws Exception { IPentahoSession session = new StandaloneSession("test"); KettleSystemListener.environmentInit(session); ModelInfo info = createModel();// w ww .java2 s .c o m CsvTransformGenerator gen = new CsvTransformGenerator(info, getDatabaseMeta()); // create the model String tableName = info.getStageTableName(); try { gen.execSqlStatement(getDropTableStatement(tableName), getDatabaseMeta(), null); } catch (CsvTransformGeneratorException e) { // table might not be there yet, it is OK } // generate the database table gen.createOrModifyTable(session); // load the table loadTable(gen, info, true, session); // check the results long rowCount = this.getRowCount(tableName); assertEquals((long) 235, rowCount); DatabaseMeta databaseMeta = getDatabaseMeta(); assertNotNull(databaseMeta); Database database = new Database(databaseMeta); assertNotNull(database); database.connect(); Connection connection = null; Statement stmt = null; ResultSet sqlResult = null; try { connection = database.getConnection(); assertNotNull(connection); stmt = database.getConnection().createStatement(); // check the first row Date testDate = new Date(); testDate.setDate(1); testDate.setHours(0); testDate.setMinutes(0); testDate.setMonth(0); testDate.setSeconds(0); testDate.setYear(110); boolean ok = stmt.execute("select * from " + tableName); assertTrue(ok); sqlResult = stmt.getResultSet(); assertNotNull(sqlResult); ok = sqlResult.next(); assertTrue(ok); // test the values assertEquals((long) 3, sqlResult.getLong(1)); assertEquals(25677.96525, sqlResult.getDouble(2)); assertEquals((long) 1231, sqlResult.getLong(3)); assertEquals(testDate.getYear(), sqlResult.getDate(4).getYear()); assertEquals(testDate.getMonth(), sqlResult.getDate(4).getMonth()); assertEquals(testDate.getDate(), sqlResult.getDate(4).getDate()); assertEquals(testDate.getHours(), sqlResult.getTime(4).getHours()); // assertEquals( testDate.getMinutes(), ((Date)cells[3]).getMinutes() ); this fails, a bug in the PDI date parsing? assertEquals(testDate.getSeconds(), sqlResult.getTime(4).getSeconds()); // assertEquals( testDate, cells[3] ); assertEquals("Afghanistan", sqlResult.getString(5)); assertEquals((long) 11, sqlResult.getLong(6)); assertEquals(111.9090909, sqlResult.getDouble(7)); assertEquals(false, sqlResult.getBoolean(8)); } finally { sqlResult.close(); stmt.close(); connection.close(); } }
From source file:com.progym.custom.fragments.FoodProgressYearlyLineFragment.java
public void setYearProgressData(final Date date, final boolean isLeftIn) { final ProgressDialog ringProgressDialog = ProgressDialog.show(getActivity(), getResources().getString(R.string.please_wait), getResources().getString(R.string.populating_data), true);/* w w w . j av a 2 s.c o m*/ ringProgressDialog.setCancelable(true); new Thread(new Runnable() { @Override public void run() { try { int yMaxAxisValue = 0; getActivity().runOnUiThread(new Runnable() { @Override public void run() { try { rlRootGraphLayout.removeView(viewChart); } catch (Exception edsx) { edsx.printStackTrace(); } } }); DATE = date; // Get amount of days in a month to find out average int daysInMonth = Utils.getDaysInMonth(date.getMonth(), Integer.valueOf(Utils.formatDate(date, DataBaseUtils.DATE_PATTERN_YYYY))); // set January as first month date.setMonth(0); date.setDate(1); int[] x = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; final XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset(); CategorySeries seriesProtein = new CategorySeries("Protein"); CategorySeries seriesFat = new CategorySeries("Fat"); CategorySeries seriesCarbs = new CategorySeries("Carbs"); List<Ingridient> list; Date dt = date; for (int element : x) { list = DataBaseUtils.getAllFoodConsumedInMonth( Utils.formatDate(dt, DataBaseUtils.DATE_PATTERN_YYYY_MM)); // init "average" data double totalProtein = 0, totalFat = 0, totalCarbs = 0, totalCallories = 0; for (Ingridient ingridient : list) { totalProtein += ingridient.protein; totalFat += ingridient.fat; totalCarbs += ingridient.carbohydrates; totalCallories += ingridient.kkal; } seriesProtein.add((double) Math.round(totalProtein * 100) / 100); seriesFat.add((double) Math.round(totalFat * 100) / 100); seriesCarbs.add((double) Math.round(totalCarbs * 100) / 100); // calculate maximum Y axis values yMaxAxisValue = Math.max(yMaxAxisValue, (int) totalProtein); yMaxAxisValue = Math.max(yMaxAxisValue, (int) totalFat); yMaxAxisValue = Math.max(yMaxAxisValue, (int) totalCarbs); // increment month dt = DateUtils.addMonths(dt, 1); } int[] colors = new int[] { getActivity().getResources().getColor(R.color.green), getActivity().getResources().getColor(R.color.orange), getActivity().getResources().getColor(R.color.purple) }; final XYMultipleSeriesRenderer renderer = buildBarRenderer(colors); setChartSettings(renderer, String.format("Protein/Carbohydrates/Fat statistic for %s year", Utils.getSpecificDateValue(DATE, "yyyy")), "Months", "Amount (g) ", 0.7, 12.3, 0, yMaxAxisValue + 30, Color.GRAY, Color.LTGRAY); renderer.getSeriesRendererAt(0).setDisplayChartValues(true); renderer.getSeriesRendererAt(1).setDisplayChartValues(true); renderer.getSeriesRendererAt(2).setDisplayChartValues(true); renderer.getSeriesRendererAt(0).setChartValuesTextSize(15f); renderer.getSeriesRendererAt(1).setChartValuesTextSize(15f); renderer.getSeriesRendererAt(2).setChartValuesTextSize(15f); // renderer.getSeriesRendererAt(0).setChartValuesTextAlign(Align.CENTER); // renderer.getSeriesRendererAt(1).setChartValuesTextAlign(Align.LEFT); // renderer.getSeriesRendererAt(2).setChartValuesTextAlign(Align.RIGHT); renderer.setXLabels(0); // renderer.setYLabels(10); // renderer.setXLabelsAlign(Align.LEFT); // renderer.setYLabelsAlign(Align.LEFT); // renderer.setPanEnabled(true, false); renderer.setClickEnabled(false); renderer.setZoomEnabled(false); renderer.setPanEnabled(false, false); renderer.setZoomButtonsVisible(false); renderer.setPanLimits(new double[] { 1, 11 }); // renderer.setZoomEnabled(false); // renderer.setZoomRate(1.1f); renderer.setShowGrid(true); renderer.setShowLegend(true); renderer.setFitLegend(true); for (int i = 0; i < ActivityWaterProgress.months_short.length; i++) { renderer.addXTextLabel(i + 1, ActivityWaterProgress.months_short[i]); } dataset.addSeries(seriesProtein.toXYSeries()); dataset.addSeries(seriesFat.toXYSeries()); dataset.addSeries(seriesCarbs.toXYSeries()); getActivity().runOnUiThread(new Runnable() { @Override public void run() { try { viewChart = ChartFactory.getLineChartView(getActivity(), dataset, renderer/* , Type.STACKED */); rlRootGraphLayout.addView(viewChart, 0); if (isLeftIn) { rightIn.setDuration(1000); viewChart.startAnimation(rightIn); } else { leftIn.setDuration(1000); viewChart.startAnimation(leftIn); } } catch (Exception edsx) { edsx.printStackTrace(); } } }); } catch (Exception e) { e.printStackTrace(); } ringProgressDialog.dismiss(); } }).start(); }
From source file:com.progym.custom.fragments.FoodProgressMonthlyLineFragment.java
public void setLineData3(final Date date, final boolean isLeftIn) { final ProgressDialog ringProgressDialog = ProgressDialog.show(getActivity(), getResources().getString(R.string.please_wait), getResources().getString(R.string.populating_data), true);//from w w w . j a v a2 s .c o m ringProgressDialog.setCancelable(true); new Thread(new Runnable() { @Override public void run() { try { int yMaxAxisValue = 0; getActivity().runOnUiThread(new Runnable() { @Override public void run() { try { rlRootGraphLayout.removeView(graphView); } catch (Exception edsx) { edsx.printStackTrace(); } } }); date.setDate(1); DATE = date; // Get amount of days in a month to find out average int daysInMonth = Utils.getDaysInMonth(date.getMonth(), Integer.valueOf(Utils.formatDate(date, DataBaseUtils.DATE_PATTERN_YYYY))); // set First day of the month as first month int[] x = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 }; // Creating an XYSeries for Consumed water XYSeries protein = new XYSeries("Protein"); XYSeries fat = new XYSeries("Fat"); XYSeries carbs = new XYSeries("Carbs"); List<Ingridient> list; Date dt = date; // * // Adding data to Income and Expense Series for (int i = 1; i <= daysInMonth; i++) { // get all water records consumed per this month list = DataBaseUtils.getAllFoodConsumedInMonth( Utils.formatDate(dt, DataBaseUtils.DATE_PATTERN_YYYY_MM_DD)); // init "average" data double totalProtein = 0, totalFat = 0, totalCarbs = 0; if (null != list) { for (Ingridient ingridient : list) { totalProtein += ingridient.protein; totalFat += ingridient.fat; totalCarbs += ingridient.carbohydrates; } } protein.add(i, (double) Math.round(totalProtein * 100) / 100); fat.add(i, (double) Math.round(totalFat * 100) / 100); carbs.add(i, (double) Math.round(totalCarbs * 100) / 100); // calories.add(i, totalCallories); dt = DateUtils.addDays(dt, 1); yMaxAxisValue = Math.max(yMaxAxisValue, (int) totalProtein); yMaxAxisValue = Math.max(yMaxAxisValue, (int) totalFat); yMaxAxisValue = Math.max(yMaxAxisValue, (int) totalCarbs); } // Creating a dataset to hold each series final XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset(); // Adding Income Series to the dataset dataset.addSeries(protein); dataset.addSeries(carbs); dataset.addSeries(fat); // Creating XYSeriesRenderer to customize protein series XYSeriesRenderer proteinRenderer = new XYSeriesRenderer(); proteinRenderer.setColor(Color.rgb(50, 255, 50)); proteinRenderer.setFillPoints(true); proteinRenderer.setLineWidth(3); proteinRenderer.setDisplayChartValues(true); // Creating XYSeriesRenderer to customize protein series XYSeriesRenderer fatRenderer = new XYSeriesRenderer(); fatRenderer.setColor(Color.rgb(123, 111, 00)); fatRenderer.setFillPoints(true); fatRenderer.setLineWidth(3); fatRenderer.setDisplayChartValues(true); // Creating XYSeriesRenderer to customize protein series XYSeriesRenderer carbsRenderer = new XYSeriesRenderer(); carbsRenderer.setColor(Color.rgb(222, 13, 11)); carbsRenderer.setFillPoints(true); carbsRenderer.setLineWidth(3); carbsRenderer.setDisplayChartValues(true); // Creating a XYMultipleSeriesRenderer to customize the whole chart final XYMultipleSeriesRenderer multiRenderer = new XYMultipleSeriesRenderer(); // multiRenderer.setXLabels(0); for (int i = 0; i < x.length; i++) { multiRenderer.addXTextLabel(i, String.valueOf(x[i])); } // Adding incomeRenderer and expenseRenderer to multipleRenderer // Note: The order of adding dataseries to dataset and renderers to multipleRenderer // should be same multiRenderer.setChartTitle(String.format("Protein/Carbs/Fat statistic ")); multiRenderer.setXTitle(Utils.getSpecificDateValue(DATE, "MMM") + " of " + Utils.formatDate(DATE, DataBaseUtils.DATE_PATTERN_YYYY)); multiRenderer.setYTitle("Amount (g) "); multiRenderer.setAxesColor(Color.WHITE); multiRenderer.setShowLegend(true); multiRenderer.addSeriesRenderer(proteinRenderer); multiRenderer.addSeriesRenderer(carbsRenderer); multiRenderer.addSeriesRenderer(fatRenderer); multiRenderer.setShowGrid(true); multiRenderer.setClickEnabled(true); multiRenderer.setXLabelsAngle(20); multiRenderer.setXLabelsColor(Color.WHITE); multiRenderer.setZoomButtonsVisible(false); // configure visible area multiRenderer.setXAxisMax(31); multiRenderer.setXAxisMin(1); multiRenderer.setYAxisMax(yMaxAxisValue + 30); multiRenderer.setAxisTitleTextSize(15); multiRenderer.setZoomEnabled(true); getActivity().runOnUiThread(new Runnable() { @Override public void run() { try { graphView = ChartFactory.getLineChartView(getActivity(), dataset, multiRenderer); rlRootGraphLayout.addView(graphView, 0); if (isLeftIn) { rightIn.setDuration(1000); graphView.startAnimation(rightIn); } else { leftIn.setDuration(1000); graphView.startAnimation(leftIn); } } catch (Exception edsx) { edsx.printStackTrace(); } } }); } catch (Exception e) { e.printStackTrace(); } ringProgressDialog.dismiss(); } }).start(); }