Merge "Made the Chronometer able to count downwards" into nyc-dev

am: f1c6371587

* commit 'f1c6371587ba9349068092971f1fdf85596d0461':
  Made the Chronometer able to count downwards
This commit is contained in:
Selim Cinek
2016-02-23 01:07:06 +00:00
committed by android-build-merger
8 changed files with 59 additions and 6 deletions

View File

@@ -423,6 +423,7 @@ package android {
field public static final int controlX2 = 16843774; // 0x10103fe
field public static final int controlY1 = 16843773; // 0x10103fd
field public static final int controlY2 = 16843775; // 0x10103ff
field public static final int countDown = 16844060; // 0x101051c
field public static final int country = 16843962; // 0x10104ba
field public static final int cropToPadding = 16843043; // 0x1010123
field public static final int cursorVisible = 16843090; // 0x1010152
@@ -46070,7 +46071,9 @@ package android.widget {
method public long getBase();
method public java.lang.String getFormat();
method public android.widget.Chronometer.OnChronometerTickListener getOnChronometerTickListener();
method public boolean isCountDown();
method public void setBase(long);
method public void setCountDown(boolean);
method public void setFormat(java.lang.String);
method public void setOnChronometerTickListener(android.widget.Chronometer.OnChronometerTickListener);
method public void start();

View File

@@ -518,6 +518,7 @@ package android {
field public static final int controlX2 = 16843774; // 0x10103fe
field public static final int controlY1 = 16843773; // 0x10103fd
field public static final int controlY2 = 16843775; // 0x10103ff
field public static final int countDown = 16844060; // 0x101051c
field public static final int country = 16843962; // 0x10104ba
field public static final int cropToPadding = 16843043; // 0x1010123
field public static final int cursorVisible = 16843090; // 0x1010152
@@ -49171,7 +49172,9 @@ package android.widget {
method public long getBase();
method public java.lang.String getFormat();
method public android.widget.Chronometer.OnChronometerTickListener getOnChronometerTickListener();
method public boolean isCountDown();
method public void setBase(long);
method public void setCountDown(boolean);
method public void setFormat(java.lang.String);
method public void setOnChronometerTickListener(android.widget.Chronometer.OnChronometerTickListener);
method public void start();

View File

@@ -423,6 +423,7 @@ package android {
field public static final int controlX2 = 16843774; // 0x10103fe
field public static final int controlY1 = 16843773; // 0x10103fd
field public static final int controlY2 = 16843775; // 0x10103ff
field public static final int countDown = 16844060; // 0x101051c
field public static final int country = 16843962; // 0x10104ba
field public static final int cropToPadding = 16843043; // 0x1010123
field public static final int cursorVisible = 16843090; // 0x1010152
@@ -46087,7 +46088,9 @@ package android.widget {
method public long getBase();
method public java.lang.String getFormat();
method public android.widget.Chronometer.OnChronometerTickListener getOnChronometerTickListener();
method public boolean isCountDown();
method public void setBase(long);
method public void setCountDown(boolean);
method public void setFormat(java.lang.String);
method public void setOnChronometerTickListener(android.widget.Chronometer.OnChronometerTickListener);
method public void start();

View File

@@ -19,15 +19,14 @@ package android.widget;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.os.Handler;
import android.os.Message;
import android.os.SystemClock;
import android.text.format.DateUtils;
import android.util.AttributeSet;
import android.util.Log;
import android.view.accessibility.AccessibilityEvent;
import android.widget.RemoteViews.RemoteView;
import com.android.internal.R;
import java.util.Formatter;
import java.util.IllegalFormatException;
import java.util.Locale;
@@ -37,11 +36,17 @@ import java.util.Locale;
* <p>
* You can give it a start time in the {@link SystemClock#elapsedRealtime} timebase,
* and it counts up from that, or if you don't give it a base time, it will use the
* time at which you call {@link #start}. By default it will display the current
* time at which you call {@link #start}.
*
* <p>The timer can also count downward towards the base time by
* setting {@link #setCountDown(boolean)} to true.
*
* <p>By default it will display the current
* timer value in the form "MM:SS" or "H:MM:SS", or you can use {@link #setFormat}
* to format the timer value into an arbitrary string.
*
* @attr ref android.R.styleable#Chronometer_format
* @attr ref android.R.styleable#Chronometer_countDown
*/
@RemoteView
public class Chronometer extends TextView {
@@ -72,6 +77,7 @@ public class Chronometer extends TextView {
private StringBuilder mFormatBuilder;
private OnChronometerTickListener mOnChronometerTickListener;
private StringBuilder mRecycle = new StringBuilder(8);
private boolean mCountDown;
/**
* Initialize this Chronometer object.
@@ -102,7 +108,8 @@ public class Chronometer extends TextView {
final TypedArray a = context.obtainStyledAttributes(
attrs, com.android.internal.R.styleable.Chronometer, defStyleAttr, defStyleRes);
setFormat(a.getString(com.android.internal.R.styleable.Chronometer_format));
setFormat(a.getString(R.styleable.Chronometer_format));
setCountDown(a.getBoolean(R.styleable.Chronometer_countDown, false));
a.recycle();
init();
@@ -113,6 +120,27 @@ public class Chronometer extends TextView {
updateText(mBase);
}
/**
* Set this view to count down to the base instead of counting up from it.
*
* @param countDown whether this view should count down
*
* @see #setBase(long)
*/
@android.view.RemotableViewMethod
public void setCountDown(boolean countDown) {
mCountDown = countDown;
}
/**
* @return whether this view counts down
*
* @see #setCountDown(boolean)
*/
public boolean isCountDown() {
return mCountDown;
}
/**
* Set the time that the count-up timer is in reference to.
*
@@ -226,9 +254,17 @@ public class Chronometer extends TextView {
private synchronized void updateText(long now) {
mNow = now;
long seconds = now - mBase;
long seconds = mCountDown ? mBase - now : now - mBase;
seconds /= 1000;
boolean negative = false;
if (seconds < 0) {
seconds = -seconds;
negative = true;
}
String text = DateUtils.formatElapsedTime(mRecycle, seconds);
if (negative) {
text = getResources().getString(R.string.negative_duration, text);
}
if (mFormat != null) {
Locale loc = Locale.getDefault();

View File

@@ -3539,6 +3539,9 @@ i
If no format string is specified, the Chronometer will simply display
"MM:SS" or "H:MM:SS". -->
<attr name="format" format="string" localization="suggested" />
<!-- Specifies whether this Chronometer counts down or counts up from the base.
If not specified this is false and the Chronometer counts up. -->
<attr name="countDown" format="boolean" />
</declare-styleable>
<declare-styleable name="CompoundButton">
<!-- Indicates the initial checked state of this button. -->

View File

@@ -2702,6 +2702,7 @@
<public type="attr" name="hotSpotY" />
<public type="attr" name="version" />
<public type="attr" name="backupInForeground" />
<public type="attr" name="countDown" />
<public type="style" name="Theme.Material.Light.DialogWhenLarge.DarkActionBar" />
<public type="style" name="Widget.Material.SeekBar.Discrete" />

View File

@@ -4230,4 +4230,7 @@
<!-- View application info for a target. -->
<string name="app_info">App info</string>
<!-- The representation of a time duration when negative. An example is -1:14. This can be used with a countdown timer for example.-->
<string name="negative_duration">\u2212<xliff:g id="time" example="1:14">%1$s</xliff:g></string>
</resources>

View File

@@ -2541,4 +2541,5 @@
<java-symbol type="string" name="carrier_app_dialog_not_now" />
<java-symbol type="string" name="carrier_app_notification_title" />
<java-symbol type="string" name="carrier_app_notification_text" />
<java-symbol type="string" name="negative_duration" />
</resources>