Skip to content

Instantly share code, notes, and snippets.

View derohimat's full-sized avatar
🏠
Working from home

Deni Rohimat derohimat

🏠
Working from home
View GitHub Profile
public class SettingsActivity extends PreferenceActivity
implements Preference.OnPreferenceChangeListener {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Add 'general' preferences, defined in the XML file
// TODO: Add preferences from XML
addPreferencesFromResource(R.xml.pref_general);
<resources>
<string name="app_name">Sunshine</string>
<string name="action_settings">Settings</string>
<string name="action_map">Map Location</string>
<string name="pref_location_label">Location</string>
<string name="pref_location_key" translatable="false">location</string>
<string name="pref_location_default" translatable="false">40377</string>
<string name="pref_units_label">Temperature Units</string>
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditTextPreference
android:defaultValue="@string/pref_location_default"
android:inputType="text"
android:key="@string/pref_location_key"
android:singleLine="true"
@derohimat
derohimat / MainFragment load Data
Last active April 9, 2016 04:49
Gist Sunshine MainFragment
private void loadData() {
mWeekForecastAdapter.clear();
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(mContext);
String location = sharedPreferences.getString(getString(R.string.pref_location_key),
getString(R.string.pref_location_default));
String units = sharedPreferences.getString(getString(R.string.pref_units_key),
getString(R.string.pref_units_metric));
Retrofit retrofit = new Retrofit.Builder()
@derohimat
derohimat / SimpleService
Last active April 9, 2016 04:47
Gist Simple Service Sunshine
public final class SimpleService {
public static final String API_URL = "http://api.openweathermap.org/data/2.5/forecast/";
public interface OpenWeatherMap {
@GET("daily?mode=json")
Call<ApiResponse> getWeather(
@Query("q") String city,
@Query("units") String units,
@Query("cnt") int count,