Search in sources :

Example 61 with FragmentManager

use of android.support.v4.app.FragmentManager in project GT by Tencent.

the class GTMainActivity method setTabSelection.

/**
	 * 根据传入的index参数来设置选中的tab页。
	 * 
	 * @param index
	 *            每个tab页对应的下标。
	 */
private synchronized void setTabSelection(int index) {
    // 每次选中之前先清楚掉上次的选中状态
    clearSelection();
    // 开启一个Fragment事务
    FragmentManager fragmentManager = getSupportFragmentManager();
    FragmentTransaction transaction = fragmentManager.beginTransaction();
    // 先隐藏掉所有的Fragment,以防止有多个Fragment显示在界面上的情况
    //TODO
    hideFragments(transaction);
    switch(index) {
        case 0:
            // 当点击了AUT tab时,改变控件的图片和文字颜色
            autImage.setImageResource(R.drawable.tab_selected_border);
            autText.setTextColor(Color.WHITE);
            if (autFragment == null) {
                autFragment = new GTAUTFragment();
                transaction.add(R.id.content, autFragment, "a");
            } else {
                transaction.show(autFragment);
            }
            break;
        case 1:
            // 当点击了参数 tab时,改变控件的图片和文字颜色
            paramImage.setImageResource(R.drawable.tab_selected_border);
            paramText.setTextColor(Color.WHITE);
            if (paramFragment == null) {
                paramFragment = new GTParamTopFragment();
                transaction.add(R.id.content, paramFragment, "b");
            } else {
                transaction.show(paramFragment);
                paramFragment.onShow(true);
            }
            break;
        case 2:
            // 当点击了耗时 tab时,改变控件的图片和文字颜色
            perfImage.setImageResource(R.drawable.tab_selected_border);
            perfText.setTextColor(Color.WHITE);
            if (perfFragment == null) {
                perfFragment = new GTPerfFragment();
                transaction.add(R.id.content, perfFragment, "c");
            } else {
                transaction.show(perfFragment);
            }
            break;
        case 3:
            // 当点击了日志 tab时,改变控件的图片和文字颜色
            logImage.setImageResource(R.drawable.tab_selected_border);
            logText.setTextColor(Color.WHITE);
            if (logFragment == null) {
                logFragment = new GTLogFragment();
                transaction.add(R.id.content, logFragment, "d");
            } else {
                transaction.show(logFragment);
            }
            break;
        case 4:
        default:
            // 当点击了插件 tab时,改变控件的图片和文字颜色
            pluginImage.setImageResource(R.drawable.tab_selected_border);
            pluginText.setTextColor(Color.WHITE);
            if (pluginFragment == null) {
                pluginFragment = new GTPluginFragment();
                transaction.add(R.id.content, pluginFragment, "e");
            } else {
                transaction.show(pluginFragment);
            }
            break;
    }
    /*
		 * 直接使用commit()可能会出错:
		 * IllegalStateException: Can not perform this action after onSaveInstanceState:\
		 * 
		 * @see http://developer.android.com/reference/android/app/FragmentTransaction.html#commitAllowingStateLoss()
		 * 
		 * 大致意思是说我使用的 commit方法是在Activity的onSaveInstanceState()之后调用的,这样会出错,因为onSaveInstanceState
		 * 方法是在该Activity即将被销毁前调用,来保存Activity数据的,如果在保存玩状态后再给它添加Fragment就会出错。解决办法就
		 * 是把commit()方法替换成 commitAllowingStateLoss()就行了,其效果是一样的。
		 */
    // transaction.commit(); 
    transaction.commitAllowingStateLoss();
}
Also used : FragmentManager(android.support.v4.app.FragmentManager) FragmentTransaction(android.support.v4.app.FragmentTransaction)

Example 62 with FragmentManager

use of android.support.v4.app.FragmentManager in project GT by Tencent.

the class GTMainActivity method removeFragments.

/*
	 * 在Activity重新加载时,要先清除遗留的Fragment
	 */
private void removeFragments() {
    FragmentManager fragmentManager = getSupportFragmentManager();
    FragmentTransaction transaction = fragmentManager.beginTransaction();
    Fragment fragment = fragmentManager.findFragmentByTag("a");
    if (fragment != null) {
        transaction.remove(fragment);
    }
    fragment = fragmentManager.findFragmentByTag("b");
    if (fragment != null) {
        transaction.remove(fragment);
    }
    fragment = fragmentManager.findFragmentByTag("c");
    if (fragment != null) {
        transaction.remove(fragment);
    }
    fragment = fragmentManager.findFragmentByTag("d");
    if (fragment != null) {
        transaction.remove(fragment);
    }
    fragment = fragmentManager.findFragmentByTag("e");
    if (fragment != null) {
        transaction.remove(fragment);
    }
    transaction.commitAllowingStateLoss();
}
Also used : FragmentManager(android.support.v4.app.FragmentManager) FragmentTransaction(android.support.v4.app.FragmentTransaction) Fragment(android.support.v4.app.Fragment)

Example 63 with FragmentManager

use of android.support.v4.app.FragmentManager in project mounts2sd by SpazeDog.

the class ActivityTabController method tabSwitchFragment.

private void tabSwitchFragment(Integer tabId) {
    FragmentManager fragmentManager = getSupportFragmentManager();
    Boolean isAdded = fragmentManager.findFragmentByTag("" + tabId) != null;
    if (!isAdded || mTabFragments.get(tabId).isDetached()) {
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        for (int id : mTabFragments.keySet()) {
            if (id != tabId && fragmentManager.findFragmentByTag("" + id) != null && !mTabFragments.get(id).isDetached()) {
                fragmentTransaction.detach(mTabFragments.get(id));
            }
        }
        if (isAdded && mTabFragments.get(tabId).isDetached()) {
            fragmentTransaction.attach(mTabFragments.get(tabId));
        } else if (!isAdded) {
            fragmentTransaction.add(R.id.fragment_frame, mTabFragments.get(tabId), "" + tabId);
        }
        fragmentTransaction.commit();
    } else {
        tabUpdateButtons();
    }
}
Also used : FragmentManager(android.support.v4.app.FragmentManager) FragmentTransaction(android.support.v4.app.FragmentTransaction)

Example 64 with FragmentManager

use of android.support.v4.app.FragmentManager in project storymaker by StoryMaker.

the class AccountsActivity method addChooseAccountFragment.

public void addChooseAccountFragment(Bundle bundle) {
    FragmentManager fragManager = getSupportFragmentManager();
    FragmentTransaction fragTrans = fragManager.beginTransaction();
    List<Account> accounts = new ArrayList<>();
    final AuthTable authTable = new AuthTable();
    String[] siteAvailableNames = Account.CONTROLLER_SITE_NAMES;
    String[] siteAvailableKeys = Account.CONTROLLER_SITE_KEYS;
    Auth auth;
    for (int i = 0; i < siteAvailableKeys.length; i++) {
        auth = authTable.getAuthDefault(this, siteAvailableKeys[i]);
        if (auth == null) {
            accounts.add(new Account(-1, siteAvailableNames[i], siteAvailableKeys[i], "", "", null, false, false));
        } else {
            accounts.add(auth.convertToAccountObject());
        }
    }
    caFragment = new ChooseAccountFragment();
    caFragment.setArguments(bundle);
    caFragment.setLoginIntent(new Intent(this, ConnectAccountActivity.class));
    // FIXME we should probably make Account object parcelable and pass this through the bundle
    caFragment.setAccountsList(accounts);
    caFragment.setOnEventListener(new SiteController.OnEventListener() {

        @Override
        public void onSuccess(Account account) {
            Auth auth = authTable.getAuthDefault(getApplicationContext(), account.getSite());
            //if auth doesn't exist in db
            if (auth == null) {
                auth = new Auth(getApplicationContext(), -1, account.getName(), account.getSite(), null, null, null, null, null);
                auth.insert();
            }
            //set id of account based on returned id of auth insert
            account.setId(auth.getId());
            auth.setCredentials(account.getCredentials());
            auth.setData(account.getData());
            auth.setUserName(account.getUserName());
            auth.setExpires(null);
            authTable.updateLastLogin(getApplicationContext(), account.getSite(), auth.getUserName());
            auth.update();
        }

        @Override
        public void onFailure(Account account, String failureMessage) {
            Auth auth = authTable.getAuthDefault(getApplicationContext(), account.getSite());
            if (auth != null) {
                //TODO set variables here
                auth.setCredentials(account.getCredentials());
                auth.setUserName(account.getName());
                auth.setData(account.getData());
                // FIXME this is a hack to get isValid to fail, probably should be a setFailed() in auth that marks that we are busted
                auth.setExpires(new Date());
                auth.update();
            }
        }

        @Override
        public void onRemove(Account account) {
            authTable.delete(getApplicationContext(), account.getId());
        }
    });
    fragTrans.add(R.id.fragmentLayout, caFragment);
    fragTrans.commit();
}
Also used : Account(io.scal.secureshare.model.Account) ChooseAccountFragment(io.scal.secureshare.lib.ChooseAccountFragment) AuthTable(org.storymaker.app.model.AuthTable) ArrayList(java.util.ArrayList) Intent(android.content.Intent) SiteController(io.scal.secureshare.controller.SiteController) Date(java.util.Date) FragmentManager(android.support.v4.app.FragmentManager) FragmentTransaction(android.support.v4.app.FragmentTransaction) Auth(org.storymaker.app.model.Auth)

Example 65 with FragmentManager

use of android.support.v4.app.FragmentManager in project HoloEverywhere by Prototik.

the class FragmentBreadCrumbs method updateCrumbs.

void updateCrumbs() {
    FragmentManager fm = mActivity.getSupportFragmentManager();
    int numEntries = fm.getBackStackEntryCount();
    int numPreEntries = getPreEntryCount();
    int numViews = mContainer.getChildCount();
    for (int i = 0; i < numEntries + numPreEntries; i++) {
        BackStackEntry bse = i < numPreEntries ? getPreEntry(i) : fm.getBackStackEntryAt(i - numPreEntries);
        if (i < numViews) {
            View v = mContainer.getChildAt(i);
            Object tag = v.getTag();
            if (tag != bse) {
                for (int j = i; j < numViews; j++) {
                    mContainer.removeViewAt(i);
                }
                numViews = i;
            }
        }
        if (i >= numViews) {
            final View item = mInflater.inflate(R.layout.fragment_bread_crumb_item, this, false);
            final TextView text = (TextView) item.findViewById(R.id.title);
            text.setText(bse.getBreadCrumbTitle());
            text.setTag(bse);
            if (i == 0) {
                item.findViewById(R.id.left_icon).setVisibility(View.GONE);
            }
            mContainer.addView(item);
            text.setOnClickListener(mOnClickListener);
        }
    }
    int viewI = numEntries + numPreEntries;
    numViews = mContainer.getChildCount();
    while (numViews > viewI) {
        mContainer.removeViewAt(numViews - 1);
        numViews--;
    }
    for (int i = 0; i < numViews; i++) {
        final View child = mContainer.getChildAt(i);
        child.findViewById(R.id.title).setEnabled(i < numViews - 1);
        if (mMaxVisible > 0) {
            child.setVisibility(i < numViews - mMaxVisible ? View.GONE : View.VISIBLE);
            final View leftIcon = child.findViewById(R.id.left_icon);
            leftIcon.setVisibility(i > numViews - mMaxVisible && i != 0 ? View.VISIBLE : View.GONE);
        }
    }
}
Also used : FragmentManager(android.support.v4.app.FragmentManager) BackStackEntry(android.support.v4.app.FragmentManager.BackStackEntry) TextView(android.widget.TextView) TextView(android.widget.TextView) View(android.view.View) SuppressLint(android.annotation.SuppressLint)

Aggregations

FragmentManager (android.support.v4.app.FragmentManager)293 FragmentTransaction (android.support.v4.app.FragmentTransaction)106 Fragment (android.support.v4.app.Fragment)99 View (android.view.View)53 TextView (android.widget.TextView)35 Bundle (android.os.Bundle)31 OnClickListener (android.view.View.OnClickListener)24 DialogFragment (android.support.v4.app.DialogFragment)23 Intent (android.content.Intent)20 ImageView (android.widget.ImageView)16 ScrollView (android.widget.ScrollView)14 ListFragment (android.support.v4.app.ListFragment)12 Button (android.widget.Button)11 ArrayList (java.util.ArrayList)9 FrontPageFragment (ingage.ingage20.fragments.FrontPageFragment)8 SearchResultFragment (ingage.ingage20.fragments.SearchResultFragment)8 ViewPager (android.support.v4.view.ViewPager)7 ActionBar (android.support.v7.app.ActionBar)7 RecyclerView (android.support.v7.widget.RecyclerView)7 CategoriesPageFragment (ingage.ingage20.fragments.CategoriesPageFragment)7