Android Open Source - patchfield Patchfield Activity






From Project

Back to project page patchfield.

License

The source code is released under:

Apache License

If you think the Android project patchfield listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Copyright 2013 Google Inc. All Rights Reserved.
 * //  w  w w  . j  av a 2  s  .co m
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */

package com.noisepages.nettoyeur.patchfield;

import android.app.Activity;
import android.app.Notification;
import android.app.PendingIntent.CanceledException;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
import android.view.KeyEvent;

/**
 * This convenience class encapsulates two common features of activities that use Patchfield, the
 * connection to the Patchfield service and navigation to a control activity via a long press on
 * the back button.
 */
public abstract class PatchfieldActivity extends Activity {

  protected IPatchfieldService patchfield = null;

  private ServiceConnection connection = new ServiceConnection() {
    @Override
    public void onServiceDisconnected(ComponentName name) {
      patchfield = null;
      onPatchfieldDisconnected();
    }

    @Override
    public void onServiceConnected(ComponentName name, IBinder service) {
      patchfield = IPatchfieldService.Stub.asInterface(service);
      onPatchfieldConnected();
    }
  };

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    bindService(new Intent("IPatchfieldService"), connection, Context.BIND_AUTO_CREATE);
  }

  protected abstract void onPatchfieldConnected();

  protected abstract void onPatchfieldDisconnected();

  /**
   * When overriding the onDestroy method, make sure to invoke this parent method _at the end_.
   */
  @Override
  protected void onDestroy() {
    unbindService(connection);
    patchfield = null;
    super.onDestroy();
  }
  
  @Override
  public boolean onKeyLongPress(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && patchfield != null) {
      try {
        Notification notification = patchfield.getNotification(null);
        if (notification != null) {
          notification.contentIntent.send();
          return true;
        }
      } catch (RemoteException e) {
        // Do nothing.
      } catch (CanceledException e) {
        // Do nothing.
      }
    }
    return super.onKeyLongPress(keyCode, event);
  }
}




Java Source Code List

com.noisepages.nettoyeur.patchfield.AudioModule.java
com.noisepages.nettoyeur.patchfield.PatchfieldActivity.java
com.noisepages.nettoyeur.patchfield.PatchfieldException.java
com.noisepages.nettoyeur.patchfield.Patchfield.java
com.noisepages.nettoyeur.patchfield.control.ControlActivity.java
com.noisepages.nettoyeur.patchfield.control.PatchView.java
com.noisepages.nettoyeur.patchfield.internal.OpenSlParams.java
com.noisepages.nettoyeur.patchfield.internal.SharedMemoryUtils.java
com.noisepages.nettoyeur.patchfield.lowpass.LowpassActivity.java
com.noisepages.nettoyeur.patchfield.lowpass.LowpassModule.java
com.noisepages.nettoyeur.patchfield.pd.PdModule.java
com.noisepages.nettoyeur.patchfield.service.PatchfieldService.java
com.noisepages.nettoyeur.patchfield.source.PcmActivity.java
com.noisepages.nettoyeur.patchfield.source.PcmSource.java