• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2010 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.example.android.searchabledict;
18 
19 import android.app.Activity;
20 import android.database.Cursor;
21 import android.net.Uri;
22 import android.os.Bundle;
23 import android.view.Menu;
24 import android.view.MenuInflater;
25 import android.view.MenuItem;
26 import android.widget.TextView;
27 
28 /**
29  * Displays a word and its definition.
30  */
31 public class WordActivity extends Activity {
32 
33     @Override
onCreate(Bundle savedInstanceState)34     protected void onCreate(Bundle savedInstanceState) {
35         super.onCreate(savedInstanceState);
36         setContentView(R.layout.word);
37 
38         Uri uri = getIntent().getData();
39         Cursor cursor = managedQuery(uri, null, null, null, null);
40 
41         if (cursor == null) {
42             finish();
43         } else {
44             cursor.moveToFirst();
45 
46             TextView word = (TextView) findViewById(R.id.word);
47             TextView definition = (TextView) findViewById(R.id.definition);
48 
49             int wIndex = cursor.getColumnIndexOrThrow(DictionaryDatabase.KEY_WORD);
50             int dIndex = cursor.getColumnIndexOrThrow(DictionaryDatabase.KEY_DEFINITION);
51 
52             word.setText(cursor.getString(wIndex));
53             definition.setText(cursor.getString(dIndex));
54         }
55     }
56 
57     @Override
onCreateOptionsMenu(Menu menu)58     public boolean onCreateOptionsMenu(Menu menu) {
59         MenuInflater inflater = getMenuInflater();
60         inflater.inflate(R.menu.options_menu, menu);
61         return true;
62     }
63 
64     @Override
onOptionsItemSelected(MenuItem item)65     public boolean onOptionsItemSelected(MenuItem item) {
66         switch (item.getItemId()) {
67             case R.id.search:
68                 onSearchRequested();
69                 return true;
70             default:
71                 return false;
72         }
73     }
74 }
75