|
|
@@ -3,22 +3,25 @@ package com.usai.apex;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
-import com.usai.util.Network;
|
|
|
import com.usai.util.dbUtil;
|
|
|
|
|
|
import android.os.Bundle;
|
|
|
import android.app.Activity;
|
|
|
+import android.app.AlertDialog;
|
|
|
import android.content.Context;
|
|
|
+import android.content.DialogInterface;
|
|
|
+//import android.content.DialogInterface.OnClickListener;
|
|
|
import android.database.Cursor;
|
|
|
import android.database.sqlite.SQLiteDatabase;
|
|
|
import android.view.LayoutInflater;
|
|
|
-import android.view.Menu;
|
|
|
import android.view.View;
|
|
|
+import android.view.View.OnClickListener;
|
|
|
import android.view.ViewGroup;
|
|
|
import android.widget.ArrayAdapter;
|
|
|
+import android.widget.Button;
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
-public class CustomizeFieldsActivity extends Activity
|
|
|
+public class CustomizeFieldsActivity extends Activity implements OnClickListener
|
|
|
{
|
|
|
//
|
|
|
// @Override
|
|
|
@@ -36,36 +39,45 @@ public class CustomizeFieldsActivity extends Activity
|
|
|
// return true;
|
|
|
// }
|
|
|
|
|
|
+
|
|
|
+
|
|
|
private static List<fieldedit> list = null;
|
|
|
private DragListAdapter adapter = null;
|
|
|
|
|
|
- public static List<fieldedit> groupKey = new ArrayList<fieldedit>();
|
|
|
+ // public static List<String> groupKey = new ArrayList<String>();
|
|
|
private List<fieldedit> showList = new ArrayList<fieldedit>();
|
|
|
- private List<fieldedit> notshowList = new ArrayList<fieldedit>();
|
|
|
- private String user/*,password*/,function_name;
|
|
|
+ private List<fieldedit> hideList = new ArrayList<fieldedit>();
|
|
|
+ private String user/* ,password */, function_name;
|
|
|
private int behavior;
|
|
|
|
|
|
public class fieldedit
|
|
|
{
|
|
|
- public String name=null;
|
|
|
- public int _id=-1;
|
|
|
- public fieldedit(String str,int i)
|
|
|
+ public String name = null;
|
|
|
+ public int _id = -1;
|
|
|
+
|
|
|
+ public fieldedit(String str, int i)
|
|
|
{
|
|
|
- name=str;
|
|
|
- _id=i;
|
|
|
-
|
|
|
+ name = str;
|
|
|
+ _id = i;
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
@Override
|
|
|
public void onCreate(Bundle savedInstanceState)
|
|
|
{
|
|
|
super.onCreate(savedInstanceState);
|
|
|
-
|
|
|
+
|
|
|
user = getIntent().getStringExtra("user");
|
|
|
-// password = getIntent().getStringExtra("password");
|
|
|
+ // password = getIntent().getStringExtra("password");
|
|
|
function_name = getIntent().getStringExtra("function_name");
|
|
|
behavior = getIntent().getIntExtra("behavior", -1);
|
|
|
setContentView(R.layout.activity_customize_fields);
|
|
|
+ Button btnok= (Button)findViewById(R.id.btnok);
|
|
|
+ btnok.setOnClickListener(this);
|
|
|
+ Button btncancel= (Button)findViewById(R.id.btncancel);
|
|
|
+ btncancel.setOnClickListener(this);
|
|
|
+
|
|
|
|
|
|
initData();
|
|
|
|
|
|
@@ -77,40 +89,43 @@ public class CustomizeFieldsActivity extends Activity
|
|
|
public void initData()
|
|
|
{
|
|
|
SQLiteDatabase db = dbUtil.OpenDB(this, null, false);
|
|
|
- Cursor cursor = db.query("fields_info",
|
|
|
- new String[] { "aname","show", "_id" },
|
|
|
- "function_name='"+function_name+"' and user='"+user+"' and behavior="+behavior,
|
|
|
- null, null, null, "priority , aname", null);
|
|
|
- while(cursor.moveToNext())
|
|
|
+ Cursor cursor = db.query("fields_info", new String[] { "aname", "show",
|
|
|
+ "_id" }, "function_name='" + function_name + "' and user='"
|
|
|
+ + user + "' and behavior=" + behavior, null, null, null,
|
|
|
+ "priority , aname", null);
|
|
|
+ while (cursor.moveToNext())
|
|
|
{
|
|
|
int show = cursor.getInt(1);
|
|
|
- if(show==1)
|
|
|
- showList.add(new fieldedit(cursor.getString(0),cursor.getInt(2)));
|
|
|
- else {
|
|
|
- notshowList.add(new fieldedit(cursor.getString(0),cursor.getInt(2)));
|
|
|
-
|
|
|
+ if (show == 1)
|
|
|
+ showList.add(new fieldedit(cursor.getString(0), cursor
|
|
|
+ .getInt(2)));
|
|
|
+ else
|
|
|
+ {
|
|
|
+ hideList.add(new fieldedit(cursor.getString(0), cursor
|
|
|
+ .getInt(2)));
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
// 数据结果
|
|
|
list = new ArrayList<fieldedit>();
|
|
|
|
|
|
// groupKey存放的是分组标签
|
|
|
- groupKey.add(new fieldedit("Display fields",-1));
|
|
|
- groupKey.add(new fieldedit("Hide fields",-1));
|
|
|
-
|
|
|
-// for (int i = 0; i < 5; i++)
|
|
|
-// {
|
|
|
-// navList.add("A选项" + i);
|
|
|
-// }
|
|
|
- list.add(new fieldedit("Display fields",-1));
|
|
|
+ // groupKey.add("Display fields");
|
|
|
+ // groupKey.add("Hide fields");
|
|
|
+
|
|
|
+ // for (int i = 0; i < 5; i++)
|
|
|
+ // {
|
|
|
+ // navList.add("A选项" + i);
|
|
|
+ // }
|
|
|
+ list.add(new fieldedit("Display fields", -1));
|
|
|
list.addAll(showList);
|
|
|
|
|
|
-// for (int i = 0; i <18; i++)
|
|
|
-// {
|
|
|
-// moreList.add("B选项" + i);
|
|
|
-// }
|
|
|
- list.add(new fieldedit("Hide fields",-1));
|
|
|
- list.addAll(notshowList);
|
|
|
+ // for (int i = 0; i <18; i++)
|
|
|
+ // {
|
|
|
+ // moreList.add("B选项" + i);
|
|
|
+ // }
|
|
|
+ list.add(new fieldedit("Hide fields", -2));
|
|
|
+ list.addAll(hideList);
|
|
|
dbUtil.CloseCursor(cursor);
|
|
|
dbUtil.CloseDB(db);
|
|
|
}
|
|
|
@@ -118,12 +133,12 @@ public class CustomizeFieldsActivity extends Activity
|
|
|
public static class DragListAdapter extends ArrayAdapter<fieldedit>
|
|
|
{
|
|
|
|
|
|
-// private Context mContext;
|
|
|
+ // private Context mContext;
|
|
|
|
|
|
public DragListAdapter(Context context, List<fieldedit> objects)
|
|
|
{
|
|
|
super(context, 0, objects);
|
|
|
-// this.mContext = context;
|
|
|
+ // this.mContext = context;
|
|
|
}
|
|
|
|
|
|
public List<fieldedit> getList()
|
|
|
@@ -134,11 +149,13 @@ public class CustomizeFieldsActivity extends Activity
|
|
|
@Override
|
|
|
public boolean isEnabled(int position)
|
|
|
{
|
|
|
- if (groupKey.contains(getItem(position)))
|
|
|
- {
|
|
|
- // 如果是分组标签,返回false,不能选中,不能点击
|
|
|
+ if (getItem(position)._id < 0) //_id<0 means a group key
|
|
|
return false;
|
|
|
- }
|
|
|
+ // if (groupKey.contains(getItem(position).name))
|
|
|
+ // {
|
|
|
+ // // 如果是分组标签,返回false,不能选中,不能点击
|
|
|
+ // return false;
|
|
|
+ // }
|
|
|
return super.isEnabled(position);
|
|
|
}
|
|
|
|
|
|
@@ -147,12 +164,17 @@ public class CustomizeFieldsActivity extends Activity
|
|
|
{
|
|
|
|
|
|
View view = convertView;
|
|
|
- if (groupKey.contains(getItem(position)))
|
|
|
+ if(getItem(position)._id<0) //_id<0 means a group key
|
|
|
{
|
|
|
- // 如果是分组标签,就加载分组标签的布局文件,两个布局文件显示效果不同
|
|
|
view = LayoutInflater.from(getContext()).inflate(
|
|
|
- R.layout.drag_list_item_tag, null);
|
|
|
+ R.layout.drag_list_item_tag, null);
|
|
|
}
|
|
|
+// if (groupKey.contains(getItem(position).name))
|
|
|
+// {
|
|
|
+// // 如果是分组标签,就加载分组标签的布局文件,两个布局文件显示效果不同
|
|
|
+// view = LayoutInflater.from(getContext()).inflate(
|
|
|
+// R.layout.drag_list_item_tag, null);
|
|
|
+// }
|
|
|
else
|
|
|
{
|
|
|
// 如果是正常数据项标签,就加在正常数据项的布局文件
|
|
|
@@ -168,4 +190,77 @@ public class CustomizeFieldsActivity extends Activity
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void onClick(View v)
|
|
|
+ {
|
|
|
+ switch (v.getId())
|
|
|
+ {
|
|
|
+ case R.id.btnok:
|
|
|
+ {
|
|
|
+// DragListView dragListView = (DragListView) findViewById(R.id.drag_list);
|
|
|
+ int count=0;
|
|
|
+ for(int i=0;i<adapter.getCount();i++)
|
|
|
+ {
|
|
|
+ fieldedit fe=adapter.getItem(i);
|
|
|
+ if(fe._id==-2||count>0)
|
|
|
+ break;
|
|
|
+ if(fe._id>=0)
|
|
|
+ count++;
|
|
|
+
|
|
|
+ }
|
|
|
+ if(count==0)
|
|
|
+ {
|
|
|
+ new AlertDialog.Builder(CustomizeFieldsActivity.this)
|
|
|
+ .setIcon(android.R.drawable.ic_dialog_info)
|
|
|
+ .setTitle("Error!")
|
|
|
+ .setMessage("You must set at least 1 field visiable!")
|
|
|
+ .setPositiveButton("OK",
|
|
|
+ new DialogInterface.OnClickListener()
|
|
|
+ {
|
|
|
+ public void onClick(
|
|
|
+ DialogInterface dialog,
|
|
|
+ int whichButton)
|
|
|
+ {
|
|
|
+
|
|
|
+// finish();
|
|
|
+ /* User clicked OK so do some stuff */
|
|
|
+ }
|
|
|
+ }).show();
|
|
|
+ break;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ int show = 1;
|
|
|
+ SQLiteDatabase db= dbUtil.OpenDB(this, null, true);
|
|
|
+ db.beginTransaction();
|
|
|
+ for(int i=0;i<adapter.getCount();i++)
|
|
|
+ {
|
|
|
+ fieldedit fe=adapter.getItem(i);
|
|
|
+ if(fe._id==-2)//hide group begin
|
|
|
+ {
|
|
|
+ show = 0;
|
|
|
+ }
|
|
|
+ if(show==1)
|
|
|
+ db.execSQL("update fields_info set show="+show+" ,priority="+i+" where _id="+fe._id);
|
|
|
+ else
|
|
|
+ db.execSQL("update fields_info set show="+show+" where _id="+fe._id);
|
|
|
+
|
|
|
+ }
|
|
|
+ db.setTransactionSuccessful();
|
|
|
+ db.endTransaction();
|
|
|
+ dbUtil.CloseDB(db);
|
|
|
+ finish();
|
|
|
+// Log.d("fields",);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case R.id.btncancel:
|
|
|
+ finish();
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ // TODO Auto-generated method stub
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
}
|