Snap for 10453938 from ce04ba0d44375dd82b3bdccbb5290693eeefcb9e to mainline-odp-release

Change-Id: Ifa75a816696b2c4956bcf7fce6b688746ac6566f
diff --git a/src/com/android/calendar/AllInOneActivity.kt b/src/com/android/calendar/AllInOneActivity.kt
index 6c2e825..d6767f0 100644
--- a/src/com/android/calendar/AllInOneActivity.kt
+++ b/src/com/android/calendar/AllInOneActivity.kt
@@ -293,7 +293,6 @@
                 mControlsParams = LayoutParams(mControlsAnimateWidth, 0)
             }
             mControlsParams?.addRule(RelativeLayout.ALIGN_PARENT_RIGHT)
-                as RelativeLayout.LayoutParams
         } else {
             // Make sure width is in between allowed min and max width values
             mControlsAnimateWidth = Math.max(
@@ -305,7 +304,7 @@
                 res.getDimension(R.dimen.max_portrait_calendar_controls_width).toInt()
             )
         }
-        mControlsAnimateHeight = res?.getDimension(R.dimen.calendar_controls_height).toInt()
+        mControlsAnimateHeight = res.getDimension(R.dimen.calendar_controls_height).toInt()
         mHideControls = true
         mIsMultipane = Utils.getConfigBool(this, R.bool.multiple_pane_config)
         mIsTabletConfig = Utils.getConfigBool(this, R.bool.tablet_config)
@@ -356,18 +355,18 @@
     private fun parseViewAction(intent: Intent?): Long {
         var timeMillis: Long = -1
         val data: Uri? = intent?.getData()
-        if (data != null && data?.isHierarchical()) {
+        if (data != null && data.isHierarchical()) {
             val path = data.getPathSegments()
-            if (path?.size == 2 && path!![0].equals("events")) {
+            if (path?.size == 2 && path[0].equals("events")) {
                 try {
                     mViewEventId = data.getLastPathSegment()?.toLong() as Long
                     if (mViewEventId != -1L) {
-                        mIntentEventStartMillis = intent?.getLongExtra(EXTRA_EVENT_BEGIN_TIME, 0)
-                        mIntentEventEndMillis = intent?.getLongExtra(EXTRA_EVENT_END_TIME, 0)
-                        mIntentAttendeeResponse = intent?.getIntExtra(
+                        mIntentEventStartMillis = intent.getLongExtra(EXTRA_EVENT_BEGIN_TIME, 0)
+                        mIntentEventEndMillis = intent.getLongExtra(EXTRA_EVENT_END_TIME, 0)
+                        mIntentAttendeeResponse = intent.getIntExtra(
                             ATTENDEE_STATUS, Attendees.ATTENDEE_STATUS_NONE
                         )
-                        mIntentAllDay = intent?.getBooleanExtra(EXTRA_EVENT_ALL_DAY, false)
+                        mIntentAllDay = intent.getBooleanExtra(EXTRA_EVENT_ALL_DAY, false)
                             as Boolean
                         timeMillis = mIntentEventStartMillis
                     }
@@ -413,7 +412,7 @@
         }
         val cancelItem: MenuItem? = mOptionsMenu?.findItem(R.id.action_cancel)
         if (cancelItem != null) {
-            cancelItem?.setVisible(false)
+            cancelItem.setVisible(false)
         }
     }
 
@@ -541,7 +540,7 @@
             val data: Uri? = intent.getData()
             if (data != null) {
                 try {
-                    eventId = data?.getLastPathSegment()?.toLong() as Long
+                    eventId = data.getLastPathSegment()?.toLong() as Long
                 } catch (e: NumberFormatException) {
                     if (DEBUG) {
                         Log.d(TAG, "Create new event")
@@ -554,12 +553,12 @@
             val end: Long = intent.getLongExtra(EXTRA_EVENT_END_TIME, -1)
             info = EventInfo()
             if (end != -1L) {
-                info?.endTime = Time()
-                info?.endTime?.set(end)
+                info.endTime = Time()
+                info.endTime?.set(end)
             }
             if (begin != -1L) {
-                info?.startTime = Time()
-                info?.startTime?.set(begin)
+                info.startTime = Time()
+                info.startTime?.set(begin)
             }
             info.id = eventId
             // We set the viewtype so if the user presses back when they are
@@ -684,7 +683,7 @@
     }
 
     @Override
-    override fun onSharedPreferenceChanged(prefs: SharedPreferences?, key: String) {
+    override fun onSharedPreferenceChanged(prefs: SharedPreferences, key: String?) {
         if (key.equals(GeneralPreferences.KEY_WEEK_START_DAY)) {
             if (mPaused) {
                 mUpdateOnResume = true
@@ -810,10 +809,10 @@
         if (event.eventType != EventType.UPDATE_TITLE || mActionBar == null) {
             return
         }
-        val start: Long? = event?.startTime?.toMillis(false /* use isDst */)
+        val start: Long? = event.startTime?.toMillis(false /* use isDst */)
         val end: Long?
         end = if (event.endTime != null) {
-            event?.endTime?.toMillis(false /* use isDst */)
+            event.endTime?.toMillis(false /* use isDst */)
         } else {
             start
         }
@@ -824,8 +823,8 @@
         )
         val oldDate: CharSequence? = mDateRange?.getText()
         mDateRange?.setText(msg)
-        updateSecondaryTitleFields(if (event?.selectedTime != null)
-            event?.selectedTime?.toMillis(true) as Long else start)
+        updateSecondaryTitleFields(if (event.selectedTime != null)
+            event.selectedTime?.toMillis(true) as Long else start)
         if (!TextUtils.equals(oldDate, msg)) {
             mDateRange?.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED)
             if (mShowWeekNum && mWeekTextView != null) {
@@ -907,23 +906,23 @@
     override fun handleEvent(event: EventInfo?) {
         var displayTime: Long = -1
         if (event?.eventType == EventType.GO_TO) {
-            if (event?.extraLong and CalendarController.EXTRA_GOTO_BACK_TO_PREVIOUS != 0L) {
+            if (event.extraLong and CalendarController.EXTRA_GOTO_BACK_TO_PREVIOUS != 0L) {
                 mBackToPreviousView = true
-            } else if (event?.viewType != mController?.previousViewType &&
-                event?.viewType != ViewType.EDIT
+            } else if (event.viewType != mController?.previousViewType &&
+                event.viewType != ViewType.EDIT
             ) {
                 // Clear the flag is change to a different view type
                 mBackToPreviousView = false
             }
             setMainPane(
-                null, R.id.main_pane, event?.viewType, event?.startTime?.toMillis(false)
+                null, R.id.main_pane, event.viewType, event.startTime?.toMillis(false)
                     as Long, false
             )
             if (mShowCalendarControls) {
                 val animationSize =
                     if (mOrientation == Configuration.ORIENTATION_LANDSCAPE) mControlsAnimateWidth
                     else mControlsAnimateHeight
-                val noControlsView = event?.viewType == ViewType.MONTH
+                val noControlsView = event.viewType == ViewType.MONTH
                 if (mControlsMenu != null) {
                     mControlsMenu?.setVisible(!noControlsView)
                     mControlsMenu?.setEnabled(!noControlsView)
@@ -965,8 +964,8 @@
                 }
             }
             displayTime =
-                if (event?.selectedTime != null) event?.selectedTime?.toMillis(true) as Long
-                else event?.startTime?.toMillis(true) as Long
+                if (event.selectedTime != null) event.selectedTime?.toMillis(true) as Long
+                else event.startTime?.toMillis(true) as Long
             if (!mIsTabletConfig) {
                 mActionBarMenuSpinnerAdapter?.setTime(displayTime)
             }
@@ -1062,4 +1061,4 @@
         private var mIsMultipane = false
         private var mIsTabletConfig = false
     }
-}
\ No newline at end of file
+}
diff --git a/src/com/android/calendar/CalendarController.kt b/src/com/android/calendar/CalendarController.kt
index 16ee8fd..41984bf 100644
--- a/src/com/android/calendar/CalendarController.kt
+++ b/src/com/android/calendar/CalendarController.kt
@@ -440,7 +440,7 @@
 
         // Set mTime if selectedTime is set
         val temp1 = event.selectedTime
-        if (temp1 != null && temp1?.toMillis(false) != 0L) {
+        if (temp1 != null && temp1.toMillis(false) != 0L) {
             mTime?.set(event.selectedTime)
         } else {
             if (startMillis != 0L) {
@@ -450,7 +450,7 @@
                 val temp2 = event.endTime
                 if (mtimeMillis < startMillis ||
                         temp2 != null && mtimeMillis > temp2.toMillis(false)) {
-                    mTime?.set(event.startTime)
+                    mTime.set(event.startTime)
                 }
             }
             event.selectedTime = mTime
diff --git a/src/com/android/calendar/CalendarViewAdapter.kt b/src/com/android/calendar/CalendarViewAdapter.kt
index 2fe1027..44590b8 100644
--- a/src/com/android/calendar/CalendarViewAdapter.kt
+++ b/src/com/android/calendar/CalendarViewAdapter.kt
@@ -133,7 +133,7 @@
                 v = convertView
             }
             val weekDay: TextView = v?.findViewById(R.id.top_button_weekday) as TextView
-            val date: TextView = v?.findViewById(R.id.top_button_date) as TextView
+            val date: TextView = v.findViewById(R.id.top_button_date) as TextView
             when (mCurrentMainView) {
                 ViewType.DAY -> {
                     weekDay.setVisibility(View.VISIBLE)
diff --git a/src/com/android/calendar/DayFragment.kt b/src/com/android/calendar/DayFragment.kt
index 39e92f5..36413cd 100644
--- a/src/com/android/calendar/DayFragment.kt
+++ b/src/com/android/calendar/DayFragment.kt
@@ -154,7 +154,7 @@
         val diff: Int = currentView?.compareToVisibleTimeRange(goToTime as Time) as Int
         if (diff == 0) {
             // In visible range. No need to switch view
-            currentView?.setSelected(goToTime, ignoreTime, animateToday)
+            currentView.setSelected(goToTime, ignoreTime, animateToday)
         } else {
             // Figure out which way to animate
             if (diff > 0) {
@@ -214,8 +214,8 @@
 // TODO support a range of time
 // TODO support event_id
 // TODO support select message
-            goTo(msg?.selectedTime, msg?.extraLong and CalendarController.EXTRA_GOTO_DATE != 0L,
-                    msg?.extraLong and CalendarController.EXTRA_GOTO_TODAY != 0L)
+            goTo(msg.selectedTime, msg.extraLong and CalendarController.EXTRA_GOTO_DATE != 0L,
+                    msg.extraLong and CalendarController.EXTRA_GOTO_TODAY != 0L)
         } else if (msg?.eventType == CalendarController.EventType.EVENTS_CHANGED) {
             eventsChanged()
         }
diff --git a/src/com/android/calendar/DayView.kt b/src/com/android/calendar/DayView.kt
index 4262163..d5f4f48 100644
--- a/src/com/android/calendar/DayView.kt
+++ b/src/com/android/calendar/DayView.kt
@@ -150,7 +150,7 @@
         @Override
         override fun run() {
             if (mClickedEvent != null) {
-                mController?.sendEventRelatedEvent(
+                mController.sendEventRelatedEvent(
                     this as Object?, EventType.VIEW_EVENT, mClickedEvent!!.id,
                     mClickedEvent!!.startMillis, mClickedEvent!!.endMillis,
                     this@DayView.getWidth() / 2, mClickedYLocation,
@@ -835,8 +835,8 @@
             if (diff < 0) {
                 diff += 7
             }
-            time!!.monthDay -= diff
-            time?.normalize(true /* ignore isDst */)
+            time.monthDay -= diff
+            time.normalize(true /* ignore isDst */)
         }
     }
 
@@ -1135,7 +1135,7 @@
         b.append(PERIOD_SPACE)
         val `when`: String?
         var flags: Int = DateUtils.FORMAT_SHOW_DATE
-        if (calEvent!!.allDay) {
+        if (calEvent.allDay) {
             flags = flags or (DateUtils.FORMAT_UTC or DateUtils.FORMAT_SHOW_WEEKDAY)
         } else {
             flags = flags or DateUtils.FORMAT_SHOW_TIME
@@ -1143,7 +1143,7 @@
                 flags = flags or DateUtils.FORMAT_24HOUR
             }
         }
-        `when` = Utils.formatDateRange(mContext, calEvent!!.startMillis, calEvent!!.endMillis,
+        `when` = Utils.formatDateRange(mContext, calEvent.startMillis, calEvent.endMillis,
             flags)
         b.append(`when`)
         b.append(PERIOD_SPACE)
@@ -2058,7 +2058,7 @@
         if (i < 0 || i >= layouts!!.size) {
             return null
         }
-        var layout: StaticLayout? = layouts!![i]
+        var layout: StaticLayout? = layouts[i]
         // Check if we have already initialized the StaticLayout and that
         // the width hasn't changed (due to vertical resizing which causes
         // re-layout of events at min height)
@@ -2117,16 +2117,16 @@
         x = mHoursWidth.toFloat()
         p.setStrokeWidth(GRID_LINE_INNER_WIDTH)
         // Line bounding the top of the all day area
-        mLines!![linesIndex++] = GRID_LINE_LEFT_MARGIN
-        mLines!![linesIndex++] = startY
-        mLines!![linesIndex++] = computeDayLeftPosition(mNumDays).toFloat()
-        mLines!![linesIndex++] = startY
+        mLines[linesIndex++] = GRID_LINE_LEFT_MARGIN
+        mLines[linesIndex++] = startY
+        mLines[linesIndex++] = computeDayLeftPosition(mNumDays).toFloat()
+        mLines[linesIndex++] = startY
         for (day in 0..mNumDays) {
             x = computeDayLeftPosition(day).toFloat()
-            mLines!![linesIndex++] = x
-            mLines!![linesIndex++] = startY
-            mLines!![linesIndex++] = x
-            mLines!![linesIndex++] = stopY
+            mLines[linesIndex++] = x
+            mLines[linesIndex++] = startY
+            mLines[linesIndex++] = x
+            mLines[linesIndex++] = stopY
         }
         p.setAntiAlias(false)
         canvas.drawLines(mLines, 0, linesIndex, p)
@@ -2160,7 +2160,7 @@
         var alpha: Int = eventTextPaint.getAlpha()
         eventTextPaint.setAlpha(mEventsAlpha)
         for (i in 0 until numEvents) {
-            val event: Event = events!!.get(i)
+            val event: Event = events.get(i)
             var startDay: Int = event.startDay
             var endDay: Int = event.endDay
             if (startDay > lastDay || endDay < firstDay) {
@@ -2796,7 +2796,7 @@
         performLongClick()
     }
 
-    private fun doScroll(e1: MotionEvent, e2: MotionEvent, deltaX: Float, deltaY: Float) {
+    private fun doScroll(e1: MotionEvent?, e2: MotionEvent, deltaX: Float, deltaY: Float) {
         cancelAnimation()
         if (mStartingScroll) {
             mInitialScrollX = 0f
@@ -2897,19 +2897,19 @@
     }
 
     private fun cancelAnimation() {
-        val `in`: Animation? = mViewSwitcher?.getInAnimation()
+        val `in`: Animation? = mViewSwitcher.getInAnimation()
         if (`in` != null) {
             // cancel() doesn't terminate cleanly.
-            `in`?.scaleCurrentDuration(0f)
+            `in`.scaleCurrentDuration(0f)
         }
-        val out: Animation? = mViewSwitcher?.getOutAnimation()
+        val out: Animation? = mViewSwitcher.getOutAnimation()
         if (out != null) {
             // cancel() doesn't terminate cleanly.
-            out?.scaleCurrentDuration(0f)
+            out.scaleCurrentDuration(0f)
         }
     }
 
-    private fun doFling(e1: MotionEvent, e2: MotionEvent, velocityX: Float, velocityY: Float) {
+    private fun doFling(e1: MotionEvent?, e2: MotionEvent, velocityX: Float, velocityY: Float) {
         cancelAnimation()
         mSelectionMode = SELECTION_HIDDEN
         eventClickCleanup()
@@ -2919,7 +2919,7 @@
             // initNextView(deltaX);
             mTouchMode = TOUCH_MODE_INITIAL_STATE
             if (DEBUG) Log.d(TAG, "doFling: velocityX $velocityX")
-            val deltaX = e2.getX().toInt() - e1.getX().toInt()
+            val deltaX = e2.getX().toInt() - e1!!.getX().toInt()
             switchViews(deltaX < 0, mViewStartX.toFloat(), mViewWidth.toFloat(), velocityX)
             mViewStartX = 0
             return
@@ -3276,14 +3276,14 @@
             events = mAllDayEvents
             numEvents = events!!.size
             for (i in 0 until numEvents) {
-                val event: Event? = events?.get(i)
+                val event: Event? = events.get(i)
                 if (!event!!.drawAsAllday() ||
-                    !mShowAllAllDayEvents && event!!.getColumn() >= maxUnexpandedColumn
+                    !mShowAllAllDayEvents && event.getColumn() >= maxUnexpandedColumn
                 ) {
                     // Don't check non-allday events or events that aren't shown
                     continue
                 }
-                if (event!!.startDay <= mSelectionDay && event!!.endDay >= mSelectionDay) {
+                if (event.startDay <= mSelectionDay && event.endDay >= mSelectionDay) {
                     val numRectangles =
                         if (mShowAllAllDayEvents) mMaxAlldayEvents.toFloat()
                         else mMaxUnexpandedAlldayEventCount.toFloat()
@@ -3291,7 +3291,7 @@
                     if (height > MAX_HEIGHT_OF_ONE_ALLDAY_EVENT) {
                         height = MAX_HEIGHT_OF_ONE_ALLDAY_EVENT.toFloat()
                     }
-                    val eventTop: Float = yOffset + height * event?.getColumn()
+                    val eventTop: Float = yOffset + height * event.getColumn()
                     val eventBottom = eventTop + height
                     if (eventTop < y && eventBottom > y) {
                         // If the touch is inside the event rectangle, then
@@ -3328,7 +3328,7 @@
         region.bottom = y + 10
         val geometry: EventGeometry = mEventGeometry
         for (i in 0 until numEvents) {
-            val event: Event? = events?.get(i)
+            val event: Event? = events.get(i)
             // Compute the event rectangle.
             if (!geometry.computeEventRect(date, left, top, cellWidth, event as Event)) {
                 continue
@@ -3348,7 +3348,7 @@
             var closestEvent: Event? = null
             var minDist = (mViewWidth + mViewHeight).toFloat() // some large distance
             for (index in 0 until len) {
-                val ev: Event? = mSelectedEvents?.get(index)
+                val ev: Event? = mSelectedEvents.get(index)
                 val dist: Float = geometry.pointToEvent(x.toFloat(), y.toFloat(), ev as Event)
                 if (dist < minDist) {
                     minDist = dist
@@ -3526,7 +3526,7 @@
 
         @Override
         override fun onScroll(
-            e1: MotionEvent,
+            e1: MotionEvent?,
             e2: MotionEvent,
             distanceX: Float,
             distanceY: Float
@@ -3550,7 +3550,7 @@
 
         @Override
         override fun onFling(
-            e1: MotionEvent,
+            e1: MotionEvent?,
             e2: MotionEvent,
             velocityX: Float,
             velocityY: Float
@@ -3987,4 +3987,4 @@
         OVERFLING_DISTANCE = vc.getScaledOverflingDistance()
         init(context as Context)
     }
-}
\ No newline at end of file
+}
diff --git a/src/com/android/calendar/EventInfoFragment.kt b/src/com/android/calendar/EventInfoFragment.kt
index fcc27fc..139da7b 100644
--- a/src/com/android/calendar/EventInfoFragment.kt
+++ b/src/com/android/calendar/EventInfoFragment.kt
@@ -353,20 +353,20 @@
         window?.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND)
         val a: WindowManager.LayoutParams? = window?.getAttributes()
         a!!.dimAmount = .4f
-        a!!.width = mDialogWidth
-        a!!.height = mDialogHeight
+        a.width = mDialogWidth
+        a.height = mDialogHeight
 
         // On tablets , do smart positioning of dialog
         // On phones , use the whole screen
         if (mX != -1 || mY != -1) {
-            a!!.x = mX - mDialogWidth / 2
-            a!!.y = mY - mDialogHeight / 2
-            if (a!!.y < mMinTop) {
-                a!!.y = mMinTop + DIALOG_TOP_MARGIN
+            a.x = mX - mDialogWidth / 2
+            a.y = mY - mDialogHeight / 2
+            if (a.y < mMinTop) {
+                a.y = mMinTop + DIALOG_TOP_MARGIN
             }
-            a!!.gravity = Gravity.LEFT or Gravity.TOP
+            a.gravity = Gravity.LEFT or Gravity.TOP
         }
-        window?.setAttributes(a)
+        window.setAttributes(a)
     }
 
     fun setDialogParams(x: Int, y: Int, minTop: Int) {
@@ -637,7 +637,7 @@
                 resources.getColor(R.color.event_info_headline_transparent_color)
             )
             sb.setSpan(
-                transparentColorSpan, timezoneIndex, displayedDatetime!!.length,
+                transparentColorSpan, timezoneIndex, displayedDatetime.length,
                 Spannable.SPAN_INCLUSIVE_INCLUSIVE
             )
             setTextCommon(view, R.id.when_datetime, sb)
@@ -681,7 +681,7 @@
         if (mResponseRadioGroup?.getVisibility() == View.VISIBLE) {
             val id: Int = mResponseRadioGroup!!.getCheckedRadioButtonId()
             if (id != View.NO_ID) {
-                text.add((getView()?.findViewById(R.id.response_label) as TextView)?.getText())
+                text.add((getView()?.findViewById(R.id.response_label) as TextView).getText())
                 text.add(
                     (mResponseRadioGroup?.findViewById(id) as RadioButton)
                         .getText().toString() + PERIOD_SPACE
diff --git a/src/com/android/calendar/EventLoader.kt b/src/com/android/calendar/EventLoader.kt
index a05e8a2..4795773 100644
--- a/src/com/android/calendar/EventLoader.kt
+++ b/src/com/android/calendar/EventLoader.kt
@@ -128,7 +128,7 @@
 
             // Check if we are still the most recent request.
             if (id == eventLoader?.mSequenceNumber?.get()) {
-                eventLoader?.mHandler?.post(successCallback)
+                eventLoader.mHandler.post(successCallback)
             } else {
                 eventLoader?.mHandler?.post(cancelCallback)
             }
diff --git a/src/com/android/calendar/GeneralPreferences.kt b/src/com/android/calendar/GeneralPreferences.kt
index dd4c955..4044ef1 100644
--- a/src/com/android/calendar/GeneralPreferences.kt
+++ b/src/com/android/calendar/GeneralPreferences.kt
@@ -172,7 +172,7 @@
     }
 
     @Override
-    override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String) {
+    override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String?) {
         val a: Activity = getActivity()
         if (key.equals(KEY_ALERTS)) {
             updateChildPreferences()
@@ -248,8 +248,8 @@
         mVibrate?.setChecked(Utils.getDefaultVibrate(getActivity(), prefs))
 
         // If needed, migrate the old alerts type settin
-        if (prefs?.contains(KEY_ALERTS) == false && prefs?.contains(KEY_ALERTS_TYPE) == true) {
-            val type: String? = prefs?.getString(KEY_ALERTS_TYPE, ALERT_TYPE_STATUS_BAR)
+        if (prefs?.contains(KEY_ALERTS) == false && prefs.contains(KEY_ALERTS_TYPE) == true) {
+            val type: String? = prefs.getString(KEY_ALERTS_TYPE, ALERT_TYPE_STATUS_BAR)
             if (type.equals(ALERT_TYPE_OFF)) {
                 mAlert?.setChecked(false)
                 mPopup?.setChecked(false)
@@ -264,7 +264,7 @@
                 mPopup?.setEnabled(true)
             }
             // clear out the old setting
-            prefs?.edit().remove(KEY_ALERTS_TYPE).commit()
+            prefs.edit().remove(KEY_ALERTS_TYPE).commit()
         }
     }
 
diff --git a/src/com/android/calendar/Utils.kt b/src/com/android/calendar/Utils.kt
index ef78048..52af887 100644
--- a/src/com/android/calendar/Utils.kt
+++ b/src/com/android/calendar/Utils.kt
@@ -186,13 +186,13 @@
             return ViewType.EDIT
         }
         if (extras != null) {
-            if (extras?.getBoolean(INTENT_KEY_DETAIL_VIEW, false)) {
+            if (extras.getBoolean(INTENT_KEY_DETAIL_VIEW, false)) {
                 // This is the "detail" view which is either agenda or day view
                 return prefs?.getInt(
                     GeneralPreferences.KEY_DETAILED_VIEW,
                     GeneralPreferences.DEFAULT_DETAILED_VIEW
                 ) as Int
-            } else if (INTENT_VALUE_VIEW_TYPE_DAY.equals(extras?.getString(INTENT_KEY_VIEW_TYPE))) {
+            } else if (INTENT_VALUE_VIEW_TYPE_DAY.equals(extras.getString(INTENT_KEY_VIEW_TYPE))) {
                 // Not sure who uses this. This logic came from LaunchActivity
                 return ViewType.DAY
             }
@@ -275,12 +275,12 @@
             //
             // silent and never -> off
             // always -> on
-            val vibrateWhen: String? = prefs?.getString(KEY_ALERTS_VIBRATE_WHEN, null)
+            val vibrateWhen: String? = prefs.getString(KEY_ALERTS_VIBRATE_WHEN, null)
             vibrate = vibrateWhen != null && vibrateWhen.equals(
                 context
                     .getString(R.string.prefDefault_alerts_vibrate_true)
             )
-            prefs?.edit().remove(KEY_ALERTS_VIBRATE_WHEN).commit()
+            prefs.edit().remove(KEY_ALERTS_VIBRATE_WHEN).commit()
             Log.d(
                 TAG, "Migrating KEY_ALERTS_VIBRATE_WHEN(" +
                     vibrateWhen + ") to KEY_ALERTS_VIBRATE = " + vibrate
@@ -302,8 +302,8 @@
         val prefs: SharedPreferences? = GeneralPreferences.getSharedPreferences(context)
         val ss = prefs?.getStringSet(key, null)
         if (ss != null) {
-            val strings = arrayOfNulls<String>(ss?.size)
-            return ss?.toTypedArray()
+            val strings = arrayOfNulls<String>(ss.size)
+            return ss.toTypedArray()
         }
         return defaultValue
     }
@@ -463,11 +463,11 @@
         // time.
         val data: Uri? = intent?.getData()
         var millis: Long? = intent?.getLongExtra(EXTRA_EVENT_BEGIN_TIME, -1)?.toLong()
-        if (millis == -1L && data != null && data?.isHierarchical()) {
-            val path: List<String> = data?.getPathSegments() as List<String>
+        if (millis == -1L && data != null && data.isHierarchical()) {
+            val path: List<String> = data.getPathSegments() as List<String>
             if (path.size == 2 && path[0].equals("time")) {
                 try {
-                    millis = (data?.getLastPathSegment()?.toLong())
+                    millis = (data.getLastPathSegment()?.toLong())
                 } catch (e: NumberFormatException) {
                     Log.i(
                         "Calendar", "timeFromIntentInMillis: Data existed but no valid time " +
@@ -818,8 +818,8 @@
             }
             val res: Resources? = context?.getResources()
             CONFLICT_COLOR = res?.getColor(R.color.month_dna_conflict_time_color) as Int
-            WORK_DAY_START_MINUTES = res?.getInteger(R.integer.work_start_minutes) as Int
-            WORK_DAY_END_MINUTES = res?.getInteger(R.integer.work_end_minutes) as Int
+            WORK_DAY_START_MINUTES = res.getInteger(R.integer.work_start_minutes) as Int
+            WORK_DAY_END_MINUTES = res.getInteger(R.integer.work_end_minutes) as Int
             WORK_DAY_END_LENGTH = DAY_IN_MINUTES - WORK_DAY_END_MINUTES
             WORK_DAY_MINUTES = WORK_DAY_END_MINUTES - WORK_DAY_START_MINUTES
             mMinutesLoaded = true
@@ -1085,7 +1085,7 @@
         val strandIterator = strands.values.iterator()
         while (strandIterator.hasNext()) {
             val strand = strandIterator.next()
-            if (strand?.count < 1 && strand.allDays == null) {
+            if (strand.count < 1 && strand.allDays == null) {
                 strandIterator.remove()
                 continue
             }
@@ -1115,17 +1115,17 @@
                         " for " + dayStartMinute.toString() + " " + dayEndMinute
                 )
             }
-            strand?.points!![strand?.position] = x.toFloat()
-            strand?.position = strand?.position?.inc() as Int
+            strand?.points!![strand.position] = x.toFloat()
+            strand.position = strand.position.inc() as Int
 
-            strand?.points!![strand?.position] = y0.toFloat()
-            strand?.position = strand?.position?.inc() as Int
+            strand.points!![strand.position] = y0.toFloat()
+            strand.position = strand.position.inc() as Int
 
-            strand?.points!![strand?.position] = x.toFloat()
-            strand?.position = strand?.position.inc() as Int
+            strand.points!![strand.position] = x.toFloat()
+            strand.position = strand.position.inc() as Int
 
-            strand?.points!![strand?.position] = y1.toFloat()
-            strand?.position = strand?.position.inc() as Int
+            strand.points!![strand.position] = y1.toFloat()
+            strand.position = strand.position.inc() as Int
         }
     }
 
@@ -1221,9 +1221,9 @@
         var strand: DNAStrand? = strands.get(color)
         if (strand == null) {
             strand = DNAStrand()
-            strand?.color = color
-            strand?.count = 0
-            strands?.put(strand?.color, strand)
+            strand.color = color
+            strand.count = 0
+            strands.put(strand.color, strand)
         }
         return strand
     }
diff --git a/src/com/android/calendar/alerts/AlertUtils.kt b/src/com/android/calendar/alerts/AlertUtils.kt
index 18b7e7d..21b2be0 100644
--- a/src/com/android/calendar/alerts/AlertUtils.kt
+++ b/src/com/android/calendar/alerts/AlertUtils.kt
@@ -53,9 +53,9 @@
         return object : AlarmManagerInterface {
             override operator fun set(type: Int, triggerAtMillis: Long, operation: PendingIntent?) {
                 if (com.android.calendar.Utils.isKeyLimePieOrLater()) {
-                    mgr.setExact(type, triggerAtMillis, operation)
+                    mgr.setExact(type, triggerAtMillis, operation!!)
                 } else {
-                    mgr.set(type, triggerAtMillis, operation)
+                    mgr.set(type, triggerAtMillis, operation!!)
                 }
             }
         }
diff --git a/src/com/android/calendar/alerts/DismissAlarmsService.kt b/src/com/android/calendar/alerts/DismissAlarmsService.kt
index 88683d3..f18cb0b 100644
--- a/src/com/android/calendar/alerts/DismissAlarmsService.kt
+++ b/src/com/android/calendar/alerts/DismissAlarmsService.kt
@@ -84,7 +84,7 @@
                 getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
             nm.cancel(notificationId as Int)
         }
-        if (SHOW_ACTION.equals(intent?.getAction())) {
+        if (SHOW_ACTION.equals(intent.getAction())) {
             // Show event on Calendar app by building an intent and task stack to start
             // EventInfoActivity with AllInOneActivity as the parent activity rooted to home.
             val i: Intent = AlertUtils.buildEventViewIntent(this, eventId as Long,
diff --git a/src/com/android/calendar/alerts/QuickResponseActivity.kt b/src/com/android/calendar/alerts/QuickResponseActivity.kt
index afccaff..cbe8636 100644
--- a/src/com/android/calendar/alerts/QuickResponseActivity.kt
+++ b/src/com/android/calendar/alerts/QuickResponseActivity.kt
@@ -43,7 +43,7 @@
             finish()
             return
         }
-        mEventId = intent?.getLongExtra(EXTRA_EVENT_ID, -1) as Long
+        mEventId = intent.getLongExtra(EXTRA_EVENT_ID, -1) as Long
         if (mEventId == -1L) {
             finish()
             return
diff --git a/src/com/android/calendar/month/MonthByWeekAdapter.kt b/src/com/android/calendar/month/MonthByWeekAdapter.kt
index c67b356..90daa97 100644
--- a/src/com/android/calendar/month/MonthByWeekAdapter.kt
+++ b/src/com/android/calendar/month/MonthByWeekAdapter.kt
@@ -262,7 +262,7 @@
         if (v !is MonthWeekEventsView) {
             return super.onTouch(v, event)
         }
-        val action: Int = event!!.getAction()
+        val action: Int = event.getAction()
 
         // Event was tapped - switch to the detailed view making sure the click animation
         // is done first.
@@ -330,7 +330,7 @@
     // Clear the visual cues of the click animation and related running code.
     private fun clearClickedView(v: MonthWeekEventsView?) {
         mListView?.removeCallbacks(mDoClick)
-        synchronized(v as Any) { v?.clearClickedDay() }
+        synchronized(v as Any) { v.clearClickedDay() }
         mClickedView = null
     }
 
diff --git a/src/com/android/calendar/month/MonthByWeekFragment.kt b/src/com/android/calendar/month/MonthByWeekFragment.kt
index 9fe9fe4..b6882b7 100644
--- a/src/com/android/calendar/month/MonthByWeekFragment.kt
+++ b/src/com/android/calendar/month/MonthByWeekFragment.kt
@@ -131,7 +131,7 @@
     private fun updateUri(): Uri {
         val child: SimpleWeekView? = mListView?.getChildAt(0) as? SimpleWeekView
         if (child != null) {
-            val julianDay: Int = child?.getFirstJulianDay()
+            val julianDay: Int = child.getFirstJulianDay()
             mFirstLoadedJulianDay = julianDay
         }
         // -1 to ensure we get all day events from any time zone
@@ -156,8 +156,8 @@
         if (size <= 2) {
             return
         }
-        val first: Long = (pathSegments!![size - 2])?.toLong() as Long
-        val last: Long = (pathSegments!![size - 1])?.toLong() as Long
+        val first: Long = (pathSegments[size - 2])?.toLong() as Long
+        val last: Long = (pathSegments[size - 1])?.toLong() as Long
         mTempTime.set(first)
         mFirstLoadedJulianDay = Time.getJulianDay(first, mTempTime.gmtoff)
         mTempTime.set(last)
@@ -222,11 +222,11 @@
         mFirstDayOfWeek = Utils.getFirstDayOfWeek(mContext)
         mShowWeekNumber = Utils.getShowWeekNumber(mContext)
         val weekParams = HashMap<String?, Int?>()
-        weekParams?.put(SimpleWeeksAdapter.WEEK_PARAMS_NUM_WEEKS, mNumWeeks)
-        weekParams?.put(SimpleWeeksAdapter.WEEK_PARAMS_SHOW_WEEK, if (mShowWeekNumber) 1 else 0)
-        weekParams?.put(SimpleWeeksAdapter.WEEK_PARAMS_WEEK_START, mFirstDayOfWeek)
-        weekParams?.put(MonthByWeekAdapter.WEEK_PARAMS_IS_MINI, if (mIsMiniMonth) 1 else 0)
-        weekParams?.put(
+        weekParams.put(SimpleWeeksAdapter.WEEK_PARAMS_NUM_WEEKS, mNumWeeks)
+        weekParams.put(SimpleWeeksAdapter.WEEK_PARAMS_SHOW_WEEK, if (mShowWeekNumber) 1 else 0)
+        weekParams.put(SimpleWeeksAdapter.WEEK_PARAMS_WEEK_START, mFirstDayOfWeek)
+        weekParams.put(MonthByWeekAdapter.WEEK_PARAMS_IS_MINI, if (mIsMiniMonth) 1 else 0)
+        weekParams.put(
                 SimpleWeeksAdapter.WEEK_PARAMS_JULIAN_DAY,
                 Time.getJulianDay(mSelectedDay.toMillis(true), mSelectedDay.gmtoff)
         )
@@ -383,21 +383,21 @@
         if (event?.eventType === EventType.GO_TO) {
             var animate = true
             if (mDaysPerWeek * mNumWeeks * 2 < Math.abs(
-                            Time.getJulianDay(event?.selectedTime?.toMillis(true) as Long,
-                                    event?.selectedTime?.gmtoff as Long) -
-                                    Time.getJulianDay(mFirstVisibleDay?.toMillis(true) as Long,
-                                            mFirstVisibleDay?.gmtoff as Long) -
+                            Time.getJulianDay(event.selectedTime?.toMillis(true) as Long,
+                                    event.selectedTime?.gmtoff as Long) -
+                                    Time.getJulianDay(mFirstVisibleDay.toMillis(true) as Long,
+                                            mFirstVisibleDay.gmtoff as Long) -
                                     mDaysPerWeek * mNumWeeks / 2L
                     )
             ) {
                 animate = false
             }
-            mDesiredDay.set(event?.selectedTime)
+            mDesiredDay.set(event.selectedTime)
             mDesiredDay.normalize(true)
-            val animateToday = event?.extraLong and
+            val animateToday = event.extraLong and
                     CalendarController.EXTRA_GOTO_TODAY.toLong() != 0L
             val delayAnimation: Boolean =
-                    goTo(event?.selectedTime?.toMillis(true)?.toLong() as Long,
+                    goTo(event.selectedTime?.toMillis(true)?.toLong() as Long,
                         animate, true, false)
             if (animateToday) {
                 // If we need to flash today start the animation after any
diff --git a/src/com/android/calendar/month/MonthWeekEventsView.kt b/src/com/android/calendar/month/MonthWeekEventsView.kt
index e4b1549..b8cdbb6 100644
--- a/src/com/android/calendar/month/MonthWeekEventsView.kt
+++ b/src/com/android/calendar/month/MonthWeekEventsView.kt
@@ -215,7 +215,7 @@
                 effectiveWidth -= SPACING_WEEK_NUMBER
             }
             DNA_ALL_DAY_WIDTH = effectiveWidth / numDays - 2 * DNA_SIDE_PADDING
-            mDNAAllDayPaint?.setStrokeWidth(DNA_ALL_DAY_WIDTH.toFloat())
+            mDNAAllDayPaint.setStrokeWidth(DNA_ALL_DAY_WIDTH.toFloat())
             mDayXs = IntArray(numDays)
             for (day in 0 until numDays) {
                 mDayXs!![day] = computeDayLeftPosition(day) + DNA_WIDTH / 2 + DNA_SIDE_PADDING
@@ -322,20 +322,20 @@
         loadColors(getContext())
         // TODO modify paint properties depending on isMini
         mMonthNumPaint = Paint()
-        mMonthNumPaint?.setFakeBoldText(false)
-        mMonthNumPaint?.setAntiAlias(true)
-        mMonthNumPaint?.setTextSize(TEXT_SIZE_MONTH_NUMBER.toFloat())
-        mMonthNumPaint?.setColor(mMonthNumColor)
-        mMonthNumPaint?.setStyle(Style.FILL)
-        mMonthNumPaint?.setTextAlign(Align.RIGHT)
-        mMonthNumPaint?.setTypeface(Typeface.DEFAULT)
-        mMonthNumAscentHeight = (-mMonthNumPaint!!.ascent() + 0.5f).toInt()
-        mMonthNumHeight = (mMonthNumPaint!!.descent() - mMonthNumPaint!!.ascent() + 0.5f).toInt()
+        mMonthNumPaint.setFakeBoldText(false)
+        mMonthNumPaint.setAntiAlias(true)
+        mMonthNumPaint.setTextSize(TEXT_SIZE_MONTH_NUMBER.toFloat())
+        mMonthNumPaint.setColor(mMonthNumColor)
+        mMonthNumPaint.setStyle(Style.FILL)
+        mMonthNumPaint.setTextAlign(Align.RIGHT)
+        mMonthNumPaint.setTypeface(Typeface.DEFAULT)
+        mMonthNumAscentHeight = (-mMonthNumPaint.ascent() + 0.5f).toInt()
+        mMonthNumHeight = (mMonthNumPaint.descent() - mMonthNumPaint.ascent() + 0.5f).toInt()
         mEventPaint = TextPaint()
-        mEventPaint?.setFakeBoldText(true)
-        mEventPaint?.setAntiAlias(true)
-        mEventPaint?.setTextSize(TEXT_SIZE_EVENT_TITLE.toFloat())
-        mEventPaint?.setColor(mMonthEventColor)
+        mEventPaint.setFakeBoldText(true)
+        mEventPaint.setAntiAlias(true)
+        mEventPaint.setTextSize(TEXT_SIZE_EVENT_TITLE.toFloat())
+        mEventPaint.setColor(mMonthEventColor)
         mSolidBackgroundEventPaint = TextPaint(mEventPaint)
         mSolidBackgroundEventPaint?.setColor(EVENT_TEXT_COLOR)
         mFramedEventPaint = TextPaint(mSolidBackgroundEventPaint)
@@ -347,13 +347,13 @@
         mEventAscentHeight = (-mEventPaint.ascent() + 0.5f).toInt()
         mEventHeight = (mEventPaint.descent() - mEventPaint.ascent() + 0.5f).toInt()
         mEventExtrasPaint = TextPaint()
-        mEventExtrasPaint?.setFakeBoldText(false)
-        mEventExtrasPaint?.setAntiAlias(true)
-        mEventExtrasPaint?.setStrokeWidth(EVENT_SQUARE_BORDER.toFloat())
-        mEventExtrasPaint?.setTextSize(TEXT_SIZE_EVENT.toFloat())
-        mEventExtrasPaint?.setColor(mMonthEventExtraColor)
-        mEventExtrasPaint?.setStyle(Style.FILL)
-        mEventExtrasPaint?.setTextAlign(Align.LEFT)
+        mEventExtrasPaint.setFakeBoldText(false)
+        mEventExtrasPaint.setAntiAlias(true)
+        mEventExtrasPaint.setStrokeWidth(EVENT_SQUARE_BORDER.toFloat())
+        mEventExtrasPaint.setTextSize(TEXT_SIZE_EVENT.toFloat())
+        mEventExtrasPaint.setColor(mMonthEventExtraColor)
+        mEventExtrasPaint.setStyle(Style.FILL)
+        mEventExtrasPaint.setTextAlign(Align.LEFT)
         mExtrasHeight = (mEventExtrasPaint.descent() - mEventExtrasPaint.ascent() + 0.5f).toInt()
         mExtrasAscentHeight = (-mEventExtrasPaint.ascent() + 0.5f).toInt()
         mExtrasDescent = (mEventExtrasPaint.descent() + 0.5f).toInt()
@@ -388,11 +388,11 @@
         mEventSquarePaint.setAntiAlias(false)
         if (DEBUG_LAYOUT) {
             Log.d("EXTRA", "mScale=$mScale")
-            Log.d("EXTRA", "mMonthNumPaint ascent=" + mMonthNumPaint?.ascent()
-                    ?.toString() + " descent=" + mMonthNumPaint?.descent()?.toString() +
+            Log.d("EXTRA", "mMonthNumPaint ascent=" + mMonthNumPaint.ascent()
+                    .toString() + " descent=" + mMonthNumPaint.descent().toString() +
                     " int height=" + mMonthNumHeight)
-            Log.d("EXTRA", "mEventPaint ascent=" + mEventPaint?.ascent()
-                    ?.toString() + " descent=" + mEventPaint.descent().toString() +
+            Log.d("EXTRA", "mEventPaint ascent=" + mEventPaint.ascent()
+                    .toString() + " descent=" + mEventPaint.descent().toString() +
                     " int height=" + mEventHeight
                     .toString() + " int ascent=" + mEventAscentHeight)
             Log.d("EXTRA", "mEventExtrasPaint ascent=" + mEventExtrasPaint.ascent()
@@ -544,15 +544,15 @@
             i++
             offset++
         }
-        if (!mOddMonth!!.get(i)) {
-            while (++i < mOddMonth!!.size && !mOddMonth!!.get(i));
+        if (!mOddMonth.get(i)) {
+            while (++i < mOddMonth.size && !mOddMonth.get(i));
             r.right = computeDayLeftPosition(i - offset)
             r.left = 0
             p.setColor(mMonthBGOtherColor)
             canvas.drawRect(r, p)
             // compute left edge for i, set up r, draw
-        } else if (!mOddMonth!!.get(mOddMonth!!.size - 1.also { i = it })) {
-            while (--i >= offset && !mOddMonth!!.get(i));
+        } else if (!mOddMonth.get(mOddMonth.size - 1.also { i = it })) {
+            while (--i >= offset && !mOddMonth.get(i));
             i++
             // compute left edge for i, set up r, draw
             r.right = mWidth
@@ -601,27 +601,27 @@
             offset++
         }
         y = mMonthNumAscentHeight + TOP_PADDING_MONTH_NUMBER
-        var isFocusMonth: Boolean = mFocusDay!!.get(i)
+        var isFocusMonth: Boolean = mFocusDay.get(i)
         var isBold = false
-        mMonthNumPaint?.setColor(if (isFocusMonth) mMonthNumColor else mMonthNumOtherColor)
+        mMonthNumPaint.setColor(if (isFocusMonth) mMonthNumColor else mMonthNumOtherColor)
         while (i < numCount) {
             if (mHasToday && todayIndex == i) {
-                mMonthNumPaint?.setColor(mMonthNumTodayColor)
-                mMonthNumPaint?.setFakeBoldText(true.also { isBold = it })
+                mMonthNumPaint.setColor(mMonthNumTodayColor)
+                mMonthNumPaint.setFakeBoldText(true.also { isBold = it })
                 if (i + 1 < numCount) {
                     // Make sure the color will be set back on the next
                     // iteration
-                    isFocusMonth = !mFocusDay!!.get(i + 1)
+                    isFocusMonth = !mFocusDay.get(i + 1)
                 }
-            } else if (mFocusDay?.get(i) !== isFocusMonth) {
-                isFocusMonth = mFocusDay!!.get(i)
-                mMonthNumPaint?.setColor(if (isFocusMonth) mMonthNumColor else mMonthNumOtherColor)
+            } else if (mFocusDay.get(i) !== isFocusMonth) {
+                isFocusMonth = mFocusDay.get(i)
+                mMonthNumPaint.setColor(if (isFocusMonth) mMonthNumColor else mMonthNumOtherColor)
             }
             x = computeDayLeftPosition(i - offset) - SIDE_PADDING_MONTH_NUMBER
             canvas.drawText(mDayNumbers!!.get(i) as String, x.toFloat(), y.toFloat(),
                     mMonthNumPaint as Paint)
             if (isBold) {
-                mMonthNumPaint?.setFakeBoldText(false.also { isBold = it })
+                mMonthNumPaint.setFakeBoldText(false.also { isBold = it })
             }
             i++
         }
@@ -857,7 +857,7 @@
         mEventExtrasPaint.setFakeBoldText(true)
         canvas.drawText(String.format(text, remainingEvents), x.toFloat(), y.toFloat(),
                 mEventExtrasPaint as Paint)
-        mEventExtrasPaint!!.setFakeBoldText(false)
+        mEventExtrasPaint.setFakeBoldText(false)
     }
 
     /**
@@ -875,13 +875,13 @@
                         (strand.points as FloatArray).size === 0) {
                     continue
                 }
-                mDNATimePaint!!.setColor(strand.color)
+                mDNATimePaint.setColor(strand.color)
                 canvas.drawLines(strand.points as FloatArray, mDNATimePaint as Paint)
             }
             // Draw black last to make sure it's on top
             val strand: Utils.DNAStrand? = mDna?.get(CONFLICT_COLOR)
-            if (strand != null && strand!!.points != null && strand!!.points?.size !== 0) {
-                mDNATimePaint!!.setColor(strand.color)
+            if (strand != null && strand.points != null && strand.points?.size !== 0) {
+                mDNATimePaint.setColor(strand.color)
                 canvas.drawLines(strand.points as FloatArray, mDNATimePaint as Paint)
             }
             if (mDayXs == null) {
@@ -889,12 +889,12 @@
             }
             val numDays = mDayXs!!.size
             val xOffset = (DNA_ALL_DAY_WIDTH - DNA_WIDTH) / 2
-            if (strand != null && strand!!.allDays != null && strand!!.allDays?.size === numDays) {
+            if (strand != null && strand.allDays != null && strand.allDays?.size === numDays) {
                 for (i in 0 until numDays) {
                     // this adds at most 7 draws. We could sort it by color and
                     // build an array instead but this is easier.
-                    if (strand!!.allDays?.get(i) !== 0) {
-                        mDNAAllDayPaint!!.setColor(strand!!.allDays!!.get(i))
+                    if (strand.allDays?.get(i) !== 0) {
+                        mDNAAllDayPaint.setColor(strand.allDays!!.get(i))
                         canvas.drawLine(mDayXs!![i].toFloat() + xOffset.toFloat(),
                                 DNA_MARGIN.toFloat(), mDayXs!![i].toFloat() + xOffset.toFloat(),
                                 DNA_MARGIN.toFloat() + DNA_ALL_DAY_HEIGHT.toFloat(),
@@ -966,7 +966,7 @@
             if (hover != null
                     && (mLastHoverTime == null || Time.compare(hover, mLastHoverTime) !== 0)) {
                 val millis: Long = hover.toMillis(true)
-                val date: String = Utils!!.formatDateRange(context, millis, millis,
+                val date: String = Utils.formatDateRange(context, millis, millis,
                         DateUtils.FORMAT_SHOW_DATE) as String
                 val accessEvent: AccessibilityEvent = AccessibilityEvent
                         .obtain(AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED)
@@ -980,7 +980,7 @@
                     for (e in events) {
                         text.add(e!!.titleAndLocation.toString() + ". ")
                         var flags: Int = DateUtils.FORMAT_SHOW_DATE or DateUtils.FORMAT_SHOW_YEAR
-                        if (!e!!.allDay) {
+                        if (!e.allDay) {
                             flags = flags or DateUtils.FORMAT_SHOW_TIME
                             if (DateFormat.is24HourFormat(context)) {
                                 flags = flags or DateUtils.FORMAT_24HOUR
@@ -988,7 +988,7 @@
                         } else {
                             flags = flags or DateUtils.FORMAT_UTC
                         }
-                        text.add(Utils.formatDateRange(context, e!!.startMillis, e!!.endMillis,
+                        text.add(Utils.formatDateRange(context, e.startMillis, e.endMillis,
                                 flags).toString() + ". ")
                     }
                 }
diff --git a/src/com/android/calendar/month/SimpleDayPickerFragment.kt b/src/com/android/calendar/month/SimpleDayPickerFragment.kt
index 01fcbac..c0bce5d 100644
--- a/src/com/android/calendar/month/SimpleDayPickerFragment.kt
+++ b/src/com/android/calendar/month/SimpleDayPickerFragment.kt
@@ -121,7 +121,7 @@
             midnight.second = 0
             midnight.monthDay++
             val millisToMidnight: Long = midnight.normalize(true) - currentMillis
-            mHandler?.postDelayed(this, millisToMidnight)
+            mHandler.postDelayed(this, millisToMidnight)
             if (mAdapter != null) {
                 mAdapter?.notifyDataSetChanged()
             }
@@ -133,7 +133,7 @@
         @Override
         override fun onChanged() {
             val day: Time? = mAdapter!!.getSelectedDay()
-            if (day!!.year !== mSelectedDay!!.year || day!!.yearDay !== mSelectedDay.yearDay) {
+            if (day!!.year !== mSelectedDay.year || day!!.yearDay !== mSelectedDay.yearDay) {
                 goTo(day!!.toMillis(true), true, true, false)
             }
         }
@@ -179,10 +179,10 @@
      */
     protected open fun setUpAdapter() {
         val weekParams = HashMap<String?, Int?>()
-        weekParams?.put(SimpleWeeksAdapter.WEEK_PARAMS_NUM_WEEKS, mNumWeeks)
-        weekParams?.put(SimpleWeeksAdapter.WEEK_PARAMS_SHOW_WEEK, if (mShowWeekNumber) 1 else 0)
-        weekParams?.put(SimpleWeeksAdapter.WEEK_PARAMS_WEEK_START, mFirstDayOfWeek)
-        weekParams?.put(SimpleWeeksAdapter.WEEK_PARAMS_JULIAN_DAY,
+        weekParams.put(SimpleWeeksAdapter.WEEK_PARAMS_NUM_WEEKS, mNumWeeks)
+        weekParams.put(SimpleWeeksAdapter.WEEK_PARAMS_SHOW_WEEK, if (mShowWeekNumber) 1 else 0)
+        weekParams.put(SimpleWeeksAdapter.WEEK_PARAMS_WEEK_START, mFirstDayOfWeek)
+        weekParams.put(SimpleWeeksAdapter.WEEK_PARAMS_JULIAN_DAY,
                 Time.getJulianDay(mSelectedDay.toMillis(false), mSelectedDay.gmtoff))
         if (mAdapter == null) {
             mAdapter = SimpleWeeksAdapter(getActivity(), weekParams)
@@ -482,7 +482,7 @@
         }
 
         // Figure out where we are
-        val offset = if (child?.getBottom() < WEEK_MIN_VISIBLE_HEIGHT) 1 else 0
+        val offset = if (child.getBottom() < WEEK_MIN_VISIBLE_HEIGHT) 1 else 0
         // Use some hysteresis for checking which month to highlight. This
         // causes the month to transition when two full weeks of a month are
         // visible.
@@ -494,9 +494,9 @@
         // Find out which month we're moving into
         val month: Int
         month = if (mIsScrollingUp) {
-            child?.getFirstMonth()
+            child.getFirstMonth()
         } else {
-            child?.getLastMonth()
+            child.getLastMonth()
         }
 
         // And how it relates to our current highlighted month
diff --git a/src/com/android/calendar/month/SimpleWeekView.kt b/src/com/android/calendar/month/SimpleWeekView.kt
index 4d1298d..cd8eb84 100644
--- a/src/com/android/calendar/month/SimpleWeekView.kt
+++ b/src/com/android/calendar/month/SimpleWeekView.kt
@@ -207,11 +207,11 @@
             if (time.monthDay === 1) {
                 firstMonth = time.month
             }
-            mOddMonth!![i] = time.month % 2 === 1
+            mOddMonth[i] = time.month % 2 === 1
             if (time.month === focusMonth) {
-                mFocusDay!![i] = true
+                mFocusDay[i] = true
             } else {
-                mFocusDay!![i] = false
+                mFocusDay[i] = false
             }
             if (time.year === today.year && time.yearDay === today.yearDay) {
                 mHasToday = true
@@ -241,12 +241,12 @@
         p.setTextSize(MINI_DAY_NUMBER_TEXT_SIZE.toFloat())
         p.setStyle(Style.FILL)
         mMonthNumPaint = Paint()
-        mMonthNumPaint?.setFakeBoldText(true)
-        mMonthNumPaint?.setAntiAlias(true)
-        mMonthNumPaint?.setTextSize(MINI_DAY_NUMBER_TEXT_SIZE.toFloat())
-        mMonthNumPaint?.setColor(mFocusMonthColor)
-        mMonthNumPaint?.setStyle(Style.FILL)
-        mMonthNumPaint?.setTextAlign(Align.CENTER)
+        mMonthNumPaint.setFakeBoldText(true)
+        mMonthNumPaint.setAntiAlias(true)
+        mMonthNumPaint.setTextSize(MINI_DAY_NUMBER_TEXT_SIZE.toFloat())
+        mMonthNumPaint.setColor(mFocusMonthColor)
+        mMonthNumPaint.setStyle(Style.FILL)
+        mMonthNumPaint.setTextAlign(Align.CENTER)
     }
 
     /**
@@ -359,24 +359,24 @@
             canvas.drawText(mDayNumbers!![0] as String, x.toFloat(), y.toFloat(), p)
             i++
         }
-        var isFocusMonth = mFocusDay!![i]
-        mMonthNumPaint?.setColor(if (isFocusMonth) mFocusMonthColor else mOtherMonthColor)
-        mMonthNumPaint?.setFakeBoldText(false)
+        var isFocusMonth = mFocusDay[i]
+        mMonthNumPaint.setColor(if (isFocusMonth) mFocusMonthColor else mOtherMonthColor)
+        mMonthNumPaint.setFakeBoldText(false)
         while (i < nDays) {
-            if (mFocusDay!![i] != isFocusMonth) {
-                isFocusMonth = mFocusDay!![i]
-                mMonthNumPaint?.setColor(if (isFocusMonth) mFocusMonthColor else mOtherMonthColor)
+            if (mFocusDay[i] != isFocusMonth) {
+                isFocusMonth = mFocusDay[i]
+                mMonthNumPaint.setColor(if (isFocusMonth) mFocusMonthColor else mOtherMonthColor)
             }
             if (mHasToday && mToday == i) {
-                mMonthNumPaint?.setTextSize(MINI_TODAY_NUMBER_TEXT_SIZE.toFloat())
-                mMonthNumPaint?.setFakeBoldText(true)
+                mMonthNumPaint.setTextSize(MINI_TODAY_NUMBER_TEXT_SIZE.toFloat())
+                mMonthNumPaint.setFakeBoldText(true)
             }
             val x = (2 * i + 1) * (mWidth - mPadding * 2) / divisor + mPadding
             canvas.drawText(mDayNumbers!![i] as String, x.toFloat(), y.toFloat(),
                     mMonthNumPaint as Paint)
             if (mHasToday && mToday == i) {
-                mMonthNumPaint?.setTextSize(MINI_DAY_NUMBER_TEXT_SIZE.toFloat())
-                mMonthNumPaint?.setFakeBoldText(false)
+                mMonthNumPaint.setTextSize(MINI_DAY_NUMBER_TEXT_SIZE.toFloat())
+                mMonthNumPaint.setFakeBoldText(false)
             }
             i++
         }
diff --git a/src/com/android/calendar/widget/CalendarAppWidgetProvider.kt b/src/com/android/calendar/widget/CalendarAppWidgetProvider.kt
index b3539f2..fcc5be3 100644
--- a/src/com/android/calendar/widget/CalendarAppWidgetProvider.kt
+++ b/src/com/android/calendar/widget/CalendarAppWidgetProvider.kt
@@ -63,7 +63,7 @@
             action.equals(Utils.getWidgetScheduledUpdateAction(context as Context)))
         ) {
             val service = Intent(context, CalendarAppWidgetService::class.java)
-            context?.startService(service)
+            context.startService(service)
         } else {
             super.onReceive(context, intent)
         }
diff --git a/src/com/android/calendar/widget/CalendarAppWidgetService.kt b/src/com/android/calendar/widget/CalendarAppWidgetService.kt
index 114fdf1..0d1018f 100644
--- a/src/com/android/calendar/widget/CalendarAppWidgetService.kt
+++ b/src/com/android/calendar/widget/CalendarAppWidgetService.kt
@@ -232,7 +232,7 @@
                 views.setOnClickFillInIntent(R.id.appwidget_loading, intent)
                 return views
             }
-            if (mModel!!.mEventInfos!!.isEmpty() || mModel!!.mRowInfos!!.isEmpty()) {
+            if (mModel!!.mEventInfos.isEmpty() || mModel!!.mRowInfos.isEmpty()) {
                 val views = RemoteViews(
                     mContext?.getPackageName(),
                     R.layout.appwidget_no_events
@@ -248,12 +248,12 @@
                 return views
             }
             val rowInfo: RowInfo? = mModel?.mRowInfos?.get(position)
-            return if (rowInfo!!.mType == RowInfo!!.TYPE_DAY) {
+            return if (rowInfo!!.mType == RowInfo.TYPE_DAY) {
                 val views = RemoteViews(
                     mContext?.getPackageName(),
                     R.layout.appwidget_day
                 )
-                val dayInfo: DayInfo? = mModel?.mDayInfos?.get(rowInfo!!.mIndex)
+                val dayInfo: DayInfo? = mModel?.mDayInfos?.get(rowInfo.mIndex)
                 updateTextView(views, R.id.date, View.VISIBLE, dayInfo!!.mDayLabel)
                 views
             } else {
@@ -267,92 +267,92 @@
                 } else {
                     views = RemoteViews(mContext?.getPackageName(), R.layout.widget_item)
                 }
-                val displayColor: Int = Utils.getDisplayColorFromColor(eventInfo!!.color)
+                val displayColor: Int = Utils.getDisplayColorFromColor(eventInfo.color)
                 val now: Long = System.currentTimeMillis()
-                if (!eventInfo!!.allDay && eventInfo!!.start <= now && now <= eventInfo!!.end) {
-                    views?.setInt(
+                if (!eventInfo.allDay && eventInfo.start <= now && now <= eventInfo.end) {
+                    views.setInt(
                         R.id.widget_row, "setBackgroundResource",
                         R.drawable.agenda_item_bg_secondary
                     )
                 } else {
-                    views?.setInt(
+                    views.setInt(
                         R.id.widget_row, "setBackgroundResource",
                         R.drawable.agenda_item_bg_primary
                     )
                 }
-                if (!eventInfo?.allDay) {
-                    updateTextView(views, R.id.`when`, eventInfo?.visibWhen
-                        as Int, eventInfo?.`when`)
-                    updateTextView(views, R.id.where, eventInfo?.visibWhere
-                        as Int, eventInfo?.where)
+                if (!eventInfo.allDay) {
+                    updateTextView(views, R.id.`when`, eventInfo.visibWhen
+                        as Int, eventInfo.`when`)
+                    updateTextView(views, R.id.where, eventInfo.visibWhere
+                        as Int, eventInfo.where)
                 }
-                updateTextView(views, R.id.title, eventInfo?.visibTitle as Int, eventInfo?.title)
+                updateTextView(views, R.id.title, eventInfo.visibTitle as Int, eventInfo.title)
                 views.setViewVisibility(R.id.agenda_item_color, View.VISIBLE)
-                val selfAttendeeStatus: Int = eventInfo?.selfAttendeeStatus as Int
-                if (eventInfo!!.allDay) {
+                val selfAttendeeStatus: Int = eventInfo.selfAttendeeStatus as Int
+                if (eventInfo.allDay) {
                     if (selfAttendeeStatus == Attendees.ATTENDEE_STATUS_INVITED) {
-                        views?.setInt(
+                        views.setInt(
                             R.id.agenda_item_color, "setImageResource",
                             R.drawable.widget_chip_not_responded_bg
                         )
-                        views?.setInt(R.id.title, "setTextColor", displayColor)
+                        views.setInt(R.id.title, "setTextColor", displayColor)
                     } else {
-                        views?.setInt(
+                        views.setInt(
                             R.id.agenda_item_color, "setImageResource",
                             R.drawable.widget_chip_responded_bg
                         )
-                        views?.setInt(R.id.title, "setTextColor", mAllDayColor)
+                        views.setInt(R.id.title, "setTextColor", mAllDayColor)
                     }
                     if (selfAttendeeStatus == Attendees.ATTENDEE_STATUS_DECLINED) {
                         // 40% opacity
-                        views?.setInt(
+                        views.setInt(
                             R.id.agenda_item_color, "setColorFilter",
                             Utils.getDeclinedColorFromColor(displayColor)
                         )
                     } else {
-                        views?.setInt(R.id.agenda_item_color, "setColorFilter", displayColor)
+                        views.setInt(R.id.agenda_item_color, "setColorFilter", displayColor)
                     }
                 } else if (selfAttendeeStatus == Attendees.ATTENDEE_STATUS_DECLINED) {
-                    views?.setInt(R.id.title, "setTextColor", mDeclinedColor)
-                    views?.setInt(R.id.`when`, "setTextColor", mDeclinedColor)
-                    views?.setInt(R.id.where, "setTextColor", mDeclinedColor)
-                    views?.setInt(
+                    views.setInt(R.id.title, "setTextColor", mDeclinedColor)
+                    views.setInt(R.id.`when`, "setTextColor", mDeclinedColor)
+                    views.setInt(R.id.where, "setTextColor", mDeclinedColor)
+                    views.setInt(
                         R.id.agenda_item_color, "setImageResource",
                         R.drawable.widget_chip_responded_bg
                     )
                     // 40% opacity
-                    views?.setInt(
+                    views.setInt(
                         R.id.agenda_item_color, "setColorFilter",
                         Utils.getDeclinedColorFromColor(displayColor)
                     )
                 } else {
-                    views?.setInt(R.id.title, "setTextColor", mStandardColor)
-                    views?.setInt(R.id.`when`, "setTextColor", mStandardColor)
-                    views?.setInt(R.id.where, "setTextColor", mStandardColor)
+                    views.setInt(R.id.title, "setTextColor", mStandardColor)
+                    views.setInt(R.id.`when`, "setTextColor", mStandardColor)
+                    views.setInt(R.id.where, "setTextColor", mStandardColor)
                     if (selfAttendeeStatus == Attendees.ATTENDEE_STATUS_INVITED) {
-                        views?.setInt(
+                        views.setInt(
                             R.id.agenda_item_color, "setImageResource",
                             R.drawable.widget_chip_not_responded_bg
                         )
                     } else {
-                        views?.setInt(
+                        views.setInt(
                             R.id.agenda_item_color, "setImageResource",
                             R.drawable.widget_chip_responded_bg
                         )
                     }
-                    views?.setInt(R.id.agenda_item_color, "setColorFilter", displayColor)
+                    views.setInt(R.id.agenda_item_color, "setColorFilter", displayColor)
                 }
-                var start: Long = eventInfo?.start as Long
-                var end: Long = eventInfo?.end as Long
+                var start: Long = eventInfo.start as Long
+                var end: Long = eventInfo.end as Long
                 // An element in ListView.
-                if (eventInfo!!.allDay) {
+                if (eventInfo.allDay) {
                     val tz: String? = Utils.getTimeZone(mContext, null)
                     val recycle = Time()
                     start = Utils.convertAlldayLocalToUTC(recycle, start, tz as String)
                     end = Utils.convertAlldayLocalToUTC(recycle, end, tz as String)
                 }
                 val fillInIntent: Intent = CalendarAppWidgetProvider.getLaunchFillInIntent(
-                    mContext, eventInfo?.id, start, end, eventInfo?.allDay
+                    mContext, eventInfo.id, start, end, eventInfo.allDay
                 )
                 views.setOnClickFillInIntent(R.id.widget_row, fillInIntent)
                 views
@@ -502,10 +502,10 @@
                     mModel = buildAppWidgetModel(mContext, matrixCursor, tz)
                 } finally {
                     if (matrixCursor != null) {
-                        matrixCursor?.close()
+                        matrixCursor.close()
                     }
                     if (cursor != null) {
-                        cursor?.close()
+                        cursor.close()
                     }
                 }