package com.example.spinnerapp;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends Activity implements OnClickListener {
private static final String SHAREDPREFERENCES = "sp";
private static final String RINGTONEPOS = null;
protected static final String RINGTONE = null;
Dialog mAlertDialog;
private static final String SNOOZETIMEPOS="keySnoozeTimePos";
private static final String SNOOZETIME="keySnoozeTime";
private Button btn1,btn2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn1 = (Button)findViewById(R.id.btn1);
btn1.setOnClickListener(this);
btn2 = (Button)findViewById(R.id.btn2);
btn2.setOnClickListener(this);
}
private void StopMusic()
{
if(mMediaPlayer!=null)
{
if(mMediaPlayer.isPlaying()==true)
{
mMediaPlayer.release();
mMediaPlayer=null;
}
}
}
//This Is For Play Music
private void PlayMusic() {
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
//mMediaPlayer.setLooping(true);
mMediaPlayer.start();
// i.e. react on the end of the music-file:
// mMediaPlayer.setOnCompletionListener(new OnCompletionListener(){
//
// // @Override
// public void onCompletion(MediaPlayer arg0) {
// System.out.println("Songs Finish");
// }
// });
}
@Override
protected void onPause() {
super.onPause();
StopMusic();
}
int ringpos=0;
private MediaPlayer mMediaPlayer=null;
private void Ringtoneset()
{
final int[] ringtoneid={R.raw.a,R.raw.b,R.raw.c};
final CharSequence[] ringtoneitems = {"Arctic","Extream","Going Solo"};
SharedPreferences mSPreferences=getSharedPreferences(SHAREDPREFERENCES,Context.MODE_WORLD_READABLE);
ringpos = mSPreferences.getInt(RINGTONEPOS,0);
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("Ringtones Set");
builder.setSingleChoiceItems(ringtoneitems, ringpos, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
// Toast.makeText(Setting.this, ringtoneitems[item], Toast.LENGTH_SHORT).show();
ringpos=item;
StopMusic();
mMediaPlayer = MediaPlayer.create(MainActivity.this,ringtoneid[item]);
PlayMusic();
}
});
builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
SharedPreferences mSharedPreferences=getSharedPreferences(SHAREDPREFERENCES,MODE_WORLD_WRITEABLE);
SharedPreferences.Editor mEditor=mSharedPreferences.edit();
mEditor.putInt(RINGTONE, ringtoneid[ringpos]);
mEditor.putInt(RINGTONEPOS, ringpos);
mEditor.commit();
Toast.makeText(MainActivity.this, ringtoneitems[ringpos], Toast.LENGTH_SHORT).show();
StopMusic();
mAlertDialog.dismiss();
}
});
builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
StopMusic();
mAlertDialog.dismiss();
}
});
mAlertDialog = builder.create();
mAlertDialog.setCancelable(false);
mAlertDialog.show();
}
private AlertDialog mAlertDialog1 = null ;
private void Snoozeset()
{
final int[] snoozetime={10,15,20};
final CharSequence[] snoozeitems = {"10 Minutes", "15 Minutes", "20 Minutes"};
// final int[] snoozetime={2,3,4};
// final CharSequence[] snoozeitems = {"2 Minutes", "3 Minutes", "4 Minutes"};
SharedPreferences mSPreferences=getSharedPreferences(SHAREDPREFERENCES,Context.MODE_WORLD_READABLE);
int pos = mSPreferences.getInt(SNOOZETIMEPOS,0);
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("Snooze Minutes");
builder.setSingleChoiceItems(snoozeitems, pos, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
// Toast.makeText(Setting.this, snoozeitems[item], Toast.LENGTH_SHORT).show();
SharedPreferences mSharedPreferences=getSharedPreferences(SHAREDPREFERENCES,MODE_WORLD_WRITEABLE);
SharedPreferences.Editor mEditor=mSharedPreferences.edit();
mEditor.putInt(SNOOZETIME, snoozetime[item]);
mEditor.putInt(SNOOZETIMEPOS, item);
mEditor.commit();
btn2.setText(snoozeitems[item].toString());
mAlertDialog.dismiss();
}
});
builder.setNegativeButton(android.R.string.cancel,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
mAlertDialog.dismiss();
}
});
mAlertDialog = builder.create();
mAlertDialog.setCancelable(true);
mAlertDialog.show();
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(v==btn1){
Snoozeset();
}else if(v==btn2){
Ringtoneset();
}
}
}
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends Activity implements OnClickListener {
private static final String SHAREDPREFERENCES = "sp";
private static final String RINGTONEPOS = null;
protected static final String RINGTONE = null;
Dialog mAlertDialog;
private static final String SNOOZETIMEPOS="keySnoozeTimePos";
private static final String SNOOZETIME="keySnoozeTime";
private Button btn1,btn2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn1 = (Button)findViewById(R.id.btn1);
btn1.setOnClickListener(this);
btn2 = (Button)findViewById(R.id.btn2);
btn2.setOnClickListener(this);
}
private void StopMusic()
{
if(mMediaPlayer!=null)
{
if(mMediaPlayer.isPlaying()==true)
{
mMediaPlayer.release();
mMediaPlayer=null;
}
}
}
//This Is For Play Music
private void PlayMusic() {
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
//mMediaPlayer.setLooping(true);
mMediaPlayer.start();
// i.e. react on the end of the music-file:
// mMediaPlayer.setOnCompletionListener(new OnCompletionListener(){
//
// // @Override
// public void onCompletion(MediaPlayer arg0) {
// System.out.println("Songs Finish");
// }
// });
}
@Override
protected void onPause() {
super.onPause();
StopMusic();
}
int ringpos=0;
private MediaPlayer mMediaPlayer=null;
private void Ringtoneset()
{
final int[] ringtoneid={R.raw.a,R.raw.b,R.raw.c};
final CharSequence[] ringtoneitems = {"Arctic","Extream","Going Solo"};
SharedPreferences mSPreferences=getSharedPreferences(SHAREDPREFERENCES,Context.MODE_WORLD_READABLE);
ringpos = mSPreferences.getInt(RINGTONEPOS,0);
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("Ringtones Set");
builder.setSingleChoiceItems(ringtoneitems, ringpos, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
// Toast.makeText(Setting.this, ringtoneitems[item], Toast.LENGTH_SHORT).show();
ringpos=item;
StopMusic();
mMediaPlayer = MediaPlayer.create(MainActivity.this,ringtoneid[item]);
PlayMusic();
}
});
builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
SharedPreferences mSharedPreferences=getSharedPreferences(SHAREDPREFERENCES,MODE_WORLD_WRITEABLE);
SharedPreferences.Editor mEditor=mSharedPreferences.edit();
mEditor.putInt(RINGTONE, ringtoneid[ringpos]);
mEditor.putInt(RINGTONEPOS, ringpos);
mEditor.commit();
Toast.makeText(MainActivity.this, ringtoneitems[ringpos], Toast.LENGTH_SHORT).show();
StopMusic();
mAlertDialog.dismiss();
}
});
builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
StopMusic();
mAlertDialog.dismiss();
}
});
mAlertDialog = builder.create();
mAlertDialog.setCancelable(false);
mAlertDialog.show();
}
private AlertDialog mAlertDialog1 = null ;
private void Snoozeset()
{
final int[] snoozetime={10,15,20};
final CharSequence[] snoozeitems = {"10 Minutes", "15 Minutes", "20 Minutes"};
// final int[] snoozetime={2,3,4};
// final CharSequence[] snoozeitems = {"2 Minutes", "3 Minutes", "4 Minutes"};
SharedPreferences mSPreferences=getSharedPreferences(SHAREDPREFERENCES,Context.MODE_WORLD_READABLE);
int pos = mSPreferences.getInt(SNOOZETIMEPOS,0);
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("Snooze Minutes");
builder.setSingleChoiceItems(snoozeitems, pos, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
// Toast.makeText(Setting.this, snoozeitems[item], Toast.LENGTH_SHORT).show();
SharedPreferences mSharedPreferences=getSharedPreferences(SHAREDPREFERENCES,MODE_WORLD_WRITEABLE);
SharedPreferences.Editor mEditor=mSharedPreferences.edit();
mEditor.putInt(SNOOZETIME, snoozetime[item]);
mEditor.putInt(SNOOZETIMEPOS, item);
mEditor.commit();
btn2.setText(snoozeitems[item].toString());
mAlertDialog.dismiss();
}
});
builder.setNegativeButton(android.R.string.cancel,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
mAlertDialog.dismiss();
}
});
mAlertDialog = builder.create();
mAlertDialog.setCancelable(true);
mAlertDialog.show();
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(v==btn1){
Snoozeset();
}else if(v==btn2){
Ringtoneset();
}
}
}
No comments:
Post a Comment