Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1b6b7e2d authored by Wenyi Wang's avatar Wenyi Wang
Browse files

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
parent 89999f4d
Loading
Loading
Loading
Loading
+66 −0
Original line number Diff line number Diff line
/*
 * 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;
    }
}
+5 −5
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import android.provider.ContactsContract;
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.MotionEvent;
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 @@ public class ContactListItemView extends ViewGroup
    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 @@ public class ContactListItemView extends ViewGroup
    }

    /**
     * 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);
+10 −3
Original line number Diff line number Diff line
@@ -24,8 +24,9 @@ import android.view.animation.Interpolator;
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 class FloatingActionButtonController {

    public FloatingActionButtonController(Activity activity, View container, ImageButton button) {
        Resources resources = activity.getResources();
        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(