Back to project page Sunshine.
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.
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); } } }