OSDN Git Service

T27936
authorYuji Konishi <yuji.k64613@gmail.com>
Fri, 30 Mar 2012 06:31:32 +0000 (15:31 +0900)
committerYuji Konishi <yuji.k64613@gmail.com>
Fri, 30 Mar 2012 06:31:32 +0000 (15:31 +0900)
workspace/EverMemo/res/layout/setting.xml
workspace/EverMemo/src/com/yuji/em/SelectNoteListActivity.java
workspace/EverMemo/src/com/yuji/em/SettingActivity.java
workspace/EverMemo/src/com/yuji/em/common/Constant.java

index f31050e..9c8efc6 100644 (file)
@@ -5,17 +5,18 @@
     android:layout_height="fill_parent"
     >
     <ScrollView android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1">
-               <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical">
+               <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:padding="0px">
                        <LinearLayout android:id="@+id/settingLayout" android:padding="6px" android:layout_margin="3px" android:background="#666666" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical">
                                <TextView android:text="@+string/date_title" android:background="#ccffff" android:layout_width="fill_parent" android:layout_height="wrap_content"></TextView>
                                <TextView android:id="@+id/settingMessage" android:padding="10px" android:text="@+string/selectTitle" android:background="#ffff66" android:layout_width="fill_parent" android:layout_height="wrap_content"></TextView>
                        </LinearLayout>
-                       <TextView android:text="@+string/date_title" android:background="#99cccc" android:layout_width="fill_parent" android:layout_height="wrap_content"></TextView>
-                       <Button android:text="ユーザ/パスワードを設定する" android:id="@+id/settingUserButton" android:layout_width="fill_parent" android:layout_height="wrap_content" /> 
-                       <TextView android:text="@+string/date_title" android:background="#99cccc" android:layout_width="fill_parent" android:layout_height="wrap_content"></TextView>
-                       <Button android:text="送信先のノートを設定する" android:id="@+id/settingNoteButton" android:layout_width="fill_parent" android:layout_height="wrap_content" /> 
-                       <TextView android:text="@+string/date_title" android:background="#99cccc" android:layout_width="fill_parent" android:layout_height="wrap_content"></TextView>
-                       <Button android:text="ヘッダーを設定する" android:id="@+id/settingHeaderButton" android:layout_width="fill_parent" android:layout_height="wrap_content" /> 
+                       <TextView android:text="@+string/date_title" android:background="#99cccc" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_margin="0px"></TextView>
+                       <Button android:text="ユーザ/パスワードを設定する" android:id="@+id/settingUserButton" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_margin="0px" /> 
+                       <TextView android:text="@+string/date_title" android:background="#99cccc" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_margin="0px"></TextView>
+                       <TextView android:text="@+string/date_title" android:background="#cc99cc" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_margin="0px"></TextView>
+                       <Button android:text="送信先のノートを設定する" android:id="@+id/settingNoteButton" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_margin="0px" /> 
+                       <TextView android:text="@+string/date_title" android:background="#99cccc" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_margin="0px"></TextView>
+                       <Button android:text="ヘッダーを設定する" android:id="@+id/settingHeaderButton" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_margin="0px" /> 
                </LinearLayout>
        </ScrollView>
        <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content">
index e40fbad..2a4e3e3 100644 (file)
@@ -2,6 +2,7 @@ package com.yuji.em;
 
 import java.util.List;
 
+import android.content.Context;
 import android.content.Intent;
 import android.os.Bundle;
 import android.view.View;
@@ -10,7 +11,6 @@ import android.widget.AdapterView;
 import android.widget.AdapterView.OnItemClickListener;
 import android.widget.ArrayAdapter;
 import android.widget.Button;
-import android.widget.Checkable;
 import android.widget.LinearLayout;
 import android.widget.ListView;
 import android.widget.TextView;
@@ -20,8 +20,10 @@ import com.yuji.em.common.Constant;
 import com.yuji.em.data.Note;
 import com.yuji.em.data.NoteDao;
 import com.yuji.em.utility.BaseActivity;
+import com.yuji.em.utility.EditPrefUtil;
 
 public class SelectNoteListActivity extends BaseActivity {
+       private EditPrefUtil pref = new EditPrefUtil(this);
        private LinearLayout messageLayout = null;
        private TextView titleView = null;
        private TextView messageView = null;
@@ -31,11 +33,10 @@ public class SelectNoteListActivity extends BaseActivity {
        private Button yesButton;
        private Button noButton;
        private ListView selectListView;
-
-       private View prevListView = null;
-       private int selectedIndex = -1;
        private boolean isEmpty = true;
 
+       private static int selectedIndex = -1;
+
        @Override
        public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
@@ -88,73 +89,56 @@ public class SelectNoteListActivity extends BaseActivity {
                        }
                });
 
-               // float fSize = titleView.getTextSize();
-               // messageView.setTextSize((float) (fSize * 1.0));
-
-               // #27899 TODO
+               // #27899
                selectListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
-               // selectListView.setItemsCanFocus(false);
-               // selectListView.setFocusable(true);
-               // selectListView.setFocusableInTouchMode(true);
 
                updateList();
-
+               selectedIndex = pref.getInt(Constant.PREF_NOTE_INDEX);
                setStatus(null);
        }
 
-       // TODO
-//     @Override
-//     public void onStart(){
-//             super.onStart();
-//             selectListView.clearChoices();
-//     }
-       
        @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
                if (resultCode == RESULT_OK) {
+                       init(this);     
                        updateList();
                        setStatus(null);
                }
        }
 
+       @Override
+       protected void onStart(){
+               super.onStart();
+               
+               selectedIndex = pref.getInt(Constant.PREF_NOTE_INDEX);
+       }
+       
+       @Override
+       protected void onPause() {
+               pref.put(Constant.PREF_NOTE_INDEX, selectedIndex);
+               pref.update();
+               
+               super.onPause();
+       }
+
        private void updateList() {
                NoteDao dao = NoteDao.getInstance();
                List<Note> list = dao.search(this);
-               // ArrayAdapter<Note> adapter = new ArrayAdapter<Note>(this,
-               // android.R.layout.simple_list_item_1, list);
                ArrayAdapter<Note> adapter = new ArrayAdapter<Note>(this,
                                R.layout.simple_list_item_2, R.id.text3, list);
                selectListView.setAdapter(adapter);
-               
-//             int size = selectListView.getChildCount();
-//             for (int i = 0; i < size; i++){
-//                     Checkable v = (Checkable)selectListView.getChildAt(i);
-//                     v.setChecked(false);
-//             }
 
-               selectedIndex = -1;
                isEmpty = dao.isEmpty(list);
        }
 
        protected void selectListViewOnItemClick(AdapterView<?> parent, View view,
                        int position, long id) {
-
-               if (view == prevListView) {
-                       return;
-               }
-               // #27594
-               // if (prevListView != null) {
-               // prevListView.setBackgroundColor(Color.WHITE);
-               // }
-               // view.setBackgroundColor(0xffccffcc);
-               prevListView = view;
-
                selectedIndex = position;
                setStatus(parent);
        }
 
        private void editButtonOnClick() {
-               if (prevListView == null || selectedIndex < 0) {
+               if (selectedIndex < 0) {
                        return;
                }
 
@@ -172,6 +156,10 @@ public class SelectNoteListActivity extends BaseActivity {
        }
 
        private void yesButtonOnClick() {
+               if (selectedIndex < 0) {
+                       return;
+               }
+
                NoteDao dao = NoteDao.getInstance();
                Note note = new Note("", "");
                dao.update(this, note, selectedIndex);
@@ -185,6 +173,10 @@ public class SelectNoteListActivity extends BaseActivity {
                setStatus(noButton);
        }
 
+       private boolean isSelected() {
+               return selectedIndex >= 0;
+       }
+
        private void setStatus(View view) {
                if (view == null) {
                        if (isEmpty) {
@@ -193,8 +185,7 @@ public class SelectNoteListActivity extends BaseActivity {
                                messageView.setText("\91\97\90M\90æ\82Ì\83m\81[\83g\82ð\90Ý\92è\82·\82é\82É\82Í\81A\83\8a\83X\83g\82ð\91I\91ð\82µ\81A\81u\8dX\90V\81v\83{\83^\83\93\82ð\89\9f\82µ\82Ä\82­\82¾\82³\82¢\81B"); // TODO
                                selectListView.setEnabled(true);
                                editButton.setVisibility(View.VISIBLE);
-                               //editButton.setEnabled(false);
-                               editButton.setEnabled(selectListView.getCheckedItemPosition() >= 0);
+                               editButton.setEnabled(isSelected());
                                deleteButton.setVisibility(View.VISIBLE);
                                deleteButton.setEnabled(false);
                                yesButton.setVisibility(View.GONE);
@@ -204,8 +195,7 @@ public class SelectNoteListActivity extends BaseActivity {
                                                : View.GONE);
                                selectListView.setEnabled(true);
                                editButton.setVisibility(View.VISIBLE);
-                               //editButton.setEnabled(false);
-                               editButton.setEnabled(selectListView.getCheckedItemPosition() >= 0);
+                               editButton.setEnabled(isSelected());
                                deleteButton.setVisibility(View.VISIBLE);
                                deleteButton.setEnabled(false);
                                yesButton.setVisibility(View.GONE);
@@ -215,8 +205,7 @@ public class SelectNoteListActivity extends BaseActivity {
                        messageLayout.setVisibility((isEmpty) ? View.VISIBLE : View.GONE);
                        selectListView.setEnabled(true);
                        editButton.setVisibility(View.VISIBLE);
-                       //editButton.setEnabled(true);
-                       editButton.setEnabled(selectListView.getCheckedItemPosition() >= 0);
+                       editButton.setEnabled(isSelected());
                        Note item = (Note) selectListView.getItemAtPosition(selectedIndex);
                        deleteButton.setVisibility(View.VISIBLE);
                        deleteButton.setEnabled(!CommonUtil.isNull(item.getTitle()));
@@ -236,4 +225,12 @@ public class SelectNoteListActivity extends BaseActivity {
                        setStatus(selectListView);
                }
        }
+       
+       public static void init(Context context){
+               EditPrefUtil pref = new EditPrefUtil(context);
+               pref.put(Constant.PREF_NOTE_INDEX, -1);
+               pref.update();
+               
+               selectedIndex = -1;
+       }
 }
index 689f3ce..d54604c 100644 (file)
@@ -65,6 +65,7 @@ public class SettingActivity extends BaseActivity {
 
        private void noteButtonOnClick(){
                NoteListActivity.init();
+               SelectNoteListActivity.init(this);
                
                Intent intent = new Intent(this,
                                (Class<?>) SelectNoteListActivity.class);
index 58e6a31..a61eb49 100644 (file)
@@ -8,6 +8,8 @@ public class Constant {
        public final static String PREF_NOTE_DAO = "NOTE_DAO";
        public final static String PREF_NOTE_INDEX = "NOTE_INDEX";
        
+       public final static String PREF_SELECTED_INDEX = "SELECTED_INDEX";
+
        public final static String EXTRA_INDEX = "EXTRA_INDEX";
        
        public final static int TOGGLE_SIZE = 5;