package com.giaour;
import java.io.File;
import java.util.ArrayList;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.ComponentName;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.content.ServiceConnection;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.IBinder;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.SeekBar;
import android.widget.Toast;
public class VanillaActivity extends Activity implements OnItemClickListener {
private static final int DIALOG_DLE = 1;
private static final int DIALOG_RNAME = 0;
private Intent intentServ;
private ListView listView;
private MyAdapter myAdapter;
private ArrayList<File> AudioData = new ArrayList<File>();
private File ChckItem;
private boolean IsRecording;
private RecordServeice recordServeice;
private Button buttonRecord;
private boolean IsPlay;
private Button ButtonPlay;
private boolean IsBind;
private SeekBar bar;
private int index = -1;
private ServiceConnection connection = new ServiceConnection() {
@Override
public void onServiceDisconnected(ComponentName name) {
recordServeice = null;
IsBind = false;
}
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
recordServeice = ((RecordServeice.LocalBinder)service).getServeice();;
IsBind = true;
}
};
private Handler handler = new Handler();
Runnable runnable = new Runnable() {
@Override
public void run() {
System.out.println("进入");
MediaPlayer mediaPlayer = recordServeice.getPlayer();
bar.setMax(mediaPlayer.getDuration());
bar.setProgress(mediaPlayer.getCurrentPosition());
handler.postDelayed(this, 1000);
}
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
intentServ = new Intent("com.giaour.FORVANILLA");
listView = (ListView) findViewById(R.id.listView);
buttonRecord = (Button) findViewById(R.id.button_record);
ButtonPlay = (Button) findViewById(R.id.button_play);
bar = (SeekBar) findViewById(R.id.seekBar);
getData();
// 注册上下文菜单
registerForContextMenu(listView);
//listView注册监听器
listView.setOnItemClickListener(this);
}
@Override
protected void onStart() {
super.onStart();
intentServ.putExtra("Audio", "");
startService(intentServ);
bindService(intentServ, connection, BIND_AUTO_CREATE);
}
public void getData() {
AudioData.clear();
String sdCrard = Environment.getExternalStorageDirectory()
.getAbsolutePath();
File file = new File(sdCrard + File.separatorChar + "Vanilla");
if (file.exists()) {
if (file.listFiles().length > 0) {
for (int i = 0; i < file.listFiles().length; i++) {
AudioData.add(file.listFiles()[i]);
System.out.println(file.listFiles()[i].getName());
}
myAdapter = new MyAdapter(this, AudioData);
listView.setAdapter(myAdapter);
} else {
for (int i = 0; i < 2; i++) {
Toast.makeText(this, "您暂时还没有通话录音", Toast.LENGTH_SHORT)
.show();
}
}
} else {
for (int i = 0; i < 2; i++) {
Toast.makeText(this, "您暂时还没有通话录音", Toast.LENGTH_SHORT).show();
}
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// 添加menu布局文件
getMenuInflater().inflate(R.menu.toggle, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if(item.getItemId()==R.id.item_use){
startActivity(new Intent(this, Settings.class));
}
return super.onOptionsItemSelected(item);
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
AdapterContextMenuInfo contextMenuInfo = (AdapterContextMenuInfo) menuInfo;
ChckItem = AudioData.get(contextMenuInfo.position);
getMenuInflater().inflate(R.menu.menu, menu);
}
@Override
public boolean onContextItemSelected(MenuItem item) {
if (item.getItemId() == R.id.item_del) {
showDialog(DIALOG_DLE);
} else {
showDialog(DIALOG_RNAME);
}
return super.onContextItemSelected(item);
}
@Override
protected Dialog onCreateDialog(int id) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
if (id == DIALOG_DLE) {
builder.setTitle("删除录音");
builder.setPositiveButton("确定", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if(ChckItem.delete()){
Toast.makeText(getApplicationContext(), "删除成功", Toast.LENGTH_SHORT).show();
}
getData();
}
});
builder.setNegativeButton("取消", null);
builder.show();
} else {
final EditText editText = new EditText(this);
builder.setTitle("重命名文件");
builder.setView(editText);
editText.setText(ChckItem.getName());
builder.setPositiveButton("确定", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if(ChckItem.renameTo(new File(ChckItem.getParentFile()
.getAbsoluteFile()
+ "/"
+ editText.getText()))){
Toast.makeText(getApplicationContext(), "重命名成功", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(getApplicationContext(), "重命名失败", Toast.LENGTH_SHORT).show();
}
getData();
}
});
builder.setNegativeButton("取消", null);
builder.show();
}
return super.onCreateDialog(id);
}
public void onClick(View v) {
System.out.println(IsRecording);
switch (v.getId()) {
case R.id.button_record:
if(IsRecording){
// intentServ.putExtra("Audio", "ON");
// startService(intentServ);
buttonRecord.setText("开始录音");
IsRecording = false;
recordServeice.doStop();
getData();
}else{
// intentServ.putExtra("Audio", "OFF");
// startService(intentServ);
buttonRecord.setText("停止录音");
IsRecording = true;
recordServeice.doRecord();
}
break;
case R.id.button_play:
if(!IsPlay){
ButtonPlay.setBackgroundResource(R.drawable.audio_song_pause);
recordServeice.doPlay(AudioData.get(0).getAbsolutePath());
IsPlay = true;
handler.post(runnable);
}else{
ButtonPlay.setBackgroundResource(R.drawable.audio_song_playing);
recordServeice.doPuse();
handler.removeCallbacks(runnable);
IsPlay = false;
}
break;
case R.id.button_up:
if(index != -1){
if(index > 0){
recordServeice.doPlay(AudioData.get(index-1).getAbsolutePath());
ButtonPlay.setBackgroundResource(R.drawable.audio_song_pause);
IsPlay = true;
}else{
recordServeice.doPlay(AudioData.get(AudioData.size()-1).getAbsolutePath());
ButtonPlay.setBackgroundResource(R.drawable.audio_song_pause);
IsPlay = true;
}
}else{
Toast.makeText(this, "请选择录音", Toast.LENGTH_LONG).show();
}
handler.post(runnable);
break;
case R.id.button_next:
if(index != -1){
if(index > 0){
recordServeice.doPlay(AudioData.get(index+1).getAbsolutePath());
ButtonPlay.setBackgroundResource(R.drawable.audio_song_pause);
IsPlay = true;
}else{
recordServeice.doPlay(AudioData.get(0).getAbsolutePath());
ButtonPlay.setBackgr
没有合适的资源?快使用搜索试试~ 我知道了~
android电话录音源代码
共60个文件
class:20个
png:18个
xml:7个
3星 · 超过75%的资源 需积分: 12 154 下载量 53 浏览量
2012-07-06
19:23:09
上传
评论 4
收藏 367KB ZIP 举报
温馨提示
在通话的同时能够对用户的通话内容进行录音 能够单独录音 能够设置是否通话录音
资源推荐
资源详情
资源评论
收起资源包目录
Vanilla.zip (60个子文件)
Vanilla
.project 843B
project.properties 360B
proguard.cfg 1KB
src
com
giaour
Settings.java 1KB
MyAdapter.java 2KB
VanillaActivity.java 9KB
RecordReceiver.java 2KB
RecordServeice.java 4KB
AndroidManifest.xml 2KB
res
drawable-ldpi
ic_launcher.png 2KB
xml
settings.xml 240B
drawable-hdpi
ic_launcher.png 4KB
vanilla.jpg 54KB
format_music.png 8KB
audio_song_pause.png 445B
theme_1.jpg 38KB
popup_arrow_right.png 266B
audio_title_bg.png 99B
audio_song_playing.png 501B
popup_arrow_left.png 268B
menu
menu.xml 271B
toggle.xml 197B
drawable-mdpi
ic_launcher.png 3KB
layout
list_itme.xml 973B
main.xml 3KB
values
strings.xml 180B
assets
gen
com
giaour
R.java 2KB
.classpath 364B
bin
resources.ap_ 118KB
classes
com
giaour
R$layout.class 403B
R$drawable.class 682B
R$attr.class 316B
VanillaActivity.class 10KB
RecordServeice.class 5KB
VanillaActivity$1.class 1KB
Settings.class 2KB
RecordServeice$LocalBinder.class 592B
R$xml.class 365B
R$id.class 848B
MyAdapter$ViewHolder.class 457B
VanillaActivity$3.class 1KB
RecordReceiver.class 2KB
R.class 549B
R$string.class 403B
R$menu.class 387B
VanillaActivity$4.class 2KB
MyAdapter.class 2KB
VanillaActivity$2.class 1KB
RecordReceiver$MyPhoneStateListener.class 2KB
res
drawable-ldpi
ic_launcher.png 2KB
drawable-hdpi
ic_launcher.png 4KB
format_music.png 8KB
audio_song_pause.png 445B
popup_arrow_right.png 266B
audio_title_bg.png 99B
audio_song_playing.png 501B
popup_arrow_left.png 268B
drawable-mdpi
ic_launcher.png 2KB
classes.dex 20KB
Vanilla.apk 130KB
共 60 条
- 1
giaourcao
- 粉丝: 1
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
前往页