diff --git a/QKSMS/src/main/AndroidManifest.xml b/QKSMS/src/main/AndroidManifest.xml index 4fff7025..6b7f8d52 100644 --- a/QKSMS/src/main/AndroidManifest.xml +++ b/QKSMS/src/main/AndroidManifest.xml @@ -68,9 +68,8 @@ android:name=".ui.MainActivity" android:icon="@mipmap/ic_launcher_teal" android:label="@string/app_name" - android:launchMode="singleTask" android:logo="@color/transparent" - android:windowSoftInputMode="stateUnchanged|adjustResize"> + android:windowSoftInputMode="adjustResize"> @@ -81,6 +80,8 @@ + + @@ -88,6 +89,20 @@ + + + + + threadIds) { + public static void showDeleteConversationsDialog(final QKActivity context, final Set threadIds) { new DefaultSmsHelper(context, R.string.not_default_delete).showIfNotDefault(null); Set threads = new HashSet<>(threadIds); // Make a copy so the list isn't reset when multi-select is disabled @@ -43,7 +44,9 @@ public class DialogHelper { Conversation.ConversationQueryHandler handler = new Conversation.ConversationQueryHandler(context.getContentResolver()); Conversation.startDelete(handler, 0, false, threads); Conversation.asyncDeleteObsoleteThreads(handler, 0); - context.showMenu(); + if (context instanceof MessageListActivity) { + context.onBackPressed(); + } }) .setNegativeButton(R.string.cancel, null) .show(); diff --git a/QKSMS/src/main/java/com/moez/QKSMS/enums/QKPreference.java b/QKSMS/src/main/java/com/moez/QKSMS/enums/QKPreference.java index f09950ca..747684ed 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/enums/QKPreference.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/enums/QKPreference.java @@ -32,7 +32,6 @@ public enum QKPreference { AVATAR_RECEIVED("pref_key_avatar_received", true), MESSAGE_COUNT("pref_key_message_count", false), - SLIDING_TAB("pref_key_sliding_tab", false), TIMESTAMPS_24H("pref_key_24h", false), // General diff --git a/QKSMS/src/main/java/com/moez/QKSMS/transaction/NotificationManager.java b/QKSMS/src/main/java/com/moez/QKSMS/transaction/NotificationManager.java index 2098a4b1..233ff711 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/transaction/NotificationManager.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/transaction/NotificationManager.java @@ -39,6 +39,7 @@ import com.moez.QKSMS.receiver.WearableIntentReceiver; import com.moez.QKSMS.ui.MainActivity; import com.moez.QKSMS.ui.ThemeManager; import com.moez.QKSMS.ui.messagelist.MessageItem; +import com.moez.QKSMS.ui.messagelist.MessageListActivity; import com.moez.QKSMS.ui.popup.QKComposeActivity; import com.moez.QKSMS.ui.popup.QKReplyActivity; import com.moez.QKSMS.ui.settings.SettingsFragment; @@ -316,7 +317,7 @@ public class NotificationManager { if (failedCursor.getCount() == 1) { title = sRes.getString(R.string.failed_message); Intent intent = new Intent(context, MainActivity.class); - intent.putExtra(MainActivity.EXTRA_THREAD_ID, failedCursor.getLong(0)); + intent.putExtra(MessageListActivity.ARG_THREAD_ID, failedCursor.getLong(0)); PI = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); } else { title = failedCursor.getCount() + " " + sRes.getString(R.string.failed_messages); @@ -475,7 +476,7 @@ public class NotificationManager { final PendingIntent replyPI = PendingIntent.getActivity(context, buildRequestCode(threadId, 0), replyIntent, PendingIntent.FLAG_UPDATE_CURRENT); Intent threadIntent = new Intent(context, MainActivity.class); - threadIntent.putExtra(MainActivity.EXTRA_THREAD_ID, threadId); + threadIntent.putExtra(MessageListActivity.ARG_THREAD_ID, threadId); final PendingIntent threadPI = PendingIntent.getActivity(context, buildRequestCode(threadId, 1), threadIntent, PendingIntent.FLAG_UPDATE_CURRENT); Intent readIntent = new Intent(ACTION_MARK_READ); @@ -575,7 +576,7 @@ public class NotificationManager { PendingIntent replyPI = PendingIntent.getActivity(context, buildRequestCode(threadId, 0), replyIntent, PendingIntent.FLAG_UPDATE_CURRENT); Intent threadIntent = new Intent(context, MainActivity.class); - threadIntent.putExtra(MainActivity.EXTRA_THREAD_ID, threadId); + threadIntent.putExtra(MessageListActivity.ARG_THREAD_ID, threadId); PendingIntent threadPI = PendingIntent.getActivity(context, buildRequestCode(threadId, 1), threadIntent, PendingIntent.FLAG_UPDATE_CURRENT); Intent readIntent = new Intent(ACTION_MARK_READ); diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/MainActivity.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/MainActivity.java index 7a6bae39..4e750fe3 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/MainActivity.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/MainActivity.java @@ -14,10 +14,7 @@ import android.net.Uri; import android.os.Bundle; import android.provider.ContactsContract; import android.support.v4.content.ContextCompat; -import android.telephony.PhoneNumberUtils; -import android.text.Html; import android.text.TextUtils; -import android.util.Log; import android.view.KeyEvent; import android.view.Menu; import android.view.MenuInflater; @@ -30,45 +27,37 @@ import butterknife.ButterKnife; import com.google.android.mms.pdu_alt.PduHeaders; import com.moez.QKSMS.R; import com.moez.QKSMS.common.ConversationPrefsHelper; -import com.moez.QKSMS.common.DialogHelper; import com.moez.QKSMS.common.DonationManager; import com.moez.QKSMS.common.LiveViewManager; import com.moez.QKSMS.common.QKRateSnack; import com.moez.QKSMS.common.google.DraftCache; -import com.moez.QKSMS.common.utils.KeyboardUtils; import com.moez.QKSMS.common.utils.MessageUtils; -import com.moez.QKSMS.common.utils.Units; import com.moez.QKSMS.data.Conversation; import com.moez.QKSMS.enums.QKPreference; -import com.moez.QKSMS.mmssms.Utils; import com.moez.QKSMS.receiver.IconColorReceiver; import com.moez.QKSMS.transaction.NotificationManager; import com.moez.QKSMS.transaction.SmsHelper; import com.moez.QKSMS.ui.base.QKActivity; -import com.moez.QKSMS.ui.compose.ComposeFragment; import com.moez.QKSMS.ui.conversationlist.ConversationListFragment; import com.moez.QKSMS.ui.dialog.ConversationSettingsDialog; import com.moez.QKSMS.ui.dialog.DefaultSmsHelper; import com.moez.QKSMS.ui.dialog.QKDialog; import com.moez.QKSMS.ui.dialog.mms.MMSSetupFragment; +import com.moez.QKSMS.ui.messagelist.MessageListActivity; import com.moez.QKSMS.ui.messagelist.MessageListFragment; import com.moez.QKSMS.ui.popup.QKReplyActivity; -import com.moez.QKSMS.ui.search.SearchFragment; +import com.moez.QKSMS.ui.search.SearchActivity; import com.moez.QKSMS.ui.settings.SettingsFragment; -import com.moez.QKSMS.ui.view.slidingmenu.SlidingMenu; import com.moez.QKSMS.ui.welcome.WelcomeActivity; import org.ligi.snackengage.SnackEngage; import org.ligi.snackengage.snacks.BaseSnack; -import java.net.URLDecoder; import java.util.Collection; -public class MainActivity extends QKActivity implements SlidingMenu.SlidingMenuListener { +public class MainActivity extends QKActivity { private final String TAG = "MainActivity"; - public final static String EXTRA_THREAD_ID = "thread_id"; - public static long sThreadShowing; private static final int THREAD_LIST_QUERY_TOKEN = 1701; @@ -80,7 +69,6 @@ public class MainActivity extends QKActivity implements SlidingMenu.SlidingMenuL public static final String MMS_SETUP_DONT_ASK_AGAIN = "mmsSetupDontAskAgain"; @Bind(R.id.root) View mRoot; - @Bind(R.id.sliding_menu) SlidingMenu mSlidingMenu; private ConversationListFragment mConversationList; private ContentFragment mContent; @@ -97,37 +85,21 @@ public class MainActivity extends QKActivity implements SlidingMenu.SlidingMenuL public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); launchWelcomeActivity(); + onNewIntent(getIntent()); - setContentView(R.layout.activity_main); + setContentView(R.layout.activity_fragment); setTitle(R.string.title_conversation_list); ButterKnife.bind(this); - setSlidingTabEnabled(mPrefs.getBoolean(SettingsFragment.SLIDING_TAB, false)); - mSlidingMenu.setListener(this); - mSlidingMenu.setContent(); - mSlidingMenu.setMenu(); - mSlidingMenu.showContent(false); - mSlidingMenu.showMenu(false); - FragmentManager fm = getFragmentManager(); - - mConversationList = (ConversationListFragment) fm.findFragmentById(R.id.menu_frame); + mConversationList = (ConversationListFragment) fm.findFragmentById(R.id.content_frame); if (mConversationList == null) { mConversationList = new ConversationListFragment(); } FragmentTransaction menuTransaction = fm.beginTransaction(); - menuTransaction.replace(R.id.menu_frame, mConversationList); + menuTransaction.replace(R.id.content_frame, mConversationList); menuTransaction.commit(); - mContent = (ContentFragment) fm.findFragmentById(R.id.content_frame); - if (mContent == null) { - mContent = ComposeFragment.getInstance(null); - } - FragmentTransaction contentTransaction = fm.beginTransaction(); - contentTransaction.replace(R.id.content_frame, (Fragment) mContent); - contentTransaction.commit(); - - onNewIntent(getIntent()); showDialogIfNeeded(savedInstanceState); LiveViewManager.registerView(QKPreference.BACKGROUND, this, key -> { @@ -192,39 +164,13 @@ public class MainActivity extends QKActivity implements SlidingMenu.SlidingMenuL startActivityForResult(welcomeIntent, WelcomeActivity.WELCOME_REQUEST_CODE); } - public void showMenu() { - mSlidingMenu.showMenu(); - } - - public SlidingMenu getSlidingMenu() { - return mSlidingMenu; - } - - /** - * Configured the sliding menu view to peek the content or not. - * - * @param slidingTabEnabled true to peek the content - */ - public void setSlidingTabEnabled(boolean slidingTabEnabled) { - if (slidingTabEnabled) { - mSlidingMenu.setBehindOffset(Units.dpToPx(this, 48)); - } else { - mSlidingMenu.setBehindOffset(0); - } - } - @Override public boolean onPrepareOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); menu.clear(); - if (mSlidingMenu.isMenuShowing() || mContent == null) { - showBackButton(false); - mConversationList.inflateToolbar(menu, inflater, this); - } else { - showBackButton(true); - mContent.inflateToolbar(menu, inflater, this); - } + showBackButton(false); + mConversationList.inflateToolbar(menu, inflater, this); return super.onPrepareOptionsMenu(menu); } @@ -238,19 +184,10 @@ public class MainActivity extends QKActivity implements SlidingMenu.SlidingMenuL switch (item.getItemId()) { case android.R.id.home: onKeyUp(KeyEvent.KEYCODE_BACK, null); - break; - case R.id.menu_settings: - switchContent(SettingsFragment.newInstance(R.xml.settings_main), true); - break; + return true; case R.id.menu_search: - switchContent(new SearchFragment(), true); - break; - case R.id.menu_changelog: - DialogHelper.showChangelog(this); - break; - case R.id.menu_donate: - DonationManager.getInstance(this).showDonateDialog(); - break; + startActivity(SearchActivity.class); + return true; } return super.onOptionsItemSelected(item); @@ -306,21 +243,10 @@ public class MainActivity extends QKActivity implements SlidingMenu.SlidingMenuL @Override public boolean onKeyUp(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { - if (!mSlidingMenu.isMenuShowing()) { - Fragment category = getFragmentManager().findFragmentByTag(SettingsFragment.CATEGORY_TAG); - if (category != null) { - getFragmentManager().beginTransaction() - .replace(R.id.content_frame, SettingsFragment.newInstance(R.xml.settings_main)).commit(); - } else { - mSlidingMenu.showMenu(); - } - return true; + if (mConversationList.isShowingBlocked()) { + mConversationList.setShowingBlocked(false); } else { - if (mConversationList.isShowingBlocked()) { - mConversationList.setShowingBlocked(false); - } else { - finish(); - } + finish(); } } @@ -331,9 +257,6 @@ public class MainActivity extends QKActivity implements SlidingMenu.SlidingMenuL protected void onPause() { super.onPause(); sThreadShowing = 0; - if (!mSlidingMenu.isMenuShowing()) { - mContent.onContentClosed(); - } } @Override @@ -353,10 +276,6 @@ public class MainActivity extends QKActivity implements SlidingMenu.SlidingMenuL protected void onResume() { super.onResume(); - if (!mSlidingMenu.isMenuShowing()) { - mContent.onContentOpened(); - } - if (mContent != null && mContent instanceof MessageListFragment) { sThreadShowing = ((MessageListFragment) mContent).getThreadId(); QKReplyActivity.dismiss(sThreadShowing); @@ -386,41 +305,19 @@ public class MainActivity extends QKActivity implements SlidingMenu.SlidingMenuL // that makes the most sense. setIntent(intent); - // This method is called whenever a MainActivity intent is started. Sometimes this is from a - // notification; other times it's from the user clicking on the app icon in the home screen - long threadId = intent.getLongExtra(EXTRA_THREAD_ID, -1); + boolean shouldOpenConversation = intent.hasExtra(MessageListActivity.ARG_THREAD_ID); // The activity can also be launched by clicking on the message button from the contacts app // Check for {sms,mms}{,to}: schemes, in which case we know to open a conversation if (intent.getData() != null) { - String data = intent.getData().toString(); String scheme = intent.getData().getScheme(); - - if (scheme.startsWith("smsto") || scheme.startsWith("mmsto")) { - String address = data.replace("smsto:", "").replace("mmsto:", ""); - threadId = Utils.getThreadId(this, formatPhoneNumber(address)); - } else if (scheme.startsWith("sms") || (scheme.startsWith("mms"))) { - String address = data.replace("sms:", "").replace("mms:", ""); - threadId = Utils.getThreadId(this, formatPhoneNumber(address)); - } + shouldOpenConversation = shouldOpenConversation || scheme.startsWith("sms") || scheme.startsWith("mms"); } - // If it has a thread id, then we know it's from a notification and we can set the - // conversation. - if (threadId != -1) { - Log.v(TAG, "Opening thread: " + threadId); - setConversation(threadId); - mSlidingMenu.showContent(); + if (shouldOpenConversation) { + intent.setClass(this, MessageListActivity.class); + startActivity(intent); } - - // Otherwise we'll just resume what was previously there, which doesn't require any code. - } - - private String formatPhoneNumber(String address) { - address = URLDecoder.decode(address); - address = "" + Html.fromHtml(address); - address = PhoneNumberUtils.formatNumber(address); - return address; } private void beginMmsSetup() { @@ -458,104 +355,6 @@ public class MainActivity extends QKActivity implements SlidingMenu.SlidingMenuL } } - public void switchContent(ContentFragment fragment, boolean animate) { - // Make sure that the activity isn't destroyed before making fragment transactions. - if (fragment != null && !mIsDestroyed) { - KeyboardUtils.hide(this); - - mContent = fragment; - FragmentManager m = getFragmentManager(); - - // Only do a replace if it is a different fragment. - if (fragment != m.findFragmentById(R.id.content_frame)) { - getFragmentManager() - .beginTransaction() - .replace(R.id.content_frame, (Fragment) fragment) - .commitAllowingStateLoss(); - } - - mSlidingMenu.showContent(animate); - invalidateOptionsMenu(); - - } else { - Log.w(TAG, "Null fragment, can't switch content"); - } - } - - public void setConversation(long threadId) { - setConversation(threadId, -1, null, false); - } - - public void setConversation(long threadId, long rowId) { - setConversation(threadId, rowId, null, false); - } - - public void setConversation(long threadId, long rowId, String pattern) { - setConversation(threadId, rowId, pattern, false); - } - - public void setConversation(long threadId, long rowId, String pattern, boolean animate) { - MessageListFragment fragment = MessageListFragment.getInstance(threadId, rowId, pattern, !animate); - - // Save the thread ID here and switch the content - sThreadShowing = threadId; - switchContent(fragment, animate); - } - - @Override - public void onOpen() { - invalidateOptionsMenu(); - sThreadShowing = 0; - - // Notify the content that it is being closed, since the menu (i.e. conversation list) is being opened. - if (mContent != null) mContent.onContentClosing(); - - // Hide the soft keyboard - KeyboardUtils.hide(this, getCurrentFocus()); - - showBackButton(false); - } - - @Override - public void onClose() { - invalidateOptionsMenu(); - - // Notify the content that it is being opened, since the menu (i.e. conversation list) is being closed. - if (mContent != null) { - mContent.onContentOpening(); - } - - if (mContent != null && mContent instanceof MessageListFragment) { - sThreadShowing = ((MessageListFragment) mContent).getThreadId(); - } else { - sThreadShowing = 0; - } - - // Hide the soft keyboard - KeyboardUtils.hide(this, getCurrentFocus()); - - showBackButton(true); - } - - @Override - public void onOpened() { - // When the menu (i.e. the conversation list) has been opened, the content has been opened. - // So notify the content fragment. - if (mContent != null) mContent.onContentClosed(); - } - - @Override - public void onClosed() { - // When the menu (i.e. the conversation list) has been closed, the content has been opened. - // So notify the content fragment. - if (mContent != null && ((Fragment) mContent).isAdded()) mContent.onContentOpened(); - } - - @Override - public void onChanging(float percentOpen) { - if (mContent != null) mContent.onMenuChanging(percentOpen); - } - /** * Build and show the proper delete thread dialog. The UI is slightly different * depending on whether there are locked messages in the thread(s) and whether we're diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/SwipeBackLayout.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/SwipeBackLayout.java new file mode 100644 index 00000000..6a4c6b59 --- /dev/null +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/SwipeBackLayout.java @@ -0,0 +1,512 @@ +package com.moez.QKSMS.ui; + +import android.app.Activity; +import android.content.Context; +import android.content.res.TypedArray; +import android.graphics.Canvas; +import android.graphics.Rect; +import android.graphics.drawable.Drawable; +import android.support.v4.view.ViewCompat; +import android.support.v4.widget.ViewDragHelper; +import android.util.AttributeSet; +import android.view.MotionEvent; +import android.view.View; +import android.view.ViewGroup; +import android.widget.FrameLayout; +import com.moez.QKSMS.R; + +import java.util.ArrayList; +import java.util.List; + +/** + * Modified version of https://github.com/ikew0ng/SwipeBackLayout + */ +public class SwipeBackLayout extends FrameLayout { + private final String TAG = "SwipeBackLayout"; + + public interface ScrollChangedListener { + void onScrollChanged(float scrollPercent); + } + + private static final int MIN_FLING_VELOCITY = 400; // dips per second + private static final int DEFAULT_SCRIM_COLOR = 0x99000000; + private static final int FULL_ALPHA = 255; + private static final float DEFAULT_SCROLL_THRESHOLD = 0.3f; + private static final int OVERSCROLL_DISTANCE = 10; + + public static final int EDGE_LEFT = ViewDragHelper.EDGE_LEFT; + public static final int EDGE_BOTTOM = ViewDragHelper.EDGE_BOTTOM; + public static final int EDGE_ALL = EDGE_LEFT | EDGE_BOTTOM; + + public static final int STATE_IDLE = ViewDragHelper.STATE_IDLE; + public static final int STATE_DRAGGING = ViewDragHelper.STATE_DRAGGING; + public static final int STATE_SETTLING = ViewDragHelper.STATE_SETTLING; + + + private static final int[] EDGE_FLAGS = { + EDGE_LEFT, EDGE_BOTTOM, EDGE_ALL + }; + + private int mEdgeFlag; + + /** + * Threshold of scroll, we will close the activity, when scrollPercent over + * this value; + */ + private float mScrollThreshold = DEFAULT_SCROLL_THRESHOLD; + + private Activity mActivity; + + private boolean mEnable = true; + + private View mContentView; + + private ViewDragHelper mDragHelper; + + private float mScrollPercent; + + private int mContentLeft; + private int mContentTop; + + /** + * The set of listeners to be sent events through. + */ + private List mListeners; + private ScrollChangedListener mScrollChangedListener; + + private Drawable mShadowLeft; + private Drawable mShadowBottom; + + private float mScrimOpacity; + private int mScrimColor = DEFAULT_SCRIM_COLOR; + + private boolean mInLayout; + private Rect mTmpRect = new Rect(); + + /** + * Edge being dragged + */ + private int mTrackingEdge = EDGE_LEFT; + + public SwipeBackLayout(Context context) { + this(context, null); + } + + public SwipeBackLayout(Context context, AttributeSet attrs) { + this(context, attrs, 0); + } + + public SwipeBackLayout(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs); + mDragHelper = ViewDragHelper.create(this, 0.2f, new ViewDragCallback()); + + int shadowLeft = R.drawable.shadow_left; + int shadowBottom = R.drawable.shadow_bottom; + setShadow(shadowLeft, EDGE_LEFT); + setShadow(shadowBottom, EDGE_BOTTOM); + final float density = getResources().getDisplayMetrics().density; + final float minVel = MIN_FLING_VELOCITY * density; + mDragHelper.setMinVelocity(minVel); + } + + /** + * Set up contentView which will be moved by user gesture + * + * @param view + */ + private void setContentView(View view) { + mContentView = view; + } + + public void setEnableGesture(boolean enable) { + mEnable = enable; + } + + /** + * Enable edge tracking for the selected edges of the parent view. The + * callback's + * {@link android.support.v4.widget.ViewDragHelper.Callback#onEdgeTouched(int, int)} + * and + * {@link android.support.v4.widget.ViewDragHelper.Callback#onEdgeDragStarted(int, int)} + * methods will only be invoked for edges for which edge tracking has been + * enabled. + * + * @param edgeFlags Combination of edge flags describing the edges to watch + * @see #EDGE_LEFT + * @see #EDGE_BOTTOM + */ + public void setEdgeTrackingEnabled(int edgeFlags) { + mEdgeFlag = edgeFlags; + mDragHelper.setEdgeTrackingEnabled(mEdgeFlag); + } + + /** + * Set a color to use for the scrim that obscures primary content while a + * drawer is open. + * + * @param color Color to use in 0xAARRGGBB format. + */ + public void setScrimColor(int color) { + mScrimColor = color; + invalidate(); + } + + /** + * Register a callback to be invoked when a swipe event is sent to this + * view. + * + * @param listener the swipe listener to attach to this view + * @deprecated use {@link #addSwipeListener} instead + */ + @Deprecated + public void setSwipeListener(SwipeListener listener) { + addSwipeListener(listener); + } + + /** + * Add a callback to be invoked when a swipe event is sent to this view. + * + * @param listener the swipe listener to attach to this view + */ + public void addSwipeListener(SwipeListener listener) { + if (mListeners == null) { + mListeners = new ArrayList(); + } + mListeners.add(listener); + } + + /** + * Removes a listener from the set of listeners + * + * @param listener + */ + public void removeSwipeListener(SwipeListener listener) { + if (mListeners == null) { + return; + } + mListeners.remove(listener); + } + + public void setScrollChangedListener(ScrollChangedListener listener) { + mScrollChangedListener = listener; + } + + public interface SwipeListener { + /** + * Invoke when state change + * + * @param state flag to describe scroll state + * @param scrollPercent scroll percent of this view + * @see #STATE_IDLE + * @see #STATE_DRAGGING + * @see #STATE_SETTLING + */ + void onScrollStateChange(int state, float scrollPercent); + + /** + * Invoke when edge touched + * + * @param edgeFlag edge flag describing the edge being touched + * @see #EDGE_LEFT + * @see #EDGE_BOTTOM + */ + void onEdgeTouch(int edgeFlag); + + /** + * Invoke when scroll percent over the threshold for the first time + */ + void onScrollOverThreshold(); + } + + /** + * Set scroll threshold, we will close the activity, when scrollPercent over + * this value + * + * @param threshold + */ + public void setScrollThresHold(float threshold) { + if (threshold >= 1.0f || threshold <= 0) { + throw new IllegalArgumentException("Threshold value should be between 0 and 1.0"); + } + mScrollThreshold = threshold; + } + + /** + * Set a drawable used for edge shadow. + * + * @param shadow Drawable to use + * @param edgeFlags Combination of edge flags describing the edge to set + * @see #EDGE_LEFT + * @see #EDGE_BOTTOM + */ + public void setShadow(Drawable shadow, int edgeFlag) { + if ((edgeFlag & EDGE_LEFT) != 0) { + mShadowLeft = shadow; + } else if ((edgeFlag & EDGE_BOTTOM) != 0) { + mShadowBottom = shadow; + } + invalidate(); + } + + /** + * Set a drawable used for edge shadow. + * + * @param resId Resource of drawable to use + * @param edgeFlags Combination of edge flags describing the edge to set + * @see #EDGE_LEFT + * @see #EDGE_BOTTOM + */ + public void setShadow(int resId, int edgeFlag) { + setShadow(getResources().getDrawable(resId), edgeFlag); + } + + /** + * Scroll out contentView and finish the activity + */ + public void scrollToFinishActivity() { + final int childWidth = mContentView.getWidth(); + final int childHeight = mContentView.getHeight(); + + int left = 0, top = 0; + if ((mEdgeFlag & EDGE_LEFT) != 0) { + left = childWidth + mShadowLeft.getIntrinsicWidth() + OVERSCROLL_DISTANCE; + mTrackingEdge = EDGE_LEFT; + } else if ((mEdgeFlag & EDGE_BOTTOM) != 0) { + top = -childHeight - mShadowBottom.getIntrinsicHeight() - OVERSCROLL_DISTANCE; + mTrackingEdge = EDGE_BOTTOM; + } + + mDragHelper.smoothSlideViewTo(mContentView, left, top); + invalidate(); + } + + @Override + public boolean onInterceptTouchEvent(MotionEvent event) { + if (!mEnable) { + return false; + } + try { + return mDragHelper.shouldInterceptTouchEvent(event); + } catch (ArrayIndexOutOfBoundsException e) { + // FIXME: handle exception + // issues #9 + return false; + } + } + + @Override + public boolean onTouchEvent(MotionEvent event) { + if (!mEnable) { + return false; + } + mDragHelper.processTouchEvent(event); + return true; + } + + @Override + protected void onLayout(boolean changed, int left, int top, int right, int bottom) { + mInLayout = true; + if (mContentView != null) + mContentView.layout(mContentLeft, mContentTop, + mContentLeft + mContentView.getMeasuredWidth(), + mContentTop + mContentView.getMeasuredHeight()); + mInLayout = false; + } + + @Override + public void requestLayout() { + if (!mInLayout) { + super.requestLayout(); + } + } + + @Override + protected boolean drawChild(Canvas canvas, View child, long drawingTime) { + final boolean drawContent = child == mContentView; + + boolean ret = super.drawChild(canvas, child, drawingTime); + if (mScrimOpacity > 0 && drawContent && mDragHelper.getViewDragState() != ViewDragHelper.STATE_IDLE) { + drawShadow(canvas, child); + drawScrim(canvas, child); + } + return ret; + } + + private void drawScrim(Canvas canvas, View child) { + final int baseAlpha = (mScrimColor & 0xff000000) >>> 24; + final int alpha = (int) (baseAlpha * mScrimOpacity); + final int color = alpha << 24 | (mScrimColor & 0xffffff); + + if ((mTrackingEdge & EDGE_LEFT) != 0) { + canvas.clipRect(0, 0, child.getLeft(), getHeight()); + } else if ((mTrackingEdge & EDGE_BOTTOM) != 0) { + canvas.clipRect(child.getLeft(), child.getBottom(), getRight(), getHeight()); + } + canvas.drawColor(color); + } + + private void drawShadow(Canvas canvas, View child) { + final Rect childRect = mTmpRect; + child.getHitRect(childRect); + + if ((mEdgeFlag & EDGE_LEFT) != 0) { + mShadowLeft.setBounds(childRect.left - mShadowLeft.getIntrinsicWidth(), childRect.top, + childRect.left, childRect.bottom); + mShadowLeft.setAlpha((int) (mScrimOpacity * FULL_ALPHA)); + mShadowLeft.draw(canvas); + } + + if ((mEdgeFlag & EDGE_BOTTOM) != 0) { + mShadowBottom.setBounds(childRect.left, childRect.bottom, childRect.right, + childRect.bottom + mShadowBottom.getIntrinsicHeight()); + mShadowBottom.setAlpha((int) (mScrimOpacity * FULL_ALPHA)); + mShadowBottom.draw(canvas); + } + } + + public void attachToActivity(Activity activity) { + mActivity = activity; + TypedArray a = activity.getTheme().obtainStyledAttributes(new int[]{ + android.R.attr.windowBackground + }); + int background = a.getResourceId(0, 0); + a.recycle(); + + ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView(); + ViewGroup decorChild = (ViewGroup) decor.getChildAt(0); + decorChild.setBackgroundResource(background); + decor.removeView(decorChild); + addView(decorChild); + setContentView(decorChild); + decor.addView(this); + } + + @Override + public void computeScroll() { + mScrimOpacity = mScrollPercent < 0.8f ? 0.4f : (1f - mScrollPercent) * 2f; + if (mDragHelper.continueSettling(true)) { + ViewCompat.postInvalidateOnAnimation(this); + } + } + + private class ViewDragCallback extends ViewDragHelper.Callback { + private boolean mIsScrollOverValid; + + @Override + public void onEdgeDragStarted(int edgeFlags, int pointerId) { + super.onEdgeDragStarted(edgeFlags, pointerId); + } + + @Override + public boolean tryCaptureView(View view, int i) { + mTrackingEdge = EDGE_LEFT; + if (mListeners != null && !mListeners.isEmpty()) { + for (SwipeListener listener : mListeners) { + listener.onEdgeTouch(mTrackingEdge); + } + } + mIsScrollOverValid = true; + boolean directionCheck = false; + if (mEdgeFlag == EDGE_LEFT) { + directionCheck = !mDragHelper.checkTouchSlop(ViewDragHelper.DIRECTION_VERTICAL, i); + } else if (mEdgeFlag == EDGE_BOTTOM) { + directionCheck = !mDragHelper.checkTouchSlop(ViewDragHelper.DIRECTION_HORIZONTAL, i); + } else if (mEdgeFlag == EDGE_ALL) { + directionCheck = true; + } + return directionCheck; + } + + @Override + public int getViewHorizontalDragRange(View child) { + return mEdgeFlag & (EDGE_LEFT); + } + + @Override + public int getViewVerticalDragRange(View child) { + return mEdgeFlag & EDGE_BOTTOM; + } + + @Override + public void onViewPositionChanged(View changedView, int left, int top, int dx, int dy) { + super.onViewPositionChanged(changedView, left, top, dx, dy); + if ((mTrackingEdge & EDGE_LEFT) != 0) { + mScrollPercent = Math.abs((float) left / (mContentView.getWidth() + mShadowLeft.getIntrinsicWidth())); + } else if ((mTrackingEdge & EDGE_BOTTOM) != 0) { + mScrollPercent = Math.abs((float) top / (mContentView.getHeight() + mShadowBottom.getIntrinsicHeight())); + } + + if (mScrollChangedListener != null) { + mScrollChangedListener.onScrollChanged(mScrollPercent); + } + + mContentLeft = left; + mContentTop = top; + invalidate(); + if (mScrollPercent < mScrollThreshold && !mIsScrollOverValid) { + mIsScrollOverValid = true; + } + if (mListeners != null && !mListeners.isEmpty() + && mDragHelper.getViewDragState() == STATE_DRAGGING + && mScrollPercent >= mScrollThreshold && mIsScrollOverValid) { + mIsScrollOverValid = false; + for (SwipeListener listener : mListeners) { + listener.onScrollOverThreshold(); + } + } + + if (mScrollPercent >= 1) { + if (!mActivity.isFinishing()) { + mActivity.finish(); + mActivity.overridePendingTransition(0, 0); + } + } + } + + @Override + public void onViewReleased(View releasedChild, float xvel, float yvel) { + final int childWidth = releasedChild.getWidth(); + final int childHeight = releasedChild.getHeight(); + + int left = 0, top = 0; + if ((mTrackingEdge & EDGE_LEFT) != 0) { + left = xvel > 0 || xvel == 0 && mScrollPercent > mScrollThreshold ? childWidth + + mShadowLeft.getIntrinsicWidth() + OVERSCROLL_DISTANCE : 0; + } else if ((mTrackingEdge & EDGE_BOTTOM) != 0) { + top = yvel < 0 || yvel == 0 && mScrollPercent > mScrollThreshold ? -(childHeight + + mShadowBottom.getIntrinsicHeight() + OVERSCROLL_DISTANCE) : 0; + } + + mDragHelper.settleCapturedViewAt(left, top); + invalidate(); + } + + @Override + public int clampViewPositionHorizontal(View child, int left, int dx) { + int ret = 0; + if ((mTrackingEdge & EDGE_LEFT) != 0) { + ret = Math.min(child.getWidth(), Math.max(left, 0)); + } + return ret; + } + + @Override + public int clampViewPositionVertical(View child, int top, int dy) { + int ret = 0; + if ((mTrackingEdge & EDGE_BOTTOM) != 0) { + ret = Math.min(0, Math.max(top, -child.getHeight())); + } + return ret; + } + + @Override + public void onViewDragStateChanged(int state) { + super.onViewDragStateChanged(state); + if (mListeners != null && !mListeners.isEmpty()) { + for (SwipeListener listener : mListeners) { + listener.onScrollStateChange(state, mScrollPercent); + } + } + } + } +} \ No newline at end of file diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKActivity.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKActivity.java index 023237cd..814241c9 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKActivity.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKActivity.java @@ -1,6 +1,7 @@ package com.moez.QKSMS.ui.base; import android.app.ProgressDialog; +import android.content.Intent; import android.content.SharedPreferences; import android.content.res.Resources; import android.graphics.PorterDuff; @@ -23,10 +24,14 @@ import android.widget.Toast; import com.android.volley.RequestQueue; import com.moez.QKSMS.QKSMSApp; import com.moez.QKSMS.R; +import com.moez.QKSMS.common.DialogHelper; +import com.moez.QKSMS.common.DonationManager; import com.moez.QKSMS.common.LiveViewManager; -import com.moez.QKSMS.enums.QKPreference; import com.moez.QKSMS.common.utils.ColorUtils; +import com.moez.QKSMS.enums.QKPreference; import com.moez.QKSMS.ui.ThemeManager; +import com.moez.QKSMS.ui.search.SearchFragment; +import com.moez.QKSMS.ui.settings.SettingsActivity; import com.moez.QKSMS.ui.view.QKTextView; import java.util.ArrayList; @@ -241,6 +246,28 @@ public abstract class QKActivity extends AppCompatActivity { } } + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.menu_settings: + startActivity(SettingsActivity.class); + return true; + case R.id.menu_changelog: + DialogHelper.showChangelog(this); + return true; + case R.id.menu_donate: + DonationManager.getInstance(this).showDonateDialog(); + return true; + } + + return super.onOptionsItemSelected(item); + } + + public void startActivity(Class cls) { + Intent intent = new Intent(this, cls); + startActivity(intent); + } + public boolean isScreenOn() { PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE); if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) { diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKContentFragment.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKContentFragment.java deleted file mode 100644 index b1135369..00000000 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKContentFragment.java +++ /dev/null @@ -1,83 +0,0 @@ -package com.moez.QKSMS.ui.base; - -import android.os.Bundle; -import com.moez.QKSMS.ui.ContentFragment; - -/** - * Base class for Fragments. QKSMS uses the recycle pattern as an optimization, and our fragment - * system has been built to help accommodate this. - *

- * Functions: - * - Exposes a new API around fragment arguments update. updateArguments(Bundle) can be used to - * reconfigure a recycled fragment, and onNewArguments() will be called whenever - * updateArguments(Bundle) is called. - *

- * - Gives callbacks for the content animations. - *

- * - Manages the current state of the fragment in terms of the animation, i.e. opening, fully - * opened, etc. - */ -public abstract class QKContentFragment extends QKFragment implements ContentFragment { - - /** - * It's not strictly necessary, but subclasses should call through to super() in their - * constructor. - */ - public QKContentFragment() { - setArguments(new Bundle()); - } - - /** - * Called whenever setArguments is called, so any setup that uses the new configurations can be - * implemented in this method. - */ - public void onNewArguments() { - } - - public void updateArguments(Bundle args) { - // Ensure that args is not null. - args = args == null ? new Bundle() : args; - - // The fragment's arguments can only be set before onAttach is called. - if (getActivity() == null) { - // If the fragment hasn't been attached to its activity yet, call the super method to - // actually set this Bundle as the arguments. - super.setArguments(args); - - } else { - // Otherwise, replace all the values in the old args with the values in the new args. - Bundle oldArgs = getArguments() == null ? new Bundle() : getArguments(); - oldArgs.clear(); - oldArgs.putAll(args); - } - - // Notify that the arguments have been changed. - onNewArguments(); - } - - /** - * Called when the content is being opened with an animation. - */ - public void onContentOpening() { - } - - /** - * Called when the content has been opened, i.e. a opening animation has finished or it had - * been opened immediately. - */ - public void onContentOpened() { - } - - /** - * Called when the content is being closed with an animation. - */ - public void onContentClosing() { - } - - /** - * Called when the content has been closed, i.e. a closing animation has finished or it had - * been closed immediately. - */ - public void onContentClosed() { - } -} diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKSwipeBackActivity.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKSwipeBackActivity.java new file mode 100644 index 00000000..4f814965 --- /dev/null +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKSwipeBackActivity.java @@ -0,0 +1,51 @@ +package com.moez.QKSMS.ui.base; + +import android.graphics.Color; +import android.graphics.drawable.ColorDrawable; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.MenuItem; +import com.moez.QKSMS.R; +import com.moez.QKSMS.ui.SwipeBackLayout; + +public abstract class QKSwipeBackActivity extends QKActivity { + + protected SwipeBackLayout mSwipeBackLayout; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_fragment); + + getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); + getWindow().getDecorView().setBackgroundDrawable(null); + mSwipeBackLayout = (SwipeBackLayout) LayoutInflater.from(this).inflate(R.layout.view_swipeback, null); + + mSwipeBackLayout.setEdgeTrackingEnabled(SwipeBackLayout.EDGE_LEFT); + mSwipeBackLayout.setEnableGesture(true); + + showBackButton(true); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case android.R.id.home: + onBackPressed(); + return true; + } + + return super.onOptionsItemSelected(item); + } + + @Override + protected void onPostCreate(Bundle savedInstanceState) { + super.onPostCreate(savedInstanceState); + mSwipeBackLayout.attachToActivity(this); + } + + @Override + public void onBackPressed() { + mSwipeBackLayout.scrollToFinishActivity(); + } +} diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/compose/ComposeActivity.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/compose/ComposeActivity.java new file mode 100644 index 00000000..4c44bbf7 --- /dev/null +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/compose/ComposeActivity.java @@ -0,0 +1,35 @@ +package com.moez.QKSMS.ui.compose; + +import android.app.FragmentManager; +import android.os.Bundle; +import android.view.Menu; +import android.view.MenuInflater; +import com.moez.QKSMS.R; +import com.moez.QKSMS.ui.base.QKSwipeBackActivity; + +public class ComposeActivity extends QKSwipeBackActivity { + + private ComposeFragment mComposeFragment; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setTitle(R.string.title_compose); + + FragmentManager fm = getFragmentManager(); + mComposeFragment = (ComposeFragment) fm.findFragmentById(R.id.content_frame); + if (mComposeFragment == null) { + mComposeFragment = new ComposeFragment(); + } + + fm.beginTransaction() + .replace(R.id.content_frame, mComposeFragment) + .commit(); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + new MenuInflater(this).inflate(R.menu.compose, menu); + return super.onCreateOptionsMenu(menu); + } +} diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/compose/ComposeFragment.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/compose/ComposeFragment.java index 1b33390c..b19f3c8d 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/compose/ComposeFragment.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/compose/ComposeFragment.java @@ -1,12 +1,8 @@ package com.moez.QKSMS.ui.compose; -import android.app.Fragment; -import android.content.Context; -import android.content.Intent; import android.os.Bundle; +import android.os.Handler; import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; @@ -17,81 +13,22 @@ import com.moez.QKSMS.common.utils.PhoneNumberUtils; import com.moez.QKSMS.interfaces.ActivityLauncher; import com.moez.QKSMS.interfaces.RecipientProvider; import com.moez.QKSMS.mmssms.Utils; -import com.moez.QKSMS.ui.MainActivity; -import com.moez.QKSMS.ui.base.QKActivity; -import com.moez.QKSMS.ui.base.QKContentFragment; +import com.moez.QKSMS.ui.base.QKFragment; +import com.moez.QKSMS.ui.messagelist.MessageListActivity; import com.moez.QKSMS.ui.view.AutoCompleteContactView; import com.moez.QKSMS.ui.view.ComposeView; import com.moez.QKSMS.ui.view.StarredContactsView; -public class ComposeFragment extends QKContentFragment implements ActivityLauncher, RecipientProvider, +public class ComposeFragment extends QKFragment implements ActivityLauncher, RecipientProvider, ComposeView.OnSendListener, AdapterView.OnItemClickListener { private final String TAG = "ComposeFragment"; - /** - * Set to true in the bundle if the ComposeFragment should show the keyboard. Defaults to false. - */ - public static final String ARG_SHOW_KEYBOARD = "showKeyboard"; - - /** - * Set a FOCUS string to indicate where the focus should be for the keyboard. Defaults to - * FOCUS_NOTHING. - */ - public static final String ARG_FOCUS = "focus"; - - public static final String FOCUS_NOTHING = "nothing"; - public static final String FOCUS_RECIPIENTS = "recipients"; - public static final String FOCUS_REPLY = "reply"; - private AutoCompleteContactView mRecipients; private ComposeView mComposeView; private StarredContactsView mStarredContactsView; - // True if the fragment's arguments have changed, and we need to potentially perform a focus - // operation when the fragment opens. - private boolean mPendingFocus = false; - - /** - * Returns a new ComposeFragment, configured with the args. - * - * @param args A Bundle with options for configuring this fragment. See the ARG_ constants for - * configuration options. - * @return the new ComposeFragment - */ - public static ComposeFragment getInstance(Bundle args) { - return getInstance(args, null); - } - - /** - * Returns a ComposeFragment, configured with the args. If possible, the given fragment - * is used instead of creating a new ComposeFragment. - * - * @param args A Bundle with options for configuring this fragment. See the ARG_ constants for - * configuration options. - * @param reuseFragment A fragment that can be used instead of creating a new one. - * @return the ComposeFragment, which may be recycled - */ - public static ComposeFragment getInstance(Bundle args, Fragment reuseFragment) { - ComposeFragment f; - - // Check if we can reuse the passed fragment. - if (reuseFragment != null && reuseFragment instanceof ComposeFragment) { - f = (ComposeFragment) reuseFragment; - } else { - f = new ComposeFragment(); - } - - // Set the arguments in this fragment. - f.updateArguments(args); - - return f; - } - - @Override - public void onNewArguments() { - // Set pending focus, because the new configuration means that we may need to focus. - mPendingFocus = true; + public ComposeFragment() { } @Override @@ -113,67 +50,18 @@ public class ComposeFragment extends QKContentFragment implements ActivityLaunch mStarredContactsView = (StarredContactsView) view.findViewById(R.id.starred_contacts); mStarredContactsView.setComposeScreenViews(mRecipients, mComposeView); + new Handler().postDelayed(() -> KeyboardUtils.showAndFocus(mContext, mRecipients), 100); + return view; } - @Override - public void onActivityResult(int requestCode, int resultCode, Intent data) { - super.onActivityResult(requestCode, resultCode, data); - - boolean handledByComposeView = mComposeView.onActivityResult(requestCode, resultCode, data); - if (!handledByComposeView) { - // ... - } - } - @Override public void onSend(String[] recipients, String body) { long threadId = Utils.getOrCreateThreadId(mContext, recipients[0]); - if (recipients.length == 1) { - ((MainActivity) mContext).setConversation(threadId); + if (threadId != 0) { + MessageListActivity.launch(mContext, threadId, -1, null, true); } else { - ((MainActivity) mContext).showMenu(); - } - } - - @Override - public void onContentOpened() { - setupInput(); - } - - /** - * Shows the keyboard and focuses on the recipients text view. - */ - public void setupInput() { - Bundle args = getArguments() == null ? new Bundle() : getArguments(); - - if (mPendingFocus) { - if (args.getBoolean(ARG_SHOW_KEYBOARD, false)) { - KeyboardUtils.show(mContext); - } - - String focus = args.getString(ARG_FOCUS, FOCUS_NOTHING); - if (FOCUS_RECIPIENTS.equals(focus)) { - mRecipients.requestFocus(); - } else if (FOCUS_REPLY.equals(focus)) { - mComposeView.requestReplyTextFocus(); - } - } - } - - @Override - public void onContentClosing() { - // Clear the focus from this fragment. - if (getActivity() != null && getActivity().getCurrentFocus() != null) { - getActivity().getCurrentFocus().clearFocus(); - } - } - - @Override - public void onContentClosed() { - super.onContentClosed(); - if (mComposeView != null) { - mComposeView.saveDraft(); + mContext.onBackPressed(); } } @@ -185,19 +73,6 @@ public class ComposeFragment extends QKContentFragment implements ActivityLaunch } } - @Override - public void onMenuChanging(float percentOpen) { - - } - - @Override - public void inflateToolbar(Menu menu, MenuInflater inflater, Context context) { - inflater.inflate(R.menu.compose, menu); - ((QKActivity) context).setTitle(R.string.title_compose); - - super.onCreateOptionsMenu(menu, inflater); - } - /** * @return the addresses of all the contacts in the AutoCompleteContactsView. */ diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/conversationlist/ConversationListFragment.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/conversationlist/ConversationListFragment.java index 93be149b..84cbe58e 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/conversationlist/ConversationListFragment.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/conversationlist/ConversationListFragment.java @@ -1,6 +1,5 @@ package com.moez.QKSMS.ui.conversationlist; -import android.app.Fragment; import android.app.LoaderManager; import android.content.Context; import android.content.CursorLoader; @@ -26,18 +25,18 @@ import com.moez.QKSMS.R; import com.moez.QKSMS.common.BlockedConversationHelper; import com.moez.QKSMS.common.DialogHelper; import com.moez.QKSMS.common.LiveViewManager; -import com.moez.QKSMS.ui.dialog.conversationdetails.ConversationDetailsDialog; -import com.moez.QKSMS.enums.QKPreference; import com.moez.QKSMS.common.utils.ColorUtils; import com.moez.QKSMS.data.Conversation; import com.moez.QKSMS.data.ConversationLegacy; +import com.moez.QKSMS.enums.QKPreference; import com.moez.QKSMS.transaction.SmsHelper; -import com.moez.QKSMS.ui.ContentFragment; import com.moez.QKSMS.ui.MainActivity; import com.moez.QKSMS.ui.ThemeManager; import com.moez.QKSMS.ui.base.QKFragment; import com.moez.QKSMS.ui.base.RecyclerCursorAdapter; -import com.moez.QKSMS.ui.compose.ComposeFragment; +import com.moez.QKSMS.ui.compose.ComposeActivity; +import com.moez.QKSMS.ui.dialog.conversationdetails.ConversationDetailsDialog; +import com.moez.QKSMS.ui.messagelist.MessageListActivity; import com.moez.QKSMS.ui.settings.SettingsFragment; import java.util.Observable; @@ -111,13 +110,7 @@ public class ConversationListFragment extends QKFragment implements LoaderManage if (mAdapter.isInMultiSelectMode()) { mAdapter.disableMultiSelectMode(true); } else { - // Show the compose fragment, showing the keyboard and focusing on the recipients edittext. - Bundle args = new Bundle(); - args.putBoolean(ComposeFragment.ARG_SHOW_KEYBOARD, true); - args.putString(ComposeFragment.ARG_FOCUS, ComposeFragment.FOCUS_RECIPIENTS); - - Fragment content = getFragmentManager().findFragmentById(R.id.content_frame); - switchFragment(ComposeFragment.getInstance(args, content)); + mContext.startActivity(ComposeActivity.class); } }); @@ -250,7 +243,7 @@ public class ConversationListFragment extends QKFragment implements LoaderManage if (mAdapter.isInMultiSelectMode()) { mAdapter.toggleSelection(conversation.getThreadId(), conversation); } else { - ((MainActivity) mContext).setConversation(conversation.getThreadId(), -1, null, true); + MessageListActivity.launch(mContext, conversation.getThreadId(), -1, null, true); } } @@ -274,10 +267,6 @@ public class ConversationListFragment extends QKFragment implements LoaderManage getLoaderManager().restartLoader(0, null, this); } - private void switchFragment(ContentFragment fragment) { - ((MainActivity) getActivity()).switchContent(fragment, true); - } - @Override public void onDestroy() { super.onDestroy(); diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListActivity.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListActivity.java new file mode 100644 index 00000000..fc1442c6 --- /dev/null +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListActivity.java @@ -0,0 +1,116 @@ +package com.moez.QKSMS.ui.messagelist; + +import android.app.FragmentManager; +import android.app.FragmentTransaction; +import android.content.Intent; +import android.os.Bundle; +import android.text.Html; +import android.util.Log; +import android.view.Menu; +import android.view.MenuInflater; +import com.crashlytics.android.Crashlytics; +import com.moez.QKSMS.R; +import com.moez.QKSMS.common.utils.PhoneNumberUtils; +import com.moez.QKSMS.mmssms.Utils; +import com.moez.QKSMS.ui.base.QKActivity; +import com.moez.QKSMS.ui.base.QKSwipeBackActivity; + +import java.net.URLDecoder; + +public class MessageListActivity extends QKSwipeBackActivity { + private final String TAG = "MessageListActivity"; + + public static final String ARG_THREAD_ID = "thread_id"; + public static final String ARG_ROW_ID = "rowId"; + public static final String ARG_HIGHLIGHT = "highlight"; + public static final String ARG_SHOW_IMMEDIATE = "showImmediate"; + + private long mThreadId; + private long mRowId; + private String mHighlight; + private boolean mShowImmediate; + + public static void launch(QKActivity context, long threadId, long rowId, String pattern, boolean showImmediate) { + Intent intent = new Intent(context, MessageListActivity.class); + intent.putExtra(ARG_THREAD_ID, threadId); + intent.putExtra(ARG_ROW_ID, rowId); + intent.putExtra(ARG_HIGHLIGHT, pattern); + intent.putExtra(ARG_SHOW_IMMEDIATE, showImmediate); + context.startActivity(intent); + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + onNewIntent(getIntent()); + } + + @Override + protected void onNewIntent(Intent intent) { + super.onNewIntent(intent); + mThreadId = intent.getLongExtra(ARG_THREAD_ID, -1); + mRowId = intent.getLongExtra(ARG_ROW_ID, -1); + mHighlight = intent.getStringExtra(ARG_HIGHLIGHT); + mShowImmediate = intent.getBooleanExtra(ARG_SHOW_IMMEDIATE, false); + + if (mThreadId == -1 && intent.getData() != null) { + String data = intent.getData().toString(); + String scheme = intent.getData().getScheme(); + + String address = null; + if (scheme.startsWith("smsto") || scheme.startsWith("mmsto")) { + address = data.replace("smsto:", "").replace("mmsto:", ""); + } else if (scheme.startsWith("sms") || (scheme.startsWith("mms"))) { + address = data.replace("sms:", "").replace("mms:", ""); + } + + address = URLDecoder.decode(address); + address = "" + Html.fromHtml(address); + address = PhoneNumberUtils.formatNumber(address); + mThreadId = Utils.getOrCreateThreadId(this, address); + } + + if (mThreadId != -1) { + Log.v(TAG, "Opening thread: " + mThreadId); + FragmentManager fm = getFragmentManager(); + MessageListFragment fragment = (MessageListFragment) fm.findFragmentById(R.id.content_frame); + if (fragment == null) { + fragment = MessageListFragment.getInstance(mThreadId, mRowId, mHighlight, mShowImmediate); + } + mSwipeBackLayout.setScrollChangedListener(fragment); + FragmentTransaction menuTransaction = fm.beginTransaction(); + menuTransaction.replace(R.id.content_frame, fragment); + menuTransaction.commit(); + } else { + String msg = "Couldn't open conversation: {action:"; + msg += intent.getAction(); + msg += ", data:"; + msg += intent.getData() == null ? "null" : intent.getData().toString(); + msg += ", scheme:"; + msg += intent.getData() == null ? "null" : intent.getData().getScheme(); + msg += ", extras:{"; + Object[] keys = intent.getExtras().keySet().toArray(); + for (int i = 0; i < keys.length; i++) { + String key = keys[i].toString(); + msg += keys[i].toString(); + msg += ":"; + msg += intent.getExtras().get(key); + if (i < keys.length - 1) { + msg += ", "; + } + } + msg += "}}"; + Log.d(TAG, msg); + Crashlytics.log(msg); + makeToast(R.string.toast_conversation_error); + finish(); + } + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + MenuInflater inflater = getMenuInflater(); + inflater.inflate(R.menu.message_list, menu); + return super.onCreateOptionsMenu(menu); + } +} diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListFragment.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListFragment.java index faf9114a..3f56f55b 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListFragment.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListFragment.java @@ -1,6 +1,5 @@ package com.moez.QKSMS.ui.messagelist; -import android.app.Activity; import android.app.AlertDialog; import android.app.LoaderManager; import android.content.ContentResolver; @@ -22,6 +21,7 @@ import android.os.AsyncTask; import android.os.Bundle; import android.os.Vibrator; import android.provider.Telephony; +import android.support.annotation.IntegerRes; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.text.SpannableString; @@ -46,8 +46,6 @@ import com.moez.QKSMS.common.CIELChEvaluator; import com.moez.QKSMS.common.ConversationPrefsHelper; import com.moez.QKSMS.common.DialogHelper; import com.moez.QKSMS.common.LiveViewManager; -import com.moez.QKSMS.ui.dialog.conversationdetails.ConversationDetailsDialog; -import com.moez.QKSMS.enums.QKPreference; import com.moez.QKSMS.common.utils.KeyboardUtils; import com.moez.QKSMS.common.utils.MessageUtils; import com.moez.QKSMS.common.vcard.ContactOperations; @@ -56,18 +54,21 @@ import com.moez.QKSMS.data.ContactList; import com.moez.QKSMS.data.Conversation; import com.moez.QKSMS.data.ConversationLegacy; import com.moez.QKSMS.data.Message; +import com.moez.QKSMS.enums.QKPreference; import com.moez.QKSMS.interfaces.ActivityLauncher; import com.moez.QKSMS.transaction.NotificationManager; import com.moez.QKSMS.transaction.SmsHelper; import com.moez.QKSMS.ui.MainActivity; +import com.moez.QKSMS.ui.SwipeBackLayout; import com.moez.QKSMS.ui.ThemeManager; -import com.moez.QKSMS.ui.base.QKContentFragment; +import com.moez.QKSMS.ui.base.QKFragment; import com.moez.QKSMS.ui.base.RecyclerCursorAdapter; import com.moez.QKSMS.ui.delivery.DeliveryReportHelper; import com.moez.QKSMS.ui.delivery.DeliveryReportItem; import com.moez.QKSMS.ui.dialog.AsyncDialog; import com.moez.QKSMS.ui.dialog.ConversationSettingsDialog; import com.moez.QKSMS.ui.dialog.QKDialog; +import com.moez.QKSMS.ui.dialog.conversationdetails.ConversationDetailsDialog; import com.moez.QKSMS.ui.settings.SettingsFragment; import com.moez.QKSMS.ui.view.ComposeView; import com.moez.QKSMS.ui.view.MessageListRecyclerView; @@ -80,8 +81,8 @@ import java.util.ArrayList; import java.util.HashSet; import java.util.List; -public class MessageListFragment extends QKContentFragment implements ActivityLauncher, SensorEventListener, - LoaderManager.LoaderCallbacks, RecyclerCursorAdapter.MultiSelectListener, +public class MessageListFragment extends QKFragment implements ActivityLauncher, SensorEventListener, + LoaderManager.LoaderCallbacks, RecyclerCursorAdapter.MultiSelectListener, SwipeBackLayout.ScrollChangedListener, RecyclerCursorAdapter.ItemClickListener { private final String TAG = "MessageListFragment"; @@ -118,7 +119,6 @@ public class MessageListFragment extends QKContentFragment implements ActivityLa private Conversation mConversation; private ConversationLegacy mConversationLegacy; - private boolean mOpened; private Sensor mProxSensor; private SensorManager mSensorManager; private AsyncDialog mAsyncDialog; @@ -134,26 +134,21 @@ public class MessageListFragment extends QKContentFragment implements ActivityLa private long mLastMessageId; private BackgroundQueryHandler mBackgroundQueryHandler; - public static final String ARG_THREAD_ID = "threadId"; - public static final String ARG_ROW_ID = "rowId"; - public static final String ARG_HIGHLIGHT = "highlight"; - public static final String ARG_SHOW_IMMEDIATE = "showImmediate"; - private long mThreadId; private long mRowId; private String mHighlight; private boolean mShowImmediate; - public static MessageListFragment getInstance(long threadId, long rowId, String highlight, boolean showImmediate) { + protected static MessageListFragment getInstance(long threadId, long rowId, String highlight, boolean showImmediate) { Bundle args = new Bundle(); - args.putLong(ARG_THREAD_ID, threadId); - args.putLong(ARG_ROW_ID, rowId); - args.putString(ARG_HIGHLIGHT, highlight); - args.putBoolean(ARG_SHOW_IMMEDIATE, showImmediate); + args.putLong(MessageListActivity.ARG_THREAD_ID, threadId); + args.putLong(MessageListActivity.ARG_ROW_ID, rowId); + args.putString(MessageListActivity.ARG_HIGHLIGHT, highlight); + args.putBoolean(MessageListActivity.ARG_SHOW_IMMEDIATE, showImmediate); MessageListFragment fragment = new MessageListFragment(); - fragment.updateArguments(args); + fragment.setArguments(args); return fragment; } @@ -166,16 +161,23 @@ public class MessageListFragment extends QKContentFragment implements ActivityLa public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - if (savedInstanceState != null) { - mThreadId = savedInstanceState.getLong(ARG_THREAD_ID, -1); - mRowId = savedInstanceState.getLong(ARG_ROW_ID, -1); - mHighlight = savedInstanceState.getString(ARG_HIGHLIGHT, null); - mShowImmediate = savedInstanceState.getBoolean(ARG_SHOW_IMMEDIATE, false); + if (getArguments() != null) { + Bundle args = getArguments(); + mThreadId = args.getLong(MessageListActivity.ARG_THREAD_ID, -1); + mRowId = args.getLong(MessageListActivity.ARG_ROW_ID, -1); + mHighlight = args.getString(MessageListActivity.ARG_HIGHLIGHT, null); + mShowImmediate = args.getBoolean(MessageListActivity.ARG_SHOW_IMMEDIATE, false); + } else if (savedInstanceState != null) { + mThreadId = savedInstanceState.getLong(MessageListActivity.ARG_THREAD_ID, -1); + mRowId = savedInstanceState.getLong(MessageListActivity.ARG_ROW_ID, -1); + mHighlight = savedInstanceState.getString(MessageListActivity.ARG_HIGHLIGHT, null); + mShowImmediate = savedInstanceState.getBoolean(MessageListActivity.ARG_SHOW_IMMEDIATE, false); } mConversationPrefs = new ConversationPrefsHelper(mContext, mThreadId); mIsSmsEnabled = MmsConfig.isSmsEnabled(mContext); mConversationDetailsDialog = new ConversationDetailsDialog(mContext, getFragmentManager()); + onOpenConversation(); setHasOptionsMenu(true); LiveViewManager.registerView(QKPreference.CONVERSATION_THEME, this, key -> { @@ -193,29 +195,12 @@ public class MessageListFragment extends QKContentFragment implements ActivityLa mBackgroundQueryHandler = new BackgroundQueryHandler(mContext.getContentResolver()); } - // This is called by BaseContentFragment when updateArguments is called. - @Override - public void onNewArguments() { - loadFromArguments(); - } - - public void loadFromArguments() { - // Save the fields from the arguments - Bundle args = getArguments(); - mThreadId = args.getLong(ARG_THREAD_ID, -1); - mRowId = args.getLong(ARG_ROW_ID, -1); - mHighlight = args.getString(ARG_HIGHLIGHT, null); - mShowImmediate = args.getBoolean(ARG_SHOW_IMMEDIATE, false); - } - @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_conversation, container, false); mRecyclerView = (MessageListRecyclerView) view.findViewById(R.id.conversation); - mOpened = !((MainActivity) mContext).getSlidingMenu().isMenuShowing(); - mAdapter = new MessageListAdapter(mContext); mAdapter.setItemClickListener(this); mAdapter.setMultiSelectListener(this); @@ -262,26 +247,19 @@ public class MessageListFragment extends QKContentFragment implements ActivityLa public void onResume() { super.onResume(); - // All the data about the conversation, such as the thread ID and the row ID to skip to, is - // stored in the arguments. So, calling this method will set up all the fields and then - // perform initialization such as set up the Conversation object, make a query in the - // adapter, etc. - loadFromArguments(); - onOpenConversation(); - } + if (mContext.getBoolean(QKPreference.PROXIMITY_SENSOR)) { + mSensorManager.registerListener(this, mProxSensor, SensorManager.SENSOR_DELAY_NORMAL); + } - @Override - public void onDestroy() { - super.onDestroy(); - mComposeView.saveDraft(); + ThemeManager.setActiveColor(mConversationPrefs.getColor()); } @Override public void onSaveInstanceState(Bundle outState) { - outState.putLong(ARG_THREAD_ID, mThreadId); - outState.putLong(ARG_ROW_ID, mRowId); - outState.putString(ARG_HIGHLIGHT, mHighlight); - outState.putBoolean(ARG_SHOW_IMMEDIATE, mShowImmediate); + outState.putLong(MessageListActivity.ARG_THREAD_ID, mThreadId); + outState.putLong(MessageListActivity.ARG_ROW_ID, mRowId); + outState.putString(MessageListActivity.ARG_HIGHLIGHT, mHighlight); + outState.putBoolean(MessageListActivity.ARG_SHOW_IMMEDIATE, mShowImmediate); } public long getThreadId() { @@ -299,7 +277,7 @@ public class MessageListFragment extends QKContentFragment implements ActivityLa } private void setTitle() { - if (mContext != null && mConversation != null && !((MainActivity) mContext).getSlidingMenu().isMenuShowing()) { + if (mContext != null && mConversation != null) { mContext.setTitle(mConversation.getRecipients().formatNames(", ")); } } @@ -481,9 +459,8 @@ public class MessageListFragment extends QKContentFragment implements ActivityLa return true; case R.id.menu_notifications: - ConversationPrefsHelper conversationPrefs = new ConversationPrefsHelper(mContext, mThreadId); - boolean notificationMuted = conversationPrefs.getNotificationsEnabled(); - conversationPrefs.putBoolean(SettingsFragment.NOTIFICATIONS, !notificationMuted); + boolean notificationMuted = mConversationPrefs.getNotificationsEnabled(); + mConversationPrefs.putBoolean(SettingsFragment.NOTIFICATIONS, !notificationMuted); mContext.invalidateOptionsMenu(); vibrateOnConversationStateChanged(notificationMuted); return true; @@ -598,67 +575,35 @@ public class MessageListFragment extends QKContentFragment implements ActivityLa } @Override - public void onContentOpening() { - super.onContentOpening(); - mOpened = false; // We're animating the fragment in, this flag warns us not to do anything heavy - } + public void onPause() { + super.onPause(); + mComposeView.saveDraft(); - @Override - public void onContentOpened() { - super.onContentOpened(); - mOpened = true; // The fragment has finished animating in - - if (mContext.getBoolean(QKPreference.PROXIMITY_SENSOR)) { - mSensorManager.registerListener(this, mProxSensor, SensorManager.SENSOR_DELAY_NORMAL); - } - - ThemeManager.setActiveColor(mConversationPrefs.getColor()); - } - - @Override - public void onContentClosing() { - } - - @Override - public void onContentClosed() { if (mSensorManager != null) { mSensorManager.unregisterListener(this); } - if (mOpened) { - if (mConversationLegacy != null) { - mConversationLegacy.markRead(); - } + if (mConversationLegacy != null) { + mConversationLegacy.markRead(); + } - if (mConversation != null) { - mConversation.blockMarkAsRead(true); - mConversation.markAsRead(); - mComposeView.saveDraft(); - } + if (mConversation != null) { + mConversation.blockMarkAsRead(true); + mConversation.markAsRead(); + mComposeView.saveDraft(); } ThemeManager.setActiveColor(ThemeManager.getThemeColor()); } @Override - public void onMenuChanging(float percentOpen) { - if (mConversationPrefs != null) { - ThemeManager.setActiveColor(mCIELChEvaluator.evaluate(percentOpen)); - } - } - - @Override - public void inflateToolbar(Menu menu, MenuInflater inflater, Context context) { - inflater.inflate(R.menu.conversation, menu); - setTitle(); - - ConversationPrefsHelper conversationPrefs = new ConversationPrefsHelper(context, mThreadId); - menu.findItem(R.id.menu_notifications).setTitle(conversationPrefs.getNotificationsEnabled() ? - R.string.menu_notifications : R.string.menu_notifications_off); - menu.findItem(R.id.menu_notifications).setIcon(conversationPrefs.getNotificationsEnabled() ? - R.drawable.ic_notifications : R.drawable.ic_notifications_muted); - + public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); + + menu.findItem(R.id.menu_notifications).setTitle(mConversationPrefs.getNotificationsEnabled() ? + R.string.menu_notifications : R.string.menu_notifications_off); + menu.findItem(R.id.menu_notifications).setIcon(mConversationPrefs.getNotificationsEnabled() ? + R.drawable.ic_notifications : R.drawable.ic_notifications_muted); } @Override @@ -707,6 +652,13 @@ public class MessageListFragment extends QKContentFragment implements ActivityLa } + @Override + public void onScrollChanged(float scrollPercent) { + if (mConversationPrefs != null) { + ThemeManager.setActiveColor(mCIELChEvaluator.evaluate(scrollPercent)); + } + } + private class DeleteMessageListener implements DialogInterface.OnClickListener { private final MessageItem mMessageItem; @@ -965,9 +917,7 @@ public class MessageListFragment extends QKContentFragment implements ActivityLa conv.clearThreadId(); conv.setDraftState(false); } - // The last message in this converation was just deleted. Send the user - // to the conversation list. - ((MainActivity) mContext).showMenu(); + mContext.onBackPressed(); } cursor.close(); } @@ -1010,7 +960,7 @@ public class MessageListFragment extends QKContentFragment implements ActivityLa Conversation.init(mContext); // Go back to the conversation list - ((MainActivity) mContext).showMenu(); + mContext.onBackPressed(); } else if (token == DELETE_MESSAGE_TOKEN) { // Check to see if we just deleted the last message startMsgListQuery(MESSAGE_LIST_QUERY_AFTER_DELETE_TOKEN); @@ -1036,25 +986,6 @@ public class MessageListFragment extends QKContentFragment implements ActivityLa mConversation.blockMarkAsRead(true); mConversation.markAsRead(); - // Delay the thread until the fragment has finished opening. If it waits longer than - // 10 seconds, then something is wrong, so cancel it. This happens when the fragment is closed before - // it opens, or the screen is rotated, and then "mOpened" never gets changed to true, - // leaving this thread running forever. This issue is actually what caused the great - // QKSMS battery drain of 2015 - long time = System.currentTimeMillis(); - while (!mOpened) { - try { - Thread.sleep(100); - } catch (InterruptedException e) { - e.printStackTrace(); - } - if (System.currentTimeMillis() - time > 10000) { - Log.w(TAG, "Task running for over 10 seconds, something is wrong"); - cancel(true); - break; - } - } - return null; } diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/popup/QKReplyActivity.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/popup/QKReplyActivity.java index eb681102..24666ec8 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/popup/QKReplyActivity.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/popup/QKReplyActivity.java @@ -28,6 +28,7 @@ import com.moez.QKSMS.ui.MainActivity; import com.moez.QKSMS.ui.ThemeManager; import com.moez.QKSMS.ui.base.QKPopupActivity; import com.moez.QKSMS.ui.messagelist.MessageColumns; +import com.moez.QKSMS.ui.messagelist.MessageListActivity; import com.moez.QKSMS.ui.view.ComposeView; public class QKReplyActivity extends QKPopupActivity implements DialogInterface.OnDismissListener, @@ -190,7 +191,7 @@ public class QKReplyActivity extends QKPopupActivity implements DialogInterface. case R.id.menu_open_thread: Intent threadIntent = new Intent(this, MainActivity.class); - threadIntent.putExtra(MainActivity.EXTRA_THREAD_ID, mConversationLegacy.getThreadId()); + threadIntent.putExtra(MessageListActivity.ARG_THREAD_ID, mConversationLegacy.getThreadId()); startActivity(threadIntent); finish(); return true; diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/search/SearchActivity.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/search/SearchActivity.java new file mode 100644 index 00000000..3f2add86 --- /dev/null +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/search/SearchActivity.java @@ -0,0 +1,35 @@ +package com.moez.QKSMS.ui.search; + +import android.app.FragmentManager; +import android.os.Bundle; +import android.view.Menu; +import android.view.MenuInflater; +import com.moez.QKSMS.R; +import com.moez.QKSMS.ui.base.QKSwipeBackActivity; + +public class SearchActivity extends QKSwipeBackActivity { + + private SearchFragment mSearchFragment; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setTitle(R.string.title_search); + + FragmentManager fm = getFragmentManager(); + mSearchFragment = (SearchFragment) fm.findFragmentById(R.id.content_frame); + if (mSearchFragment == null) { + mSearchFragment = new SearchFragment(); + } + + fm.beginTransaction() + .replace(R.id.content_frame, mSearchFragment) + .commit(); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + new MenuInflater(this).inflate(R.menu.search, menu); + return super.onCreateOptionsMenu(menu); + } +} diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/search/SearchFragment.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/search/SearchFragment.java index 12ebac04..c7286c74 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/search/SearchFragment.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/search/SearchFragment.java @@ -1,28 +1,24 @@ package com.moez.QKSMS.ui.search; import android.content.AsyncQueryHandler; -import android.content.Context; import android.content.SharedPreferences; import android.content.res.Resources; import android.database.Cursor; import android.net.Uri; import android.os.Bundle; +import android.os.Handler; import android.provider.Telephony; import android.support.v7.widget.LinearLayoutManager; -import android.view.KeyEvent; import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuInflater; import android.view.View; import android.view.ViewGroup; import android.view.inputmethod.EditorInfo; import com.moez.QKSMS.R; import com.moez.QKSMS.common.utils.KeyboardUtils; import com.moez.QKSMS.data.Contact; -import com.moez.QKSMS.ui.MainActivity; -import com.moez.QKSMS.ui.base.QKActivity; -import com.moez.QKSMS.ui.base.QKContentFragment; +import com.moez.QKSMS.ui.base.QKFragment; import com.moez.QKSMS.ui.base.RecyclerCursorAdapter; +import com.moez.QKSMS.ui.messagelist.MessageListActivity; import com.moez.QKSMS.ui.view.MessageListRecyclerView; import com.moez.QKSMS.ui.view.QKEditText; import com.moez.QKSMS.ui.view.QKTextView; @@ -30,7 +26,7 @@ import com.moez.QKSMS.ui.view.QKTextView; import java.util.HashMap; import java.util.regex.Pattern; -public class SearchFragment extends QKContentFragment implements RecyclerCursorAdapter.ItemClickListener { +public class SearchFragment extends QKFragment implements RecyclerCursorAdapter.ItemClickListener { private AsyncQueryHandler mQueryHandler; // Track which TextView's show which Contact objects so that we can update @@ -47,6 +43,10 @@ public class SearchFragment extends QKContentFragment implements RecyclerCursorA private SearchAdapter mAdapter; private Pattern mPattern; + public SearchFragment() { + + } + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -68,27 +68,21 @@ public class SearchFragment extends QKContentFragment implements RecyclerCursorA View view = inflater.inflate(R.layout.fragment_search, container, false); mQuery = (QKEditText) view.findViewById(R.id.search_query); - mQuery.setTextChangedListener(new QKEditText.TextChangedListener() { - @Override - public void onTextChanged(CharSequence s) { - mSearchString = s.toString(); - query(); - } + mQuery.setTextChangedListener(s -> { + mSearchString = s.toString(); + query(); }); - mQuery.setOnEditorActionListener(new QKTextView.OnEditorActionListener() { - @Override - public boolean onEditorAction(android.widget.TextView v, int actionId, KeyEvent event) { - if (actionId == EditorInfo.IME_ACTION_SEARCH) { - mSearchString = mQuery.getText().toString(); - query(); + mQuery.setOnEditorActionListener((v, actionId, event) -> { + if (actionId == EditorInfo.IME_ACTION_SEARCH) { + mSearchString = mQuery.getText().toString(); + query(); - // Hide the keyboard when the user makes a query - mQuery.clearFocus(); - KeyboardUtils.hide(mContext, mQuery); - return true; - } - return false; + // Hide the keyboard when the user makes a query + mQuery.clearFocus(); + KeyboardUtils.hide(mContext, mQuery); + return true; } + return false; }); mLayoutManager = new LinearLayoutManager(mContext); @@ -100,6 +94,7 @@ public class SearchFragment extends QKContentFragment implements RecyclerCursorA mRecyclerView.setLayoutManager(mLayoutManager); mRecyclerView.setAdapter(mAdapter); + new Handler().postDelayed(() -> KeyboardUtils.showAndFocus(mContext, mQuery), 50); return view; } @@ -114,12 +109,10 @@ public class SearchFragment extends QKContentFragment implements RecyclerCursorA } - Contact.UpdateListener mContactListener = new Contact.UpdateListener() { - public void onUpdate(Contact updated) { - QKTextView tv = mContactMap.get(updated); - if (tv != null) { - tv.setText(updated.getNameAndNumber()); - } + Contact.UpdateListener mContactListener = updated -> { + QKTextView tv = mContactMap.get(updated); + if (tv != null) { + tv.setText(updated.getNameAndNumber()); } }; @@ -129,29 +122,10 @@ public class SearchFragment extends QKContentFragment implements RecyclerCursorA Contact.removeListener(mContactListener); } - @Override - public void onContentOpened() { - // Show the keyboard and focus on the query text when the fragment is opened. - KeyboardUtils.showAndFocus(mContext, mQuery); - } - - @Override - public void onMenuChanging(float percentOpen) { - - } - - @Override - public void inflateToolbar(Menu menu, MenuInflater inflater, Context context) { - inflater.inflate(R.menu.search, menu); - ((QKActivity) context).setTitle(R.string.title_search); - - super.onCreateOptionsMenu(menu, inflater); - } - @Override public void onItemClick(SearchData data, View view) { - MainActivity mainActivity = (MainActivity) mContext; - mainActivity.setConversation(data.threadId, data.rowId, mSearchString); + MessageListActivity.launch(mContext, data.threadId, data.rowId, mSearchString, true); + mContext.finish(); } @Override diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/settings/SettingsActivity.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/settings/SettingsActivity.java new file mode 100644 index 00000000..b7458458 --- /dev/null +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/settings/SettingsActivity.java @@ -0,0 +1,35 @@ +package com.moez.QKSMS.ui.settings; + +import android.app.FragmentManager; +import android.os.Bundle; +import com.moez.QKSMS.R; +import com.moez.QKSMS.ui.base.QKSwipeBackActivity; + +public class SettingsActivity extends QKSwipeBackActivity { + + private SettingsFragment mSettingsFragment; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + FragmentManager fm = getFragmentManager(); + mSettingsFragment = (SettingsFragment) fm.findFragmentById(R.id.content_frame); + if (mSettingsFragment == null) { + mSettingsFragment = SettingsFragment.newInstance(R.xml.settings_main); + } + + fm.beginTransaction() + .replace(R.id.content_frame, mSettingsFragment) + .commit(); + } + + @Override + public void onBackPressed() { + if (getFragmentManager().getBackStackEntryCount() > 0) { + getFragmentManager().popBackStack(); + } else { + super.onBackPressed(); + } + } +} diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/settings/SettingsFragment.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/settings/SettingsFragment.java index ec0b8a83..b23f1269 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/settings/SettingsFragment.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/settings/SettingsFragment.java @@ -35,17 +35,16 @@ import com.moez.QKSMS.common.DialogHelper; import com.moez.QKSMS.common.DonationManager; import com.moez.QKSMS.common.ListviewHelper; import com.moez.QKSMS.common.LiveViewManager; -import com.moez.QKSMS.enums.QKPreference; 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.enums.QKPreference; import com.moez.QKSMS.receiver.NightModeAutoReceiver; import com.moez.QKSMS.transaction.EndlessJabber; import com.moez.QKSMS.transaction.NotificationManager; import com.moez.QKSMS.transaction.SmsHelper; -import com.moez.QKSMS.ui.ContentFragment; -import com.moez.QKSMS.ui.MainActivity; import com.moez.QKSMS.ui.ThemeManager; +import com.moez.QKSMS.ui.base.QKActivity; import com.moez.QKSMS.ui.dialog.BlockedNumberDialog; import com.moez.QKSMS.ui.dialog.BubblePreferenceDialog; import com.moez.QKSMS.ui.dialog.QKDialog; @@ -65,7 +64,7 @@ import java.util.Set; import java.util.Stack; public class SettingsFragment extends PreferenceFragment implements Preference.OnPreferenceChangeListener, - Preference.OnPreferenceClickListener, ContentFragment { + Preference.OnPreferenceClickListener { private final String TAG = "PreferenceFragment"; public static final String CATEGORY_APPEARANCE = "pref_key_category_appearance"; @@ -100,7 +99,6 @@ public class SettingsFragment extends PreferenceFragment implements Preference.O public static final String FONT_SIZE = "pref_key_font_size"; public static final String FONT_WEIGHT = "pref_key_font_weight"; public static final String MESSAGE_COUNT = "pref_key_message_count"; - public static final String SLIDING_TAB = "pref_key_sliding_tab"; public static final String PROXIMITY_CALLING = "pref_key_prox_sensor_calling"; public static final String DELIVERY_REPORTS = "pref_key_delivery"; public static final String DELIVERY_TOAST = "pref_key_delivery_toast"; @@ -163,7 +161,7 @@ public class SettingsFragment extends PreferenceFragment implements Preference.O public static final String GITHUB_URL = "https://github.com/qklabs/qksms"; public static final String CROWDIN_URL = "https://crowdin.com/project/qksms"; - private MainActivity mContext; + private QKActivity mContext; private PreferenceManager mPreferenceManager; private SharedPreferences mPrefs; private Resources mRes; @@ -186,7 +184,7 @@ public class SettingsFragment extends PreferenceFragment implements Preference.O private int mResource; - public static SettingsFragment newInstance(int category) { + protected static SettingsFragment newInstance(int category) { SettingsFragment fragment = new SettingsFragment(); Bundle args = new Bundle(); @@ -200,11 +198,14 @@ public class SettingsFragment extends PreferenceFragment implements Preference.O public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Bundle args = getArguments(); + setHasOptionsMenu(true); - mContext = (MainActivity) getActivity(); + mContext = (QKActivity) getActivity(); mPrefs = mContext.getPrefs(); mRes = mContext.getResources(); + mContext.setTitle(R.string.title_settings); + mResource = args.getInt("category", R.xml.settings); addPreferencesFromResource(mResource); @@ -333,6 +334,12 @@ public class SettingsFragment extends PreferenceFragment implements Preference.O } } + @Override + public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + inflater.inflate(R.menu.settings, menu); + super.onCreateOptionsMenu(menu, inflater); + } + /** * Removed top level preferences from the layout */ @@ -431,9 +438,6 @@ public class SettingsFragment extends PreferenceFragment implements Preference.O case NIGHT_START: updateAlarmManager(mContext, true); break; - case SLIDING_TAB: - mContext.setSlidingTabEnabled((Boolean) newValue); - break; case YAPPY: if ((Boolean) newValue) { try { @@ -520,6 +524,7 @@ public class SettingsFragment extends PreferenceFragment implements Preference.O Fragment fragment = SettingsFragment.newInstance(resId); getFragmentManager() .beginTransaction() + .addToBackStack(null) .replace(R.id.content_frame, fragment, CATEGORY_TAG) .commit(); } @@ -704,40 +709,4 @@ public class SettingsFragment extends PreferenceFragment implements Preference.O alarmManager.cancel(nightIntent); } } - - @Override - public void onContentOpening() { - - } - - @Override - public void onContentOpened() { - - } - - @Override - public void onContentClosing() { - - } - - @Override - public void onContentClosed() { - - } - - @Override - public void onMenuChanging(float percentOpen) { - - } - - @Override - public void inflateToolbar(Menu menu, MenuInflater inflater, Context context) { - if (mContext == null) { - mContext = (MainActivity) context; - mPrefs = mContext.getPrefs(); - } - - inflater.inflate(R.menu.settings, menu); - mContext.setTitle(R.string.title_settings); - } } diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/slidingmenu/CustomViewAbove.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/slidingmenu/CustomViewAbove.java deleted file mode 100644 index bec8be98..00000000 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/slidingmenu/CustomViewAbove.java +++ /dev/null @@ -1,866 +0,0 @@ -package com.moez.QKSMS.ui.view.slidingmenu; - -import android.content.Context; -import android.graphics.Canvas; -import android.support.v4.view.KeyEventCompat; -import android.support.v4.view.MotionEventCompat; -import android.support.v4.view.VelocityTrackerCompat; -import android.support.v4.view.ViewConfigurationCompat; -import android.util.AttributeSet; -import android.util.FloatMath; -import android.util.Log; -import android.view.FocusFinder; -import android.view.KeyEvent; -import android.view.MotionEvent; -import android.view.SoundEffectConstants; -import android.view.VelocityTracker; -import android.view.View; -import android.view.ViewConfiguration; -import android.view.ViewGroup; -import android.view.animation.Interpolator; -import android.widget.Scroller; - -public class CustomViewAbove extends ViewGroup { - - private static final String TAG = "CustomViewAbove"; - private static final boolean DEBUG = false; - - private static final boolean USE_CACHE = false; - - private static final int MAX_SETTLE_DURATION = 350; // ms - private static final int MIN_DISTANCE_FOR_FLING = 25; // dips - - private static final Interpolator sInterpolator = t -> (float) Math.pow(0.63 * t - 1.0f, 5) + 1.0f; - - private View mContent; - - private int mCurItem; - private Scroller mScroller; - - private boolean mScrollingCacheEnabled; - - private boolean mScrolling; - - private boolean mIsBeingDragged; - private boolean mIsUnableToDrag; - private int mTouchSlop; - private float mInitialMotionX; - /** - * Position of the last motion event. - */ - private float mLastMotionX; - private float mLastMotionY; - /** - * ID of the active pointer. This is used to retain consistency during - * drags/flings if multiple pointers are used. - */ - protected int mActivePointerId = INVALID_POINTER; - /** - * Sentinel value for no current active pointer. - * Used by {@link #mActivePointerId}. - */ - private static final int INVALID_POINTER = -1; - - /** - * Determines speed during touch scrolling - */ - protected VelocityTracker mVelocityTracker; - private int mMinimumVelocity; - protected int mMaximumVelocity; - private int mFlingDistance; - - private CustomViewBehind mViewBehind; - - private OnPageChangeListener mOnPageChangeListener; - private OnPageChangeListener mInternalPageChangeListener; - - private SlidingMenu.SlidingMenuListener mListener; - - /** - * Callback interface for responding to changing state of the selected page. - */ - public interface OnPageChangeListener { - - /** - * This method will be invoked when the current page is scrolled, either as part - * of a programmatically initiated smooth scroll or a user initiated touch scroll. - * - * @param position Position index of the first page currently being displayed. - * Page position+1 will be visible if positionOffset is nonzero. - * @param positionOffset Value from [0, 1) indicating the offset from the page at position. - * @param positionOffsetPixels Value in pixels indicating the offset from position. - */ - void onPageScrolled(int position, float positionOffset, int positionOffsetPixels); - - /** - * This method will be invoked when a new page becomes selected. Animation is not - * necessarily complete. - * - * @param position Position index of the new selected page. - */ - void onPageSelected(int position, boolean anim); - - } - - /** - * Simple implementation of the {@link OnPageChangeListener} interface with stub - * implementations of each method. Extend this if you do not intend to override - * every method of {@link OnPageChangeListener}. - */ - public static class SimpleOnPageChangeListener implements OnPageChangeListener { - - public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { - // This space for rent - } - - public void onPageSelected(int position, boolean anim) { - // This space for rent - } - - } - - public CustomViewAbove(Context context) { - this(context, null); - } - - public CustomViewAbove(Context context, AttributeSet attrs) { - super(context, attrs); - initCustomViewAbove(); - } - - void initCustomViewAbove() { - setWillNotDraw(false); - setDescendantFocusability(FOCUS_AFTER_DESCENDANTS); - setFocusable(true); - final Context context = getContext(); - mScroller = new Scroller(context, sInterpolator); - final ViewConfiguration configuration = ViewConfiguration.get(context); - mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration); - mMinimumVelocity = configuration.getScaledMinimumFlingVelocity(); - mMaximumVelocity = configuration.getScaledMaximumFlingVelocity(); - setInternalPageChangeListener(new SimpleOnPageChangeListener() { - public void onPageSelected(int position, boolean anim) { - if (mViewBehind != null) { - switch (position) { - case 0: - case 2: - mViewBehind.setChildrenEnabled(true); - break; - case 1: - mViewBehind.setChildrenEnabled(false); - break; - } - } - } - }); - - final float density = context.getResources().getDisplayMetrics().density; - mFlingDistance = (int) (MIN_DISTANCE_FOR_FLING * density); - } - - /** - * Set the currently selected page. If the CustomViewPager has already been through its first - * layout there will be a smooth animated transition between the current item and the - * specified item. - * - * @param item Item index to select - */ - public void setCurrentItem(int item) { - setCurrentItem(item, true); - } - - /** - * Set the currently selected page. - * - * @param item Item index to select - * @param smoothScroll True to smoothly scroll to the new item, false to transition immediately - */ - public void setCurrentItem(int item, boolean smoothScroll) { - setCurrentItem(item, smoothScroll, false); - } - - /** - * Set the currently selected page. - * - * @param item Item index to select - * @param smoothScroll True to smoothly scroll to the new item, false to transition immediately - * @param notify True if the open and close listeners should be notified. - */ - public void setCurrentItem(int item, boolean smoothScroll, boolean notify) { - setCurrentItemInternal(item, smoothScroll, false, 0, notify); - } - - public int getCurrentItem() { - return mCurItem; - } - - void setCurrentItemInternal(int item, boolean smoothScroll, boolean always) { - setCurrentItemInternal(item, smoothScroll, always, 0); - } - - void setCurrentItemInternal(int item, boolean smoothScroll, boolean always, int velocity) { - setCurrentItemInternal(item, smoothScroll, always, velocity, false); - } - - void setCurrentItemInternal(int item, boolean smoothScroll, boolean always, int velocity, boolean notify) { - if (!always && mCurItem == item) { - setScrollingCacheEnabled(false); - - if (notify) { - // Notify the listeners here, because the client has switched content. - if (isMenuOpen()) { - if (mListener != null) - mListener.onOpened(); - } else { - if (mListener != null) - mListener.onClosed(); - } - } - - return; - } - - item = mViewBehind.getMenuPage(item); - - final boolean dispatchSelected = mCurItem != item; - mCurItem = item; - final int destX = getDestScrollX(mCurItem); - if (dispatchSelected && mOnPageChangeListener != null) { - mOnPageChangeListener.onPageSelected(item, smoothScroll); - } - if (dispatchSelected && mInternalPageChangeListener != null) { - mInternalPageChangeListener.onPageSelected(item, smoothScroll); - } - if (smoothScroll) { - smoothScrollTo(destX, 0, velocity); - } else { - completeScroll(); - scrollTo(destX, 0); - } - } - - /** - * Set a listener that will be invoked whenever the page changes or is incrementally - * scrolled. See {@link OnPageChangeListener}. - * - * @param listener Listener to set - */ - public void setOnPageChangeListener(OnPageChangeListener listener) { - mOnPageChangeListener = listener; - } - - public void setListener(SlidingMenu.SlidingMenuListener listener) { - mListener = listener; - } - - /** - * Set a separate OnPageChangeListener for internal use by the support library. - * - * @param listener Listener to set - * @return The old listener that was set, if any. - */ - OnPageChangeListener setInternalPageChangeListener(OnPageChangeListener listener) { - OnPageChangeListener oldListener = mInternalPageChangeListener; - mInternalPageChangeListener = listener; - return oldListener; - } - - // We want the duration of the page snap animation to be influenced by the distance that - // the screen has to travel, however, we don't want this duration to be effected in a - // purely linear fashion. Instead, we use this method to moderate the effect that the distance - // of travel has on the overall snap duration. - float distanceInfluenceForSnapDuration(float f) { - f -= 0.5f; // center the values about 0. - f *= 0.3f * Math.PI / 2.0f; - return FloatMath.sin(f); - } - - public int getDestScrollX(int page) { - switch (page) { - case 0: - case 2: - return mViewBehind.getMenuLeft(mContent, page); - case 1: - return mContent.getLeft(); - } - return 0; - } - - private int getLeftBound() { - return mViewBehind.getAbsLeftBound(mContent); - } - - private int getRightBound() { - return mViewBehind.getAbsRightBound(mContent); - } - - public boolean isMenuOpen() { - return mCurItem == 0 || mCurItem == 2; - } - - public int getBehindWidth() { - if (mViewBehind == null) { - return 0; - } else { - return mViewBehind.getBehindWidth(); - } - } - - /** - * Like {@link View#scrollBy}, but scroll smoothly instead of immediately. - * - * @param x the number of pixels to scroll by on the X axis - * @param y the number of pixels to scroll by on the Y axis - * @param velocity the velocity associated with a fling, if applicable. (0 otherwise) - */ - void smoothScrollTo(int x, int y, int velocity) { - if (getChildCount() == 0) { - // Nothing to do. - setScrollingCacheEnabled(false); - return; - } - int sx = getScrollX(); - int sy = getScrollY(); - int dx = x - sx; - int dy = y - sy; - if (dx == 0 && dy == 0) { - completeScroll(); - if (isMenuOpen()) { - if (mListener != null) - mListener.onOpened(); - } else { - if (mListener != null) - mListener.onClosed(); - } - return; - } - - setScrollingCacheEnabled(true); - mScrolling = true; - - final int width = getBehindWidth(); - final int halfWidth = width / 2; - final float distanceRatio = Math.min(1f, 1.0f * Math.abs(dx) / width); - final float distance = halfWidth + halfWidth * - distanceInfluenceForSnapDuration(distanceRatio); - - int duration = 0; - velocity = Math.abs(velocity); - if (velocity > 0) { - duration = 4 * Math.round(1000 * Math.abs(distance / velocity)); - } else { - duration = MAX_SETTLE_DURATION; - } - duration = Math.min(duration, MAX_SETTLE_DURATION); - - mScroller.startScroll(sx, sy, dx, dy, duration); - invalidate(); - } - - public void setContent(View v) { - if (mContent != null) - this.removeView(mContent); - mContent = v; - addView(mContent); - } - - public View getContent() { - return mContent; - } - - public void setCustomViewBehind(CustomViewBehind cvb) { - mViewBehind = cvb; - } - - @Override - protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - - int width = getDefaultSize(0, widthMeasureSpec); - int height = getDefaultSize(0, heightMeasureSpec); - setMeasuredDimension(width, height); - - final int contentWidth = getChildMeasureSpec(widthMeasureSpec, 0, width); - final int contentHeight = getChildMeasureSpec(heightMeasureSpec, 0, height); - mContent.measure(contentWidth, contentHeight); - } - - @Override - protected void onSizeChanged(int w, int h, int oldw, int oldh) { - super.onSizeChanged(w, h, oldw, oldh); - // Make sure scroll position is set correctly. - if (w != oldw) { - // [ChrisJ] - This fixes the onConfiguration change for orientation issue.. - // maybe worth having a look why the recomputeScroll pos is screwing up? - completeScroll(); - scrollTo(getDestScrollX(mCurItem), getScrollY()); - } - } - - @Override - protected void onLayout(boolean changed, int l, int t, int r, int b) { - final int width = r - l; - final int height = b - t; - mContent.layout(0, 0, width, height); - } - - - @Override - public void computeScroll() { - if (!mScroller.isFinished()) { - if (mScroller.computeScrollOffset()) { - int oldX = getScrollX(); - int oldY = getScrollY(); - int x = mScroller.getCurrX(); - int y = mScroller.getCurrY(); - - if (oldX != x || oldY != y) { - scrollTo(x, y); - pageScrolled(x); - } - - // Keep on drawing until the animation has finished. - invalidate(); - return; - } - } - - // Done with scroll, clean up state. - completeScroll(); - } - - private void pageScrolled(int xpos) { - final int widthWithMargin = getWidth(); - final int position = xpos / widthWithMargin; - final int offsetPixels = xpos % widthWithMargin; - final float offset = (float) offsetPixels / widthWithMargin; - - onPageScrolled(position, offset, offsetPixels); - } - - /** - * This method will be invoked when the current page is scrolled, either as part - * of a programmatically initiated smooth scroll or a user initiated touch scroll. - * If you override this method you must call through to the superclass implementation - * (e.g. super.onPageScrolled(position, offset, offsetPixels)) before onPageScrolled - * returns. - * - * @param position Position index of the first page currently being displayed. - * Page position+1 will be visible if positionOffset is nonzero. - * @param offset Value from [0, 1) indicating the offset from the page at position. - * @param offsetPixels Value in pixels indicating the offset from position. - */ - protected void onPageScrolled(int position, float offset, int offsetPixels) { - if (mOnPageChangeListener != null) { - mOnPageChangeListener.onPageScrolled(position, offset, offsetPixels); - } - if (mInternalPageChangeListener != null) { - mInternalPageChangeListener.onPageScrolled(position, offset, offsetPixels); - } - } - - private void completeScroll() { - boolean needPopulate = mScrolling; - if (needPopulate) { - // Done with scroll, no longer want to cache view drawing. - setScrollingCacheEnabled(false); - mScroller.abortAnimation(); - int oldX = getScrollX(); - int oldY = getScrollY(); - int x = mScroller.getCurrX(); - int y = mScroller.getCurrY(); - if (oldX != x || oldY != y) { - scrollTo(x, y); - } - if (isMenuOpen()) { - if (mListener != null) - mListener.onOpened(); - } else { - if (mListener != null) - mListener.onClosed(); - } - } - mScrolling = false; - } - - private boolean thisTouchAllowed(MotionEvent ev) { - return !isMenuOpen(); - } - - private boolean thisSlideAllowed(float dx) { - boolean allowed; - if (isMenuOpen()) { - allowed = mViewBehind.menuOpenSlideAllowed(dx); - } else { - allowed = mViewBehind.menuClosedSlideAllowed(dx); - } - if (DEBUG) - Log.v(TAG, "this slide allowed " + allowed + " dx: " + dx); - return allowed; - } - - private int getPointerIndex(MotionEvent ev, int id) { - int activePointerIndex = MotionEventCompat.findPointerIndex(ev, id); - if (activePointerIndex == -1) - mActivePointerId = INVALID_POINTER; - return activePointerIndex; - } - - /** - * True if the user has tapped DOWN, and so tapping UP means that the drawer should open. - */ - private boolean mQuickReturn = false; - - @Override - public boolean onInterceptTouchEvent(MotionEvent ev) { - - final int action = ev.getAction() & MotionEventCompat.ACTION_MASK; - - if (DEBUG) - if (action == MotionEvent.ACTION_DOWN) - Log.v(TAG, "Received ACTION_DOWN"); - - if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP - || (action != MotionEvent.ACTION_DOWN && mIsUnableToDrag)) { - endDrag(); - return false; - } - - switch (action) { - case MotionEvent.ACTION_MOVE: - determineDrag(ev); - break; - case MotionEvent.ACTION_DOWN: - int index = MotionEventCompat.getActionIndex(ev); - mActivePointerId = MotionEventCompat.getPointerId(ev, index); - if (mActivePointerId == INVALID_POINTER) - break; - mLastMotionX = mInitialMotionX = MotionEventCompat.getX(ev, index); - mLastMotionY = MotionEventCompat.getY(ev, index); - if (thisTouchAllowed(ev)) { - mIsBeingDragged = false; - mIsUnableToDrag = false; - if (isMenuOpen() && mViewBehind.menuTouchInQuickReturn(mContent, ev.getX() + mScrollX)) { - mQuickReturn = true; - } - } else { - mIsUnableToDrag = true; - } - break; - case MotionEventCompat.ACTION_POINTER_UP: - onSecondaryPointerUp(ev); - break; - } - - if (!mIsBeingDragged) { - if (mVelocityTracker == null) { - mVelocityTracker = VelocityTracker.obtain(); - } - mVelocityTracker.addMovement(ev); - } - return mIsBeingDragged || mQuickReturn; - } - - - @Override - public boolean onTouchEvent(MotionEvent ev) { - - if (!mIsBeingDragged && !thisTouchAllowed(ev)) - return false; - - final int action = ev.getAction(); - - if (mVelocityTracker == null) { - mVelocityTracker = VelocityTracker.obtain(); - } - mVelocityTracker.addMovement(ev); - - switch (action & MotionEventCompat.ACTION_MASK) { - case MotionEvent.ACTION_DOWN: - /* - * If being flinged and user touches, stop the fling. isFinished - * will be false if being flinged. - */ - completeScroll(); - - // Remember where the motion event started - int index = MotionEventCompat.getActionIndex(ev); - mActivePointerId = MotionEventCompat.getPointerId(ev, index); - mLastMotionX = mInitialMotionX = ev.getX(); - break; - case MotionEvent.ACTION_MOVE: - if (!mIsBeingDragged) { - determineDrag(ev); - if (mIsUnableToDrag) - return false; - } - if (mIsBeingDragged) { - // Scroll to follow the motion event - final int activePointerIndex = getPointerIndex(ev, mActivePointerId); - if (mActivePointerId == INVALID_POINTER) - break; - final float x = MotionEventCompat.getX(ev, activePointerIndex); - final float deltaX = mLastMotionX - x; - mLastMotionX = x; - float oldScrollX = getScrollX(); - float scrollX = oldScrollX + deltaX; - final float leftBound = getLeftBound(); - final float rightBound = getRightBound(); - if (scrollX < leftBound) { - scrollX = leftBound; - } else if (scrollX > rightBound) { - scrollX = rightBound; - } - // Don't lose the rounded component - mLastMotionX += scrollX - (int) scrollX; - scrollTo((int) scrollX, getScrollY()); - pageScrolled((int) scrollX); - } - break; - case MotionEvent.ACTION_UP: - if (mIsBeingDragged) { - final VelocityTracker velocityTracker = mVelocityTracker; - velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); - int initialVelocity = (int) VelocityTrackerCompat.getXVelocity( - velocityTracker, mActivePointerId); - final int scrollX = getScrollX(); - final float pageOffset = (float) (scrollX - getDestScrollX(mCurItem)) / getBehindWidth(); - final int activePointerIndex = getPointerIndex(ev, mActivePointerId); - if (mActivePointerId != INVALID_POINTER) { - final float x = MotionEventCompat.getX(ev, activePointerIndex); - final int totalDelta = (int) (x - mInitialMotionX); - int nextPage = determineTargetPage(pageOffset, initialVelocity, totalDelta); - setCurrentItemInternal(nextPage, true, true, initialVelocity); - } else { - setCurrentItemInternal(mCurItem, true, true, initialVelocity); - } - mActivePointerId = INVALID_POINTER; - endDrag(); - } else if (mQuickReturn && mViewBehind.menuTouchInQuickReturn(mContent, ev.getX() + mScrollX)) { - // close the menu - setCurrentItem(1); - endDrag(); - } - break; - case MotionEvent.ACTION_CANCEL: - if (mIsBeingDragged) { - setCurrentItemInternal(mCurItem, true, true); - mActivePointerId = INVALID_POINTER; - endDrag(); - } - break; - case MotionEventCompat.ACTION_POINTER_DOWN: { - final int indexx = MotionEventCompat.getActionIndex(ev); - mLastMotionX = MotionEventCompat.getX(ev, indexx); - mActivePointerId = MotionEventCompat.getPointerId(ev, indexx); - break; - } - case MotionEventCompat.ACTION_POINTER_UP: - onSecondaryPointerUp(ev); - int pointerIndex = getPointerIndex(ev, mActivePointerId); - if (mActivePointerId == INVALID_POINTER) - break; - mLastMotionX = MotionEventCompat.getX(ev, pointerIndex); - break; - } - return true; - } - - private void determineDrag(MotionEvent ev) { - final int activePointerId = mActivePointerId; - final int pointerIndex = getPointerIndex(ev, activePointerId); - if (activePointerId == INVALID_POINTER || pointerIndex == INVALID_POINTER) - return; - final float x = MotionEventCompat.getX(ev, pointerIndex); - final float dx = x - mLastMotionX; - final float xDiff = Math.abs(dx); - final float y = MotionEventCompat.getY(ev, pointerIndex); - final float dy = y - mLastMotionY; - final float yDiff = Math.abs(dy); - if (xDiff > (isMenuOpen() ? mTouchSlop / 2 : mTouchSlop) && xDiff > yDiff && thisSlideAllowed(dx)) { - startDrag(); - mLastMotionX = x; - mLastMotionY = y; - setScrollingCacheEnabled(true); - // TODO add back in touch slop check - } else if (xDiff > mTouchSlop) { - mIsUnableToDrag = true; - } - } - - @Override - public void scrollTo(int x, int y) { - super.scrollTo(x, y); - float percentOpen = getPercentOpen(); - mScrollX = x; - mViewBehind.scrollBehindTo(mContent, x, y); - ((SlidingMenu) getParent()).manageLayers(percentOpen); - if (mListener != null) { - mListener.onChanging(percentOpen); - } - } - - private int determineTargetPage(float pageOffset, int velocity, int deltaX) { - int targetPage = mCurItem; - if (Math.abs(deltaX) > mFlingDistance && Math.abs(velocity) > mMinimumVelocity) { - if (velocity > 0 && deltaX > 0) { - targetPage -= 1; - } else if (velocity < 0 && deltaX < 0) { - targetPage += 1; - } - } else { - targetPage = Math.round(mCurItem + pageOffset); - } - return targetPage; - } - - protected float getPercentOpen() { - return Math.abs(mScrollX - mContent.getLeft()) / getBehindWidth(); - } - - @Override - protected void dispatchDraw(Canvas canvas) { - super.dispatchDraw(canvas); - // Draw the margin drawable if needed. - mViewBehind.drawShadow(mContent, canvas); - } - - // variables for drawing - private float mScrollX = 0.0f; - - private void onSecondaryPointerUp(MotionEvent ev) { - if (DEBUG) Log.v(TAG, "onSecondaryPointerUp called"); - final int pointerIndex = MotionEventCompat.getActionIndex(ev); - final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex); - if (pointerId == mActivePointerId) { - // This was our active pointer going up. Choose a new - // active pointer and adjust accordingly. - final int newPointerIndex = pointerIndex == 0 ? 1 : 0; - mLastMotionX = MotionEventCompat.getX(ev, newPointerIndex); - mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex); - if (mVelocityTracker != null) { - mVelocityTracker.clear(); - } - } - } - - private void startDrag() { - mIsBeingDragged = true; - mQuickReturn = false; - } - - private void endDrag() { - mQuickReturn = false; - mIsBeingDragged = false; - mIsUnableToDrag = false; - mActivePointerId = INVALID_POINTER; - - if (mVelocityTracker != null) { - mVelocityTracker.recycle(); - mVelocityTracker = null; - } - } - - private void setScrollingCacheEnabled(boolean enabled) { - if (mScrollingCacheEnabled != enabled) { - mScrollingCacheEnabled = enabled; - if (USE_CACHE) { - final int size = getChildCount(); - for (int i = 0; i < size; ++i) { - final View child = getChildAt(i); - if (child.getVisibility() != GONE) { - child.setDrawingCacheEnabled(enabled); - } - } - } - } - } - - - @Override - public boolean dispatchKeyEvent(KeyEvent event) { - // Let the focused view and/or our descendants get the key first - return super.dispatchKeyEvent(event) || executeKeyEvent(event); - } - - /** - * You can call this function yourself to have the scroll view perform - * scrolling from a key event, just as if the event had been dispatched to - * it by the view hierarchy. - * - * @param event The key event to execute. - * @return Return true if the event was handled, else false. - */ - public boolean executeKeyEvent(KeyEvent event) { - boolean handled = false; - if (event.getAction() == KeyEvent.ACTION_DOWN) { - switch (event.getKeyCode()) { - case KeyEvent.KEYCODE_DPAD_LEFT: - handled = arrowScroll(FOCUS_LEFT); - break; - case KeyEvent.KEYCODE_DPAD_RIGHT: - handled = arrowScroll(FOCUS_RIGHT); - break; - case KeyEvent.KEYCODE_TAB: - // The focus finder had a bug handling FOCUS_FORWARD and FOCUS_BACKWARD - // before Android 3.0. Ignore the tab key on those devices. - if (KeyEventCompat.hasNoModifiers(event)) { - handled = arrowScroll(FOCUS_FORWARD); - } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_SHIFT_ON)) { - handled = arrowScroll(FOCUS_BACKWARD); - } - break; - } - } - return handled; - } - - public boolean arrowScroll(int direction) { - View currentFocused = findFocus(); - if (currentFocused == this) currentFocused = null; - - boolean handled = false; - - View nextFocused = FocusFinder.getInstance().findNextFocus(this, currentFocused, - direction); - if (nextFocused != null && nextFocused != currentFocused) { - if (direction == View.FOCUS_LEFT) { - handled = nextFocused.requestFocus(); - } else if (direction == View.FOCUS_RIGHT) { - // If there is nothing to the right, or this is causing us to - // jump to the left, then what we really want to do is page right. - if (currentFocused != null && nextFocused.getLeft() <= currentFocused.getLeft()) { - handled = pageRight(); - } else { - handled = nextFocused.requestFocus(); - } - } - } else if (direction == FOCUS_LEFT || direction == FOCUS_BACKWARD) { - // Trying to move left and nothing there; try to page. - handled = pageLeft(); - } else if (direction == FOCUS_RIGHT || direction == FOCUS_FORWARD) { - // Trying to move right and nothing there; try to page. - handled = pageRight(); - } - if (handled) { - playSoundEffect(SoundEffectConstants.getContantForFocusDirection(direction)); - } - return handled; - } - - boolean pageLeft() { - if (mCurItem > 0) { - setCurrentItem(mCurItem - 1, true); - return true; - } - return false; - } - - boolean pageRight() { - if (mCurItem < 1) { - setCurrentItem(mCurItem + 1, true); - return true; - } - return false; - } - -} diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/slidingmenu/CustomViewBehind.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/slidingmenu/CustomViewBehind.java deleted file mode 100644 index 05a3c2f1..00000000 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/slidingmenu/CustomViewBehind.java +++ /dev/null @@ -1,162 +0,0 @@ -package com.moez.QKSMS.ui.view.slidingmenu; - -import android.content.Context; -import android.graphics.Canvas; -import android.graphics.drawable.Drawable; -import android.util.AttributeSet; -import android.view.MotionEvent; -import android.view.View; -import android.view.ViewGroup; -import com.moez.QKSMS.common.utils.Units; - -public class CustomViewBehind extends ViewGroup { - private static final String TAG = "CustomViewBehind"; - - private View mContent; - private int mWidthOffset; - private boolean mChildrenEnabled; - - private float mScrollScale; - private Drawable mShadowDrawable; - private int mShadowWidth; - - public CustomViewBehind(Context context) { - this(context, null); - } - - public CustomViewBehind(Context context, AttributeSet attrs) { - super(context, attrs); - mShadowWidth = Units.dpToPx(getContext(), 8); - } - - public void setWidthOffset(int i) { - mWidthOffset = i; - requestLayout(); - } - - public int getBehindWidth() { - return mContent.getWidth(); - } - - public void setContent(View v) { - if (mContent != null) { - removeView(mContent); - } - mContent = v; - addView(mContent); - } - - public View getContent() { - return mContent; - } - - public void setChildrenEnabled(boolean enabled) { - mChildrenEnabled = enabled; - } - - @Override - public void scrollTo(int x, int y) { - super.scrollTo(x, y); - } - - @Override - public boolean onInterceptTouchEvent(MotionEvent e) { - return !mChildrenEnabled; - } - - @Override - public boolean onTouchEvent(MotionEvent e) { - return !mChildrenEnabled; - } - - @Override - protected void dispatchDraw(Canvas canvas) { - super.dispatchDraw(canvas); - } - - @Override - protected void onLayout(boolean changed, int l, int t, int r, int b) { - final int width = r - l; - final int height = b - t; - mContent.layout(0, 0, width - mWidthOffset, height); - } - - @Override - protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - int width = getDefaultSize(0, widthMeasureSpec); - int height = getDefaultSize(0, heightMeasureSpec); - setMeasuredDimension(width, height); - final int contentWidth = getChildMeasureSpec(widthMeasureSpec, 0, width - mWidthOffset); - final int contentHeight = getChildMeasureSpec(heightMeasureSpec, 0, height); - mContent.measure(contentWidth, contentHeight); - } - - public void setScrollScale(float scrollScale) { - mScrollScale = scrollScale; - } - - public void setShadowDrawable(Drawable shadow) { - mShadowDrawable = shadow; - invalidate(); - } - - public int getMenuPage(int page) { - page = (page > 1) ? 2 : ((page < 1) ? 0 : page); - if (page > 1) { - return 0; - } else { - return page; - } - } - - public void scrollBehindTo(View content, int x, int y) { - int vis = View.VISIBLE; - if (x >= content.getLeft()) vis = View.INVISIBLE; - scrollTo((int) ((x + getBehindWidth()) * mScrollScale), y); - setVisibility(vis); - } - - public int getMenuLeft(View content, int page) { - switch (page) { - case 0: - return content.getLeft() - getBehindWidth(); - case 2: - return content.getLeft(); - } - return content.getLeft(); - } - - public int getAbsLeftBound(View content) { - return content.getLeft() - getBehindWidth(); - } - - public int getAbsRightBound(View content) { - return content.getLeft(); - } - - /** - * Returns whether x is on a menu. - * - * @param content content - * @param x the position of the touch - */ - public boolean menuTouchInQuickReturn(View content, float x) { - return x >= content.getLeft(); - } - - public boolean menuClosedSlideAllowed(float dx) { - return dx > 0; - } - - public boolean menuOpenSlideAllowed(float dx) { - return dx < 0; - } - - public void drawShadow(View content, Canvas canvas) { - if (mShadowDrawable == null || mShadowWidth <= 0) return; - int left = content.getLeft() - mShadowWidth; - mShadowDrawable.setBounds(left, 0, left + mShadowWidth, getHeight()); - mShadowDrawable.draw(canvas); - } - -} diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/slidingmenu/SlidingMenu.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/slidingmenu/SlidingMenu.java deleted file mode 100644 index c6d025f9..00000000 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/slidingmenu/SlidingMenu.java +++ /dev/null @@ -1,300 +0,0 @@ -package com.moez.QKSMS.ui.view.slidingmenu; - -import android.annotation.SuppressLint; -import android.content.Context; -import android.graphics.Rect; -import android.os.Build; -import android.os.Parcel; -import android.os.Parcelable; -import android.support.v4.content.ContextCompat; -import android.util.AttributeSet; -import android.view.LayoutInflater; -import android.view.View; -import android.widget.RelativeLayout; -import com.moez.QKSMS.R; -import com.moez.QKSMS.ui.view.slidingmenu.CustomViewAbove.OnPageChangeListener; - -/** - * Stripped down version of Jeremy Feinstein's SlidingMenu library - */ -public class SlidingMenu extends RelativeLayout { - private static final String TAG = "SlidingMenu"; - - private boolean mActionbarOverlay = false; - - private CustomViewAbove mViewAbove; - private CustomViewBehind mViewBehind; - - private SlidingMenuListener mListener; - - public interface SlidingMenuListener { - void onOpen(); - - void onOpened(); - - void onClose(); - - void onClosed(); - - void onChanging(float percentOpen); - } - - /** - * Instantiates a new SlidingMenu. - * - * @param context the associated Context - */ - public SlidingMenu(Context context) { - this(context, null); - } - - /** - * Instantiates a new SlidingMenu. - * - * @param context the associated Context - * @param attrs the attrs - */ - public SlidingMenu(Context context, AttributeSet attrs) { - this(context, attrs, 0); - } - - /** - * Instantiates a new SlidingMenu. - * - * @param context the associated Context - * @param attrs the attrs - * @param defStyle the def style - */ - public SlidingMenu(Context context, AttributeSet attrs, int defStyle) { - super(context, attrs, defStyle); - - LayoutParams behindParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); - mViewBehind = new CustomViewBehind(context); - addView(mViewBehind, behindParams); - LayoutParams aboveParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); - mViewAbove = new CustomViewAbove(context); - addView(mViewAbove, aboveParams); - mViewBehind.setScrollScale(0.5f); - mViewBehind.setShadowDrawable(ContextCompat.getDrawable(getContext(), R.drawable.shadow_slidingmenu)); - mViewAbove.setCustomViewBehind(mViewBehind); - mViewAbove.setOnPageChangeListener(new OnPageChangeListener() { - public static final int POSITION_OPEN = 0; - public static final int POSITION_CLOSE = 1; - - public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { - } - - public void onPageSelected(int position, boolean anim) { - if (position == POSITION_OPEN && mListener != null && anim) { - mListener.onOpen(); - } else if (position == POSITION_OPEN && mListener != null) { - mListener.onOpened(); - } else if (position == POSITION_CLOSE && mListener != null && anim) { - mListener.onClose(); - } else if (position == POSITION_CLOSE && mListener != null) { - mListener.onClosed(); - } - } - }); - - } - - /** - * Set the above view content from a layout resource. The resource will be inflated, adding all top-level views - * to the above view. - */ - public void setContent() { - mViewAbove.setContent(LayoutInflater.from(getContext()).inflate(R.layout.content_frame, null)); - } - - /** - * Retrieves the current content. - * - * @return the current content - */ - public View getContent() { - return mViewAbove.getContent(); - } - - /** - * Set the behind view (menu) content from a layout resource. The resource will be inflated, adding all top-level views - * to the behind view. - */ - public void setMenu() { - mViewBehind.setContent(LayoutInflater.from(getContext()).inflate(R.layout.menu_frame, null)); - } - - /** - * Retrieves the main menu. - * - * @return the main menu - */ - public View getMenu() { - return mViewBehind.getContent(); - } - - /** - * Opens the menu and shows the menu view. - */ - public void showMenu() { - showMenu(true); - } - - /** - * Opens the menu and shows the menu view. - * - * @param animate true to animate the transition, false to ignore animation - */ - public void showMenu(boolean animate) { - mViewAbove.setCurrentItem(0, animate, true); - } - - /** - * Closes the menu and shows the above view. - */ - public void showContent() { - showContent(true); - } - - /** - * Closes the menu and shows the above view. - * - * @param animate true to animate the transition, false to ignore animation - */ - public void showContent(boolean animate) { - mViewAbove.setCurrentItem(1, animate, true); - } - - /** - * Toggle the SlidingMenu. If it is open, it will be closed, and vice versa. - */ - public void toggle() { - toggle(true); - } - - /** - * Toggle the SlidingMenu. If it is open, it will be closed, and vice versa. - * - * @param animate true to animate the transition, false to ignore animation - */ - public void toggle(boolean animate) { - if (isMenuShowing()) { - showContent(animate); - } else { - showMenu(animate); - } - } - - /** - * Checks if is the behind view showing. - * - * @return Whether or not the behind view is showing - */ - public boolean isMenuShowing() { - return mViewAbove.getCurrentItem() == 0 || mViewAbove.getCurrentItem() == 2; - } - - /** - * Sets the behind offset. - * - * @param i The margin, in pixels, on the right of the screen that the behind view scrolls to. - */ - public void setBehindOffset(int i) { - mViewBehind.setWidthOffset(i); - } - - public void setListener(SlidingMenuListener listener) { - mListener = listener; - mViewAbove.setListener(listener); - } - - public static class SavedState extends BaseSavedState { - - private final int mItem; - - public SavedState(Parcelable superState, int item) { - super(superState); - mItem = item; - } - - private SavedState(Parcel in) { - super(in); - mItem = in.readInt(); - } - - public int getItem() { - return mItem; - } - - /* (non-Javadoc) - * @see android.view.AbsSavedState#writeToParcel(android.os.Parcel, int) - */ - public void writeToParcel(Parcel out, int flags) { - super.writeToParcel(out, flags); - out.writeInt(mItem); - } - - public static final Creator CREATOR = - new Creator() { - public SavedState createFromParcel(Parcel in) { - return new SavedState(in); - } - - public SavedState[] newArray(int size) { - return new SavedState[size]; - } - }; - - } - - /* (non-Javadoc) - * @see android.view.View#onSaveInstanceState() - */ - @Override - protected Parcelable onSaveInstanceState() { - Parcelable superState = super.onSaveInstanceState(); - SavedState ss = new SavedState(superState, mViewAbove.getCurrentItem()); - return ss; - } - - /* (non-Javadoc) - * @see android.view.View#onRestoreInstanceState(android.os.Parcelable) - */ - @Override - protected void onRestoreInstanceState(Parcelable state) { - SavedState ss = (SavedState) state; - super.onRestoreInstanceState(ss.getSuperState()); - mViewAbove.setCurrentItem(ss.getItem()); - } - - /* (non-Javadoc) - * @see android.view.ViewGroup#fitSystemWindows(android.graphics.Rect) - */ - @SuppressLint("NewApi") - @Override - protected boolean fitSystemWindows(Rect insets) { - int leftPadding = insets.left; - int rightPadding = insets.right; - int topPadding = insets.top; - int bottomPadding = insets.bottom; - if (!mActionbarOverlay) { - setPadding(leftPadding, topPadding, rightPadding, bottomPadding); - } - return true; - } - - public void manageLayers(float percentOpen) { - if (Build.VERSION.SDK_INT < 11) return; - - boolean layer = percentOpen > 0.0f && percentOpen < 1.0f; - final int layerType = layer ? View.LAYER_TYPE_HARDWARE : View.LAYER_TYPE_NONE; - - if (layerType != getContent().getLayerType()) { - getHandler().post(() -> { - getContent().setLayerType(layerType, null); - getMenu().setLayerType(layerType, null); - }); - } - } - -} diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/widget/WidgetService.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/widget/WidgetService.java index cbfdbe54..1bce49bc 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/widget/WidgetService.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/widget/WidgetService.java @@ -41,6 +41,7 @@ import com.moez.QKSMS.data.ContactHelper; import com.moez.QKSMS.data.Conversation; import com.moez.QKSMS.ui.MainActivity; import com.moez.QKSMS.ui.ThemeManager; +import com.moez.QKSMS.ui.messagelist.MessageListActivity; public class WidgetService extends RemoteViewsService { private static final String TAG = "WidgetService"; @@ -205,7 +206,7 @@ public class WidgetService extends RemoteViewsService { // On click intent. Intent clickIntent = new Intent(); - clickIntent.putExtra(MainActivity.EXTRA_THREAD_ID, conversation.getThreadId()); + clickIntent.putExtra(MessageListActivity.ARG_THREAD_ID, conversation.getThreadId()); remoteViews.setOnClickFillInIntent(R.id.conversation, clickIntent); return remoteViews; diff --git a/QKSMS/src/main/res/drawable-xhdpi/shadow_bottom.png b/QKSMS/src/main/res/drawable-xhdpi/shadow_bottom.png new file mode 100644 index 00000000..4569174a Binary files /dev/null and b/QKSMS/src/main/res/drawable-xhdpi/shadow_bottom.png differ diff --git a/QKSMS/src/main/res/drawable-xhdpi/shadow_left.png b/QKSMS/src/main/res/drawable-xhdpi/shadow_left.png new file mode 100644 index 00000000..82c71c2f Binary files /dev/null and b/QKSMS/src/main/res/drawable-xhdpi/shadow_left.png differ diff --git a/QKSMS/src/main/res/layout/activity_main.xml b/QKSMS/src/main/res/layout/activity_fragment.xml similarity index 84% rename from QKSMS/src/main/res/layout/activity_main.xml rename to QKSMS/src/main/res/layout/activity_fragment.xml index c14961bb..380efaa3 100644 --- a/QKSMS/src/main/res/layout/activity_main.xml +++ b/QKSMS/src/main/res/layout/activity_fragment.xml @@ -3,7 +3,6 @@ xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" - android:fitsSystemWindows="true" android:orientation="vertical"> @@ -13,8 +12,8 @@ android:layout_height="0dp" android:layout_weight="1"> - @@ -22,6 +21,7 @@ android:layout_width="match_parent" android:layout_height="8dp" android:background="@drawable/ab_shadow" /> + \ No newline at end of file diff --git a/QKSMS/src/main/res/layout/view_swipeback.xml b/QKSMS/src/main/res/layout/view_swipeback.xml new file mode 100644 index 00000000..711f47fc --- /dev/null +++ b/QKSMS/src/main/res/layout/view_swipeback.xml @@ -0,0 +1,5 @@ + + diff --git a/QKSMS/src/main/res/menu/conversation.xml b/QKSMS/src/main/res/menu/message_list.xml similarity index 100% rename from QKSMS/src/main/res/menu/conversation.xml rename to QKSMS/src/main/res/menu/message_list.xml diff --git a/QKSMS/src/main/res/values/strings.xml b/QKSMS/src/main/res/values/strings.xml index 7b085cff..7a77e7f3 100644 --- a/QKSMS/src/main/res/values/strings.xml +++ b/QKSMS/src/main/res/values/strings.xml @@ -152,8 +152,6 @@ Font weight Message count Show the number of messages for each conversation - Sliding panel tab - Sliding tab that allows you to quickly view your last conversation Sent timestamps Show the timestamp for when a message was sent, not received @@ -632,6 +630,7 @@ EndlessJabber is not installed, opening Google Play Couldn\'t load the changelog. Please try again later + Couldn\'t open conversation Thank you for donating! You\'re my new best friend. diff --git a/QKSMS/src/main/res/values/themes.xml b/QKSMS/src/main/res/values/themes.xml index 01c003cd..31678b2c 100644 --- a/QKSMS/src/main/res/values/themes.xml +++ b/QKSMS/src/main/res/values/themes.xml @@ -50,6 +50,7 @@ @color/grey_light_mega_ultra @color/grey_material @color/grey_light_mega_ultra + true diff --git a/QKSMS/src/main/res/xml/settings.xml b/QKSMS/src/main/res/xml/settings.xml index 9069905c..2c934944 100644 --- a/QKSMS/src/main/res/xml/settings.xml +++ b/QKSMS/src/main/res/xml/settings.xml @@ -44,9 +44,6 @@ - diff --git a/QKSMS/src/main/res/xml/settings_appearance.xml b/QKSMS/src/main/res/xml/settings_appearance.xml index 219266fb..f99286db 100644 --- a/QKSMS/src/main/res/xml/settings_appearance.xml +++ b/QKSMS/src/main/res/xml/settings_appearance.xml @@ -135,13 +135,6 @@ android:summary="@string/pref_message_count_summary" android:title="@string/pref_message_count" android:widgetLayout="@layout/view_switch" /> -