Friday, July 15, 2011

Thread Concepts:

By Magesh Kumar   Posted at  9:59 PM   Android No comments
Method1:
import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.widget.Toast;


public class Method1 extends Activity {


class PrinterTask extends AsyncTask<String, Void, Void> {


protected Void doInBackground(String... x) {
while (true) {
System.out.println(x[0]);
test();


try {
Thread.sleep(1000);
test2();


} catch (InterruptedException ie) {
ie.printStackTrace();
}
}
}
};


@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);


new PrinterTask().execute("---------------------");
//new PrinterTask().execute("foo foo foo");


System.out.println("onCreate() is done.");
}


public void test2() {
// TODO Auto-generated method stub
System.out.println("test2 is done.");
}


public void test() {
// TODO Auto-generated method stub
System.out.println("test is done.");
}
}
Method2:



import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.KeyEvent;
import android.widget.TextView;


public class Method2 extends Activity implements Runnable {


private String pi_string;
private TextView tv;
private ProgressDialog pd;


@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main2);


tv = (TextView) this.findViewById(R.id.tv);
tv.setText("Press any key to start calculation");
}


public boolean onKeyDown(int keyCode, KeyEvent event) {


pd = ProgressDialog.show(this, "Working..", "Calculating Pi", true,
false);


Thread thread = new Thread(this);

thread.start();



return super.onKeyDown(keyCode, event);
}


public void run() {
pi_string = "gfdsgs";
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
handler.sendEmptyMessage(0);
}


private Handler handler = new Handler() {
public void handleMessage(Message msg) {
pd.dismiss();
tv.setText(pi_string);


}
};


}


Async Task in Android

By Magesh Kumar   Posted at  9:41 PM   Android No comments
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;


public class AsyncTasks extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);


Button upload = (Button) findViewById(R.id.widget27);


upload.setOnClickListener(new OnClickListener() {
public void onClick(View pV) {
new DoInBackground().execute();

}
});
}


public void do_update() {

// your stuff here
Log.i("MSG", "msg");

}


private class DoInBackground extends AsyncTask<Void, Void, Void> implements
DialogInterface.OnCancelListener {
private ProgressDialog dialog;


protected void onPreExecute() {
dialog = ProgressDialog.show(AsyncTasks.this, "", "Busy...", true, true,
this);
}


protected Void doInBackground(Void... v) {
do_update();
return null;
}


protected void onPostExecute(Void v) {
dialog.dismiss();
}


public void onCancel(DialogInterface dialog) {
cancel(true);
dialog.dismiss();
}
}
}

Tuesday, June 21, 2011

Flip Animation

By Magesh Kumar   Posted at  2:37 AM   Android No comments

Main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical" android:layout_width="fill_parent"
      android:layout_height="fill_parent">
      <TextView android:layout_width="fill_parent"
            android:layout_height="wrap_content" android:text="@string/hello" />
      <ViewFlipper android:id="@+id/viewflipper"
            android:layout_width="fill_parent" android:layout_height="fill_parent">
            <LinearLayout android:layout_width="fill_parent"
                  android:layout_height="wrap_content" android:orientation="vertical">
                  <TextView android:layout_width="wrap_content"
                        android:layout_height="wrap_content" android:text="First Screen" />
                  <Button android:id="@+id/button1" android:layout_width="fill_parent"
                        android:layout_height="wrap_content" android:text="Flip to second page" />
            </LinearLayout>
            <LinearLayout android:layout_width="fill_parent"
                  android:layout_height="fill_parent" android:orientation="vertical">
                  <TextView android:layout_width="wrap_content"
                        android:layout_height="wrap_content" android:text="Second Screen" />
                  <Button android:id="@+id/button2" android:layout_width="fill_parent"
                        android:layout_height="fill_parent" android:text="Flip back" />
            </LinearLayout>
      </ViewFlipper>
</LinearLayout>

Main.java
package com.magesh;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ViewFlipper;

public class Main extends Activity {
               
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        final ViewFlipper MyViewFlipper = (ViewFlipper)findViewById(R.id.viewflipper);
        Button button1 = (Button)findViewById(R.id.button1);
        Button button2 = (Button)findViewById(R.id.button2);

        Animation animationFlipIn  = AnimationUtils.loadAnimation(this, R.anim.flipin);
        Animation animationFlipOut = AnimationUtils.loadAnimation(this, R.anim.flipout);
        MyViewFlipper.setInAnimation(animationFlipIn);
        MyViewFlipper.setOutAnimation(animationFlipOut);
       
        button1.setOnClickListener(new Button.OnClickListener(){

                                                @Override
                                                public void onClick(View arg0) {
                                                                // TODO Auto-generated method stub
                                                                MyViewFlipper.showNext();
                                                }});
       
        button2.setOnClickListener(new Button.OnClickListener(){

                                                @Override
                                                public void onClick(View arg0) {
                                                                // TODO Auto-generated method stub
                                                                MyViewFlipper.showPrevious();
                                                }});
    }
}

In res/anim/flipin.xml
Flipin.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
      android:interpolator="@android:anim/decelerate_interpolator">
<translate
      android:fromXDelta="-100%"
      android:toXDelta="0%"
      android:duration="500" />
</set>
Flipout.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
      android:interpolator="@android:anim/decelerate_interpolator">
<translate
      android:fromXDelta="0%"
      android:toXDelta="100%"
      android:duration="500" />
</set>

X-Files Effect

By Magesh Kumar   Posted at  12:35 AM   Photoshop No comments

You've seen X-Files, haven't you? And you liked the effect they use for their title? Something very mysterious, right. Well, it isn't as complex as you might think. All you need is Photoshop and a little bit of patience.
Start with a RGB image and make the background black. Type something. If you are using Photoshop 4.0, hit Ctrl-E (Cmd-E on Mac) to merge type layer down. Now, open Channel Palette (Window>Show Channels) and  drag any of the channels to a New Channel icon. This will create channel #4. Double click it and rename it to "original type".
Drag original type channel to a new channel icon to duplicate it. Double click channel #5 and rename it to "white". Then Ctrl-click (Cmd-click on Mac) on the channel to load it as a selection. Now we have to expand it a little. Use Select>Modify>Expand with setting of 2 pixels. Edit>Fill with white. Remove the selection (Select>None).
Filter>Blur>Gaussian Blur... with setting of 2
Drag the white channel to a new channel icon so we can have one more channel. Double click channel #6 and rename it to "yellow". Ctrl-click it to get the selection. Again, Select>Modify> Expand... and enter value of 2. Fill it with white and remove the selection and gaussian blur it all by 3.
Finally drag yellow to a new channel icon. Rename it to "green", Ctrl-click it, and expand by 6. Fill it with white, deselect, then blur by 10 pixels. Now, preparations are ready. Let's do it.
Switch to channel RGB. Select>Load Selection... choose channel "green". Now pick some nice green color as foreground color. Here, this setting is used R:0 G:255 B:0
Edit>Fill... with foreground. Do the same for the "yellow" channel but use R:128 G:255 B:0 color.
Repeat the process for the "white" channel but use plain white color.
Finally, load "original type", Select>Modify>Contract by 1 pixel and fill with black.
You are X-Filed!


Oil Effect

By Magesh Kumar   Posted at  12:27 AM   Photoshop No comments

1.
Start a new file.
 File | new...
Choose a suitable size and make sure you are in RGB mode and that the resolution is set to 72 dpi. Use Black as background color.
Type in a optional text with white color.
Layer | Type | Render Layer
Blur the text with 1,0 pixel. Filter | Blur | Guassian Blur....


2. Layer | Flatten Image
Image | Rotate Canvas | 90 CW
Filter | Stylize | Wind... Check Wind andFrom the left
Filter | Stylize | Solarize
Image | Rotate Canvas | 90 CCW






3.
Now, colorize the image by doing this:

Image | Adjust | Hue/Saturation... CheckColorize and test these settings:
Hue: 23, Saturation: 67 Lightness: 0

Back to top ↑
Connect with Us

What they says

© 2013 MaGeSH 2 help. WP Mythemeshop Converted by BloggerTheme9
Blogger templates. Proudly Powered by Blogger.