Esempio n. 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 forecastFragment =
        ((ForecastFragment) getSupportFragmentManager().findFragmentById(R.id.fragment_forecast));
    forecastFragment.setUseTodayLayout(!mTwoPane);
  }
Esempio n. 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);
    }
  }
Esempio n. 3
0
 @Override
 protected void onResume() {
   super.onResume();
   String location = Utility.getPreferredLocation(this);
   // update the location in our second pane using the fragment manager
   if (location != null && !location.equals(mLocation)) {
     ForecastFragment ff =
         (ForecastFragment) getSupportFragmentManager().findFragmentById(R.id.fragment_forecast);
     if (null != ff) {
       ff.onLocationChanged();
     }
     DetailFragment df =
         (DetailFragment) getSupportFragmentManager().findFragmentByTag(DETAILFRAGMENT_TAG);
     if (null != df) {
       df.onLocationChanged(location);
     }
     mLocation = location;
   }
 }
 @Override
 public Fragment getItem(int position) {
   Forecast f = forecasts.get(position);
   return ForecastFragment.newInstance(activity, f);
 }
Esempio n. 5
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mLocation = Utility.getPreferredLocation(this);
    Uri contentUri = getIntent() != null ? getIntent().getData() : null;
    setContentView(R.layout.activity_main);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    ActionBar ab = getSupportActionBar();
    if (ab != null) ab.setDisplayShowTitleEnabled(false);

    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) {
        DetailActivityFragment fragment = new DetailActivityFragment();
        if (contentUri != null) {
          Bundle args = new Bundle();
          args.putParcelable(DetailActivityFragment.DETAIL_URI, contentUri);
          fragment.setArguments(args);
        }
        getSupportFragmentManager()
            .beginTransaction()
            .replace(R.id.weather_detail_container, fragment, DETAILFRAGMENT_TAG)
            .commit();
      }
    } else {
      mTwoPane = false;
      getSupportActionBar().setElevation(0f);
    }

    ForecastFragment forecastFragment =
        ((ForecastFragment) getSupportFragmentManager().findFragmentById(R.id.fragment_forecast));
    forecastFragment.setUseTodayLayout(!mTwoPane);
    if (contentUri != null) {
      forecastFragment.setInitialSelectedDate(
          WeatherContract.WeatherEntry.getDateFromUri(contentUri));
    }

    SunshineSyncAdapter.initializeSyncAdapter(this);

    // If Google Play Services is up to date, we'll want to register GCM. If it is not, we'll
    // skip the registration and this device will not receive any downstream messages from
    // our fake server. Because weather alerts are not a core feature of the app, this should
    // not affect the behavior of the app, from a user perspective.
    if (checkPlayServices()) {
      // Because this is the initial creation of the app, we'll want to be certain we have
      // a token. If we do not, then we will start the IntentService that will register this
      // application with GCM.
      SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
      boolean sentToken = sharedPreferences.getBoolean(SENT_TOKEN_TO_SERVER, false);
      if (!sentToken) {
        Intent intent = new Intent(this, RegistrationIntentService.class);
        startService(intent);
      }
    }
  }