/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. */
  16. package com.google.marvin.randroid;
  17. import com.google.tts.TTS;
  18. import android.content.Context;
  19. import android.content.Intent;
  20. import android.content.pm.PackageManager.NameNotFoundException;
  21. import android.net.Uri;
  22. import android.os.Bundle;
  23. import android.preference.Preference;
  24. import android.preference.PreferenceActivity;
  25. import android.preference.Preference.OnPreferenceClickListener;
  26. import android.view.WindowManager;
  27. /**
  28. * Displays preferences
  29. *
  30. * @author clchen@google.com (Charles L. Chen)
  31. */
  32. public class PrefsActivity extends PreferenceActivity {
  33. @Override
  34. protected void onCreate(Bundle savedInstanceState) {
  35. super.onCreate(savedInstanceState);
  36. // Have the system blur any windows behind this one.
  37. getWindow().setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND,
  38. WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
  39. addPreferencesFromResource(R.xml.prefs);
  40. final Context ctx = this;
  41. Preference ttsSettings = findPreference("tts_settings");
  42. ttsSettings.setOnPreferenceClickListener(new OnPreferenceClickListener() {
  43. public boolean onPreferenceClick(Preference preference) {
  44. if (TTS.isInstalled(ctx)) {
  45. try {
  46. int flags = Context.CONTEXT_INCLUDE_CODE | Context.CONTEXT_IGNORE_SECURITY;
  47. Context myContext = createPackageContext("com.google.tts", flags);
  48. Class<?> appClass =
  49. myContext.getClassLoader().loadClass("com.google.tts.ConfigurationManager");
  50. Intent intent = new Intent(myContext, appClass);
  51. startActivity(intent);
  52. } catch (NameNotFoundException e) {
  53. // TODO Auto-generated catch block
  54. e.printStackTrace();
  55. } catch (ClassNotFoundException e) {
  56. // TODO Auto-generated catch block
  57. e.printStackTrace();
  58. }
  59. } else {
  60. Uri marketUri = Uri.parse("market://search?q=pname:com.google.tts");
  61. Intent marketIntent = new Intent(Intent.ACTION_VIEW, marketUri);
  62. startActivity(marketIntent);
  63. }
  64. return true;
  65. }
  66. });
  67. }
  68. }