- private TextView tv;
- private ProgressDialog pd;
- @Override
- public void onCreate(Bundle icicle) {
- super.onCreate(icicle);
- setContentView(R.layout.main);
- tv = (TextView) this.findViewById(R.id.main);
- tv.setText("Press any key to start calculation");
- }
- @Override
- pd = ProgressDialog.show(this, "Working..", "Calculating Pi", true,
- false);
- thread.start();
- return super.onKeyDown(keyCode, event);
- }
- public void run() {
- pi_string = Pi.computePi(800).toString();
- handler.sendEmptyMessage(0);
- }
- private Handler handler = new Handler() {
- @Override
- public void handleMessage(Message msg) {
- pd.dismiss();
- tv.setText(pi_string);
- }
- };
- }
2010년 12월 29일 수요일
Progress Dialog
Android Progress Dialog Example
In android, we can show progress bar through dialog also. For this we need to use ProgressDialog.
Here is a example for how to use ProgressDialog :
To dismiss a ProgressDialog use ProgressDialogName.dismiss()
( ex : dialog.dismiss()).
The output will looks like
Here is a example for how to use ProgressDialog :
1 | public class ExampleApp extends Activity { |
2 | @Override |
3 | protected void onCreate(Bundle savedInstanceState) { |
4 | super.onCreate(savedInstanceState); |
5 | setContentView(R.layout.main); |
6 | ProgressDialog dialog = ProgressDialog.show (ExampleApp.this, "", "Please wait for few seconds..." |
7 | } |
8 | } |
To dismiss a ProgressDialog use ProgressDialogName.dismiss()
( ex : dialog.dismiss()).
The output will looks like
2010년 12월 22일 수요일
Adding new media to the media store.
By default, media files created by your application will be unavailable to other
applications. As a result, it’s good practice to insert it into the Media Store
to make it available to other applications.
Android provides two alternatives for inserting media into the Media Store,
either using the Media Scanner to interpret your file and insert it automatically,
or manually inserting a new record in the appropriate Content Provider.
Using the Media Scanner
If you have recorded new media of any kind, the MediaScannerConnection
class provides a simple way for you to add it to the Media Store without
needing to construct the full record for the Media Store Content Provider.
Before you can use the scanFile method to initiate a content scan on your file,
you must call connect and wait for the connection to the Media Scanner to complete.
This call is asynchronous, so you will need to implement
a MediaScannerConnectionClient to notify you when the connection has been
made. You can use this same class to notify you when the scan is complete,
at which point you can disconnect your Media Scanner Connection.
The skeleton code for creating a new MediaScannerConnectionClient
MediaScannerConnectionClient mediaScannerClient =
new MediaScannerConnectionClient() {
private MediaScannerConnection msc = null;
{
msc = new MediaScannerConnection(getApplicationContext(), this);
msc.connect();
}
public void onMediaScannerConnected() {
msc.scanFile("/sdcard/test1.jpg", null);
}
public void onScanCompleted(String path, Uri uri) {
msc.disconnect();
}
};
applications. As a result, it’s good practice to insert it into the Media Store
to make it available to other applications.
Android provides two alternatives for inserting media into the Media Store,
either using the Media Scanner to interpret your file and insert it automatically,
or manually inserting a new record in the appropriate Content Provider.
Using the Media Scanner
If you have recorded new media of any kind, the MediaScannerConnection
class provides a simple way for you to add it to the Media Store without
needing to construct the full record for the Media Store Content Provider.
Before you can use the scanFile method to initiate a content scan on your file,
you must call connect and wait for the connection to the Media Scanner to complete.
This call is asynchronous, so you will need to implement
a MediaScannerConnectionClient to notify you when the connection has been
made. You can use this same class to notify you when the scan is complete,
at which point you can disconnect your Media Scanner Connection.
The skeleton code for creating a new MediaScannerConnectionClient
MediaScannerConnectionClient mediaScannerClient =
new MediaScannerConnectionClient() {
private MediaScannerConnection msc = null;
{
msc = new MediaScannerConnection(getApplicationContext(), this);
msc.connect();
}
public void onMediaScannerConnected() {
msc.scanFile("/sdcard/test1.jpg", null);
}
public void onScanCompleted(String path, Uri uri) {
msc.disconnect();
}
};
2010년 12월 21일 화요일
Using the camera and taking pictures in android
I will demonstrate the mechanisms you can use to control the camera and take
photos within your applications
- Using Intents to take pictures
The easiest way to take a picture using the device camera is using the
ACTION_IMAGE_CAPTURE Media Store static constant in an Intent passed to
startActivityForResult.
startActivityForResult(new Intent(MediaStore.ACTION_IMAGE_CAPTURE),
TAKE_PICTURE);
This will launch the camera Activity, allowing users to modify the image
settings manually, and preventing you from having to rewrite the entire
camera application.
The image capture action supports two modes, thumbnail and full image.
➤ Thumbnail By default, the picture taken by the image capture action will
return a thumbnail Bitmap in the data extra within the Intent parameter
returned in onActivityResult.
As shown in Listing 11-11, call getParcelableExtra specifying the extra
name data on the Intent parameter to return the thumbnail as a Bitmap.
➤ Full image If you specify an output URI using a MediaStore.EXTRA_OUTPUT
extra in the launch Intent, the full-size image taken by the camera will
be saved to the specified location.
In this case no thumbnail will be returned in the Activity result callback
and the result Intent data will be null.
- Below example shows how to use the image capture action to capture either
a thumbnail or full image using an Intent.
private static int TAKE_PICTURE = 1;
private Uri outputFileUri;
private void getThumbailPicture() {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, TAKE_PICTURE);
}
private void saveFullImage() {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File file = new File(Environment.getExternalStorageDirectory(),
"test.jpg");
outputFileUri = Uri.fromFile(file);
intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
startActivityForResult(intent, TAKE_PICTURE);
}
@Override
protected void onActivityResult(int requestCode,
int resultCode, Intent data) {
if (requestCode == TAKE_PICTURE) {
Uri imageUri = null;
// Check if the result includes a thumbnail Bitmap
if (data != null) {
if (data.hasExtra("data")) {
Bitmap thumbnail = data.getParcelableExtra("data");
// TODO Do something with the thumbnail
}
}
else {
// TODO Do something with the full image stored
// in outputFileUri
}
}
}
- The End -
photos within your applications
- Using Intents to take pictures
The easiest way to take a picture using the device camera is using the
ACTION_IMAGE_CAPTURE Media Store static constant in an Intent passed to
startActivityForResult.
startActivityForResult(new Intent(MediaStore.ACTION_IMAGE_CAPTURE),
TAKE_PICTURE);
This will launch the camera Activity, allowing users to modify the image
settings manually, and preventing you from having to rewrite the entire
camera application.
The image capture action supports two modes, thumbnail and full image.
➤ Thumbnail By default, the picture taken by the image capture action will
return a thumbnail Bitmap in the data extra within the Intent parameter
returned in onActivityResult.
As shown in Listing 11-11, call getParcelableExtra specifying the extra
name data on the Intent parameter to return the thumbnail as a Bitmap.
➤ Full image If you specify an output URI using a MediaStore.EXTRA_OUTPUT
extra in the launch Intent, the full-size image taken by the camera will
be saved to the specified location.
In this case no thumbnail will be returned in the Activity result callback
and the result Intent data will be null.
- Below example shows how to use the image capture action to capture either
a thumbnail or full image using an Intent.
private static int TAKE_PICTURE = 1;
private Uri outputFileUri;
private void getThumbailPicture() {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, TAKE_PICTURE);
}
private void saveFullImage() {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File file = new File(Environment.getExternalStorageDirectory(),
"test.jpg");
outputFileUri = Uri.fromFile(file);
intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
startActivityForResult(intent, TAKE_PICTURE);
}
@Override
protected void onActivityResult(int requestCode,
int resultCode, Intent data) {
if (requestCode == TAKE_PICTURE) {
Uri imageUri = null;
// Check if the result includes a thumbnail Bitmap
if (data != null) {
if (data.hasExtra("data")) {
Bitmap thumbnail = data.getParcelableExtra("data");
// TODO Do something with the thumbnail
}
}
else {
// TODO Do something with the full image stored
// in outputFileUri
}
}
}
- The End -
2010년 12월 20일 월요일
ImageViewer can One-Finger-Zoom.
I made this android app to zoom-in/out by one finger.
Using pinch-zoom, we have to use two hands and two fingers.
It always makes me feel dissatisfaction.
Using pinch-zoom, we have to use two hands and two fingers.
It always makes me feel dissatisfaction.
Red-Stone made by OpenGL.
Red-Stone is the program i made when i was an university student.
It's about 8 years ago.
It is just red-colored stone rotating around and transforms to a butterfly, a hand and the miky-mouse.
It's about 8 years ago.
It is just red-colored stone rotating around and transforms to a butterfly, a hand and the miky-mouse.
Implementation of the Mutual Exclusion Algorithm
I implement the mutual exclusion algorithm. of the distributed operating system.
There are four files. (server.pdf, client.pdf, error.pdf, sclist.pdf)
Rewrite the source code in the pdf file to .c source file and compile the soruce codes. Then it work correctly.
There are four files. (server.pdf, client.pdf, error.pdf, sclist.pdf)
Rewrite the source code in the pdf file to .c source file and compile the soruce codes. Then it work correctly.
피드 구독하기:
글 (Atom)








