Skip to content

Commit fde5c25

Browse files
committed
fixed connection opening and added fragments boilerplate code
1 parent 8a4343f commit fde5c25

11 files changed

+121
-25
lines changed

Diff for: app/build.gradle

+5-6
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,16 @@ android {
2121

2222
dependencies {
2323
compile fileTree(include: ['*.jar'], dir: 'libs')
24-
/*
25-
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
26-
exclude group: 'com.android.support', module: 'support-annotations'
27-
})
28-
*/
24+
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
25+
exclude group: 'com.android.support', module: 'support-annotations'
26+
})
27+
2928
compile 'com.android.support:appcompat-v7:25.2.0'
3029
compile 'com.android.support.constraint:constraint-layout:1.0.0-beta5'
3130
compile 'com.github.PhilJay:MPAndroidChart:v3.0.1'
3231
compile 'com.android.support:design:25.2.0'
3332
compile 'com.android.support:support-v4:25.2.0'
3433
compile 'com.github.bumptech.glide:glide:3.7.0'
3534
compile 'de.hdodenhof:circleimageview:2.1.0'
36-
//testCompile 'junit:junit:4.12'
35+
testCompile 'junit:junit:4.12'
3736
}

Diff for: app/src/main/AndroidManifest.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="com.viveksb007.pslab">
44

5-
<uses-feature android:name="android.hardware.usb.host" />
5+
<uses-feature android:name="android.hardware.usb.host"/>
6+
67

78
<application
89
android:allowBackup="true"

Diff for: app/src/main/java/com/viveksb007/pslab/activity/MainActivity.java

+14-18
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,19 @@ protected void onCreate(Bundle savedInstanceState) {
7474
device_found = mCommunicationHandler.device_found;
7575
if (device_found) {
7676
Log.d(TAG, "PSLab device found");
77+
try {
78+
mCommunicationHandler.open();
79+
connected = mCommunicationHandler.isConnected();
80+
if (connected) {
81+
Log.d(TAG, "Connection established");
82+
}
83+
} catch (IOException e) {
84+
e.printStackTrace();
85+
Log.e(TAG, "Error in establishing connection");
86+
}
7787
} else {
7888
Log.d(TAG, "PSLab device not found");
7989
}
80-
try {
81-
mCommunicationHandler.open();
82-
connected = mCommunicationHandler.isConnected();
83-
if (connected) {
84-
Log.d(TAG, "Connection established");
85-
}
86-
} catch (IOException e) {
87-
e.printStackTrace();
88-
Log.e(TAG, "Error in establishing connection");
89-
}
9090

9191
toolbar = (Toolbar) findViewById(R.id.toolbar);
9292
setSupportActionBar(toolbar);
@@ -142,17 +142,13 @@ private Fragment getHomeFragment() {
142142
case 0:
143143
return HomeFragment.newInstance(connected, device_found);
144144
case 1:
145-
ApplicationsFragment applicationsFragment = new ApplicationsFragment();
146-
return applicationsFragment;
145+
return ApplicationsFragment.newInstance();
147146
case 2:
148-
SavedExperiments savedExperiments = new SavedExperiments();
149-
return savedExperiments;
147+
return SavedExperiments.newInstance();
150148
case 3:
151-
DesignExperiments designExperiments = new DesignExperiments();
152-
return designExperiments;
149+
return DesignExperiments.newInstance();
153150
case 4:
154-
SettingsFragment settingsFragment = new SettingsFragment();
155-
return settingsFragment;
151+
return SettingsFragment.newInstance();
156152
default:
157153
return HomeFragment.newInstance(connected, device_found);
158154
}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,29 @@
11
package com.viveksb007.pslab.fragment;
22

3+
import android.os.Bundle;
4+
import android.support.annotation.Nullable;
35
import android.support.v4.app.Fragment;
6+
import android.view.LayoutInflater;
7+
import android.view.View;
8+
import android.view.ViewGroup;
9+
10+
import com.viveksb007.pslab.R;
411

512
/**
613
* Created by viveksb007 on 29/3/17.
714
*/
815

916
public class ApplicationsFragment extends Fragment {
17+
18+
public static ApplicationsFragment newInstance() {
19+
ApplicationsFragment applicationsFragment = new ApplicationsFragment();
20+
return applicationsFragment;
21+
}
22+
23+
@Nullable
24+
@Override
25+
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
26+
View view = inflater.inflate(R.layout.applications_fragment, container, false);
27+
return view;
28+
}
1029
}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,29 @@
11
package com.viveksb007.pslab.fragment;
22

3+
import android.os.Bundle;
4+
import android.support.annotation.Nullable;
35
import android.support.v4.app.Fragment;
6+
import android.view.LayoutInflater;
7+
import android.view.View;
8+
import android.view.ViewGroup;
9+
10+
import com.viveksb007.pslab.R;
411

512
/**
613
* Created by viveksb007 on 15/3/17.
714
*/
815

916
public class DesignExperiments extends Fragment {
17+
18+
public static DesignExperiments newInstance() {
19+
DesignExperiments designExperiments = new DesignExperiments();
20+
return designExperiments;
21+
}
22+
23+
@Nullable
24+
@Override
25+
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
26+
View view = inflater.inflate(R.layout.design_experiments_fragment, container, false);
27+
return view;
28+
}
1029
}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,29 @@
11
package com.viveksb007.pslab.fragment;
22

3+
import android.os.Bundle;
4+
import android.support.annotation.Nullable;
35
import android.support.v4.app.Fragment;
6+
import android.view.LayoutInflater;
7+
import android.view.View;
8+
import android.view.ViewGroup;
9+
10+
import com.viveksb007.pslab.R;
411

512
/**
613
* Created by viveksb007 on 15/3/17.
714
*/
815

916
public class SavedExperiments extends Fragment {
17+
18+
public static SavedExperiments newInstance() {
19+
SavedExperiments savedExperiments = new SavedExperiments();
20+
return savedExperiments;
21+
}
22+
23+
@Nullable
24+
@Override
25+
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
26+
View view = inflater.inflate(R.layout.saved_experiments_fragment, container, false);
27+
return view;
28+
}
1029
}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,29 @@
11
package com.viveksb007.pslab.fragment;
22

3+
import android.os.Bundle;
4+
import android.support.annotation.Nullable;
35
import android.support.v4.app.Fragment;
6+
import android.view.LayoutInflater;
7+
import android.view.View;
8+
import android.view.ViewGroup;
9+
10+
import com.viveksb007.pslab.R;
411

512
/**
613
* Created by viveksb007 on 15/3/17.
714
*/
815

916
public class SettingsFragment extends Fragment {
17+
18+
public static SettingsFragment newInstance() {
19+
SettingsFragment settingsFragment = new SettingsFragment();
20+
return settingsFragment;
21+
}
22+
23+
@Nullable
24+
@Override
25+
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
26+
View view = inflater.inflate(R.layout.settings_fragment, container, false);
27+
return view;
28+
}
1029
}

Diff for: app/src/main/res/layout/applications_fragment.xml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:orientation="vertical" android:layout_width="match_parent"
4+
android:layout_height="match_parent">
5+
6+
</LinearLayout>
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:orientation="vertical" android:layout_width="match_parent"
4+
android:layout_height="match_parent">
5+
6+
</LinearLayout>
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:orientation="vertical" android:layout_width="match_parent"
4+
android:layout_height="match_parent">
5+
6+
</LinearLayout>

Diff for: app/src/main/res/layout/settings_fragment.xml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:orientation="vertical" android:layout_width="match_parent"
4+
android:layout_height="match_parent">
5+
6+
</LinearLayout>

0 commit comments

Comments
 (0)