Android Open Source - sunshine Main Activity






From Project

Back to project page sunshine.

License

The source code is released under:

Apache License

If you think the Android project sunshine listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.zmb.sunshine;
//www.  jav a2 s .  co m
import android.app.Activity;
import android.app.FragmentManager;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

import com.zmb.sunshine.sync.SunshineSyncAdapter;

public class MainActivity extends Activity implements ForecastFragment.Callback {

    private boolean mIsTwoPaneUi = false;

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

        FragmentManager fm = getFragmentManager();

        // check if we're in two pane UI or single pane
        if (findViewById(R.id.weather_detail_container) != null) {
            mIsTwoPaneUi = true;

            // show the detail view in this activity
            // (we only need to restore the detail fragment if
            // it wasn't already saved off)
            if (savedInstanceState== null) {
                fm.beginTransaction()
                        .replace(R.id.weather_detail_container, new DetailFragment())
                        .commit();
            }
        } else {
            mIsTwoPaneUi = false;
        }

        ForecastFragment ff = (ForecastFragment)(fm.findFragmentById(R.id.fragment_forecast));
        ff.setUseEnhancedTodayView(!mIsTwoPaneUi);

        SunshineSyncAdapter.initialize(this);
        SunshineSyncAdapter.syncNow(this);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            Intent i = new Intent(this, SettingsActivity.class);
            startActivity(i);
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    /**
     * Called when a particular day is selected from the forecast list.
     * @param date
     */
    @Override
    public void onItemSelected(String date) {
        if (mIsTwoPaneUi) {
            // on tablets, we replace the detail fragment
            DetailFragment details = new DetailFragment();
            Bundle dateBundle = new Bundle();
            dateBundle.putString(DetailFragment.DATE_KEY, date);
            details.setArguments(dateBundle);
            getFragmentManager().beginTransaction()
                    .replace(R.id.weather_detail_container, details)
                    .commit();
        } else {
            // on phones, we launch the detail activity
            Intent intent = new Intent(this, DetailActivity.class);
            intent.putExtra(DetailFragment.DATE_KEY, date);
            startActivity(intent);
        }
    }
}




Java Source Code List

com.zmb.sunshine.ApplicationTest.java
com.zmb.sunshine.DetailActivity.java
com.zmb.sunshine.DetailFragment.java
com.zmb.sunshine.ForecastAdapter.java
com.zmb.sunshine.ForecastFragment.java
com.zmb.sunshine.MainActivity.java
com.zmb.sunshine.SettingsActivity.java
com.zmb.sunshine.SettingsFragment.java
com.zmb.sunshine.Sunshine.java
com.zmb.sunshine.data.AWeatherDataParser.java
com.zmb.sunshine.data.Convert.java
com.zmb.sunshine.data.DayForecast.java
com.zmb.sunshine.data.DayOfWeek.java
com.zmb.sunshine.data.IWeatherDataParser.java
com.zmb.sunshine.data.WeatherParseException.java
com.zmb.sunshine.data.WeatherProvider.java
com.zmb.sunshine.data.db.AndroidDatabaseManager.java
com.zmb.sunshine.data.db.WeatherContract.java
com.zmb.sunshine.data.db.WeatherDbHelper.java
com.zmb.sunshine.data.openweathermap.OpenWeatherMapParser.java
com.zmb.sunshine.data.worldweatheronline.WorldWeatherOnlineParser.java
com.zmb.sunshine.sync.DummyAuthenticatorService.java
com.zmb.sunshine.sync.DummyAuthenticator.java
com.zmb.sunshine.sync.SunshineSyncAdapter.java
com.zmb.sunshine.sync.SunshineSyncService.java
com.zmb.sunshine.widget.SunshineWidget.java
com.zmb.utils.IoUtils.java