Commits

Jiangge Zhang committed 509fca4 Merge

合并

  • Participants
  • Parent commits 5a75cd3, 5376d3d

Comments (0)

Files changed (2)

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

  * 
  */
 public class NotebookManageActivity extends Activity {
-	/** 将有意义的字符串代替按键的数字代号 */
-	private static final int MENU_ADD = Menu.FIRST;
-	private static final int MENU_MORE = Menu.FIRST + 1;
-	private static final int LPMENU_EDIT = 10;
-	private static final int LPMENU_DELETE = 11;
-	private static final int LPMENU_SHARE = 12;
+	/**笔记本条目浏览的List*/
 	private ListView listView;
+	/**笔记本条目浏览中每个List的HashMap*/
 	private ArrayList<HashMap<String, Object>> listItem = new ArrayList<HashMap<String, Object>>();
 	private NotebookGateway notebookGateway = (NotebookGateway) Session.getInstance(this).query(Notebook.class);
 
 	public void onCreate(Bundle savedInstanceState) {
 		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) {
-			String lpmenuTitle = "菜单";
-			String lpmenuEdit = "编辑";
-			String lpmenuDelete = "删除";
-			String lpmenuShare = "分享";
-			menu.setHeaderTitle(lpmenuTitle);
-			menu.add(0, LPMENU_EDIT, 0, lpmenuEdit);
-			menu.add(0, LPMENU_DELETE, 0, lpmenuDelete);
-			menu.add(0, LPMENU_SHARE, 0, lpmenuShare);
-		}
-	};
+		public void onCreateContextMenu(ContextMenu menu, View v,ContextMenuInfo menuInfo) {
+			String lpMenuTitle = "菜单";
+			String lpMenuItem1 = "编辑";
+			String lpMenuItem2 = "删除";
+			String lpMenuItem3 = "分享";
+			
+			menu.setHeaderTitle(lpMenuTitle);
+			/**第二个参数为操作ID */
+			menu.add(0, 0, 0, lpMenuItem1);
+			menu.add(0, 1, 0, lpMenuItem2);
+			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);}
 
-	// TODO添加长按菜单链接
-	/**
-	 * manage长按菜单操作链接
-	 */
+	/**manage长按菜单操作链接*/
 	@Override
 	public boolean onContextItemSelected(MenuItem item) {
-		// ContextMenuInfo menuInfo = (ContextMenuInfo) item.getMenuInfo();
 		AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
 		int listItemId = (Integer) listItem.get(info.position).get("id");
 		String notebookName = (String) listItem.get(info.position).get("notebookname");
 		NotebookGateway notebookListGateway = (NotebookGateway) Session.getInstance(this).query(Notebook.class);
 
 		switch (item.getItemId()) {
-		case LPMENU_EDIT:
+		 /** 长按菜单的“编辑”操作*/
+		case 0:
 			Intent intent = new Intent();
 			intent.setClass(NotebookManageActivity.this, NotebookManageCreatActivity.class);
 			Bundle bundle = new Bundle();
 			intent.putExtras(bundle);
 			startActivity(intent);
 			break;
-		case LPMENU_DELETE:
-
+		/** 长按菜单的“删除”操作*/
+		case 1:
+			//TODO 待修改
 			notebookListGateway.deleteById(listItemId);
+			/**变相刷新界面*/
 			Intent selfintent = new Intent();
 			selfintent.setClass(NotebookManageActivity.this, NotebookManageActivity.class);
 			startActivity(selfintent);
 			NotebookManageActivity.this.finish();
 			break;
-		case LPMENU_SHARE:
-			break;
-		}
+		/** 长按菜单的“分享”操作*/
+		//TODO待实现
+		case 2:
+			break;}
+		return super.onContextItemSelected(item);}
 
-		return super.onContextItemSelected(item);
-	}
-
-	/**
-	 * Menu按键名设置
-	 */
+	/**Menu按键名设置*/
 	@Override
 	public boolean onCreateOptionsMenu(Menu menu) {
 		String tab1Name = "新增笔记本";
 		String tab2Name = "更多";
-		menu.add(0, MENU_ADD, 0, tab1Name);
-		menu.add(0, MENU_MORE, 0, tab2Name);
-		return super.onCreateOptionsMenu(menu);
-	}
+		menu.add(0, Menu.FIRST, 0, tab1Name);
+		menu.add(0, Menu.FIRST+1, 0, tab2Name);
+		return super.onCreateOptionsMenu(menu);	}
 
-	// TODO MENU操作
-	/**
-	 * manage页面menu操作设置
-	 */
+	/**manage页面menu操作设置*/
 	@Override
 	public boolean onOptionsItemSelected(MenuItem item) {
 		switch (item.getItemId()) {
-		case MENU_ADD:
+		/** Menu中的“新增笔记本”操作*/
+		case Menu.FIRST:
 			Intent intent = new Intent();
 			intent.setClass(NotebookManageActivity.this, NotebookManageCreatActivity.class);
 			startActivity(intent);
 			break;
-
-		case MENU_MORE:
-			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);	}	};
 
-	// TODO 短按转接
-	/**
-	 * 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);
-		intent.setClass(this, NotesDisplayActivity.class);
+		startActivity(intent);}
 
-		startActivity(intent);
-	}
 
-	/**
-	 * manage页面listview内容创建
-	 */
+	/**manage页面listview内容创建 */
 	private void initViews() {
 		listView = (ListView) findViewById(R.id.notebookManageMylist);
-
 		ArrayList<Notebook> list = new ArrayList<Notebook>();
 		list = (ArrayList<Notebook>) notebookGateway.findAll();
 		NoteGateway noteGateway = (NoteGateway) Session.getInstance(this).query(Note.class);
 				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

 public class NotebookManageCreatActivity extends Activity {
 	/** 新建笔记本之文件名 */
 	private EditText notebookName;
+	private Bundle bundle = this.getIntent().getExtras();
 	private NotebookGateway notebookGateway = (NotebookGateway) Session.getInstance(this).query(Notebook.class);
-	private Bundle bundleTemp;
+	//TODO待修改
+	
 
 	protected void onCreate(Bundle savedInstanceState) {
 		super.onCreate(savedInstanceState);
 		setContentView(R.layout.notebookmanage_creat);
-		Bundle bundle = this.getIntent().getExtras();
-		bundleTemp = bundle;
+		
+		/** 两个底部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为空,即重新建立一个新笔记本*/
 		if (null == bundle) {
 			TextView titleView = (TextView) findViewById(R.id.noteBookManageTitle);
 			titleView.setText("新建笔记本");
 			EditText hintView = (EditText) findViewById(R.id.noteBookNewName);
-			hintView.setHint("请输入笔记本名");
-		} else {
+			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) {
-			if (null == bundleTemp) {
+			/**bundle为空,做新建笔记本操作*/
+			if (null == bundle) {
 				notebookName = (EditText) findViewById(R.id.noteBookNewName);
 				String content = notebookName.getText().toString();
 				Notebook notebook = new Notebook(content, "Zero");
 				Intent intent = new Intent();
 				intent.setClass(NotebookManageCreatActivity.this,
 						NotebookManageActivity.class);
-				startActivity(intent);
-			} else {
-				int listItemId = bundleTemp.getInt("listItemId");
+				startActivity(intent);}
+			/**bundle不为空,做修改笔记本操作*/
+			else {
+				int listItemId = bundle.getInt("listItemId");
 				notebookName = (EditText) findViewById(R.id.noteBookNewName);
 				String content = notebookName.getText().toString();
 				Notebook notebook = notebookGateway.findById(listItemId);
 				Intent intent = new Intent();
 				intent.setClass(NotebookManageCreatActivity.this,
 						NotebookManageActivity.class);
-				startActivity(intent);
-			}
-		}
-	};
+				startActivity(intent);}	}	};
 
 	/** 按钮“取消“的操作设置 */
 	OnClickListener cancle = new OnClickListener() {
 			Intent intent = new Intent();
 			intent.setClass(NotebookManageCreatActivity.this,
 					NotebookManageActivity.class);
-			startActivity(intent);
-		}
-	};
-}
+			startActivity(intent);}	};	}