├── README
├── Where4
├── .project
├── AndroidManifest.xml
├── default.properties
├── gen
│ └── haseman
│ │ └── project
│ │ └── where4
│ │ └── R.java
├── res
│ ├── drawable
│ │ └── icon.png
│ ├── layout
│ │ └── main.xml
│ └── values
│ │ └── strings.xml
└── src
│ ├── ARKit
│ ├── ARLayout.java
│ ├── ARSphericalView.java
│ └── SphericalPoint.java
│ └── haseman
│ └── project
│ ├── fourSquareLibs
│ ├── FourSqareVenue.java
│ └── FourSquareClient.java
│ └── where4
│ ├── CompassListener.java
│ ├── CustomCameraView.java
│ └── HoldMeUp.java
└── license
/README:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/haseman/Android-AR-Kit/5e354e76f5776e959aadb9944ce1500469089443/README
--------------------------------------------------------------------------------
/Where4/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | Where4
4 |
5 |
6 |
7 |
8 |
9 | com.android.ide.eclipse.adt.ResourceManagerBuilder
10 |
11 |
12 |
13 |
14 | com.android.ide.eclipse.adt.PreCompilerBuilder
15 |
16 |
17 |
18 |
19 | org.eclipse.jdt.core.javabuilder
20 |
21 |
22 |
23 |
24 | com.android.ide.eclipse.adt.ApkBuilder
25 |
26 |
27 |
28 |
29 |
30 | com.android.ide.eclipse.adt.AndroidNature
31 | org.eclipse.jdt.core.javanature
32 |
33 |
34 |
--------------------------------------------------------------------------------
/Where4/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/Where4/default.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system use,
7 | # "build.properties", and override values to adapt the script to your
8 | # project structure.
9 |
10 | # Indicates whether an apk should be generated for each density.
11 | split.density=false
12 | # Project target.
13 | target=android-3
14 | apk-configurations=
15 |
--------------------------------------------------------------------------------
/Where4/gen/haseman/project/where4/R.java:
--------------------------------------------------------------------------------
1 | /* AUTO-GENERATED FILE. DO NOT MODIFY.
2 | *
3 | * This class was automatically generated by the
4 | * aapt tool from the resource data it found. It
5 | * should not be modified by hand.
6 | */
7 |
8 | package haseman.project.where4;
9 |
10 | public final class R {
11 | public static final class attr {
12 | }
13 | public static final class drawable {
14 | public static final int icon=0x7f020000;
15 | }
16 | public static final class layout {
17 | public static final int main=0x7f030000;
18 | }
19 | public static final class string {
20 | public static final int app_name=0x7f040001;
21 | public static final int hello=0x7f040000;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/Where4/res/drawable/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/haseman/Android-AR-Kit/5e354e76f5776e959aadb9944ce1500469089443/Where4/res/drawable/icon.png
--------------------------------------------------------------------------------
/Where4/res/layout/main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
12 |
13 |
--------------------------------------------------------------------------------
/Where4/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Hello World, HoldMeUp
4 | Where 4
5 |
6 |
--------------------------------------------------------------------------------
/Where4/src/ARKit/ARLayout.java:
--------------------------------------------------------------------------------
1 | package ARKit;
2 |
3 | import java.util.Enumeration;
4 | import java.util.Vector;
5 |
6 | import android.content.Context;
7 | import android.graphics.Canvas;
8 | import android.graphics.Color;
9 | import android.graphics.Paint;
10 | import android.hardware.Sensor;
11 | import android.hardware.SensorEvent;
12 | import android.hardware.SensorEventListener;
13 | import android.hardware.SensorManager;
14 | import android.location.Location;
15 | import android.location.LocationListener;
16 | import android.location.LocationManager;
17 | import android.location.GpsStatus.Listener;
18 | import android.os.Bundle;
19 | import android.util.Log;
20 | import android.view.View;
21 |
22 | public class ARLayout extends View implements LocationListener, SensorEventListener
23 | {
24 |
25 | private final float xAngleWidth = 29;
26 | private final float yAngleWidth = 19;
27 |
28 | public float screenWidth = 480;
29 | public float screenHeight = 320;
30 | private Location lastLocation;
31 |
32 | volatile Vector arViews = new Vector();
33 |
34 | public SensorManager sensorMan;
35 | public LocationManager locMan;
36 | public Location curLocation = null;
37 | private Context ctx;
38 | public float direction = (float) 22.4;
39 | public double inclination;
40 | public double rollingX = (float)0;
41 | public double rollingZ = (float)0;
42 | public float kFilteringFactor = (float)0.05;
43 | public float one = (float)0;
44 | public float two = (float)0;
45 | public float three = (float)0;
46 | private boolean locationChanged = false;
47 | public boolean debug = false;
48 |
49 | public ARLayout(Context context)
50 | {
51 | super(context);
52 | ctx = context;
53 |
54 | sensorMan = (SensorManager)ctx.getSystemService(Context.SENSOR_SERVICE);
55 | sensorMan.registerListener(this, sensorMan.getDefaultSensor(Sensor.TYPE_ORIENTATION), SensorManager.SENSOR_DELAY_FASTEST);
56 | sensorMan.registerListener(this, sensorMan.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_FASTEST);
57 | locMan = (LocationManager)ctx.getSystemService(Context.LOCATION_SERVICE);
58 | locMan.requestLocationUpdates(LocationManager.GPS_PROVIDER, 100, 1, this);
59 |
60 | }
61 | public void onLocationChanged(Location location)
62 | {
63 | if(curLocation == null)
64 | {
65 | curLocation = location;
66 | ARSphericalView.deviceLocation = location;
67 | locationChanged = true;
68 | }
69 | else if(curLocation.getLatitude() == location.getLatitude() &&
70 | curLocation.getLongitude() == location.getLongitude())
71 | locationChanged = false;
72 | else
73 | locationChanged = true;
74 |
75 | curLocation = location;
76 | postInvalidate();
77 | }
78 |
79 | public void onProviderDisabled(String provider){}
80 |
81 | public void onProviderEnabled(String provider){}
82 |
83 | public void onStatusChanged(String provider, int status, Bundle extras){}
84 |
85 | public void onAccuracyChanged(Sensor arg0, int arg1){}
86 |
87 | public void onSensorChanged(SensorEvent evt)
88 | {
89 | float vals[] = evt.values;
90 | float localDirection;
91 | if(evt.sensor.getType() == Sensor.TYPE_ORIENTATION)
92 | {
93 | float tmp = vals[0];
94 | tmp += 90;
95 | if(tmp > 360)
96 | tmp -= 360;
97 |
98 | direction =(float) ((tmp * kFilteringFactor) + (direction * (1.0 - kFilteringFactor)));
99 | //direction = direction-90;
100 | if(direction < 0)
101 | localDirection = 360+direction;
102 | else
103 | localDirection = direction;
104 |
105 | if(locationChanged)
106 | updateLayouts(localDirection, (float)inclination, curLocation);
107 | else
108 | updateLayouts(localDirection, (float)inclination, null);
109 | }
110 | if(evt.sensor.getType() == Sensor.TYPE_ACCELEROMETER)
111 | {
112 | rollingZ = (vals[2] * kFilteringFactor) + (rollingZ * (1.0 - kFilteringFactor));
113 | rollingX = (vals[0] * kFilteringFactor) + (rollingX * (1.0 - kFilteringFactor));
114 |
115 | if (rollingZ != 0.0)
116 | {
117 | inclination = Math.atan(rollingX / rollingZ);// + Math.PI / 2.0;
118 | } else if (rollingX < 0)
119 | {
120 | inclination = Math.PI/2.0;
121 | } else if (rollingX >= 0)
122 | {
123 | inclination = 3 * Math.PI/2.0;
124 | }
125 |
126 | //convert to degress
127 | inclination = inclination * (360/(2*Math.PI));
128 |
129 | //flip!
130 | if(inclination < 0)
131 | inclination = inclination + 90;
132 | else
133 | inclination = inclination -90;
134 |
135 | }
136 | if(direction < 0)
137 | localDirection = 360+direction;
138 | else
139 | localDirection = direction;
140 |
141 | if(locationChanged)
142 | updateLayouts(localDirection, (float)inclination, curLocation);
143 | else
144 | updateLayouts(localDirection, (float)inclination, null);
145 |
146 | postInvalidate();
147 | }
148 |
149 | //Sort views by distance
150 | private void sortArViews()
151 | {
152 | //TODO
153 | }
154 | public void addARView(ARSphericalView view)
155 | {
156 | arViews.add(view);
157 | }
158 | public void removeARView(ARSphericalView view)
159 | {
160 | arViews.remove(view);
161 | }
162 | private boolean isVisibleY(float lowerArm, float upperArm, float inc)
163 | {
164 | return true;//(inc >= lowerArm &&inc <= upperArm);
165 | }
166 |
167 | public void clearARViews()
168 | {
169 | arViews.removeAllElements();
170 | }
171 | //Given a point, is it visible on the screen?
172 | private boolean isVisibleX(float leftArm, float rightArm, float az)
173 | {
174 | // //Flip!
175 | // if(leftArm > rightArm)
176 | // {
177 | // if(!(az <= leftArm && az >= rightArm))
178 | // return false;
179 | // }
180 | // else
181 | // {
182 | // if(!(az >= leftArm && az <= rightArm))
183 | // return false;
184 | // }
185 |
186 | return true;
187 | }
188 | private float calcXvalue(float leftArm, float rightArm, float az)
189 | {
190 | float ret = 0;
191 | float offset;
192 | if(leftArm > rightArm)
193 | {
194 | if(az >= leftArm)
195 | {
196 | offset = az - leftArm;
197 | }
198 | if(az <= rightArm)
199 | {
200 | offset = 360 - leftArm + az;
201 | }
202 | else
203 | offset = az - leftArm;
204 | }
205 | else
206 | {
207 | offset = az - leftArm;
208 | }
209 |
210 | return (offset/xAngleWidth) * screenWidth;
211 | }
212 | private float calcYvalue(float lowerArm, float upperArm, float inc)
213 | {
214 | //distance in degress to the lower arm
215 | float offset = ((upperArm - yAngleWidth) - inc) * -1;
216 | return screenHeight - ((offset/yAngleWidth) * screenHeight);
217 | }
218 | public void onDraw(Canvas c)
219 | {
220 | //Log.e("Spec","Updating "+arViews.size()+" views");
221 | //long time = System.currentTimeMillis();
222 | Enumeration e = arViews.elements();
223 | if(debug)
224 | {
225 | Paint p = new Paint();
226 | p.setColor(Color.WHITE);
227 |
228 | c.drawText("Compass:"+String.valueOf(direction), 20, 20, p);
229 |
230 | c.drawText("Inclination"+String.valueOf(inclination), 150, 20, p);
231 | }
232 | while(e.hasMoreElements())
233 | {
234 | ARSphericalView view = e.nextElement();
235 | // if(!view.visible)
236 | // continue;
237 | view.draw(c);
238 | }
239 | //Log.e("Spec","Took "+(System.currentTimeMillis() - time)+" seconds");
240 | }
241 | public void updateLayouts(float Azi, float zAngle, Location l)
242 | {
243 |
244 | if(Azi != -1)
245 | {
246 | //Process the acceleromitor stuff
247 | float leftArm = Azi -(xAngleWidth/2);
248 | float rightArm = Azi +(xAngleWidth/2);
249 | if(leftArm < 0)
250 | leftArm = leftArm + 360;
251 | if(rightArm > 360)
252 | rightArm = rightArm - 360;
253 |
254 | float upperArm = zAngle + (yAngleWidth/2);
255 | float lowerArm = zAngle - (yAngleWidth/2);
256 |
257 | Enumeration e = arViews.elements();
258 |
259 | if(arViews.size() == 0)
260 | return;
261 |
262 | while(e.hasMoreElements())
263 | {
264 | //If we have a location, and the view has one, update it's data
265 | try{
266 | ARSphericalView view = e.nextElement();
267 | if(l != null && view.location != null)
268 | {
269 | view.azimuth = l.bearingTo(view.location);
270 | if(view.azimuth < 0)
271 | view.azimuth = 360+view.azimuth;
272 | if(l.hasAltitude() && view.location.hasAltitude())
273 | {
274 | view.inclination = (float) Math.atan(((view.location.getAltitude() - l.getAltitude()) / l.distanceTo(view.location)));
275 | }
276 | }
277 | // if(!isVisibleX(leftArm, rightArm, view.azimuth))
278 | // {
279 | // view.visible = false;
280 | // continue;
281 | // }
282 | // if(!isVisibleY(lowerArm, upperArm, view.inclination))
283 | // {
284 | // view.visible = false;
285 | // continue;
286 | // }
287 | view.visible = true;
288 |
289 | view.layout((int)calcXvalue(leftArm, rightArm, view.azimuth), (int)calcYvalue(lowerArm, upperArm, view.inclination), view.getBottom(), view.getRight());
290 | }
291 | catch(Exception x)
292 | {
293 | Log.e("ArLayout", x.getMessage());
294 | }
295 | }
296 |
297 | }
298 | //37.763557,-122.410719
299 |
300 | }
301 |
302 | public void close()
303 | {
304 | sensorMan.unregisterListener(this);
305 | locMan.removeUpdates(this);
306 | }
307 |
308 | }
309 |
--------------------------------------------------------------------------------
/Where4/src/ARKit/ARSphericalView.java:
--------------------------------------------------------------------------------
1 | package ARKit;
2 |
3 | import android.content.Context;
4 | import android.graphics.Canvas;
5 | import android.graphics.Color;
6 | import android.graphics.Paint;
7 | import android.location.Location;
8 | import android.util.Log;
9 | import android.view.View;
10 |
11 | public class ARSphericalView extends View
12 | {
13 | public volatile float azimuth; //Angle from north
14 | public volatile float distance; //Distance to object
15 | public volatile float inclination = -1; //angle off horizon.
16 | public volatile Location location;
17 |
18 | public volatile int x;
19 | public volatile int y;
20 | public volatile boolean visible = false;
21 |
22 | public static Location deviceLocation;
23 | //used to compute inclination
24 | public static float currentAltitude = 0;
25 | protected Paint p = new Paint();
26 |
27 | public ARSphericalView(Context ctx)
28 | {
29 | super(ctx);
30 | }
31 | public ARSphericalView(Context ctx, Location deviceLocation, Location objectLocation)
32 | {
33 | super(ctx);
34 | if(deviceLocation != null)
35 | {
36 | azimuth = deviceLocation.bearingTo(objectLocation);
37 | distance = deviceLocation.distanceTo(objectLocation);
38 | if(deviceLocation.hasAccuracy() && objectLocation.hasAltitude())
39 | {
40 | double opposite;
41 | boolean neg = false;
42 | if(objectLocation.getAltitude() > deviceLocation.getAltitude())
43 | {
44 | opposite = objectLocation.getAltitude() - deviceLocation.getAltitude();
45 | }
46 | else
47 | {
48 | opposite = deviceLocation.getAltitude() - objectLocation.getAltitude();
49 | neg = true;
50 | }
51 | inclination = (float) Math.atan(((double)opposite/distance));
52 | if(neg)
53 | inclination = inclination * -1;
54 | }
55 | }
56 | }
57 | public void draw(Canvas c)
58 | {
59 |
60 | }
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/Where4/src/ARKit/SphericalPoint.java:
--------------------------------------------------------------------------------
1 | package ARKit;
2 |
3 | public class SphericalPoint
4 | {
5 | public float azimuth; //Angle from north
6 | public float distance; //Distance to object
7 | public float inclination; //angle off horizon.
8 |
9 | //used to compute inclination
10 | public static float currentAltitude = 0;
11 |
12 | public SphericalPoint(float angleFromNorth, float distance, float altitude)
13 | {
14 | this.distance = distance;
15 | //arctan of opposite/adjacent
16 | float opposite;
17 | boolean neg = false;
18 | if(altitude > currentAltitude)
19 | {
20 | opposite = altitude - currentAltitude;
21 | }
22 | else
23 | {
24 | opposite = currentAltitude - altitude;
25 | neg = true;
26 | }
27 | inclination = (float) Math.atan(((double)opposite/distance));
28 | if(neg)
29 | opposite = opposite * -1;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/Where4/src/haseman/project/fourSquareLibs/FourSqareVenue.java:
--------------------------------------------------------------------------------
1 | package haseman.project.fourSquareLibs;
2 |
3 | import ARKit.ARSphericalView;
4 | import android.content.Context;
5 | import android.graphics.Canvas;
6 | import android.graphics.Color;
7 |
8 | public class FourSqareVenue extends ARSphericalView
9 | {
10 | public String name;
11 | public int checkins;
12 | public FourSqareVenue(Context ctx)
13 | {
14 | super(ctx);
15 | inclination = 0;
16 | }
17 |
18 | public void draw(Canvas c)
19 | {
20 |
21 | p.setColor(Color.WHITE);
22 | if(name != null)
23 | c.drawText(name, getLeft(), getTop(), p);
24 |
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Where4/src/haseman/project/fourSquareLibs/FourSquareClient.java:
--------------------------------------------------------------------------------
1 | package haseman.project.fourSquareLibs;
2 |
3 | import haseman.project.where4.HoldMeUp;
4 |
5 | import java.io.InputStreamReader;
6 | import java.net.HttpURLConnection;
7 | import java.net.URL;
8 | import java.util.Enumeration;
9 | import java.util.Vector;
10 |
11 | import org.xmlpull.v1.XmlPullParser;
12 | import org.xmlpull.v1.XmlPullParserFactory;
13 |
14 | import android.location.Location;
15 | import android.util.Log;
16 |
17 | public class FourSquareClient
18 | {
19 | int highestCheckin = 0;
20 | private void adjustAz(Vector v)
21 | {
22 | Enumeration e = v.elements();
23 | while(e.hasMoreElements())
24 | {
25 | FourSqareVenue ven = (FourSqareVenue)e.nextElement();
26 | ven.inclination = (ven.checkins / highestCheckin) * 100;
27 | Log.e("inc","Inclination is "+ven.inclination);
28 | }
29 | }
30 | public Vector getVenuList(Location loc)
31 | {
32 |
33 | Vector v = new Vector();
34 | try{
35 | URL url = new URL("http://api.foursquare.com/v1/venues?l=5&geolat="+loc.getLatitude()+"&geolong="+loc.getLongitude());
36 | Log.e("where4","Url: "+url.toString());
37 | HttpURLConnection httpconn;
38 | httpconn = (HttpURLConnection) url.openConnection();
39 | httpconn.setDoInput(true);
40 | httpconn.setDoOutput(false);
41 | httpconn.connect();
42 | int httpRC = httpconn.getResponseCode();
43 | if (httpRC == HttpURLConnection.HTTP_OK)
44 | {
45 | XmlPullParserFactory x = XmlPullParserFactory.newInstance();
46 | x.setNamespaceAware(false);
47 | XmlPullParser p = x.newPullParser();
48 | p.setInput(new InputStreamReader(httpconn.getInputStream()));
49 | boolean parsing = true;
50 | String curText="", name;
51 | float lat=-1,lon=-1;
52 | FourSqareVenue curVen = new FourSqareVenue(HoldMeUp.ctx);
53 | while(parsing)
54 | {
55 | int next = p.next();
56 | switch(next)
57 | {
58 | case XmlPullParser.START_TAG:
59 | name = p.getName();
60 | if(name.equals("venue"))
61 | curVen = new FourSqareVenue(HoldMeUp.ctx);
62 | break;
63 | case XmlPullParser.END_TAG:
64 | name = p.getName();
65 | if(name.equals("venue"))
66 | {
67 | curVen.location = new Location("FourSqareApi");
68 | curVen.location.setLatitude(lat);
69 | curVen.location.setLongitude(lon);
70 | v.add(curVen);
71 | }
72 | else if(name.equals("name"))
73 | curVen.name = curText;
74 |
75 | else if(name.equals("geolat"))
76 | lat = Float.parseFloat(curText);
77 | else if(name.equals("geolong"))
78 | lon = Float.parseFloat(curText);
79 | else if(name.equals("checkins"))
80 | {
81 | curVen.checkins = Integer.parseInt(curText);
82 | if(curVen.checkins > highestCheckin)
83 | highestCheckin = curVen.checkins;
84 | }
85 | break;
86 | case XmlPullParser.CDSECT:
87 | case XmlPullParser.TEXT:
88 | curText = p.getText();
89 | break;
90 | case XmlPullParser.END_DOCUMENT:
91 | parsing = false;
92 |
93 | }
94 | }
95 | adjustAz(v);
96 | }
97 | }catch(Exception e)
98 | {
99 | Log.e("4sqrClient","Failed to get");
100 | }
101 |
102 | return v;
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/Where4/src/haseman/project/where4/CompassListener.java:
--------------------------------------------------------------------------------
1 | //package haseman.project.where4;
2 | //
3 | //import android.content.Context;
4 | //import android.graphics.Canvas;
5 | //import android.graphics.Color;
6 | //import android.graphics.Paint;
7 | //import android.hardware.Sensor;
8 | //import android.hardware.SensorEvent;
9 | //import android.hardware.SensorEventListener;
10 | //import android.hardware.SensorManager;
11 | //import android.location.Location;
12 | //import android.location.LocationListener;
13 | //import android.location.LocationManager;
14 | //import android.location.GpsStatus.Listener;
15 | //import android.os.Bundle;
16 | //import android.view.View;
17 | //
18 | ////Height degrees =25
19 | ////Width degrees =38
20 | //public class CompassListener extends View
21 | //{
22 | // public static SensorManager sensorMan;
23 | // public static LocationManager locMan;
24 | // public static Location curLocation = null;
25 | // private Context ctx;
26 | // public static float direction = (float) 22.4;
27 | // public static double inclination;
28 | // public static double rollingX = (float)0;
29 | // public static double rollingZ = (float)0;
30 | // public static float kFilteringFactor = (float)0.05;
31 | // public static float one = (float)0;
32 | // public static float two = (float)0;
33 | // public static float three = (float)0;
34 | // private boolean locationChanged = false;
35 | // private LocationListener gpsListener = new LocationListener(){
36 | //
37 | // public void onLocationChanged(Location location)
38 | // {
39 | // if(curLocation == null)
40 | // {
41 | // curLocation = location;
42 | // ARSphericalView.deviceLocation = location;
43 | // locationChanged = true;
44 | // }
45 | // else if(curLocation.getLatitude() == location.getLatitude() &&
46 | // curLocation.getLongitude() == location.getLongitude())
47 | // locationChanged = false;
48 | // else
49 | // locationChanged = true;
50 | //
51 | // curLocation = location;
52 | // }
53 | //
54 | // public void onProviderDisabled(String provider){}
55 | //
56 | // public void onProviderEnabled(String provider){}
57 | //
58 | // public void onStatusChanged(String provider, int status, Bundle extras){}
59 | //
60 | // };
61 | // private SensorEventListener listener = new SensorEventListener(){
62 | //
63 | // public void onAccuracyChanged(Sensor arg0, int arg1)
64 | // {
65 | // // TODO Auto-generated method stub
66 | //
67 | // }
68 | //
69 | // public void onSensorChanged(SensorEvent evt)
70 | // {
71 | // float vals[] = evt.values;
72 | //
73 | // if(evt.sensor.getType() == Sensor.TYPE_ORIENTATION)
74 | // {
75 | // float tmp = vals[0];
76 | // //tmp = tmp-90;
77 | // if(tmp < 0)
78 | // tmp = tmp+360;
79 | //
80 | // direction =(float) ((tmp * kFilteringFactor) + (direction * (1.0 - kFilteringFactor)));
81 | // //direction = direction-90;
82 | // if(direction < 0)
83 | // direction = 360+direction;
84 | //// rollingZ = (float) ((vals[2] * kFilteringFactor) + (rollingZ * (1.0 - kFilteringFactor)));
85 | //// if(rollingZ < 0)
86 | //// rollingZ = rollingZ * -1;
87 | //
88 | // //inclination = two*10;
89 | //
90 | // //inclination = inclination * -1;
91 | //
92 | // if(locationChanged)
93 | // updateLayouts(direction+90, (float)inclination, curLocation);
94 | // else
95 | // updateLayouts(direction, (float)inclination, null);
96 | // }
97 | // if(evt.sensor.getType() == Sensor.TYPE_ACCELEROMETER)
98 | // {
99 | // //two =(float) ((vals[2] * kFilteringFactor) + (two * (1.0 - kFilteringFactor)));
100 | // //hree = (float) ((vals[1] * kFilteringFactor) + (three * (1.0 - kFilteringFactor)));
101 | // rollingZ = (vals[2] * kFilteringFactor) + (rollingZ * (1.0 - kFilteringFactor));
102 | // rollingX = (vals[0] * kFilteringFactor) + (rollingX * (1.0 - kFilteringFactor));
103 | //
104 | // if (rollingZ != 0.0)
105 | // {
106 | // inclination = Math.atan(rollingX / rollingZ);// + Math.PI / 2.0;
107 | // } else if (rollingX < 0)
108 | // {
109 | // inclination = Math.PI/2.0;
110 | // } else if (rollingX >= 0)
111 | // {
112 | // inclination = 3 * Math.PI/2.0;
113 | // }
114 | //
115 | // //convert to degress
116 | // inclination = inclination * (360/(2*Math.PI));
117 | //
118 | // //flip!
119 | // if(inclination < 0)
120 | // inclination = inclination + 90;
121 | // else
122 | // inclination = inclination -90;
123 | //
124 | // }
125 | //
126 | // ARLayout.postStaticInvalidate();
127 | // CompassListener.this.postInvalidate();
128 | // if(locationChanged)
129 | // ARLayout.updateLayouts(direction+90, (float)inclination, curLocation);
130 | // else
131 | // ARLayout.updateLayouts(direction, (float)inclination, null);
132 | // }
133 | // };
134 | // public CompassListener(Context ctx)
135 | // {
136 | // super(ctx);
137 | // this.ctx = ctx;
138 | //// new Thread(){
139 | ////
140 | //// public void run(){
141 | // sensorMan = (SensorManager)CompassListener.this.ctx.getSystemService(Context.SENSOR_SERVICE);
142 | // sensorMan.registerListener(listener, sensorMan.getDefaultSensor(Sensor.TYPE_ORIENTATION), SensorManager.SENSOR_DELAY_FASTEST);
143 | // sensorMan.registerListener(listener, sensorMan.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_FASTEST);
144 | // locMan = (LocationManager)CompassListener.this.ctx.getSystemService(Context.LOCATION_SERVICE);
145 | // locMan.requestLocationUpdates(LocationManager.GPS_PROVIDER, 100, 1, gpsListener);
146 | // //}
147 | //// }.start();
148 | // }
149 | //
150 | // protected void onDraw(Canvas c)
151 | // {
152 | // super.onDraw(c);
153 | // //c.drawColor(Color.WHITE);
154 | // Paint p = new Paint();
155 | // p.setColor(Color.WHITE);
156 | //
157 | // c.drawText("Compass:"+String.valueOf(direction), 20, 20, p);
158 | // c.drawText("ZDirection"+String.valueOf(rollingZ), 40, 40, p);
159 | // c.drawText("XDirection"+String.valueOf(rollingX), 50, 120, p);
160 | ////
161 | //// c.drawText("ZDirection"+String.valueOf(one), 50, 80, p);
162 | //// if(curLocation != null)
163 | //// c.drawText("LatLon: "+String.valueOf(curLocation.getLatitude()) +":"+String.valueOf(curLocation.getLongitude()), 50, 60, p);
164 | // //c.drawText("Accel"+String.valueOf(two), 50, 100, p);
165 | // //c.drawText("YDirection"+String.valueOf(three), 50, 120, p);
166 | // c.drawText("Inclination"+String.valueOf(inclination), 50, 140, p);
167 | // }
168 | // public void close()
169 | // {
170 | // sensorMan.unregisterListener(listener);
171 | // locMan.removeGpsStatusListener((Listener) gpsListener);
172 | // }
173 | //}
174 |
--------------------------------------------------------------------------------
/Where4/src/haseman/project/where4/CustomCameraView.java:
--------------------------------------------------------------------------------
1 | package haseman.project.where4;
2 |
3 | import java.io.IOException;
4 |
5 | import android.content.Context;
6 | import android.graphics.Bitmap;
7 | import android.graphics.Canvas;
8 | import android.graphics.Color;
9 | import android.graphics.Paint;
10 | import android.graphics.PixelFormat;
11 | import android.hardware.Camera;
12 | import android.hardware.Camera.Parameters;
13 | import android.hardware.Camera.Size;
14 | import android.util.AttributeSet;
15 | import android.util.Config;
16 | import android.util.Log;
17 | import android.view.Surface;
18 | import android.view.SurfaceHolder;
19 | import android.view.SurfaceView;
20 | import android.view.View;
21 | import android.view.Window;
22 |
23 |
24 | public class CustomCameraView extends SurfaceView
25 | {
26 | Camera camera;
27 | SurfaceHolder previewHolder;
28 |
29 | //Callback for the surfaceholder
30 | SurfaceHolder.Callback surfaceHolderListener = new SurfaceHolder.Callback() {
31 | public void surfaceCreated(SurfaceHolder holder) {
32 | camera=Camera.open();
33 |
34 | try
35 | {
36 | camera.setPreviewDisplay(previewHolder);
37 | }
38 | catch (Throwable t) {
39 |
40 | }
41 | }
42 |
43 | public void surfaceChanged(SurfaceHolder surfaceHolder, int format, int w, int h)
44 | {
45 | //Parameters params = camera.getParameters();
46 | //params.setPreviewSize(w, h);
47 | //params.setPictureFormat(PixelFormat.JPEG);
48 | //camera.setParameters(params);
49 | camera.startPreview();
50 | }
51 |
52 | public void surfaceDestroyed(SurfaceHolder arg0)
53 | {
54 | // TODO Auto-generated method stub
55 | camera.stopPreview();
56 | camera.release();
57 |
58 | }
59 | };
60 | public CustomCameraView(Context ctx)
61 | {
62 | super(ctx);
63 |
64 | previewHolder = this.getHolder();
65 | previewHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
66 | previewHolder.addCallback(surfaceHolderListener);
67 | setBackgroundColor(Color.TRANSPARENT);
68 | }
69 | public CustomCameraView(Context context, AttributeSet attrs)
70 | {
71 | super(context, attrs);
72 | }
73 | protected void onDraw (Canvas canvas)
74 | {
75 | super.onDraw(canvas);
76 | //CompassListener.sensorMan.get
77 | //Paint p = new Paint();
78 | //p.setColor(Color.WHITE);
79 | //canvas.drawText(String.valueOf(CompassListener.direction), 170, 0, new Paint());
80 | }
81 | public void closeCamera()
82 | {
83 | if(camera != null)
84 | camera.release();
85 | }
86 | public void dispatchDraw(Canvas c)
87 | {
88 | super.dispatchDraw(c);
89 | //Log.i("Drawing","Got Dispatch!");
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/Where4/src/haseman/project/where4/HoldMeUp.java:
--------------------------------------------------------------------------------
1 | package haseman.project.where4;
2 |
3 | import haseman.project.fourSquareLibs.FourSqareVenue;
4 | import haseman.project.fourSquareLibs.FourSquareClient;
5 |
6 | import java.util.Enumeration;
7 | import java.util.Vector;
8 |
9 | import ARKit.ARLayout;
10 | import android.app.Activity;
11 | import android.content.Context;
12 | import android.content.pm.ActivityInfo;
13 | import android.location.Location;
14 | import android.location.LocationListener;
15 | import android.location.LocationManager;
16 | import android.os.Bundle;
17 | import android.util.Log;
18 | import android.view.Display;
19 | import android.view.Window;
20 | import android.view.WindowManager;
21 | import android.widget.FrameLayout;
22 |
23 | public class HoldMeUp extends Activity {
24 | /** Called when the activity is first created. */
25 | CustomCameraView cv;
26 | public static volatile Context ctx;
27 | ARLayout ar;
28 | volatile Location curLocation = null;
29 |
30 | private LocationListener gpsListener = new LocationListener(){
31 |
32 | public void onLocationChanged(Location location)
33 | {
34 | Log.e("HoldMe","Got first");
35 | if(curLocation != null)
36 | return;
37 | curLocation = location;
38 | new Thread(){
39 | public void run(){
40 | FourSquareClient fc = new FourSquareClient();
41 | Vector vc = fc.getVenuList(curLocation);
42 | Log.e("Where4","CurLocation LA:"+curLocation.getLatitude()+" LO:"+curLocation.getLongitude());
43 | ar.clearARViews();
44 | if(vc != null && vc.size() > 0)
45 | {
46 | Enumeration e = vc.elements();
47 | while(e.hasMoreElements())
48 | {
49 | FourSqareVenue fq = (FourSqareVenue) e.nextElement();
50 | Log.e("Where4","Got Venue:"+fq.name);
51 | if(fq.location != null)
52 | Log.i("Where4", "Lat:"+fq.location.getLatitude()+":"+fq.location.getLongitude());
53 | Log.e("Where4", "Azimuth: "+fq.azimuth);
54 | ar.addARView(fq);
55 | }
56 | }
57 | }
58 | }.start();
59 | LocationManager locMan = (LocationManager)ctx.getSystemService(Context.LOCATION_SERVICE);
60 | locMan.removeUpdates(this);
61 | }
62 |
63 | public void onProviderDisabled(String provider){}
64 |
65 | public void onProviderEnabled(String provider){}
66 |
67 | public void onStatusChanged(String provider, int status, Bundle extras){}
68 |
69 | };
70 |
71 | private void addLoadingLayouts()
72 | {
73 | FourSqareVenue fs = new FourSqareVenue(this.getApplicationContext());
74 | fs.azimuth = 0;
75 | fs.inclination = 0;
76 | fs.name = "Loading";
77 | ar.addARView(fs);
78 | fs = new FourSqareVenue(this.getApplicationContext());
79 | fs.azimuth = 45;
80 | fs.inclination = 0;
81 | fs.name = "Loading";
82 | ar.addARView(fs);
83 | fs = new FourSqareVenue(this.getApplicationContext());
84 | fs.azimuth = 90;
85 | fs.inclination = 0;
86 | fs.name = "Loading";
87 | ar.addARView(fs);
88 | fs = new FourSqareVenue(this.getApplicationContext());
89 | fs.azimuth = 135;
90 | fs.inclination = 0;
91 | fs.name = "Loading";
92 | ar.addARView(fs);
93 | fs = new FourSqareVenue(this.getApplicationContext());
94 | fs.azimuth = 180;
95 | fs.inclination = 0;
96 | fs.name = "Loading";
97 | ar.addARView(fs);
98 | fs = new FourSqareVenue(this.getApplicationContext());
99 | fs.azimuth = 210;
100 | fs.inclination = 0;
101 | fs.name = "Loading";
102 | ar.addARView(fs);
103 | fs = new FourSqareVenue(this.getApplicationContext());
104 | fs.azimuth = 270;
105 | fs.inclination = 0;
106 | fs.name = "Loading";
107 | ar.addARView(fs);
108 | ar.postInvalidate();
109 | }
110 |
111 | public void onStart()
112 | {
113 | super.onStart();
114 | }
115 | public void onCreate(Bundle savedInstanceState) {
116 | try{
117 | super.onCreate(savedInstanceState);
118 |
119 | ctx = this.getApplicationContext();
120 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
121 | requestWindowFeature(Window.FEATURE_NO_TITLE);
122 |
123 | getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
124 | WindowManager.LayoutParams.FLAG_FULLSCREEN);
125 |
126 | ar = new ARLayout(getApplicationContext());
127 |
128 | cv = new CustomCameraView(this.getApplicationContext());
129 | requestWindowFeature(Window.FEATURE_NO_TITLE);
130 | //cl = new CompassListener(this.getApplicationContext());
131 | WindowManager w = getWindowManager();
132 | Display d = w.getDefaultDisplay();
133 | int width = d.getWidth();
134 | int height = d.getHeight();
135 | ar.screenHeight = height;
136 | ar.screenWidth = width;
137 | FrameLayout rl = new FrameLayout(getApplicationContext());
138 | rl.addView(cv,width, height);
139 | ar.debug = true;
140 | rl.addView(ar, width, height);
141 | setContentView(rl);
142 | LocationManager locMan = (LocationManager)ctx.getSystemService(Context.LOCATION_SERVICE);
143 | locMan.requestLocationUpdates(LocationManager.GPS_PROVIDER, 100, 1, gpsListener);
144 | //Log.e("Where","Orientation:"+i);
145 | //rl.bringChildToFront(cl);
146 | addLoadingLayouts();
147 |
148 | }catch(Exception e)
149 | {
150 | e.printStackTrace();
151 | }
152 | }
153 | public void onDestroy()
154 | {
155 | super.onDestroy();
156 | cv.closeCamera();
157 | ar.close();
158 | //cl.close();
159 | //cv.closeCamera();
160 | }
161 | }
--------------------------------------------------------------------------------
/license:
--------------------------------------------------------------------------------
1 | Copyright (c) 2009 by Chris Haseman
2 | http://hasemanOnMobile.com
3 |
4 | All Rights Reserved
5 | ATTRIBUTION ASSURANCE LICENSE (adapted from the original BSD license)
6 | Redistribution and use in source and binary forms, with or without
7 | modification, are permitted provided that the conditions below are met.
8 | These conditions require a modest attribution to Chris Haseman (the
9 | "Author"), who hopes that its promotional value may help justify the
10 | thousands of dollars in otherwise billable time invested in writing
11 | this and other freely available, open-source software.
12 |
13 | 1. Redistributions of source code, in whole or part and with or without
14 | modification (the "Code"), must prominently display this GPG-signed
15 | text in verifiable form.
16 | 2. Redistributions of the Code in binary form must be accompanied by
17 | this GPG-signed text in any documentation and, each time the resulting
18 | executable program or a program dependent thereon is launched, a
19 | prominent display (e.g., splash screen or banner text) of the Author's
20 | attribution information, which includes:
21 | (a) Name ("Chris Haseman"),
22 | (b) Professional identification ("Software Engineer"), and
23 | (c) URL ("http://hasemanOnMobile.com").
24 | 3. Neither the name nor any trademark of the Author may be used to
25 | endorse or promote products derived from this software without specific
26 | prior written permission.
27 | 4. Users are entirely responsible, to the exclusion of the Author and
28 | any other persons, for compliance with (1) regulations set by owners or
29 | administrators of employed equipment, (2) licensing terms of any other
30 | software, and (3) local regulations regarding use, including those
31 | regarding import, export, and use of encryption software.
32 |
33 | THIS FREE SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND
34 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
35 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
36 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
37 | EVENT SHALL THE AUTHOR OR ANY CONTRIBUTOR BE LIABLE FOR
38 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
39 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
40 | EFFECTS OF UNAUTHORIZED OR MALICIOUS NETWORK ACCESS;
41 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
42 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
43 | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
44 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
46 | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
47 |
--------------------------------------------------------------------------------