├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── drawable-v21
│ │ │ │ ├── geo_marker.png
│ │ │ │ ├── ic_menu_send.xml
│ │ │ │ ├── ic_menu_slideshow.xml
│ │ │ │ ├── ic_menu_gallery.xml
│ │ │ │ ├── ic_menu_manage.xml
│ │ │ │ ├── ic_menu_camera.xml
│ │ │ │ └── ic_menu_share.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── drawable-hdpi
│ │ │ │ └── geo_marker.png
│ │ │ ├── drawable-mdpi
│ │ │ │ └── geo_marker.png
│ │ │ ├── drawable-xhdpi
│ │ │ │ └── geo_marker.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── drawable-xxhdpi
│ │ │ │ └── geo_marker.png
│ │ │ ├── drawable-xxxhdpi
│ │ │ │ └── geo_marker.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── drawable
│ │ │ │ └── side_nav_bar.xml
│ │ │ ├── values-v21
│ │ │ │ └── styles.xml
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ ├── values
│ │ │ │ ├── colors.xml
│ │ │ │ ├── drawables.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── styles.xml
│ │ │ │ └── strings.xml
│ │ │ ├── menu
│ │ │ │ ├── activity_main_drawer.xml
│ │ │ │ └── main.xml
│ │ │ └── layout
│ │ │ │ ├── activity_main.xml
│ │ │ │ ├── nav_header_main.xml
│ │ │ │ ├── fragment_learn.xml
│ │ │ │ ├── app_bar_main.xml
│ │ │ │ ├── fragment_track.xml
│ │ │ │ ├── wifi_list_item.xml
│ │ │ │ └── fragment_settings.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── find
│ │ │ │ └── wifitool
│ │ │ │ ├── OnFragmentInteractionListener.java
│ │ │ │ ├── httpCalls
│ │ │ │ ├── FindWiFi.java
│ │ │ │ ├── HttpCallback.java
│ │ │ │ └── FindWiFiImpl.java
│ │ │ │ ├── wifi
│ │ │ │ ├── WifiObject.java
│ │ │ │ ├── WifiArrayAdapter.java
│ │ │ │ ├── WifiData.java
│ │ │ │ ├── WifiDataNetwork.java
│ │ │ │ └── WifiIntentReceiver.java
│ │ │ │ ├── database
│ │ │ │ ├── Event.java
│ │ │ │ └── InternalDataBase.java
│ │ │ │ ├── internal
│ │ │ │ ├── Utils.java
│ │ │ │ └── Constants.java
│ │ │ │ ├── MainActivity.java
│ │ │ │ ├── TrackFragment.java
│ │ │ │ ├── LearnFragment.java
│ │ │ │ └── SettingsFragment.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── find
│ │ │ └── wifitool
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── find
│ │ └── wifitool
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── screenshots
├── learn.png
├── track.png
├── create.png
├── settings.png
└── nav-header.png
├── .idea
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── vcs.xml
├── modules.xml
├── runConfigurations.xml
├── gradle.xml
├── compiler.xml
└── misc.xml
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── gradle.properties
├── LICENSE
├── gradlew.bat
├── README.md
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/screenshots/learn.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/uncleashi/find-client-android/HEAD/screenshots/learn.png
--------------------------------------------------------------------------------
/screenshots/track.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/uncleashi/find-client-android/HEAD/screenshots/track.png
--------------------------------------------------------------------------------
/screenshots/create.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/uncleashi/find-client-android/HEAD/screenshots/create.png
--------------------------------------------------------------------------------
/screenshots/settings.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/uncleashi/find-client-android/HEAD/screenshots/settings.png
--------------------------------------------------------------------------------
/screenshots/nav-header.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/uncleashi/find-client-android/HEAD/screenshots/nav-header.png
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/uncleashi/find-client-android/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v21/geo_marker.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/uncleashi/find-client-android/HEAD/app/src/main/res/drawable-v21/geo_marker.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/uncleashi/find-client-android/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/uncleashi/find-client-android/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/geo_marker.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/uncleashi/find-client-android/HEAD/app/src/main/res/drawable-hdpi/geo_marker.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/geo_marker.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/uncleashi/find-client-android/HEAD/app/src/main/res/drawable-mdpi/geo_marker.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/geo_marker.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/uncleashi/find-client-android/HEAD/app/src/main/res/drawable-xhdpi/geo_marker.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/uncleashi/find-client-android/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/uncleashi/find-client-android/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/geo_marker.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/uncleashi/find-client-android/HEAD/app/src/main/res/drawable-xxhdpi/geo_marker.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/geo_marker.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/uncleashi/find-client-android/HEAD/app/src/main/res/drawable-xxxhdpi/geo_marker.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/uncleashi/find-client-android/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/java/com/find/wifitool/OnFragmentInteractionListener.java:
--------------------------------------------------------------------------------
1 | package com.find.wifitool;
2 |
3 | import android.net.Uri;
4 |
5 | /**
6 | * Created by akshay on 30/12/16.
7 | */
8 |
9 | public interface OnFragmentInteractionListener {
10 |
11 | void onFragmentInteraction(Uri uri);
12 | }
13 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/side_nav_bar.xml:
--------------------------------------------------------------------------------
1 |
3 |
9 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v21/ic_menu_send.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values-v21/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #e51717
4 | #b90808
5 | #e51717
6 | #b20909
7 |
8 | #BDBDBD
9 | #4CAF50
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v21/ic_menu_slideshow.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v21/ic_menu_gallery.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/test/java/com/find/wifitool/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.find.wifitool;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v21/ic_menu_manage.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
--------------------------------------------------------------------------------
/app/src/main/java/com/find/wifitool/httpCalls/FindWiFi.java:
--------------------------------------------------------------------------------
1 | package com.find.wifitool.httpCalls;
2 |
3 | import com.squareup.okhttp.Callback;
4 |
5 | import org.json.JSONObject;
6 |
7 | /**
8 | * Created by akshay on 30/12/16.
9 | */
10 |
11 | /**
12 | * Asynchronous HTTP library for the Find API.
13 | */
14 | public interface FindWiFi {
15 |
16 | /**
17 | * Track
18 | */
19 | void findTrack(Callback callback, String serverAddr, JSONObject requestBody);
20 |
21 | /**
22 | * Learn
23 | */
24 | void findLearn(Callback callback, String serverAddr, JSONObject requestBody);
25 | }
26 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/values/drawables.xml:
--------------------------------------------------------------------------------
1 |
2 | - @android:drawable/ic_menu_camera
3 | - @android:drawable/ic_menu_gallery
4 | - @android:drawable/ic_menu_slideshow
5 | - @android:drawable/ic_menu_manage
6 | - @android:drawable/ic_menu_share
7 | - @android:drawable/ic_menu_send
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v21/ic_menu_camera.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 160dp
5 |
6 | 16dp
7 | 16dp
8 | 16dp
9 | 250dp
10 | 64dp
11 | 16dp
12 |
13 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /home/akshay/Android/Sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/activity_main_drawer.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
9 |
13 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v21/ic_menu_share.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/java/com/find/wifitool/wifi/WifiObject.java:
--------------------------------------------------------------------------------
1 | package com.find.wifitool.wifi;
2 |
3 | import android.os.Parcel;
4 | import android.os.Parcelable;
5 |
6 | /**
7 | * Created by akshay on 31/12/16.
8 | */
9 |
10 | public class WifiObject implements Parcelable {
11 |
12 | public String wifiName;
13 | public String grpName;
14 | public String userName;
15 |
16 | // constructor
17 | public WifiObject(String wifi, String group, String user) {
18 | this.wifiName = wifi;
19 | this.grpName = group;
20 | this.userName = user;
21 | }
22 |
23 | @Override
24 | public int describeContents() {
25 | return 0;
26 | }
27 |
28 | @Override
29 | public void writeToParcel(Parcel dest, int flags) {
30 |
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Find
3 |
4 | Open navigation drawer
5 | Close navigation drawer
6 |
7 | Settings
8 | Quit
9 | Visit FIND Github
10 | Visit App Github
11 | Report Issue
12 | Visit FIND website
13 | Visit Kontext website
14 |
15 |
16 | Hello blank fragment
17 | [click to set]
18 |
19 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/find/wifitool/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.find.wifitool;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.find.wifitool", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/main.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
9 |
10 |
15 |
16 |
21 |
22 |
27 |
28 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.0"
6 | defaultConfig {
7 | applicationId "com.findTools.Find"
8 | minSdkVersion 18
9 | targetSdkVersion 23
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
25 | exclude group: 'com.android.support', module: 'support-annotations'
26 | })
27 | compile 'com.squareup.okhttp:okhttp:2.4.0'
28 | compile 'com.android.support:appcompat-v7:25.0.1'
29 | compile 'com.android.support:design:25.0.1'
30 | testCompile 'junit:junit:4.12'
31 | }
32 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
16 |
17 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2016 uncleashi
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/nav_header_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
14 |
15 |
22 |
23 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_learn.xml:
--------------------------------------------------------------------------------
1 |
2 |
14 |
15 |
21 |
22 |
30 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/app_bar_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
13 |
14 |
19 |
20 |
26 |
27 |
28 |
29 |
34 |
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/app/src/main/java/com/find/wifitool/httpCalls/HttpCallback.java:
--------------------------------------------------------------------------------
1 | package com.find.wifitool.httpCalls;
2 |
3 | import android.os.Handler;
4 | import android.os.Looper;
5 |
6 | import com.squareup.okhttp.Callback;
7 | import com.squareup.okhttp.Request;
8 | import com.squareup.okhttp.Response;
9 |
10 | import java.io.IOException;
11 |
12 | /**
13 | * Created by akshay on 30/12/16.
14 | */
15 |
16 | public class HttpCallback implements Callback {
17 |
18 | private static final String TAG = HttpCallback.class.getSimpleName();
19 |
20 | // private variables
21 | private final com.squareup.okhttp.Callback delegate;
22 | private final Handler handler;
23 |
24 | //Constructor
25 | public HttpCallback(com.squareup.okhttp.Callback delegate) {
26 | this.delegate = delegate;
27 | this.handler = new Handler(Looper.getMainLooper());
28 | }
29 |
30 | @Override
31 | public void onFailure(final Request request, final IOException e) {
32 | handler.post(new Runnable() {
33 | @Override
34 | public void run() {
35 | delegate.onFailure(request, e);
36 | }
37 | });
38 | }
39 |
40 | @Override
41 | public void onResponse(final Response response) throws IOException {
42 | handler.post(new Runnable() {
43 | @Override
44 | public void run() {
45 | try {
46 | delegate.onResponse(response);
47 | } catch (IOException e) {
48 | delegate.onFailure(null, e);
49 | }
50 | }
51 | });
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
11 |
12 |
13 |
14 |
15 |
16 |
22 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/app/src/main/java/com/find/wifitool/wifi/WifiArrayAdapter.java:
--------------------------------------------------------------------------------
1 | package com.find.wifitool.wifi;
2 |
3 | import android.content.Context;
4 | import android.support.annotation.NonNull;
5 | import android.view.LayoutInflater;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 | import android.widget.ArrayAdapter;
9 | import android.widget.TextView;
10 |
11 | import com.find.wifitool.R;
12 |
13 | import java.util.List;
14 |
15 | /**
16 | * Created by akshay on 30/12/16.
17 | */
18 |
19 | public class WifiArrayAdapter extends ArrayAdapter {
20 |
21 | private static final String TAG = WifiArrayAdapter.class.getSimpleName();
22 |
23 | // Constructor
24 | public WifiArrayAdapter(Context mContext, int layoutResourceId, List objects) {
25 | super(mContext, layoutResourceId, objects);
26 | }
27 |
28 | @NonNull
29 | @Override
30 | public View getView(int position, View convertView, ViewGroup parent) {
31 |
32 | final WifiObject wifiItem = getItem(position);
33 |
34 | if(convertView == null){
35 | convertView = LayoutInflater.from(getContext()).inflate(R.layout.wifi_list_item, parent, false);
36 | }
37 |
38 | // Getting UI components
39 | TextView wifiName = (TextView) convertView.findViewById(R.id.wifiName);
40 | TextView wifiGroup = (TextView) convertView.findViewById(R.id.fieldGrpName);
41 | TextView wifiUser = (TextView) convertView.findViewById(R.id.fieldUsrName);
42 |
43 | // Setting UI components
44 | wifiName.setText(wifiItem.wifiName);
45 | wifiGroup.setText(wifiItem.grpName);
46 | wifiUser.setText(wifiItem.userName);
47 |
48 | return convertView;
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/app/src/main/java/com/find/wifitool/wifi/WifiData.java:
--------------------------------------------------------------------------------
1 | package com.find.wifitool.wifi;
2 |
3 | import android.os.Parcel;
4 | import android.os.Parcelable;
5 |
6 | import java.util.ArrayList;
7 | import java.util.List;
8 |
9 | /**
10 | * Created by akshay on 30/12/16.
11 | */
12 |
13 | public class WifiData implements Parcelable {
14 |
15 | private List mNetworks;
16 |
17 | public WifiData() {
18 | mNetworks = new ArrayList();
19 | }
20 |
21 | public WifiData(Parcel in) {
22 | in.readTypedList(mNetworks, WifiDataNetwork.CREATOR);
23 | }
24 |
25 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
26 | public WifiData createFromParcel(Parcel in) {
27 | return new WifiData(in);
28 | }
29 |
30 | public WifiData[] newArray(int size) {
31 | return new WifiData[size];
32 | }
33 | };
34 |
35 | @Override
36 | public int describeContents() {
37 | return 0;
38 | }
39 |
40 | @Override
41 | public void writeToParcel(Parcel dest, int flags) {
42 | dest.writeTypedList(mNetworks);
43 | }
44 |
45 | /**
46 | * @return Returns a string containing a concise, human-readable description
47 | * of this object.
48 | */
49 | @Override
50 | public String toString() {
51 | if (mNetworks == null || mNetworks.size() == 0)
52 | return "Empty data";
53 | else
54 | return mNetworks.size() + " networks data";
55 | }
56 |
57 | /**
58 | * @return Returns the list of scanned networks
59 | */
60 | public List getNetworks() {
61 | return mNetworks;
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/app/src/main/java/com/find/wifitool/database/Event.java:
--------------------------------------------------------------------------------
1 | package com.find.wifitool.database;
2 |
3 | /**
4 | * Created by akshay on 30/12/16.
5 | */
6 |
7 | public class Event {
8 |
9 | //private variables
10 | private int _id;
11 | private String _wifiName;
12 | private String _wifiGroup;
13 | private String _wifiUser;
14 |
15 | // Empty constructor
16 | public Event(){
17 |
18 | }
19 |
20 | public Event(int id, String wifiName, String wifiGroup, String wifiUser){
21 | this._id = id;
22 | this._wifiName = wifiName;
23 | this._wifiGroup = wifiGroup;
24 | this._wifiUser = wifiUser;
25 | }
26 |
27 | public Event(String wifiName, String wifiGroup, String wifiUser){
28 | this._wifiName = wifiName;
29 | this._wifiGroup = wifiGroup;
30 | this._wifiUser = wifiUser;
31 | }
32 |
33 | // getting ID
34 | public int getID(){
35 | return this._id;
36 | }
37 |
38 | // setting id
39 | public void setID(int id){
40 | this._id = id;
41 | }
42 |
43 | // getting wifiName
44 | public String getWifiName(){
45 | return this._wifiName;
46 | }
47 |
48 | // setting wifiName
49 | public void setWifiName(String wifiName){
50 | this._wifiName = wifiName;
51 | }
52 |
53 | // getting wifiGrp
54 | public String getWifiGroup(){
55 | return this._wifiGroup;
56 | }
57 |
58 | // setting wifiGrp
59 | public void setWifiGroup(String wifiGroup){
60 | this._wifiGroup = wifiGroup;
61 | }
62 |
63 | // getting wifiUser
64 | public String getWifiUser(){
65 | return this._wifiUser;
66 | }
67 |
68 | // setting wifiUser
69 | public void setWifiUser(String wifiUser){
70 | this._wifiUser = wifiUser;
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/app/src/main/java/com/find/wifitool/internal/Utils.java:
--------------------------------------------------------------------------------
1 | package com.find.wifitool.internal;
2 |
3 | import android.content.Context;
4 | import android.location.LocationManager;
5 | import android.net.wifi.WifiManager;
6 |
7 | /**
8 | * Created by akshay on 30/12/16.
9 | */
10 |
11 | public class Utils {
12 |
13 | // empty construtor
14 | private Utils() {
15 |
16 | }
17 |
18 | // Checking if WiFi adapter is ON or OFF
19 | public static boolean isWiFiAvailable(Context context) {
20 | WifiManager wifi = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
21 | if (wifi.isWifiEnabled()) {
22 | return true;
23 | }
24 | else return false;
25 | }
26 |
27 | // Checking Location service status
28 | public static boolean isLocationAvailable(Context context) {
29 | LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
30 | boolean gps_enabled = false;
31 | boolean network_enabled = false;
32 |
33 | try {
34 | gps_enabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
35 | } catch(Exception ex) {}
36 |
37 | try {
38 | network_enabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
39 | } catch(Exception ex) {}
40 |
41 | if(!gps_enabled && !network_enabled)
42 | return false;
43 | else return true;
44 | }
45 |
46 | // Checking if we have location permission or not
47 | public static boolean hasAnyLocationPermission(Context context) {
48 | int fineLocationPermission = context.checkCallingOrSelfPermission("android.permission.ACCESS_FINE_LOCATION");
49 | int coarseLocationPermission = context.checkCallingOrSelfPermission("android.permission.ACCESS_COARSE_LOCATION");
50 | return fineLocationPermission == 0 || coarseLocationPermission == 0;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/app/src/main/java/com/find/wifitool/internal/Constants.java:
--------------------------------------------------------------------------------
1 | package com.find.wifitool.internal;
2 |
3 | /**
4 | * Created by akshay on 30/12/16.
5 | */
6 |
7 | public class Constants {
8 |
9 | private Constants() {
10 | }
11 |
12 | private static final String PACKAGE_NAME = "om.find.wifitool";
13 |
14 | // Shared prefs
15 | public static final String PREFS_NAME = PACKAGE_NAME + "com.find.wifitool.Prefs";
16 | public static final String USER_NAME = PACKAGE_NAME + "user";
17 | public static final String GROUP_NAME = PACKAGE_NAME + "group";
18 | public static final String SERVER_NAME = PACKAGE_NAME + "server";
19 | public static final String LOCATION_NAME = PACKAGE_NAME + "location";
20 | public static final String TRACK_INTERVAL = PACKAGE_NAME + "trackInterval";
21 | public static final String LEARN_INTERVAL = PACKAGE_NAME + "learnInterval";
22 | public static final String LEARN_PERIOD = PACKAGE_NAME + "learnPeriod";
23 | public static final String IS_FIRST_RUN = PACKAGE_NAME + "isFirstRun";
24 |
25 | //Default values
26 | public static final String DEFAULT_USERNAME = "user";
27 | public static final String DEFAULT_GROUP = "group";
28 | public static final String DEFAULT_SERVER = "https://ml.internalpositioning.com/";
29 | public static final String DEFAULT_LOCATION_NAME = "location";
30 | public static final int DEFAULT_TRACKING_INTERVAL = 5;
31 | public static final int DEFAULT_LEARNING_INTERVAL = 5;
32 | public static final int DEFAULT_LEARNING_PERIOD = 3;
33 |
34 | // BRaodcast message tag
35 | public static final String TRACK_BCAST = "com.find.wifitool.track";
36 |
37 | public static final String TRACK_TAG = "track";
38 | public static final String LEARN_TAG = "learn";
39 |
40 | // Web URLs
41 | public static final String FIND_GITHUB_URL = "https://github.com/schollz/find";
42 | public static final String FIND_APP_URL = " https://github.com/uncleashi/find-client-android";
43 | public static final String FIND_WEB_URL = "https://www.internalpositioning.com/";
44 | public static final String FIND_ISSUES_URL = "https://github.com/schollz/find/issues";
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/app/src/main/java/com/find/wifitool/wifi/WifiDataNetwork.java:
--------------------------------------------------------------------------------
1 | package com.find.wifitool.wifi;
2 |
3 | import android.net.wifi.ScanResult;
4 | import android.os.Parcel;
5 | import android.os.Parcelable;
6 |
7 | /**
8 | * Created by akshay on 30/12/16.
9 | */
10 |
11 | public class WifiDataNetwork implements Comparable, Parcelable {
12 |
13 | private static final String TAG = WifiDataNetwork.class.getSimpleName();
14 |
15 | // private variables
16 | private String bssid;
17 | private String ssid;
18 | private String capabilities;
19 | private int frequency;
20 | private int level;
21 | private long timestamp;
22 |
23 | // Constructor
24 | public WifiDataNetwork(ScanResult result) {
25 | bssid = result.BSSID;
26 | ssid = result.SSID;
27 | capabilities = result.capabilities;
28 | frequency = result.frequency;
29 | level = result.level;
30 | timestamp = System.currentTimeMillis();
31 | }
32 |
33 | public WifiDataNetwork(Parcel in) {
34 | bssid = in.readString();
35 | ssid = in.readString();
36 | capabilities = in.readString();
37 | frequency = in.readInt();
38 | level = in.readInt();
39 | timestamp = in.readLong();
40 | }
41 |
42 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
43 | public WifiDataNetwork createFromParcel(Parcel in) {
44 | return new WifiDataNetwork(in);
45 | }
46 |
47 | public WifiDataNetwork[] newArray(int size) {
48 | return new WifiDataNetwork[size];
49 | }
50 | };
51 |
52 | @Override
53 | public int compareTo(WifiDataNetwork another) {
54 | return another.level - this.level;
55 | }
56 |
57 | @Override
58 | public int describeContents() {
59 | return 0;
60 | }
61 |
62 | @Override
63 | public void writeToParcel(Parcel dest, int flags) {
64 | dest.writeString(bssid);
65 | dest.writeString(ssid);
66 | dest.writeString(capabilities);
67 | dest.writeInt(frequency);
68 | dest.writeInt(level);
69 | dest.writeLong(timestamp);
70 | }
71 |
72 | @Override
73 | public String toString() {
74 | return ssid + " addr:" + bssid + " lev:" + level + "dBm freq:" + frequency + "MHz cap:" + capabilities;
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_track.xml:
--------------------------------------------------------------------------------
1 |
2 |
14 |
15 |
26 |
38 |
39 |
54 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/wifi_list_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
15 |
16 |
24 |
25 |
35 |
36 |
45 |
46 |
56 |
57 |
64 |
65 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/app/src/main/java/com/find/wifitool/database/InternalDataBase.java:
--------------------------------------------------------------------------------
1 | package com.find.wifitool.database;
2 |
3 | import android.content.ContentValues;
4 | import android.content.Context;
5 | import android.database.Cursor;
6 | import android.database.sqlite.SQLiteDatabase;
7 | import android.database.sqlite.SQLiteOpenHelper;
8 |
9 | import java.util.ArrayList;
10 | import java.util.List;
11 |
12 | /**
13 | * Created by akshay on 30/12/16.
14 | */
15 |
16 | public class InternalDataBase extends SQLiteOpenHelper {
17 |
18 | // Private variables
19 | private static final String DATABASE_NAME = "WifiDB";
20 | private static final String TABLE_NAME = "Wifi_db";
21 | private static final String COLUMN_ID = "ID";
22 | private static final String COLUMN_NAME = "WIFINAME";
23 | private static final String COLUMN_GROUP = "WIFIGROUP";
24 | private static final String COLUMN_USER = "WIFIUSER";
25 | private static final int DATABASE_VERSION = 1;
26 |
27 | public InternalDataBase(Context context) {
28 | super(context, DATABASE_NAME, null, DATABASE_VERSION);
29 | }
30 |
31 | // Create DB
32 | @Override
33 | public void onCreate(SQLiteDatabase db) {
34 | String sql = "CREATE TABLE " + TABLE_NAME
35 | + "(" + COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
36 | + COLUMN_NAME + " VARCHAR, "
37 | + COLUMN_GROUP + " VARCHAR, "
38 | + COLUMN_USER + " VARCHAR);";
39 |
40 | db.execSQL(sql);
41 | }
42 |
43 | @Override
44 | public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
45 | String sql = "DROP TABLE IF EXISTS" + TABLE_NAME;
46 | db.execSQL(sql);
47 | onCreate(db);
48 | }
49 |
50 | /**
51 | * All CRUD(Create, Read, Update, Delete) Operations
52 | */
53 | // Adding new event
54 | public void addEvent(Event event) {
55 | SQLiteDatabase db = this.getWritableDatabase();
56 |
57 | ContentValues values = new ContentValues();
58 | values.put(COLUMN_NAME, event.getWifiName());
59 | values.put(COLUMN_GROUP, event.getWifiGroup());
60 | values.put(COLUMN_USER, event.getWifiUser());
61 |
62 | db.insert(TABLE_NAME, null, values);
63 | db.close(); // Closing database connection
64 | }
65 |
66 | // Getting all records
67 | public List getAllEvents() {
68 | SQLiteDatabase db = this.getReadableDatabase();
69 | Cursor cursor = db.rawQuery("SELECT * FROM " + TABLE_NAME, null);
70 | List eventList = new ArrayList();
71 |
72 | if (cursor.moveToFirst()) {
73 | do {
74 | Event event = new Event();
75 | event.setID(Integer.parseInt(cursor.getString(0)));
76 | event.setWifiName(cursor.getString(1));
77 | event.setWifiGroup(cursor.getString(2));
78 | event.setWifiUser(cursor.getString(3));
79 | eventList.add(event);
80 | } while (cursor.moveToNext());
81 | }
82 | cursor.close();
83 | return eventList;
84 | }
85 |
86 | // Deleting all records
87 | public void deleteRecords() {
88 | SQLiteDatabase db = this.getWritableDatabase();
89 | db.execSQL("DELETE FROM " + TABLE_NAME);
90 | db.close();
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/app/src/main/java/com/find/wifitool/httpCalls/FindWiFiImpl.java:
--------------------------------------------------------------------------------
1 | package com.find.wifitool.httpCalls;
2 |
3 | import android.content.Context;
4 | import android.os.AsyncTask;
5 | import android.util.Log;
6 |
7 | import com.squareup.okhttp.Callback;
8 | import com.squareup.okhttp.MediaType;
9 | import com.squareup.okhttp.OkHttpClient;
10 | import com.squareup.okhttp.Request;
11 | import com.squareup.okhttp.RequestBody;
12 |
13 | import org.json.JSONObject;
14 |
15 | /**
16 | * Created by akshay on 30/12/16.
17 | */
18 |
19 | public class FindWiFiImpl implements FindWiFi {
20 |
21 | private static final String TAG = FindWiFiImpl.class.getSimpleName();
22 | public static final MediaType MEDIA_TYPE_JSON = MediaType.parse("application/json; charset=utf-8");
23 |
24 | // private variables
25 | private static final int GET = 0;
26 | private static final int PUT = 1;
27 | private static final int POST = 2;
28 | private static final int DELETE = 3;
29 |
30 | private final Context ctx;
31 | private final OkHttpClient httpClient;
32 |
33 | // Constructor
34 | public FindWiFiImpl(Context context) {
35 | this.ctx = context;
36 | this.httpClient = new OkHttpClient();
37 | }
38 |
39 | @Override
40 | public void findTrack(Callback callback, String serverAddr, JSONObject requestBody) {
41 | new AuthTask("track", serverAddr, POST, requestBody.toString(), callback).execute();
42 | }
43 |
44 | @Override
45 | public void findLearn(Callback callback, String serverAddr, JSONObject requestBody) {
46 | new AuthTask("learn", serverAddr, POST, requestBody.toString(), callback).execute();
47 | }
48 |
49 | private class AuthTask extends AsyncTask {
50 | private final String urlPart;
51 | private final int method;
52 | private final String json;
53 | private final String serverAddr;
54 | private final Callback callback;
55 |
56 | AuthTask(String urlPart, String serverAddr, int method, String json, Callback callback) {
57 | this.urlPart = urlPart;
58 | this.serverAddr = serverAddr;
59 | this.method = method;
60 | this.json = json;
61 | this.callback = callback;
62 | }
63 |
64 | @Override
65 | protected Void doInBackground(Void... params) {
66 |
67 | try {
68 | Request.Builder requestBuilder = new Request.Builder()
69 | .url(serverAddr + urlPart);
70 | switch (method) {
71 | case PUT:
72 | requestBuilder.put(RequestBody.create(MEDIA_TYPE_JSON, json));
73 | break;
74 | case POST:
75 | requestBuilder.post(RequestBody.create(MEDIA_TYPE_JSON, json));
76 | break;
77 | case DELETE:
78 | requestBuilder.delete(RequestBody.create(MEDIA_TYPE_JSON, json));
79 | break;
80 | default: break;
81 | }
82 | Request request = requestBuilder.build();
83 | httpClient.newCall(request).enqueue(new HttpCallback(callback));
84 | } catch (Exception e) {
85 | Log.e(TAG, "IOException", e);
86 | }
87 | return null;
88 | }
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # FIND- Indoor Positioning System (Android Client App)
2 |
3 | This client app helps you get started with FIND development. With this app you can easily:
4 |
5 | - "Learn": connect to the server and then submit fingerprints.
6 | - "Track": track what room you are in using just the WiFi networks around you
7 | - more coming soon...
8 | All this using less battery and with higher accuracy indoors than the GPS.
9 |
10 | ----------
11 |
12 | **About FIND**
13 |
14 | The **Framework for Internal Navigation and Discovery (FIND)** allows you to use your (Android) smartphone or WiFi-enabled computer (laptop or Raspberry Pi or etc.) to determine your position within your home or office. You can easily use this system in place of motion sensors as its resolution will allow your phone to distinguish whether you are in the living room, the kitchen or the bedroom, etc. The position information can then be used in a variety of ways including home automation, way-finding, or tracking!
15 | To learn more about it or to run your own private server, check out https://github.com/schollz/find
16 |
17 | ----------
18 | **Requirements**
19 | 1. Android Studio
20 | 2. Android Mobile with WiFi adapter
21 |
22 | **Dependencies**
23 | 1. OkHttp (Async HTTP library)
24 |
25 | If you use Android Studio these dependencies are managed automatically for you. (When you first import the project you'll be asked to sync the relevant modules from the SDK manager.)
26 |
27 | **Getting Started**
28 |
29 | These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
30 |
31 | As usual, you get started by cloning the project to your local machine:
32 | ```
33 | $ git clone git://github.com/uncleashi/find-app-android
34 | ```
35 | **Building and Running**
36 | Import the FindWifiTool app into Android Studio as an existing project and select :
37 | ```Run > Run app ```
38 |
39 | **Default Configuration**
40 | 1. User: user
41 | 2. Group: group
42 | 3. Server: https://ml.internalpositioning.com
43 | 4. Learn Period: : 3 min
44 | 5. Track Interval: 5 sec
45 | 6. Learn Interval: 5 sec
46 |
47 | **Wifi-Fingerprint:**
48 | ```json
49 | {
50 | "group":"some group",
51 | "username":"some user",
52 | "location":"some place",
53 | "time":12309123,
54 | "wifi-fingerprint":
55 | [
56 | {
57 | "mac":"AA:AA:AA:AA:AA:AA",
58 | "rssi":-45
59 | },
60 | {
61 | "mac":"BB:BB:BB:BB:BB:BB",
62 | "rssi":-55
63 | }
64 | ]
65 | }
66 | ```
67 | Above JSON is sent via POST https://ml.internalpositioning.com/learn or POST https://ml.internalpositioning.com/track (or the server set by you ) depending on whether it is *Learning* or *Tracking*.
68 |
69 | ----------
70 | **App Screenshots**
71 |
72 | *Create Activity*
73 |
74 | 
75 |
76 | *Learn Activity*
77 |
78 | 
79 |
80 | *Track Activity*
81 |
82 | 
83 |
84 | *Setting Activity*
85 |
86 | 
87 |
88 | *Nav-Header*
89 |
90 | 
91 |
92 | ----------
93 |
94 | **Authors**
95 |
96 | - Akshay Dekate
97 | - Shailesh Srivastava
98 |
99 | ----------
100 |
101 | **License**
102 |
103 | The code supplied here is covered under the MIT Open Source License:
104 |
105 | Copyright (c) 2016 Akshay Dekate
106 |
107 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
108 |
109 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
110 |
111 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
112 |
113 | ----------
114 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/app/src/main/java/com/find/wifitool/wifi/WifiIntentReceiver.java:
--------------------------------------------------------------------------------
1 | package com.find.wifitool.wifi;
2 |
3 | import android.app.IntentService;
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.net.wifi.ScanResult;
7 | import android.net.wifi.WifiManager;
8 | import android.support.v4.content.LocalBroadcastManager;
9 | import android.util.Log;
10 |
11 | import com.find.wifitool.httpCalls.FindWiFi;
12 | import com.find.wifitool.httpCalls.FindWiFiImpl;
13 | import com.find.wifitool.internal.Constants;
14 | import com.squareup.okhttp.Callback;
15 | import com.squareup.okhttp.Request;
16 | import com.squareup.okhttp.Response;
17 |
18 | import org.json.JSONArray;
19 | import org.json.JSONException;
20 | import org.json.JSONObject;
21 |
22 | import java.io.IOException;
23 | import java.util.Arrays;
24 | import java.util.HashSet;
25 | import java.util.List;
26 | import java.util.Set;
27 |
28 | /**
29 | * Created by akshay on 30/12/16.
30 | */
31 |
32 | public class WifiIntentReceiver extends IntentService {
33 |
34 | private static final String TAG = WifiIntentReceiver.class.getSimpleName();
35 |
36 | // private variables
37 | private WifiManager mWifiManager;
38 | private WifiData mWifiData;
39 | private FindWiFi client;
40 | private String eventName, userName, groupName, serverName, locationName;
41 | private JSONObject wifiFingerprint;
42 | private String currLocation;
43 |
44 | private static final Set AD_HOC_HEX_VALUES =
45 | new HashSet(Arrays.asList('2','6', 'a', 'e', 'A', 'E'));
46 |
47 | /**
48 | * Creates an IntentService. Invoked by your subclass's constructor.
49 | */
50 | public WifiIntentReceiver() {
51 | super(TAG);
52 | }
53 |
54 | @Override
55 | protected void onHandleIntent(Intent intent) {
56 | client = new FindWiFiImpl(getApplicationContext());
57 |
58 | // Getting all the value passed from previous Fragment
59 | eventName = intent.getStringExtra("event");
60 | userName = intent.getStringExtra("userName");
61 | groupName = intent.getStringExtra("groupName");
62 | serverName = intent.getStringExtra("serverName");
63 | locationName = intent.getStringExtra("locationName");
64 | Long timeStamp = System.currentTimeMillis()/1000;
65 |
66 | // getting all wifi APs and forming data payload
67 | try {
68 | mWifiData = new WifiData();
69 | mWifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
70 | JSONArray wifiResultsArray = new JSONArray();
71 | List mResults = mWifiManager.getScanResults();
72 |
73 | for (ScanResult result : mResults) {
74 | JSONObject wifiResults = new JSONObject();
75 | if (shouldLog(result)) {
76 | wifiResults.put("mac", result.BSSID);
77 | wifiResults.put("rssi", result.level);
78 | wifiResultsArray.put(wifiResults);
79 | }
80 | }
81 | wifiFingerprint = new JSONObject();
82 | wifiFingerprint.put("group", groupName);
83 | wifiFingerprint.put("username", userName);
84 | wifiFingerprint.put("location", locationName);
85 | wifiFingerprint.put("time", timeStamp);
86 | wifiFingerprint.put("wifi-fingerprint", wifiResultsArray);
87 | Log.d(TAG, String.valueOf(wifiFingerprint));
88 |
89 | } catch (Exception ex) {
90 | ex.printStackTrace();
91 | }
92 |
93 | // Send the packet to server
94 | sendPayload(eventName, serverName, wifiFingerprint);
95 |
96 | }
97 |
98 | // Function to check to check the route(learn or track) and send data to server
99 | private void sendPayload(String event, String serverName, JSONObject json) {
100 |
101 | if(event.equalsIgnoreCase("track")) {
102 | Callback postTrackEvent = new Callback() {
103 | @Override
104 | public void onFailure(Request request, IOException e) {
105 | Log.e(TAG, "Failed request: " + request, e);
106 | }
107 |
108 | @Override
109 | public void onResponse(Response response) throws IOException {
110 | String body = response.body().string();
111 | if (response.isSuccessful()) {
112 | Log.d(TAG, body);
113 | try {
114 | JSONObject json = new JSONObject(body);
115 | currLocation = json.getString("location");
116 | } catch (JSONException e) {
117 | Log.e(TAG, "Failed to extract location from response: " + body, e);
118 | }
119 | sendCurrentLocation(currLocation);
120 | } else {
121 | Log.e(TAG, "Unsuccessful request: " + body);
122 | }
123 | }
124 | };
125 | client.findTrack(postTrackEvent, serverName, json);
126 |
127 | } else {
128 | Callback postLearnEvent = new Callback() {
129 | @Override
130 | public void onFailure(Request request, IOException e) {
131 | Log.e(TAG, "Failed request: " + request, e);
132 | }
133 |
134 | @Override
135 | public void onResponse(Response response) throws IOException {
136 | String body = response.body().string();
137 | Log.d(TAG, body);
138 | }
139 | };
140 | client.findLearn(postLearnEvent, serverName, json);
141 |
142 | }
143 |
144 | }
145 |
146 | // Broadcasting current location extracted from Response
147 | private void sendCurrentLocation(String location) {
148 | if (location != null && !location.isEmpty()) {
149 | Intent intent = new Intent(Constants.TRACK_BCAST);
150 | intent.putExtra("location", location);
151 | LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(intent);
152 | }
153 | }
154 |
155 | /**
156 | * Returns true if the given scan should be logged, or false if it is an
157 | * ad-hoc AP or if it is an AP that has opted out of Google's collection
158 | * practices.
159 | */
160 | private static boolean shouldLog(final ScanResult sr) {
161 | // Only apply this test if we have exactly 17 character long BSSID which should
162 | // be the case.
163 | final char secondNybble = sr.BSSID.length() == 17 ? sr.BSSID.charAt(1) : ' ';
164 |
165 | if(AD_HOC_HEX_VALUES.contains(secondNybble)) {
166 | return false;
167 | }
168 | else {
169 | return true;
170 | }
171 | }
172 | }
173 |
--------------------------------------------------------------------------------
/app/src/main/java/com/find/wifitool/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.find.wifitool;
2 |
3 | import android.Manifest;
4 | import android.content.Intent;
5 | import android.content.SharedPreferences;
6 | import android.content.pm.PackageManager;
7 | import android.net.Uri;
8 | import android.os.Build;
9 | import android.os.Bundle;
10 | import android.support.design.widget.FloatingActionButton;
11 | import android.support.design.widget.Snackbar;
12 | import android.support.v4.app.ActivityCompat;
13 | import android.support.v4.app.Fragment;
14 | import android.support.v4.app.FragmentManager;
15 | import android.support.v4.content.ContextCompat;
16 | import android.view.View;
17 | import android.support.design.widget.NavigationView;
18 | import android.support.v4.view.GravityCompat;
19 | import android.support.v4.widget.DrawerLayout;
20 | import android.support.v7.app.ActionBarDrawerToggle;
21 | import android.support.v7.app.AppCompatActivity;
22 | import android.support.v7.widget.Toolbar;
23 | import android.view.Menu;
24 | import android.view.MenuItem;
25 | import android.widget.Toast;
26 |
27 | import com.find.wifitool.internal.Constants;
28 |
29 | public class MainActivity extends AppCompatActivity
30 | implements NavigationView.OnNavigationItemSelectedListener, OnFragmentInteractionListener {
31 |
32 | private static final String TAG = MainActivity.class.getSimpleName();
33 |
34 | final private int REQUEST_CODE_ASK_PERMISSIONS = 1234;
35 | private SharedPreferences sharedPreferences;
36 |
37 | @Override
38 | protected void onCreate(Bundle savedInstanceState) {
39 | super.onCreate(savedInstanceState);
40 | setContentView(R.layout.activity_main);
41 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
42 | setSupportActionBar(toolbar);
43 |
44 | DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
45 | ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
46 | this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
47 | drawer.setDrawerListener(toggle);
48 | toggle.syncState();
49 |
50 | NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
51 | navigationView.setNavigationItemSelectedListener(this);
52 |
53 | //Check for Android M runtime permissions
54 | if(Build.VERSION.SDK_INT >= 23) {
55 | if (ContextCompat.checkSelfPermission(this,
56 | Manifest.permission.ACCESS_FINE_LOCATION)
57 | != PackageManager.PERMISSION_GRANTED) {
58 |
59 | if (ActivityCompat.shouldShowRequestPermissionRationale(this,
60 | Manifest.permission.ACCESS_FINE_LOCATION)) {
61 | } else {
62 | ActivityCompat.requestPermissions(this,
63 | new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
64 | REQUEST_CODE_ASK_PERMISSIONS);
65 | }
66 | }
67 | }
68 |
69 | // Calling function to set some default values if its our first run
70 | sharedPreferences = getSharedPreferences(Constants.PREFS_NAME, 0);
71 | setDefaultPrefs();
72 |
73 | // Set the Learn Fragment as default
74 | Fragment fragment = new LearnFragment();
75 | FragmentManager fragmentManager = getSupportFragmentManager();
76 | fragmentManager.beginTransaction()
77 | .replace(R.id.content, fragment)
78 | .commit();
79 | }
80 |
81 | @Override
82 | public void onRequestPermissionsResult(int requestCode,
83 | String permissions[], int[] grantResults) {
84 | switch (requestCode) {
85 | case REQUEST_CODE_ASK_PERMISSIONS: {
86 | // If request is cancelled, the result arrays are empty.
87 | if (grantResults.length > 0
88 | && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
89 |
90 | Toast.makeText(MainActivity.this, "Permission granted, Loading Mission Control!",
91 | Toast.LENGTH_SHORT)
92 | .show();
93 | } else {
94 | // Permission Denied
95 | Toast.makeText(MainActivity.this, "App need FINE LOCATION ACCESS to discover nearby Wifi APs",
96 | Toast.LENGTH_SHORT)
97 | .show();
98 | }
99 | return;
100 | }
101 | }
102 | }
103 |
104 | // Setting default values in case fo 1st run
105 | private void setDefaultPrefs() {
106 | SharedPreferences.Editor editor = sharedPreferences.edit();
107 |
108 | boolean isFirstRun = sharedPreferences.contains(Constants.IS_FIRST_RUN);
109 |
110 | if(isFirstRun == false) {
111 | editor.putString(Constants.USER_NAME, Constants.DEFAULT_USERNAME);
112 | editor.putString(Constants.SERVER_NAME, Constants.DEFAULT_SERVER);
113 | editor.putString(Constants.GROUP_NAME, Constants.DEFAULT_GROUP);
114 | editor.putInt(Constants.TRACK_INTERVAL, Constants.DEFAULT_TRACKING_INTERVAL);
115 | editor.putInt(Constants.LEARN_PERIOD, Constants.DEFAULT_LEARNING_PERIOD);
116 | editor.putInt(Constants.LEARN_INTERVAL, Constants.DEFAULT_LEARNING_INTERVAL);
117 | editor.putBoolean(Constants.IS_FIRST_RUN, false);
118 | editor.apply();
119 | }
120 | }
121 |
122 | @Override
123 | public void onBackPressed() {
124 | DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
125 | if (drawer.isDrawerOpen(GravityCompat.START)) {
126 |
127 | drawer.closeDrawer(GravityCompat.START);
128 | } else {
129 | super.onBackPressed();
130 | }
131 | }
132 |
133 | @Override
134 | public boolean onCreateOptionsMenu(Menu menu) {
135 | // Inflate the menu; this adds items to the action bar if it is present.
136 | getMenuInflater().inflate(R.menu.main, menu);
137 | return true;
138 | }
139 |
140 | @Override
141 | public boolean onOptionsItemSelected(MenuItem item) {
142 | int id = item.getItemId();
143 |
144 | //noinspection SimplifiableIfStatement
145 | if(id == R.id.action_FIND_github) {
146 | Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(Constants.FIND_GITHUB_URL));
147 | startActivity(browserIntent);
148 | } else if(id == R.id.action_app_github) {
149 | Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(Constants.FIND_APP_URL));
150 | startActivity(browserIntent);
151 | } else if(id == R.id.action_issue) {
152 | Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(Constants.FIND_ISSUES_URL));
153 | startActivity(browserIntent);
154 | } else if(id == R.id.action_Find) {
155 | Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(Constants.FIND_WEB_URL));
156 | startActivity(browserIntent);
157 | }
158 |
159 | return super.onOptionsItemSelected(item);
160 | }
161 |
162 | @SuppressWarnings("StatementWithEmptyBody")
163 | @Override
164 | public boolean onNavigationItemSelected(MenuItem item) {
165 | // Handle navigation view item clicks here.
166 | int id = item.getItemId();
167 |
168 | Fragment fragment;
169 | if (id == R.id.nav_settings) {
170 | fragment = new SettingsFragment();
171 | } else if (id == R.id.nav_track) {
172 | fragment = new TrackFragment();
173 | } else {
174 | // Anything else is home
175 | fragment = new LearnFragment();
176 | }
177 |
178 | // Insert the fragment by replacing any existing fragment
179 | FragmentManager fragmentManager = getSupportFragmentManager();
180 | fragmentManager.beginTransaction()
181 | .replace(R.id.content, fragment)
182 | .commit();
183 |
184 | DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
185 | drawer.closeDrawer(GravityCompat.START);
186 | return true;
187 | }
188 |
189 | @Override
190 | public void onFragmentInteraction(Uri uri) {
191 |
192 | }
193 |
194 | @Override
195 | public void onDestroy() {
196 | super.onDestroy();
197 | }
198 | }
199 |
--------------------------------------------------------------------------------
/app/src/main/java/com/find/wifitool/TrackFragment.java:
--------------------------------------------------------------------------------
1 | package com.find.wifitool;
2 |
3 | import android.content.BroadcastReceiver;
4 | import android.content.Context;
5 | import android.content.DialogInterface;
6 | import android.content.Intent;
7 | import android.content.IntentFilter;
8 | import android.content.SharedPreferences;
9 | import android.os.Build;
10 | import android.os.Bundle;
11 | import android.os.Handler;
12 | import android.provider.Settings;
13 | import android.support.v4.app.Fragment;
14 | import android.support.v4.content.LocalBroadcastManager;
15 | import android.support.v7.app.AlertDialog;
16 | import android.util.Log;
17 | import android.view.LayoutInflater;
18 | import android.view.View;
19 | import android.view.ViewGroup;
20 | import android.widget.TextView;
21 | import android.widget.Toast;
22 |
23 | import com.find.wifitool.internal.Constants;
24 | import com.find.wifitool.internal.Utils;
25 | import com.find.wifitool.wifi.WifiIntentReceiver;
26 |
27 | /**
28 | * Created by akshay on 30/12/16.
29 | */
30 |
31 | public class TrackFragment extends Fragment {
32 |
33 | private static final String TAG = TrackFragment.class.getSimpleName();
34 |
35 | // TODO: Rename parameter arguments, choose names that match
36 | // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
37 | private static final String ARG_PARAM1 = "param1";
38 | private static final String ARG_PARAM2 = "param2";
39 | private String mParam1;
40 | private String mParam2;
41 |
42 | //private variables
43 | private OnFragmentInteractionListener mListener;
44 | private Context mContext;
45 | private SharedPreferences sharedPreferences;
46 | private String strUsername;
47 | private String strServer;
48 | private String strGroup;
49 | private String strLocation = null; // We don't need any location value fr Tracking
50 | private int trackVal;
51 |
52 | private TextView currLocView;
53 |
54 | Handler handler = new Handler();
55 |
56 | /**
57 | * Use this factory method to create a new instance of
58 | * this fragment using the provided parameters.
59 | *
60 | * @param param1 Parameter 1.
61 | * @param param2 Parameter 2.
62 | * @return A new instance of fragment SettingsFragment.
63 | */
64 | // TODO: Rename and change types and number of parameters
65 | public static SettingsFragment newInstance(String param1, String param2) {
66 | SettingsFragment fragment = new SettingsFragment();
67 | Bundle args = new Bundle();
68 | args.putString(ARG_PARAM1, param1);
69 | args.putString(ARG_PARAM2, param2);
70 | fragment.setArguments(args);
71 | return fragment;
72 | }
73 |
74 | // Required empty public constructor
75 | public TrackFragment() {
76 | }
77 |
78 | @Override
79 | public void onCreate(Bundle savedInstanceState) {
80 | super.onCreate(savedInstanceState);
81 | if (getArguments() != null) {
82 | mParam1 = getArguments().getString(ARG_PARAM1);
83 | mParam2 = getArguments().getString(ARG_PARAM2);
84 | }
85 |
86 | // Checking if the Location service is enabled in case of Android M or above users
87 | if (!Utils.isLocationAvailable(mContext)) {
88 | AlertDialog.Builder dialog = new AlertDialog.Builder(getActivity());
89 | dialog.setMessage("Location service is not On. Users running Android M and above have to turn on location services for FIND to work properly");
90 | dialog.setPositiveButton("Enable Locations service", new DialogInterface.OnClickListener() {
91 | @Override
92 | public void onClick(DialogInterface paramDialogInterface, int paramInt) {
93 | Intent myIntent = new Intent( Settings.ACTION_LOCATION_SOURCE_SETTINGS);
94 | getActivity().startActivity(myIntent);
95 | }
96 | });
97 | dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
98 |
99 | @Override
100 | public void onClick(DialogInterface paramDialogInterface, int paramInt) {
101 | logMeToast("Thank you!! Getting things in place.");
102 | }
103 | });
104 | dialog.show();
105 | }
106 |
107 | // Getting values from Shared prefs for Tracking
108 | sharedPreferences = getActivity().getSharedPreferences(Constants.PREFS_NAME, 0);
109 | strGroup = sharedPreferences.getString(Constants.GROUP_NAME, Constants.DEFAULT_GROUP);
110 | strUsername = sharedPreferences.getString(Constants.USER_NAME, Constants.DEFAULT_USERNAME);
111 | strServer = sharedPreferences.getString(Constants.SERVER_NAME, Constants.DEFAULT_SERVER);
112 | trackVal = sharedPreferences.getInt(Constants.TRACK_INTERVAL, Constants.DEFAULT_TRACKING_INTERVAL);
113 | }
114 |
115 | @Override
116 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
117 | Bundle savedInstanceState) {
118 |
119 | View rootView = inflater.inflate(R.layout.fragment_track, container, false);
120 | currLocView = (TextView)rootView.findViewById(R.id.labelLocationName);
121 | handler.post(runnableCode);
122 |
123 | // Listener to the broadcast message from WifiIntent
124 | LocalBroadcastManager.getInstance(mContext).registerReceiver(mMessageReceiver,
125 | new IntentFilter(Constants.TRACK_BCAST));
126 |
127 | // Inflate the layout for this fragment
128 | return rootView;
129 | }
130 |
131 | // Getting the CurrentLocation from the received braodcast
132 | private BroadcastReceiver mMessageReceiver = new BroadcastReceiver() {
133 | @Override
134 | public void onReceive(Context context, Intent intent) {
135 | String currLocation = intent.getStringExtra("location");
136 | currLocView.setTextColor(getResources().getColor(R.color.currentLocationColor));
137 | currLocView.setText(currLocation);
138 | }
139 | };
140 |
141 | // Timers to keep track of our Tracking period
142 | private Runnable runnableCode = new Runnable() {
143 | @Override
144 | public void run() {
145 | if (Build.VERSION.SDK_INT >= 23 ) {
146 | if(Utils.isWiFiAvailable(mContext) && Utils.hasAnyLocationPermission(mContext)) {
147 | Intent intent = new Intent(mContext, WifiIntentReceiver.class);
148 | intent.putExtra("event", Constants.TRACK_TAG);
149 | intent.putExtra("groupName", strGroup);
150 | intent.putExtra("userName", strUsername);
151 | intent.putExtra("serverName", strServer);
152 | intent.putExtra("locationName", sharedPreferences.getString(Constants.LOCATION_NAME, ""));
153 | mContext.startService(intent);
154 | }
155 | }
156 | else if (Build.VERSION.SDK_INT < 23) {
157 | if(Utils.isWiFiAvailable(mContext)) {
158 | Intent intent = new Intent(mContext, WifiIntentReceiver.class);
159 | intent.putExtra("groupName", strGroup);
160 | intent.putExtra("userName", strUsername);
161 | intent.putExtra("serverName", strServer);
162 | intent.putExtra("locationName", sharedPreferences.getString(Constants.LOCATION_NAME, ""));
163 | mContext.startService(intent);
164 | }
165 | }
166 | else {
167 | return;
168 | }
169 | handler.postDelayed(runnableCode, trackVal * 1000);
170 | }
171 | };
172 |
173 | @Override
174 | public void onAttach(Context context) {
175 | super.onAttach(context);
176 | mContext = context;
177 | try {
178 | mListener = (OnFragmentInteractionListener) context;
179 | } catch (ClassCastException e) {
180 | throw new ClassCastException(context.toString()
181 | + " must implement OnFragmentInteractionListener");
182 | }
183 | }
184 |
185 | @Override
186 | public void onDetach() {
187 | super.onDetach();
188 | handler.removeCallbacks(runnableCode);
189 | LocalBroadcastManager.getInstance(mContext).unregisterReceiver(mMessageReceiver);
190 | mListener = null;
191 | }
192 |
193 | // Logging message in form of Toasts
194 | private void logMeToast(String message) {
195 | Log.d(TAG, message);
196 | toast(message);
197 | }
198 |
199 | private void toast(String s) {
200 | Toast.makeText(getActivity(), s, Toast.LENGTH_LONG).show();
201 | }
202 | }
203 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
17 |
18 |
27 |
28 |
38 |
39 |
46 |
47 |
58 |
59 |
69 |
70 |
77 |
78 |
89 |
90 |
100 |
101 |
108 |
109 |
110 |
120 |
121 |
131 |
132 |
141 |
142 |
151 |
152 |
159 |
160 |
171 |
172 |
182 |
183 |
192 |
193 |
202 |
203 |
210 |
211 |
222 |
223 |
233 |
234 |
243 |
244 |
254 |
255 |
263 |
264 |
265 |
--------------------------------------------------------------------------------
/app/src/main/java/com/find/wifitool/LearnFragment.java:
--------------------------------------------------------------------------------
1 | package com.find.wifitool;
2 |
3 | import android.app.AlertDialog;
4 | import android.app.ProgressDialog;
5 | import android.content.Context;
6 | import android.content.DialogInterface;
7 | import android.content.Intent;
8 | import android.content.SharedPreferences;
9 | import android.os.Build;
10 | import android.os.Bundle;
11 | import android.os.Handler;
12 | import android.provider.Settings;
13 | import android.support.design.widget.FloatingActionButton;
14 | import android.support.design.widget.Snackbar;
15 | import android.support.v4.app.Fragment;
16 | import android.util.Log;
17 | import android.view.LayoutInflater;
18 | import android.view.View;
19 | import android.view.ViewGroup;
20 | import android.widget.AdapterView;
21 | import android.widget.EditText;
22 | import android.widget.ListView;
23 | import android.widget.Toast;
24 |
25 | import com.find.wifitool.OnFragmentInteractionListener;
26 | import com.find.wifitool.database.Event;
27 | import com.find.wifitool.database.InternalDataBase;
28 | import com.find.wifitool.internal.Constants;
29 | import com.find.wifitool.internal.Utils;
30 | import com.find.wifitool.wifi.WifiArrayAdapter;
31 | import com.find.wifitool.wifi.WifiIntentReceiver;
32 | import com.find.wifitool.wifi.WifiObject;
33 |
34 | import java.util.ArrayList;
35 | import java.util.List;
36 |
37 | /**
38 | * Created by akshay on 30/12/16.
39 | */
40 |
41 | public class LearnFragment extends Fragment {
42 |
43 | private static final String TAG = LearnFragment.class.getSimpleName();
44 |
45 | // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
46 | private static final String ARG_PARAM1 = "param1";
47 | private static final String ARG_PARAM2 = "param2";
48 | private String mParam1;
49 | private String mParam2;
50 |
51 | //private variables
52 | private Context mContext = getActivity();
53 | private OnFragmentInteractionListener mListener;
54 | Handler handler = new Handler();
55 |
56 | private SharedPreferences sharedPreferences;
57 | private String strUsername;
58 | private String strServer;
59 | private String strGroup;
60 | private int learnIntervalVal;
61 | private int learnPeriodVal;
62 |
63 | private ArrayList arrayList;
64 | private WifiArrayAdapter wifiArrayAdapter;
65 |
66 | /**
67 | * Use this factory method to create a new instance of
68 | * this fragment using the provided parameters.
69 | *
70 | * @param param1 Parameter 1.
71 | * @param param2 Parameter 2.
72 | * @return A new instance of fragment HomeFragment.
73 | */
74 | // TODO: Rename and change types and number of parameters
75 | public static LearnFragment newInstance(String param1, String param2) {
76 | LearnFragment fragment = new LearnFragment();
77 | Bundle args = new Bundle();
78 | args.putString(ARG_PARAM1, param1);
79 | args.putString(ARG_PARAM2, param2);
80 | fragment.setArguments(args);
81 | return fragment;
82 | }
83 |
84 | // Required empty public constructor
85 | public LearnFragment() {
86 | }
87 |
88 | @Override
89 | public void onCreate(Bundle savedInstanceState) {
90 | super.onCreate(savedInstanceState);
91 | if (getArguments() != null) {
92 | mParam1 = getArguments().getString(ARG_PARAM1);
93 | mParam2 = getArguments().getString(ARG_PARAM2);
94 | }
95 |
96 | // Checking if the Location service is enabled in case of Android M or above users
97 | if (!Utils.isLocationAvailable(mContext)) {
98 | // notify user
99 | android.support.v7.app.AlertDialog.Builder dialog = new android.support.v7.app.AlertDialog.Builder(getActivity());
100 | dialog.setMessage("Location service is not On. Users running Android M and above have to turn on location services for FIND to work properly");
101 | dialog.setPositiveButton("Enable Locations service", new DialogInterface.OnClickListener() {
102 | @Override
103 | public void onClick(DialogInterface paramDialogInterface, int paramInt) {
104 | Intent myIntent = new Intent( Settings.ACTION_LOCATION_SOURCE_SETTINGS);
105 | getActivity().startActivity(myIntent);
106 | }
107 | });
108 | dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
109 |
110 | @Override
111 | public void onClick(DialogInterface paramDialogInterface, int paramInt) {
112 | logMeToast("Thank you!! Getting things in place.");
113 | }
114 | });
115 | dialog.show();
116 | }
117 |
118 | // Creating WiFi list adapter
119 | arrayList = new ArrayList<>();
120 | wifiArrayAdapter = new WifiArrayAdapter(getActivity(), R.layout.wifi_list_item, arrayList);
121 |
122 | // Getting values from Shared prefs for Learning
123 | sharedPreferences = getActivity().getSharedPreferences(Constants.PREFS_NAME, 0);
124 | strGroup = sharedPreferences.getString(Constants.GROUP_NAME, Constants.DEFAULT_GROUP);
125 | strUsername = sharedPreferences.getString(Constants.USER_NAME, Constants.DEFAULT_USERNAME);
126 | strServer = sharedPreferences.getString(Constants.SERVER_NAME, Constants.DEFAULT_SERVER);
127 | learnIntervalVal = sharedPreferences.getInt(Constants.LEARN_INTERVAL, Constants.DEFAULT_LEARNING_INTERVAL);
128 | learnPeriodVal = sharedPreferences.getInt(Constants.LEARN_PERIOD, Constants.DEFAULT_LEARNING_PERIOD);
129 |
130 | // Initialising internal DB n retriving values from it to fill our listView
131 | final InternalDataBase internalDataBase = new InternalDataBase(getActivity());
132 |
133 | List eventList = internalDataBase.getAllEvents();
134 | for(Event event : eventList) {
135 | WifiObject wifi = new WifiObject(event.getWifiName(), event.getWifiGroup(), event.getWifiUser());
136 | wifiArrayAdapter.add(wifi);
137 | }
138 |
139 | }
140 |
141 | @Override
142 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
143 | Bundle savedInstanceState) {
144 | View rootView = inflater.inflate(R.layout.fragment_learn, container, false);
145 |
146 | // Listening to Fab button click
147 | FloatingActionButton fab = (FloatingActionButton)rootView.findViewById(R.id.fab);
148 | fab.setOnClickListener(new View.OnClickListener() {
149 | @Override
150 | public void onClick(View view) {
151 | AlertDialog.Builder builder =
152 | new AlertDialog.Builder(getActivity()).setTitle("Add location");
153 | final EditText editText = new EditText(getActivity());
154 | editText.setHintTextColor(getResources().getColor(R.color.hintTextColor));
155 | editText.setHint(Constants.DEFAULT_LOCATION_NAME);
156 | builder.setView(editText);
157 | builder.setPositiveButton("Add", new DialogInterface.OnClickListener() {
158 | @Override
159 | public void onClick(DialogInterface dialog, int which) {
160 | String strLocationName = editText.getText().toString();
161 | InternalDataBase internalDataBase = new InternalDataBase(getActivity());
162 | SharedPreferences.Editor editor = sharedPreferences.edit();
163 | editor.putString(Constants.LOCATION_NAME, strLocationName);
164 | editor.apply();
165 | dialog.dismiss();
166 | WifiObject wifi = new WifiObject(strLocationName, strGroup , strUsername);
167 | insertIntoList(wifi);
168 | internalDataBase.addEvent(new Event(strLocationName, strGroup, strUsername));
169 | handler.post(runnableCode);
170 | }
171 | });
172 | builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
173 | @Override
174 | public void onClick(DialogInterface dialog, int which) {
175 | dialog.dismiss();
176 | }
177 | });
178 | builder.show();
179 |
180 | Snackbar.make(view, "Add unique location name", Snackbar.LENGTH_LONG)
181 | .setAction("Action", null).show();
182 | }
183 | });
184 |
185 | ListView listView = (ListView)rootView.findViewById(R.id.listView);
186 | listView.setAdapter(wifiArrayAdapter);
187 | listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
188 | @Override
189 | public void onItemClick(AdapterView> parent, View view, int position, long id) {
190 | //TODO: Add your custom Fragment here
191 | }
192 | });
193 |
194 | return rootView;
195 | }
196 |
197 | // Insert new location into listView
198 | private void insertIntoList(WifiObject wifi) {
199 | wifiArrayAdapter.add(wifi);
200 |
201 | final ProgressDialog progress = new ProgressDialog(getActivity());
202 | progress.setTitle("Learning");
203 | progress.setMessage("Please wait while we are collecting the Wifi APs around you...");
204 | progress.setCanceledOnTouchOutside(false);
205 | progress.show();
206 |
207 | Runnable progressRunnable = new Runnable() {
208 | @Override
209 | public void run() {
210 | progress.cancel();
211 | handler.removeCallbacks(runnableCode);
212 | }
213 | };
214 | Handler pdCanceller = new Handler();
215 | pdCanceller.postDelayed(progressRunnable, learnPeriodVal * 60 * 1000);
216 | }
217 |
218 | // Timers to keep track of our Learning period
219 | private Runnable runnableCode = new Runnable() {
220 | @Override
221 | public void run() {
222 | // Passing values to WifiIntent for further processing
223 | if (Build.VERSION.SDK_INT >= 23 ) {
224 | if(Utils.isWiFiAvailable(mContext) && Utils.hasAnyLocationPermission(mContext)) {
225 | Intent intent = new Intent(mContext, WifiIntentReceiver.class);
226 | intent.putExtra("event", Constants.LEARN_TAG);
227 | intent.putExtra("groupName", strGroup);
228 | intent.putExtra("userName", strUsername);
229 | intent.putExtra("serverName", strServer);
230 | intent.putExtra("locationName", sharedPreferences.getString(Constants.LOCATION_NAME, ""));
231 | mContext.startService(intent);
232 | }
233 | }
234 | else if (Build.VERSION.SDK_INT < 23) {
235 | if(Utils.isWiFiAvailable(mContext)) {
236 | Intent intent = new Intent(mContext, WifiIntentReceiver.class);
237 | intent.putExtra("event", Constants.LEARN_TAG);
238 | intent.putExtra("groupName", strGroup);
239 | intent.putExtra("userName", strUsername);
240 | intent.putExtra("serverName", strServer);
241 | intent.putExtra("locationName", sharedPreferences.getString(Constants.LOCATION_NAME, ""));
242 | mContext.startService(intent);
243 | }
244 | }
245 | else {
246 | return;
247 | }
248 | handler.postDelayed(runnableCode, learnIntervalVal * 1000);
249 | }
250 | };
251 |
252 | @Override
253 | public void onViewCreated(View view, Bundle savedInstanceState) {
254 | super.onViewCreated(view, savedInstanceState);
255 | }
256 |
257 | @Override
258 | public void onAttach(Context context) {
259 | super.onAttach(context);
260 | mContext = context;
261 | try {
262 | mListener = (OnFragmentInteractionListener) context;
263 | } catch (ClassCastException e) {
264 | throw new ClassCastException(context.toString()
265 | + " must implement OnFragmentInteractionListener");
266 | }
267 | }
268 |
269 | @Override
270 | public void onResume() {
271 | super.onResume();
272 | }
273 |
274 | @Override
275 | public void onDetach() {
276 | super.onDetach();
277 | handler.removeCallbacks(runnableCode);
278 | mListener = null;
279 | }
280 |
281 | // Logging message in form of Toasts
282 | private void logMeToast(String message) {
283 | Log.e(TAG, message);
284 | toast(message);
285 | }
286 |
287 | private void toast(String s) {
288 | Toast.makeText(getActivity(), s, Toast.LENGTH_LONG).show();
289 | }
290 | }
291 |
--------------------------------------------------------------------------------
/app/src/main/java/com/find/wifitool/SettingsFragment.java:
--------------------------------------------------------------------------------
1 | package com.find.wifitool;
2 |
3 | import android.app.AlertDialog;
4 | import android.content.Context;
5 | import android.content.DialogInterface;
6 | import android.content.SharedPreferences;
7 | import android.net.Uri;
8 | import android.os.Bundle;
9 | import android.support.v4.app.Fragment;
10 | import android.view.LayoutInflater;
11 | import android.view.View;
12 | import android.view.ViewGroup;
13 | import android.widget.EditText;
14 | import android.widget.NumberPicker;
15 | import android.widget.TextView;
16 |
17 | import com.find.wifitool.internal.Constants;
18 |
19 | /**
20 | * Created by akshay on 30/12/16.
21 | */
22 |
23 | public class SettingsFragment extends Fragment {
24 |
25 | private static final String TAG = SettingsFragment.class.getSimpleName();
26 |
27 | // TODO: Rename parameter arguments, choose names that match
28 | // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
29 | private static final String ARG_PARAM1 = "param1";
30 | private static final String ARG_PARAM2 = "param2";
31 | private String mParam1;
32 | private String mParam2;
33 | private OnFragmentInteractionListener mListener;
34 |
35 | //private variables
36 | private TextView labelUserName;
37 | private TextView labelGroupName;
38 | private TextView labelServerName;
39 | private TextView learnInterval;
40 | private TextView trackInterval;
41 | private TextView learnPeriod;
42 | private TextView labelLearnInterval;
43 | private TextView labelTrackInterval;
44 | private TextView labelLearnPeriod;
45 |
46 | private SharedPreferences sharedPreferences;
47 | private String prefUsername;
48 | private String prefServerName;
49 | private String prefGroupName;
50 | private int prefTrackInterval;
51 | private int prefLearnInterval;
52 | private int prefLearnPeriod;
53 |
54 |
55 | /**
56 | * Use this factory method to create a new instance of
57 | * this fragment using the provided parameters.
58 | *
59 | * @param param1 Parameter 1.
60 | * @param param2 Parameter 2.
61 | * @return A new instance of fragment SettingsFragment.
62 | */
63 | // TODO: Rename and change types and number of parameters
64 | public static SettingsFragment newInstance(String param1, String param2) {
65 | SettingsFragment fragment = new SettingsFragment();
66 | Bundle args = new Bundle();
67 | args.putString(ARG_PARAM1, param1);
68 | args.putString(ARG_PARAM2, param2);
69 | fragment.setArguments(args);
70 | return fragment;
71 | }
72 |
73 | // Required empty public constructor
74 | public SettingsFragment() {
75 | }
76 |
77 | @Override
78 | public void onCreate(Bundle savedInstanceState) {
79 | super.onCreate(savedInstanceState);
80 | if (getArguments() != null) {
81 | mParam1 = getArguments().getString(ARG_PARAM1);
82 | mParam2 = getArguments().getString(ARG_PARAM2);
83 | }
84 |
85 | sharedPreferences = getActivity().getSharedPreferences(Constants.PREFS_NAME, 0);
86 | prefUsername = sharedPreferences.getString(Constants.USER_NAME, Constants.DEFAULT_USERNAME);
87 | prefServerName = sharedPreferences.getString(Constants.SERVER_NAME, Constants.DEFAULT_SERVER);
88 | prefGroupName = sharedPreferences.getString(Constants.GROUP_NAME, Constants.DEFAULT_GROUP);
89 | prefTrackInterval = sharedPreferences.getInt(Constants.TRACK_INTERVAL, Constants.DEFAULT_TRACKING_INTERVAL);
90 | prefLearnInterval = sharedPreferences.getInt(Constants.LEARN_INTERVAL, Constants.DEFAULT_LEARNING_INTERVAL);
91 | prefLearnPeriod = sharedPreferences.getInt(Constants.LEARN_PERIOD, Constants.DEFAULT_LEARNING_PERIOD);
92 |
93 | }
94 |
95 | @Override
96 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
97 | Bundle savedInstanceState) {
98 |
99 | View rootView = inflater.inflate(R.layout.fragment_settings, container, false);
100 |
101 | // Getting all the UI components
102 | labelUserName = (TextView)rootView.findViewById(R.id.fieldUserName);
103 | labelGroupName = (TextView)rootView.findViewById(R.id.fieldGroupName);
104 | labelServerName = (TextView)rootView.findViewById(R.id.fieldServerName);
105 | labelLearnInterval = (TextView)rootView.findViewById(R.id.labelLearnInterval);
106 | labelTrackInterval = (TextView)rootView.findViewById(R.id.labelTrackInterval);
107 | labelLearnPeriod = (TextView)rootView.findViewById(R.id.labelLearnPeriod);
108 | learnInterval = (TextView)rootView.findViewById(R.id.fieldLearnInterval);
109 | learnPeriod = (TextView)rootView.findViewById(R.id.fieldLearnPeriod);
110 | trackInterval = (TextView)rootView.findViewById(R.id.fieldTrackInterval);
111 |
112 | // Rendering the setting page
113 | drawUi();
114 |
115 | // UserName click listener
116 | labelUserName.setOnClickListener(new View.OnClickListener() {
117 | @Override
118 | public void onClick(View v) {
119 | AlertDialog.Builder builder =
120 | new AlertDialog.Builder(getActivity()).setTitle("Edit User name");
121 | final EditText editText = new EditText(getActivity());
122 | editText.setText(labelUserName.getText());
123 | builder.setView(editText);
124 | builder.setPositiveButton("Save", new DialogInterface.OnClickListener() {
125 | @Override
126 | public void onClick(DialogInterface dialog, int which) {
127 | String strUserName = editText.getText().toString();
128 | SharedPreferences.Editor editor = sharedPreferences.edit();
129 | editor.putString(Constants.USER_NAME, strUserName);
130 | labelUserName.setText(strUserName);
131 | editor.apply();
132 | dialog.dismiss();
133 | }
134 | });
135 | builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
136 | @Override
137 | public void onClick(DialogInterface dialog, int which) {
138 | dialog.dismiss();
139 | }
140 | });
141 | builder.show();
142 | }
143 | });
144 |
145 | // GroupName click listener
146 | labelGroupName.setOnClickListener(new View.OnClickListener() {
147 | @Override
148 | public void onClick(View v) {
149 | AlertDialog.Builder builder =
150 | new AlertDialog.Builder(getActivity()).setTitle("Edit Group name");
151 | final EditText editText = new EditText(getActivity());
152 | editText.setText(labelGroupName.getText());
153 | builder.setView(editText);
154 | builder.setPositiveButton("Save", new DialogInterface.OnClickListener() {
155 | @Override
156 | public void onClick(DialogInterface dialog, int which) {
157 | String strGrpName = editText.getText().toString();
158 | SharedPreferences.Editor editor = sharedPreferences.edit();
159 | editor.putString(Constants.GROUP_NAME, strGrpName);
160 | labelGroupName.setText(strGrpName);
161 | editor.apply();
162 | dialog.dismiss();
163 | }
164 | });
165 | builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
166 | @Override
167 | public void onClick(DialogInterface dialog, int which) {
168 | dialog.dismiss();
169 | }
170 | });
171 | builder.show();
172 | }
173 | });
174 |
175 | // ServerName click listener
176 | labelServerName.setOnClickListener(new View.OnClickListener() {
177 | @Override
178 | public void onClick(View v) {
179 | AlertDialog.Builder builder =
180 | new AlertDialog.Builder(getActivity()).setTitle("Edit Server address");
181 | final EditText editText = new EditText(getActivity());
182 | editText.setText(labelServerName.getText());
183 | builder.setView(editText);
184 | builder.setPositiveButton("Save", new DialogInterface.OnClickListener() {
185 | @Override
186 | public void onClick(DialogInterface dialog, int which) {
187 | String strServerName = editText.getText().toString();
188 | SharedPreferences.Editor editor = sharedPreferences.edit();
189 | editor.putString(Constants.SERVER_NAME, strServerName);
190 | labelServerName.setText(strServerName);
191 | editor.apply();
192 | dialog.dismiss();
193 | }
194 | });
195 | builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
196 | @Override
197 | public void onClick(DialogInterface dialog, int which) {
198 | dialog.dismiss();
199 | }
200 | });
201 | builder.show();
202 | }
203 | });
204 |
205 | // Learning Interval click listener
206 | labelLearnInterval.setOnClickListener(new View.OnClickListener() {
207 | @Override
208 | public void onClick(View v) {
209 | AlertDialog.Builder builder =
210 | new AlertDialog.Builder(getActivity()).setTitle("Edit Learning Period");
211 |
212 | final NumberPicker numberPicker = new NumberPicker(getActivity());
213 | builder.setView(numberPicker);
214 | String[] nums = new String[11];
215 | for(int i = 0; i < nums.length; i++)
216 | nums[i] = Integer.toString(i);
217 |
218 | numberPicker.setMinValue(0);
219 | numberPicker.setMaxValue(nums.length-1);
220 | numberPicker.setWrapSelectorWheel(false);
221 | numberPicker.setDisplayedValues(nums);
222 | numberPicker.setValue(5);
223 |
224 | builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
225 | public void onClick(DialogInterface dialog, int whichButton) {
226 | int learnIntervalVal = numberPicker.getValue();
227 | SharedPreferences.Editor editor = sharedPreferences.edit();
228 | editor.putInt(Constants.LEARN_INTERVAL, learnIntervalVal);
229 | learnInterval.setText(String.valueOf(learnIntervalVal));
230 | editor.apply();
231 | dialog.dismiss();
232 | }
233 | });
234 |
235 | builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
236 | public void onClick(DialogInterface dialog, int whichButton) {
237 | dialog.dismiss();
238 | }
239 | });
240 | builder.show();
241 | }
242 | });
243 |
244 | // Learn Period click listener
245 | labelLearnPeriod.setOnClickListener(new View.OnClickListener() {
246 | @Override
247 | public void onClick(View v) {
248 | AlertDialog.Builder builder =
249 | new AlertDialog.Builder(getActivity()).setTitle("Edit Learning Peri");
250 |
251 | final NumberPicker numberPicker = new NumberPicker(getActivity());
252 | builder.setView(numberPicker);
253 | String[] nums = new String[11];
254 | for(int i = 0; i < nums.length; i++)
255 | nums[i] = Integer.toString(i);
256 |
257 | numberPicker.setMinValue(0);
258 | numberPicker.setMaxValue(nums.length-1);
259 | numberPicker.setWrapSelectorWheel(false);
260 | numberPicker.setDisplayedValues(nums);
261 | numberPicker.setValue(5);
262 |
263 | builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
264 | public void onClick(DialogInterface dialog, int whichButton) {
265 | int learnPeriodlVal = numberPicker.getValue();
266 | SharedPreferences.Editor editor = sharedPreferences.edit();
267 | editor.putInt(Constants.LEARN_PERIOD, learnPeriodlVal);
268 | learnPeriod.setText(String.valueOf(learnPeriodlVal));
269 | editor.apply();
270 | dialog.dismiss();
271 | }
272 | });
273 |
274 | builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
275 | public void onClick(DialogInterface dialog, int whichButton) {
276 | dialog.dismiss();
277 | }
278 | });
279 | builder.show();
280 | }
281 | });
282 |
283 | // Track Interval click listener
284 | labelTrackInterval.setOnClickListener(new View.OnClickListener() {
285 | @Override
286 | public void onClick(View v) {
287 | AlertDialog.Builder builder =
288 | new AlertDialog.Builder(getActivity()).setTitle("Edit Tracking Period");
289 |
290 | final NumberPicker numberPicker = new NumberPicker(getActivity());
291 | builder.setView(numberPicker);
292 | String[] nums = new String[16];
293 | for(int i = 0; i < nums.length; i++)
294 | nums[i] = Integer.toString(i);
295 |
296 | numberPicker.setMinValue(0);
297 | numberPicker.setMaxValue(nums.length-1);
298 | numberPicker.setWrapSelectorWheel(false);
299 | numberPicker.setDisplayedValues(nums);
300 | numberPicker.setValue(5);
301 |
302 | builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
303 | public void onClick(DialogInterface dialog, int whichButton) {
304 | int trackIntervalVal = numberPicker.getValue();
305 | SharedPreferences.Editor editor = sharedPreferences.edit();
306 | editor.putInt(Constants.TRACK_INTERVAL, trackIntervalVal);
307 | trackInterval.setText(String.valueOf(trackIntervalVal));
308 | editor.apply();
309 | dialog.dismiss();
310 | }
311 | });
312 |
313 | builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
314 | public void onClick(DialogInterface dialog, int whichButton) {
315 | dialog.dismiss();
316 | }
317 | });
318 | builder.show();
319 | }
320 | });
321 |
322 | return rootView;
323 | }
324 |
325 | public void onButtonPressed(Uri uri) {
326 | if (mListener != null) {
327 | mListener.onFragmentInteraction(uri);
328 | }
329 | }
330 |
331 | // Draw setting page UI
332 | private void drawUi() {
333 | // User name
334 | if(prefUsername != null && !prefUsername.isEmpty()) {
335 | labelUserName.setText(prefUsername);
336 |
337 | } else {
338 | labelUserName.setText(Constants.DEFAULT_USERNAME);
339 | }
340 |
341 | // Group name
342 | if(prefGroupName != null && !prefGroupName.isEmpty()) {
343 | labelGroupName.setText(prefGroupName);
344 | } else {
345 | labelGroupName.setText(Constants.DEFAULT_GROUP);
346 | }
347 |
348 | // Server name
349 | if(prefServerName != null && !prefServerName.isEmpty()) {
350 | labelServerName.setText(prefServerName);
351 | } else {
352 | labelServerName.setText(Constants.DEFAULT_SERVER);
353 | }
354 |
355 | // Track Interval
356 | trackInterval.setText(String.valueOf(prefTrackInterval));
357 |
358 | // Learn Interval
359 | learnInterval.setText(String.valueOf(prefLearnInterval));
360 |
361 | // Learn period
362 | learnPeriod.setText(String.valueOf(prefLearnPeriod));
363 |
364 | }
365 |
366 | @Override
367 | public void onAttach(Context context) {
368 | super.onAttach(context);
369 | try {
370 | mListener = (OnFragmentInteractionListener) context;
371 | } catch (ClassCastException e) {
372 | throw new ClassCastException(context.toString()
373 | + " must implement OnFragmentInteractionListener");
374 | }
375 | }
376 |
377 | @Override
378 | public void onDetach() {
379 | super.onDetach();
380 | mListener = null;
381 | }
382 | }
383 |
--------------------------------------------------------------------------------