package com.xyx.activity;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.widget.TextView;

import com.xyx.R;
import com.xyx.interfaces.IDataFromMyAPIEvent;
import com.xyx.server.hprose.DataFromMyAPI;
import com.xyx.util.Utils;

public class AstroDetailsActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		//show activity
		setContentView(R.layout.activity_astro_details);
		
		Intent intent = getIntent();
		Integer index = intent.getExtras().getInt(Utils.EXTRA_ASTRO_DATA);
		DataFromMyAPI api = new DataFromMyAPI(new DataFormAPIEvent());
		api.execute(String.valueOf(index));			
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.astro_details, menu);
		return true;
	}
	
	
	
	class DataFormAPIEvent implements IDataFromMyAPIEvent {

		@Override
		public void loadData() {
			// TODO Auto-generated method stub
			
		}

		@Override
		public void updateUI(ArrayList<String> data) {
			if (data == null)
				return;
			
			TextView tv = (TextView)findViewById(R.id.astroDetails);
			StringBuilder sb = new StringBuilder();
			for (String s : data){
				sb.append(s + "\n");
			}
			tv.setText(sb.toString());
		}
		
	}

}

@@ -1298,132 +1298,475 @@
 %0A%09%09%09
-StringBuilder sb = new StringBuilder();%0A%09%09%09for (String s : data)%7B%0A%09%09%09%09sb.append(s + %22%5Cn%22);%0A%09%09%09%7D%0A%09%09%09tv.setText(sb.toString())
+tv.setText(processRawData(data));%0A%09%09%7D%0A%09%09%0A%09%09%0A%09%09private String processRawData(ArrayList%3CString%3E data)%0A%09%09%7B%0A%09%09%09String sb = %22%22;%0A%09%09%09for (String s : data)%7B%0A%09%09%09%09%0A%09%09%09%09s = s.replaceAll(%22%5C%5C%7B%7C%5C%5C%7D%22, %22%22);%0A%09%09%09%09String%5B%5D ss = s.split(%22title=%22);%0A%0A%09%09%09%09if(ss.length == 2)%0A%09%09%09%09%7B%0A%09%09%09%09%09String s2 = ss%5B0%5D.replaceAll(%22value=%22, %22      %22).replaceAll(%22, rank=0,%7C, rank=%22, %22%22);%0A%09%09%09%09%09sb = ss%5B1%5D + s2 +  %22%5Cn%22 + sb;%0A%09%09%09%09%7D%0A%09%09%09%09else%0A%09%09%09%09%7B%0A%09%09%09%09%09%0A%09%09%09%09%09sb= ss%5B0%5D + %22%5Cn%22 + sb;%0A%09%09%09%09%7D%0A%0A%09%09%09%7D%0A%09%09%09%0A%09%09%09return sb
 ;%0A%09%09

split raw data