1821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen/*
2821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen * Copyright (C) 2017 The Android Open Source Project
3821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen *
4821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen * Licensed under the Apache License, Version 2.0 (the "License");
5821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen * you may not use this file except in compliance with the License.
6821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen * You may obtain a copy of the License at
7821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen *
8821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen *      http://www.apache.org/licenses/LICENSE-2.0
9821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen *
10821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen * Unless required by applicable law or agreed to in writing, software
11821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen * distributed under the License is distributed on an "AS IS" BASIS,
12821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen * See the License for the specific language governing permissions and
14821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen * limitations under the License.
15821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen */
16821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen
174426b102bd69152fb6f305260237e5c2aad7d5a6Aurimas Liutikaspackage androidx.car.drawer;
18821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen
1982b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chenimport android.animation.ValueAnimator;
20821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chenimport android.content.res.Configuration;
21821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chenimport android.os.Bundle;
2282b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chenimport android.util.TypedValue;
23821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chenimport android.view.LayoutInflater;
24821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chenimport android.view.MenuItem;
25821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chenimport android.view.View;
26821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chenimport android.view.ViewGroup;
27821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen
28f87e4dfc7bcd2583e7908ca3cda65cec6c697080Aurimas Liutikasimport androidx.annotation.LayoutRes;
29f87e4dfc7bcd2583e7908ca3cda65cec6c697080Aurimas Liutikasimport androidx.annotation.Nullable;
30f87e4dfc7bcd2583e7908ca3cda65cec6c697080Aurimas Liutikasimport androidx.appcompat.app.ActionBarDrawerToggle;
31f87e4dfc7bcd2583e7908ca3cda65cec6c697080Aurimas Liutikasimport androidx.appcompat.app.AppCompatActivity;
3243bebae97babb6ae6c95c44b07797916fe533138Anthony Chenimport androidx.appcompat.widget.Toolbar;
334426b102bd69152fb6f305260237e5c2aad7d5a6Aurimas Liutikasimport androidx.car.R;
34f87e4dfc7bcd2583e7908ca3cda65cec6c697080Aurimas Liutikasimport androidx.drawerlayout.widget.DrawerLayout;
35f87e4dfc7bcd2583e7908ca3cda65cec6c697080Aurimas Liutikas
36f87e4dfc7bcd2583e7908ca3cda65cec6c697080Aurimas Liutikasimport com.google.android.material.appbar.AppBarLayout;
374426b102bd69152fb6f305260237e5c2aad7d5a6Aurimas Liutikas
38821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen/**
39821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen * Common base Activity for car apps that need to present a Drawer.
40821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen *
41821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen * <p>This Activity manages the overall layout. To use it, sub-classes need to:
42821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen *
43821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen * <ul>
443ad4bcf5b299bc7baf49f6b46354b524e2dd9830Dean Harding *   <li>Provide the root-items for the drawer by calling {@link #getDrawerController()}.
453ad4bcf5b299bc7baf49f6b46354b524e2dd9830Dean Harding *       {@link CarDrawerController#setRootAdapter(CarDrawerAdapter)}.
46821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen *   <li>Add their main content using {@link #setMainContent(int)} or {@link #setMainContent(View)}.
47821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen *       They can also add fragments to the main-content container by obtaining its id using
48821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen *       {@link #getContentContainerId()}
49821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen * </ul>
50821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen *
51821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen * <p>This class will take care of drawer toggling and display.
52821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen *
5382b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen * <p>This Activity also exposes the ability to have its toolbar optionally hide if any content
5482b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen * in its main view is scrolled. Be default, this ability is turned off. Call
5582b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen * {@link #setToolbarCollapsible()} to enable this behavior. Additionally, a user can set elevation
5682b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen * on this toolbar by calling the appropriate {@link #setToolbarElevation(float)} method. There is
5782b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen * elevation on the toolbar by default.
5882b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen *
59821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen * <p>The rootAdapter can implement nested-navigation, in its click-handling, by passing the
60821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen * CarDrawerAdapter for the next level to
613b8bebcd0ac54c253cf444118d402cc2492b8e70Anthony Chen * {@link CarDrawerController#pushAdapter(CarDrawerAdapter)}.
62821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen *
63b308672ec84f4ca7b49c6640135cdc58b49dc46dAnthony Chen * <p>Any Activity's based on this class need to set their theme to
64b308672ec84f4ca7b49c6640135cdc58b49dc46dAnthony Chen * {@code Theme.Car.Light.NoActionBar.Drawer} or a derivative.
65821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen */
663ad4bcf5b299bc7baf49f6b46354b524e2dd9830Dean Hardingpublic class CarDrawerActivity extends AppCompatActivity {
6782b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen    private static final int ANIMATION_DURATION_MS = 100;
6882b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen
69a5295314847de64c65b824fcebb41b81ae619454Anthony Chen    private CarDrawerController mDrawerController;
7082b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen    private AppBarLayout mAppBarLayout;
7143bebae97babb6ae6c95c44b07797916fe533138Anthony Chen    private Toolbar mToolbar;
72821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen
73821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen    @Override
74821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen    protected void onCreate(Bundle savedInstanceState) {
75821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen        super.onCreate(savedInstanceState);
76821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen
77821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen        setContentView(R.layout.car_drawer_activity);
78821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen
7982b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen        mAppBarLayout = findViewById(R.id.appbar);
8082b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen        mAppBarLayout.setBackgroundColor(getThemeColorPrimary());
8182b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen        setToolbarElevation(getResources().getDimension(R.dimen.car_app_bar_default_elevation));
8282b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen
83821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen        DrawerLayout drawerLayout = findViewById(R.id.drawer_layout);
84821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen        ActionBarDrawerToggle drawerToggle = new ActionBarDrawerToggle(
8543bebae97babb6ae6c95c44b07797916fe533138Anthony Chen                /* activity= */ this,
8643bebae97babb6ae6c95c44b07797916fe533138Anthony Chen                drawerLayout,
87821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen                R.string.car_drawer_open,
88821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen                R.string.car_drawer_close);
89821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen
9082b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen        mToolbar = findViewById(R.id.car_toolbar);
9182b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen        setSupportActionBar(mToolbar);
92821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen
9343bebae97babb6ae6c95c44b07797916fe533138Anthony Chen        mDrawerController = new CarDrawerController(drawerLayout, drawerToggle);
943ad4bcf5b299bc7baf49f6b46354b524e2dd9830Dean Harding        CarDrawerAdapter rootAdapter = getRootAdapter();
953ad4bcf5b299bc7baf49f6b46354b524e2dd9830Dean Harding        if (rootAdapter != null) {
963ad4bcf5b299bc7baf49f6b46354b524e2dd9830Dean Harding            mDrawerController.setRootAdapter(rootAdapter);
973ad4bcf5b299bc7baf49f6b46354b524e2dd9830Dean Harding        }
98821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen
99821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
100821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen        getSupportActionBar().setHomeButtonEnabled(true);
101821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen    }
102821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen
103a5295314847de64c65b824fcebb41b81ae619454Anthony Chen    /**
104a5295314847de64c65b824fcebb41b81ae619454Anthony Chen     * Returns the {@link CarDrawerController} that is responsible for handling events relating
105a5295314847de64c65b824fcebb41b81ae619454Anthony Chen     * to the drawer in this Activity.
106a5295314847de64c65b824fcebb41b81ae619454Anthony Chen     *
107a5295314847de64c65b824fcebb41b81ae619454Anthony Chen     * @return The {@link CarDrawerController} linked to this Activity. This value will be
108a5295314847de64c65b824fcebb41b81ae619454Anthony Chen     * {@code null} if this method is called before {@code onCreate()} has been called.
109a5295314847de64c65b824fcebb41b81ae619454Anthony Chen     */
110a5295314847de64c65b824fcebb41b81ae619454Anthony Chen    @Nullable
111a5295314847de64c65b824fcebb41b81ae619454Anthony Chen    protected CarDrawerController getDrawerController() {
112a5295314847de64c65b824fcebb41b81ae619454Anthony Chen        return mDrawerController;
113a5295314847de64c65b824fcebb41b81ae619454Anthony Chen    }
114a5295314847de64c65b824fcebb41b81ae619454Anthony Chen
115821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen    @Override
116821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen    protected void onPostCreate(Bundle savedInstanceState) {
117821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen        super.onPostCreate(savedInstanceState);
118821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen        mDrawerController.syncState();
119821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen    }
120821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen
121821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen    /**
122821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen     * @return Adapter for root content of the Drawer.
1233ad4bcf5b299bc7baf49f6b46354b524e2dd9830Dean Harding     * @deprecated Do not implement this, instead call {@link #getDrawerController}.
1243ad4bcf5b299bc7baf49f6b46354b524e2dd9830Dean Harding     * {@link CarDrawerController#setRootAdapter(CarDrawerAdapter)} directly.
125821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen     */
1263ad4bcf5b299bc7baf49f6b46354b524e2dd9830Dean Harding    @Deprecated
1273ad4bcf5b299bc7baf49f6b46354b524e2dd9830Dean Harding    @Nullable
1283ad4bcf5b299bc7baf49f6b46354b524e2dd9830Dean Harding    protected CarDrawerAdapter getRootAdapter() {
1293ad4bcf5b299bc7baf49f6b46354b524e2dd9830Dean Harding        return null;
1303ad4bcf5b299bc7baf49f6b46354b524e2dd9830Dean Harding    }
131821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen
132821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen    /**
133821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen     * Set main content to display in this Activity. It will be added to R.id.content_frame in
134821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen     * car_drawer_activity.xml. NOTE: Do not use {@link #setContentView(View)}.
135821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen     *
136821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen     * @param view View to display as main content.
137821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen     */
138821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen    public void setMainContent(View view) {
139821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen        ViewGroup parent = findViewById(getContentContainerId());
140821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen        parent.addView(view);
141821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen    }
142821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen
143821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen    /**
144821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen     * Set main content to display in this Activity. It will be added to R.id.content_frame in
145821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen     * car_drawer_activity.xml. NOTE: Do not use {@link #setContentView(int)}.
146821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen     *
147821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen     * @param resourceId Layout to display as main content.
148821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen     */
149821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen    public void setMainContent(@LayoutRes int resourceId) {
150821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen        ViewGroup parent = findViewById(getContentContainerId());
151821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen        LayoutInflater inflater = getLayoutInflater();
152821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen        inflater.inflate(resourceId, parent, true);
153821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen    }
154821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen
155821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen    /**
15682b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen     * Sets the elevation on the toolbar of this Activity.
15782b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen     *
15882b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen     * @param elevation The elevation to set.
15982b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen     */
16082b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen    public void setToolbarElevation(float elevation) {
16182b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen        // The AppBar's default animator needs to be set to null to manually change the elevation.
16282b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen        mAppBarLayout.setStateListAnimator(null);
16382b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen        mAppBarLayout.setElevation(elevation);
16482b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen    }
16582b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen
16682b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen    /**
16782b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen     * Sets the elevation of the toolbar and animate it from the current elevation value.
16882b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen     *
16982b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen     * @param elevation The elevation to set.
17082b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen     */
17182b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen    public void setToolbarElevationWithAnimation(float elevation) {
17282b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen        ValueAnimator elevationAnimator =
17382b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen                ValueAnimator.ofFloat(mAppBarLayout.getElevation(), elevation);
17482b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen        elevationAnimator
17582b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen                .setDuration(ANIMATION_DURATION_MS)
17682b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen                .addUpdateListener(animation -> setToolbarElevation(
17782b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen                        (float) animation.getAnimatedValue()));
17882b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen        elevationAnimator.start();
17982b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen    }
18082b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen
18182b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen    /**
18282b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen     * Sets the toolbar of this Activity as collapsible. When any content in the main view of the
18382b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen     * Activity is scrolled, the toolbar will collapse and show itself accordingly.
18482b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen     */
18582b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen    public void setToolbarCollapsible() {
18682b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen        AppBarLayout.LayoutParams params =
18782b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen                (AppBarLayout.LayoutParams) mToolbar.getLayoutParams();
18882b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen        params.setScrollFlags(AppBarLayout.LayoutParams.SCROLL_FLAG_SCROLL
18982b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen                | AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS);
19082b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen    }
19182b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen
19282b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen    /**
19382b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen     * Sets the toolbar to always show even if content in the main view of the Activity has been
19482b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen     * scrolled. This is the default behavior.
19582b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen     */
19682b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen    public void setToolbarAlwaysShow() {
19782b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen        AppBarLayout.LayoutParams params =
19882b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen                (AppBarLayout.LayoutParams) mToolbar.getLayoutParams();
19982b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen        params.setScrollFlags(0);
20082b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen    }
20182b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen
20282b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen    /**
203821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen     * Get the id of the main content Container which is a FrameLayout. Subclasses can add their own
204821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen     * content/fragments inside here.
205821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen     *
206821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen     * @return Id of FrameLayout where main content of the subclass Activity can be added.
207821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen     */
208821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen    protected int getContentContainerId() {
209821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen        return R.id.content_frame;
210821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen    }
211821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen
212821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen    @Override
213821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen    protected void onStop() {
214821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen        super.onStop();
215821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen        mDrawerController.closeDrawer();
216821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen    }
217821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen
218821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen    @Override
219821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen    public void onConfigurationChanged(Configuration newConfig) {
220821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen        super.onConfigurationChanged(newConfig);
221821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen        mDrawerController.onConfigurationChanged(newConfig);
222821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen    }
223821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen
224821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen    @Override
225821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen    public boolean onOptionsItemSelected(MenuItem item) {
226821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen        return mDrawerController.onOptionsItemSelected(item) || super.onOptionsItemSelected(item);
227821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen    }
22882b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen
22982b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen    /**
23082b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen     * Returns the color that has been set as {@code colorPrimary} on the current Theme of this
23182b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen     * Activity.
23282b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen     */
23382b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen    private int getThemeColorPrimary() {
23482b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen        TypedValue value = new TypedValue();
23582b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen        getTheme().resolveAttribute(android.R.attr.colorPrimary, value, true);
23682b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen        return value.data;
23782b733feeae2707a6dbc09e0e4a9de303731f141Anthony Chen    }
238821d290de9dfa8a3706d0feca78fc269b67c5efcAnthony Chen}
239