diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/ContentFragment.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/ContentFragment.java new file mode 100644 index 00000000..1def4b53 --- /dev/null +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/ContentFragment.java @@ -0,0 +1,30 @@ +package com.moez.QKSMS.ui; + +/** + * This interface is for fragments that must extend something other than a vanilla Fragment. It + * allows the fragment to get content animation callbacks without the developer having to + * rewrite the base class to extend BaseContentFragment. + */ +public interface ContentFragment { + /** + * Called when the content is being opened with an animation. + */ + void onContentOpening(); + + /** + * Called when the content has been opened, i.e. a opening animation has finished or it had + * been opened immediately. + */ + void onContentOpened(); + + /** + * Called when the content is being closed with an animation. + */ + void onContentClosing(); + + /** + * Called when the content has been closed, i.e. a closing animation has finished or it had + * been closed immediately. + */ + void onContentClosed(); +} 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 0cc1f6ab..946fdcd9 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/MainActivity.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/MainActivity.java @@ -6,10 +6,8 @@ import android.app.FragmentManager; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; -import android.content.SharedPreferences; import android.content.pm.ComponentInfo; import android.content.pm.PackageManager; -import android.content.res.Resources; import android.media.RingtoneManager; import android.net.Uri; import android.os.Bundle; @@ -24,6 +22,7 @@ import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; +import android.widget.CheckBox; import android.widget.ImageView; import com.google.android.mms.pdu_alt.PduHeaders; import com.moez.QKSMS.R; @@ -39,7 +38,6 @@ 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.base.QKContentFragment; import com.moez.QKSMS.ui.compose.ComposeFragment; import com.moez.QKSMS.ui.conversationlist.ConversationListFragment; import com.moez.QKSMS.ui.dialog.ConversationNotificationSettingsDialog; @@ -49,7 +47,6 @@ import com.moez.QKSMS.ui.dialog.mms.MMSSetupFragment; import com.moez.QKSMS.ui.messagelist.MessageListFragment; import com.moez.QKSMS.ui.search.SearchFragment; import com.moez.QKSMS.ui.settings.SettingsFragment; -import com.moez.QKSMS.ui.view.QKCheckBox; import com.moez.QKSMS.ui.view.slidingmenu.SlidingMenu; import com.moez.QKSMS.ui.welcome.WelcomeActivity; import com.nispok.snackbar.Snackbar; @@ -90,7 +87,7 @@ public class MainActivity extends QKActivity implements SlidingMenu.OnOpenListen private SlidingMenu mSlidingMenu; private ConversationListFragment mConversationList; - private Fragment mContent; + private ContentFragment mContent; private long mWaitingForThreadId = -1; private boolean mIsDestroyed = false; @@ -156,7 +153,7 @@ public class MainActivity extends QKActivity implements SlidingMenu.OnOpenListen } getFragmentManager().beginTransaction() - .replace(R.id.content_frame, mContent) + .replace(R.id.content_frame, (Fragment) mContent) .commit(); } @@ -295,7 +292,7 @@ public class MainActivity extends QKActivity implements SlidingMenu.OnOpenListen } public Fragment getContent() { - return mContent; + return (Fragment) mContent; } public long getThreadId() { @@ -406,7 +403,7 @@ public class MainActivity extends QKActivity implements SlidingMenu.OnOpenListen super.onPause(); sIsShowing = false; if (!mSlidingMenu.isMenuShowing()) { - QKContentFragment.notifyOnContentClosed(mContent); + mContent.onContentClosed(); } } @@ -430,7 +427,7 @@ public class MainActivity extends QKActivity implements SlidingMenu.OnOpenListen ThemeManager.loadThemeProperties(this); if (!mSlidingMenu.isMenuShowing()) { - QKContentFragment.notifyOnContentOpened(mContent); + mContent.onContentOpened(); } NotificationManager.initQuickCompose(this, false, false); @@ -530,7 +527,7 @@ public class MainActivity extends QKActivity implements SlidingMenu.OnOpenListen outState.putLong(KEY_THREADID, sThreadId); } - public void switchContent(Fragment fragment, boolean animate) { + 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); @@ -542,7 +539,7 @@ public class MainActivity extends QKActivity implements SlidingMenu.OnOpenListen if (fragment != m.findFragmentById(R.id.content_frame)) { getFragmentManager() .beginTransaction() - .replace(R.id.content_frame, fragment) + .replace(R.id.content_frame, (Fragment) fragment) .commitAllowingStateLoss(); } @@ -587,9 +584,8 @@ public class MainActivity extends QKActivity implements SlidingMenu.OnOpenListen invalidateOptionsMenu(); sIsContentHidden = true; - // Notify the content that it is being closed, since the menu (i.e. conversation list) is - // being opened. - QKContentFragment.notifyOnContentClosing(mContent); + // 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()); @@ -606,9 +602,8 @@ public class MainActivity extends QKActivity implements SlidingMenu.OnOpenListen invalidateOptionsMenu(); sIsContentHidden = false; - // Notify the content that it is being opened, since the menu (i.e. conversation list) is - // being closed. - QKContentFragment.notifyOnContentOpening(mContent); + // Notify the content that it is being opened, since the menu (i.e. conversation list) is being closed. + if (mContent != null) mContent.onContentOpening(); // Hide the soft keyboard KeyboardUtils.hide(this, getCurrentFocus()); @@ -620,14 +615,14 @@ public class MainActivity extends QKActivity implements SlidingMenu.OnOpenListen public void onOpened() { // When the menu (i.e. the conversation list) has been opened, the content has been opened. // So notify the content fragment. - QKContentFragment.notifyOnContentClosed(mContent); + 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. - QKContentFragment.notifyOnContentOpened(mContent); + if (mContent != null) mContent.onContentOpened(); } /** @@ -653,7 +648,7 @@ public class MainActivity extends QKActivity implements SlidingMenu.OnOpenListen R.plurals.confirm_delete_conversation, cnt, cnt)); } - final QKCheckBox checkbox = (QKCheckBox) contents.findViewById(R.id.delete_locked); + final CheckBox checkbox = (CheckBox) contents.findViewById(R.id.delete_locked); if (!hasLockedMessages) { checkbox.setVisibility(View.GONE); } else { 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 index 3c96318f..73a99fbf 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKContentFragment.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKContentFragment.java @@ -1,10 +1,10 @@ package com.moez.QKSMS.ui.base; -import android.app.Fragment; import android.os.Bundle; import android.view.View; import com.moez.QKSMS.common.LiveViewManager; import com.moez.QKSMS.interfaces.LiveView; +import com.moez.QKSMS.ui.ContentFragment; import com.moez.QKSMS.ui.ThemeManager; import com.moez.QKSMS.ui.settings.SettingsFragment; @@ -22,19 +22,7 @@ import com.moez.QKSMS.ui.settings.SettingsFragment; * - Manages the current state of the fragment in terms of the animation, i.e. opening, fully * opened, etc. */ -public class QKContentFragment extends QKFragment implements LiveView { - - private static final boolean LOCAL_LOGV = false; - - /** - * Holds the state of the content in the menu. - */ - private int mContentAnimationState = STATE_OPENED; - - public static final int STATE_OPENING = 0; - public static final int STATE_OPENED = 1; - public static final int STATE_CLOSING = 2; - public static final int STATE_CLOSED = 3; +public class QKContentFragment extends QKFragment implements LiveView, ContentFragment { /** * It's not strictly necessary, but subclasses should call through to super() in their @@ -84,71 +72,30 @@ public class QKContentFragment extends QKFragment implements LiveView { refresh(); } - /** - * @return The current state of the animation of the content. - */ - public int getContentAnimationState() { - return mContentAnimationState; - } - - /** - * Call on a BaseContentFragment to notify it that it is opening. - */ - public final void performOnContentOpening() { - mContentAnimationState = STATE_OPENING; - onContentOpening(); - } - - /** - * Call on a BaseContentFragment to notify it that it has been opened fully, i.e. an opening - * animation has finished or the Fragment has been opened immediately. - */ - public final void performOnContentOpened() { - mContentAnimationState = STATE_OPENED; - onContentOpened(); - } - - /** - * Call on a BaseContentFragment to notify it that it is closing. - */ - public final void performOnContentClosing() { - mContentAnimationState = STATE_CLOSING; - onContentClosing(); - } - - /** - * Call on a BaseContentFragment to notify it that it has been closed fully, i.e. a closing - * animation has finished or the Fragment has been closed immediately. - */ - public final void performOnContentClosed() { - mContentAnimationState = STATE_CLOSED; - onContentClosed(); - } - /** * Called when the content is being opened with an animation. */ - protected void onContentOpening() { + public void onContentOpening() { } /** * Called when the content has been opened, i.e. a opening animation has finished or it had * been opened immediately. */ - protected void onContentOpened() { + public void onContentOpened() { } /** * Called when the content is being closed with an animation. */ - protected void onContentClosing() { + public void onContentClosing() { } /** * Called when the content has been closed, i.e. a closing animation has finished or it had * been closed immediately. */ - protected void onContentClosed() { + public void onContentClosed() { } @Override @@ -158,67 +105,4 @@ public class QKContentFragment extends QKFragment implements LiveView { view.setBackgroundColor(ThemeManager.getBackgroundColor()); } } - - /** - * This interface is for fragments that must extend something other than a vanilla Fragment. It - * allows the fragment to get content animation callbacks without the developer having to - * rewrite the base class to extend BaseContentFragment. - */ - public interface ContentFragment { - /** - * Called when the content is being opened with an animation. - */ - void onContentOpening(); - - /** - * Called when the content has been opened, i.e. a opening animation has finished or it had - * been opened immediately. - */ - void onContentOpened(); - - /** - * Called when the content is being closed with an animation. - */ - void onContentClosing(); - - /** - * Called when the content has been closed, i.e. a closing animation has finished or it had - * been closed immediately. - */ - void onContentClosed(); - } - - // The following static methods will notify a Fragment about their content animations if - // appropriate, or do nothing otherwise. - public static void notifyOnContentOpening(Fragment fragment) { - if (fragment instanceof QKContentFragment) { - ((QKContentFragment) fragment).performOnContentOpening(); - } else if (fragment instanceof ContentFragment) { - ((ContentFragment) fragment).onContentOpening(); - } - } - - public static void notifyOnContentOpened(Fragment fragment) { - if (fragment instanceof QKContentFragment) { - ((QKContentFragment) fragment).performOnContentOpened(); - } else if (fragment instanceof ContentFragment) { - ((ContentFragment) fragment).onContentOpened(); - } - } - - public static void notifyOnContentClosing(Fragment fragment) { - if (fragment instanceof QKContentFragment) { - ((QKContentFragment) fragment).performOnContentClosing(); - } else if (fragment instanceof ContentFragment) { - ((ContentFragment) fragment).onContentClosing(); - } - } - - public static void notifyOnContentClosed(Fragment fragment) { - if (fragment instanceof QKContentFragment) { - ((QKContentFragment) fragment).performOnContentClosed(); - } else if (fragment instanceof ContentFragment) { - ((ContentFragment) fragment).onContentClosed(); - } - } } 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 73dcab8e..52086c8a 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 @@ -142,7 +142,7 @@ public class ComposeFragment extends QKContentFragment implements ActivityLaunch } @Override - protected void onContentOpened() { + public void onContentOpened() { setupInput(); } @@ -167,7 +167,7 @@ public class ComposeFragment extends QKContentFragment implements ActivityLaunch } @Override - protected void onContentClosing() { + public void onContentClosing() { // Clear the focus from this fragment. if (getActivity() != null && getActivity().getCurrentFocus() != null) { getActivity().getCurrentFocus().clearFocus(); 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 c79baa0d..4005d241 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 @@ -29,6 +29,7 @@ import com.moez.QKSMS.data.Conversation; import com.moez.QKSMS.data.ConversationLegacy; import com.moez.QKSMS.interfaces.LiveView; 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; @@ -262,11 +263,7 @@ public class ConversationListFragment extends QKFragment implements LoaderManage getLoaderManager().initLoader(0, null, this); } - private void switchFragment(Fragment fragment) { - if (getActivity() == null) { - return; - } - // TODO + private void switchFragment(ContentFragment fragment) { ((MainActivity) getActivity()).switchContent(fragment, true); } 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 a4c37e5d..e73d4f02 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 @@ -724,13 +724,13 @@ public class MessageListFragment extends QKContentFragment implements ActivityLa } @Override - protected void onContentOpening() { + public void onContentOpening() { super.onContentOpening(); mOpened = false; // We're animating the fragment in, this flag warns us not to do anything heavy } @Override - protected void onContentOpened() { + public void onContentOpened() { super.onContentOpened(); mOpened = true; // The fragment has finished animating in @@ -740,11 +740,11 @@ public class MessageListFragment extends QKContentFragment implements ActivityLa } @Override - protected void onContentClosing() { + public void onContentClosing() { } @Override - protected void onContentClosed() { + public void onContentClosed() { if (mSensorManager != null) { mSensorManager.unregisterListener(this); } 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 dcfe9ef7..d4e45cd9 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 @@ -126,7 +126,7 @@ public class SearchFragment extends QKContentFragment implements RecyclerCursorA } @Override - protected void onContentOpened() { + public void onContentOpened() { // Show the keyboard and focus on the query text when the fragment is opened. KeyboardUtils.showAndFocus(mContext, mQuery); } 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 3136f0a3..38e636ce 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 @@ -31,24 +31,25 @@ import android.widget.Toast; import com.mariussoft.endlessjabber.sdk.EndlessJabberInterface; import com.moez.QKSMS.R; import com.moez.QKSMS.common.AnalyticsManager; -import com.moez.QKSMS.ui.dialog.BubblePreferenceDialog; -import com.moez.QKSMS.interfaces.LiveView; -import com.moez.QKSMS.receiver.NightModeAutoReceiver; import com.moez.QKSMS.common.DonationManager; import com.moez.QKSMS.common.ListviewHelper; import com.moez.QKSMS.common.LiveViewManager; import com.moez.QKSMS.common.utils.DateFormatter; import com.moez.QKSMS.common.utils.KeyboardUtils; +import com.moez.QKSMS.interfaces.LiveView; +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.dialog.BubblePreferenceDialog; import com.moez.QKSMS.ui.dialog.QKDialog; import com.moez.QKSMS.ui.dialog.mms.MMSSetupFragment; +import com.moez.QKSMS.ui.view.QKTextView; import com.moez.QKSMS.ui.view.colorpicker.ColorPickerDialog; import com.moez.QKSMS.ui.view.colorpicker.ColorPickerSwatch; -import com.moez.QKSMS.ui.view.QKTextView; import java.text.ParseException; import java.text.SimpleDateFormat; @@ -60,8 +61,8 @@ import java.util.HashSet; import java.util.Set; import java.util.Stack; -public class SettingsFragment extends PreferenceFragment implements - Preference.OnPreferenceChangeListener, Preference.OnPreferenceClickListener, LiveView { +public class SettingsFragment extends PreferenceFragment implements Preference.OnPreferenceChangeListener, + Preference.OnPreferenceClickListener, LiveView, ContentFragment { private final String TAG = "PreferenceFragment"; public static final String CATEGORY_APPEARANCE = "pref_key_category_appearance"; @@ -159,6 +160,7 @@ public class SettingsFragment extends PreferenceFragment implements public static final String CATEGORY_TAG = "settings_category_fragment_tag"; private MainActivity mContext; + private PreferenceManager mPreferenceManager; private SharedPreferences mPrefs; private Resources mRes; private ListView mListView; @@ -707,4 +709,23 @@ public class SettingsFragment extends PreferenceFragment implements } } + @Override + public void onContentOpening() { + + } + + @Override + public void onContentOpened() { + + } + + @Override + public void onContentClosing() { + + } + + @Override + public void onContentClosed() { + + } }