gamarra Posted July 16, 2012 at 10:55 AM Report Share #468822 Posted July 16, 2012 at 10:55 AM boas pessoal. gostaria de saber como faço para ler um ficheiro xml no android? por exemplo : tenho um ficheiro xml que diz la para aparecer a cor vermelha, o ficheiro e lido detecta a cor vermelha e coloca a cor num surfaceview alguem me pode explicar como se faz ? Link to comment Share on other sites More sharing options...
HappyHippyHippo Posted July 16, 2012 at 11:16 AM Report Share #468825 Posted July 16, 2012 at 11:16 AM - lês o ficheiro XML - crias a tua view - procuras o que tens de procurar da "source" que pretendes - alteras os pixeis da view criada dependendo dos pixeis verificados na "source" IRC : sim, é algo que ainda existe >> #p@p Portugol Plus Link to comment Share on other sites More sharing options...
gamarra Posted July 16, 2012 at 11:21 AM Author Report Share #468826 Posted July 16, 2012 at 11:21 AM neste site http://www.ibm.com/developerworks/br/opensource/library/x-android/ ele fala do SAX, o que e? Link to comment Share on other sites More sharing options...
HappyHippyHippo Posted July 16, 2012 at 11:31 AM Report Share #468827 Posted July 16, 2012 at 11:31 AM http://pt.wikipedia.org/wiki/Simple_API_for_XML IRC : sim, é algo que ainda existe >> #p@p Portugol Plus Link to comment Share on other sites More sharing options...
gamarra Posted July 16, 2012 at 12:44 PM Author Report Share #468844 Posted July 16, 2012 at 12:44 PM json file , algum tutorial a mostrar como se lê automaticamente????? Link to comment Share on other sites More sharing options...
Flinger Posted July 16, 2012 at 02:08 PM Report Share #468863 Posted July 16, 2012 at 02:08 PM http://www.androidhive.info/2012/01/android-json-parsing-tutorial/ Link to comment Share on other sites More sharing options...
gamarra Posted July 18, 2012 at 10:43 AM Author Report Share #469118 Posted July 18, 2012 at 10:43 AM pessoal estou a tentar fazer um programa que tem um ficheiro json, e que dentro desse ficheiro json tem as cores rgb em hex e vários cenários. depois quando tocar numa imagem ele vai comparar as cores rgb ao ficheiro json e mostra a cor numa surfaceview so que devo ter um grande erro no codigo so que não consigo descobrir try { BufferedReader cr = new BufferedReader(new InputStreamReader(this.getAssets().open("themeScenariosInfo.json"))); String line; while ((line = cr.readLine()) != null) { sb.append(line); } //Log.d("",sb.toString()); }catch (IOException e) { e.printStackTrace(); } try { JSONObject json = new JSONObject(new JSONTokener(sb.toString())); JSONArray jsonRgb = json.getJSONArray("themeScenariosInfo"); for(int i=0;i<jsonRgb.length();i++){ JSONObject jsonObject = (JSONObject) jsonRgb.get(i); String jsonRgb1 = jsonObject.getString("scenarioId"); JSONArray jsonRgb2 = jsonObject.getJSONArray("scenarioSpotables"); for(int e=0;i<jsonRgb2.length();i++){ JSONObject jsonObject1 = (JSONObject) jsonRgb2.get(e); String jsonRgb3 = jsonObject1.getString("spotableId"); final JSONArray jsonRgb4 = jsonObject1.getJSONArray("spotableRGBs"); textView.setText(String.valueOf(jsonObject1)); //JSONObject jsonRgb5 = jsonRgb4.getJSONObject(Color.rgb(e, e, e)); //Log.d("","kjfjf"); for(int r=0;r<jsonRgb4.length();r++){ textView.setText(String.valueOf(jsonRgb4)); image.setOnTouchListener(new ImageView.OnTouchListener(){ public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub // textView.setText("Touch coordinates : " + // String.valueOf(event.getX()) + "x" + String.valueOf(event.getY())); ImageView imageView = ((ImageView)v); Bitmap bitmap = ((BitmapDrawable)imageView.getDrawable()).getBitmap(); //Log.d("FF",bitmap.getHeight()+""); float escla = bitmap.getWidth()/image.getWidth(); float escala= bitmap.getHeight()/image.getHeight(); int color = bitmap.getPixel(((int)(event.getX()*escla)),((int)(event.getY()*escala))); int redValue = ((color >> 16) & 0xFF); int blueValue = ((color >> 8) & 0xFF); int greenValue = ((color >> 0) & 0xFF); if("color".equals(jsonRgb4)){ textView.invalidate(); } return true; } }); } } } } catch (JSONException e) { e.printStackTrace(); } } Link to comment Share on other sites More sharing options...
Flinger Posted July 18, 2012 at 11:15 AM Report Share #469131 Posted July 18, 2012 at 11:15 AM JSONArray jsonRgb4 if("color".equals(jsonRgb4)) Citação http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#equals(java.lang.Object) equals public boolean equals(Object anObject) Compares this string to the specified object. The result is true if and only if the argument is not null and is a String object that represents the same sequence of characters as this object. Overrides:equals in class Object Parameters:an Object - the object to compare this String against. Returns: true if the String are equal; false otherwise. See Also:compareTo(java.lang.String), equalsIgnoreCase(java.lang.String) Estás a tentar compara a string "color" com um objecto. Assim à cabeça detecto esse erro, não quer dizer que não existam mais. Link to comment Share on other sites More sharing options...
gamarra Posted July 19, 2012 at 01:27 PM Author Report Share #469244 Posted July 19, 2012 at 01:27 PM (edited) como faço oconversor de int para hexadecimal ? Edited July 19, 2012 at 01:27 PM by gamarra Link to comment Share on other sites More sharing options...
nram Posted July 20, 2012 at 09:48 AM Report Share #469337 Posted July 20, 2012 at 09:48 AM if("color".equals(jsonRgb4)) O que pretendias fazer com isso? Usar o teu inteiro color ou usar mesmo a string color para comparar? É que me parece que querias usar o inteiro, pelo que disseste depois. :S Não podes usar equals em Strings, porque estarias a comparar apontadores e como é óbvio não te irá dar igual. Link to comment Share on other sites More sharing options...
gamarra Posted July 20, 2012 at 10:16 AM Author Report Share #469343 Posted July 20, 2012 at 10:16 AM já consegui, agora esta me a dar este erro 07-20 10:14:15.203: E/AndroidRuntime(788): java.lang.NullPointerException Link to comment Share on other sites More sharing options...
nram Posted July 20, 2012 at 10:18 AM Report Share #469344 Posted July 20, 2012 at 10:18 AM já consegui, agora esta me a dar este erro 07-20 10:14:15.203: E/AndroidRuntime(788): java.lang.NullPointerException Mostra o código onde te dá esse erro. Link to comment Share on other sites More sharing options...
gamarra Posted July 20, 2012 at 10:20 AM Author Report Share #469345 Posted July 20, 2012 at 10:20 AM public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_get_xml); final TextView textView = (TextView)findViewById(R.id.textView1); final ImageView image = (ImageView)findViewById(R.id.imageView1); final SurfaceView viewcolor = (SurfaceView)findViewById(R.id.surfaceView1); final StringBuilder sb = new StringBuilder(50); try { BufferedReader cr = new BufferedReader(new InputStreamReader(this.getAssets().open("themeScenariosInfo.json"))); String line; while ((line = cr.readLine()) != null) { sb.append(line); } //Log.d("",sb.toString()); }catch (IOException e) { e.printStackTrace(); } try { JSONObject json = new JSONObject(new JSONTokener(sb.toString())); JSONArray jsonRgb = json.getJSONArray("themeScenariosInfo"); for(int i=0;i<jsonRgb.length();i++){ JSONObject jsonObject = (JSONObject) jsonRgb.get(i); String jsonRgb1 = jsonObject.getString("scenarioId"); JSONArray jsonRgb2 = jsonObject.getJSONArray("scenarioSpotables"); for(int e=0;i<jsonRgb2.length();i++){ JSONObject jsonObject1 = (JSONObject) jsonRgb2.get(e); String jsonRgb3 = jsonObject1.getString("spotableId"); JSONArray jsonRgb4 = jsonObject1.getJSONArray("spotableRGBs"); textView.setText(String.valueOf(jsonObject1)); for(int r=0;r<jsonRgb4.length();r++){ textView.setText(String.valueOf(jsonRgb4)); final String jsonrgb5 = ((JSONObject)jsonRgb4.get(r)).getString("rgb"); image.setOnTouchListener(new ImageView.OnTouchListener(){ public boolean onTouch(View v, MotionEvent event) { textView.setText("Touch coordinates : " + String.valueOf(event.getX()) + "x" + String.valueOf(event.getY())); ImageView imageView = ((ImageView)v); Bitmap bitmap = ((BitmapDrawable)imageView.getDrawable()).getBitmap(); //Log.d("FF",bitmap.getHeight()+""); float escla = bitmap.getWidth()/image.getWidth(); float escala= bitmap.getHeight()/image.getHeight(); int color = bitmap.getPixel(((int)(event.getX()*escla)),((int)(event.getY()*escala))); int redValue = Color.red(color);//((color >> 16) & 0xFF); int blueValue = Color.blue(color);//((color >> 8) & 0xFF); int greenValue = Color.green(color);//((color >> 0) & 0xFF); String hexadecimal; if (color < 0) hexadecimal = Integer.toHexString(Math.abs(color)); else hexadecimal = Integer.toHexString(color); if (hexadecimal.equals(jsonrgb5)){ viewcolor.setBackgroundColor(color); } return true; } Link to comment Share on other sites More sharing options...
nram Posted July 20, 2012 at 10:22 AM Report Share #469347 Posted July 20, 2012 at 10:22 AM Em que linha? Link to comment Share on other sites More sharing options...
gamarra Posted July 20, 2012 at 10:27 AM Author Report Share #469349 Posted July 20, 2012 at 10:27 AM quando eu carrego na imageview ele da o erro , nao sei a linha e isso que estou a procura Link to comment Share on other sites More sharing options...
HappyHippyHippo Posted July 20, 2012 at 10:30 AM Report Share #469350 Posted July 20, 2012 at 10:30 AM Mostra o código onde te dá esse erro. quando eu carrego na imageview ele da o erro , nao sei a linha e isso que estou a procura então o erro é no evento de clicar na imageview e não amostras nenhuma linha do eventlistener ??? IRC : sim, é algo que ainda existe >> #p@p Portugol Plus Link to comment Share on other sites More sharing options...
gamarra Posted July 20, 2012 at 10:33 AM Author Report Share #469351 Posted July 20, 2012 at 10:33 AM esta lá image.setOnTouchListener(new ImageView.OnTouchListener(){ não é isto???? Link to comment Share on other sites More sharing options...
HappyHippyHippo Posted July 20, 2012 at 11:08 AM Report Share #469354 Posted July 20, 2012 at 11:08 AM (edited) tens de começar a escrever as tags do geshi corretas no teu caso (como estás a usar Java) seria [ code=java] (sem o espaço claro) final String jsonrgb5 = ((JSONObject)jsonRgb4.get(r)).getString("rgb"); image.setOnTouchListener(new ImageView.OnTouchListener(){ // ... if (hexadecimal.equals(jsonrgb5)){ // tenho um felling que "jsonrgb5" não está definido no scope do listener // .. } Edited July 20, 2012 at 11:12 AM by HappyHippyHippo IRC : sim, é algo que ainda existe >> #p@p Portugol Plus Link to comment Share on other sites More sharing options...
gamarra Posted July 20, 2012 at 01:30 PM Author Report Share #469375 Posted July 20, 2012 at 01:30 PM pessoal estou aqui com uma dificuldade, estou a tentar mudar o valor inteiro para hexa decimal so que ele esta sempre a dar o mesmo valor que e ff009d mas nao e o valor da cor, alguem me pode ajudar int color = bitmap.getPixel(((int)(event.getX()*escla)),((int)(event.getY()*escala))); int redValue = Color.red(color);//((color >> 16) & 0xFF); int blueValue = Color.blue(color);//((color >> 8) & 0xFF); int greenValue = Color.green(color);//((color >> 0) & 0xFF); String hexadecimal; if (color < 0) hexadecimal = Integer.toHexString(Math.abs(color)); else hexadecimal = Integer.toHexString(color); Link to comment Share on other sites More sharing options...
nram Posted July 21, 2012 at 07:10 PM Report Share #469553 Posted July 21, 2012 at 07:10 PM pessoal estou aqui com uma dificuldade, estou a tentar mudar o valor inteiro para hexa decimal so que ele esta sempre a dar o mesmo valor que e ff009d mas nao e o valor da cor, alguem me pode ajudar int color = bitmap.getPixel(((int)(event.getX()*escla)),((int)(event.getY()*escala))); int redValue = Color.red(color);//((color >> 16) & 0xFF); int blueValue = Color.blue(color);//((color >> 8) & 0xFF); int greenValue = Color.green(color);//((color >> 0) & 0xFF); String hexadecimal; if (color < 0) hexadecimal = Integer.toHexString(Math.abs(color)); else hexadecimal = Integer.toHexString(color); Não é o valor da cor? Como sabes? Mete branco e verifica se dá FFFFF ou preto 000000 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now