From d4b37ed49721fe6150737d7e265807428ce1acb7 Mon Sep 17 00:00:00 2001 From: Martin Woolley Date: Thu, 14 Nov 2024 08:26:34 +0000 Subject: [PATCH 1/2] Upgraded to gradle 8.7 --- MPChartLib/build.gradle | 5 ++--- build.gradle | 6 ++++-- gradle/wrapper/gradle-wrapper.properties | 12 ++++++------ 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/MPChartLib/build.gradle b/MPChartLib/build.gradle index 0fb6dc7036..46585ed13c 100644 --- a/MPChartLib/build.gradle +++ b/MPChartLib/build.gradle @@ -1,5 +1,4 @@ apply plugin: 'com.android.library' -apply plugin: 'com.github.dcendents.android-maven' group='com.github.philjay' @@ -30,7 +29,7 @@ dependencies { task sourcesJar(type: Jar) { from android.sourceSets.main.java.srcDirs - classifier = 'sources' + archiveClassifier = 'sources' } task javadoc(type: Javadoc) { @@ -41,7 +40,7 @@ task javadoc(type: Javadoc) { } task javadocJar(type: Jar, dependsOn: javadoc) { - classifier = 'javadoc' + archiveClassifier = 'javadoc' from javadoc.destinationDir } diff --git a/build.gradle b/build.gradle index cee7a83e80..02eedb0028 100644 --- a/build.gradle +++ b/build.gradle @@ -1,11 +1,13 @@ buildscript { + ext { + agp_version = '8.5.1' + } repositories { jcenter() google() } dependencies { - classpath 'com.android.tools.build:gradle:3.4.0' - classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' + classpath "com.android.tools.build:gradle:$agp_version" } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 0f8bc4e375..ba840863d1 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Sat Apr 27 15:48:29 CEST 2019 -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip +#Thu Nov 14 08:23:15 GMT 2024 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists From 130ae9c7a1f61bf44081f7e94175b21014a03d79 Mon Sep 17 00:00:00 2001 From: Martin Woolley Date: Thu, 14 Nov 2024 14:08:44 +0000 Subject: [PATCH 2/2] Migrated to target API 34 - involved changing switch statements to nested if statements in menu related code --- .idea/runConfigurations/MPChartExample.xml | 32 ++- .settings/org.eclipse.buildship.core.prefs | 13 ++ .../org.eclipse.buildship.core.prefs | 2 + .../.settings/org.eclipse.jdt.core.prefs | 4 + MPChartExample/build.gradle | 7 +- MPChartExample/src/main/AndroidManifest.xml | 6 +- .../mpchartexample/AnotherBarActivity.java | 109 ++++----- .../mpchartexample/BarChartActivity.java | 116 ++++------ .../BarChartActivityMultiDataset.java | 98 ++++---- .../mpchartexample/BarChartActivitySinus.java | 99 ++++---- .../BarChartPositiveNegative.java | 11 +- .../mpchartexample/BubbleChartActivity.java | 98 ++++---- .../CandleStickChartActivity.java | 108 ++++----- .../mpchartexample/CombinedChartActivity.java | 54 ++--- .../CubicLineChartActivity.java | 191 +++++++--------- .../mpchartexample/DrawChartActivity.java | 62 +++-- .../DynamicalAddingActivity.java | 64 ++---- .../mpchartexample/FilledLineActivity.java | 11 +- .../mpchartexample/HalfPieChartActivity.java | 11 +- .../HorizontalBarChartActivity.java | 116 ++++------ .../HorizontalBarNegativeChartActivity.java | 116 ++++------ .../InvertedLineChartActivity.java | 140 +++++------- .../mpchartexample/LineChartActivity1.java | 215 ++++++++---------- .../mpchartexample/LineChartActivity2.java | 201 +++++++--------- .../LineChartActivityColored.java | 11 +- .../mpchartexample/LineChartTime.java | 194 +++++++--------- .../ListViewBarChartActivity.java | 11 +- .../ListViewMultiChartActivity.java | 11 +- .../MultiLineChartActivity.java | 206 ++++++++--------- .../mpchartexample/PerformanceLineChart.java | 11 +- .../mpchartexample/PieChartActivity.java | 150 +++++------- .../PiePolylineChartActivity.java | 138 +++++------ .../mpchartexample/RadarChartActivity.java | 137 +++++------ .../RealtimeLineChartActivity.java | 44 ++-- .../mpchartexample/ScatterChartActivity.java | 95 ++++---- .../mpchartexample/ScrollViewActivity.java | 11 +- .../mpchartexample/StackedBarActivity.java | 123 ++++------ .../StackedBarActivityNegative.java | 123 ++++------ .../fragments/SimpleChartDemo.java | 11 +- .../notimportant/MainActivity.java | 33 ++- .../org.eclipse.buildship.core.prefs | 2 + .../.settings/org.eclipse.jdt.core.prefs | 4 + MPChartLib/build.gradle | 6 +- MPChartLib/src/main/AndroidManifest.xml | 2 +- 44 files changed, 1343 insertions(+), 1864 deletions(-) create mode 100644 .settings/org.eclipse.buildship.core.prefs create mode 100644 MPChartExample/.settings/org.eclipse.buildship.core.prefs create mode 100644 MPChartExample/.settings/org.eclipse.jdt.core.prefs create mode 100644 MPChartLib/.settings/org.eclipse.buildship.core.prefs create mode 100644 MPChartLib/.settings/org.eclipse.jdt.core.prefs diff --git a/.idea/runConfigurations/MPChartExample.xml b/.idea/runConfigurations/MPChartExample.xml index e6bcf50331..4e308bc5e2 100644 --- a/.idea/runConfigurations/MPChartExample.xml +++ b/.idea/runConfigurations/MPChartExample.xml @@ -1,20 +1,20 @@ - + \ No newline at end of file diff --git a/.settings/org.eclipse.buildship.core.prefs b/.settings/org.eclipse.buildship.core.prefs new file mode 100644 index 0000000000..1cd8b4ba33 --- /dev/null +++ b/.settings/org.eclipse.buildship.core.prefs @@ -0,0 +1,13 @@ +arguments= +auto.sync=false +build.scans.enabled=false +connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER) +connection.project.dir= +eclipse.preferences.version=1 +gradle.user.home= +java.home= +jvm.arguments= +offline.mode=false +override.workspace.settings=false +show.console.view=true +show.executions.view=true diff --git a/MPChartExample/.settings/org.eclipse.buildship.core.prefs b/MPChartExample/.settings/org.eclipse.buildship.core.prefs new file mode 100644 index 0000000000..a7b84d9296 --- /dev/null +++ b/MPChartExample/.settings/org.eclipse.buildship.core.prefs @@ -0,0 +1,2 @@ +connection.project.dir=.. +eclipse.preferences.version=1 diff --git a/MPChartExample/.settings/org.eclipse.jdt.core.prefs b/MPChartExample/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000000..d1a8228954 --- /dev/null +++ b/MPChartExample/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,4 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=21 +org.eclipse.jdt.core.compiler.compliance=21 +org.eclipse.jdt.core.compiler.source=21 diff --git a/MPChartExample/build.gradle b/MPChartExample/build.gradle index 2d607e9991..a254950ce1 100644 --- a/MPChartExample/build.gradle +++ b/MPChartExample/build.gradle @@ -1,11 +1,12 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 28 + compileSdkVersion 34 + namespace = "com.xxmassdeveloper.mpchartexample" defaultConfig { applicationId "com.xxmassdeveloper.mpchartexample" - minSdkVersion 16 - targetSdkVersion 28 + minSdkVersion 24 + targetSdkVersion 34 versionCode 57 versionName '3.1.0' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" diff --git a/MPChartExample/src/main/AndroidManifest.xml b/MPChartExample/src/main/AndroidManifest.xml index 99334e601a..5c1b370fb3 100644 --- a/MPChartExample/src/main/AndroidManifest.xml +++ b/MPChartExample/src/main/AndroidManifest.xml @@ -1,6 +1,5 @@ - + @@ -12,7 +11,8 @@ android:theme="@style/AppTheme"> + android:label="@string/app_name" + android:exported="true"> diff --git a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/AnotherBarActivity.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/AnotherBarActivity.java index 69b5a96c42..87a4b9ca8f 100644 --- a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/AnotherBarActivity.java +++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/AnotherBarActivity.java @@ -6,7 +6,9 @@ import android.content.pm.PackageManager; import android.net.Uri; import android.os.Bundle; + import androidx.core.content.ContextCompat; + import android.view.Menu; import android.view.MenuItem; import android.view.WindowManager; @@ -129,73 +131,44 @@ public boolean onCreateOptionsMenu(Menu menu) { @Override public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.viewGithub: { - Intent i = new Intent(Intent.ACTION_VIEW); - i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/AnotherBarActivity.java")); - startActivity(i); - break; - } - case R.id.actionToggleValues: { - - for (IDataSet set : chart.getData().getDataSets()) - set.setDrawValues(!set.isDrawValuesEnabled()); - - chart.invalidate(); - break; - } - /* - case R.id.actionToggleIcons: { break; } - */ - case R.id.actionToggleHighlight: { - - if(chart.getData() != null) { - chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled()); - chart.invalidate(); - } - break; - } - case R.id.actionTogglePinch: { - if (chart.isPinchZoomEnabled()) - chart.setPinchZoom(false); - else - chart.setPinchZoom(true); - - chart.invalidate(); - break; - } - case R.id.actionToggleAutoScaleMinMax: { - chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled()); - chart.notifyDataSetChanged(); - break; - } - case R.id.actionToggleBarBorders: { - for (IBarDataSet set : chart.getData().getDataSets()) - ((BarDataSet)set).setBarBorderWidth(set.getBarBorderWidth() == 1.f ? 0.f : 1.f); - + if (item.getItemId() == R.id.viewGithub) { + Intent i = new Intent(Intent.ACTION_VIEW); + i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/AnotherBarActivity.java")); + startActivity(i); + } else if (item.getItemId() == R.id.actionToggleValues) { + for (IDataSet set : chart.getData().getDataSets()) + set.setDrawValues(!set.isDrawValuesEnabled()); + chart.invalidate(); + } else if (item.getItemId() == R.id.actionToggleHighlight) { + if (chart.getData() != null) { + chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled()); chart.invalidate(); - break; - } - case R.id.animateX: { - chart.animateX(2000); - break; - } - case R.id.animateY: { - chart.animateY(2000); - break; } - case R.id.animateXY: { - - chart.animateXY(2000, 2000); - break; - } - case R.id.actionSave: { - if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { - saveToGallery(); - } else { - requestStoragePermission(chart); - } - break; + } else if (item.getItemId() == R.id.actionTogglePinch) { + if (chart.isPinchZoomEnabled()) + chart.setPinchZoom(false); + else + chart.setPinchZoom(true); + + chart.invalidate(); + } else if (item.getItemId() == R.id.actionToggleAutoScaleMinMax) { + chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled()); + chart.notifyDataSetChanged(); + } else if (item.getItemId() == R.id.actionToggleBarBorders) { + for (IBarDataSet set : chart.getData().getDataSets()) + ((BarDataSet) set).setBarBorderWidth(set.getBarBorderWidth() == 1.f ? 0.f : 1.f); + chart.invalidate(); + } else if (item.getItemId() == R.id.animateX) { + chart.animateX(2000); + } else if (item.getItemId() == R.id.animateY) { + chart.animateY(2000); + } else if (item.getItemId() == R.id.animateXY) { + chart.animateXY(2000, 2000); + } else if (item.getItemId() == R.id.actionSave) { + if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { + saveToGallery(); + } else { + requestStoragePermission(chart); } } return true; @@ -207,8 +180,10 @@ protected void saveToGallery() { } @Override - public void onStartTrackingTouch(SeekBar seekBar) {} + public void onStartTrackingTouch(SeekBar seekBar) { + } @Override - public void onStopTrackingTouch(SeekBar seekBar) {} + public void onStopTrackingTouch(SeekBar seekBar) { + } } diff --git a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/BarChartActivity.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/BarChartActivity.java index 0d83e3444a..95a935a6e0 100644 --- a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/BarChartActivity.java +++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/BarChartActivity.java @@ -7,7 +7,9 @@ import android.graphics.RectF; import android.net.Uri; import android.os.Bundle; + import androidx.core.content.ContextCompat; + import android.util.Log; import android.view.Menu; import android.view.MenuItem; @@ -206,74 +208,47 @@ public boolean onCreateOptionsMenu(Menu menu) { @Override public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.viewGithub: { - Intent i = new Intent(Intent.ACTION_VIEW); - i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/BarChartActivity.java")); - startActivity(i); - break; - } - case R.id.actionToggleValues: { - for (IDataSet set : chart.getData().getDataSets()) - set.setDrawValues(!set.isDrawValuesEnabled()); - - chart.invalidate(); - break; - } - case R.id.actionToggleIcons: { - for (IDataSet set : chart.getData().getDataSets()) - set.setDrawIcons(!set.isDrawIconsEnabled()); - - chart.invalidate(); - break; - } - case R.id.actionToggleHighlight: { - if (chart.getData() != null) { - chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled()); - chart.invalidate(); - } - break; - } - case R.id.actionTogglePinch: { - if (chart.isPinchZoomEnabled()) - chart.setPinchZoom(false); - else - chart.setPinchZoom(true); - + if (item.getItemId() == R.id.viewGithub) { + Intent i = new Intent(Intent.ACTION_VIEW); + i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/BarChartActivity.java")); + startActivity(i); + } else if (item.getItemId() == R.id.actionToggleValues) { + for (IDataSet set : chart.getData().getDataSets()) + set.setDrawValues(!set.isDrawValuesEnabled()); + chart.invalidate(); + } else if (item.getItemId() == R.id.actionToggleIcons) { + for (IDataSet set : chart.getData().getDataSets()) + set.setDrawIcons(!set.isDrawIconsEnabled()); + chart.invalidate(); + } else if (item.getItemId() == R.id.actionToggleHighlight) { + if (chart.getData() != null) { + chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled()); chart.invalidate(); - break; - } - case R.id.actionToggleAutoScaleMinMax: { - chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled()); - chart.notifyDataSetChanged(); - break; } - case R.id.actionToggleBarBorders: { - for (IBarDataSet set : chart.getData().getDataSets()) - ((BarDataSet) set).setBarBorderWidth(set.getBarBorderWidth() == 1.f ? 0.f : 1.f); - - chart.invalidate(); - break; - } - case R.id.animateX: { - chart.animateX(2000); - break; - } - case R.id.animateY: { - chart.animateY(2000); - break; - } - case R.id.animateXY: { - chart.animateXY(2000, 2000); - break; - } - case R.id.actionSave: { - if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { - saveToGallery(); - } else { - requestStoragePermission(chart); - } - break; + } else if (item.getItemId() == R.id.actionTogglePinch) { + if (chart.isPinchZoomEnabled()) + chart.setPinchZoom(false); + else + chart.setPinchZoom(true); + chart.invalidate(); + } else if (item.getItemId() == R.id.actionToggleAutoScaleMinMax) { + chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled()); + chart.notifyDataSetChanged(); + } else if (item.getItemId() == R.id.actionToggleBarBorders) { + for (IBarDataSet set : chart.getData().getDataSets()) + ((BarDataSet) set).setBarBorderWidth(set.getBarBorderWidth() == 1.f ? 0.f : 1.f); + chart.invalidate(); + } else if (item.getItemId() == R.id.animateX) { + chart.animateX(2000); + } else if (item.getItemId() == R.id.animateY) { + chart.animateY(2000); + } else if (item.getItemId() == R.id.animateXY) { + chart.animateXY(2000, 2000); + } else if (item.getItemId() == R.id.actionSave) { + if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { + saveToGallery(); + } else { + requestStoragePermission(chart); } } return true; @@ -295,10 +270,12 @@ protected void saveToGallery() { } @Override - public void onStartTrackingTouch(SeekBar seekBar) {} + public void onStartTrackingTouch(SeekBar seekBar) { + } @Override - public void onStopTrackingTouch(SeekBar seekBar) {} + public void onStopTrackingTouch(SeekBar seekBar) { + } private final RectF onValueSelectedRectF = new RectF(); @@ -323,5 +300,6 @@ public void onValueSelected(Entry e, Highlight h) { } @Override - public void onNothingSelected() { } + public void onNothingSelected() { + } } diff --git a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/BarChartActivityMultiDataset.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/BarChartActivityMultiDataset.java index 075af0edbc..f100ff1d3f 100644 --- a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/BarChartActivityMultiDataset.java +++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/BarChartActivityMultiDataset.java @@ -200,68 +200,48 @@ public boolean onCreateOptionsMenu(Menu menu) { @Override public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.viewGithub: { - Intent i = new Intent(Intent.ACTION_VIEW); - i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/BarChartActivityMultiDataset.java")); - startActivity(i); - break; - } - case R.id.actionToggleValues: { - for (IBarDataSet set : chart.getData().getDataSets()) - set.setDrawValues(!set.isDrawValuesEnabled()); - - chart.invalidate(); - break; - } - case R.id.actionTogglePinch: { - if (chart.isPinchZoomEnabled()) - chart.setPinchZoom(false); - else - chart.setPinchZoom(true); - - chart.invalidate(); - break; - } - case R.id.actionToggleAutoScaleMinMax: { - chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled()); - chart.notifyDataSetChanged(); - break; - } - case R.id.actionToggleBarBorders: { - for (IBarDataSet set : chart.getData().getDataSets()) - ((BarDataSet) set).setBarBorderWidth(set.getBarBorderWidth() == 1.f ? 0.f : 1.f); - + int itemId = item.getItemId(); + if (itemId == R.id.viewGithub) { + Intent i = new Intent(Intent.ACTION_VIEW); + i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/BarChartActivityMultiDataset.java")); + startActivity(i); + } else if (itemId == R.id.actionToggleValues) { + for (IBarDataSet set : chart.getData().getDataSets()) + set.setDrawValues(!set.isDrawValuesEnabled()); + + chart.invalidate(); + } else if (itemId == R.id.actionTogglePinch) { + if (chart.isPinchZoomEnabled()) + chart.setPinchZoom(false); + else + chart.setPinchZoom(true); + + chart.invalidate(); + } else if (itemId == R.id.actionToggleAutoScaleMinMax) { + chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled()); + chart.notifyDataSetChanged(); + } else if (itemId == R.id.actionToggleBarBorders) { + for (IBarDataSet set : chart.getData().getDataSets()) + ((BarDataSet) set).setBarBorderWidth(set.getBarBorderWidth() == 1.f ? 0.f : 1.f); + + chart.invalidate(); + } else if (itemId == R.id.actionToggleHighlight) { + if (chart.getData() != null) { + chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled()); chart.invalidate(); - break; - } - case R.id.actionToggleHighlight: { - if (chart.getData() != null) { - chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled()); - chart.invalidate(); - } - break; - } - case R.id.actionSave: { - if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { - saveToGallery(); - } else { - requestStoragePermission(chart); - } - break; - } - case R.id.animateX: { - chart.animateX(2000); - break; - } - case R.id.animateY: { - chart.animateY(2000); - break; } - case R.id.animateXY: { - chart.animateXY(2000, 2000); - break; + } else if (itemId == R.id.actionSave) { + if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { + saveToGallery(); + } else { + requestStoragePermission(chart); } + } else if (itemId == R.id.animateX) { + chart.animateX(2000); + } else if (itemId == R.id.animateY) { + chart.animateY(2000); + } else if (itemId == R.id.animateXY) { + chart.animateXY(2000, 2000); } return true; } diff --git a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/BarChartActivitySinus.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/BarChartActivitySinus.java index 95443e8214..42f35e31e9 100644 --- a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/BarChartActivitySinus.java +++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/BarChartActivitySinus.java @@ -149,68 +149,47 @@ public boolean onCreateOptionsMenu(Menu menu) { @Override public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.viewGithub: { - Intent i = new Intent(Intent.ACTION_VIEW); - i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/BarChartActivitySinus.java")); - startActivity(i); - break; - } - case R.id.actionToggleValues: { - for (IBarDataSet set : chart.getData().getDataSets()) - set.setDrawValues(!set.isDrawValuesEnabled()); - - chart.invalidate(); - break; - } - case R.id.actionToggleHighlight: { - if (chart.getData() != null) { - chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled()); - chart.invalidate(); - } - break; - } - case R.id.actionTogglePinch: { - if (chart.isPinchZoomEnabled()) - chart.setPinchZoom(false); - else - chart.setPinchZoom(true); - + int itemId = item.getItemId(); + if (itemId == R.id.viewGithub) { + Intent i = new Intent(Intent.ACTION_VIEW); + i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/BarChartActivitySinus.java")); + startActivity(i); + } else if (itemId == R.id.actionToggleValues) { + for (IBarDataSet set : chart.getData().getDataSets()) + set.setDrawValues(!set.isDrawValuesEnabled()); + + chart.invalidate(); + } else if (itemId == R.id.actionToggleHighlight) { + if (chart.getData() != null) { + chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled()); chart.invalidate(); - break; } - case R.id.actionToggleAutoScaleMinMax: { - chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled()); - chart.notifyDataSetChanged(); - break; - } - case R.id.actionToggleBarBorders: { - for (IBarDataSet set : chart.getData().getDataSets()) - ((BarDataSet) set).setBarBorderWidth(set.getBarBorderWidth() == 1.f ? 0.f : 1.f); - - chart.invalidate(); - break; - } - case R.id.animateX: { - chart.animateX(2000); - break; - } - case R.id.animateY: { - chart.animateY(2000); - break; - } - case R.id.animateXY: { - - chart.animateXY(2000, 2000); - break; - } - case R.id.actionSave: { - if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { - saveToGallery(); - } else { - requestStoragePermission(chart); - } - break; + } else if (itemId == R.id.actionTogglePinch) { + if (chart.isPinchZoomEnabled()) + chart.setPinchZoom(false); + else + chart.setPinchZoom(true); + + chart.invalidate(); + } else if (itemId == R.id.actionToggleAutoScaleMinMax) { + chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled()); + chart.notifyDataSetChanged(); + } else if (itemId == R.id.actionToggleBarBorders) { + for (IBarDataSet set : chart.getData().getDataSets()) + ((BarDataSet) set).setBarBorderWidth(set.getBarBorderWidth() == 1.f ? 0.f : 1.f); + + chart.invalidate(); + } else if (itemId == R.id.animateX) { + chart.animateX(2000); + } else if (itemId == R.id.animateY) { + chart.animateY(2000); + } else if (itemId == R.id.animateXY) { + chart.animateXY(2000, 2000); + } else if (itemId == R.id.actionSave) { + if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { + saveToGallery(); + } else { + requestStoragePermission(chart); } } return true; diff --git a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/BarChartPositiveNegative.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/BarChartPositiveNegative.java index 4fec7dd6ab..4375372f78 100644 --- a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/BarChartPositiveNegative.java +++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/BarChartPositiveNegative.java @@ -183,13 +183,10 @@ public boolean onCreateOptionsMenu(Menu menu) { @Override public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.viewGithub: { - Intent i = new Intent(Intent.ACTION_VIEW); - i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/BarChartPositiveNegative.java")); - startActivity(i); - break; - } + if (item.getItemId() == R.id.viewGithub) { + Intent i = new Intent(Intent.ACTION_VIEW); + i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/BarChartPositiveNegative.java")); + startActivity(i); } return true; diff --git a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/BubbleChartActivity.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/BubbleChartActivity.java index 6288dda2be..9cd45eb129 100644 --- a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/BubbleChartActivity.java +++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/BubbleChartActivity.java @@ -159,68 +159,48 @@ public boolean onCreateOptionsMenu(Menu menu) { @Override public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.viewGithub: { - Intent i = new Intent(Intent.ACTION_VIEW); - i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/BubbleChartActivity.java")); - startActivity(i); - break; - } - case R.id.actionToggleValues: { - for (IDataSet set : chart.getData().getDataSets()) - set.setDrawValues(!set.isDrawValuesEnabled()); - + int itemId = item.getItemId(); + if (itemId == R.id.viewGithub) { + Intent i = new Intent(Intent.ACTION_VIEW); + i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/BubbleChartActivity.java")); + startActivity(i); + } else if (itemId == R.id.actionToggleValues) { + for (IDataSet set : chart.getData().getDataSets()) + set.setDrawValues(!set.isDrawValuesEnabled()); + + chart.invalidate(); + } else if (itemId == R.id.actionToggleIcons) { + for (IDataSet set : chart.getData().getDataSets()) + set.setDrawIcons(!set.isDrawIconsEnabled()); + + chart.invalidate(); + } else if (itemId == R.id.actionToggleHighlight) { + if (chart.getData() != null) { + chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled()); chart.invalidate(); - break; - } - case R.id.actionToggleIcons: { - for (IDataSet set : chart.getData().getDataSets()) - set.setDrawIcons(!set.isDrawIconsEnabled()); - - chart.invalidate(); - break; - } - case R.id.actionToggleHighlight: { - if(chart.getData() != null) { - chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled()); - chart.invalidate(); - } - break; - } - case R.id.actionTogglePinch: { - if (chart.isPinchZoomEnabled()) - chart.setPinchZoom(false); - else - chart.setPinchZoom(true); - - chart.invalidate(); - break; - } - case R.id.actionToggleAutoScaleMinMax: { - chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled()); - chart.notifyDataSetChanged(); - break; - } - case R.id.actionSave: { - if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { - saveToGallery(); - } else { - requestStoragePermission(chart); - } - break; - } - case R.id.animateX: { - chart.animateX(2000); - break; - } - case R.id.animateY: { - chart.animateY(2000); - break; } - case R.id.animateXY: { - chart.animateXY(2000, 2000); - break; + } else if (itemId == R.id.actionTogglePinch) { + if (chart.isPinchZoomEnabled()) + chart.setPinchZoom(false); + else + chart.setPinchZoom(true); + + chart.invalidate(); + } else if (itemId == R.id.actionToggleAutoScaleMinMax) { + chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled()); + chart.notifyDataSetChanged(); + } else if (itemId == R.id.actionSave) { + if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { + saveToGallery(); + } else { + requestStoragePermission(chart); } + } else if (itemId == R.id.animateX) { + chart.animateX(2000); + } else if (itemId == R.id.animateY) { + chart.animateY(2000); + } else if (itemId == R.id.animateXY) { + chart.animateXY(2000, 2000); } return true; } diff --git a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/CandleStickChartActivity.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/CandleStickChartActivity.java index ecf7167a62..762399faca 100644 --- a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/CandleStickChartActivity.java +++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/CandleStickChartActivity.java @@ -151,75 +151,53 @@ public boolean onCreateOptionsMenu(Menu menu) { @Override public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.viewGithub: { - Intent i = new Intent(Intent.ACTION_VIEW); - i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/CandleStickChartActivity.java")); - startActivity(i); - break; - } - case R.id.actionToggleValues: { - for (IDataSet set : chart.getData().getDataSets()) - set.setDrawValues(!set.isDrawValuesEnabled()); - - chart.invalidate(); - break; - } - case R.id.actionToggleIcons: { - for (IDataSet set : chart.getData().getDataSets()) - set.setDrawIcons(!set.isDrawIconsEnabled()); - - chart.invalidate(); - break; - } - case R.id.actionToggleHighlight: { - if(chart.getData() != null) { - chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled()); - chart.invalidate(); - } - break; - } - case R.id.actionTogglePinch: { - if (chart.isPinchZoomEnabled()) - chart.setPinchZoom(false); - else - chart.setPinchZoom(true); - + int itemId = item.getItemId(); + if (itemId == R.id.viewGithub) { + Intent i = new Intent(Intent.ACTION_VIEW); + i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/CandleStickChartActivity.java")); + startActivity(i); + } else if (itemId == R.id.actionToggleValues) { + for (IDataSet set : chart.getData().getDataSets()) + set.setDrawValues(!set.isDrawValuesEnabled()); + + chart.invalidate(); + } else if (itemId == R.id.actionToggleIcons) { + for (IDataSet set : chart.getData().getDataSets()) + set.setDrawIcons(!set.isDrawIconsEnabled()); + + chart.invalidate(); + } else if (itemId == R.id.actionToggleHighlight) { + if (chart.getData() != null) { + chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled()); chart.invalidate(); - break; } - case R.id.actionToggleAutoScaleMinMax: { - chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled()); - chart.notifyDataSetChanged(); - break; + } else if (itemId == R.id.actionTogglePinch) { + if (chart.isPinchZoomEnabled()) + chart.setPinchZoom(false); + else + chart.setPinchZoom(true); + + chart.invalidate(); + } else if (itemId == R.id.actionToggleAutoScaleMinMax) { + chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled()); + chart.notifyDataSetChanged(); + } else if (itemId == R.id.actionToggleMakeShadowSameColorAsCandle) { + for (ICandleDataSet set : chart.getData().getDataSets()) { + ((CandleDataSet) set).setShadowColorSameAsCandle(!set.getShadowColorSameAsCandle()); } - case R.id.actionToggleMakeShadowSameColorAsCandle: { - for (ICandleDataSet set : chart.getData().getDataSets()) { - ((CandleDataSet) set).setShadowColorSameAsCandle(!set.getShadowColorSameAsCandle()); - } - chart.invalidate(); - break; - } - case R.id.animateX: { - chart.animateX(2000); - break; - } - case R.id.animateY: { - chart.animateY(2000); - break; - } - case R.id.animateXY: { - chart.animateXY(2000, 2000); - break; - } - case R.id.actionSave: { - if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { - saveToGallery(); - } else { - requestStoragePermission(chart); - } - break; + chart.invalidate(); + } else if (itemId == R.id.animateX) { + chart.animateX(2000); + } else if (itemId == R.id.animateY) { + chart.animateY(2000); + } else if (itemId == R.id.animateXY) { + chart.animateXY(2000, 2000); + } else if (itemId == R.id.actionSave) { + if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { + saveToGallery(); + } else { + requestStoragePermission(chart); } } return true; diff --git a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/CombinedChartActivity.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/CombinedChartActivity.java index 0308b9a891..ab58047f23 100644 --- a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/CombinedChartActivity.java +++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/CombinedChartActivity.java @@ -240,39 +240,31 @@ public boolean onCreateOptionsMenu(Menu menu) { @Override public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.viewGithub: { - Intent i = new Intent(Intent.ACTION_VIEW); - i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/CombinedChartActivity.java")); - startActivity(i); - break; + int itemId = item.getItemId(); + if (itemId == R.id.viewGithub) { + Intent i = new Intent(Intent.ACTION_VIEW); + i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/CombinedChartActivity.java")); + startActivity(i); + } else if (itemId == R.id.actionToggleLineValues) { + for (IDataSet set : chart.getData().getDataSets()) { + if (set instanceof LineDataSet) + set.setDrawValues(!set.isDrawValuesEnabled()); } - case R.id.actionToggleLineValues: { - for (IDataSet set : chart.getData().getDataSets()) { - if (set instanceof LineDataSet) - set.setDrawValues(!set.isDrawValuesEnabled()); - } - - chart.invalidate(); - break; - } - case R.id.actionToggleBarValues: { - for (IDataSet set : chart.getData().getDataSets()) { - if (set instanceof BarDataSet) - set.setDrawValues(!set.isDrawValuesEnabled()); - } - - chart.invalidate(); - break; - } - case R.id.actionRemoveDataSet: { - int rnd = (int) getRandom(chart.getData().getDataSetCount(), 0); - chart.getData().removeDataSet(chart.getData().getDataSetByIndex(rnd)); - chart.getData().notifyDataChanged(); - chart.notifyDataSetChanged(); - chart.invalidate(); - break; + + chart.invalidate(); + } else if (itemId == R.id.actionToggleBarValues) { + for (IDataSet set : chart.getData().getDataSets()) { + if (set instanceof BarDataSet) + set.setDrawValues(!set.isDrawValuesEnabled()); } + + chart.invalidate(); + } else if (itemId == R.id.actionRemoveDataSet) { + int rnd = (int) getRandom(chart.getData().getDataSetCount(), 0); + chart.getData().removeDataSet(chart.getData().getDataSetByIndex(rnd)); + chart.getData().notifyDataChanged(); + chart.notifyDataSetChanged(); + chart.invalidate(); } return true; } diff --git a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/CubicLineChartActivity.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/CubicLineChartActivity.java index 996e088f43..b6d1dd7c03 100644 --- a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/CubicLineChartActivity.java +++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/CubicLineChartActivity.java @@ -162,134 +162,105 @@ public boolean onCreateOptionsMenu(Menu menu) { @Override public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.viewGithub: { - Intent i = new Intent(Intent.ACTION_VIEW); - i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/CubicLineChartActivity.java")); - startActivity(i); - break; - } - case R.id.actionToggleValues: { - for (IDataSet set : chart.getData().getDataSets()) - set.setDrawValues(!set.isDrawValuesEnabled()); - + int itemId = item.getItemId(); + if (itemId == R.id.viewGithub) { + Intent i = new Intent(Intent.ACTION_VIEW); + i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/CubicLineChartActivity.java")); + startActivity(i); + } else if (itemId == R.id.actionToggleValues) { + for (IDataSet set : chart.getData().getDataSets()) + set.setDrawValues(!set.isDrawValuesEnabled()); + + chart.invalidate(); + } else if (itemId == R.id.actionToggleHighlight) { + if (chart.getData() != null) { + chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled()); chart.invalidate(); - break; - } - case R.id.actionToggleHighlight: { - if(chart.getData() != null) { - chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled()); - chart.invalidate(); - } - break; } - case R.id.actionToggleFilled: { + } else if (itemId == R.id.actionToggleFilled) { + List sets = chart.getData() + .getDataSets(); - List sets = chart.getData() - .getDataSets(); + for (ILineDataSet iSet : sets) { - for (ILineDataSet iSet : sets) { + LineDataSet set = (LineDataSet) iSet; - LineDataSet set = (LineDataSet) iSet; - - if (set.isDrawFilledEnabled()) - set.setDrawFilled(false); - else - set.setDrawFilled(true); - } - chart.invalidate(); - break; + if (set.isDrawFilledEnabled()) + set.setDrawFilled(false); + else + set.setDrawFilled(true); } - case R.id.actionToggleCircles: { - List sets = chart.getData() - .getDataSets(); + chart.invalidate(); + } else if (itemId == R.id.actionToggleCircles) { + List sets = chart.getData() + .getDataSets(); - for (ILineDataSet iSet : sets) { + for (ILineDataSet iSet : sets) { - LineDataSet set = (LineDataSet) iSet; - if (set.isDrawCirclesEnabled()) - set.setDrawCircles(false); - else - set.setDrawCircles(true); - } - chart.invalidate(); - break; + LineDataSet set = (LineDataSet) iSet; + if (set.isDrawCirclesEnabled()) + set.setDrawCircles(false); + else + set.setDrawCircles(true); } - case R.id.actionToggleCubic: { - List sets = chart.getData() - .getDataSets(); + chart.invalidate(); + } else if (itemId == R.id.actionToggleCubic) { + List sets = chart.getData() + .getDataSets(); - for (ILineDataSet iSet : sets) { + for (ILineDataSet iSet : sets) { - LineDataSet set = (LineDataSet) iSet; - set.setMode(set.getMode() == LineDataSet.Mode.CUBIC_BEZIER - ? LineDataSet.Mode.LINEAR - : LineDataSet.Mode.CUBIC_BEZIER); - } - chart.invalidate(); - break; + LineDataSet set = (LineDataSet) iSet; + set.setMode(set.getMode() == LineDataSet.Mode.CUBIC_BEZIER + ? LineDataSet.Mode.LINEAR + : LineDataSet.Mode.CUBIC_BEZIER); } - case R.id.actionToggleStepped: { - List sets = chart.getData() - .getDataSets(); + chart.invalidate(); + } else if (itemId == R.id.actionToggleStepped) { + List sets = chart.getData() + .getDataSets(); - for (ILineDataSet iSet : sets) { + for (ILineDataSet iSet : sets) { - LineDataSet set = (LineDataSet) iSet; - set.setMode(set.getMode() == LineDataSet.Mode.STEPPED - ? LineDataSet.Mode.LINEAR - : LineDataSet.Mode.STEPPED); - } - chart.invalidate(); - break; + LineDataSet set = (LineDataSet) iSet; + set.setMode(set.getMode() == LineDataSet.Mode.STEPPED + ? LineDataSet.Mode.LINEAR + : LineDataSet.Mode.STEPPED); } - case R.id.actionToggleHorizontalCubic: { - List sets = chart.getData() - .getDataSets(); + chart.invalidate(); + } else if (itemId == R.id.actionToggleHorizontalCubic) { + List sets = chart.getData() + .getDataSets(); - for (ILineDataSet iSet : sets) { + for (ILineDataSet iSet : sets) { - LineDataSet set = (LineDataSet) iSet; - set.setMode(set.getMode() == LineDataSet.Mode.HORIZONTAL_BEZIER - ? LineDataSet.Mode.LINEAR - : LineDataSet.Mode.HORIZONTAL_BEZIER); - } - chart.invalidate(); - break; - } - case R.id.actionTogglePinch: { - if (chart.isPinchZoomEnabled()) - chart.setPinchZoom(false); - else - chart.setPinchZoom(true); - - chart.invalidate(); - break; + LineDataSet set = (LineDataSet) iSet; + set.setMode(set.getMode() == LineDataSet.Mode.HORIZONTAL_BEZIER + ? LineDataSet.Mode.LINEAR + : LineDataSet.Mode.HORIZONTAL_BEZIER); } - case R.id.actionToggleAutoScaleMinMax: { - chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled()); - chart.notifyDataSetChanged(); - break; - } - case R.id.animateX: { - chart.animateX(2000); - break; - } - case R.id.animateY: { - chart.animateY(2000); - break; - } - case R.id.animateXY: { - chart.animateXY(2000, 2000); - break; - } - case R.id.actionSave: { - if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { - saveToGallery(); - } else { - requestStoragePermission(chart); - } - break; + chart.invalidate(); + } else if (itemId == R.id.actionTogglePinch) { + if (chart.isPinchZoomEnabled()) + chart.setPinchZoom(false); + else + chart.setPinchZoom(true); + + chart.invalidate(); + } else if (itemId == R.id.actionToggleAutoScaleMinMax) { + chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled()); + chart.notifyDataSetChanged(); + } else if (itemId == R.id.animateX) { + chart.animateX(2000); + } else if (itemId == R.id.animateY) { + chart.animateY(2000); + } else if (itemId == R.id.animateXY) { + chart.animateXY(2000, 2000); + } else if (itemId == R.id.actionSave) { + if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { + saveToGallery(); + } else { + requestStoragePermission(chart); } } return true; diff --git a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/DrawChartActivity.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/DrawChartActivity.java index 7a32e5329c..aaeb084106 100644 --- a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/DrawChartActivity.java +++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/DrawChartActivity.java @@ -99,48 +99,38 @@ public boolean onCreateOptionsMenu(Menu menu) { @Override public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.actionToggleValues: { - List sets = chart.getData() - .getDataSets(); + int itemId = item.getItemId(); + if (itemId == R.id.actionToggleValues) { + List sets = chart.getData() + .getDataSets(); - for (ILineDataSet iSet : sets) { + for (ILineDataSet iSet : sets) { - LineDataSet set = (LineDataSet) iSet; - set.setDrawValues(!set.isDrawValuesEnabled()); - } - - chart.invalidate(); - break; + LineDataSet set = (LineDataSet) iSet; + set.setDrawValues(!set.isDrawValuesEnabled()); } - case R.id.actionToggleHighlight: { - if(chart.getData() != null) { - chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled()); - chart.invalidate(); - } - break; - } - case R.id.actionTogglePinch: { - if (chart.isPinchZoomEnabled()) - chart.setPinchZoom(false); - else - chart.setPinchZoom(true); + chart.invalidate(); + } else if (itemId == R.id.actionToggleHighlight) { + if (chart.getData() != null) { + chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled()); chart.invalidate(); - break; - } - case R.id.actionToggleAutoScaleMinMax: { - chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled()); - chart.notifyDataSetChanged(); - break; } - case R.id.actionSave: { - if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { - saveToGallery(); - } else { - requestStoragePermission(chart); - } - break; + } else if (itemId == R.id.actionTogglePinch) { + if (chart.isPinchZoomEnabled()) + chart.setPinchZoom(false); + else + chart.setPinchZoom(true); + + chart.invalidate(); + } else if (itemId == R.id.actionToggleAutoScaleMinMax) { + chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled()); + chart.notifyDataSetChanged(); + } else if (itemId == R.id.actionSave) { + if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { + saveToGallery(); + } else { + requestStoragePermission(chart); } } return true; diff --git a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/DynamicalAddingActivity.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/DynamicalAddingActivity.java index 84de449283..4459e26b8b 100644 --- a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/DynamicalAddingActivity.java +++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/DynamicalAddingActivity.java @@ -190,45 +190,31 @@ public boolean onCreateOptionsMenu(Menu menu) { @Override public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.viewGithub: { - Intent i = new Intent(Intent.ACTION_VIEW); - i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/DynamicalAddingActivity.java")); - startActivity(i); - break; - } - case R.id.actionAddEntry: { - addEntry(); - Toast.makeText(this, "Entry added!", Toast.LENGTH_SHORT).show(); - break; - } - case R.id.actionRemoveEntry: { - removeLastEntry(); - Toast.makeText(this, "Entry removed!", Toast.LENGTH_SHORT).show(); - break; - } - case R.id.actionAddDataSet: { - addDataSet(); - Toast.makeText(this, "DataSet added!", Toast.LENGTH_SHORT).show(); - break; - } - case R.id.actionRemoveDataSet: { - removeDataSet(); - Toast.makeText(this, "DataSet removed!", Toast.LENGTH_SHORT).show(); - break; - } - case R.id.actionClear: { - chart.clear(); - Toast.makeText(this, "Chart cleared!", Toast.LENGTH_SHORT).show(); - break; - } - case R.id.actionSave: { - if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { - saveToGallery(); - } else { - requestStoragePermission(chart); - } - break; + int itemId = item.getItemId(); + if (itemId == R.id.viewGithub) { + Intent i = new Intent(Intent.ACTION_VIEW); + i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/DynamicalAddingActivity.java")); + startActivity(i); + } else if (itemId == R.id.actionAddEntry) { + addEntry(); + Toast.makeText(this, "Entry added!", Toast.LENGTH_SHORT).show(); + } else if (itemId == R.id.actionRemoveEntry) { + removeLastEntry(); + Toast.makeText(this, "Entry removed!", Toast.LENGTH_SHORT).show(); + } else if (itemId == R.id.actionAddDataSet) { + addDataSet(); + Toast.makeText(this, "DataSet added!", Toast.LENGTH_SHORT).show(); + } else if (itemId == R.id.actionRemoveDataSet) { + removeDataSet(); + Toast.makeText(this, "DataSet removed!", Toast.LENGTH_SHORT).show(); + } else if (itemId == R.id.actionClear) { + chart.clear(); + Toast.makeText(this, "Chart cleared!", Toast.LENGTH_SHORT).show(); + } else if (itemId == R.id.actionSave) { + if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { + saveToGallery(); + } else { + requestStoragePermission(chart); } } diff --git a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/FilledLineActivity.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/FilledLineActivity.java index e821a04969..a2d6bb88fd 100644 --- a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/FilledLineActivity.java +++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/FilledLineActivity.java @@ -172,13 +172,10 @@ public boolean onCreateOptionsMenu(Menu menu) { @Override public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.viewGithub: { - Intent i = new Intent(Intent.ACTION_VIEW); - i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/FilledLineActivity.java")); - startActivity(i); - break; - } + if (item.getItemId() == R.id.viewGithub) { + Intent i = new Intent(Intent.ACTION_VIEW); + i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/FilledLineActivity.java")); + startActivity(i); } return true; diff --git a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/HalfPieChartActivity.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/HalfPieChartActivity.java index ed2adcc960..c881ef8262 100644 --- a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/HalfPieChartActivity.java +++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/HalfPieChartActivity.java @@ -151,13 +151,10 @@ public boolean onCreateOptionsMenu(Menu menu) { @Override public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.viewGithub: { - Intent i = new Intent(Intent.ACTION_VIEW); - i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/HalfPieChartActivity.java")); - startActivity(i); - break; - } + if (item.getItemId() == R.id.viewGithub) { + Intent i = new Intent(Intent.ACTION_VIEW); + i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/HalfPieChartActivity.java")); + startActivity(i); } return true; diff --git a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/HorizontalBarChartActivity.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/HorizontalBarChartActivity.java index 27f7f29627..a84d70682a 100644 --- a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/HorizontalBarChartActivity.java +++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/HorizontalBarChartActivity.java @@ -163,82 +163,60 @@ public boolean onCreateOptionsMenu(Menu menu) { @Override public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.viewGithub: { - Intent i = new Intent(Intent.ACTION_VIEW); - i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/HorizontalBarChartActivity.java")); - startActivity(i); - break; + int itemId = item.getItemId(); + if (itemId == R.id.viewGithub) { + Intent i = new Intent(Intent.ACTION_VIEW); + i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/HorizontalBarChartActivity.java")); + startActivity(i); + } else if (itemId == R.id.actionToggleValues) { + List sets = chart.getData() + .getDataSets(); + + for (IBarDataSet iSet : sets) { + iSet.setDrawValues(!iSet.isDrawValuesEnabled()); } - case R.id.actionToggleValues: { - List sets = chart.getData() - .getDataSets(); - for (IBarDataSet iSet : sets) { - iSet.setDrawValues(!iSet.isDrawValuesEnabled()); - } + chart.invalidate(); + } else if (itemId == R.id.actionToggleIcons) { + List sets = chart.getData() + .getDataSets(); - chart.invalidate(); - break; - } - case R.id.actionToggleIcons: { - List sets = chart.getData() - .getDataSets(); - - for (IBarDataSet iSet : sets) { - iSet.setDrawIcons(!iSet.isDrawIconsEnabled()); - } - - chart.invalidate(); - break; - } - case R.id.actionToggleHighlight: { - if(chart.getData() != null) { - chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled()); - chart.invalidate(); - } - break; - } - case R.id.actionTogglePinch: { - if (chart.isPinchZoomEnabled()) - chart.setPinchZoom(false); - else - chart.setPinchZoom(true); - - chart.invalidate(); - break; + for (IBarDataSet iSet : sets) { + iSet.setDrawIcons(!iSet.isDrawIconsEnabled()); } - case R.id.actionToggleAutoScaleMinMax: { - chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled()); - chart.notifyDataSetChanged(); - break; - } - case R.id.actionToggleBarBorders: { - for (IBarDataSet set : chart.getData().getDataSets()) - ((BarDataSet)set).setBarBorderWidth(set.getBarBorderWidth() == 1.f ? 0.f : 1.f); + chart.invalidate(); + } else if (itemId == R.id.actionToggleHighlight) { + if (chart.getData() != null) { + chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled()); chart.invalidate(); - break; - } - case R.id.animateX: { - chart.animateX(2000); - break; } - case R.id.animateY: { - chart.animateY(2000); - break; - } - case R.id.animateXY: { - chart.animateXY(2000, 2000); - break; - } - case R.id.actionSave: { - if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { - saveToGallery(); - } else { - requestStoragePermission(chart); - } - break; + } else if (itemId == R.id.actionTogglePinch) { + if (chart.isPinchZoomEnabled()) + chart.setPinchZoom(false); + else + chart.setPinchZoom(true); + + chart.invalidate(); + } else if (itemId == R.id.actionToggleAutoScaleMinMax) { + chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled()); + chart.notifyDataSetChanged(); + } else if (itemId == R.id.actionToggleBarBorders) { + for (IBarDataSet set : chart.getData().getDataSets()) + ((BarDataSet) set).setBarBorderWidth(set.getBarBorderWidth() == 1.f ? 0.f : 1.f); + + chart.invalidate(); + } else if (itemId == R.id.animateX) { + chart.animateX(2000); + } else if (itemId == R.id.animateY) { + chart.animateY(2000); + } else if (itemId == R.id.animateXY) { + chart.animateXY(2000, 2000); + } else if (itemId == R.id.actionSave) { + if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { + saveToGallery(); + } else { + requestStoragePermission(chart); } } return true; diff --git a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/HorizontalBarNegativeChartActivity.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/HorizontalBarNegativeChartActivity.java index 86d578cc43..d0417b72c0 100644 --- a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/HorizontalBarNegativeChartActivity.java +++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/HorizontalBarNegativeChartActivity.java @@ -164,82 +164,60 @@ public boolean onCreateOptionsMenu(Menu menu) { @Override public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.viewGithub: { - Intent i = new Intent(Intent.ACTION_VIEW); - i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/HorizontalBarChartActivity.java")); - startActivity(i); - break; + int itemId = item.getItemId(); + if (itemId == R.id.viewGithub) { + Intent i = new Intent(Intent.ACTION_VIEW); + i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/HorizontalBarChartActivity.java")); + startActivity(i); + } else if (itemId == R.id.actionToggleValues) { + List sets = chart.getData() + .getDataSets(); + + for (IBarDataSet iSet : sets) { + iSet.setDrawValues(!iSet.isDrawValuesEnabled()); } - case R.id.actionToggleValues: { - List sets = chart.getData() - .getDataSets(); - for (IBarDataSet iSet : sets) { - iSet.setDrawValues(!iSet.isDrawValuesEnabled()); - } + chart.invalidate(); + } else if (itemId == R.id.actionToggleIcons) { + List sets = chart.getData() + .getDataSets(); - chart.invalidate(); - break; - } - case R.id.actionToggleIcons: { - List sets = chart.getData() - .getDataSets(); - - for (IBarDataSet iSet : sets) { - iSet.setDrawIcons(!iSet.isDrawIconsEnabled()); - } - - chart.invalidate(); - break; - } - case R.id.actionToggleHighlight: { - if(chart.getData() != null) { - chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled()); - chart.invalidate(); - } - break; - } - case R.id.actionTogglePinch: { - if (chart.isPinchZoomEnabled()) - chart.setPinchZoom(false); - else - chart.setPinchZoom(true); - - chart.invalidate(); - break; + for (IBarDataSet iSet : sets) { + iSet.setDrawIcons(!iSet.isDrawIconsEnabled()); } - case R.id.actionToggleAutoScaleMinMax: { - chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled()); - chart.notifyDataSetChanged(); - break; - } - case R.id.actionToggleBarBorders: { - for (IBarDataSet set : chart.getData().getDataSets()) - ((BarDataSet)set).setBarBorderWidth(set.getBarBorderWidth() == 1.f ? 0.f : 1.f); + chart.invalidate(); + } else if (itemId == R.id.actionToggleHighlight) { + if (chart.getData() != null) { + chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled()); chart.invalidate(); - break; - } - case R.id.animateX: { - chart.animateX(2000); - break; } - case R.id.animateY: { - chart.animateY(2000); - break; - } - case R.id.animateXY: { - chart.animateXY(2000, 2000); - break; - } - case R.id.actionSave: { - if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { - saveToGallery(); - } else { - requestStoragePermission(chart); - } - break; + } else if (itemId == R.id.actionTogglePinch) { + if (chart.isPinchZoomEnabled()) + chart.setPinchZoom(false); + else + chart.setPinchZoom(true); + + chart.invalidate(); + } else if (itemId == R.id.actionToggleAutoScaleMinMax) { + chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled()); + chart.notifyDataSetChanged(); + } else if (itemId == R.id.actionToggleBarBorders) { + for (IBarDataSet set : chart.getData().getDataSets()) + ((BarDataSet) set).setBarBorderWidth(set.getBarBorderWidth() == 1.f ? 0.f : 1.f); + + chart.invalidate(); + } else if (itemId == R.id.animateX) { + chart.animateX(2000); + } else if (itemId == R.id.animateY) { + chart.animateY(2000); + } else if (itemId == R.id.animateXY) { + chart.animateXY(2000, 2000); + } else if (itemId == R.id.actionSave) { + if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { + saveToGallery(); + } else { + requestStoragePermission(chart); } } return true; diff --git a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/InvertedLineChartActivity.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/InvertedLineChartActivity.java index 08983710f2..7f52a4f923 100644 --- a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/InvertedLineChartActivity.java +++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/InvertedLineChartActivity.java @@ -151,98 +151,74 @@ public boolean onCreateOptionsMenu(Menu menu) { @Override public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.viewGithub: { - Intent i = new Intent(Intent.ACTION_VIEW); - i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/InvertedLineChartActivity.java")); - startActivity(i); - break; + int itemId = item.getItemId(); + if (itemId == R.id.viewGithub) { + Intent i = new Intent(Intent.ACTION_VIEW); + i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/InvertedLineChartActivity.java")); + startActivity(i); + } else if (itemId == R.id.actionToggleValues) { + List sets = chart.getData() + .getDataSets(); + + for (ILineDataSet iSet : sets) { + + LineDataSet set = (LineDataSet) iSet; + set.setDrawValues(!set.isDrawValuesEnabled()); } - case R.id.actionToggleValues: { - List sets = chart.getData() - .getDataSets(); - - for (ILineDataSet iSet : sets) { - - LineDataSet set = (LineDataSet) iSet; - set.setDrawValues(!set.isDrawValuesEnabled()); - } + chart.invalidate(); + } else if (itemId == R.id.actionToggleHighlight) { + if (chart.getData() != null) { + chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled()); chart.invalidate(); - break; } - case R.id.actionToggleHighlight: { - if(chart.getData() != null) { - chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled()); - chart.invalidate(); - } - break; - } - case R.id.actionToggleFilled: { - - List sets = chart.getData() - .getDataSets(); + } else if (itemId == R.id.actionToggleFilled) { + List sets = chart.getData() + .getDataSets(); - for (ILineDataSet iSet : sets) { + for (ILineDataSet iSet : sets) { - LineDataSet set = (LineDataSet) iSet; - if (set.isDrawFilledEnabled()) - set.setDrawFilled(false); - else - set.setDrawFilled(true); - } - chart.invalidate(); - break; - } - case R.id.actionToggleCircles: { - List sets = chart.getData() - .getDataSets(); - - for (ILineDataSet iSet : sets) { - - LineDataSet set = (LineDataSet) iSet; - if (set.isDrawCirclesEnabled()) - set.setDrawCircles(false); - else - set.setDrawCircles(true); - } - chart.invalidate(); - break; - } - case R.id.animateX: { - chart.animateX(2000); - break; - } - case R.id.animateY: { - chart.animateY(2000); - break; + LineDataSet set = (LineDataSet) iSet; + if (set.isDrawFilledEnabled()) + set.setDrawFilled(false); + else + set.setDrawFilled(true); } - case R.id.animateXY: { + chart.invalidate(); + } else if (itemId == R.id.actionToggleCircles) { + List sets = chart.getData() + .getDataSets(); - chart.animateXY(2000, 2000); - break; - } - case R.id.actionTogglePinch: { - if (chart.isPinchZoomEnabled()) - chart.setPinchZoom(false); - else - chart.setPinchZoom(true); + for (ILineDataSet iSet : sets) { - chart.invalidate(); - break; - } - case R.id.actionToggleAutoScaleMinMax: { - chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled()); - chart.notifyDataSetChanged(); - break; + LineDataSet set = (LineDataSet) iSet; + if (set.isDrawCirclesEnabled()) + set.setDrawCircles(false); + else + set.setDrawCircles(true); } - case R.id.actionSave: { - if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { - saveToGallery(); - } else { - requestStoragePermission(chart); - } - break; + chart.invalidate(); + } else if (itemId == R.id.animateX) { + chart.animateX(2000); + } else if (itemId == R.id.animateY) { + chart.animateY(2000); + } else if (itemId == R.id.animateXY) { + chart.animateXY(2000, 2000); + } else if (itemId == R.id.actionTogglePinch) { + if (chart.isPinchZoomEnabled()) + chart.setPinchZoom(false); + else + chart.setPinchZoom(true); + + chart.invalidate(); + } else if (itemId == R.id.actionToggleAutoScaleMinMax) { + chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled()); + chart.notifyDataSetChanged(); + } else if (itemId == R.id.actionSave) { + if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { + saveToGallery(); + } else { + requestStoragePermission(chart); } } return true; diff --git a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/LineChartActivity1.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/LineChartActivity1.java index dd43b056eb..a2feb18073 100644 --- a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/LineChartActivity1.java +++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/LineChartActivity1.java @@ -266,152 +266,121 @@ public boolean onCreateOptionsMenu(Menu menu) { @Override public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.viewGithub: { - Intent i = new Intent(Intent.ACTION_VIEW); - i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/LineChartActivity1.java")); - startActivity(i); - break; + int itemId = item.getItemId(); + if (itemId == R.id.viewGithub) { + Intent i = new Intent(Intent.ACTION_VIEW); + i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/LineChartActivity1.java")); + startActivity(i); + } else if (itemId == R.id.actionToggleValues) { + List sets = chart.getData() + .getDataSets(); + + for (ILineDataSet iSet : sets) { + + LineDataSet set = (LineDataSet) iSet; + set.setDrawValues(!set.isDrawValuesEnabled()); } - case R.id.actionToggleValues: { - List sets = chart.getData() - .getDataSets(); - for (ILineDataSet iSet : sets) { + chart.invalidate(); + } else if (itemId == R.id.actionToggleIcons) { + List sets = chart.getData() + .getDataSets(); - LineDataSet set = (LineDataSet) iSet; - set.setDrawValues(!set.isDrawValuesEnabled()); - } + for (ILineDataSet iSet : sets) { - chart.invalidate(); - break; + LineDataSet set = (LineDataSet) iSet; + set.setDrawIcons(!set.isDrawIconsEnabled()); } - case R.id.actionToggleIcons: { - List sets = chart.getData() - .getDataSets(); - - for (ILineDataSet iSet : sets) { - - LineDataSet set = (LineDataSet) iSet; - set.setDrawIcons(!set.isDrawIconsEnabled()); - } + chart.invalidate(); + } else if (itemId == R.id.actionToggleHighlight) { + if (chart.getData() != null) { + chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled()); chart.invalidate(); - break; - } - case R.id.actionToggleHighlight: { - if(chart.getData() != null) { - chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled()); - chart.invalidate(); - } - break; } - case R.id.actionToggleFilled: { - - List sets = chart.getData() - .getDataSets(); + } else if (itemId == R.id.actionToggleFilled) { + List sets = chart.getData() + .getDataSets(); - for (ILineDataSet iSet : sets) { + for (ILineDataSet iSet : sets) { - LineDataSet set = (LineDataSet) iSet; - if (set.isDrawFilledEnabled()) - set.setDrawFilled(false); - else - set.setDrawFilled(true); - } - chart.invalidate(); - break; + LineDataSet set = (LineDataSet) iSet; + if (set.isDrawFilledEnabled()) + set.setDrawFilled(false); + else + set.setDrawFilled(true); } - case R.id.actionToggleCircles: { - List sets = chart.getData() - .getDataSets(); + chart.invalidate(); + } else if (itemId == R.id.actionToggleCircles) { + List sets = chart.getData() + .getDataSets(); - for (ILineDataSet iSet : sets) { + for (ILineDataSet iSet : sets) { - LineDataSet set = (LineDataSet) iSet; - if (set.isDrawCirclesEnabled()) - set.setDrawCircles(false); - else - set.setDrawCircles(true); - } - chart.invalidate(); - break; + LineDataSet set = (LineDataSet) iSet; + if (set.isDrawCirclesEnabled()) + set.setDrawCircles(false); + else + set.setDrawCircles(true); } - case R.id.actionToggleCubic: { - List sets = chart.getData() - .getDataSets(); + chart.invalidate(); + } else if (itemId == R.id.actionToggleCubic) { + List sets = chart.getData() + .getDataSets(); - for (ILineDataSet iSet : sets) { + for (ILineDataSet iSet : sets) { - LineDataSet set = (LineDataSet) iSet; - set.setMode(set.getMode() == LineDataSet.Mode.CUBIC_BEZIER - ? LineDataSet.Mode.LINEAR - : LineDataSet.Mode.CUBIC_BEZIER); - } - chart.invalidate(); - break; + LineDataSet set = (LineDataSet) iSet; + set.setMode(set.getMode() == LineDataSet.Mode.CUBIC_BEZIER + ? LineDataSet.Mode.LINEAR + : LineDataSet.Mode.CUBIC_BEZIER); } - case R.id.actionToggleStepped: { - List sets = chart.getData() - .getDataSets(); + chart.invalidate(); + } else if (itemId == R.id.actionToggleStepped) { + List sets = chart.getData() + .getDataSets(); - for (ILineDataSet iSet : sets) { + for (ILineDataSet iSet : sets) { - LineDataSet set = (LineDataSet) iSet; - set.setMode(set.getMode() == LineDataSet.Mode.STEPPED - ? LineDataSet.Mode.LINEAR - : LineDataSet.Mode.STEPPED); - } - chart.invalidate(); - break; + LineDataSet set = (LineDataSet) iSet; + set.setMode(set.getMode() == LineDataSet.Mode.STEPPED + ? LineDataSet.Mode.LINEAR + : LineDataSet.Mode.STEPPED); } - case R.id.actionToggleHorizontalCubic: { - List sets = chart.getData() - .getDataSets(); + chart.invalidate(); + } else if (itemId == R.id.actionToggleHorizontalCubic) { + List sets = chart.getData() + .getDataSets(); - for (ILineDataSet iSet : sets) { - - LineDataSet set = (LineDataSet) iSet; - set.setMode(set.getMode() == LineDataSet.Mode.HORIZONTAL_BEZIER - ? LineDataSet.Mode.LINEAR - : LineDataSet.Mode.HORIZONTAL_BEZIER); - } - chart.invalidate(); - break; - } - case R.id.actionTogglePinch: { - if (chart.isPinchZoomEnabled()) - chart.setPinchZoom(false); - else - chart.setPinchZoom(true); + for (ILineDataSet iSet : sets) { - chart.invalidate(); - break; + LineDataSet set = (LineDataSet) iSet; + set.setMode(set.getMode() == LineDataSet.Mode.HORIZONTAL_BEZIER + ? LineDataSet.Mode.LINEAR + : LineDataSet.Mode.HORIZONTAL_BEZIER); } - case R.id.actionToggleAutoScaleMinMax: { - chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled()); - chart.notifyDataSetChanged(); - break; - } - case R.id.animateX: { - chart.animateX(2000); - break; - } - case R.id.animateY: { - chart.animateY(2000, Easing.EaseInCubic); - break; - } - case R.id.animateXY: { - chart.animateXY(2000, 2000); - break; - } - case R.id.actionSave: { - if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { - saveToGallery(); - } else { - requestStoragePermission(chart); - } - break; + chart.invalidate(); + } else if (itemId == R.id.actionTogglePinch) { + if (chart.isPinchZoomEnabled()) + chart.setPinchZoom(false); + else + chart.setPinchZoom(true); + + chart.invalidate(); + } else if (itemId == R.id.actionToggleAutoScaleMinMax) { + chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled()); + chart.notifyDataSetChanged(); + } else if (itemId == R.id.animateX) { + chart.animateX(2000); + } else if (itemId == R.id.animateY) { + chart.animateY(2000, Easing.EaseInCubic); + } else if (itemId == R.id.animateXY) { + chart.animateXY(2000, 2000); + } else if (itemId == R.id.actionSave) { + if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { + saveToGallery(); + } else { + requestStoragePermission(chart); } } return true; diff --git a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/LineChartActivity2.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/LineChartActivity2.java index 6b9cbb5f22..7f18696dfb 100644 --- a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/LineChartActivity2.java +++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/LineChartActivity2.java @@ -229,139 +229,110 @@ public boolean onCreateOptionsMenu(Menu menu) { @Override public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.viewGithub: { - Intent i = new Intent(Intent.ACTION_VIEW); - i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/LineChartActivity2.java")); - startActivity(i); - break; + int itemId = item.getItemId(); + if (itemId == R.id.viewGithub) { + Intent i = new Intent(Intent.ACTION_VIEW); + i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/LineChartActivity2.java")); + startActivity(i); + } else if (itemId == R.id.actionToggleValues) { + List sets = chart.getData() + .getDataSets(); + + for (ILineDataSet iSet : sets) { + + LineDataSet set = (LineDataSet) iSet; + set.setDrawValues(!set.isDrawValuesEnabled()); } - case R.id.actionToggleValues: { - List sets = chart.getData() - .getDataSets(); - - for (ILineDataSet iSet : sets) { - - LineDataSet set = (LineDataSet) iSet; - set.setDrawValues(!set.isDrawValuesEnabled()); - } + chart.invalidate(); + } else if (itemId == R.id.actionToggleHighlight) { + if (chart.getData() != null) { + chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled()); chart.invalidate(); - break; - } - case R.id.actionToggleHighlight: { - if (chart.getData() != null) { - chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled()); - chart.invalidate(); - } - break; } - case R.id.actionToggleFilled: { + } else if (itemId == R.id.actionToggleFilled) { + List sets = chart.getData() + .getDataSets(); - List sets = chart.getData() - .getDataSets(); + for (ILineDataSet iSet : sets) { - for (ILineDataSet iSet : sets) { - - LineDataSet set = (LineDataSet) iSet; - if (set.isDrawFilledEnabled()) - set.setDrawFilled(false); - else - set.setDrawFilled(true); - } - chart.invalidate(); - break; - } - case R.id.actionToggleCircles: { - List sets = chart.getData() - .getDataSets(); - - for (ILineDataSet iSet : sets) { - - LineDataSet set = (LineDataSet) iSet; - if (set.isDrawCirclesEnabled()) - set.setDrawCircles(false); - else - set.setDrawCircles(true); - } - chart.invalidate(); - break; + LineDataSet set = (LineDataSet) iSet; + if (set.isDrawFilledEnabled()) + set.setDrawFilled(false); + else + set.setDrawFilled(true); } - case R.id.actionToggleCubic: { - List sets = chart.getData() - .getDataSets(); + chart.invalidate(); + } else if (itemId == R.id.actionToggleCircles) { + List sets = chart.getData() + .getDataSets(); - for (ILineDataSet iSet : sets) { + for (ILineDataSet iSet : sets) { - LineDataSet set = (LineDataSet) iSet; - set.setMode(set.getMode() == LineDataSet.Mode.CUBIC_BEZIER - ? LineDataSet.Mode.LINEAR - : LineDataSet.Mode.CUBIC_BEZIER); - } - chart.invalidate(); - break; + LineDataSet set = (LineDataSet) iSet; + if (set.isDrawCirclesEnabled()) + set.setDrawCircles(false); + else + set.setDrawCircles(true); } - case R.id.actionToggleStepped: { - List sets = chart.getData() - .getDataSets(); + chart.invalidate(); + } else if (itemId == R.id.actionToggleCubic) { + List sets = chart.getData() + .getDataSets(); - for (ILineDataSet iSet : sets) { + for (ILineDataSet iSet : sets) { - LineDataSet set = (LineDataSet) iSet; - set.setMode(set.getMode() == LineDataSet.Mode.STEPPED - ? LineDataSet.Mode.LINEAR - : LineDataSet.Mode.STEPPED); - } - chart.invalidate(); - break; + LineDataSet set = (LineDataSet) iSet; + set.setMode(set.getMode() == LineDataSet.Mode.CUBIC_BEZIER + ? LineDataSet.Mode.LINEAR + : LineDataSet.Mode.CUBIC_BEZIER); } - case R.id.actionToggleHorizontalCubic: { - List sets = chart.getData() - .getDataSets(); + chart.invalidate(); + } else if (itemId == R.id.actionToggleStepped) { + List sets = chart.getData() + .getDataSets(); - for (ILineDataSet iSet : sets) { + for (ILineDataSet iSet : sets) { - LineDataSet set = (LineDataSet) iSet; - set.setMode(set.getMode() == LineDataSet.Mode.HORIZONTAL_BEZIER - ? LineDataSet.Mode.LINEAR - : LineDataSet.Mode.HORIZONTAL_BEZIER); - } - chart.invalidate(); - break; + LineDataSet set = (LineDataSet) iSet; + set.setMode(set.getMode() == LineDataSet.Mode.STEPPED + ? LineDataSet.Mode.LINEAR + : LineDataSet.Mode.STEPPED); } - case R.id.actionTogglePinch: { - if (chart.isPinchZoomEnabled()) - chart.setPinchZoom(false); - else - chart.setPinchZoom(true); + chart.invalidate(); + } else if (itemId == R.id.actionToggleHorizontalCubic) { + List sets = chart.getData() + .getDataSets(); - chart.invalidate(); - break; - } - case R.id.actionToggleAutoScaleMinMax: { - chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled()); - chart.notifyDataSetChanged(); - break; - } - case R.id.animateX: { - chart.animateX(2000); - break; - } - case R.id.animateY: { - chart.animateY(2000); - break; - } - case R.id.animateXY: { - chart.animateXY(2000, 2000); - break; + for (ILineDataSet iSet : sets) { + + LineDataSet set = (LineDataSet) iSet; + set.setMode(set.getMode() == LineDataSet.Mode.HORIZONTAL_BEZIER + ? LineDataSet.Mode.LINEAR + : LineDataSet.Mode.HORIZONTAL_BEZIER); } - case R.id.actionSave: { - if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { - saveToGallery(); - } else { - requestStoragePermission(chart); - } - break; + chart.invalidate(); + } else if (itemId == R.id.actionTogglePinch) { + if (chart.isPinchZoomEnabled()) + chart.setPinchZoom(false); + else + chart.setPinchZoom(true); + + chart.invalidate(); + } else if (itemId == R.id.actionToggleAutoScaleMinMax) { + chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled()); + chart.notifyDataSetChanged(); + } else if (itemId == R.id.animateX) { + chart.animateX(2000); + } else if (itemId == R.id.animateY) { + chart.animateY(2000); + } else if (itemId == R.id.animateXY) { + chart.animateXY(2000, 2000); + } else if (itemId == R.id.actionSave) { + if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { + saveToGallery(); + } else { + requestStoragePermission(chart); } } return true; diff --git a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/LineChartActivityColored.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/LineChartActivityColored.java index 6a12e8f95d..ceaaacecd8 100644 --- a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/LineChartActivityColored.java +++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/LineChartActivityColored.java @@ -138,13 +138,10 @@ public boolean onCreateOptionsMenu(Menu menu) { @Override public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.viewGithub: { - Intent i = new Intent(Intent.ACTION_VIEW); - i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/LineChartActivityColored.java")); - startActivity(i); - break; - } + if (item.getItemId() == R.id.viewGithub) { + Intent i = new Intent(Intent.ACTION_VIEW); + i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/LineChartActivityColored.java")); + startActivity(i); } return true; diff --git a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/LineChartTime.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/LineChartTime.java index 212b90ff87..a92268b409 100644 --- a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/LineChartTime.java +++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/LineChartTime.java @@ -167,128 +167,100 @@ public boolean onCreateOptionsMenu(Menu menu) { @Override public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.viewGithub: { - Intent i = new Intent(Intent.ACTION_VIEW); - i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/LineChartTime.java")); - startActivity(i); - break; + int itemId = item.getItemId(); + if (itemId == R.id.viewGithub) { + Intent i = new Intent(Intent.ACTION_VIEW); + i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/LineChartTime.java")); + startActivity(i); + } else if (itemId == R.id.actionToggleValues) { + List sets = chart.getData() + .getDataSets(); + + for (ILineDataSet iSet : sets) { + + LineDataSet set = (LineDataSet) iSet; + set.setDrawValues(!set.isDrawValuesEnabled()); } - case R.id.actionToggleValues: { - List sets = chart.getData() - .getDataSets(); - - for (ILineDataSet iSet : sets) { - - LineDataSet set = (LineDataSet) iSet; - set.setDrawValues(!set.isDrawValuesEnabled()); - } + chart.invalidate(); + } else if (itemId == R.id.actionToggleHighlight) { + if (chart.getData() != null) { + chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled()); chart.invalidate(); - break; } - case R.id.actionToggleHighlight: { - if (chart.getData() != null) { - chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled()); - chart.invalidate(); - } - break; - } - case R.id.actionToggleFilled: { - - List sets = chart.getData() - .getDataSets(); + } else if (itemId == R.id.actionToggleFilled) { + List sets = chart.getData() + .getDataSets(); - for (ILineDataSet iSet : sets) { + for (ILineDataSet iSet : sets) { - LineDataSet set = (LineDataSet) iSet; - if (set.isDrawFilledEnabled()) - set.setDrawFilled(false); - else - set.setDrawFilled(true); - } - chart.invalidate(); - break; - } - case R.id.actionToggleCircles: { - List sets = chart.getData() - .getDataSets(); - - for (ILineDataSet iSet : sets) { - - LineDataSet set = (LineDataSet) iSet; - if (set.isDrawCirclesEnabled()) - set.setDrawCircles(false); - else - set.setDrawCircles(true); - } - chart.invalidate(); - break; - } - case R.id.actionToggleCubic: { - List sets = chart.getData() - .getDataSets(); - - for (ILineDataSet iSet : sets) { - - LineDataSet set = (LineDataSet) iSet; - if (set.getMode() == LineDataSet.Mode.CUBIC_BEZIER) - set.setMode(LineDataSet.Mode.LINEAR); - else - set.setMode(LineDataSet.Mode.CUBIC_BEZIER); - } - chart.invalidate(); - break; - } - case R.id.actionToggleStepped: { - List sets = chart.getData() - .getDataSets(); - - for (ILineDataSet iSet : sets) { - - LineDataSet set = (LineDataSet) iSet; - if (set.getMode() == LineDataSet.Mode.STEPPED) - set.setMode(LineDataSet.Mode.LINEAR); - else - set.setMode(LineDataSet.Mode.STEPPED); - } - chart.invalidate(); - break; - } - case R.id.actionTogglePinch: { - if (chart.isPinchZoomEnabled()) - chart.setPinchZoom(false); + LineDataSet set = (LineDataSet) iSet; + if (set.isDrawFilledEnabled()) + set.setDrawFilled(false); else - chart.setPinchZoom(true); - - chart.invalidate(); - break; - } - case R.id.actionToggleAutoScaleMinMax: { - chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled()); - chart.notifyDataSetChanged(); - break; - } - case R.id.animateX: { - chart.animateX(2000); - break; + set.setDrawFilled(true); } - case R.id.animateY: { - chart.animateY(2000); - break; + chart.invalidate(); + } else if (itemId == R.id.actionToggleCircles) { + List sets = chart.getData() + .getDataSets(); + + for (ILineDataSet iSet : sets) { + + LineDataSet set = (LineDataSet) iSet; + if (set.isDrawCirclesEnabled()) + set.setDrawCircles(false); + else + set.setDrawCircles(true); } - case R.id.animateXY: { - chart.animateXY(2000, 2000); - break; + chart.invalidate(); + } else if (itemId == R.id.actionToggleCubic) { + List sets = chart.getData() + .getDataSets(); + + for (ILineDataSet iSet : sets) { + + LineDataSet set = (LineDataSet) iSet; + if (set.getMode() == LineDataSet.Mode.CUBIC_BEZIER) + set.setMode(LineDataSet.Mode.LINEAR); + else + set.setMode(LineDataSet.Mode.CUBIC_BEZIER); } + chart.invalidate(); + } else if (itemId == R.id.actionToggleStepped) { + List sets = chart.getData() + .getDataSets(); - case R.id.actionSave: { - if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { - saveToGallery(); - } else { - requestStoragePermission(chart); - } - break; + for (ILineDataSet iSet : sets) { + + LineDataSet set = (LineDataSet) iSet; + if (set.getMode() == LineDataSet.Mode.STEPPED) + set.setMode(LineDataSet.Mode.LINEAR); + else + set.setMode(LineDataSet.Mode.STEPPED); + } + chart.invalidate(); + } else if (itemId == R.id.actionTogglePinch) { + if (chart.isPinchZoomEnabled()) + chart.setPinchZoom(false); + else + chart.setPinchZoom(true); + + chart.invalidate(); + } else if (itemId == R.id.actionToggleAutoScaleMinMax) { + chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled()); + chart.notifyDataSetChanged(); + } else if (itemId == R.id.animateX) { + chart.animateX(2000); + } else if (itemId == R.id.animateY) { + chart.animateY(2000); + } else if (itemId == R.id.animateXY) { + chart.animateXY(2000, 2000); + } else if (itemId == R.id.actionSave) { + if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { + saveToGallery(); + } else { + requestStoragePermission(chart); } } return true; diff --git a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/ListViewBarChartActivity.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/ListViewBarChartActivity.java index 1466e5f9de..1897a13926 100644 --- a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/ListViewBarChartActivity.java +++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/ListViewBarChartActivity.java @@ -164,13 +164,10 @@ public boolean onCreateOptionsMenu(Menu menu) { @Override public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.viewGithub: { - Intent i = new Intent(Intent.ACTION_VIEW); - i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/ListViewBarChartActivity.java")); - startActivity(i); - break; - } + if (item.getItemId() == R.id.viewGithub) { + Intent i = new Intent(Intent.ACTION_VIEW); + i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/ListViewBarChartActivity.java")); + startActivity(i); } return true; diff --git a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/ListViewMultiChartActivity.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/ListViewMultiChartActivity.java index 1455691620..9ca3c1dc99 100644 --- a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/ListViewMultiChartActivity.java +++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/ListViewMultiChartActivity.java @@ -192,13 +192,10 @@ public boolean onCreateOptionsMenu(Menu menu) { @Override public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.viewGithub: { - Intent i = new Intent(Intent.ACTION_VIEW); - i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/ListViewMultiChartActivity.java")); - startActivity(i); - break; - } + if (item.getItemId() == R.id.viewGithub) { + Intent i = new Intent(Intent.ACTION_VIEW); + i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/ListViewMultiChartActivity.java")); + startActivity(i); } return true; diff --git a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/MultiLineChartActivity.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/MultiLineChartActivity.java index 11d69d8dae..b97be718a3 100644 --- a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/MultiLineChartActivity.java +++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/MultiLineChartActivity.java @@ -147,142 +147,114 @@ public boolean onCreateOptionsMenu(Menu menu) { @Override public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.viewGithub: { - Intent i = new Intent(Intent.ACTION_VIEW); - i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/MultiLineChartActivity.java")); - startActivity(i); - break; + int itemId = item.getItemId(); + if (itemId == R.id.viewGithub) { + Intent i = new Intent(Intent.ACTION_VIEW); + i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/MultiLineChartActivity.java")); + startActivity(i); + } else if (itemId == R.id.actionToggleValues) { + List sets = chart.getData() + .getDataSets(); + + for (ILineDataSet iSet : sets) { + + LineDataSet set = (LineDataSet) iSet; + set.setDrawValues(!set.isDrawValuesEnabled()); } - case R.id.actionToggleValues: { - List sets = chart.getData() - .getDataSets(); - for (ILineDataSet iSet : sets) { - - LineDataSet set = (LineDataSet) iSet; - set.setDrawValues(!set.isDrawValuesEnabled()); - } - - chart.invalidate(); - break; - } + chart.invalidate(); /* case R.id.actionToggleIcons: { break; } */ - case R.id.actionTogglePinch: { - if (chart.isPinchZoomEnabled()) - chart.setPinchZoom(false); - else - chart.setPinchZoom(true); - - chart.invalidate(); - break; - } - case R.id.actionToggleAutoScaleMinMax: { - chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled()); - chart.notifyDataSetChanged(); - break; - } - case R.id.actionToggleHighlight: { - if(chart.getData() != null) { - chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled()); - chart.invalidate(); - } - break; - } - case R.id.actionToggleFilled: { - List sets = chart.getData() - .getDataSets(); - - for (ILineDataSet iSet : sets) { - - LineDataSet set = (LineDataSet) iSet; - if (set.isDrawFilledEnabled()) - set.setDrawFilled(false); - else - set.setDrawFilled(true); - } - chart.invalidate(); - break; - } - case R.id.actionToggleCircles: { - List sets = chart.getData() - .getDataSets(); - - for (ILineDataSet iSet : sets) { - - LineDataSet set = (LineDataSet) iSet; - if (set.isDrawCirclesEnabled()) - set.setDrawCircles(false); - else - set.setDrawCircles(true); - } + } else if (itemId == R.id.actionTogglePinch) { + if (chart.isPinchZoomEnabled()) + chart.setPinchZoom(false); + else + chart.setPinchZoom(true); + + chart.invalidate(); + } else if (itemId == R.id.actionToggleAutoScaleMinMax) { + chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled()); + chart.notifyDataSetChanged(); + } else if (itemId == R.id.actionToggleHighlight) { + if (chart.getData() != null) { + chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled()); chart.invalidate(); - break; } - case R.id.actionToggleCubic: { - List sets = chart.getData() - .getDataSets(); + } else if (itemId == R.id.actionToggleFilled) { + List sets = chart.getData() + .getDataSets(); - for (ILineDataSet iSet : sets) { + for (ILineDataSet iSet : sets) { - LineDataSet set = (LineDataSet) iSet; - set.setMode(set.getMode() == LineDataSet.Mode.CUBIC_BEZIER - ? LineDataSet.Mode.LINEAR - : LineDataSet.Mode.CUBIC_BEZIER); - } - chart.invalidate(); - break; + LineDataSet set = (LineDataSet) iSet; + if (set.isDrawFilledEnabled()) + set.setDrawFilled(false); + else + set.setDrawFilled(true); } - case R.id.actionToggleStepped: { - List sets = chart.getData() - .getDataSets(); + chart.invalidate(); + } else if (itemId == R.id.actionToggleCircles) { + List sets = chart.getData() + .getDataSets(); - for (ILineDataSet iSet : sets) { + for (ILineDataSet iSet : sets) { - LineDataSet set = (LineDataSet) iSet; - set.setMode(set.getMode() == LineDataSet.Mode.STEPPED - ? LineDataSet.Mode.LINEAR - : LineDataSet.Mode.STEPPED); - } - chart.invalidate(); - break; + LineDataSet set = (LineDataSet) iSet; + if (set.isDrawCirclesEnabled()) + set.setDrawCircles(false); + else + set.setDrawCircles(true); } - case R.id.actionToggleHorizontalCubic: { - List sets = chart.getData() - .getDataSets(); + chart.invalidate(); + } else if (itemId == R.id.actionToggleCubic) { + List sets = chart.getData() + .getDataSets(); - for (ILineDataSet iSet : sets) { + for (ILineDataSet iSet : sets) { - LineDataSet set = (LineDataSet) iSet; - set.setMode(set.getMode() == LineDataSet.Mode.HORIZONTAL_BEZIER - ? LineDataSet.Mode.LINEAR - : LineDataSet.Mode.HORIZONTAL_BEZIER); - } - chart.invalidate(); - break; + LineDataSet set = (LineDataSet) iSet; + set.setMode(set.getMode() == LineDataSet.Mode.CUBIC_BEZIER + ? LineDataSet.Mode.LINEAR + : LineDataSet.Mode.CUBIC_BEZIER); } - case R.id.actionSave: { - if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { - saveToGallery(); - } else { - requestStoragePermission(chart); - } - break; - } - case R.id.animateX: { - chart.animateX(2000); - break; + chart.invalidate(); + } else if (itemId == R.id.actionToggleStepped) { + List sets = chart.getData() + .getDataSets(); + + for (ILineDataSet iSet : sets) { + + LineDataSet set = (LineDataSet) iSet; + set.setMode(set.getMode() == LineDataSet.Mode.STEPPED + ? LineDataSet.Mode.LINEAR + : LineDataSet.Mode.STEPPED); } - case R.id.animateY: { - chart.animateY(2000); - break; + chart.invalidate(); + } else if (itemId == R.id.actionToggleHorizontalCubic) { + List sets = chart.getData() + .getDataSets(); + + for (ILineDataSet iSet : sets) { + + LineDataSet set = (LineDataSet) iSet; + set.setMode(set.getMode() == LineDataSet.Mode.HORIZONTAL_BEZIER + ? LineDataSet.Mode.LINEAR + : LineDataSet.Mode.HORIZONTAL_BEZIER); } - case R.id.animateXY: { - chart.animateXY(2000, 2000); - break; + chart.invalidate(); + } else if (itemId == R.id.actionSave) { + if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { + saveToGallery(); + } else { + requestStoragePermission(chart); } + } else if (itemId == R.id.animateX) { + chart.animateX(2000); + } else if (itemId == R.id.animateY) { + chart.animateY(2000); + } else if (itemId == R.id.animateXY) { + chart.animateXY(2000, 2000); } return true; } diff --git a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/PerformanceLineChart.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/PerformanceLineChart.java index c557323451..5671c09a3b 100644 --- a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/PerformanceLineChart.java +++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/PerformanceLineChart.java @@ -107,13 +107,10 @@ public boolean onCreateOptionsMenu(Menu menu) { @Override public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.viewGithub: { - Intent i = new Intent(Intent.ACTION_VIEW); - i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/PerformanceLineChart.java")); - startActivity(i); - break; - } + if (item.getItemId() == R.id.viewGithub) { + Intent i = new Intent(Intent.ACTION_VIEW); + i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/PerformanceLineChart.java")); + startActivity(i); } return true; diff --git a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/PieChartActivity.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/PieChartActivity.java index 830025fbb1..726996d925 100644 --- a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/PieChartActivity.java +++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/PieChartActivity.java @@ -181,97 +181,69 @@ public boolean onCreateOptionsMenu(Menu menu) { @Override public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.viewGithub: { - Intent i = new Intent(Intent.ACTION_VIEW); - i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/PieChartActivity.java")); - startActivity(i); - break; + int itemId = item.getItemId(); + if (itemId == R.id.viewGithub) { + Intent i = new Intent(Intent.ACTION_VIEW); + i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/PieChartActivity.java")); + startActivity(i); + } else if (itemId == R.id.actionToggleValues) { + for (IDataSet set : chart.getData().getDataSets()) + set.setDrawValues(!set.isDrawValuesEnabled()); + + chart.invalidate(); + } else if (itemId == R.id.actionToggleIcons) { + for (IDataSet set : chart.getData().getDataSets()) + set.setDrawIcons(!set.isDrawIconsEnabled()); + + chart.invalidate(); + } else if (itemId == R.id.actionToggleHole) { + if (chart.isDrawHoleEnabled()) + chart.setDrawHoleEnabled(false); + else + chart.setDrawHoleEnabled(true); + chart.invalidate(); + } else if (itemId == R.id.actionToggleMinAngles) { + if (chart.getMinAngleForSlices() == 0f) + chart.setMinAngleForSlices(36f); + else + chart.setMinAngleForSlices(0f); + chart.notifyDataSetChanged(); + chart.invalidate(); + } else if (itemId == R.id.actionToggleCurvedSlices) { + boolean toSet = !chart.isDrawRoundedSlicesEnabled() || !chart.isDrawHoleEnabled(); + chart.setDrawRoundedSlices(toSet); + if (toSet && !chart.isDrawHoleEnabled()) { + chart.setDrawHoleEnabled(true); } - case R.id.actionToggleValues: { - for (IDataSet set : chart.getData().getDataSets()) - set.setDrawValues(!set.isDrawValuesEnabled()); - - chart.invalidate(); - break; - } - case R.id.actionToggleIcons: { - for (IDataSet set : chart.getData().getDataSets()) - set.setDrawIcons(!set.isDrawIconsEnabled()); - - chart.invalidate(); - break; - } - case R.id.actionToggleHole: { - if (chart.isDrawHoleEnabled()) - chart.setDrawHoleEnabled(false); - else - chart.setDrawHoleEnabled(true); - chart.invalidate(); - break; - } - case R.id.actionToggleMinAngles: { - if (chart.getMinAngleForSlices() == 0f) - chart.setMinAngleForSlices(36f); - else - chart.setMinAngleForSlices(0f); - chart.notifyDataSetChanged(); - chart.invalidate(); - break; - } - case R.id.actionToggleCurvedSlices: { - boolean toSet = !chart.isDrawRoundedSlicesEnabled() || !chart.isDrawHoleEnabled(); - chart.setDrawRoundedSlices(toSet); - if (toSet && !chart.isDrawHoleEnabled()) { - chart.setDrawHoleEnabled(true); - } - if (toSet && chart.isDrawSlicesUnderHoleEnabled()) { - chart.setDrawSlicesUnderHole(false); - } - chart.invalidate(); - break; - } - case R.id.actionDrawCenter: { - if (chart.isDrawCenterTextEnabled()) - chart.setDrawCenterText(false); - else - chart.setDrawCenterText(true); - chart.invalidate(); - break; - } - case R.id.actionToggleXValues: { - - chart.setDrawEntryLabels(!chart.isDrawEntryLabelsEnabled()); - chart.invalidate(); - break; - } - case R.id.actionTogglePercent: - chart.setUsePercentValues(!chart.isUsePercentValuesEnabled()); - chart.invalidate(); - break; - case R.id.animateX: { - chart.animateX(1400); - break; - } - case R.id.animateY: { - chart.animateY(1400); - break; - } - case R.id.animateXY: { - chart.animateXY(1400, 1400); - break; - } - case R.id.actionToggleSpin: { - chart.spin(1000, chart.getRotationAngle(), chart.getRotationAngle() + 360, Easing.EaseInOutCubic); - break; + if (toSet && chart.isDrawSlicesUnderHoleEnabled()) { + chart.setDrawSlicesUnderHole(false); } - case R.id.actionSave: { - if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { - saveToGallery(); - } else { - requestStoragePermission(chart); - } - break; + chart.invalidate(); + } else if (itemId == R.id.actionDrawCenter) { + if (chart.isDrawCenterTextEnabled()) + chart.setDrawCenterText(false); + else + chart.setDrawCenterText(true); + chart.invalidate(); + } else if (itemId == R.id.actionToggleXValues) { + chart.setDrawEntryLabels(!chart.isDrawEntryLabelsEnabled()); + chart.invalidate(); + } else if (itemId == R.id.actionTogglePercent) { + chart.setUsePercentValues(!chart.isUsePercentValuesEnabled()); + chart.invalidate(); + } else if (itemId == R.id.animateX) { + chart.animateX(1400); + } else if (itemId == R.id.animateY) { + chart.animateY(1400); + } else if (itemId == R.id.animateXY) { + chart.animateXY(1400, 1400); + } else if (itemId == R.id.actionToggleSpin) { + chart.spin(1000, chart.getRotationAngle(), chart.getRotationAngle() + 360, Easing.EaseInOutCubic); + } else if (itemId == R.id.actionSave) { + if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { + saveToGallery(); + } else { + requestStoragePermission(chart); } } return true; diff --git a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/PiePolylineChartActivity.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/PiePolylineChartActivity.java index dd3bd575da..db3d02dcc1 100644 --- a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/PiePolylineChartActivity.java +++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/PiePolylineChartActivity.java @@ -182,90 +182,64 @@ public boolean onCreateOptionsMenu(Menu menu) { @Override public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.viewGithub: { - Intent i = new Intent(Intent.ACTION_VIEW); - i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/PiePolylineChartActivity.java")); - startActivity(i); - break; + int itemId = item.getItemId(); + if (itemId == R.id.viewGithub) { + Intent i = new Intent(Intent.ACTION_VIEW); + i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/PiePolylineChartActivity.java")); + startActivity(i); + } else if (itemId == R.id.actionToggleValues) { + for (IDataSet set : chart.getData().getDataSets()) + set.setDrawValues(!set.isDrawValuesEnabled()); + + chart.invalidate(); + } else if (itemId == R.id.actionToggleHole) { + if (chart.isDrawHoleEnabled()) + chart.setDrawHoleEnabled(false); + else + chart.setDrawHoleEnabled(true); + chart.invalidate(); + } else if (itemId == R.id.actionToggleMinAngles) { + if (chart.getMinAngleForSlices() == 0f) + chart.setMinAngleForSlices(36f); + else + chart.setMinAngleForSlices(0f); + chart.notifyDataSetChanged(); + chart.invalidate(); + } else if (itemId == R.id.actionToggleCurvedSlices) { + boolean toSet = !chart.isDrawRoundedSlicesEnabled() || !chart.isDrawHoleEnabled(); + chart.setDrawRoundedSlices(toSet); + if (toSet && !chart.isDrawHoleEnabled()) { + chart.setDrawHoleEnabled(true); } - case R.id.actionToggleValues: { - for (IDataSet set : chart.getData().getDataSets()) - set.setDrawValues(!set.isDrawValuesEnabled()); - - chart.invalidate(); - break; - } - case R.id.actionToggleHole: { - if (chart.isDrawHoleEnabled()) - chart.setDrawHoleEnabled(false); - else - chart.setDrawHoleEnabled(true); - chart.invalidate(); - break; - } - case R.id.actionToggleMinAngles: { - if (chart.getMinAngleForSlices() == 0f) - chart.setMinAngleForSlices(36f); - else - chart.setMinAngleForSlices(0f); - chart.notifyDataSetChanged(); - chart.invalidate(); - break; - } - case R.id.actionToggleCurvedSlices: { - boolean toSet = !chart.isDrawRoundedSlicesEnabled() || !chart.isDrawHoleEnabled(); - chart.setDrawRoundedSlices(toSet); - if (toSet && !chart.isDrawHoleEnabled()) { - chart.setDrawHoleEnabled(true); - } - if (toSet && chart.isDrawSlicesUnderHoleEnabled()) { - chart.setDrawSlicesUnderHole(false); - } - chart.invalidate(); - break; - } - case R.id.actionDrawCenter: { - if (chart.isDrawCenterTextEnabled()) - chart.setDrawCenterText(false); - else - chart.setDrawCenterText(true); - chart.invalidate(); - break; - } - case R.id.actionToggleXValues: { - - chart.setDrawEntryLabels(!chart.isDrawEntryLabelsEnabled()); - chart.invalidate(); - break; - } - case R.id.actionTogglePercent: - chart.setUsePercentValues(!chart.isUsePercentValuesEnabled()); - chart.invalidate(); - break; - case R.id.animateX: { - chart.animateX(1400); - break; - } - case R.id.animateY: { - chart.animateY(1400); - break; - } - case R.id.animateXY: { - chart.animateXY(1400, 1400); - break; - } - case R.id.actionToggleSpin: { - chart.spin(1000, chart.getRotationAngle(), chart.getRotationAngle() + 360, Easing.EaseInOutCubic); - break; + if (toSet && chart.isDrawSlicesUnderHoleEnabled()) { + chart.setDrawSlicesUnderHole(false); } - case R.id.actionSave: { - if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { - saveToGallery(); - } else { - requestStoragePermission(chart); - } - break; + chart.invalidate(); + } else if (itemId == R.id.actionDrawCenter) { + if (chart.isDrawCenterTextEnabled()) + chart.setDrawCenterText(false); + else + chart.setDrawCenterText(true); + chart.invalidate(); + } else if (itemId == R.id.actionToggleXValues) { + chart.setDrawEntryLabels(!chart.isDrawEntryLabelsEnabled()); + chart.invalidate(); + } else if (itemId == R.id.actionTogglePercent) { + chart.setUsePercentValues(!chart.isUsePercentValuesEnabled()); + chart.invalidate(); + } else if (itemId == R.id.animateX) { + chart.animateX(1400); + } else if (itemId == R.id.animateY) { + chart.animateY(1400); + } else if (itemId == R.id.animateXY) { + chart.animateXY(1400, 1400); + } else if (itemId == R.id.actionToggleSpin) { + chart.spin(1000, chart.getRotationAngle(), chart.getRotationAngle() + 360, Easing.EaseInOutCubic); + } else if (itemId == R.id.actionSave) { + if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { + saveToGallery(); + } else { + requestStoragePermission(chart); } } return true; diff --git a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/RadarChartActivity.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/RadarChartActivity.java index 883eb7dfc1..ed9ae67079 100644 --- a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/RadarChartActivity.java +++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/RadarChartActivity.java @@ -159,95 +159,66 @@ public boolean onCreateOptionsMenu(Menu menu) { @Override public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.viewGithub: { - Intent i = new Intent(Intent.ACTION_VIEW); - i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/RadarChartActivity.java")); - startActivity(i); - break; - } - case R.id.actionToggleValues: { - for (IDataSet set : chart.getData().getDataSets()) - set.setDrawValues(!set.isDrawValuesEnabled()); - + int itemId = item.getItemId(); + if (itemId == R.id.viewGithub) { + Intent i = new Intent(Intent.ACTION_VIEW); + i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/RadarChartActivity.java")); + startActivity(i); + } else if (itemId == R.id.actionToggleValues) { + for (IDataSet set : chart.getData().getDataSets()) + set.setDrawValues(!set.isDrawValuesEnabled()); + + chart.invalidate(); + } else if (itemId == R.id.actionToggleHighlight) { + if (chart.getData() != null) { + chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled()); chart.invalidate(); - break; - } - case R.id.actionToggleHighlight: { - if (chart.getData() != null) { - chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled()); - chart.invalidate(); - } - break; } - case R.id.actionToggleRotate: { - if (chart.isRotationEnabled()) - chart.setRotationEnabled(false); + } else if (itemId == R.id.actionToggleRotate) { + if (chart.isRotationEnabled()) + chart.setRotationEnabled(false); + else + chart.setRotationEnabled(true); + chart.invalidate(); + } else if (itemId == R.id.actionToggleFilled) { + ArrayList sets = (ArrayList) chart.getData() + .getDataSets(); + + for (IRadarDataSet set : sets) { + if (set.isDrawFilledEnabled()) + set.setDrawFilled(false); else - chart.setRotationEnabled(true); - chart.invalidate(); - break; - } - case R.id.actionToggleFilled: { - - ArrayList sets = (ArrayList) chart.getData() - .getDataSets(); - - for (IRadarDataSet set : sets) { - if (set.isDrawFilledEnabled()) - set.setDrawFilled(false); - else - set.setDrawFilled(true); - } - chart.invalidate(); - break; + set.setDrawFilled(true); } - case R.id.actionToggleHighlightCircle: { + chart.invalidate(); + } else if (itemId == R.id.actionToggleHighlightCircle) { + ArrayList sets = (ArrayList) chart.getData() + .getDataSets(); - ArrayList sets = (ArrayList) chart.getData() - .getDataSets(); - - for (IRadarDataSet set : sets) { - set.setDrawHighlightCircleEnabled(!set.isDrawHighlightCircleEnabled()); - } - chart.invalidate(); - break; - } - case R.id.actionToggleXLabels: { - chart.getXAxis().setEnabled(!chart.getXAxis().isEnabled()); - chart.notifyDataSetChanged(); - chart.invalidate(); - break; - } - case R.id.actionToggleYLabels: { - - chart.getYAxis().setEnabled(!chart.getYAxis().isEnabled()); - chart.invalidate(); - break; - } - case R.id.animateX: { - chart.animateX(1400); - break; - } - case R.id.animateY: { - chart.animateY(1400); - break; - } - case R.id.animateXY: { - chart.animateXY(1400, 1400); - break; - } - case R.id.actionToggleSpin: { - chart.spin(2000, chart.getRotationAngle(), chart.getRotationAngle() + 360, Easing.EaseInOutCubic); - break; + for (IRadarDataSet set : sets) { + set.setDrawHighlightCircleEnabled(!set.isDrawHighlightCircleEnabled()); } - case R.id.actionSave: { - if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { - saveToGallery(); - } else { - requestStoragePermission(chart); - } - break; + chart.invalidate(); + } else if (itemId == R.id.actionToggleXLabels) { + chart.getXAxis().setEnabled(!chart.getXAxis().isEnabled()); + chart.notifyDataSetChanged(); + chart.invalidate(); + } else if (itemId == R.id.actionToggleYLabels) { + chart.getYAxis().setEnabled(!chart.getYAxis().isEnabled()); + chart.invalidate(); + } else if (itemId == R.id.animateX) { + chart.animateX(1400); + } else if (itemId == R.id.animateY) { + chart.animateY(1400); + } else if (itemId == R.id.animateXY) { + chart.animateXY(1400, 1400); + } else if (itemId == R.id.actionToggleSpin) { + chart.spin(2000, chart.getRotationAngle(), chart.getRotationAngle() + 360, Easing.EaseInOutCubic); + } else if (itemId == R.id.actionSave) { + if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { + saveToGallery(); + } else { + requestStoragePermission(chart); } } return true; diff --git a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/RealtimeLineChartActivity.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/RealtimeLineChartActivity.java index e26c460ffa..cb92096386 100644 --- a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/RealtimeLineChartActivity.java +++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/RealtimeLineChartActivity.java @@ -191,33 +191,23 @@ public boolean onCreateOptionsMenu(Menu menu) { @Override public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.viewGithub: { - Intent i = new Intent(Intent.ACTION_VIEW); - i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/RealtimeLineChartActivity.java")); - startActivity(i); - break; - } - case R.id.actionAdd: { - addEntry(); - break; - } - case R.id.actionClear: { - chart.clearValues(); - Toast.makeText(this, "Chart cleared!", Toast.LENGTH_SHORT).show(); - break; - } - case R.id.actionFeedMultiple: { - feedMultiple(); - break; - } - case R.id.actionSave: { - if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { - saveToGallery(); - } else { - requestStoragePermission(chart); - } - break; + int itemId = item.getItemId(); + if (itemId == R.id.viewGithub) { + Intent i = new Intent(Intent.ACTION_VIEW); + i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/RealtimeLineChartActivity.java")); + startActivity(i); + } else if (itemId == R.id.actionAdd) { + addEntry(); + } else if (itemId == R.id.actionClear) { + chart.clearValues(); + Toast.makeText(this, "Chart cleared!", Toast.LENGTH_SHORT).show(); + } else if (itemId == R.id.actionFeedMultiple) { + feedMultiple(); + } else if (itemId == R.id.actionSave) { + if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { + saveToGallery(); + } else { + requestStoragePermission(chart); } } return true; diff --git a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/ScatterChartActivity.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/ScatterChartActivity.java index e51755ad0b..ccb91e9105 100644 --- a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/ScatterChartActivity.java +++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/ScatterChartActivity.java @@ -158,67 +158,48 @@ public boolean onCreateOptionsMenu(Menu menu) { @Override public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.viewGithub: { - Intent i = new Intent(Intent.ACTION_VIEW); - i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/ScatterChartActivity.java")); - startActivity(i); - break; + int itemId = item.getItemId(); + if (itemId == R.id.viewGithub) { + Intent i = new Intent(Intent.ACTION_VIEW); + i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/ScatterChartActivity.java")); + startActivity(i); + } else if (itemId == R.id.actionToggleValues) { + List sets = chart.getData() + .getDataSets(); + + for (IScatterDataSet iSet : sets) { + + ScatterDataSet set = (ScatterDataSet) iSet; + set.setDrawValues(!set.isDrawValuesEnabled()); } - case R.id.actionToggleValues: { - List sets = chart.getData() - .getDataSets(); - - for (IScatterDataSet iSet : sets) { - - ScatterDataSet set = (ScatterDataSet) iSet; - set.setDrawValues(!set.isDrawValuesEnabled()); - } - - chart.invalidate(); - break; - } - case R.id.actionToggleHighlight: { - if(chart.getData() != null) { - chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled()); - chart.invalidate(); - } - break; - } - case R.id.actionTogglePinch: { - if (chart.isPinchZoomEnabled()) - chart.setPinchZoom(false); - else - chart.setPinchZoom(true); + chart.invalidate(); + } else if (itemId == R.id.actionToggleHighlight) { + if (chart.getData() != null) { + chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled()); chart.invalidate(); - break; - } - case R.id.actionToggleAutoScaleMinMax: { - chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled()); - chart.notifyDataSetChanged(); - break; - } - case R.id.animateX: { - chart.animateX(3000); - break; - } - case R.id.animateY: { - chart.animateY(3000); - break; - } - case R.id.animateXY: { - - chart.animateXY(3000, 3000); - break; } - case R.id.actionSave: { - if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { - saveToGallery(); - } else { - requestStoragePermission(chart); - } - break; + } else if (itemId == R.id.actionTogglePinch) { + if (chart.isPinchZoomEnabled()) + chart.setPinchZoom(false); + else + chart.setPinchZoom(true); + + chart.invalidate(); + } else if (itemId == R.id.actionToggleAutoScaleMinMax) { + chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled()); + chart.notifyDataSetChanged(); + } else if (itemId == R.id.animateX) { + chart.animateX(3000); + } else if (itemId == R.id.animateY) { + chart.animateY(3000); + } else if (itemId == R.id.animateXY) { + chart.animateXY(3000, 3000); + } else if (itemId == R.id.actionSave) { + if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { + saveToGallery(); + } else { + requestStoragePermission(chart); } } return true; diff --git a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/ScrollViewActivity.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/ScrollViewActivity.java index 37de64d728..6a6af07c74 100644 --- a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/ScrollViewActivity.java +++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/ScrollViewActivity.java @@ -84,13 +84,10 @@ public boolean onCreateOptionsMenu(Menu menu) { @Override public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.viewGithub: { - Intent i = new Intent(Intent.ACTION_VIEW); - i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/ScrollViewActivity.java")); - startActivity(i); - break; - } + if (item.getItemId() == R.id.viewGithub) { + Intent i = new Intent(Intent.ACTION_VIEW); + i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/ScrollViewActivity.java")); + startActivity(i); } return true; diff --git a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/StackedBarActivity.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/StackedBarActivity.java index 676e0e62b0..ae0171969a 100644 --- a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/StackedBarActivity.java +++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/StackedBarActivity.java @@ -161,87 +161,64 @@ public boolean onCreateOptionsMenu(Menu menu) { @Override public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.viewGithub: { - Intent i = new Intent(Intent.ACTION_VIEW); - i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/StackedBarActivity.java")); - startActivity(i); - break; + int itemId = item.getItemId(); + if (itemId == R.id.viewGithub) { + Intent i = new Intent(Intent.ACTION_VIEW); + i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/StackedBarActivity.java")); + startActivity(i); + } else if (itemId == R.id.actionToggleValues) { + List sets = chart.getData() + .getDataSets(); + + for (IBarDataSet iSet : sets) { + + BarDataSet set = (BarDataSet) iSet; + set.setDrawValues(!set.isDrawValuesEnabled()); } - case R.id.actionToggleValues: { - List sets = chart.getData() - .getDataSets(); - for (IBarDataSet iSet : sets) { + chart.invalidate(); + } else if (itemId == R.id.actionToggleIcons) { + List sets = chart.getData() + .getDataSets(); - BarDataSet set = (BarDataSet) iSet; - set.setDrawValues(!set.isDrawValuesEnabled()); - } + for (IBarDataSet iSet : sets) { - chart.invalidate(); - break; - } - case R.id.actionToggleIcons: { - List sets = chart.getData() - .getDataSets(); - - for (IBarDataSet iSet : sets) { - - BarDataSet set = (BarDataSet) iSet; - set.setDrawIcons(!set.isDrawIconsEnabled()); - } - - chart.invalidate(); - break; - } - case R.id.actionToggleHighlight: { - if (chart.getData() != null) { - chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled()); - chart.invalidate(); - } - break; - } - case R.id.actionTogglePinch: { - if (chart.isPinchZoomEnabled()) - chart.setPinchZoom(false); - else - chart.setPinchZoom(true); - - chart.invalidate(); - break; + BarDataSet set = (BarDataSet) iSet; + set.setDrawIcons(!set.isDrawIconsEnabled()); } - case R.id.actionToggleAutoScaleMinMax: { - chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled()); - chart.notifyDataSetChanged(); - break; - } - case R.id.actionToggleBarBorders: { - for (IBarDataSet set : chart.getData().getDataSets()) - ((BarDataSet) set).setBarBorderWidth(set.getBarBorderWidth() == 1.f ? 0.f : 1.f); + chart.invalidate(); + } else if (itemId == R.id.actionToggleHighlight) { + if (chart.getData() != null) { + chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled()); chart.invalidate(); - break; - } - case R.id.animateX: { - chart.animateX(2000); - break; } - case R.id.animateY: { - chart.animateY(2000); - break; - } - case R.id.animateXY: { - - chart.animateXY(2000, 2000); - break; - } - case R.id.actionSave: { - if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { - saveToGallery(); - } else { - requestStoragePermission(chart); - } - break; + } else if (itemId == R.id.actionTogglePinch) { + if (chart.isPinchZoomEnabled()) + chart.setPinchZoom(false); + else + chart.setPinchZoom(true); + + chart.invalidate(); + } else if (itemId == R.id.actionToggleAutoScaleMinMax) { + chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled()); + chart.notifyDataSetChanged(); + } else if (itemId == R.id.actionToggleBarBorders) { + for (IBarDataSet set : chart.getData().getDataSets()) + ((BarDataSet) set).setBarBorderWidth(set.getBarBorderWidth() == 1.f ? 0.f : 1.f); + + chart.invalidate(); + } else if (itemId == R.id.animateX) { + chart.animateX(2000); + } else if (itemId == R.id.animateY) { + chart.animateY(2000); + } else if (itemId == R.id.animateXY) { + chart.animateXY(2000, 2000); + } else if (itemId == R.id.actionSave) { + if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { + saveToGallery(); + } else { + requestStoragePermission(chart); } } return true; diff --git a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/StackedBarActivityNegative.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/StackedBarActivityNegative.java index 7af58c85ca..c00c510fa6 100644 --- a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/StackedBarActivityNegative.java +++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/StackedBarActivityNegative.java @@ -139,87 +139,64 @@ public boolean onCreateOptionsMenu(Menu menu) { @Override public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.viewGithub: { - Intent i = new Intent(Intent.ACTION_VIEW); - i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/StackedBarActivityNegative.java")); - startActivity(i); - break; + int itemId = item.getItemId(); + if (itemId == R.id.viewGithub) { + Intent i = new Intent(Intent.ACTION_VIEW); + i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/StackedBarActivityNegative.java")); + startActivity(i); + } else if (itemId == R.id.actionToggleValues) { + List sets = chart.getData() + .getDataSets(); + + for (IBarDataSet iSet : sets) { + + BarDataSet set = (BarDataSet) iSet; + set.setDrawValues(!set.isDrawValuesEnabled()); } - case R.id.actionToggleValues: { - List sets = chart.getData() - .getDataSets(); - for (IBarDataSet iSet : sets) { + chart.invalidate(); + } else if (itemId == R.id.actionToggleIcons) { + List sets = chart.getData() + .getDataSets(); - BarDataSet set = (BarDataSet) iSet; - set.setDrawValues(!set.isDrawValuesEnabled()); - } + for (IBarDataSet iSet : sets) { - chart.invalidate(); - break; - } - case R.id.actionToggleIcons: { - List sets = chart.getData() - .getDataSets(); - - for (IBarDataSet iSet : sets) { - - BarDataSet set = (BarDataSet) iSet; - set.setDrawIcons(!set.isDrawIconsEnabled()); - } - - chart.invalidate(); - break; + BarDataSet set = (BarDataSet) iSet; + set.setDrawIcons(!set.isDrawIconsEnabled()); } - case R.id.actionToggleHighlight: { - if(chart.getData() != null) { - chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled()); - chart.invalidate(); - } - break; - } - case R.id.actionTogglePinch: { - if (chart.isPinchZoomEnabled()) - chart.setPinchZoom(false); - else - chart.setPinchZoom(true); + chart.invalidate(); + } else if (itemId == R.id.actionToggleHighlight) { + if (chart.getData() != null) { + chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled()); chart.invalidate(); - break; - } - case R.id.actionToggleAutoScaleMinMax: { - chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled()); - chart.notifyDataSetChanged(); - break; - } - case R.id.actionToggleBarBorders: { - for (IBarDataSet set : chart.getData().getDataSets()) - ((BarDataSet)set).setBarBorderWidth(set.getBarBorderWidth() == 1.f ? 0.f : 1.f); - - chart.invalidate(); - break; - } - case R.id.animateX: { - chart.animateX(3000); - break; - } - case R.id.animateY: { - chart.animateY(3000); - break; - } - case R.id.animateXY: { - - chart.animateXY(3000, 3000); - break; } - case R.id.actionSave: { - if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { - saveToGallery(); - } else { - requestStoragePermission(chart); - } - break; + } else if (itemId == R.id.actionTogglePinch) { + if (chart.isPinchZoomEnabled()) + chart.setPinchZoom(false); + else + chart.setPinchZoom(true); + + chart.invalidate(); + } else if (itemId == R.id.actionToggleAutoScaleMinMax) { + chart.setAutoScaleMinMaxEnabled(!chart.isAutoScaleMinMaxEnabled()); + chart.notifyDataSetChanged(); + } else if (itemId == R.id.actionToggleBarBorders) { + for (IBarDataSet set : chart.getData().getDataSets()) + ((BarDataSet) set).setBarBorderWidth(set.getBarBorderWidth() == 1.f ? 0.f : 1.f); + + chart.invalidate(); + } else if (itemId == R.id.animateX) { + chart.animateX(3000); + } else if (itemId == R.id.animateY) { + chart.animateY(3000); + } else if (itemId == R.id.animateXY) { + chart.animateXY(3000, 3000); + } else if (itemId == R.id.actionSave) { + if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { + saveToGallery(); + } else { + requestStoragePermission(chart); } } return true; diff --git a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/fragments/SimpleChartDemo.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/fragments/SimpleChartDemo.java index 32b78142b5..d20a6b90ea 100644 --- a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/fragments/SimpleChartDemo.java +++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/fragments/SimpleChartDemo.java @@ -100,13 +100,10 @@ public boolean onCreateOptionsMenu(Menu menu) { @Override public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.viewGithub: { - Intent i = new Intent(Intent.ACTION_VIEW); - i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/fragments/SimpleChartDemo.java")); - startActivity(i); - break; - } + if (item.getItemId() == R.id.viewGithub) { + Intent i = new Intent(Intent.ACTION_VIEW); + i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/fragments/SimpleChartDemo.java")); + startActivity(i); } return true; diff --git a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/notimportant/MainActivity.java b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/notimportant/MainActivity.java index 88e5dc8d8b..11ab848b7c 100644 --- a/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/notimportant/MainActivity.java +++ b/MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/notimportant/MainActivity.java @@ -255,24 +255,21 @@ public boolean onOptionsItemSelected(MenuItem item) { Intent i; - switch (item.getItemId()) { - case R.id.viewGithub: - i = new Intent(Intent.ACTION_VIEW); - i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart")); - startActivity(i); - break; - case R.id.report: - i = new Intent(Intent.ACTION_SENDTO, Uri.fromParts( - "mailto", "philjay.librarysup@gmail.com", null)); - i.putExtra(Intent.EXTRA_SUBJECT, "MPAndroidChart Issue"); - i.putExtra(Intent.EXTRA_TEXT, "Your error report here..."); - startActivity(Intent.createChooser(i, "Report Problem")); - break; - case R.id.website: - i = new Intent(Intent.ACTION_VIEW); - i.setData(Uri.parse("http://at.linkedin.com/in/philippjahoda")); - startActivity(i); - break; + int itemId = item.getItemId(); + if (itemId == R.id.viewGithub) { + i = new Intent(Intent.ACTION_VIEW); + i.setData(Uri.parse("https://github.com/PhilJay/MPAndroidChart")); + startActivity(i); + } else if (itemId == R.id.report) { + i = new Intent(Intent.ACTION_SENDTO, Uri.fromParts( + "mailto", "philjay.librarysup@gmail.com", null)); + i.putExtra(Intent.EXTRA_SUBJECT, "MPAndroidChart Issue"); + i.putExtra(Intent.EXTRA_TEXT, "Your error report here..."); + startActivity(Intent.createChooser(i, "Report Problem")); + } else if (itemId == R.id.website) { + i = new Intent(Intent.ACTION_VIEW); + i.setData(Uri.parse("http://at.linkedin.com/in/philippjahoda")); + startActivity(i); } return true; diff --git a/MPChartLib/.settings/org.eclipse.buildship.core.prefs b/MPChartLib/.settings/org.eclipse.buildship.core.prefs new file mode 100644 index 0000000000..a7b84d9296 --- /dev/null +++ b/MPChartLib/.settings/org.eclipse.buildship.core.prefs @@ -0,0 +1,2 @@ +connection.project.dir=.. +eclipse.preferences.version=1 diff --git a/MPChartLib/.settings/org.eclipse.jdt.core.prefs b/MPChartLib/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000000..d1a8228954 --- /dev/null +++ b/MPChartLib/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,4 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=21 +org.eclipse.jdt.core.compiler.compliance=21 +org.eclipse.jdt.core.compiler.source=21 diff --git a/MPChartLib/build.gradle b/MPChartLib/build.gradle index 46585ed13c..79a5f2de4f 100644 --- a/MPChartLib/build.gradle +++ b/MPChartLib/build.gradle @@ -3,11 +3,11 @@ apply plugin: 'com.android.library' group='com.github.philjay' android { - compileSdkVersion 28 - buildToolsVersion '28.0.3' + compileSdkVersion 34 + namespace = "com.github.mikephil.charting" defaultConfig { minSdkVersion 14 - targetSdkVersion 28 + targetSdkVersion 34 versionCode 3 versionName '3.1.0' } diff --git a/MPChartLib/src/main/AndroidManifest.xml b/MPChartLib/src/main/AndroidManifest.xml index d75f87c7e2..af45ebcb44 100644 --- a/MPChartLib/src/main/AndroidManifest.xml +++ b/MPChartLib/src/main/AndroidManifest.xml @@ -1,5 +1,5 @@ - +