diff --git a/res/layout/recipient_preference_contact_widget.xml b/res/layout/recipient_preference_contact_widget.xml new file mode 100644 index 0000000000..2114a95765 --- /dev/null +++ b/res/layout/recipient_preference_contact_widget.xml @@ -0,0 +1,25 @@ + + + + + + + + + + \ No newline at end of file diff --git a/res/values/strings.xml b/res/values/strings.xml index 00bde6ef62..bc945e4e44 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -1415,6 +1415,7 @@ Signal is locked TAP TO UNLOCK Reminder: + About diff --git a/res/xml/recipient_preferences.xml b/res/xml/recipient_preferences.xml index ec7464b5c1..28e3c6b61e 100644 --- a/res/xml/recipient_preferences.xml +++ b/res/xml/recipient_preferences.xml @@ -2,6 +2,12 @@ + + + + + + { + Intent intent = new Intent(getContext(), WebRtcCallService.class); + intent.setAction(WebRtcCallService.ACTION_OUTGOING_CALL); + intent.putExtra(WebRtcCallService.EXTRA_REMOTE_ADDRESS, recipient.getAddress()); + getContext().startService(intent); + + Intent activityIntent = new Intent(getContext(), WebRtcCallActivity.class); + activityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + startActivity(activityIntent); + }) + .execute(); + } + + @Override + public void onInSecureCallClicked() { + try { + Intent dialIntent = new Intent(Intent.ACTION_DIAL, + Uri.parse("tel:" + recipient.getAddress().serialize())); + startActivity(dialIntent); + } catch (ActivityNotFoundException anfe) { + Log.w(TAG, anfe); + Dialogs.showAlertDialog(getContext(), + getString(R.string.ConversationActivity_calls_not_supported), + getString(R.string.ConversationActivity_this_device_does_not_appear_to_support_dial_actions)); + } + } + } } } diff --git a/src/org/thoughtcrime/securesms/preferences/widgets/ContactPreference.java b/src/org/thoughtcrime/securesms/preferences/widgets/ContactPreference.java new file mode 100644 index 0000000000..8a9f0e0af9 --- /dev/null +++ b/src/org/thoughtcrime/securesms/preferences/widgets/ContactPreference.java @@ -0,0 +1,92 @@ +package org.thoughtcrime.securesms.preferences.widgets; + + +import android.content.Context; +import android.graphics.PorterDuff; +import android.support.v7.preference.Preference; +import android.support.v7.preference.PreferenceViewHolder; +import android.util.AttributeSet; +import android.view.View; +import android.widget.ImageView; + +import org.thoughtcrime.securesms.R; + +public class ContactPreference extends Preference { + + private ImageView messageButton; + private ImageView callButton; + private ImageView secureCallButton; + + private Listener listener; + private boolean secure; + + public ContactPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + initialize(); + } + + public ContactPreference(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + initialize(); + } + + public ContactPreference(Context context, AttributeSet attrs) { + super(context, attrs); + initialize(); + } + + public ContactPreference(Context context) { + super(context); + initialize(); + } + + private void initialize() { + setWidgetLayoutResource(R.layout.recipient_preference_contact_widget); + } + + @Override + public void onBindViewHolder(PreferenceViewHolder view) { + super.onBindViewHolder(view); + + this.messageButton = (ImageView) view.findViewById(R.id.message); + this.callButton = (ImageView) view.findViewById(R.id.call); + this.secureCallButton = (ImageView) view.findViewById(R.id.secure_call); + + if (listener != null) setListener(listener); + setSecure(secure); + } + + public void setSecure(boolean secure) { + this.secure = secure; + + if (secureCallButton != null) secureCallButton.setVisibility(secure ? View.VISIBLE : View.GONE); + if (callButton != null) callButton.setVisibility(secure ? View.GONE : View.VISIBLE); + + int color; + + if (secure) { + color = getContext().getResources().getColor(R.color.textsecure_primary); + } else { + color = getContext().getResources().getColor(R.color.grey_600); + } + + if (messageButton != null) messageButton.setColorFilter(color, PorterDuff.Mode.SRC_IN); + if (secureCallButton != null) secureCallButton.setColorFilter(color, PorterDuff.Mode.SRC_IN); + if (callButton != null) callButton.setColorFilter(color, PorterDuff.Mode.SRC_IN); + } + + public void setListener(Listener listener) { + this.listener = listener; + + if (this.messageButton != null) this.messageButton.setOnClickListener(v -> listener.onMessageClicked()); + if (this.secureCallButton != null) this.secureCallButton.setOnClickListener(v -> listener.onSecureCallClicked()); + if (this.callButton != null) this.callButton.setOnClickListener(v -> listener.onInSecureCallClicked()); + } + + public interface Listener { + public void onMessageClicked(); + public void onSecureCallClicked(); + public void onInSecureCallClicked(); + } + +}