| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- package com.ht.gate;
- import androidx.appcompat.app.AppCompatActivity;
- import android.annotation.SuppressLint;
- import android.app.ProgressDialog;
- import android.content.ComponentName;
- import android.content.DialogInterface;
- import android.content.Intent;
- import android.content.ServiceConnection;
- import android.content.SharedPreferences;
- import android.os.Bundle;
- import android.os.IBinder;
- import android.provider.Settings;
- import android.text.InputType;
- import android.util.Log;
- import android.view.View;
- import android.widget.TextView;
- import com.ht.gate.domain.Room;
- import java.io.IOException;
- import butterknife.BindView;
- import butterknife.ButterKnife;
- import butterknife.OnClick;
- import es.dmoral.toasty.Toasty;
- import retrofit2.Call;
- import retrofit2.Callback;
- import retrofit2.Response;
- @SuppressLint("SetTextI18n")
- public class SettingsActivity extends AppCompatActivity {
- private static final String TAG = "SettingsActivity";
- @BindView(R.id.tv_title)
- TextView tvTitle;
- @BindView(R.id.tv_space_id)
- TextView tvSpaceId;
- @BindView(R.id.tv_address)
- TextView tvAddress;
- public static final String PREF_NAME_SETTINGS = "settings";
- public static final String PREF_KEY_ADDRESS = "address";
- private SharedPreferences sharedPreferences;
- private DoorService.DoorBinder mDoorBinder;
- private ServiceConnection connection = new ServiceConnection() {
- @Override
- public void onServiceConnected(ComponentName name, IBinder service) {
- Log.d(TAG, "onServiceConnected");
- mDoorBinder = (DoorService.DoorBinder) service;
- }
- @Override
- public void onServiceDisconnected(ComponentName name) {
- Log.d(TAG, "onServiceDisconnected");
- mDoorBinder = null;
- }
- };
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_settings);
- ButterKnife.bind(this);
- sharedPreferences = getSharedPreferences(PREF_NAME_SETTINGS, MODE_PRIVATE);
- bindService(new Intent(this, DoorService.class), connection, BIND_AUTO_CREATE);
- }
- @Override
- protected void onResume() {
- super.onResume();
- View decorView = getWindow().getDecorView();
- int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
- | View.SYSTEM_UI_FLAG_FULLSCREEN
- | View.SYSTEM_UI_FLAG_IMMERSIVE;
- decorView.setSystemUiVisibility(uiOptions);
- Room room = Room.fromBase64(sharedPreferences.getString(Constants.PREF_ROOM_INFO, null));
- if (room != null) {
- tvTitle.setText(room.getRoomName() + room.getRoomBizNum());
- tvSpaceId.setText(room.getDeviceCode());
- }
- tvAddress.setText(sharedPreferences.getString(PREF_KEY_ADDRESS, ""));
- }
- @Override
- protected void onDestroy() {
- super.onDestroy();
- if (connection != null) {
- unbindService(connection);
- }
- }
- @OnClick(R.id.btn_back)
- void back() {
- finish();
- }
- @OnClick(R.id.btn_change_space_id)
- void changeSpaceId() {
- Intent intent = new Intent(this, LoginActivity.class);
- intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
- | Intent.FLAG_ACTIVITY_CLEAR_TASK);
- startActivity(intent);
- finish();
- }
- @OnClick(R.id.btn_change_address)
- void changeAddress() {
- new PromptBuilder(this)
- .setTitle("输入空间门禁地址")
- .setValue(tvAddress.getText().toString())
- .setPositiveButton("确定")
- .setNegativeButton("取消")
- .setPromptListener(new PromptBuilder.PromptListener() {
- @Override
- public void onCancel(DialogInterface dialog) {
- dialog.dismiss();
- }
- @Override
- public void onConfirm(DialogInterface dialog, String value) {
- dialog.dismiss();
- tvAddress.setText(value);
- sharedPreferences.edit()
- .putString(PREF_KEY_ADDRESS, value)
- .apply();
- if (mDoorBinder != null) {
- mDoorBinder.getService().restartSocket();
- }
- }
- })
- .show();
- }
- }
|