aboutsummaryrefslogtreecommitdiff
path: root/src/net/cbaines/suma/BuildingActivity.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/net/cbaines/suma/BuildingActivity.java')
-rw-r--r--src/net/cbaines/suma/BuildingActivity.java178
1 files changed, 178 insertions, 0 deletions
diff --git a/src/net/cbaines/suma/BuildingActivity.java b/src/net/cbaines/suma/BuildingActivity.java
new file mode 100644
index 0000000..6b03164
--- /dev/null
+++ b/src/net/cbaines/suma/BuildingActivity.java
@@ -0,0 +1,178 @@
+/*
+ * 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.sql.SQLException;
+
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.graphics.drawable.Drawable;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.Display;
+import android.view.View;
+import android.view.WindowManager;
+import android.widget.CheckBox;
+import android.widget.CompoundButton;
+import android.widget.CompoundButton.OnCheckedChangeListener;
+import android.widget.ImageButton;
+import android.widget.ImageView.ScaleType;
+import android.widget.TextView;
+
+import com.j256.ormlite.android.apptools.OrmLiteBaseActivity;
+import com.j256.ormlite.dao.Dao;
+
+public class BuildingActivity extends OrmLiteBaseActivity<DatabaseHelper> implements OnCheckedChangeListener, Preferences {
+
+ final static String TAG = "BusTimeActivity";
+
+ private Context instance;
+
+ private ImageButton imageButton;
+
+ private TextView buildingName;
+ private TextView buildingID;
+
+ private Building building;
+
+ private CheckBox favouritesCheckBox;
+
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.building_activity);
+ instance = this;
+
+ String ID = getIntent().getExtras().getString("buildingID");
+
+ final SharedPreferences favouritesPrefs = instance.getSharedPreferences(FAVOURITES_PREFERENCES, 0);
+
+ favouritesCheckBox = (CheckBox) findViewById(R.id.buildingActivityFavouriteCheckBox);
+ favouritesCheckBox.setChecked(favouritesPrefs.getBoolean(ID, false));
+ favouritesCheckBox.setOnCheckedChangeListener(this);
+
+ buildingName = (TextView) findViewById(R.id.buildingActivityName);
+ buildingID = (TextView) findViewById(R.id.buildingActivityID);
+
+ Log.i(TAG, "Building id " + ID);
+
+ try {
+ Dao<Building, String> buildingDao = getHelper().getBuildingDao();
+
+ building = buildingDao.queryForId(ID);
+
+ buildingName.setText(building.name);
+
+ } catch (SQLException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+
+ buildingID.setText(ID);
+ try {
+
+ /* First, get the Display from the WindowManager */
+ Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
+
+ /* Now we can retrieve all display-related infos */
+ int orientation = display.getOrientation();
+ Log.i(TAG, "orientation " + orientation);
+ Log.i(TAG, "width " + display.getWidth() + " height " + display.getHeight());
+ int width;
+ // if (orientation == 0) {
+ width = display.getWidth();
+ // } else {
+ // width = display.getHeight();
+ // }
+
+ URL imageURL;
+ Log.i(TAG, "Screen width " + width);
+ if (width >= 1000) {
+ imageURL = new URL("http://data.southampton.ac.uk/images/buildings/1000/" + ID + ".jpg");
+ } else if (width >= 800) {
+ imageURL = new URL("http://data.southampton.ac.uk/images/buildings/1000/" + ID + ".jpg");
+ } else if (width >= 600) {
+ imageURL = new URL("http://data.southampton.ac.uk/images/buildings/600/" + ID + ".jpg");
+ } else if (width >= 400) {
+ imageURL = new URL("http://data.southampton.ac.uk/images/buildings/600/" + ID + ".jpg");
+ } else if (width >= 300) {
+ imageURL = new URL("http://data.southampton.ac.uk/images/buildings/300/" + ID + ".jpg");
+ } else if (width >= 200) {
+ imageURL = new URL("http://data.southampton.ac.uk/images/buildings/200/" + ID + ".jpg");
+ } else {
+ imageURL = new URL("http://data.southampton.ac.uk/images/buildings/100/" + ID + ".jpg");
+ }
+ Log.i(TAG, "URL " + imageURL);
+
+ InputStream is = (InputStream) imageURL.getContent();
+ Drawable image = Drawable.createFromStream(is, "src");
+
+ imageButton = new ImageButton(this);
+ imageButton = (ImageButton) findViewById(R.id.buildingActivityImage);
+ imageButton.setImageDrawable(image);
+ imageButton.setScaleType(ScaleType.CENTER_INSIDE);
+ 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();
+ }
+
+ }
+
+ 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 button, boolean checked) {
+ SharedPreferences favouritesPreferences = getSharedPreferences(FAVOURITES_PREFERENCES, 0);
+
+ if (checked) {
+ favouritesPreferences.edit().putBoolean(building.id, true).commit();
+ } else {
+ favouritesPreferences.edit().remove(building.id).commit();
+ }
+ }
+
+}