Change content intent of stopwatch notification to launch MainActivity and scroll to stopwatch page
This commit is contained in:
parent
ce1c56e979
commit
398a875654
@ -29,6 +29,11 @@ import butterknife.Bind;
|
||||
public class MainActivity extends BaseActivity {
|
||||
private static final String TAG = "MainActivity";
|
||||
|
||||
public static final int PAGE_ALARMS = 0;
|
||||
public static final int PAGE_TIMERS = 1;
|
||||
public static final int PAGE_STOPWATCH = 2;
|
||||
public static final String EXTRA_SHOW_PAGE = "com.philliphsu.clock2.extra.SHOW_PAGE";
|
||||
|
||||
/**
|
||||
* The {@link android.support.v4.view.PagerAdapter} that will provide
|
||||
* fragments for each of the sections. We use a
|
||||
@ -230,6 +235,20 @@ public class MainActivity extends BaseActivity {
|
||||
});
|
||||
|
||||
mAddItemDrawable = ContextCompat.getDrawable(this, R.drawable.ic_add_24dp);
|
||||
|
||||
final int initialPage = getIntent().getIntExtra(EXTRA_SHOW_PAGE, -1);
|
||||
if (initialPage > 0/*0 is already the default page*/ && initialPage <= PAGE_STOPWATCH) {
|
||||
// Run this only after the ViewPager is finished drawing
|
||||
mViewPager.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// TOneverDO: smoothScroll == false, or else the onPageScrolled callback won't
|
||||
// be called for the intermediate pages that are responsible for translating
|
||||
// the FAB
|
||||
mViewPager.setCurrentItem(initialPage, true/*smoothScroll*/);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -387,11 +406,11 @@ public class MainActivity extends BaseActivity {
|
||||
public Fragment getItem(int position) {
|
||||
// getItem is called to instantiate the fragment for the given page.
|
||||
switch (position) {
|
||||
case 0:
|
||||
case PAGE_ALARMS:
|
||||
return AlarmsFragment.newInstance(1);
|
||||
case 1:
|
||||
case PAGE_TIMERS:
|
||||
return new TimersFragment();
|
||||
case 2:
|
||||
case PAGE_STOPWATCH:
|
||||
return new StopwatchFragment();
|
||||
default:
|
||||
return PlaceholderFragment.newInstance(position + 1);
|
||||
|
||||
@ -86,7 +86,11 @@ public class StopwatchNotificationService extends ChronometerNotificationService
|
||||
@Override
|
||||
protected PendingIntent getContentIntent() {
|
||||
Intent intent = new Intent(this, MainActivity.class);
|
||||
intent.putExtra(null/*TODO:MainActivity.EXTRA_SHOW_PAGE*/, 2/*TODO:MainActivity.INDEX_STOPWATCH*/);
|
||||
// http://stackoverflow.com/a/3128418/5055032
|
||||
// "For some unspecified reason, extras will be delivered only if you've set some action"
|
||||
// This ONLY applies to PendingIntents...
|
||||
intent.setAction("foo"/*dummy action*/);
|
||||
intent.putExtra(MainActivity.EXTRA_SHOW_PAGE, MainActivity.PAGE_STOPWATCH);
|
||||
return PendingIntent.getActivity(this, 0, intent, 0);
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user