| 1 |
package ${packageName}; |
| 2 |
|
| 3 |
import android.os.Bundle; |
| 4 |
import android.support.wearable.activity.WearableActivity; |
| 5 |
import android.support.wearable.view.BoxInsetLayout; |
| 6 |
import android.view.View; |
| 7 |
import android.widget.TextView; |
| 8 |
|
| 9 |
import java.text.SimpleDateFormat; |
| 10 |
import java.util.Date; |
| 11 |
import java.util.Locale; |
| 12 |
|
| 13 |
public class ${activityClass} extends WearableActivity { |
| 14 |
|
| 15 |
private static final SimpleDateFormat AMBIENT_DATE_FORMAT = |
| 16 |
new SimpleDateFormat("HH:mm", Locale.US); |
| 17 |
|
| 18 |
private BoxInsetLayout mContainerView; |
| 19 |
private TextView mTextView; |
| 20 |
private TextView mClockView; |
| 21 |
|
| 22 |
@Override |
| 23 |
protected void onCreate(Bundle savedInstanceState) { |
| 24 |
super.onCreate(savedInstanceState); |
| 25 |
setContentView(R.layout.${layoutName}); |
| 26 |
setAmbientEnabled(); |
| 27 |
|
| 28 |
mContainerView = (BoxInsetLayout) findViewById(R.id.container); |
| 29 |
mTextView = (TextView) findViewById(R.id.text); |
| 30 |
mClockView = (TextView) findViewById(R.id.clock); |
| 31 |
} |
| 32 |
|
| 33 |
@Override |
| 34 |
public void onEnterAmbient(Bundle ambientDetails) { |
| 35 |
super.onEnterAmbient(ambientDetails); |
| 36 |
updateDisplay(); |
| 37 |
} |
| 38 |
|
| 39 |
@Override |
| 40 |
public void onUpdateAmbient() { |
| 41 |
super.onUpdateAmbient(); |
| 42 |
updateDisplay(); |
| 43 |
} |
| 44 |
|
| 45 |
@Override |
| 46 |
public void onExitAmbient() { |
| 47 |
updateDisplay(); |
| 48 |
super.onExitAmbient(); |
| 49 |
} |
| 50 |
|
| 51 |
private void updateDisplay() { |
| 52 |
if (isAmbient()) { |
| 53 |
mContainerView.setBackgroundColor(getResources().getColor(android.R.color.black)); |
| 54 |
mTextView.setTextColor(getResources().getColor(android.R.color.white)); |
| 55 |
mClockView.setVisibility(View.VISIBLE); |
| 56 |
|
| 57 |
mClockView.setText(AMBIENT_DATE_FORMAT.format(new Date())); |
| 58 |
} else { |
| 59 |
mContainerView.setBackground(null); |
| 60 |
mTextView.setTextColor(getResources().getColor(android.R.color.black)); |
| 61 |
mClockView.setVisibility(View.GONE); |
| 62 |
} |
| 63 |
} |
| 64 |
} |