summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorJeff Sharkey <jsharkey@android.com>2011-06-10 19:47:31 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-06-10 19:47:31 -0700
commiteaf7ce6067707fcebd58067135376af51858d2e5 (patch)
tree24be28b58f0cdbccbac4f44a986f8d8afa3aaace /core
parent57af6e76789c096fc7c7d3c3a8a192f8ee46ccf0 (diff)
parentcd2ca4038a027315832c38c68be5076000bc4b53 (diff)
downloadframeworks_base-eaf7ce6067707fcebd58067135376af51858d2e5.zip
frameworks_base-eaf7ce6067707fcebd58067135376af51858d2e5.tar.gz
frameworks_base-eaf7ce6067707fcebd58067135376af51858d2e5.tar.bz2
Merge "Move data cycle methods to framework object."
Diffstat (limited to 'core')
-rw-r--r--core/java/android/net/NetworkPolicyManager.java81
-rw-r--r--core/java/android/widget/TabWidget.java6
2 files changed, 86 insertions, 1 deletions
diff --git a/core/java/android/net/NetworkPolicyManager.java b/core/java/android/net/NetworkPolicyManager.java
index 0f4dc9a..08b1a81 100644
--- a/core/java/android/net/NetworkPolicyManager.java
+++ b/core/java/android/net/NetworkPolicyManager.java
@@ -16,8 +16,11 @@
package android.net;
+import static android.text.format.Time.MONTH_DAY;
+
import android.content.Context;
import android.os.RemoteException;
+import android.text.format.Time;
import java.io.PrintWriter;
@@ -88,7 +91,83 @@ public class NetworkPolicyManager {
return POLICY_NONE;
}
}
-
+
+ /**
+ * Compute the last cycle boundary for the given {@link NetworkPolicy}. For
+ * example, if cycle day is 20th, and today is June 15th, it will return May
+ * 20th. When cycle day doesn't exist in current month, it snaps to the 1st
+ * of following month.
+ *
+ * @hide
+ */
+ public static long computeLastCycleBoundary(long currentTime, NetworkPolicy policy) {
+ final Time now = new Time(Time.TIMEZONE_UTC);
+ now.set(currentTime);
+
+ // first, find cycle boundary for current month
+ final Time cycle = new Time(now);
+ cycle.hour = cycle.minute = cycle.second = 0;
+ snapToCycleDay(cycle, policy.cycleDay);
+
+ if (Time.compare(cycle, now) >= 0) {
+ // cycle boundary is beyond now, use last cycle boundary; start by
+ // pushing ourselves squarely into last month.
+ final Time lastMonth = new Time(now);
+ lastMonth.hour = lastMonth.minute = lastMonth.second = 0;
+ lastMonth.monthDay = 1;
+ lastMonth.month -= 1;
+ lastMonth.normalize(true);
+
+ cycle.set(lastMonth);
+ snapToCycleDay(cycle, policy.cycleDay);
+ }
+
+ return cycle.toMillis(true);
+ }
+
+ /** {@hide} */
+ public static long computeNextCycleBoundary(long currentTime, NetworkPolicy policy) {
+ final Time now = new Time(Time.TIMEZONE_UTC);
+ now.set(currentTime);
+
+ // first, find cycle boundary for current month
+ final Time cycle = new Time(now);
+ cycle.hour = cycle.minute = cycle.second = 0;
+ snapToCycleDay(cycle, policy.cycleDay);
+
+ if (Time.compare(cycle, now) <= 0) {
+ // cycle boundary is before now, use next cycle boundary; start by
+ // pushing ourselves squarely into next month.
+ final Time nextMonth = new Time(now);
+ nextMonth.hour = nextMonth.minute = nextMonth.second = 0;
+ nextMonth.monthDay = 1;
+ nextMonth.month += 1;
+ nextMonth.normalize(true);
+
+ cycle.set(nextMonth);
+ snapToCycleDay(cycle, policy.cycleDay);
+ }
+
+ return cycle.toMillis(true);
+ }
+
+ /**
+ * Snap to the cycle day for the current month given; when cycle day doesn't
+ * exist, it snaps to 1st of following month.
+ *
+ * @hide
+ */
+ public static void snapToCycleDay(Time time, int cycleDay) {
+ if (cycleDay > time.getActualMaximum(MONTH_DAY)) {
+ // cycle day isn't valid this month; snap to 1st of next month
+ time.month += 1;
+ time.monthDay = 1;
+ } else {
+ time.monthDay = cycleDay;
+ }
+ time.normalize(true);
+ }
+
/** {@hide} */
public static void dumpPolicy(PrintWriter fout, int policy) {
fout.write("[");
diff --git a/core/java/android/widget/TabWidget.java b/core/java/android/widget/TabWidget.java
index 1fe1f79..3d1dedc 100644
--- a/core/java/android/widget/TabWidget.java
+++ b/core/java/android/widget/TabWidget.java
@@ -514,6 +514,12 @@ public class TabWidget extends LinearLayout implements OnFocusChangeListener {
}
@Override
+ public void removeAllViews() {
+ super.removeAllViews();
+ mSelectedTab = -1;
+ }
+
+ @Override
public void sendAccessibilityEventUnchecked(AccessibilityEvent event) {
// this class fires events only when tabs are focused or selected
if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_FOCUSED && isFocused()) {