| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291 |
- package com.usai.apex;
- import java.util.HashMap;
- import java.util.Iterator;
- import java.util.LinkedHashMap;
- import com.usai.util.commonUtil;
- import android.R.integer;
- import android.os.Bundle;
- import android.util.Log;
- import android.view.KeyEvent;
- import android.view.Menu;
- import android.view.MenuInflater;
- 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;
- LinkedHashMap<String, Integer> tabmap = new LinkedHashMap<String, Integer>();
- // HashMap<String, DetailFragment> fragments = new HashMap<String,
- // DetailFragment>();
- String function_name;
- String _id;
- @Override
- protected void onCreate(Bundle savedInstanceState)
- {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_detail);
- int count = getIntent().getIntExtra("actions_count", 0);
- for (int i = 0; i < count; i++)
- {
- tabmap.put(getIntent().getStringExtra("action" + i),
- commonUtil.generateViewId());
- }
- function_name = getIntent().getStringExtra("function_name");
- _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();
- bundle.putString("action_type", tag);
- bundle.putString("id", _id);
- bundle.putString("module_name", function_name);
- Log.d("createTabContent", "create fragment" + tag);
- f = new DetailFragment();
- f.setArguments(bundle);
- 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<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);
- }
- // 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);
- }
- }
|