From a861c1a81fe83ccf0c067cc4ab3f1d1595ab0305 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Thu, 1 May 2014 18:46:30 +0200 Subject: [PATCH] Added preferences with "Contact Developer" option. --- AndroidManifest.xml | 12 ++-- build.gradle | 2 +- res/menu/menu.xml | 9 +++ res/values/strings.xml | 9 +++ res/xml/preferences.xml | 8 +++ .../nutomic/controldlna/gui/MainActivity.java | 25 ++++++- .../controldlna/gui/PreferencesActivity.java | 66 +++++++++++++++++++ 7 files changed, 123 insertions(+), 8 deletions(-) create mode 100644 res/menu/menu.xml create mode 100644 res/xml/preferences.xml create mode 100644 src/com/github/nutomic/controldlna/gui/PreferencesActivity.java diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 5fe10e4..54dacba 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -27,7 +27,7 @@ on Android 4.4 (but that's not my error). --> @@ -40,14 +40,18 @@ + + - + - + - diff --git a/build.gradle b/build.gradle index e7a79c2..3bf7600 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:0.7.0' + classpath 'com.android.tools.build:gradle:0.8.3' } } diff --git a/res/menu/menu.xml b/res/menu/menu.xml new file mode 100644 index 0000000..70f3d03 --- /dev/null +++ b/res/menu/menu.xml @@ -0,0 +1,9 @@ + + + + + + + \ No newline at end of file diff --git a/res/values/strings.xml b/res/values/strings.xml index 51e3647..2c8c9d3 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -37,4 +37,13 @@ UPNP Route Provider Service + + controldlna%1$snutomic%2$scom + + + Preferences + + + Contact Developer + diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml new file mode 100644 index 0000000..1c0e091 --- /dev/null +++ b/res/xml/preferences.xml @@ -0,0 +1,8 @@ + + + + + + \ No newline at end of file diff --git a/src/com/github/nutomic/controldlna/gui/MainActivity.java b/src/com/github/nutomic/controldlna/gui/MainActivity.java index 9fcc689..e00633d 100644 --- a/src/com/github/nutomic/controldlna/gui/MainActivity.java +++ b/src/com/github/nutomic/controldlna/gui/MainActivity.java @@ -46,7 +46,10 @@ import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBar.Tab; import android.support.v7.app.ActionBar.TabListener; import android.support.v7.app.ActionBarActivity; +import android.util.Log; import android.view.KeyEvent; +import android.view.Menu; +import android.view.MenuItem; import android.view.View; import android.widget.CheckBox; import android.widget.CompoundButton; @@ -103,8 +106,6 @@ public class MainActivity extends ActionBarActivity { final ActionBar actionBar = getSupportActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); - actionBar.setDisplayShowTitleEnabled(false); - actionBar.setDisplayShowHomeEnabled(false); setContentView(R.layout.activity_main); mViewPager = (ViewPager) findViewById(R.id.pager); @@ -177,7 +178,25 @@ public class MainActivity extends ActionBarActivity { onNewIntent(getIntent()); } - /** + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.menu, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.preferences: + Intent i = new Intent(this, PreferencesActivity.class); + startActivity(i); + return true; + default: + return super.onOptionsItemSelected(item); + } + } + + /** * Displays the RouteFragment immediately (instead of ServerFragment). */ @Override diff --git a/src/com/github/nutomic/controldlna/gui/PreferencesActivity.java b/src/com/github/nutomic/controldlna/gui/PreferencesActivity.java new file mode 100644 index 0000000..39d0689 --- /dev/null +++ b/src/com/github/nutomic/controldlna/gui/PreferencesActivity.java @@ -0,0 +1,66 @@ +/* +Copyright (c) 2013, Felix Ableitner +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.github.nutomic.controldlna.gui; + +import android.content.Intent; +import android.net.Uri; +import android.os.Bundle; +import android.preference.Preference; +import android.preference.PreferenceActivity; +import android.preference.PreferenceScreen; + +import com.github.nutomic.controldlna.R; + +public class PreferencesActivity extends PreferenceActivity { + + private static final String KEY_CONTACT_DEV = "contact_dev"; + + private Preference mContactDev; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + addPreferencesFromResource(R.xml.preferences); + final PreferenceScreen screen = getPreferenceScreen(); + mContactDev = screen.findPreference(KEY_CONTACT_DEV); + } + + @Override + public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, + Preference preference) { + if (preference == mContactDev) { + Intent i = new Intent(Intent.ACTION_SENDTO, Uri.fromParts( + "mailto", getString(R.string.contact_mail, "@", "."), null)); + startActivity(i); + return true; + } + return super.onPreferenceTreeClick(preferenceScreen, preference); + } + +}