Loading...
Logo
Processing Forum
xavierv1's Profile
6 Posts
13 Responses
1 Followers

Activity Trend

Last 30 days
Show:
Private Message
    In Processing if you want that a function is executed in a diferent thread, you have just to use the following command:

    thread("myFunc"); // this command creates a new thread and executes myFunc in that thread

    void myFunc(){ ... }

    The restriction is that 'myFunc' must be void, with no parameters and it could not be declared in a subclass in the sketch (it must be a public function in the pApplet class).
    If you nedd that 'myFunc' has parameters, See this Post
    enjoy this.
    If you want to get a ring tone here you have the code:

    1. //http://developer.android.com/reference/android/media/RingtoneManager.html

    2. import android.media.Ringtone;
    3. import android.media.RingtoneManager;
    4. import android.database.Cursor;

    5. RingtoneManager ringManager;
    6. Ringtone ring;
    7. Cursor cursor;

    8. void setup() {
    9.   size(screenWidth, screenHeight, A2D);
    10.   ringManager = new RingtoneManager(this);
    11.   cursor = ringManager.getCursor();
    12.   maxN = cursor.getCount();  
    13.   ring = ringManager.getRingtone(0);  
    14. }


    15. int maxN;
    16. int n = 1;

    17. void draw() {  ;  }


    18. void mouseReleased(){
    19.   if(ring.isPlaying()){
    20.     ring.stop();
    21.     ring = ringManager.getRingtone(n);
    22.     n = (n < maxN-1)? n+1 : 0;
    23.   }else{ 
    24.     ring.play();
    25.   }
    26. }

    To Set the Window(Screen) Bright in Processing for Android simply add the following code to your sketch:


    1. void setup(){...}
    2. void draw() {...}

    3. //www.akeric.com/blog/?p=1313


    4. //-----------------------------------------------------------------------------------------
    5. // Override the parent (super) Activity class:
    6. // States onCreate(), onStart(), and onStop() aren't called by the sketch.  Processing is entered at
    7. // the 'onResume()' state, and exits at the 'onPause()' state, so just override them:

    8. void onResume() {
    9.   super.onResume();

    10.   setWindowBright();

    11.   println("RESUMED! (Sketch Entered...)");
    12. }

    13. import android.view.WindowManager;
    14. import android.view.WindowManager.LayoutParams;



    15. void setWindowBright(){
    16.   getWindow().addFlags(LayoutParams.FLAG_KEEP_SCREEN_ON | LayoutParams.FLAG_TURN_SCREEN_ON);  

    17. // to set a diferent bright level (other than default)
    18. //  WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
    19. //  layoutParams.screenBrightness = 0.8f;                   
    20. //  getWindow().setAttributes(layoutParams); 
    21. }
    To get a Translucent / Transparent window like this:




    Here yo have the code:

    1. // http://xavierstechno.blogspot.com/
    2. //http://java.sun.com/developer/technicalArticles/GUI/translucent_shaped_windows/
    3. import com.sun.awt.AWTUtilities;
    4. import java.awt.*;
    5. import javax.swing.JFrame;

    6. JFrame topFrame = null;
    7. PGraphics pg3D;
    8. int framePosX = 800;
    9. int framePosY = 300;
    10. int frameWidth = 300;
    11. int frameHeight = 300;
    12. float opacitatTopFrame = 0.9f;

    13. public void init(){
    14.   frame.removeNotify();
    15.   frame.setUndecorated(true);
    16.   AWTUtilities.setWindowOpaque(frame, false);
    17.   AWTUtilities.setWindowOpacity(frame, 0.0f);  
    18.   //frame.setOpacity(0.0f);
    19.   frame.setBackground(new Color(0.0f,0.0f,0.0f,0.0f));                
    20.   frame.setVisible(false);
    21.   frame.setLayout( null );
    22.   frame.addNotify();
    23.   
    24.   GraphicsConfiguration translucencyCapableGC;
    25.   translucencyCapableGC = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();

    26.   topFrame = new JFrame(translucencyCapableGC);
    27.   topFrame.setUndecorated(true);
    28.   //topFrame.setOpacity(opacitatTopFrame);
    29.   AWTUtilities.setWindowOpaque(topFrame, false);
    30.   AWTUtilities.setWindowOpacity(topFrame, opacitatTopFrame);    
    31.   topFrame.setAlwaysOnTop(false);
    32.   topFrame.setLocationRelativeTo(null);
    33.   topFrame.setLocation(framePosX, framePosY);
    34.   topFrame.setSize(frameWidth, frameHeight);
    35.   topFrame.setBackground(new Color(0,0,0,0));
    36.   topFrame.setVisible(true);
    37.   topFrame.setTitle( frame == null? "":frame.getTitle() );
    38.   topFrame.setIconImage( frame.getIconImage() );
    39.   topFrame.setLayout( null ); 
    40.   topFrame.addNotify();
    41.   super.init();
    42.   g.format = ARGB;
    43.   g.setPrimary(false);
    44. }


    45. void setup() {
    46.   size(frameWidth, frameHeight);
    47.   colorMode(RGB,255,255,255,255);
    48.   pg3D = createGraphics(frameWidth, frameHeight,P3D);
    49.   pg3D.colorMode(RGB,255,255,255,255);
    50. }


    51. float angle = 0;

    52. void draw() {

    53.    background(0,0,255,135);
    54.    fill(0,255,0,55);
    55.    int mX = MouseInfo.getPointerInfo().getLocation().x-framePosX;
    56.    int mY = MouseInfo.getPointerInfo().getLocation().y-framePosY;
    57.    rectMode(CENTER);
    58.    rect(mX, mY,50,50);
    59.    
    60.    pg3D.beginDraw();
    61.      pg3D.background(0,0,0,0);
    62.      pg3D.stroke(0); 
    63.      pg3D.fill(255,0,0,255);
    64.      pg3D.translate(100,100);   pg3D.rotateZ(angle);   pg3D.rotateX(angle);   pg3D.rotateY(angle);
    65.      pg3D.rectMode(CENTER);
    66.      pg3D.rect(0,0,50,50);
    67.    pg3D.endDraw();
    68.    
    69.    image(pg3D,0,0);
    70.    frame.setVisible(false);
    71.    topFrame.add(this);
    72.    
    73.    angle+=0.02;
    74. }