Still need to put the "Add alarm" item at the top and the clock at the bottom.
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2009 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.
+-->
+
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:state_selected="true" android:state_window_focused="true"
+ android:drawable="@drawable/ic_clock_alarm_selected" />
+ <item android:state_checked="false"
+ android:drawable="@drawable/ic_clock_alarm_off" />
+ <item android:state_checked="true"
+ android:drawable="@drawable/ic_clock_alarm_on" />
+</selector>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
- android:paddingLeft="5dip"
+ android:paddingTop="4dip"
+ android:paddingBottom="4dip"
android:layout_width="fill_parent"
- android:layout_height="wrap_content">
+ android:layout_height="wrap_content"
+ android:orientation="horizontal">
+
+ <LinearLayout android:id="@+id/indicator"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:paddingLeft="14dip"
+ android:paddingRight="14dip"
+ android:paddingTop="8dip"
+ android:paddingBottom="8dip"
+ android:orientation="vertical">
+ <CheckBox android:id="@+id/clock_onoff"
+ android:focusable="false"
+ android:background="@drawable/indicator_clock_onoff"
+ android:layout_height="wrap_content"
+ android:layout_width="wrap_content"
+ android:layout_gravity="center"
+ android:button="@null"/>
+ <ImageView android:id="@+id/bar_onoff"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ android:paddingTop="4dip"
+ android:src="@drawable/ic_indicator_off" />
+ </LinearLayout>
+
+ <ImageView
+ android:src="@*android:drawable/divider_vertical_dark"
+ android:layout_width="wrap_content"
+ android:layout_height="fill_parent"
+ android:scaleType="fitXY"
+ android:gravity="fill_vertical" />
<!-- A layout that displays the time. Shows time, am/pm (if 12-hour),
and an optional line below, used for day/days of week -->
-
<com.android.deskclock.DigitalClock android:id="@+id/digitalClock"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
- android:layout_weight="1"
android:gravity="center_vertical"
+ android:layout_weight="1"
android:orientation="vertical"
android:paddingLeft="8dip"
android:paddingRight="8dip">
<LinearLayout
android:layout_width="fill_parent"
- android:layout_height="wrap_content">
+ android:layout_height="wrap_content"
+ android:baselineAligned="true">
<TextView android:id="@+id/timeDisplay"
+ android:includeFontPadding="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:textSize="30sp"
+ android:paddingRight="6dip"
+ android:textSize="36sp"
android:textColor="@color/white"/>
<TextView android:id="@+id/am_pm"
android:layout_width="wrap_content"
- android:layout_height="fill_parent"
- android:gravity="bottom"
- android:textSize="12sp"
+ android:layout_height="wrap_content"
+ android:textSize="16sp"
+ android:textStyle="bold"
android:textColor="@color/white"/>
+ <TextView android:id="@+id/label"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:textSize="16sp"
+ android:textColor="@color/grey"
+ android:textStyle="bold"
+ android:gravity="right"
+ android:paddingRight="8dip"
+ android:singleLine="true"/>
+
</LinearLayout>
<TextView android:id="@+id/daysOfWeek"
+ android:includeFontPadding="false"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="10sp"
- android:textColor="@color/ltgrey"/>
-
- <TextView android:id="@+id/label"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:textSize="12sp"
- android:textColor="@color/ltgrey"
- android:textStyle="bold|italic"
- android:singleLine="true"/>
+ android:textColor="@color/grey"/>
</com.android.deskclock.DigitalClock>
- <CheckBox android:id="@+id/alarmButton"
- android:focusable="false"
- android:layout_width="60dip"
- android:layout_height="76dip"
- android:layout_gravity="center_vertical"/>
-
</LinearLayout>
<color name="white">#ffffffff</color>
<color name="red">#ffee0000</color>
- <color name="ltgrey">#ffe0e0e0</color>
+ <color name="grey">#ffaaaaaa</color>
</resources>
import android.content.res.Configuration;
import android.database.Cursor;
import android.database.DataSetObserver;
+import android.graphics.Typeface;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CursorAdapter;
+import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
private ListView mAlarmsList;
private Cursor mCursor;
+ private void updateIndicatorAndAlarm(boolean enabled, ImageView bar,
+ Alarm alarm) {
+ bar.setImageResource(enabled ? R.drawable.ic_indicator_on
+ : R.drawable.ic_indicator_off);
+ Alarms.enableAlarm(this, alarm.id, enabled);
+ if (enabled) {
+ SetAlarm.popAlarmSetToast(this, alarm.hour, alarm.minutes,
+ alarm.daysOfWeek);
+ }
+ }
+
private class AlarmTimeAdapter extends CursorAdapter {
public AlarmTimeAdapter(Context context, Cursor cursor) {
super(context, cursor);
public void bindView(View view, Context context, Cursor cursor) {
final Alarm alarm = new Alarm(cursor);
- CheckBox onButton = (CheckBox)view.findViewById(R.id.alarmButton);
- onButton.setChecked(alarm.enabled);
- onButton.setOnClickListener(new OnClickListener() {
+ View indicator = view.findViewById(R.id.indicator);
+
+ // Set the initial resource for the bar image.
+ final ImageView barOnOff =
+ (ImageView) indicator.findViewById(R.id.bar_onoff);
+ barOnOff.setImageResource(alarm.enabled ?
+ R.drawable.ic_indicator_on : R.drawable.ic_indicator_off);
+
+ // Set the initial state of the clock "checkbox"
+ final CheckBox clockOnOff =
+ (CheckBox) indicator.findViewById(R.id.clock_onoff);
+ clockOnOff.setChecked(alarm.enabled);
+
+ // Handle the "checkbox" click and toggle the alarm.
+ clockOnOff.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
boolean isChecked = ((CheckBox) v).isChecked();
- Alarms.enableAlarm(AlarmClock.this, alarm.id,
- isChecked);
- if (isChecked) {
- SetAlarm.popAlarmSetToast(AlarmClock.this,
- alarm.hour, alarm.minutes, alarm.daysOfWeek);
- }
+ updateIndicatorAndAlarm(isChecked, barOnOff, alarm);
+ }
+ });
+
+ // Clicking outside the "checkbox" should also change the state.
+ indicator.setOnClickListener(new OnClickListener() {
+ public void onClick(View v) {
+ clockOnOff.toggle();
+ updateIndicatorAndAlarm(clockOnOff.isChecked(),
+ barOnOff, alarm);
}
});
c.set(Calendar.HOUR_OF_DAY, alarm.hour);
c.set(Calendar.MINUTE, alarm.minutes);
digitalClock.updateTime(c);
+ digitalClock.setTypeface(Typeface.DEFAULT);
// Set the repeat text or leave it blank if it does not repeat.
TextView daysOfWeekView =
// Display the label
TextView labelView =
- (TextView) digitalClock.findViewById(R.id.label);
+ (TextView) view.findViewById(R.id.label);
if (alarm.label != null && alarm.label.length() != 0) {
labelView.setText(alarm.label);
labelView.setVisibility(View.VISIBLE);
private TextView mAmPm;
private String mAmString, mPmString;
- AmPm(View parent, Typeface tf) {
+ AmPm(View parent) {
mAmPm = (TextView) parent.findViewById(R.id.am_pm);
- if (tf != null) {
- mAmPm.setTypeface(tf);
- }
String[] ampm = new DateFormatSymbols().getAmPmStrings();
mAmString = ampm[0];
"fonts/Clockopia.ttf");
mTimeDisplay = (TextView) findViewById(R.id.timeDisplay);
mTimeDisplay.setTypeface(tf);
- mAmPm = new AmPm(this, null);
+ mAmPm = new AmPm(this);
mCalendar = Calendar.getInstance();
setDateFormat();
void setLive(boolean live) {
mLive = live;
}
+
+ void setTypeface(Typeface tf) {
+ mTimeDisplay.setTypeface(tf);
+ }
}