Android BedClock with TextSwitcher color
<p>I have a bed clock and I wanted to add a change of color. I am AmbilWarna dialogue.</p>

<p>The problem is that the color change only seconds. See it on the screens.</p>

<p>White text first use:
<a href="http://i47.tinypic.com/vii53d.jpg" rel="nofollow">http://i47.tinypic.com/vii53d.jpg</a></p>

<p>Change the color to yellow:
<a href="http://i47.tinypic.com/11klgug.png" rel="nofollow">http://i47.tinypic.com/11klgug.png</a></p>

<p>Watch runs and seconds change from white to yellow.
<a href="http://i50.tinypic.com/n6cbht.jpg" rel="nofollow">http://i50.tinypic.com/n6cbht.jpg</a></p>

<p>After switching off the clock and on. The color changes for the entire H: MM: SS.</p>

<p>What was wrong that only the second change color?</p>

<p>Code:</p>

<pre><code>@Override
    protected void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        getWindow().requestFeature(Window.FEATURE_NO_TITLE);

        mInflater = getLayoutInflater();

        setContentView(R.layout.bedclock);

        registerForContextMenu(findViewById(R.id.bedclock_time_hour));
        registerForContextMenu(findViewById(R.id.bedclock_time_min));
        registerForContextMenu(findViewById(R.id.bedclock_time_sec));

        mSwitchHour = (TextSwitcher) findViewById(R.id.bedclock_time_hour);
        mSwitchHour.setFactory(this);
        mSwitchHour.setOnClickListener(this);
        mSwitchMin = (TextSwitcher) findViewById(R.id.bedclock_time_min);
        mSwitchMin.setFactory(this);
        mSwitchMin.setOnClickListener(this);
        mSwitchSec = (TextSwitcher) findViewById(R.id.bedclock_time_sec);
        mSwitchSec.setFactory(this);
        mSwitchSec.setOnClickListener(this);

        mAnimations = new ArrayList&lt;int[]&gt;();
        mAnimations.add(ANIMATION_FADE, new int[] { R.anim.slow_fade_in,
                R.anim.slow_fade_out });
        mAnimations.add(ANIMATION_PUSHUP, new int[] { R.anim.push_up_in,
                R.anim.push_up_out });
        mAnimations.add(ANIMATION_PUSHLEFT, new int[] { R.anim.push_left_in,
                R.anim.push_left_out });
        mAnimations.add(ANIMATION_PUSHDOWN, new int[] { R.anim.push_down_in,
                R.anim.push_down_out });
        mAnimations.add(ANIMATION_PUSHRIGHT, new int[] { R.anim.push_right_in,
                R.anim.push_right_out });
        mAnimations.add(ANIMATION_EXPLODE, new int[] { R.anim.slow_fade_in,
                R.anim.wave_scale });
        mAnimations.add(ANIMATION_SHATTER, new int[] { R.anim.shake,
                R.anim.push_down_out });
        mAnimations.add(ANIMATION_HYPER, new int[] { R.anim.hyperspace_in,
                R.anim.hyperspace_out });

        mPrefs = getSharedPreferences(AlarmClock.PREFERENCES, 0);

        setAnimation(mPrefs.getInt("bedclock_animation", ANIMATION_FADE));

        mOrient = mPrefs.getInt("bedclock_orientation",
                ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        setRequestedOrientation(mOrient);

        mDoWakeLock = mPrefs.getBoolean("bedclock_wake_lock", false);
        if (mDoWakeLock) {
            mPower = (PowerManager) getSystemService(Context.POWER_SERVICE);
            mWakeLock = mPower.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK,
                    BedClock.class.getName());
        }

        mCal = Calendar.getInstance();
        mHandler = new Handler();
        mBatteryReceiver = new BroadcastReceiver() {
            public void onReceive(Context context, Intent intent) {
                int plugged = intent.getIntExtra("plugged", 0);
                if (mWakeLock == null)
                    return;
                if ((plugged == BatteryManager.BATTERY_PLUGGED_AC)
                        || (plugged == BatteryManager.BATTERY_PLUGGED_USB)) {
                    if (!mWakeLock.isHeld()) {
                        mWakeLock.acquire();
                        android.util.Log.v("Alarm",
                                "BedClock: wakelock/acquire-plugged");
                    }
                } else {
                    if (mWakeLock.isHeld()) {
                        mWakeLock.release();
                        android.util.Log.v("Alarm",
                                "BedClock: wakelock/release-unplug");
                    }
                }
            }

        };

    }

    @Override
    protected void onDestroy() {
        if (mWakeLock != null &amp;&amp; mWakeLock.isHeld()) {
            mWakeLock.release();
            android.util.Log.v("Alarm", "BedClock: wakelock/release-destroy");
        }
        super.onDestroy();
    }

    @Override
    public void onResume() {
        super.onResume();

        if (mDoWakeLock &amp;&amp; mBatteryReceiver != null) {
            registerReceiver(mBatteryReceiver, new IntentFilter(
                    Intent.ACTION_BATTERY_CHANGED));
        }

        mCallback = new Runnable() {
            public void run() {
                BedClock.this.updateClock();
                mHandler.postDelayed(mCallback, 1000);
            }
        };
        mHandler.postDelayed(mCallback, 0);

    }

    @Override
    public void onPause() {
        cleanup();
        super.onPause();

    }

    public void setAnimation(int anim) {
        mAnim = anim;

        mPrefs.edit().putInt("bedclock_animation", mAnim).commit();
        int[] anim_ids = mAnimations.get(anim);

        Animation in_anim = AnimationUtils.loadAnimation(this, anim_ids[0]);
        Animation out_anim = AnimationUtils.loadAnimation(this, anim_ids[1]);

        mSwitchHour.setInAnimation(in_anim);
        mSwitchHour.setOutAnimation(out_anim);
        mSwitchMin.setInAnimation(in_anim);
        mSwitchMin.setOutAnimation(out_anim);
        mSwitchSec.setInAnimation(in_anim);
        mSwitchSec.setOutAnimation(out_anim);

    }

    public void updateClock() {
        boolean is24 = Alarms.get24HourMode(this);
        mCal.setTime(new Date());

        String s;

        s = DateFormat.format(is24 ? "k:" : "h:", mCal).toString();
        if (!s.equals(mHour)) {
            mSwitchHour.setText(mHour = s);

        }
        s = DateFormat.format(
                mOrient == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE ? "mm:"
                        : "mm", mCal).toString();
        if (!s.equals(mMin)) {
            mSwitchMin.setText(mMin = s);
        }
        s = DateFormat.format("ss", mCal).toString();
        if (!s.equals(mSec)) {
            mSwitchSec.setText(mSec = s);

        }

    }

    public View makeView() {
        textView = (TextView) LayoutInflater.from(getApplicationContext())
                .inflate(R.layout.bedclock_text, mSwitchHour, false);

        return textView;

    }

    public void onCreateContextMenu(ContextMenu menu, View view,
            ContextMenuInfo menuInfo) {
        // super.onCreateContextMenu(menu, v, menuInfo);

        menu.setHeaderTitle("Options");
        MenuItem anim = menu.add(0, MENUITEM_ANIM, 0, R.string.next_animation);
        MenuItem color_picker = menu.add(0, MENUITEM_COLOR_PICKER, 0,
                "Change Color");

        MenuItem close = menu.add(0, MENUITEM_CLOSE, 0, R.string.hide_clock);
    }

    @Override
    public boolean onContextItemSelected(MenuItem item) {
        int id = item.getItemId();
        switch (id) {
        case MENUITEM_CLOSE: {
            cleanup();
            finish();
            return true;
        }
        case MENUITEM_ANIM: {
            setAnimation(mAnim + 1 &gt;= mAnimations.size() ? 0 : mAnim + 1);
            return true;
        }
        case MENUITEM_COLOR_PICKER: {
            AmbilWarnaDialog dialog = new AmbilWarnaDialog(BedClock.this, 222,
                    new OnAmbilWarnaListener() {

                        public void onCancel(AmbilWarnaDialog dialog) {
                            // TODO Auto-generated method stub
                            Log.i("", "");
                        }

                        public void onOk(AmbilWarnaDialog dialog, int color) {

                            textView.setTextColor(color);

                            SharedPreferences sharedPrefs = PreferenceManager
                                    .getDefaultSharedPreferences(getApplicationContext());
                            SharedPreferences.Editor editor = sharedPrefs
                                    .edit();
                            editor.putInt(COLOR_PREFERENCE_KEY, color);
                            editor.commit();
                            Toast.makeText(getApplicationContext(), "CHANGED!",
                                    Toast.LENGTH_LONG).show();
                        }

                    });
            dialog.show();
            break;
        }
        }
        return true;

    }

    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_MENU) {
            return super.onKeyDown(keyCode, event);
        }

        cleanup();
        finish();
        return true;
    }

    public void cleanup() {
        try {
            if (mWakeLock != null &amp;&amp; mWakeLock.isHeld()) {
                mWakeLock.release();
                android.util.Log.v("Alarm",
                        "BedClock: wakelock/release-cleanup");
            }
            if (mDoWakeLock &amp;&amp; mBatteryReceiver != null) {
                unregisterReceiver(mBatteryReceiver);
            }
            if (mHandler != null &amp;&amp; mCallback != null) {
                mHandler.removeCallbacks(mCallback);
                mCallback = null;
            }
        } catch (Exception e) {
            android.util.Log.v("Alarm", "BedClock: cleanup exception!");
        }
    }
</code></pre>

<p>AmbilWarna dialog is in ContextMenu.</p>
