| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602 |
- package com.usai.apex;
- import android.app.AlertDialog;
- import android.content.DialogInterface;
- import android.content.Intent;
- import android.database.sqlite.SQLiteDatabase;
- import android.os.Bundle;
- import android.support.v4.app.Fragment;
- import android.support.v4.app.FragmentTransaction;
- import android.support.v7.app.ActionBar;
- import android.support.v7.app.AppCompatActivity;
- import android.text.TextUtils;
- import android.util.Log;
- import android.view.Gravity;
- import android.view.KeyEvent;
- import android.view.LayoutInflater;
- import android.view.Menu;
- import android.view.MenuItem;
- import android.view.View;
- import android.widget.EditText;
- import android.widget.FrameLayout;
- import android.widget.TabHost;
- import android.widget.TabWidget;
- import android.widget.TextView;
- import com.usai.apex.Result.AMResultActivity;
- import com.usai.apex.mainframe.RootActivity;
- import com.usai.util.commonUtil;
- import com.usai.util.dbUtil;
- import org.json.JSONException;
- import org.json.JSONObject;
- import java.util.HashMap;
- import java.util.Iterator;
- import java.util.LinkedHashMap;
- import java.util.List;
- public class DetailActivity extends AppCompatActivity implements
- TabHost.TabContentFactory
- {
- boolean showlogin = false;
- // int radomid = 1 + (int) (Math.random() * 15);
- TabHost mTabHost;
- LinkedHashMap<String, Integer> tabmap = new LinkedHashMap<String, Integer>();
- HashMap<String,String> contentmap = new HashMap<String ,String>();
- // HashMap<String, DetailFragment> fragments = new HashMap<String,
- // DetailFragment>();
- String function_name;
- String _id;
- String cargo_criterion;
- int criterion_type;
- String email_to = null,email_subject = null,email_content = null;
- TextView mtitleview;
- // @Override
- // public void setTitle(CharSequence title) {
- //// View mActionBarView = LayoutInflater.from(this).inflate(R.layout.actionbar_customtitle, null);
- ////
- //// TextView mtitleviewtitleview = mActionBarView.findViewById(R.id.title);
- //
- // if(title==null)
- // title="";
- // if(mtitleview!=null)
- // mtitleview.setText(title);
- // }
- private void setCustomActionBar() {
- ActionBar.LayoutParams lp =new ActionBar.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.MATCH_PARENT, Gravity.CENTER);
- View mActionBarView = LayoutInflater.from(this).inflate(R.layout.actionbar_customtitle, null);
- mtitleview= mActionBarView.findViewById(R.id.title);
- function_name = getIntent().getStringExtra("function_name");
- String title = "";
- if(function_name.equals("Ocean Booking"))
- title="Booking Detail";
- else if(function_name.equals("Ocean B/L info."))
- title="B/L info. Detail";
- else if(function_name.equals("Container detail"))
- title="Container Detail";
- else if(function_name.equals("Cargo Tracking"))
- title="Cargo Detail";
- mtitleview.setText(title);
- setTitle(title);
- //
- // mActionBarView.setBackgroundColor(Color.YELLOW);
- // titleview.setBackgroundColor(Color.BLUE);
- ActionBar actionBar = getSupportActionBar();
- actionBar.setCustomView(mActionBarView, lp);
- // actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
- // actionBar.setDisplayShowCustomEnabled(true);
- actionBar.setDisplayHomeAsUpEnabled(true);
- // actionBar.setIcon(getNumberDrawable());
- // actionBar.setDisplayShowHomeEnabled(true);
- actionBar.setDisplayShowTitleEnabled(true);
- }
- public DetailActivity get_instance()
- {
- return this;
- }
- // String email_to = null,email_subject = null,email_content = null;
- public void save_content(String which,String content)
- {
- contentmap.put(which, content);
- try {
- JSONObject jsonObject = new JSONObject(content);
- email_to = jsonObject.getString("email");
- email_subject = jsonObject.getString("email_subject");
- email_content = jsonObject.getString("email_content");
- } catch (JSONException e) {
- e.printStackTrace();
- }
- }
- @Override
- protected void onCreate(Bundle savedInstanceState)
- {
- Log.d("DetailActivity", "onCreate");
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_detail);
- setCustomActionBar();
- List<Fragment> fragments = getSupportFragmentManager().getFragments();
- if (fragments != null)
- {
- Log.d("DetailActivity", "fragments count=" + fragments.size());
- // for (int i = 0; i < fragments.size(); i++)
- // Log.e("DetailFragment", "fragment name="
- // + fragments.get(i).getTag());
- }
- if (savedInstanceState != null)
- {
- tabmap = (LinkedHashMap<String, Integer>) savedInstanceState
- .getSerializable("tabmap");
- contentmap = (HashMap<String, String>) savedInstanceState.getSerializable("contentmap");
- }
- else
- {
- int count = getIntent().getIntExtra("actions_count", 0);
- for (int i = 0; i < count; i++)
- {
- int vid = commonUtil.generateViewId();
- tabmap.put(getIntent().getStringExtra("action" + i), vid);
- }
- }
- function_name = getIntent().getStringExtra("function_name");
-
- if(function_name.equals("Ocean Booking"))
- setTitle("Booking Detail");
- else if(function_name.equals("Ocean B/L info."))
- setTitle("B/L info. Detail");
- else if(function_name.equals("Container detail"))
- setTitle("Container Detail");
- // else if(function_name.equals("Cargo Tracking"))
- // setTitle("Cargo Detail");
- //
-
- if (function_name.equals("Cargo Tracking"))
- {
- criterion_type = getIntent().getIntExtra("criterion_type", 0);
- cargo_criterion = getIntent().getStringExtra("cargo_criterion");
- setTitle("Cargo Detail");
- }
- _id = getIntent().getStringExtra("_id");
- setupTabs();
- }
- // @Override
- // protected void onSaveInstanceState(Bundle outState)
- // {
- // Iterator<String> iter=fragments.keySet().iterator();
- //
- // while (iter.hasNext())
- // {
- // String tag = (String) iter.next();
- // getSupportFragmentManager().putFragment(outState,tag,fragments.get(tag));
- //
- // }
- // outState.putStringArray("tags", fragments.keySet().toArray(new
- // String[0]));
- // Log.d("onSaveInstanceState","save fragments" +
- // fragments.keySet().size());
- // super.onSaveInstanceState(outState);
- // }
- //
- // @Override
- // protected void onRestoreInstanceState(Bundle savedInstanceState)
- // {
- // String [] tags =savedInstanceState.getStringArray("tags");
- // Log.d("onRestoreInstanceState","load fragments" + tags.length);
- // for(int i=0;i<tags.length;i++)
- // {
- // Log.d("onRestoreInstanceState","load fragment" + tags[i]);
- // fragments.put(tags[i],(DetailFragment)
- // getSupportFragmentManager().getFragment(savedInstanceState,tags[i]));
- // }
- //
- // super.onRestoreInstanceState(savedInstanceState);
- // }
- /** {@inheritDoc} */
- public View createTabContent(String tag)
- {
- FrameLayout fl = new FrameLayout(this);
- fl.setId(tabmap.get(tag));
- Fragment f;
- Bundle bundle = new Bundle();
- if (function_name.equals("Cargo Tracking"))
- {
- if (criterion_type == 0)
- bundle.putString("hbol", cargo_criterion);
- else
- bundle.putString("container_no", cargo_criterion);
- }
- bundle.putString("action_type", tag);
- bundle.putString("id", _id);
- bundle.putString("module_name", function_name);
- // Log.e("findFragmentByTag", "tag=" + tag + ", isnull= "
- // + (getSupportFragmentManager().findFragmentByTag(tag) == null));
- f = getSupportFragmentManager().findFragmentById(tabmap.get(tag));
- if (f == null)
- {
- Log.d("createTabContent", "create fragment" + tag);
- f = new DetailFragment();
-
- f.setArguments(bundle);
- }
- ((DetailFragment)f).set_content( contentmap.get(tag));
- FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
- ft.replace(fl.getId(), f);
- ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
- ft.addToBackStack(tag);
- ft.commit();
- return fl;
- }
- @Override
- protected void onSaveInstanceState(Bundle outState)
- {
- outState.putSerializable("tabmap", tabmap);
- outState.putSerializable("contentmap", contentmap);
- super.onSaveInstanceState(outState);
- }
- // TabHost mTabHost;
- // private FrameLayout mTabContent;
-
- // @Override
- // public boolean onKeyDown(int keyCode, KeyEvent event)
- // {
- // if (keyCode == KeyEvent.KEYCODE_BACK)
- // {
- // // Intent myIntent = new Intent();
- // // myIntent = new Intent(EditActivity.this, tabActivity.class);
- // // startActivity(myIntent);
- // finish();
- // return true;
- // }
- // return super.onKeyDown(keyCode, event);
- // }
- @Override
- public boolean onKeyUp(int keyCode, KeyEvent event)
- {
- if (keyCode == KeyEvent.KEYCODE_BACK)
- {
- // Intent myIntent = new Intent();
- // myIntent = new Intent(EditActivity.this, tabActivity.class);
- // startActivity(myIntent);
- finish();
- return true;
- }
- return super.onKeyUp(keyCode, event);
- }
- //
- // @Override
- // protected void onCreate(Bundle savedInstanceState)
- // {
- // super.onCreate(savedInstanceState);
- // setContentView(R.layout.activity_detail);
- // // Show the Up button in the action bar.
- // setupActionBar();
- // setupTabs();
- // }
- //
- // /**
- // * Set up the {@link android.app.ActionBar}.
- // */
- // private void setupActionBar()
- // {
- //
- // getActionBar().setDisplayHomeAsUpEnabled(true);
- //
- // }
- //
- // // private View createTabIndicatorView(ViewGroup parent, CharSequence
- // label, Drawable icon) {
- // // final LayoutInflater inflater = LayoutInflater.from(this);
- // // final View tabIndicator = inflater.inflate(R.layout.tab_indicator,
- // parent, false);
- // //
- // //// final TextView tv = (TextView)
- // tabIndicator.findViewById(R.id.tab_title);
- // //// tv.setText(label);
- // ////
- // //// final ImageView iconView = (ImageView)
- // tabIndicator.findViewById(R.id.tab_icon);
- // //// iconView.setImageDrawable(icon);
- // //
- // // return tabIndicator;
- // // }
- //
- // @Override
- // public View createTabContent(String tag)
- // {
- // final TextView tv = new TextView(this);
- // tv.setText("Content for tab with tag " + tag);
- // return tv;
- // }
- private void setupTabs()
- {
- mTabHost = (TabHost) findViewById(R.id.tabhost);
- // mTabContent = (FrameLayout) findViewById(android.R.id.tabcontent);
- // FrameLayout tab1 = new FrameLayout(this);
- mTabHost.setup();
- Iterator<String> iter = tabmap.keySet().iterator();
- while (iter.hasNext())
- {
- String name = (String) iter.next();
- mTabHost.addTab(mTabHost.newTabSpec(name).setIndicator(name)
- .setContent(this));
- // String val = (String) tabmap.get(field);
- // parms.putString(field, val);
- // // Cursor c = (Cursor) m_listadapter.getItem(key);
- // Log.d("@@@@@@@@@", field + " : " + val);
- }
- TabWidget tabWidget=mTabHost.getTabWidget();
- for (int i = 0; i < tabWidget.getChildCount(); i++) {
- tabWidget.getChildAt(i).getLayoutParams().height = commonUtil.dp2px(this,39);
- tabWidget.getChildAt(i).setPadding(24,0,24,0);
- // tabWidget.getChildAt(i).getLayoutParams().height = 60;
- TextView tv=(TextView)tabWidget.getChildAt(i).findViewById(android.R.id.title);
- // tv.setGravity(BIND_AUTO_CREATE);
- // tv.setPadding(10, 10,10, 10);
- tv.setTextSize(12);//设置字体的大小;
- // tv.setTextColor(Color.WHITE);//设置字体的颜色;
- //获取tabs图片;
- // ImageView iv=(ImageView)tabWidget.getChildAt(i).findViewById(android.R.id.icon);
- }
- // for (int i=1; i <= tabmap.size(); i++) {
- // String name = tabmap.keySet().iterator().;
- // mTabHost.addTab(mTabHost.newTabSpec(name)
- // .setIndicator(name)
- // .setContent(this));
- // }
- // // if(true)
- // // return;
- //
- // // View tab1 = createTabIndicatorView(mTabHost.getTabWidget(),
- // // "Login",null);
- // // tabhost.addTab(
- // // tabhost.newTabSpec("tab" + i).setIndicator(tab)
- // // .setContent(Mytabfirst.this)); tabhost.setCurrentTab(i);
- // // i++; tab = null;
- //
- // // // ��ɵײ��Զ�����ʽ�İ�ť
- // // String[] title = new String[] { "Login", "Not login" };
- // // int[] tabIds = new int[] { R.id.tab1, R.id.tab2 };
- // mTabHost.addTab(mTabHost.newTabSpec("Login").setIndicator("Login")
- // .setContent(this));
- // //
- // mTabHost.addTab(mTabHost.newTabSpec("Direct Tracking").setIndicator("Direct Tracking").setContent(R.id.tab2));
- // mTabHost.addTab(mTabHost.newTabSpec("Service Location")
- // .setIndicator("Service Location").setContent(this));
- // FragmentManager manager = this.getFragmentManager();
- // Instantiate a new fragment.
- // Fragment loginFragment = new LoginFragment();
- // // Fragment dtFragement = new DirectTrackingFragment();
- // Fragment slFragment = new ServiceLocationFragment();
- // // Add the fragment to the activity, pushing this transaction
- // // on to the back stack.
- //
- // FragmentTransaction ft =
- // getSupportFragmentManager().beginTransaction();
- // ft.replace(mTabHost.getTabContentView().getChildAt(0).getId(),
- // loginFragment);
- // ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
- // ft.addToBackStack("Login");
- //
- // // ft.replace(R.id.tab2, dtFragement);
- // // ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
- // // ft.addToBackStack("Tracking");
- //
- // ft.replace(R.id.tab3, (Fragment) slFragment);
- // ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
- // ft.addToBackStack("Location");
- //
- // ft.commit();
- // if (manager.findFragmentByTag(tabId) == null)
- // {
- // FragmentTransaction trans = manager.beginTransaction();
- // trans.replace(contentViewID, frag, tabId);
- // trans.commit();
- // }
- // for (int i = 0; i < title.length; i++) {
- // Button button = new Button(this);
- // button.setText(title[i]);
- // button.setBackgroundDrawable(this.getResources().getDrawable(
- // R.drawable.tab_lable)); //�Զ��尴ť��ʽ
- // mTabHost.addTab(mTabHost.newTabSpec(title[i]).setIndicator(button)
- // .setContent(tabIds[i]));
- // }
- // mTabHost.setOnTabChangedListener(this);
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu)
- {
- // Inflate the menu; this adds items to the action bar if it is present.
- if (function_name.equals("Cargo Tracking")) {
- getMenuInflater().inflate(R.menu.cargo_menu, menu);
- } else {
- getMenuInflater().inflate(R.menu.detail, menu);
- }
- return true;
- }
- @Override
- public boolean onOptionsItemSelected(MenuItem item)
- {
- switch (item.getItemId())
- {
- case R.id.action_close:
- finish();
- // if (SearchResultActivity.instance != null) {
- // SearchResultActivity.instance.finish();
- // }
- // if (SearchListActivity.instance != null) {
- // SearchListActivity.instance.finish();
- // }
- Intent intent = new Intent(this, RootActivity.class);
- startActivity(intent);
- break;
- case android.R.id.home:
- finish();
- break;
- case R.id.action_addto_favorite:
- // LayoutInflater factory = LayoutInflater.from(this);
- // final View textEntryView = factory.inflate(R.layout.alert_dialog_text_entry, null);
- final View edit = new EditText(this);
- new AlertDialog.Builder(this)
- .setIconAttribute(android.R.attr.alertDialogIcon)
- .setTitle(R.string.str_createname)
- .setView(edit)
- .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int whichButton) {
- String name = ((EditText)edit).getText().toString();
- if(TextUtils.isEmpty(name))
- {
- new android.app.AlertDialog.Builder(DetailActivity.this)
- .setTitle("Warning")
- .setMessage("Name can not be empty.")
- .setPositiveButton("OK", new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- }
- })
- .show();
- return;
- }
- String param = getIntent().toUri(0);
- SQLiteDatabase db = dbUtil.OpenDB(
- ApexTrackingApplication.get_instance(), null, true);
- db.execSQL("insert into favorites(name,params,user,create_time,module_name) values('"
- + name
- + "','"
- + param
- + "','"
- + ApexTrackingApplication.get_user()
- + "',"
- + System.currentTimeMillis()
- + ",'"
- +getIntent().getStringExtra("function_name")+ "')");
- dbUtil.CloseDB(db);
- /* User clicked OK so do some stuff */
- }
- })
- .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int whichButton) {
- /* User clicked cancel so do some stuff */
- }
- })
- .create().show();
- return true;
- case R.id.action_search_document: {
- String cargo_str = contentmap.get("Tracking");
- try {
- JSONObject cargo_json = new JSONObject(cargo_str);
- String hbol = cargo_json.optString("hbol");
- if (hbol != null && hbol.length() > 0) {
- Bundle parms = new Bundle();
- parms.putString("bol",hbol);
- parms.putString("module_name","Download Document");
- Intent resultIntent = new Intent(this, AMResultActivity.class);
- resultIntent.putExtra("query_params",parms);
- startActivity(resultIntent);
- } else {
- showAlter("There is no hbol to search");
- }
- } catch (JSONException e) {
- e.printStackTrace();
- showAlter("There is no hbol to search");
- }
- }
- break;
- case R.id.action_share_detail: {
- Intent share = new Intent();
- share.setAction(Intent.ACTION_SEND);
- // share.putExtra(Intent.EXTRA_STREAM, uri);
- share.setType("text/plain");
- if (email_content != null) {
- share.putExtra(Intent.EXTRA_TEXT, email_content); //附带的说明信息
- }
- if (email_subject != null) {
- share.putExtra(Intent.EXTRA_SUBJECT, email_subject);
- }
- if (email_to != null) {
- share.putExtra(Intent.EXTRA_EMAIL, email_to.split(","));
- }
- // share.putExtra(Intent.EXTRA_CC, new String[]{"ray.zhang@united-cn.net"});
- // startActivity(Intent.createChooser(share,getString(R.string.str_sendto)));
- startActivity(Intent.createChooser(share, "Share"));
- }
- break;
- }
- return super.onOptionsItemSelected(item);
- }
- public void showAlter(String msg) {
- new AlertDialog.Builder(this)
- .setMessage(msg)
- .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialogInterface, int i) {
- }
- })
- .show();
- }
- }
|