List of usage examples for android.support.v4.app FragmentManager beginTransaction
public abstract FragmentTransaction beginTransaction();
From source file:android.support.v17.leanback.app.BrowseSupportFragment.java
private void swapToMainFragment() { final VerticalGridView gridView = mHeadersSupportFragment.getVerticalGridView(); if (isShowingHeaders() && gridView != null && gridView.getScrollState() != RecyclerView.SCROLL_STATE_IDLE) { // if user is scrolling HeadersSupportFragment, swap to empty fragment and wait scrolling // finishes. getChildFragmentManager().beginTransaction().replace(R.id.scale_frame, new Fragment()).commit(); gridView.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override/* w ww. j av a2 s.co m*/ public void onScrollStateChanged(RecyclerView recyclerView, int newState) { if (newState == RecyclerView.SCROLL_STATE_IDLE) { gridView.removeOnScrollListener(this); FragmentManager fm = getChildFragmentManager(); Fragment currentFragment = fm.findFragmentById(R.id.scale_frame); if (currentFragment != mMainFragment) { fm.beginTransaction().replace(R.id.scale_frame, mMainFragment).commit(); } } } }); } else { // Otherwise swap immediately getChildFragmentManager().beginTransaction().replace(R.id.scale_frame, mMainFragment).commit(); } }
From source file:br.liveo.ndrawer.ui.activity.MainActivity.java
License:asdf
@Override public void onItemClick(int position) { Fragment mFragment;//from ww w.j a v a 2 s.c o m FragmentManager mFragmentManager = getSupportFragmentManager(); if (position == 0) { mFragment = new ViewPagerFragment(); } else if (position == 1) { mFragment = new ViewPagerFragment5(); } else if (position == 2) { mFragment = new ViewPagerFragment3(); } else { mFragment = new ViewPagerFragment4(); } if (mFragment != null) { mFragmentManager.beginTransaction().replace(R.id.container, mFragment).commit(); } setElevationToolBar(position != 2 ? 15 : 0); }
From source file:com.cardio3g.MainActivity.java
@Override public void onClick(View view) { if (view == btnBuiltIn) { if (boolBuilt) { boolBuilt = false;//from w w w .j a v a2 s . c o m if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { btnBuiltIn.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnMuscleIsolation.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnCustomProgram.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnSportsTraining.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnhealthyLiving.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnPersonalTrainer.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnVideos.setBackground(getResources().getDrawable(R.drawable.smallbtn, null)); btnVideos.setTextColor(getResources().getColor(android.R.color.white, null)); btnCardio.setBackground(getResources().getDrawable(R.drawable.smallbtn, null)); btnCardio.setTextColor(getResources().getColor(android.R.color.white, null)); btnImages.setBackground(getResources().getDrawable(R.drawable.smallbtn, null)); btnImages.setTextColor(getResources().getColor(android.R.color.white, null)); Fragment f = getSupportFragmentManager().findFragmentById(R.id.frame); android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager(); android.support.v4.app.FragmentTransaction fragmentTransaction = fragmentManager .beginTransaction(); fragmentTransaction.setCustomAnimations(R.anim.push_down_in, R.anim.push_down_in); if (f != null) fragmentTransaction.remove(f); fragmentTransaction.commit(); } else { btnBuiltIn.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnMuscleIsolation.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnCustomProgram.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnSportsTraining.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnhealthyLiving.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnPersonalTrainer.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnVideos.setBackground(getResources().getDrawable(R.drawable.smallbtn)); btnVideos.setTextColor(getResources().getColor(android.R.color.white)); btnCardio.setBackground(getResources().getDrawable(R.drawable.smallbtn)); btnCardio.setTextColor(getResources().getColor(android.R.color.white)); btnImages.setBackground(getResources().getDrawable(R.drawable.smallbtn)); btnImages.setTextColor(getResources().getColor(android.R.color.white)); Fragment f = getSupportFragmentManager().findFragmentById(R.id.frame); android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager(); android.support.v4.app.FragmentTransaction fragmentTransaction = fragmentManager .beginTransaction(); if (f != null) fragmentTransaction.remove(f); fragmentTransaction.commit(); } } else { boolBuilt = true; removeAllFragments(getSupportFragmentManager()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { btnBuiltIn.setBackground(getResources().getDrawable(R.drawable.buttonselected, null)); btnMuscleIsolation.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnCustomProgram.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnSportsTraining.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnhealthyLiving.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnPersonalTrainer.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnVideos.setBackground(getResources().getDrawable(R.drawable.smallbtn, null)); btnVideos.setTextColor(getResources().getColor(android.R.color.white, null)); btnCardio.setBackground(getResources().getDrawable(R.drawable.smallbtn, null)); btnCardio.setTextColor(getResources().getColor(android.R.color.white, null)); btnImages.setBackground(getResources().getDrawable(R.drawable.smallbtn, null)); btnImages.setTextColor(getResources().getColor(android.R.color.white, null)); android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager(); android.support.v4.app.FragmentTransaction fragmentTransaction = fragmentManager .beginTransaction(); fragmentTransaction.setCustomAnimations(R.anim.push_up_in, R.anim.push_up_in); fragmentTransaction.replace(R.id.frame, new BuiltInProgramsFragment()); fragmentTransaction.addToBackStack(null); fragmentTransaction.commit(); } else { btnBuiltIn.setBackground(getResources().getDrawable(R.drawable.buttonselected)); btnMuscleIsolation.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnCustomProgram.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnSportsTraining.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnhealthyLiving.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnPersonalTrainer.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnVideos.setBackground(getResources().getDrawable(R.drawable.smallbtn)); btnVideos.setTextColor(getResources().getColor(android.R.color.white)); btnCardio.setBackground(getResources().getDrawable(R.drawable.smallbtn)); btnCardio.setTextColor(getResources().getColor(android.R.color.white)); btnImages.setBackground(getResources().getDrawable(R.drawable.smallbtn)); btnImages.setTextColor(getResources().getColor(android.R.color.white)); android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager(); android.support.v4.app.FragmentTransaction fragmentTransaction = fragmentManager .beginTransaction(); fragmentTransaction.replace(R.id.frame, new BuiltInProgramsFragment()); fragmentTransaction.addToBackStack(null); fragmentTransaction.commit(); } } } if (view == btnMuscleIsolation) { if (boolMuscle) { boolMuscle = false; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { btnBuiltIn.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnMuscleIsolation.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnCustomProgram.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnSportsTraining.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnhealthyLiving.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnPersonalTrainer.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnVideos.setBackground(getResources().getDrawable(R.drawable.smallbtn, null)); btnVideos.setTextColor(getResources().getColor(android.R.color.white, null)); btnCardio.setBackground(getResources().getDrawable(R.drawable.smallbtn, null)); btnCardio.setTextColor(getResources().getColor(android.R.color.white, null)); btnImages.setBackground(getResources().getDrawable(R.drawable.smallbtn, null)); btnImages.setTextColor(getResources().getColor(android.R.color.white, null)); Fragment f = getSupportFragmentManager().findFragmentById(R.id.frame); android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager(); android.support.v4.app.FragmentTransaction fragmentTransaction = fragmentManager .beginTransaction(); fragmentTransaction.setCustomAnimations(R.anim.push_down_in, R.anim.push_down_in); if (f != null) fragmentTransaction.remove(f); fragmentTransaction.commit(); } else { btnBuiltIn.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnMuscleIsolation.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnCustomProgram.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnSportsTraining.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnhealthyLiving.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnPersonalTrainer.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnVideos.setBackground(getResources().getDrawable(R.drawable.smallbtn)); btnVideos.setTextColor(getResources().getColor(android.R.color.white)); btnCardio.setBackground(getResources().getDrawable(R.drawable.smallbtn)); btnCardio.setTextColor(getResources().getColor(android.R.color.white)); btnImages.setBackground(getResources().getDrawable(R.drawable.smallbtn)); btnImages.setTextColor(getResources().getColor(android.R.color.white)); Fragment f = getSupportFragmentManager().findFragmentById(R.id.frame); android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager(); android.support.v4.app.FragmentTransaction fragmentTransaction = fragmentManager .beginTransaction(); if (f != null) fragmentTransaction.remove(f); fragmentTransaction.commit(); } } else { boolMuscle = true; removeAllFragments(getSupportFragmentManager()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { btnBuiltIn.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnMuscleIsolation.setBackground(getResources().getDrawable(R.drawable.buttonselected, null)); btnCustomProgram.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnSportsTraining.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnhealthyLiving.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnPersonalTrainer.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnVideos.setBackground(getResources().getDrawable(R.drawable.smallbtn, null)); btnVideos.setTextColor(getResources().getColor(android.R.color.white, null)); btnCardio.setBackground(getResources().getDrawable(R.drawable.smallbtn, null)); btnCardio.setTextColor(getResources().getColor(android.R.color.white, null)); btnImages.setBackground(getResources().getDrawable(R.drawable.smallbtn, null)); btnImages.setTextColor(getResources().getColor(android.R.color.white, null)); android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager(); android.support.v4.app.FragmentTransaction fragmentTransaction = fragmentManager .beginTransaction(); fragmentTransaction.setCustomAnimations(R.anim.push_up_in, R.anim.push_up_out); fragmentTransaction.replace(R.id.frame, new MuscleIsolationFragment()); fragmentTransaction.addToBackStack(null); fragmentTransaction.commit(); } else { btnBuiltIn.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnMuscleIsolation.setBackground(getResources().getDrawable(R.drawable.buttonselected)); btnCustomProgram.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnSportsTraining.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnhealthyLiving.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnPersonalTrainer.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnVideos.setBackground(getResources().getDrawable(R.drawable.smallbtn)); btnVideos.setTextColor(getResources().getColor(android.R.color.white)); btnCardio.setBackground(getResources().getDrawable(R.drawable.smallbtn)); btnCardio.setTextColor(getResources().getColor(android.R.color.white)); btnImages.setBackground(getResources().getDrawable(R.drawable.smallbtn)); btnImages.setTextColor(getResources().getColor(android.R.color.white)); android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager(); android.support.v4.app.FragmentTransaction fragmentTransaction = fragmentManager .beginTransaction(); fragmentTransaction.replace(R.id.frame, new MuscleIsolationFragment()); fragmentTransaction.addToBackStack(null); fragmentTransaction.commit(); } } } if (view == btnCustomProgram) { if (boolCustom) { boolCustom = false; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { btnBuiltIn.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnMuscleIsolation.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnCustomProgram.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnSportsTraining.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnhealthyLiving.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnPersonalTrainer.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnVideos.setBackground(getResources().getDrawable(R.drawable.smallbtn, null)); btnVideos.setTextColor(getResources().getColor(android.R.color.white, null)); btnCardio.setBackground(getResources().getDrawable(R.drawable.smallbtn, null)); btnCardio.setTextColor(getResources().getColor(android.R.color.white, null)); btnImages.setBackground(getResources().getDrawable(R.drawable.smallbtn, null)); btnImages.setTextColor(getResources().getColor(android.R.color.white, null)); Fragment f = getSupportFragmentManager().findFragmentById(R.id.frame); android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager(); android.support.v4.app.FragmentTransaction fragmentTransaction = fragmentManager .beginTransaction(); fragmentTransaction.setCustomAnimations(R.anim.push_down_in, R.anim.push_down_in); if (f != null) fragmentTransaction.remove(f); fragmentTransaction.commit(); } else { btnBuiltIn.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnMuscleIsolation.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnCustomProgram.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnSportsTraining.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnhealthyLiving.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnPersonalTrainer.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnVideos.setBackground(getResources().getDrawable(R.drawable.smallbtn)); btnVideos.setTextColor(getResources().getColor(android.R.color.white)); btnCardio.setBackground(getResources().getDrawable(R.drawable.smallbtn)); btnCardio.setTextColor(getResources().getColor(android.R.color.white)); btnImages.setBackground(getResources().getDrawable(R.drawable.smallbtn)); btnImages.setTextColor(getResources().getColor(android.R.color.white)); Fragment f = getSupportFragmentManager().findFragmentById(R.id.frame); android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager(); android.support.v4.app.FragmentTransaction fragmentTransaction = fragmentManager .beginTransaction(); if (f != null) fragmentTransaction.remove(f); fragmentTransaction.commit(); } } else { boolCustom = true; removeAllFragments(getSupportFragmentManager()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { btnBuiltIn.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnMuscleIsolation.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnCustomProgram.setBackground(getResources().getDrawable(R.drawable.buttonselected, null)); btnSportsTraining.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnhealthyLiving.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnPersonalTrainer.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnVideos.setBackground(getResources().getDrawable(R.drawable.smallbtn, null)); btnVideos.setTextColor(getResources().getColor(android.R.color.white, null)); btnCardio.setBackground(getResources().getDrawable(R.drawable.smallbtn, null)); btnCardio.setTextColor(getResources().getColor(android.R.color.white, null)); btnImages.setBackground(getResources().getDrawable(R.drawable.smallbtn, null)); btnImages.setTextColor(getResources().getColor(android.R.color.white, null)); android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager(); android.support.v4.app.FragmentTransaction fragmentTransaction = fragmentManager .beginTransaction(); fragmentTransaction.setCustomAnimations(R.anim.push_up_in, R.anim.push_up_out); fragmentTransaction.replace(R.id.frame, new CustomProgramFragment()); fragmentTransaction.addToBackStack(null); fragmentTransaction.commit(); } else { btnBuiltIn.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnMuscleIsolation.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnCustomProgram.setBackground(getResources().getDrawable(R.drawable.buttonselected)); btnSportsTraining.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnhealthyLiving.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnPersonalTrainer.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnVideos.setBackground(getResources().getDrawable(R.drawable.smallbtn)); btnVideos.setTextColor(getResources().getColor(android.R.color.white)); btnCardio.setBackground(getResources().getDrawable(R.drawable.smallbtn)); btnCardio.setTextColor(getResources().getColor(android.R.color.white)); btnImages.setBackground(getResources().getDrawable(R.drawable.smallbtn)); btnImages.setTextColor(getResources().getColor(android.R.color.white)); android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager(); android.support.v4.app.FragmentTransaction fragmentTransaction = fragmentManager .beginTransaction(); fragmentTransaction.replace(R.id.frame, new CustomProgramFragment()); fragmentTransaction.addToBackStack(null); fragmentTransaction.commit(); } } } if (view == btnSportsTraining) { if (boolSports) { boolSports = false; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { btnBuiltIn.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnMuscleIsolation.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnCustomProgram.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnSportsTraining.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnhealthyLiving.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnPersonalTrainer.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnVideos.setBackground(getResources().getDrawable(R.drawable.smallbtn, null)); btnVideos.setTextColor(getResources().getColor(android.R.color.white, null)); btnCardio.setBackground(getResources().getDrawable(R.drawable.smallbtn, null)); btnCardio.setTextColor(getResources().getColor(android.R.color.white, null)); btnImages.setBackground(getResources().getDrawable(R.drawable.smallbtn, null)); btnImages.setTextColor(getResources().getColor(android.R.color.white, null)); Fragment f = getSupportFragmentManager().findFragmentById(R.id.frame); android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager(); android.support.v4.app.FragmentTransaction fragmentTransaction = fragmentManager .beginTransaction(); fragmentTransaction.setCustomAnimations(R.anim.push_down_in, R.anim.push_down_in); if (f != null) fragmentTransaction.remove(f); fragmentTransaction.commit(); } else { btnBuiltIn.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnMuscleIsolation.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnCustomProgram.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnSportsTraining.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnhealthyLiving.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnPersonalTrainer.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnVideos.setBackground(getResources().getDrawable(R.drawable.smallbtn)); btnVideos.setTextColor(getResources().getColor(android.R.color.white)); btnCardio.setBackground(getResources().getDrawable(R.drawable.smallbtn)); btnCardio.setTextColor(getResources().getColor(android.R.color.white)); btnImages.setBackground(getResources().getDrawable(R.drawable.smallbtn)); btnImages.setTextColor(getResources().getColor(android.R.color.white)); Fragment f = getSupportFragmentManager().findFragmentById(R.id.frame); android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager(); android.support.v4.app.FragmentTransaction fragmentTransaction = fragmentManager .beginTransaction(); if (f != null) fragmentTransaction.remove(f); fragmentTransaction.commit(); } } else { boolSports = true; removeAllFragments(getSupportFragmentManager()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { btnBuiltIn.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnMuscleIsolation.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnCustomProgram.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnSportsTraining.setBackground(getResources().getDrawable(R.drawable.buttonselected, null)); btnhealthyLiving.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnPersonalTrainer.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnVideos.setBackground(getResources().getDrawable(R.drawable.smallbtn, null)); btnVideos.setTextColor(getResources().getColor(android.R.color.white, null)); btnCardio.setBackground(getResources().getDrawable(R.drawable.smallbtn, null)); btnCardio.setTextColor(getResources().getColor(android.R.color.white, null)); btnImages.setBackground(getResources().getDrawable(R.drawable.smallbtn, null)); btnImages.setTextColor(getResources().getColor(android.R.color.white, null)); android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager(); android.support.v4.app.FragmentTransaction fragmentTransaction = fragmentManager .beginTransaction(); fragmentTransaction.setCustomAnimations(R.anim.push_up_in, R.anim.push_up_out); fragmentTransaction.replace(R.id.frame, new SportsTrainingFragment()); fragmentTransaction.addToBackStack(null); fragmentTransaction.commit(); } else { btnBuiltIn.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnMuscleIsolation.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnCustomProgram.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnSportsTraining.setBackground(getResources().getDrawable(R.drawable.buttonselected)); btnhealthyLiving.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnPersonalTrainer.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnVideos.setBackground(getResources().getDrawable(R.drawable.smallbtn)); btnVideos.setTextColor(getResources().getColor(android.R.color.white)); btnCardio.setBackground(getResources().getDrawable(R.drawable.smallbtn)); btnCardio.setTextColor(getResources().getColor(android.R.color.white)); btnImages.setBackground(getResources().getDrawable(R.drawable.smallbtn)); btnImages.setTextColor(getResources().getColor(android.R.color.white)); android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager(); android.support.v4.app.FragmentTransaction fragmentTransaction = fragmentManager .beginTransaction(); //fragmentTransaction.setCustomAnimations(R.anim.push_up_in,R.anim.push_up_out); fragmentTransaction.replace(R.id.frame, new SportsTrainingFragment()); fragmentTransaction.addToBackStack(null); fragmentTransaction.commit(); } } } if (view == btnhealthyLiving) { if (boolHealthy) { boolHealthy = false; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { btnBuiltIn.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnMuscleIsolation.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnCustomProgram.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnSportsTraining.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnhealthyLiving.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnPersonalTrainer.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnVideos.setBackground(getResources().getDrawable(R.drawable.smallbtn, null)); btnVideos.setTextColor(getResources().getColor(android.R.color.white, null)); btnCardio.setBackground(getResources().getDrawable(R.drawable.smallbtn, null)); btnCardio.setTextColor(getResources().getColor(android.R.color.white, null)); btnImages.setBackground(getResources().getDrawable(R.drawable.smallbtn, null)); btnImages.setTextColor(getResources().getColor(android.R.color.white, null)); Fragment f = getSupportFragmentManager().findFragmentById(R.id.frame); android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager(); android.support.v4.app.FragmentTransaction fragmentTransaction = fragmentManager .beginTransaction(); fragmentTransaction.setCustomAnimations(R.anim.push_down_in, R.anim.push_down_in); if (f != null) fragmentTransaction.remove(f); fragmentTransaction.commit(); } else { btnBuiltIn.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnMuscleIsolation.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnCustomProgram.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnSportsTraining.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnhealthyLiving.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnPersonalTrainer.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnVideos.setBackground(getResources().getDrawable(R.drawable.smallbtn)); btnVideos.setTextColor(getResources().getColor(android.R.color.white)); btnCardio.setBackground(getResources().getDrawable(R.drawable.smallbtn)); btnCardio.setTextColor(getResources().getColor(android.R.color.white)); btnImages.setBackground(getResources().getDrawable(R.drawable.smallbtn)); btnImages.setTextColor(getResources().getColor(android.R.color.white)); Fragment f = getSupportFragmentManager().findFragmentById(R.id.frame); android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager(); android.support.v4.app.FragmentTransaction fragmentTransaction = fragmentManager .beginTransaction(); //fragmentTransaction.setCustomAnimations(R.anim.push_down_in,R.anim.push_down_in); if (f != null) fragmentTransaction.remove(f); fragmentTransaction.commit(); } } else { boolHealthy = true; removeAllFragments(getSupportFragmentManager()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { btnBuiltIn.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnMuscleIsolation.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnCustomProgram.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnSportsTraining.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnhealthyLiving.setBackground(getResources().getDrawable(R.drawable.buttonselected, null)); btnPersonalTrainer.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnVideos.setBackground(getResources().getDrawable(R.drawable.smallbtn, null)); btnVideos.setTextColor(getResources().getColor(android.R.color.white, null)); btnCardio.setBackground(getResources().getDrawable(R.drawable.smallbtn, null)); btnCardio.setTextColor(getResources().getColor(android.R.color.white, null)); btnImages.setBackground(getResources().getDrawable(R.drawable.smallbtn, null)); btnImages.setTextColor(getResources().getColor(android.R.color.white, null)); android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager(); android.support.v4.app.FragmentTransaction fragmentTransaction = fragmentManager .beginTransaction(); fragmentTransaction.setCustomAnimations(R.anim.push_up_in, R.anim.push_up_out); fragmentTransaction.replace(R.id.frame, new HealthyLivingFragment()); fragmentTransaction.addToBackStack(null); fragmentTransaction.commit(); } else { btnBuiltIn.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnMuscleIsolation.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnCustomProgram.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnSportsTraining.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnhealthyLiving.setBackground(getResources().getDrawable(R.drawable.buttonselected)); btnPersonalTrainer.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnVideos.setBackground(getResources().getDrawable(R.drawable.smallbtn)); btnVideos.setTextColor(getResources().getColor(android.R.color.white)); btnCardio.setBackground(getResources().getDrawable(R.drawable.smallbtn)); btnCardio.setTextColor(getResources().getColor(android.R.color.white)); btnImages.setBackground(getResources().getDrawable(R.drawable.smallbtn)); btnImages.setTextColor(getResources().getColor(android.R.color.white)); android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager(); android.support.v4.app.FragmentTransaction fragmentTransaction = fragmentManager .beginTransaction(); //fragmentTransaction.setCustomAnimations(R.anim.push_up_in,R.anim.push_up_out); fragmentTransaction.replace(R.id.frame, new HealthyLivingFragment()); fragmentTransaction.addToBackStack(null); fragmentTransaction.commit(); } } } if (view == btnPersonalTrainer) { if (boolPersonal) { boolPersonal = false; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { btnBuiltIn.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnMuscleIsolation.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnCustomProgram.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnSportsTraining.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnhealthyLiving.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnPersonalTrainer.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnVideos.setBackground(getResources().getDrawable(R.drawable.smallbtn, null)); btnVideos.setTextColor(getResources().getColor(android.R.color.white, null)); btnCardio.setBackground(getResources().getDrawable(R.drawable.smallbtn, null)); btnCardio.setTextColor(getResources().getColor(android.R.color.white, null)); btnImages.setBackground(getResources().getDrawable(R.drawable.smallbtn, null)); btnImages.setTextColor(getResources().getColor(android.R.color.white, null)); Fragment f = getSupportFragmentManager().findFragmentById(R.id.frame); android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager(); android.support.v4.app.FragmentTransaction fragmentTransaction = fragmentManager .beginTransaction(); fragmentTransaction.setCustomAnimations(R.anim.push_down_in, R.anim.push_down_in); if (f != null) fragmentTransaction.remove(f); fragmentTransaction.commit(); } else { btnBuiltIn.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnMuscleIsolation.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnCustomProgram.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnSportsTraining.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnhealthyLiving.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnPersonalTrainer.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnVideos.setBackground(getResources().getDrawable(R.drawable.smallbtn)); btnVideos.setTextColor(getResources().getColor(android.R.color.white)); btnCardio.setBackground(getResources().getDrawable(R.drawable.smallbtn)); btnCardio.setTextColor(getResources().getColor(android.R.color.white)); btnImages.setBackground(getResources().getDrawable(R.drawable.smallbtn)); btnImages.setTextColor(getResources().getColor(android.R.color.white)); Fragment f = getSupportFragmentManager().findFragmentById(R.id.frame); android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager(); android.support.v4.app.FragmentTransaction fragmentTransaction = fragmentManager .beginTransaction(); //fragmentTransaction.setCustomAnimations(R.anim.push_down_in,R.anim.push_down_in); if (f != null) fragmentTransaction.remove(f); fragmentTransaction.commit(); } } else { boolPersonal = true; removeAllFragments(getSupportFragmentManager()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { btnBuiltIn.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnMuscleIsolation.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnCustomProgram.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnSportsTraining.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnhealthyLiving.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnPersonalTrainer.setBackground(getResources().getDrawable(R.drawable.buttonselected, null)); btnVideos.setBackground(getResources().getDrawable(R.drawable.smallbtn, null)); btnVideos.setTextColor(getResources().getColor(android.R.color.white, null)); btnCardio.setBackground(getResources().getDrawable(R.drawable.smallbtn, null)); btnCardio.setTextColor(getResources().getColor(android.R.color.white, null)); btnImages.setBackground(getResources().getDrawable(R.drawable.smallbtn, null)); btnImages.setTextColor(getResources().getColor(android.R.color.white, null)); removeAllFragments(getSupportFragmentManager()); android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager(); android.support.v4.app.FragmentTransaction fragmentTransaction = fragmentManager .beginTransaction(); fragmentTransaction.setCustomAnimations(R.anim.push_up_in, R.anim.push_up_out); fragmentTransaction.replace(R.id.frame, new PersonalTrainerFragment()); fragmentTransaction.addToBackStack(null); fragmentTransaction.commit(); } else { btnBuiltIn.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnMuscleIsolation.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnCustomProgram.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnSportsTraining.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnhealthyLiving.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnPersonalTrainer.setBackground(getResources().getDrawable(R.drawable.buttonselected)); btnVideos.setBackground(getResources().getDrawable(R.drawable.smallbtn)); btnVideos.setTextColor(getResources().getColor(android.R.color.white)); btnCardio.setBackground(getResources().getDrawable(R.drawable.smallbtn)); btnCardio.setTextColor(getResources().getColor(android.R.color.white)); btnImages.setBackground(getResources().getDrawable(R.drawable.smallbtn)); btnImages.setTextColor(getResources().getColor(android.R.color.white)); android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager(); android.support.v4.app.FragmentTransaction fragmentTransaction = fragmentManager .beginTransaction(); fragmentTransaction.replace(R.id.frame, new PersonalTrainerFragment()); fragmentTransaction.addToBackStack(null); fragmentTransaction.commit(); } } } if (view == btnVideos) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { btnVideos.setBackground(getResources().getDrawable(R.drawable.smallbtnclickd, null)); btnVideos.setTextColor(getResources().getColor(android.R.color.black, null)); btnBuiltIn.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnMuscleIsolation.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnCustomProgram.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnSportsTraining.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnhealthyLiving.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnPersonalTrainer.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnCardio.setBackground(getResources().getDrawable(R.drawable.smallbtn, null)); btnCardio.setTextColor(getResources().getColor(android.R.color.white, null)); btnImages.setBackground(getResources().getDrawable(R.drawable.smallbtn, null)); btnImages.setTextColor(getResources().getColor(android.R.color.white, null)); Intent intent = new Intent(MainActivity.this, AllImagesVideosActivity.class); intent.putExtra("type", "video"); startActivity(intent); } else { btnVideos.setBackground(getResources().getDrawable(R.drawable.smallbtnclickd)); btnVideos.setTextColor(getResources().getColor(android.R.color.black)); btnBuiltIn.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnMuscleIsolation.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnCustomProgram.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnSportsTraining.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnhealthyLiving.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnPersonalTrainer.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnCardio.setBackground(getResources().getDrawable(R.drawable.smallbtn)); btnCardio.setTextColor(getResources().getColor(android.R.color.white)); btnImages.setBackground(getResources().getDrawable(R.drawable.smallbtn)); btnImages.setTextColor(getResources().getColor(android.R.color.white)); Intent intent = new Intent(MainActivity.this, AllImagesVideosActivity.class); intent.putExtra("type", "video"); startActivity(intent); } } if (view == btnCardio) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { btnCardio.setBackground(getResources().getDrawable(R.drawable.smallbtnclickd, null)); btnCardio.setTextColor(getResources().getColor(android.R.color.black, null)); btnBuiltIn.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnMuscleIsolation.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnCustomProgram.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnSportsTraining.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnhealthyLiving.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnPersonalTrainer.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnVideos.setBackground(getResources().getDrawable(R.drawable.smallbtn, null)); btnVideos.setTextColor(getResources().getColor(android.R.color.white, null)); btnImages.setBackground(getResources().getDrawable(R.drawable.smallbtn, null)); btnImages.setTextColor(getResources().getColor(android.R.color.white, null)); try { startActivity(new Intent(MainActivity.this, Visit3GCardioActivity.class)); finish(); } catch (Exception e) { e.printStackTrace(); } } else { btnCardio.setBackground(getResources().getDrawable(R.drawable.smallbtnclickd)); btnCardio.setTextColor(getResources().getColor(android.R.color.black)); btnBuiltIn.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnMuscleIsolation.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnCustomProgram.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnSportsTraining.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnhealthyLiving.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnPersonalTrainer.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnVideos.setBackground(getResources().getDrawable(R.drawable.smallbtn)); btnVideos.setTextColor(getResources().getColor(android.R.color.white)); btnImages.setBackground(getResources().getDrawable(R.drawable.smallbtn)); btnImages.setTextColor(getResources().getColor(android.R.color.white)); try { startActivity(new Intent(MainActivity.this, Visit3GCardioActivity.class)); finish(); } catch (Exception e) { e.printStackTrace(); } } } if (view == btnImages) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { btnImages.setBackground(getResources().getDrawable(R.drawable.smallbtnclickd, null)); btnImages.setTextColor(getResources().getColor(android.R.color.black, null)); btnBuiltIn.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnMuscleIsolation.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnCustomProgram.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnSportsTraining.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnhealthyLiving.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnPersonalTrainer.setBackground(getResources().getDrawable(R.drawable.buttonunselected, null)); btnVideos.setBackground(getResources().getDrawable(R.drawable.smallbtn, null)); btnVideos.setTextColor(getResources().getColor(android.R.color.white, null)); btnCardio.setBackground(getResources().getDrawable(R.drawable.smallbtn, null)); btnCardio.setTextColor(getResources().getColor(android.R.color.white, null)); Intent intent = new Intent(MainActivity.this, AllImagesVideosActivity.class); intent.putExtra("type", "image"); startActivity(intent); } else { btnImages.setBackground(getResources().getDrawable(R.drawable.smallbtnclickd)); btnImages.setTextColor(getResources().getColor(android.R.color.black)); btnBuiltIn.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnMuscleIsolation.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnCustomProgram.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnSportsTraining.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnhealthyLiving.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnPersonalTrainer.setBackground(getResources().getDrawable(R.drawable.buttonunselected)); btnVideos.setBackground(getResources().getDrawable(R.drawable.smallbtn)); btnVideos.setTextColor(getResources().getColor(android.R.color.white)); btnCardio.setBackground(getResources().getDrawable(R.drawable.smallbtn)); btnCardio.setTextColor(getResources().getColor(android.R.color.white)); Intent intent = new Intent(MainActivity.this, AllImagesVideosActivity.class); intent.putExtra("type", "image"); startActivity(intent); } } }
From source file:com.aimfire.gallery.GalleryActivity.java
private void addDownloadFileFragment(String resId, String name, int size) { try {// w ww . ja v a2 s. c om FragmentManager fragmentManager = getSupportFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); Bundle bundle = new Bundle(); bundle.putString(MainConsts.EXTRA_ID_RESOURCE, resId); bundle.putString(MainConsts.EXTRA_NAME, name); bundle.putInt(MainConsts.EXTRA_SIZE, size); DownloadFileFragment ddf = new DownloadFileFragment(); ddf.setArguments(bundle); ddf.setRetainInstance(true); fragmentTransaction.add(R.id.display_panel, ddf, name); fragmentTransaction.commitAllowingStateLoss(); } catch (Exception e) { /* * we could potentially have the same kind of exception we saw * when we remove fragment in the midst of screen rotation. it * is not clear if/when this happens, if the fragment will be * created/added. */ if (BuildConfig.DEBUG) Log.e(TAG, "addDownloadFileFragment: commit failed " + e.getMessage()); } }
From source file:com.aimfire.gallery.GalleryActivity.java
private void removeDownloadFileFragment(String name) { /*/* w w w.j a va 2s. c o m*/ * we do not need the fragment anymore. remove it. */ try { FragmentManager fragmentManager = getSupportFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); Fragment fragment = fragmentManager.findFragmentByTag(name); fragmentTransaction.remove(fragment); fragmentTransaction.commitAllowingStateLoss(); } catch (Exception e) { /* * observed exception when we remove while at the same time doing a screen * rotation. this happens despite we call commitAllowingStateLoss instead * of commit. if we encounter this occasionally, it's not a big deal - the * fragment will eventually be destroyed when we exit the activity. * * it is not clear if the remove is successful (thus memory be freed) if * commit fails */ if (BuildConfig.DEBUG) Log.e(TAG, "removeDownloadFileFragment: commit failed " + e.getMessage()); } }
From source file:com.aptoide.amethyst.AppViewActivity.java
@Override protected void onRestart() { super.onRestart(); final AppViewFragment fragment = AppViewFragment.newInstance(lifecycleController); final FragmentManager manager = getSupportFragmentManager(); manager.beginTransaction().replace(R.id.content, fragment).commitAllowingStateLoss(); }
From source file:com.aptoide.amethyst.AppViewActivity.java
@Override protected void onStop() { final FragmentManager manager = getSupportFragmentManager(); final Fragment fragment = manager.findFragmentById(R.id.content); manager.beginTransaction().remove(fragment).commitAllowingStateLoss(); super.onStop(); }
From source file:com.actionbarsherlock.sample.hcgallery.MainActivity.java
public void toggleVisibleTitles() { // Use these for custom animations. final FragmentManager fm = getSupportFragmentManager(); final TitlesFragment f = (TitlesFragment) fm.findFragmentById(R.id.frag_title); final View titlesView = f.getView(); mLabelIndex = 1 - mLabelIndex;/*ww w. j ava 2 s . c o m*/ // Determine if we're in portrait, and whether we're showing or hiding the titles // with this toggle. final boolean isPortrait = getResources() .getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT; final boolean shouldShow = f.isHidden() || mCurrentTitlesAnimator != null; // Cancel the current titles animation if there is one. if (mCurrentTitlesAnimator != null) mCurrentTitlesAnimator.cancel(); // Begin setting up the object animator. We'll animate the bottom or right edge of the // titles view, as well as its alpha for a fade effect. ObjectAnimator objectAnimator = ObjectAnimator.ofPropertyValuesHolder(titlesView, PropertyValuesHolder.ofInt(isPortrait ? "bottom" : "right", shouldShow ? getResources().getDimensionPixelSize(R.dimen.titles_size) : 0), PropertyValuesHolder.ofFloat("alpha", shouldShow ? 1 : 0)); // At each step of the animation, we'll perform layout by calling setLayoutParams. final ViewGroup.LayoutParams lp = titlesView.getLayoutParams(); objectAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { public void onAnimationUpdate(ValueAnimator valueAnimator) { // *** WARNING ***: triggering layout at each animation frame highly impacts // performance so you should only do this for simple layouts. More complicated // layouts can be better served with individual animations on child views to // avoid the performance penalty of layout. if (isPortrait) { lp.height = (Integer) valueAnimator.getAnimatedValue(); } else { lp.width = (Integer) valueAnimator.getAnimatedValue(); } titlesView.setLayoutParams(lp); } }); if (shouldShow) { fm.beginTransaction().show(f).commit(); objectAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animator) { mCurrentTitlesAnimator = null; } }); } else { objectAnimator.addListener(new AnimatorListenerAdapter() { boolean canceled; @Override public void onAnimationCancel(Animator animation) { canceled = true; super.onAnimationCancel(animation); } @Override public void onAnimationEnd(Animator animator) { if (canceled) return; mCurrentTitlesAnimator = null; fm.beginTransaction().hide(f).commit(); } }); } // Start the animation. objectAnimator.start(); mCurrentTitlesAnimator = objectAnimator; invalidateOptionsMenu(); // Manually trigger onNewIntent to check for ACTION_DIALOG. onNewIntent(getIntent()); }
From source file:com.battlelancer.seriesguide.ui.dialogs.TraktCredentialsDialogFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { getDialog().setTitle(R.string.pref_trakt); final Context context = getActivity().getApplicationContext(); final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); final View layout = inflater.inflate(R.layout.trakt_credentials_dialog, null); final FragmentManager fm = getFragmentManager(); final Bundle args = getArguments(); // restore the username from settings final String username = prefs.getString(SeriesGuidePreferences.KEY_TRAKTUSER, ""); // new account toggle final View mailviews = layout.findViewById(R.id.mailviews); mailviews.setVisibility(View.GONE); CheckBox newAccCheckBox = (CheckBox) layout.findViewById(R.id.checkNewAccount); newAccCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { mailviews.setVisibility(View.VISIBLE); } else { mailviews.setVisibility(View.GONE); }/*from w ww . j a va2 s. c o m*/ } }); // status strip final TextView status = (TextView) layout.findViewById(R.id.status); final View progressbar = layout.findViewById(R.id.progressbar); final View progress = layout.findViewById(R.id.progress); progress.setVisibility(View.GONE); final Button connectbtn = (Button) layout.findViewById(R.id.connectbutton); final Button disconnectbtn = (Button) layout.findViewById(R.id.disconnectbutton); // enable buttons based on if there are saved credentials if (TextUtils.isEmpty(username)) { // user has to enable first disconnectbtn.setEnabled(false); } else { // make it obvious trakt is connected connectbtn.setEnabled(false); EditText usernameField = (EditText) layout.findViewById(R.id.username); usernameField.setEnabled(false); usernameField.setText(username); EditText passwordField = (EditText) layout.findViewById(R.id.password); passwordField.setEnabled(false); passwordField.setText("********"); // fake password newAccCheckBox.setEnabled(false); } connectbtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // prevent multiple instances connectbtn.setEnabled(false); disconnectbtn.setEnabled(false); // prevent user canceling the dialog setCancelable(false); final String username = ((EditText) layout.findViewById(R.id.username)).getText().toString(); final String passwordHash = Utils .toSHA1(((EditText) layout.findViewById(R.id.password)).getText().toString().getBytes()); final String email = ((EditText) layout.findViewById(R.id.email)).getText().toString(); final boolean isNewAccount = ((CheckBox) layout.findViewById(R.id.checkNewAccount)).isChecked(); final String traktApiKey = getResources().getString(R.string.trakt_apikey); AsyncTask<String, Void, Response> accountValidatorTask = new AsyncTask<String, Void, Response>() { @Override protected void onPreExecute() { progress.setVisibility(View.VISIBLE); progressbar.setVisibility(View.VISIBLE); status.setText(R.string.waitplease); } @Override protected Response doInBackground(String... params) { // check if we have any usable data if (username.length() == 0 || passwordHash == null) { return null; } // check for connectivity if (!AndroidUtils.isNetworkConnected(context)) { Response r = new Response(); r.status = TraktStatus.FAILURE; r.error = context.getString(R.string.offline); return r; } // use a separate ServiceManager here to avoid // setting wrong credentials final ServiceManager manager = new ServiceManager(); manager.setApiKey(traktApiKey); manager.setAuthentication(username, passwordHash); manager.setUseSsl(true); Response response = null; try { if (isNewAccount) { // create new account response = manager.accountService().create(username, passwordHash, email).fire(); } else { // validate existing account response = manager.accountService().test().fire(); } } catch (TraktException te) { response = te.getResponse(); } catch (ApiException ae) { response = null; } return response; } @Override protected void onPostExecute(Response response) { progressbar.setVisibility(View.GONE); connectbtn.setEnabled(true); setCancelable(true); if (response == null) { status.setText(R.string.trakt_generalerror); return; } if (response.status.equals(TraktStatus.FAILURE)) { status.setText(response.error); return; } // try to encrypt the password before storing it String passwordEncr = SimpleCrypto.encrypt(passwordHash, context); if (passwordEncr == null) { // password encryption failed status.setText(R.string.trakt_generalerror); return; } // prepare writing credentials to settings Editor editor = prefs.edit(); editor.putString(SeriesGuidePreferences.KEY_TRAKTUSER, username) .putString(SeriesGuidePreferences.KEY_TRAKTPWD, passwordEncr); if (response.status.equals(TraktStatus.SUCCESS) && passwordEncr.length() != 0 && editor.commit()) { // try setting new auth data for service manager if (Utils.getServiceManagerWithAuth(context, true) == null) { status.setText(R.string.trakt_generalerror); return; } // all went through dismiss(); if (isForwardingGivenTask) { if (TraktAction.values()[args .getInt(ShareItems.TRAKTACTION)] == TraktAction.CHECKIN_EPISODE) { FragmentTransaction ft = fm.beginTransaction(); Fragment prev = fm.findFragmentByTag("progress-dialog"); if (prev != null) { ft.remove(prev); } ProgressDialog newFragment = ProgressDialog.newInstance(); newFragment.show(ft, "progress-dialog"); } // relaunch the trakt task which called us AndroidUtils.executeAsyncTask(new TraktTask(context, fm, args, null), new Void[] { null }); } } } }; accountValidatorTask.execute(); } }); disconnectbtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // clear trakt credentials new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { clearTraktCredentials(prefs); // force removing credentials from memory ServiceManager manager = Utils.getServiceManagerWithAuth(context, false); if (manager != null) { manager.setAuthentication(null, null); } return null; } }.execute(); dismiss(); } }); return layout; }