'Public Sub CaptureScreen( act As Activity, dir As String, fileName As String)
Public Sub CaptureScreen(dir As String, fileName As String)
Dim Obj1, Obj2 As Reflector
Dim bmp As Bitmap
Dim c As Canvas
Obj1.Target = Obj1.GetActivityBA
Obj1.Target = Obj1.GetField("vg")
bmp.InitializeMutable(Activity.Width, Activity.Height)
c.Initialize2(bmp)
Dim args(1) As Object
Dim types(1) As String
Obj2.Target = c
Obj2.Target = Obj2.GetField("canvas")
args(0) = Obj2.Target
types(0) = "android.graphics.Canvas"
Obj1.RunMethod4("draw", args, types)
Dim Out As OutputStream
Out = File.OpenOutput( dir, fileName, False)
Dim fmt As String = "PNG"
If fileName.ToUpperCase.Contains("JPG") Then fmt = "JPEG"
If fileName.ToUpperCase.Contains("JPEG") Then fmt = "JPEG"
bmp.WriteToStream(Out, 100, fmt)
Out.Close
End Sub
pv1.Initialize("pv1")
Activity.Color=Colors.black
Activity.AddView(pv1, -1%x, 1%y, 60%y, 60%y)
Dim piedata() As Float = Array As Float(35, 65)
pv1.Data = piedata
Dim piecolors() As Int = Array As Int(Colors.green, Colors.Blue)
pv1.PieColors = piecolors
pv1.ShowPercentLabel = True
pv1.BringToFront
What graphs are you making use of? I have done a saving option for one of them - think it was multi line charts.Thanks very much for taking the time to look Klaus. @Johan Schoeman is there a solution to this?
What graphs are you making use of? I have done a saving option for one of them - think it was multi line charts.
I need to revisit this library as I need to reverse some changes that I have done recently. I will then add save options to the other graph type that I have not done so before.
The bar and pie graphs in the library already provides for the below methods (the wrapper code) - you should be able to get a Bitmap back and then save it:tHANKS VERY MUCH, The only graphs I am using ( at this point) are the bar and pie graphs. There is a small test program attached at post #4.
Thanks again for any help and for your efforts with the library
/**
* Saves the current state of the chart to the gallery as a JPEG image. The
* filename and compression can be set. 0 == maximum compression, 100 = low
* compression (high quality). NOTE: Needs permission WRITE_EXTERNAL_STORAGE
*
* fileName e.g. "my_image"
* quality e.g. 50, min = 0, max = 100
*/
public void saveToGallery(String fileName, int quality) {
cv.saveToGallery(fileName, quality);
}
/**
* Saves the current chart state with the given name to the given path on
* the sdcard leaving the path empty "" will put the saved file directly on
* the SD card chart is saved as a PNG image, example:
* saveToPath("myfilename", "foldername1/foldername2");
*
* fileName e.g. "my_image"
* pathOnSD e.g. "folder1/folder2/folder3"
*/
public void saveToPath(String fileName, String pathOnSD) {
cv.saveToPath(fileName, pathOnSD);
}
/**
* Returns the bitmap that represents the chart.
*
* @return
*/
public Bitmap getChartBitmap() {
Bitmap image = cv.getChartBitmap();
// byte[] byteArray = cv.getChartBitmap();
// image = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length); //added by johan schoeman
BitmapWrapper bw = new BitmapWrapper(); //added by johan schoeman - Erel advised
bw.setObject(image);
return image;
}
public void setSavedImageBackgroundColor(int color){
cv.setSavedImageBackgroundColor(color);
}
Dim bm As Bitmap
bm = mpc1.ChartBitmap
Will look into it tonight - there is probably still some "noise" that I have not reversed out.I suspected that it may be from another library so I searched and downloaded the project from your mpchartlib. I tried to run the sample project with this version but i just got a whole load of errors.
Logger connected to: samsung GT-N7100
--------- beginning of /dev/log/main
Copying updated assets files (1)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Class not found: mpandroidchartwrapper.pieViewWrapper, trying: JHS.MPChart.pieViewWrapper
Error occurred on line: 30 (Main)
java.lang.RuntimeException: java.lang.ClassNotFoundException: JHS.MPChart.pieViewWrapper
at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:166)
at anywheresoftware.b4a.objects.ActivityWrapper.LoadLayout(ActivityWrapper.java:209)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:710)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:342)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
at JHS.MPChart.main.afterFirstLayout(main.java:102)
at JHS.MPChart.main.access$000(main.java:17)
at JHS.MPChart.main$WaitForLayout.run(main.java:80)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5602)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: JHS.MPChart.pieViewWrapper
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:251)
at java.lang.Class.forName(Class.java:216)
at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayoutHelper(LayoutBuilder.java:377)
at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayoutHelper(LayoutBuilder.java:425)
at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:144)
... 21 more
Caused by: java.lang.NoClassDefFoundError: JHS/MPChart/pieViewWrapper
... 27 more
Caused by: java.lang.ClassNotFoundException: Didn't find class "JHS.MPChart.pieViewWrapper" on path: DexPathList[[zip file "/data/app/JHS.MPChart-1.apk"],nativeLibraryDirectories=[/data/app-lib/JHS.MPChart-1, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:67)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
... 27 more
** Activity (main) Resume **
Copying updated assets files (1)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Class not found: mpandroidchartwrapper.pieViewWrapper, trying: JHS.MPChart.pieViewWrapper
Error occurred on line: 30 (Main)
java.lang.RuntimeException: java.lang.ClassNotFoundException: JHS.MPChart.pieViewWrapper
at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:166)
at anywheresoftware.b4a.objects.ActivityWrapper.LoadLayout(ActivityWrapper.java:209)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:710)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:342)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
at JHS.MPChart.main.afterFirstLayout(main.java:102)
at JHS.MPChart.main.access$000(main.java:17)
at JHS.MPChart.main$WaitForLayout.run(main.java:80)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5602)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: JHS.MPChart.pieViewWrapper
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:251)
at java.lang.Class.forName(Class.java:216)
at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayoutHelper(LayoutBuilder.java:377)
at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayoutHelper(LayoutBuilder.java:425)
at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:144)
... 21 more
Caused by: java.lang.NoClassDefFoundError: JHS/MPChart/pieViewWrapper
... 27 more
Caused by: java.lang.ClassNotFoundException: Didn't find class "JHS.MPChart.pieViewWrapper" on path: DexPathList[[zip file "/data/app/JHS.MPChart-1.apk"],nativeLibraryDirectories=[/data/app-lib/JHS.MPChart-1, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:67)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
... 27 more
I suspected that it may be from another library so I searched and downloaded the project from your mpchartlib. I tried to run the sample project with this version but i just got a whole load of errors.
Logger connected to: samsung GT-N7100
--------- beginning of /dev/log/main
Copying updated assets files (1)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Class not found: mpandroidchartwrapper.pieViewWrapper, trying: JHS.MPChart.pieViewWrapper
Error occurred on line: 30 (Main)
java.lang.RuntimeException: java.lang.ClassNotFoundException: JHS.MPChart.pieViewWrapper
at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:166)
at anywheresoftware.b4a.objects.ActivityWrapper.LoadLayout(ActivityWrapper.java:209)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:710)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:342)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
at JHS.MPChart.main.afterFirstLayout(main.java:102)
at JHS.MPChart.main.access$000(main.java:17)
at JHS.MPChart.main$WaitForLayout.run(main.java:80)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5602)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: JHS.MPChart.pieViewWrapper
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:251)
at java.lang.Class.forName(Class.java:216)
at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayoutHelper(LayoutBuilder.java:377)
at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayoutHelper(LayoutBuilder.java:425)
at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:144)
... 21 more
Caused by: java.lang.NoClassDefFoundError: JHS/MPChart/pieViewWrapper
... 27 more
Caused by: java.lang.ClassNotFoundException: Didn't find class "JHS.MPChart.pieViewWrapper" on path: DexPathList[[zip file "/data/app/JHS.MPChart-1.apk"],nativeLibraryDirectories=[/data/app-lib/JHS.MPChart-1, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:67)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
... 27 more
** Activity (main) Resume **
Copying updated assets files (1)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Class not found: mpandroidchartwrapper.pieViewWrapper, trying: JHS.MPChart.pieViewWrapper
Error occurred on line: 30 (Main)
java.lang.RuntimeException: java.lang.ClassNotFoundException: JHS.MPChart.pieViewWrapper
at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:166)
at anywheresoftware.b4a.objects.ActivityWrapper.LoadLayout(ActivityWrapper.java:209)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:710)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:342)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
at JHS.MPChart.main.afterFirstLayout(main.java:102)
at JHS.MPChart.main.access$000(main.java:17)
at JHS.MPChart.main$WaitForLayout.run(main.java:80)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5602)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: JHS.MPChart.pieViewWrapper
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:251)
at java.lang.Class.forName(Class.java:216)
at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayoutHelper(LayoutBuilder.java:377)
at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayoutHelper(LayoutBuilder.java:425)
at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:144)
... 21 more
Caused by: java.lang.NoClassDefFoundError: JHS/MPChart/pieViewWrapper
... 27 more
Caused by: java.lang.ClassNotFoundException: Didn't find class "JHS.MPChart.pieViewWrapper" on path: DexPathList[[zip file "/data/app/JHS.MPChart-1.apk"],nativeLibraryDirectories=[/data/app-lib/JHS.MPChart-1, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:67)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
... 27 more
#End Region
#AdditionalRes: ..\ProjectRes
#Region Activity Attributes
#Region Project Attributes
#ApplicationLabel: MPPieChart
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: landscape
#CanInstallToExternalStorage: False
#End Region
#AdditionalRes: ..\ProjectRes
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Private mpc1 As PieChart
Private iv1 As ImageView
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("main")
mpc1.UsePercentValues = True
mpc1.DrawHoleEnabled = True
mpc1.HoleColorTransparent = True
mpc1.TransparentCircleColor = Colors.White
mpc1.TransparentCircleAlpha = 110
mpc1.HoleRadius = 58.0
mpc1.TransparentCircleRadius = 61.0
mpc1.DrawCenterText = True
mpc1.CenterText = "Wrapped by Johan"
mpc1.CenterTextColor = Colors.White
mpc1.CenterTextRadiusPercent = 100.0
mpc1.CenterTextSize = 12.0
mpc1.DrawSliceText = True
mpc1.HoleColor = Colors.Black
mpc1.TransparentCircleColor = Colors.Transparent
mpc1.RotationEnabled = True
' RIGHT_OF_CHART, RIGHT_OF_CHART_CENTER, RIGHT_OF_CHART_INSIDE,
' LEFT_OF_CHART, LEFT_OF_CHART_CENTER, LEFT_OF_CHART_INSIDE,
' BELOW_CHART_LEFT, BELOW_CHART_RIGHT, BELOW_CHART_CENTER,
' PIECHART_CENTER
mpc1.TheLegendPosition = "RIGHT_OF_CHART"
mpc1.TheLegendColor = Colors.yellow
mpc1.TheLegendTextSize = 12.0
mpc1.LegendTitle = "MONTHS"
mpc1.ChartDescription = "TITLE : Some Arbitrary Data"
mpc1.ChartDescriptionColor = Colors.ARGB(200,0,255,255)
mpc1.ChartDescriptionTextSize = 14
mpc1.ValueTextColor = Colors.Black
mpc1.ValueTextSize = 12.0
mpc1.PieColors = Array As Int(Colors.Blue, Colors.Yellow, Colors.Green, Colors.Red, Colors.Magenta, Colors.Cyan)
mpc1.LegendText = Array As String("Jan", "Feb", "Mar", "Apr", "May", "Jun")
mpc1.ChartData = Array As Float(128.0, 16.0, 46.0, 40.0, 30.0, 40.0) 'values - it will be converted to %
mpc1.PieData = 6
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub mpc1_value_selected(index As Int, value As Float)
Log("index = " & index)
Log("value = " & value)
End Sub
Sub mpc1_long_pressed
Log("Long Pressed")
Dim bm As Bitmap = mpc1.ChartBitmap
iv1.Bitmap = bm
End Sub
Attached are new B4A lib files for AndroidCharts that will return a bitmap to the B4A project (have added it for bar, pie, and line charts). Sure you will figure out how to use it - see the sample code below and take note of the files in the /Objects/res folder of the original B4A projects that use this library. The property of these files need to be set to READ ONLY else they will get deleted when you compile the project(s) for the first time.Thanks very much @Johan . I have not tried it yet but is this the same library? the one I have is called AndroidCharts.jar V1.00
#Region Project Attributes
#ApplicationLabel: AndroidPieChart
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: landscape
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Private pv1 As PieView
Private iv1 As ImageView
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("main")
iv1.Initialize("")
pv1.Initialize("pv1")
Activity.AddView(pv1, 51%x, 5%y, 49%x, 90%y)
Activity.AddView(iv1, 0%x, 5%y, 49%x, 90%y)
Dim piedata() As Float = Array As Float(10, 15, 20, 25, 15, 10, 5)
pv1.Data = piedata
Dim piecolors() As Int = Array As Int(Colors.Green, Colors.Blue, Colors.Magenta, Colors.Yellow, Colors.DarkGray, Colors.Cyan, Colors.Red)
pv1.PieColors = piecolors
pv1.PieTextColor = Colors.Black
pv1.ShowPercentLabel = True
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub pv1_pie_clicked
Log("Touched pie slice with index = " & pv1.PieClickedIndex)
Dim bm As Bitmap
bm = pv1.ChartBitmap
iv1.Bitmap = bm
End Sub
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?