CopyPastor

Detecting plagiarism made easy.

Score: 0.7647862434387207; Reported for: String similarity Open both answers

Possible Plagiarism

Plagiarized on 2019-06-17
by Patrick Lüthi

Original Post

Original - Posted on 2012-06-05
by Derzu



            
Present in both answers; Present only in the new answer; Present only in the old answer;

JAVA:
public class JavaScriptInterface { Context mContext; private static int ind=-1; private static int [] val = { 25, 25, 50, 30, 40, 30, 30, 5, 9 }; public JavaScriptInterface(Context c) { mContext = c; } @JavascriptInterface public JSONArray getChartData() { String texto = " [ {name: 'valor1', 2007: "+val[(++ind)%9]+"}, "+ " {name: 'valor2', 2007: "+val[(++ind)%9]+"}, "+ " {name: 'valor3', 2007: "+val[(++ind)%9]+"} ]"; JSONArray jsonar=null; try { jsonar = new JSONArray(texto); } catch (JSONException e) { e.printStackTrace(); } return jsonar; } }
JS:
window.generateData = function() { /*var data = [ {name: 'valor1', 2007: 50}, {name: 'valor2', 2007: 20}, {name: 'valor3', 2007: 30} ]; */ var data = JSON.parse( Android.getChartData() ); return data; };
I found a solution, using JSON. My Java method returns a JSONArray, on my javascript code I receive this and convert to a javascript vector using JSON.parse(). See the example:
Java:
public class JavaScriptInterface { Context mContext; private static int ind=-1; private static int [] val = { 25, 25, 50, 30, 40, 30, 30, 5, 9 };
public JavaScriptInterface(Context c) { mContext = c; }
@JavascriptInterface public JSONArray getChartData() { String texto = " [ {name: 'valor1', 2007: "+val[(++ind)%9]+"}, "+ " {name: 'valor2', 2007: "+val[(++ind)%9]+"}, "+ " {name: 'valor3', 2007: "+val[(++ind)%9]+"} ]"; JSONArray jsonar=null; try { jsonar = new JSONArray(texto); } catch (JSONException e) { e.printStackTrace(); } return jsonar; } }
Now the javascript code:
window.generateData = function() { /*var data = [ {name: 'valor1', 2007: 50}, {name: 'valor2', 2007: 20}, {name: 'valor3', 2007: 30} ]; */ var data = JSON.parse( Android.getChartData() ); return data; }; The commented code above show how it was when static, and now the data came from the Java code.
It was testes on Android 2.1 and 3.2.

        
Present in both answers; Present only in the new answer; Present only in the old answer;