[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Menu Drawer Item refactor #1

Merged
merged 4 commits into from
Apr 10, 2013
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Re-implementing all the menu items with the improved MenuDrawerItem c…
…lass
  • Loading branch information
Robert Collins committed Apr 10, 2013
commit e25a4ae82a2ac0d91a2b42008b35a3808b5a9654
47 changes: 35 additions & 12 deletions src/org/wordpress/android/ui/MenuDrawerItem.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,38 @@
/**
* Represents a single item in the WPActionBarActivity's menu drawer. A MenuDrawerItem determines
* the label and icon to use in the menu, its presence in the menu, its selection state, and the
* action that happens when the item is selected.
*/
package org.wordpress.android.ui;

import android.view.View;
import android.content.Intent;

abstract class MenuDrawerItem {
/**
* Signifies that the item has no unique ID so should not be tracked in the last selected
* item preference.
*/
public static int NO_ITEM_ID = -1;

/**
* When menu item is selected this method is called. Returns the intent that will be started.
* Called when the menu item is selected.
*/
abstract public Intent onSelectItem();
abstract public void onSelectItem();
/**
* Determines if the menu item should be displayed in the menu
* Determines if the menu item should be displayed in the menu. Default is always true.
*/
public Boolean isVisible(){
return true;
};
/**
* Determines if the item
* Determines if the item is selected. Default is always false.
*/
public Boolean isSelected(){
return false;
}
/**
* Method to allow the menu item to provide additional configuration to the view
* Method to allow the menu item to provide additional configuration to the view, default
* implementation does nothing.
*/
public void onConfigureView(View view){};

Expand All @@ -48,30 +57,44 @@ public Boolean isSelected(){
MenuDrawerItem(int stringRes, int iconRes){
this(NO_ITEM_ID, stringRes, iconRes);
}
/**
* Determines if the item has an id for remembering the last selected item
*/
public boolean hasItemId(){
return getItemId() != NO_ITEM_ID;
}
/**
* Get's the item's unique ID
*/
public int getItemId(){
return mItemId;
}
/**
* Returns the item's string representation (used by ArrayAdapter.getView)
*/
public String toString(){
return "";
}

/**
* The resource id to use for the menu item's title
*/
public int getTitleRes(){
return mTitle;
}

/**
* The resource id to use for the menu item's icon
*/
public int getIconRes(){
return mIconRes;
}

public Intent selectItem(){
return onSelectItem();
public void selectItem(){
onSelectItem();
}

/**
* Allows the menu item to do additional manipulation to the view
*/
public void configureView(View v){
// By default do nothing
onConfigureView(v);
}

Expand Down
Loading