当前位置: 首页>>代码示例>>Java>>正文


Java SavedState类代码示例

本文整理汇总了Java中android.support.v4.app.Fragment.SavedState的典型用法代码示例。如果您正苦于以下问题:Java SavedState类的具体用法?Java SavedState怎么用?Java SavedState使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SavedState类属于android.support.v4.app.Fragment包,在下文中一共展示了SavedState类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: instantiateItem

import android.support.v4.app.Fragment.SavedState; //导入依赖的package包/类
public Object instantiateItem(ViewGroup container, int position) {
    if (this.mFragments.size() > position) {
        Fragment f = (Fragment) this.mFragments.get(position);
        if (f != null) {
            return f;
        }
    }
    if (this.mCurTransaction == null) {
        this.mCurTransaction = this.mFragmentManager.beginTransaction();
    }
    Fragment fragment = getItem(position);
    if (this.mSavedState.size() > position) {
        SavedState fss = (SavedState) this.mSavedState.get(position);
        if (fss != null) {
            fragment.setInitialSavedState(fss);
        }
    }
    while (this.mFragments.size() <= position) {
        this.mFragments.add(null);
    }
    fragment.setMenuVisibility(false);
    fragment.setUserVisibleHint(false);
    this.mFragments.set(position, fragment);
    this.mCurTransaction.add(container.getId(), fragment);
    return fragment;
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:27,代码来源:FragmentStatePagerAdapter.java

示例2: BackStackEntry

import android.support.v4.app.Fragment.SavedState; //导入依赖的package包/类
private BackStackEntry(Parcel in) {
  final ClassLoader loader = getClass().getClassLoader();
  fname = in.readString();
  args = in.readBundle(loader);

  switch (in.readInt()) {
    case NO_STATE:
      state = null;
      break;
    case SAVED_STATE:
      state = SavedState.CREATOR.createFromParcel(in);
      break;
    case PARCELABLE_STATE:
      state = in.readParcelable(loader);
      break;
    default:
      throw new IllegalStateException();
  }
}
 
开发者ID:JetradarMobile,项目名称:android-multibackstack,代码行数:20,代码来源:BackStackEntry.java

示例3: restoreState

import android.support.v4.app.Fragment.SavedState; //导入依赖的package包/类
public void restoreState(Parcelable state, ClassLoader loader) {
    if (state != null) {
        Bundle bundle = (Bundle) state;
        bundle.setClassLoader(loader);
        Parcelable[] fss = bundle.getParcelableArray("states");
        this.mSavedState.clear();
        this.mFragments.clear();
        if (fss != null) {
            for (Parcelable parcelable : fss) {
                this.mSavedState.add((SavedState) parcelable);
            }
        }
        for (String key : bundle.keySet()) {
            if (key.startsWith("f")) {
                int index = Integer.parseInt(key.substring(1));
                Fragment f = this.mFragmentManager.getFragment(bundle, key);
                if (f != null) {
                    while (this.mFragments.size() <= index) {
                        this.mFragments.add(null);
                    }
                    f.setMenuVisibility(false);
                    this.mFragments.set(index, f);
                } else {
                    Log.w(TAG, "Bad fragment at key " + key);
                }
            }
        }
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:30,代码来源:FragmentStatePagerAdapter.java

示例4: saveFragmentInstanceState

import android.support.v4.app.Fragment.SavedState; //导入依赖的package包/类
public SavedState saveFragmentInstanceState(Fragment fragment) {
    if (fragment.mIndex < 0) {
        throwException(new IllegalStateException("Fragment " + fragment + " is not currently in the FragmentManager"));
    }
    if (fragment.mState <= 0) {
        return null;
    }
    Bundle result = saveFragmentBasicState(fragment);
    if (result != null) {
        return new SavedState(result);
    }
    return null;
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:14,代码来源:FragmentManagerImpl.java

示例5: AbstractFragmentPagerAdapter

import android.support.v4.app.Fragment.SavedState; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public AbstractFragmentPagerAdapter(FragmentManager fragmentManager, int length) {
	this.fragmentManager = fragmentManager;
	
	//É obrigado a saber o tamanho desta forma pq se chamar o getCount() vai dar pau pq a classe filha ainda não atribui nada... Pena que não dá pra fazer nada antes de chamar o super().
	this.fragments = (T[]) new Fragment[length];
	this.savedStates = new SavedState[length];
}
 
开发者ID:ZalemSoftware,项目名称:Ymir,代码行数:9,代码来源:AbstractFragmentPagerAdapter.java

示例6: instantiateItem

import android.support.v4.app.Fragment.SavedState; //导入依赖的package包/类
@Override
public Object instantiateItem(ViewGroup container, int position) {
	//Se já está armazenado em memporia, só recupera.
	T fragment = fragments[position]; 
	if (fragment != null) {
		return fragment;
	}
	
	int containerId = container.getId();
	if (containerId == View.NO_ID) {
		throw new IllegalArgumentException("The ViewPager has no id");
	}
	
	//Cria o fragmento e restaura o estado anterior, se existir. Apenas fragmentos destruídos terão o estado armazenado.
	String fragmentTag = createFragmentTag(position);
	fragment = createFragment(position);
       if (listener != null) {
           listener.onFragmentCreated(fragment, position);
       }
	SavedState savedState = savedStates[position];
	if (savedState != null) {
		fragment.setInitialSavedState(savedState);
		savedStates[position] = null;
	}
	
	//Adiciona o fragmento na tela, salva-o em memória e faz sua inicialização.
	FragmentTransaction transaction = fragmentManager.beginTransaction();
	transaction.add(containerId, fragment, fragmentTag);
	transaction.commit();
	fragments[position] = fragment;

	internalInitializeFragment(fragment, position);
	
	return fragment;
}
 
开发者ID:ZalemSoftware,项目名称:Ymir,代码行数:36,代码来源:AbstractFragmentPagerAdapter.java

示例7: restoreState

import android.support.v4.app.Fragment.SavedState; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public void restoreState(Parcelable state, ClassLoader loader) {
	Bundle bundle = (Bundle) state;
	bundle.setClassLoader(loader);

	//Restaura os fragmentos mantidos automaticamente pelo Android.
	BitSet fragmentPositions = (BitSet) bundle.getSerializable(SAVED_FRAGMENTS_POSITIONS);
	int nextSetBit = 0;
	while ((nextSetBit = fragmentPositions.nextSetBit(nextSetBit)) != -1) {
		int fragmentPosition = nextSetBit++;
		String fragmentTag = createFragmentTag(fragmentPosition); 
		T fragment = (T) fragmentManager.findFragmentByTag(fragmentTag);
		//O fragmento deve existir, mas evita que algum problema na sua restauração automática pare a aplicação. 
		if (fragment != null) {
			fragments[fragmentPosition] = fragment;
			internalInitializeFragment(fragment, fragmentPosition);
		}
	}
	
	//Tem que fazer desta forma porque quando a Activity é destruída o array de saved states é recuperado
	//como Parcelable[], ou seja, o cast pra SavedState[] não funciona.
	Parcelable[] parcelables = bundle.getParcelableArray(SAVED_STATES);
	
	if (BuildConfig.DEBUG && parcelables.length != savedStates.length) {
		throw new AssertionError();
	}
	
	for (int i = 0; i < parcelables.length; i++) {
		savedStates[i] = (SavedState) parcelables[i];
	}
	
}
 
开发者ID:ZalemSoftware,项目名称:Ymir,代码行数:34,代码来源:AbstractFragmentPagerAdapter.java

示例8: createFromParcel

import android.support.v4.app.Fragment.SavedState; //导入依赖的package包/类
@Override
public PerspectiveInstance createFromParcel(Parcel source) {
	PerspectiveInstance instance = new PerspectiveInstance(source.readInt(), source.readInt(), 
														   AndroidBugsUtils.applyWorkaroundForIntentDefaultClassloaderBug(source));
	
	PerspectiveResultRequest resultRequest = AndroidBugsUtils.applyWorkaroundForParcelableDefaultClassloaderBug(source);
	instance.setResultRequest(resultRequest);
	SavedState savedState = AndroidBugsUtils.applyWorkaroundForParcelableDefaultClassloaderBug(source);
	instance.setSavedState(savedState);
	instance.setHasUnfinishedWork(AndroidBugsUtils.applyWorkaroundForBug5973_read(source));
	return instance;
}
 
开发者ID:ZalemSoftware,项目名称:Ymir,代码行数:13,代码来源:PerspectiveActivity.java

示例9: create

import android.support.v4.app.Fragment.SavedState; //导入依赖的package包/类
@NonNull
public static BackStackEntry create(@NonNull FragmentManager fm, @NonNull Fragment f) {
  String fname = f.getClass().getName();
  SavedState state = fm.saveFragmentInstanceState(f);
  Bundle args = f.getArguments();
  return new BackStackEntry(fname, state, args);
}
 
开发者ID:JetradarMobile,项目名称:android-multibackstack,代码行数:8,代码来源:BackStackEntry.java

示例10: writeToParcel

import android.support.v4.app.Fragment.SavedState; //导入依赖的package包/类
@Override
public void writeToParcel(Parcel out, int flags) {
  out.writeString(fname);
  out.writeBundle(args);

  if (state == null) {
    out.writeInt(NO_STATE);
  } else if (state.getClass() == SavedState.class) {
    out.writeInt(SAVED_STATE);
    state.writeToParcel(out, flags);
  } else {
    out.writeInt(PARCELABLE_STATE);
    out.writeParcelable(state, flags);
  }
}
 
开发者ID:JetradarMobile,项目名称:android-multibackstack,代码行数:16,代码来源:BackStackEntry.java

示例11: saveFragmentInstanceState

import android.support.v4.app.Fragment.SavedState; //导入依赖的package包/类
@Override
public SavedState saveFragmentInstanceState(Fragment arg0) {
	return owner.getChildFragmentManager().saveFragmentInstanceState(arg0);
}
 
开发者ID:ZalemSoftware,项目名称:Ymir,代码行数:5,代码来源:AndroidBugsUtils.java

示例12: savePerspectiveState

import android.support.v4.app.Fragment.SavedState; //导入依赖的package包/类
private void savePerspectiveState(Perspective perspective, PerspectiveInstance perspectiveInstance) {
    SavedState savedState = getSupportFragmentManager().saveFragmentInstanceState(perspective);
    perspectiveInstance.setSavedState(savedState);
    perspectiveInstance.setHasUnfinishedWork(perspective.hasUnfinishedWork());
}
 
开发者ID:ZalemSoftware,项目名称:Ymir,代码行数:6,代码来源:PerspectiveActivity.java

示例13: getSavedState

import android.support.v4.app.Fragment.SavedState; //导入依赖的package包/类
public SavedState getSavedState() {
	return savedState;
}
 
开发者ID:ZalemSoftware,项目名称:Ymir,代码行数:4,代码来源:PerspectiveActivity.java

示例14: setSavedState

import android.support.v4.app.Fragment.SavedState; //导入依赖的package包/类
public void setSavedState(SavedState savedState) {
	this.savedState = savedState;
}
 
开发者ID:ZalemSoftware,项目名称:Ymir,代码行数:4,代码来源:PerspectiveActivity.java

示例15: m89a

import android.support.v4.app.Fragment.SavedState; //导入依赖的package包/类
public SavedState m89a(Parcel parcel) {
    return new SavedState(parcel, null);
}
 
开发者ID:Qwaz,项目名称:solved-hacking-problem,代码行数:4,代码来源:C0010g.java


注:本文中的android.support.v4.app.Fragment.SavedState类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。