• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2009 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.customlocale;
18 
19 import android.app.Activity;
20 import android.content.Intent;
21 import android.os.Bundle;
22 import android.text.TextUtils;
23 import android.util.Log;
24 import android.view.KeyEvent;
25 import android.view.View;
26 import android.widget.Button;
27 import android.widget.EditText;
28 
29 /**
30  * Dialog to ask the user for a new locale. <p/> Returns the locale code (e.g.
31  * "en_US") via an intent with a "locale" extra string and a "select" extra
32  * boolean.
33  */
34 public class NewLocaleDialog extends Activity implements View.OnClickListener {
35 
36     public static final String INTENT_EXTRA_LOCALE = "locale";
37     public static final String INTENT_EXTRA_SELECT = "select";
38 
39     private static final String TAG = "NewLocale";
40     private static final boolean DEBUG = true;
41     private Button mButtonAdd;
42     private Button mButtonAddSelect;
43     private EditText mEditText;
44     private boolean mWasEmpty;
45 
46     @Override
onCreate(Bundle savedInstanceState)47     protected void onCreate(Bundle savedInstanceState) {
48         super.onCreate(savedInstanceState);
49 
50         setContentView(R.layout.new_locale);
51 
52         mEditText = (EditText) findViewById(R.id.value);
53         mWasEmpty = true;
54 
55         mButtonAdd = (Button) findViewById(R.id.add);
56         mButtonAdd.setOnClickListener(this);
57 
58         mButtonAddSelect = (Button) findViewById(R.id.add_and_select);
59         mButtonAddSelect.setOnClickListener(this);
60     }
61 
onClick(View v)62     public void onClick(View v) {
63         String locale = mEditText.getText().toString();
64         boolean select = v == mButtonAddSelect;
65 
66         if (DEBUG) {
67             Log.d(TAG, "New Locale: " + locale + (select ? " + select" : ""));
68         }
69 
70         Intent data = new Intent(NewLocaleDialog.this, NewLocaleDialog.class);
71         data.putExtra(INTENT_EXTRA_LOCALE, locale);
72         data.putExtra(INTENT_EXTRA_SELECT, select);
73         setResult(RESULT_OK, data);
74 
75         finish();
76     }
77 }
78