1 /* 2 * Copyright (C) 2011 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.android.settings.inputmethod; 18 19 import com.android.settings.R; 20 21 import android.app.Activity; 22 import android.content.Intent; 23 import android.os.Bundle; 24 import android.view.View; 25 26 public class UserDictionaryAddWordActivity extends Activity { 27 28 private static final String STATE_KEY_IS_OPEN = "isOpen"; 29 30 public static final String MODE_EDIT_ACTION = "com.android.settings.USER_DICTIONARY_EDIT"; 31 public static final String MODE_INSERT_ACTION = "com.android.settings.USER_DICTIONARY_INSERT"; 32 33 private UserDictionaryAddWordContents mContents; 34 35 @Override 36 public void onCreate(final Bundle savedInstanceState) { 37 super.onCreate(savedInstanceState); 38 setContentView(R.layout.user_dictionary_add_word); 39 final Intent intent = getIntent(); 40 final String action = intent.getAction(); 41 final int mode; 42 if (MODE_EDIT_ACTION.equals(action)) { 43 mode = UserDictionaryAddWordContents.MODE_EDIT; 44 } else if (MODE_INSERT_ACTION.equals(action)) { 45 mode = UserDictionaryAddWordContents.MODE_INSERT; 46 } else { 47 // Can never come here because we only support these two actions in the manifest 48 throw new RuntimeException("Unsupported action: " + action); 49 } 50 51 // The following will get the EXTRA_WORD and EXTRA_LOCALE fields that are in the intent. 52 // We do need to add the action by hand, because UserDictionaryAddWordContents expects 53 // it to be in the bundle, in the EXTRA_MODE key. 54 final Bundle args = intent.getExtras(); 55 args.putInt(UserDictionaryAddWordContents.EXTRA_MODE, mode); 56 57 if (null != savedInstanceState) { 58 // Override options if we have a saved state. 59 args.putAll(savedInstanceState); 60 } 61 62 mContents = new UserDictionaryAddWordContents(getWindow().getDecorView(), args); 63 } 64 65 @Override 66 public void onSaveInstanceState(final Bundle outState) { 67 mContents.saveStateIntoBundle(outState); 68 } 69 70 public void onClickCancel(final View v) { 71 finish(); 72 } 73 74 public void onClickConfirm(final View v) { 75 mContents.apply(this); 76 finish(); 77 } 78 } 79