ActionBarActivityDelegateHC.java revision 51e35e07a00e4b56a1ca330323e69ef9258c4e57
1/* 2 * Copyright (C) 2013 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 17package android.support.v7.app; 18 19import android.content.Context; 20import android.content.res.Configuration; 21import android.os.Bundle; 22import android.support.v4.view.WindowCompat; 23import android.support.v7.internal.view.ActionModeWrapper; 24import android.support.v7.internal.view.menu.MenuWrapper; 25import android.support.v7.view.ActionMode; 26import android.support.v7.view.Menu; 27import android.view.View; 28import android.view.ViewGroup; 29import android.view.Window; 30 31class ActionBarActivityDelegateHC extends ActionBarActivityDelegate { 32 33 Menu mMenu; 34 35 ActionBarActivityDelegateHC(ActionBarActivity activity) { 36 super(activity); 37 } 38 39 @Override 40 public ActionBar createSupportActionBar() { 41 return new ActionBarImplHC(mActivity, mActivity); 42 } 43 44 @Override 45 public void onCreate(Bundle savedInstanceState) { 46 super.onCreate(savedInstanceState); 47 48 if (mHasActionBar) { 49 // If action bar is requested by inheriting from the appcompat theme, 50 // the system will not know about that. So explicitly request for an action bar. 51 mActivity.requestWindowFeature(WindowCompat.FEATURE_ACTION_BAR); 52 } 53 if (mOverlayActionBar) { 54 mActivity.requestWindowFeature(WindowCompat.FEATURE_ACTION_BAR_OVERLAY); 55 } 56 } 57 58 @Override 59 public void onConfigurationChanged(Configuration newConfig) { 60 } 61 62 @Override 63 public void onStop() { 64 } 65 66 @Override 67 public void onPostResume() { 68 } 69 70 @Override 71 public void setContentView(View v) { 72 mActivity.superSetContentView(v); 73 } 74 75 @Override 76 public void setContentView(int resId) { 77 mActivity.superSetContentView(resId); 78 } 79 80 @Override 81 public void setContentView(View v, ViewGroup.LayoutParams lp) { 82 mActivity.superSetContentView(v, lp); 83 } 84 85 @Override 86 public void addContentView(View v, ViewGroup.LayoutParams lp) { 87 mActivity.superAddContentView(v, lp); 88 } 89 90 @Override 91 public boolean supportRequestWindowFeature(int featureId) { 92 return mActivity.requestWindowFeature(featureId); 93 } 94 95 @Override 96 public View onCreatePanelView(int featureId) { 97 // Do not create custom options menu on HC+ 98 return null; 99 } 100 101 @Override 102 public boolean onCreatePanelMenu(int featureId, android.view.Menu frameworkMenu) { 103 if (featureId == Window.FEATURE_OPTIONS_PANEL) { 104 // This is a boundary where we transition from framework Menu objects to support 105 // library Menu objects. 106 if (mMenu == null) { 107 mMenu = MenuWrapper.createMenuWrapper(frameworkMenu); 108 } 109 boolean show = mActivity.onCreateSupportOptionsMenu(mMenu); 110 // FIXME: Reintroduce support options menu dispatch through facade. 111 //show |= mActivity.mFragments.dispatchCreateSupportOptionsMenu(mMenu, 112 // mActivity.getCompatMenuInflater()); 113 return show; 114 } else { 115 return mActivity.superOnCreatePanelMenu(featureId, frameworkMenu); 116 } 117 } 118 119 @Override 120 public boolean onMenuItemSelected(int featureId, android.view.MenuItem frameworkItem) { 121 return mActivity.onSupportMenuItemSelected(featureId, 122 MenuWrapper.createMenuItemWrapper(frameworkItem)); 123 } 124 125 @Override 126 public boolean onPreparePanel(int featureId, View view, android.view.Menu menu) { 127 if (featureId == Window.FEATURE_OPTIONS_PANEL && mMenu != null) { 128 boolean goforit = mActivity.onPrepareSupportOptionsMenu(mMenu); 129 // FIXME: Reintroduce support options menu dispatch through facade. 130 //goforit |= mActivity.mFragments.dispatchPrepareSupportOptionsMenu(mMenu); 131 return goforit; 132 } else { 133 return mActivity.superOnPreparePanelMenu(featureId, view, menu); 134 } 135 } 136 137 @Override 138 public void setTitle(CharSequence title) { 139 // Handled by framework 140 } 141 142 @Override 143 public ActionMode startSupportActionMode(ActionMode.Callback callback) { 144 if (callback == null) { 145 throw new IllegalArgumentException("ActionMode callback can not be null."); 146 } 147 148 Context context = getActionBarThemedContext(); 149 150 ActionModeWrapper.CallbackWrapper wrappedCallback = new ActionModeWrapper.CallbackWrapper( 151 context, callback); 152 ActionModeWrapper wrappedMode = null; 153 154 android.view.ActionMode frameworkMode = mActivity.startActionMode(wrappedCallback); 155 156 if (frameworkMode != null) { 157 wrappedMode = new ActionModeWrapper(context, 158 mActivity.startActionMode(wrappedCallback)); 159 wrappedCallback.setLastStartedActionMode(wrappedMode); 160 } 161 162 return wrappedMode; 163 } 164 165 @Override 166 public void onActionModeStarted(android.view.ActionMode mode) { 167 mActivity.onSupportActionModeStarted( 168 new ActionModeWrapper(getActionBarThemedContext(), mode)); 169 } 170 171 @Override 172 void setSupportProgressBarVisibility(boolean visible) { 173 mActivity.setProgressBarVisibility(visible); 174 } 175 176 @Override 177 void setSupportProgressBarIndeterminateVisibility(boolean visible) { 178 mActivity.setProgressBarIndeterminateVisibility(visible); 179 } 180 181 @Override 182 void setSupportProgressBarIndeterminate(boolean indeterminate) { 183 mActivity.setProgressBarIndeterminate(indeterminate); 184 } 185 186 @Override 187 void setSupportProgress(int progress) { 188 mActivity.setProgress(progress); 189 } 190 191 @Override 192 public void onActionModeFinished(android.view.ActionMode mode) { 193 mActivity.onSupportActionModeFinished( 194 new ActionModeWrapper(getActionBarThemedContext(), mode)); 195 } 196 197 @Override 198 public void supportInvalidateOptionsMenu() { 199 } 200 201 @Override 202 public boolean onBackPressed() { 203 return false; 204 } 205 206} 207