Log wrapper and actionbarsherlock update

This commit is contained in:
Dominik 2012-06-20 19:28:05 +03:00
parent af4d8a59d1
commit 4130123e77
36 changed files with 407 additions and 183 deletions

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="60" android:versionName="4.0.2" package="com.actionbarsherlock"> <manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="90" android:versionName="4.1.0" package="com.actionbarsherlock">
<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="15"/> <uses-sdk android:minSdkVersion="7" android:targetSdkVersion="15"/>

View File

@ -11,7 +11,7 @@
<parent> <parent>
<groupId>com.actionbarsherlock</groupId> <groupId>com.actionbarsherlock</groupId>
<artifactId>parent</artifactId> <artifactId>parent</artifactId>
<version>4.0.2</version> <version>4.1.0</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>

View File

@ -0,0 +1,144 @@
package android.support.v4.app;
import android.util.Log;
import android.view.View;
import android.view.Window;
import com.actionbarsherlock.ActionBarSherlock.OnCreatePanelMenuListener;
import com.actionbarsherlock.ActionBarSherlock.OnMenuItemSelectedListener;
import com.actionbarsherlock.ActionBarSherlock.OnPreparePanelListener;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;
import java.util.ArrayList;
/** I'm in ur package. Stealing ur variables. */
public abstract class _ActionBarSherlockTrojanHorse extends FragmentActivity implements OnCreatePanelMenuListener, OnPreparePanelListener, OnMenuItemSelectedListener {
private static final boolean DEBUG = false;
private static final String TAG = "_ActionBarSherlockTrojanHorse";
/** Fragment interface for menu creation callback. */
public interface OnCreateOptionsMenuListener {
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater);
}
/** Fragment interface for menu preparation callback. */
public interface OnPrepareOptionsMenuListener {
public void onPrepareOptionsMenu(Menu menu);
}
/** Fragment interface for menu item selection callback. */
public interface OnOptionsItemSelectedListener {
public boolean onOptionsItemSelected(MenuItem item);
}
private ArrayList<Fragment> mCreatedMenus;
///////////////////////////////////////////////////////////////////////////
// Sherlock menu handling
///////////////////////////////////////////////////////////////////////////
@Override
public boolean onCreatePanelMenu(int featureId, Menu menu) {
if (DEBUG) Log.d(TAG, "[onCreatePanelMenu] featureId: " + featureId + ", menu: " + menu);
if (featureId == Window.FEATURE_OPTIONS_PANEL) {
boolean result = onCreateOptionsMenu(menu);
if (DEBUG) Log.d(TAG, "[onCreatePanelMenu] activity create result: " + result);
MenuInflater inflater = getSupportMenuInflater();
boolean show = false;
ArrayList<Fragment> newMenus = null;
if (mFragments.mActive != null) {
for (int i = 0; i < mFragments.mAdded.size(); i++) {
Fragment f = mFragments.mAdded.get(i);
if (f != null && !f.mHidden && f.mHasMenu && f.mMenuVisible && f instanceof OnCreateOptionsMenuListener) {
show = true;
((OnCreateOptionsMenuListener)f).onCreateOptionsMenu(menu, inflater);
if (newMenus == null) {
newMenus = new ArrayList<Fragment>();
}
newMenus.add(f);
}
}
}
if (mCreatedMenus != null) {
for (int i = 0; i < mCreatedMenus.size(); i++) {
Fragment f = mCreatedMenus.get(i);
if (newMenus == null || !newMenus.contains(f)) {
f.onDestroyOptionsMenu();
}
}
}
mCreatedMenus = newMenus;
if (DEBUG) Log.d(TAG, "[onCreatePanelMenu] fragments create result: " + show);
result |= show;
if (DEBUG) Log.d(TAG, "[onCreatePanelMenu] returning " + result);
return result;
}
return false;
}
@Override
public boolean onPreparePanel(int featureId, View view, Menu menu) {
if (DEBUG) Log.d(TAG, "[onPreparePanel] featureId: " + featureId + ", view: " + view + " menu: " + menu);
if (featureId == Window.FEATURE_OPTIONS_PANEL) {
boolean result = onPrepareOptionsMenu(menu);
if (DEBUG) Log.d(TAG, "[onPreparePanel] activity prepare result: " + result);
boolean show = false;
if (mFragments.mActive != null) {
for (int i = 0; i < mFragments.mAdded.size(); i++) {
Fragment f = mFragments.mAdded.get(i);
if (f != null && !f.mHidden && f.mHasMenu && f.mMenuVisible && f instanceof OnPrepareOptionsMenuListener) {
show = true;
((OnPrepareOptionsMenuListener)f).onPrepareOptionsMenu(menu);
}
}
}
if (DEBUG) Log.d(TAG, "[onPreparePanel] fragments prepare result: " + show);
result |= show;
result &= menu.hasVisibleItems();
if (DEBUG) Log.d(TAG, "[onPreparePanel] returning " + result);
return result;
}
return false;
}
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
if (DEBUG) Log.d(TAG, "[onMenuItemSelected] featureId: " + featureId + ", item: " + item);
if (featureId == Window.FEATURE_OPTIONS_PANEL) {
if (onOptionsItemSelected(item)) {
return true;
}
if (mFragments.mActive != null) {
for (int i = 0; i < mFragments.mAdded.size(); i++) {
Fragment f = mFragments.mAdded.get(i);
if (f != null && !f.mHidden && f.mHasMenu && f.mMenuVisible && f instanceof OnOptionsItemSelectedListener) {
if (((OnOptionsItemSelectedListener)f).onOptionsItemSelected(item)) {
return true;
}
}
}
}
}
return false;
}
public abstract boolean onCreateOptionsMenu(Menu menu);
public abstract boolean onPrepareOptionsMenu(Menu menu);
public abstract boolean onOptionsItemSelected(MenuItem item);
public abstract MenuInflater getSupportMenuInflater();
}

View File

@ -523,6 +523,20 @@ public abstract class ActionBarSherlock {
*/ */
public void dispatchPanelClosed(int featureId, android.view.Menu menu) {} public void dispatchPanelClosed(int featureId, android.view.Menu menu) {}
/**
* Notify the action bar that the activity has been destroyed. This method
* should be called before the superclass implementation.
*
* <blockquote><p>
* @Override
* public void onDestroy() {
* mSherlock.dispatchDestroy();
* super.onDestroy();
* }
* </p></blockquote>
*/
public void dispatchDestroy() {}
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////

View File

@ -76,6 +76,12 @@ public abstract class SherlockActivity extends Activity implements OnCreatePanel
super.onStop(); super.onStop();
} }
@Override
protected void onDestroy() {
getSherlock().dispatchDestroy();
super.onDestroy();
}
@Override @Override
protected void onPostCreate(Bundle savedInstanceState) { protected void onPostCreate(Bundle savedInstanceState) {
getSherlock().dispatchPostCreate(savedInstanceState); getSherlock().dispatchPostCreate(savedInstanceState);

View File

@ -1,18 +1,18 @@
package com.actionbarsherlock.app; package com.actionbarsherlock.app;
import static com.actionbarsherlock.app.SherlockFragmentActivity.DEBUG;
import android.app.Activity; import android.app.Activity;
import android.support.v4.app.DialogFragment; import android.support.v4.app.DialogFragment;
import android.util.Log; import com.actionbarsherlock.internal.view.menu.MenuItemWrapper;
import com.actionbarsherlock.internal.view.menu.MenuItemMule; import com.actionbarsherlock.internal.view.menu.MenuWrapper;
import com.actionbarsherlock.internal.view.menu.MenuMule;
import com.actionbarsherlock.view.Menu; import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater; import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem; import com.actionbarsherlock.view.MenuItem;
public class SherlockDialogFragment extends DialogFragment { import static com.actionbarsherlock.app.SherlockFragmentActivity.OnCreateOptionsMenuListener;
private static final String TAG = "SherlockDialogFragment"; import static com.actionbarsherlock.app.SherlockFragmentActivity.OnOptionsItemSelectedListener;
import static com.actionbarsherlock.app.SherlockFragmentActivity.OnPrepareOptionsMenuListener;
public class SherlockDialogFragment extends DialogFragment implements OnCreateOptionsMenuListener, OnPrepareOptionsMenuListener, OnOptionsItemSelectedListener {
private SherlockFragmentActivity mActivity; private SherlockFragmentActivity mActivity;
public SherlockFragmentActivity getSherlockActivity() { public SherlockFragmentActivity getSherlockActivity() {
@ -22,53 +22,45 @@ public class SherlockDialogFragment extends DialogFragment {
@Override @Override
public void onAttach(Activity activity) { public void onAttach(Activity activity) {
if (!(activity instanceof SherlockFragmentActivity)) { if (!(activity instanceof SherlockFragmentActivity)) {
throw new IllegalStateException(TAG + " must be attached to a SherlockFragmentActivity."); throw new IllegalStateException(getClass().getSimpleName() + " must be attached to a SherlockFragmentActivity.");
} }
mActivity = (SherlockFragmentActivity)activity; mActivity = (SherlockFragmentActivity)activity;
super.onAttach(activity); super.onAttach(activity);
} }
@Override
public void onDetach() {
mActivity = null;
super.onDetach();
}
@Override @Override
public final void onCreateOptionsMenu(android.view.Menu menu, android.view.MenuInflater inflater) { public final void onCreateOptionsMenu(android.view.Menu menu, android.view.MenuInflater inflater) {
if (DEBUG) Log.d(TAG, "[onCreateOptionsMenu] menu: " + menu + ", inflater: " + inflater); onCreateOptionsMenu(new MenuWrapper(menu), mActivity.getSupportMenuInflater());
if (menu instanceof MenuMule) {
MenuMule mule = (MenuMule)menu;
mule.mDispatchShow = true;
onCreateOptionsMenu(mule.unwrap(), mActivity.getSupportMenuInflater());
}
} }
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
//Nothing to see here. //Nothing to see here.
} }
@Override @Override
public final void onPrepareOptionsMenu(android.view.Menu menu) { public final void onPrepareOptionsMenu(android.view.Menu menu) {
if (DEBUG) Log.d(TAG, "[onPrepareOptionsMenu] menu: " + menu); onPrepareOptionsMenu(new MenuWrapper(menu));
if (menu instanceof MenuMule) {
MenuMule mule = (MenuMule)menu;
mule.mDispatchShow = true;
onPrepareOptionsMenu(mule.unwrap());
}
} }
@Override
public void onPrepareOptionsMenu(Menu menu) { public void onPrepareOptionsMenu(Menu menu) {
//Nothing to see here. //Nothing to see here.
} }
@Override @Override
public final boolean onOptionsItemSelected(android.view.MenuItem item) { public final boolean onOptionsItemSelected(android.view.MenuItem item) {
if (DEBUG) Log.d(TAG, "[onOptionsItemSelected] item: " + item); return onOptionsItemSelected(new MenuItemWrapper(item));
if (item instanceof MenuItemMule) {
return onOptionsItemSelected(((MenuItemMule)item).unwrap());
}
return false;
} }
@Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
//Nothing to see here. //Nothing to see here.
return false; return false;

View File

@ -76,6 +76,12 @@ public abstract class SherlockExpandableListActivity extends ExpandableListActiv
super.onStop(); super.onStop();
} }
@Override
protected void onDestroy() {
getSherlock().dispatchDestroy();
super.onDestroy();
}
@Override @Override
protected void onPostCreate(Bundle savedInstanceState) { protected void onPostCreate(Bundle savedInstanceState) {
getSherlock().dispatchPostCreate(savedInstanceState); getSherlock().dispatchPostCreate(savedInstanceState);

View File

@ -1,18 +1,18 @@
package com.actionbarsherlock.app; package com.actionbarsherlock.app;
import static com.actionbarsherlock.app.SherlockFragmentActivity.DEBUG;
import android.app.Activity; import android.app.Activity;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.util.Log; import com.actionbarsherlock.internal.view.menu.MenuItemWrapper;
import com.actionbarsherlock.internal.view.menu.MenuItemMule; import com.actionbarsherlock.internal.view.menu.MenuWrapper;
import com.actionbarsherlock.internal.view.menu.MenuMule;
import com.actionbarsherlock.view.Menu; import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater; import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem; import com.actionbarsherlock.view.MenuItem;
public class SherlockFragment extends Fragment { import static com.actionbarsherlock.app.SherlockFragmentActivity.OnCreateOptionsMenuListener;
private static final String TAG = "SherlockFragment"; import static com.actionbarsherlock.app.SherlockFragmentActivity.OnOptionsItemSelectedListener;
import static com.actionbarsherlock.app.SherlockFragmentActivity.OnPrepareOptionsMenuListener;
public class SherlockFragment extends Fragment implements OnCreateOptionsMenuListener, OnPrepareOptionsMenuListener, OnOptionsItemSelectedListener {
private SherlockFragmentActivity mActivity; private SherlockFragmentActivity mActivity;
public SherlockFragmentActivity getSherlockActivity() { public SherlockFragmentActivity getSherlockActivity() {
@ -22,53 +22,45 @@ public class SherlockFragment extends Fragment {
@Override @Override
public void onAttach(Activity activity) { public void onAttach(Activity activity) {
if (!(activity instanceof SherlockFragmentActivity)) { if (!(activity instanceof SherlockFragmentActivity)) {
throw new IllegalStateException(TAG + " must be attached to a SherlockFragmentActivity."); throw new IllegalStateException(getClass().getSimpleName() + " must be attached to a SherlockFragmentActivity.");
} }
mActivity = (SherlockFragmentActivity)activity; mActivity = (SherlockFragmentActivity)activity;
super.onAttach(activity); super.onAttach(activity);
} }
@Override
public void onDetach() {
mActivity = null;
super.onDetach();
}
@Override @Override
public final void onCreateOptionsMenu(android.view.Menu menu, android.view.MenuInflater inflater) { public final void onCreateOptionsMenu(android.view.Menu menu, android.view.MenuInflater inflater) {
if (DEBUG) Log.d(TAG, "[onCreateOptionsMenu] menu: " + menu + ", inflater: " + inflater); onCreateOptionsMenu(new MenuWrapper(menu), mActivity.getSupportMenuInflater());
if (menu instanceof MenuMule) {
MenuMule mule = (MenuMule)menu;
mule.mDispatchShow = true;
onCreateOptionsMenu(mule.unwrap(), mActivity.getSupportMenuInflater());
}
} }
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
//Nothing to see here. //Nothing to see here.
} }
@Override @Override
public final void onPrepareOptionsMenu(android.view.Menu menu) { public final void onPrepareOptionsMenu(android.view.Menu menu) {
if (DEBUG) Log.d(TAG, "[onPrepareOptionsMenu] menu: " + menu); onPrepareOptionsMenu(new MenuWrapper(menu));
if (menu instanceof MenuMule) {
MenuMule mule = (MenuMule)menu;
mule.mDispatchShow = true;
onPrepareOptionsMenu(mule.unwrap());
}
} }
@Override
public void onPrepareOptionsMenu(Menu menu) { public void onPrepareOptionsMenu(Menu menu) {
//Nothing to see here. //Nothing to see here.
} }
@Override @Override
public final boolean onOptionsItemSelected(android.view.MenuItem item) { public final boolean onOptionsItemSelected(android.view.MenuItem item) {
if (DEBUG) Log.d(TAG, "[onOptionsItemSelected] item: " + item); return onOptionsItemSelected(new MenuItemWrapper(item));
if (item instanceof MenuItemMule) {
return onOptionsItemSelected(((MenuItemMule)item).unwrap());
}
return false;
} }
@Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
//Nothing to see here. //Nothing to see here.
return false; return false;

View File

@ -2,27 +2,24 @@ package com.actionbarsherlock.app;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.FragmentActivity; import android.support.v4.app._ActionBarSherlockTrojanHorse;
import android.util.Log; import android.util.Log;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.View; import android.view.View;
import android.view.ViewGroup.LayoutParams; import android.view.ViewGroup.LayoutParams;
import android.view.Window; import android.view.Window;
import com.actionbarsherlock.ActionBarSherlock; import com.actionbarsherlock.ActionBarSherlock;
import com.actionbarsherlock.ActionBarSherlock.OnActionModeFinishedListener;
import com.actionbarsherlock.ActionBarSherlock.OnActionModeStartedListener;
import com.actionbarsherlock.ActionBarSherlock.OnCreatePanelMenuListener;
import com.actionbarsherlock.ActionBarSherlock.OnMenuItemSelectedListener;
import com.actionbarsherlock.ActionBarSherlock.OnPreparePanelListener;
import com.actionbarsherlock.internal.view.menu.MenuItemMule;
import com.actionbarsherlock.internal.view.menu.MenuMule;
import com.actionbarsherlock.view.ActionMode; import com.actionbarsherlock.view.ActionMode;
import com.actionbarsherlock.view.Menu; import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater; import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem; import com.actionbarsherlock.view.MenuItem;
public abstract class SherlockFragmentActivity extends FragmentActivity implements OnCreatePanelMenuListener, OnPreparePanelListener, OnMenuItemSelectedListener, OnActionModeStartedListener, OnActionModeFinishedListener { import static com.actionbarsherlock.ActionBarSherlock.OnActionModeFinishedListener;
static final boolean DEBUG = false; import static com.actionbarsherlock.ActionBarSherlock.OnActionModeStartedListener;
/** @see {@link _ActionBarSherlockTrojanHorse} */
public class SherlockFragmentActivity extends _ActionBarSherlockTrojanHorse implements OnActionModeStartedListener, OnActionModeFinishedListener {
private static final boolean DEBUG = false;
private static final String TAG = "SherlockFragmentActivity"; private static final String TAG = "SherlockFragmentActivity";
private ActionBarSherlock mSherlock; private ActionBarSherlock mSherlock;
@ -85,6 +82,12 @@ public abstract class SherlockFragmentActivity extends FragmentActivity implemen
super.onStop(); super.onStop();
} }
@Override
protected void onDestroy() {
getSherlock().dispatchDestroy();
super.onDestroy();
}
@Override @Override
protected void onPostCreate(Bundle savedInstanceState) { protected void onPostCreate(Bundle savedInstanceState) {
getSherlock().dispatchPostCreate(savedInstanceState); getSherlock().dispatchPostCreate(savedInstanceState);
@ -221,75 +224,14 @@ public abstract class SherlockFragmentActivity extends FragmentActivity implemen
// Sherlock menu handling // Sherlock menu handling
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
@Override
public boolean onCreatePanelMenu(int featureId, Menu menu) {
if (DEBUG) Log.d(TAG, "[onCreatePanelMenu] featureId: " + featureId + ", menu: " + menu);
if (featureId == Window.FEATURE_OPTIONS_PANEL) {
boolean result = onCreateOptionsMenu(menu);
if (DEBUG) Log.d(TAG, "[onCreatePanelMenu] activity create result: " + result);
//Dispatch to parent panel creation for fragment dispatching
if (DEBUG) Log.d(TAG, "[onCreatePanelMenu] dispatching to native with mule");
MenuMule mule = new MenuMule(menu);
super.onCreatePanelMenu(featureId, mule);
if (DEBUG) Log.d(TAG, "[onCreatePanelMenu] fragments create result: " + mule.mDispatchShow);
result |= mule.mDispatchShow;
if (DEBUG) Log.d(TAG, "[onCreatePanelMenu] returning " + result);
return result;
}
return false;
}
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
return true; return true;
} }
@Override
public boolean onPreparePanel(int featureId, View view, Menu menu) {
if (DEBUG) Log.d(TAG, "[onPreparePanel] featureId: " + featureId + ", view: " + view + " menu: " + menu);
if (featureId == Window.FEATURE_OPTIONS_PANEL) {
boolean result = onPrepareOptionsMenu(menu);
if (DEBUG) Log.d(TAG, "[onPreparePanel] activity prepare result: " + result);
//Dispatch to parent panel preparation for fragment dispatching
if (DEBUG) Log.d(TAG, "[onPreparePanel] dispatching to native with mule");
MenuMule mule = new MenuMule(menu);
super.onPreparePanel(featureId, view, mule);
if (DEBUG) Log.d(TAG, "[onPreparePanel] fragments prepare result: " + mule.mDispatchShow);
result |= mule.mDispatchShow;
result &= menu.hasVisibleItems();
if (DEBUG) Log.d(TAG, "[onPreparePanel] returning " + result);
return result;
}
return false;
}
public boolean onPrepareOptionsMenu(Menu menu) { public boolean onPrepareOptionsMenu(Menu menu) {
return true; return true;
} }
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
if (DEBUG) Log.d(TAG, "[onMenuItemSelected] featureId: " + featureId + ", item: " + item);
if (featureId == Window.FEATURE_OPTIONS_PANEL) {
if (onOptionsItemSelected(item)) {
return true;
}
//Dispatch to parent panel selection for fragment dispatching
if (DEBUG) Log.d(TAG, "[onMenuItemSelected] dispatching to native with mule");
return super.onMenuItemSelected(featureId, new MenuItemMule(item));
}
return false;
}
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
return false; return false;
} }

View File

@ -76,6 +76,12 @@ public abstract class SherlockListActivity extends ListActivity implements OnCre
super.onStop(); super.onStop();
} }
@Override
protected void onDestroy() {
getSherlock().dispatchDestroy();
super.onDestroy();
}
@Override @Override
protected void onPostCreate(Bundle savedInstanceState) { protected void onPostCreate(Bundle savedInstanceState) {
getSherlock().dispatchPostCreate(savedInstanceState); getSherlock().dispatchPostCreate(savedInstanceState);

View File

@ -1,18 +1,18 @@
package com.actionbarsherlock.app; package com.actionbarsherlock.app;
import static com.actionbarsherlock.app.SherlockFragmentActivity.DEBUG;
import android.app.Activity; import android.app.Activity;
import android.support.v4.app.ListFragment; import android.support.v4.app.ListFragment;
import android.util.Log; import com.actionbarsherlock.internal.view.menu.MenuItemWrapper;
import com.actionbarsherlock.internal.view.menu.MenuItemMule; import com.actionbarsherlock.internal.view.menu.MenuWrapper;
import com.actionbarsherlock.internal.view.menu.MenuMule;
import com.actionbarsherlock.view.Menu; import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater; import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem; import com.actionbarsherlock.view.MenuItem;
public class SherlockListFragment extends ListFragment { import static com.actionbarsherlock.app.SherlockFragmentActivity.OnCreateOptionsMenuListener;
private static final String TAG = "SherlockListFragment"; import static com.actionbarsherlock.app.SherlockFragmentActivity.OnOptionsItemSelectedListener;
import static com.actionbarsherlock.app.SherlockFragmentActivity.OnPrepareOptionsMenuListener;
public class SherlockListFragment extends ListFragment implements OnCreateOptionsMenuListener, OnPrepareOptionsMenuListener, OnOptionsItemSelectedListener {
private SherlockFragmentActivity mActivity; private SherlockFragmentActivity mActivity;
public SherlockFragmentActivity getSherlockActivity() { public SherlockFragmentActivity getSherlockActivity() {
@ -22,53 +22,45 @@ public class SherlockListFragment extends ListFragment {
@Override @Override
public void onAttach(Activity activity) { public void onAttach(Activity activity) {
if (!(activity instanceof SherlockFragmentActivity)) { if (!(activity instanceof SherlockFragmentActivity)) {
throw new IllegalStateException(TAG + " must be attached to a SherlockFragmentActivity."); throw new IllegalStateException(getClass().getSimpleName() + " must be attached to a SherlockFragmentActivity.");
} }
mActivity = (SherlockFragmentActivity)activity; mActivity = (SherlockFragmentActivity)activity;
super.onAttach(activity); super.onAttach(activity);
} }
@Override
public void onDetach() {
mActivity = null;
super.onDetach();
}
@Override @Override
public final void onCreateOptionsMenu(android.view.Menu menu, android.view.MenuInflater inflater) { public final void onCreateOptionsMenu(android.view.Menu menu, android.view.MenuInflater inflater) {
if (DEBUG) Log.d(TAG, "[onCreateOptionsMenu] menu: " + menu + ", inflater: " + inflater); onCreateOptionsMenu(new MenuWrapper(menu), mActivity.getSupportMenuInflater());
if (menu instanceof MenuMule) {
MenuMule mule = (MenuMule)menu;
mule.mDispatchShow = true;
onCreateOptionsMenu(mule.unwrap(), mActivity.getSupportMenuInflater());
}
} }
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
//Nothing to see here. //Nothing to see here.
} }
@Override @Override
public final void onPrepareOptionsMenu(android.view.Menu menu) { public final void onPrepareOptionsMenu(android.view.Menu menu) {
if (DEBUG) Log.d(TAG, "[onPrepareOptionsMenu] menu: " + menu); onPrepareOptionsMenu(new MenuWrapper(menu));
if (menu instanceof MenuMule) {
MenuMule mule = (MenuMule)menu;
mule.mDispatchShow = true;
onPrepareOptionsMenu(mule.unwrap());
}
} }
@Override
public void onPrepareOptionsMenu(Menu menu) { public void onPrepareOptionsMenu(Menu menu) {
//Nothing to see here. //Nothing to see here.
} }
@Override @Override
public final boolean onOptionsItemSelected(android.view.MenuItem item) { public final boolean onOptionsItemSelected(android.view.MenuItem item) {
if (DEBUG) Log.d(TAG, "[onOptionsItemSelected] item: " + item); return onOptionsItemSelected(new MenuItemWrapper(item));
if (item instanceof MenuItemMule) {
return onOptionsItemSelected(((MenuItemMule)item).unwrap());
}
return false;
} }
@Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
//Nothing to see here. //Nothing to see here.
return false; return false;

View File

@ -76,6 +76,12 @@ public abstract class SherlockPreferenceActivity extends PreferenceActivity impl
super.onStop(); super.onStop();
} }
@Override
protected void onDestroy() {
getSherlock().dispatchDestroy();
super.onDestroy();
}
@Override @Override
protected void onPostCreate(Bundle savedInstanceState) { protected void onPostCreate(Bundle savedInstanceState) {
getSherlock().dispatchPostCreate(savedInstanceState); getSherlock().dispatchPostCreate(savedInstanceState);

View File

@ -81,6 +81,8 @@ public class ActionBarSherlockCompat extends ActionBarSherlock implements MenuBu
/** Whether or not the title is stable and can be displayed. */ /** Whether or not the title is stable and can be displayed. */
private boolean mIsTitleReady = false; private boolean mIsTitleReady = false;
/** Whether or not the parent activity has been destroyed. */
private boolean mIsDestroyed = false;
/* Emulate PanelFeatureState */ /* Emulate PanelFeatureState */
private boolean mClosingActionMenu; private boolean mClosingActionMenu;
@ -413,7 +415,7 @@ public class ActionBarSherlockCompat extends ActionBarSherlock implements MenuBu
} }
// Next collapse any expanded action views. // Next collapse any expanded action views.
if (aActionBar != null && wActionBar.hasExpandedActionView()) { if (wActionBar != null && wActionBar.hasExpandedActionView()) {
if (action == KeyEvent.ACTION_UP) { if (action == KeyEvent.ACTION_UP) {
wActionBar.collapseActionView(); wActionBar.collapseActionView();
} }
@ -428,7 +430,7 @@ public class ActionBarSherlockCompat extends ActionBarSherlock implements MenuBu
mMenuKeyIsLongPress = true; mMenuKeyIsLongPress = true;
} else if (event.getAction() == KeyEvent.ACTION_UP) { } else if (event.getAction() == KeyEvent.ACTION_UP) {
if (!mMenuKeyIsLongPress) { if (!mMenuKeyIsLongPress) {
if (mActionMode == null) { if (mActionMode == null && wActionBar != null) {
if (wActionBar.isOverflowMenuShowing()) { if (wActionBar.isOverflowMenuShowing()) {
wActionBar.hideOverflowMenu(); wActionBar.hideOverflowMenu();
} else { } else {
@ -445,6 +447,11 @@ public class ActionBarSherlockCompat extends ActionBarSherlock implements MenuBu
return result; return result;
} }
@Override
public void dispatchDestroy() {
mIsDestroyed = true;
}
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// Menu callback lifecycle and creation // Menu callback lifecycle and creation
@ -977,7 +984,7 @@ public class ActionBarSherlockCompat extends ActionBarSherlock implements MenuBu
@Override @Override
public void run() { public void run() {
//Invalidate if the panel menu hasn't been created before this. //Invalidate if the panel menu hasn't been created before this.
if (!mActivity.isFinishing() && mMenu == null) { if (!mIsDestroyed && !mActivity.isFinishing() && mMenu == null) {
dispatchInvalidateOptionsMenu(); dispatchInvalidateOptionsMenu();
} }
} }

View File

@ -217,7 +217,6 @@ public class ActionBarWrapper extends ActionBar implements android.app.ActionBar
public TabWrapper(android.app.ActionBar.Tab nativeTab) { public TabWrapper(android.app.ActionBar.Tab nativeTab) {
mNativeTab = nativeTab; mNativeTab = nativeTab;
mNativeTab.setTag(this); mNativeTab.setTag(this);
mNativeTab.setTabListener(this);
} }
@Override @Override
@ -289,6 +288,7 @@ public class ActionBarWrapper extends ActionBar implements android.app.ActionBar
@Override @Override
public Tab setTabListener(TabListener listener) { public Tab setTabListener(TabListener listener) {
mNativeTab.setTabListener(listener != null ? this : null);
mListener = listener; mListener = listener;
return this; return this;
} }

View File

@ -140,6 +140,8 @@ public final class AnimatorProxy extends Animation {
return; return;
} }
view.setAnimation(this);
final RectF after = mAfter; final RectF after = mAfter;
computeRect(after, view); computeRect(after, view);
after.union(mBefore); after.union(mBefore);
@ -202,4 +204,9 @@ public final class AnimatorProxy extends Animation {
transformMatrix(t.getMatrix(), view); transformMatrix(t.getMatrix(), view);
} }
} }
@Override
public void reset() {
/* Do nothing. */
}
} }

View File

@ -24,6 +24,8 @@ public final class Constants {
public static final String PACKAGE_NAME = "org.thialfihar.android.apg"; public static final String PACKAGE_NAME = "org.thialfihar.android.apg";
public static final boolean DEBUG = true;
/* /*
* TODO: * TODO:
* *

View File

@ -31,7 +31,7 @@ import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.os.IBinder; import android.os.IBinder;
import android.util.Log; import org.thialfihar.android.apg.util.Log;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;

View File

@ -47,7 +47,7 @@ import android.database.sqlite.SQLiteQueryBuilder;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.os.IBinder; import android.os.IBinder;
import android.util.Log; import org.thialfihar.android.apg.util.Log;
/** /**
* ATTENTION: * ATTENTION:

View File

@ -22,7 +22,7 @@ import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper; import android.database.sqlite.SQLiteOpenHelper;
import android.net.Uri; import android.net.Uri;
import android.util.Log; import org.thialfihar.android.apg.util.Log;
public class ApgServiceBlobDatabase extends SQLiteOpenHelper { public class ApgServiceBlobDatabase extends SQLiteOpenHelper {

View File

@ -21,7 +21,7 @@ import android.content.ContentValues;
import android.database.Cursor; import android.database.Cursor;
import android.net.Uri; import android.net.Uri;
import android.os.ParcelFileDescriptor; import android.os.ParcelFileDescriptor;
import android.util.Log; import org.thialfihar.android.apg.util.Log;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;

View File

@ -28,11 +28,11 @@ import org.spongycastle.openpgp.PGPSecretKey;
import org.spongycastle.openpgp.PGPSecretKeyRing; import org.spongycastle.openpgp.PGPSecretKeyRing;
import org.thialfihar.android.apg.Constants; import org.thialfihar.android.apg.Constants;
import android.util.Log; import org.thialfihar.android.apg.util.Log;
public class PGPConversionHelper { public class PGPConversionHelper {
/** /**
* Converts Vector<PGPSecretKey> to a byte[] array to send it by intent to service * Converts Vector<PGPSecretKey> to a byte[]
* *
* @param keys * @param keys
* @return * @return
@ -94,10 +94,17 @@ public class PGPConversionHelper {
return keyRing; return keyRing;
} }
/**
* Convert from byte[] to ArrayList<PGPSecretKey>
*
* @param keysBytes
* @return
*/
public static ArrayList<PGPSecretKey> BytesToPGPSecretKeyList(byte[] keysBytes) { public static ArrayList<PGPSecretKey> BytesToPGPSecretKeyList(byte[] keysBytes) {
PGPSecretKeyRing keyRing = BytesToPGPSecretKeyRing(keysBytes); PGPSecretKeyRing keyRing = BytesToPGPSecretKeyRing(keysBytes);
ArrayList<PGPSecretKey> keys = new ArrayList<PGPSecretKey>(); ArrayList<PGPSecretKey> keys = new ArrayList<PGPSecretKey>();
@SuppressWarnings("unchecked")
Iterator<PGPSecretKey> itr = keyRing.getSecretKeys(); Iterator<PGPSecretKey> itr = keyRing.getSecretKeys();
while (itr.hasNext()) { while (itr.hasNext()) {
keys.add(itr.next()); keys.add(itr.next());
@ -106,12 +113,24 @@ public class PGPConversionHelper {
return keys; return keys;
} }
/**
* Convert from byte[] to PGPSecretKey
*
* @param keysBytes
* @return
*/
public static PGPSecretKey BytesToPGPSecretKey(byte[] keyBytes) { public static PGPSecretKey BytesToPGPSecretKey(byte[] keyBytes) {
PGPSecretKey key = BytesToPGPSecretKeyList(keyBytes).get(0); PGPSecretKey key = BytesToPGPSecretKeyList(keyBytes).get(0);
return key; return key;
} }
/**
* Convert from PGPSecretKey to byte[]
*
* @param keysBytes
* @return
*/
public static byte[] PGPSecretKeyToBytes(PGPSecretKey key) { public static byte[] PGPSecretKeyToBytes(PGPSecretKey key) {
try { try {
return key.getEncoded(); return key.getEncoded();
@ -122,6 +141,12 @@ public class PGPConversionHelper {
} }
} }
/**
* Convert from PGPSecretKeyRing to byte[]
*
* @param keysBytes
* @return
*/
public static byte[] PGPSecretKeyRingToBytes(PGPSecretKeyRing keyRing) { public static byte[] PGPSecretKeyRingToBytes(PGPSecretKeyRing keyRing) {
try { try {
return keyRing.getEncoded(); return keyRing.getEncoded();

View File

@ -97,7 +97,7 @@ import android.database.sqlite.SQLiteDatabase;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.os.Environment; import android.os.Environment;
import android.util.Log; import org.thialfihar.android.apg.util.Log;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.BufferedReader; import java.io.BufferedReader;

View File

@ -31,7 +31,7 @@ import android.app.Dialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener; import android.content.DialogInterface.OnClickListener;
import android.util.Log; import org.thialfihar.android.apg.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.widget.EditText; import android.widget.EditText;

View File

@ -28,7 +28,7 @@ import android.content.Context;
import android.database.Cursor; import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper; import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log; import org.thialfihar.android.apg.util.Log;
import java.io.IOException; import java.io.IOException;
import java.util.Date; import java.util.Date;

View File

@ -48,7 +48,7 @@ import android.os.Bundle;
import android.os.Message; import android.os.Message;
import android.os.Messenger; import android.os.Messenger;
import android.os.RemoteException; import android.os.RemoteException;
import android.util.Log; import org.thialfihar.android.apg.util.Log;
/** /**
* This Service contains all important long lasting operations for APG. It receives Intents with * This Service contains all important long lasting operations for APG. It receives Intents with

View File

@ -46,7 +46,7 @@ import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.Message; import android.os.Message;
import android.os.Messenger; import android.os.Messenger;
import android.util.Log; import org.thialfihar.android.apg.util.Log;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.view.animation.AnimationUtils; import android.view.animation.AnimationUtils;

View File

@ -48,7 +48,7 @@ import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.os.Message; import android.os.Message;
import android.os.Messenger; import android.os.Messenger;
import android.util.Log; import org.thialfihar.android.apg.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;

View File

@ -49,7 +49,7 @@ import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.Message; import android.os.Message;
import android.os.Messenger; import android.os.Messenger;
import android.util.Log; import org.thialfihar.android.apg.util.Log;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.view.animation.AnimationUtils; import android.view.animation.AnimationUtils;

View File

@ -26,7 +26,7 @@ import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle; import android.os.Bundle;
import android.text.Html; import android.text.Html;
import android.text.method.LinkMovementMethod; import android.text.method.LinkMovementMethod;
import android.util.Log; import org.thialfihar.android.apg.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;

View File

@ -32,7 +32,7 @@ import org.thialfihar.android.apg.R;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.os.Message; import android.os.Message;
import android.util.Log; import org.thialfihar.android.apg.util.Log;
import android.widget.Toast; import android.widget.Toast;
import com.google.zxing.integration.android.IntentIntegrator; import com.google.zxing.integration.android.IntentIntegrator;

View File

@ -46,7 +46,7 @@ import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.Message; import android.os.Message;
import android.os.Messenger; import android.os.Messenger;
import android.util.Log; import org.thialfihar.android.apg.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;

View File

@ -43,7 +43,7 @@ import com.actionbarsherlock.view.MenuItem;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.os.Message; import android.os.Message;
import android.util.Log; import org.thialfihar.android.apg.util.Log;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;

View File

@ -30,7 +30,7 @@ import android.os.Message;
import android.os.Messenger; import android.os.Messenger;
import android.os.RemoteException; import android.os.RemoteException;
import android.support.v4.app.DialogFragment; import android.support.v4.app.DialogFragment;
import android.util.Log; import org.thialfihar.android.apg.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.widget.CheckBox; import android.widget.CheckBox;

View File

@ -38,7 +38,7 @@ import android.os.Message;
import android.os.Messenger; import android.os.Messenger;
import android.os.RemoteException; import android.os.RemoteException;
import android.support.v4.app.DialogFragment; import android.support.v4.app.DialogFragment;
import android.util.Log; import org.thialfihar.android.apg.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.widget.EditText; import android.widget.EditText;

View File

@ -19,7 +19,7 @@ package org.thialfihar.android.apg.util;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import android.content.Context; import android.content.Context;
import android.util.Log; import org.thialfihar.android.apg.util.Log;
public class Compatibility { public class Compatibility {

View File

@ -0,0 +1,83 @@
/*
* Copyright (C) 2012 Dominik Schürmann <dominik@dominikschuermann.de>
*
* 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.thialfihar.android.apg.util;
import org.thialfihar.android.apg.Constants;
/**
* Wraps Android Logging to enable or disable debug output using Constants
*
*/
public final class Log {
public static void v(String tag, String msg) {
if (Constants.DEBUG) {
android.util.Log.v(tag, msg);
}
}
public static void v(String tag, String msg, Throwable tr) {
if (Constants.DEBUG) {
android.util.Log.v(tag, msg, tr);
}
}
public static void d(String tag, String msg) {
if (Constants.DEBUG) {
android.util.Log.d(tag, msg);
}
}
public static void d(String tag, String msg, Throwable tr) {
if (Constants.DEBUG) {
android.util.Log.d(tag, msg, tr);
}
}
public static void i(String tag, String msg) {
if (Constants.DEBUG) {
android.util.Log.i(tag, msg);
}
}
public static void i(String tag, String msg, Throwable tr) {
if (Constants.DEBUG) {
android.util.Log.i(tag, msg, tr);
}
}
public static void w(String tag, String msg) {
android.util.Log.w(tag, msg);
}
public static void w(String tag, String msg, Throwable tr) {
android.util.Log.w(tag, msg, tr);
}
public static void w(String tag, Throwable tr) {
android.util.Log.w(tag, tr);
}
public static void e(String tag, String msg) {
android.util.Log.e(tag, msg);
}
public static void e(String tag, String msg, Throwable tr) {
android.util.Log.e(tag, msg, tr);
}
}