Commit dec6df54 authored by Marcel Vološin's avatar Marcel Vološin
Browse files

first commit

parents
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
Night Runner
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<resourceExtensions />
<wildcardResourcePatterns>
<entry name="!?*.java" />
<entry name="!?*.form" />
<entry name="!?*.class" />
<entry name="!?*.groovy" />
<entry name="!?*.scala" />
<entry name="!?*.flex" />
<entry name="!?*.kt" />
<entry name="!?*.clj" />
<entry name="!?*.aj" />
</wildcardResourcePatterns>
<annotationProcessing>
<profile default="true" name="Default" enabled="false">
<processorPath useClasspath="true" />
</profile>
</annotationProcessing>
</component>
</project>
\ No newline at end of file
<component name="CopyrightManager">
<settings default="" />
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="PROJECT" charset="UTF-8" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="distributionType" value="LOCAL" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleHome" value="C:\Program Files\Android\Android Studio\gradle\gradle-2.8" />
<option name="gradleJvm" value="1.8" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" />
</set>
</option>
</GradleProjectSettings>
</option>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="EntryPointsManager">
<entry_points version="2.0" />
</component>
<component name="NullableNotNullManager">
<option name="myDefaultNullable" value="android.support.annotation.Nullable" />
<option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
<option name="myNullables">
<value>
<list size="4">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" />
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
</list>
</value>
</option>
<option name="myNotNulls">
<value>
<list size="4">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" />
</list>
</value>
</option>
</component>
<component name="ProjectLevelVcsManager" settingsEditedManually="false">
<OptionsSetting value="true" id="Add" />
<OptionsSetting value="true" id="Remove" />
<OptionsSetting value="true" id="Checkout" />
<OptionsSetting value="true" id="Update" />
<OptionsSetting value="true" id="Status" />
<OptionsSetting value="true" id="Edit" />
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
<option name="id" value="Android" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/NightRunner.iml" filepath="$PROJECT_DIR$/NightRunner.iml" />
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RunConfigurationProducerService">
<option name="ignoredProducers">
<set>
<option value="org.jetbrains.plugins.gradle.execution.test.runner.AllInPackageGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer" />
</set>
</option>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="" />
</component>
</project>
\ No newline at end of file
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "smarts.volosin.marcel.nightrunner"
minSdkVersion 18
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.google.android.gms:play-services:8.3.0'
}
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in C:\Users\Marcel\AppData\Local\Android\sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
package smarts.volosin.marcel.nightrunner;
import android.app.Application;
import android.test.ApplicationTestCase;
/**
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
*/
public class ApplicationTest extends ApplicationTestCase<Application> {
public ApplicationTest() {
super(Application.class);
}
}
\ No newline at end of file
<resources>
<!--
TODO: Before you run your application, you need a Google Maps API key.
To get one, follow this link, follow the directions and press "Create" at the end:
https://console.developers.google.com/flows/enableapi?apiid=maps_android_backend&keyType=CLIENT_SIDE_ANDROID&r=F4:25:27:19:1E:EA:AE:4B:29:D7:8B:E7:A4:0B:25:EA:79:A3:22:69%3Bsmarts.volosin.marcel.nightrunner
You can also add your credentials to an existing key, using this line:
F4:25:27:19:1E:EA:AE:4B:29:D7:8B:E7:A4:0B:25:EA:79:A3:22:69;smarts.volosin.marcel.nightrunner
Alternatively, follow the directions here:
https://developers.google.com/maps/documentation/android/start#get-key
Once you have your key (it starts with "AIza"), replace the "google_maps_key"
string in this file.
-->
<string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">
AIzaSyDPihXfy-JSKFz4co_F4xwHaIplLrQ_1tc
</string>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="smarts.volosin.marcel.nightrunner">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<!--
!!!! ATTENTION !!!!
Class named MoonClaculation.java wasn't created by author of this application.
It was created by Angus McIntyre in 01.06.1996
-->
<application
android:allowBackup="true"
android:icon="@mipmap/icon"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".TrackerActivity" />
<activity android:name=".ForecastActivity" />
<activity android:name=".SummaryActivity" />
<!--
The API key for Google Maps-based APIs is defined as a string resource.
(See the file "res/values/google_maps_api.xml").
Note that the API key is linked to the encryption key used to sign the APK.
You need a different API key for each encryption key, including the release key that is used to
sign the APK for publishing.
You can define the keys for the debug and release targets in src/debug/ and src/release/.
-->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key" />
<activity
android:name=".MapsActivity"
android:label="@string/title_activity_maps" />
<activity android:name=".MakacsHistory" />
<activity android:name=".LocalHistoryActivity" />
<activity android:name=".PerformanceDetailActivity" />
<service android:name=".WeatherUpdater" />
<activity android:name=".SettingsActivity" />
<receiver
android:name=".BootReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="start.alarm" />
</intent-filter>
</receiver>
</application>
</manifest>
package smarts.volosin.marcel.nightrunner;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class BootReceiver extends BroadcastReceiver {
private static final String TAG = "BootReceiver";
@Override
public void onReceive(Context context, Intent intent) {
Log.i(TAG, "onReceive()");
Intent actIntent = new Intent(context, WeatherUpdater.class);
PendingIntent pi = PendingIntent.getService(context, 0, actIntent, 0);
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
am.setInexactRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), AlarmManager.INTERVAL_FIFTEEN_MINUTES, pi);
}
}
\ No newline at end of file
package smarts.volosin.marcel.nightrunner;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteConstraintException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteQuery;
import android.util.Log;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class DatabaseOperation {
private static final String TAG = "Database operation";
private Context context;
private SQLiteDatabase database;
public DatabaseOperation(Context context){
this.context = context;
}
public void saveCityToDb(String city){
DbHelper helper = new DbHelper(context);
database = helper.getReadableDatabase();
database.execSQL("delete from city");
database.execSQL(String.format("insert into city values (null, \"%s\")",city));
database.close();
helper.close();
}
public String getCityFromDb(){
DbHelper helper = new DbHelper(context);
database = helper.getReadableDatabase();
Cursor cursor = database.rawQuery("SELECT city from city", null);
if (cursor != null) {
if (cursor.moveToFirst()) {
String city = cursor.getString(0);
cursor.close();
database.close();
helper.close();
return city;
}
}
database.close();
helper.close();
return null;
}
public void saveNicknameToDb(String nickname){
DbHelper helper = new DbHelper(context);
database = helper.getReadableDatabase();
database.execSQL("delete from nickname");
database.execSQL(String.format("insert into nickname values (null, \"%s\")",nickname));
database.close();
helper.close();
}
public String getNicknameFromDb(){
DbHelper helper = new DbHelper(context);
database = helper.getReadableDatabase();
Cursor cursor = database.rawQuery("SELECT nickname from nickname", null);
if (cursor != null) {
if (cursor.moveToFirst()) {
String nickname= cursor.getString(0);
cursor.close();
database.close();
helper.close();
return nickname;
}
}
database.close();
helper.close();
return null;
}
public void saveJsonToDb(JSONObject data){
DbHelper helper = new DbHelper(context);
database = helper.getReadableDatabase();
if(data != null) {
try {
database.execSQL("delete FROM forecast");
String query = String.format("INSERT into forecast values(%d, '%s')", data.getLong("dt"), data.toString());
database.execSQL(query);
}catch(SQLiteConstraintException e){
Log.e(TAG, "Trying to insert existing forecast data");
} catch (JSONException e) {
e.printStackTrace();
}
}
database.close();
helper.close();
}
public ForecastRow getForecast(){
String city, temp, temp_max, temp_min, desc;
DbHelper helper = new DbHelper(context);
database = helper.getReadableDatabase();
Cursor cursor = database.rawQuery("SELECT * from forecast", null);
if (cursor != null) {
if (cursor.moveToFirst()) {
try {
JSONObject json = new JSONObject(cursor.getString(1));
Log.i(TAG, "toto je nas json z databazy" + json.toString());
cursor.close();
database.close();
helper.close();
JsonParser parser = new JsonParser();
return parser.getForecast(json);
} catch (JSONException e) {
e.printStackTrace();
}
}
}
Log.e(TAG, "getForecast() nema cursor");
return null;
}
public void removeRecord (String key){
DbHelper helper = new DbHelper(context);
database = helper.getReadableDatabase();
database.execSQL("delete FROM performances where id = "+ key+";");
database.close();
helper.close();
}
}
package smarts.volosin.marcel.nightrunner;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
public class DbHelper extends SQLiteOpenHelper {
public static final int DATABASE_VERSION = 9;
private static final String SQL_CREATE_PERFORMACES = "CREATE TABLE performances ( " +
"id INTEGER PRIMARY KEY autoincrement, " +
"duration LONG not null, " +
"distance LONG not null, " +
"top_speed FLOAT, " +
"top_acceleration FLOAT, " +
"date_time varchar(40)" +
")";
private static final String SQL_CREATE_CITY_TABLE = "CREATE TABLE city (" +
"id INTEGER PRIMARY KEY autoincrement, " +
"city varchar(30))";
private static final String SQL_CREATE_FORECAST_TABLE= "Create TABLE forecast (" +
"_id INTEGER PRIMARY KEY, " +
"data TEXT)";
public static final String SQL_CREATE_NICKNAME_TABLE="CREATE TABLE nickname(" +
"id INTEGER PRIMARY KEY autoincrement, " +
"nickname varchar(30))";
private static final String TAG = "DbHelper";
public DbHelper(Context context) {
super(context,"performances.db", null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(SQL_CREATE_PERFORMACES);
db.execSQL(SQL_CREATE_FORECAST_TABLE);
db.execSQL(SQL_CREATE_CITY_TABLE);
db.execSQL(SQL_CREATE_NICKNAME_TABLE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS performances");
db.execSQL("DROP TABLE IF EXISTS forecast");
db.execSQL("DROP TABLE IF EXISTS city");
db.execSQL("DROP TABLE IF EXISTS nickname");
onCreate(db);
}
}
package smarts.volosin.marcel.nightrunner;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import org.json.JSONException;
import org.json.JSONObject;
import org.w3c.dom.Text;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
public class ForecastActivity extends AppCompatActivity {
private static final String TAG = "ForecastAactivity";
private TextView forecastView, temp, temp_min, temp_max, desc, city, phaseView, windV, humiV;