Search in sources :

Example 1 with HomeFragment

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

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    alarmio = (Alarmio) getApplicationContext();
    alarmio.setListener(this);
    if (savedInstanceState == null) {
        fragment = new SplashFragment();
        getSupportFragmentManager().beginTransaction().add(R.id.fragment, fragment).commit();
    } else {
        if (fragment == null)
            fragment = new HomeFragment();
        getSupportFragmentManager().beginTransaction().replace(R.id.fragment, fragment).commit();
    }
    getSupportFragmentManager().addOnBackStackChangedListener(this);
}
Also used : SplashFragment(james.alarmio.fragments.SplashFragment) HomeFragment(james.alarmio.fragments.HomeFragment)

Example 2 with HomeFragment

use of james.alarmio.fragments.HomeFragment 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

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