package com.example.kisibox;

import java.util.List;
import java.util.Vector;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.ViewPager;
import android.view.Window;
import android.widget.TextView;

public class KisiMain extends FragmentActivity {

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);

		setContentView(R.layout.kisi_main);

		getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
				R.layout.window_title);

		TextView title = (TextView) findViewById(R.id.title);

		title.setText("Your Locations");

		initializePager();

	}

	public void initializePager() {
		//TODO: change from Test to real Data


		List<Fragment> fragments = new Vector<Fragment>(); 
		fragments.add(LocationOneDoor.newInstance("Home","Rmerstrae","17","Front Door"));
		
		
		fragments.add(LocationTwoDoors.newInstance("Meier","Hauptstrae","5","Front Door","Appartment Door"));
		fragments.add(LocationThreeDoors.newInstance("Mller","Dorfstrae","23","Front Door","Garage Door","Cellar Door"));	
		fragments.add(LocationFourDoors.newInstance("Uni","Boltzmannstrae","15","Front Door","Library","Room 02.07.23","Room 00.09.11"));		
		
		
		FragmentManager fm = getSupportFragmentManager();
		ViewPager pager = (ViewPager) findViewById(R.id.pager);
		MyFragmentPagerAdapter pagerAdapter = new MyFragmentPagerAdapter(fm,
				fragments);
		pager.setAdapter(pagerAdapter);

	}
}

@@ -72,16 +72,156 @@
 ector;%0A%0A
+import org.json.JSONArray;%0Aimport org.json.JSONException;%0A%0Aimport com.example.kisibox.model.Location;%0Aimport com.manavo.rest.RestCallback;%0A%0A
 import a
@@ -411,24 +411,57 @@
 .ViewPager;%0A
+import android.util.SparseArray;%0A
 import andro
@@ -509,16 +509,17 @@
 tView;%0A%0A
+%0A
 public c
@@ -560,16 +560,57 @@
 vity %7B%0A%0A
+%09public SparseArray%3CLocation%3E locations;%0A
 %09public 
@@ -1028,296 +1028,614 @@
 %7B%0A%09%09
-//TODO: change from Test to real Data%0A%0A%0A%09%09List%3CFragment%3E fragments = new Vector%3CFragment%3E(); %0A%09%09fragments.add(LocationOneDoor.newInstance(%22Home%22,%22Rmerstrae%22,%2217%22,%22Front Door%22));%0A%09%09%0A%09%09%0A%09%09fragments.add(LocationTwoDoors.newInstance(%22Meier%22,%22Hauptstrae%22,%225%22,%22Front Door%22,%22Appartment Door%22)
+updateLocations();%0A%09%7D%0A%0A%09private void updateLocations() %7B%0A%09%09KisiApi api = new KisiApi(this);%0A%0A%09%09api.setCallback(new RestCallback() %7B%0A%09%09%09public void success(Object obj) %7B%0A%09%09%09%09JSONArray data = (JSONArray)obj;%0A%0A%09%09%09%09setupView(data);%0A%09%09%09%7D%0A%0A%09%09%7D);%0A%09%09api.get(%22locations%22);%0A%09%09%0A%09%7D%0A%09%0A%09private void setupView(JSONArray locations_json) %7B%0A%09%09%0A%09%09List%3CFragment%3E fragments = new Vector%3CFragment%3E(); %0A%09%09locations = new SparseArray%3CLocation%3E();%0A%09%09%0A%09%09try %7B%0A%09%09%09for (int i=0; i%3Clocations_json.length(); i++) %7B%0A%09%09%09%09Location location = new Location(locations_json.getJSONObject(i));%0A%09%09%09%09locations.put(location.getId(), location
 );%0A
+%09%09
 %09%09fr
@@ -1658,18 +1658,20 @@
 tion
-ThreeDoors
+ViewFragment
 .new
@@ -1683,217 +1683,129 @@
 nce(
-%22Mller%22,%22Dorfstrae%22,%2223%22,%22Front Door%22,%22Garage Door%22,%22Cellar Door%22));%09%0A%09%09fragments.add(LocationFourDoors.newInstance(%22Uni%22,%22Boltzmannstrae%22,%2215%22,%22Front Door%22,%22Library%22,%22Room 02.07.23%22,%22Room 00.09.11%22));%09%09%0A%09%09%0A%09%09
+location.getId()));%0A%09%09%09%7D%0A%09%09%7D catch (JSONException e) %7B%0A%09%09%09// TODO Auto-generated catch block%0A%09%09%09e.printStackTrace();%0A%09%09%7D%0A
 %0A%09%09F
@@ -1981,21 +1981,17 @@
 pter(fm,
-%0A%09%09%09%09
+ 
 fragment
@@ -2028,14 +2028,13 @@
 apter);%0A
-%0A
 %09%7D%0A%7D%0A

connect mainscreen to api