Java 类android.provider.AlarmClock 实例源码

项目:MDSimpleNotes    文件:MainActivity.java   
private void setupDrawerContent(NavigationView navigationView) {
    navigationView.setNavigationItemSelectedListener(new OnNavigationItemSelectedListener() {

        @Override
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            menuItem.setChecked(true);
            mDrawerLayout.closeDrawers();
            switch (menuItem.getItemId()) {
                case R.id.navItem1:
                    Intent alarm = new Intent(AlarmClock.ACTION_SET_ALARM);
                    startActivity(alarm);
                    break;
                case R.id.navItem2:
                    try {
                        export();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    break;
            }
            return false;
        }
    });
}
项目:TabletClock    文件:ClockActivity.java   
@SuppressLint("InlinedApi")
@Override
public void onClick(View v) {
    if (android.os.Build.VERSION.SDK_INT >= 9) {
        if (v == mAlarm1View || v == mAlarm2View) {
            Animations.click(v, this);
        } else {
            try {
                Intent i = new Intent(
                        android.os.Build.VERSION.SDK_INT >= 19 ? AlarmClock.ACTION_SHOW_ALARMS
                                : AlarmClock.ACTION_SET_ALARM);
                startActivity(i);
            } catch (Exception e) {
                Toast.makeText(ClockActivity.this, R.string.alerror,
                        Toast.LENGTH_SHORT).show();
            }
        }
    } else {
        mWheatherFlipListener.onClick(v);
    }
}
项目:GallyShuttle    文件:ScheduleActivity.java   
private void setAlarm(LocalDateTime alarmTime) {

        Alarm alarm = new Alarm.Builder(this)
                .setArrivalTime(DateUtils.formatTime(arrivalTime))
                .setStationName(scheduleViewPager.getAdapter().getPageTitle(scheduleViewPager.getCurrentItem()).toString())
                .setTriggerTime(alarmTime.toDate().getTime())
                .build();

        Intent alarmIntent = new Intent(AlarmClock.ACTION_SET_ALARM);
        alarmIntent.putExtra(AlarmClock.EXTRA_MESSAGE, alarm.getStationName() + " arrival reminder.");
        alarmIntent.putExtra(AlarmClock.EXTRA_HOUR, alarmTime.getHourOfDay());
        alarmIntent.putExtra(AlarmClock.EXTRA_MINUTES, alarmTime.getMinuteOfHour());
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            alarmIntent.putExtra(AlarmClock.EXTRA_VIBRATE, sharedPreferences.getBoolean(getString(R.string.pref_key_alarm_vibrate), true));
            String ringtone = sharedPreferences.getString(getString(R.string.pref_key_alarm_ringtone), "");
            if (TextUtils.isEmpty(ringtone)) {
                alarmIntent.putExtra(AlarmClock.VALUE_RINGTONE_SILENT, true);
            } else {
                alarmIntent.putExtra(AlarmClock.EXTRA_RINGTONE, ringtone);
            }
        }

        startActivity(Intent.createChooser(alarmIntent, "Set alarm"));
        Snackbar.make(coordinatorLayout, "Alarm set for " + DateUtils.formatTime(alarmTime), Snackbar.LENGTH_LONG).show();
    }
项目:10-bitClockWidget    文件:ClockWidgetUpdateService.java   
private PendingIntent createOnClickPendingIntent() {
    Intent openClockIntent = new Intent(AlarmClock.ACTION_SET_ALARM);
    ActivityInfo clockInfo = getPackageManager().resolveActivity(openClockIntent, 0).activityInfo;
    return PendingIntent.getActivity(this, RC_OPEN_CLOCK,
            getPackageManager().getLaunchIntentForPackage(clockInfo.packageName),
            PendingIntent.FLAG_CANCEL_CURRENT);
}
项目:Marv    文件:MainActivity.java   
private void setAlarm(int hours,int minutes){

        Intent i = new Intent(AlarmClock.ACTION_SET_ALARM);
        i.putExtra(AlarmClock.EXTRA_MESSAGE, "It's about time!");
        i.putExtra(AlarmClock.EXTRA_HOUR, hours);
        i.putExtra(AlarmClock.EXTRA_MINUTES, minutes);
        startActivity(i);

    }
项目:AlexaAndroid    文件:AndroidSystemHandler.java   
private void setTimer(final AvsSetAlertItem item){
    Intent i = new Intent(AlarmClock.ACTION_SET_TIMER);
    try {
        int time = (int) ((item.getScheduledTimeMillis() - System.currentTimeMillis()) / 1000);
        i.putExtra(AlarmClock.EXTRA_LENGTH, time);
        i.putExtra(AlarmClock.EXTRA_SKIP_UI, true);
        context.startActivity(i);
        AlexaManager.getInstance(context)
                .sendEvent(Event.getSetAlertSucceededEvent(item.getToken()), null);

        //cheating way to tell Alexa that the timer happened successfully--this SHOULD be improved
        //todo make this better
        new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
            @Override
            public void run() {
                AlexaManager.getInstance(context)
                        .sendEvent(Event.getAlertStartedEvent(item.getToken()), new ImplAsyncCallback<AvsResponse, Exception>() {
                            @Override
                            public void complete() {
                                AlexaManager.getInstance(context)
                                        .sendEvent(Event.getAlertStoppedEvent(item.getToken()), null);
                            }
                        });
            }
        }, time * 1000);
    } catch (ParseException e) {
        e.printStackTrace();
    }

}
项目:AlexaAndroid    文件:AndroidSystemHandler.java   
private void setAlarm(AvsSetAlertItem item){
    Intent i = new Intent(AlarmClock.ACTION_SET_ALARM);
    try {
        i.putExtra(AlarmClock.EXTRA_HOUR, item.getHour());
        i.putExtra(AlarmClock.EXTRA_MINUTES, item.getMinutes());
        i.putExtra(AlarmClock.EXTRA_SKIP_UI, true);
        context.startActivity(i);
        AlexaManager.getInstance(context)
                .sendEvent(Event.getSetAlertSucceededEvent(item.getToken()), null);

    } catch (ParseException e) {
        e.printStackTrace();
    }
}
项目:Easer    文件:AlarmLoader.java   
@Override
public boolean load(@ValidData @NonNull AlarmOperationData data) {
    AlarmOperationData.AlarmData iData = data.data;
    Intent intent = new Intent(AlarmClock.ACTION_SET_ALARM);
    int hour = iData.time.get(Calendar.HOUR_OF_DAY);
    int minute = iData.time.get(Calendar.MINUTE);
    if (!iData.absolute) {
        Calendar calendar = Calendar.getInstance();
        minute += calendar.get(Calendar.MINUTE);
        if (minute >= 60) {
            hour += 1;
            minute -= 60;
        }
        hour += calendar.get(Calendar.HOUR_OF_DAY);
        if (hour >= 24) {
            hour -= 24;
        }
    }
    intent.putExtra(AlarmClock.EXTRA_HOUR, hour);
    intent.putExtra(AlarmClock.EXTRA_MINUTES, minute);
    intent.putExtra(AlarmClock.EXTRA_MESSAGE, iData.message);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        intent.putExtra(AlarmClock.EXTRA_VIBRATE, true);
    }
    intent.putExtra(AlarmClock.EXTRA_SKIP_UI, true);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    if (intent.resolveActivity(context.getPackageManager()) != null) {
        context.startActivity(intent);
        return true;
    } else
        return false;
}
项目:Klok    文件:ClockOnlyWidget.java   
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.clock_only_widget);

    /*Launch system alarm app on clock click*/
    Intent openClockIntent = new Intent(AlarmClock.ACTION_SHOW_ALARMS);
    openClockIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent clockPendingIntent = PendingIntent.getActivity(context, 0, openClockIntent, 0);
    remoteViews.setOnClickPendingIntent(R.id.textClock, clockPendingIntent);

    /*Redrawing and updating clock_only_widget*/
    appWidgetManager.updateAppWidget(appWidgetIds[0], remoteViews);
}
项目:Noyze    文件:VolumePanel.java   
private void hookIntoEvents() {
    Context context = getContext();
       MainThreadBus.get().register(this);
       mAppTypeMonitor = new AppTypeMonitor(MediaStore.ACTION_IMAGE_CAPTURE, AlarmClock.ACTION_SET_ALARM);
       mAppTypeMonitor.register(context);
       mPriorityModeObserver = new GlobalSetting(context, mUiHandler, Constants.ZEN_MODE) {
           @Override protected void handleValueChanged(int value) {
               mPriorityMode = value;
               onPriorityModeChanged(value);
           }
       };
       mPriorityMode = mPriorityModeObserver.getValue();
       mPriorityModeObserver.setListening(true);
       registeredOtto = true;
}
项目:canicoffee    文件:CanICoffeePresenter.java   
@Override
    public void setCoffeeReminder(MainActivity mainActivity, boolean isFirstCoffeeCycle) {
        if (!canICoffeeView.getTimeWake().equals("")) {
            Intent intent = new Intent(AlarmClock.ACTION_SET_ALARM);
//            Log.i(TAG, "setCoffeeReminder isFirstCoffeeCycle: " + isFirstCoffeeCycle);
            int hourOffset, minOffset;
            String message;
            if (isFirstCoffeeCycle) {
                hourOffset = 3;
                minOffset = 30;
                message = mainActivity.getString(R.string.txt_remind_coffee_time_1);
            } else {
                hourOffset = 7;
                minOffset = 30;
                message = mainActivity.getString(R.string.txt_remind_coffee_time_2);
            }
            Time time = canICoffeeView.getTime();
            Time coffeeTime = mTimeWorker.getTimeHourMin(time.getHour() + hourOffset, time.getMinutes() + minOffset);
            Time fixedCoffeeTime = mTimeWorker.getFixedAmPm(coffeeTime.getHour(), coffeeTime.getMinutes());
            int coffeeHour = (int) fixedCoffeeTime.getHour();
            int coffeeMinute = (int) fixedCoffeeTime.getMinutes();
            intent.putExtra(AlarmClock.EXTRA_HOUR, coffeeHour);
            intent.putExtra(AlarmClock.EXTRA_MINUTES, coffeeMinute);
//            Log.i(TAG, "setCoffeeReminder " + coffeeHour + "H" + coffeeMinute + "M");
            intent.putExtra(AlarmClock.EXTRA_MESSAGE, message);
            mainActivity.startActivity(intent);
        } else {
            Toast.makeText(mainActivity, mainActivity.getString(R.string.txt_toast_empty_time), Toast.LENGTH_SHORT).show();
        }
    }
项目:Geoclock    文件:AlarmClockReceiver.java   
@Override
public void onReceive(final Context context, final Intent intent) {
    if (intent.hasExtra(ALARM_ID)) {
        GeoAlarm alarm = GeoAlarm.getGeoAlarm(context, UUID.fromString(intent.getStringExtra(ALARM_ID)));
        if (alarm != null && alarm.enabled) {
            ActiveAlarmManager activeAlarmManager = new ActiveAlarmManager(context);

            Intent alarmClockIntent = new Intent(AlarmClock.ACTION_SET_ALARM);
            Calendar cal = new GregorianCalendar();
            alarmClockIntent.putExtra(AlarmClock.EXTRA_HOUR, cal.get(Calendar.HOUR_OF_DAY));
            alarmClockIntent.putExtra(AlarmClock.EXTRA_MINUTES, cal.get(Calendar.MINUTE) + 1);
            alarmClockIntent.putExtra(AlarmClock.EXTRA_SKIP_UI, true);
            alarmClockIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            if (intent.resolveActivity(context.getPackageManager()) != null) {
                context.startActivity(alarmClockIntent);
            } else {
                // TODO: I have no idea how to handle this
                Log.e(TAG, "There is no alarm clock app");
            }

            if (alarm.days == null || alarm.days.isEmpty())  {
                GeoAlarm.remove(context, alarm);
                GeoAlarm.save(context, alarm.withEnabled(false));
                activeAlarmManager.removeActiveAlarms(ImmutableSet.of(alarm.id));
            } else {
                activeAlarmManager.resetActiveAlarms();
            }
        }
    }
}
项目:Noyze    文件:VolumePanel.java   
private void hookIntoEvents() {
    Context context = getContext();
       MainThreadBus.get().register(this);
       mAppTypeMonitor = new AppTypeMonitor(MediaStore.ACTION_IMAGE_CAPTURE, AlarmClock.ACTION_SET_ALARM);
       mAppTypeMonitor.register(context);
       mPriorityModeObserver = new GlobalSetting(context, mUiHandler, Constants.ZEN_MODE) {
           @Override protected void handleValueChanged(int value) {
               mPriorityMode = value;
               onPriorityModeChanged(value);
           }
       };
       mPriorityMode = mPriorityModeObserver.getValue();
       mPriorityModeObserver.setListening(true);
       registeredOtto = true;
}
项目:AndroidWearable-Samples    文件:SetTimerActivity.java   
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    int paramLength = getIntent().getIntExtra(AlarmClock.EXTRA_LENGTH, 0);
    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, "SetTimerActivity:onCreate=" + paramLength);
    }
    if (paramLength > 0 && paramLength <= 86400) {
        long durationMillis = paramLength * 1000;
        setupTimer(durationMillis);
        finish();
        return;
    }

    Resources res = getResources();
    for (int i = 0; i < NUMBER_OF_TIMES; i++) {
        mTimeOptions[i] = new ListViewItem(
                res.getQuantityString(R.plurals.timer_minutes, i + 1, i + 1),
                (i + 1) * 60 * 1000);
    }

    setContentView(R.layout.timer_set_timer);

    // Initialize a simple list of countdown time options.
    mListView = (ListView) findViewById(R.id.times_list_view);
    ArrayAdapter<ListViewItem> arrayAdapter = new ArrayAdapter<ListViewItem>(this,
            android.R.layout.simple_list_item_1, mTimeOptions);
    mListView.setAdapter(arrayAdapter);
    mListView.setOnItemClickListener(this);

    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addApi(Wearable.API)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .build();
}
项目:flow-android    文件:CalendarHelper.java   
public static Intent getAddAlarmIntent(String title, String location, Date startDate) {
    Calendar calendar = GregorianCalendar.getInstance();
    calendar.setTime(startDate);

    Intent intent = new Intent(AlarmClock.ACTION_SET_ALARM);
    intent.putExtra(AlarmClock.EXTRA_HOUR, calendar.get(Calendar.HOUR_OF_DAY));
    intent.putExtra(AlarmClock.EXTRA_MINUTES, calendar.get(Calendar.MINUTE));
    intent.putExtra(AlarmClock.EXTRA_MESSAGE, String.format("%s - %s", title, location));
    // To show the Alarm app after adding an alarm, uncomment the line below:
    // intent.putExtra(AlarmClock.EXTRA_SKIP_UI, true);

    /* Note: API 19 (KitKat) allows you to set the alarm's day(s) via the extra AlarmClock.EXTRA_DAYS */

    return intent;
}
项目:HelloBrazil    文件:MyActivity.java   
private void setAlarm(Date date, int min) {
    long time = date.getTime() - (long) 1000 * 60 * min;
    Date newTime = new Date(time);
    Intent openNewAlarm = new Intent(AlarmClock.ACTION_SET_ALARM);
    openNewAlarm.putExtra(AlarmClock.EXTRA_HOUR, newTime.getHours());
    openNewAlarm.putExtra(AlarmClock.EXTRA_MINUTES, newTime.getMinutes());
    startActivity(openNewAlarm);
}
项目:maxs    文件:TimerSet.java   
@Override
public Message execute(String arguments, Command command, MAXSModuleIntentService service) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT)
        return new Message("Timer needs a minimum API level of 19 (KitKat)");

    String duration;
    String timerDescription;
    int spaceIndex = arguments.indexOf(' ');
    if (spaceIndex == -1) {
        duration = arguments;
        timerDescription = null;
    } else {
        duration = arguments.substring(0, spaceIndex);
        timerDescription = arguments.substring(spaceIndex);
    }
    Intent intent = new Intent(AlarmClock.ACTION_SET_TIMER);
    int seconds = toSeconds(duration);
    intent.putExtra(AlarmClock.EXTRA_LENGTH, seconds);

    if (timerDescription == null) timerDescription = "Created by MAXS";
    intent.putExtra(AlarmClock.EXTRA_MESSAGE, timerDescription);

    intent.putExtra(AlarmClock.EXTRA_SKIP_UI, true);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    service.startActivity(intent);

    return new Message("Timer set");
}
项目:maxs    文件:AlarmSet.java   
@Override
public Message execute(String arguments, Command command, MAXSModuleIntentService service) {

    String time;
    String alarmDescription;
    int spaceIndex = arguments.indexOf(' ');
    if (spaceIndex == -1) {
        time = arguments;
        alarmDescription = null;
    } else {
        time = arguments.substring(0, spaceIndex);
        alarmDescription = arguments.substring(spaceIndex);
    }

    String[] splitedTime = time.split(":");
    if (splitedTime.length != 2) return new Message("Invalid time format: " + time, false);

    int hour = Integer.parseInt(splitedTime[0]);
    int minutes = Integer.parseInt(splitedTime[1]);

    if (alarmDescription == null) alarmDescription = "Created by MAXS";

    Intent intent = new Intent(AlarmClock.ACTION_SET_ALARM);
    intent.putExtra(AlarmClock.EXTRA_MINUTES, minutes);
    intent.putExtra(AlarmClock.EXTRA_HOUR, hour);
    intent.putExtra(AlarmClock.EXTRA_MESSAGE, alarmDescription);
    intent.putExtra(AlarmClock.EXTRA_SKIP_UI, true);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    service.startActivity(intent);

    return new Message("Alarm set");
}
项目:android_packages_apps_ClockWidget    文件:ClockWidget.java   
private static void setupEditOnClick(Context context, RemoteViews widget) {
    String intentAction = Build.VERSION.SDK_INT >= 19 ? AlarmClock.ACTION_SHOW_ALARMS : AlarmClock.ACTION_SET_ALARM;
    Intent launchIntent = new Intent(intentAction);
    PendingIntent launchPendingIntent = PendingIntent.getActivity(context, r.nextInt(), launchIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    widget.setOnClickPendingIntent(R.id.clock_edit_button, launchPendingIntent);
}
项目:GeometricWeather    文件:WidgetClockDayVerticalUtils.java   
public static void refreshWidgetView(Context context, Location location, Weather weather) {
    if (weather == null) {
        return;
    }

    SharedPreferences sharedPreferences = context.getSharedPreferences(
            context.getString(R.string.sp_widget_clock_day_vertical_setting),
            Context.MODE_PRIVATE);
    String viewStyle = sharedPreferences.getString(context.getString(R.string.key_view_type), "rectangle");
    boolean showCard = sharedPreferences.getBoolean(context.getString(R.string.key_show_card), false);
    boolean blackText = sharedPreferences.getBoolean(context.getString(R.string.key_black_text), false);
    boolean hideSubtitle = sharedPreferences.getBoolean(context.getString(R.string.key_hide_subtitle), false);
    String subtitleData = sharedPreferences.getString(context.getString(R.string.key_subtitle_data), "time");
    boolean dayTime = TimeManager.getInstance(context).getDayTime(context, weather, false).isDayTime();

            SharedPreferences defaultSharePreferences = PreferenceManager.getDefaultSharedPreferences(context);
    boolean fahrenheit = defaultSharePreferences.getBoolean(
            context.getString(R.string.key_fahrenheit),
            false);
    String iconStyle = defaultSharePreferences.getString(
            context.getString(R.string.key_widget_icon_style),
            "material");
    boolean touchToRefresh = defaultSharePreferences.getBoolean(
            context.getString(R.string.key_click_widget_to_refresh),
            false);

    int textColor;
    if (blackText || showCard) {
        textColor = ContextCompat.getColor(context, R.color.colorTextDark);
    } else {
        textColor = ContextCompat.getColor(context, R.color.colorTextLight);
    }

    RemoteViews views = buildWidgetViewDayPart(
            context, weather,
            dayTime, textColor, fahrenheit,
            iconStyle, blackText,
            viewStyle,
            hideSubtitle, subtitleData);

    views.setViewVisibility(R.id.widget_clock_day_card, showCard ? View.VISIBLE : View.GONE);

    Intent intentClock = new Intent(AlarmClock.ACTION_SHOW_ALARMS);
    PendingIntent pendingIntentClock = PendingIntent.getActivity(
            context, CLOCK_PENDING_INTENT_CODE, intentClock, PendingIntent.FLAG_UPDATE_CURRENT);
    views.setOnClickPendingIntent(R.id.widget_clock_day_clockButton, pendingIntentClock);

    PendingIntent pendingIntentWeather;
    if (touchToRefresh) {
        pendingIntentWeather = PendingIntent.getService(
                context,
                WEATHER_PENDING_INTENT_CODE,
                new Intent(context, NormalUpdateService.class),
                PendingIntent.FLAG_UPDATE_CURRENT);
    } else {
        pendingIntentWeather = PendingIntent.getActivity(
                context,
                WEATHER_PENDING_INTENT_CODE,
                IntentHelper.buildMainActivityIntent(context, location),
                PendingIntent.FLAG_UPDATE_CURRENT);
    }
    views.setOnClickPendingIntent(R.id.widget_clock_day_weatherButton, pendingIntentWeather);

    // commit.
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
    appWidgetManager.updateAppWidget(
            new ComponentName(context, WidgetClockDayVerticalProvider.class),
            views);
}
项目:GeometricWeather    文件:WidgetClockDayHorizontalUtils.java   
public static void refreshWidgetView(Context context, Location location, Weather weather) {
    if (weather == null) {
        return;
    }

    SharedPreferences sharedPreferences = context.getSharedPreferences(
            context.getString(R.string.sp_widget_clock_day_horizontal_setting),
            Context.MODE_PRIVATE);
    boolean showCard = sharedPreferences.getBoolean(context.getString(R.string.key_show_card), false);
    boolean blackText = sharedPreferences.getBoolean(context.getString(R.string.key_black_text), false);
    boolean dayTime = TimeManager.getInstance(context).getDayTime(context, weather, false).isDayTime();

    SharedPreferences defaultSharePreferences = PreferenceManager.getDefaultSharedPreferences(context);
    boolean fahrenheit = defaultSharePreferences.getBoolean(
            context.getString(R.string.key_fahrenheit),
            false);
    String iconStyle = defaultSharePreferences.getString(
            context.getString(R.string.key_widget_icon_style),
            "material");
    boolean touchToRefresh = defaultSharePreferences.getBoolean(
            context.getString(R.string.key_click_widget_to_refresh),
            false);

    int textColor;
    if (blackText || showCard) {
        textColor = ContextCompat.getColor(context, R.color.colorTextDark);
    } else {
        textColor = ContextCompat.getColor(context, R.color.colorTextLight);
    }

    RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_clock_day_horizontal);

    views.setImageViewResource(
            R.id.widget_clock_day_icon,
            getWeatherIconId(weather, dayTime, iconStyle, blackText));

    views.setTextViewText(
            R.id.widget_clock_day_lunar,
            getLunarText(context));

    views.setTextViewText(
            R.id.widget_clock_day_subtitle,
            getSubtitleText(weather, fahrenheit));

    views.setTextColor(R.id.widget_clock_day_clock, textColor);
    views.setTextColor(R.id.widget_clock_day_clock_aa, textColor);
    views.setTextColor(R.id.widget_clock_day_title, textColor);
    views.setTextColor(R.id.widget_clock_day_lunar, textColor);
    views.setTextColor(R.id.widget_clock_day_subtitle, textColor);

    views.setViewVisibility(R.id.widget_clock_day_card, showCard ? View.VISIBLE : View.GONE);

    Intent intentClock = new Intent(AlarmClock.ACTION_SHOW_ALARMS);
    PendingIntent pendingIntentClock = PendingIntent.getActivity(
            context,
            CLOCK_PENDING_INTENT_CODE,
            intentClock,
            PendingIntent.FLAG_UPDATE_CURRENT);
    views.setOnClickPendingIntent(R.id.widget_clock_day_clockButton, pendingIntentClock);

    PendingIntent pendingIntentWeather;
    if (touchToRefresh) {
        pendingIntentWeather = PendingIntent.getService(
                context,
                WEATHER_PENDING_INTENT_CODE,
                new Intent(context, NormalUpdateService.class),
                PendingIntent.FLAG_UPDATE_CURRENT);
    } else {
         pendingIntentWeather = PendingIntent.getActivity(
                context,
                WEATHER_PENDING_INTENT_CODE,
                IntentHelper.buildMainActivityIntent(context, location),
                PendingIntent.FLAG_UPDATE_CURRENT);
    }
    views.setOnClickPendingIntent(R.id.widget_clock_day_weatherButton, pendingIntentWeather);

    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
    appWidgetManager.updateAppWidget(
            new ComponentName(context, WidgetClockDayHorizontalProvider.class),
            views);
}
项目:CodeColors    文件:MainActivity.java   
@Override
public void onClick(DialogInterface dialog, int which) {
    startActivity(new Intent(AlarmClock.ACTION_SET_ALARM));
}
项目:Drudgery    文件:MainActivity.java   
@Override
public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {
        case R.id.mi_about_dq: {
            WebView wv = new WebView(this);
            String txt = getString(R.string.game_description);
            wv.loadData(txt, "text/html", null);

            AlertDialog.Builder builder = new AlertDialog.Builder(this);

            builder.setView(wv).setTitle(R.string.mi_about_dq)
                    .setPositiveButton(null, null).setNegativeButton(null, null)
                    .setNeutralButton(null, null).show();
            return true;
        }
        case R.id.mi_start_break: {
            Intent i = new Intent(AlarmClock.ACTION_SET_ALARM);
            Calendar rightNow = Calendar.getInstance();
            ViewPager pager = (ViewPager) findViewById(R.id.pager);
            int idx = pager.getCurrentItem();
            int blen = shiftPrefs[idx].getInt(BREAKTIME,DEF_BREAKTIME);
            rightNow.add(Calendar.MINUTE, prefs.getInt(BREAKTIME, blen));
            i.putExtra(AlarmClock.EXTRA_MESSAGE, R.string.msg_back_to_work);
            i.putExtra(AlarmClock.EXTRA_HOUR, rightNow.get(Calendar.HOUR_OF_DAY));
            i.putExtra(AlarmClock.EXTRA_MINUTES, rightNow.get(Calendar.MINUTE));
            i.putExtra(AlarmClock.EXTRA_SKIP_UI, true);
            if (getPackageManager().queryIntentActivities(i, 0).size() == 0) {
                Toast.makeText(this, R.string.msg_no_alarmclock, Toast.LENGTH_SHORT)
                        .show();
            }
            else {
                startActivity(i);
            }
            return true;
        }
        case R.id.mi_share: {
            Intent intent = new Intent("com.google.zxing.client.android.ENCODE");
            intent.putExtra("ENCODE_TYPE","TEXT_TYPE");
            intent.putExtra("ENCODE_DATA","market://details?id=de.onyxbits.drudgery");
            startActivity(intent);
            return true;
        }
    }
    return super.onOptionsItemSelected(item);
}