示例#1
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mLocation = Utility.getPreferredLocation(this);

    setContentView(R.layout.activity_main);
    if (findViewById(R.id.weather_detail_container) != null) {
      // The detail container view will be present only in the large-screen layouts
      // (res/layout-sw600dp). If this view is present, then the activity should be
      // in two-pane mode.
      mTwoPane = true;
      // In two-pane mode, show the detail view in this activity by
      // adding or replacing the detail fragment using a
      // fragment transaction.
      if (savedInstanceState == null) {
        getSupportFragmentManager()
            .beginTransaction()
            .replace(R.id.weather_detail_container, new DetailFragment(), DETAILFRAGMENT_TAG)
            .commit();
      }
    } else {
      mTwoPane = false;
      getSupportActionBar().setElevation(0f);
    }

    ForecastFragment ff =
        (ForecastFragment) getSupportFragmentManager().findFragmentById(R.id.fragment_forecast);
    ff.setUseTodayLayout(!mTwoPane); // if twopane then don't use, if not use
    SunshineSyncAdapter.initializeSyncAdapter(this);
  }
示例#2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    //        getSupportActionBar().setDisplayShowHomeEnabled(true);
    //        getSupportActionBar().setIcon(R.mipmap.ic_launcher);

    if (findViewById(R.id.weather_detail_container) != null) {
      // The detail container view will be present only in the large-screen layouts
      // (res/layout-sw600dp). If this view is present, then the activity should be
      // in two-pane mode.
      mTwoPane = true;
      // In two-pane mode, show the detail view in this activity by
      // adding or replacing the detail fragment using a
      // fragment transaction.
      if (savedInstanceState == null) {
        getSupportFragmentManager()
            .beginTransaction()
            .replace(R.id.weather_detail_container, new DetailFragment(), DETAILFRAGMENT_TAG)
            .commit();
      }
    } else {
      mTwoPane = false;
      getSupportActionBar().setElevation(0f);
    }

    ForecastFragment forecastFragment =
        ((ForecastFragment) getSupportFragmentManager().findFragmentById(R.id.fragment_forecast));
    forecastFragment.setUseTodayLayout(!mTwoPane);

    SunshineSyncAdapter.initializeSyncAdapter(this);

    // If Google Play Services is not available, some features, such as GCM-powered weather
    // alerts, will not be available.
    if (checkPlayServices()) {
      mGcm = GoogleCloudMessaging.getInstance(this);
      String regId = getRegistrationId(this);

      if (PROJECT_NUMBER.equals("Your Project Number")) {
        new AlertDialog.Builder(this)
            .setTitle("Needs Project Number")
            .setMessage(
                "GCM will not function in Sunshine until you set the Project Number to the one from the Google Developers Console.")
            .setPositiveButton(android.R.string.ok, null)
            .create()
            .show();
      } else if (regId.isEmpty()) {
        registerInBackground(this);
      }
    } else {
      Log.i(LOG_TAG, "No valid Google Play Services APK. Weather alerts will be disabled.");
      // Store regID as null
      storeRegistrationId(this, null);
    }
  }