Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.

Commit e017bd5

Browse files
committed
Update: Add Server change page
1 parent 524e74c commit e017bd5

File tree

8 files changed

+186
-5
lines changed

8 files changed

+186
-5
lines changed

android/app/src/main/AndroidManifest.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@
4646
android:name=".ui_main.AboutActivity"
4747
android:theme="@style/Theme.NodeSet" >
4848
</activity>
49+
<activity
50+
android:name=".ui_main.SettingActivity"
51+
android:theme="@style/Theme.NodeSet" >
52+
</activity>
4953
<activity
5054
android:name=".ui_main.NodeDetailActivity"
5155
android:theme="@style/Theme.NodeSet" >

android/app/src/main/java/cc/seeed/iot/MyApplication.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.util.BitSet;
1010

1111
import cc.seeed.iot.datastruct.User;
12+
import cc.seeed.iot.webapi.IotApi;
1213
import cc.seeed.iot.webapi.model.Node;
1314

1415
/**
@@ -21,6 +22,8 @@ public class MyApplication extends Application {
2122

2223
private User user = new User();
2324

25+
private String server_url;
26+
2427
/**
2528
* into smartconfig state
2629
*/
@@ -62,6 +65,16 @@ public void setNodes(ArrayList<Node> nodes) {
6265
this.nodes = nodes;
6366
}
6467

68+
public String getServer_url() {
69+
return server_url;
70+
}
71+
72+
public void setServer_url(String server_url) {
73+
this.server_url = server_url;
74+
SharedPreferences.Editor editor = sp.edit();
75+
editor.putString("server_url", server_url);
76+
editor.apply();
77+
}
6578

6679
public Boolean getConfigState() {
6780
return configState;
@@ -82,9 +95,16 @@ public void onCreate() {
8295
user.email = sp.getString("userName", "[email protected]");
8396
user.user_key = sp.getString("userToken", "sBoKhjQNdtT8oTjukEeg98Ui3fuF3416zh-1Qm5Nkm0");
8497

98+
server_url = sp.getString("server_url", "https://iot.seeed.cc/v1");
8599

86100
configState = sp.getBoolean("configState", false);
87101

88102
configState = sp.getBoolean("loginState", false);
103+
104+
init();
105+
}
106+
107+
private void init() {
108+
IotApi.SetServerUrl(server_url);
89109
}
90110
}

android/app/src/main/java/cc/seeed/iot/ui_main/AboutActivity.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import cc.seeed.iot.R;
1717
import cc.seeed.iot.ui_smartconfig.SmartConnectActivity;
1818

19-
//todo: fix about layout
2019
public class AboutActivity extends AppCompatActivity {
2120
public Toolbar mToolbar;
2221
TextView aboutBodyView;

android/app/src/main/java/cc/seeed/iot/ui_main/MainScreenActivity.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@ public boolean onNavigationItemSelected(MenuItem menuItem) {
216216
mDrawerLayout.closeDrawers();
217217
switch (menuItem.getItemId()) {
218218
case R.id.nav_nodes_list:
219-
Log.e("iot", "id_list");
220219
break;
221220
case R.id.nav_smartconfig: {
222221
((MyApplication) getApplication()).setConfigState(false);
@@ -225,6 +224,12 @@ public boolean onNavigationItemSelected(MenuItem menuItem) {
225224
startActivity(intent);
226225
}
227226
break;
227+
case R.id.nav_setting: {
228+
Intent intent = new Intent(MainScreenActivity.this,
229+
SettingActivity.class);
230+
startActivity(intent);
231+
}
232+
break;
228233
case R.id.nav_about: {
229234
Intent intent = new Intent(MainScreenActivity.this,
230235
AboutActivity.class);
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
package cc.seeed.iot.ui_main;
2+
3+
import android.content.pm.PackageInfo;
4+
import android.content.pm.PackageManager;
5+
import android.os.Bundle;
6+
import android.support.v7.app.AppCompatActivity;
7+
import android.support.v7.widget.Toolbar;
8+
import android.text.Html;
9+
import android.text.InputType;
10+
import android.text.method.LinkMovementMethod;
11+
import android.util.Log;
12+
import android.view.MenuItem;
13+
import android.view.View;
14+
import android.view.WindowManager;
15+
import android.widget.Button;
16+
import android.widget.TextView;
17+
18+
import java.util.Set;
19+
20+
import cc.seeed.iot.MyApplication;
21+
import cc.seeed.iot.R;
22+
import cc.seeed.iot.webapi.IotApi;
23+
24+
public class SettingActivity extends AppCompatActivity implements View.OnClickListener {
25+
private Toolbar mToolbar;
26+
private TextView mUrlView;
27+
private Button mChangeView;
28+
29+
private String server_url;
30+
31+
@Override
32+
protected void onCreate(Bundle savedInstanceState) {
33+
super.onCreate(savedInstanceState);
34+
setContentView(R.layout.setting);
35+
36+
mToolbar = (Toolbar) findViewById(R.id.toolbar);
37+
setSupportActionBar(mToolbar);
38+
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
39+
getSupportActionBar().setTitle("Setting");
40+
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
41+
42+
mUrlView = (TextView) findViewById(R.id.url);
43+
mChangeView = (Button) findViewById(R.id.bt_change);
44+
mChangeView.setOnClickListener(this);
45+
46+
initView();
47+
}
48+
49+
private void initView() {
50+
server_url = ((MyApplication) getApplication()).getServer_url();
51+
mUrlView.setText(server_url);
52+
mUrlView.setEnabled(false);
53+
mChangeView.setText("Change");
54+
}
55+
56+
57+
@Override
58+
public boolean onOptionsItemSelected(MenuItem item) {
59+
int id = item.getItemId();
60+
61+
if (id == android.R.id.home) {
62+
onBackPressed();
63+
return true;
64+
}
65+
return super.onOptionsItemSelected(item);
66+
}
67+
68+
@Override
69+
public void onBackPressed() {
70+
super.onBackPressed();
71+
}
72+
73+
@Override
74+
public void onClick(View v) {
75+
int id = v.getId();
76+
if (id == R.id.bt_change) {
77+
String action = mChangeView.getText().toString();
78+
if (action.equals("Change")) {
79+
mChangeView.setText("Confirm");
80+
mUrlView.setEnabled(true);
81+
} else if (action.equals("Confirm")) {
82+
mChangeView.setText("Change");
83+
mUrlView.setEnabled(false);
84+
85+
saveServerUrl(mUrlView.getText().toString());
86+
//todo: if change error, then do not change to back?
87+
}
88+
}
89+
}
90+
91+
private void saveServerUrl(String s) {
92+
((MyApplication) getApplication()).setServer_url(s);
93+
IotApi.SetServerUrl(s);
94+
}
95+
96+
}

android/app/src/main/java/cc/seeed/iot/ui_setnode/SetupIotNodeActivity.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,8 @@ public void onItemClick(View view, int postion) {
501501

502502
@Override
503503
public void onClick(View v) {
504+
if(mGroveDrivers == null) //todo fixed, find method do it.use database?
505+
return;
504506
switch (v.getId()) {
505507
case R.id.ib_correct:
506508
int position = uiStateControl.getSetPin();

android/app/src/main/java/cc/seeed/iot/webapi/IotApi.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import javax.net.ssl.TrustManager;
1616
import javax.net.ssl.X509TrustManager;
1717

18+
import cc.seeed.iot.MyApplication;
1819
import retrofit.RequestInterceptor;
1920
import retrofit.RestAdapter;
2021
import retrofit.android.MainThreadExecutor;
@@ -25,11 +26,13 @@
2526
*/
2627
public class IotApi {
2728

28-
// private String IOT_WEB_API_ENDPOINT = "http://192.168.21.83:8080/v1";
29+
// private String IOT_WEB_API_ENDPOINT = "http://192.168.21.83:8080/v1";
2930
// private String iot_url = "http://192.168.18.194:8080/v1";
3031
// private String iot_url = "http://192.168.18.251:8080/v1"; //jacky shao
3132
// private String iot_url = "https://iot.yuzhe.me/v1";
32-
private String iot_url = "https://iot.seeed.cc/v1";
33+
// private String iot_url = "https://iot.seeed.cc/v1";
34+
35+
private static String iot_url = "https://iot.seeed.cc/v1";
3336

3437
private final IotService mIotService;
3538

@@ -39,9 +42,12 @@ public class IotApi {
3942
// mIotService = init(httpExecutor, callbackExecutor);
4043
// }
4144

45+
public static void SetServerUrl(String url) {
46+
iot_url = url;
47+
}
4248

4349
public IotApi() {
44-
// iot_url = MySharedPreference.getSvrAdd();
50+
4551
Executor httpExecutor = Executors.newSingleThreadExecutor();
4652
MainThreadExecutor callbackExecutor = new MainThreadExecutor();
4753
mIotService = init(httpExecutor, callbackExecutor);
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:tools="http://schemas.android.com/tools"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent"
5+
android:orientation="vertical">
6+
7+
<android.support.v7.widget.Toolbar
8+
android:id="@+id/toolbar"
9+
android:layout_width="match_parent"
10+
android:layout_height="?attr/actionBarSize"
11+
android:background="?attr/colorPrimary"
12+
android:elevation="5dp"
13+
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
14+
15+
</android.support.v7.widget.Toolbar>
16+
17+
<RelativeLayout
18+
android:layout_width="wrap_content"
19+
android:layout_height="wrap_content"
20+
android:layout_margin="16dp">
21+
22+
<TextView
23+
android:id="@+id/server"
24+
style="?android:attr/textAppearanceLarge"
25+
android:layout_width="wrap_content"
26+
android:layout_height="wrap_content"
27+
android:layout_centerVertical="true"
28+
android:text="Server: " />
29+
30+
<Button
31+
android:id="@+id/bt_change"
32+
style="attr/buttonBarPositiveButtonStyle"
33+
android:layout_width="wrap_content"
34+
android:layout_height="wrap_content"
35+
android:layout_alignParentRight="true"
36+
tools:text="Change" />
37+
38+
<EditText
39+
android:id="@+id/url"
40+
android:layout_width="match_parent"
41+
android:layout_height="wrap_content"
42+
android:layout_toLeftOf="@id/bt_change"
43+
android:layout_toRightOf="@id/server" />
44+
45+
46+
</RelativeLayout>
47+
48+
49+
</LinearLayout>

0 commit comments

Comments
 (0)