import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.GregorianCalendar;
import android.R.integer;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.Toast;
public class ParkingSetting extends Activity implements OnClickListener,
OnItemSelectedListener {
private ImageView imgInfo, imgAlarm, imgEmail, imgFacebook, imgTwitter;
private Spinner spnReminderTone, spnReminderTime;
private ArrayAdapter
private Button btnOk;
private static final int CAMERA_PIC_REQUEST = 1111;
private ImageView mImage;
final int[] ringtoneid = { R.raw.churchbell, R.raw.solaris, R.raw.whistler };
private MediaPlayer mMediaPlayer = null;
private String strMonthTitle;
private String strTicket_Path;
private int Year;
private static File mFile;
@Override
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.parking_setting);
imgInfo = (ImageView) findViewById(R.id.imgInfo);
imgInfo.setOnClickListener(this);
imgAlarm = (ImageView) findViewById(R.id.imgAlarm);
imgAlarm.setOnClickListener(this);
imgEmail = (ImageView) findViewById(R.id.imgEmail);
imgEmail.setOnClickListener(this);
imgFacebook = (ImageView) findViewById(R.id.imgFacebook);
imgFacebook.setOnClickListener(this);
imgTwitter = (ImageView) findViewById(R.id.imgTwitter);
imgTwitter.setOnClickListener(this);
btnOk = (Button) findViewById(R.id.btnOk);
btnOk.setOnClickListener(this);
Calendar cal = Calendar.getInstance();
Year = cal.get(Calendar.YEAR);
Toast.makeText(this, ""+Year, Toast.LENGTH_LONG).show();
SimpleDateFormat month_year = new SimpleDateFormat("MMMM yyyy");
strMonthTitle = month_year.format(cal.getTime());
strTicket_Path = "ABD"+File.separator+""+Year+File.separator+strMonthTitle;
spnReminderTime = (Spinner) findViewById(R.id.spnReminderTime);
aadpReminderTime = new ArrayAdapter(this,
android.R.layout.simple_spinner_item);
aadpReminderTime
.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
aadpReminderTime.add("15 Minutes");
aadpReminderTime.add("30 Minutes");
aadpReminderTime.add("45 Minutes");
aadpReminderTime.add("60 Minutes");
spnReminderTime.setAdapter(aadpReminderTime);
spnReminderTime.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView arg0, View arg1,
int arg2, long arg3) {
}
@Override
public void onNothingSelected(AdapterView arg0) {
}
});
spnReminderTone = (Spinner) findViewById(R.id.spnReminderTone);
aadpReminderTone = new ArrayAdapter(this,
android.R.layout.simple_spinner_item);
aadpReminderTone
.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
aadpReminderTone.add("Church Bell");
aadpReminderTone.add("Solaris");
aadpReminderTone.add("Whistler");
spnReminderTone.setAdapter(aadpReminderTone);
spnReminderTone.setOnItemSelectedListener(this);
spnReminderTone.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView arg0, View arg1,
int position, long arg3) {
StopMusic();
mMediaPlayer = MediaPlayer.create(ParkingSetting.this,
ringtoneid[position]);
PlayMusic();
}
@Override
public void onNothingSelected(AdapterView arg0) {
}
});
}
// @Override
// protected void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// createDirIfNotExists("Android/test10/hello_1");
// }
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.imgInfo:
// TODO
break;
case R.id.imgAlarm:
// TODO
break;
case R.id.imgEmail:
// TODO
break;
case R.id.imgFacebook:
// TODO
break;
case R.id.imgTwitter:
// TODO
break;
case R.id.btnOk:
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, CAMERA_PIC_REQUEST);
break;
default:
break;
}
}
@Override
public void onItemSelected(AdapterView arg0, View arg1, int arg2,long arg3) {
}
@Override
public void onNothingSelected(AdapterView arg0) {
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_PIC_REQUEST) {
Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
ImageView mImageView = new ImageView(getBaseContext());
mImageView.setImageBitmap(thumbnail);
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
thumbnail.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
createDirIfNotExists(strTicket_Path);
mFile = new File(Environment.getExternalStorageDirectory(),strTicket_Path+File.separator +"Ticket_"+System.currentTimeMillis()+".jpg");
try {
mFile.createNewFile();
FileOutputStream fo = new FileOutputStream(mFile);
fo.write(bytes.toByteArray());
fo.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public static String createDirIfNotExists(String path) {
boolean ret = true;
mFile = new File(Environment.getExternalStorageDirectory(), path);
if (!mFile.exists()) {
if (!mFile.mkdirs()) {
ret = false;
}
}
return path;
}
// This Is For Play Music
private void PlayMusic() {
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mMediaPlayer.start();
}
// This Is For Stop Music
private void StopMusic() {
if (mMediaPlayer != null) {
if (mMediaPlayer.isPlaying() == true) {
mMediaPlayer.release();
mMediaPlayer = null;
}
}
}
@Override
protected void onPause() {
super.onPause();
StopMusic();
}
}
Manifest file you have to give permissions for camera and write_external_storage_directory
No comments:
Post a Comment