Home | History | Annotate | Download | only in deskclock
      1 /*
      2  * Copyright (C) 2012 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 com.android.deskclock;
     18 
     19 import android.app.Fragment;
     20 import android.support.v4.widget.PopupMenuCompat;
     21 import android.view.MenuItem;
     22 import android.view.View;
     23 import android.widget.PopupMenu;
     24 
     25 public class DeskClockFragment extends Fragment {
     26 
     27     public void onPageChanged(int page) {
     28         // Do nothing here , only in derived classes
     29     }
     30 
     31     /**
     32      * Installs click and touch listeners on a fake overflow menu button.
     33      *
     34      * @param menuButton the fragment's fake overflow menu button
     35      */
     36     public void setupFakeOverflowMenuButton(View menuButton) {
     37         final PopupMenu fakeOverflow = new PopupMenu(menuButton.getContext(), menuButton) {
     38             @Override
     39             public void show() {
     40                 getActivity().onPrepareOptionsMenu(getMenu());
     41                 super.show();
     42             }
     43         };
     44         fakeOverflow.inflate(R.menu.desk_clock_menu);
     45         fakeOverflow.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener () {
     46             @Override
     47             public boolean onMenuItemClick(MenuItem item) {
     48                 return getActivity().onOptionsItemSelected(item);
     49             }
     50         });
     51 
     52         menuButton.setOnTouchListener(PopupMenuCompat.getDragToOpenListener(fakeOverflow));
     53         menuButton.setOnClickListener(new View.OnClickListener() {
     54             @Override
     55             public void onClick(View v) {
     56                 fakeOverflow.show();
     57             }
     58         });
     59     }
     60 }
     61