pull/6/head
parent
9d2333387d
commit
7fdd8e4611
@ -0,0 +1,74 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.micode.notes.data;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.database.Cursor;
|
||||||
|
import android.provider.ContactsContract.CommonDataKinds.Phone;
|
||||||
|
import android.provider.ContactsContract.Data;
|
||||||
|
import android.telephony.PhoneNumberUtils;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
public class Contact {//联系人
|
||||||
|
private static HashMap<String, String> sContactCache;
|
||||||
|
private static final String TAG = "Contact";
|
||||||
|
//定义字符串"CALLER_ID_SELECTION"
|
||||||
|
private static final String CALLER_ID_SELECTION = "PHONE_NUMBERS_EQUAL(" + Phone.NUMBER
|
||||||
|
+ ",?) AND " + Data.MIMETYPE + "='" + Phone.CONTENT_ITEM_TYPE + "'"
|
||||||
|
+ " AND " + Data.RAW_CONTACT_ID + " IN "
|
||||||
|
+ "(SELECT raw_contact_id "
|
||||||
|
+ " FROM phone_lookup"
|
||||||
|
+ " WHERE min_match = '+')";
|
||||||
|
//获取联系人
|
||||||
|
public static String getContact(Context context, String phoneNumber) {
|
||||||
|
if(sContactCache == null) {
|
||||||
|
sContactCache = new HashMap<String, String>();
|
||||||
|
}//如果为空则创建新的sContactCache
|
||||||
|
|
||||||
|
if(sContactCache.containsKey(phoneNumber)) {
|
||||||
|
return sContactCache.get(phoneNumber);
|
||||||
|
}//查询hash表中已有的phoneNumber信息
|
||||||
|
|
||||||
|
String selection = CALLER_ID_SELECTION.replace("+",
|
||||||
|
PhoneNumberUtils.toCallerIDMinMatch(phoneNumber));
|
||||||
|
// 查找数据库中phoneNumber的信息
|
||||||
|
Cursor cursor = context.getContentResolver().query(
|
||||||
|
Data.CONTENT_URI,
|
||||||
|
new String [] { Phone.DISPLAY_NAME },
|
||||||
|
selection,
|
||||||
|
new String[] { phoneNumber },
|
||||||
|
null);
|
||||||
|
//判断查找的结果
|
||||||
|
if (cursor != null && cursor.moveToFirst()) {
|
||||||
|
try {
|
||||||
|
String name = cursor.getString(0);
|
||||||
|
sContactCache.put(phoneNumber, name);
|
||||||
|
return name;//找到相关信息返回name
|
||||||
|
} catch (IndexOutOfBoundsException e) {
|
||||||
|
Log.e(TAG, " Cursor get string error " + e.toString());
|
||||||
|
return null;//异常
|
||||||
|
} finally {
|
||||||
|
cursor.close();//没找到相关信息
|
||||||
|
}
|
||||||
|
} else {//未找到相关信息
|
||||||
|
Log.d(TAG, "No contact matched with number:" + phoneNumber);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,103 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.micode.notes.gtask.data;
|
||||||
|
|
||||||
|
import android.database.Cursor;
|
||||||
|
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
public abstract class Node {
|
||||||
|
//定义了各种用于表征同步状态的常量
|
||||||
|
public static final int SYNC_ACTION_NONE = 0;// 本地和云端都无可更新内容
|
||||||
|
|
||||||
|
public static final int SYNC_ACTION_ADD_REMOTE = 1;// 需要在远程云端增加内容
|
||||||
|
|
||||||
|
public static final int SYNC_ACTION_ADD_LOCAL = 2;// 需要在本地增加内容
|
||||||
|
|
||||||
|
public static final int SYNC_ACTION_DEL_REMOTE = 3;// 需要在远程云端删除内容
|
||||||
|
|
||||||
|
public static final int SYNC_ACTION_DEL_LOCAL = 4;// 需要在本地删除内容
|
||||||
|
|
||||||
|
public static final int SYNC_ACTION_UPDATE_REMOTE = 5;//远程更新内容
|
||||||
|
|
||||||
|
public static final int SYNC_ACTION_UPDATE_LOCAL = 6;//本地更新内容
|
||||||
|
|
||||||
|
public static final int SYNC_ACTION_UPDATE_CONFLICT = 7;//同步出现冲突
|
||||||
|
|
||||||
|
public static final int SYNC_ACTION_ERROR = 8;//同步错误
|
||||||
|
|
||||||
|
private String mGid;
|
||||||
|
|
||||||
|
private String mName;
|
||||||
|
|
||||||
|
private long mLastModified;//记录最后一次修改时间
|
||||||
|
|
||||||
|
|
||||||
|
private boolean mDeleted;//表征是否被删除
|
||||||
|
|
||||||
|
public Node() {
|
||||||
|
mGid = null;
|
||||||
|
mName = "";
|
||||||
|
mLastModified = 0;
|
||||||
|
mDeleted = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract JSONObject getCreateAction(int actionId);
|
||||||
|
|
||||||
|
public abstract JSONObject getUpdateAction(int actionId);
|
||||||
|
|
||||||
|
public abstract void setContentByRemoteJSON(JSONObject js);
|
||||||
|
|
||||||
|
public abstract void setContentByLocalJSON(JSONObject js);
|
||||||
|
|
||||||
|
public abstract JSONObject getLocalJSONFromContent();
|
||||||
|
|
||||||
|
public abstract int getSyncAction(Cursor c);
|
||||||
|
|
||||||
|
public void setGid(String gid) {
|
||||||
|
this.mGid = gid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.mName = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLastModified(long lastModified) {
|
||||||
|
this.mLastModified = lastModified;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeleted(boolean deleted) {
|
||||||
|
this.mDeleted = deleted;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGid() {
|
||||||
|
return this.mGid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return this.mName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getLastModified() {
|
||||||
|
return this.mLastModified;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getDeleted() {
|
||||||
|
return this.mDeleted;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,90 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
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);//设置s为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()));//根据24小时制或者是12小时进行设置
|
||||||
|
updateTitle(mDate.getTimeInMillis());//更新题目
|
||||||
|
}
|
||||||
|
|
||||||
|
public void set24HourView(boolean is24HourView) {
|
||||||
|
mIs24HourView = is24HourView;
|
||||||
|
}//设置为24小时页面
|
||||||
|
|
||||||
|
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;//是否按照24小时制显示
|
||||||
|
setTitle(DateUtils.formatDateTime(this.getContext(), date, flag));//设置对应的题目
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onClick(DialogInterface arg0, int arg1) {
|
||||||
|
if (mOnDateTimeSetListener != null) {
|
||||||
|
mOnDateTimeSetListener.OnDateTimeSet(this, mDate.getTimeInMillis());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package net.micode.notes.ui;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.view.Menu;
|
||||||
|
import android.view.MenuItem;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.View.OnClickListener;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.PopupMenu;
|
||||||
|
import android.widget.PopupMenu.OnMenuItemClickListener;
|
||||||
|
|
||||||
|
import net.micode.notes.R;
|
||||||
|
|
||||||
|
public class DropdownMenu {
|
||||||
|
private Button mButton;
|
||||||
|
private PopupMenu mPopupMenu;
|
||||||
|
private Menu mMenu;
|
||||||
|
|
||||||
|
public DropdownMenu(Context context, Button button, int menuId) {//放下菜单
|
||||||
|
mButton = button;
|
||||||
|
mButton.setBackgroundResource(R.drawable.dropdown_icon);//设置背景资源,改变对应的背景图片
|
||||||
|
mPopupMenu = new PopupMenu(context, mButton);//显示菜单
|
||||||
|
mMenu = mPopupMenu.getMenu();
|
||||||
|
mPopupMenu.getMenuInflater().inflate(menuId, mMenu);//填充菜单
|
||||||
|
mButton.setOnClickListener(new OnClickListener() {
|
||||||
|
public void onClick(View v) {
|
||||||
|
mPopupMenu.show();
|
||||||
|
}//显示对应的菜单
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOnDropdownMenuItemClickListener(OnMenuItemClickListener listener) {
|
||||||
|
if (mPopupMenu != null) {
|
||||||
|
mPopupMenu.setOnMenuItemClickListener(listener);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public MenuItem findItem(int id) {
|
||||||
|
return mMenu.findItem(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTitle(CharSequence title) {
|
||||||
|
mButton.setText(title);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue