Android Open Source - Sunshine Detail 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 net.alteridem.sunshine;
//www.  j a  va  2s .co  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.util.Locale;

public class DetailActivity extends ActionBarActivity {

    private static final String LOG_TAG = DetailActivity.class.getSimpleName();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_detail);
        if (savedInstanceState == null) {
            String date = getIntent().getStringExtra(WeatherDetailFragment.DATE_KEY);
            Bundle args = new Bundle();
            args.putString(WeatherDetailFragment.DATE_KEY, date);

            WeatherDetailFragment fragment = new WeatherDetailFragment();
            fragment.setArguments(args);

            getSupportFragmentManager().beginTransaction()
                    .add(R.id.weather_detail_container, fragment)
                    .commit();
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.detail, 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_view_location) {
            viewLocationOnMap();
            return true;
        }
        if (id == R.id.action_settings) {
            startActivity(new Intent(this, SettingsActivity.class));
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    private void viewLocationOnMap() {
        SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
        String location = sharedPreferences.getString(getString(R.string.pref_location_key), getString(R.string.pref_location_default));
        String uri = String.format(Locale.ENGLISH, "geo:0,0?q=%s", location);
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
        if(intent.resolveActivity(getPackageManager()) != null ) {
            startActivity(intent);
        } else {
            Log.d(LOG_TAG, "Couldn't call " + location);
        }
    }
}




Java Source Code List

net.alteridem.sunshine.DetailActivity.java
net.alteridem.sunshine.ForecastAdapter.java
net.alteridem.sunshine.ForecastFragment.java
net.alteridem.sunshine.ForecastItemViewHolder.java
net.alteridem.sunshine.IForecastFragmentHost.java
net.alteridem.sunshine.MainActivity.java
net.alteridem.sunshine.SettingsActivity.java
net.alteridem.sunshine.Utility.java
net.alteridem.sunshine.WeatherDataParser.java
net.alteridem.sunshine.WeatherDetailFragment.java
net.alteridem.sunshine.data.WeatherContract.java
net.alteridem.sunshine.data.WeatherDbHelper.java
net.alteridem.sunshine.data.WeatherProvider.java
net.alteridem.sunshine.sync.WeatherAuthenticatorService.java
net.alteridem.sunshine.sync.WeatherAuthenticator.java
net.alteridem.sunshine.sync.WeatherSyncAdapter.java
net.alteridem.sunshine.sync.WeatherSyncService.java