• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.Activity;
20 import android.app.Fragment;
21 import android.os.Bundle;
22 import android.support.v7.widget.PopupMenu;
23 import android.view.MenuItem;
24 import android.view.View;
25 import android.widget.ImageButton;
26 
27 public class DeskClockFragment extends Fragment {
28 
29     protected ImageButton mFab;
30     protected ImageButton mLeftButton;
31     protected ImageButton mRightButton;
32 
onPageChanged(int page)33     public void onPageChanged(int page) {
34         // Do nothing here , only in derived classes
35     }
36 
onFabClick(View view)37     public void onFabClick(View view){
38         // Do nothing here , only in derived classes
39     }
40 
41     @Override
onActivityCreated(Bundle savedInstanceState)42     public void onActivityCreated(Bundle savedInstanceState) {
43         super.onActivityCreated(savedInstanceState);
44         final Activity activity = getActivity();
45         if (activity instanceof DeskClock) {
46             final DeskClock deskClockActivity = (DeskClock) activity;
47             mFab = deskClockActivity.getFab();
48             mLeftButton = deskClockActivity.getLeftButton();
49             mRightButton = deskClockActivity.getRightButton();
50         }
51     }
52 
setFabAppearance()53     public void setFabAppearance() {
54         // Do nothing here , only in derived classes
55     }
56 
setLeftRightButtonAppearance()57     public void setLeftRightButtonAppearance() {
58         // Do nothing here , only in derived classes
59     }
60 
onLeftButtonClick(View view)61     public void onLeftButtonClick(View view) {
62         // Do nothing here , only in derived classes
63     }
64 
onRightButtonClick(View view)65     public void onRightButtonClick(View view) {
66         // Do nothing here , only in derived classes
67     }
68     /**
69      * Installs click and touch listeners on a fake overflow menu button.
70      *
71      * @param menuButton the fragment's fake overflow menu button
72      */
setupFakeOverflowMenuButton(View menuButton)73     public void setupFakeOverflowMenuButton(View menuButton) {
74         final PopupMenu fakeOverflow = new PopupMenu(menuButton.getContext(), menuButton) {
75             @Override
76             public void show() {
77                 getActivity().onPrepareOptionsMenu(getMenu());
78                 super.show();
79             }
80         };
81         fakeOverflow.inflate(R.menu.desk_clock_menu);
82         fakeOverflow.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener () {
83             @Override
84             public boolean onMenuItemClick(MenuItem item) {
85                 return getActivity().onOptionsItemSelected(item);
86             }
87         });
88 
89         menuButton.setOnTouchListener(fakeOverflow.getDragToOpenListener());
90         menuButton.setOnClickListener(new View.OnClickListener() {
91             @Override
92             public void onClick(View v) {
93                 fakeOverflow.show();
94             }
95         });
96     }
97 }
98