Android Open Source - soundheap Soundheap Context






From Project

Back to project page soundheap.

License

The source code is released under:

Copyright (c) 2014, Nicholas Wertzberger All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are...

If you think the Android project soundheap 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

package com.ideaheap.sound.context;
//from  ww w  .  ja va  2  s  .  c o m
import java.io.File;
import java.util.LinkedList;
import java.util.List;
import android.content.res.Resources;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.ideaheap.sound.R;
import com.ideaheap.sound.control.MainController;
import com.ideaheap.sound.control.PlaybackController;
import com.ideaheap.sound.control.ProjectController;
import com.ideaheap.sound.control.RecordController;
import com.ideaheap.sound.control.TabController;
import com.ideaheap.sound.control.TabListener;
import com.ideaheap.sound.service.AudioPlayService;
import com.ideaheap.sound.service.AudioRecordService;
import com.ideaheap.sound.service.RepositoryService;
import com.ideaheap.sound.ui.PlaybackFragment;
import com.ideaheap.sound.ui.ProjectFragment;
import com.ideaheap.sound.ui.RecordFragment;

/**
 * Instead of using Spring or some other IOC framework, I have decided to
 * experiment with doing all of this wiring myself, as i prefer doing the whole
 * constructor arguments thing, and switching to this context is relatively
 * simple.
 * 
 * @author nwertzberger
 * 
 */
public class SoundheapContext {
  private static SoundheapContext ctx = null;

  // Singletons
  public final AudioRecordService recorder;
  public final AudioPlayService player;
  public final RepositoryService repository;
  
  // Request
  public MainController mainController;
  public RecordController recordController;

  /**
   * This is a Singleton class, so we can initialize singleton scope in the
   * constructor.
   * @param activity
   */
  private SoundheapContext(SherlockFragmentActivity activity) {
    recorder = new AudioRecordService();
    player = new AudioPlayService();

    // Wire up our base repository
    Resources res = activity.getResources();
    String REPOSITORY = res.getString(R.string.repository);
    File repo = new File(REPOSITORY);
    repository = new RepositoryService(repo);
    
  }

  /**
   *  Things that should be re-generated every time the context is
   *  re-initialized
   * @param activity
   */
  private void requestScope(SherlockFragmentActivity activity) {
    List<TabController> tabs = new LinkedList<TabController>();
    
    // Record-tab related builds
    RecordFragment record = new RecordFragment();
    recordController = new RecordController(
      activity,
      new TabListener(record,R.id.fragment_container),
      recorder,
      repository
    );
    tabs.add(recordController);
    
    
    // Playback-tab related builds
    PlaybackFragment playback = new PlaybackFragment();
    tabs.add(new PlaybackController(
      activity,
      new TabListener(playback, R.id.fragment_container)
    ));
    
    // Project-tab related builds
    ProjectFragment projects = new ProjectFragment();
    tabs.add(new ProjectController(
      activity,
      new TabListener(projects, R.id.fragment_container)
    ));
    
    // Build the ui views
    mainController = new MainController(activity, tabs);
  }
  
  public static SoundheapContext generateContext(SherlockFragmentActivity activity) {
    if (ctx == null) {
      ctx = new SoundheapContext(activity);
    }
    ctx.requestScope(activity);
    
    return ctx;
  }
  
  public static SoundheapContext getContext() throws SoundheapException {
    if (ctx == null) {
      throw new SoundheapException("No previous activity tied to this context");
    }
    return ctx;
  }
}




Java Source Code List

com.ideaheap.sound.context.SoundheapContext.java
com.ideaheap.sound.context.SoundheapException.java
com.ideaheap.sound.control.MainController.java
com.ideaheap.sound.control.PlaybackController.java
com.ideaheap.sound.control.ProjectController.java
com.ideaheap.sound.control.RecordController.java
com.ideaheap.sound.control.TabController.java
com.ideaheap.sound.control.TabListener.java
com.ideaheap.sound.service.AudioLevelListener.java
com.ideaheap.sound.service.AudioPlayService.java
com.ideaheap.sound.service.AudioRecordService.java
com.ideaheap.sound.service.AudioUpdateListener.java
com.ideaheap.sound.service.RepositoryService.java
com.ideaheap.sound.ui.PlaybackFragment.java
com.ideaheap.sound.ui.ProjectFragment.java
com.ideaheap.sound.ui.RecordFragment.java
com.ideaheap.sound.ui.SoundheapActivity.java
com.ideaheap.sound.ui.tabs.PlaybackTab.java
com.ideaheap.sound.ui.tabs.ProjectTab.java