Commits

Michael Ma  committed b5f2ff1

添加Activity销毁过程 修复back键错误
去除部分Activity补间动画

  • Participants
  • Parent commits 8f42aad

Comments (0)

Files changed (7)

File Project/res/values/main_activity.xml

 <?xml version="1.0" encoding="utf-8"?>
 <resources>
     <string name="mainTab1">登录</string>
-    <string name="mainTab2">添加笔记</string>
+    <string name="mainTab2">笔记本管理</string>
     <string name="mainTab3">设置</string>
 </resources>

File Project/res/values/note_bookmark.xml

 <resources>
     <string name="bookmarkTitle">书签</string>
     <string name="addBookmarkHint">添加书签</string>
-    <string name="bookmarkCancle">取消</string>
+    <string name="bookmarkCancle">返回</string>
     <string name="bookmarkSubmit">完成</string>
 </resources>

File Project/src/com/noodle/note/activity/BookmarkManageActivity.java

 	private Button buttonComplete;
 	private Button buttonCancle;
 	private Session session;
-	/** 书签条目浏览的List */
 	private ListView listView;
-	/** 书签条目浏览中每个List的HashMap */
 	private ArrayList<HashMap<String, Object>> listItem = new ArrayList<HashMap<String, Object>>();
 
 	@Override
 		buttonCancle = (Button) findViewById(R.id.bookmarkCancle);
 		buttonComplete.setOnClickListener(complete);
 		buttonCancle.setOnClickListener(cancle);
-		bundle = this.getIntent().getExtras();
 		session = Session.getInstance(this);
 		bundle = this.getIntent().getExtras();
 		line = bundle.getInt("line");
 		column = bundle.getInt("column");
 		noteId = bundle.getInt("noteId");
-		/** ListView的内容显示 */
 		initViews();
-		/** 设置监听器 */
 		setListeners();
 	}
 
 			Note note = Registry.getInstance().getEntity(Note.class, noteId);
 			Bookmark bookmark = new Bookmark(note, line, column);
 			bookmark.setName(bookmarkName);
-			BookmarkGateway bookmarkGateway = (BookmarkGateway) session
-					.query(Bookmark.class);
+			BookmarkGateway bookmarkGateway = (BookmarkGateway) session.query(Bookmark.class);
 			bookmarkGateway.create(bookmark);
 			Intent intent = new Intent();
-			Bundle bundle = new Bundle();
-			bundle.putInt("id", noteId);
 			intent.putExtras(bundle);
-			intent.setClass(BookmarkManageActivity.this, NoteReadActivity.class);
+			intent.setClass(BookmarkManageActivity.this, BookmarkManageActivity.class);
 			startActivity(intent);
+			overridePendingTransition(0, 0);
+			BookmarkManageActivity.this.finish();
 		}
 	};
 	/**
-	 * 按钮“取消“的操作设置
+	 * 按钮“返回“的操作设置
 	 */
 	OnClickListener cancle = new OnClickListener() {
 
 		@Override
 		public void onClick(View v) {
-			Intent intent = new Intent();
-			int noteId = bundle.getInt("noteId");
-			Bundle bundle = new Bundle();
-			bundle.putInt("id", noteId);
-			intent.putExtras(bundle);
-			intent.setClass(BookmarkManageActivity.this, NoteReadActivity.class);
-			startActivity(intent);
+			BookmarkManageActivity.this.finish();
 		}
 	};
 
-	/** listView项的长按菜单 */
+	/** 
+	 * listView项的长按菜单
+	 */
 	OnCreateContextMenuListener longPressMenu = new OnCreateContextMenuListener() {
 
 		@Override
-		public void onCreateContextMenu(ContextMenu menu, View v,
-				ContextMenuInfo menuInfo) {
+		public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
 			String deleteItem = "删除";
 			/** 第二个参数为操作ID */
 			menu.add(0, 0, 0, deleteItem);
 		}
 	};
 
-	/** listView项的接口设置以及监听器设置 */
+	/** 
+	 * listView项的接口设置以及监听器设置
+	 */
 	public void setListeners() {
-		listItemAdapter = new SimpleAdapter(this, listItem,
-				R.layout.bookmark_manage_listview, new String[] {
-						"bookmarkname", "bookmarkpos" }, new int[] {
-						R.id.bookmarkName, R.id.bookmarkPos });
+		listItemAdapter = new SimpleAdapter(this, listItem, R.layout.bookmark_manage_listview, new String[] { "bookmarkname", "bookmarkpos" }, new int[] { R.id.bookmarkName,
+				R.id.bookmarkPos });
 		listView.setAdapter(listItemAdapter);
 		listView.setOnItemClickListener(oicl);
 		listView.setOnCreateContextMenuListener(longPressMenu);
 	}
 
-	/** 长按菜单操作设置 */
+	/** 
+	 * 长按菜单操作设置
+	 */
 	@Override
 	public boolean onContextItemSelected(MenuItem item) {
-		AdapterView.AdapterContextMenuInfo info = (AdapterContextMenuInfo) item
-				.getMenuInfo();
-		int listItemId = (Integer) listItem.get(info.position)
-				.get("bookmarkid");
-		BookmarkGateway bookmarkGateway = (BookmarkGateway) Session
-				.getInstance(this).query(Bookmark.class);
+		AdapterView.AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
+		int listItemId = (Integer) listItem.get(info.position).get("bookmarkid");
+		BookmarkGateway bookmarkGateway = (BookmarkGateway) Session.getInstance(this).query(Bookmark.class);
 		Bookmark bookmark = bookmarkGateway.findById(listItemId);
 		switch (item.getItemId()) {
-		/** 长按各项菜单操作 */
+		// 长按各项菜单操作 
 		case 0:
 			bookmarkGateway.delete(bookmark);
-			/** 变相刷新界面 */
-			// Bundle bundle = new Bundle();
-			// bundle.putInt("line", line);
-			// bundle.putInt("column", column);
-			// bundle.putInt("noteId", noteId);
+			Bundle bundle = new Bundle();
+			bundle.putInt("line", line);
+			bundle.putInt("column", column);
+			bundle.putInt("noteId", noteId);
 
 			Intent selfintent = new Intent();
 			selfintent.putExtras(bundle);
-			selfintent.setClass(BookmarkManageActivity.this,
-					BookmarkManageActivity.class);
+			selfintent.setClass(BookmarkManageActivity.this, BookmarkManageActivity.class);
 			startActivity(selfintent);
+			overridePendingTransition(0, 0);
 			BookmarkManageActivity.this.finish();
 			break;
 		}
 		return super.onContextItemSelected(item);
 	}
 
-	/** listView的项短按操作 */
+	/** 
+	 * listView的项短按操作
+	 */
 	OnItemClickListener oicl = new OnItemClickListener() {
-		public void onItemClick(AdapterView<?> adapter, View v, int position,
-				long id) {
+		public void onItemClick(AdapterView<?> adapter, View v, int position, long id) {
 			int startLine = (Integer) listItem.get(position).get("bookmarkpos");
 			shortpress(noteId, startLine);
 		}
 	};
 
-	/** listview短按链接设置 */
+	/** 
+	 * listview短按链接设置
+	 */
 	private void shortpress(int id, int startLine) {
 		Intent intent = new Intent();
 		Bundle bundle = new Bundle();
 		startActivity(intent);
 	}
 
-	/** listView的内容创建 */
+	/** 
+	 * listView的内容创建
+	 */
 	private void initViews() {
-		BookmarkGateway bookmarkGateway = (BookmarkGateway) Session
-				.getInstance(BookmarkManageActivity.this).query(Bookmark.class);
+		BookmarkGateway bookmarkGateway = (BookmarkGateway) Session.getInstance(BookmarkManageActivity.this).query(Bookmark.class);
 		listView = (ListView) findViewById(R.id.bookmarkManageList);
 		ArrayList<Bookmark> bookmarkList = new ArrayList<Bookmark>();
 		// TODO 错误

File Project/src/com/noodle/note/activity/MainActivity.java

 		tab2 = (ImageView) findViewById(R.id.tab2);
 		tab3 = (ImageView) findViewById(R.id.tab3);
 		
-
 		// 初始化滚动背景
 		RelativeLayout.LayoutParams rl = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
 		rl.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
 	    	//TODO 登录功能尚未实现
 	        return true;
 	    case R.id.mainTab2:
-	    	startActivity(new Intent().setClass(this, EditNoteActivity.class));
+	    	startActivity(new Intent().setClass(this, NotebookManageActivity.class));
 	        return true;
 	    case R.id.mainTab3:
 	    	//TODO 设置功能尚未实现
 	        return super.onOptionsItemSelected(item);
 	    }
 	}
+	
 }

File Project/src/com/noodle/note/activity/NoteReadActivity.java

 		intent.putExtras(bundle);
 		intent.setClass(this, BookmarkManageActivity.class);
 		this.startActivity(intent);
-		//NoteReadActivity.this.finish();
+	//	NoteReadActivity.this.finish();
 	}
 
 	private void displayContent() {
 		startLine = this.getIntent().getExtras().getInt("startLine");
 		noteContentView.setText(content);
 		noteContentView.scrollBy(0, startLine);
-		
 	}
 	
 	private void editNote(){

File Project/src/com/noodle/note/activity/NotebookManageActivity.java

  * 
  */
 public class NotebookManageActivity extends Activity {
-	/**笔记本条目浏览的List*/
+	/** 笔记本条目浏览的List */
 	private ListView listView;
-	/**笔记本条目浏览中每个List的HashMap*/
+	/** 笔记本条目浏览中每个List的HashMap */
 	private ArrayList<HashMap<String, Object>> listItem = new ArrayList<HashMap<String, Object>>();
 
 	@Override
 		super.onCreate(savedInstanceState);
 		setContentView(R.layout.notebookmanage_main);
 		initViews();
-		setListeners();}
+		setListeners();
+	}
+
 	/** manage页面listview长按菜单 */
 	OnCreateContextMenuListener longpressmenu = new OnCreateContextMenuListener() {
-		public void onCreateContextMenu(ContextMenu menu, View v,ContextMenuInfo menuInfo) {
+		public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
 			String lpMenuTitle = "菜单";
 			String lpMenuItem1 = "编辑";
 			String lpMenuItem2 = "删除";
 			String lpMenuItem3 = "分享";
-			
+
 			menu.setHeaderTitle(lpMenuTitle);
-			/**第二个参数为操作ID */
+			/** 第二个参数为操作ID */
 			menu.add(0, 0, 0, lpMenuItem1);
 			menu.add(0, 1, 0, lpMenuItem2);
-			menu.add(0, 2, 0, lpMenuItem3);}	};
+			menu.add(0, 2, 0, lpMenuItem3);
+		}
+	};
 
-	/**manage页面listview项的接口设置以及监听器设置*/
+	/** manage页面listview项的接口设置以及监听器设置 */
 	public void setListeners() {
 		SimpleAdapter listItemAdapter = new SimpleAdapter(this, listItem, R.layout.notebookmanage_listview, new String[] { "notebookname", "notebookcount" }, new int[] {
 				R.id.notebookManageListName, R.id.notebookManageListCount });
 		listView.setAdapter(listItemAdapter);
 		listView.setOnItemClickListener(oicl);
-		listView.setOnCreateContextMenuListener(longpressmenu);}
+		listView.setOnCreateContextMenuListener(longpressmenu);
+	}
 
-	/**manage长按菜单操作链接*/
+	/** manage长按菜单操作链接 */
 	@Override
 	public boolean onContextItemSelected(MenuItem item) {
 		AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
 		NotebookGateway notebookListGateway = (NotebookGateway) Session.getInstance(this).query(Notebook.class);
 
 		switch (item.getItemId()) {
-		 /** 长按菜单的“编辑”操作*/
+		/** 长按菜单的“编辑”操作 */
 		case 0:
 			Intent intent = new Intent();
 			intent.setClass(NotebookManageActivity.this, NotebookManageCreatActivity.class);
 			intent.putExtras(bundle);
 			startActivity(intent);
 			break;
-		/** 长按菜单的“删除”操作*/
+		/** 长按菜单的“删除”操作 */
 		case 1:
 			notebookListGateway.deleteById(listItemId);
-			/**变相刷新界面*/
+			/** 变相刷新界面 */
 			Intent selfintent = new Intent();
 			selfintent.setClass(NotebookManageActivity.this, NotebookManageActivity.class);
 			startActivity(selfintent);
 			NotebookManageActivity.this.finish();
 			break;
-		/** 长按菜单的“分享”操作*/
-		//TODO待实现
+		/** 长按菜单的“分享”操作 */
+		// TODO待实现
 		case 2:
-			break;}
-		return super.onContextItemSelected(item);}
+			break;
+		}
+		return super.onContextItemSelected(item);
+	}
 
-	/**Menu按键名设置*/
+	/** Menu按键名设置 */
 	@Override
 	public boolean onCreateOptionsMenu(Menu menu) {
 		String tab1Name = "新增笔记本";
 		String tab2Name = "更多";
 		menu.add(0, Menu.FIRST, 0, tab1Name);
-		menu.add(0, Menu.FIRST+1, 0, tab2Name);
-		return super.onCreateOptionsMenu(menu);	}
+		menu.add(0, Menu.FIRST + 1, 0, tab2Name);
+		return super.onCreateOptionsMenu(menu);
+	}
 
-	/**manage页面menu操作设置*/
+	/** manage页面menu操作设置 */
 	@Override
 	public boolean onOptionsItemSelected(MenuItem item) {
 		switch (item.getItemId()) {
-		/** Menu中的“新增笔记本”操作*/
+		/** Menu中的“新增笔记本”操作 */
 		case Menu.FIRST:
 			Intent intent = new Intent();
 			intent.setClass(NotebookManageActivity.this, NotebookManageCreatActivity.class);
 			startActivity(intent);
+			NotebookManageActivity.this.finish();
 			break;
-		/** Menu中的“更多”操作*/
-		//TODO 待实现
-		case Menu.FIRST+1:
-			break;}
-		return super.onOptionsItemSelected(item);}
+		/** Menu中的“更多”操作 */
+		// TODO 待实现
+		case Menu.FIRST + 1:
+			break;
+		}
+		return super.onOptionsItemSelected(item);
+	}
 
 	/** manage页面liseview短按监听 */
 	OnItemClickListener oicl = new OnItemClickListener() {
 		public void onItemClick(AdapterView<?> adapter, View v, int position, long id) {
 			int pk = (Integer) listItem.get(position).get("id");
-			shortpress(pk);	}	};
+			shortpress(pk);
+		}
+	};
 
-	/**manage页面listview短按链接设置*/
+	/** manage页面listview短按链接设置 */
 	private void shortpress(int pk) {
 		Intent intent = new Intent();
 		Bundle bundle = new Bundle();
 		bundle.putInt("id", pk);
 		intent.setClass(this, NotesDisplayActivity.class);
 		intent.putExtras(bundle);
-		startActivity(intent);}
+		startActivity(intent);
+	}
 
-
-	/**manage页面listview内容创建 */
+	/** manage页面listview内容创建 */
 	private void initViews() {
 		NotebookGateway notebookGateway = (NotebookGateway) Session.getInstance(NotebookManageActivity.this).query(Notebook.class);
 		listView = (ListView) findViewById(R.id.notebookManageMylist);
 				contentMap.put("notebookname", nb.getName());
 				contentMap.put("notebookcount", noteGateway.count(nb.getId()) + "篇笔记");
 				contentMap.put("id", nb.getId());
-			listItem.add(contentMap);}	}
-		else{
-			/**创建一个仅有提示意义的显示笔记本样本,没有实际的内容以及对象。*/
+				listItem.add(contentMap);
+			}
+		} else {
+			/** 创建一个仅有提示意义的显示笔记本样本,没有实际的内容以及对象。 */
 			HashMap<String, Object> noContentMap = new HashMap<String, Object>();
 			noContentMap.put("notebookname", "暂无笔记");
 			noContentMap.put("notebookcount", "没有笔记,没有书");
-			listItem.add(noContentMap);}	}	}
+			listItem.add(noContentMap);
+		}
+	}
+}

File Project/src/com/noodle/note/activity/NotebookManageCreatActivity.java

 	private EditText notebookName;
 	private Bundle bundle;
 	private NotebookGateway notebookGateway = (NotebookGateway) Session.getInstance(this).query(Notebook.class);
-	//TODO待修改
-	
+
+	// TODO待修改
 
 	protected void onCreate(Bundle savedInstanceState) {
 		super.onCreate(savedInstanceState);
 		setContentView(R.layout.notebookmanage_creat);
 		bundle = this.getIntent().getExtras();
-		
-		/** 两个底部Button的监听器设置*/
+
+		/** 两个底部Button的监听器设置 */
 		Button buttonComplete = (Button) findViewById(R.id.noteBookButtonSubmit);
 		buttonComplete.setOnClickListener(submit);
 		Button buttonCancle = (Button) findViewById(R.id.noteBookButtonCancle);
 		buttonCancle.setOnClickListener(cancle);
-		
-		/**界面显示选择操作*/
-		WhichtoShow();}
-	
-	/** 新建笔记本与编辑笔记本共用一个界面,以下的显示操作以及按钮操作都是通过bundle内容来判断具体显示哪个界面内容以及进行什么操作*/
-	private void WhichtoShow(){
-		/**bundle为空,即重新建立一个新笔记本*/
+
+		/** 界面显示选择操作 */
+		WhichtoShow();
+	}
+
+	/**
+	 * 新建笔记本与编辑笔记本共用一个界面,以下的显示操作以及按钮操作都是通过bundle内容来判断具体显示哪个界面内容以及进行什么操作
+	 */
+	private void WhichtoShow() {
+		/** bundle为空,即重新建立一个新笔记本 */
 		if (null == bundle) {
 			TextView titleView = (TextView) findViewById(R.id.noteBookManageTitle);
 			titleView.setText("新建笔记本");
 			EditText hintView = (EditText) findViewById(R.id.noteBookNewName);
-			hintView.setHint("请输入笔记本名");}
-		/**bundle不为空,即笔记本原本存在,此时只是修改某些内容*/
+			hintView.setHint("请输入笔记本名");
+		}
+		/** bundle不为空,即笔记本原本存在,此时只是修改某些内容 */
 		else {
 			TextView titleView = (TextView) findViewById(R.id.noteBookManageTitle);
 			titleView.setText("编辑笔记本");
 			EditText hintView = (EditText) findViewById(R.id.noteBookNewName);
-			hintView.setText(bundle.getString("notebookName"));	}	}
-	
-	/** 按钮“完成“的操作设置 */
+			hintView.setText(bundle.getString("notebookName"));
+		}
+	}
+
+	/**
+	 * 按钮“完成“的操作设置
+	 */
 	OnClickListener submit = new OnClickListener() {
 		public void onClick(View v) {
-			/**bundle为空,做新建笔记本操作*/
+			// bundle为空,做新建笔记本操作
 			if (null == bundle) {
 				notebookName = (EditText) findViewById(R.id.noteBookNewName);
 				String content = notebookName.getText().toString();
 				Notebook notebook = new Notebook(content, "Zero");
 				notebookGateway.create(notebook);
 				Intent intent = new Intent();
-				intent.setClass(NotebookManageCreatActivity.this,
-						NotebookManageActivity.class);
-				startActivity(intent);}
-			/**bundle不为空,做修改笔记本操作*/
+				intent.setClass(NotebookManageCreatActivity.this, NotebookManageActivity.class);
+				startActivity(intent);
+				NotebookManageCreatActivity.this.finish();
+			}
+			// bundle不为空,做修改笔记本操作
 			else {
 				int listItemId = bundle.getInt("listItemId");
 				notebookName = (EditText) findViewById(R.id.noteBookNewName);
 				notebook.setName(content);
 				notebookGateway.update(notebook);
 				Intent intent = new Intent();
-				intent.setClass(NotebookManageCreatActivity.this,
-						NotebookManageActivity.class);
-				startActivity(intent);}	}	};
+				intent.setClass(NotebookManageCreatActivity.this, NotebookManageActivity.class);
+				startActivity(intent);
+				NotebookManageCreatActivity.this.finish();
+			}
+		}
+	};
 
-	/** 按钮“取消“的操作设置 */
+	/**
+	 * 按钮“取消“的操作设置
+	 */
 	OnClickListener cancle = new OnClickListener() {
 		public void onClick(View v) {
 			Intent intent = new Intent();
-			intent.setClass(NotebookManageCreatActivity.this,
-					NotebookManageActivity.class);
-			startActivity(intent);}	};	}
+			intent.setClass(NotebookManageCreatActivity.this, NotebookManageActivity.class);
+			startActivity(intent);
+			NotebookManageCreatActivity.this.finish();
+		}
+	};
+}