Showing
7 changed files
with
158 additions
and
0 deletions
... | @@ -23,6 +23,7 @@ | ... | @@ -23,6 +23,7 @@ |
23 | </intent-filter> | 23 | </intent-filter> |
24 | </activity> | 24 | </activity> |
25 | <activity android:name=".ui.MainActivity" /> | 25 | <activity android:name=".ui.MainActivity" /> |
26 | + <activity android:name=".ui.SettingActivity" /> | ||
26 | </application> | 27 | </application> |
27 | 28 | ||
28 | </manifest> | 29 | </manifest> |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -126,4 +126,36 @@ public class Api { | ... | @@ -126,4 +126,36 @@ public class Api { |
126 | } | 126 | } |
127 | }); | 127 | }); |
128 | } | 128 | } |
129 | + | ||
130 | + static public void getSetting(final Callback callback) { | ||
131 | + callApi("GET", "/api/setting", null, new Callback() { | ||
132 | + @Override | ||
133 | + public void callbackMethod(Object obj) { | ||
134 | + ApiResult apiResult = (ApiResult) obj; | ||
135 | + if(apiResult.isSuccess()) { | ||
136 | + JsonObject resp = (JsonObject) apiResult.getData(); | ||
137 | + callback.callbackMethod(new Setting(resp.get("recording").getAsBoolean())); | ||
138 | + } else { | ||
139 | + callback.callbackMethod(null); | ||
140 | + } | ||
141 | + } | ||
142 | + }); | ||
143 | + } | ||
144 | + | ||
145 | + static public void setSetting(Setting setting, final Callback callback) { | ||
146 | + JsonObject params = new JsonObject(); | ||
147 | + params.addProperty("recording", setting.getRecording()); | ||
148 | + | ||
149 | + callApi("PUT", "/api/setting", params, new Callback() { | ||
150 | + @Override | ||
151 | + public void callbackMethod(Object obj) { | ||
152 | + ApiResult apiResult = (ApiResult) obj; | ||
153 | + if(apiResult.isSuccess()) { | ||
154 | + callback.callbackMethod(true); | ||
155 | + } else { | ||
156 | + callback.callbackMethod(null); | ||
157 | + } | ||
158 | + } | ||
159 | + }); | ||
160 | + } | ||
129 | } | 161 | } | ... | ... |
... | @@ -2,15 +2,26 @@ package com.sunnni.smartdoorlock.ui; | ... | @@ -2,15 +2,26 @@ package com.sunnni.smartdoorlock.ui; |
2 | 2 | ||
3 | import androidx.appcompat.app.AppCompatActivity; | 3 | import androidx.appcompat.app.AppCompatActivity; |
4 | 4 | ||
5 | +import android.content.Intent; | ||
5 | import android.os.Bundle; | 6 | import android.os.Bundle; |
7 | +import android.view.View; | ||
8 | +import android.widget.Button; | ||
6 | 9 | ||
7 | import com.sunnni.smartdoorlock.R; | 10 | import com.sunnni.smartdoorlock.R; |
8 | 11 | ||
9 | public class MainActivity extends AppCompatActivity { | 12 | public class MainActivity extends AppCompatActivity { |
13 | + private Button btnSetting; | ||
10 | 14 | ||
11 | @Override | 15 | @Override |
12 | protected void onCreate(Bundle savedInstanceState) { | 16 | protected void onCreate(Bundle savedInstanceState) { |
13 | super.onCreate(savedInstanceState); | 17 | super.onCreate(savedInstanceState); |
14 | setContentView(R.layout.activity_main); | 18 | setContentView(R.layout.activity_main); |
19 | + btnSetting = (Button) findViewById(R.id.btn_setting); | ||
20 | + btnSetting.setOnClickListener(new View.OnClickListener() { | ||
21 | + @Override | ||
22 | + public void onClick(View view) { | ||
23 | + startActivity(new Intent(MainActivity.this, SettingActivity.class)); | ||
24 | + } | ||
25 | + }); | ||
15 | } | 26 | } |
16 | } | 27 | } | ... | ... |
1 | +package com.sunnni.smartdoorlock.ui; | ||
2 | + | ||
3 | +import android.content.Intent; | ||
4 | +import android.content.SharedPreferences; | ||
5 | +import android.os.Bundle; | ||
6 | +import android.view.View; | ||
7 | +import android.widget.Button; | ||
8 | +import android.widget.CompoundButton; | ||
9 | +import android.widget.Switch; | ||
10 | +import android.widget.Toast; | ||
11 | + | ||
12 | +import com.sunnni.smartdoorlock.R; | ||
13 | +import com.sunnni.smartdoorlock.api.Api; | ||
14 | +import com.sunnni.smartdoorlock.api.Setting; | ||
15 | + | ||
16 | +import androidx.appcompat.app.AppCompatActivity; | ||
17 | + | ||
18 | +public class SettingActivity extends AppCompatActivity { | ||
19 | + private Switch swcRecording; | ||
20 | + private Button btnLogout; | ||
21 | + | ||
22 | + @Override | ||
23 | + protected void onCreate(Bundle savedInstanceState) { | ||
24 | + super.onCreate(savedInstanceState); | ||
25 | + setContentView(R.layout.activity_setting); | ||
26 | + btnLogout = (Button) findViewById(R.id.btn_logout); | ||
27 | + btnLogout.setOnClickListener(new View.OnClickListener() { | ||
28 | + @Override | ||
29 | + public void onClick(View view) { | ||
30 | + SharedPreferences pref = getSharedPreferences("gateway", MODE_PRIVATE); | ||
31 | + SharedPreferences.Editor editor = pref.edit(); | ||
32 | + editor.remove("accessToken"); | ||
33 | + editor.commit(); | ||
34 | + startActivity(new Intent(SettingActivity.this, SplashActivity.class)); | ||
35 | + } | ||
36 | + }); | ||
37 | + | ||
38 | + swcRecording = (Switch) findViewById(R.id.swc_recording); | ||
39 | + swcRecording.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { | ||
40 | + @Override | ||
41 | + public void onCheckedChanged(CompoundButton compoundButton, boolean b) { | ||
42 | + Api.setSetting(new Setting(true), new Api.Callback() { | ||
43 | + @Override | ||
44 | + public void callbackMethod(Object obj) { | ||
45 | + if(obj == null) { | ||
46 | + Toast.makeText(getApplicationContext(),"연결 상태가 불안정합니다.",Toast.LENGTH_SHORT).show(); | ||
47 | + } | ||
48 | + } | ||
49 | + }); | ||
50 | + } | ||
51 | + }); | ||
52 | + | ||
53 | + Api.getSetting(new Api.Callback() { | ||
54 | + @Override | ||
55 | + public void callbackMethod(Object obj) { | ||
56 | + Setting setting = (Setting) obj; | ||
57 | + if(setting == null) { | ||
58 | + Toast.makeText(getApplicationContext(),"연결 상태가 불안정합니다.",Toast.LENGTH_SHORT).show(); | ||
59 | + return; | ||
60 | + } | ||
61 | + | ||
62 | + swcRecording.setChecked(setting.getRecording()); | ||
63 | + } | ||
64 | + }); | ||
65 | + } | ||
66 | +} |
... | @@ -15,4 +15,12 @@ | ... | @@ -15,4 +15,12 @@ |
15 | app:layout_constraintRight_toRightOf="parent" | 15 | app:layout_constraintRight_toRightOf="parent" |
16 | app:layout_constraintTop_toTopOf="parent" /> | 16 | app:layout_constraintTop_toTopOf="parent" /> |
17 | 17 | ||
18 | + <Button | ||
19 | + android:id="@+id/btn_setting" | ||
20 | + android:layout_width="wrap_content" | ||
21 | + android:layout_height="wrap_content" | ||
22 | + android:text="btn_setting" | ||
23 | + tools:layout_editor_absoluteX="166dp" | ||
24 | + tools:layout_editor_absoluteY="399dp" /> | ||
25 | + | ||
18 | </androidx.constraintlayout.widget.ConstraintLayout> | 26 | </androidx.constraintlayout.widget.ConstraintLayout> |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
app/src/main/res/layout/activity_setting.xml
0 → 100644
1 | +<?xml version="1.0" encoding="utf-8"?> | ||
2 | +<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
3 | + xmlns:app="http://schemas.android.com/apk/res-auto" | ||
4 | + xmlns:tools="http://schemas.android.com/tools" | ||
5 | + android:layout_width="match_parent" | ||
6 | + android:layout_height="match_parent"> | ||
7 | + | ||
8 | + <Button | ||
9 | + android:id="@+id/btn_logout" | ||
10 | + android:layout_width="wrap_content" | ||
11 | + android:layout_height="wrap_content" | ||
12 | + android:layout_marginStart="22dp" | ||
13 | + android:layout_marginTop="9dp" | ||
14 | + android:text="btn_logout" | ||
15 | + app:layout_constraintStart_toStartOf="@+id/swc_recording" | ||
16 | + app:layout_constraintTop_toBottomOf="@+id/swc_recording" /> | ||
17 | + | ||
18 | + <Switch | ||
19 | + android:id="@+id/swc_recording" | ||
20 | + android:layout_width="wrap_content" | ||
21 | + android:layout_height="wrap_content" | ||
22 | + android:layout_marginEnd="117dp" | ||
23 | + android:layout_marginTop="151dp" | ||
24 | + android:text="swc_recording" | ||
25 | + app:layout_constraintEnd_toEndOf="parent" | ||
26 | + app:layout_constraintTop_toTopOf="parent" /> | ||
27 | +</androidx.constraintlayout.widget.ConstraintLayout> | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment