Home | History | Annotate | Download | only in app
      1 /*
      2  * Copyright (C) 2015 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package androidx.appcompat.app;
     18 
     19 import android.view.KeyEvent;
     20 import android.view.Menu;
     21 
     22 import androidx.appcompat.test.R;
     23 import androidx.appcompat.testutils.BaseTestActivity;
     24 import androidx.appcompat.widget.Toolbar;
     25 
     26 public class ToolbarAppCompatActivity extends BaseTestActivity {
     27 
     28     private Toolbar mToolbar;
     29 
     30     public int mCreateMenuCount;
     31     public int mPrepareMenuCount;
     32     public int mKeyShortcutCount;
     33 
     34     @Override
     35     protected int getContentViewLayoutResId() {
     36         return R.layout.toolbar_decor_content;
     37     }
     38 
     39     @Override
     40     protected void onContentViewSet() {
     41         mToolbar = findViewById(R.id.toolbar);
     42         setSupportActionBar(mToolbar);
     43     }
     44 
     45     public Toolbar getToolbar() {
     46         return mToolbar;
     47     }
     48 
     49     @Override
     50     public boolean onKeyShortcut(int keyCode, KeyEvent event) {
     51         ++mKeyShortcutCount;
     52         return super.onKeyShortcut(keyCode, event);
     53     }
     54 
     55     @Override
     56     public boolean onCreateOptionsMenu(Menu menu) {
     57         ++mCreateMenuCount;
     58         return super.onCreateOptionsMenu(menu);
     59     }
     60 
     61     @Override
     62     public boolean onPrepareOptionsMenu(Menu menu) {
     63         ++mPrepareMenuCount;
     64         return super.onPrepareOptionsMenu(menu);
     65     }
     66 
     67     public void resetCounters() {
     68         mCreateMenuCount = mPrepareMenuCount = mKeyShortcutCount = 0;
     69     }
     70 }
     71