Remove all the clock layouts except the digital. Remove the clock picker and any
settings related to change the clock face.
Next step: Move the settings and add alarm menu items to buttons.
android:taskAffinity=""
android:configChanges="orientation|keyboardHidden|keyboard|navigation"/>
- <activity android:name="ClockPicker" />
-
<receiver android:name="AlarmReceiver">
<intent-filter>
<action android:name="com.android.deskclock.ALARM_ALERT" />
+++ /dev/null
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2008 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.
--->
-
-<!-- Chewie... the hyperdrive ain't working -->
-<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
- android:oneshot="false" android:visible="true">
- <item android:drawable="@drawable/circle0_drawable" android:duration="80" />
- <item android:drawable="@drawable/circle1_drawable" android:duration="80" />
- <item android:drawable="@drawable/circle2_drawable" android:duration="80" />
- <item android:drawable="@drawable/circle3_drawable" android:duration="80" />
-</animation-list>
-
-
-
+++ /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.
--->
-<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
- android:oneshot="false" android:src="@drawable/circle0"
- android:gravity="center"/>
+++ /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.
--->
-<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
- android:oneshot="false" android:src="@drawable/circle1"
- android:gravity="center"/>
+++ /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.
--->
-<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
- android:oneshot="false" android:src="@drawable/circle2"
- android:gravity="center"/>
+++ /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.
--->
-<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
- android:oneshot="false" android:src="@drawable/circle3"
- android:gravity="center"/>
+++ /dev/null
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2008 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.
--->
-
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/base_layout"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:gravity="center_vertical">
-
- <FrameLayout
- android:id="@+id/clock_layout"
- android:layout_width="208dip"
- android:layout_height="fill_parent"/>
-
- <ListView
- android:id="@+id/alarms_list"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content" />
-
-</LinearLayout>
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"/>
- <LinearLayout
- android:id="@+id/clockView"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:layout_gravity="fill_vertical|center"/>
+ <include layout="@layout/digital_clock" />
<LinearLayout
android:layout_width="wrap_content"
android:id="@+id/base_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
- android:layout_marginTop="6dip"
android:orientation="vertical">
- <LinearLayout
- android:id="@+id/clock_layout"
- android:layout_width="fill_parent"
- android:layout_height="192dip"/>
-
<ListView
android:id="@+id/alarms_list"
android:layout_width="fill_parent"
+++ /dev/null
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2008 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.
--->
-
-<AnalogClock xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/clock"
- style="@style/clock"
- android:dial="@drawable/clock_dial"
- android:hand_hour="@drawable/clock_hour"
- android:hand_minute="@drawable/clock_minute"/>
+++ /dev/null
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2008 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.
--->
-
-<AnalogClock xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/clock"
- style="@style/clock"
- android:dial="@drawable/clockdroid2_dial"
- android:hand_hour="@drawable/clockdroid2_hour"
- android:hand_minute="@drawable/clockdroid2_minute"/>
+++ /dev/null
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2008 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.
--->
-
-<AnalogClock xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/clock"
- style="@style/clock"
- android:dial="@drawable/clockdroids_dial"
- android:hand_hour="@drawable/clockdroids_hour"
- android:hand_minute="@drawable/clockdroids_minute"/>
+++ /dev/null
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2008 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.
--->
-
-<AnalogClock xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/clock"
- style="@style/clock"
- android:dial="@drawable/clockgoog_dial"
- android:hand_hour="@drawable/clockgoog_hour"
- android:hand_minute="@drawable/clockgoog_minute"/>
+++ /dev/null
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2008 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.
--->
-
-<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent">
-
- <TextView
- android:id="@+id/instructions"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:padding="5dip"
- android:background="#70000000"
- android:text="@string/clock_instructions"
- android:layout_alignParentTop="true"
- android:layout_centerHorizontal="true"
- />
- <LinearLayout
- android:id="@+id/clock_layout"
- android:layout_width="fill_parent"
- android:layout_below="@+id/instructions"
- android:layout_height="208dip"
- android:gravity="center"/>
-
- <Gallery android:id="@+id/gallery"
- android:background="#70000000"
- android:layout_width="fill_parent"
- android:layout_height="80dip"
- android:layout_alignParentBottom="true"
- android:layout_alignParentLeft="true"
- android:gravity="center_vertical"
- android:spacing="16dp"
- />
-
-</RelativeLayout>
-
<item android:id="@+id/menu_add_alarm"
android:title="@string/add_alarm"
android:icon="@android:drawable/ic_menu_add"/>
- <item android:id="@+id/menu_toggle_clock"
- android:title="@string/hide_clock"
- android:icon="@drawable/ic_menu_clock_face"/>
<item android:id="@+id/menu_settings"
android:title="@string/settings"
android:icon="@android:drawable/ic_menu_preferences"/>
setContentView(inflateView(inflater));
- /* set clock face */
- SharedPreferences settings =
- getSharedPreferences(AlarmClock.PREFERENCES, 0);
- int face = settings.getInt(AlarmClock.PREF_CLOCK_FACE, 0);
- if (face < 0 || face >= AlarmClock.CLOCKS.length) {
- face = 0;
- }
- ViewGroup clockView = (ViewGroup) findViewById(R.id.clockView);
- inflater.inflate(AlarmClock.CLOCKS[face], clockView);
- View clockLayout = findViewById(R.id.clock);
- if (clockLayout instanceof DigitalClock) {
- ((DigitalClock) clockLayout).setAnimate();
- }
-
/* snooze behavior: pop a snooze confirmation view, kick alarm
manager. */
Button snooze = (Button) findViewById(R.id.snooze);
public class AlarmClock extends Activity implements OnItemClickListener {
final static String PREFERENCES = "AlarmClock";
- final static String PREF_CLOCK_FACE = "face";
- final static String PREF_SHOW_CLOCK = "show_clock";
/** Cap alarm count at this number */
final static int MAX_ALARM_COUNT = 12;
private SharedPreferences mPrefs;
private LayoutInflater mFactory;
- private ViewGroup mClockLayout;
- private View mClock = null;
private ListView mAlarmsList;
private Cursor mCursor;
private String mAm, mPm;
- /**
- * Which clock face to show
- */
- private int mFace = -1;
-
- /*
- * FIXME: it would be nice for this to live in an xml config file.
- */
- final static int[] CLOCKS = {
- R.layout.clock_basic_bw,
- R.layout.clock_googly,
- R.layout.clock_droid2,
- R.layout.clock_droids,
- R.layout.digital_clock
- };
-
private class AlarmTimeAdapter extends CursorAdapter {
public AlarmTimeAdapter(Context context, Cursor cursor) {
super(context, cursor);
mCursor = Alarms.getAlarmsCursor(getContentResolver());
updateLayout();
- setClockVisibility(mPrefs.getBoolean(PREF_SHOW_CLOCK, true));
- }
-
- @Override
- public void onConfigurationChanged(Configuration newConfig) {
- super.onConfigurationChanged(newConfig);
- updateLayout();
- inflateClock();
}
private void updateLayout() {
mAlarmsList.setVerticalScrollBarEnabled(true);
mAlarmsList.setOnItemClickListener(this);
mAlarmsList.setOnCreateContextMenuListener(this);
-
- mClockLayout = (ViewGroup) findViewById(R.id.clock_layout);
- mClockLayout.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- final Intent intent =
- new Intent(AlarmClock.this, ClockPicker.class);
- intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- startActivity(intent);
- }
- });
- }
-
- @Override
- protected void onResume() {
- super.onResume();
-
- int face = mPrefs.getInt(PREF_CLOCK_FACE, 0);
- if (mFace != face) {
- if (face < 0 || face >= AlarmClock.CLOCKS.length) {
- mFace = 0;
- } else {
- mFace = face;
- }
- inflateClock();
- }
}
@Override
mCursor.deactivate();
}
- protected void inflateClock() {
- if (mClock != null) {
- mClockLayout.removeView(mClock);
- }
-
- LayoutInflater.from(this).inflate(CLOCKS[mFace], mClockLayout);
- mClock = findViewById(R.id.clock);
-
- TextView am = (TextView) findViewById(R.id.am);
- TextView pm = (TextView) findViewById(R.id.pm);
-
- if (am != null) {
- am.setText(mAm);
- }
- if (pm != null) {
- pm.setText(mPm);
- }
- }
-
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate our menu.
public boolean onPrepareOptionsMenu(Menu menu) {
menu.findItem(R.id.menu_add_alarm).setVisible(
mAlarmsList.getAdapter().getCount() < MAX_ALARM_COUNT);
- menu.findItem(R.id.menu_toggle_clock).setTitle(
- getClockVisibility() ? R.string.hide_clock
- : R.string.show_clock);
return super.onPrepareOptionsMenu(menu);
}
startActivity(intent);
return true;
- case R.id.menu_toggle_clock:
- setClockVisibility(!getClockVisibility());
- saveClockVisibility();
- return true;
-
case R.id.menu_settings:
startActivity(new Intent(this, SettingsActivity.class));
return true;
return super.onOptionsItemSelected(item);
}
-
-
- private boolean getClockVisibility() {
- return mClockLayout.getVisibility() == View.VISIBLE;
- }
-
- private void setClockVisibility(boolean visible) {
- mClockLayout.setVisibility(visible ? View.VISIBLE : View.GONE);
- }
-
- private void saveClockVisibility() {
- mPrefs.edit().putBoolean(PREF_SHOW_CLOCK, getClockVisibility()).commit();
- }
}
+++ /dev/null
-/*
- * Copyright (C) 2008 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.
- */
-
-package com.android.deskclock;
-
-import android.app.Activity;
-import android.content.SharedPreferences;
-import android.os.Bundle;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.view.Window;
-import android.widget.AdapterView;
-import android.widget.BaseAdapter;
-import android.widget.Gallery;
-
-/**
- * Clock face picker for the Alarm Clock application.
- */
-public class ClockPicker extends Activity implements
- AdapterView.OnItemSelectedListener, AdapterView.OnItemClickListener {
-
- private LayoutInflater mFactory;
- private Gallery mGallery;
-
- private SharedPreferences mPrefs;
- private View mClock;
- private ViewGroup mClockLayout;
- private int mPosition;
-
- @Override
- public void onCreate(Bundle icicle) {
- super.onCreate(icicle);
- requestWindowFeature(Window.FEATURE_NO_TITLE);
-
- mFactory = LayoutInflater.from(this);
- setContentView(R.layout.clockpicker);
-
- mGallery = (Gallery) findViewById(R.id.gallery);
- mGallery.setAdapter(new ClockAdapter());
- mGallery.setOnItemSelectedListener(this);
- mGallery.setOnItemClickListener(this);
-
- mPrefs = getSharedPreferences(AlarmClock.PREFERENCES, 0);
- int face = mPrefs.getInt(AlarmClock.PREF_CLOCK_FACE, 0);
- if (face < 0 || face >= AlarmClock.CLOCKS.length) face = 0;
-
- mClockLayout = (ViewGroup) findViewById(R.id.clock_layout);
- mClockLayout.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- selectClock(mPosition);
- }
- });
-
- mGallery.setSelection(face, false);
- }
-
- public void onItemSelected(AdapterView parent, View v, int position, long id) {
- if (mClock != null) {
- mClockLayout.removeView(mClock);
- }
- mClock = mFactory.inflate(AlarmClock.CLOCKS[position], null);
- mClockLayout.addView(mClock, 0);
- mPosition = position;
- }
-
- public void onItemClick(AdapterView parent, View v, int position, long id) {
- selectClock(position);
- }
-
- private synchronized void selectClock(int position) {
- SharedPreferences.Editor ed = mPrefs.edit();
- ed.putInt(AlarmClock.PREF_CLOCK_FACE, position);
- ed.commit();
-
- setResult(RESULT_OK);
- finish();
- }
-
- public void onNothingSelected(AdapterView parent) {
- }
-
- class ClockAdapter extends BaseAdapter {
-
- public ClockAdapter() {
- }
-
- public int getCount() {
- return AlarmClock.CLOCKS.length;
- }
-
- public Object getItem(int position) {
- return position;
- }
-
- public long getItemId(int position) {
- return position;
- }
-
- public View getView(final int position, View convertView, ViewGroup parent) {
- View clock = mFactory.inflate(AlarmClock.CLOCKS[position], null);
- return clock;
- }
-
- }
-}
import android.content.IntentFilter;
import android.content.res.Resources;
import android.database.ContentObserver;
-import android.graphics.drawable.AnimationDrawable;
-import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.provider.Settings;
import android.text.format.DateFormat;
private String mFormat;
private TextView mTimeDisplay;
private AmPm mAmPm;
- private boolean mAnimate;
private ContentObserver mFormatChangeObserver;
private boolean mLive = true;
private boolean mAttached;
if (mAttached) return;
mAttached = true;
- if (mAnimate) {
- setBackgroundResource(R.drawable.animate_circle);
- /* Start the animation (looped playback by default). */
- ((AnimationDrawable) getBackground()).start();
- }
-
if (mLive) {
/* monitor time ticks, time changed, timezone */
IntentFilter filter = new IntentFilter();
if (!mAttached) return;
mAttached = false;
- Drawable background = getBackground();
- if (background instanceof AnimationDrawable) {
- ((AnimationDrawable) background).stop();
- }
-
if (mLive) {
mContext.unregisterReceiver(mIntentReceiver);
}
mAmPm.setShowAmPm(mFormat == M12);
}
- void setAnimate() {
- mAnimate = true;
- }
-
void setLive(boolean live) {
mLive = live;
}