package com.jqyd.manager; import com.jqyd.app.MyApp; import com.jqyd.shareInterface.CheckState_interface; import com.jqyd.shareInterface.GpsService; import com.jqyd.shareInterface.Optsharepre_interface; import com.jqyd.son.Khlb; import android.app.Activity; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.location.LocationManager; import android.os.Bundle; import android.provider.Settings; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.Toast; public class Khbf extends Activity implements OnClickListener { private Button khbf; private Button msbf; private Button echf; private MyApp myApp; private Optsharepre_interface share_obj = null; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.khbf); khbf = (Button) this.findViewById(R.id.khbf); msbf = (Button) this.findViewById(R.id.msbf); echf = (Button) this.findViewById(R.id.echf); khbf.setOnClickListener(this); msbf.setOnClickListener(this); echf.setOnClickListener(this); myApp = (MyApp) this.getApplication(); share_obj = new Optsharepre_interface(Khbf.this); } @Override public void onClick(View v) { // TODO Auto-generated method stub if(v == khbf){ myApp.setModuleName("sczf"); startActivity(new Intent().setClass(this,Khlb.class)); }else if(v == msbf){ //String dwMode = new Optsharepre_interface(Khbf.this).getDataFromPres("DWMODE"); myApp.setModuleName("msbf"); share_obj.editPres("cjlx", "msbf"); boolean flag = checkGpState(); if (flag) { Intent stateService = new Intent(Khbf.this, GpsService.class); startService(stateService); startActivity(new Intent().setClass(this, Khcjlb.class)); } /*if(dwMode.equals("1")){ boolean flag = false; flag = checkGpState(); if(flag){ Intent stateService = new Intent(Khbf.this, GpsService.class); startService(stateService); startActivity(new Intent().setClass(this,Khcj.class)); } } */ }else if(v == echf){ myApp.setModuleName("echf"); startActivity(new Intent().setClass(this,Khlb.class)); } } /** * 检查GPS状态 */ private boolean checkGpState() { boolean flag = false; LocationManager locMgr = (LocationManager) this .getSystemService(Context.LOCATION_SERVICE); if (!locMgr .isProviderEnabled(android.location.LocationManager.GPS_PROVIDER)) { new AlertDialog.Builder(Khbf.this).setMessage("GPS模块不可用,请打开GPS功能") .setPositiveButton("确定", new DialogInterface.OnClickListener() { public void onClick( DialogInterface dialoginterface, int i) { Intent intent = new Intent(); intent .setAction(Settings.ACTION_LOCATION_SOURCE_SETTINGS); intent .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); } }).show(); }else{ flag = true; } return flag; } /** * 检测并启动Gps搜星 */ public void startGps(){ int gps_flag = new CheckState_interface(Khbf.this).checkGpState(); if(gps_flag == 1){//GPS设备已打开 Intent stateService = new Intent(Khbf.this, GpsService.class); startService(stateService); }else{//GPS设备未打开 Toast.makeText(this, "GPS模块不可用,请打开GPS功能!", Toast.LENGTH_LONG).show(); } } }