Java tutorial
/* * Copyright (C) 2013 - Gareth Llewellyn * * This file is part of the Unofficial HackedIO Android App https://github.com/NetworksAreMadeOfString/HackedIO-Android-App * * This app is unofficial. The "Hacked.io" logo is copyright (and maybe even a trademark of) Telefnica UK Limited. * The author of this app is not affiliated with Telefnica UK Limited, The Lab ( https://thelab.o2.com/ ) or * Geeks of London ( http://geeksoflondon.com/ ) although the author <strong>is</strong> an attendee. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. * * You should have received a copy of the GNU General Public License along with * this program. If not, see <http://www.gnu.org/licenses/> */ package app.hacked; import android.os.Bundle; import android.support.v4.app.Fragment; import android.text.Html; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; import android.widget.Toast; import com.android.volley.Request; import com.android.volley.RequestQueue; import com.android.volley.Response; import com.android.volley.VolleyError; import com.android.volley.toolbox.JsonObjectRequest; import com.android.volley.toolbox.Volley; import org.json.JSONObject; public class WorkShopsFragment extends Fragment { RequestQueue queue = null; private View progressBar = null; TextView workshopPayload = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); queue = Volley.newRequestQueue(getActivity()); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.workshop_fragment, null); workshopPayload = (TextView) view.findViewById(R.id.workshopPayload); progressBar = view.findViewById(R.id.progressBar); return view; } @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); String url = "http://hackedioapp.networksaremadeofstring.co.uk/workshops.php"; JsonObjectRequest jsObjRequest = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { try { if (response.has("success") && response.getBoolean("success") && response.has("workshops")) { Log.e("response", response.toString()); workshopPayload.setText(Html.fromHtml(response.getString("workshops"))); progressBar.setVisibility(View.GONE); } else { Toast.makeText(getActivity(), "An Error Was encountered", Toast.LENGTH_SHORT) .show(); } } catch (Exception e) { e.printStackTrace(); Toast.makeText(getActivity(), "An Error Was encountered", Toast.LENGTH_SHORT).show(); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { // TODO Auto-generated method stub Toast.makeText(getActivity(), "An Error Was encountered", Toast.LENGTH_SHORT).show(); } }); queue.add(jsObjRequest); } }