Use AppCompatContactsActivity as super class of activities (2/3)

- interpolator.fast_out_slow_in was introduce in API level 21, use
  linear for Kitkat.

- use AppCompatCheckBox to show colored CheckBox

- also fixed button color in contacts_unavailable_fragment_content on K

Bug: 25629359
Change-Id: I492f10adfb07e8f7d0fc2ffbac0063f2486820cc
diff --git a/src/com/android/contacts/common/activity/AppCompatTransactionSafeActivity.java b/src/com/android/contacts/common/activity/AppCompatTransactionSafeActivity.java
new file mode 100644
index 0000000..e70a9fd
--- /dev/null
+++ b/src/com/android/contacts/common/activity/AppCompatTransactionSafeActivity.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.contacts.common.activity;
+
+import android.os.Bundle;
+import android.support.v7.app.AppCompatActivity;
+
+/**
+ * A common superclass that keeps track of whether an {@link AppCompatActivity} has saved its state
+ * yet or not, copied from {@link com.android.contacts.common.activity.TransactionSafeActivity},
+ * which will be deprecated after Kitkat backporting is done.
+ */
+public abstract class AppCompatTransactionSafeActivity extends AppCompatActivity {
+
+    private boolean mIsSafeToCommitTransactions;
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        mIsSafeToCommitTransactions = true;
+    }
+
+    @Override
+    protected void onStart() {
+        super.onStart();
+        mIsSafeToCommitTransactions = true;
+    }
+
+    @Override
+    protected void onResume() {
+        super.onResume();
+        mIsSafeToCommitTransactions = true;
+    }
+
+    @Override
+    protected void onSaveInstanceState(Bundle outState) {
+        super.onSaveInstanceState(outState);
+        mIsSafeToCommitTransactions = false;
+    }
+
+    /**
+     * Returns true if it is safe to commit {@link FragmentTransaction}s at this time, based on
+     * whether {@link FragmentActivity#onSaveInstanceState} has been called or not.
+     *
+     * Make sure that the current activity calls into
+     * {@link super.onSaveInstanceState(Bundle outState)} (if that method is overridden),
+     * so the flag is properly set.
+     */
+    public boolean isSafeToCommitTransactions() {
+        return mIsSafeToCommitTransactions;
+    }
+}
diff --git a/src/com/android/contacts/common/list/ContactListItemView.java b/src/com/android/contacts/common/list/ContactListItemView.java
index 18e82ad..bb3fbc9 100644
--- a/src/com/android/contacts/common/list/ContactListItemView.java
+++ b/src/com/android/contacts/common/list/ContactListItemView.java
@@ -31,6 +31,7 @@
 import android.provider.ContactsContract.Contacts;
 import android.support.v4.content.ContextCompat;
 import android.support.v4.graphics.drawable.DrawableCompat;
+import android.support.v7.widget.AppCompatCheckBox;
 import android.text.Spannable;
 import android.text.SpannableString;
 import android.text.TextUtils;
@@ -43,7 +44,6 @@
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.AbsListView.SelectionBoundsAdjuster;
-import android.widget.CheckBox;
 import android.widget.ImageView;
 import android.widget.ImageView.ScaleType;
 import android.widget.QuickContactBadge;
@@ -185,7 +185,7 @@
     private TextView mSnippetView;
     private TextView mStatusView;
     private ImageView mPresenceIcon;
-    private CheckBox mCheckBox;
+    private AppCompatCheckBox mCheckBox;
     private ImageView mVideoCallIcon;
 
     private ColorStateList mSecondaryTextColor;
@@ -1198,11 +1198,11 @@
     }
 
     /**
-     * Returns the {@link CheckBox} view, creating it if necessary.
+     * Returns the {@link AppCompatCheckBox} view, creating it if necessary.
      */
-    public CheckBox getCheckBox() {
+    public AppCompatCheckBox getCheckBox() {
         if (mCheckBox == null) {
-            mCheckBox = new CheckBox(getContext());
+            mCheckBox = new AppCompatCheckBox(getContext());
             // Make non-focusable, so the rest of the ContactListItemView can be clicked.
             mCheckBox.setFocusable(false);
             addView(mCheckBox);
diff --git a/src/com/android/contacts/common/widget/FloatingActionButtonController.java b/src/com/android/contacts/common/widget/FloatingActionButtonController.java
index eb69d3c..739b3cc 100644
--- a/src/com/android/contacts/common/widget/FloatingActionButtonController.java
+++ b/src/com/android/contacts/common/widget/FloatingActionButtonController.java
@@ -24,8 +24,9 @@
 import android.view.View;
 import android.widget.ImageButton;
 
-import com.android.contacts.common.util.ViewUtil;
 import com.android.contacts.common.R;
+import com.android.contacts.common.compat.CompatUtils;
+import com.android.contacts.common.util.ViewUtil;
 import com.android.phone.common.animation.AnimUtils;
 
 /**
@@ -50,8 +51,14 @@
 
     public FloatingActionButtonController(Activity activity, View container, ImageButton button) {
         Resources resources = activity.getResources();
-        mFabInterpolator = AnimationUtils.loadInterpolator(activity,
-                android.R.interpolator.fast_out_slow_in);
+        if (CompatUtils.isLollipopCompatible()) {
+            mFabInterpolator = AnimationUtils.loadInterpolator(activity,
+                    android.R.interpolator.fast_out_slow_in);
+        } else {
+            // Use linear to avoid crash on Kitkat since fast_out_slow_in was added in API level 21
+            mFabInterpolator = AnimationUtils.loadInterpolator(activity,
+                    android.R.interpolator.linear);
+        }
         mFloatingActionButtonWidth = resources.getDimensionPixelSize(
                 R.dimen.floating_action_button_width);
         mFloatingActionButtonMarginRight = resources.getDimensionPixelOffset(