|
@@ -0,0 +1,444 @@
|
|
|
|
|
+package com.usai.ratradefiling.home;
|
|
|
|
|
+
|
|
|
|
|
+import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
|
+
|
|
|
|
|
+import android.app.AlertDialog;
|
|
|
|
|
+import android.content.Context;
|
|
|
|
|
+import android.content.DialogInterface;
|
|
|
|
|
+import android.content.SharedPreferences;
|
|
|
|
|
+import android.content.pm.PackageManager;
|
|
|
|
|
+import android.os.Bundle;
|
|
|
|
|
+import android.view.LayoutInflater;
|
|
|
|
|
+import android.view.Menu;
|
|
|
|
|
+import android.view.MenuItem;
|
|
|
|
|
+import android.view.View;
|
|
|
|
|
+import android.view.ViewGroup;
|
|
|
|
|
+import android.widget.ArrayAdapter;
|
|
|
|
|
+import android.widget.Button;
|
|
|
|
|
+import android.widget.TextView;
|
|
|
|
|
+
|
|
|
|
|
+import com.usai.ratradefiling.R;
|
|
|
|
|
+import com.usai.ratradefiling.TradeFilingApplication;
|
|
|
|
|
+import com.usai.ratradefiling.dataprovider.RADataProvider;
|
|
|
|
|
+import com.usai.ratradefiling.fields.CustomizeFieldsActivity;
|
|
|
|
|
+import com.usai.ratradefiling.fields.DragListView;
|
|
|
|
|
+import com.usai.redant.rautils.utils.FileManager;
|
|
|
|
|
+import com.usai.redant.rautils.utils.RAConverter;
|
|
|
|
|
+
|
|
|
|
|
+import org.json.JSONArray;
|
|
|
|
|
+import org.json.JSONException;
|
|
|
|
|
+import org.json.JSONObject;
|
|
|
|
|
+
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+
|
|
|
|
|
+public class FunctionPanelSettingActivity extends AppCompatActivity implements
|
|
|
|
|
+ View.OnClickListener, DragListView.DragListViewDelegate
|
|
|
|
|
+{
|
|
|
|
|
+ //
|
|
|
|
|
+ // @Override
|
|
|
|
|
+ // protected void onCreate(Bundle savedInstanceState)
|
|
|
|
|
+ // {
|
|
|
|
|
+ // super.onCreate(savedInstanceState);
|
|
|
|
|
+ // setContentView(R.layout.activity_customize_fields);
|
|
|
|
|
+ // }
|
|
|
|
|
+ //
|
|
|
|
|
+// @Override
|
|
|
|
|
+// public boolean onCreateOptionsMenu(Menu menu)
|
|
|
|
|
+// {
|
|
|
|
|
+// // Inflate the menu; this adds items to the action bar if it is present.
|
|
|
|
|
+// getMenuInflater().inflate(R.menu.customize_fields, menu);
|
|
|
|
|
+// return true;
|
|
|
|
|
+// }
|
|
|
|
|
+
|
|
|
|
|
+ // private static List<fieldedit> list = null;
|
|
|
|
|
+ private FunctionPanelSettingActivity.DragListAdapter adapter = null;
|
|
|
|
|
+
|
|
|
|
|
+ // public static List<String> groupKey = new ArrayList<String>();
|
|
|
|
|
+ private static List<JSONObject> list = null;
|
|
|
|
|
+ private List<JSONObject> showList = null;
|
|
|
|
|
+ private List<JSONObject> hideList = null;
|
|
|
|
|
+ // private List<fieldedit> showList = new ArrayList<fieldedit>();
|
|
|
|
|
+// private List<fieldedit> hideList = new ArrayList<fieldedit>();
|
|
|
|
|
+ private String user/* ,password */;
|
|
|
|
|
+// private int behavior;
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public boolean dragListViewCanMoveItem(DragListView dragListView, int from, int to) {
|
|
|
|
|
+
|
|
|
|
|
+ int hidePosition = adapter.getPosition(mHideField);
|
|
|
|
|
+ // hide -> display && displayCount >= maxDisplayCount
|
|
|
|
|
+// if (from > hidePosition && to < hidePosition && hidePosition > maxDisplayCount) {
|
|
|
|
|
+//
|
|
|
|
|
+// new AlertDialog.Builder(this)
|
|
|
|
|
+// .setTitle("Warning")
|
|
|
|
|
+// .setMessage("the maximums count of display items is " + maxDisplayCount)
|
|
|
|
|
+// .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
|
|
|
|
|
+// @Override
|
|
|
|
|
+// public void onClick(DialogInterface dialog, int which) {
|
|
|
|
|
+//
|
|
|
|
|
+// }
|
|
|
|
|
+// })
|
|
|
|
|
+// .show();
|
|
|
|
|
+//
|
|
|
|
|
+// return false;
|
|
|
|
|
+// }
|
|
|
|
|
+
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public class fieldedit
|
|
|
|
|
+ {
|
|
|
|
|
+ public String name = null;
|
|
|
|
|
+ public int _id = -1;
|
|
|
|
|
+
|
|
|
|
|
+ public fieldedit(String str, int i)
|
|
|
|
|
+ {
|
|
|
|
|
+ name = str;
|
|
|
|
|
+ _id = i;
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+// private boolean forNewResult = false;
|
|
|
|
|
+// private int maxDisplayCount = 0;
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onCreate(Bundle savedInstanceState)
|
|
|
|
|
+ {
|
|
|
|
|
+ super.onCreate(savedInstanceState);
|
|
|
|
|
+
|
|
|
|
|
+ user = TradeFilingApplication.get_user();
|
|
|
|
|
+ // password = getIntent().getStringExtra("password");
|
|
|
|
|
+
|
|
|
|
|
+// forNewResult = getIntent().getBooleanExtra("forNewResult", false);
|
|
|
|
|
+// maxDisplayCount = getIntent().getIntExtra("maxDisplayCount", 0);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ setContentView(R.layout.activity_function_panel_setting);
|
|
|
|
|
+ Button btnok = (Button) findViewById(R.id.btnok);
|
|
|
|
|
+ btnok.setOnClickListener(this);
|
|
|
|
|
+ Button btncancel = (Button) findViewById(R.id.btncancel);
|
|
|
|
|
+ btncancel.setOnClickListener(this);
|
|
|
|
|
+
|
|
|
|
|
+ initData();
|
|
|
|
|
+
|
|
|
|
|
+ DragListView dragListView = (DragListView) findViewById(R.id.drag_list);
|
|
|
|
|
+//
|
|
|
|
|
+// if (forNewResult) {
|
|
|
|
|
+//
|
|
|
|
|
+// dragListView.setDelegate(this);
|
|
|
|
|
+// }
|
|
|
|
|
+
|
|
|
|
|
+ adapter = new FunctionPanelSettingActivity.DragListAdapter(this, list);
|
|
|
|
|
+ dragListView.setAdapter(adapter);
|
|
|
|
|
+
|
|
|
|
|
+// SharedPreferences RunOnce = getSharedPreferences("Apex", 0);
|
|
|
|
|
+
|
|
|
|
|
+// String vername;
|
|
|
|
|
+// try
|
|
|
|
|
+// {
|
|
|
|
|
+// vername = getPackageManager().getPackageInfo(
|
|
|
|
|
+// "com.usai.apex", 0).versionName;
|
|
|
|
|
+// boolean bFirstRun = RunOnce.getBoolean(
|
|
|
|
|
+// "FirstRun"+vername+"_fields", true);
|
|
|
|
|
+//// if(bFirstRun&&false)
|
|
|
|
|
+//// {
|
|
|
|
|
+//// SharedPreferences.Editor editor = RunOnce.edit();
|
|
|
|
|
+//// editor.putBoolean("FirstRun"+vername+"_fields", false);
|
|
|
|
|
+//// // Don't forget to commit your edits!!!
|
|
|
|
|
+//// editor.commit();
|
|
|
|
|
+//// Intent intent = new Intent();
|
|
|
|
|
+//// intent.setClass(this, HelpActivity.class);
|
|
|
|
|
+//// intent.putExtra("caller", "fields");
|
|
|
|
|
+//// startActivity(intent);
|
|
|
|
|
+////
|
|
|
|
|
+//// }
|
|
|
|
|
+// }
|
|
|
|
|
+// catch (PackageManager.NameNotFoundException e)
|
|
|
|
|
+// {
|
|
|
|
|
+// // TODO Auto-generated catch block
|
|
|
|
|
+// e.printStackTrace();
|
|
|
|
|
+// }
|
|
|
|
|
+ }
|
|
|
|
|
+// @Override
|
|
|
|
|
+// public boolean onOptionsItemSelected(MenuItem item)
|
|
|
|
|
+// {
|
|
|
|
|
+// switch (item.getItemId())
|
|
|
|
|
+// {
|
|
|
|
|
+//// case R.id.action_help:
|
|
|
|
|
+//// Intent intent = new Intent();
|
|
|
|
|
+//// intent.setClass(this, HelpActivity.class);
|
|
|
|
|
+//// intent.putExtra("caller", "fields");
|
|
|
|
|
+////// // intent.putExtra("password", password);
|
|
|
|
|
+////// intent.putExtra("function_name", function_name);
|
|
|
|
|
+////// intent.putExtra("behavior", Network.BEHAVIOR_SEARCH);
|
|
|
|
|
+//// startActivity(intent);
|
|
|
|
|
+//// break;
|
|
|
|
|
+//
|
|
|
|
|
+// default:
|
|
|
|
|
+// break;
|
|
|
|
|
+// }
|
|
|
|
|
+// return super.onOptionsItemSelected(item);
|
|
|
|
|
+// }
|
|
|
|
|
+
|
|
|
|
|
+ private JSONObject mDisplayField, mHideField;
|
|
|
|
|
+ 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())
|
|
|
|
|
+// {
|
|
|
|
|
+// int show = cursor.getInt(1);
|
|
|
|
|
+// if (show == 1)
|
|
|
|
|
+// showList.add(new fieldedit(cursor.getString(0), cursor
|
|
|
|
|
+// .getInt(2)));
|
|
|
|
|
+// else
|
|
|
|
|
+// {
|
|
|
|
|
+// hideList.add(new fieldedit(cursor.getString(0), cursor
|
|
|
|
|
+// .getInt(2)));
|
|
|
|
|
+//
|
|
|
|
|
+// }
|
|
|
|
|
+// }
|
|
|
|
|
+ try
|
|
|
|
|
+ {
|
|
|
|
|
+ JSONObject fields = RADataProvider.updateFunctionPanel();
|
|
|
|
|
+
|
|
|
|
|
+// JSONObject.parseArray(array.toJSONString(), JSONObject.class);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ showList= RAConverter.JsonArray2List(fields.optJSONArray("active_functions")) ;
|
|
|
|
|
+ hideList= RAConverter.JsonArray2List(fields.optJSONArray("deactive_functions")) ;
|
|
|
|
|
+// fields.getJSONArray("hide");
|
|
|
|
|
+ // ��ݽ��
|
|
|
|
|
+ list = new ArrayList<JSONObject>();
|
|
|
|
|
+
|
|
|
|
|
+ // groupKey��ŵ��Ƿ����ǩ
|
|
|
|
|
+ // groupKey.add("Display fields");
|
|
|
|
|
+ // groupKey.add("Hide fields");
|
|
|
|
|
+
|
|
|
|
|
+ // for (int i = 0; i < 5; i++)
|
|
|
|
|
+ // {
|
|
|
|
|
+ // navList.add("Aѡ��" + i);
|
|
|
|
|
+ // }
|
|
|
|
|
+// if (forNewResult) {
|
|
|
|
|
+// mDisplayField = new fieldedit("Additional Fields To Display", -1);
|
|
|
|
|
+// } else {
|
|
|
|
|
+// mDisplayField = new fieldedit(getString(R.string.str_displayitem), -1);
|
|
|
|
|
+// }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ mDisplayField= new JSONObject("{\"name\":\"My Functions\",\"id\":-1}");
|
|
|
|
|
+ list.add(mDisplayField);
|
|
|
|
|
+ list.addAll(showList);
|
|
|
|
|
+ mHideField = new JSONObject("{\"name\":\"All Functions\",\"id\":-2}");
|
|
|
|
|
+ list.add(mHideField);
|
|
|
|
|
+ list.addAll(hideList);
|
|
|
|
|
+ } catch (Exception e)
|
|
|
|
|
+ {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ // for (int i = 0; i <18; i++)
|
|
|
|
|
+ // {
|
|
|
|
|
+ // moreList.add("Bѡ��" + i);
|
|
|
|
|
+ // }
|
|
|
|
|
+// if (forNewResult) {
|
|
|
|
|
+// mHideField = new fieldedit("Additional Fields", -2);
|
|
|
|
|
+// } else {
|
|
|
|
|
+// mHideField = new fieldedit(getString(R.string.str_hideitem), -2);
|
|
|
|
|
+// }
|
|
|
|
|
+
|
|
|
|
|
+// dbUtil.CloseCursor(cursor);
|
|
|
|
|
+// dbUtil.CloseDB(db);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public static class DragListAdapter extends ArrayAdapter<JSONObject>
|
|
|
|
|
+ {
|
|
|
|
|
+
|
|
|
|
|
+ // private Context mContext;
|
|
|
|
|
+
|
|
|
|
|
+ public DragListAdapter(Context context, List<JSONObject> objects)
|
|
|
|
|
+ {
|
|
|
|
|
+ super(context, 0, objects);
|
|
|
|
|
+ // this.mContext = context;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public List<JSONObject> getList()
|
|
|
|
|
+ {
|
|
|
|
|
+ return list;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public boolean isEnabled(int position)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (getItem(position).optInt("id") < 0) // _id<0 means a group key
|
|
|
|
|
+ return false;
|
|
|
|
|
+ // if (groupKey.contains(getItem(position).name))
|
|
|
|
|
+ // {
|
|
|
|
|
+ // // ����Ƿ����ǩ������false������ѡ�У����ܵ��
|
|
|
|
|
+ // return false;
|
|
|
|
|
+ // }
|
|
|
|
|
+ return super.isEnabled(position);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public int switchpos()
|
|
|
|
|
+ {
|
|
|
|
|
+
|
|
|
|
|
+ for (int i = 1; i < getCount(); i++)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (getItem(i).optInt("id") < 0)
|
|
|
|
|
+ return i;
|
|
|
|
|
+ }
|
|
|
|
|
+ return -1;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public View getView(int position, View convertView, ViewGroup parent)
|
|
|
|
|
+ {
|
|
|
|
|
+
|
|
|
|
|
+ View view = convertView;
|
|
|
|
|
+ if (getItem(position).optInt("id") < 0) // _id<0 means a group key
|
|
|
|
|
+ {
|
|
|
|
|
+ view = LayoutInflater.from(getContext()).inflate(
|
|
|
|
|
+ R.layout.drag_list_item_tag, null);
|
|
|
|
|
+ }
|
|
|
|
|
+ // if (groupKey.contains(getItem(position).name))
|
|
|
|
|
+ // {
|
|
|
|
|
+ // // ����Ƿ����ǩ���ͼ��ط����ǩ�IJ����ļ������������ļ���ʾЧ��ͬ
|
|
|
|
|
+ // view = LayoutInflater.from(getContext()).inflate(
|
|
|
|
|
+ // R.layout.drag_list_item_tag, null);
|
|
|
|
|
+ // }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ // �������������ǩ���ͼ����������IJ����ļ�
|
|
|
|
|
+ view = LayoutInflater.from(getContext()).inflate(
|
|
|
|
|
+ R.layout.drag_list_item, null);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ TextView textView = (TextView) view
|
|
|
|
|
+ .findViewById(R.id.drag_list_item_text);
|
|
|
|
|
+ textView.setText(getItem(position).optString("name"));
|
|
|
|
|
+
|
|
|
|
|
+ return view;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onClick(View v)
|
|
|
|
|
+ {
|
|
|
|
|
+ switch (v.getId())
|
|
|
|
|
+ {
|
|
|
|
|
+ case R.id.btnok:
|
|
|
|
|
+ {
|
|
|
|
|
+ // DragListView dragListView = (DragListView)
|
|
|
|
|
+ // findViewById(R.id.drag_list);
|
|
|
|
|
+// if (!forNewResult) {
|
|
|
|
|
+// int count = 0;
|
|
|
|
|
+// for (int i = 0; i < adapter.getCount(); i++)
|
|
|
|
|
+// {
|
|
|
|
|
+// JSONObject item = adapter.getItem(i);
|
|
|
|
|
+// if (item.optInt("id",0)== -2 || count > 0)
|
|
|
|
|
+// break;
|
|
|
|
|
+// if (item.optInt("id",0) >= 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;
|
|
|
|
|
+// showList.clear();
|
|
|
|
|
+// hideList.clear();
|
|
|
|
|
+// SQLiteDatabase db = dbUtil.OpenDB(this, null, true);
|
|
|
|
|
+// db.beginTransaction();
|
|
|
|
|
+ JSONArray jarr_show = new JSONArray();
|
|
|
|
|
+ JSONArray jarr_hide = new JSONArray();
|
|
|
|
|
+ for (int i = 0; i < adapter.getCount(); i++)
|
|
|
|
|
+ {
|
|
|
|
|
+ JSONObject item = adapter.getItem(i);
|
|
|
|
|
+ if (item.optInt("id",0) == -2)// hide group begin
|
|
|
|
|
+ {
|
|
|
|
|
+ show = 0;
|
|
|
|
|
+ }
|
|
|
|
|
+ if(item.optInt("id",0)<0)
|
|
|
|
|
+ continue;
|
|
|
|
|
+ if (show == 1 )
|
|
|
|
|
+ jarr_show.put(item);
|
|
|
|
|
+// showList.add(item);
|
|
|
|
|
+// db.execSQL("update fields_info set show=" + show
|
|
|
|
|
+// + " ,priority=" + i + " where _id=" + fe._id);
|
|
|
|
|
+ else
|
|
|
|
|
+ jarr_hide.put(item);
|
|
|
|
|
+// hideList.add(item);
|
|
|
|
|
+// db.execSQL("update fields_info set show=" + show
|
|
|
|
|
+// + " where _id=" + fe._id);
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ JSONObject fields = RADataProvider.updateFunctionPanel();
|
|
|
|
|
+ try
|
|
|
|
|
+ {
|
|
|
|
|
+ fields.put("active_functions",jarr_show);
|
|
|
|
|
+ fields.put("deactive_functions",jarr_hide);
|
|
|
|
|
+ String userfilePath = TradeFilingApplication.get_instance().getFilesDir().getPath()+"/FunctionPanel_"+user+".json";
|
|
|
|
|
+ FileManager.writeJson(fields.toString(),userfilePath);
|
|
|
|
|
+
|
|
|
|
|
+ } catch (JSONException e)
|
|
|
|
|
+ {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+// 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
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+}
|
|
|
|
|
+//
|
|
|
|
|
+//{
|
|
|
|
|
+//
|
|
|
|
|
+// @Override
|
|
|
|
|
+// protected void onCreate(Bundle savedInstanceState)
|
|
|
|
|
+// {
|
|
|
|
|
+// super.onCreate(savedInstanceState);
|
|
|
|
|
+// setContentView(R.layout.activity_function_panel_setting);
|
|
|
|
|
+// }
|
|
|
|
|
+//}
|