Jump to content


Photo

Looking for Java Help


  • Please log in to reply
10 replies to this topic

#1 Copaman

Copaman

    Ryan

  • Project Team
  • 2,144 posts
  • Location:Lehigh University
  • Projects:Winning.
  •  Slowly becoming a Veteran

Posted 04 December 2009 - 05:04 PM

This is for a class of mine... Engineering Design and Development.

Previously I had thought my project would involve simplicity and not-programming stuff. I've been told by my teacher that I should probably just write a program for smartphones instead of doing my original idea (which I though was more practical and easier to do).

Ideally...

GPS positioning sampling at Time 1.
GPS positioning sampling at Time 2.
Calculate distance between Sample 1 and Sample 2 in miles.
Calculate the change in Time in hours.
[Distance/(Change in Time)] = Average V.
If Average V > 20 MPH, Phone enters "Airplane Mode"
If Average V < 20 MPH, Phone functions normally.



Would anyone care to help? I've been scrambling trying to learn Java, but I'm having trouble and the big wigs of the program associated with my class are coming to see what every student has done in the first week of Jan... ANY help would be appreciated.

Posted Image

 

If you meet me:

Have some courtesy,

Have some sympathy,

And some taste.

Use all your well-learned politesse,

Or I'll lay your soul to waste.


#2 Bart

Bart

  • Network Admins
  • 8,524 posts
  • Location:The Netherlands
  • Division:Revora
  • Job:Network Leader

Posted 04 December 2009 - 05:41 PM

Well, how much do you know? It's a bit hard to help if we don't know whether you can make hello world :p
bartvh | Join me, make your signature small!
Einstein: "We can’t solve problems by using the same kind of thinking we used when we created them."

#3 Copaman

Copaman

    Ryan

  • Project Team
  • 2,144 posts
  • Location:Lehigh University
  • Projects:Winning.
  •  Slowly becoming a Veteran

Posted 05 December 2009 - 02:42 AM

The internet is my friend when it comes to Java programming.

I can definitely do Hello World... learned how to script the distance formula today so that's one part of my quest.

Also I'm thinking about going about this for Android-based phones. I'll be installing the Android Plugin for Eclipse on Tuesday.

Posted Image

 

If you meet me:

Have some courtesy,

Have some sympathy,

And some taste.

Use all your well-learned politesse,

Or I'll lay your soul to waste.


#4 Copaman

Copaman

    Ryan

  • Project Team
  • 2,144 posts
  • Location:Lehigh University
  • Projects:Winning.
  •  Slowly becoming a Veteran

Posted 26 May 2010 - 12:05 AM

So I thought I'd give you all an update and ask for more help (lol):

So far I've written the distance/velocity formula code, the GPS location sampler code, and the timertask that I think I'm going to use to run the thing "AtFixedRate".

I have a couple of questions.

1. If my GPS sampling is placed into the run() method of the timertask, would I be able to store the coordinates for each iteration of the timertask as variables? ie GPS sample at time 1 stored as x1 y1, GPS at time 2 is x2 y2, GPS at time 3 gives new values of x1 and y1, etc.

2. If I can't do that, how can I go about augmenting the GPS sample at a given rate that lets me do the above?

3. I have to put each of the individual parts together and have the code "working" [read: it has to look like it'll work, it has to theoretically work, but it probably doesn't actually have to work perfectly]. I'm going to need help with this. Any takers?

Posted Image

 

If you meet me:

Have some courtesy,

Have some sympathy,

And some taste.

Use all your well-learned politesse,

Or I'll lay your soul to waste.


#5 Bart

Bart

  • Network Admins
  • 8,524 posts
  • Location:The Netherlands
  • Division:Revora
  • Job:Network Leader

Posted 26 May 2010 - 08:48 AM

If my GPS sampling is placed into the run() method of the timertask, would I be able to store the coordinates for each iteration of the timertask as variables? ie GPS sample at time 1 stored as x1 y1, GPS at time 2 is x2 y2, GPS at time 3 gives new values of x1 and y1, etc.

But of course. That's so basic, a language that can't do that would be severely crippled.
You should put them in a list. There are various options:
- arrays
- arraylist
- linkedlist
I'm going to let you google the rest, since it's core knowledge you'll need to understand anyway :p

I have to put each of the individual parts together and have the code "working" [read: it has to look like it'll work, it has to theoretically work, but it probably doesn't actually have to work perfectly]. I'm going to need help with this. Any takers?

There's really too little information abuot your project to be able to help
bartvh | Join me, make your signature small!
Einstein: "We can’t solve problems by using the same kind of thinking we used when we created them."

#6 Jeeves

Jeeves

    I write the interwebz

  • Members
  • 4,156 posts
  •  Friendly neighborhood standards Nazi

Posted 27 May 2010 - 01:31 AM

Or use a double-linked list, just for lols

World Domination Status: 2.7%


#7 Copaman

Copaman

    Ryan

  • Project Team
  • 2,144 posts
  • Location:Lehigh University
  • Projects:Winning.
  •  Slowly becoming a Veteran

Posted 07 June 2010 - 11:39 PM

So I have one last question and my program should (fingers crossed) be ready for testing...

I have a package with the following code:

package com.ryan.android.cellsafe;

import android.app.Activity;
import android.os.Bundle;
import android.provider.Settings;
import android.provider.Settings.System;
import android.widget.TextView;
import android.content.Context;
import android.content.ContentResolver;
import android.content.Intent;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;

public class CellSafe extends Activity {
	
	
	private TextView tv;
	private LocationManager lm;
	private LocationListener ll;
	double mySpeed, maxSpeed, limitSpeed;
	
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		tv = new TextView(this);
		setContentView(tv);
		
		maxSpeed = mySpeed = 0;
		limitSpeed = 7.8232;
		
		lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
		ll = new SpeedoActionListener();
		lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, ll);
	}
	
	private class SpeedoActionListener implements LocationListener {
		
		@Override
		public void onLocationChanged(Location location) {
			if(location!=null){
				if(location.hasSpeed()){
					mySpeed = location.getSpeed();
					if(mySpeed>maxSpeed)
						maxSpeed = mySpeed;
					tv.setText("\nCurrent speed: " + mySpeed*2.2369 + " mph, Max speed: " + maxSpeed*2.2369 + " mph");
					if(mySpeed>=limitSpeed){
						
						//***AREA IN QUESTION***
						
					}
					
							}
						
						}
					}
				   				
		
		
		   @Override
	   	public void onProviderDisabled(String provider) {
	   		//TODO Auto-generated method stub
	   		
	   	}
	   	
	   	@Override
	   	public void onProviderEnabled(String provider) {
	   		//TODO Auto-generated method stub
	   	}
	   	
	   	@Override
	   	public void onStatusChanged(String provider, int status, Bundle extras) {
	   		//TODO Auto-generated method stub
	   		
		}

			   	
	}
}


For the area in question in the above code, I have another bit of code:

package com.ryan.android.airplanechange;

import android.provider.Settings;
import android.app.Activity;
import android.content.Context;

public class AirplaneChange extends Activity {
	public void method() {
		Context context = getApplicationContext();
		
		boolean isEnabled = Settings.System.getInt(context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0) == 1;
		
		Settings.System.putInt(context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, isEnabled ? 0 : 1);
	}


}




As you can tell, they are from different packages. When the particular if statement from the first bit of code is valid, that is, the value of mySpeed is greater than or equal to the value of limitSpeed, I need the second bit of code to do its thing.

How do I make that happen?

Posted Image

 

If you meet me:

Have some courtesy,

Have some sympathy,

And some taste.

Use all your well-learned politesse,

Or I'll lay your soul to waste.


#8 Jeeves

Jeeves

    I write the interwebz

  • Members
  • 4,156 posts
  •  Friendly neighborhood standards Nazi

Posted 08 June 2010 - 02:12 AM

For android-specific shiz you might want to ask xda-devs if you don't get a reply soon

World Domination Status: 2.7%


#9 Bart

Bart

  • Network Admins
  • 8,524 posts
  • Location:The Netherlands
  • Division:Revora
  • Job:Network Leader

Posted 08 June 2010 - 08:13 AM

Eh...
AirplaneChange apc = new AirplaneChange();
apc.method();

My advice: buy a book :p
bartvh | Join me, make your signature small!
Einstein: "We can’t solve problems by using the same kind of thinking we used when we created them."

#10 Copaman

Copaman

    Ryan

  • Project Team
  • 2,144 posts
  • Location:Lehigh University
  • Projects:Winning.
  •  Slowly becoming a Veteran

Posted 08 June 2010 - 10:42 AM

Eh...

AirplaneChange apc = new AirplaneChange();
apc.method();

My advice: buy a book :p


Thank you :)

I'm done with the damn thing next week. Probably won't touch Java after that... ^_^

Posted Image

 

If you meet me:

Have some courtesy,

Have some sympathy,

And some taste.

Use all your well-learned politesse,

Or I'll lay your soul to waste.


#11 Jeeves

Jeeves

    I write the interwebz

  • Members
  • 4,156 posts
  •  Friendly neighborhood standards Nazi

Posted 23 June 2010 - 04:43 AM

Buy a book? Perhaps that's where I'm going wrong. All five of my Java books were free, and I can't write a line of it!

World Domination Status: 2.7%





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users