/*
* AUTHOR bangbang.song@gmail.com
*/
package com.cngphone.AnFetion;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.regex.Matcher;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ListActivity;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.ServiceConnection;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.os.IBinder;
import android.text.Spannable;
import android.text.method.LinkMovementMethod;
import android.text.method.MovementMethod;
import android.text.util.Linkify;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
import android.widget.Toast;
import com.cngphone.AnFetion.Fetion.FetionMessageProvider;
import com.cngphone.AnFetion.tools.LogUtil;
import com.cngphone.AnFetion.tools.SystemInfo;
import com.cngphone.AnFetion2.R;
/*
* a simple fetion message viewer.
*/
public class FetionMessageHistory extends ListActivity
implements SimpleCursorAdapter.ViewBinder {
private final static boolean LOCAL_LOG = false;
private final static String TAG = "FeitonHistory";
/* export the msgs for some purpose, oh ?*/
// private File EXTERNAL_APP_DIR = null;
private File EXTERNAL_DATA_DIR = null;
private boolean mCanExported = false;
private final static int DIALOG_ABOUTME = 1;
private final static int DIALOG_CONFIRM_DEL = 2;
private final static int MENU_RETURN = Menu.FIRST;
/*
* call the sender or receiver.
*/
private final static int MENU_CALL = Menu.FIRST + 1;
private final static int MENU_DEL = Menu.FIRST + 2;
private final static int MENU_HELP = Menu.FIRST + 3;
private final static int MENU_BUG = Menu.FIRST + 4;
private final static int MENU_ABOUTME = Menu.FIRST + 5;
private final static int MENU_FEEDBACK = Menu.FIRST + 6;
private final static int MENU_EXPORT = Menu.FIRST + 7;
private final static int MENU_EXPORT_ALL = Menu.FIRST + 8;
public final static String SHOW_MSGS_WHO = "com.bangbang.action.SHOW_MSGS_WHO";
public final static String SHOW_MSGS = "com.bangbang.action.SHOW_MSGS";
/*
* u can dial the gays.
*/
private String mFetionFriendUri;
private FetionFriend mMe = null;
private FetionFriend mFriend = null;
private FetionService mFetionService = null;
private ServiceConnection mConn = null;
private Uri mContentUri = null;
private Cursor mCursor = null; // for export & import
// private SimpleCursorAdapter.ViewBinder mViewBinder = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
mConn = new ServiceConnection(){
public void onServiceDisconnected(ComponentName comName){
mFetionService = null;
};
public void onServiceConnected(ComponentName comName, IBinder ibinder){
mFetionService = ((FetionService.LocalBinder) ibinder).getService();
mMe = mFetionService.getMyself();
mFriend = getFriendById(mFetionFriendUri);
setTitle("查看与 " + mFriend.getName() + " 的聊天记录");
}
};
if (null == getIntent() || null == getIntent().getData()) {
if (Settings.DEBUG) LogUtil.d(TAG, "the para the start " +
this.getClass().getCanonicalName() +
"is incorrect");
throw new IllegalArgumentException("incorrect para");
}
mContentUri = getIntent().getData();
mFetionFriendUri = mContentUri.getLastPathSegment();
LogUtil.d(TAG,"uri = " + mContentUri.toString());
bindService(new Intent(FetionMessageHistory.this, FetionService.class),
mConn , Context.BIND_AUTO_CREATE);
mCursor = managedQuery(mContentUri, null, null, null,
"_date DESC" /* reverse order*/
);
// the cursor is always not null so (null != cursor) does not work.
if (0 != mCursor.getCount()) {
mCanExported = true;
SimpleCursorAdapter adapter =
new FetionSimpleCursorAdapter(this,
R.layout.fetion_message,
mCursor,
new String[] { FetionMessageProvider.KEY_DATE,
FetionMessageProvider.KEY_FROM,
FetionMessageProvider.KEY_MSG
},
new int[] {
R.id.date,
R.id.from,
R.id.message
}
);
// TODO custom my view
// adapter.setViewBindtrueer(this);
setListAdapter(adapter);
} else {
// FIXME: this can not work, why???
// TODO:
getListView().setEmptyView(findViewById(R.id.no_msg));
}
// nullpoint exception WHY???
// mMe = mFetionService.getMyself();
// mFriend = getFriendById(mFetionFriendUri);
// setTitle("查看与 " + mFriend.FriendName + " 的聊天记录");
}
/*
* id : [sip|tel]:xxxxxx fetion ID
*/
private FetionFriend getFriendById(String id){
ArrayList<FetionFriend> friends = mFetionService.getReserveNotify().getBuddies();
for (FetionFriend a : friends) {
if (0 == a.Uri.indexOf(id)) {
return a;
}
}
return null;
}
public boolean setViewValue(View view, Cursor cursor, int columnIndex){
String from = cursor.getString(cursor.getColumnIndexOrThrow("_from"));
if (cursor.getColumnIndex("_from") == columnIndex) {
((EditText)findViewById(R.id.from)).setText(getFetionFriendNameById(from));
return false;
}
return false;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
menu.add(0, MENU_RETURN, 0, "返回聊天");
menu.add(0, MENU_CALL, 0, "呼叫对方");
if (mCanExported) {
menu.add(0, MENU_DEL, 0, "删除消息");
menu.add(0, MENU_EXPORT, 0, "导出聊天记录");
}
menu.add(0, MENU_EXPORT_ALL, 0, "导出与所有好友聊天记录" );
menu.add(0, MENU_BUG, 0, "报告缺陷");
menu.add(0, MENU_ABOUTME, 0, "关于飞信历史");
menu.add(0, MENU_FEEDBACK, 0, "信息反馈");
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
switch (item.getItemId()) {
case (MENU_RETURN): {
finish();
break;
}
case (MENU_CALL): {
callTheGay();
break;
}
case (MENU_HELP): {
if (Settings.DEBUG)
LogUtil.d(TAG,"fetion message helper is not supported yet");
break;
}
case (MENU_DEL): {
showDialog(DIALOG_CONFIRM_DEL);
break;
}
case (MENU_EXPORT): {
exportMessage();
break;
}
case (MENU_EXPORT_ALL): {
exprotMessageAll();
break;
}
case
评论10
最新资源