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