diff --git a/LocationRinger/AndroidManifest.xml b/LocationRinger/AndroidManifest.xml index 1c2914c..695a6a4 100644 --- a/LocationRinger/AndroidManifest.xml +++ b/LocationRinger/AndroidManifest.xml @@ -110,6 +110,14 @@ android:enabled="true" android:exported="true" android:process=":PassiveLocationChangedReceiver" /> + + + + + + \ No newline at end of file diff --git a/LocationRinger/res/values/strings.xml b/LocationRinger/res/values/strings.xml index a9499df..a21cd48 100644 --- a/LocationRinger/res/values/strings.xml +++ b/LocationRinger/res/values/strings.xml @@ -87,5 +87,6 @@ This Ringer is applied when there is no applicable ringers Delete Ringer Name + Start Location Service \ No newline at end of file diff --git a/LocationRinger/src/com/TwentyCodes/android/LocationRinger/ui/LauncherShortcuts.java b/LocationRinger/src/com/TwentyCodes/android/LocationRinger/ui/LauncherShortcuts.java new file mode 100644 index 0000000..7edd18b --- /dev/null +++ b/LocationRinger/src/com/TwentyCodes/android/LocationRinger/ui/LauncherShortcuts.java @@ -0,0 +1,136 @@ +/** + * LauncherShortcuts.java + * @date May 22, 2012 + * @author ricky barrette + * @author Twenty Codes, LLC + * + * Copyright (C) 2008 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.TwentyCodes.android.LocationRinger.ui; + +import android.app.Activity; +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.os.Parcelable; + +import com.TwentyCodes.android.LocationRinger.R; +import com.TwentyCodes.android.LocationRinger.services.LocationService; +import com.TwentyCodes.android.debug.LocationLibraryConstants; + +/** + * This Activity actually handles two stages of a launcher shortcut's life cycle. + * + * 1. Your application offers to provide shortcuts to the launcher. When + * the user installs a shortcut, an activity within your application + * generates the actual shortcut and returns it to the launcher, where it + * is shown to the user as an icon. + * + * 2. Any time the user clicks on an installed shortcut, an intent is sent. + * Typically this would then be handled as necessary by an activity within + * your application. + * + * We handle stage 1 (creating a shortcut) by simply sending back the information (in the form + * of an {@link android.content.Intent} that the launcher will use to create the shortcut. + * + * You can also implement this in an interactive way, by having your activity actually present + * UI for the user to select the specific nature of the shortcut, such as a contact, picture, URL, + * media item, or action. + * + * We handle stage 2 (responding to a shortcut) in this sample by simply displaying the contents + * of the incoming {@link android.content.Intent}. + * + * In a real application, you would probably use the shortcut intent to display specific content + * or start a particular operation. + */ +public class LauncherShortcuts extends Activity { + + @Override + public void onCreate(Bundle icicle) { + super.onCreate(icicle); + + // Resolve the intent + + final Intent intent = getIntent(); + final String action = intent.getAction(); + + // If the intent is a request to create a shortcut, we'll do that and exit + + if (Intent.ACTION_CREATE_SHORTCUT.equals(action)) { + setupShortcut(); + finish(); + return; + } + + /* + * start the location service in single shot mode + */ + Intent service = new Intent(this, LocationService.class) + .putExtra(LocationService.INTENT_EXTRA_REQUIRED_ACCURACY, Integer.parseInt(this.getSharedPreferences(SettingsActivity.SETTINGS, Context.MODE_WORLD_READABLE).getString(SettingsActivity.ACCURACY , "50"))) + .setAction(LocationLibraryConstants.INTENT_ACTION_UPDATE); + this.startService(service); + + this.finish(); + } + + /** + * This function creates a shortcut and returns it to the caller. There are actually two + * intents that you will send back. + * + * The first intent serves as a container for the shortcut and is returned to the launcher by + * setResult(). This intent must contain three fields: + * + * + * + * If you use a simple drawable resource, note that you must wrapper it using + * {@link android.content.Intent.ShortcutIconResource}, as shown below. This is required so + * that the launcher can access resources that are stored in your application's .apk file. If + * you return a bitmap, such as a thumbnail, you can simply put the bitmap into the extras + * bundle using {@link android.content.Intent#EXTRA_SHORTCUT_ICON}. + * + * The shortcut intent can be any intent that you wish the launcher to send, when the user + * clicks on the shortcut. Typically this will be {@link android.content.Intent#ACTION_VIEW} + * with an appropriate Uri for your content, but any Intent will work here as long as it + * triggers the desired action within your Activity. + */ + private void setupShortcut() { + // First, set up the shortcut intent. For this example, we simply create an intent that + // will bring us directly back to this activity. A more typical implementation would use a + // data Uri in order to display a more specific result, or a custom action in order to + // launch a specific operation. + + Intent shortcutIntent = new Intent(Intent.ACTION_MAIN); + shortcutIntent.setClassName(this, this.getClass().getName()); + + // Then, set up the container intent (the response to the caller) + + Intent intent = new Intent(); + intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); + intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.start_location_service)); + Parcelable iconResource = Intent.ShortcutIconResource.fromContext(this, R.drawable.icon); + intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource); + + // Now, return the result to the launcher + + setResult(RESULT_OK, intent); + } +} \ No newline at end of file