Android Open Source - Sunshine Main Activity






From Project

Back to project page Sunshine.

License

The source code is released under:

MIT 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 me.kalehv.t.sunshine;
/*w  ww .  j  a va  2 s. c o m*/
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;

import java.lang.reflect.Method;


public class MainActivity extends ActionBarActivity
{
    private final String LOG_TAG = MainActivity.class.getSimpleName();

    @Override
    protected void onResume()
    {
        Log.v(LOG_TAG, "onResume");
        super.onResume();
    }

    @Override
    protected void onDestroy()
    {
        Log.v(LOG_TAG, "onDestroy");
        super.onDestroy();
    }

    @Override
    protected void onStart()
    {
        Log.v(LOG_TAG, "onStart");
        super.onStart();
    }

    @Override
    protected void onStop()
    {
        super.onStop();
        Log.v(LOG_TAG, "onStop");
    }

    @Override
    protected void onPause()
    {
        Log.v(LOG_TAG, "onPause");
        super.onPause();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        Log.v(LOG_TAG, "onCreate");

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        if (savedInstanceState == null)
        {
            getSupportFragmentManager().beginTransaction()
                    .add(R.id.container, new ForecastFragment())
                    .commit();
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu)
    {
        getMenuInflater().inflate(R.menu.main, menu);
        return super.onCreateOptionsMenu(menu);
    }

    @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.
        switch (item.getItemId())
        {
            case R.id.action_settings:
                Intent settingsIntent = new Intent(this, SettingsActivity.class);
                startActivity(settingsIntent);

            case R.id.action_map_location:
                onOpenPreferredLocationInMap();
        }
        return super.onOptionsItemSelected(item);
    }

    private void onOpenPreferredLocationInMap()
    {
        SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);

        String location = sharedPreferences.getString(
                getString(R.string.pref_location_key),
                getString(R.string.pref_location_default));

        Uri geoLocationUri = Uri.parse("geo:0,0?").buildUpon()
                .appendQueryParameter("q", location)
                .build();

        Intent mapIntent = new Intent(Intent.ACTION_VIEW);
        mapIntent.setData(geoLocationUri);

        startActivity(mapIntent);
    }
}




Java Source Code List

me.kalehv.t.sunshine.ApplicationTest.java
me.kalehv.t.sunshine.DetailActivity.java
me.kalehv.t.sunshine.ForecastFragment.java
me.kalehv.t.sunshine.FullTestSuite.java
me.kalehv.t.sunshine.MainActivity.java
me.kalehv.t.sunshine.SettingsActivity.java
me.kalehv.t.sunshine.TestDB.java
me.kalehv.t.sunshine.data.WeatherContract.java
me.kalehv.t.sunshine.data.WeatherDbHelper.java
me.kalehv.t.sunshine.data.WeatherProvider.java