-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
383 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
app/src/main/java/com/calgen/prodek/sunshine_v2/Activity/AppCompactPreferenceActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package com.calgen.prodek.sunshine_v2.Activity; | ||
|
||
import android.content.res.Configuration; | ||
import android.os.Bundle; | ||
import android.preference.PreferenceActivity; | ||
import android.support.annotation.LayoutRes; | ||
import android.support.annotation.Nullable; | ||
import android.support.v7.app.ActionBar; | ||
import android.support.v7.app.AppCompatDelegate; | ||
import android.support.v7.widget.Toolbar; | ||
import android.view.MenuInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
|
||
/** | ||
* Created by Gurupad on 15-Jun-16. | ||
*/ | ||
public abstract class AppCompactPreferenceActivity extends PreferenceActivity { | ||
|
||
private AppCompatDelegate mDelegate; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
getDelegate().installViewFactory(); | ||
getDelegate().onCreate(savedInstanceState); | ||
super.onCreate(savedInstanceState); | ||
} | ||
|
||
@Override | ||
protected void onPostCreate(Bundle savedInstanceState) { | ||
super.onPostCreate(savedInstanceState); | ||
getDelegate().onPostCreate(savedInstanceState); | ||
} | ||
|
||
public ActionBar getSupportActionBar() { | ||
return getDelegate().getSupportActionBar(); | ||
} | ||
|
||
public void setSupportActionBar(@Nullable Toolbar toolbar) { | ||
getDelegate().setSupportActionBar(toolbar); | ||
} | ||
|
||
@Override | ||
public MenuInflater getMenuInflater() { | ||
return getDelegate().getMenuInflater(); | ||
} | ||
|
||
@Override | ||
public void setContentView(@LayoutRes int layoutResID) { | ||
getDelegate().setContentView(layoutResID); | ||
} | ||
|
||
@Override | ||
public void setContentView(View view) { | ||
getDelegate().setContentView(view); | ||
} | ||
|
||
@Override | ||
public void setContentView(View view, ViewGroup.LayoutParams params) { | ||
getDelegate().setContentView(view, params); | ||
} | ||
|
||
@Override | ||
public void addContentView(View view, ViewGroup.LayoutParams params) { | ||
getDelegate().addContentView(view, params); | ||
} | ||
|
||
@Override | ||
protected void onPostResume() { | ||
super.onPostResume(); | ||
getDelegate().onPostResume(); | ||
} | ||
|
||
@Override | ||
protected void onTitleChanged(CharSequence title, int color) { | ||
super.onTitleChanged(title, color); | ||
getDelegate().setTitle(title); | ||
} | ||
|
||
@Override | ||
public void onConfigurationChanged(Configuration newConfig) { | ||
super.onConfigurationChanged(newConfig); | ||
getDelegate().onConfigurationChanged(newConfig); | ||
} | ||
|
||
@Override | ||
protected void onStop() { | ||
super.onStop(); | ||
getDelegate().onStop(); | ||
} | ||
|
||
@Override | ||
protected void onDestroy() { | ||
super.onDestroy(); | ||
getDelegate().onDestroy(); | ||
} | ||
|
||
public void invalidateOptionsMenu() { | ||
getDelegate().invalidateOptionsMenu(); | ||
} | ||
|
||
private AppCompatDelegate getDelegate() { | ||
if (mDelegate == null) { | ||
mDelegate = AppCompatDelegate.create(this, null); | ||
} | ||
return mDelegate; | ||
} | ||
} |
17 changes: 9 additions & 8 deletions
17
...lgen/prodek/sunshine_v2/MainActivity.java → .../sunshine_v2/Activity/DetailActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,41 @@ | ||
package com.calgen.prodek.sunshine_v2; | ||
package com.calgen.prodek.sunshine_v2.Activity; | ||
|
||
import android.content.Intent; | ||
import android.os.Bundle; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.support.v7.widget.Toolbar; | ||
import android.view.Menu; | ||
import android.view.MenuItem; | ||
|
||
public class MainActivity extends AppCompatActivity { | ||
import com.calgen.prodek.sunshine_v2.R; | ||
|
||
public class DetailActivity extends AppCompatActivity { | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
setContentView(R.layout.activity_detail); | ||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); | ||
setSupportActionBar(toolbar); | ||
getSupportActionBar().setDisplayHomeAsUpEnabled(true); | ||
} | ||
|
||
@Override | ||
public boolean onCreateOptionsMenu(Menu menu) { | ||
// Inflate the menu; this adds items to the action bar if it is present. | ||
getMenuInflater().inflate(R.menu.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(); | ||
|
||
//noinspection SimplifiableIfStatement | ||
if (id == R.id.action_settings) { | ||
startActivity(new Intent(this, SettingsActivity.class)); | ||
return true; | ||
} | ||
|
||
return super.onOptionsItemSelected(item); | ||
} | ||
|
||
} |
69 changes: 69 additions & 0 deletions
69
app/src/main/java/com/calgen/prodek/sunshine_v2/Activity/MainActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package com.calgen.prodek.sunshine_v2.Activity; | ||
|
||
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.AppCompatActivity; | ||
import android.support.v7.widget.Toolbar; | ||
import android.util.Log; | ||
import android.view.Menu; | ||
import android.view.MenuItem; | ||
|
||
import com.calgen.prodek.sunshine_v2.R; | ||
|
||
public class MainActivity extends AppCompatActivity { | ||
|
||
private static final String LOG_TAG = MainActivity.class.getSimpleName(); | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); | ||
setSupportActionBar(toolbar); | ||
} | ||
|
||
@Override | ||
public boolean onCreateOptionsMenu(Menu menu) { | ||
// Inflate the menu; this adds items to the action bar if it is present. | ||
getMenuInflater().inflate(R.menu.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(); | ||
|
||
switch (id) { | ||
case R.id.action_settings: | ||
startActivity(new Intent(this, SettingsActivity.class)); | ||
return true; | ||
|
||
case R.id.action_map: | ||
openPreferredLocationInMap(); | ||
return true; | ||
} | ||
return super.onOptionsItemSelected(item); | ||
} | ||
|
||
private void openPreferredLocationInMap() { | ||
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); | ||
|
||
String preferredLocation = sharedPreferences.getString( | ||
getResources().getString(R.string.pref_location_key), | ||
getResources().getString(R.string.pref_location_default)); | ||
|
||
Uri gmmIntentUri = Uri.parse("geo:0,0?q=" + preferredLocation); | ||
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri); | ||
if (mapIntent.resolveActivity(getPackageManager()) != null) { | ||
startActivity(mapIntent); | ||
} else { | ||
Log.e(LOG_TAG, "Couldn't alunch the map activity"); | ||
} | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
app/src/main/java/com/calgen/prodek/sunshine_v2/Activity/SettingsActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package com.calgen.prodek.sunshine_v2.Activity; | ||
|
||
import android.os.Bundle; | ||
import android.preference.ListPreference; | ||
import android.preference.Preference; | ||
import android.preference.PreferenceManager; | ||
import android.support.v4.app.NavUtils; | ||
import android.view.MenuItem; | ||
|
||
import com.calgen.prodek.sunshine_v2.R; | ||
|
||
/** | ||
* Created by Gurupad on 15-Jun-16. | ||
*/ | ||
public class SettingsActivity extends AppCompactPreferenceActivity implements Preference.OnPreferenceChangeListener { | ||
|
||
@Override | ||
public void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
// Add 'general' preferences, defined in the XML file | ||
addPreferencesFromResource(R.xml.pref_general); | ||
|
||
getSupportActionBar().setDisplayHomeAsUpEnabled(true); | ||
|
||
// For all preferences, attach an OnPreferenceChangeListener so the UI summary can be | ||
// updated when the preference changes. | ||
bindPreferenceSummaryToValue(findPreference(getResources().getString(R.string.pref_location_key))); | ||
bindPreferenceSummaryToValue(findPreference(getResources().getString(R.string.pref_temperature_key))); | ||
} | ||
|
||
|
||
@Override | ||
public boolean onOptionsItemSelected(MenuItem item) { | ||
|
||
if (item.getItemId() == android.R.id.home) { | ||
NavUtils.navigateUpFromSameTask(this); | ||
return true; | ||
} | ||
return super.onOptionsItemSelected(item); | ||
} | ||
|
||
/** | ||
* Attaches a listener so the summary is always updated with the preference value. | ||
* Also fires the listener once, to initialize the summary (so it shows up before the value | ||
* is changed.) | ||
*/ | ||
private void bindPreferenceSummaryToValue(Preference preference) { | ||
// Set the listener to watch for value changes. | ||
preference.setOnPreferenceChangeListener(this); | ||
|
||
// Trigger the listener immediately with the preference's | ||
// current value. | ||
onPreferenceChange(preference, | ||
PreferenceManager | ||
.getDefaultSharedPreferences(preference.getContext()) | ||
.getString(preference.getKey(), "")); | ||
} | ||
|
||
@Override | ||
public boolean onPreferenceChange(Preference preference, Object value) { | ||
String stringValue = value.toString(); | ||
|
||
if (preference instanceof ListPreference) { | ||
// For list preferences, look up the correct display value in | ||
// the preference's 'entries' list (since they have separate labels/values). | ||
ListPreference listPreference = (ListPreference) preference; | ||
int prefIndex = listPreference.findIndexOfValue(stringValue); | ||
if (prefIndex >= 0) { | ||
preference.setSummary(listPreference.getEntries()[prefIndex]); | ||
} | ||
} else { | ||
// For other preferences, set the summary to the value's simple string representation. | ||
preference.setSummary(stringValue); | ||
} | ||
return true; | ||
} | ||
} |
19 changes: 0 additions & 19 deletions
19
app/src/main/java/com/calgen/prodek/sunshine_v2/DetailActivity.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.