TransportMediator.java 7.85 KB
package android.support.v4.media;

import android.app.Activity;
import android.content.Context;
import android.media.AudioManager;
import android.media.RemoteControlClient;
import android.os.Build.VERSION;
import android.view.KeyEvent;
import android.view.KeyEvent.Callback;
import android.view.KeyEvent.DispatcherState;
import android.view.View;
import android.view.ViewTreeObserver;
import android.view.Window;
import di;
import dj;
import java.util.ArrayList;

public class TransportMediator
  extends TransportController
{
  public static final int FLAG_KEY_MEDIA_FAST_FORWARD = 64;
  public static final int FLAG_KEY_MEDIA_NEXT = 128;
  public static final int FLAG_KEY_MEDIA_PAUSE = 16;
  public static final int FLAG_KEY_MEDIA_PLAY = 4;
  public static final int FLAG_KEY_MEDIA_PLAY_PAUSE = 8;
  public static final int FLAG_KEY_MEDIA_PREVIOUS = 1;
  public static final int FLAG_KEY_MEDIA_REWIND = 2;
  public static final int FLAG_KEY_MEDIA_STOP = 32;
  public static final int KEYCODE_MEDIA_PAUSE = 127;
  public static final int KEYCODE_MEDIA_PLAY = 126;
  public static final int KEYCODE_MEDIA_RECORD = 130;
  final Context a;
  final TransportPerformer b;
  final AudioManager c;
  final View d;
  final Object e;
  final dj f;
  final ArrayList<TransportStateListener> g = new ArrayList();
  final di h = new di()
  {
    public final long a()
    {
      return TransportMediator.this.b.onGetCurrentPosition();
    }
    
    public final void a(int paramAnonymousInt)
    {
      TransportMediator.this.b.onAudioFocusChange(paramAnonymousInt);
    }
    
    public final void a(long paramAnonymousLong)
    {
      TransportMediator.this.b.onSeekTo(paramAnonymousLong);
    }
    
    public final void a(KeyEvent paramAnonymousKeyEvent)
    {
      paramAnonymousKeyEvent.dispatch(TransportMediator.this.i);
    }
  };
  final KeyEvent.Callback i = new KeyEvent.Callback()
  {
    public final boolean onKeyDown(int paramAnonymousInt, KeyEvent paramAnonymousKeyEvent)
    {
      if (TransportMediator.a(paramAnonymousInt)) {
        return TransportMediator.this.b.onMediaButtonDown(paramAnonymousInt, paramAnonymousKeyEvent);
      }
      return false;
    }
    
    public final boolean onKeyLongPress(int paramAnonymousInt, KeyEvent paramAnonymousKeyEvent)
    {
      return false;
    }
    
    public final boolean onKeyMultiple(int paramAnonymousInt1, int paramAnonymousInt2, KeyEvent paramAnonymousKeyEvent)
    {
      return false;
    }
    
    public final boolean onKeyUp(int paramAnonymousInt, KeyEvent paramAnonymousKeyEvent)
    {
      if (TransportMediator.a(paramAnonymousInt)) {
        return TransportMediator.this.b.onMediaButtonUp(paramAnonymousInt, paramAnonymousKeyEvent);
      }
      return false;
    }
  };
  
  public TransportMediator(Activity paramActivity, TransportPerformer paramTransportPerformer)
  {
    this(paramActivity, null, paramTransportPerformer);
  }
  
  private TransportMediator(Activity paramActivity, View paramView, TransportPerformer paramTransportPerformer)
  {
    if (paramActivity != null) {}
    for (Object localObject = paramActivity;; localObject = paramView.getContext())
    {
      this.a = ((Context)localObject);
      this.b = paramTransportPerformer;
      this.c = ((AudioManager)this.a.getSystemService("audio"));
      if (paramActivity != null) {
        paramView = paramActivity.getWindow().getDecorView();
      }
      this.d = paramView;
      this.e = this.d.getKeyDispatcherState();
      if (Build.VERSION.SDK_INT < 18) {
        break;
      }
      this.f = new dj(this.a, this.c, this.d, this.h);
      return;
    }
    this.f = null;
  }
  
  public TransportMediator(View paramView, TransportPerformer paramTransportPerformer)
  {
    this(null, paramView, paramTransportPerformer);
  }
  
  static boolean a(int paramInt)
  {
    switch (paramInt)
    {
    default: 
      return false;
    }
    return true;
  }
  
  private TransportStateListener[] a()
  {
    if (this.g.size() <= 0) {
      return null;
    }
    TransportStateListener[] arrayOfTransportStateListener = new TransportStateListener[this.g.size()];
    this.g.toArray(arrayOfTransportStateListener);
    return arrayOfTransportStateListener;
  }
  
  private void b()
  {
    TransportStateListener[] arrayOfTransportStateListener = a();
    if (arrayOfTransportStateListener != null)
    {
      int k = arrayOfTransportStateListener.length;
      int j = 0;
      while (j < k)
      {
        arrayOfTransportStateListener[j].onPlayingChanged(this);
        j += 1;
      }
    }
  }
  
  private void c()
  {
    dj localdj;
    long l;
    int k;
    RemoteControlClient localRemoteControlClient;
    int j;
    if (this.f != null)
    {
      localdj = this.f;
      boolean bool = this.b.onIsPlaying();
      l = this.b.onGetCurrentPosition();
      k = this.b.onGetTransportControlFlags();
      if (localdj.o != null)
      {
        localRemoteControlClient = localdj.o;
        if (!bool) {
          break label87;
        }
        j = 3;
        if (!bool) {
          break label92;
        }
      }
    }
    label87:
    label92:
    for (float f1 = 1.0F;; f1 = 0.0F)
    {
      localRemoteControlClient.setPlaybackState(j, l, f1);
      localdj.o.setTransportControlFlags(k);
      return;
      j = 1;
      break;
    }
  }
  
  public void destroy()
  {
    dj localdj = this.f;
    localdj.d();
    localdj.c.getViewTreeObserver().removeOnWindowAttachListener(localdj.h);
    localdj.c.getViewTreeObserver().removeOnWindowFocusChangeListener(localdj.i);
  }
  
  public boolean dispatchKeyEvent(KeyEvent paramKeyEvent)
  {
    return paramKeyEvent.dispatch(this.i, (KeyEvent.DispatcherState)this.e, this);
  }
  
  public int getBufferPercentage()
  {
    return this.b.onGetBufferPercentage();
  }
  
  public long getCurrentPosition()
  {
    return this.b.onGetCurrentPosition();
  }
  
  public long getDuration()
  {
    return this.b.onGetDuration();
  }
  
  public Object getRemoteControlClient()
  {
    if (this.f != null) {
      return this.f.o;
    }
    return null;
  }
  
  public int getTransportControlFlags()
  {
    return this.b.onGetTransportControlFlags();
  }
  
  public boolean isPlaying()
  {
    return this.b.onIsPlaying();
  }
  
  public void pausePlaying()
  {
    if (this.f != null)
    {
      dj localdj = this.f;
      if (localdj.q == 3)
      {
        localdj.q = 2;
        localdj.o.setPlaybackState(2);
      }
      localdj.b();
    }
    this.b.onPause();
    c();
    b();
  }
  
  public void refreshState()
  {
    c();
    b();
    TransportStateListener[] arrayOfTransportStateListener = a();
    if (arrayOfTransportStateListener != null)
    {
      int k = arrayOfTransportStateListener.length;
      int j = 0;
      while (j < k)
      {
        arrayOfTransportStateListener[j].onTransportControlsChanged(this);
        j += 1;
      }
    }
  }
  
  public void registerStateListener(TransportStateListener paramTransportStateListener)
  {
    this.g.add(paramTransportStateListener);
  }
  
  public void seekTo(long paramLong)
  {
    this.b.onSeekTo(paramLong);
  }
  
  public void startPlaying()
  {
    if (this.f != null)
    {
      dj localdj = this.f;
      if (localdj.q != 3)
      {
        localdj.q = 3;
        localdj.o.setPlaybackState(3);
      }
      if (localdj.p) {
        localdj.a();
      }
    }
    this.b.onStart();
    c();
    b();
  }
  
  public void stopPlaying()
  {
    if (this.f != null)
    {
      dj localdj = this.f;
      if (localdj.q != 1)
      {
        localdj.q = 1;
        localdj.o.setPlaybackState(1);
      }
      localdj.b();
    }
    this.b.onStop();
    c();
    b();
  }
  
  public void unregisterStateListener(TransportStateListener paramTransportStateListener)
  {
    this.g.remove(paramTransportStateListener);
  }
}


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