Example #1
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);

    appStatus = AppStatus.getInstance(this);
    mhandler = new Handler();
    //		loading = new ProgressDialog(this);
    //		loading.setMessage("Loading...");
    //		loading.setCancelable(true);

    startApp();
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_menu_category);

    // myTextView = (TextView) findViewById(R.id.myTextView);
    myButton = (ImageButton) findViewById(R.id.mapButton_1);
    myListView = (ListView) findViewById(R.id.myListView);
    mySpinner = (Spinner) findViewById(R.id.spinner1);

    //        myTextView = (TextView) findViewById(R.id.textView_test);

    DH = new DBHelper(this);

    Bundle bundle = getIntent().getExtras();
    spotname = bundle.getString("name"); // 鄉鎮縣市區(全區)
    spotengname = bundle.getString("engname"); // 縣市

    // 判斷是否有上網
    if (AppStatus.getInstance(this).isOnline(this)) {

      visitExternalLinks();

      // 讀取string array
      res = getResources();
      spotCategoryArray = res.getStringArray(R.array.spot_category);

      adapterTemp = ArrayAdapter.createFromResource(this, R.array.spot_category, R.layout.item2);

      adapterTemp.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

      mySpinner.setAdapter(adapterTemp);

      mySpinner.setOnItemSelectedListener(
          new OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View v, int position, long id) {
              spotCategory = spotCategoryArray[position];

              status = (LocationManager) getSystemService(LOCATION_SERVICE);

              boolean isGPSEnabled = status.isProviderEnabled(LocationManager.GPS_PROVIDER);
              boolean isNetworkEnabled = status.isProviderEnabled(LocationManager.NETWORK_PROVIDER);

              if (!isGPSEnabled && !isNetworkEnabled) {
                Toast.makeText(
                        ActivitySearchLocalCitiesSpotCategory.this, "請開啟定位服務", Toast.LENGTH_LONG)
                    .show();
                startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)); // ??????
              } else {

                double longitude;
                double latitude;

                if (isNetworkEnabled) {

                  Log.d("Network", "Network Enabled");
                  if (status != null) {
                    mostRecentLocation =
                        status.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
                    if (mostRecentLocation != null) {
                      latitude = mostRecentLocation.getLatitude();
                      longitude = mostRecentLocation.getLongitude();
                      Log.v(TAG, "Network " + latitude + "," + longitude);
                    }
                  }
                }

                if (isGPSEnabled) {
                  if (mostRecentLocation == null) {
                    Log.d("GPS", "GPS Enabled");
                    if (status != null) {
                      mostRecentLocation =
                          status.getLastKnownLocation(LocationManager.GPS_PROVIDER);
                      if (mostRecentLocation != null) {
                        latitude = mostRecentLocation.getLatitude();
                        longitude = mostRecentLocation.getLongitude();
                        Log.v(TAG, "GPS " + latitude + "," + longitude);
                      }
                    }
                  }
                }

                new MyTask(ActivitySearchLocalCitiesSpotCategory.this).execute();
              }
            }

            @Override
            public void onNothingSelected(AdapterView<?> arg0) {}
          });

      myButton.setOnClickListener(
          new View.OnClickListener() {

            @Override
            public void onClick(View v) {
              // TODO Auto-generated method stub
              Intent intent = new Intent();
              intent.setClass(ActivitySearchLocalCitiesSpotCategory.this, ActivityMap.class);
              intent.putExtra("list", Travelers);
              startActivity(intent);
              overridePendingTransition(R.anim.my_scale_action, R.anim.my_alpha_action);
            }
          });

    } else {
      openOptionsDialogIsNetworkAvailable();
    }
  }