增加日历到期后的关闭按钮,优化日历action图片资源

最近测试常提给我同一个bug,就是这个

进入日历,设置一个日程,日程时间到后,没有关闭按钮

原图是这样的增加日历到期后的关闭按钮,优化日历action图片资源_第1张图片

测试觉得上面那个日历提醒没有关闭按钮很不合理!???(黑人问号脸)
好吧,加一个吧
(1)先自定义一些图案样式(路径:alps/vendor/mediatek/proprietary/packages/apps/Calendar/res/drawable/)在这里增加一个ic_action_alarm.xml文件

<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="24dp"
        android:height="24dp"
        android:viewportWidth="24.0"
        android:viewportHeight="24.0">
    <path
        android:fillColor="#FFFFFFFF"
        android:pathData="M22,5.72l-4.6,-3.86 -1.29,1.53 4.6,3.86L22,5.72zM7.88,3.39L6.6,1.86 2,5.71l1.29,1.53 4.59,-3.85zM12.5,8L11,8v6l4.75,2.85 0.75,-1.23 -4,-2.37L12.5,8zM12,4c-4.97,0 -9,4.03 -9,9s4.02,9 9,9c4.97,0 9,-4.03 9,-9s-4.03,-9 -9,-9zM12,20c-3.87,0 -7,-3.13 -7,-7s3.13,-7 7,-7 7,3.13 7,7 -3.13,7 -7,7z"/>
vector>

(2)再在相同路径下增加ic_action_alarm_off.xml文件

<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="24dp"
        android:height="24dp"
        android:viewportWidth="24.0"
        android:viewportHeight="24.0">
    <path
        android:fillColor="#FFFFFFFF"
        android:pathData="M12,6c3.87,0 7,3.13 7,7 0,0.84 -0.16,1.65 -0.43,2.4l1.52,1.52c0.58,-1.19 0.91,-2.51 0.91,-3.92 0,-4.97 -4.03,-9 -9,-9 -1.41,0 -2.73,0.33 -3.92,0.91L9.6,6.43C10.35,6.16 11.16,6 12,6zM22,5.72l-4.6,-3.86 -1.29,1.53 4.6,3.86L22,5.72zM2.92,2.29L1.65,3.57 2.98,4.9l-1.11,0.93 1.42,1.42 1.11,-0.94 0.8,0.8C3.83,8.69 3,10.75 3,13c0,4.97 4.02,9 9,9 2.25,0 4.31,-0.83 5.89,-2.2l2.2,2.2 1.27,-1.27L3.89,3.27l-0.97,-0.98zM16.47,18.39C15.26,19.39 13.7,20 12,20c-3.87,0 -7,-3.13 -7,-7 0,-1.7 0.61,-3.26 1.61,-4.47l9.86,9.86zM8.02,3.28L6.6,1.86l-0.86,0.71 1.42,1.42 0.86,-0.71z"/>
vector>

(3)还是在相同路径下增加ic_action_call.xml文件

<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="24dp"
        android:height="24dp"
        android:viewportWidth="24.0"
        android:viewportHeight="24.0">
    <path
        android:fillColor="#FFFFFFFF"
        android:pathData="M6.62,10.79c1.44,2.83 3.76,5.14 6.59,6.59l2.2,-2.2c0.27,-0.27 0.67,-0.36 1.02,-0.24 1.12,0.37 2.33,0.57 3.57,0.57 0.55,0 1,0.45 1,1V20c0,0.55 -0.45,1 -1,1 -9.39,0 -17,-7.61 -17,-17 0,-0.55 0.45,-1 1,-1h3.5c0.55,0 1,0.45 1,1 0,1.25 0.2,2.45 0.57,3.57 0.11,0.35 0.03,0.74 -0.25,1.02l-2.2,2.2z"/>
vector>

(4)增加ic_action_email.xml文件

<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="24dp"
    android:height="24dp"
    android:viewportHeight="24.0"
    android:viewportWidth="24.0">
    <path
        android:fillColor="#FFFFFFFF"
        android:pathData="M20,4L4,4c-1.1,0 -1.99,0.9 -1.99,2L2,18c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2L22,6c0,-1.1 -0.9,-2 -2,-2z
        M20,18L4,18L4,8l8,5 8,-5v10z
        M12,11L4,6h16l-8,5z
        M23,20v-1h-1v1h-1v1h1v1h1v-1h1v-1h-4z" />
vector>

(5)增加ic_action_map.xml文件

<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="24dp"
        android:height="24dp"
        android:viewportWidth="24.0"
        android:viewportHeight="24.0">
    <path
        android:fillColor="#FFFFFFFF"
        android:pathData="M12,2C8.13,2 5,5.13 5,9c0,5.25 7,13 7,13s7,-7.75 7,-13c0,-3.87 -3.13,-7 -7,-7zM12,11.5c-1.38,0 -2.5,-1.12 -2.5,-2.5s1.12,-2.5 2.5,-2.5 2.5,1.12 2.5,2.5 -1.12,2.5 -2.5,2.5z"/>
vector>

(6)增加value中string字符串(路径:alps/vendor/mediatek/proprietary/packages/apps/Calendar/res/values/strings.xml)

    
    <string name="shut_label">"Shut"string> 

还有(路径: alps/vendor/mediatek/proprietary/packages/apps/Calendar/res/values-zh-rCN/strings.xml)

    <string name="snooze_label" msgid="1515893621063224666">"稍后"string>
    <string name="shut_label">"关闭"string> 

(7)然后是我们的重头戏,修改(路径:alps/vendor/mediatek/proprietary/packages/apps/Calendar/src/com/android/calendar/alerts/AlertReceiver.java)

1,先导包

import com.android.calendar.alerts.AlertUtils;

2,定义

   private static final String SHUT_ACTION = "com.android.calendar.SHUT";

3,加入相应intent判断条件

                Intent i = new Intent(context, QuickResponseActivity.class);
                i.putExtra(QuickResponseActivity.EXTRA_EVENT_ID, eventId);
                i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(i);
            }
       //add 在开始这里加入
        } else if(SHUT_ACTION.equals(intent.getAction())){
            long eventStart = intent.getLongExtra(AlertUtils.EVENT_START_KEY, -1);
            long eventEnd = intent.getLongExtra(AlertUtils.EVENT_END_KEY, -1);
            final long eventId = intent.getLongExtra(EXTRA_EVENT_ID, -1);
            if (eventId != -1) {
                AlertUtils.removeEventNotification(context, eventId, eventStart, eventEnd);
            }
      //add  加入结束
        } else {
            Intent i = new Intent();
            i.setClass(context, AlertService.class);
            i.putExtras(intent);

4,在此行最后加入shutIntent

        //add 
        PendingIntent mapIntent = null, callIntent = null, snoozeIntent = null, emailIntent = null, shutIntent = null;

5,再次创造shutintent

           // Create snooze intent.  TODO: change snooze to 10 minutes.
            snoozeIntent = createSnoozeIntent(context, eventId, startMillis, endMillis,
                    notificationId);

            //add  开始加入
            //Creat shut intent
            shutIntent =createShutBroadcastIntent(context, eventId, startMillis, endMillis);
        }
          //add 加入结束
        if (Utils.isJellybeanOrLater()) {

6,这里的图片全部改成我们自定义的,并加入shutintent附图

         // Add action buttons. Show at most three, using the following priority ordering:
            // 1. Map
            // 2. Call
            // 3. Email
            // 4. Snooze
            // Actions will only be shown if they are applicable; i.e. with no location, map will
            // not be shown, and with no recipients, snooze will not be shown.
            // TODO: Get icons, get strings. Maybe show preview of actual location/number?
            int numActions = 0;
            if (mapIntent != null && numActions < MAX_NOTIF_ACTIONS) {
                notificationBuilder.addAction(/*R.drawable.ic_map,*/R.drawable.ic_action_map,//modify by guanqi
                        resources.getString(R.string.map_label/*这个是加入的自定义图片*/), mapIntent);
                numActions++;
            }
            if (callIntent != null && numActions < MAX_NOTIF_ACTIONS) {
                notificationBuilder.addAction(/*R.drawable.ic_call,*/R.drawable.ic_action_call,//modify by guanqi
                        resources.getString(R.string.call_label/*这个是加入的自定义图片*/), callIntent);
                numActions++;
            }
            if (emailIntent != null && numActions < MAX_NOTIF_ACTIONS) {
                notificationBuilder.addAction(/*R.drawable.ic_menu_email_holo_dark,*/R.drawable.ic_action_email,//modify by guanqi
                        resources.getString(R.string.email_guests_label/*这个是加入的自定义图片*/), emailIntent);
                numActions++;
            }
            if (snoozeIntent != null && numActions < MAX_NOTIF_ACTIONS) {
                notificationBuilder.addAction(/*R.drawable.ic_alarm_holo_dark,*/R.drawable.ic_action_alarm,//modify by guanqi
                        resources.getString(R.string.snooze_label/*这个是加入的自定义图片*/), snoozeIntent);
                numActions++;
            }
            //add 加入开始 start
            if (shutIntent != null && numActions < MAX_NOTIF_ACTIONS) {
                notificationBuilder.addAction(/*R.drawable.ic_alarm_holo_dark,*/R.drawable.ic_action_alarm_off,//modify by guanqi
                        resources.getString(R.string.shut_label/*这个是加入的自定义图片*/), shutIntent);
                numActions++;
            }
          //add  加入结束(end)
            /** M: set category for interruptions feature. */
            notificationBuilder.setCategory(Notification.CATEGORY_EVENT);
            return notificationBuilder.getNotification();

        } else {

7,这里创造pendingintent在点击关闭按钮的时候将notifycation移除

  //add  (start)
    /**
     * Create a pending intent to send oursele a broadcast to shut 
     * use the AlertUtils to remove notification and event 
     */
    private static PendingIntent createShutBroadcastIntent(Context context, long eventId,
            long startMillis, long endMillis){
        Intent broadcastIntent = new Intent(SHUT_ACTION);
        broadcastIntent.setClass(context, AlertReceiver.class);
        broadcastIntent.putExtra(EXTRA_EVENT_ID, eventId);
        broadcastIntent.putExtra(AlertUtils.EVENT_START_KEY, startMillis);
        broadcastIntent.putExtra(AlertUtils.EVENT_END_KEY, endMillis);
        return PendingIntent.getBroadcast(context,
                    Long.valueOf(eventId).hashCode(), broadcastIntent,
                    PendingIntent.FLAG_CANCEL_CURRENT);

    }
  //add (end)

至此我们的修改就结束了修改后的图片是这样的,这是另一个同事修改的,只不过是“关闭”换成了“忽略”
增加日历到期后的关闭按钮,优化日历action图片资源_第2张图片

你可能感兴趣的:(技术总结)