package com.mymusictwo;
import java.util.ArrayList;
import com.data.Data;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;
public class Main extends Activity implements OnClickListener, OnTouchListener, OnItemClickListener{
Context context;
private EditText play_music_name;
private EditText play_music_time;
private EditText play_clock_time;
private Button save_config;
private Dialog menuDialog;
private View menuView;
private ListView listView;
private ArrayAdapter<String> adapter;
String []items ={"Adscjnsdjcnsnj","Adscjnsdjcnsnj"};
private ArrayList<String> path ;
private ArrayList<String> name ;
private boolean haveData = false;
private String music_path;
//歌曲名称
private int choosed = -1;
private void init(){
context = Main.this;
play_music_name = (EditText)findViewById(R.id.play_music_name);
play_music_time = (EditText)findViewById(R.id.play_music_time);
play_clock_time = (EditText)findViewById(R.id.play_clock_time);
save_config = (Button)findViewById(R.id.save_config);
save_config.setOnClickListener(this);
play_music_name.setOnTouchListener(this);
// 设置自定义menu菜单
menuView = View.inflate(this, R.layout.list_menu, null);
// 创建AlertDialog
menuDialog = new Dialog(context);
listView = (ListView)menuView.findViewById(R.id.listView1);
adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,items);
listView.setAdapter(adapter);
listView.setOnItemClickListener(this);
menuDialog.setContentView(menuView);
menuDialog.setTitle("请选择喜欢的歌曲?");
Window window = menuDialog.getWindow();
window.setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND,
WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
init();
Data.getRootPath(Data.path);
String music_name = Data.readShare(context, 0,Data.play_name );
String music_time = Data.readShare(context, 0,Data.play_time );
String clock_time = Data.readShare(context, 0,Data.clock_time );
if(music_name.length()!=0){
haveData = true;
music_path = music_name;
music_name=music_name.substring(music_name.lastIndexOf("/")+1);
play_music_name.setText(music_name);
}
if(music_time.length()!=0){
play_music_time.setText(music_time);
}
if(clock_time.length()!=0){
play_clock_time.setText(clock_time);
}
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId()){
case R.id.save_config:
if(play_music_name.getText().toString().length() == 0){
Toast.makeText(context, "请输入歌曲名", Toast.LENGTH_SHORT).show();
}else if(play_music_time.getText().toString().length() == 0){
Toast.makeText(context, "请输入播放时间", Toast.LENGTH_SHORT).show();
}else if(play_clock_time.getText().toString().length() == 0){
Toast.makeText(context, "请输入闹钟时间", Toast.LENGTH_SHORT).show();
}
if(play_music_name.getText().toString().length() != 0&&play_music_time.getText().toString().length() != 0&&play_clock_time.getText().toString().length()!=0){
if(haveData){
Data.writeShare(context, 0, Data.play_name, music_path);
}else{
Data.writeShare(context, 0, Data.play_name, path.get(choosed));
}
Data.writeShare(context, 0, Data.play_time, play_music_time.getText().toString());
Data.writeShare(context, 0, Data.clock_time, play_clock_time.getText().toString());
finish();
}
break;
}
}
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
path = (ArrayList<String>) Data.getFileDir(Data.getRootPath(Data.path));
name = (ArrayList<String>) Data.getFileName(Data.getRootPath(Data.path));
//Toast.makeText(context,Data.getRootPath(Data.path) , Toast.LENGTH_SHORT).show();
String str ="";
if(name!=null){
if(name.size()>0){
for(int i=0;i<name.size();i++){
str+=name.get(i)+",";
adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,str.split(","));
listView.setAdapter(adapter);
menuDialog.setContentView(menuView);
}
menuDialog.show();
}else{
play_music_name.setText("");
Toast.makeText(context, "请在file目录中添加歌曲!", Toast.LENGTH_SHORT).show();
}
}else{
Toast.makeText(context, "请在file目录中添加歌曲!", Toast.LENGTH_SHORT).show();
}
play_music_name.setText("");
play_music_name.setFocusable(false);
return false;
}
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
// TODO Auto-generated method stub
choosed = arg2;
haveData = false;
play_music_name.setText(name.get(arg2));
//Toast.makeText(context, arg2+"", Toast.LENGTH_SHORT).show();
menuDialog.dismiss();
}
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if ((keyCode == KeyEvent.KEYCODE_BACK) )
{
finish();
return true;
}else{
return true;
}
}
}
|
|