Java源码示例:com.hippo.yorozuya.IntIdGenerator

示例1
@Override
protected void onRestoreInstanceState(Parcelable state) {
    if (state == null || !state.getClass().equals(SavedState.class)) {
        // Didn't save state for us in onSaveInstanceState
        super.onRestoreInstanceState(state);
        return;
    }

    SavedState myState = (SavedState) state;
    mTaskId = myState.asyncTaskId;
    if (IntIdGenerator.INVALID_ID != mTaskId) {
        Object o = ((EhApplication) getContext().getApplicationContext()).getGlobalStuff(mTaskId);
        if (o instanceof Task) {
            mTask = (Task) o;
            mTask.setPreference(this);
        }
    }
    if (null == mTask) {
        mTaskId = IntIdGenerator.INVALID_ID;
    }

    // TODO if not task, show not reopen dialog

    super.onRestoreInstanceState(myState.getSuperState());
}
 
示例2
protected Parcelable saveInstanceState(Parcelable superState) {
    Bundle bundle = new Bundle();
    bundle.putParcelable(KEY_SUPER, superState);
    int shownView = mViewTransition.getShownViewIndex();
    bundle.putInt(KEY_SHOWN_VIEW, shownView);
    bundle.putString(KEY_TIP, mTipView.getText().toString());

    // TODO It's a bad design
    EhApplication app = (EhApplication) getContext().getApplicationContext();
    if (mSavedDataId != IntIdGenerator.INVALID_ID) {
        app.removeGlobalStuff(mSavedDataId);
        mSavedDataId = IntIdGenerator.INVALID_ID;
    }
    mSavedDataId = app.putGlobalStuff(mData);
    bundle.putInt(KEY_DATA, mSavedDataId);

    bundle.putInt(KEY_NEXT_ID, mIdGenerator.nextId());
    bundle.putParcelable(KEY_PAGE_DIVIDER, mPageDivider);
    bundle.putInt(KEY_START_PAGE, mStartPage);
    bundle.putInt(KEY_END_PAGE, mEndPage);
    bundle.putInt(KEY_PAGES, mPages);
    return bundle;
}
 
示例3
@Override
protected void onRestoreInstanceState(Parcelable state) {
    if (state == null || !state.getClass().equals(SavedState.class)) {
        // Didn't save state for us in onSaveInstanceState
        super.onRestoreInstanceState(state);
        return;
    }

    SavedState myState = (SavedState) state;
    mTaskId = myState.asyncTaskId;
    if (IntIdGenerator.INVALID_ID != mTaskId) {
        Object o = ((EhApplication) getContext().getApplicationContext()).getGlobalStuff(mTaskId);
        if (o instanceof Task) {
            mTask = (Task) o;
            mTask.setPreference(this);
        }
    }
    if (null == mTask) {
        mTaskId = IntIdGenerator.INVALID_ID;
    }

    // TODO if not task, show not reopen dialog

    super.onRestoreInstanceState(myState.getSuperState());
}
 
示例4
protected Parcelable saveInstanceState(Parcelable superState) {
    Bundle bundle = new Bundle();
    bundle.putParcelable(KEY_SUPER, superState);
    int shownView = mViewTransition.getShownViewIndex();
    bundle.putInt(KEY_SHOWN_VIEW, shownView);
    bundle.putString(KEY_TIP, mTipView.getText().toString());

    // TODO It's a bad design
    EhApplication app = (EhApplication) getContext().getApplicationContext();
    if (mSavedDataId != IntIdGenerator.INVALID_ID) {
        app.removeGlobalStuff(mSavedDataId);
        mSavedDataId = IntIdGenerator.INVALID_ID;
    }
    mSavedDataId = app.putGlobalStuff(mData);
    bundle.putInt(KEY_DATA, mSavedDataId);

    bundle.putInt(KEY_NEXT_ID, mIdGenerator.nextId());
    bundle.putParcelable(KEY_PAGE_DIVIDER, mPageDivider);
    bundle.putInt(KEY_START_PAGE, mStartPage);
    bundle.putInt(KEY_END_PAGE, mEndPage);
    bundle.putInt(KEY_PAGES, mPages);
    return bundle;
}
 
示例5
protected void onTaskEnd() {
    // Dismiss dialog
    Dialog dialog = getDialog();
    if (null != dialog) {
        dialog.dismiss();
    }
    // Clear async
    mTask = null;
    mTaskId = IntIdGenerator.INVALID_ID;
}
 
示例6
@Override
protected Parcelable restoreInstanceState(Parcelable state) {
  Bundle bundle = (Bundle) state;

  int id = bundle.getInt(KEY_DATA_MAP, IntIdGenerator.INVALID_ID);
  if (id != IntIdGenerator.INVALID_ID) {
    FavouriteStatusRouter router = EhApplication.getFavouriteStatusRouter();
    Map<String, GalleryInfo> map = router.restoreDataMap(id);
    if (map != null) {
      this.map = map;
    }
  }

  return super.restoreInstanceState(state);
}
 
示例7
protected Parcelable restoreInstanceState(Parcelable state) {
    if (state instanceof Bundle) {
        Bundle bundle = (Bundle) state;
        mViewTransition.showView(bundle.getInt(KEY_SHOWN_VIEW), false);
        mTipView.setText(bundle.getString(KEY_TIP));

        mSavedDataId = bundle.getInt(KEY_DATA);
        ArrayList<E> newData = null;
        EhApplication app = (EhApplication) getContext().getApplicationContext();
        if (mSavedDataId != IntIdGenerator.INVALID_ID) {
            newData = (ArrayList<E>) app.removeGlobalStuff(mSavedDataId);
            mSavedDataId = IntIdGenerator.INVALID_ID;
            if (newData != null) {
                mData = newData;
            }
        }

        mIdGenerator.setNextId(bundle.getInt(KEY_NEXT_ID));
        mPageDivider = bundle.getParcelable(KEY_PAGE_DIVIDER);
        mStartPage = bundle.getInt(KEY_START_PAGE);
        mEndPage = bundle.getInt(KEY_END_PAGE);
        mPages = bundle.getInt(KEY_PAGES);

        notifyDataSetChanged();

        if (newData == null) {
            mPageDivider.clear();
            mStartPage = 0;
            mEndPage = 0;
            mPages = 0;
            firstRefresh();
        }

        return bundle.getParcelable(KEY_SUPER);
    } else {
        return state;
    }
}
 
示例8
protected void onTaskEnd() {
    // Dismiss dialog
    Dialog dialog = getDialog();
    if (null != dialog) {
        dialog.dismiss();
    }
    // Clear async
    mTask = null;
    mTaskId = IntIdGenerator.INVALID_ID;
}
 
示例9
@Override
protected Parcelable restoreInstanceState(Parcelable state) {
  Bundle bundle = (Bundle) state;

  int id = bundle.getInt(KEY_DATA_MAP, IntIdGenerator.INVALID_ID);
  if (id != IntIdGenerator.INVALID_ID) {
    FavouriteStatusRouter router = EhApplication.getFavouriteStatusRouter();
    Map<Long, GalleryInfo> map = router.restoreDataMap(id);
    if (map != null) {
      this.map = map;
    }
  }

  return super.restoreInstanceState(state);
}
 
示例10
protected Parcelable restoreInstanceState(Parcelable state) {
    if (state instanceof Bundle) {
        Bundle bundle = (Bundle) state;
        mViewTransition.showView(bundle.getInt(KEY_SHOWN_VIEW), false);
        mTipView.setText(bundle.getString(KEY_TIP));

        mSavedDataId = bundle.getInt(KEY_DATA);
        ArrayList<E> newData = null;
        EhApplication app = (EhApplication) getContext().getApplicationContext();
        if (mSavedDataId != IntIdGenerator.INVALID_ID) {
            newData = (ArrayList<E>) app.removeGlobalStuff(mSavedDataId);
            mSavedDataId = IntIdGenerator.INVALID_ID;
            if (newData != null) {
                mData = newData;
            }
        }

        mIdGenerator.setNextId(bundle.getInt(KEY_NEXT_ID));
        mPageDivider = bundle.getParcelable(KEY_PAGE_DIVIDER);
        mStartPage = bundle.getInt(KEY_START_PAGE);
        mEndPage = bundle.getInt(KEY_END_PAGE);
        mPages = bundle.getInt(KEY_PAGES);

        notifyDataSetChanged();

        if (newData == null) {
            mPageDivider.clear();
            mStartPage = 0;
            mEndPage = 0;
            mPages = 0;
            firstRefresh();
        }

        return bundle.getParcelable(KEY_SUPER);
    } else {
        return state;
    }
}
 
示例11
@Override
protected final void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (savedInstanceState != null) {
        mStageId = savedInstanceState.getInt(KEY_STAGE_ID, IntIdGenerator.INVALID_ID);
        ArrayList<String> list = savedInstanceState.getStringArrayList(KEY_SCENE_TAG_LIST);
        if (list != null) {
            mSceneTagList.addAll(list);
            mDelaySceneTagList.addAll(list);
        }
        mIdGenerator.lazySet(savedInstanceState.getInt(KEY_NEXT_ID));
    }

    if (mStageId == IntIdGenerator.INVALID_ID) {
        ((SceneApplication) getApplicationContext()).registerStageActivity(this);
    } else {
        ((SceneApplication) getApplicationContext()).registerStageActivity(this, mStageId);
    }

    // Create layout
    onCreate2(savedInstanceState);

    Intent intent = getIntent();
    if (savedInstanceState == null) {
        if (intent != null) {
            String action = intent.getAction();
            if (Intent.ACTION_MAIN.equals(action)) {
                Announcer announcer = getLaunchAnnouncer();
                if (announcer != null) {
                    startScene(announcer);
                    return;
                }
            } else if (ACTION_START_SCENE.equals(action)) {
                if (startSceneFromIntent(intent)) {
                    return;
                }
            }
        }

        // Can't recognize intent
        onUnrecognizedIntent(intent);
    }
}
 
示例12
@Override
protected final void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (savedInstanceState != null) {
        mStageId = savedInstanceState.getInt(KEY_STAGE_ID, IntIdGenerator.INVALID_ID);
        ArrayList<String> list = savedInstanceState.getStringArrayList(KEY_SCENE_TAG_LIST);
        if (list != null) {
            mSceneTagList.addAll(list);
            mDelaySceneTagList.addAll(list);
        }
        mIdGenerator.lazySet(savedInstanceState.getInt(KEY_NEXT_ID));
    }

    if (mStageId == IntIdGenerator.INVALID_ID) {
        ((SceneApplication) getApplicationContext()).registerStageActivity(this);
    } else {
        ((SceneApplication) getApplicationContext()).registerStageActivity(this, mStageId);
    }

    // Create layout
    onCreate2(savedInstanceState);

    Intent intent = getIntent();
    if (savedInstanceState == null) {
        if (intent != null) {
            String action = intent.getAction();
            if (Intent.ACTION_MAIN.equals(action)) {
                Announcer announcer = getLaunchAnnouncer();
                if (announcer != null) {
                    startScene(announcer);
                    return;
                }
            } else if (ACTION_START_SCENE.equals(action)) {
                if (startSceneFromIntent(intent)) {
                    return;
                }
            }
        }

        // Can't recognize intent
        onUnrecognizedIntent(intent);
    }
}