|
| 1 | +/* |
| 2 | + Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + or more contributor license agreements. See the NOTICE file |
| 4 | + distributed with this work for additional information |
| 5 | + regarding copyright ownership. The ASF licenses this file |
| 6 | + to you under the Apache License, Version 2.0 (the |
| 7 | + "License"); you may not use this file except in compliance |
| 8 | + with the License. You may obtain a copy of the License at |
| 9 | +
|
| 10 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +
|
| 12 | + Unless required by applicable law or agreed to in writing, |
| 13 | + software distributed under the License is distributed on an |
| 14 | + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + KIND, either express or implied. See the License for the |
| 16 | + specific language governing permissions and limitations |
| 17 | + under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +package cn.imaq.missionhelper; |
| 21 | + |
| 22 | +import android.os.Bundle; |
| 23 | +import android.provider.Settings; |
| 24 | +import android.webkit.WebView; |
| 25 | +import android.widget.Toast; |
| 26 | + |
| 27 | +import com.amap.api.location.AMapLocation; |
| 28 | +import com.amap.api.location.AMapLocationClient; |
| 29 | +import com.amap.api.location.AMapLocationClientOption; |
| 30 | +import com.amap.api.location.AMapLocationListener; |
| 31 | + |
| 32 | +import org.apache.cordova.*; |
| 33 | + |
| 34 | +public class MainActivity extends CordovaActivity |
| 35 | +{ |
| 36 | + private AMapLocationClient locationClient = null; |
| 37 | + private long backTime = 0; |
| 38 | + |
| 39 | + @Override |
| 40 | + public void onCreate(Bundle savedInstanceState) |
| 41 | + { |
| 42 | + super.onCreate(savedInstanceState); |
| 43 | + // Set by <content src="index.html" /> in config.xml |
| 44 | + loadUrl(launchUrl); |
| 45 | + } |
| 46 | + |
| 47 | + @Override |
| 48 | + public void onDestroy() { |
| 49 | + super.onDestroy(); |
| 50 | + if (locationClient != null) { |
| 51 | + locationClient.stopLocation(); |
| 52 | + locationClient.onDestroy(); |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + @Override |
| 57 | + public void onBackPressed() { |
| 58 | + long time = System.currentTimeMillis(); |
| 59 | + if (time - backTime > 2000) { |
| 60 | + Toast.makeText(getApplicationContext(), "Press again to exit", Toast.LENGTH_SHORT).show(); |
| 61 | + backTime = time; |
| 62 | + } else { |
| 63 | + System.exit(0); |
| 64 | + } |
| 65 | + } |
| 66 | +} |
0 commit comments