Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 47 additions & 9 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,44 @@
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

android {
compileSdkVersion 20
buildToolsVersion '26.0.2'
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}

dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}

repositories {
maven { url 'https://maven.fabric.io/public' }
}

android {
compileSdkVersion 26
buildToolsVersion "26.0.2"
defaultConfig {
applicationId "com.ubidots.ubidots"
minSdkVersion 14
targetSdkVersion 20
minSdkVersion 19
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
useLibrary 'org.apache.http.legacy'
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LGPL2.1'
}
buildTypes {
release {
Expand All @@ -20,8 +49,17 @@ android {
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.android.gms:play-services:5.0.89'
compile 'com.android.support:support-v4:20.0.+'
compile 'com.google.code.gson:gson:2.2.4'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.google.android.gms:play-services-maps:11.4.2'
compile 'com.google.android.gms:play-services-location:11.4.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.2'
compile 'org.apache.httpcomponents:httpclient-android:4.3.5'
compile('com.crashlytics.sdk.android:answers:1.4.1@aar') {
transitive = true;
}
}
3 changes: 3 additions & 0 deletions app/fabric.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#Contains API Secret used to validate your application. Commit to internal source control; avoid making secret public.
#Mon Oct 23 19:44:05 CDT 2017
apiSecret=
44 changes: 30 additions & 14 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ubidots.ubidots" >

package="com.ubidots.ubidots">
<!--
The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
Google Maps Android API v2, but you must specify either coarse or fine
location permissions for the 'MyLocation' functionality.
-->
<permission
android:name="com.ubidots.ubidots.MAPS_RECEIVE"
android:protectionLevel="signature" />
Expand All @@ -20,18 +24,15 @@

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/UbidotsTheme" >
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />

<activity
android:name=".MainActivity"
android:configChanges="orientation"
android:label="@string/app_name"
android:theme="@style/UbidotsTheme.NoActionBar" >
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand All @@ -47,10 +48,19 @@
android:name=".UbidotsActivity"
android:label="@string/title_activity_ubidots" >
</activity>

<!--
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.maps.v2.API_KEY"
android:value="here_goes_api_key" />
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key" />



<service
android:name=".services.PushLocationService"
Expand All @@ -62,6 +72,12 @@
<action android:name="com.ubidots.ubidots.ACTION_PUSH_LOCATION_ALARM" />
</intent-filter>
</receiver>
</application>

</manifest>
<meta-data
android:name="io.fabric.ApiKey"
android:value=""
/>

</application>
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
41 changes: 40 additions & 1 deletion app/src/main/java/com/ubidots/ubidots/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,40 @@
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v7.app.AppCompatActivity;

import com.ubidots.ubidots.fragments.BrowserFragment;
import com.ubidots.ubidots.fragments.MainFragment;

import com.crashlytics.android.answers.Answers;
import io.fabric.sdk.android.Fabric;

//public class MainActivity extends AppCompatActivity implements MainFragment.MainFragmentButtonsInterface {
public class MainActivity extends Activity implements MainFragment.MainFragmentButtonsInterface {
// We want to know if the user has logged in before
private SharedPreferences mSharedPreferences;
private boolean mUserFirstTime;
private boolean isUserLoggedIn;
private FragmentManager mFragmentManager;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Fabric.with(this, new Answers());
setContentView(R.layout.activity_main);

mFragmentManager = getFragmentManager();
// Get the preference to check if the user has logged in previously
mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
mUserFirstTime = mSharedPreferences.getBoolean(Constants.FIRST_TIME, true);
//isUserLoggedIn = mSharedPreferences.getBoolean(Constants.FIRST_TIME, false);

if (savedInstanceState == null) {
/* if (savedInstanceState == null) {
if (mUserFirstTime) {
MainFragment mainFragment = new MainFragment();
getFragmentManager()
Expand All @@ -39,7 +48,37 @@ protected void onCreate(Bundle savedInstanceState) {
startActivity(ubidotsIntent);
finish();
}
}*/
/*if (savedInstanceState == null) {
if(!isUserLoggedIn) {
MainFragment mainFragment = new MainFragment();
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.add(R.id.fragment_container, mainFragment);
fragmentTransaction.commit();
Intent ubidotsIntent = new Intent(this, UbidotsActivity.class);
ubidotsIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(ubidotsIntent);
finish();
}

}
*/
if (savedInstanceState == null) {
if (mUserFirstTime) {
MainFragment mainFragment = new MainFragment();
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.add(R.id.fragment_container, mainFragment);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
} else {
Intent ubidotsIntent = new Intent(this, UbidotsActivity.class);
startActivity(ubidotsIntent);
finish();
}
}

}

// Method from MainFragment
Expand Down
73 changes: 62 additions & 11 deletions app/src/main/java/com/ubidots/ubidots/UbidotsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import android.app.ActionBar;
import android.app.Activity;
import android.app.DialogFragment;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
Expand All @@ -20,9 +19,10 @@
import android.net.ConnectivityManager;
import android.net.Uri;
import android.os.Bundle;

import android.preference.PreferenceManager;
import android.support.v4.app.NotificationCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
Expand All @@ -31,22 +31,24 @@
import android.widget.CompoundButton;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MapStyleOptions;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import com.ubidots.ubidots.fragments.ChangePushTimeFragment;
import com.ubidots.ubidots.services.PushLocationService;

import java.lang.reflect.Field;

public class UbidotsActivity extends Activity implements
ChangePushTimeFragment.DialogListener {
public class UbidotsActivity extends AppCompatActivity implements ChangePushTimeFragment.DialogListener,OnMapReadyCallback {
// Preferences
private SharedPreferences mSharedPreferences;
private SharedPreferences.Editor mEditor;
Expand Down Expand Up @@ -102,10 +104,8 @@ protected void onCreate(Bundle savedInstanceState) {
mEditor = mSharedPreferences.edit();

// Get preferences variables
boolean firstTime =
mSharedPreferences.getBoolean(Constants.FIRST_TIME, true);
mAlreadyRunning =
mSharedPreferences.getBoolean(Constants.SERVICE_RUNNING, false);
boolean firstTime = mSharedPreferences.getBoolean(Constants.FIRST_TIME, true);
mAlreadyRunning = mSharedPreferences.getBoolean(Constants.SERVICE_RUNNING, false);
mTimeToPush = mSharedPreferences.getInt(Constants.PUSH_TIME, 1);

// Set the text at the left of the Switch
Expand All @@ -124,8 +124,39 @@ protected void onCreate(Bundle savedInstanceState) {
// Check if Google Maps is installed
if (isGoogleMapsInstalled()) {
// Instantiate the fragment containing the map in the layout
mGoogleMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();

//mGoogleMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
//mGoogleMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map));
MapFragment mapFragment = ((MapFragment) getFragmentManager().findFragmentById(R.id.map));
final UbidotsActivity activity = this;
mapFragment.getMapAsync(this);

mapFragment.getMapAsync(new OnMapReadyCallback()
{
@Override
public void onMapReady(GoogleMap googleMap)
{
mGoogleMap = googleMap;
if (mGoogleMap == null)
{
Toast.makeText(getApplicationContext(), "Unable to open Google map. Unable to continue", Toast.LENGTH_LONG).show();
return;
}
try
{
//For customizing styles tweak res/raw/style_json.json https://mapstyle.withgoogle.com/
boolean success = mGoogleMap.setMapStyle(MapStyleOptions.loadRawResourceStyle(activity, R.raw.style_json));
if (!success)
{
//dbglog.Log("Style parsing failed.");
System.out.println("Style parsing failed.");
}
} catch (Exception e)
{
//dbglog.Log("Style parsing failed.");
System.out.println("Style parsing failed.");
}
}
});
// Get the location given by the system
LocationManager location = (LocationManager) getSystemService(LOCATION_SERVICE);

Expand All @@ -152,7 +183,11 @@ public void onProviderDisabled(String provider) { }
};

// Set the listener to the location manager
location.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
try {
location.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
} catch (SecurityException e) {
e.printStackTrace();
}
}

// Update the text inside the button with the time to push
Expand Down Expand Up @@ -341,4 +376,20 @@ public void onReceive(Context context, Intent intent) {
}
}
}


@Override
public void onMapReady(GoogleMap map) {
// DO WHATEVER YOU WANT WITH GOOGLEMAP
map.setMapType(GoogleMap.MAP_TYPE_HYBRID);
try {
map.setMyLocationEnabled(true);
} catch (SecurityException e) {
e.printStackTrace();
}
map.setTrafficEnabled(true);
map.setIndoorEnabled(true);
map.setBuildingsEnabled(true);
map.getUiSettings().setZoomControlsEnabled(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;


Expand Down
Loading