Permalink
Browse files

initial commit

  • Loading branch information...
0 parents commit 2a81d2c9cf30003edb212b7703a9c076527ab9a4 @trajano committed Jan 21, 2012
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="src" path="gen"/>
+ <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
+ <classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
+ <classpathentry kind="output" path="bin/classes"/>
+</classpath>
@@ -0,0 +1,2 @@
+gen/
+bin/
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>GasPrices</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.ApkBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>com.android.ide.eclipse.adt.AndroidNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
@@ -0,0 +1,4 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.source=1.5
@@ -0,0 +1,54 @@
+eclipse.preferences.version=1
+editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
+sp_cleanup.add_default_serial_version_id=true
+sp_cleanup.add_generated_serial_version_id=false
+sp_cleanup.add_missing_annotations=true
+sp_cleanup.add_missing_deprecated_annotations=true
+sp_cleanup.add_missing_methods=false
+sp_cleanup.add_missing_nls_tags=false
+sp_cleanup.add_missing_override_annotations=true
+sp_cleanup.add_missing_override_annotations_interface_methods=true
+sp_cleanup.add_serial_version_id=false
+sp_cleanup.always_use_blocks=true
+sp_cleanup.always_use_parentheses_in_expressions=false
+sp_cleanup.always_use_this_for_non_static_field_access=false
+sp_cleanup.always_use_this_for_non_static_method_access=false
+sp_cleanup.convert_to_enhanced_for_loop=true
+sp_cleanup.correct_indentation=true
+sp_cleanup.format_source_code=true
+sp_cleanup.format_source_code_changes_only=false
+sp_cleanup.make_local_variable_final=true
+sp_cleanup.make_parameters_final=true
+sp_cleanup.make_private_fields_final=true
+sp_cleanup.make_type_abstract_if_missing_method=false
+sp_cleanup.make_variable_declarations_final=true
+sp_cleanup.never_use_blocks=false
+sp_cleanup.never_use_parentheses_in_expressions=true
+sp_cleanup.on_save_use_additional_actions=true
+sp_cleanup.organize_imports=true
+sp_cleanup.qualify_static_field_accesses_with_declaring_class=false
+sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
+sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
+sp_cleanup.qualify_static_member_accesses_with_declaring_class=true
+sp_cleanup.qualify_static_method_accesses_with_declaring_class=false
+sp_cleanup.remove_private_constructors=true
+sp_cleanup.remove_trailing_whitespaces=true
+sp_cleanup.remove_trailing_whitespaces_all=true
+sp_cleanup.remove_trailing_whitespaces_ignore_empty=false
+sp_cleanup.remove_unnecessary_casts=true
+sp_cleanup.remove_unnecessary_nls_tags=true
+sp_cleanup.remove_unused_imports=true
+sp_cleanup.remove_unused_local_variables=false
+sp_cleanup.remove_unused_private_fields=true
+sp_cleanup.remove_unused_private_members=false
+sp_cleanup.remove_unused_private_methods=true
+sp_cleanup.remove_unused_private_types=true
+sp_cleanup.sort_members=true
+sp_cleanup.sort_members_all=true
+sp_cleanup.use_blocks=true
+sp_cleanup.use_blocks_only_for_return_and_throw=false
+sp_cleanup.use_parentheses_in_expressions=true
+sp_cleanup.use_this_for_non_static_field_access=true
+sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true
+sp_cleanup.use_this_for_non_static_method_access=true
+sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="net.trajano.gasprices"
+ android:versionCode="1"
+ android:versionName="1.0" >
+
+ <uses-sdk android:minSdkVersion="14" />
+ <uses-permission android:name="android.permission.INTERNET"/>
+ <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
+
+ <application
+ android:icon="@drawable/ic_launcher"
+ android:label="@string/app_name" >
+ <activity
+ android:name=".GasPricesActivity"
+ android:label="@string/app_name" >
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ <receiver android:name="GasPricesWidgetProvider">
+ <intent-filter>
+ <action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
+ </intent-filter>
+ </receiver>
+ </application>
+
+</manifest>
@@ -0,0 +1,40 @@
+-optimizationpasses 5
+-dontusemixedcaseclassnames
+-dontskipnonpubliclibraryclasses
+-dontpreverify
+-verbose
+-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
+
+-keep public class * extends android.app.Activity
+-keep public class * extends android.app.Application
+-keep public class * extends android.app.Service
+-keep public class * extends android.content.BroadcastReceiver
+-keep public class * extends android.content.ContentProvider
+-keep public class * extends android.app.backup.BackupAgentHelper
+-keep public class * extends android.preference.Preference
+-keep public class com.android.vending.licensing.ILicensingService
+
+-keepclasseswithmembernames class * {
+ native <methods>;
+}
+
+-keepclasseswithmembers class * {
+ public <init>(android.content.Context, android.util.AttributeSet);
+}
+
+-keepclasseswithmembers class * {
+ public <init>(android.content.Context, android.util.AttributeSet, int);
+}
+
+-keepclassmembers class * extends android.app.Activity {
+ public void *(android.view.View);
+}
+
+-keepclassmembers enum * {
+ public static **[] values();
+ public static ** valueOf(java.lang.String);
+}
+
+-keep class * implements android.os.Parcelable {
+ public static final android.os.Parcelable$Creator *;
+}
@@ -0,0 +1,11 @@
+# This file is automatically generated by Android Tools.
+# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
+#
+# This file must be checked in Version Control Systems.
+#
+# To customize properties used by the Ant build system use,
+# "ant.properties", and override values to adapt the script to your
+# project structure.
+
+# Project target.
+target=android-14
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:orientation="vertical" >
+
+ <TextView
+ android:id="@+id/GasPriceText"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/hello" />
+
+</LinearLayout>
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+ <string name="hello">Over here would show what the current gas price is and tomorrow\'s gas price.</string>
+ <string name="app_name">Gas Prices</string>
+
+</resources>
@@ -0,0 +1,42 @@
+package net.trajano.gasprices;
+
+public final class DistanceUtil {
+ /**
+ * Radius of the earth in km. Value obtained from Google.
+ */
+ public static final double RADIUS_OF_THE_EARTH_IN_KM = 6378.1;
+
+ /**
+ * Calculate the distance between two points on the earth. This uses the
+ * ÔhaversineÕ formula to calculate the great-circle distance between two
+ * points Ð that is, the shortest distance over the earthÕs surface Ð giving
+ * an Ôas-the-crow-fliesÕ distance between the points (ignoring any hills,
+ * of course!).
+ *
+ * @see http://www.movable-type.co.uk/scripts/latlong.html
+ * @param lat1
+ * @param long1
+ * @param lat2
+ * @param long2
+ * @return
+ */
+ public static double distance(final double lat1, final double long1,
+ final double lat2, final double long2) {
+ final double dLat = Math.toRadians(lat2 - lat1);
+ final double dLon = Math.toRadians(long2 - long1);
+ final double rlat1 = Math.toRadians(lat1);
+ final double rlat2 = Math.toRadians(lat2);
+
+ final double a = Math.sin(dLat / 2) * Math.sin(dLat / 2)
+ + Math.sin(dLon / 2) * Math.sin(dLon / 2) * Math.cos(rlat1)
+ * Math.cos(rlat2);
+ final double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
+ return RADIUS_OF_THE_EARTH_IN_KM * c;
+ }
+
+ /**
+ * Prevent instantiation of utility class.
+ */
+ private DistanceUtil() {
+ }
+}
@@ -0,0 +1,16 @@
+package net.trajano.gasprices;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.os.StrictMode;
+
+public class GasPricesActivity extends Activity {
+ /** Called when the activity is first created. */
+ @Override
+ public void onCreate(final Bundle savedInstanceState) {
+ StrictMode.enableDefaults();
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.main);
+ new UpdateDataTask(this).execute();
+ }
+}
@@ -0,0 +1,15 @@
+package net.trajano.gasprices;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+
+public class GasPricesWidgetProvider extends BroadcastReceiver {
+
+ @Override
+ public void onReceive(final Context context, final Intent intent) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
@@ -0,0 +1,93 @@
+package net.trajano.gasprices;
+
+import java.io.IOException;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.Scanner;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.json.JSONTokener;
+
+import android.app.Activity;
+import android.os.AsyncTask;
+import android.util.Log;
+import android.widget.TextView;
+
+public final class UpdateDataTask extends AsyncTask<Void, Integer, JSONObject> {
+ /**
+ * Activity.
+ */
+ private final Activity activity;
+
+ public UpdateDataTask(final Activity activity) {
+ this.activity = activity;
+ }
+
+ @Override
+ protected JSONObject doInBackground(final Void... params) {
+ try {
+ final HttpURLConnection urlConnection = (HttpURLConnection) new URL(
+ "http://www.tomorrowsgaspricetoday.com/mobile/json_mobile_data.php")
+ .openConnection();
+ try {
+ // Read the JSON data, skip the first character since it breaks
+ // the
+ // parsing.
+ final String jsonData = new Scanner(
+ urlConnection.getInputStream()).useDelimiter("\\A")
+ .next().substring(1);
+
+ final JSONObject object = (JSONObject) new JSONTokener(jsonData)
+ .nextValue();
+ final JSONArray prices = (JSONArray) object.get("gasprices");
+
+ final double currentLatitude = 43.6669;
+ final double currentLongitude = -79.3824;
+ double currentDistance = Double.MAX_VALUE;
+ JSONObject currentPrices = null;
+ for (int i = 0; i < prices.length(); ++i) {
+ final JSONObject currentObject = prices.getJSONObject(i);
+ if (currentObject.isNull("location_latitude")) {
+ continue;
+ }
+ final double lat = currentObject
+ .getDouble("location_latitude");
+ final double longitude = currentObject
+ .getDouble("location_longitude");
+ final double distance = DistanceUtil.distance(
+ currentLatitude, currentLongitude, lat, longitude);
+ if (distance <= currentDistance) {
+ currentDistance = distance;
+ currentPrices = currentObject;
+ }
+ }
+ return currentPrices;
+ } finally {
+ urlConnection.disconnect();
+ }
+ } catch (final JSONException e) {
+ Log.e("GasPrices", e.getMessage());
+ return null;
+ } catch (final IOException e) {
+ Log.e("GasPrices", e.getMessage());
+ return null;
+ }
+ }
+
+ @Override
+ protected void onPostExecute(final JSONObject result) {
+ if (result == null) {
+ return;
+ }
+ Log.v("ME", "result is =" + result);
+ final TextView v = (TextView) activity.findViewById(R.id.GasPriceText);
+ try {
+ v.setText(result.getString("regular") + "\n" + result);
+ } catch (final JSONException e) {
+ Log.e("GasPrices", e.getMessage());
+ return;
+ }
+ }
+}

0 comments on commit 2a81d2c

Please sign in to comment.