예제 #1
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            Intent intent = Intent;
            Uri uri = null;
            String query = null;

            if (Intent.ActionSearch.Equals(intent.Action))
            {
                query = intent.GetStringExtra(SearchManager.Query);
            }
            else if (bundle != null)
            {
                query = bundle.GetString(SearchManager.Query);
            }

            if (query != null && query.Length > 0)
            {
                uri = Uri.WithAppendedPath(WikiNote.Notes.SEARCH_URI, Uri.Encode(query));
            }

            if (uri == null)
            {
                // somehow we got called w/o a query so fall back to a reasonable
                // default (all notes)
                uri = WikiNote.Notes.ALL_NOTES_URI;
            }

            // Do the query
            ICursor c = ManagedQuery(uri, WikiNote.WIKI_LISTNOTES_PROJECTION, null, null,
                        WikiNote.Notes.BY_TITLE_SORT_ORDER);
            _cursor = c;

            _helper = new WikiActivityHelper(this);

            // Bind the results of the search into the list
            ListAdapter = new SimpleCursorAdapter(
                                      this,
                                      Android.Resource.Layout.SimpleListItem1,
                                      _cursor,
                                      new String[] { WikiNote.Notes.TITLE },
                                      new int[] { Android.Resource.Id.Text1 });
            SetDefaultKeyMode(DefaultKey.Shortcut);
        }
예제 #2
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            SetContentView(Resource.Layout.Main);

            this._noteView = FindViewById<TextView>(Resource.Id.noteview);
            AndroidUri localUri = Intent.Data;

            if ((localUri == null) && (bundle != null))
            {
                localUri = AndroidUri.Parse(bundle.GetString(KEY_URL));
            }

            if ((localUri == null) || (localUri.PathSegments.Count < 2))
            {
                localUri = AndroidUri.WithAppendedPath(WikiNote.Notes.ALL_NOTES_URI, Resources.GetString(Resource.String.start_page));
            }

            ICursor localCursor = ManagedQuery(localUri, WikiNote.WIKI_NOTES_PROJECTION, null, null, null);

            bool newNote = false;
            if ((localCursor == null) || (localCursor.Count == 0))
            {
                try
                {
                    // no matching wikinote, so create it
                    localUri = ContentResolver.Insert(localUri, null);
                    if (localUri == null)
                    {
                        Log.Error("WikiNotes", "Failed to insert new wikinote into " + Intent.Data);
                        Finish();
                        return;
                    }
                    // make sure that the new note was created successfully, and
                    // select it
                    localCursor = ManagedQuery(localUri, WikiNote.WIKI_NOTES_PROJECTION, null, null, null);
                    if ((localCursor == null) || (localCursor.Count == 0))
                    {
                        Log.Error("WikiNotes", "Failed to open new wikinote: " + Intent.Data);
                        Finish();
                        return;
                    }
                    newNote = true;
                }
                catch (Exception ex)
                {
                    Log.Error(WikiNote.LOG_TAG, ex.Message);
                }
            }

            _uri = localUri;
            _cursor = localCursor;
            localCursor.MoveToFirst();
            _helper = new WikiActivityHelper(this);

            // get the note name
            String noteName = _cursor.GetString(_cursor
                .GetColumnIndexOrThrow(WikiNote.Notes.TITLE));
            _noteName = noteName;

            // set the title to the name of the page
            Title = Resources.GetString(Resource.String.wiki_title, noteName);

            // If a new note was created, jump straight into editing it
            if (newNote)
            {
                _helper.EditNote(noteName, null);
            }

            // Set the menu shortcut keys to be default keys for the activity as well
            SetDefaultKeyMode(DefaultKey.Shortcut);
        }