/* * Southampton University Map App * Copyright (C) 2011 Christopher Baines * * 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 2 * 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, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ package net.cbaines.suma; import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; import java.util.Iterator; import android.content.Context; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.CheckBox; import android.widget.CompoundButton; import android.widget.CompoundButton.OnCheckedChangeListener; import android.widget.ImageButton; import android.widget.TextView; import com.hp.hpl.jena.query.Query; import com.hp.hpl.jena.query.QueryExecution; import com.hp.hpl.jena.query.QueryExecutionFactory; import com.hp.hpl.jena.query.QueryFactory; import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.ResultSet; import com.hp.hpl.jena.rdf.model.Literal; import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.RDFNode; import com.hp.hpl.jena.rdf.model.Resource; import com.hp.hpl.jena.tdb.TDBFactory; import com.j256.ormlite.android.apptools.OrmLiteBaseActivity; public class BuildingActivity extends OrmLiteBaseActivity implements OnCheckedChangeListener { final static String TAG = "BusTimeActivity"; private boolean dataChanged; private Context instance; private ImageButton imageButton; private TextView buildingName; private TextView buildingID; private CheckBox favouritesCheckBox; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.building_activity); instance = this; String ID = getIntent().getExtras().getString("buildingID"); favouritesCheckBox = (CheckBox) findViewById(R.id.buildingActivityFavouriteCheckBox); // favouritesCheckBox.setChecked(busStop.favourite); favouritesCheckBox.setOnCheckedChangeListener(this); buildingName = (TextView) findViewById(R.id.buildingActivityName); buildingID = (TextView) findViewById(R.id.buildingActivityName); Log.i(TAG, "Building id " + ID); buildingID.setText(ID); try { URL url = new URL("http://data.southampton.ac.uk/images/buildings/600/" + ID + ".jpg"); InputStream is = (InputStream) url.getContent(); Drawable image = Drawable.createFromStream(is, "src"); imageButton = new ImageButton(this); imageButton = (ImageButton) findViewById(R.id.buildingActivityImage); imageButton.setImageDrawable(image); imageButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { } }); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } String directory = "/data/data/net.cbaines.suma/databases"; Model model = TDBFactory.createModel(directory); String queryString = ID; Query query = QueryFactory.create(queryString); QueryExecution qexec = QueryExecutionFactory.create(query, model); try { ResultSet results = qexec.execSelect(); for (; results.hasNext();) { QuerySolution soln = results.nextSolution(); Log.i(TAG, "solution " + soln.toString()); for (Iterator iter = soln.varNames(); iter.hasNext();) { Log.i(TAG, "solnVarName " + iter.next()); } // RDFNode x = soln.get("varName"); // Get a result variable by // name. // Resource r = soln.getResource("VarR"); // Get a result // variable // - must be a resource // Literal l = soln.getLiteral("VarL"); // Get a result variable // - // must be a literal } } finally { qexec.close(); } } public void onResume() { super.onResume(); } public void onPause() { super.onPause(); } public void finish() { setResult(RESULT_OK, getIntent()); super.finish(); } @Override public Object onRetainNonConfigurationInstance() { return null; } public void onCheckedChanged(CompoundButton arg0, boolean arg1) { // TODO Auto-generated method stub } }