@Override protected List<JSONObject> doInBackground(Void... params) { List<JSONObject> checkins = new ArrayList<JSONObject>(); try { ACSClient sdk = DemoApplication.getSdk(); Map<String, Object> data = new HashMap<String, Object>(); data.put("place_id", place.getString("id")); CCResponse response = sdk.sendRequest("checkins/search.json", CCRequestMethod.GET, data, false); JSONObject responseJSON = response.getResponseData(); CCMeta meta = response.getMeta(); if ("ok".equals(meta.getStatus()) && meta.getCode() == 200 && "searchCheckins".equals(meta.getMethod())) { JSONArray checkinsJArray = responseJSON.getJSONArray("checkins"); for (int i = 0; i < checkinsJArray.length(); i++) { checkins.add(checkinsJArray.getJSONObject(i)); } } } catch (ACSClientError e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return checkins; }
protected void performCheckin() { JSONObject checkin = null; String errorMsg = null; try { ACSClient sdk = DemoApplication.getSdk(); Map<String, Object> data = new HashMap<String, Object>(); try { data.put("place_id", place.getString("id")); } catch (JSONException e) { e.printStackTrace(); } CCResponse response = sdk.sendRequest("checkins/create.json", CCRequestMethod.POST, data, false); JSONObject responseJSON = response.getResponseData(); CCMeta meta = response.getMeta(); if ("ok".equals(meta.getStatus()) && meta.getCode() == 200 && "createCheckin".equals(meta.getMethod())) { JSONArray checkins = null; try { checkins = responseJSON.getJSONArray("checkins"); checkin = checkins.getJSONObject(0); listOfCheckin.add(0, checkin); } catch (JSONException e) { e.printStackTrace(); } showCheckins(); } else { errorMsg = meta.getMessage(); } } catch (ACSClientError e) { errorMsg = e.getMessage(); } catch (IOException e) { e.printStackTrace(); } if (errorMsg != null) { AlertDialog alertDialog = new AlertDialog.Builder(this).create(); alertDialog.setTitle("Checkin Failed"); alertDialog.setMessage(errorMsg); alertDialog.setButton( "OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // here you can add functions dialog.dismiss(); } }); alertDialog.setIcon(R.drawable.icon); alertDialog.show(); } }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.placeview); Intent intent = getIntent(); String p = intent.getStringExtra("place"); if (p != null) { try { place = new JSONObject(p); TextView name = (TextView) findViewById(R.id.PlaceName); name.setText(place.getString("name")); } catch (JSONException e) { e.printStackTrace(); } } View doneButton = findViewById(R.id.done); doneButton.setOnClickListener( new View.OnClickListener() { public void onClick(View view) { finish(); } }); View refreshButton = findViewById(R.id.refresh); refreshButton.setOnClickListener( new View.OnClickListener() { public void onClick(View view) { performRefresh(); } }); View checkinButton = findViewById(R.id.checkin); checkinButton.setOnClickListener( new View.OnClickListener() { public void onClick(View view) { performCheckin(); } }); if (DemoApplication.getSdk().getCurrentUser() == null) { // disable check in button checkinButton.setEnabled(false); } else checkinButton.setEnabled(true); new GetCheckinsTask().execute(); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); sdk = DemoApplication.getSdk(); map = (MapView) findViewById(R.id.map); map.setBuiltInZoomControls(true); Drawable marker = getResources().getDrawable(R.drawable.marker); marker.setBounds(0, 0, marker.getIntrinsicWidth(), marker.getIntrinsicHeight()); overlay = new SitesOverlay(marker); map.getOverlays().add(overlay); me = new MyLocationOverlay(this, map); map.getOverlays().add(me); LayoutInflater layoutInflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); noteBaloon = (BaloonLayout) layoutInflater.inflate(R.layout.baloon, null); RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(200, 100); layoutParams.addRule(RelativeLayout.CENTER_VERTICAL); layoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL); noteBaloon.setLayoutParams(layoutParams); noteBaloon .findViewById(R.id.placeInfo) .setOnClickListener( new View.OnClickListener() { public void onClick(View v) { overlay.showPlace(); } }); ((TextView) noteBaloon.findViewById(R.id.placeName)).setTextColor(Color.BLACK); ((TextView) noteBaloon.findViewById(R.id.placeAddress)).setTextColor(Color.BLACK); final ListView list = (ListView) findViewById(R.id.placeList); PlaceAdapter placeAdapter = new PlaceAdapter(this); list.setAdapter(placeAdapter); list.setClickable(true); list.setFocusable(true); list.setSelected(true); list.setOnItemClickListener( new ListView.OnItemClickListener() { public void onItemClick(AdapterView<?> arg0, View v, int position, long arg3) { list.setSelection(position); JSONObject place = (JSONObject) list.getItemAtPosition(position); Intent myIntent = new Intent(getBaseContext(), PlaceView.class); myIntent.putExtra("place", place.toString()); startActivity(myIntent); } }); findViewById(R.id.refresh) .setOnClickListener( new View.OnClickListener() { public void onClick(View v) { new GetPlacesTask().execute(); } }); findViewById(R.id.refreshList) .setOnClickListener( new View.OnClickListener() { public void onClick(View v) { new GetPlacesTask().execute(); } }); findViewById(R.id.listButton) .setOnClickListener( new View.OnClickListener() { public void onClick(View v) { showListView(); } }); findViewById(R.id.mapButton) .setOnClickListener( new View.OnClickListener() { public void onClick(View v) { hideListView(); } }); hideListView(); new GetPlacesTask().execute(); // findViewById(R.id.listView).setVisibility(View.INVISIBLE); }