Search in sources :

Example 1 with StopwatchFragment

use of james.alarmio.fragments.StopwatchFragment in project Alarmio by TheAndroidMaster.

the class MainActivity method onNewIntent.

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    if (intent.hasExtra(EXTRA_FRAGMENT)) {
        boolean shouldBackStack = fragment instanceof HomeFragment;
        int fragmentId = intent.getIntExtra(EXTRA_FRAGMENT, -1);
        if (fragmentId == FRAGMENT_TIMER && intent.hasExtra(TimerReceiver.EXTRA_TIMER_ID)) {
            int id = intent.getIntExtra(TimerReceiver.EXTRA_TIMER_ID, 0);
            if (alarmio.getTimers().size() <= id || id < 0)
                return;
            Bundle args = new Bundle();
            args.putParcelable(TimerFragment.EXTRA_TIMER, alarmio.getTimers().get(id));
            fragment = new TimerFragment();
            fragment.setArguments(args);
        } else if (fragmentId == FRAGMENT_STOPWATCH) {
            if (fragment instanceof StopwatchFragment)
                return;
            fragment = new StopwatchFragment();
        } else
            return;
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction().setCustomAnimations(R.anim.slide_in_up_sheet, R.anim.slide_out_up_sheet, R.anim.slide_in_down_sheet, R.anim.slide_out_down_sheet).replace(R.id.fragment, fragment);
        if (shouldBackStack)
            transaction.addToBackStack(null);
        transaction.commit();
    }
}
Also used : FragmentTransaction(androidx.fragment.app.FragmentTransaction) Bundle(android.os.Bundle) HomeFragment(james.alarmio.fragments.HomeFragment) StopwatchFragment(james.alarmio.fragments.StopwatchFragment) TimerFragment(james.alarmio.fragments.TimerFragment)

Aggregations

Bundle (android.os.Bundle)1 FragmentTransaction (androidx.fragment.app.FragmentTransaction)1 HomeFragment (james.alarmio.fragments.HomeFragment)1 StopwatchFragment (james.alarmio.fragments.StopwatchFragment)1 TimerFragment (james.alarmio.fragments.TimerFragment)1