|
@@ -0,0 +1,271 @@
|
|
|
|
|
+package com.usai.apex;
|
|
|
|
|
+
|
|
|
|
|
+import java.util.HashMap;
|
|
|
|
|
+import java.util.Iterator;
|
|
|
|
|
+
|
|
|
|
|
+import com.usai.util.commonUtil;
|
|
|
|
|
+
|
|
|
|
|
+import android.os.Bundle;
|
|
|
|
|
+import android.view.KeyEvent;
|
|
|
|
|
+import android.view.Menu;
|
|
|
|
|
+import android.view.MenuItem;
|
|
|
|
|
+import android.view.View;
|
|
|
|
|
+import android.widget.FrameLayout;
|
|
|
|
|
+import android.widget.TabHost;
|
|
|
|
|
+import android.support.v4.app.Fragment;
|
|
|
|
|
+import android.support.v4.app.FragmentActivity;
|
|
|
|
|
+import android.support.v4.app.FragmentTransaction;
|
|
|
|
|
+import android.support.v4.app.NavUtils;
|
|
|
|
|
+
|
|
|
|
|
+public class DetailActivity extends FragmentActivity implements
|
|
|
|
|
+ TabHost.TabContentFactory
|
|
|
|
|
+{
|
|
|
|
|
+ // int radomid = 1 + (int) (Math.random() * 15);
|
|
|
|
|
+ TabHost mTabHost;
|
|
|
|
|
+ HashMap<String, Integer> tabmap = new HashMap<String, Integer>();
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ protected void onCreate(Bundle savedInstanceState)
|
|
|
|
|
+ {
|
|
|
|
|
+ super.onCreate(savedInstanceState);
|
|
|
|
|
+
|
|
|
|
|
+ setContentView(R.layout.activity_detail);
|
|
|
|
|
+
|
|
|
|
|
+ if (getIntent().getBooleanExtra("Detail", true))
|
|
|
|
|
+ tabmap.put("Detail", commonUtil.generateViewId());
|
|
|
|
|
+ if (getIntent().getBooleanExtra("Tracking", false))
|
|
|
|
|
+ tabmap.put("Tracking", commonUtil.generateViewId());
|
|
|
|
|
+ if (getIntent().getBooleanExtra("AMS LOG", false))
|
|
|
|
|
+ tabmap.put("AMS LOG", commonUtil.generateViewId());
|
|
|
|
|
+ if (getIntent().getBooleanExtra("ISF LOG", false))
|
|
|
|
|
+ tabmap.put("ISF LOG", commonUtil.generateViewId());
|
|
|
|
|
+
|
|
|
|
|
+ // final TabHost tabHost = getTabHost();
|
|
|
|
|
+ // mTabHost = (TabHost) findViewById(R.id.tabhost);
|
|
|
|
|
+
|
|
|
|
|
+ setupTabs();
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /** {@inheritDoc} */
|
|
|
|
|
+ public View createTabContent(String tag)
|
|
|
|
|
+ {
|
|
|
|
|
+ // final TextView tv = new TextView(this);
|
|
|
|
|
+ // tv.setText("Content for tab with tag " + tag);
|
|
|
|
|
+ FrameLayout fl = new FrameLayout(this);
|
|
|
|
|
+ fl.setId(tabmap.get(tag));
|
|
|
|
|
+
|
|
|
|
|
+ Fragment f;
|
|
|
|
|
+ Bundle bundle = new Bundle();
|
|
|
|
|
+ bundle.putSerializable("type", "tag");
|
|
|
|
|
+
|
|
|
|
|
+ if (tag.equals("Detail"))
|
|
|
|
|
+ f = new DetailFragment();
|
|
|
|
|
+ else
|
|
|
|
|
+ if (tag.equals("Tracking"))
|
|
|
|
|
+ f = new StatusFragment();
|
|
|
|
|
+ else
|
|
|
|
|
+ if (tag.equals("AMS LOG"))
|
|
|
|
|
+ {
|
|
|
|
|
+ f = new CBPFragment();
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ /* if(tag.equals("AMS LOG")) */
|
|
|
|
|
+ f = new CBPFragment();
|
|
|
|
|
+
|
|
|
|
|
+ f.setArguments(bundle);
|
|
|
|
|
+ // 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(fl.getId(), f);
|
|
|
|
|
+ ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
|
|
|
|
|
+ ft.addToBackStack(tag);
|
|
|
|
|
+ ft.commit();
|
|
|
|
|
+ return fl;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 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
|
|
|
|
|
+ // 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 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);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 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.
|
|
|
|
|
+ getMenuInflater().inflate(R.menu.detail, menu);
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public boolean onOptionsItemSelected(MenuItem item)
|
|
|
|
|
+ {
|
|
|
|
|
+ switch (item.getItemId())
|
|
|
|
|
+ {
|
|
|
|
|
+ case android.R.id.home:
|
|
|
|
|
+ // This ID represents the Home or Up button. In the case of this
|
|
|
|
|
+ // activity, the Up button is shown. Use NavUtils to allow users
|
|
|
|
|
+ // to navigate up one level in the application structure. For
|
|
|
|
|
+ // more details, see the Navigation pattern on Android Design:
|
|
|
|
|
+ //
|
|
|
|
|
+ //
|
|
|
|
|
+ // http: //
|
|
|
|
|
+ // developer.android.com/design/patterns/navigation.html#up-vs-back
|
|
|
|
|
+ //
|
|
|
|
|
+ NavUtils.navigateUpFromSameTask(this);
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ return super.onOptionsItemSelected(item);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+}
|