Java 类android.app.ActionBar.Tab 实例源码

项目:LibVNCAndroid    文件:TabListener.java   
/**
 * @brief Method called when the tab is selected
 * @param tab
 * @param ft
 * @details Method called when the tab is selected
 */
@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
    // Check if the fragment is already initialized
      mFragment = mActivity.getFragmentManager().findFragmentByTag(mTag);
      mActivity.getSupportFragmentManager().findFragmentByTag(mTag);
    if (mFragment == null) {
      // If not, instantiate and add it to the activity
      mFragment = Fragment.instantiate(
                        mActivity, mClass.getName());
      //mFragment.setProviderId(mTag); // id for event provider
      setmTransaction(ft);
      ft.add(android.R.id.content, mFragment, mTag);
    } else {
      // If it exists, simply attach it in order to show it
        setmTransaction(ft);
      ft.attach(mFragment);
    }


  }
项目:LibVNCAndroid    文件:TabListener.java   
/**
 * @brief Method called when the tab is unselected
 * @param tab
 * @param ft
 * @details Method called when the tab is unselected
 */
@Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {

      if (mFragment != null) {
      // Detach the fragment, because another one is being attached
      ft.detach(mFragment);
    }

  }
项目:kill-you-power-consumer    文件:ListPackages.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // this.setContentView(R.layout.layout_main);

    ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    actionBar.setDisplayShowTitleEnabled(true);

    Tab customerTab = actionBar.newTab().setText(
            this.getResources().getString(R.string.customer_tab));
    final Fragment customerPackageList = new CustomerPackageFragment(this);
    customerTab.setTabListener(new PackageTabListener(customerPackageList));

    Tab systemTab = actionBar.newTab().setText(
            this.getResources().getString(R.string.system_tab));
    final Fragment systemPackageList = new SystemPackageFragment(this);
    systemTab.setTabListener(new PackageTabListener(systemPackageList));

    actionBar.addTab(customerTab);
    actionBar.addTab(systemTab);
}
项目:AndroidAdapters    文件:MainActivity.java   
@Override
public void onTabSelected(final Tab tab, final FragmentTransaction ft) {
    if (fragment == null) {
        fragment = Fragment.instantiate(MainActivity.this, clazz.getName());
        ft.replace(R.id.fragment_container, fragment, clazz.getSimpleName());
    } else if (fragment.isDetached()) {
        ft.attach(fragment);
    }

    currentFragment = fragment;

    if (searchView != null) {
        searchView.setOnQueryTextListener(null);
        searchView.setQuery(null, false);
        searchView.setOnQueryTextListener(createSearchQueryListener());
    }
}
项目:sdl_mobileweather_tutorial_android    文件:MainActivity.java   
@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
    Fragment fragment = null;
    /*if (tab.getPosition() == 0) {
        fragment = new AlertsFragment();
    }
    else if (tab.getPosition() == 1) {
        fragment = new ConditionsFragment();
    }
    else if (tab.getPosition() == 2) {
        fragment = new ForecastFragment();
    }*/
    if (tab.getPosition() == 0) {
        fragment = new ConditionsFragment();
    }
    else if (tab.getPosition() == 1) {
        fragment = new ForecastFragment();
    }

    if (fragment != null) {
        mCurrentFragment = fragment;
        getFragmentManager().beginTransaction().replace(R.id.content_frame, fragment).commit();
    }
}
项目:ischool-oppia-mobile    文件:CourseActivity.java   
public void onTabSelected(Tab tab, FragmentTransaction ft) {
    int tabSelected = tab.getPosition();
    Log.d(TAG, "Tab selected " + tabSelected + " current act " + currentActivityNo);

    if (canNavigateTo(tabSelected)){
        viewPager.setCurrentItem(tabSelected);
        currentActivityNo = tabSelected;
        this.stopReading();
        WidgetFactory currentWidget = (WidgetFactory) apAdapter.getItem(currentActivityNo);
        currentWidget.resetTimeTracking();
    }
    else{
        Runnable setPreviousTab = new Runnable(){
            @Override
            public void run() {
                UIUtils.showAlert(CourseActivity.this, R.string.sequencing_dialog_title, R.string.sequencing_section_message);
                actionBar.setSelectedNavigationItem(currentActivityNo);
                viewPager.setCurrentItem(currentActivityNo);
            }
        };
        Handler handler=new Handler();
        handler.post(setPreviousTab);
    }
}
项目:sample-gallery-android    文件:MainActivity.java   
@Override
protected void onResume() {
    super.onResume();
    // Select proper stack
    ActionBar actionBar = getActionBar();
    if (actionBar != null) {
        Tab tab = actionBar.getSelectedTab();
        Stack<String> backStack = backStacks.get(tab.getTag());
        if (!backStack.isEmpty()) {
            // Restore topmost fragment (e.g. after application switch)
            String tag = backStack.peek();
            Fragment fragment = getFragmentManager().findFragmentByTag(tag);
            if (fragment.isDetached()) {
                FragmentTransaction ft = getFragmentManager().beginTransaction();
                ft.attach(fragment);
                ft.commit();
            }
        }
    }
}
项目:sample-gallery-android    文件:MainActivity.java   
@Override
protected void onPause() {
    super.onPause();
    // Select proper stack
    ActionBar actionBar = getActionBar();
    if (actionBar != null) {
        Tab tab = actionBar.getSelectedTab();
        Stack<String> backStack = backStacks.get(tab.getTag());
        if (!backStack.isEmpty()) {
            // Detach topmost fragment otherwise it will not be correctly
            // displayed
            // after orientation change
            String tag = backStack.peek();
            FragmentTransaction ft = getFragmentManager().beginTransaction();
            Fragment fragment = getFragmentManager().findFragmentByTag(tag);
            ft.detach(fragment);
            ft.commit();
        }
    }
}
项目:sample-gallery-android    文件:MainActivity.java   
@Override
public void onTabReselected(Tab tab, FragmentTransaction ft) {
    // Select proper stack
    Stack<String> backStack = backStacks.get(tab.getTag());

    if (backStack.size() > 1) {
        // ft.setCustomAnimations(R.anim.slide_from_right,
        // R.anim.slide_to_left);
        // Clean the stack leaving only initial fragment
        while (backStack.size() > 1) {
            // Pop topmost fragment
            String tag = backStack.pop();
            Fragment fragment = getFragmentManager().findFragmentByTag(tag);
            // Remove it
            ft.remove(fragment);
        }
    }
    showFragment(backStack, ft);
}
项目:sample-gallery-android    文件:MainActivity.java   
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    // Select proper stack
    ActionBar actionBar = getActionBar();
    if (actionBar != null) {
        Tab tab = actionBar.getSelectedTab();
        Stack<String> backStack = backStacks.get(tab.getTag());
        Fragment fragment = getFragmentManager().findFragmentByTag(backStack.peek());

        // Passing the Activity Result for the child fragment
        if (fragment != null) {
            fragment.onActivityResult(requestCode, resultCode, data);
        }
    }
}
项目:sample-gallery-android    文件:MainActivity.java   
public void addFragment(Fragment fragment) {
    // Select proper stack
    ActionBar actionBar = getActionBar();
    if (actionBar != null) {
        Tab tab = actionBar.getSelectedTab();
        Stack<String> backStack = backStacks.get(tab.getTag());

        FragmentTransaction ft = getFragmentManager().beginTransaction();

        // Get topmost fragment
        String tag = backStack.peek();
        Fragment top = getFragmentManager().findFragmentByTag(tag);
        if (top != null) {
            ft.detach(top);
        }
        // Add new fragment
        addFragment(fragment, backStack, ft);
        ft.commit();
    }
}
项目:sample-gallery-android    文件:MainActivity.java   
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
        // do something on back.
        ActionBar actionBar = getActionBar();
        if (actionBar != null) {
            Tab tabSelected = actionBar.getSelectedTab();
            if (tabSelected.getText().equals(getString(R.string.tab__list))) {
                finish();
                moveTaskToBack(true);
            } else {
                getActionBar().selectTab(actionBar.newTab().setTag(TabType.LIST).setText(R.string.tab__list).setTabListener(this));
            }
        }
    }
    return super.onKeyDown(keyCode, event);
}
项目:CalendarMute    文件:MainActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    ActionBar ab = getActionBar();
    ab.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Add tabs
    Tab tab = ab.newTab()
            .setText(R.string.agendas)
            .setTabListener(new CalendarMuteTabListener<>(this, TAG_TAB_CALENDARS, CalendarsFragment.class));
    ab.addTab(tab);

    tab = ab.newTab()
            .setText(R.string.actions)
            .setTabListener(new CalendarMuteTabListener<>(this, TAG_TAB_ACTIONS, ActionsFragment.class));
    ab.addTab(tab);

    if(ACTION_SHOW_ACTIONS.equals(getIntent().getAction()))
        ab.setSelectedNavigationItem(1); // Show actions tab
    if(savedInstanceState != null && savedInstanceState.containsKey(KEY_SAVED_CURRENT_TAB))
        ab.setSelectedNavigationItem(savedInstanceState.getInt(KEY_SAVED_CURRENT_TAB));

    // Start service
    MuteService.startIfNecessary(this);
}
项目:unofficial-linkedin-sdk-android    文件:EventTabsAdapter.java   
public void addTab(Tab tab, Class<?> clss, Event event){
    TabInfo info = new TabInfo(clss, event);
    tab.setTag(info);
    tab.setTabListener(this);
    mTabs.add(info);
       mFragments.add(EventFragment.newInstance(event));
    mActionBar.addTab(tab);
    notifyDataSetChanged();
}
项目:unofficial-linkedin-sdk-android    文件:EventTabsAdapter.java   
@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
    mViewPager.setCurrentItem(tab.getPosition());
    Object tag = tab.getTag();
    for (int i = 0; i<mTabs.size(); i++){
        if (mTabs.get(i) == tag){
            mViewPager.setCurrentItem(i);
        }
    }
}
项目:Bitter    文件:TabListener.java   
public void onTabSelected(Tab tab, FragmentTransaction ft) {
    if (mFragment == null) {
        mFragment = Fragment.instantiate(mActivity, mClass.getName());
        ft.add(android.R.id.content, mFragment, mTag);
    } else {
        ft.attach(mFragment);
    }
}
项目:nexus-gallery    文件:GalleryActivity.java   
public void addTab(ActionBar.Tab tab, Class<?> clss, Bundle args) {
    TabInfo info = new TabInfo(clss, args);
    tab.setTag(info);
    tab.setTabListener(this);
    mTabs.add(info);
    mActionBar.addTab(tab);
    notifyDataSetChanged();
}
项目:nexus-gallery    文件:GalleryActivity.java   
@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
    Object tag = tab.getTag();
    for (int i = 0; i < mTabs.size(); i++) {
        if (mTabs.get(i) == tag) {
            mViewPager.setCurrentItem(i);
        }
    }
}
项目:CalendarTrigger    文件:CalendarTabListener.java   
@Override
public void onTabSelected(Tab tab, FragmentTransaction fragmentTransaction) {

    fragment = activity.getFragmentManager().findFragmentByTag(tag);

    if(fragment == null) { // Create fragment
        fragment = Fragment.instantiate(activity, fragmentClass.getName());
        fragmentTransaction.add(android.R.id.content, fragment, tag);
    }
    else { // Reuse
        fragmentTransaction.attach(fragment);
    }
}
项目:sample-gallery-android    文件:MainActivity.java   
@Override
public void onBackPressed() {
    // Select proper stack
    ActionBar actionBar = getActionBar();
    if (actionBar != null) {
        Tab tab = actionBar.getSelectedTab();
        Stack<String> backStack = backStacks.get(tab.getTag());
        // Remove a fragment from the stack
        String tag;

        hideKeyboard();
        if (backStack.isEmpty()) {
            shouldDisplayHomeUp(false);
            // Let application finish
            // super.onBackPressed();
        } else {
            // Show/hide ActionBar up button
            if (backStack.size() > 1) {
                shouldDisplayHomeUp(true);
            } else {
                shouldDisplayHomeUp(false);
            }

            if (!backStack.isEmpty()) {
                tag = backStack.pop();

                FragmentTransaction ft = getFragmentManager().beginTransaction();
                Fragment fragment = getFragmentManager().findFragmentByTag(tag);

                // Remove topmost fragment from back stack and forget it
                ft.remove(fragment);
                showFragment(backStack, ft);
                ft.commit();
            }
        }
    }
}
项目:sample-gallery-android    文件:MainActivity.java   
@Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
    // Select proper stack
    Stack<String> backStack = backStacks.get(tab.getTag());
    // Get topmost fragment
    String tag = "";
    if (!backStack.isEmpty()) {
        tag = backStack.peek();
        Fragment fragment = getFragmentManager().findFragmentByTag(tag);
        // Detach it
        ft.detach(fragment);
    }

}
项目:CalendarMute    文件:CalendarMuteTabListener.java   
@Override
public void onTabSelected(Tab tab, FragmentTransaction fragmentTransaction) {

    fragment = activity.getFragmentManager().findFragmentByTag(tag);

    if(fragment == null) { // Create fragment
        fragment = Fragment.instantiate(activity, fragmentClass.getName());
        fragmentTransaction.add(android.R.id.content, fragment, tag);
    }
    else { // Reuse
        fragmentTransaction.attach(fragment);
    }
}
项目:ApkLauncher    文件:FragmentNestingTabs.java   
public void onTabSelected(Tab tab, FragmentTransaction ft) {
    if (mFragment == null) {
        mFragment = Fragment.instantiate(mActivity, mClass.getName(), mArgs);
        ft.add(android.R.id.content, mFragment, mTag);
    } else {
        ft.attach(mFragment);
    }
}
项目:ApkLauncher    文件:FragmentTabs.java   
public void onTabSelected(Tab tab, FragmentTransaction ft) {
    if (mFragment == null) {
        mFragment = Fragment.instantiate(mActivity, mClass.getName(), mArgs);
        ft.add(android.R.id.content, mFragment, mTag);
    } else {
        ft.attach(mFragment);
    }
}
项目:ApiDemos    文件:FragmentNestingTabs.java   
public void onTabSelected(Tab tab, FragmentTransaction ft) {
    if (mFragment == null) {
        mFragment = Fragment.instantiate(mActivity, mClass.getName(), mArgs);
        ft.add(android.R.id.content, mFragment, mTag);
    } else {
        ft.attach(mFragment);
    }
}
项目:ApiDemos    文件:FragmentTabs.java   
public void onTabSelected(Tab tab, FragmentTransaction ft) {
    if (mFragment == null) {
        mFragment = Fragment.instantiate(mActivity, mClass.getName(), mArgs);
        ft.add(android.R.id.content, mFragment, mTag);
    } else {
        ft.attach(mFragment);
    }
}
项目:CCDownload    文件:DownloadListActivity.java   
@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
    viewPager.setCurrentItem(tab.getPosition());
}
项目:CCDownload    文件:MainActivity.java   
@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
    viewPager.setCurrentItem(tab.getPosition());
}
项目:buildAPKsSamples    文件:ActionBarDisplayOptions.java   
public void onTabSelected(Tab tab, FragmentTransaction ft) {
}
项目:buildAPKsSamples    文件:ActionBarDisplayOptions.java   
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
}
项目:buildAPKsSamples    文件:ActionBarDisplayOptions.java   
public void onTabReselected(Tab tab, FragmentTransaction ft) {
}
项目:LibVNCAndroid    文件:ActivityTabs.java   
/**
 * @brief This is the onCreate method
 * @param savedInstanceState
 * @details The onCreate method adds an actionBar to the activity with two tabs (recent and favorites).
 * It also load the preferences file into the prefs attribute and sets the rememeberExit attribute.
 */
@Override
public void onCreate(Bundle savedInstanceState) {       
       super.onCreate(savedInstanceState);
       setContentView(R.layout.tab_host);

        final ActionBar actionBar = getActionBar();
        actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE|ActionBar.DISPLAY_SHOW_HOME);


        final String recents = getString(R.string.recents);
        final String favorites = getString(R.string.favoritesTab);

        // add tabs
        Tab tab1 = actionBar.newTab()
                  .setText(recents)
                  .setTabListener(new TabListener<ListFragmentTab>(
                   this, "tab1", ListFragmentTab.class));
        actionBar.addTab(tab1);


        Tab tab2 = actionBar.newTab()
               .setText(favorites)
               .setTabListener(new TabListener<ListFragmentTabFav>(
                    this, "tab2", ListFragmentTabFav.class));

        actionBar.addTab(tab2);


        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

        //accedemos a fichero preferencias
        (Configuration.getInstance()).setPrefs( getSharedPreferences("PreferencesFile",Context.MODE_PRIVATE));


        (Configuration.getInstance()).readPrefs();

        // Orientation Change Occurred
        if(savedInstanceState!=null){
            int currentTabIndex = savedInstanceState.getInt("tab_index");
            actionBar.setSelectedNavigationItem(currentTabIndex);
        }

        //nombre en la activity bar
        final String title = getString(R.string.connections);
        setTitle(title);

}
项目:Steppy-Android    文件:MainActivity.java   
@Override
public void onTabReselected(Tab tab, FragmentTransaction ft) {
}
项目:Steppy-Android    文件:MainActivity.java   
@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
    // on tab selected
    // show respected fragment view
    viewPager.setCurrentItem(tab.getPosition());
}
项目:Steppy-Android    文件:MainActivity.java   
@Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
}
项目:Steppy-Android    文件:DashBoardActivityBand.java   
@Override
public void onTabReselected(Tab tab, FragmentTransaction ft) {
}
项目:Steppy-Android    文件:DashBoardActivityBand.java   
@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
    // on tab selected
    // show respected fragment view
    viewPager.setCurrentItem(tab.getPosition());
}
项目:Steppy-Android    文件:DashBoardActivityBand.java   
@Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
}
项目:TenguChat    文件:StartConversationActivity.java   
@Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
    return;
}
项目:TenguChat    文件:StartConversationActivity.java   
@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
    mViewPager.setCurrentItem(tab.getPosition());
    onTabChanged();
}