瀏覽代碼

apn list add

liuzhenxing 3 年之前
父節點
當前提交
37d38a9803

+ 4 - 4
.idea/deploymentTargetDropDown.xml

@@ -1,9 +1,9 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <project version="4">
   <component name="deploymentTargetDropDown">
-    <targetSelectedWithDropDown>
+    <runningDeviceTargetSelectedWithDropDown>
       <Target>
-        <type value="QUICK_BOOT_TARGET" />
+        <type value="RUNNING_DEVICE_TARGET" />
         <deviceKey>
           <Key>
             <type value="VIRTUAL_DEVICE_PATH" />
@@ -11,7 +11,7 @@
           </Key>
         </deviceKey>
       </Target>
-    </targetSelectedWithDropDown>
-    <timeTargetWasSelectedWithDropDown value="2022-06-28T02:31:20.856030Z" />
+    </runningDeviceTargetSelectedWithDropDown>
+    <timeTargetWasSelectedWithDropDown value="2022-06-30T06:32:34.088152Z" />
   </component>
 </project>

+ 2 - 0
.idea/misc.xml

@@ -11,8 +11,10 @@
         <entry key="app/src/main/res/layout/activity_display.xml" value="0.11610486891385768" />
         <entry key="app/src/main/res/layout/activity_list.xml" value="0.19300911854103345" />
         <entry key="app/src/main/res/layout/activity_main.xml" value="0.3546195652173913" />
+        <entry key="app/src/main/res/layout/activity_wifi_login.xml" value="0.16236068895643363" />
         <entry key="app/src/main/res/layout/bright_activity.xml" value="0.1889564336372847" />
         <entry key="app/src/main/res/layout/display_activity.xml" value="0.20199275362318841" />
+        <entry key="app/src/main/res/layout/item_cancel_sure.xml" value="0.14903846153846154" />
         <entry key="app/src/main/res/layout/item_center.xml" value="0.13179347826086957" />
         <entry key="app/src/main/res/layout/item_checkbox.xml" value="0.20199275362318841" />
         <entry key="app/src/main/res/layout/item_connections.xml" value="0.19300911854103345" />

+ 56 - 1
app/src/main/java/com/xplora/xpsettings/Activity/ApnEditActivity.java

@@ -1,9 +1,17 @@
 package com.xplora.xpsettings.Activity;
 
+import android.content.Intent;
 import android.os.Bundle;
+import android.os.Handler;
+import android.os.Looper;
+import android.os.Message;
 import android.widget.ListView;
 
+import androidx.annotation.NonNull;
+
 import com.xplora.xpsettings.Adapter.BaseListAdapter;
+import com.xplora.xpsettings.DataManager;
+import com.xplora.xpsettings.Model.ApnModel;
 import com.xplora.xpsettings.Model.BaseModel;
 import com.xplora.xpsettings.R;
 import com.xplora.xpsettings.Utils.Constant;
@@ -12,6 +20,7 @@ import java.util.ArrayList;
 import java.util.List;
 
 public class ApnEditActivity extends BaseActivity {
+    public ApnModel mApnModel = new ApnModel();
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
@@ -30,11 +39,57 @@ public class ApnEditActivity extends BaseActivity {
             model.cellType = Constant.CellType.TITLE_EDIT;
             mDataList.add(model);
         }
+
+        //底部加按钮
+        BaseModel model = new BaseModel();
+        model.cellType = Constant.CellType.CANCEL_SURE;
+        mDataList.add(model);
     }
 
     private void initView() {
-        mAdapter = new BaseListAdapter(ApnEditActivity.this, R.layout.item_xpstyle, mDataList);
+        mAdapter = new BaseListAdapter(ApnEditActivity.this, R.layout.item_xpstyle, mDataList, mHandler);
         ListView listView = findViewById(R.id.activity_listview);
         listView.setAdapter(mAdapter);
     }
+
+    Handler mHandler = new Handler(Looper.myLooper()) {
+        @Override
+        public void handleMessage(@NonNull Message msg) {
+            super.handleMessage(msg);
+            if (msg.what == Constant.MSG_TEXTEDIT_FINISH) {
+                String s = (String)msg.obj;
+                s = "value";
+                switch (msg.arg1) {
+                    case 0:
+                        mApnModel.apn_name = s.trim();
+                        break;
+                    case 1:
+                        mApnModel.user_name = s.trim();
+                        break;
+                    case 2:
+                        mApnModel.password = s.trim();
+                        break;
+                    case 3:
+                        mApnModel.mcc = s.trim();
+                        break;
+                    case 4:
+                        mApnModel.mnc = s.trim();
+                        break;
+                    default:
+                        break;
+                }
+            } else if (msg.what == Constant.MSG_CANCEL_CLICK) {
+                Intent intent = new Intent();
+                intent.setAction(Constant.INENT_RESULT_ACTION_CANCEL);
+                setResult(RESULT_OK, intent);
+                finish();
+            } else if (msg.what == Constant.MSG_SURE_CLICK) {
+                Intent intent = new Intent();
+                intent.setAction(Constant.INENT_RESULT_ACTION);
+                intent.putExtra(Constant.INENT_RESULT_VALUE, mApnModel);
+                setResult(RESULT_OK, intent);
+                finish();
+            }
+        }
+    };
 }

+ 52 - 41
app/src/main/java/com/xplora/xpsettings/Activity/ApnListActivity.java

@@ -21,6 +21,7 @@ import com.xplora.xpsettings.Utils.Constant;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Vector;
 
 
 public class ApnListActivity extends BaseActivity {
@@ -35,50 +36,60 @@ public class ApnListActivity extends BaseActivity {
 
     private void initData() {
         mApnList = DataManager.getApnList();
-        String[] stringList = getResources().getStringArray(R.array.apn_titls_array);
-
         for (int i = 0; i < mApnList.size(); i++) {
-            String apnName = mApnList.get(i).apn_name.trim();
-            String mcc = stringList[3] + mApnList.get(i).mcc;
-            String mnc = stringList[4] + mApnList.get(i).mnc;
-            BaseModel model = new BaseModel();
-            model.title = apnName;
-            model.subTitle = mcc + " " + mnc;
-            model.isShowArrow = true;
-            model.cellType = Constant.CellType.TITLE_SUBTITLE;
-            mDataList.add(model);
+            addBaseMode(mApnList.get(i));
         }
     }
 
+    private void addBaseMode(ApnModel apnModel) {
+        String[] stringList = getResources().getStringArray(R.array.apn_titls_array);
+
+        String apnName = apnModel.apn_name.trim();
+        String mcc = stringList[3] + apnModel.mcc;
+        String mnc = stringList[4] + apnModel.mnc;
+        BaseModel model = new BaseModel();
+        model.title = apnName;
+        model.subTitle = mcc + " " + mnc;
+        model.isShowArrow = true;
+        model.cellType = Constant.CellType.TITLE_SUBTITLE;
+        mDataList.add(model);
+    }
+
     private void initView() {
         ListView listView = findViewById(R.id.activity_listview);
         View emptyView = findViewById(R.id.empty_view);
-        if (mApnList.size() == 0) {
-            listView.setVisibility(View.GONE);
-            emptyView.setVisibility(View.VISIBLE);
-
-            TextView textView = findViewById(R.id.empty_text);
-            textView.setText(R.string.apn_hint);
-
-            Button button = findViewById(R.id.empty_button);
-            button.setOnClickListener(new View.OnClickListener() {
-                @Override
-                public void onClick(View v) {
-                    clickAddButton();
-                }
-            });
-        } else {
-            mAdapter = new BaseListAdapter(this, 0, mDataList);
-            listView.setAdapter(mAdapter);
-            listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
-                @Override
-                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
-                    Intent intent = new Intent(ApnListActivity.this, CameraResolutionActivity.class);
-                    intent.putExtra(Constant.INENT_VIEW_TYPE, position);
-                    startActivityForResult(intent, 0);
-                }
-            });
-        }
+
+        listView.setVisibility(mApnList.size() == 0 ? View.GONE : View.VISIBLE);
+        emptyView.setVisibility(mApnList.size() == 0 ? View.VISIBLE : View.GONE);
+
+        initEmptyView();
+        initList(listView);
+    }
+
+    private void initEmptyView() {
+        TextView textView = findViewById(R.id.empty_text);
+        textView.setText(R.string.apn_hint);
+
+        Button button = findViewById(R.id.empty_button);
+        button.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                clickAddButton();
+            }
+        });
+    }
+
+    private void initList(ListView listView) {
+        mAdapter = new BaseListAdapter(this, 0, mDataList);
+        listView.setAdapter(mAdapter);
+        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
+            @Override
+            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
+                Intent intent = new Intent(ApnListActivity.this, CameraResolutionActivity.class);
+                intent.putExtra(Constant.INENT_VIEW_TYPE, position);
+                startActivityForResult(intent, 0);
+            }
+        });
     }
 
     public void clickAddButton() {
@@ -90,10 +101,10 @@ public class ApnListActivity extends BaseActivity {
     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
         super.onActivityResult(requestCode, resultCode, data);
         if (data.getAction().equals(Constant.INENT_RESULT_ACTION)) {
-            int viewType = data.getIntExtra(Constant.INENT_VIEW_TYPE, 0);
-            String value = data.getStringExtra(Constant.INENT_RESULT_VALUE);
-            BaseModel model = mDataList.get(viewType);
-            model.subTitle = value;
+            ApnModel apnModel = (ApnModel)data.getSerializableExtra(Constant.INENT_RESULT_VALUE);
+            mApnList.add(apnModel);
+            addBaseMode(apnModel);
+            initView();
             mAdapter.setBaseObjects(mDataList);
             mAdapter.notifyDataSetInvalidated();
         }

+ 66 - 10
app/src/main/java/com/xplora/xpsettings/Adapter/BaseListAdapter.java

@@ -4,10 +4,13 @@ import android.annotation.SuppressLint;
 import android.content.Context;
 import android.os.Handler;
 import android.os.Message;
+import android.text.Editable;
+import android.text.TextWatcher;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.ArrayAdapter;
+import android.widget.Button;
 import android.widget.CheckBox;
 import android.widget.EditText;
 import android.widget.ImageView;
@@ -71,6 +74,8 @@ public class BaseListAdapter extends ArrayAdapter<BaseModel> {
             view = LayoutInflater.from(getContext()).inflate(R.layout.item_checkbox, null);
         } else if (model.cellType == Constant.CellType.REFRESH) {
             view = LayoutInflater.from(getContext()).inflate(R.layout.item_refresh, null);
+        } else if (model.cellType == Constant.CellType.CANCEL_SURE) {
+            view = LayoutInflater.from(getContext()).inflate(R.layout.item_cancel_sure, null);
         }
 
         assert view != null;
@@ -80,9 +85,11 @@ public class BaseListAdapter extends ArrayAdapter<BaseModel> {
         ImageView itembackground = view.findViewById(R.id.item_background);
         ImageView itemIcon = view.findViewById(R.id.item_icon);
         ImageView itemArrow = view.findViewById(R.id.item_arrow);
-        Switch itemSwitch = view.findViewById(R.id.item_switch);
-        CheckBox itemCheckbox = view.findViewById(R.id.item_checkbox);
         IconProgressView iconProgressView = view.findViewById(R.id.item_icon_progress);
+        Switch switchButton = view.findViewById(R.id.item_switch);
+        CheckBox checkboxButton = view.findViewById(R.id.item_checkbox);
+        Button cancelButton = view.findViewById(R.id.button_cancel);
+        Button sureButton = view.findViewById(R.id.button_sure);
 
 
         if (itemTitle != null) {
@@ -100,9 +107,9 @@ public class BaseListAdapter extends ArrayAdapter<BaseModel> {
         if (itemArrow != null) {
             itemArrow.setVisibility(model.isShowArrow ? View.VISIBLE : View.GONE);
         }
-        if (itemSwitch != null) {
-            itemSwitch.setChecked(model.isOn);
-            itemSwitch.setOnCheckedChangeListener((compoundButton, b) -> {
+        if (switchButton != null) {
+            switchButton.setChecked(model.isOn);
+            switchButton.setOnCheckedChangeListener((compoundButton, b) -> {
                     if (mHandler == null)
                         return;
                     Message message = new Message();
@@ -113,11 +120,11 @@ public class BaseListAdapter extends ArrayAdapter<BaseModel> {
                 }
             );
         }
-        if (itemCheckbox != null) {
-            itemCheckbox.setChecked(model.isOn);
-            itemCheckbox.setEnabled(false);
-            itemCheckbox.setFocusable(false);
-            itemCheckbox.setOnCheckedChangeListener((compoundButton, b) -> {
+        if (checkboxButton != null) {
+            checkboxButton.setChecked(model.isOn);
+            checkboxButton.setEnabled(false);
+            checkboxButton.setFocusable(false);
+            checkboxButton.setOnCheckedChangeListener((compoundButton, b) -> {
                     if (mHandler == null)
                         return;
                     Message message = new Message();
@@ -132,6 +139,55 @@ public class BaseListAdapter extends ArrayAdapter<BaseModel> {
             //iconProgressView.setProgressColor(((IconProgressModel)model).progressColor);
             iconProgressView.setProgress100(((IconProgressModel)model).progress);
         }
+        if (cancelButton != null) {
+            cancelButton.setOnClickListener(new View.OnClickListener() {
+                @Override
+                public void onClick(View v) {
+                    if (mHandler == null)
+                        return;
+                    Message message = new Message();
+                    message.what = Constant.MSG_CANCEL_CLICK;
+                    mHandler.sendMessage(message);
+                }
+            });
+        }
+        if (sureButton != null) {
+            sureButton.setOnClickListener(new View.OnClickListener() {
+                @Override
+                public void onClick(View v) {
+                    if (mHandler == null)
+                        return;
+                    Message message = new Message();
+                    message.what = Constant.MSG_SURE_CLICK;
+                    mHandler.sendMessage(message);
+                }
+            });
+        }
+
+        if (itemEdit != null) {
+            TextWatcher watcher = new TextWatcher() {
+                @Override
+                public void beforeTextChanged(CharSequence s, int start, int count, int after) {
+
+                }
+                @Override
+                public void onTextChanged(CharSequence s, int start, int before, int count) {
+
+                }
+                @Override
+                public void afterTextChanged(Editable s) {
+                    if (mHandler == null)
+                        return;
+                    Message message = new Message();
+                    message.what = Constant.MSG_TEXTEDIT_FINISH;
+                    message.arg1 = position;
+                    message.obj = s.toString();
+                    mHandler.sendMessage(message);
+                }
+            };
+            itemEdit.addTextChangedListener(watcher);
+        }
+
         return view;
     }
 

+ 3 - 1
app/src/main/java/com/xplora/xpsettings/Model/ApnModel.java

@@ -1,6 +1,8 @@
 package com.xplora.xpsettings.Model;
 
-public class ApnModel {
+import java.io.Serializable;
+
+public class ApnModel implements Serializable {
     public String apn_name = "";
     public String user_name = "";
     public String password = "";

+ 5 - 0
app/src/main/java/com/xplora/xpsettings/Utils/Constant.java

@@ -10,10 +10,14 @@ public class Constant {
     public static String PACKAGE_NAME = "com.xplora.xpsettings";
     public static String INENT_VIEW_TYPE = "inent_view_type";
     public static String INENT_RESULT_ACTION = "inent_result_action";
+    public static String INENT_RESULT_ACTION_CANCEL = "inent_result_action_cancel";
     public static String INENT_RESULT_VALUE = "inent_result_value";
 
     public static final int MSG_SWITCHC_CHANGE = 0;
     public static final int MSG_CHECKBOX_CHANGE = 1;
+    public static final int MSG_CANCEL_CLICK = 2;
+    public static final int MSG_SURE_CLICK = 3;
+    public static final int MSG_TEXTEDIT_FINISH = 4;
 
     public enum CellType {
         TITLE,
@@ -28,6 +32,7 @@ public class Constant {
         SWITCH,
         CHECKBOX,
         REFRESH,
+        CANCEL_SURE,
     }
 
     public enum E_SEEKBAR_TYPE {

+ 43 - 0
app/src/main/res/layout/item_cancel_sure.xml

@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="wrap_content"
+    android:layout_height="wrap_content">
+
+    <RelativeLayout
+        android:layout_width="match_parent"
+        android:layout_height="50dp">
+
+        <Button
+            android:id="@+id/button_cancel"
+            android:layout_width="85dp"
+            android:layout_height="28dp"
+            android:layout_alignParentStart="true"
+            android:layout_centerVertical="true"
+            android:text="@string/button_cancel"
+            android:textSize="12sp"
+            android:textFontWeight="700"
+            android:fontFamily="Roboto"
+            android:paddingRight="15dp"
+            android:backgroundTint="@color/xp_red"
+            style="@style/xp_style_button_right"
+            />
+
+        <Button
+            android:id="@+id/button_sure"
+            android:layout_width="85dp"
+            android:layout_height="28dp"
+            android:layout_alignParentEnd="true"
+            android:layout_centerVertical="true"
+            android:text="@string/button_yes"
+            android:textSize="12sp"
+            android:textFontWeight="700"
+            android:fontFamily="Roboto"
+            android:paddingLeft="15dp"
+            android:backgroundTint="@color/xp_green"
+            style="@style/xp_style_button_left"
+            />
+
+    </RelativeLayout>
+
+</RelativeLayout>

+ 11 - 2
app/src/main/res/layout/item_title_edit.xml

@@ -17,19 +17,28 @@
             android:layout_centerVertical="true"
             android:fontFamily="Roboto"
             android:textColor="@color/white"
-            android:textSize="13sp" />
+            android:textSize="12sp" />
 
         <EditText
             android:id="@+id/item_edit"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_toEndOf="@id/item_title"
+            android:layout_marginStart="8dp"
             android:layout_marginEnd="8dp"
             android:layout_centerVertical="true"
             android:layout_alignParentEnd="true"
             android:fontFamily="Roboto"
             android:textColor="@color/white"
-            android:textSize="10sp"
+            android:textAlignment="textEnd"
+            android:textSize="12sp"
+            android:layout_gravity="center|end"
+            android:background="@null"
+            android:maxLines="1"
+            android:lines="1"
+            android:inputType="text"
+            android:imeOptions="actionNext"
+            tools:ignore="TextFields"
             />
 
     </RelativeLayout>