Toggle navigation
Toggle navigation
This project
Loading...
Sign in
cse437_e
/
smartdoorlock-frontend
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
오윤석
2020-11-09 23:38:11 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
1f892312ceabf9e3946f8639447d83038fd06629
1f892312
1 parent
fbd67021
setting page api 연결
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
158 additions
and
0 deletions
app/src/main/AndroidManifest.xml
app/src/main/java/com/sunnni/smartdoorlock/api/Api.java
app/src/main/java/com/sunnni/smartdoorlock/api/Setting.java
app/src/main/java/com/sunnni/smartdoorlock/ui/MainActivity.java
app/src/main/java/com/sunnni/smartdoorlock/ui/SettingActivity.java
app/src/main/res/layout/activity_main.xml
app/src/main/res/layout/activity_setting.xml
app/src/main/AndroidManifest.xml
View file @
1f89231
...
...
@@ -23,6 +23,7 @@
</intent-filter>
</activity>
<activity
android:name=
".ui.MainActivity"
/>
<activity
android:name=
".ui.SettingActivity"
/>
</application>
</manifest>
\ No newline at end of file
...
...
app/src/main/java/com/sunnni/smartdoorlock/api/Api.java
View file @
1f89231
...
...
@@ -126,4 +126,36 @@ public class Api {
}
});
}
static
public
void
getSetting
(
final
Callback
callback
)
{
callApi
(
"GET"
,
"/api/setting"
,
null
,
new
Callback
()
{
@Override
public
void
callbackMethod
(
Object
obj
)
{
ApiResult
apiResult
=
(
ApiResult
)
obj
;
if
(
apiResult
.
isSuccess
())
{
JsonObject
resp
=
(
JsonObject
)
apiResult
.
getData
();
callback
.
callbackMethod
(
new
Setting
(
resp
.
get
(
"recording"
).
getAsBoolean
()));
}
else
{
callback
.
callbackMethod
(
null
);
}
}
});
}
static
public
void
setSetting
(
Setting
setting
,
final
Callback
callback
)
{
JsonObject
params
=
new
JsonObject
();
params
.
addProperty
(
"recording"
,
setting
.
getRecording
());
callApi
(
"PUT"
,
"/api/setting"
,
params
,
new
Callback
()
{
@Override
public
void
callbackMethod
(
Object
obj
)
{
ApiResult
apiResult
=
(
ApiResult
)
obj
;
if
(
apiResult
.
isSuccess
())
{
callback
.
callbackMethod
(
true
);
}
else
{
callback
.
callbackMethod
(
null
);
}
}
});
}
}
...
...
app/src/main/java/com/sunnni/smartdoorlock/api/Setting.java
0 → 100644
View file @
1f89231
package
com
.
sunnni
.
smartdoorlock
.
api
;
public
class
Setting
{
private
boolean
recording
;
public
Setting
(
boolean
recording
)
{
this
.
recording
=
recording
;
}
public
boolean
getRecording
()
{
return
recording
;
}
}
app/src/main/java/com/sunnni/smartdoorlock/ui/MainActivity.java
View file @
1f89231
...
...
@@ -2,15 +2,26 @@ package com.sunnni.smartdoorlock.ui;
import
androidx.appcompat.app.AppCompatActivity
;
import
android.content.Intent
;
import
android.os.Bundle
;
import
android.view.View
;
import
android.widget.Button
;
import
com.sunnni.smartdoorlock.R
;
public
class
MainActivity
extends
AppCompatActivity
{
private
Button
btnSetting
;
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
activity_main
);
btnSetting
=
(
Button
)
findViewById
(
R
.
id
.
btn_setting
);
btnSetting
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
view
)
{
startActivity
(
new
Intent
(
MainActivity
.
this
,
SettingActivity
.
class
));
}
});
}
}
...
...
app/src/main/java/com/sunnni/smartdoorlock/ui/SettingActivity.java
0 → 100644
View file @
1f89231
package
com
.
sunnni
.
smartdoorlock
.
ui
;
import
android.content.Intent
;
import
android.content.SharedPreferences
;
import
android.os.Bundle
;
import
android.view.View
;
import
android.widget.Button
;
import
android.widget.CompoundButton
;
import
android.widget.Switch
;
import
android.widget.Toast
;
import
com.sunnni.smartdoorlock.R
;
import
com.sunnni.smartdoorlock.api.Api
;
import
com.sunnni.smartdoorlock.api.Setting
;
import
androidx.appcompat.app.AppCompatActivity
;
public
class
SettingActivity
extends
AppCompatActivity
{
private
Switch
swcRecording
;
private
Button
btnLogout
;
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
activity_setting
);
btnLogout
=
(
Button
)
findViewById
(
R
.
id
.
btn_logout
);
btnLogout
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
view
)
{
SharedPreferences
pref
=
getSharedPreferences
(
"gateway"
,
MODE_PRIVATE
);
SharedPreferences
.
Editor
editor
=
pref
.
edit
();
editor
.
remove
(
"accessToken"
);
editor
.
commit
();
startActivity
(
new
Intent
(
SettingActivity
.
this
,
SplashActivity
.
class
));
}
});
swcRecording
=
(
Switch
)
findViewById
(
R
.
id
.
swc_recording
);
swcRecording
.
setOnCheckedChangeListener
(
new
CompoundButton
.
OnCheckedChangeListener
()
{
@Override
public
void
onCheckedChanged
(
CompoundButton
compoundButton
,
boolean
b
)
{
Api
.
setSetting
(
new
Setting
(
true
),
new
Api
.
Callback
()
{
@Override
public
void
callbackMethod
(
Object
obj
)
{
if
(
obj
==
null
)
{
Toast
.
makeText
(
getApplicationContext
(),
"연결 상태가 불안정합니다."
,
Toast
.
LENGTH_SHORT
).
show
();
}
}
});
}
});
Api
.
getSetting
(
new
Api
.
Callback
()
{
@Override
public
void
callbackMethod
(
Object
obj
)
{
Setting
setting
=
(
Setting
)
obj
;
if
(
setting
==
null
)
{
Toast
.
makeText
(
getApplicationContext
(),
"연결 상태가 불안정합니다."
,
Toast
.
LENGTH_SHORT
).
show
();
return
;
}
swcRecording
.
setChecked
(
setting
.
getRecording
());
}
});
}
}
app/src/main/res/layout/activity_main.xml
View file @
1f89231
...
...
@@ -15,4 +15,12 @@
app:layout_constraintRight_toRightOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
/>
<Button
android:id=
"@+id/btn_setting"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"btn_setting"
tools:layout_editor_absoluteX=
"166dp"
tools:layout_editor_absoluteY=
"399dp"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
...
...
app/src/main/res/layout/activity_setting.xml
0 → 100644
View file @
1f89231
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
xmlns:tools=
"http://schemas.android.com/tools"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
>
<Button
android:id=
"@+id/btn_logout"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginStart=
"22dp"
android:layout_marginTop=
"9dp"
android:text=
"btn_logout"
app:layout_constraintStart_toStartOf=
"@+id/swc_recording"
app:layout_constraintTop_toBottomOf=
"@+id/swc_recording"
/>
<Switch
android:id=
"@+id/swc_recording"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginEnd=
"117dp"
android:layout_marginTop=
"151dp"
android:text=
"swc_recording"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
Please
register
or
login
to post a comment