Drew há 6 anos atrás
pai
commit
96481ab4a6

+ 1 - 0
app/build.gradle

@@ -33,4 +33,5 @@ dependencies {
     implementation "android.arch.lifecycle:extensions:1.1.3"
     implementation 'com.jakewharton:butterknife:10.2.0'
     annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.0'
+    implementation 'com.kaopiz:kprogresshud:1.2.0'
 }

+ 2 - 1
app/src/main/AndroidManifest.xml

@@ -10,7 +10,8 @@
         android:roundIcon="@mipmap/ic_launcher_round"
         android:supportsRtl="false"
         android:theme="@style/AppTheme"
-        tools:ignore="GoogleAppIndexingWarning">
+        tools:ignore="GoogleAppIndexingWarning"
+        tools:replace="android:supportsRtl">
         <activity android:name=".SettingsActivity"></activity>
         <activity android:name=".WelcomeActivity" />
         <activity android:name=".MainActivity" />

+ 46 - 0
app/src/main/java/com/ht/gate/SettingsActivity.java

@@ -1,23 +1,69 @@
 package com.ht.gate;
 
+import androidx.appcompat.app.AlertDialog;
 import androidx.appcompat.app.AppCompatActivity;
 
+import android.content.SharedPreferences;
 import android.os.Bundle;
+import android.text.InputType;
+import android.view.ViewGroup;
+import android.widget.EditText;
+import android.widget.LinearLayout;
+import android.widget.TextView;
 
+import butterknife.BindView;
 import butterknife.ButterKnife;
 import butterknife.OnClick;
 
 public class SettingsActivity extends AppCompatActivity {
+    @BindView(R.id.tv_space_id)
+    TextView tvSpaceId;
+    @BindView(R.id.tv_space_name)
+    TextView tvSpaceName;
+
+    private SharedPreferences sharedPreferences;
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_settings);
         ButterKnife.bind(this);
+        sharedPreferences = getSharedPreferences("settings", MODE_PRIVATE);
+    }
+
+    @Override
+    protected void onResume() {
+        super.onResume();
+        tvSpaceId.setText(sharedPreferences.getString("spaceId", ""));
     }
 
     @OnClick(R.id.btn_back)
     void back() {
         finish();
     }
+
+    @OnClick(R.id.btn_change_space_id)
+    void changeSpaceId() {
+        AlertDialog.Builder builder = new AlertDialog.Builder(this);
+        builder.setTitle("输入空间ID");
+        final EditText input = new EditText(this);
+        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
+        input.setLayoutParams(params);
+        input.setInputType(InputType.TYPE_CLASS_TEXT);
+
+        LinearLayout linearLayout = new LinearLayout(this);
+        linearLayout.setPadding(Utils.dp2px(18, SettingsActivity.this), 0, Utils.dp2px(18, SettingsActivity.this), 0);
+        linearLayout.addView(input);
+        builder.setView(linearLayout);
+        builder.setPositiveButton("确定", (dialog, which) -> {
+            sharedPreferences = getSharedPreferences("settings", MODE_PRIVATE);
+            sharedPreferences.edit()
+                    .putString("spaceId", input.getText().toString())
+                    .apply();
+        });
+        builder.setNegativeButton("取消", (dialog, which) -> dialog.cancel());
+        builder.show();
+    }
+
+
 }

+ 16 - 0
app/src/main/java/com/ht/gate/Utils.java

@@ -0,0 +1,16 @@
+package com.ht.gate;
+
+import android.content.Context;
+import android.util.TypedValue;
+
+public class Utils {
+    public static int sp2px(float sp, Context context) {
+        return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, sp,
+                context.getResources().getDisplayMetrics());
+    }
+
+    public static int dp2px(float dp, Context context) {
+        return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp,
+                context.getResources().getDisplayMetrics());
+    }
+}

+ 130 - 1
app/src/main/res/layout/activity_settings.xml

@@ -55,6 +55,135 @@
             android:gravity="center"
             android:orientation="horizontal">
 
+            <TextView
+                android:layout_width="115dp"
+                android:layout_height="wrap_content"
+                android:text="空间ID"
+                android:textColor="@android:color/white"
+                android:textSize="18sp" />
+
+            <TextView
+                android:id="@+id/tv_space_id"
+                android:layout_width="0dp"
+                android:layout_height="wrap_content"
+                android:layout_weight="1"
+                android:fontFamily="@font/source_han_sans_sc_medium"
+                android:text="ABC-EF"
+                android:textColor="@android:color/white"
+                android:textSize="18sp" />
+
+            <Button
+                android:id="@+id/btn_change_space_id"
+                style="@style/Widget.AppCompat.Button.Borderless"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:background="?selectableItemBackgroundBorderless"
+                android:fontFamily="@font/source_han_sans_sc_medium"
+                android:minWidth="0dp"
+                android:paddingLeft="9dp"
+                android:paddingRight="9dp"
+                android:text="修改"
+                android:textColor="#E4BF85"
+                android:textSize="18sp" />
+        </LinearLayout>
+
+        <View
+            android:layout_width="match_parent"
+            android:layout_height="1dp"
+            android:background="#4df2f4f5" />
+
+        <LinearLayout
+            android:layout_width="match_parent"
+            android:layout_height="89dp"
+            android:gravity="center"
+            android:orientation="horizontal">
+
+            <TextView
+                android:layout_width="115dp"
+                android:layout_height="wrap_content"
+                android:text="空间名称"
+                android:textColor="@android:color/white"
+                android:textSize="18sp" />
+
+            <TextView
+                android:id="@+id/tv_space_name"
+                android:layout_width="0dp"
+                android:layout_height="wrap_content"
+                android:layout_weight="1"
+                android:fontFamily="@font/source_han_sans_sc_medium"
+                android:text="A101"
+                android:textColor="@android:color/white"
+                android:textSize="18sp" />
+
+            <Button
+                android:id="@+id/btn_change_space_name"
+                style="@style/Widget.AppCompat.Button.Borderless"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:background="?selectableItemBackgroundBorderless"
+                android:fontFamily="@font/source_han_sans_sc_medium"
+                android:minWidth="0dp"
+                android:paddingLeft="9dp"
+                android:paddingRight="9dp"
+                android:text="修改"
+                android:textColor="#E4BF85"
+                android:textSize="18sp" />
+        </LinearLayout>
+
+        <View
+            android:layout_width="match_parent"
+            android:layout_height="1dp"
+            android:background="#4df2f4f5" />
+
+        <LinearLayout
+            android:layout_width="match_parent"
+            android:layout_height="89dp"
+            android:gravity="center"
+            android:orientation="horizontal">
+
+            <TextView
+                android:layout_width="115dp"
+                android:layout_height="wrap_content"
+                android:text="门禁地址"
+                android:textColor="@android:color/white"
+                android:textSize="18sp" />
+
+            <TextView
+                android:id="@+id/tv_address"
+                android:layout_width="0dp"
+                android:layout_height="wrap_content"
+                android:layout_weight="1"
+                android:fontFamily="@font/source_han_sans_sc_medium"
+                android:text="0.0.0.0"
+                android:textColor="@android:color/white"
+                android:textSize="18sp" />
+
+            <Button
+                android:id="@+id/btn_change_address"
+                style="@style/Widget.AppCompat.Button.Borderless"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:background="?selectableItemBackgroundBorderless"
+                android:fontFamily="@font/source_han_sans_sc_medium"
+                android:minWidth="0dp"
+                android:paddingLeft="9dp"
+                android:paddingRight="9dp"
+                android:text="修改"
+                android:textColor="#E4BF85"
+                android:textSize="18sp" />
+        </LinearLayout>
+
+        <View
+            android:layout_width="match_parent"
+            android:layout_height="1dp"
+            android:background="#4df2f4f5" />
+
+        <LinearLayout
+            android:layout_width="match_parent"
+            android:layout_height="89dp"
+            android:gravity="center"
+            android:orientation="horizontal">
+
             <TextView
                 android:layout_width="115dp"
                 android:layout_height="wrap_content"
@@ -82,7 +211,7 @@
                 android:paddingRight="9dp"
                 android:text="更新"
                 android:textColor="#E4BF85"
-                android:textSize="18dp" />
+                android:textSize="18sp" />
         </LinearLayout>
 
         <View