Created
August 24, 2013 14:20
-
-
Save SebastianEngel/6328419 to your computer and use it in GitHub Desktop.
ActionBarSherlock compatible implementation of a YouTubePlayerSupportFragment (YouTube Android Player API)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright (C) 2013 Sebastian Engel | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software | |
* distributed under the License is distributed on an "AS IS" BASIS, | |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
* See the License for the specific language governing permissions and | |
* limitations under the License. | |
*/ | |
package com.example; | |
import android.app.Activity; | |
import com.actionbarsherlock.app.SherlockFragmentActivity; | |
import com.actionbarsherlock.internal.view.menu.MenuItemWrapper; | |
import com.actionbarsherlock.internal.view.menu.MenuWrapper; | |
import com.actionbarsherlock.view.Menu; | |
import com.actionbarsherlock.view.MenuInflater; | |
import com.actionbarsherlock.view.MenuItem; | |
import com.google.android.youtube.player.YouTubePlayerSupportFragment; | |
import static com.actionbarsherlock.app.SherlockFragmentActivity.OnCreateOptionsMenuListener; | |
import static com.actionbarsherlock.app.SherlockFragmentActivity.OnOptionsItemSelectedListener; | |
import static com.actionbarsherlock.app.SherlockFragmentActivity.OnPrepareOptionsMenuListener; | |
/** | |
* ActionBarSherlock compatible implementation of a {@link YouTubePlayerSupportFragment}. | |
* | |
* @author Sebastian Engel | |
*/ | |
public class SherlockYouTubePlayerFragment extends YouTubePlayerSupportFragment | |
implements OnCreateOptionsMenuListener, OnPrepareOptionsMenuListener, OnOptionsItemSelectedListener { | |
private SherlockFragmentActivity mActivity; | |
public SherlockFragmentActivity getSherlockActivity() { | |
return mActivity; | |
} | |
@Override | |
public void onAttach(Activity activity) { | |
if (!(activity instanceof SherlockFragmentActivity)) { | |
throw new IllegalStateException( | |
getClass().getSimpleName() + " must be attached to a SherlockFragmentActivity."); | |
} | |
mActivity = (SherlockFragmentActivity)activity; | |
super.onAttach(activity); | |
} | |
@Override | |
public void onDetach() { | |
mActivity = null; | |
super.onDetach(); | |
} | |
@Override | |
public final void onCreateOptionsMenu(android.view.Menu menu, android.view.MenuInflater inflater) { | |
onCreateOptionsMenu(new MenuWrapper(menu), mActivity.getSupportMenuInflater()); | |
} | |
@Override | |
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {} | |
@Override | |
public final void onPrepareOptionsMenu(android.view.Menu menu) { | |
onPrepareOptionsMenu(new MenuWrapper(menu)); | |
} | |
@Override | |
public void onPrepareOptionsMenu(Menu menu) {} | |
@Override | |
public final boolean onOptionsItemSelected(android.view.MenuItem item) { | |
return onOptionsItemSelected(new MenuItemWrapper(item)); | |
} | |
@Override | |
public boolean onOptionsItemSelected(MenuItem item) { | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment