Java Code Examples for android.app.FragmentTransaction#setCustomAnimations()

The following examples show how to use android.app.FragmentTransaction#setCustomAnimations() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DirectoryFragment.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
private static void show(FragmentManager fm, int type, RootInfo root, DocumentInfo doc, String query, int anim) {
	final Bundle args = new Bundle();
	args.putInt(EXTRA_TYPE, type);
	args.putParcelable(EXTRA_ROOT, root);
	args.putParcelable(EXTRA_DOC, doc);
	args.putString(EXTRA_QUERY, query);

	final FragmentTransaction ft = fm.beginTransaction();
	switch (anim) {
	case ANIM_SIDE:
		args.putBoolean(EXTRA_IGNORE_STATE, true);
		break;
	case ANIM_DOWN:
		ft.setCustomAnimations(R.animator.dir_down, R.animator.dir_frozen);
		break;
	case ANIM_UP:
		ft.setCustomAnimations(R.animator.dir_frozen, R.animator.dir_up);
		break;
	}

	final DirectoryFragment fragment = new DirectoryFragment();
	fragment.setArguments(args);

	ft.replace(R.id.container_directory, fragment);
	ft.commitAllowingStateLoss();
}
 
Example 2
Source File: FragmentCustomAnimations.java    From codeexamples-android with Eclipse Public License 1.0 6 votes vote down vote up
void addFragmentToStack() {
    mStackLevel++;

    // Instantiate a new fragment.
    Fragment newFragment = CountingFragment.newInstance(mStackLevel);

    // Add the fragment to the activity, pushing this transaction
    // on to the back stack.
    FragmentTransaction ft = getFragmentManager().beginTransaction();
    ft.setCustomAnimations(R.animator.fragment_slide_left_enter,
            R.animator.fragment_slide_left_exit,
            R.animator.fragment_slide_right_enter,
            R.animator.fragment_slide_right_exit);
    ft.replace(R.id.simple_fragment, newFragment);
    ft.addToBackStack(null);
    ft.commit();
}
 
Example 3
Source File: MainActivity.java    From QuickLyric with GNU General Public License v3.0 6 votes vote down vote up
private LyricsViewFragment init(FragmentManager fragmentManager, boolean startEmpty) {
    LyricsViewFragment lyricsViewFragment = (LyricsViewFragment) fragmentManager.findFragmentByTag(LYRICS_FRAGMENT_TAG);
    if (lyricsViewFragment == null || lyricsViewFragment.isDetached())
        lyricsViewFragment = new LyricsViewFragment();
    lyricsViewFragment.startEmpty(startEmpty);
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    fragmentTransaction.setCustomAnimations(R.animator.slide_in_end, R.animator.slide_out_start, R.animator.slide_in_start, R.animator.slide_out_end);
    if (!lyricsViewFragment.isAdded()) {
        fragmentTransaction.add(id.main_fragment_container, lyricsViewFragment, LYRICS_FRAGMENT_TAG);
    }

    Fragment[] activeFragments = getActiveFragments();
    displayedFragment = getDisplayedFragment(activeFragments);

    for (Fragment fragment : activeFragments)
        if (fragment != null) {
            if (fragment != displayedFragment && !fragment.isHidden()) {
                fragmentTransaction.hide(fragment);
                fragment.onHiddenChanged(true);
            } else if (fragment == displayedFragment)
                fragmentTransaction.show(fragment);
        }
    fragmentTransaction.commit();
    return lyricsViewFragment;
}
 
Example 4
Source File: MainActivity.java    From BlackLight with GNU General Public License v3.0 6 votes vote down vote up
private void switchTo(int id) {
	FragmentTransaction ft = mManager.beginTransaction();
	ft.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out, android.R.animator.fade_in, android.R.animator.fade_out);
	
	for (int i = 0; i < mFragments.length; i++) {
		Fragment f = mFragments[i];
		
		if (f != null) {
			if (i != id) {
				ft.hide(f);
			} else {
				ft.show(f);
			}
		}
	}
	
	ft.commit();
}
 
Example 5
Source File: Launcher.java    From TurboLauncher with Apache License 2.0 6 votes vote down vote up
public void onClickTransitionEffectButton(View v, final boolean pageOrDrawer) {
	Bundle bundle = new Bundle();
	bundle.putBoolean(
			TransitionEffectsFragment.PAGE_OR_DRAWER_SCROLL_SELECT,
			pageOrDrawer);
	FragmentManager fragmentManager = getFragmentManager();
	FragmentTransaction fragmentTransaction = fragmentManager
			.beginTransaction();

	mTransitionEffectsFragment = new TransitionEffectsFragment();
	mTransitionEffectsFragment.setArguments(bundle);
	fragmentTransaction.setCustomAnimations(0, 0);
	fragmentTransaction.replace(R.id.launcher, mTransitionEffectsFragment,
			TransitionEffectsFragment.TRANSITION_EFFECTS_FRAGMENT);
	fragmentTransaction.commit();
}
 
Example 6
Source File: DirectoryFragment.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
private static void show(FragmentManager fm, int type, RootInfo root, DocumentInfo doc, String query, int anim) {
	final Bundle args = new Bundle();
	args.putInt(EXTRA_TYPE, type);
	args.putParcelable(EXTRA_ROOT, root);
	args.putParcelable(EXTRA_DOC, doc);
	args.putString(EXTRA_QUERY, query);

	final FragmentTransaction ft = fm.beginTransaction();
	switch (anim) {
	case ANIM_SIDE:
		args.putBoolean(EXTRA_IGNORE_STATE, true);
		break;
	case ANIM_DOWN:
		ft.setCustomAnimations(R.animator.dir_down, R.animator.dir_frozen);
		break;
	case ANIM_UP:
		ft.setCustomAnimations(R.animator.dir_frozen, R.animator.dir_up);
		break;
	}

	final DirectoryFragment fragment = new DirectoryFragment();
	fragment.setArguments(args);

	ft.replace(R.id.container_directory, fragment);
	ft.commitAllowingStateLoss();
}
 
Example 7
Source File: DirectoryFragment.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
private static void show(FragmentManager fm, int type, RootInfo root, DocumentInfo doc, String query, int anim) {
	final Bundle args = new Bundle();
	args.putInt(EXTRA_TYPE, type);
	args.putParcelable(EXTRA_ROOT, root);
	args.putParcelable(EXTRA_DOC, doc);
	args.putString(EXTRA_QUERY, query);

	final FragmentTransaction ft = fm.beginTransaction();
	switch (anim) {
	case ANIM_SIDE:
		args.putBoolean(EXTRA_IGNORE_STATE, true);
		break;
	case ANIM_DOWN:
		ft.setCustomAnimations(R.animator.dir_down, R.animator.dir_frozen);
		break;
	case ANIM_UP:
		ft.setCustomAnimations(R.animator.dir_frozen, R.animator.dir_up);
		break;
	}

	final DirectoryFragment fragment = new DirectoryFragment();
	fragment.setArguments(args);

	ft.replace(R.id.container_directory, fragment);
	ft.commitAllowingStateLoss();
}
 
Example 8
Source File: HumanBodyActivity.java    From HumanBody with Apache License 2.0 5 votes vote down vote up
/**
 * 设置人体正反面
 * @author leibing
 * @createTime 2016/10/07
 * @lastModify 2016/10/07
 * @param
 * @return
 */
private void setBodyFrontBack() {
    switch (curSexFace){
        case MAN_FRONT:
            // 当为男性正面,则设置为男性反面
            curSexFace = MAN_BACK;
            break;
        case MAN_BACK:
            // 当为男性反面,则设置为男性正面
            curSexFace = MAN_FRONT;
            break;
        case WOMEN_FRONT:
            // 当为女性正面,则设置为女性反面
            curSexFace = WOMEN_BACK;
            break;
        case WOMEN_BACK:
            // 当为女性反面,则设置为女性正面
            curSexFace = WOMEN_FRONT;
            break;
    }

    if (curSexFace == MAN_FRONT || curSexFace == WOMEN_FRONT){
        // 当前面为男性正面或女性正面均设置为正面
        reverseTv.setText("正面");
    }else if (curSexFace == MAN_BACK || curSexFace == WOMEN_BACK){
        // 当前面为男性反面或女性反面均设置为反面
        reverseTv.setText("反面");
    }

    // 执行动画更新fragment内容
    FragmentTransaction fm = getFragmentManager().beginTransaction();
    fm.setCustomAnimations(R.anim.animator_two_enter, R.anim.animator_one_exit);
    fragmentHumanBody = HumanBodyFragment.newInstance(curSexFace);
    fm.replace(R.id.ly_fragment_area, fragmentHumanBody, "FragmentHumanBody");
    fm.commit();
}
 
Example 9
Source File: BasicActivity.java    From uPods-android with Apache License 2.0 5 votes vote down vote up
@Override
public void showFragment(int id, Fragment fragment, String tag, IFragmentsManager.FragmentOpenType openType, IFragmentsManager.FragmentAnimationType animationType) {
    android.app.FragmentManager fm = getFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    if (animationType == IFragmentsManager.FragmentAnimationType.BOTTOM_TOP) {
        ft.setCustomAnimations(R.animator.animation_fragment_bototm_top, R.animator.animation_fragment_top_bototm,
                R.animator.animation_fragment_bototm_top, R.animator.animation_fragment_top_bototm);
    }
    if (openType == IFragmentsManager.FragmentOpenType.OVERLAY) {
        ft.add(id, fragment, tag);
        if (this instanceof IOverlayable) {
            ((IOverlayable) this).toggleOverlay();
        }
    } else {
        ft.replace(id, fragment, tag);
    }
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);

    if (fragment instanceof IControlStackHistory) {//Decide ether fragment should be added to stack history
        if (((IControlStackHistory) fragment).shouldBeAddedToStack()) {
            ft.addToBackStack(tag);
        }
    } else {
        ft.addToBackStack(tag);
    }

    ft.commitAllowingStateLoss();
}
 
Example 10
Source File: ConversationsActivity.java    From Pix-Art-Messenger with GNU General Public License v3.0 5 votes vote down vote up
private void openConversation(Conversation conversation, Bundle extras) {
    ConversationFragment conversationFragment = (ConversationFragment) getFragmentManager().findFragmentById(R.id.secondary_fragment);
    final boolean mainNeedsRefresh;
    if (conversationFragment == null) {
        mainNeedsRefresh = false;
        Fragment mainFragment = getFragmentManager().findFragmentById(R.id.main_fragment);
        if (mainFragment instanceof ConversationFragment) {
            conversationFragment = (ConversationFragment) mainFragment;
        } else {
            conversationFragment = new ConversationFragment();
            FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
            fragmentTransaction.setCustomAnimations(
                    R.animator.fade_right_in, R.animator.fade_right_out,
                    R.animator.fade_right_in, R.animator.fade_right_out
            );
            fragmentTransaction.replace(R.id.main_fragment, conversationFragment);
            fragmentTransaction.addToBackStack(null);
            try {
                fragmentTransaction.commit();
            } catch (IllegalStateException e) {
                Log.w(Config.LOGTAG, "sate loss while opening conversation", e);
                //allowing state loss is probably fine since view intents et all are already stored and a click can probably be 'ignored'
                return;
            }
        }
    } else {
        mainNeedsRefresh = true;
    }
    conversationFragment.reInit(conversation, extras == null ? new Bundle() : extras);
    if (mainNeedsRefresh) {
        refreshFragment(R.id.main_fragment);
    } else {
        invalidateActionBarTitle();
    }
    IntroHelper.showIntro(this, conversation.getMode() == Conversational.MODE_MULTI);
}
 
Example 11
Source File: BlackListActivity.java    From NotificationPeekPort with Apache License 2.0 5 votes vote down vote up
/**
 * Replace black list fragment with suggestion list fragment, get ready to show suggestions.
 */
private void showSuggestionFragment() {
    if (mSuggestionFragment == null || mSuggestionShowing) {
        return;
    }

    mSuggestionShowing = true;

    FragmentTransaction ft = getFragmentManager().beginTransaction();
    ft.setCustomAnimations(R.animator.fragment_in, R.animator.fragment_out,
            R.animator.fragment_in, R.animator.fragment_out);

    ft.replace(R.id.fragment_container, mSuggestionFragment)
            .addToBackStack(null).commit();
}
 
Example 12
Source File: MainActivity.java    From QuickLyric with GNU General Public License v3.0 5 votes vote down vote up
public void updateLyricsFragment(int outAnim, int inAnim, boolean transition, boolean lock, Lyrics lyrics) {
    LyricsViewFragment lyricsViewFragment = (LyricsViewFragment) getFragmentManager().findFragmentByTag(LYRICS_FRAGMENT_TAG);
    FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
    fragmentTransaction.setCustomAnimations(inAnim, outAnim, inAnim, outAnim);
    Fragment activeFragment = getDisplayedFragment(getActiveFragments());
    if (lyricsViewFragment != null && lyricsViewFragment.getView() != null) {
        SharedPreferences preferences = getSharedPreferences("current_music", Context.MODE_PRIVATE);
        String artist = preferences.getString("artist", null);
        String track = preferences.getString("track", null);
        if (lyrics.isLRC() && !(lyrics.getOriginalArtist().equals(artist) && lyrics.getOriginalTitle().equals(track))) {
            LrcView parser = new LrcView(this, null);
            parser.setOriginalLyrics(lyrics);
            parser.setSourceLrc(lyrics.getText());
            lyrics = parser.getStaticLyrics();
        }
        lyricsViewFragment.manualUpdateLock = lock;
        lyricsViewFragment.update(lyrics, lyricsViewFragment.getView(), true);
        if (transition) {
            fragmentTransaction.hide(activeFragment).show(lyricsViewFragment);
            prepareAnimations(activeFragment);
            prepareAnimations(lyricsViewFragment);
        }
        showRefreshFab(true);
        lyricsViewFragment.expandToolbar();
    } else {
        Bundle lyricsBundle = new Bundle();
        try {
            lyricsBundle.putByteArray("lyrics", lyrics.toBytes());
        } catch (IOException e) {
            e.printStackTrace();
        }
        lyricsViewFragment = new LyricsViewFragment();
        lyricsViewFragment.setArguments(lyricsBundle);
        if (!(activeFragment instanceof LyricsViewFragment) && activeFragment != null)
            fragmentTransaction.hide(activeFragment).add(id.main_fragment_container, lyricsViewFragment, LYRICS_FRAGMENT_TAG);
        else
            fragmentTransaction.replace(id.main_fragment_container, lyricsViewFragment, LYRICS_FRAGMENT_TAG);
    }
    fragmentTransaction.commitAllowingStateLoss();
}
 
Example 13
Source File: Utils.java    From UTubeTV with The Unlicense 5 votes vote down vote up
public static void showFragment(Activity activity, Fragment fragment, int resID, int animationType, boolean addToBackStack) {
  // check params and bail if necessary
  if (fragment == null || activity == null) {
    DUtils.log("bad params: " + DUtils.currentMethod());
    return;
  }

  FragmentManager fragmentManager = activity.getFragmentManager();
  FragmentTransaction ft = fragmentManager.beginTransaction();

  switch (animationType) {
    case 0:
      break;
    //      case 1:
    //        ft.setCustomAnimations(R.animator.slide_in_left, R.animator.slide_out_left, R.animator.slide_in_right, R.animator.slide_out_right);
    //        break;
    //      case 2:
    //        ft.setCustomAnimations(R.animator.slide_in_down, R.animator.slide_out_down, R.animator.slide_in_up, R.animator.slide_out_up);
    //        break;
    //      case 3:
    //        ft.setCustomAnimations(R.animator.fraggy_enter, R.animator.fraggy_exit, R.animator.fraggy_pop_enter, R.animator.fraggy_pop_exit);
    //        break;
    default:
      ft.setCustomAnimations(R.animator.fade_enter, R.animator.fade_exit, R.animator.fade_enter, R.animator.fade_exit);
      break;
  }

  ft.replace(resID, fragment);

  if (addToBackStack)
    ft.addToBackStack(null);

  ft.commit();
}
 
Example 14
Source File: HumanBodyActivity.java    From HumanBody with Apache License 2.0 5 votes vote down vote up
/**
 * 设置人体正反面
 * @author leibing
 * @createTime 2016/10/07
 * @lastModify 2016/10/07
 * @param
 * @return
 */
private void setBodyFrontBack() {
    switch (curSexFace){
        case MAN_FRONT:
            // 当为男性正面,则设置为男性反面
            curSexFace = MAN_BACK;
            break;
        case MAN_BACK:
            // 当为男性反面,则设置为男性正面
            curSexFace = MAN_FRONT;
            break;
        case WOMEN_FRONT:
            // 当为女性正面,则设置为女性反面
            curSexFace = WOMEN_BACK;
            break;
        case WOMEN_BACK:
            // 当为女性反面,则设置为女性正面
            curSexFace = WOMEN_FRONT;
            break;
    }

    if (curSexFace == MAN_FRONT || curSexFace == WOMEN_FRONT){
        // 当前面为男性正面或女性正面均设置为正面
        reverseTv.setText("正面");
    }else if (curSexFace == MAN_BACK || curSexFace == WOMEN_BACK){
        // 当前面为男性反面或女性反面均设置为反面
        reverseTv.setText("反面");
    }

    // 执行动画更新fragment内容
    FragmentTransaction fm = getFragmentManager().beginTransaction();
    fm.setCustomAnimations(R.anim.animator_two_enter, R.anim.animator_one_exit);
    fragmentHumanBody = HumanBodyFragment.newInstance(curSexFace);
    fm.replace(R.id.ly_fragment_area, fragmentHumanBody, "FragmentHumanBody");
    fm.commit();
}
 
Example 15
Source File: MainActivity.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
public void onTabSelected(Tab tab, FragmentTransaction ft) {
	// Check if the fragment is already initialized
	if (mFragment == null) {
		// If not, instantiate and add it to the activity
		mFragment = Fragment.instantiate(mActivity, mClass.getName());
		ft.add(android.R.id.content, mFragment, mTag);
	} else {
		// If it exists, simply attach it in order to show it
		ft.setCustomAnimations(android.R.animator.fade_in,
				R.animator.animationtest);
		ft.attach(mFragment);
	}
}
 
Example 16
Source File: MainActivity.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
	if (mFragment != null) {
		ft.setCustomAnimations(android.R.animator.fade_in,
				R.animator.test);
		ft.detach(mFragment);
	}
}
 
Example 17
Source File: MainActivity.java    From Girls with Apache License 2.0 4 votes vote down vote up
private void switchToFragment(int i) {
    FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
    fragmentTransaction.setCustomAnimations(android.R.animator.fade_in,
            android.R.animator.fade_out);

    if (mCurrentFragmentIndex == i) {
        fragmentTransaction.add(R.id.fragmentContainer, getFragment(i));
        fragmentTransaction.commitAllowingStateLoss();
        mCurrentFragmentIndex = i;
        if (i == BOTTOM_ITEM_TITLE_MEIZI_INDEX) {
            mGirlFragmentAdded = true;
        }
        return;
    }

    fragmentTransaction.hide(getFragment(mCurrentFragmentIndex));

    switch (i) {
        case BOTTOM_ITEM_TITLE_MEIZI_INDEX:
            if (mGirlFragmentAdded) {
                fragmentTransaction.show(getFragment(i));
            } else {
                fragmentTransaction.add(R.id.fragmentContainer, getFragment(i));
                mGirlFragmentAdded = true;
            }
            break;
        case BOTTOM_ITEM_TITLE_ANDROID_INDEX:
            if (mAndroidFragmentAdded) {
                fragmentTransaction.show(getFragment(i));
            } else {
                fragmentTransaction.add(R.id.fragmentContainer, getFragment(i));
                mAndroidFragmentAdded = true;
            }
            break;
        case BOTTOM_ITEM_TITLE_IOS_INDEX:
            if (mIOSFragmentAdded) {
                fragmentTransaction.show(getFragment(i));
            } else {
                fragmentTransaction.add(R.id.fragmentContainer, getFragment(i));
                mIOSFragmentAdded = true;
            }
            break;
        case BOTTOM_ITEM_TITLE_VIDEO_INDEX:
            if (mVideoFragmentAdded) {
                fragmentTransaction.show(getFragment(i));
            } else {
                fragmentTransaction.add(R.id.fragmentContainer, getFragment(i));
                mVideoFragmentAdded = true;
            }
            break;
        case BOTTOM_ITEM_TITLE_WEB_INDEX:
            if (mWebFragmentAdded) {
                fragmentTransaction.show(getFragment(i));
            } else {
                fragmentTransaction.add(R.id.fragmentContainer, getFragment(i));
                mWebFragmentAdded = true;
            }
            break;
        default:
            break;
    }


    fragmentTransaction.commitAllowingStateLoss();
    mCurrentFragmentIndex = i;
}
 
Example 18
Source File: MainActivity.java    From QuickLyric with GNU General Public License v3.0 4 votes vote down vote up
public void updateLyricsFragment(int outAnim, String... params) { // Should only be called from SearchFragment or IdDecoder
    String artist = params[0];
    String song = params[1];
    String url = null;
    if (params.length > 2)
        url = params[2];
    LyricsViewFragment lyricsViewFragment = (LyricsViewFragment)
            getFragmentManager().findFragmentByTag(LYRICS_FRAGMENT_TAG);
    if (lyricsViewFragment != null) {
        if (!lyricsViewFragment.isActiveFragment) {
            selectItem(0);
        }
        lyricsViewFragment.fetchLyrics(true, null, 0L, params);
    } else {
        Lyrics lyrics = new Lyrics(Lyrics.SEARCH_ITEM);
        lyrics.setArtist(artist);
        lyrics.setTitle(song);
        lyrics.setURL(url);
        Bundle lyricsBundle = new Bundle();
        try {
            if (artist != null && song != null)
                lyricsBundle.putByteArray("lyrics", lyrics.toBytes());
        } catch (IOException e) {
            e.printStackTrace();
        }
        lyricsViewFragment = new LyricsViewFragment();
        lyricsViewFragment.setArguments(lyricsBundle);

        FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
        fragmentTransaction.setCustomAnimations(R.animator.slide_in_start, outAnim, R.animator.slide_in_start, outAnim);
        Fragment activeFragment = getDisplayedFragment(getActiveFragments());
        if (activeFragment != null) {
            prepareAnimations(activeFragment);
            fragmentTransaction.hide(activeFragment);
        }
        fragmentTransaction.add(id.main_fragment_container, lyricsViewFragment, LYRICS_FRAGMENT_TAG);
        lyricsViewFragment.isActiveFragment = true;
        fragmentTransaction.commit();
    }
    if (drawer instanceof DrawerLayout && !mDrawerToggle.isDrawerIndicatorEnabled()) {
        mDrawerToggle.setDrawerIndicatorEnabled(true);
        ((DrawerLayout) drawer).setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
    }
}
 
Example 19
Source File: MainActivity.java    From QuickLyric with GNU General Public License v3.0 4 votes vote down vote up
private void selectItem(int position) {
    FragmentManager fragmentManager = getFragmentManager();
    Fragment newFragment;
    String tag;
    switch (position) {
        default:
            // Lyrics
            tag = LYRICS_FRAGMENT_TAG;
            newFragment = fragmentManager.findFragmentByTag(tag);
            if (newFragment == null || !(newFragment instanceof LyricsViewFragment))
                newFragment = new LyricsViewFragment();
            ((LyricsViewFragment) newFragment).showTransitionAnim = true;
            break;
        case 1:
            // Recent Tracks
            tag = RECENT_TRACKS_FRAGMENT_TAG;
            newFragment = fragmentManager.findFragmentByTag(tag);
            if (newFragment == null || !(newFragment instanceof RecentTracksFragment))
                newFragment = new RecentTracksFragment();
            ((RecentTracksFragment) newFragment).showTransitionAnim = true;
            break;
        case 2:
            // Saved Lyrics
            tag = LOCAL_LYRICS_FRAGMENT_TAG;
            newFragment = fragmentManager.findFragmentByTag(tag);
            if (newFragment == null || !(newFragment instanceof LocalLyricsFragment))
                newFragment = new LocalLyricsFragment();
            ((LocalLyricsFragment) newFragment).showTransitionAnim = true;
            break;
        case 3:
            // Separator
            return;
        case 4:
            // Settings
            if (drawer instanceof DrawerLayout)
                ((DrawerLayout) drawer).closeDrawer(drawerView);
            drawer.postDelayed(new Runnable() {
                @Override
                public void run() {
                    Intent settingsIntent = new Intent(MainActivity.this, SettingsActivity.class);
                    startActivityForResult(settingsIntent, 77);
                }
            }, 250);
            return;
        case 5:
            // Feedback
            return;
        case 6:
            // About Dialog
            if (drawer instanceof DrawerLayout)
                ((DrawerLayout) drawer).closeDrawer(drawerView);
            drawer.postDelayed(new Runnable() {
                @Override
                public void run() {
                    Intent aboutIntent = new Intent(MainActivity.this, AboutActivity.class);
                    startActivityForResult(aboutIntent, 77);
                }
            }, 250);
            return;
    }

    final Fragment activeFragment = getDisplayedFragment(getActiveFragments());
    prepareAnimations(activeFragment);

    // Insert the fragment by replacing any existing fragment
    if (newFragment != activeFragment) {
        if (mActionMode != null)
            mActionMode.finish();
        FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
        fragmentTransaction.setCustomAnimations(R.animator.slide_in_start, R.animator.slide_out_start, R.animator.slide_in_start, R.animator.slide_out_start);
        fragmentTransaction.hide(activeFragment);
        if (newFragment.isAdded())
            fragmentTransaction.show(newFragment);
        else
            fragmentTransaction.add(id.main_fragment_container, newFragment, tag);
        ((CollapsingToolbarLayout) findViewById(R.id.toolbar_layout)).setCollapsedTitleTextColor(Color.WHITE);
        fragmentTransaction.commitAllowingStateLoss();
        if (activeFragment instanceof LyricsViewFragment || newFragment instanceof LyricsViewFragment) {
            final Fragment newFragmentCopy = newFragment;
            activeFragment.getView().postDelayed(() -> {
                if (activeFragment instanceof LyricsViewFragment && activeFragment.getView() != null) {
                    expandToolbar(false);
                    showRefreshFab(false);
                } else if (newFragmentCopy instanceof LyricsViewFragment && activeFragment.getView() != null) {
                    expandToolbar(true);
                    showRefreshFab(true);
                }
            }, getResources().getInteger(android.R.integer.config_longAnimTime));
        }
        MaterialSuggestionsSearchView suggestionsSearchView = findViewById(id.material_search_view);
        if (suggestionsSearchView.isSearchOpen())
            suggestionsSearchView.closeSearch();
    }
    if (drawer instanceof DrawerLayout && (newFragment == activeFragment))
        ((DrawerLayout) drawer).closeDrawer(drawerView);
}
 
Example 20
Source File: OrreryActivity.java    From AnimationApiDemos with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.orrery_main);

	ImageView orrery = (ImageView) findViewById(R.id.orrery);
	OrreryDrawable myOrreryDrawable = OrreryDrawable.Create();
	orrery.setImageDrawable(myOrreryDrawable);

	// ================================================================
	// 分别控制两种属性的动画
	// PropertyValuesHolder earthPositionValues = PropertyValuesHolder
	// .ofFloat("EarthPosition", 0, (float) (2 * Math.PI));
	// PropertyValuesHolder moonPositionValues =
	// PropertyValuesHolder.ofFloat(
	// "MoonPosition", 0, (float) (2 * Math.PI * 13));
	// ObjectAnimator orreryAnimator =
	// ObjectAnimator.ofPropertyValuesHolder(
	// myOrreryDrawable, earthPositionValues, moonPositionValues);

	// ================================================================
	// 使用新的数据结构,同时控制地球和月球
	OrreryDrawable.SolarSystemData startSolarSystemData = new OrreryDrawable.SolarSystemData();
	startSolarSystemData.rotationEarth = 0;
	startSolarSystemData.rotationMoon = 0;
	OrreryDrawable.SolarSystemData endSolarSystemData = new OrreryDrawable.SolarSystemData();
	endSolarSystemData.rotationEarth = (float) (2 * Math.PI);
	endSolarSystemData.rotationMoon = (float) (2 * Math.PI * 13);
	// 使用自定义的Evaluator
	OrreryEvaluator orreryEvaluator = new OrreryEvaluator();
	// ObjectAnimator orreryAnimator = ObjectAnimator.ofObject(
	// myOrreryDrawable, "SolarSystemData", orreryEvaluator,
	// startSolarSystemData, endSolarSystemData);

	// ================================================================
	// 尝试一下Keyframe
	Keyframe startFrame = Keyframe.ofObject(0, startSolarSystemData);
	Keyframe endFrame = Keyframe.ofObject(1, endSolarSystemData);
	PropertyValuesHolder solarSystemFrames = PropertyValuesHolder
			.ofKeyframe("SolarSystemData", startFrame, endFrame);
	solarSystemFrames.setEvaluator(orreryEvaluator);

	ObjectAnimator orreryAnimator = ObjectAnimator.ofPropertyValuesHolder(
			myOrreryDrawable, solarSystemFrames);

	// Default value is 10
	Log.i("FrameDelay", "delay: " + ValueAnimator.getFrameDelay());
	ValueAnimator.setFrameDelay(50);

	orreryAnimator.setDuration(60000);
	orreryAnimator.setInterpolator(new LinearInterpolator());
	orreryAnimator.setRepeatCount(ValueAnimator.INFINITE);
	orreryAnimator.setRepeatMode(ValueAnimator.RESTART);

	orreryAnimator.start();

	// add the fragment:
	FragmentTransaction ft = getFragmentManager().beginTransaction();

	ft.setCustomAnimations(R.anim.fade_in, android.R.animator.fade_out);
	ft.add(R.id.frame, new OrreryInfo());
	ft.commit();
}