PageRenderTime 9ms CodeModel.GetById 1ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/randroid/src/com/google/marvin/randroid/PrefsActivity.java

http://eyes-free.googlecode.com/
Java | 78 lines | 45 code | 10 blank | 23 comment | 2 complexity | 5d20ea3f263517b5225f58e02a199d84 MD5 | raw file
 1/*
 2 * Copyright (C) 2008 Google Inc.
 3 * 
 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 5 * use this file except in compliance with the License. You may obtain a copy of
 6 * 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, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
14 * the License.
15 */
16package com.google.marvin.randroid;
17
18import com.google.tts.TTS;
19
20import android.content.Context;
21import android.content.Intent;
22import android.content.pm.PackageManager.NameNotFoundException;
23import android.net.Uri;
24import android.os.Bundle;
25import android.preference.Preference;
26import android.preference.PreferenceActivity;
27import android.preference.Preference.OnPreferenceClickListener;
28import android.view.WindowManager;
29
30/**
31 * Displays preferences
32 * 
33 * @author clchen@google.com (Charles L. Chen)
34 */
35public class PrefsActivity extends PreferenceActivity {
36
37  @Override
38  protected void onCreate(Bundle savedInstanceState) {
39    super.onCreate(savedInstanceState);
40
41    // Have the system blur any windows behind this one.
42    getWindow().setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND,
43        WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
44
45    addPreferencesFromResource(R.xml.prefs);
46
47    final Context ctx = this;
48
49    Preference ttsSettings = findPreference("tts_settings");
50    ttsSettings.setOnPreferenceClickListener(new OnPreferenceClickListener() {
51      public boolean onPreferenceClick(Preference preference) {
52        if (TTS.isInstalled(ctx)) {
53          try {
54            int flags = Context.CONTEXT_INCLUDE_CODE | Context.CONTEXT_IGNORE_SECURITY;
55            Context myContext = createPackageContext("com.google.tts", flags);
56            Class<?> appClass =
57                myContext.getClassLoader().loadClass("com.google.tts.ConfigurationManager");
58            Intent intent = new Intent(myContext, appClass);
59            startActivity(intent);
60          } catch (NameNotFoundException e) {
61            // TODO Auto-generated catch block
62            e.printStackTrace();
63          } catch (ClassNotFoundException e) {
64            // TODO Auto-generated catch block
65            e.printStackTrace();
66          }
67        } else {
68          Uri marketUri = Uri.parse("market://search?q=pname:com.google.tts");
69          Intent marketIntent = new Intent(Intent.ACTION_VIEW, marketUri);
70          startActivity(marketIntent);
71        }
72        return true;
73      }
74    });
75  }
76
77
78}