首页

安卓日历小部件源码(AppWidgetProvider)

java

2020-7-21

一款关于日历与行程安排的项目源码,点击日期可以转跳到日程新增界面,事件是提前定好的类型,提醒周期很丰富,可以按照周、年、月、日、小时和分钟为周期进行提醒,日历默认会显示一些节假日和纪念日信息。当日期被标记上事件以后会在日期右上角显示一个小红角作为提醒。

package com.yarin.android.TodayDate;

import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.text.format.Time;
import android.widget.RemoteViews;

public class TodayDateSmall extends AppWidgetProvider
{
	   @Override
	   public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
	      RemoteViews updateView = buildUpdate(context);
	      appWidgetManager.updateAppWidget(appWidgetIds, updateView);
	      super.onUpdate(context, appWidgetManager, appWidgetIds);
	   }
	   
	   private String[] months = {"一月", "二月", "三月", "四月",
               "五月", "六月", "七月", "八月",
               "九月", "十月", "十一月", "十二月"};
	   
	   
	   private RemoteViews buildUpdate(Context context) {
	      RemoteViews updateView = null;
	      Time time = new Time();
	      time.setToNow();
	      String month = months[time.month];
	      updateView = new RemoteViews(context.getPackageName(), R.layout.widget_layout_small);
	      updateView.setTextViewText(R.id.Date, new Integer(time.monthDay).toString());
	      updateView.setTextViewText(R.id.Month, month);
	      Intent launchIntent = new Intent();
	      launchIntent.setComponent(new ComponentName("com.android.calendar", "com.android.calendar.LaunchActivity"));
	      launchIntent.setAction(Intent.ACTION_MAIN);
	      launchIntent.addCategory(Intent.CATEGORY_LAUNCHER);
	      launchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
	      PendingIntent intent = PendingIntent.getActivity(context, 0, launchIntent, 0);
	      updateView.setOnClickPendingIntent(R.id.SmallBase, intent);
	      return updateView;
	   }
}

资源下载此资源下载价格为1D币(VIP免费),请先
资源文件列表
TodayDate/.classpath , 280
TodayDate/.project , 845
TodayDate/AndroidManifest.xml , 1110
TodayDate/bin/classes.dex , 5648
TodayDate/bin/com/yarin/android/TodayDate/R$attr.class , 367
TodayDate/bin/com/yarin/android/TodayDate/R$drawable.class , 547
TodayDate/bin/com/yarin/android/TodayDate/R$id.class , 530
TodayDate/bin/com/yarin/android/TodayDate/R$layout.class , 473
TodayDate/bin/com/yarin/android/TodayDate/R$string.class , 463
TodayDate/bin/com/yarin/android/TodayDate/R$xml.class , 450
TodayDate/bin/com/yarin/android/TodayDate/R.class , 647
TodayDate/bin/com/yarin/android/TodayDate/TodayDate.class , 3261
TodayDate/bin/com/yarin/android/TodayDate/TodayDateSmall.class , 2755
TodayDate/bin/resources.ap_ , 13098
TodayDate/bin/TodayDate.apk , 17833
TodayDate/default.properties , 449
TodayDate/gen/com/yarin/android/TodayDate/R.java , 1396
TodayDate/res/drawable/bg.9.png , 367
TodayDate/res/drawable/bg2.9.png , 507
TodayDate/res/drawable/bgblack.png , 2748
TodayDate/res/drawable/bgblacksmall.png , 1252
TodayDate/res/drawable/icon.png , 3288
TodayDate/res/layout/widget_layout.xml , 1680
TodayDate/res/layout/widget_layout_small.xml , 1384
TodayDate/res/values/strings.xml , 167
TodayDate/res/xml/widget.xml , 283
TodayDate/res/xml/widget_small.xml , 281
TodayDate/src/com/yarin/android/TodayDate/TodayDate.java , 1946
TodayDate/src/com/yarin/android/TodayDate/TodayDateSmall.java , 1894
没有账号? 忘记密码?

社交账号快速登录