Android Open Source - VisEQ Preference 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;
/*from  w  w  w  .j a  v  a2 s.  c om*/
import java.util.ArrayList;
import java.util.List;

import android.app.ActionBar;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.Toast;

public class PreferenceVisualizationActivity extends BackableActivity {

  public MyApplication myapp;
  public PreferenceVisualizer viz;
  private String currentSort = "none";
  private ActionBar actionBar;
  
  @Override
  protected void onStart(){
    super.onStart();
    actionBar = getActionBar();

    SharedPreferences memory = getSharedPreferences("VizEQ",MODE_PRIVATE);
    int posi = memory.getInt("colorPos", -1);
    if (posi > 0) VizEQ.numRand = posi;    
    switch (VizEQ.numRand)
    {
      case 1:
        actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.Red)));
        break;
      case 2:
        actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.Green)));        
        break;
      case 3:
        actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.Blue)));
        break;
      case 4:
        actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.Purple)));        
        break;
      case 5:
        actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.Orange)));
        break;      
    }
    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.setDisplayShowTitleEnabled(true);
  }
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    myapp = (MyApplication) this.getApplicationContext();
    
    setContentView(R.layout.activity_preference_visualization);
    actionBar = getActionBar();
    actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.LightGreen)));
    
    RelativeLayout vizlayout = (RelativeLayout) findViewById(R.id.vizlayout);
    
    int res_x = this.getResources().getDisplayMetrics().widthPixels;
    int res_y = this.getResources().getDisplayMetrics().heightPixels;
    viz = new PreferenceVisualizer(myapp.requests, res_x, res_y);
    new Thread(new Runnable()
    {

      @Override
      public void run() {
        // TODO Auto-generated method stub
        //viz.init();
        viz.sortByArtist();
        currentSort = "artist";
//        Log.d("viz", "packing circles...");
        //viz.packCircles2();
//        Log.d("viz","circles packed");
        final List<PVCircle> circles = viz.getCircles();
        
        if (circles.isEmpty()==false)
        {
//          Log.d("viz", "circles obtained");
        
          runOnUiThread(new Runnable()
          {
  
            @Override
            public void run() {
              // TODO Auto-generated method stub
//              Log.d("viz", "running on ui thread - viewCircles");
              viewCircles(circles);
              
            }
            
          });
        }
        else 
        {
          runOnUiThread(new Runnable()
          {
            @Override
            public void run() {
              Toast.makeText(PreferenceVisualizationActivity.this, "There are no requests from the crowd", Toast.LENGTH_LONG).show();
            }
          });
        
        }
      }
      
    }).start();
    
  }
  
  public void sortByArtist(View view)
  {
    if(!currentSort.equals("artist"))
    {
      new Thread(new Runnable()
      {
        public void run()
        {
          // TODO Auto-generated method stub
          //viz.init();
          viz.sortByArtist();
          currentSort = "artist";
//          Log.d("viz", "packing circles...");
          //viz.packCircles2();
//          Log.d("viz","circles packed");
          final List<PVCircle> circles = viz.getCircles();
          
          if (circles.isEmpty()==false)
          {
            
//            Log.d("viz", "circles obtained");
            runOnUiThread(new Runnable()
            {
  
              @Override
              public void run() {
                // TODO Auto-generated method stub
//                Log.d("viz", "running on ui thread - viewCircles");
                viewCircles(circles);
              }
              
            });
          }
          else 
          {
            runOnUiThread(new Runnable()
            {
              @Override
              public void run() {
                Toast.makeText(PreferenceVisualizationActivity.this, "There are no requests from the crowd", Toast.LENGTH_LONG).show();
              }
            });
          
          }
        }
      }).start();
    }
  }
  
  public void sortByAlbum(View view)
  {
    if(!currentSort.equals("album"))
    {
      new Thread(new Runnable()
      {
        public void run()
        {
          //viz.init();
          viz.sortByAlbum();
          currentSort = "album";
//          Log.d("viz", "packing circles...");
          //viz.packCircles2();
//          Log.d("viz","circles packed");
          final List<PVCircle> circles = viz.getCircles();
          
          if (circles.isEmpty()==false)
          {
//            Log.d("viz", "circles obtained");
            runOnUiThread(new Runnable()
            {
  
              @Override
              public void run() {
                // TODO Auto-generated method stub
//                Log.d("viz", "running on ui thread - viewCircles");
                viewCircles(circles);
              }
              
            });
          }
          else 
          {
            runOnUiThread(new Runnable()
            {
              @Override
              public void run() {
                Toast.makeText(PreferenceVisualizationActivity.this, "There are no requests from the crowd", Toast.LENGTH_LONG).show();
              }
            });
          
          }
        }
      }).start();
    }
  }
  
  public void sortByTrack(View view)
  {
    if(!currentSort.equals("track"))
    {
      new Thread(new Runnable()
      {
        public void run()
        {
          // TODO Auto-generated method stub
          //viz.init();
          viz.sortByTrack();
          currentSort = "track";
          //viz.packCircles2();
//          Log.d("viz","circles packed");
          final List<PVCircle> circles = viz.getCircles();
          if (viz.getCircles().isEmpty()==false)
          {
//            Log.d("viz", "circles obtained");
            runOnUiThread(new Runnable()
            {
  
              @Override
              public void run() {
                // TODO Auto-generated method stub
//                Log.d("viz", "running on ui thread - viewCircles");
                viewCircles(circles);
              }
              
            });
          }
          else 
          {
            runOnUiThread(new Runnable()
            {
              @Override
              public void run() {
                Toast.makeText(PreferenceVisualizationActivity.this, "There are no requests from the crowd", Toast.LENGTH_LONG).show();
              }
            });
          
          }
        }
      }).start();
    }
  }

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.preference_visualization, menu);
    return true;
  }
  
  public void viewCircles(List<PVCircle> circles)
  {
    RelativeLayout vizlayout = (RelativeLayout) findViewById(R.id.vizlayout);
    vizlayout.removeAllViews();
    List<PreferenceCircle> pCircles = new ArrayList<PreferenceCircle>();
    for(int i=0; i<circles.size(); i++)
    {
      PVCircle currCircle = circles.get(i);

//      Log.d("viewCircles", "currCircle.getRadius = " + currCircle.getRadius());
//      Log.d("viewCircles", "currCircle.getRadius * 300 = " + (currCircle.getRadius()*225));
      PreferenceCircle pCircle = new PreferenceCircle(this, (int) currCircle.getX(), (int) currCircle.getY(), (int) currCircle.getRadius(), currCircle.getName(), currCircle.getTrackList());
//      Log.d("viewCircles", "pCircle.getRadius = " + pCircle.radius);
      pCircle.color = currCircle.getColor();
      pCircles.add(pCircle);
    }
    MyCanvas myCanvas = new MyCanvas(this, pCircles, pCircles.size());
    int width = getResources().getDisplayMetrics().widthPixels;
    int height = getResources().getDisplayMetrics().heightPixels;
    vizlayout.addView(myCanvas, width, height);
  }
  
  public static void getDetails(Context context, PreferenceCircle pCircle)
  {
    Intent i = new Intent(context, RequestDetailsActivity.class);
    i.putParcelableArrayListExtra("tracks", (ArrayList<Track>) pCircle.tracks);
    i.putExtra("requestName", pCircle.name);
    i.putExtra("color", pCircle.color);
    context.startActivity(i);
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    // Handle item selection
    switch (item.getItemId()) {
    case R.id.action_settings:
      Intent nextIntent  = new Intent(PreferenceVisualizationActivity.this, ProfileActivity.class);
      startActivity(nextIntent);
      break;
    case R.id.about:
      Intent nextIntent2  = new Intent(PreferenceVisualizationActivity.this, AboutActivity.class);
      startActivity(nextIntent2);
      break;
    default:
      super.onOptionsItemSelected(item);
    }
    return true;
  }

}




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