/androidsays/src/com/google/marvin/androidsays/MemeDownloader.java

http://eyes-free.googlecode.com/ · Java · 69 lines · 39 code · 10 blank · 20 comment · 0 complexity · 52feb21f8724eec4528521ca0fb74477 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.androidsays;
  17. import android.app.Activity;
  18. import android.content.Context;
  19. import android.content.Intent;
  20. import android.content.pm.PackageManager.NameNotFoundException;
  21. import android.os.Bundle;
  22. /**
  23. * Handles the downloading of theme files for mem.
  24. *
  25. * @author clchen@google.com (Charles L. Chen)
  26. */
  27. public class MemeDownloader extends Activity {
  28. private String dataSource;
  29. @Override
  30. public void onCreate(Bundle icicle) {
  31. super.onCreate(icicle);
  32. dataSource = this.getIntent().getData().toString();
  33. setContentView(R.layout.main);
  34. (new Thread(new loader())).start();
  35. }
  36. public void runMem() {
  37. startApp("com.google.marvin.androidsays", "AndroidSays");
  38. finish();
  39. }
  40. private void startApp(String packageName, String className) {
  41. try {
  42. int flags = Context.CONTEXT_INCLUDE_CODE | Context.CONTEXT_IGNORE_SECURITY;
  43. Context myContext = createPackageContext(packageName, flags);
  44. Class<?> appClass = myContext.getClassLoader().loadClass(packageName + "." + className);
  45. Intent intent = new Intent(myContext, appClass);
  46. startActivity(intent);
  47. } catch (NameNotFoundException e) {
  48. e.printStackTrace();
  49. } catch (ClassNotFoundException e) {
  50. e.printStackTrace();
  51. }
  52. }
  53. public class loader implements Runnable {
  54. public void run() {
  55. Unzipper.unzip(dataSource);
  56. runMem();
  57. }
  58. }
  59. }