ListMenuPresenter.java 7.64 KB
package android.support.v7.view.menu;

import android.content.Context;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.annotation.RestrictTo;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AlertDialog.Builder;
import android.support.v7.appcompat.R.layout;
import android.util.SparseArray;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager.LayoutParams;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.ListAdapter;
import fu;
import java.util.ArrayList;

@RestrictTo({android.support.annotation.RestrictTo.Scope.LIBRARY_GROUP})
public class ListMenuPresenter
  implements MenuPresenter, AdapterView.OnItemClickListener
{
  public static final String VIEWS_TAG = "android:menu:list";
  Context a;
  LayoutInflater b;
  MenuBuilder c;
  ExpandedMenuView d;
  int e;
  int f;
  int g;
  a h;
  private MenuPresenter.Callback i;
  private int j;
  
  public ListMenuPresenter(int paramInt1, int paramInt2)
  {
    this.g = paramInt1;
    this.f = paramInt2;
  }
  
  public ListMenuPresenter(Context paramContext, int paramInt)
  {
    this(paramInt, 0);
    this.a = paramContext;
    this.b = LayoutInflater.from(this.a);
  }
  
  public boolean collapseItemActionView(MenuBuilder paramMenuBuilder, MenuItemImpl paramMenuItemImpl)
  {
    return false;
  }
  
  public boolean expandItemActionView(MenuBuilder paramMenuBuilder, MenuItemImpl paramMenuItemImpl)
  {
    return false;
  }
  
  public boolean flagActionItems()
  {
    return false;
  }
  
  public ListAdapter getAdapter()
  {
    if (this.h == null) {
      this.h = new a();
    }
    return this.h;
  }
  
  public int getId()
  {
    return this.j;
  }
  
  public MenuView getMenuView(ViewGroup paramViewGroup)
  {
    if (this.d == null)
    {
      this.d = ((ExpandedMenuView)this.b.inflate(R.layout.abc_expanded_menu_layout, paramViewGroup, false));
      if (this.h == null) {
        this.h = new a();
      }
      this.d.setAdapter(this.h);
      this.d.setOnItemClickListener(this);
    }
    return this.d;
  }
  
  public void initForMenu(Context paramContext, MenuBuilder paramMenuBuilder)
  {
    if (this.f != 0)
    {
      this.a = new ContextThemeWrapper(paramContext, this.f);
      this.b = LayoutInflater.from(this.a);
    }
    for (;;)
    {
      this.c = paramMenuBuilder;
      if (this.h != null) {
        this.h.notifyDataSetChanged();
      }
      return;
      if (this.a != null)
      {
        this.a = paramContext;
        if (this.b == null) {
          this.b = LayoutInflater.from(this.a);
        }
      }
    }
  }
  
  public void onCloseMenu(MenuBuilder paramMenuBuilder, boolean paramBoolean)
  {
    if (this.i != null) {
      this.i.onCloseMenu(paramMenuBuilder, paramBoolean);
    }
  }
  
  public void onItemClick(AdapterView<?> paramAdapterView, View paramView, int paramInt, long paramLong)
  {
    this.c.performItemAction(this.h.a(paramInt), this, 0);
  }
  
  public void onRestoreInstanceState(Parcelable paramParcelable)
  {
    restoreHierarchyState((Bundle)paramParcelable);
  }
  
  public Parcelable onSaveInstanceState()
  {
    if (this.d == null) {
      return null;
    }
    Bundle localBundle = new Bundle();
    saveHierarchyState(localBundle);
    return localBundle;
  }
  
  public boolean onSubMenuSelected(SubMenuBuilder paramSubMenuBuilder)
  {
    if (!paramSubMenuBuilder.hasVisibleItems()) {
      return false;
    }
    fu localfu = new fu(paramSubMenuBuilder);
    Object localObject = localfu.a;
    AlertDialog.Builder localBuilder = new AlertDialog.Builder(((MenuBuilder)localObject).getContext());
    localfu.c = new ListMenuPresenter(localBuilder.getContext(), R.layout.abc_list_menu_item_layout);
    localfu.c.setCallback(localfu);
    localfu.a.addMenuPresenter(localfu.c);
    localBuilder.setAdapter(localfu.c.getAdapter(), localfu);
    View localView = ((MenuBuilder)localObject).getHeaderView();
    if (localView != null) {
      localBuilder.setCustomTitle(localView);
    }
    for (;;)
    {
      localBuilder.setOnKeyListener(localfu);
      localfu.b = localBuilder.create();
      localfu.b.setOnDismissListener(localfu);
      localObject = localfu.b.getWindow().getAttributes();
      ((WindowManager.LayoutParams)localObject).type = 1003;
      ((WindowManager.LayoutParams)localObject).flags |= 0x20000;
      localfu.b.show();
      if (this.i != null) {
        this.i.onOpenSubMenu(paramSubMenuBuilder);
      }
      return true;
      localBuilder.setIcon(((MenuBuilder)localObject).getHeaderIcon()).setTitle(((MenuBuilder)localObject).getHeaderTitle());
    }
  }
  
  public void restoreHierarchyState(Bundle paramBundle)
  {
    paramBundle = paramBundle.getSparseParcelableArray("android:menu:list");
    if (paramBundle != null) {
      this.d.restoreHierarchyState(paramBundle);
    }
  }
  
  public void saveHierarchyState(Bundle paramBundle)
  {
    SparseArray localSparseArray = new SparseArray();
    if (this.d != null) {
      this.d.saveHierarchyState(localSparseArray);
    }
    paramBundle.putSparseParcelableArray("android:menu:list", localSparseArray);
  }
  
  public void setCallback(MenuPresenter.Callback paramCallback)
  {
    this.i = paramCallback;
  }
  
  public void setId(int paramInt)
  {
    this.j = paramInt;
  }
  
  public void setItemIndexOffset(int paramInt)
  {
    this.e = paramInt;
    if (this.d != null) {
      updateMenuView(false);
    }
  }
  
  public void updateMenuView(boolean paramBoolean)
  {
    if (this.h != null) {
      this.h.notifyDataSetChanged();
    }
  }
  
  final class a
    extends BaseAdapter
  {
    private int b = -1;
    
    public a()
    {
      a();
    }
    
    private void a()
    {
      MenuItemImpl localMenuItemImpl = ListMenuPresenter.this.c.getExpandedItem();
      if (localMenuItemImpl != null)
      {
        ArrayList localArrayList = ListMenuPresenter.this.c.getNonActionItems();
        int j = localArrayList.size();
        int i = 0;
        while (i < j)
        {
          if ((MenuItemImpl)localArrayList.get(i) == localMenuItemImpl)
          {
            this.b = i;
            return;
          }
          i += 1;
        }
      }
      this.b = -1;
    }
    
    public final MenuItemImpl a(int paramInt)
    {
      ArrayList localArrayList = ListMenuPresenter.this.c.getNonActionItems();
      int i = ListMenuPresenter.this.e + paramInt;
      paramInt = i;
      if (this.b >= 0)
      {
        paramInt = i;
        if (i >= this.b) {
          paramInt = i + 1;
        }
      }
      return (MenuItemImpl)localArrayList.get(paramInt);
    }
    
    public final int getCount()
    {
      int i = ListMenuPresenter.this.c.getNonActionItems().size() - ListMenuPresenter.this.e;
      if (this.b < 0) {
        return i;
      }
      return i - 1;
    }
    
    public final long getItemId(int paramInt)
    {
      return paramInt;
    }
    
    public final View getView(int paramInt, View paramView, ViewGroup paramViewGroup)
    {
      if (paramView == null) {
        paramView = ListMenuPresenter.this.b.inflate(ListMenuPresenter.this.g, paramViewGroup, false);
      }
      for (;;)
      {
        ((MenuView.ItemView)paramView).initialize(a(paramInt), 0);
        return paramView;
      }
    }
    
    public final void notifyDataSetChanged()
    {
      a();
      super.notifyDataSetChanged();
    }
  }
}


/* Location:              /home/merong/decompile/hackery-dex2jar.jar!/android/support/v7/view/menu/ListMenuPresenter.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */