Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 591a6567 authored by rachelzhang's avatar rachelzhang Committed by Android (Google) Code Review
Browse files

Merge "Use the new TimePicker" into lmp-dev

parents 117f6da3 26f1eef7
Loading
Loading
Loading
Loading
+0 −8
Original line number Diff line number Diff line
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

# include res directory from timepicker
datetimepicker_dir := ../../../frameworks/opt/datetimepicker/res
res_dirs := $(datetimepicker_dir) res
LOCAL_RESOURCE_DIR := $(addprefix $(LOCAL_PATH)/, $(res_dirs))

LOCAL_MODULE_TAGS := optional

LOCAL_STATIC_JAVA_LIBRARIES := android-support-v13
LOCAL_STATIC_JAVA_LIBRARIES += android-support-v4
LOCAL_STATIC_JAVA_LIBRARIES += android-opt-datetimepicker

LOCAL_SRC_FILES := $(call all-java-files-under, src)

@@ -21,10 +15,8 @@ LOCAL_OVERRIDES_PACKAGES := AlarmClock
LOCAL_SDK_VERSION := current

LOCAL_PROGUARD_FLAG_FILES := proguard.flags
LOCAL_PROGUARD_FLAG_FILES += ../../../frameworks/opt/datetimepicker/proguard.flags

LOCAL_AAPT_FLAGS := --auto-add-overlay
LOCAL_AAPT_FLAGS += --extra-packages com.android.datetimepicker

include $(BUILD_PACKAGE)

+6 −6
Original line number Diff line number Diff line
@@ -29,6 +29,12 @@
        <item name="android:buttonStyle">?android:attr/borderlessButtonStyle</item>
    </style>

    <style name="TimePickerTheme" parent="@android:style/Theme.Material.Dialog">
        <item name="android:colorControlActivated">@color/witch_green</item>
        <item name="android:colorAccent">@color/witch_green</item>
        <item name="android:colorControlNormal">@color/white</item>
    </style>

    <style name="PopupMenu" parent="@android:style/Widget.Material.PopupMenu.Overflow">
        <item name="android:popupBackground">@color/bright_foreground_light_disabled</item>
    </style>
@@ -92,8 +98,6 @@
        <item name="android:textStyle">bold</item>
    </style>

    <style name="SetAlarmTheme" parent="@android:style/Theme.Material.DialogWhenLarge"/>

    <style name="AlarmAlertFullScreenWindowTitle">
        <item name="android:maxLines">1</item>
        <item name="android:scrollHorizontally">true</item>
@@ -272,10 +276,6 @@
        <item name="android:textSize">@dimen/city_time_font_size</item>
    </style>

    <style name="TimePickerDialog" parent="android:style/Theme.Material.Dialog">
        <item name="android:windowNoTitle">true</item>
    </style>

    <style name="TextAppearance">
        <item name="android:textSize">16sp</item>
        <item name="android:textStyle">normal</item>
+6 −24
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.app.LoaderManager;
import android.app.TimePickerDialog.OnTimeSetListener;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
@@ -40,7 +41,6 @@ import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Vibrator;
import android.text.format.DateFormat;
import android.transition.AutoTransition;
import android.transition.Transition;
import android.transition.TransitionManager;
@@ -63,11 +63,10 @@ import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.TimePicker;
import android.widget.Toast;
import android.widget.ToggleButton;

import com.android.datetimepicker.time.RadialPickerLayout;
import com.android.datetimepicker.time.TimePickerDialog;
import com.android.deskclock.alarms.AlarmStateManager;
import com.android.deskclock.provider.Alarm;
import com.android.deskclock.provider.AlarmInstance;
@@ -83,9 +82,7 @@ import java.util.HashSet;
 * AlarmClock application.
 */
public class AlarmClockFragment extends DeskClockFragment implements
        LoaderManager.LoaderCallbacks<Cursor>,
        TimePickerDialog.OnTimeSetListener,
        View.OnTouchListener {
        LoaderManager.LoaderCallbacks<Cursor>, OnTimeSetListener, View.OnTouchListener {
    private static final float EXPAND_DECELERATION = 1f;
    private static final float COLLAPSE_DECELERATION = 0.7f;
    private static final int ANIMATION_DURATION = 300;
@@ -448,17 +445,6 @@ public class AlarmClockFragment extends DeskClockFragment implements
            // Remove the SCROLL_TO_ALARM extra now that we've processed it.
            intent.removeExtra(SCROLL_TO_ALARM_INTENT_EXTRA);
        }

        // Make sure to use the child FragmentManager. We have to use that one for the
        // case where an intent comes in telling the activity to load the timepicker,
        // which means we have to use that one everywhere so that the fragment can get
        // correctly picked up here if it's open.
        TimePickerDialog tpd = (TimePickerDialog) getChildFragmentManager().
                findFragmentByTag(AlarmUtils.FRAG_TAG_TIME_PICKER);
        if (tpd != null) {
            // The dialog is already open so we need to set the listener again.
            tpd.setOnTimeSetListener(this);
        }
    }

    private void hideUndoBar(boolean animate, MotionEvent event) {
@@ -520,7 +506,7 @@ public class AlarmClockFragment extends DeskClockFragment implements

    // Callback used by TimePickerDialog
    @Override
    public void onTimeSet(RadialPickerLayout view, int hourOfDay, int minute) {
    public void onTimeSet(TimePicker timePicker, int hourOfDay, int minute) {
        if (mSelectedAlarm == null) {
            // If mSelectedAlarm is null then we're creating a new alarm.
            Alarm a = new Alarm();
@@ -532,7 +518,6 @@ public class AlarmClockFragment extends DeskClockFragment implements
            a.hour = hourOfDay;
            a.minutes = minute;
            a.enabled = true;

            mAddedAlarm = a;
            asyncAddAlarm(a);
        } else {
@@ -901,9 +886,7 @@ public class AlarmClockFragment extends DeskClockFragment implements
                @Override
                public void onClick(View view) {
                    mSelectedAlarm = itemHolder.alarm;
                    AlarmUtils.showTimeEditDialog(getChildFragmentManager(),
                            alarm, AlarmClockFragment.this
                            , DateFormat.is24HourFormat(getActivity()));
                    AlarmUtils.showTimeEditDialog(AlarmClockFragment.this, alarm);
                    expandAlarm(itemHolder, true);
                    itemHolder.alarmItem.post(mScrollRunnable);
                }
@@ -1516,8 +1499,7 @@ public class AlarmClockFragment extends DeskClockFragment implements
        // Set the "selected" alarm as null, and we'll create the new one when the timepicker
        // comes back.
        mSelectedAlarm = null;
        AlarmUtils.showTimeEditDialog(getChildFragmentManager(),
                null, AlarmClockFragment.this, DateFormat.is24HourFormat(getActivity()));
        AlarmUtils.showTimeEditDialog(this, null);
    }

    private static AlarmInstance setupAlarmInstance(Context context, Alarm alarm) {
+16 −20
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@ import android.content.Context;
import android.text.format.DateFormat;
import android.widget.Toast;

import com.android.datetimepicker.time.TimePickerDialog;
import android.app.TimePickerDialog;
import com.android.deskclock.provider.Alarm;
import com.android.deskclock.provider.AlarmInstance;

@@ -48,21 +48,16 @@ public class AlarmUtils {
                : alarmTimeStr;
    }

    public static void showTimeEditDialog(FragmentManager manager, final Alarm alarm,
            TimePickerDialog.OnTimeSetListener listener, boolean is24HourMode) {

        int hour, minutes;
        if (alarm == null) {
            hour = 0; minutes = 0;
        } else {
            hour = alarm.hour;
            minutes = alarm.minutes;
        }
        TimePickerDialog dialog = TimePickerDialog.newInstance(listener,
                hour, minutes, is24HourMode);
        dialog.setThemeDark(true);

        // Make sure the dialog isn't already added.
    /**
     * Show the time picker dialog. This is called from AlarmClockFragment to set alarm.
     * @param fragment The calling fragment (which is also a onTimeSetListener),
     *                 we use it as the target fragment of the TimePickerFragment, so later the
     *                 latter can retrieve it and set it as its onTimeSetListener when the fragment
     *                 is recreated.
     * @param alarm The clicked alarm, it can be null if user was clicking the fab instead.
     */
    public static void showTimeEditDialog(Fragment fragment, final Alarm alarm) {
        final FragmentManager manager = fragment.getFragmentManager();
        manager.executePendingTransactions();
        final FragmentTransaction ft = manager.beginTransaction();
        final Fragment prev = manager.findFragmentByTag(FRAG_TAG_TIME_PICKER);
@@ -70,10 +65,11 @@ public class AlarmUtils {
            ft.remove(prev);
        }
        ft.commit();

        if (dialog != null && !dialog.isAdded()) {
            dialog.show(manager, FRAG_TAG_TIME_PICKER);
        }
        final TimePickerFragment timePickerFragment = new TimePickerFragment();
        timePickerFragment.setTargetFragment(fragment, 0);
        timePickerFragment.setOnTimeSetListener((TimePickerDialog.OnTimeSetListener) fragment);
        timePickerFragment.setAlarm(alarm);
        timePickerFragment.show(manager, FRAG_TAG_TIME_PICKER);
    }

    /**
+67 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2014 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.app.Dialog;
import android.app.DialogFragment;
import android.app.TimePickerDialog;
import android.app.TimePickerDialog.OnTimeSetListener;
import android.os.Bundle;
import android.text.format.DateFormat;

import com.android.deskclock.provider.Alarm;

import java.util.Calendar;

public class TimePickerFragment extends DialogFragment {

    private Alarm mAlarm;
    private OnTimeSetListener mListener;

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        final int hour, minute;
        if (mAlarm == null) {
            final Calendar c = Calendar.getInstance();
            hour = c.get(Calendar.HOUR_OF_DAY);
            minute = c.get(Calendar.MINUTE);
        } else {
            hour = mAlarm.hour;
            minute = mAlarm.minutes;
        }

        return new TimePickerDialog(getActivity(), R.style.TimePickerTheme, mListener, hour, minute,
                DateFormat.is24HourFormat(getActivity()));
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        if (getTargetFragment() instanceof OnTimeSetListener) {
            setOnTimeSetListener((OnTimeSetListener) getTargetFragment());
        }
    }

    public void setOnTimeSetListener(OnTimeSetListener listener) {
        mListener = listener;
    }

    public void setAlarm(Alarm alarm) {
        mAlarm = alarm;
    }
}