TaskStackBuilder.java 6.5 KB
package android.support.v4.app;

import android.app.Activity;
import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Build.VERSION;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import java.util.ArrayList;
import java.util.Iterator;

public final class TaskStackBuilder
  implements Iterable<Intent>
{
  private static final a a = new b();
  private final ArrayList<Intent> b = new ArrayList();
  private final Context c;
  
  static
  {
    if (Build.VERSION.SDK_INT >= 11)
    {
      a = new c();
      return;
    }
  }
  
  private TaskStackBuilder(Context paramContext)
  {
    this.c = paramContext;
  }
  
  public static TaskStackBuilder create(Context paramContext)
  {
    return new TaskStackBuilder(paramContext);
  }
  
  @Deprecated
  public static TaskStackBuilder from(Context paramContext)
  {
    return create(paramContext);
  }
  
  public final TaskStackBuilder addNextIntent(Intent paramIntent)
  {
    this.b.add(paramIntent);
    return this;
  }
  
  public final TaskStackBuilder addNextIntentWithParentStack(Intent paramIntent)
  {
    ComponentName localComponentName2 = paramIntent.getComponent();
    ComponentName localComponentName1 = localComponentName2;
    if (localComponentName2 == null) {
      localComponentName1 = paramIntent.resolveActivity(this.c.getPackageManager());
    }
    if (localComponentName1 != null) {
      addParentStack(localComponentName1);
    }
    addNextIntent(paramIntent);
    return this;
  }
  
  public final TaskStackBuilder addParentStack(Activity paramActivity)
  {
    Object localObject = null;
    if ((paramActivity instanceof SupportParentable)) {
      localObject = ((SupportParentable)paramActivity).getSupportParentActivityIntent();
    }
    if (localObject == null) {}
    for (paramActivity = NavUtils.getParentActivityIntent(paramActivity);; paramActivity = (Activity)localObject)
    {
      if (paramActivity != null)
      {
        ComponentName localComponentName = paramActivity.getComponent();
        localObject = localComponentName;
        if (localComponentName == null) {
          localObject = paramActivity.resolveActivity(this.c.getPackageManager());
        }
        addParentStack((ComponentName)localObject);
        addNextIntent(paramActivity);
      }
      return this;
    }
  }
  
  public final TaskStackBuilder addParentStack(ComponentName paramComponentName)
  {
    int i = this.b.size();
    try
    {
      for (paramComponentName = NavUtils.getParentActivityIntent(this.c, paramComponentName); paramComponentName != null; paramComponentName = NavUtils.getParentActivityIntent(this.c, paramComponentName.getComponent())) {
        this.b.add(i, paramComponentName);
      }
      return this;
    }
    catch (PackageManager.NameNotFoundException paramComponentName)
    {
      Log.e("TaskStackBuilder", "Bad ComponentName while traversing activity parent metadata");
      throw new IllegalArgumentException(paramComponentName);
    }
  }
  
  public final TaskStackBuilder addParentStack(Class<?> paramClass)
  {
    return addParentStack(new ComponentName(this.c, paramClass));
  }
  
  public final Intent editIntentAt(int paramInt)
  {
    return (Intent)this.b.get(paramInt);
  }
  
  @Deprecated
  public final Intent getIntent(int paramInt)
  {
    return editIntentAt(paramInt);
  }
  
  public final int getIntentCount()
  {
    return this.b.size();
  }
  
  public final Intent[] getIntents()
  {
    Intent[] arrayOfIntent = new Intent[this.b.size()];
    if (arrayOfIntent.length == 0) {
      return arrayOfIntent;
    }
    arrayOfIntent[0] = new Intent((Intent)this.b.get(0)).addFlags(268484608);
    int i = 1;
    while (i < arrayOfIntent.length)
    {
      arrayOfIntent[i] = new Intent((Intent)this.b.get(i));
      i += 1;
    }
    return arrayOfIntent;
  }
  
  public final PendingIntent getPendingIntent(int paramInt1, int paramInt2)
  {
    return getPendingIntent(paramInt1, paramInt2, null);
  }
  
  public final PendingIntent getPendingIntent(int paramInt1, int paramInt2, Bundle paramBundle)
  {
    if (this.b.isEmpty()) {
      throw new IllegalStateException("No intents added to TaskStackBuilder; cannot getPendingIntent");
    }
    paramBundle = (Intent[])this.b.toArray(new Intent[this.b.size()]);
    paramBundle[0] = new Intent(paramBundle[0]).addFlags(268484608);
    return a.a(this.c, paramBundle, paramInt1, paramInt2);
  }
  
  @Deprecated
  public final Iterator<Intent> iterator()
  {
    return this.b.iterator();
  }
  
  public final void startActivities()
  {
    startActivities(null);
  }
  
  public final void startActivities(Bundle paramBundle)
  {
    if (this.b.isEmpty()) {
      throw new IllegalStateException("No intents added to TaskStackBuilder; cannot startActivities");
    }
    Intent[] arrayOfIntent = (Intent[])this.b.toArray(new Intent[this.b.size()]);
    arrayOfIntent[0] = new Intent(arrayOfIntent[0]).addFlags(268484608);
    if (!ContextCompat.startActivities(this.c, arrayOfIntent, paramBundle))
    {
      paramBundle = new Intent(arrayOfIntent[(arrayOfIntent.length - 1)]);
      paramBundle.addFlags(268435456);
      this.c.startActivity(paramBundle);
    }
  }
  
  public static abstract interface SupportParentable
  {
    public abstract Intent getSupportParentActivityIntent();
  }
  
  static abstract interface a
  {
    public abstract PendingIntent a(Context paramContext, Intent[] paramArrayOfIntent, int paramInt1, int paramInt2);
  }
  
  static final class b
    implements TaskStackBuilder.a
  {
    public final PendingIntent a(Context paramContext, Intent[] paramArrayOfIntent, int paramInt1, int paramInt2)
    {
      paramArrayOfIntent = new Intent(paramArrayOfIntent[(paramArrayOfIntent.length - 1)]);
      paramArrayOfIntent.addFlags(268435456);
      return PendingIntent.getActivity(paramContext, paramInt1, paramArrayOfIntent, paramInt2);
    }
  }
  
  static final class c
    implements TaskStackBuilder.a
  {
    public final PendingIntent a(Context paramContext, Intent[] paramArrayOfIntent, int paramInt1, int paramInt2)
    {
      paramArrayOfIntent[0] = new Intent(paramArrayOfIntent[0]).addFlags(268484608);
      return PendingIntent.getActivities(paramContext, paramInt1, paramArrayOfIntent, paramInt2);
    }
  }
}


/* Location:              /home/merong/decompile/hackery-dex2jar.jar!/android/support/v4/app/TaskStackBuilder.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */