Skip to content

Commit

Permalink
Switch to use BuildConfig for DEBUG flag.
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeWharton committed Jan 14, 2013
1 parent e349c11 commit 145431d
Show file tree
Hide file tree
Showing 11 changed files with 275 additions and 253 deletions.
10 changes: 10 additions & 0 deletions actionbarsherlock/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.easytesting</groupId>
<artifactId>fest-assert-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.pivotallabs</groupId>
<artifactId>robolectric</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
21 changes: 10 additions & 11 deletions actionbarsherlock/src/android/support/v4/app/Watson.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
import com.actionbarsherlock.ActionBarSherlock.OnCreatePanelMenuListener;
import com.actionbarsherlock.ActionBarSherlock.OnMenuItemSelectedListener;
import com.actionbarsherlock.ActionBarSherlock.OnPreparePanelListener;
import com.actionbarsherlock.BuildConfig;
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 Watson extends FragmentActivity implements OnCreatePanelMenuListener, OnPreparePanelListener, OnMenuItemSelectedListener {
private static final boolean DEBUG = false;
private static final String TAG = "Watson";

/** Fragment interface for menu creation callback. */
Expand All @@ -39,11 +38,11 @@ public interface OnOptionsItemSelectedListener {

@Override
public boolean onCreatePanelMenu(int featureId, Menu menu) {
if (DEBUG) Log.d(TAG, "[onCreatePanelMenu] featureId: " + featureId + ", menu: " + menu);
if (BuildConfig.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);
if (BuildConfig.DEBUG) Log.d(TAG, "[onCreatePanelMenu] activity create result: " + result);

MenuInflater inflater = getSupportMenuInflater();
boolean show = false;
Expand Down Expand Up @@ -73,22 +72,22 @@ public boolean onCreatePanelMenu(int featureId, Menu menu) {

mCreatedMenus = newMenus;

if (DEBUG) Log.d(TAG, "[onCreatePanelMenu] fragments create result: " + show);
if (BuildConfig.DEBUG) Log.d(TAG, "[onCreatePanelMenu] fragments create result: " + show);
result |= show;

if (DEBUG) Log.d(TAG, "[onCreatePanelMenu] returning " + result);
if (BuildConfig.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 (BuildConfig.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);
if (BuildConfig.DEBUG) Log.d(TAG, "[onPreparePanel] activity prepare result: " + result);

boolean show = false;
if (mFragments.mAdded != null) {
Expand All @@ -101,19 +100,19 @@ public boolean onPreparePanel(int featureId, View view, Menu menu) {
}
}

if (DEBUG) Log.d(TAG, "[onPreparePanel] fragments prepare result: " + show);
if (BuildConfig.DEBUG) Log.d(TAG, "[onPreparePanel] fragments prepare result: " + show);
result |= show;

result &= menu.hasVisibleItems();
if (DEBUG) Log.d(TAG, "[onPreparePanel] returning " + result);
if (BuildConfig.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 (BuildConfig.DEBUG) Log.d(TAG, "[onMenuItemSelected] featureId: " + featureId + ", item: " + item);

if (featureId == Window.FEATURE_OPTIONS_PANEL) {
if (onOptionsItemSelected(item)) {
Expand Down
46 changes: 23 additions & 23 deletions actionbarsherlock/src/com/actionbarsherlock/ActionBarSherlock.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
package com.actionbarsherlock;

import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Iterator;
import android.app.Activity;
import android.content.Context;
import android.content.res.Configuration;
Expand All @@ -27,6 +18,16 @@
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Iterator;

import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;

/**
* <p>Helper for implementing the action bar design pattern across all versions
Expand All @@ -40,7 +41,6 @@
*/
public abstract class ActionBarSherlock {
protected static final String TAG = "ActionBarSherlock";
protected static final boolean DEBUG = false;

private static final Class<?>[] CONSTRUCTOR_ARGS = new Class[] { Activity.class, int.class };
private static final HashMap<Implementation, Class<? extends ActionBarSherlock>> IMPLEMENTATIONS =
Expand Down Expand Up @@ -122,12 +122,12 @@ public static void registerImplementation(Class<? extends ActionBarSherlock> imp
if (!implementationClass.isAnnotationPresent(Implementation.class)) {
throw new IllegalArgumentException("Class " + implementationClass.getSimpleName() + " is not annotated with @Implementation");
} else if (IMPLEMENTATIONS.containsValue(implementationClass)) {
if (DEBUG) Log.w(TAG, "Class " + implementationClass.getSimpleName() + " already registered");
if (BuildConfig.DEBUG) Log.w(TAG, "Class " + implementationClass.getSimpleName() + " already registered");
return;
}

Implementation impl = implementationClass.getAnnotation(Implementation.class);
if (DEBUG) Log.i(TAG, "Registering " + implementationClass.getSimpleName() + " with qualifier " + impl);
if (BuildConfig.DEBUG) Log.i(TAG, "Registering " + implementationClass.getSimpleName() + " with qualifier " + impl);
IMPLEMENTATIONS.put(impl, implementationClass);
}

Expand Down Expand Up @@ -223,7 +223,7 @@ public static ActionBarSherlock wrap(Activity activity, int flags) {
throw new IllegalStateException("No implementations match configuration.");
}
Class<? extends ActionBarSherlock> impl = impls.values().iterator().next();
if (DEBUG) Log.i(TAG, "Using implementation: " + impl.getSimpleName());
if (BuildConfig.DEBUG) Log.i(TAG, "Using implementation: " + impl.getSimpleName());

try {
Constructor<? extends ActionBarSherlock> ctor = impl.getConstructor(CONSTRUCTOR_ARGS);
Expand Down Expand Up @@ -253,7 +253,7 @@ public static ActionBarSherlock wrap(Activity activity, int flags) {


protected ActionBarSherlock(Activity activity, int flags) {
if (DEBUG) Log.d(TAG, "[<ctor>] activity: " + activity + ", flags: " + flags);
if (BuildConfig.DEBUG) Log.d(TAG, "[<ctor>] activity: " + activity + ", flags: " + flags);

mActivity = activity;
mIsDelegate = (flags & FLAG_DELEGATE) != 0;
Expand Down Expand Up @@ -551,7 +551,7 @@ public void dispatchRestoreInstanceState(Bundle savedInstanceState) {}
* @return {@code true} if menu creation should proceed.
*/
protected final boolean callbackCreateOptionsMenu(Menu menu) {
if (DEBUG) Log.d(TAG, "[callbackCreateOptionsMenu] menu: " + menu);
if (BuildConfig.DEBUG) Log.d(TAG, "[callbackCreateOptionsMenu] menu: " + menu);

boolean result = true;
if (mActivity instanceof OnCreatePanelMenuListener) {
Expand All @@ -562,7 +562,7 @@ protected final boolean callbackCreateOptionsMenu(Menu menu) {
result = listener.onCreateOptionsMenu(menu);
}

if (DEBUG) Log.d(TAG, "[callbackCreateOptionsMenu] returning " + result);
if (BuildConfig.DEBUG) Log.d(TAG, "[callbackCreateOptionsMenu] returning " + result);
return result;
}

Expand All @@ -572,7 +572,7 @@ protected final boolean callbackCreateOptionsMenu(Menu menu) {
* @return {@code true} if menu preparation should proceed.
*/
protected final boolean callbackPrepareOptionsMenu(Menu menu) {
if (DEBUG) Log.d(TAG, "[callbackPrepareOptionsMenu] menu: " + menu);
if (BuildConfig.DEBUG) Log.d(TAG, "[callbackPrepareOptionsMenu] menu: " + menu);

boolean result = true;
if (mActivity instanceof OnPreparePanelListener) {
Expand All @@ -583,7 +583,7 @@ protected final boolean callbackPrepareOptionsMenu(Menu menu) {
result = listener.onPrepareOptionsMenu(menu);
}

if (DEBUG) Log.d(TAG, "[callbackPrepareOptionsMenu] returning " + result);
if (BuildConfig.DEBUG) Log.d(TAG, "[callbackPrepareOptionsMenu] returning " + result);
return result;
}

Expand All @@ -595,7 +595,7 @@ protected final boolean callbackPrepareOptionsMenu(Menu menu) {
* @return {@code true} if the item selection was handled in the callback.
*/
protected final boolean callbackOptionsItemSelected(MenuItem item) {
if (DEBUG) Log.d(TAG, "[callbackOptionsItemSelected] item: " + item.getTitleCondensed());
if (BuildConfig.DEBUG) Log.d(TAG, "[callbackOptionsItemSelected] item: " + item.getTitleCondensed());

boolean result = false;
if (mActivity instanceof OnMenuItemSelectedListener) {
Expand All @@ -606,7 +606,7 @@ protected final boolean callbackOptionsItemSelected(MenuItem item) {
result = listener.onOptionsItemSelected(item);
}

if (DEBUG) Log.d(TAG, "[callbackOptionsItemSelected] returning " + result);
if (BuildConfig.DEBUG) Log.d(TAG, "[callbackOptionsItemSelected] returning " + result);
return result;
}

Expand Down Expand Up @@ -666,7 +666,7 @@ protected final boolean callbackOptionsItemSelected(MenuItem item) {
* @param view The desired content to display.
*/
public void setContentView(View view) {
if (DEBUG) Log.d(TAG, "[setContentView] view: " + view);
if (BuildConfig.DEBUG) Log.d(TAG, "[setContentView] view: " + view);

setContentView(view, new ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT));
}
Expand Down Expand Up @@ -698,7 +698,7 @@ public void setContentView(View view) {
* Change the title associated with this activity.
*/
public void setTitle(int resId) {
if (DEBUG) Log.d(TAG, "[setTitle] resId: " + resId);
if (BuildConfig.DEBUG) Log.d(TAG, "[setTitle] resId: " + resId);

setTitle(mActivity.getString(resId));
}
Expand Down Expand Up @@ -767,7 +767,7 @@ public void setTitle(int resId) {
* @return Menu inflater instance.
*/
public MenuInflater getMenuInflater() {
if (DEBUG) Log.d(TAG, "[getMenuInflater]");
if (BuildConfig.DEBUG) Log.d(TAG, "[getMenuInflater]");

// Make sure that action views can get an appropriate theme.
if (mMenuInflater == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import com.actionbarsherlock.ActionBarSherlock;
import com.actionbarsherlock.BuildConfig;
import com.actionbarsherlock.view.ActionMode;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
Expand All @@ -19,7 +20,6 @@

/** @see {@link android.support.v4.app.Watson} */
public class SherlockFragmentActivity extends Watson implements OnActionModeStartedListener, OnActionModeFinishedListener {
private static final boolean DEBUG = false;
private static final String TAG = "SherlockFragmentActivity";

private ActionBarSherlock mSherlock;
Expand Down Expand Up @@ -139,33 +139,33 @@ protected void onRestoreInstanceState(Bundle savedInstanceState) {
///////////////////////////////////////////////////////////////////////////

public MenuInflater getSupportMenuInflater() {
if (DEBUG) Log.d(TAG, "[getSupportMenuInflater]");
if (BuildConfig.DEBUG) Log.d(TAG, "[getSupportMenuInflater]");

return getSherlock().getMenuInflater();
}

public void invalidateOptionsMenu() {
if (DEBUG) Log.d(TAG, "[invalidateOptionsMenu]");
if (BuildConfig.DEBUG) Log.d(TAG, "[invalidateOptionsMenu]");

getSherlock().dispatchInvalidateOptionsMenu();
}

public void supportInvalidateOptionsMenu() {
if (DEBUG) Log.d(TAG, "[supportInvalidateOptionsMenu]");
if (BuildConfig.DEBUG) Log.d(TAG, "[supportInvalidateOptionsMenu]");

invalidateOptionsMenu();
}

@Override
public final boolean onCreatePanelMenu(int featureId, android.view.Menu menu) {
if (DEBUG) Log.d(TAG, "[onCreatePanelMenu] featureId: " + featureId + ", menu: " + menu);
if (BuildConfig.DEBUG) Log.d(TAG, "[onCreatePanelMenu] featureId: " + featureId + ", menu: " + menu);

if (featureId == Window.FEATURE_OPTIONS_PANEL && !mIgnoreNativeCreate) {
mIgnoreNativeCreate = true;
boolean result = getSherlock().dispatchCreateOptionsMenu(menu);
mIgnoreNativeCreate = false;

if (DEBUG) Log.d(TAG, "[onCreatePanelMenu] returning " + result);
if (BuildConfig.DEBUG) Log.d(TAG, "[onCreatePanelMenu] returning " + result);
return result;
}
return super.onCreatePanelMenu(featureId, menu);
Expand All @@ -178,14 +178,14 @@ public final boolean onCreateOptionsMenu(android.view.Menu menu) {

@Override
public final boolean onPreparePanel(int featureId, View view, android.view.Menu menu) {
if (DEBUG) Log.d(TAG, "[onPreparePanel] featureId: " + featureId + ", view: " + view + ", menu: " + menu);
if (BuildConfig.DEBUG) Log.d(TAG, "[onPreparePanel] featureId: " + featureId + ", view: " + view + ", menu: " + menu);

if (featureId == Window.FEATURE_OPTIONS_PANEL && !mIgnoreNativePrepare) {
mIgnoreNativePrepare = true;
boolean result = getSherlock().dispatchPrepareOptionsMenu(menu);
mIgnoreNativePrepare = false;

if (DEBUG) Log.d(TAG, "[onPreparePanel] returning " + result);
if (BuildConfig.DEBUG) Log.d(TAG, "[onPreparePanel] returning " + result);
return result;
}
return super.onPreparePanel(featureId, view, menu);
Expand All @@ -198,14 +198,14 @@ public final boolean onPrepareOptionsMenu(android.view.Menu menu) {

@Override
public final boolean onMenuItemSelected(int featureId, android.view.MenuItem item) {
if (DEBUG) Log.d(TAG, "[onMenuItemSelected] featureId: " + featureId + ", item: " + item);
if (BuildConfig.DEBUG) Log.d(TAG, "[onMenuItemSelected] featureId: " + featureId + ", item: " + item);

if (featureId == Window.FEATURE_OPTIONS_PANEL && !mIgnoreNativeSelected) {
mIgnoreNativeSelected = true;
boolean result = getSherlock().dispatchOptionsItemSelected(item);
mIgnoreNativeSelected = false;

if (DEBUG) Log.d(TAG, "[onMenuItemSelected] returning " + result);
if (BuildConfig.DEBUG) Log.d(TAG, "[onMenuItemSelected] returning " + result);
return result;
}
return super.onMenuItemSelected(featureId, item);
Expand Down
Loading

0 comments on commit 145431d

Please sign in to comment.