forked from hzuapps/android-labs-2018
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
52 changed files
with
1,182 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.example.ibook" | ||
android:versionCode="1" | ||
android:versionName="1.0" > | ||
|
||
<uses-sdk | ||
android:minSdkVersion="8" | ||
android:targetSdkVersion="17" /> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@drawable/icon_app" | ||
android:label="@string/app_names" | ||
android:theme="@style/AppTheme" > | ||
<activity | ||
android:name="com.example.ibook.MainActivity" | ||
android:label="@string/app_names" > | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
<activity | ||
android:name="com.example.ibook.SecondAtivity" | ||
android:label="@string/app_names" > | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package edu.hzuapps.androidlabs.soft1606070302235; | ||
|
||
public class Soft1606070302235Activity{ | ||
|
||
} |
Binary file not shown.
151 changes: 151 additions & 0 deletions
151
Soft1606070302235/java/edu/hzuapps/androidlabs/Soft1606070302235/SecondActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
package edu.hzuapps.androidlabs.soft1606070302235; | ||
|
||
import java.text.SimpleDateFormat; | ||
import java.util.Calendar; | ||
import java.util.Date; | ||
|
||
import com.example.beans.Cuns; | ||
import com.example.luoji.MyDataBase; | ||
import com.example.luoji.MyOpenHelper; | ||
|
||
import android.os.Bundle; | ||
import android.app.Activity; | ||
import android.app.AlertDialog; | ||
import android.content.DialogInterface; | ||
import android.content.Intent; | ||
import android.database.sqlite.SQLiteDatabase; | ||
import android.view.Menu; | ||
import android.view.MenuItem; | ||
import android.view.View; | ||
import android.view.View.OnClickListener; | ||
import android.widget.Button; | ||
import android.widget.EditText; | ||
import android.widget.Toast; | ||
|
||
/* | ||
*用来编辑日记 | ||
*主要包括一个方法,isSave()用来保存数据; | ||
*/ | ||
public class SecondActivity extends Activity { | ||
|
||
EditText ed1,ed2; | ||
Button bt1; | ||
MyDataBase myDatabase; | ||
Cuns cun; | ||
int ids; | ||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_second); | ||
ed1=(EditText) findViewById(R.id.editText1); | ||
ed2=(EditText) findViewById(R.id.editText2); | ||
bt1=(Button) findViewById(R.id.button1); | ||
myDatabase=new MyDataBase(this); | ||
|
||
Intent intent=this.getIntent(); | ||
ids=intent.getIntExtra("ids", 0); | ||
//默认为0,不为0,则为修改数据时跳转过来的 | ||
if(ids!=0){ | ||
cun=myDatabase.getTiandCon(ids); | ||
ed1.setText(cun.getTitle()); | ||
ed2.setText(cun.getContent()); | ||
} | ||
//保存按钮的点击事件,他和返回按钮是一样的功能,所以都调用isSave()方法; | ||
bt1.setOnClickListener(new OnClickListener() { | ||
|
||
@Override | ||
public void onClick(View v) { | ||
// TODO Auto-generated method stub | ||
isSave(); | ||
} | ||
}); | ||
} | ||
/* | ||
* 返回按钮调用的方法。 | ||
* @see android.app.Activity#onBackPressed() | ||
*/ | ||
@Override | ||
public void onBackPressed() { | ||
// TODO Auto-generated method stub | ||
//super.onBackPressed(); | ||
SimpleDateFormat formatter = new SimpleDateFormat ("yyyy.MM.dd HH:mm:ss"); | ||
Date curDate = new Date(System.currentTimeMillis());//获取当前时间 | ||
String times = formatter.format(curDate); | ||
String title=ed1.getText().toString(); | ||
String content=ed2.getText().toString(); | ||
//是要修改数据 | ||
if(ids!=0){ | ||
cun=new Cuns(title,ids, content, times); | ||
myDatabase.toUpdate(cun); | ||
Intent intent=new Intent(SecondActivity.this,Soft1606070302235Activity.class); | ||
startActivity(intent); | ||
SecondActivity.this.finish(); | ||
} | ||
//新建日记 | ||
else{ | ||
if(title.equals("")&&content.equals("")){ | ||
Intent intent=new Intent(SecondActivity.this,Soft1606070302235Activity.class); | ||
startActivity(intent); | ||
SecondActivity.this.finish(); | ||
} | ||
else{ | ||
cun=new Cuns(title,content,times); | ||
myDatabase.toInsert(cun); | ||
Intent intent=new Intent(SecondActivity.this,Soft1606070302235Activity.class); | ||
startActivity(intent); | ||
SecondActivity.this.finish(); | ||
} | ||
|
||
} | ||
} | ||
private void isSave(){ | ||
SimpleDateFormat formatter = new SimpleDateFormat ("yyyy.MM.dd HH:mm:ss"); | ||
Date curDate = new Date(System.currentTimeMillis());//获取当前时间 | ||
String times = formatter.format(curDate); | ||
String title=ed1.getText().toString(); | ||
String content=ed2.getText().toString(); | ||
//是要修改数据 | ||
if(ids!=0){ | ||
cun=new Cuns(title,ids, content, times); | ||
myDatabase.toUpdate(cun); | ||
Intent intent=new Intent(SecondActivity.this,Soft1606070302235Activity.class); | ||
startActivity(intent); | ||
SecondActivity.this.finish(); | ||
} | ||
//新建日记 | ||
else{ | ||
cun=new Cuns(title,content,times); | ||
myDatabase.toInsert(cun); | ||
Intent intent=new Intent(SecondActivity.this,Soft1606070302235Activity.class); | ||
startActivity(intent); | ||
SecondActivity.this.finish(); | ||
} | ||
} | ||
|
||
|
||
@Override | ||
public boolean onCreateOptionsMenu(Menu menu) { | ||
// Inflate the menu; this adds items to the action bar if it is present. | ||
getMenuInflater().inflate(R.menu.second_activity, menu); | ||
return true; | ||
} | ||
@Override | ||
public boolean onOptionsItemSelected(MenuItem item) { | ||
// TODO Auto-generated method stub | ||
switch (item.getItemId()) { | ||
case R.id.action_settings: | ||
Intent intent=new Intent(Intent.ACTION_SEND); | ||
intent.setType("text/plain"); | ||
intent.putExtra(Intent.EXTRA_TEXT, "标题:"+ed1.getText().toString()+" 内容:"+ed2.getText().toString()); | ||
startActivity(intent); | ||
break; | ||
|
||
default: | ||
break; | ||
} | ||
return false; | ||
} | ||
|
||
|
||
} | ||
|
149 changes: 149 additions & 0 deletions
149
...06070302235/java/edu/hzuapps/androidlabs/Soft1606070302235/Soft1606070302235Activity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
package edu.hzuapps.androidlabs.soft1606070302235; | ||
import java.util.ArrayList; | ||
|
||
import com.example.beans.Cuns; | ||
import com.example.luoji.MyAdapter; | ||
import com.example.luoji.MyDataBase; | ||
|
||
import android.os.Bundle; | ||
import android.app.Activity; | ||
import android.app.AlertDialog; | ||
import android.content.DialogInterface; | ||
import android.content.Intent; | ||
import android.view.LayoutInflater; | ||
import android.view.Menu; | ||
import android.view.MenuItem; | ||
import android.view.View; | ||
import android.view.View.OnClickListener; | ||
import android.view.View.OnLongClickListener; | ||
import android.widget.AdapterView; | ||
import android.widget.AdapterView.OnItemClickListener; | ||
import android.widget.AdapterView.OnItemLongClickListener; | ||
import android.widget.Button; | ||
import android.widget.ListView; | ||
|
||
/* | ||
* 这个类主要包括五个点击事件,分别为 | ||
* 1,ListView的长按点击事件,用来AlertDialog来判断是否删除数据。 | ||
* 2,ListView的点击事件,跳转到第二个界面,用来修改数据 | ||
* 3,新建便签按钮的点击事件,跳转到第二界面,用来新建便签 | ||
* 4,menu里的退出事件,用来退出程序 | ||
* 5,menu里的新建事件,用来新建便签 | ||
*/ | ||
public class Soft1606070302235Activity extends Activity { | ||
|
||
Button bt; | ||
ListView lv; | ||
LayoutInflater inflater; | ||
ArrayList<Cuns> array; | ||
MyDataBase mdb; | ||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_soft1606070302235); | ||
|
||
lv=(ListView) findViewById(R.id.listView1); | ||
bt=(Button) findViewById(R.id.button1); | ||
inflater=getLayoutInflater(); | ||
|
||
mdb=new MyDataBase(this); | ||
array=mdb.getArray(); | ||
MyAdapter adapter=new MyAdapter(inflater,array); | ||
lv.setAdapter(adapter); | ||
/* | ||
* 点击listView里面的item,进入到第二个页面,用来修改日记 | ||
*/ | ||
lv.setOnItemClickListener(new OnItemClickListener() { | ||
@Override | ||
public void onItemClick(AdapterView<?> parent, View view, | ||
int position, long id) { | ||
// TODO Auto-generated method stub | ||
Intent intent=new Intent(getApplicationContext(),SecondActivity.class); | ||
intent.putExtra("ids",array.get(position).getIds() ); | ||
startActivity(intent); | ||
Soft1606070302235Activity.this.finish(); | ||
} | ||
}); | ||
/* | ||
* 长点后来判断是否删除数据 | ||
*/ | ||
lv.setOnItemLongClickListener(new OnItemLongClickListener() { | ||
|
||
@Override | ||
public boolean onItemLongClick(AdapterView<?> parent, View view, | ||
final int position, long id) { | ||
// TODO Auto-generated method stub | ||
//AlertDialog,来判断是否删除日记。 | ||
new AlertDialog.Builder(Soft1606070302235Activity.this) | ||
.setTitle("删除") | ||
.setMessage("是否删除笔记") | ||
.setNegativeButton("取消", new DialogInterface.OnClickListener() { | ||
|
||
@Override | ||
public void onClick(DialogInterface dialog, int which) { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
}) | ||
.setPositiveButton("确定", new DialogInterface.OnClickListener() { | ||
|
||
@Override | ||
public void onClick(DialogInterface dialog, int which) { | ||
// TODO Auto-generated method stub | ||
mdb.toDelete(array.get(position).getIds()); | ||
array=mdb.getArray(); | ||
MyAdapter adapter=new MyAdapter(inflater,array); | ||
lv.setAdapter(adapter); | ||
} | ||
}) | ||
.create().show(); | ||
return true; | ||
} | ||
}); | ||
/* | ||
* 按钮点击事件,用来新建日记 | ||
*/ | ||
bt.setOnClickListener(new OnClickListener() { | ||
|
||
@Override | ||
public void onClick(View v) { | ||
// TODO Auto-generated method stub | ||
Intent intent=new Intent(getApplicationContext(),SecondActivity.class); | ||
startActivity(intent); | ||
Soft1606070302235Activity.this.finish(); | ||
} | ||
}); | ||
|
||
|
||
|
||
} | ||
|
||
@Override | ||
public boolean onCreateOptionsMenu(Menu menu) { | ||
// Inflate the menu; this adds items to the action bar if it is present. | ||
getMenuInflater().inflate(R.menu.main, menu); | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean onOptionsItemSelected(MenuItem item) { | ||
// TODO Auto-generated method stub | ||
switch (item.getItemId()) { | ||
case R.id.item1: | ||
Intent intent=new Intent(getApplicationContext(),SecondActivity.class); | ||
startActivity(intent); | ||
this.finish(); | ||
break; | ||
case R.id.item2: | ||
this.finish(); | ||
break; | ||
default: | ||
break; | ||
} | ||
return true; | ||
|
||
} | ||
|
||
|
||
} | ||
|
43 changes: 43 additions & 0 deletions
43
Soft1606070302235/java/edu/hzuapps/androidlabs/beans/Cuns.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.example.beans; | ||
/* | ||
* 用来暂时存储数据 | ||
*/ | ||
public class Cuns { | ||
private String title;//标题 | ||
private String content;//内容 | ||
private String times;//时间 | ||
private int ids;//编号 | ||
public Cuns(String ti,int id,String con ,String time){ | ||
this.ids=id; | ||
this.title=ti; | ||
this.content=con; | ||
this.times=time; | ||
} | ||
public Cuns(String ti,String con,String time){ | ||
this.title=ti; | ||
this.content=con; | ||
this.times=time; | ||
} | ||
public Cuns(int i,String ti,String time){ | ||
this.ids=i; | ||
this.title=ti; | ||
this.times=time; | ||
} | ||
public Cuns(String ti,String con){ | ||
this.title=ti; | ||
this.content=con; | ||
} | ||
public int getIds() { | ||
return ids; | ||
} | ||
public String getTitle() { | ||
return title; | ||
} | ||
public String getContent() { | ||
return content; | ||
} | ||
public String getTimes() { | ||
return times; | ||
} | ||
|
||
} |
Oops, something went wrong.