Skip to content

Commit c3ac76e

Browse files
committed
加入条件查询
1 parent cf15c63 commit c3ac76e

10 files changed

+313
-17
lines changed

app/build.gradle

+2
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,6 @@ dependencies {
2626
androidTestImplementation 'com.android.support.test:runner:1.0.2'
2727
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
2828
implementation files('libs/commons-beanutils-1.8.0.jar')
29+
//AutoSizeLayout
30+
implementation 'me.jessyan:autosize:1.0.5'
2931
}

app/src/main/AndroidManifest.xml

+7
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,19 @@
33
package="com.hasee.oracledatabase">
44
<uses-permission android:name="android.permission.INTERNET"/>
55
<application
6+
android:name=".BaseApplication"
67
android:allowBackup="true"
78
android:icon="@drawable/logo"
89
android:label="@string/app_name"
910
android:roundIcon="@drawable/logo"
1011
android:supportsRtl="true"
1112
android:theme="@style/AppTheme">
13+
<meta-data
14+
android:name="design_width_in_dp"
15+
android:value="360"/>
16+
<meta-data
17+
android:name="design_height_in_dp"
18+
android:value="640"/>
1219
<activity android:name=".MainActivity">
1320
<intent-filter>
1421
<action android:name="android.intent.action.MAIN" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Copyright 2018 JessYan
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.hasee.oracledatabase;
17+
18+
import android.app.Activity;
19+
import android.app.Application;
20+
import android.util.DisplayMetrics;
21+
22+
import me.jessyan.autosize.AutoSize;
23+
import me.jessyan.autosize.AutoSizeConfig;
24+
import me.jessyan.autosize.external.ExternalAdaptInfo;
25+
import me.jessyan.autosize.external.ExternalAdaptManager;
26+
import me.jessyan.autosize.internal.CustomAdapt;
27+
28+
/**
29+
* ================================================
30+
* v0.9.1 发布后新增了副单位,可以在 pt、in、mm 三个冷门单位中选择一个作为副单位,然后在 layout 文件中使用副单位进行布局
31+
* 副单位可以规避修改 {@link DisplayMetrics#density} 所造成的对于其他使用 dp 布局的系统控件或三方库控件的不良影响
32+
* 使用副单位后可直接在 AndroidManifest 中填写设计图上的像素尺寸,不需要再将像素转化为 dp
33+
* <a href="https://github.com/JessYanCoding/AndroidAutoSize/blob/master/README-zh.md#preview">点击查看在布局中的实时预览方式</a>
34+
* <p>
35+
* 本框架核心原理来自于 <a href="https://mp.weixin.qq.com/s/d9QCoBP6kV9VSWvVldVVwA">今日头条官方适配方案</a>
36+
* <p>
37+
* 本框架源码的注释都很详细, 欢迎阅读学习
38+
* <p>
39+
* AndroidAutoSize 会在 APP 启动时自动完成初始化, 如果您想设置自定义参数可以在 {@link Application#onCreate()} 中设置
40+
* <p>
41+
* Created by JessYan on 2018/8/9 17:05
42+
* <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
43+
* <a href="https://github.com/JessYanCoding">Follow me</a>
44+
* ================================================
45+
*/
46+
public class BaseApplication extends Application {
47+
@Override
48+
public void onCreate() {
49+
super.onCreate();
50+
/**
51+
* 以下是 AndroidAutoSize 可以自定义的参数, {@link AutoSizeConfig} 的每个方法的注释都写的很详细
52+
* 使用前请一定记得跳进源码,查看方法的注释, 下面的注释只是简单描述!!!
53+
*/
54+
AutoSizeConfig.getInstance()
55+
56+
//是否让框架支持自定义 Fragment 的适配参数, 由于这个需求是比较少见的, 所以须要使用者手动开启
57+
//如果没有这个需求建议不开启
58+
.setCustomFragment(true)
59+
60+
//是否打印 AutoSize 的内部日志, 默认为 true, 如果您不想 AutoSize 打印日志, 则请设置为 false
61+
// .setLog(false)
62+
63+
//是否使用设备的实际尺寸做适配, 默认为 false, 如果设置为 false, 在以屏幕高度为基准进行适配时
64+
//AutoSize 会将屏幕总高度减去状态栏高度来做适配, 如果设备上有导航栏还会减去导航栏的高度
65+
//设置为 true 则使用设备的实际屏幕高度, 不会减去状态栏以及导航栏高度
66+
// .setUseDeviceSize(true)
67+
68+
//是否全局按照宽度进行等比例适配, 默认为 true, 如果设置为 false, AutoSize 会全局按照高度进行适配
69+
// .setBaseOnWidth(false)
70+
71+
//设置屏幕适配逻辑策略类, 一般不用设置, 使用框架默认的就好
72+
// .setAutoAdaptStrategy(new AutoAdaptStrategy())
73+
;
74+
//当 App 中出现多进程, 并且您需要适配所有的进程, 就需要在 App 初始化时调用 initCompatMultiProcess()
75+
//在 Demo 中跳转的三方库中的 DefaultErrorActivity 就是在另外一个进程中, 所以要想适配这个 Activity 就需要调用 initCompatMultiProcess()
76+
// AutoSize.initCompatMultiProcess(this);
77+
}
78+
79+
}

app/src/main/java/com/hasee/oracledatabase/MainActivity.java

+12-5
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.hasee.oracledatabase.fragment.AddFragment;
2727
import com.hasee.oracledatabase.fragment.DeleteFragment;
2828
import com.hasee.oracledatabase.fragment.HandleDialog;
29+
import com.hasee.oracledatabase.fragment.SelectSingleFragment;
2930
import com.hasee.oracledatabase.fragment.ShowMsgFragment;
3031
import com.hasee.oracledatabase.fragment.UpdateFragment;
3132
import com.hasee.oracledatabase.util.SocketUtil;
@@ -57,6 +58,8 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
5758
private DeleteFragment deleteFragment;//删除页面
5859
private UpdateFragment updateFragment;//更新页面
5960
private HandleDialog handleDialog = new HandleDialog();//处理框
61+
private SelectSingleFragment selectSingleFragment;//条件查询
62+
private ShowMsgFragment showMsgFragment;//操作框
6063

6164
@Override
6265
protected void onCreate(Bundle savedInstanceState) {
@@ -94,6 +97,9 @@ public boolean onOptionsItemSelected(MenuItem item) {
9497
case android.R.id.home:
9598
drawerLayout.openDrawer(Gravity.LEFT);
9699
break;
100+
case R.id.refresh_menu:
101+
selectAllData();
102+
break;
97103
case R.id.clear_data://清空本地缓存
98104
objectList.clear();
99105
adapter.notifyDataSetChanged();
@@ -107,16 +113,14 @@ public boolean onOptionsItemSelected(MenuItem item) {
107113
deleteFragment = new DeleteFragment();
108114
deleteFragment.show(getSupportFragmentManager(), "delete_dialog");
109115
break;
110-
case R.id.update_menu:
111-
// updateFragment = new UpdateFragment();
112-
// updateFragment.show(getSupportFragmentManager(), "update_dialog");
113-
break;
114116
case R.id.select_menu_all:
115117
JSONArray jsonArray = new JSONArray();
116118
jsonArray.add(3);
117119
sendMessageToServer(jsonArray.toString());
118120
break;
119121
case R.id.select_menu_single:
122+
selectSingleFragment = new SelectSingleFragment();
123+
selectSingleFragment.show(getSupportFragmentManager(),"selectSingle_dialog");
120124
// new Thread(new Runnable() {
121125
// @Override
122126
// public void run() {
@@ -292,7 +296,7 @@ public void sendMessage(JSONObject jsonObject) {
292296
bundle.putSerializable("jsonItem",jsonObject);
293297
switch (flag){
294298
case 0:
295-
ShowMsgFragment showMsgFragment = new ShowMsgFragment();
299+
showMsgFragment = new ShowMsgFragment();
296300
showMsgFragment.setArguments(bundle);
297301
showMsgFragment.show(getSupportFragmentManager(),"showMsg_dialog");
298302
break;
@@ -329,6 +333,9 @@ public void handleMessage(Message msg) {
329333
if(updateFragment != null){
330334
updateFragment.dismiss();
331335
}
336+
if(selectSingleFragment != null){
337+
selectSingleFragment.dismiss();
338+
}
332339
closeProgressDialog();
333340
selectAllData();
334341
showToast("操作成功");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
package com.hasee.oracledatabase.fragment;
2+
3+
import android.content.Context;
4+
import android.os.Bundle;
5+
import android.support.annotation.NonNull;
6+
import android.support.annotation.Nullable;
7+
import android.support.v4.app.DialogFragment;
8+
import android.view.LayoutInflater;
9+
import android.view.View;
10+
import android.view.ViewGroup;
11+
import android.widget.AdapterView;
12+
import android.widget.ArrayAdapter;
13+
import android.widget.Button;
14+
import android.widget.EditText;
15+
import android.widget.Spinner;
16+
import android.widget.TextView;
17+
18+
import com.hasee.oracledatabase.MyListener;
19+
import com.hasee.oracledatabase.R;
20+
21+
import net.sf.json.JSONArray;
22+
23+
public class SelectSingleFragment extends DialogFragment {
24+
private TextView selectSingleFragmentNumberTv, selectSingleFragmentNameTv, selectSingleFragmentAgeTv;
25+
private Button selectSingleSubmitButton;
26+
private Spinner selectSingleSpinner;
27+
private String[] selectItem = new String[]{"=",">","<",">=","<="};
28+
private ArrayAdapter<String> adapter;
29+
private String item = "=";
30+
private JSONArray jsonArray;
31+
private MyListener listener;
32+
33+
@Override
34+
public void onAttach(Context context) {
35+
super.onAttach(context);
36+
listener = (MyListener)getActivity();
37+
}
38+
39+
@Nullable
40+
@Override
41+
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
42+
View view = inflater.inflate(R.layout.select_single_dialog,container,false);
43+
selectSingleFragmentNumberTv = (EditText)view.findViewById(R.id.selectSingleFragment_number_tv);
44+
selectSingleFragmentNameTv = (EditText)view.findViewById(R.id.selectSingleFragment_name_tv);
45+
selectSingleFragmentAgeTv = (EditText)view.findViewById(R.id.selectSingleFragment_age_tv);
46+
selectSingleSpinner = (Spinner)view.findViewById(R.id.selectSingle_spinner);
47+
adapter = new ArrayAdapter<String>(getActivity(),android.R.layout.simple_spinner_item,selectItem);
48+
selectSingleSpinner.setAdapter(adapter);
49+
selectSingleSpinner.setOnItemSelectedListener(onItemSelectedListener);
50+
selectSingleSubmitButton = (Button)view.findViewById(R.id.selectSingle_submit_button);
51+
selectSingleSubmitButton.setOnClickListener(new View.OnClickListener() {
52+
@Override
53+
public void onClick(View view) {
54+
jsonArray = new JSONArray();
55+
String number = selectSingleFragmentNumberTv.getText().toString().trim();
56+
String name = selectSingleFragmentNameTv.getText().toString().trim();
57+
String age = selectSingleFragmentAgeTv.getText().toString().trim();
58+
jsonArray.add("7");
59+
if(!"".equals(number)){
60+
jsonArray.add("s_number="+"'"+number+"'");
61+
}
62+
if (!"".equals(name)){
63+
jsonArray.add("s_name="+"'"+name+"'");
64+
}
65+
if(!"".equals(age)){
66+
jsonArray.add("s_age"+item+age);
67+
}
68+
listener.sendMessageToServer(jsonArray.toString());
69+
}
70+
});
71+
return view;
72+
}
73+
74+
public AdapterView.OnItemSelectedListener onItemSelectedListener = new AdapterView.OnItemSelectedListener() {
75+
@Override
76+
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
77+
switch (i){
78+
case 0:
79+
item = "=";
80+
break;
81+
case 1:
82+
item = ">";
83+
break;
84+
case 2:
85+
item = "<";
86+
break;
87+
case 3:
88+
item = ">=";
89+
break;
90+
case 4:
91+
item = "<=";
92+
break;
93+
}
94+
}
95+
96+
@Override
97+
public void onNothingSelected(AdapterView<?> adapterView) {
98+
99+
}
100+
};
101+
}
2.13 KB
Loading
Binary file not shown.

app/src/main/res/layout/handle_dialog.xml

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
<LinearLayout
88
android:layout_width="match_parent"
99
android:layout_height="wrap_content"
10-
android:gravity="center">
10+
android:gravity="center"
11+
android:background="@color/toolBar_bg">
1112
<TextView
1213
android:layout_width="wrap_content"
1314
android:layout_height="wrap_content"
1415
android:text="操作表"
15-
android:layout_margin="10dp"/>
16+
android:textColor="#fff"
17+
android:layout_margin="10dp" />
1618
</LinearLayout>
1719
<LinearLayout
1820
android:layout_width="match_parent"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:layout_width="match_parent"
4+
android:layout_height="wrap_content"
5+
android:orientation="vertical">
6+
<RelativeLayout
7+
android:layout_width="match_parent"
8+
android:layout_height="wrap_content"
9+
android:background="@color/toolBar_bg">
10+
<TextView
11+
android:layout_width="wrap_content"
12+
android:layout_height="wrap_content"
13+
android:layout_margin="10dp"
14+
android:text="条件查询"
15+
android:textColor="#fff"
16+
android:layout_centerInParent="true"/>
17+
</RelativeLayout>
18+
<LinearLayout
19+
android:layout_width="300dp"
20+
android:layout_height="wrap_content"
21+
android:layout_margin="10dp"
22+
android:layout_gravity="center"
23+
android:orientation="horizontal">
24+
<TextView
25+
android:layout_width="0dp"
26+
android:layout_height="wrap_content"
27+
android:layout_weight="1"
28+
android:gravity="center"
29+
android:text="number:"/>
30+
<EditText
31+
android:id="@+id/selectSingleFragment_number_tv"
32+
android:layout_width="0dp"
33+
android:layout_height="wrap_content"
34+
android:layout_weight="4"
35+
android:gravity="center"
36+
android:inputType="number"
37+
android:hint="选填(例:201600840)"
38+
android:maxLines="1"/>
39+
</LinearLayout>
40+
<LinearLayout
41+
android:layout_width="300dp"
42+
android:layout_height="wrap_content"
43+
android:layout_margin="10dp"
44+
android:layout_gravity="center"
45+
android:orientation="horizontal">
46+
<TextView
47+
android:layout_width="0dp"
48+
android:layout_height="wrap_content"
49+
android:layout_weight="1"
50+
android:gravity="center"
51+
android:text="name:"/>
52+
<EditText
53+
android:id="@+id/selectSingleFragment_name_tv"
54+
android:layout_width="0dp"
55+
android:layout_height="wrap_content"
56+
android:layout_weight="4"
57+
android:gravity="center"
58+
android:hint="选填(例:张三)"
59+
android:maxLines="1"/>
60+
</LinearLayout>
61+
<LinearLayout
62+
android:layout_width="300dp"
63+
android:layout_height="wrap_content"
64+
android:layout_margin="10dp"
65+
android:layout_gravity="center"
66+
android:orientation="horizontal">
67+
<TextView
68+
android:layout_width="0dp"
69+
android:layout_height="wrap_content"
70+
android:layout_weight="1"
71+
android:gravity="center"
72+
android:text="age:"/>
73+
<Spinner
74+
android:id="@+id/selectSingle_spinner"
75+
android:layout_width="0dp"
76+
android:layout_height="wrap_content"
77+
android:layout_weight="2"
78+
android:layout_gravity="center"
79+
android:gravity="center">
80+
81+
</Spinner>
82+
<EditText
83+
android:id="@+id/selectSingleFragment_age_tv"
84+
android:layout_width="0dp"
85+
android:layout_height="wrap_content"
86+
android:layout_weight="2"
87+
android:gravity="center"
88+
android:hint="选填(例:>20)"
89+
android:inputType="number"
90+
android:maxLines="1"/>
91+
</LinearLayout>
92+
<Button
93+
android:id="@+id/selectSingle_submit_button"
94+
android:layout_width="wrap_content"
95+
android:layout_height="wrap_content"
96+
android:layout_gravity="center"
97+
android:layout_marginBottom="20dp"
98+
android:text="确定"/>
99+
</LinearLayout>

0 commit comments

Comments
 (0)