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

Commit fdfeaaf4 authored by Andrew Lee's avatar Andrew Lee
Browse files

Change FAB icon and behavior for contacts tab.

+ Change the icon/behavior depending on the tab position.
+ Move current tab position logic from DialtactsActivity into the
lists fragment.
- Delete unused method, shift some helpers around.

Bug: 19366434
Change-Id: I6da767300907b3afd006248afb882bebde7bdfe6
parent 7ea6420e
Loading
Loading
Loading
Loading
+27 −21
Original line number Diff line number Diff line
@@ -197,11 +197,6 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O
     */
    private boolean mIsLandscape;

    /**
     * The position of the currently selected tab in the attached {@link ListsFragment}.
     */
    private int mCurrentTabPosition = 0;

    /**
     * True if the dialpad is only temporarily showing due to being in call
     */
@@ -581,7 +576,9 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.floating_action_button:
                if (!mIsDialpadShown) {
                if (mListsFragment.getTabPosition() == ListsFragment.TAB_INDEX_ALL_CONTACTS) {
                    sendAddNewContactIntent();
                } else if (!mIsDialpadShown) {
                    mInCallDialpadUp = false;
                    showDialpadFragment(true);
                }
@@ -612,14 +609,7 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O
                showCallHistory();
                break;
            case R.id.menu_add_contact:
                try {
                    startActivity(new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI));
                } catch (ActivityNotFoundException e) {
                    Toast toast = Toast.makeText(this,
                            R.string.add_contact_not_available,
                            Toast.LENGTH_SHORT);
                    toast.show();
                }
                sendAddNewContactIntent();
                break;
            case R.id.menu_import_export:
                // We hard-code the "contactsAreAvailable" argument because doing it properly would
@@ -1094,6 +1084,17 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O
        return intent;
    }

    private void sendAddNewContactIntent() {
        try {
            startActivity(new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI));
        } catch (ActivityNotFoundException e) {
            Toast toast = Toast.makeText(this,
                    R.string.add_contact_not_available,
                    Toast.LENGTH_SHORT);
            toast.show();
        }
    }

    private boolean canIntentBeHandled(Intent intent) {
        final PackageManager packageManager = getPackageManager();
        final List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(intent,
@@ -1194,22 +1195,26 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O
        } else if (position != ListsFragment.TAB_INDEX_SPEED_DIAL) {
            mFloatingActionButtonController.onPageScrolled(1);
        }

        if (position == ListsFragment.TAB_INDEX_ALL_CONTACTS) {
            mFloatingActionButtonController.changeIcon(
                    getResources().getDrawable(R.drawable.ic_person_add_24dp),
                    getResources().getString(R.string.search_shortcut_create_new_contact));
        } else {
            mFloatingActionButtonController.changeIcon(
                    getResources().getDrawable(R.drawable.fab_ic_dial),
                    getResources().getString(R.string.action_menu_dialpad_button));
        }
    }

    @Override
    public void onPageSelected(int position) {
        position = mListsFragment.getRtlPosition(position);
        mCurrentTabPosition = position;
    }

    @Override
    public void onPageScrollStateChanged(int state) {
    }

    private TelephonyManager getTelephonyManager() {
        return (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    }

    private TelecomManager getTelecomManager() {
        return (TelecomManager) getSystemService(Context.TELECOM_SERVICE);
    }
@@ -1249,7 +1254,8 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O
     * @param animate Whether or not to animate the transition.
     */
    private void updateFloatingActionButtonControllerAlignment(boolean animate) {
        int align = (!mIsLandscape && mCurrentTabPosition == ListsFragment.TAB_INDEX_SPEED_DIAL) ?
        int align = (!mIsLandscape &&
                mListsFragment.getTabPosition() == ListsFragment.TAB_INDEX_SPEED_DIAL) ?
                FloatingActionButtonController.ALIGN_MIDDLE :
                        FloatingActionButtonController.ALIGN_END;
        mFloatingActionButtonController.align(align, 0 /* offsetX */, 0 /* offsetY */, animate);
+1 −1
Original line number Diff line number Diff line
@@ -399,7 +399,7 @@ public class DialpadFragment extends Fragment

        final View floatingActionButtonContainer =
                fragmentView.findViewById(R.id.dialpad_floating_action_button_container);
        final View floatingActionButton =
        final ImageButton floatingActionButton =
                (ImageButton) fragmentView.findViewById(R.id.dialpad_floating_action_button);
        floatingActionButton.setOnClickListener(this);
        mFloatingActionButtonController = new FloatingActionButtonController(getActivity(),
+11 −0
Original line number Diff line number Diff line
@@ -79,6 +79,11 @@ public class ListsFragment extends Fragment implements ViewPager.OnPageChangeLis
    private String[] mTabTitles;
    private int[] mTabIcons;

    /**
     * The position of the currently selected tab.
     */
    private int mTabPosition = TAB_INDEX_SPEED_DIAL;

    /**
     * Call shortcuts older than this date (persisted in shared preferences) will not show up in
     * at the top of the screen
@@ -226,6 +231,8 @@ public class ListsFragment extends Fragment implements ViewPager.OnPageChangeLis

    @Override
    public void onPageSelected(int position) {
        mTabPosition = getRtlPosition(position);

        final int count = mOnPageChangeListeners.size();
        for (int i = 0; i < count; i++) {
            mOnPageChangeListeners.get(i).onPageSelected(position);
@@ -241,6 +248,10 @@ public class ListsFragment extends Fragment implements ViewPager.OnPageChangeLis
        }
    }

    public int getTabPosition() {
        return mTabPosition;
    }

    public void showRemoveView(boolean show) {
        mRemoveViewContent.setVisibility(show ? View.VISIBLE : View.GONE);
        mRemoveView.setAlpha(show ? 0 : 1);