[Android] Add a SherlockGridFragment based on both SherlockListFragment and GridFragment

Ludovic Fauvet git at videolan.org
Mon Oct 8 23:15:06 CEST 2012


vlc-ports/android | branch: master | Ludovic Fauvet <etix at videolan.org> | Fri Oct  5 18:02:29 2012 +0200| [3d05727448bc275c11c4ca521f8654ca6115512e] | committer: Ludovic Fauvet

Add a SherlockGridFragment based on both SherlockListFragment and GridFragment

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=3d05727448bc275c11c4ca521f8654ca6115512e
---

 .../videolan/android/ui/SherlockGridFragment.java  |   85 ++++++++++++++++++++
 1 file changed, 85 insertions(+)

diff --git a/vlc-android/src/org/videolan/android/ui/SherlockGridFragment.java b/vlc-android/src/org/videolan/android/ui/SherlockGridFragment.java
new file mode 100644
index 0000000..c1eaeb3
--- /dev/null
+++ b/vlc-android/src/org/videolan/android/ui/SherlockGridFragment.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2012 Jake Wharton
+ *
+ * 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 org.videolan.android.ui;
+
+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 static com.actionbarsherlock.app.SherlockFragmentActivity.OnCreateOptionsMenuListener;
+import static com.actionbarsherlock.app.SherlockFragmentActivity.OnOptionsItemSelectedListener;
+import static com.actionbarsherlock.app.SherlockFragmentActivity.OnPrepareOptionsMenuListener;
+
+public class SherlockGridFragment extends GridFragment 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) {
+        //Nothing to see here.
+    }
+
+    @Override
+    public final void onPrepareOptionsMenu(android.view.Menu menu) {
+        onPrepareOptionsMenu(new MenuWrapper(menu));
+    }
+
+    @Override
+    public void onPrepareOptionsMenu(Menu menu) {
+        //Nothing to see here.
+    }
+
+    @Override
+    public final boolean onOptionsItemSelected(android.view.MenuItem item) {
+        return onOptionsItemSelected(new MenuItemWrapper(item));
+    }
+
+    @Override
+    public boolean onOptionsItemSelected(MenuItem item) {
+        //Nothing to see here.
+        return false;
+    }
+}
\ No newline at end of file



More information about the Android mailing list