1/*
2 * Copyright (C) 2007 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
17package com.android.quake;
18
19import android.app.Activity;
20import android.os.Bundle;
21import android.util.Log;
22import android.view.WindowManager;
23
24import java.io.File;
25
26
27public class QuakeActivity extends Activity {
28
29    QuakeView mQuakeView;
30
31    static QuakeLib mQuakeLib;
32
33    boolean mKeepScreenOn = true;
34
35    @Override protected void onCreate(Bundle icicle) {
36        Log.i("QuakeActivity", "onCreate");
37        super.onCreate(icicle);
38        if (USE_DOWNLOADER) {
39            if (! DownloaderActivity.ensureDownloaded(this,
40                    getString(R.string.quake_customDownloadText), FILE_CONFIG_URL,
41                    CONFIG_VERSION, SDCARD_DATA_PATH, USER_AGENT)) {
42                return;
43            }
44        }
45
46        if (foundQuakeData()) {
47
48            if (mQuakeLib == null) {
49                mQuakeLib = new QuakeLib();
50                if(! mQuakeLib.init()) {
51                    setContentView(new QuakeViewNoData(
52                            getApplication(),
53                            QuakeViewNoData.E_INITFAILED));
54                    return;
55                }
56            }
57
58            if (mKeepScreenOn) {
59                getWindow().setFlags(
60                        WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,
61                        WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
62            }
63
64            if (mQuakeView == null) {
65                mQuakeView = new
66                QuakeView(getApplication());
67                mQuakeView.setQuakeLib(mQuakeLib);
68            }
69            setContentView(mQuakeView);
70        }
71        else {
72            setContentView(new QuakeViewNoData(getApplication(),
73                            QuakeViewNoData.E_NODATA));
74        }
75    }
76
77    @Override protected void onPause() {
78        super.onPause();
79        if (mQuakeView != null) {
80            mQuakeView.onPause();
81        }
82    }
83
84    @Override protected void onResume() {
85        super.onResume();
86        if (mQuakeView != null) {
87            mQuakeView.onResume();
88        }
89    }
90
91    @Override protected void onDestroy() {
92        super.onDestroy();
93        if (mQuakeLib != null) {
94            mQuakeLib.quit();
95        }
96    }
97
98    private boolean foundQuakeData() {
99        return fileExists(SDCARD_DATA_PATH + PAK0_PATH)
100		|| fileExists(INTERNAL_DATA_PATH + PAK0_PATH);
101    }
102
103    private boolean fileExists(String s) {
104        File f = new File(s);
105        return f.exists();
106    }
107
108    private final static boolean USE_DOWNLOADER = false;
109
110    private final static String FILE_CONFIG_URL =
111        "http://example.com/android/quake/quake11.config";
112    private final static String CONFIG_VERSION = "1.1";
113    private final static String SDCARD_DATA_PATH = "/sdcard/data/quake";
114    private final static String INTERNAL_DATA_PATH = "/data/quake";
115    private final static String PAK0_PATH = "/id1/pak0.pak";
116    private final static String USER_AGENT = "Android Quake Downloader";
117
118}
119