Skip to content

Commit

Permalink
Adding HTTP data transmitter
Browse files Browse the repository at this point in the history
  • Loading branch information
audaciouscode committed Apr 7, 2016
1 parent 229653c commit 2b13afe
Show file tree
Hide file tree
Showing 7 changed files with 738 additions and 4 deletions.
18 changes: 14 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,20 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
classpath 'com.android.tools.build:gradle:2.0.0'
}
}

repositories {
jcenter()
}

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"

useLibrary 'org.apache.http.legacy'

defaultConfig {
// applicationId "com.audacious_software.pdk.passivedatakit"
minSdkVersion 14
Expand All @@ -39,11 +45,15 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
// testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.android.support:recyclerview-v7:23.2.1'
compile 'com.android.support:cardview-v7:23.2.1'
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:recyclerview-v7:23.3.0'
compile 'com.android.support:cardview-v7:23.3.0'
compile 'com.google.android.gms:play-services-location:8.4.0'
compile 'com.google.android.gms:play-services-maps:8.4.0'
compile 'com.squareup.okhttp3:okhttp:3.2.0'
compile 'commons-io:commons-io:2.4'
compile 'org.apache.commons:commons-lang3:3.4'
compile 'com.fasterxml.jackson.core:jackson-core:2.7.3'
}

buildTypes {
Expand Down
55 changes: 55 additions & 0 deletions src/com/audacious_software/passive_data_kit/DeviceInformation.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
package com.audacious_software.passive_data_kit;

import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.wifi.WifiManager;
import android.os.BatteryManager;

public class DeviceInformation {
private static boolean sWifiAvailable = false;
private static long sLastWifiCheck = 0;

public static boolean isKindleFire()
{
boolean isKindle = android.os.Build.MANUFACTURER.equalsIgnoreCase("Amazon")
Expand All @@ -10,4 +21,48 @@ public static boolean isKindleFire()

return isKindle;
}

public static boolean wifiAvailable(Context context) {
long now = System.currentTimeMillis();

if (now - DeviceInformation.sLastWifiCheck > 10000) {
DeviceInformation.sLastWifiCheck = now;

WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);

if (wifi.isWifiEnabled()) {
DeviceInformation.sWifiAvailable = true;

ConnectivityManager connection = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

NetworkInfo netInfo = connection.getActiveNetworkInfo();

if (netInfo != null) {
if (netInfo.getType() != ConnectivityManager.TYPE_WIFI) {
DeviceInformation.sWifiAvailable = false;
}
else if (netInfo.getState() != NetworkInfo.State.CONNECTED
&& netInfo.getState() != NetworkInfo.State.CONNECTING) {
DeviceInformation.sWifiAvailable = false;
}
}
else {
DeviceInformation.sWifiAvailable = false;
}
}
else {
DeviceInformation.sWifiAvailable = false;
}
}

return DeviceInformation.sWifiAvailable;
}

public static boolean isPluggedIn(Context context) {
Intent intent = context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));

int plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);

return plugged == BatteryManager.BATTERY_PLUGGED_AC || plugged == BatteryManager.BATTERY_PLUGGED_USB || plugged == BatteryManager.BATTERY_PLUGGED_WIRELESS;
}
}
6 changes: 6 additions & 0 deletions src/com/audacious_software/passive_data_kit/Logger.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@

import android.content.Context;

import java.util.HashMap;

/**
* Created by cjkarr on 4/3/2016.
*/
public class Logger {
private Context mContext = null;

public void log(String event, HashMap<String, Object> details) {
// TODO
}

private static class LoggerHolder {
public static Logger instance = new Logger();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ public abstract class Generator
public static final String TIMESTAMP = "timestamp";
public static final String GENERATOR = "generator";
public static final String SOURCE = "source";
public static final String MEDIA_ATTACHMENT_KEY = "attachment";
public static final String MEDIA_CONTENT_TYPE_KEY = "attachment-type";
public static final String MEDIA_ATTACHMENT_GUID_KEY = "attachment-guid";

protected Context mContext = null;

Expand Down

0 comments on commit 2b13afe

Please sign in to comment.