summaryrefslogtreecommitdiffstats
path: root/core/java/com/android/internal
diff options
context:
space:
mode:
Diffstat (limited to 'core/java/com/android/internal')
-rw-r--r--core/java/com/android/internal/util/weather/HttpRetriever.java152
-rw-r--r--core/java/com/android/internal/util/weather/WeatherInfo.java115
-rw-r--r--core/java/com/android/internal/util/weather/WeatherXmlParser.java177
-rw-r--r--core/java/com/android/internal/util/weather/YahooPlaceFinder.java41
-rw-r--r--core/java/com/android/internal/widget/LockPatternUtils.java178
5 files changed, 663 insertions, 0 deletions
diff --git a/core/java/com/android/internal/util/weather/HttpRetriever.java b/core/java/com/android/internal/util/weather/HttpRetriever.java
new file mode 100644
index 0000000..a3417a0
--- /dev/null
+++ b/core/java/com/android/internal/util/weather/HttpRetriever.java
@@ -0,0 +1,152 @@
+/******************************************************************************
+ * Class : HttpConnectHelper.java *
+ * Main Weather activity, in this demo apps i use API from yahoo, you can *
+ * use other weather web service which you prefer *
+ * *
+ * Version : v1.0 *
+ * Date : May 09, 2011 *
+ * Copyright (c)-2011 DatNQ some right reserved *
+ * You can distribute, modify or what ever you want but WITHOUT ANY WARRANTY *
+ * Be honest by keep credit of this file *
+ * *
+ * If you have any concern, feel free to contact with me via email, i will *
+ * check email in free time *
+ * Email: nguyendatnq@gmail.com *
+ * ---------------------------------------------------------------------------*
+ * Modification Logs: *
+ * KEYCHANGE DATE AUTHOR DESCRIPTION *
+ * ---------------------------------------------------------------------------*
+ * ------- May 09, 2011 DatNQ Create new *
+ ******************************************************************************/
+
+/**
+ * Modification into Android-internal HttpRetreiver.java
+ * Copyright (C) 2012 The AOKP Project
+ */
+
+
+package com.android.internal.util.weather;
+
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.util.EntityUtils;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.w3c.dom.Document;
+
+import android.util.Log;
+
+public class HttpRetriever {
+
+ private final String TAG = getClass().getSimpleName();
+ private DefaultHttpClient client = new DefaultHttpClient();
+ private HttpURLConnection httpConnection;
+
+ public String retrieve(String url) {
+ HttpGet get = new HttpGet(url);
+ try {
+ HttpResponse getResponse = client.execute(get);
+ HttpEntity getResponseEntity = getResponse.getEntity();
+ if (getResponseEntity != null) {
+ String response = EntityUtils.toString(getResponseEntity);
+ return response;
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ private void requestConnectServer(String strURL) throws IOException {
+ httpConnection = (HttpURLConnection) new URL(strURL).openConnection();
+ httpConnection.connect();
+
+ if (httpConnection.getResponseCode() != HttpURLConnection.HTTP_OK) {
+ Log.e(TAG, "Something wrong with connection");
+ httpConnection.disconnect();
+ throw new IOException("Error in connection: " + httpConnection.getResponseCode());
+ }
+ }
+
+ private void requestDisconnect() {
+ if (httpConnection != null) {
+ httpConnection.disconnect();
+ }
+ }
+
+ public Document getDocumentFromURL(String strURL) throws IOException {
+ if (strURL == null) {
+ Log.e(TAG, "Invalid input URL");
+ return null;
+ }
+
+ // Connect to server, get data and close
+ requestConnectServer(strURL);
+ String strDocContent = getDataFromConnection();
+ requestDisconnect();
+
+ if (strDocContent == null) {
+ Log.e(TAG, "Cannot get XML content");
+ return null;
+ }
+
+ int strContentSize = strDocContent.length();
+ StringBuffer strBuff = new StringBuffer();
+ strBuff.setLength(strContentSize + 1);
+ strBuff.append(strDocContent);
+ ByteArrayInputStream is = new ByteArrayInputStream(strDocContent.getBytes());
+
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ DocumentBuilder db;
+ Document docData = null;
+
+ try {
+ db = dbf.newDocumentBuilder();
+ docData = db.parse(is);
+ } catch (Exception e) {
+ Log.e(TAG, "Parser data error");
+ return null;
+ }
+ return docData;
+ }
+
+ private String getDataFromConnection() throws IOException {
+ if (httpConnection == null) {
+ Log.e(TAG, "Connection is null");
+ return null;
+ }
+
+ String strValue = null;
+ InputStream inputStream = httpConnection.getInputStream();
+ if (inputStream == null) {
+ Log.e(TAG, "Input stream error");
+ return null;
+ }
+
+ StringBuffer strBuf = new StringBuffer();
+ BufferedReader buffReader = new BufferedReader(new InputStreamReader(inputStream));
+ String strLine = "";
+
+ while ((strLine = buffReader.readLine()) != null) {
+ strBuf.append(strLine + "\n");
+ strValue += strLine + "\n";
+ }
+
+ // Release resource to system
+ buffReader.close();
+ inputStream.close();
+ return strBuf.toString();
+ }
+}
diff --git a/core/java/com/android/internal/util/weather/WeatherInfo.java b/core/java/com/android/internal/util/weather/WeatherInfo.java
new file mode 100644
index 0000000..2b65785
--- /dev/null
+++ b/core/java/com/android/internal/util/weather/WeatherInfo.java
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) 2012 The AOKP 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.android.internal.util.weather;
+
+import android.content.Context;
+import com.android.internal.R;
+
+public class WeatherInfo {
+
+ public static final String NODATA = "-";
+
+ public String city, forecast_date, condition, condition_code, temp, temp_unit,
+ humidity, wind, wind_dir, speed_unit, low, high;
+ public long last_sync;
+
+ public WeatherInfo() {
+ this.city = NODATA;
+ this.forecast_date = NODATA;
+ this.condition = NODATA;
+ this.condition_code = NODATA;
+ this.temp = NODATA;
+ this.temp_unit = NODATA;
+ this.humidity = NODATA;
+ this.wind = NODATA;
+ this.wind_dir = NODATA;
+ this.speed_unit = NODATA;
+ this.low = NODATA;
+ this.high = NODATA;
+ this.last_sync = 0;
+ }
+
+ public WeatherInfo(Context context, String city, String fdate, String condition, String condition_code,
+ String temp, String temp_unit, String humidity,
+ String wind, String wind_dir, String speed_unit,
+ String low, String high, long last_sync) {
+ this.city = city;
+ this.forecast_date = fdate;
+ this.condition = condition;
+ this.condition_code = condition_code;
+ this.humidity = humidity + "%";
+ this.wind = calcDirection(context, wind_dir) + " " + trimSpeed(wind) + speed_unit;
+ this.speed_unit = speed_unit;
+ this.last_sync = last_sync;
+ // Only the current temperature gets the temp_unit added.
+ this.temp_unit = temp_unit;
+ this.temp = temp + "°" + temp_unit;
+ this.low = low + "°";
+ this.high = high + "°";
+ }
+
+ /**
+ * find the optimal weather string (helper function for translation)
+ *
+ * @param conditionCode condition code from Yahoo (this is the main
+ * identifier which will be used to find a matching translation
+ * in the project's resources
+ * @param providedString
+ * @return either the defaultString (which should be Yahoo's weather
+ * condition text), or the translated version from resources
+ */
+ public static String getTranslatedConditionString(Context context, int conditionCode,
+ String providedString) {
+ int resID = context.getResources().getIdentifier("weather_" + conditionCode, "string",
+ context.getPackageName());
+ return (resID != 0) ? context.getResources().getString(resID) : providedString;
+ }
+
+ private String calcDirection(Context context, String degrees) {
+ try {
+ int deg = Integer.parseInt(degrees);
+ if (deg >= 338 || deg <= 22)
+ return context.getResources().getString(R.string.weather_N);
+ else if (deg < 68)
+ return context.getResources().getString(R.string.weather_NE);
+ else if (deg < 113)
+ return context.getResources().getString(R.string.weather_E);
+ else if (deg < 158)
+ return context.getResources().getString(R.string.weather_SE);
+ else if (deg < 203)
+ return context.getResources().getString(R.string.weather_S);
+ else if (deg < 248)
+ return context.getResources().getString(R.string.weather_SW);
+ else if (deg < 293)
+ return context.getResources().getString(R.string.weather_W);
+ else if (deg < 338)
+ return context.getResources().getString(R.string.weather_NW);
+ else
+ return "";
+ } catch (NumberFormatException e) {
+ return "";
+ }
+ }
+
+ private String trimSpeed(String speed) {
+ try {
+ return String.valueOf(Math.round(Float.parseFloat(speed)));
+ } catch (NumberFormatException e) {
+ return "";
+ }
+ }
+}
diff --git a/core/java/com/android/internal/util/weather/WeatherXmlParser.java b/core/java/com/android/internal/util/weather/WeatherXmlParser.java
new file mode 100644
index 0000000..a2986fc
--- /dev/null
+++ b/core/java/com/android/internal/util/weather/WeatherXmlParser.java
@@ -0,0 +1,177 @@
+/******************************************************************************
+ * Class : YahooWeatherHelper.java *
+ * Parser helper for Yahoo *
+ * *
+ * Version : v1.0 *
+ * Date : May 06, 2011 *
+ * Copyright (c)-2011 DatNQ some right reserved *
+ * You can distribute, modify or what ever you want but WITHOUT ANY WARRANTY *
+ * Be honest by keep credit of this file *
+ * *
+ * If you have any concern, feel free to contact with me via email, i will *
+ * check email in free time *
+ * Email: nguyendatnq@gmail.com *
+ * ---------------------------------------------------------------------------*
+ * Modification Logs: *
+ * KEYCHANGE DATE AUTHOR DESCRIPTION *
+ * ---------------------------------------------------------------------------*
+ * ------- May 06, 2011 DatNQ Create new *
+ ******************************************************************************/
+/*
+ * Modification into Android-internal WeatherXmlParser.java
+ * Copyright (C) 2012 The AOKP Project
+ */
+
+package com.android.internal.util.weather;
+
+import java.io.StringReader;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.InputSource;
+
+import android.content.Context;
+import android.util.Log;
+
+public class WeatherXmlParser {
+
+ protected static final String TAG = "WeatherXmlParser";
+
+ /** Yahoo attributes */
+ private static final String PARAM_YAHOO_LOCATION = "yweather:location";
+ private static final String PARAM_YAHOO_UNIT = "yweather:units";
+ private static final String PARAM_YAHOO_ATMOSPHERE = "yweather:atmosphere";
+ private static final String PARAM_YAHOO_CONDITION = "yweather:condition";
+ private static final String PARAM_YAHOO_WIND = "yweather:wind";
+ private static final String PARAM_YAHOO_FORECAST = "yweather:forecast";
+
+ private static final String ATT_YAHOO_CITY = "city";
+ private static final String ATT_YAHOO_TEMP = "temp";
+ private static final String ATT_YAHOO_CODE = "code";
+ private static final String ATT_YAHOO_TEMP_UNIT = "temperature";
+ private static final String ATT_YAHOO_HUMIDITY = "humidity";
+ private static final String ATT_YAHOO_TEXT = "text";
+ private static final String ATT_YAHOO_DATE = "date";
+ private static final String ATT_YAHOO_SPEED = "speed";
+ private static final String ATT_YAHOO_DIRECTION = "direction";
+ private static final String ATT_YAHOO_TODAY_HIGH = "high";
+ private static final String ATT_YAHOO_TODAY_LOW = "low";
+
+ private Context mContext;
+
+ public WeatherXmlParser(Context context) {
+ mContext = context;
+ }
+
+ public WeatherInfo parseWeatherResponse(Document docWeather) {
+ if (docWeather == null) {
+ Log.e(TAG, "Invalid doc weather");
+ return null;
+ }
+
+ String strCity = null;
+ String strDate = null;
+ String strCondition = null;
+ String strCondition_code = null;
+ String strTemp = null;
+ String strTempUnit = null;
+ String strHumidity = null;
+ String strWindSpeed = null;
+ String strWindDir = null;
+ String strSpeedUnit = null;
+ String strHigh = null;
+ String strLow = null;
+
+ try {
+ Element root = docWeather.getDocumentElement();
+ root.normalize();
+
+ NamedNodeMap locationNode = root.getElementsByTagName(PARAM_YAHOO_LOCATION).item(0)
+ .getAttributes();
+ if (locationNode != null) {
+ strCity = locationNode.getNamedItem(ATT_YAHOO_CITY).getNodeValue();
+ }
+
+ NamedNodeMap unitNode = root.getElementsByTagName(PARAM_YAHOO_UNIT).item(0)
+ .getAttributes();
+
+ if (locationNode != null) {
+ strTempUnit = unitNode.getNamedItem(ATT_YAHOO_TEMP_UNIT).getNodeValue();
+ strSpeedUnit = unitNode.getNamedItem(ATT_YAHOO_SPEED).getNodeValue();
+ }
+
+ NamedNodeMap atmosNode = root.getElementsByTagName(PARAM_YAHOO_ATMOSPHERE).item(0)
+ .getAttributes();
+ if (atmosNode != null) {
+ strHumidity = atmosNode.getNamedItem(ATT_YAHOO_HUMIDITY).getNodeValue();
+ }
+
+ NamedNodeMap conditionNode = root.getElementsByTagName(PARAM_YAHOO_CONDITION).item(0)
+ .getAttributes();
+ if (conditionNode != null) {
+ strCondition = conditionNode.getNamedItem(ATT_YAHOO_TEXT).getNodeValue();
+ strCondition_code = conditionNode.getNamedItem(ATT_YAHOO_CODE).getNodeValue();
+ strCondition = WeatherInfo.getTranslatedConditionString(mContext, Integer.parseInt(strCondition_code), strCondition);
+ strTemp = conditionNode.getNamedItem(ATT_YAHOO_TEMP).getNodeValue();
+ strDate = conditionNode.getNamedItem(ATT_YAHOO_DATE).getNodeValue();
+ }
+
+ NamedNodeMap temNode = root.getElementsByTagName(PARAM_YAHOO_WIND).item(0)
+ .getAttributes();
+ if (temNode != null) {
+ strWindSpeed = temNode.getNamedItem(ATT_YAHOO_SPEED).getNodeValue();
+ strWindDir = temNode.getNamedItem(ATT_YAHOO_DIRECTION).getNodeValue();
+ }
+
+ NamedNodeMap fcNode = root.getElementsByTagName(PARAM_YAHOO_FORECAST).item(0).getAttributes();
+ if (fcNode != null) {
+ strHigh = fcNode.getNamedItem(ATT_YAHOO_TODAY_HIGH).getNodeValue();
+ strLow = fcNode.getNamedItem(ATT_YAHOO_TODAY_LOW).getNodeValue();
+ }
+ } catch (Exception e) {
+ Log.e(TAG, "Something wrong with parser data: " + e.toString());
+ return null;
+ }
+
+ /* Weather info */
+ WeatherInfo yahooWeatherInfo = new WeatherInfo(mContext, strCity, strDate, strCondition, strCondition_code, strTemp,
+ strTempUnit, strHumidity, strWindSpeed, strWindDir, strSpeedUnit, strLow, strHigh, System.currentTimeMillis());
+
+ Log.d(TAG, "Weather updated for " + strCity + ": " + strDate + ", " + strCondition + "(" + strCondition_code
+ + "), " + strTemp + strTempUnit + ", " + strHumidity + "% humidity, " + ", wind: " + strWindDir + " at "
+ + strWindSpeed + strSpeedUnit + ", low: " + strLow + strTempUnit + " high: " + strHigh + strTempUnit);
+
+ return yahooWeatherInfo;
+ }
+
+ public String parsePlaceFinderResponse(String response) {
+ try {
+
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ DocumentBuilder db = dbf.newDocumentBuilder();
+ Document doc = db.parse(new InputSource(new StringReader(response)));
+
+ NodeList resultNodes = doc.getElementsByTagName("Result");
+
+ Node resultNode = resultNodes.item(0);
+ NodeList attrsList = resultNode.getChildNodes();
+
+ for (int i = 0; i < attrsList.getLength(); i++) {
+ Node node = attrsList.item(i);
+ Node firstChild = node.getFirstChild();
+ if ("woeid".equalsIgnoreCase(node.getNodeName()) && firstChild != null) {
+ return firstChild.getNodeValue();
+ }
+ }
+ } catch (Exception e) {
+ Log.e(TAG, e.toString());
+ }
+ return null;
+ }
+}
diff --git a/core/java/com/android/internal/util/weather/YahooPlaceFinder.java b/core/java/com/android/internal/util/weather/YahooPlaceFinder.java
new file mode 100644
index 0000000..fb8efe4
--- /dev/null
+++ b/core/java/com/android/internal/util/weather/YahooPlaceFinder.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2012 The AOKP 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.android.internal.util.weather;
+
+import android.content.Context;
+
+public class YahooPlaceFinder {
+
+ private static final String YAHOO_API_BASE_REV_URL = "http://where.yahooapis.com/geocode?appid=jYkTZp64&q=%1$s,+%2$s&gflags=R";
+ private static final String YAHOO_API_BASE_URL = "http://where.yahooapis.com/geocode?appid=jYkTZp64&q=%1$s";
+
+ public static String reverseGeoCode(Context c, double latitude, double longitude) {
+
+ String url = String.format(YAHOO_API_BASE_REV_URL, String.valueOf(latitude),
+ String.valueOf(longitude));
+ String response = new HttpRetriever().retrieve(url);
+ return new WeatherXmlParser(c).parsePlaceFinderResponse(response);
+
+ }
+
+ public static String GeoCode(Context c, String location) {
+ String url = String.format(YAHOO_API_BASE_URL, location).replace(' ', '+');
+ String response = new HttpRetriever().retrieve(url);
+ return new WeatherXmlParser(c).parsePlaceFinderResponse(response);
+ }
+
+}
diff --git a/core/java/com/android/internal/widget/LockPatternUtils.java b/core/java/com/android/internal/widget/LockPatternUtils.java
index 75fef24..8f419e4 100644
--- a/core/java/com/android/internal/widget/LockPatternUtils.java
+++ b/core/java/com/android/internal/widget/LockPatternUtils.java
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2007 The Android Open Source Project
+ * Copyright (C) 2012 The CyanogenMod Project (Calendar)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,6 +24,8 @@ import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
+import android.database.Cursor;
+import android.net.Uri;
import android.os.Binder;
import android.os.Bundle;
import android.os.IBinder;
@@ -31,10 +34,13 @@ import android.os.ServiceManager;
import android.os.SystemClock;
import android.os.UserHandle;
import android.os.storage.IMountService;
+import android.provider.CalendarContract;
import android.provider.Settings;
import android.security.KeyStore;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
+import android.text.format.DateFormat;
+import android.text.format.Time;
import android.util.Log;
import android.view.IWindowManager;
import android.view.View;
@@ -47,7 +53,10 @@ import com.google.android.collect.Lists;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
+import java.text.SimpleDateFormat;
+import java.util.Date;
import java.util.List;
+import java.util.TimeZone;
/**
* Utilities for the lock pattern and its settings.
@@ -1038,6 +1047,166 @@ public class LockPatternUtils {
return nextAlarm;
}
+ /**
+ * @return A formatted string of the next calendar event with a reminder
+ * (for showing on the lock screen), or null if there is no next event
+ * within a certain look-ahead time.
+ */
+ public String[] getNextCalendarAlarm(long lookahead, String[] calendars,
+ boolean remindersOnly) {
+ long now = System.currentTimeMillis();
+ long later = now + lookahead;
+
+ StringBuilder where = new StringBuilder();
+ if (remindersOnly) {
+ where.append(CalendarContract.Events.HAS_ALARM + "=1");
+ }
+ if (calendars != null && calendars.length > 0) {
+ if (remindersOnly) {
+ where.append(" AND ");
+ }
+ where.append(CalendarContract.Events.CALENDAR_ID + " in (");
+ for (int i = 0; i < calendars.length; i++) {
+ where.append(calendars[i]);
+ if (i != calendars.length - 1) {
+ where.append(",");
+ }
+ }
+ where.append(") ");
+ }
+
+ // Projection array
+ String[] projection = new String[] {
+ CalendarContract.Events.TITLE,
+ CalendarContract.Instances.BEGIN,
+ CalendarContract.Events.DESCRIPTION,
+ CalendarContract.Events.EVENT_LOCATION,
+ CalendarContract.Events.ALL_DAY
+ };
+
+ // The indices for the projection array
+ int TITLE_INDEX = 0;
+ int BEGIN_TIME_INDEX = 1;
+ int DESCRIPTION_INDEX = 2;
+ int LOCATION_INDEX = 3;
+ int ALL_DAY_INDEX = 4;
+
+ Uri uri = Uri.withAppendedPath(CalendarContract.Instances.CONTENT_URI,
+ String.format("%d/%d", now, later));
+ String[] nextCalendarAlarm = new String[2];
+ Cursor cursor = null;
+
+ try {
+ cursor = mContentResolver.query(uri, projection,
+ where.toString(), null, "begin ASC");
+
+ if (cursor != null && cursor.moveToFirst()) {
+
+ String title = cursor.getString(TITLE_INDEX);
+ long begin = cursor.getLong(BEGIN_TIME_INDEX);
+ String description = cursor.getString(DESCRIPTION_INDEX);
+ String location = cursor.getString(LOCATION_INDEX);
+ boolean allDay = cursor.getInt(ALL_DAY_INDEX) != 0;
+
+ // Check the next event in the case of all day event. As UTC is used for all day
+ // events, the next event may be the one that actually starts sooner
+ if (allDay && !cursor.isLast()) {
+ cursor.moveToNext();
+ long nextBegin = cursor.getLong(BEGIN_TIME_INDEX);
+ if (nextBegin < begin + TimeZone.getDefault().getOffset(begin)) {
+ title = cursor.getString(TITLE_INDEX);
+ begin = nextBegin;
+ description = cursor.getString(DESCRIPTION_INDEX);
+ location = cursor.getString(LOCATION_INDEX);
+ allDay = cursor.getInt(ALL_DAY_INDEX) != 0;
+ }
+ }
+
+ // Set the event title as the first array item
+ nextCalendarAlarm[0] = title.toString();
+
+ // Start building the event details string
+ // Starting with the date
+ Date start = new Date(begin);
+ StringBuilder sb = new StringBuilder();
+
+ if (allDay) {
+ SimpleDateFormat sdf = new SimpleDateFormat(
+ mContext.getString(R.string.abbrev_wday_month_day_no_year));
+ // Calendar stores all-day events in UTC -- setting the time zone ensures
+ // the correct date is shown.
+ sdf.setTimeZone(TimeZone.getTimeZone(Time.TIMEZONE_UTC));
+ sb.append(sdf.format(start));
+ } else {
+ sb.append(DateFormat.format("E", start));
+ sb.append(" ");
+ sb.append(DateFormat.getTimeFormat(mContext).format(start));
+ }
+
+ // Add the event location if it should be shown
+ int showLocation = Settings.System.getInt(mContext.getContentResolver(),
+ Settings.System.LOCKSCREEN_CALENDAR_SHOW_LOCATION, 0);
+ if (showLocation != 0 && !TextUtils.isEmpty(location)) {
+ switch(showLocation) {
+ case 1:
+ // Show first line
+ int end = location.indexOf('\n');
+ if(end == -1) {
+ sb.append(": " + location);
+ } else {
+ sb.append(": " + location.substring(0, end));
+ }
+ break;
+ case 2:
+ // Show all
+ sb.append(": " + location);
+ break;
+ }
+ }
+
+ // Add the event description if it should be shown
+ int showDescription = Settings.System.getInt(mContext.getContentResolver(),
+ Settings.System.LOCKSCREEN_CALENDAR_SHOW_DESCRIPTION, 0);
+ if (showDescription != 0 && !TextUtils.isEmpty(description)) {
+
+ // Show the appropriate separator
+ if (showLocation == 0) {
+ sb.append(": ");
+ } else {
+ sb.append(" - ");
+ }
+
+ switch(showDescription) {
+ case 1:
+ // Show first line
+ int end = description.indexOf('\n');
+ if(end == -1) {
+ sb.append(description);
+ } else {
+ sb.append(description.substring(0, end));
+ }
+ break;
+ case 2:
+ // Show all
+ sb.append(description);
+ break;
+ }
+ }
+
+ // Set the time, location and description as the second array item
+ nextCalendarAlarm[1] = sb.toString();
+ }
+ } catch (Exception e) {
+ // Do nothing
+ } finally {
+ if (cursor != null) {
+ cursor.close();
+ }
+ }
+
+ return nextCalendarAlarm;
+ }
+
private boolean getBoolean(String secureSettingKey, boolean defaultValue) {
try {
return getLockSettings().getBoolean(secureSettingKey, defaultValue,
@@ -1346,4 +1515,13 @@ public class LockPatternUtils {
return false;
}
+ /**
+ * @hide
+ * Set the lock-before-unlock option (show widgets before the secure
+ * unlock screen). See config_enableLockBeforeUnlockScreen
+ */
+ public void setLockBeforeUnlock(boolean enabled) {
+ setBoolean(Settings.Secure.LOCK_BEFORE_UNLOCK, enabled);
+ }
+
}