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

Commit 247df6ee authored by Andrew Lee's avatar Andrew Lee
Browse files

Reorganize Intent utilities, add send SMS intent.

+ Rename CallIntentUtils.java to IntentUtil.java.
+ Consolidate various intent creation methods to new file, and update
referenes throughout the application.

Bug: 20433758
Change-Id: Iee9e37985217c38c816124d0e74dff40a2871680
parent 8ba6e006
Loading
Loading
Loading
Loading
+14 −0
Original line number Original line Diff line number Diff line
@@ -79,6 +79,20 @@


    </LinearLayout>
    </LinearLayout>


    <LinearLayout
        android:id="@+id/send_message_action"
        style="@style/CallLogActionStyle">

        <ImageView
            style="@style/CallLogActionIconStyle"
            android:src="@drawable/ic_textsms_24dp" />

        <TextView
            style="@style/CallLogActionTextStyle"
            android:text="@string/call_log_action_send_message" />

    </LinearLayout>

    <LinearLayout
    <LinearLayout
        android:id="@+id/details_action"
        android:id="@+id/details_action"
        style="@style/CallLogActionStyle">
        style="@style/CallLogActionStyle">
+5 −0
Original line number Original line Diff line number Diff line
@@ -550,6 +550,11 @@
         [CHAR LIMIT=30] -->
         [CHAR LIMIT=30] -->
    <string name="call_log_action_voicemail">LISTEN</string>
    <string name="call_log_action_voicemail">LISTEN</string>


    <!-- Button text for a button displayed underneath an entry in the call log, which opens up a
         messaging app to send a SMS to the number represented by the call log entry.
         [CHAR LIMIT=50] -->
    <string name="call_log_action_send_message">Send Message</string>

    <!-- Button text for the button displayed underneath an entry in the call log.
    <!-- Button text for the button displayed underneath an entry in the call log.
         Tapping navigates the user to the call details screen where the user can view details for
         Tapping navigates the user to the call details screen where the user can view details for
         the call log entry. [CHAR LIMIT=50] -->
         the call log entry. [CHAR LIMIT=50] -->
+4 −3
Original line number Original line Diff line number Diff line
@@ -64,7 +64,7 @@ import com.android.dialer.calllog.PhoneNumberDisplayHelper;
import com.android.dialer.calllog.PhoneNumberUtilsWrapper;
import com.android.dialer.calllog.PhoneNumberUtilsWrapper;
import com.android.dialer.util.AsyncTaskExecutor;
import com.android.dialer.util.AsyncTaskExecutor;
import com.android.dialer.util.AsyncTaskExecutors;
import com.android.dialer.util.AsyncTaskExecutors;
import com.android.dialer.util.CallIntentUtil;
import com.android.dialer.util.IntentUtil;
import com.android.dialer.util.DialerUtils;
import com.android.dialer.util.DialerUtils;
import com.android.dialer.util.TelecomUtil;
import com.android.dialer.util.TelecomUtil;
import com.android.dialer.voicemail.VoicemailPlaybackFragment;
import com.android.dialer.voicemail.VoicemailPlaybackFragment;
@@ -323,8 +323,9 @@ public class CallDetailActivity extends Activity implements ProximitySensorAware
                        getSystemService(Context.TELEPHONY_SERVICE);
                        getSystemService(Context.TELEPHONY_SERVICE);
                if (tm.getCallState() == TelephonyManager.CALL_STATE_IDLE) {
                if (tm.getCallState() == TelephonyManager.CALL_STATE_IDLE) {
                    DialerUtils.startActivityWithErrorToast(this,
                    DialerUtils.startActivityWithErrorToast(this,
                            CallIntentUtil.getCallIntent(Uri.fromParts(PhoneAccount.SCHEME_TEL,
                            IntentUtil.getCallIntent(
                                    mNumber, null)), R.string.call_not_available);
                                    Uri.fromParts(PhoneAccount.SCHEME_TEL, mNumber, null)),
                                    R.string.call_not_available);
                    return true;
                    return true;
                }
                }
            }
            }
+11 −38
Original line number Original line Diff line number Diff line
@@ -29,7 +29,6 @@ import android.content.res.Resources;
import android.net.Uri;
import android.net.Uri;
import android.os.Bundle;
import android.os.Bundle;
import android.os.Trace;
import android.os.Trace;
import android.provider.ContactsContract.Contacts;
import android.provider.ContactsContract.Intents;
import android.provider.ContactsContract.Intents;
import android.speech.RecognizerIntent;
import android.speech.RecognizerIntent;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager;
@@ -82,7 +81,7 @@ import com.android.dialer.list.SearchFragment;
import com.android.dialer.list.SmartDialSearchFragment;
import com.android.dialer.list.SmartDialSearchFragment;
import com.android.dialer.list.SpeedDialFragment;
import com.android.dialer.list.SpeedDialFragment;
import com.android.dialer.settings.DialerSettingsActivity;
import com.android.dialer.settings.DialerSettingsActivity;
import com.android.dialer.util.CallIntentUtil;
import com.android.dialer.util.IntentUtil;
import com.android.dialer.util.DialerUtils;
import com.android.dialer.util.DialerUtils;
import com.android.dialer.widget.ActionBarController;
import com.android.dialer.widget.ActionBarController;
import com.android.dialer.widget.SearchEditTextLayout;
import com.android.dialer.widget.SearchEditTextLayout;
@@ -587,7 +586,10 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O
        switch (view.getId()) {
        switch (view.getId()) {
            case R.id.floating_action_button:
            case R.id.floating_action_button:
                if (mListsFragment.getTabPosition() == ListsFragment.TAB_INDEX_ALL_CONTACTS) {
                if (mListsFragment.getTabPosition() == ListsFragment.TAB_INDEX_ALL_CONTACTS) {
                    sendAddNewContactIntent();
                    DialerUtils.startActivityWithErrorToast(
                            this,
                            IntentUtil.getNewContactIntent(),
                            R.string.add_contact_not_available);
                } else if (!mIsDialpadShown) {
                } else if (!mIsDialpadShown) {
                    mInCallDialpadUp = false;
                    mInCallDialpadUp = false;
                    showDialpadFragment(true);
                    showDialpadFragment(true);
@@ -622,7 +624,10 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O
                startActivity(intent);
                startActivity(intent);
                break;
                break;
            case R.id.menu_add_contact:
            case R.id.menu_add_contact:
                sendAddNewContactIntent();
                DialerUtils.startActivityWithErrorToast(
                        this,
                        IntentUtil.getNewContactIntent(),
                        R.string.add_contact_not_available);
                break;
                break;
            case R.id.menu_import_export:
            case R.id.menu_import_export:
                // We hard-code the "contactsAreAvailable" argument because doing it properly would
                // We hard-code the "contactsAreAvailable" argument because doing it properly would
@@ -1082,38 +1087,6 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O
        return getTelecomManager().isInCall();
        return getTelecomManager().isInCall();
    }
    }


    public static Intent getAddNumberToContactIntent(CharSequence text) {
        return getAddToContactIntent(null /* name */, text /* phoneNumber */,
                -1 /* phoneNumberType */);
    }

    public static Intent getAddToContactIntent(CharSequence name, CharSequence phoneNumber,
            int phoneNumberType) {
        Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
        intent.putExtra(Intents.Insert.PHONE, phoneNumber);
        // Only include the name and phone type extras if they are specified (the method
        // getAddNumberToContactIntent does not use them).
        if (name != null) {
            intent.putExtra(Intents.Insert.NAME, name);
        }
        if (phoneNumberType != -1) {
            intent.putExtra(Intents.Insert.PHONE_TYPE, phoneNumberType);
        }
        intent.setType(Contacts.CONTENT_ITEM_TYPE);
        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) {
    private boolean canIntentBeHandled(Intent intent) {
        final PackageManager packageManager = getPackageManager();
        final PackageManager packageManager = getPackageManager();
        final List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(intent,
        final List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(intent,
@@ -1171,8 +1144,8 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O
    @Override
    @Override
    public void onCallNumberDirectly(String phoneNumber, boolean isVideoCall) {
    public void onCallNumberDirectly(String phoneNumber, boolean isVideoCall) {
        Intent intent = isVideoCall ?
        Intent intent = isVideoCall ?
                CallIntentUtil.getVideoCallIntent(phoneNumber, getCallOrigin()) :
                IntentUtil.getVideoCallIntent(phoneNumber, getCallOrigin()) :
                CallIntentUtil.getCallIntent(phoneNumber, getCallOrigin());
                IntentUtil.getCallIntent(phoneNumber, getCallOrigin());
        DialerUtils.startActivityWithErrorToast(this, intent);
        DialerUtils.startActivityWithErrorToast(this, intent);
        mClearSearchOnPause = true;
        mClearSearchOnPause = true;
    }
    }
+6 −12
Original line number Original line Diff line number Diff line
@@ -72,6 +72,7 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder {
    public View voicemailButtonView;
    public View voicemailButtonView;
    public View createNewContactButtonView;
    public View createNewContactButtonView;
    public View addToExistingContactButtonView;
    public View addToExistingContactButtonView;
    public View sendMessageView;
    public View detailsButtonView;
    public View detailsButtonView;
    public View reportButtonView;
    public View reportButtonView;


@@ -218,35 +219,26 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder {
        ViewStub stub = (ViewStub) rootView.findViewById(R.id.call_log_entry_actions_stub);
        ViewStub stub = (ViewStub) rootView.findViewById(R.id.call_log_entry_actions_stub);
        if (stub != null) {
        if (stub != null) {
            actionsView = (ViewGroup) stub.inflate();
            actionsView = (ViewGroup) stub.inflate();
        }


        if (videoCallButtonView == null) {
            videoCallButtonView = actionsView.findViewById(R.id.video_call_action);
            videoCallButtonView = actionsView.findViewById(R.id.video_call_action);
            videoCallButtonView.setOnClickListener(mActionListener);
            videoCallButtonView.setOnClickListener(mActionListener);
        }


        if (voicemailButtonView == null) {
            voicemailButtonView = actionsView.findViewById(R.id.voicemail_action);
            voicemailButtonView = actionsView.findViewById(R.id.voicemail_action);
            voicemailButtonView.setOnClickListener(mActionListener);
            voicemailButtonView.setOnClickListener(mActionListener);
        }


        if (createNewContactButtonView == null) {
            createNewContactButtonView = actionsView.findViewById(R.id.create_new_contact_action);
            createNewContactButtonView = actionsView.findViewById(R.id.create_new_contact_action);
            createNewContactButtonView.setOnClickListener(mActionListener);
            createNewContactButtonView.setOnClickListener(mActionListener);
        }


        if (addToExistingContactButtonView == null) {
            addToExistingContactButtonView =
            addToExistingContactButtonView =
                    actionsView.findViewById(R.id.add_to_existing_contact_action);
                    actionsView.findViewById(R.id.add_to_existing_contact_action);
            addToExistingContactButtonView.setOnClickListener(mActionListener);
            addToExistingContactButtonView.setOnClickListener(mActionListener);
        }


        if (detailsButtonView == null) {
            sendMessageView = actionsView.findViewById(R.id.send_message_action);
            sendMessageView.setOnClickListener(mActionListener);

            detailsButtonView = actionsView.findViewById(R.id.details_action);
            detailsButtonView = actionsView.findViewById(R.id.details_action);
            detailsButtonView.setOnClickListener(mActionListener);
            detailsButtonView.setOnClickListener(mActionListener);
        }


        if (reportButtonView == null) {
            reportButtonView = actionsView.findViewById(R.id.report_action);
            reportButtonView = actionsView.findViewById(R.id.report_action);
            reportButtonView.setOnClickListener(new View.OnClickListener() {
            reportButtonView.setOnClickListener(new View.OnClickListener() {
                @Override
                @Override
@@ -344,6 +336,8 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder {
            addToExistingContactButtonView.setVisibility(View.GONE);
            addToExistingContactButtonView.setVisibility(View.GONE);
        }
        }


        sendMessageView.setTag(IntentProvider.getSendSmsIntentProvider(number));

        mCallLogListItemHelper.setActionContentDescriptions(this);
        mCallLogListItemHelper.setActionContentDescriptions(this);
    }
    }


Loading