PageRenderTime 7ms CodeModel.GetById 1ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

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