diff --git a/database/v/.gradle/4.6/fileHashes/fileHashes.bin b/database/v/.gradle/4.6/fileHashes/fileHashes.bin index 337df7e..57ffe70 100644 Binary files a/database/v/.gradle/4.6/fileHashes/fileHashes.bin and b/database/v/.gradle/4.6/fileHashes/fileHashes.bin differ diff --git a/database/v/.gradle/4.6/fileHashes/fileHashes.lock b/database/v/.gradle/4.6/fileHashes/fileHashes.lock index 6904733..b1b7c61 100644 Binary files a/database/v/.gradle/4.6/fileHashes/fileHashes.lock and b/database/v/.gradle/4.6/fileHashes/fileHashes.lock differ diff --git a/database/v/.gradle/4.6/javaCompile/classAnalysis.bin b/database/v/.gradle/4.6/javaCompile/classAnalysis.bin index 2a213ee..109a56d 100644 Binary files a/database/v/.gradle/4.6/javaCompile/classAnalysis.bin and b/database/v/.gradle/4.6/javaCompile/classAnalysis.bin differ diff --git a/database/v/.gradle/4.6/javaCompile/javaCompile.lock b/database/v/.gradle/4.6/javaCompile/javaCompile.lock index 0b634a2..fd62d90 100644 Binary files a/database/v/.gradle/4.6/javaCompile/javaCompile.lock and b/database/v/.gradle/4.6/javaCompile/javaCompile.lock differ diff --git a/database/v/.gradle/4.6/javaCompile/taskHistory.bin b/database/v/.gradle/4.6/javaCompile/taskHistory.bin index fe4b443..1091e63 100644 Binary files a/database/v/.gradle/4.6/javaCompile/taskHistory.bin and b/database/v/.gradle/4.6/javaCompile/taskHistory.bin differ diff --git a/database/v/.gradle/4.6/taskHistory/taskHistory.bin b/database/v/.gradle/4.6/taskHistory/taskHistory.bin index 62c84a8..596bdbf 100644 Binary files a/database/v/.gradle/4.6/taskHistory/taskHistory.bin and b/database/v/.gradle/4.6/taskHistory/taskHistory.bin differ diff --git a/database/v/.gradle/4.6/taskHistory/taskHistory.lock b/database/v/.gradle/4.6/taskHistory/taskHistory.lock index b88af7f..3b937be 100644 Binary files a/database/v/.gradle/4.6/taskHistory/taskHistory.lock and b/database/v/.gradle/4.6/taskHistory/taskHistory.lock differ diff --git a/database/v/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/database/v/.gradle/buildOutputCleanup/buildOutputCleanup.lock index 1018d6f..d28546b 100644 Binary files a/database/v/.gradle/buildOutputCleanup/buildOutputCleanup.lock and b/database/v/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/database/v/.idea/workspace.xml b/database/v/.idea/workspace.xml index cb4b43f..449a236 100644 --- a/database/v/.idea/workspace.xml +++ b/database/v/.idea/workspace.xml @@ -39,102 +39,117 @@ - - + + - - + + + + + + + + + + + + + + - - + + + + + + + + + + + - - + + - - - - + + - - + + - - + + + + + + + + - - + + - - + + - - + + - + + + - - - - - + + - - + + - - - - - - - - + + - - + + - - + + - - - - - + + @@ -142,15 +157,6 @@ - - - - - - - - - @@ -2439,16 +2445,16 @@ @@ -2463,18 +2469,6 @@ - - - - - - - - - + + + @@ -2640,10 +2646,9 @@ - + - - + @@ -2651,9 +2656,10 @@ - + - + + @@ -2797,11 +2803,11 @@ - + - + @@ -2811,16 +2817,16 @@ - + - - + + @@ -2874,13 +2880,6 @@ - - - - - - - @@ -2947,13 +2946,6 @@ - - - - - - - @@ -2961,13 +2953,6 @@ - - - - - - - @@ -2980,22 +2965,7 @@ - - - - - - - - - - - - - - - - + @@ -3020,50 +2990,8 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + @@ -3089,16 +3017,6 @@ - - - - - - - - - - @@ -3124,126 +3042,195 @@ - + - - - - - - - + + + + + - + - - + + + + + - + - - + + - + + + + + + + + + + + + + + + + + + + + + + - + - - + + + + + + + + + - + - - + + - + - - - - + + + + + + + + - + - - + + + + + - + - - + + - - + + + + + + + + + - - + + - + - - - - - - - + + + + + + + + + - - + + + + + + + + + + + + + + - - + + - - + + + + + + + + + + + + + + diff --git a/database/v/app/build/intermediates/incremental/mergeDebugResources/compile-file-map.properties b/database/v/app/build/intermediates/incremental/mergeDebugResources/compile-file-map.properties index d437c32..757dff3 100644 --- a/database/v/app/build/intermediates/incremental/mergeDebugResources/compile-file-map.properties +++ b/database/v/app/build/intermediates/incremental/mergeDebugResources/compile-file-map.properties @@ -1,4 +1,4 @@ -#Sun Jan 13 21:00:27 CST 2019 +#Mon Jan 14 18:17:07 CST 2019 C\:\\Users\\cici\\.gradle\\caches\\transforms-1\\files-1.1\\appcompat-v7-27.1.1.aar\\7bd18af0ecc63420c6c9e4912da6757b\\res\\drawable-xxhdpi-v4\\abc_scrubber_primary_mtrl_alpha.9.png=C\:\\Users\\cici\\Desktop\\dingguaguademo\\database\\v\\app\\build\\intermediates\\res\\merged\\debug\\drawable-xxhdpi-v4_abc_scrubber_primary_mtrl_alpha.9.png.flat C\:\\Users\\cici\\.gradle\\caches\\transforms-1\\files-1.1\\appcompat-v7-27.1.1.aar\\7bd18af0ecc63420c6c9e4912da6757b\\res\\drawable-xhdpi-v4\\abc_ic_star_black_16dp.png=C\:\\Users\\cici\\Desktop\\dingguaguademo\\database\\v\\app\\build\\intermediates\\res\\merged\\debug\\drawable-xhdpi-v4_abc_ic_star_black_16dp.png.flat C\:\\Users\\cici\\.gradle\\caches\\transforms-1\\files-1.1\\appcompat-v7-27.1.1.aar\\7bd18af0ecc63420c6c9e4912da6757b\\res\\drawable-xxhdpi-v4\\abc_text_select_handle_right_mtrl_light.png=C\:\\Users\\cici\\Desktop\\dingguaguademo\\database\\v\\app\\build\\intermediates\\res\\merged\\debug\\drawable-xxhdpi-v4_abc_text_select_handle_right_mtrl_light.png.flat diff --git a/database/v/app/build/intermediates/merged_manifests/debug/processDebugManifest/merged/AndroidManifest.xml b/database/v/app/build/intermediates/merged_manifests/debug/processDebugManifest/merged/AndroidManifest.xml index a7dc423..ab3dc48 100644 --- a/database/v/app/build/intermediates/merged_manifests/debug/processDebugManifest/merged/AndroidManifest.xml +++ b/database/v/app/build/intermediates/merged_manifests/debug/processDebugManifest/merged/AndroidManifest.xml @@ -58,12 +58,12 @@ android:theme="@android:style/Theme.Translucent.NoTitleBar" android:windowSoftInputMode="stateHidden|adjustResize" /> - + - + - + - + diff --git a/database/v/app/src/main/java/com/example/cici/bean/MyDB.java b/database/v/app/src/main/java/com/example/cici/bean/MyDB.java deleted file mode 100644 index 834fa53..0000000 --- a/database/v/app/src/main/java/com/example/cici/bean/MyDB.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.example.cici.bean; - - - -import android.content.Context; -import android.database.sqlite.SQLiteDatabase; -import android.database.sqlite.SQLiteOpenHelper; - - -public class MyDB extends SQLiteOpenHelper { - public final static String TABLE_NAME_RECORD = "record"; - - public final static String RECORD_ID = "_id"; - public final static String RECORD_TITLE = "title_name"; - public final static String RECORD_BODY = "text_body"; - public final static String RECORD_TIME = "create_time"; - public final static String NOTICE_TIME ="notice_time"; - public final static String RECORD_VOICEURL = "voice_url"; - - - public MyDB(Context context) { - super(context, "21.db", null, 1); - } - - @Override - public void onCreate(SQLiteDatabase db) { - db.execSQL("CREATE TABLE "+TABLE_NAME_RECORD+" ("+RECORD_ID+" INTEGER PRIMARY KEY AUTOINCREMENT," + - RECORD_TITLE+" VARCHAR(30)," + - RECORD_BODY+" TEXT," + - RECORD_TIME+" DATETIME NOT NULL," + - RECORD_VOICEURL+" VARCHAR(30)," + - NOTICE_TIME+" DATETIME)"); - } - - @Override - public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { - } -} \ No newline at end of file diff --git a/database/v/app/src/main/java/com/example/cici/bean/Record.java b/database/v/app/src/main/java/com/example/cici/bean/Record.java index 784ef72..b70b4df 100644 --- a/database/v/app/src/main/java/com/example/cici/bean/Record.java +++ b/database/v/app/src/main/java/com/example/cici/bean/Record.java @@ -1,12 +1,17 @@ package com.example.cici.bean; -public class Record { +import java.util.List; + +import cn.bmob.v3.BmobObject; + +public class Record extends BmobObject { private Integer id; private String titleName; private String textBody; private String createTime; private String noticeTime; private String voiceurl; + private List voice; public Integer getId() { return id; @@ -51,17 +56,12 @@ public class Record { public void setVoiceurl(String voiceurl) { this.voiceurl = voiceurl; } - @Override - public String toString() { - return "Record{" + - "id=" + id + - ", titleName='" + titleName + '\'' + - ", textBody='" + textBody + '\'' + - ", createTime='" + createTime + '\'' + - ", noticeTime='" + noticeTime + '\'' + - ",voiceulr='"+voiceurl+'\''+ - '}'; - } + public List getVoice() { + return voice; + } + public void setVoice(List voice) { + this.voice = voice; + } } diff --git a/database/v/app/src/main/java/com/example/cici/memoire/AmendActivity.java b/database/v/app/src/main/java/com/example/cici/memoire/AmendActivity.java index 6ec69ef..fb47a22 100644 --- a/database/v/app/src/main/java/com/example/cici/memoire/AmendActivity.java +++ b/database/v/app/src/main/java/com/example/cici/memoire/AmendActivity.java @@ -1,10 +1,9 @@ package com.example.cici.memoire; + import android.annotation.SuppressLint; -import android.content.ContentValues; import android.content.DialogInterface; import android.content.Intent; -import android.database.sqlite.SQLiteDatabase; import android.media.MediaPlayer; import android.media.MediaRecorder; import android.os.Bundle; @@ -15,9 +14,10 @@ import android.support.v7.app.AlertDialog; import android.util.Log; import android.view.KeyEvent; import android.view.View; +import android.widget.AdapterView; import android.widget.Button; import android.widget.EditText; -import android.widget.RelativeLayout; +import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; @@ -28,29 +28,37 @@ import java.io.FileOutputStream; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; +import java.util.List; import java.util.Timer; import java.util.TimerTask; import com.example.cici.adapter.MAdapter; -import com.example.cici.bean.MyDB; import com.example.cici.bean.Record; import com.example.cici.voice.R; -public class AmendActivity extends BaseActivity implements View.OnClickListener{ +import cn.bmob.v3.exception.BmobException; +import cn.bmob.v3.listener.UpdateListener; + + +public class AmendActivity extends BaseActivity implements View.OnClickListener,AdapterView.OnItemClickListener { private final static String TAG = "AmendActivity"; - MyDB myDB; + private Record record=new Record(); private Button btnSave; private Button btnBack; private TextView amendTime; private TextView amendTitle; private EditText amendBody; - private Record record; private AlertDialog.Builder dialog; + private String obj; + private String getpath; - private Button btnUpcoming; private Button btnNotice; + private MediaPlayer mPlayer = null;// 播放器 + private String path = ""; + private String fileName = null; + private long limitTime = 0;// 录音文件最短事件1秒 private Button startRecord; private MediaRecorder mRecorder = null;// 录音器 private boolean isPause = false;// 当前录音是否处于暂停状态 @@ -60,25 +68,21 @@ public class AmendActivity extends BaseActivity implements View.OnClickListener{ private Timer timer; private String playFileName = null;// 选中的播放文件 // 相关变量 - private int second = 0; - private int minute = 0; - private int hour = 0; + private int s = 0; + private int m= 0; + private int h = 0; private TextView stopRecord; private TextView time;// 计时显示 private MAdapter mAdapter; private TextView playRecord; - private MediaPlayer mPlayer = null;// 播放器 - private String path = ""; - private String fileName = null; - private long limitTime = 0;// 录音文件最短事件1秒 - + private View whichSelecte = null;// 记录被选中的Item + private ListView mListView;// 音频文件列表 + private ArrayList voiceList = new ArrayList<>(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.amend_linear_layout); - path = Environment.getExternalStorageDirectory().getAbsolutePath() - + "/Anhry/" + getPackageName() + "/Record"; init(); } @@ -88,6 +92,8 @@ public class AmendActivity extends BaseActivity implements View.OnClickListener{ public void onClick(View v) { String body; body = amendBody.getText().toString(); + path = Environment.getExternalStorageDirectory().getAbsolutePath() + + "/Anhry/" + getPackageName() + "/Record"; switch (v.getId()){ case R.id.button_save: if (updateFunction(body)){ @@ -139,13 +145,96 @@ public class AmendActivity extends BaseActivity implements View.OnClickListener{ } } + + @Override + public boolean onKeyDown(int keyCode, KeyEvent event) { + if (keyCode == KeyEvent.KEYCODE_BACK) { + //当返回按键被按下 + if (!isShowIng()){ + showDialog(amendBody.getText().toString()); + clearDialog(); + } + } + return false; + } + + /* + * 初始化函数 + */ + @SuppressLint("SetTextI18n") + void init(){ + btnBack = findViewById(R.id.button_back); + btnSave = findViewById(R.id.button_save); + amendTitle = findViewById(R.id.amend_title); + amendBody = findViewById(R.id.amend_body); + amendTime = findViewById(R.id.amend_title_time); + playRecord=findViewById(R.id.amend_playRecord); + stopRecord=findViewById(R.id.amend_stopRecord); + startRecord=findViewById(R.id.btn_amend_menu_startRecord); + btnNotice = findViewById(R.id.btn_amend_menu_notice); + time=findViewById(R.id.amend_time); + mListView = (ListView) findViewById(R.id.listview); + mAdapter = new MAdapter(this, list); + mListView.setAdapter(mAdapter); + mListView.setOnItemClickListener(this); + btnSave.setOnClickListener(this); + btnBack.setOnClickListener(this); + + startRecord.setOnClickListener(this); + stopRecord.setOnClickListener(this); + playRecord.setOnClickListener(this); + btnNotice.setOnClickListener(this); + + Intent intent = this.getIntent(); + if (intent!=null){ + + amendTitle.setText(intent.getStringExtra("titleName")); + String str=""; + if (intent.getStringExtra("noticeTime")!=null){ + str = " 提醒时间:"+intent.getStringExtra("noticeTime"); + } + amendTime.setText(intent.getStringExtra("createTime")+str); + amendBody.setText(intent.getStringExtra("textBody")); + getpath=intent.getStringExtra("voiceurl"); + obj=intent.getStringExtra("obj"); + voiceList=intent.getStringArrayListExtra("voice"); + initVoice(voiceList); + //playRecord.setText(getpath); + record.setObjectId(obj); + } + } + /* + 录音 + + */ + public void initVoice(List voiceList) { + + if (voiceList.size() > 0) { + ArrayList voicelist= new ArrayList<>(); + for (int j = 0; j < voiceList.size(); j++) { + list.add(voiceList.get(j)); + mAdapter.notifyDataSetChanged(); + } + } + } + @Override + public void onItemClick(AdapterView parent, View view, int position, + long id) { + + + // 列表文件的选中效果 + if (whichSelecte != null) { + whichSelecte + .setBackgroundColor(getResources().getColor(R.color.no)); + } + view.setBackgroundColor(getResources().getColor(R.color.yes)); + // 要播放文件的路径 + playFileName = path + "/" + list.get(position); + whichSelecte = view; + time.setText(list.get(position)); + } private void playRecord() { // 对按钮的可点击事件的控制是保证不出现空指针的重点!! - startRecord.setEnabled(false); - //delete.setEnabled(false); - //stopPlay.setEnabled(true); - //startPlay.setEnabled(false); - //pausePlay.setEnabled(true); if (mPlayer != null) { mPlayer.release(); mPlayer = null; @@ -160,10 +249,7 @@ public class AmendActivity extends BaseActivity implements View.OnClickListener{ mPlayer.release(); mPlayer = null; startRecord.setEnabled(true); - // startPlay.setEnabled(true); - // stopPlay.setEnabled(false); - //delete.setEnabled(true); - //pausePlay.setEnabled(false); + } }); try { @@ -179,9 +265,7 @@ public class AmendActivity extends BaseActivity implements View.OnClickListener{ mPlayer = null; } Toast.makeText(this, "播放失败,可返回重试!", Toast.LENGTH_LONG).show(); - // stopPlay.setEnabled(false); - //delete.setEnabled(true); - //pausePlay.setEnabled(false); + } } private boolean limitTime() { @@ -246,9 +330,9 @@ public class AmendActivity extends BaseActivity implements View.OnClickListener{ e.printStackTrace(); } // 录音结束 、时间归零 - minute= 0; - hour= 0; - second= 0; + m = 0; + h = 0; + s = 0; } // 不管合成是否成功、删除录音片段 for (int i = 0; i < mList.size(); i++) { @@ -324,8 +408,8 @@ public class AmendActivity extends BaseActivity implements View.OnClickListener{ @Override public void handleMessage(Message msg) { time.setText("您本次的录音时长为: " - + String.format("%1$02d:%2$02d:%3$02d", hour, minute, - second)); + + String.format("%1$02d:%2$02d:%3$02d", h, m, + s)); super.handleMessage(msg); } }; @@ -336,13 +420,13 @@ public class AmendActivity extends BaseActivity implements View.OnClickListener{ @Override public void run() { - second++; - if (second>= 60) { - second= 0; - minute++; - if (minute >= 60) { - minute = 0; - hour++; + s++; + if (s >= 60) { + s= 0; + m++; + if (m >= 60) { + m = 0; + h++; } } handler.sendEmptyMessage(1); @@ -360,65 +444,6 @@ public class AmendActivity extends BaseActivity implements View.OnClickListener{ String time = formatter.format(curDate); return time; } - @Override - public boolean onKeyDown(int keyCode, KeyEvent event) { - if (keyCode == KeyEvent.KEYCODE_BACK) { - //当返回按键被按下 - if (!isShowIng()){ - showDialog(amendBody.getText().toString()); - clearDialog(); - } - } - return false; - } - - /* - * 初始化函数 - */ - @SuppressLint("SetTextI18n") - void init(){ - myDB = new MyDB(this); - btnBack = findViewById(R.id.button_back); - btnSave = findViewById(R.id.button_save); - amendTitle = findViewById(R.id.amend_title); - amendBody = findViewById(R.id.amend_body); - amendTime = findViewById(R.id.amend_title_time); - startRecord=findViewById(R.id.btn_amend_menu_startRecord); - stopRecord=findViewById(R.id.amend_stopRecord); - playRecord=findViewById(R.id.amend_playRecord); - time=findViewById(R.id.amend_time); - btnNotice = findViewById(R.id.btn_amend_menu_notice); - - btnSave.setOnClickListener(this); - btnBack.setOnClickListener(this); - - btnNotice.setOnClickListener(this); - btnUpcoming.setOnClickListener(this); - startRecord.setOnClickListener(this); - stopRecord.setOnClickListener(this); - playRecord.setOnClickListener(this); - - Intent intent = this.getIntent(); - if (intent!=null){ - - record = new Record(); - - record.setId(Integer.valueOf(intent.getStringExtra(MyDB.RECORD_ID))); - record.setTitleName(intent.getStringExtra(MyDB.RECORD_TITLE)); - record.setTextBody(intent.getStringExtra(MyDB.RECORD_BODY)); - record.setCreateTime(intent.getStringExtra(MyDB.RECORD_TIME)); - record.setNoticeTime(intent.getStringExtra(MyDB.NOTICE_TIME)); - record.setVoiceurl(intent.getStringExtra(MyDB.RECORD_VOICEURL)); - - amendTitle.setText(record.getTitleName()); - String str=""; - if (record.getNoticeTime()!=null){ - str = " 提醒时间:"+record.getNoticeTime(); - } - amendTime.setText(record.getCreateTime()+str); - amendBody.setText(record.getTextBody()); - } - } /* * 返回主界面 @@ -434,8 +459,6 @@ public class AmendActivity extends BaseActivity implements View.OnClickListener{ */ boolean updateFunction(String body){ - SQLiteDatabase db; - ContentValues values; boolean flag = true; if (body.length()>200){ @@ -444,15 +467,17 @@ public class AmendActivity extends BaseActivity implements View.OnClickListener{ } if(flag){ // update - db = myDB.getWritableDatabase(); - values = new ContentValues(); - values.put(MyDB.RECORD_BODY,body); - values.put(MyDB.RECORD_TIME,getNowTime()); - values.put(MyDB.RECORD_VOICEURL,path); - db.update(MyDB.TABLE_NAME_RECORD,values,MyDB.RECORD_ID +"=?", - new String[]{record.getId().toString()}); + Record record=new Record(); + record.setTextBody(body); + record.setCreateTime(getNowTime()); + record.update(record.getObjectId(), new UpdateListener() { + @Override + public void done(BmobException e) { + + } + }); Toast.makeText(this,"修改成功",Toast.LENGTH_SHORT).show(); - db.close(); + } return flag; } diff --git a/database/v/app/src/main/java/com/example/cici/memoire/EditActivity.java b/database/v/app/src/main/java/com/example/cici/memoire/EditActivity.java index 6a79e38..b52bb99 100644 --- a/database/v/app/src/main/java/com/example/cici/memoire/EditActivity.java +++ b/database/v/app/src/main/java/com/example/cici/memoire/EditActivity.java @@ -2,12 +2,9 @@ package com.example.cici.memoire; import android.annotation.SuppressLint; import android.app.DatePickerDialog; -import android.app.ProgressDialog; import android.app.TimePickerDialog; -import android.content.ContentValues; import android.content.DialogInterface; import android.content.Intent; -import android.database.sqlite.SQLiteDatabase; import android.icu.util.Calendar; import android.media.MediaPlayer; import android.media.MediaRecorder; @@ -21,9 +18,11 @@ import android.support.v7.app.AlertDialog; import android.util.Log; import android.view.KeyEvent; import android.view.View; +import android.widget.AdapterView; import android.widget.Button; import android.widget.DatePicker; import android.widget.EditText; +import android.widget.ListView; import android.widget.TextView; import android.widget.TimePicker; import android.widget.Toast; @@ -32,7 +31,6 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; -import java.text.Format; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; @@ -40,21 +38,23 @@ import java.util.Timer; import java.util.TimerTask; import com.example.cici.adapter.MAdapter; -import com.example.cici.bean.MyDB; +import com.example.cici.bean.Record; import com.example.cici.utils.DateFormatType; import com.example.cici.utils.MyFormat; import com.example.cici.utils.MyTimeGetter; import com.example.cici.voice.R; +import cn.bmob.v3.exception.BmobException; +import cn.bmob.v3.listener.SaveListener; + import static com.example.cici.utils.MyFormat.*; @RequiresApi(api = Build.VERSION_CODES.N) public class EditActivity extends BaseActivity implements View.OnClickListener, DatePickerDialog.OnDateSetListener, - TimePickerDialog.OnTimeSetListener{ + TimePickerDialog.OnTimeSetListener,AdapterView.OnItemClickListener { private final static String TAG = "EditActivity"; - MyDB myDB; private Button btnSave; private Button btnBack; private TextView editTime; @@ -77,6 +77,7 @@ public class EditActivity extends BaseActivity implements View.OnClickListener, private boolean timeSetTag; MyTimeGetter myTimeGetter; + private ListView mListView;// 音频文件列表 private MediaPlayer mPlayer = null;// 播放器 private String path = ""; private String fileName = null; @@ -97,6 +98,7 @@ public class EditActivity extends BaseActivity implements View.OnClickListener, private TextView time;// 计时显示 private MAdapter mAdapter; private TextView playRecord; + private View whichSelecte = null;// 记录被选中的Item @Override @@ -113,7 +115,6 @@ public class EditActivity extends BaseActivity implements View.OnClickListener, */ void init(){ mAdapter = new MAdapter(this, list); - myDB = new MyDB(this); btnBack = findViewById(R.id.button_back); btnSave = findViewById(R.id.button_save); editTitle = findViewById(R.id.edit_title); @@ -136,6 +137,10 @@ public class EditActivity extends BaseActivity implements View.OnClickListener, startRecord.setOnClickListener(this); stopRecord.setOnClickListener(this); playRecord.setOnClickListener(this); + mListView = (ListView) findViewById(R.id.listview); + mAdapter = new MAdapter(this, list); + mListView.setAdapter(mAdapter); + mListView.setOnItemClickListener(this); Date date = new Date(System.currentTimeMillis()); createDate = myDateFormat(date,DateFormatType.NORMAL_TIME); @@ -187,6 +192,8 @@ public class EditActivity extends BaseActivity implements View.OnClickListener, String body; title = editTitle.getText().toString(); body = editBody.getText().toString(); + path = Environment.getExternalStorageDirectory().getAbsolutePath() + + "/Anhry/" + getPackageName() + "/Record"; switch (v.getId()){ case R.id.button_save: if (saveFunction(title,body,createDate)){ @@ -227,6 +234,7 @@ public class EditActivity extends BaseActivity implements View.OnClickListener, if (isPause) { // 完成录音 stopRecord(); + playRecord.setVisibility(View.VISIBLE); } else { // 暂停录音 try { @@ -245,16 +253,32 @@ public class EditActivity extends BaseActivity implements View.OnClickListener, default: break; } - path = Environment.getExternalStorageDirectory().getAbsolutePath() - + "/Anhry/" + getPackageName() + "/Record"; + } /* 录音 */ + @Override + public void onItemClick(AdapterView parent, View view, int position, + long id) { + // 屏蔽点击事件的一种方式 + + + // 列表文件的选中效果 + if (whichSelecte != null) { + whichSelecte + .setBackgroundColor(getResources().getColor(R.color.no)); + } + view.setBackgroundColor(getResources().getColor(R.color.yes)); + // 要播放文件的路径 + playFileName = path + "/" + list.get(position); + whichSelecte = view; + time.setText(list.get(position)); + } private void playRecord() { // 对按钮的可点击事件的控制是保证不出现空指针的重点!! - startRecord.setEnabled(false); + // startRecord.setEnabled(false); //delete.setEnabled(false); //stopPlay.setEnabled(true); //startPlay.setEnabled(false); @@ -272,7 +296,7 @@ public class EditActivity extends BaseActivity implements View.OnClickListener, // 播放完毕改变状态,释放资源 mPlayer.release(); mPlayer = null; - startRecord.setEnabled(true); + //startRecord.setEnabled(true); // startPlay.setEnabled(true); // stopPlay.setEnabled(false); //delete.setEnabled(true); @@ -346,6 +370,7 @@ public class EditActivity extends BaseActivity implements View.OnClickListener, } } list.add(fileName1); + //playRecord.setText(fileName1); mAdapter.notifyDataSetChanged(); } catch (Exception e) { // 这里捕获流的IO异常,万一系统错误需要提示用户 @@ -380,7 +405,6 @@ public class EditActivity extends BaseActivity implements View.OnClickListener, Toast.makeText(this, "录音时间长度不得低于1秒钟!", Toast.LENGTH_SHORT).show(); return ; } - stopRecord.setEnabled(true); mRecorder.stop(); mRecorder.release(); timer.cancel(); @@ -396,8 +420,6 @@ public class EditActivity extends BaseActivity implements View.OnClickListener, private void startRecord() { stopRecord.setText("暂停录音"); startRecord.setText("录音中..."); - startRecord.setEnabled(false); - stopRecord.setEnabled(true); if (!isPause) { // 新录音清空列表 mList.clear(); @@ -419,8 +441,6 @@ public class EditActivity extends BaseActivity implements View.OnClickListener, } catch (Exception e) { // 若录音器启动失败就需要重启应用,屏蔽掉按钮的点击事件。 否则会出现各种异常。 Toast.makeText(this, "录音器启动失败,请返回重试!", Toast.LENGTH_LONG).show(); - startRecord.setEnabled(false); - stopRecord.setEnabled(false); mRecorder.release(); mRecorder = null; this.finish(); @@ -505,32 +525,37 @@ public class EditActivity extends BaseActivity implements View.OnClickListener, flag = false; } - if(flag){ - SQLiteDatabase db; - ContentValues values; + if(flag) { + // 存储备忘录信息 - db = myDB.getWritableDatabase(); - values = new ContentValues(); - values.put(MyDB.RECORD_TITLE,title); - values.put(MyDB.RECORD_BODY,body); - values.put(MyDB.RECORD_TIME,createDate); - values.put(MyDB.RECORD_VOICEURL,path); - if (timeSetTag){ + Record record = new Record(); + record.setTitleName(title); + record.setCreateTime(createDate); + record.setTextBody(body); + record.setVoiceurl(fileName); + record.setVoice(list); + + if (timeSetTag) { // 为当前备忘录添加提醒 DatePicker datePicker = dialogDate.getDatePicker(); - String str = datePicker.getYear()+"-"+ - (datePicker.getMonth()+1)+"-"+ - datePicker.getDayOfMonth()+" "+ - MyFormat.timeFormat(hour,minute); - values.put(MyDB.NOTICE_TIME,str); + String str = datePicker.getYear() + "-" + + (datePicker.getMonth() + 1) + "-" + + datePicker.getDayOfMonth() + " " + + MyFormat.timeFormat(hour, minute); + record.setNoticeTime(str); } - db.insert(MyDB.TABLE_NAME_RECORD,null,values); - Toast.makeText(this,"保存成功",Toast.LENGTH_SHORT).show(); - db.close(); + record.save(new SaveListener() { + @Override + public void done(String s, BmobException e) { + + } + }); + Toast.makeText(this, "保存成功", Toast.LENGTH_SHORT).show(); } return flag; } + /* * 弹窗函数 * @param title diff --git a/database/v/app/src/main/java/com/example/cici/memoire/MainActivity.java b/database/v/app/src/main/java/com/example/cici/memoire/MainActivity.java index 3e87a05..c9ca117 100644 --- a/database/v/app/src/main/java/com/example/cici/memoire/MainActivity.java +++ b/database/v/app/src/main/java/com/example/cici/memoire/MainActivity.java @@ -5,8 +5,6 @@ import android.annotation.SuppressLint; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; -import android.database.Cursor; -import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; @@ -23,11 +21,16 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; -import com.example.cici.bean.MyDB; + import com.example.cici.bean.Record; import com.example.cici.utils.DateFormatType; import com.example.cici.voice.R; +import cn.bmob.v3.BmobQuery; +import cn.bmob.v3.exception.BmobException; +import cn.bmob.v3.listener.FindListener; +import cn.bmob.v3.listener.UpdateListener; + import static com.example.cici.utils.MyFormat.*; public class MainActivity extends BaseActivity implements View.OnClickListener, @@ -35,10 +38,10 @@ public class MainActivity extends BaseActivity implements View.OnClickListener, private final static String TAG = "MainActivity"; - MyDB myDB; private ListView myListView; private Button createButton; private MyBaseAdapter myBaseAdapter; + private List recordList; @Override protected void onCreate(Bundle savedInstanceState) { @@ -53,37 +56,24 @@ public class MainActivity extends BaseActivity implements View.OnClickListener, createButton.setOnClickListener(this); myListView = findViewById(R.id.list_view); + recordList = new ArrayList<>(); + BmobQuery query = new BmobQuery<>(); + query.order("-createdAt"); + query.setLimit(20); + query.findObjects(new FindListener() { + @Override + public void done(List lists, BmobException e) { + if (e == null) { + + recordList=lists; + myBaseAdapter.addRecord(recordList); + myBaseAdapter.notifyDataSetChanged(); + + } - List recordList = new ArrayList<>(); - myDB = new MyDB(this); - SQLiteDatabase db = myDB.getReadableDatabase(); - Cursor cursor = db.query(MyDB.TABLE_NAME_RECORD,null, - null,null,null, - null,MyDB.NOTICE_TIME+","+MyDB.RECORD_TIME+" DESC"); - if(cursor.moveToFirst()){ - Record record; - while (!cursor.isAfterLast()){ - record = new Record(); - record.setId( - Integer.valueOf(cursor.getString(cursor.getColumnIndex(MyDB.RECORD_ID)))); - record.setTitleName( - cursor.getString(cursor.getColumnIndex(MyDB.RECORD_TITLE)) - ); - record.setTextBody( - cursor.getString(cursor.getColumnIndex(MyDB.RECORD_BODY)) - ); - record.setCreateTime( - cursor.getString(cursor.getColumnIndex(MyDB.RECORD_TIME))); - record.setNoticeTime( - cursor.getString(cursor.getColumnIndex(MyDB.NOTICE_TIME))); - record.setVoiceurl( - cursor.getString(cursor.getColumnIndex(MyDB.RECORD_VOICEURL))); - recordList.add(record); - cursor.moveToNext(); - } } - cursor.close(); - db.close(); + }); + // 创建一个Adapter的实例 myBaseAdapter = new MyBaseAdapter(this,recordList,R.layout.list_item); myListView.setAdapter(myBaseAdapter); @@ -109,14 +99,16 @@ public class MainActivity extends BaseActivity implements View.OnClickListener, public void onItemClick(AdapterView parent, View view, int position, long id) { Intent intent = new Intent(MainActivity.this,AmendActivity.class); Record record = (Record) myListView.getItemAtPosition(position); - intent.putExtra(MyDB.RECORD_TITLE,record.getTitleName().trim()); - intent.putExtra(MyDB.RECORD_BODY,record.getTextBody().trim()); - intent.putExtra(MyDB.RECORD_TIME,record.getCreateTime().trim()); - intent.putExtra(MyDB.RECORD_ID,record.getId().toString().trim()); - intent.putExtra(MyDB.RECORD_VOICEURL,record.getVoiceurl().toString().trim()); + intent.putExtra("titleName",record.getTitleName().trim()); + intent.putExtra("textBody",record.getTextBody().trim()); + intent.putExtra("createTime",record.getCreateTime().trim()); + intent.putExtra("id",record.toString().trim()); + intent.putExtra("voiceurl",record.getVoiceurl().trim()); + intent.putStringArrayListExtra("voice",(ArrayList)record.getVoice()); if (record.getNoticeTime()!=null) { - intent.putExtra(MyDB.NOTICE_TIME, record.getNoticeTime().trim()); + intent.putExtra("noticeTime", record.getNoticeTime().trim()); } + intent.putExtra("obj",record.getObjectId()); this.startActivity(intent); MainActivity.this.finish(); } @@ -140,18 +132,25 @@ public class MainActivity extends BaseActivity implements View.OnClickListener, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - SQLiteDatabase db = myDB.getWritableDatabase(); - db.delete(MyDB.TABLE_NAME_RECORD, - MyDB.RECORD_ID +"=?", - new String[]{String.valueOf(record.getId())}); - db.close(); - myBaseAdapter.removeItem(position); - myListView.post(new Runnable() { + + record.setObjectId(record.getObjectId()); + record.delete(new UpdateListener() { @Override - public void run() { - myBaseAdapter.notifyDataSetChanged(); + public void done(BmobException e) { + if (e == null) { + + } else { + + } } }); + myBaseAdapter.removeItem(position); + myListView.post(new Runnable() { + @Override + public void run() { + myBaseAdapter.notifyDataSetChanged(); + } + }); } }); dialog.setNegativeButton("取消", @@ -179,6 +178,10 @@ public class MainActivity extends BaseActivity implements View.OnClickListener, this.layoutId = layoutId; } + public void addRecord(List list) { + this.recordList = list; + + } @Override public int getCount() { if (recordList!=null&&recordList.size()>0) diff --git a/database/v/app/src/main/res/layout/amend_linear_layout.xml b/database/v/app/src/main/res/layout/amend_linear_layout.xml index 4d71c3f..b865950 100644 --- a/database/v/app/src/main/res/layout/amend_linear_layout.xml +++ b/database/v/app/src/main/res/layout/amend_linear_layout.xml @@ -38,7 +38,6 @@ android:id="@+id/amend_time_lay" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_above="@+id/listview" android:layout_alignParentStart="true" android:layout_marginBottom="-20dp" android:orientation="vertical"> @@ -61,33 +60,33 @@ android:hint="@string/edit_body_hint" android:textSize="12sp" /> - + + + + +