本文整理汇总了Java中android.provider.AlarmClock类的典型用法代码示例。如果您正苦于以下问题:Java AlarmClock类的具体用法?Java AlarmClock怎么用?Java AlarmClock使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AlarmClock类属于android.provider包,在下文中一共展示了AlarmClock类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setAlarm
import android.provider.AlarmClock; //导入依赖的package包/类
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();
}
示例2: setAlarm
import android.provider.AlarmClock; //导入依赖的package包/类
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);
}
示例3: setupDrawerContent
import android.provider.AlarmClock; //导入依赖的package包/类
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;
}
});
}
示例4: createOnClickPendingIntent
import android.provider.AlarmClock; //导入依赖的package包/类
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);
}
示例5: setTimer
import android.provider.AlarmClock; //导入依赖的package包/类
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();
}
}
示例6: setAlarm
import android.provider.AlarmClock; //导入依赖的package包/类
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();
}
}
示例7: load
import android.provider.AlarmClock; //导入依赖的package包/类
@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;
}
示例8: onUpdate
import android.provider.AlarmClock; //导入依赖的package包/类
@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);
}
示例9: hookIntoEvents
import android.provider.AlarmClock; //导入依赖的package包/类
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;
}
示例10: setCoffeeReminder
import android.provider.AlarmClock; //导入依赖的package包/类
@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();
}
}
示例11: onClick
import android.provider.AlarmClock; //导入依赖的package包/类
@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);
}
}
示例12: onReceive
import android.provider.AlarmClock; //导入依赖的package包/类
@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();
}
}
}
}
示例13: onCreate
import android.provider.AlarmClock; //导入依赖的package包/类
@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();
}
示例14: getAddAlarmIntent
import android.provider.AlarmClock; //导入依赖的package包/类
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;
}
示例15: setAlarm
import android.provider.AlarmClock; //导入依赖的package包/类
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);
}