All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.solovyev.android.menu.MenuItemWrapper Maven / Gradle / Ivy

There is a newer version: 1.1.18
Show newest version
package org.solovyev.android.menu;

import android.app.Activity;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
* User: serso
* Date: 8/13/12
* Time: 4:24 PM
*/
class MenuItemWrapper {

    @Nullable
    private final LabeledMenuItem labeledMenuItem;

    @Nullable
    private Integer menuItemId;

    @Nullable
    private final IdentifiableMenuItem identifiableMenuItem;

    MenuItemWrapper(@NotNull LabeledMenuItem labeledMenuItem) {
        this.labeledMenuItem = labeledMenuItem;
        this.identifiableMenuItem = null;
    }

    MenuItemWrapper(@NotNull IdentifiableMenuItem identifiableMenuItem) {
        this.identifiableMenuItem = identifiableMenuItem;
        this.labeledMenuItem = null;
    }

    @NotNull
    public AMenuItem getMenuItem() {
        return labeledMenuItem != null ? labeledMenuItem : identifiableMenuItem;
    }

    @Nullable
    public Integer getMenuItemId() {
        return identifiableMenuItem == null ? menuItemId : identifiableMenuItem.getItemId();
    }

    public void setMenuItemId(@Nullable Integer menuItemId) {
        assert labeledMenuItem != null;
        this.menuItemId = menuItemId;
    }

    @NotNull
    public String getCaption(@NotNull Activity activity) {
        assert labeledMenuItem != null;
        return labeledMenuItem.getCaption(activity);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy