Merge pull request #156 from qklabs/develop

Develop
This commit is contained in:
Moez Bhatti
2015-08-20 01:11:27 -04:00
174 changed files with 881 additions and 1048 deletions
@@ -199,4 +199,4 @@ public class Country implements Parcelable {
public String toString() {
return "Country {ISO=" + mCountryIso + ", source=" + mSource + ", time=" + mTimestamp + "}";
}
}
}
@@ -134,4 +134,4 @@ public class CountryDetector {
}
}
}
}
}
@@ -27,4 +27,4 @@ public interface CountryListener {
* @param country the changed or detected country.
*/
void onCountryDetected(Country country);
}
}
@@ -38,4 +38,4 @@ interface ICountryDetector
* Remove the listener
*/
void removeCountryListener(ICountryListener listener);
}
}
@@ -23,4 +23,4 @@ package android.location;
interface ICountryListener
{
void onCountryDetected(Country country);
}
}
@@ -14,4 +14,4 @@ public class APN {
public APN() {
}
}
}
@@ -7,4 +7,4 @@ public class MMSPart {
public String MimeType = "";
public byte[] Data;
public Uri Path;
}
}
@@ -0,0 +1,105 @@
package com.mariussoft.endlessjabber.sdk;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.net.Uri;
public class EndlessJabberInterface {
/** Checks whether or not EndlessJabber is installed */
public static boolean IsInstalled(Context ctx) {
PackageManager pm = ctx.getPackageManager();
try {
pm.getPackageInfo("com.mariussoft.endlessjabber", PackageManager.GET_ACTIVITIES);
return true;
} catch (NameNotFoundException e) {
return false;
}
}
/** Opens up GooglePlay and redirects it to the EndlessJabber app */
public static void OpenGooglePlayLink(Context ctx) {
final String appPackageName = "com.mariussoft.endlessjabber";
try {
ctx.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
} catch (android.content.ActivityNotFoundException anfe) {
ctx.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=" + appPackageName)));
}
}
/** Launches EndlessJabber */
public static void LaunchEndlessJabber(Context ctx) {
Intent intent = ctx.getPackageManager().getLaunchIntentForPackage("com.mariussoft.endlessjabber");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ctx.startActivity(intent);
}
/**
* Enables integration by specifying which class to call
*
* @param context
* The context to use
* @param concreteImplementation
* The concrete implementation to call on events
* @param sendSMS
* If true, your app will be responsible for sending SMS messages
* as well as presisting them to the SMS repository
* @param sendMMS
* If true, your app will be responsible for sending & persisting
* MMS messages to the MMS repository
* @throws Exception
*/
@SuppressWarnings("rawtypes")
public static void EnableIntegration(Context context, Class concreteImplementation, boolean sendSMS, boolean sendMMS) throws Exception {
Class<?> clazz = concreteImplementation;
if (!IEndlessJabberImplementation.class.isAssignableFrom(clazz)) {
throw new Exception("Class must implement IEndlessJabberImplementation");
}
SharedPreferences.Editor editor = context.getSharedPreferences("EndlessJabberSDK", Context.MODE_PRIVATE).edit();
editor.putString("InterfaceClass", concreteImplementation.getName());
editor.putBoolean("SendSMS", sendSMS);
editor.putBoolean("SendMMS", sendMMS);
editor.commit();
SendInfoToEndlessJabber(context);
}
/** Disables integration */
@SuppressWarnings("rawtypes")
public static void DisableIntegration(Context context, Class nameOfImplementation) {
SharedPreferences.Editor editor = context.getSharedPreferences("EndlessJabberSDK", Context.MODE_PRIVATE).edit();
editor.clear();
editor.commit();
SendInfoToEndlessJabber(context);
}
/**
* Refresh integration info with EndlessJabber
*
* @param ctx
* Context to use
*/
static void SendInfoToEndlessJabber(Context context) {
String EndlessJabber_INTENT = "com.mariussoft.endlessjabber.action.extendResponse";
SharedPreferences prefs = context.getSharedPreferences("EndlessJabberSDK", Context.MODE_PRIVATE);
Intent i = new Intent();
i.setAction(EndlessJabber_INTENT);
i.putExtra("Action", "UpdateInfo");
i.putExtra("PackageName", context.getPackageName());
i.putExtra("Enabled", prefs.contains("InterfaceClass"));
if (prefs.contains("InterfaceClass")) {
i.putExtra("SendSMS", prefs.getBoolean("SendSMS", false));
i.putExtra("SendMMS", prefs.getBoolean("SendMMS", false));
}
context.sendBroadcast(i);
}
}
@@ -0,0 +1,22 @@
package com.mariussoft.endlessjabber.sdk;
import android.content.Context;
import android.content.Intent;
public class EndlessJabberReceiver extends WakefulBroadcastReceiver {
public static final String EndlessJabber_INTENT = "com.mariussoft.endlessjabber.action.extend";
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(EndlessJabber_INTENT)) {
// This is the Intent to deliver to our service.
Intent service = new Intent(context, EndlessJabberWakefulService.class);
service.putExtras(intent.getExtras());
startWakefulService(context, service);
}
}
}
@@ -0,0 +1,78 @@
package com.mariussoft.endlessjabber.sdk;
import android.app.IntentService;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
public class EndlessJabberWakefulService extends IntentService {
public EndlessJabberWakefulService() {
super("EndlessJabberWakefulService");
}
@Override
protected void onHandleIntent(Intent intent) {
Context context = getApplicationContext();
// Get the class to call
String implemenationClass = context.getSharedPreferences("EndlessJabberSDK", Context.MODE_PRIVATE).getString("InterfaceClass", null);
if (implemenationClass == null) {
return;
}
IEndlessJabberImplementation instanceOfMyClass;
try {
instanceOfMyClass = (IEndlessJabberImplementation) Class.forName(implemenationClass).newInstance();
Bundle extras = intent.getExtras();
switch (extras.getString("Action")) {
case "UpdateRead": {
long time = extras.getLong("Time");
int conversationID = extras.getInt("ConversationID");
instanceOfMyClass.UpdateReadMessages(context, time, conversationID);
break;
}
case "DeleteThread": {
int conversationID = extras.getInt("ConversationID");
instanceOfMyClass.DeleteThread(context, conversationID);
break;
}
case "SendMMS": {
boolean save = extras.getBoolean("Save");
boolean send = extras.getBoolean("Send");
String[] Recipients = extras.getStringArray("Recipients");
MMSPart[] parts = new MMSPart[extras.getParcelableArray("Parts").length];
for (int i = 0; i < parts.length; i++) {
parts[i] = (MMSPart) extras.getParcelableArray("Parts")[i];
}
instanceOfMyClass.SendMMS(context, Recipients, parts, extras.getString("Subject"), save, send);
break;
}
case "SendSMS": {
boolean send = extras.getBoolean("Send");
String[] Recipients = extras.getStringArray("Recipients");
String message = extras.getString("Message");
instanceOfMyClass.SendSMS(context, Recipients, message, send);
break;
}
case "UpdateInfo": {
EndlessJabberInterface.SendInfoToEndlessJabber(context);
break;
}
}
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
}
EndlessJabberReceiver.completeWakefulIntent(intent);
}
}
@@ -0,0 +1,50 @@
package com.mariussoft.endlessjabber.sdk;
import android.content.Context;
/**
*
* Interface to implement EndlessJabber integration
*
*/
public interface IEndlessJabberImplementation {
/**
* Update all messages in the SMS/MMS repositories as read where the time <= the provided time as well as where the threadID matches the provided ID
* @param context The context to utilize
* @param time The 'time' in the SMS database to use when marking messages as read
* (NOTE* for MMS divide by 1000 as MMS repository stores times as 1/1000th of the SMS)
* @param threadID The ID of the thread in the SMS/MMS repositories to update
*/
void UpdateReadMessages(Context context, long time, int threadID);
/**
* Delete any messages/conversations in the SMS/MMS repositories where the threadID matches the provided ID
* @param context The context to utilize
* @param threadID The ID of the thread in the SMS/MMS repositories to delete
*/
void DeleteThread(Context context,int threadID);
/**
* Method gets called when EndlessJabber is requested to send an MMS message via the web app
* @param context The context to utilize
* @param recipients List of recipients to send message to
* @param parts The message parts to send along with message
* @param subject The MMS subject of the message
* @param save Whether or not to save the MMS to the MMS repository
* @param send If true, send the message along with saving it to the MMS repository
* NOTE: On KitKat save will be true only when enabled in the SDK & your app is the default messaging app on the system
*
* If both save & send are false, this call is only for informational purposes (e.g. modify notifications, update UI, etc...)
*/
void SendMMS(Context context, String[] recipients, MMSPart[] parts, String subject, boolean save, boolean send);
/**
* Method gets called when EndlessJabber is requested to send an SMS message via the web app
* @param context The context to utilize
* @param recipients List of recipients to send message to
* @param message The message to send
* @param send If true, send the message along with saving it to the SMS repository, otherwise this is only for informational purposes (e.g. modify notifications, update UI, etc...)
*/
void SendSMS(Context context, String[] recipients, String message, boolean send);
}
@@ -0,0 +1,57 @@
package com.mariussoft.endlessjabber.sdk;
import android.os.Parcel;
import android.os.Parcelable;
/**
*
* An MMS attachment
*
*/
public class MMSPart implements Parcelable {
/**
* The name of the MMS attachment
*/
public String Name = "";
/**
* The MimeType of the MMS attachment
*/
public String MimeType = "";
/**
* The byte[] of the MMS attachment
*/
public byte[] Data;
public MMSPart() {
}
public MMSPart(Parcel parcel) {
Name = parcel.readString();
MimeType = parcel.readString();
Data = new byte[parcel.readInt()];
parcel.readByteArray(Data);
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int arg1) {
dest.writeString(Name);
dest.writeString(MimeType);
dest.writeInt(Data.length);
dest.writeByteArray(Data);
}
public static final Parcelable.Creator<MMSPart> CREATOR = new Parcelable.Creator<MMSPart>() {
public MMSPart createFromParcel(Parcel in) {
return new MMSPart(in);
}
public MMSPart[] newArray(int size) {
return new MMSPart[size];
}
};
}
@@ -0,0 +1,135 @@
package com.mariussoft.endlessjabber.sdk;
/*
* Copyright (C) 2013 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.
*/
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.PowerManager;
import android.util.Log;
import android.util.SparseArray;
/**
* Helper for the common pattern of implementing a {@link BroadcastReceiver}
* that receives a device wakeup event and then passes the work off
* to a {@link android.app.Service}, while ensuring that the
* device does not go back to sleep during the transition.
*
* <p>This class takes care of creating and managing a partial wake lock
* for you; you must request the {@link android.Manifest.permission#WAKE_LOCK}
* permission to use it.</p>
*
* <h3>Example</h3>
*
* <p>A {@link WakefulBroadcastReceiver} uses the method
* {@link WakefulBroadcastReceiver#startWakefulService startWakefulService()}
* to start the service that does the work. This method is comparable to
* {@link android.content.Context#startService startService()}, except that
* the {@link WakefulBroadcastReceiver} is holding a wake lock when the service
* starts. The intent that is passed with
* {@link WakefulBroadcastReceiver#startWakefulService startWakefulService()}
* holds an extra identifying the wake lock.</p>
*
* {@sample development/samples/Support4Demos/src/com/example/android/supportv4/content/SimpleWakefulReceiver.java complete}
*
* <p>The service (in this example, an {@link android.app.IntentService}) does
* some work. When it is finished, it releases the wake lock by calling
* {@link WakefulBroadcastReceiver#completeWakefulIntent
* completeWakefulIntent(intent)}. The intent it passes as a parameter
* is the same intent that the {@link WakefulBroadcastReceiver} originally
* passed in.</p>
*
* {@sample development/samples/Support4Demos/src/com/example/android/supportv4/content/SimpleWakefulService.java complete}
*/
public abstract class WakefulBroadcastReceiver extends BroadcastReceiver {
private static final String EXTRA_WAKE_LOCK_ID = "android.support.content.wakelockid";
private static final SparseArray<PowerManager.WakeLock> mActiveWakeLocks
= new SparseArray<PowerManager.WakeLock>();
private static int mNextId = 1;
/**
* Do a {@link android.content.Context#startService(android.content.Intent)
* Context.startService}, but holding a wake lock while the service starts.
* This will modify the Intent to hold an extra identifying the wake lock;
* when the service receives it in {@link android.app.Service#onStartCommand
* Service.onStartCommand}, it should pass back the Intent it receives there to
* {@link #completeWakefulIntent(android.content.Intent)} in order to release
* the wake lock.
*
* @param context The Context in which it operate.
* @param intent The Intent with which to start the service, as per
* {@link android.content.Context#startService(android.content.Intent)
* Context.startService}.
*/
public static ComponentName startWakefulService(Context context, Intent intent) {
synchronized (mActiveWakeLocks) {
int id = mNextId;
mNextId++;
if (mNextId <= 0) {
mNextId = 1;
}
intent.putExtra(EXTRA_WAKE_LOCK_ID, id);
ComponentName comp = context.startService(intent);
if (comp == null) {
return null;
}
PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
"wake:" + comp.flattenToShortString());
wl.setReferenceCounted(false);
wl.acquire(60*1000);
mActiveWakeLocks.put(id, wl);
return comp;
}
}
/**
* Finish the execution from a previous {@link #startWakefulService}. Any wake lock
* that was being held will now be released.
*
* @param intent The Intent as originally generated by {@link #startWakefulService}.
* @return Returns true if the intent is associated with a wake lock that is
* now released; returns false if there was no wake lock specified for it.
*/
public static boolean completeWakefulIntent(Intent intent) {
final int id = intent.getIntExtra(EXTRA_WAKE_LOCK_ID, 0);
if (id == 0) {
return false;
}
synchronized (mActiveWakeLocks) {
PowerManager.WakeLock wl = mActiveWakeLocks.get(id);
if (wl != null) {
wl.release();
mActiveWakeLocks.remove(id);
return true;
}
// We return true whether or not we actually found the wake lock
// the return code is defined to indicate whether the Intent contained
// an identifier for a wake lock that it was supposed to match.
// We just log a warning here if there is no wake lock found, which could
// happen for example if this function is called twice on the same
// intent or the process is killed and restarted before processing the intent.
Log.w("WakefulBroadcastReceiver", "No active wake lock id #" + id);
return true;
}
}
}
@@ -4,6 +4,7 @@ import android.util.Log;
import android.view.View;
import com.moez.QKSMS.R;
import com.moez.QKSMS.data.Conversation;
import com.moez.QKSMS.transaction.SmsHelper;
import com.moez.QKSMS.ui.MainActivity;
import com.moez.QKSMS.ui.conversationlist.ConversationListAdapter;
import com.moez.QKSMS.ui.dialog.DefaultSmsHelper;
@@ -22,6 +23,27 @@ public class DialogHelper {
showDeleteConversationDialog(context, threadIds);
}
public static void showDeleteFailedMessagesDialog(final MainActivity context, final long threadId) {
new DefaultSmsHelper(context, null, R.string.not_default_delete).showIfNotDefault(null);
new QKDialog()
.setContext(context)
.setTitle(R.string.delete_all_failed)
.setMessage(R.string.delete_all_failed_confirmation)
.setPositiveButton(R.string.yes, new View.OnClickListener() {
@Override
public void onClick(View v) {
new Thread(new Runnable() {
public void run() {
SmsHelper.deleteFailedMessages(context, threadId);
}
}).start();
}
}).setNegativeButton(R.string.cancel, null)
.show(context.getFragmentManager(), QKDialog.CONFIRMATION_TAG);
}
public static void showDeleteConversationDialog(final MainActivity context, final List<Long> threadIds) {
new DefaultSmsHelper(context, null, R.string.not_default_delete).showIfNotDefault(null);
@@ -70,4 +92,5 @@ public class DialogHelper {
}).setNegativeButton(R.string.cancel, null)
.show(context.getFragmentManager(), QKDialog.CONFIRMATION_TAG);
}
}
@@ -121,12 +121,12 @@ public class FontManager {
}
// Otherwise, get the heavy font weight.
if (fontWeight == RobotoTypefaceManager.TextWeight.LIGHT) {
return RobotoTypefaceManager.TextWeight.NORMAL;
} else if (fontFamily == RobotoTypefaceManager.FontFamily.ROBOTO) {
return RobotoTypefaceManager.TextWeight.MEDIUM;
if (fontWeight == TypefaceManager.TextWeight.LIGHT) {
return TypefaceManager.TextWeight.NORMAL;
} else if (fontFamily == TypefaceManager.FontFamily.ROBOTO || fontFamily == TypefaceManager.FontFamily.LATO) {
return TypefaceManager.TextWeight.MEDIUM;
} else {
return RobotoTypefaceManager.TextWeight.BOLD;
return TypefaceManager.TextWeight.BOLD;
}
}
}
@@ -29,13 +29,13 @@ import com.moez.QKSMS.R;
*
* @author Evgeny Shishkin
*/
public class RobotoTextViewUtils {
public class TextViewUtils {
private RobotoTextViewUtils() {
private TextViewUtils() {
}
/**
* Typeface initialization using the attributes. Used in RobotoTextView constructor.
* Typeface initialization using the attributes. Used in TextView constructor.
*
* @param textView The roboto text view
* @param context The context the widget is running in, through which it can
@@ -49,15 +49,15 @@ public class RobotoTextViewUtils {
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RobotoTextView);
if (a.hasValue(R.styleable.RobotoTextView_typeface)) {
int typefaceValue = a.getInt(R.styleable.RobotoTextView_typeface, RobotoTypefaceManager.Typeface.ROBOTO_REGULAR);
typeface = RobotoTypefaceManager.obtainTypeface(context, typefaceValue);
int typefaceValue = a.getInt(R.styleable.RobotoTextView_typeface, TypefaceManager.Typeface.ROBOTO_REGULAR);
typeface = TypefaceManager.obtainTypeface(context, typefaceValue);
}
a.recycle();
}
if (typeface == null) {
typeface = RobotoTypefaceManager.obtainTypeface(context, RobotoTypefaceManager.Typeface.ROBOTO_REGULAR);
typeface = TypefaceManager.obtainTypeface(context, TypefaceManager.Typeface.ROBOTO_REGULAR);
}
setTypeface(textView, typeface);
@@ -86,4 +86,4 @@ public class RobotoTextViewUtils {
paint.setTypeface(typeface);
}
}
}
@@ -6,7 +6,7 @@ import android.util.SparseArray;
/**
* Stripped down version of https://github.com/johnkil/Android-RobotoTextView/blob/master/robototextview/src/main/java/com/devspark/robototextview/util/RobotoTypefaceManager.java
*/
public class RobotoTypefaceManager {
public class TypefaceManager {
private final static SparseArray<android.graphics.Typeface> mTypefaces = new SparseArray<>();
@@ -113,6 +113,58 @@ public class RobotoTypefaceManager {
throw new IllegalArgumentException("`textWeight` attribute value " + textWeight +
" is not supported for this font family " + fontFamily);
}
} else if (fontFamily == FontFamily.LATO) {
if (textWeight == TextWeight.NORMAL) {
switch (textStyle) {
case TextStyle.NORMAL:
typeface = Typeface.LATO_REGULAR;
break;
default:
throw new IllegalArgumentException("`textStyle` attribute value " + textStyle +
" is not supported for this fontFamily " + fontFamily +
" and textWeight " + textWeight);
}
} else if (textWeight == TextWeight.THIN) {
switch (textStyle) {
case TextStyle.NORMAL:
typeface = Typeface.LATO_THIN;
break;
default:
throw new IllegalArgumentException("`textStyle` attribute value " + textStyle +
" is not supported for this fontFamily " + fontFamily +
" and textWeight " + textWeight);
}
} else if (textWeight == TextWeight.LIGHT) {
switch (textStyle) {
case TextStyle.NORMAL:
typeface = Typeface.LATO_LIGHT;
break;
default:
throw new IllegalArgumentException("`textStyle` attribute value " + textStyle +
" is not supported for this fontFamily " + fontFamily +
" and textWeight " + textWeight);
}
} else if (textWeight == TextWeight.MEDIUM) {
switch (textStyle) {
case TextStyle.NORMAL:
typeface = Typeface.LATO_MEDIUM;
break;
default:
throw new IllegalArgumentException("`textStyle` attribute value " + textStyle +
" is not supported for this fontFamily " + fontFamily +
" and textWeight " + textWeight);
}
} else if (textWeight == TextWeight.BOLD) {
switch (textStyle) {
default:
throw new IllegalArgumentException("`textStyle` attribute value " + textStyle +
" is not supported for this fontFamily " + fontFamily +
" and textWeight " + textWeight);
}
} else {
throw new IllegalArgumentException("`textWeight` attribute value " + textWeight +
" is not supported for this font family " + fontFamily);
}
} else {
throw new IllegalArgumentException("Unknown `fontFamily` attribute value " + fontFamily);
}
@@ -143,6 +195,18 @@ public class RobotoTypefaceManager {
case Typeface.ROBOTO_CONDENSED_BOLD:
typefacePath = "fonts/RobotoCondensed-Bold.ttf";
break;
case Typeface.LATO_THIN:
typefacePath = "fonts/Lato-Hairline.ttf";
break;
case Typeface.LATO_LIGHT:
typefacePath = "fonts/Lato-Light.ttf";
break;
case Typeface.LATO_REGULAR:
typefacePath = "fonts/Lato-Regular.ttf";
break;
case Typeface.LATO_MEDIUM:
typefacePath = "fonts/Lato-Bold.ttf";
break;
default:
throw new IllegalArgumentException("Unknown `typeface` attribute value " + typefaceValue);
}
@@ -158,11 +222,16 @@ public class RobotoTypefaceManager {
public final static int ROBOTO_CONDENSED_LIGHT = 12;
public final static int ROBOTO_CONDENSED_REGULAR = 14;
public final static int ROBOTO_CONDENSED_BOLD = 16;
public final static int LATO_THIN = 22;
public final static int LATO_LIGHT = 24;
public final static int LATO_REGULAR = 26;
public final static int LATO_MEDIUM = 28;
}
public class FontFamily {
public static final int ROBOTO = 0;
public static final int ROBOTO_CONDENSED = 1;
public static final int LATO = 2;
}
public class TextWeight {
@@ -177,4 +246,4 @@ public class RobotoTypefaceManager {
public static final int NORMAL = 0;
}
}
}
@@ -846,4 +846,4 @@ public class Emojis {
public static final String LARGE_BLUE_DIAMOND = "large_blue_diamond";
public static final String SMALL_ORANGE_DIAMOND = "small_orange_diamond";
public static final String SMALL_BLUE_DIAMOND = "small_blue_diamond";
}
}
@@ -257,4 +257,4 @@ public class DraftCache {
String s = String.format(format, args);
Log.d(TAG, "[DraftCache/" + Thread.currentThread().getId() + "] " + s);
}
}
}
@@ -4,91 +4,107 @@ import android.content.Context;
import android.content.SharedPreferences;
import android.text.format.DateUtils;
import com.moez.QKSMS.QKSMSApp;
import com.moez.QKSMS.R;
import com.moez.QKSMS.ui.MainActivity;
import com.moez.QKSMS.ui.settings.SettingsFragment;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
public abstract class DateFormatter {
public static String getConversationTimestamp(Context context, long date) {
SharedPreferences prefs = MainActivity.getPrefs(context);
SimpleDateFormat formatter = new SimpleDateFormat("D, y");
SimpleDateFormat formatter;
if (formatter.format(date).equals(formatter.format(System.currentTimeMillis()))) {
formatter = new SimpleDateFormat(prefs.getBoolean(SettingsFragment.TIMESTAMPS_24H, false) ? "H:mm" : "h:mm a");
if (isSameDay(date)) {
formatter = accountFor24HourTime(context, new SimpleDateFormat("h:mm a"));
} else if (isSameWeek(date)) {
formatter = new SimpleDateFormat("EEE");
} else if (isSameYear(date)) {
formatter = new SimpleDateFormat("MMM d");
} else {
formatter = new SimpleDateFormat("w, y");
if (formatter.format(date).equals(formatter.format(System.currentTimeMillis()))) {
formatter = new SimpleDateFormat("EEE");
} else {
formatter = new SimpleDateFormat("y");
if (formatter.format(date).equals(formatter.format(System.currentTimeMillis()))) {
formatter = new SimpleDateFormat("MMM d");
} else {
formatter = new SimpleDateFormat("MMM d y");
}
}
formatter = new SimpleDateFormat("MMM d y");
}
return formatter.format(date);
}
public static String getMessageTimestamp(Context context, long date) {
private static boolean isSameDay(long date) {
SimpleDateFormat formatter = new SimpleDateFormat("D, y");
return formatter.format(date).equals(formatter.format(System.currentTimeMillis()));
}
private static boolean isSameWeek(long date) {
SimpleDateFormat formatter = new SimpleDateFormat("w, y");
return formatter.format(date).equals(formatter.format(System.currentTimeMillis()));
}
private static boolean isSameYear(long date) {
SimpleDateFormat formatter = new SimpleDateFormat("y");
return formatter.format(date).equals(formatter.format(System.currentTimeMillis()));
}
private static boolean isYesterday(long date) {
SimpleDateFormat formatter = new SimpleDateFormat("yD");
return Integer.parseInt(formatter.format(date)) + 1 == Integer.parseInt(formatter.format(System.currentTimeMillis()));
}
public static SimpleDateFormat accountFor24HourTime(Context context, SimpleDateFormat input) { //pass in 12 hour time. If needed, change to 24 hr.
SharedPreferences prefs = MainActivity.getPrefs(context);
boolean isUsing24HourTime = prefs.getBoolean(SettingsFragment.TIMESTAMPS_24H, false);
SimpleDateFormat formatter = new SimpleDateFormat("D, y");
if (formatter.format(date).equals(formatter.format(System.currentTimeMillis()))) {
return new SimpleDateFormat(isUsing24HourTime ? "H:mm" : "h:mm a").format(date);
if (isUsing24HourTime) {
return new SimpleDateFormat(input.toPattern().replace('h', 'H').replaceAll(" a", ""));
} else return input;
}
public static SimpleDateFormat accountForFlippedDayMonth(SimpleDateFormat input) { //Pass in MMM d, if needed, change to d MMM. fix https://github.com/qklabs/qksms/issues/128.
boolean shouldBeFlipped = !(Locale.getDefault().equals(Locale.US) || Locale.getDefault().equals(Locale.CANADA));
if (shouldBeFlipped) {
return new SimpleDateFormat(input.toPattern().replaceAll("MMM", "temp").replaceAll("d", "MMM").replaceAll("temp", "d"));
} else return input;
}
public static String getMessageTimestamp(Context context, long date) {
if (isSameDay(date)) {
return accountFor24HourTime(context, new SimpleDateFormat("h:mm a")).format(date);
} else if (isYesterday(date)) {
return context.getString(R.string.date_yesterday) +" " + accountFor24HourTime(context, new SimpleDateFormat("h:mm a")).format(date);
} else if (isSameWeek(date)) {
return accountFor24HourTime(context, new SimpleDateFormat("EEE h:mm a")).format(date);
} else if (isSameYear(date)) {
return accountForFlippedDayMonth(accountFor24HourTime(context, new SimpleDateFormat("MMM d, h:mm a"))).format(date);
}
// Yesterday
formatter = new SimpleDateFormat("yD");
if (Integer.parseInt(formatter.format(date)) + 1 == Integer.parseInt(formatter.format(System.currentTimeMillis()))) {
return "Yesterday " + new SimpleDateFormat(isUsing24HourTime ? "H:mm" : "h:mm a").format(date);
}
// In the same week
formatter = new SimpleDateFormat("w, y");
if (formatter.format(date).equals(formatter.format(System.currentTimeMillis()))) {
return new SimpleDateFormat(isUsing24HourTime ? "EEE H:mm" : "EEE h:mm a").format(date);
}
// In the same year
formatter = new SimpleDateFormat("y");
if (formatter.format(date).equals(formatter.format(System.currentTimeMillis()))) {
return new SimpleDateFormat(isUsing24HourTime ? "MMM d, H:mm" : "MMM d, h:mm a").format(date);
}
return new SimpleDateFormat(isUsing24HourTime ? "MMM d y, H:mm" : "MMM d y, h:mm a").format(date);
return accountForFlippedDayMonth(accountFor24HourTime(context, new SimpleDateFormat("MMM d y, h:mm a"))).format(date);
}
public static String getDate(Context context, long date) {
SharedPreferences prefs = MainActivity.getPrefs(context);
SimpleDateFormat formatter = new SimpleDateFormat(prefs.getBoolean(SettingsFragment.TIMESTAMPS_24H, false) ? "MMMM d y, H:mm:ss" : "MMMM d y, h:mm:ss a");
SimpleDateFormat formatter = accountForFlippedDayMonth(accountFor24HourTime(context, new SimpleDateFormat("MMMM d y, h:mm:ss a")));
return formatter.format(date);
}
public static String getRelativeTimestamp(long date) {
String relativeTimestamp = (String) DateUtils.getRelativeTimeSpanString(date);
if (relativeTimestamp.equals("in 0 minutes") || relativeTimestamp.equals("0 minutes ago"))
return "Just now";
return QKSMSApp.getApplication().getString(com.moez.QKSMS.R.string.date_just_now);
return relativeTimestamp;
}
public static String getSummaryTimestamp(Context context, String time) {
SharedPreferences prefs = MainActivity.getPrefs(context);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("H:mm");
Date date;
try {
date = simpleDateFormat.parse(time);
simpleDateFormat = prefs.getBoolean(SettingsFragment.TIMESTAMPS_24H, false) ? new SimpleDateFormat("H:mm") : new SimpleDateFormat("h:mm a");
simpleDateFormat = accountFor24HourTime(context, new SimpleDateFormat("H:mm"));
time = simpleDateFormat.format(date);
} catch (Exception e) {
} catch (ParseException e) {
e.printStackTrace();
}
@@ -120,4 +120,4 @@ public class AndroidCustomField extends VCardProperty {
warnings.add(new Warning("Items must contain exactly one value."));
}
}
}
}
@@ -557,4 +557,4 @@ public class ContactOperations {
return contentValues;
}
}
}
}
@@ -284,4 +284,4 @@ public class DataMappings {
private DataMappings(){
//hide constructor
}
}
}
@@ -1182,4 +1182,4 @@ public class Contact {
private static void log(String msg) {
Log.d(TAG, msg);
}
}
}
@@ -17,7 +17,7 @@ import android.provider.BaseColumns;
import android.provider.ContactsContract;
import android.telephony.PhoneNumberUtils;
import android.util.Log;
import com.moez.QKSMS.common.RobotoTypefaceManager;
import com.moez.QKSMS.common.TypefaceManager;
import com.moez.QKSMS.common.utils.Units;
import com.moez.QKSMS.ui.MainActivity;
import com.moez.QKSMS.ui.ThemeManager;
@@ -205,7 +205,7 @@ public class ContactHelper {
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setColor(Color.WHITE);
paint.setTypeface(RobotoTypefaceManager.obtainTypeface(context, RobotoTypefaceManager.Typeface.ROBOTO_LIGHT));
paint.setTypeface(TypefaceManager.obtainTypeface(context, TypefaceManager.Typeface.ROBOTO_LIGHT));
paint.setTextSize(length / 2);
Rect bounds = new Rect();
@@ -175,4 +175,4 @@ public class ContactList extends ArrayList<Contact> {
private void log(String msg) {
Log.d(LogTag.TAG, "[ContactList] " + msg);
}
}
}
@@ -1468,4 +1468,4 @@ public class Conversation {
}
return address;
}
}
}
@@ -318,4 +318,4 @@ public class ConversationLegacy {
}
}.execute((Void[]) null);
}
}
}
@@ -193,4 +193,4 @@ public class Message {
e.printStackTrace();
}
}
}
}
@@ -273,4 +273,4 @@ public class RecipientIdCache {
}.start();
}
}
}
@@ -133,4 +133,4 @@ class CountedDataInputStream extends FilterInputStream {
readOrThrow(buf);
return new String(buf, charset);
}
}
}
@@ -20,4 +20,4 @@ public class ExifInvalidFormatException extends Exception {
public ExifInvalidFormatException(String meg) {
super(meg);
}
}
}
@@ -40,4 +40,4 @@ public class IabException extends Exception {
/** Returns the IAB result (error) that this exception signals. */
public IabResult getResult() { return mResult; }
}
}
@@ -18,4 +18,4 @@ public class MarkSeenService extends IntentService {
SmsHelper.markMmsSeen(this);
NotificationManager.update(this);
}
}
}
@@ -542,6 +542,35 @@ public class SmsHelper {
return messages;
}
public static List<Message> deleteFailedMessages(Context context, long threadId) {
Log.d(TAG, "Deleting failed messages");
List<Message> messages = new ArrayList<Message>();
try {
cursor = context.getContentResolver().query(SMS_CONTENT_PROVIDER, new String[]{COLUMN_ID}, FAILED_SELECTION, null, sortDateDesc);
cursor.moveToFirst();
for (int i = 0; i < cursor.getCount(); i++) {
messages.add(new Message(context, cursor.getLong(cursor.getColumnIndexOrThrow(COLUMN_ID))));
cursor.moveToNext();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
cursor.close();
}
for (Message m : messages)
{
if(m.getThreadId() == threadId) {
Log.d(TAG, "Deleting failed message to " + m.getName() + "\n Body: " + m.getBody());
m.delete();
}
}
return messages;
}
/**
* Add an SMS to the given URI.
*
@@ -51,8 +51,9 @@ public class ConversationListFragment extends QKFragment implements LoaderManage
private final int MENU_VIEW_DETAILS = 3;
private final int MENU_MARK_READ = 4;
private final int MENU_MARK_UNREAD = 5;
private final int MENU_DELETE_CONVERSATION = 6;
private final int MENU_MULTI_SELECT = 7;
private final int MENU_DELETE_FAILED = 6;
private final int MENU_DELETE_CONVERSATION = 7;
private final int MENU_MULTI_SELECT = 8;
private RecyclerView mRecyclerView;
private FloatingActionButton mFab;
@@ -193,6 +194,10 @@ public class ConversationListFragment extends QKFragment implements LoaderManage
dialog.addMenuItem(R.string.menu_notification_settings, MENU_NOTIFICATION_SETTINGS);
dialog.addMenuItem(R.string.menu_view_details, MENU_VIEW_DETAILS);
if (conversation.hasError()) {
dialog.addMenuItem(R.string.delete_all_failed, MENU_DELETE_FAILED);
}
dialog.addMenuItem(R.string.menu_delete_conversation, MENU_DELETE_CONVERSATION);
dialog.buildMenu(new AdapterView.OnItemClickListener() {
@@ -233,6 +238,10 @@ public class ConversationListFragment extends QKFragment implements LoaderManage
case MENU_DELETE_CONVERSATION:
DialogHelper.showDeleteConversationDialog((MainActivity) mContext, threadId);
break;
case MENU_DELETE_FAILED:
//Deletes all failed messages from all conversations
DialogHelper.showDeleteFailedMessagesDialog((MainActivity) mContext, threadId);
break;
}
}
}).show(((MainActivity) mContext).getFragmentManager(), "conversation options");
@@ -159,4 +159,4 @@ public class AsyncDialog {
}
}
}
}
}
@@ -60,4 +60,4 @@ public class MessageItemCache extends LruCache<Long, MessageItem> {
}
return item;
}
}
}
@@ -1,5 +1,6 @@
package com.moez.QKSMS.ui.messagelist;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.LoaderManager;
import android.content.ClipData;
@@ -218,8 +219,8 @@ public class MessageListFragment extends QKContentFragment implements ActivityLa
}
@Override
public void onStart() {
super.onStart();
public void onAttach(Activity activity) {
super.onAttach(activity);
// Make sure to notify that this conversation has been opened. This will mark it as read, load new drafts, etc.
onOpenConversation();
@@ -234,4 +234,4 @@ public class MessageListViewHolder extends ClickyViewHolder<MessageItem> impleme
}
}
}
}
}
@@ -148,4 +148,4 @@ public class QKComposeActivity extends QKPopupActivity implements ComposeView.On
mStarredContactsView.collapse();
mCompose.requestReplyTextFocus();
}
}
}
@@ -64,4 +64,4 @@ class ViewHolder {
int position;
QKTextView mResponseIndex;
QKEditText mResponse;
}
}
@@ -10,7 +10,7 @@ import com.android.ex.chips.RecipientEditTextView;
import com.moez.QKSMS.interfaces.LiveView;
import com.moez.QKSMS.common.FontManager;
import com.moez.QKSMS.common.LiveViewManager;
import com.moez.QKSMS.common.RobotoTypefaceManager;
import com.moez.QKSMS.common.TypefaceManager;
import com.moez.QKSMS.ui.MainActivity;
import com.moez.QKSMS.ui.ThemeManager;
import com.moez.QKSMS.ui.settings.SettingsFragment;
@@ -57,8 +57,8 @@ public class AutoCompleteContactView extends RecipientEditTextView implements Li
@Override
public void refresh() {
setTypeface(RobotoTypefaceManager.obtainTypeface(mContext, FontManager.getFontFamily(mContext),
FontManager.getFontWeight(mContext, false), RobotoTypefaceManager.TextStyle.NORMAL));
setTypeface(TypefaceManager.obtainTypeface(mContext, FontManager.getFontFamily(mContext),
FontManager.getFontWeight(mContext, false), TypefaceManager.TextStyle.NORMAL));
setTextSize(TypedValue.COMPLEX_UNIT_SP, FontManager.getTextSize(mContext, FontManager.TEXT_TYPE_PRIMARY));
setTextColor(ThemeManager.getTextOnBackgroundPrimary());
@@ -24,7 +24,7 @@ import android.widget.ImageView;
import com.moez.QKSMS.R;
import com.moez.QKSMS.interfaces.LiveView;
import com.moez.QKSMS.common.LiveViewManager;
import com.moez.QKSMS.common.RobotoTypefaceManager;
import com.moez.QKSMS.common.TypefaceManager;
import com.moez.QKSMS.common.utils.ImageUtils;
import com.moez.QKSMS.common.utils.PhoneNumberUtils;
import com.moez.QKSMS.common.utils.Units;
@@ -77,7 +77,7 @@ public class AvatarView extends ImageView implements View.OnClickListener, LiveV
mPaint.setTextSize(Units.dpToPx(context, 32));
mPaint.setTextAlign(Paint.Align.CENTER);
mPaint.setAntiAlias(true);
mPaint.setTypeface(RobotoTypefaceManager.obtainTypeface(context, RobotoTypefaceManager.Typeface.ROBOTO_LIGHT));
mPaint.setTypeface(TypefaceManager.obtainTypeface(context, TypefaceManager.Typeface.ROBOTO_LIGHT));
final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AvatarView, defStyle, 0);
for (int i = 0; i < a.getIndexCount(); i++) {
@@ -357,7 +357,7 @@ public class ComposeView extends LinearLayout implements View.OnClickListener, L
if (mButtonState != buttonState) {
mButtonState = buttonState;
float translation = Units.dpToPx(mContext, 16) / 3;
float translation = Units.dpToPx(mContext, 14) / 3;
float barRotation1 = mButtonBar1.getRotation();
float barTranslation1 = mButtonBar1.getTranslationY();
float barRotation2 = mButtonBar2.getRotation();
@@ -367,23 +367,18 @@ public class ComposeView extends LinearLayout implements View.OnClickListener, L
float barRotationTarget2 = mButtonState == SendButtonState.ATTACH ? 90 : 135;
float barTranslationTarget2 = mButtonState == SendButtonState.SEND ? translation : 0;
if (barRotation1 != barRotationTarget1) {
ObjectAnimator.ofFloat(mButtonBar1, "rotation", barRotation1, barRotationTarget1)
.setDuration(ANIMATION_DURATION)
.start();
ObjectAnimator.ofFloat(mButtonBar2, "rotation", barRotation2, barRotationTarget2)
.setDuration(ANIMATION_DURATION)
.start();
}
if (barTranslation1 != barTranslationTarget1) {
ObjectAnimator.ofFloat(mButtonBar1, "translationY", barTranslation1, barTranslationTarget1)
.setDuration(ANIMATION_DURATION)
.start();
ObjectAnimator.ofFloat(mButtonBar2, "translationY", barTranslation2, barTranslationTarget2)
.setDuration(ANIMATION_DURATION)
.start();
}
ObjectAnimator.ofFloat(mButtonBar1, "rotation", barRotation1, barRotationTarget1)
.setDuration(ANIMATION_DURATION)
.start();
ObjectAnimator.ofFloat(mButtonBar2, "rotation", barRotation2, barRotationTarget2)
.setDuration(ANIMATION_DURATION)
.start();
ObjectAnimator.ofFloat(mButtonBar1, "translationY", barTranslation1, barTranslationTarget1)
.setDuration(ANIMATION_DURATION)
.start();
ObjectAnimator.ofFloat(mButtonBar2, "translationY", barTranslation2, barTranslationTarget2)
.setDuration(ANIMATION_DURATION)
.start();
}
}
@@ -77,4 +77,4 @@ public class MessageListRecyclerView extends RecyclerView {
return mContextMenuInfo;
}
}
}
@@ -37,4 +37,4 @@ public class MmsImageView extends ImageView {
super.setImageDrawable(drawable);
}
}
}
}
@@ -11,7 +11,7 @@ import android.util.TypedValue;
import com.moez.QKSMS.interfaces.LiveView;
import com.moez.QKSMS.common.FontManager;
import com.moez.QKSMS.common.LiveViewManager;
import com.moez.QKSMS.common.RobotoTypefaceManager;
import com.moez.QKSMS.common.TypefaceManager;
import com.moez.QKSMS.ui.ThemeManager;
import com.moez.QKSMS.ui.settings.SettingsFragment;
@@ -97,8 +97,8 @@ public class QKEditText extends android.widget.EditText implements LiveView {
// Typeface and colors
int fontFamily = FontManager.getFontFamily(mContext);
int fontWeight = FontManager.getFontWeight(mContext, false);
setTypeface(RobotoTypefaceManager.obtainTypeface(mContext, fontFamily, fontWeight,
RobotoTypefaceManager.TextStyle.NORMAL));
setTypeface(TypefaceManager.obtainTypeface(mContext, fontFamily, fontWeight,
TypefaceManager.TextStyle.NORMAL));
setTextColor(ThemeManager.getTextOnBackgroundPrimary());
setHintTextColor(ThemeManager.getTextOnBackgroundSecondary());
@@ -74,4 +74,4 @@ public class QKLinearLayout extends LinearLayout {
background.mutate().setColorFilter(mBackgroundTint, PorterDuff.Mode.MULTIPLY);
super.setBackgroundDrawable(background);
}
}
}
@@ -11,7 +11,7 @@ import android.widget.TextView;
import com.moez.QKSMS.interfaces.LiveView;
import com.moez.QKSMS.common.FontManager;
import com.moez.QKSMS.common.LiveViewManager;
import com.moez.QKSMS.common.RobotoTypefaceManager;
import com.moez.QKSMS.common.TypefaceManager;
import com.moez.QKSMS.common.utils.MessageUtils;
import com.moez.QKSMS.ui.MainActivity;
import com.moez.QKSMS.ui.ThemeManager;
@@ -162,8 +162,8 @@ public class QKTextView extends TextView implements LiveView {
// Typeface
int fontFamily = FontManager.getFontFamily(mContext);
int fontWeight = FontManager.getFontWeight(mContext, FontManager.getIsFontHeavy(mType));
setTypeface(RobotoTypefaceManager.obtainTypeface(mContext, fontFamily, fontWeight,
RobotoTypefaceManager.TextStyle.NORMAL));
setTypeface(TypefaceManager.obtainTypeface(mContext, fontFamily, fontWeight,
TypefaceManager.TextStyle.NORMAL));
// Text size and color
setTextSize(TypedValue.COMPLEX_UNIT_SP, FontManager.getTextSize(mContext, mType));
@@ -172,4 +172,4 @@ public class QKTextView extends TextView implements LiveView {
// Markdown support enabled
setText(getText(), BufferType.NORMAL);
}
}
}
@@ -3,7 +3,7 @@ package com.moez.QKSMS.ui.view;
import android.content.Context;
import android.support.v7.widget.AppCompatTextView;
import android.util.AttributeSet;
import com.moez.QKSMS.common.RobotoTextViewUtils;
import com.moez.QKSMS.common.TextViewUtils;
public class RobotoTextView extends AppCompatTextView {
@@ -15,7 +15,7 @@ public class RobotoTextView extends AppCompatTextView {
super(context, attrs);
if (!isInEditMode()) {
RobotoTextViewUtils.initTypeface(this, context, attrs);
TextViewUtils.initTypeface(this, context, attrs);
}
}
@@ -23,8 +23,8 @@ public class RobotoTextView extends AppCompatTextView {
super(context, attrs, defStyle);
if (!isInEditMode()) {
RobotoTextViewUtils.initTypeface(this, context, attrs);
TextViewUtils.initTypeface(this, context, attrs);
}
}
}
}
@@ -189,4 +189,4 @@ public class WrappingLinearLayoutManager extends android.support.v7.widget.Linea
recycler.recycleView(child);
}
}
}
@@ -116,4 +116,4 @@ public class ColorPickerDialog extends DialogFragment implements ColorPickerSwat
mPalette.setVisibility(View.GONE);
}
}
}
}
@@ -128,4 +128,4 @@ public class ColorPickerPalette extends TableLayout {
mDescription = resources.getString(R.string.color_swatch_description);
mDescriptionSelected = resources.getString(R.string.color_swatch_description_selected);
}
}
}
@@ -50,4 +50,4 @@ public class ColorPickerSwatch extends FrameLayout implements View.OnClickListen
public interface OnColorSelectedListener {
void onColorSelected(int color);
}
}
}
@@ -40,4 +40,4 @@ public class ColorStateDrawable extends LayerDrawable {
return super.onStateChange(states);
}
}
}
@@ -296,4 +296,4 @@ public class WidgetService extends RemoteViewsService {
}
}
}
}