commit 6cd146c8cfa73888a2e8e2264ef41e2221a19bde Author: sonichy Date: Fri May 19 13:14:55 2023 +0800 first diff --git a/README.md b/README.md new file mode 100644 index 0000000..d542064 --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +# 倒数日 +事件倒数日计算 + +![alt](preview.jpg) + +## 参考 +[制作半圆背景](https://www.shuzhiduo.com/A/B0zqGV35vL/) +[ListView设置选中状态](https://blog.csdn.net/ws_lm/article/details/53764008) \ No newline at end of file diff --git a/main/AndroidManifest.xml b/main/AndroidManifest.xml new file mode 100644 index 0000000..ce67fde --- /dev/null +++ b/main/AndroidManifest.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/main/java/com/hty/daycount/DBHelper.java b/main/java/com/hty/daycount/DBHelper.java new file mode 100644 index 0000000..7a34bab --- /dev/null +++ b/main/java/com/hty/daycount/DBHelper.java @@ -0,0 +1,73 @@ +package com.hty.daycount; + +import android.content.ContentValues; +import android.content.Context; +import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteOpenHelper; + +public class DBHelper extends SQLiteOpenHelper { + public static final String DATABASE_NAME = "event.db"; + private final static int VERSION = 1; + static String TableName = "event"; + private SQLiteDatabase db; + private static DBHelper mInstance = null; + + public DBHelper(Context context) { + super(context, DATABASE_NAME, null, VERSION); + } + + public static synchronized DBHelper getInstance(Context context) { + if (mInstance == null) { + mInstance = new DBHelper(context); + } + return mInstance; + } + + @Override + public void onCreate(SQLiteDatabase db) { + this.db = db; + db.execSQL("CREATE TABLE "+ TableName + " (_id INTEGER PRIMARY KEY , time INTEGER, event TEXT)"); + } + + @Override + public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { + // db.execSQL("DROP TABLE IF EXISTS battery"); + // onCreate(db); + switch (newVersion) { + case 2: + break; + } + } + + public void insert(ContentValues values) { + db = getWritableDatabase(); + db.insert(TableName, null, values); + db.close(); + } + + public Cursor query(String s) { + db = getWritableDatabase(); + Cursor c; + if (s.equals("")) { + c = db.query(TableName, null, null, null, null, null, "time desc"); + } else { + c = db.query(TableName, null, "event LIKE '%" + s + "%'", null, null, null, "time desc"); + } + return c; + } + + public void del(String id) { + if (db == null) + db = getWritableDatabase(); + db.delete(TableName, "_id=?", new String[] { id }); + // Log.e("id", id + ""); + // db.ExecuteNonQuery(CommandType.Text, "VACUUM"); + } + + @Override + public void close() { + if (db != null) + db.close(); + } +} \ No newline at end of file diff --git a/main/java/com/hty/daycount/MainActivity.java b/main/java/com/hty/daycount/MainActivity.java new file mode 100644 index 0000000..b45ffb3 --- /dev/null +++ b/main/java/com/hty/daycount/MainActivity.java @@ -0,0 +1,356 @@ +package com.hty.daycount; + +import android.app.Activity; +import android.app.AlertDialog; +import android.app.SearchManager; +import android.content.ContentValues; +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.util.Log; +import android.view.ContextMenu; +import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.view.inputmethod.InputMethodManager; +import android.widget.AdapterView; +import android.widget.DatePicker; +import android.widget.EditText; +import android.widget.ListView; +import android.widget.SimpleCursorAdapter; +import android.widget.TextView; +import android.widget.Toast; + +import java.lang.reflect.Field; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.List; +import java.util.Locale; + +public class MainActivity extends Activity { + + TextView textView_event1, textView_date, textView_count1, textView_day1; + ListView listView; + SimpleCursorAdapter adapter; + InputMethodManager IMM; + SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd E", Locale.getDefault()); + int position1 = 0; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + IMM = (InputMethodManager) getApplicationContext().getSystemService(Context.INPUT_METHOD_SERVICE); + textView_event1 = (TextView) findViewById(R.id.textView_event1); + textView_date = (TextView) findViewById(R.id.textView_date); + textView_count1 = (TextView) findViewById(R.id.textView_count1); + textView_day1 = (TextView) findViewById(R.id.textView_day1); + Date date = new Date(); + textView_date.setText(SDF.format(date)); + listView = (ListView) findViewById(R.id.listView); + listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); + search(""); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + String[] sm = { "刷新", "添加", "更新日志", "关于", "退出" }; + for (int i=0; i= 0) + view.setBackgroundResource(R.drawable.count_bg); + else + view.setBackgroundResource(R.drawable.count_bg1); + ((TextView)view).setText(Math.abs(d) + ""); + return true; + } else if (view.getId() == R.id.textView_day) { + Date date = new Date(cursor.getLong(columnIndex)); + Date date1 = new Date(); + long ms = date.getTime() - date1.getTime(); + if (ms >= 0) + view.setBackgroundResource(R.drawable.day_bg); + else + view.setBackgroundResource(R.drawable.day_bg1); + return true; + } + return false; + } + }); + listView.setAdapter(adapter); + listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView adapterView, View view, int position, long id) { + String event = ((TextView) view.findViewById(R.id.textView_event)).getText().toString(); + String stime = ((TextView) view.findViewById(R.id.textView_time)).getText().toString(); + String count = ((TextView) view.findViewById(R.id.textView_count)).getText().toString(); + Date date = new Date(Long.parseLong(stime)); + Date date1 = new Date(); + long ms = date.getTime() - date1.getTime(); + long d = ms / 1000 / 60 / 60 / 24; + if (ms >= 0) + textView_count1.setTextColor(0xff00bfff); + else + textView_count1.setTextColor(0xffffa500); + if (ms >= 0 && d <= 5) + textView_day1.setBackgroundColor(0xffff0000); + else + textView_day1.setBackgroundColor(0x00ff0000); + textView_event1.setText(event); + textView_date.setText(SDF.format(date)); + textView_count1.setText(count); + } + }); + listView.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() { + @Override + public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) { + //AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo; + //String title = ((TextView) info.targetView.findViewById(R.id.title)).getText().toString(); + //menu.setHeaderTitle(title); + String[] sm = { "搜索", "修改", "删除" }; + for (int i=0; i + + + + + + + \ No newline at end of file diff --git a/main/res/drawable/count_bg1.xml b/main/res/drawable/count_bg1.xml new file mode 100644 index 0000000..4ca2335 --- /dev/null +++ b/main/res/drawable/count_bg1.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/main/res/drawable/day_bg.xml b/main/res/drawable/day_bg.xml new file mode 100644 index 0000000..e61a807 --- /dev/null +++ b/main/res/drawable/day_bg.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/main/res/drawable/day_bg1.xml b/main/res/drawable/day_bg1.xml new file mode 100644 index 0000000..1e53469 --- /dev/null +++ b/main/res/drawable/day_bg1.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/main/res/drawable/event_bg.xml b/main/res/drawable/event_bg.xml new file mode 100644 index 0000000..ea19fec --- /dev/null +++ b/main/res/drawable/event_bg.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/main/res/drawable/item_activated.xml b/main/res/drawable/item_activated.xml new file mode 100644 index 0000000..c2f034f --- /dev/null +++ b/main/res/drawable/item_activated.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/main/res/drawable/item_bg.xml b/main/res/drawable/item_bg.xml new file mode 100644 index 0000000..07a31e4 --- /dev/null +++ b/main/res/drawable/item_bg.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/main/res/drawable/item_bg1.xml b/main/res/drawable/item_bg1.xml new file mode 100644 index 0000000..e56a197 --- /dev/null +++ b/main/res/drawable/item_bg1.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/main/res/layout/activity_main.xml b/main/res/layout/activity_main.xml new file mode 100644 index 0000000..33c4024 --- /dev/null +++ b/main/res/layout/activity_main.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/main/res/layout/event_edit.xml b/main/res/layout/event_edit.xml new file mode 100644 index 0000000..3451eea --- /dev/null +++ b/main/res/layout/event_edit.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/main/res/layout/item_event.xml b/main/res/layout/item_event.xml new file mode 100644 index 0000000..ceb53af --- /dev/null +++ b/main/res/layout/item_event.xml @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/main/res/mipmap-hdpi/ic_launcher.png b/main/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 0000000..c0864bd Binary files /dev/null and b/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/main/res/mipmap-mdpi/ic_launcher.png b/main/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 0000000..5f1c129 Binary files /dev/null and b/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/main/res/mipmap-xhdpi/ic_launcher.png b/main/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 0000000..c7cbbc1 Binary files /dev/null and b/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/main/res/mipmap-xxhdpi/ic_launcher.png b/main/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 0000000..157fc25 Binary files /dev/null and b/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/main/res/mipmap-xxxhdpi/ic_launcher.png b/main/res/mipmap-xxxhdpi/ic_launcher.png new file mode 100644 index 0000000..20d6b44 Binary files /dev/null and b/main/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/main/res/values/colors.xml b/main/res/values/colors.xml new file mode 100644 index 0000000..1f3f3a5 --- /dev/null +++ b/main/res/values/colors.xml @@ -0,0 +1,4 @@ + + + #f3f3f3 + \ No newline at end of file diff --git a/main/res/values/strings.xml b/main/res/values/strings.xml new file mode 100644 index 0000000..df4da21 --- /dev/null +++ b/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + 倒数日 + \ No newline at end of file diff --git a/preview.jpg b/preview.jpg new file mode 100644 index 0000000..94add15 Binary files /dev/null and b/preview.jpg differ