Merged 'master' into 'per-contact-colors'

This commit is contained in:
Moez Bhatti
2015-12-23 01:24:33 -05:00
19 changed files with 333 additions and 46 deletions
+7
View File
@@ -450,6 +450,13 @@
android:name=".receiver.UnreadBadgeService"
android:exported="false" />
<service
android:name=".service.ShouldIAnswerService">
<intent-filter>
<action android:name="com.moez.QKSMS.ShouldIAnswerService" />
</intent-filter>
</service>
<!-- Service that delivers messages from the phone "quick response" -->
<service
android:name=".service.HeadlessSmsSendService"
@@ -0,0 +1,16 @@
package com.moez.QKSMS.common.utils;
import android.content.Context;
import android.content.pm.PackageManager;
public class PackageUtils {
public static boolean isAppInstalled(Context context, String packageName) {
try {
context.getPackageManager().getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
return true;
} catch (PackageManager.NameNotFoundException e) {
return false;
}
}
}
@@ -11,25 +11,33 @@ import android.telephony.SmsMessage;
import android.util.Log;
import com.moez.QKSMS.common.BlockedConversationHelper;
import com.moez.QKSMS.common.ConversationPrefsHelper;
import com.moez.QKSMS.common.utils.PackageUtils;
import com.moez.QKSMS.data.Message;
import com.moez.QKSMS.service.NotificationService;
import com.moez.QKSMS.transaction.NotificationManager;
import com.moez.QKSMS.transaction.SmsHelper;
import com.moez.QKSMS.ui.settings.SettingsFragment;
import org.mistergroup.muzutozvednout.ShouldIAnswerBinder;
public class MessagingReceiver extends BroadcastReceiver {
private final String TAG = "MessagingReceiver";
String address;
String body;
long date;
private Context mContext;
private SharedPreferences mPrefs;
Uri uri;
private String mAddress;
private String mBody;
private long mDate;
private Uri mUri;
@Override
public void onReceive(Context context, Intent intent) {
Log.i(TAG, "onReceive");
abortBroadcast();
Log.i(TAG, "Received text message");
mContext = context;
mPrefs = PreferenceManager.getDefaultSharedPreferences(context);
if (intent.getExtras() != null) {
Object[] pdus = (Object[]) intent.getExtras().get("pdus");
@@ -40,49 +48,88 @@ public class MessagingReceiver extends BroadcastReceiver {
SmsMessage sms = messages[0];
if (messages.length == 1 || sms.isReplace()) {
body = sms.getDisplayMessageBody();
mBody = sms.getDisplayMessageBody();
} else {
StringBuilder bodyText = new StringBuilder();
for (SmsMessage message : messages) {
bodyText.append(message.getMessageBody());
}
body = bodyText.toString();
mBody = bodyText.toString();
}
address = sms.getDisplayOriginatingAddress();
date = sms.getTimestampMillis();
mAddress = sms.getDisplayOriginatingAddress();
mDate = sms.getTimestampMillis();
uri = SmsHelper.addMessageToInbox(context, address, body, date);
if (mPrefs.getBoolean(SettingsFragment.SHOULD_I_ANSWER, false) &&
PackageUtils.isAppInstalled(mContext, "org.mistergroup.muzutozvednout")) {
Message message = new Message(context, uri);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
ConversationPrefsHelper conversationPrefs = new ConversationPrefsHelper(context, message.getThreadId());
ShouldIAnswerBinder shouldIAnswerBinder = new ShouldIAnswerBinder();
shouldIAnswerBinder.setCallback(new ShouldIAnswerBinder.Callback() {
@Override
public void onNumberRating(String number, int rating) {
Log.i(TAG, "onNumberRating " + number + ": " + String.valueOf(rating));
shouldIAnswerBinder.unbind(context.getApplicationContext());
if (rating != ShouldIAnswerBinder.RATING_NEGATIVE) {
insertMessageAndNotify();
}
}
if (BlockedConversationHelper.isFutureBlocked(prefs, address)) {
BlockedConversationHelper.unblockFutureConversation(prefs, address);
BlockedConversationHelper.blockConversation(prefs, message.getThreadId());
message.markSeen();
BlockedConversationHelper.FutureBlockedConversationObservable.getInstance().futureBlockedConversationReceived();
@Override
public void onServiceConnected() {
try {
shouldIAnswerBinder.getNumberRating(mAddress);
} catch (Exception e) {
e.printStackTrace();
}
}
} else if (conversationPrefs.getNotificationsEnabled() && !BlockedConversationHelper.getBlockedConversationIds(
PreferenceManager.getDefaultSharedPreferences(context)).contains(message.getThreadId())) {
Intent messageHandlerIntent = new Intent(context, NotificationService.class);
messageHandlerIntent.putExtra(NotificationService.EXTRA_POPUP, true);
messageHandlerIntent.putExtra(NotificationService.EXTRA_URI, uri.toString());
context.startService(messageHandlerIntent);
@Override
public void onServiceDisconnected() {
}
});
UnreadBadgeService.update(context);
NotificationManager.create(context);
shouldIAnswerBinder.bind(context.getApplicationContext());
} else {
message.markSeen();
}
if (conversationPrefs.getWakePhoneEnabled()) {
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "MessagingReceiver");
wakeLock.acquire();
wakeLock.release();
insertMessageAndNotify();
}
}
}
private void insertMessageAndNotify() {
mUri = SmsHelper.addMessageToInbox(mContext, mAddress, mBody, mDate);
Message message = new Message(mContext, mUri);
ConversationPrefsHelper conversationPrefs = new ConversationPrefsHelper(mContext, message.getThreadId());
// The user has set messages from this address to be blocked, but we at the time there weren't any
// messages from them already in the database, so we couldn't block any thread URI. Now that we have one,
// we can block it, so that the conversation list adapter knows to ignore this thread in the main list
if (BlockedConversationHelper.isFutureBlocked(mPrefs, mAddress)) {
BlockedConversationHelper.unblockFutureConversation(mPrefs, mAddress);
BlockedConversationHelper.blockConversation(mPrefs, message.getThreadId());
message.markSeen();
BlockedConversationHelper.FutureBlockedConversationObservable.getInstance().futureBlockedConversationReceived();
// If we have notifications enabled and this conversation isn't blocked
} else if (conversationPrefs.getNotificationsEnabled() && !BlockedConversationHelper.getBlockedConversationIds(
PreferenceManager.getDefaultSharedPreferences(mContext)).contains(message.getThreadId())) {
Intent messageHandlerIntent = new Intent(mContext, NotificationService.class);
messageHandlerIntent.putExtra(NotificationService.EXTRA_POPUP, true);
messageHandlerIntent.putExtra(NotificationService.EXTRA_URI, mUri.toString());
mContext.startService(messageHandlerIntent);
UnreadBadgeService.update(mContext);
NotificationManager.create(mContext);
} else { // We shouldn't show a notification for this message
message.markSeen();
}
if (conversationPrefs.getWakePhoneEnabled()) {
PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "MessagingReceiver");
wakeLock.acquire();
wakeLock.release();
}
}
}
@@ -0,0 +1,64 @@
package com.moez.QKSMS.service;
import android.annotation.SuppressLint;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.os.Messenger;
import android.os.RemoteException;
import android.preference.PreferenceManager;
import android.support.annotation.Nullable;
import com.moez.QKSMS.ui.settings.SettingsFragment;
public class ShouldIAnswerService extends Service {
private Messenger mMessenger = new Messenger(new BlockingEnabledHandler(this));
@Nullable
@Override
public IBinder onBind(Intent intent) {
return mMessenger.getBinder();
}
private class BlockingEnabledHandler extends Handler {
private Context mContext;
private BlockingEnabledHandler(Context context) {
mContext = context;
}
@SuppressLint("CommitPrefEdits")
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
Messenger messenger = msg.replyTo;
if (messenger != null && (msg.what == 918 || msg.what == 919)) {
Bundle data = new Bundle();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext);
if (msg.what == 919) {
boolean enabled=msg.getData().getBoolean("enabled");
prefs.edit().putBoolean(SettingsFragment.SHOULD_I_ANSWER, enabled).commit();
}
data.putBoolean("blocking_enabled", prefs.getBoolean(SettingsFragment.SHOULD_I_ANSWER, false));
Message message = new Message();
message.what = msg.what;
message.setData(data);
try {
messenger.send(message);
} catch (RemoteException e) {
e.printStackTrace();
}
}
}
}
}
@@ -535,7 +535,7 @@ public class NotificationManager {
SlideshowModel model = message.mSlideshow;
if (model != null && model.isSimple()) {
if (model != null && model.isSimple() && model.get(0).getImage() != null) {
Log.d(TAG, "MMS type: image");
ImageModel imageModel = model.get(0).getImage();
Bitmap image = imageModel.getBitmap(imageModel.getWidth(), imageModel.getHeight());
@@ -665,6 +665,10 @@ public class NotificationManager {
*/
public static void initQuickCompose(Context context, boolean override, boolean overrideCancel) {
if (sPrefs == null) {
init(context);
}
if (sPrefs.getBoolean(SettingsFragment.QUICKCOMPOSE, false) || override) {
Intent composeIntent = new Intent(context, QKComposeActivity.class);
PendingIntent composePI = PendingIntent.getActivity(context, 9, composeIntent, PendingIntent.FLAG_UPDATE_CURRENT);
@@ -458,7 +458,10 @@ public class SmsHelper {
do {
Uri threadUri = Uri.withAppendedPath(Message.MMS_SMS_CONTENT_PROVIDER, conversationCursor.getString(Conversation.ID));
Cursor messageCursor = context.getContentResolver().query(threadUri, MessageColumns.PROJECTION, SmsHelper.UNREAD_SELECTION, null, SmsHelper.sortDateDesc);
result += messageCursor.getCount();
if (messageCursor != null) {
result += messageCursor.getCount();
messageCursor.close();
}
} while (conversationCursor.moveToNext());
}
@@ -412,6 +412,10 @@ public class MessageListAdapter extends RecyclerCursorAdapter<MessageListViewHol
if (messageItem.mSlideshow == null) {
messageItem.setOnPduLoaded(messageItem1 -> {
if (mCursor == null) {
// The pdu has probably loaded after shutting down the fragment. Don't try to bind anything now
return;
}
if (messageItem1 != null && messageItem1.getMessageId() == messageItem1.getMessageId()) {
messageItem1.setCachedFormattedMessage(null);
bindGrouping(holder, messageItem);
@@ -12,6 +12,8 @@ import android.content.res.Resources;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.preference.CheckBoxPreference;
import android.preference.EditTextPreference;
import android.preference.ListPreference;
import android.preference.Preference;
@@ -36,6 +38,7 @@ import com.moez.QKSMS.common.ListviewHelper;
import com.moez.QKSMS.common.LiveViewManager;
import com.moez.QKSMS.common.utils.DateFormatter;
import com.moez.QKSMS.common.utils.KeyboardUtils;
import com.moez.QKSMS.common.utils.PackageUtils;
import com.moez.QKSMS.interfaces.LiveView;
import com.moez.QKSMS.receiver.NightModeAutoReceiver;
import com.moez.QKSMS.transaction.EndlessJabber;
@@ -107,6 +110,7 @@ public class SettingsFragment extends PreferenceFragment implements Preference.O
public static final String BLOCKED_ENABLED = "pref_key_blocked_enabled";
public static final String BLOCKED_SENDERS = "pref_key_blocked_senders";
public static final String BLOCKED_FUTURE = "pref_key_block_future";
public static final String SHOULD_I_ANSWER = "pref_key_should_i_answer";
public static final String MOBILE_ONLY = "pref_key_mobile_only";
public static final String COMPOSE_GROUP = "pref_key_compose_group";
public static final String SPLIT_SMS = "pref_key_split";
@@ -526,6 +530,30 @@ public class SettingsFragment extends PreferenceFragment implements Preference.O
case BLOCKED_FUTURE:
BlockedNumberDialog.showDialog(mContext);
break;
case SHOULD_I_ANSWER:
final String packageName = "org.mistergroup.muzutozvednout";
if (!PackageUtils.isAppInstalled(mContext, packageName)) {
String referrer="referrer=utm_source%3Dqksms%26utm_medium%3Dapp%26utm_campaign%3Dqksmssettings";
new QKDialog()
.setContext(mContext)
.setTitle(R.string.dialog_should_i_answer_title)
.setMessage(R.string.dialog_should_i_answer_message)
.setNegativeButton(R.string.cancel, null)
.setPositiveButton(R.string.okay, v -> {
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + packageName + "&" + referrer)));
} catch (android.content.ActivityNotFoundException anfe) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + packageName + "&" + referrer)));
}
})
.show();
new Handler().postDelayed(() -> {
mPrefs.edit().putBoolean(SHOULD_I_ANSWER, false).commit();
((CheckBoxPreference) preference).setChecked(false);
}, 500);
}
break;
case NOTIFICATION_LED_COLOR:
mLedColorPickerDialog.show(getActivity().getFragmentManager(), "colorpicker");
break;
@@ -0,0 +1,98 @@
package org.mistergroup.muzutozvednout;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.os.Messenger;
import android.os.RemoteException;
/**
* Created by Mister Group s.r.o. on 30.11.2015.
*/
public class ShouldIAnswerBinder {
public static final int RATING_UNKNOWN = 0;
public static final int RATING_POSITIVE = 1;
public static final int RATING_NEGATIVE = 2;
public static final int RATING_NEUTRAL = 3;
private Callback callback;
public boolean isBound;
public interface Callback {
void onNumberRating(String number, int rating);
void onServiceConnected();
void onServiceDisconnected();
}
public void setCallback(Callback callback) {
this.callback = callback;
}
public void bind(Context context) {
Intent intent=new Intent("org.mistergroup.muzutozvednout.PublicService");
intent.setPackage("org.mistergroup.muzutozvednout");
context.bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
}
public void unbind(Context context) {
if ((isBound) && (serviceMessenger != null)) {
context.unbindService(mConnection);
}
}
public void getNumberRating(String number) throws RemoteException {
Message msg = new Message();
msg.what = 1;
Bundle data = new Bundle();
data.putString("number", number);
msg.setData(data);
msg.replyTo = messenger;
serviceMessenger.send(msg);
}
private final Messenger messenger = new Messenger(new IncomingHandler());
private static Messenger serviceMessenger = null;
private ServiceConnection mConnection = new ServiceConnection() {
public void onServiceConnected(ComponentName className, IBinder service) {
serviceMessenger = new Messenger(service);
isBound = true;
if (callback != null)
callback.onServiceConnected();
}
public void onServiceDisconnected(ComponentName className) {
serviceMessenger = null;
isBound = false;
if (callback != null)
callback.onServiceDisconnected();
}
};
private class IncomingHandler extends Handler {
static final int GET_NUMBER_RATING = 1;
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case GET_NUMBER_RATING:
Bundle inData = msg.getData();
String number = inData.getString("number");
int rating = inData.getInt("rating");
if (callback != null)
callback.onNumberRating(number, rating);
break;
default:
super.handleMessage(msg);
}
}
}
}
+1 -1
View File
@@ -4,6 +4,6 @@
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
android:fillColor="#FF000000"
android:fillColor="#FFFFFFFF"
android:pathData="M9,16.17L4.83,12l-1.42,1.41L9,19 21,7l-1.41,-1.41z" />
</vector>
+1 -1
View File
@@ -4,6 +4,6 @@
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:fillColor="#FFFFFFFF"
android:pathData="M6.62,10.79c1.44,2.83 3.76,5.14 6.59,6.59l2.2,-2.2c0.27,-0.27 0.67,-0.36 1.02,-0.24 1.12,0.37 2.33,0.57 3.57,0.57 0.55,0 1,0.45 1,1V20c0,0.55 -0.45,1 -1,1 -9.39,0 -17,-7.61 -17,-17 0,-0.55 0.45,-1 1,-1h3.5c0.55,0 1,0.45 1,1 0,1.25 0.2,2.45 0.57,3.57 0.11,0.35 0.03,0.74 -0.25,1.02l-2.2,2.2z"/>
</vector>
+1 -1
View File
@@ -4,6 +4,6 @@
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
android:fillColor="#FF000000"
android:fillColor="#FFFFFFFF"
android:pathData="M3,17.25V21h3.75L17.81,9.94l-3.75,-3.75L3,17.25zM20.71,7.04c0.39,-0.39 0.39,-1.02 0,-1.41l-2.34,-2.34c-0.39,-0.39 -1.02,-0.39 -1.41,0l-1.83,1.83 3.75,3.75 1.83,-1.83z" />
</vector>
@@ -4,6 +4,6 @@
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
android:fillColor="#FF000000"
android:fillColor="#FFFFFFFF"
android:pathData="M20,2L4,2c-1.1,0 -1.99,0.9 -1.99,2L2,22l4,-4h14c1.1,0 2,-0.9 2,-2L22,4c0,-1.1 -0.9,-2 -2,-2zM9,11L7,11L7,9h2v2zM13,11h-2L11,9h2v2zM17,11h-2L15,9h2v2z" />
</vector>
@@ -4,6 +4,6 @@
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
android:fillColor="#FF000000"
android:fillColor="#FFFFFFFF"
android:pathData="M20,2L4,2c-1.1,0 -1.99,0.9 -1.99,2L2,22l4,-4h14c1.1,0 2,-0.9 2,-2L22,4c0,-1.1 -0.9,-2 -2,-2zM13,14h-2v-2h2v2zM13,10h-2L11,6h2v4z" />
</vector>
@@ -4,6 +4,6 @@
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
android:fillColor="#FF000000"
android:fillColor="#FFFFFFFF"
android:pathData="M20,2H4c-1.1,0 -1.99,0.9 -1.99,2L2,22l4,-4h14c1.1,0 2,-0.9 2,-2V4c0,-1.1 -0.9,-2 -2,-2zM5,14l3.5,-4.5 2.5,3.01L14.5,8l4.5,6H5z" />
</vector>
+1 -1
View File
@@ -4,6 +4,6 @@
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
android:fillColor="#FF000000"
android:fillColor="#FFFFFFFF"
android:pathData="M10,9V5l-7,7 7,7v-4.1c5,0 8.5,1.6 11,5.1 -1,-5 -4,-10 -11,-11z" />
</vector>
+5
View File
@@ -110,6 +110,7 @@
<string name="pref_category_summary_appearance">Themes, fonts, colors, avatars, and more</string>
<string name="pref_category_general">General</string>
<string name="pref_category_summary_general">Delivery, message sending, formatting</string>
<string name="pref_category_blocking">Message blocking</string>
<string name="pref_category_notifications">Notifications</string>
<string name="pref_category_summary_notifications">Sounds, LED, privacy</string>
<string name="pref_category_mms">MMS</string>
@@ -170,6 +171,8 @@
<string name="pref_blocked_conversations_summary">Long-press on a conversation and block to move to blocked inbox and stop notifications</string>
<string name="pref_block_future">Block future messages</string>
<string name="pref_block_future_summary">Add additional phone numbers to block</string>
<string name="pref_should_i_answer">Should I Answer? Integration</string>
<string name="pref_should_i_answer_summary">Automatically delete incoming messages from numbers which are blocked through Should I Answer?</string>
<string name="pref_mobile_only">Mobile numbers</string>
<string name="pref_mobile_only_summary">Only show mobile numbers in contact suggestions</string>
<string name="pref_auto_emoji">Automatic emoji</string>
@@ -575,6 +578,8 @@
<string name="dialog_conversation_details_last_message_date">Last message date</string>
<string name="dialog_conversation_details_message_count">Message count</string>
<string name="dialog_conversation_details_recipients">Recipients (%s)</string>
<string name="dialog_should_i_answer_title">Should I Answer? not installed</string>
<string name="dialog_should_i_answer_message">Would you like to download the app from Google Play now?</string>
<!-- Title for audio file picker -->
<string name="select_audio">Choose audio</string>
+12 -1
View File
@@ -89,7 +89,7 @@
</PreferenceCategory>
<PreferenceCategory
android:layout="@layout/list_item_preference_category"
android:title="@string/pref_category_general">
android:title="@string/pref_category_blocking">
<CheckBoxPreference
android:defaultValue="false"
android:key="pref_key_blocked_enabled"
@@ -104,6 +104,17 @@
android:layout="@layout/list_item_preference"
android:summary="@string/pref_block_future_summary"
android:title="@string/pref_block_future" />
<CheckBoxPreference
android:defaultValue="false"
android:key="pref_key_should_i_answer"
android:layout="@layout/list_item_preference"
android:summary="@string/pref_should_i_answer_summary"
android:title="@string/pref_should_i_answer"
android:widgetLayout="@layout/view_switch" />
</PreferenceCategory>
<PreferenceCategory
android:layout="@layout/list_item_preference_category"
android:title="@string/pref_category_general">
<CheckBoxPreference
android:defaultValue="false"
android:key="pref_key_mobile_only"