Android Open Source - VisEQ Host Sound Visualization Activity






From Project

Back to project page VisEQ.

License

The source code is released under:

Copyright (c) 2012, Spotify AB All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:...

If you think the Android project VisEQ 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.lsu.vizeq;
/*  ww  w .j a v  a  2  s.  co m*/
import android.app.Activity;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.view.Gravity;
import android.view.Menu;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ToggleButton;

public class HostSoundVisualizationActivity extends Activity {
  
  private VisualizerView vizView;
  private static int saveSlider = 0;

  public static boolean dirty = false;
  public static boolean flash = false;
  public static String[] data = new String[VisualizerView.NUM_BANDS];
  
  AsyncTask<Void,String,String> my_task;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    
    dirty = false;
    data = new String[VisualizerView.NUM_BANDS];
    
    requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
                                WindowManager.LayoutParams.FLAG_FULLSCREEN);
    
    setContentView(R.layout.activity_host_sound_visualization);
    
    my_task = new AsyncTask<Void,String,String>() {
      int flashTime = 0;
      @Override
      protected String doInBackground(Void... params) {
        while (!isCancelled()) {
          try {
            Thread.sleep(20);
          }
          catch (InterruptedException e) {
            e.printStackTrace();
          }
          if (dirty) {
            vizView.SetCircleStates(data);
            dirty = false;
          }
          if (flash)
          {
            vizView.flash = true;
            flash = false;
          }
          //if (flashTime == 1)
            //vizView.flash = false;
          
          //flashTime = ++flashTime % 2;
        }
        return "hostsoundvisualization asynctask canceled";
      }
    };
    
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
        my_task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void[])null);
    else
        my_task.execute((Void[])null);
    
    vizView = (VisualizerView)findViewById(R.id.visualizer);
    
    
    
    vizView.init(this, true);
    
    LinearLayout controls = new LinearLayout(this);
    controls.setOrientation(LinearLayout.VERTICAL);
    controls.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
    LinearLayout text = new LinearLayout(this);
    text.setOrientation(LinearLayout.HORIZONTAL);
    text.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
    LinearLayout text2 = new LinearLayout(this);
    text2.setOrientation(LinearLayout.HORIZONTAL);
    text2.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, 1));
    LinearLayout text3 = new LinearLayout(this);
    text3.setOrientation(LinearLayout.HORIZONTAL);
    text3.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, 1));
    SeekBar freqSlider = new SeekBar(this);
    RelativeLayout.LayoutParams params =  new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    params.setMargins(3,3,3,3);
    freqSlider.setLayoutParams(params);
    freqSlider.setMax(PlayerActivity.NUM_FLASH_BANDS - 1);
    freqSlider.setProgress(saveSlider);
    TextView lowText = new TextView(this);
    lowText.setText("Bass drum");
    TextView highText = new TextView(this);
    highText.setText("Hi-hat");
    //lowText.setGravity(Gravity.LEFT);
    //highText.setGravity(Gravity.RIGHT);
    text2.setGravity(Gravity.LEFT);
    text3.setGravity(Gravity.RIGHT);
    lowText.setTextColor(Color.WHITE);
    highText.setTextColor(Color.WHITE);
    Typeface font = Typeface.createFromAsset(getAssets(), "Mission Gothic Light.otf");
    lowText.setTypeface(font);
    highText.setTypeface(font);
    text2.addView(lowText);
    text3.addView(highText);
    controls.addView(freqSlider);
    text.addView(text2);
    text.addView(text3);
    controls.addView(text);
    
    ToggleButton tog = (ToggleButton)findViewById(R.id.taptoflash);
    tog.setChecked(!MyApplication.tapToFlash);
    tog.setTextOff("Auto");
    tog.setTextOn("Auto");
    tog.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

      @Override
      public void onCheckedChanged(CompoundButton buttonView,
          boolean isChecked) {
        if (isChecked) {
          MyApplication.tapToFlash = false;
        }
        else {
          MyApplication.tapToFlash = true;
          Toast.makeText(HostSoundVisualizationActivity.this, "You've got the lights!  Tap anywhere to flash all party lights.", Toast.LENGTH_SHORT).show();
        }
      }
      
    });
    ((ViewGroup) findViewById(R.id.host_viz_daddy)).addView(controls);
    
freqSlider.setOnSeekBarChangeListener(new OnSeekBarChangeListener(){
      
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                PlayerActivity.BAND_TO_FLASH = progress;
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {;
                
               
               // dialog.show();
            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                // TODO Auto-generated method stub
              saveSlider = PlayerActivity.BAND_TO_FLASH;
            }

        });

  }

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.host_sound_visualization, menu);
    return true;
  }
  
  @Override
  public void onDestroy() {
    super.onDestroy();
    my_task.cancel(true);
    if (VisualizerView.cam != null) VisualizerView.cam.release();
    VisualizerView.cam = null;
  }

  
  
}




Java Source Code List

com.lsu.vizeq.AboutActivity.java
com.lsu.vizeq.Artist.java
com.lsu.vizeq.BackableActivity.java
com.lsu.vizeq.HostActivity.java
com.lsu.vizeq.HostMenuActivity.java
com.lsu.vizeq.HostProfileActivity.java
com.lsu.vizeq.HostSoundVisualizationActivity.java
com.lsu.vizeq.Installation.java
com.lsu.vizeq.LibSpotifyWrapper.java
com.lsu.vizeq.LoginActivity.java
com.lsu.vizeq.MyApplication.java
com.lsu.vizeq.MyCanvas.java
com.lsu.vizeq.PVCircle.java
com.lsu.vizeq.PacketParser.java
com.lsu.vizeq.PlayerActivity.java
com.lsu.vizeq.PreferenceCircle.java
com.lsu.vizeq.PreferenceVisualizationActivity.java
com.lsu.vizeq.PreferenceVisualizer.java
com.lsu.vizeq.ProfileActivity.java
com.lsu.vizeq.RemoteControlReceiver.java
com.lsu.vizeq.RequestDetailsActivity.java
com.lsu.vizeq.RoleActivity.java
com.lsu.vizeq.SearchActivity.java
com.lsu.vizeq.SearchPartyActivity.java
com.lsu.vizeq.ServiceBinder.java
com.lsu.vizeq.SettingsActivity.java
com.lsu.vizeq.SoundVisualizationActivity.java
com.lsu.vizeq.SpotifyService.java
com.lsu.vizeq.TrackRow.java
com.lsu.vizeq.Track.java
com.lsu.vizeq.VisualizerView.java
com.lsu.vizeq.VizEQ.java
com.lsu.vizeq.WebService.java
com.lsu.vizeq.util.SystemPropertiesProxy.java
com.lsu.vizeq.util.SystemUiHiderBase.java
com.lsu.vizeq.util.SystemUiHiderHoneycomb.java
com.lsu.vizeq.util.SystemUiHider.java
com.lsu.vizeq.util.TunnelPlayerWorkaround.java