mirror of https://github.com/MiCode/Notes.git
commit
ebe6ba3b5d
|
@ -51,7 +51,7 @@
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".ui.NoteEditActivity"
|
android:name=".ui.NoteEditActivity"
|
||||||
android:configChanges="keyboardHidden|orientation"
|
android:configChanges="keyboardHidden|orientation|screenSize"
|
||||||
android:launchMode="singleTop"
|
android:launchMode="singleTop"
|
||||||
android:theme="@style/NoteTheme" >
|
android:theme="@style/NoteTheme" >
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:layout_gravity="center_horizontal"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<NumberPicker
|
||||||
|
android:id="@+id/date"
|
||||||
|
android:layout_width="120dip"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:focusable="true"
|
||||||
|
android:focusableInTouchMode="true"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<NumberPicker
|
||||||
|
android:id="@+id/hour"
|
||||||
|
android:layout_width="50dip"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginLeft="5dip"
|
||||||
|
android:focusable="true"
|
||||||
|
android:focusableInTouchMode="true"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<NumberPicker
|
||||||
|
android:id="@+id/minute"
|
||||||
|
android:layout_width="50dip"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginLeft="5dip"
|
||||||
|
android:focusable="true"
|
||||||
|
android:focusableInTouchMode="true"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<NumberPicker
|
||||||
|
android:id="@+id/amPm"
|
||||||
|
android:layout_width="50dip"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginLeft="5dip"
|
||||||
|
android:focusable="true"
|
||||||
|
android:focusableInTouchMode="true"
|
||||||
|
/>
|
||||||
|
</LinearLayout>
|
|
@ -37,13 +37,12 @@
|
||||||
<item
|
<item
|
||||||
android:id="@+id/menu_send_to_desktop"
|
android:id="@+id/menu_send_to_desktop"
|
||||||
android:title="@string/menu_send_to_desktop"/>
|
android:title="@string/menu_send_to_desktop"/>
|
||||||
<!--
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/menu_alert"
|
android:id="@+id/menu_alert"
|
||||||
android:title="@string/menu_alert" /> -->
|
android:title="@string/menu_alert" />
|
||||||
|
|
||||||
<!--
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/menu_delete_remind"
|
android:id="@+id/menu_delete_remind"
|
||||||
android:title="@string/menu_remove_remind" /> -->
|
android:title="@string/menu_remove_remind" />
|
||||||
</menu>
|
</menu>
|
||||||
|
|
|
@ -42,12 +42,11 @@
|
||||||
android:id="@+id/menu_send_to_desktop"
|
android:id="@+id/menu_send_to_desktop"
|
||||||
android:title="@string/menu_send_to_desktop"/>
|
android:title="@string/menu_send_to_desktop"/>
|
||||||
|
|
||||||
<!--
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/menu_alert"
|
android:id="@+id/menu_alert"
|
||||||
android:title="@string/menu_alert" /> -->
|
android:title="@string/menu_alert" />
|
||||||
<!--
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/menu_delete_remind"
|
android:id="@+id/menu_delete_remind"
|
||||||
android:title="@string/menu_remove_remind" /> -->
|
android:title="@string/menu_remove_remind" />
|
||||||
</menu>
|
</menu>
|
|
@ -25,6 +25,7 @@
|
||||||
<string name="notelist_string_info">...</string>
|
<string name="notelist_string_info">...</string>
|
||||||
<string name="notelist_menu_new">新建便签</string>
|
<string name="notelist_menu_new">新建便签</string>
|
||||||
<string name="delete_remind_time_message">成功删除提醒</string>
|
<string name="delete_remind_time_message">成功删除提醒</string>
|
||||||
|
<string name="set_remind_time_message">创建提醒</string>
|
||||||
<string name="note_alert_expired">已过期</string>
|
<string name="note_alert_expired">已过期</string>
|
||||||
<string name="format_date_ymd">yyyyMMdd</string>
|
<string name="format_date_ymd">yyyyMMdd</string>
|
||||||
<string name="format_datetime_mdhm">MM月dd日 kk:mm</string>
|
<string name="format_datetime_mdhm">MM月dd日 kk:mm</string>
|
||||||
|
@ -116,6 +117,8 @@
|
||||||
<string name="search_hint">搜索便签</string>
|
<string name="search_hint">搜索便签</string>
|
||||||
<string name="search_setting_description">便签中的文字</string>
|
<string name="search_setting_description">便签中的文字</string>
|
||||||
<string name="search">便签</string>
|
<string name="search">便签</string>
|
||||||
|
<string name="datetime_dialog_ok">设置</string>
|
||||||
|
<string name="datetime_dialog_cancel">取消</string>
|
||||||
<plurals name="search_results_title">
|
<plurals name="search_results_title">
|
||||||
<item quantity="other"><xliff:g id="NUMBER">%1$s</xliff:g> 条符合“<xliff:g id="SEARCH">%2$s</xliff:g>”的搜索结果</item>
|
<item quantity="other"><xliff:g id="NUMBER">%1$s</xliff:g> 条符合“<xliff:g id="SEARCH">%2$s</xliff:g>”的搜索结果</item>
|
||||||
</plurals>
|
</plurals>
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
<string name="notelist_string_info">...</string>
|
<string name="notelist_string_info">...</string>
|
||||||
<string name="notelist_menu_new">新建便簽</string>
|
<string name="notelist_menu_new">新建便簽</string>
|
||||||
<string name="delete_remind_time_message">成功刪除提醒</string>
|
<string name="delete_remind_time_message">成功刪除提醒</string>
|
||||||
|
<string name="set_remind_time_message">創建提醒</string>
|
||||||
<string name="note_alert_expired">已過期</string>
|
<string name="note_alert_expired">已過期</string>
|
||||||
<string name="format_date_ymd">yyyyMMdd</string>
|
<string name="format_date_ymd">yyyyMMdd</string>
|
||||||
<string name="format_datetime_mdhm">MM月dd日 kk:mm</string>
|
<string name="format_datetime_mdhm">MM月dd日 kk:mm</string>
|
||||||
|
@ -117,6 +118,8 @@
|
||||||
<string name="search_hint">搜索便籤</string>
|
<string name="search_hint">搜索便籤</string>
|
||||||
<string name="search_setting_description">便籤中的文字</string>
|
<string name="search_setting_description">便籤中的文字</string>
|
||||||
<string name="search">便籤</string>
|
<string name="search">便籤</string>
|
||||||
|
<string name="datetime_dialog_ok">設置</string>
|
||||||
|
<string name="datetime_dialog_cancel">取消</string>
|
||||||
<plurals name="search_results_title">
|
<plurals name="search_results_title">
|
||||||
<item quantity="other"><xliff:g id="NUMBER">%1$s</xliff:g> 條符合”<xliff:g id="SEARCH">%2$s</xliff:g>“的搜尋結果</item>
|
<item quantity="other"><xliff:g id="NUMBER">%1$s</xliff:g> 條符合”<xliff:g id="SEARCH">%2$s</xliff:g>“的搜尋結果</item>
|
||||||
</plurals>
|
</plurals>
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
<string name="notelist_string_info">...</string>
|
<string name="notelist_string_info">...</string>
|
||||||
<string name="notelist_menu_new">Add note</string>
|
<string name="notelist_menu_new">Add note</string>
|
||||||
<string name="delete_remind_time_message">Delete reminder successfully</string>
|
<string name="delete_remind_time_message">Delete reminder successfully</string>
|
||||||
|
<string name="set_remind_time_message">Set reminder</string>
|
||||||
<string name="note_alert_expired">Expired</string>
|
<string name="note_alert_expired">Expired</string>
|
||||||
<string name="format_date_ymd">yyyyMMdd</string>
|
<string name="format_date_ymd">yyyyMMdd</string>
|
||||||
<string name="format_datetime_mdhm">MMMd kk:mm</string>
|
<string name="format_datetime_mdhm">MMMd kk:mm</string>
|
||||||
|
@ -123,6 +124,8 @@
|
||||||
<string name="search_hint">Search notes</string>
|
<string name="search_hint">Search notes</string>
|
||||||
<string name="search_setting_description">Text in your notes</string>
|
<string name="search_setting_description">Text in your notes</string>
|
||||||
<string name="search">Notes</string>
|
<string name="search">Notes</string>
|
||||||
|
<string name="datetime_dialog_ok">set</string>
|
||||||
|
<string name="datetime_dialog_cancel">cancel</string>
|
||||||
<plurals name="search_results_title">
|
<plurals name="search_results_title">
|
||||||
<item quantity="one"><xliff:g id="number" example="1">%1$s</xliff:g> result for \"<xliff:g id="search" example="???">%2$s</xliff:g>\"</item>
|
<item quantity="one"><xliff:g id="number" example="1">%1$s</xliff:g> result for \"<xliff:g id="search" example="???">%2$s</xliff:g>\"</item>
|
||||||
<!-- Case of 0 or 2 or more results. -->
|
<!-- Case of 0 or 2 or more results. -->
|
||||||
|
|
|
@ -0,0 +1,469 @@
|
||||||
|
package net.micode.notes.ui;
|
||||||
|
|
||||||
|
import java.text.DateFormatSymbols;
|
||||||
|
import java.util.Calendar;
|
||||||
|
|
||||||
|
import net.micode.notes.R;
|
||||||
|
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.text.format.DateFormat;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.FrameLayout;
|
||||||
|
import android.widget.NumberPicker;
|
||||||
|
|
||||||
|
public class DateTimePicker extends FrameLayout {
|
||||||
|
|
||||||
|
private static final boolean DEFAULT_ENABLE_STATE = true;
|
||||||
|
|
||||||
|
private static final int HOURS_IN_HALF_DAY = 12;
|
||||||
|
private static final int HOURS_IN_ALL_DAY = 24;
|
||||||
|
private static final int DAYS_IN_ALL_WEEK = 7;
|
||||||
|
private static final int DATE_SPINNER_MIN_VAL = 0;
|
||||||
|
private static final int DATE_SPINNER_MAX_VAL = DAYS_IN_ALL_WEEK - 1;
|
||||||
|
private static final int HOUR_SPINNER_MIN_VAL_24_HOUR_VIEW = 0;
|
||||||
|
private static final int HOUR_SPINNER_MAX_VAL_24_HOUR_VIEW = 23;
|
||||||
|
private static final int HOUR_SPINNER_MIN_VAL_12_HOUR_VIEW = 1;
|
||||||
|
private static final int HOUR_SPINNER_MAX_VAL_12_HOUR_VIEW = 12;
|
||||||
|
private static final int MINUT_SPINNER_MIN_VAL = 0;
|
||||||
|
private static final int MINUT_SPINNER_MAX_VAL = 59;
|
||||||
|
private static final int AMPM_SPINNER_MIN_VAL = 0;
|
||||||
|
private static final int AMPM_SPINNER_MAX_VAL = 1;
|
||||||
|
|
||||||
|
private final NumberPicker mDateSpinner;
|
||||||
|
private final NumberPicker mHourSpinner;
|
||||||
|
private final NumberPicker mMinuteSpinner;
|
||||||
|
private final NumberPicker mAmPmSpinner;
|
||||||
|
private Calendar mDate;
|
||||||
|
|
||||||
|
private String[] mDateDisplayValues = new String[DAYS_IN_ALL_WEEK];
|
||||||
|
|
||||||
|
private boolean mIsAm;
|
||||||
|
|
||||||
|
private boolean mIs24HourView;
|
||||||
|
|
||||||
|
private boolean mIsEnabled = DEFAULT_ENABLE_STATE;
|
||||||
|
|
||||||
|
private boolean mInitialising;
|
||||||
|
|
||||||
|
private OnDateTimeChangedListener mOnDateTimeChangedListener;
|
||||||
|
|
||||||
|
private NumberPicker.OnValueChangeListener mOnDateChangedListener = new NumberPicker.OnValueChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
|
||||||
|
mDate.add(Calendar.DAY_OF_YEAR, newVal - oldVal);
|
||||||
|
updateDateControl();
|
||||||
|
onDateTimeChanged();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private NumberPicker.OnValueChangeListener mOnHourChangedListener = new NumberPicker.OnValueChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
|
||||||
|
boolean isDateChanged = false;
|
||||||
|
Calendar cal = Calendar.getInstance();
|
||||||
|
if (!mIs24HourView) {
|
||||||
|
if (!mIsAm && oldVal == HOURS_IN_HALF_DAY - 1 && newVal == HOURS_IN_HALF_DAY) {
|
||||||
|
cal.setTimeInMillis(mDate.getTimeInMillis());
|
||||||
|
cal.add(Calendar.DAY_OF_YEAR, 1);
|
||||||
|
isDateChanged = true;
|
||||||
|
} else if (mIsAm && oldVal == HOURS_IN_HALF_DAY && newVal == HOURS_IN_HALF_DAY - 1) {
|
||||||
|
cal.setTimeInMillis(mDate.getTimeInMillis());
|
||||||
|
cal.add(Calendar.DAY_OF_YEAR, -1);
|
||||||
|
isDateChanged = true;
|
||||||
|
}
|
||||||
|
if (oldVal == HOURS_IN_HALF_DAY - 1 && newVal == HOURS_IN_HALF_DAY ||
|
||||||
|
oldVal == HOURS_IN_HALF_DAY && newVal == HOURS_IN_HALF_DAY - 1) {
|
||||||
|
mIsAm = !mIsAm;
|
||||||
|
updateAmPmControl();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (oldVal == HOURS_IN_ALL_DAY - 1 && newVal == 0) {
|
||||||
|
cal.setTimeInMillis(mDate.getTimeInMillis());
|
||||||
|
cal.add(Calendar.DAY_OF_YEAR, 1);
|
||||||
|
isDateChanged = true;
|
||||||
|
} else if (oldVal == 0 && newVal == HOURS_IN_ALL_DAY - 1) {
|
||||||
|
cal.setTimeInMillis(mDate.getTimeInMillis());
|
||||||
|
cal.add(Calendar.DAY_OF_YEAR, -1);
|
||||||
|
isDateChanged = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int newHour = mHourSpinner.getValue() % HOURS_IN_HALF_DAY + (mIsAm ? 0 : HOURS_IN_HALF_DAY);
|
||||||
|
mDate.set(Calendar.HOUR_OF_DAY, newHour);
|
||||||
|
onDateTimeChanged();
|
||||||
|
if (isDateChanged) {
|
||||||
|
setCurrentYear(cal.get(Calendar.YEAR));
|
||||||
|
setCurrentMonth(cal.get(Calendar.MONTH));
|
||||||
|
setCurrentDay(cal.get(Calendar.DAY_OF_MONTH));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private NumberPicker.OnValueChangeListener mOnMinuteChangedListener = new NumberPicker.OnValueChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
|
||||||
|
int minValue = mMinuteSpinner.getMinValue();
|
||||||
|
int maxValue = mMinuteSpinner.getMaxValue();
|
||||||
|
int offset = 0;
|
||||||
|
if (oldVal == maxValue && newVal == minValue) {
|
||||||
|
offset += 1;
|
||||||
|
} else if (oldVal == minValue && newVal == maxValue) {
|
||||||
|
offset -= 1;
|
||||||
|
}
|
||||||
|
if (offset != 0) {
|
||||||
|
mDate.add(Calendar.HOUR_OF_DAY, offset);
|
||||||
|
mHourSpinner.setValue(getCurrentHour());
|
||||||
|
updateDateControl();
|
||||||
|
int newHour = getCurrentHourOfDay();
|
||||||
|
if (newHour >= HOURS_IN_HALF_DAY) {
|
||||||
|
mIsAm = false;
|
||||||
|
updateAmPmControl();
|
||||||
|
} else {
|
||||||
|
mIsAm = true;
|
||||||
|
updateAmPmControl();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mDate.set(Calendar.MINUTE, newVal);
|
||||||
|
onDateTimeChanged();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private NumberPicker.OnValueChangeListener mOnAmPmChangedListener = new NumberPicker.OnValueChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
|
||||||
|
mIsAm = !mIsAm;
|
||||||
|
if (mIsAm) {
|
||||||
|
mDate.add(Calendar.HOUR_OF_DAY, -HOURS_IN_HALF_DAY);
|
||||||
|
} else {
|
||||||
|
mDate.add(Calendar.HOUR_OF_DAY, HOURS_IN_HALF_DAY);
|
||||||
|
}
|
||||||
|
updateAmPmControl();
|
||||||
|
onDateTimeChanged();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public interface OnDateTimeChangedListener {
|
||||||
|
void onDateTimeChanged(DateTimePicker view, int year, int month,
|
||||||
|
int dayOfMonth, int hourOfDay, int minute);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DateTimePicker(Context context) {
|
||||||
|
this(context, System.currentTimeMillis());
|
||||||
|
}
|
||||||
|
|
||||||
|
public DateTimePicker(Context context, long date) {
|
||||||
|
this(context, date, DateFormat.is24HourFormat(context));
|
||||||
|
}
|
||||||
|
|
||||||
|
public DateTimePicker(Context context, long date, boolean is24HourView) {
|
||||||
|
super(context);
|
||||||
|
mDate = Calendar.getInstance();
|
||||||
|
mInitialising = true;
|
||||||
|
mIsAm = getCurrentHourOfDay() >= HOURS_IN_HALF_DAY;
|
||||||
|
inflate(context, R.layout.datetime_picker, this);
|
||||||
|
|
||||||
|
mDateSpinner = (NumberPicker) findViewById(R.id.date);
|
||||||
|
mDateSpinner.setMinValue(DATE_SPINNER_MIN_VAL);
|
||||||
|
mDateSpinner.setMaxValue(DATE_SPINNER_MAX_VAL);
|
||||||
|
mDateSpinner.setOnValueChangedListener(mOnDateChangedListener);
|
||||||
|
|
||||||
|
mHourSpinner = (NumberPicker) findViewById(R.id.hour);
|
||||||
|
mHourSpinner.setOnValueChangedListener(mOnHourChangedListener);
|
||||||
|
mMinuteSpinner = (NumberPicker) findViewById(R.id.minute);
|
||||||
|
mMinuteSpinner.setMinValue(MINUT_SPINNER_MIN_VAL);
|
||||||
|
mMinuteSpinner.setMaxValue(MINUT_SPINNER_MAX_VAL);
|
||||||
|
mMinuteSpinner.setOnLongPressUpdateInterval(100);
|
||||||
|
mMinuteSpinner.setOnValueChangedListener(mOnMinuteChangedListener);
|
||||||
|
|
||||||
|
String[] stringsForAmPm = new DateFormatSymbols().getAmPmStrings();
|
||||||
|
mAmPmSpinner = (NumberPicker) findViewById(R.id.amPm);
|
||||||
|
mAmPmSpinner.setMinValue(AMPM_SPINNER_MIN_VAL);
|
||||||
|
mAmPmSpinner.setMaxValue(AMPM_SPINNER_MAX_VAL);
|
||||||
|
mAmPmSpinner.setDisplayedValues(stringsForAmPm);
|
||||||
|
mAmPmSpinner.setOnValueChangedListener(mOnAmPmChangedListener);
|
||||||
|
|
||||||
|
// update controls to initial state
|
||||||
|
updateDateControl();
|
||||||
|
updateHourControl();
|
||||||
|
updateAmPmControl();
|
||||||
|
|
||||||
|
set24HourView(is24HourView);
|
||||||
|
|
||||||
|
// set to current time
|
||||||
|
setCurrentDate(date);
|
||||||
|
|
||||||
|
setEnabled(isEnabled());
|
||||||
|
|
||||||
|
// set the content descriptions
|
||||||
|
mInitialising = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setEnabled(boolean enabled) {
|
||||||
|
if (mIsEnabled == enabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
super.setEnabled(enabled);
|
||||||
|
mDateSpinner.setEnabled(enabled);
|
||||||
|
mMinuteSpinner.setEnabled(enabled);
|
||||||
|
mHourSpinner.setEnabled(enabled);
|
||||||
|
mAmPmSpinner.setEnabled(enabled);
|
||||||
|
mIsEnabled = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEnabled() {
|
||||||
|
return mIsEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current date in millis
|
||||||
|
*
|
||||||
|
* @return the current date in millis
|
||||||
|
*/
|
||||||
|
public long getCurrentDateInTimeMillis() {
|
||||||
|
return mDate.getTimeInMillis();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the current date
|
||||||
|
*
|
||||||
|
* @param date The current date in millis
|
||||||
|
*/
|
||||||
|
public void setCurrentDate(long date) {
|
||||||
|
Calendar cal = Calendar.getInstance();
|
||||||
|
cal.setTimeInMillis(date);
|
||||||
|
setCurrentDate(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH),
|
||||||
|
cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the current date
|
||||||
|
*
|
||||||
|
* @param year The current year
|
||||||
|
* @param month The current month
|
||||||
|
* @param dayOfMonth The current dayOfMonth
|
||||||
|
* @param hourOfDay The current hourOfDay
|
||||||
|
* @param minute The current minute
|
||||||
|
*/
|
||||||
|
public void setCurrentDate(int year, int month,
|
||||||
|
int dayOfMonth, int hourOfDay, int minute) {
|
||||||
|
setCurrentYear(year);
|
||||||
|
setCurrentMonth(month);
|
||||||
|
setCurrentDay(dayOfMonth);
|
||||||
|
setCurrentHour(hourOfDay);
|
||||||
|
setCurrentMinute(minute);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get current year
|
||||||
|
*
|
||||||
|
* @return The current year
|
||||||
|
*/
|
||||||
|
public int getCurrentYear() {
|
||||||
|
return mDate.get(Calendar.YEAR);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set current year
|
||||||
|
*
|
||||||
|
* @param year The current year
|
||||||
|
*/
|
||||||
|
public void setCurrentYear(int year) {
|
||||||
|
if (!mInitialising && year == getCurrentYear()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mDate.set(Calendar.YEAR, year);
|
||||||
|
updateDateControl();
|
||||||
|
onDateTimeChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get current month in the year
|
||||||
|
*
|
||||||
|
* @return The current month in the year
|
||||||
|
*/
|
||||||
|
public int getCurrentMonth() {
|
||||||
|
return mDate.get(Calendar.MONTH);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set current month in the year
|
||||||
|
*
|
||||||
|
* @param month The month in the year
|
||||||
|
*/
|
||||||
|
public void setCurrentMonth(int month) {
|
||||||
|
if (!mInitialising && month == getCurrentMonth()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mDate.set(Calendar.MONTH, month);
|
||||||
|
updateDateControl();
|
||||||
|
onDateTimeChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get current day of the month
|
||||||
|
*
|
||||||
|
* @return The day of the month
|
||||||
|
*/
|
||||||
|
public int getCurrentDay() {
|
||||||
|
return mDate.get(Calendar.DAY_OF_MONTH);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set current day of the month
|
||||||
|
*
|
||||||
|
* @param dayOfMonth The day of the month
|
||||||
|
*/
|
||||||
|
public void setCurrentDay(int dayOfMonth) {
|
||||||
|
if (!mInitialising && dayOfMonth == getCurrentDay()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mDate.set(Calendar.DAY_OF_MONTH, dayOfMonth);
|
||||||
|
updateDateControl();
|
||||||
|
onDateTimeChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get current hour in 24 hour mode, in the range (0~23)
|
||||||
|
* @return The current hour in 24 hour mode
|
||||||
|
*/
|
||||||
|
public int getCurrentHourOfDay() {
|
||||||
|
return mDate.get(Calendar.HOUR_OF_DAY);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getCurrentHour() {
|
||||||
|
if (mIs24HourView){
|
||||||
|
return getCurrentHourOfDay();
|
||||||
|
} else {
|
||||||
|
int hour = getCurrentHourOfDay();
|
||||||
|
if (hour > HOURS_IN_HALF_DAY) {
|
||||||
|
return hour - HOURS_IN_HALF_DAY;
|
||||||
|
} else {
|
||||||
|
return hour == 0 ? HOURS_IN_HALF_DAY : hour;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set current hour in 24 hour mode, in the range (0~23)
|
||||||
|
*
|
||||||
|
* @param hourOfDay
|
||||||
|
*/
|
||||||
|
public void setCurrentHour(int hourOfDay) {
|
||||||
|
if (!mInitialising && hourOfDay == getCurrentHourOfDay()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mDate.set(Calendar.HOUR_OF_DAY, hourOfDay);
|
||||||
|
if (!mIs24HourView) {
|
||||||
|
if (hourOfDay >= HOURS_IN_HALF_DAY) {
|
||||||
|
mIsAm = false;
|
||||||
|
if (hourOfDay > HOURS_IN_HALF_DAY) {
|
||||||
|
hourOfDay -= HOURS_IN_HALF_DAY;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
mIsAm = true;
|
||||||
|
if (hourOfDay == 0) {
|
||||||
|
hourOfDay = HOURS_IN_HALF_DAY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
updateAmPmControl();
|
||||||
|
}
|
||||||
|
mHourSpinner.setValue(hourOfDay);
|
||||||
|
onDateTimeChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get currentMinute
|
||||||
|
*
|
||||||
|
* @return The Current Minute
|
||||||
|
*/
|
||||||
|
public int getCurrentMinute() {
|
||||||
|
return mDate.get(Calendar.MINUTE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set current minute
|
||||||
|
*/
|
||||||
|
public void setCurrentMinute(int minute) {
|
||||||
|
if (!mInitialising && minute == getCurrentMinute()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mMinuteSpinner.setValue(minute);
|
||||||
|
mDate.set(Calendar.MINUTE, minute);
|
||||||
|
onDateTimeChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if this is in 24 hour view else false.
|
||||||
|
*/
|
||||||
|
public boolean is24HourView () {
|
||||||
|
return mIs24HourView;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set whether in 24 hour or AM/PM mode.
|
||||||
|
*
|
||||||
|
* @param is24HourView True for 24 hour mode. False for AM/PM mode.
|
||||||
|
*/
|
||||||
|
public void set24HourView(boolean is24HourView) {
|
||||||
|
if (mIs24HourView == is24HourView) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mIs24HourView = is24HourView;
|
||||||
|
mAmPmSpinner.setVisibility(is24HourView ? View.GONE : View.VISIBLE);
|
||||||
|
int hour = getCurrentHourOfDay();
|
||||||
|
updateHourControl();
|
||||||
|
setCurrentHour(hour);
|
||||||
|
updateAmPmControl();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateDateControl() {
|
||||||
|
Calendar cal = Calendar.getInstance();
|
||||||
|
cal.setTimeInMillis(mDate.getTimeInMillis());
|
||||||
|
cal.add(Calendar.DAY_OF_YEAR, -DAYS_IN_ALL_WEEK / 2 - 1);
|
||||||
|
mDateSpinner.setDisplayedValues(null);
|
||||||
|
for (int i = 0; i < DAYS_IN_ALL_WEEK; ++i) {
|
||||||
|
cal.add(Calendar.DAY_OF_YEAR, 1);
|
||||||
|
mDateDisplayValues[i] = (String) DateFormat.format("MM.dd EEEE", cal);
|
||||||
|
}
|
||||||
|
mDateSpinner.setDisplayedValues(mDateDisplayValues);
|
||||||
|
mDateSpinner.setValue(DAYS_IN_ALL_WEEK / 2);
|
||||||
|
mDateSpinner.invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateAmPmControl() {
|
||||||
|
if (mIs24HourView) {
|
||||||
|
mAmPmSpinner.setVisibility(View.GONE);
|
||||||
|
} else {
|
||||||
|
int index = mIsAm ? Calendar.AM : Calendar.PM;
|
||||||
|
mAmPmSpinner.setValue(index);
|
||||||
|
mAmPmSpinner.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateHourControl() {
|
||||||
|
if (mIs24HourView) {
|
||||||
|
mHourSpinner.setMinValue(HOUR_SPINNER_MIN_VAL_24_HOUR_VIEW);
|
||||||
|
mHourSpinner.setMaxValue(HOUR_SPINNER_MAX_VAL_24_HOUR_VIEW);
|
||||||
|
} else {
|
||||||
|
mHourSpinner.setMinValue(HOUR_SPINNER_MIN_VAL_12_HOUR_VIEW);
|
||||||
|
mHourSpinner.setMaxValue(HOUR_SPINNER_MAX_VAL_12_HOUR_VIEW);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the callback that indicates the 'Set' button has been pressed.
|
||||||
|
* @param callback the callback, if null will do nothing
|
||||||
|
*/
|
||||||
|
public void setOnDateTimeChangedListener(OnDateTimeChangedListener callback) {
|
||||||
|
mOnDateTimeChangedListener = callback;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onDateTimeChanged() {
|
||||||
|
if (mOnDateTimeChangedListener != null) {
|
||||||
|
mOnDateTimeChangedListener.onDateTimeChanged(this, getCurrentYear(),
|
||||||
|
getCurrentMonth(), getCurrentDay(), getCurrentHourOfDay(), getCurrentMinute());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,75 @@
|
||||||
|
package net.micode.notes.ui;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.Calendar;
|
||||||
|
|
||||||
|
import net.micode.notes.R;
|
||||||
|
import net.micode.notes.ui.DateTimePicker;
|
||||||
|
import net.micode.notes.ui.DateTimePicker.OnDateTimeChangedListener;
|
||||||
|
|
||||||
|
import android.app.AlertDialog;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.content.DialogInterface.OnClickListener;
|
||||||
|
import android.text.format.DateFormat;
|
||||||
|
import android.text.format.DateUtils;
|
||||||
|
|
||||||
|
public class DateTimePickerDialog extends AlertDialog implements OnClickListener {
|
||||||
|
|
||||||
|
private Calendar mDate = Calendar.getInstance();
|
||||||
|
private boolean mIs24HourView;
|
||||||
|
private OnDateTimeSetListener mOnDateTimeSetListener;
|
||||||
|
private DateTimePicker mDateTimePicker;
|
||||||
|
|
||||||
|
public interface OnDateTimeSetListener {
|
||||||
|
void OnDateTimeSet(AlertDialog dialog, long date);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DateTimePickerDialog(Context context, long date) {
|
||||||
|
super(context);
|
||||||
|
mDateTimePicker = new DateTimePicker(context);
|
||||||
|
setView(mDateTimePicker);
|
||||||
|
mDateTimePicker.setOnDateTimeChangedListener(new OnDateTimeChangedListener() {
|
||||||
|
public void onDateTimeChanged(DateTimePicker view, int year, int month,
|
||||||
|
int dayOfMonth, int hourOfDay, int minute) {
|
||||||
|
mDate.set(Calendar.YEAR, year);
|
||||||
|
mDate.set(Calendar.MONTH, month);
|
||||||
|
mDate.set(Calendar.DAY_OF_MONTH, dayOfMonth);
|
||||||
|
mDate.set(Calendar.HOUR_OF_DAY, hourOfDay);
|
||||||
|
mDate.set(Calendar.MINUTE, minute);
|
||||||
|
updateTitle(mDate.getTimeInMillis());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
mDate.setTimeInMillis(date);
|
||||||
|
mDate.set(Calendar.SECOND, 0);
|
||||||
|
mDateTimePicker.setCurrentDate(mDate.getTimeInMillis());
|
||||||
|
setButton(context.getString(R.string.datetime_dialog_ok), this);
|
||||||
|
setButton2(context.getString(R.string.datetime_dialog_cancel), (OnClickListener)null);
|
||||||
|
set24HourView(DateFormat.is24HourFormat(this.getContext()));
|
||||||
|
updateTitle(mDate.getTimeInMillis());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void set24HourView(boolean is24HourView) {
|
||||||
|
mIs24HourView = is24HourView;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOnDateTimeSetListener(OnDateTimeSetListener callBack) {
|
||||||
|
mOnDateTimeSetListener = callBack;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateTitle(long date) {
|
||||||
|
int flag =
|
||||||
|
DateUtils.FORMAT_SHOW_YEAR |
|
||||||
|
DateUtils.FORMAT_SHOW_DATE |
|
||||||
|
DateUtils.FORMAT_SHOW_TIME;
|
||||||
|
flag |= mIs24HourView ? DateUtils.FORMAT_24HOUR : DateUtils.FORMAT_24HOUR;
|
||||||
|
setTitle(DateUtils.formatDateTime(this.getContext(), date, flag));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onClick(DialogInterface arg0, int arg1) {
|
||||||
|
if (mOnDateTimeSetListener != null) {
|
||||||
|
mOnDateTimeSetListener.OnDateTimeSet(this, mDate.getTimeInMillis());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -60,6 +60,7 @@ import net.micode.notes.model.WorkingNote.NoteSettingChangedListener;
|
||||||
import net.micode.notes.tool.DataUtils;
|
import net.micode.notes.tool.DataUtils;
|
||||||
import net.micode.notes.tool.ResourceParser;
|
import net.micode.notes.tool.ResourceParser;
|
||||||
import net.micode.notes.tool.ResourceParser.TextAppearanceResources;
|
import net.micode.notes.tool.ResourceParser.TextAppearanceResources;
|
||||||
|
import net.micode.notes.ui.DateTimePickerDialog.OnDateTimeSetListener;
|
||||||
import net.micode.notes.ui.NoteEditText.OnTextViewChangeListener;
|
import net.micode.notes.ui.NoteEditText.OnTextViewChangeListener;
|
||||||
import net.micode.notes.widget.NoteWidgetProvider_2x;
|
import net.micode.notes.widget.NoteWidgetProvider_2x;
|
||||||
import net.micode.notes.widget.NoteWidgetProvider_4x;
|
import net.micode.notes.widget.NoteWidgetProvider_4x;
|
||||||
|
@ -493,6 +494,11 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
||||||
} else {
|
} else {
|
||||||
menu.findItem(R.id.menu_list_mode).setTitle(R.string.menu_list_mode);
|
menu.findItem(R.id.menu_list_mode).setTitle(R.string.menu_list_mode);
|
||||||
}
|
}
|
||||||
|
if (mWorkingNote.hasClockAlert()) {
|
||||||
|
menu.findItem(R.id.menu_alert).setVisible(false);
|
||||||
|
} else {
|
||||||
|
menu.findItem(R.id.menu_delete_remind).setVisible(false);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -532,12 +538,28 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
||||||
case R.id.menu_send_to_desktop:
|
case R.id.menu_send_to_desktop:
|
||||||
sendToDesktop();
|
sendToDesktop();
|
||||||
break;
|
break;
|
||||||
|
case R.id.menu_alert:
|
||||||
|
setReminder();
|
||||||
|
break;
|
||||||
|
case R.id.menu_delete_remind:
|
||||||
|
mWorkingNote.setAlertDate(0, false);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setReminder() {
|
||||||
|
DateTimePickerDialog d = new DateTimePickerDialog(this, System.currentTimeMillis());
|
||||||
|
d.setOnDateTimeSetListener(new OnDateTimeSetListener() {
|
||||||
|
public void OnDateTimeSet(AlertDialog dialog, long date) {
|
||||||
|
mWorkingNote.setAlertDate(date , true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
d.show();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Share note to apps that support {@link Intent#ACTION_SEND} action
|
* Share note to apps that support {@link Intent#ACTION_SEND} action
|
||||||
* and {@text/plain} type
|
* and {@text/plain} type
|
||||||
|
|
|
@ -18,6 +18,7 @@ package net.micode.notes.ui;
|
||||||
|
|
||||||
import android.accounts.Account;
|
import android.accounts.Account;
|
||||||
import android.accounts.AccountManager;
|
import android.accounts.AccountManager;
|
||||||
|
import android.app.ActionBar;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
|
@ -369,13 +370,6 @@ public class NotesPreferenceActivity extends PreferenceActivity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
|
||||||
getActionBar().setHomeButtonEnabled(true);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case android.R.id.home:
|
case android.R.id.home:
|
||||||
|
|
Loading…
Reference in New Issue