Fixed crash when opening settings

This commit is contained in:
Moez Bhatti
2015-09-18 18:50:15 -04:00
parent 2e3c263f38
commit 2f896f692b
7 changed files with 58 additions and 58 deletions
@@ -1,5 +1,9 @@
package com.moez.QKSMS.ui;
import android.content.Context;
import android.view.Menu;
import android.view.MenuInflater;
/**
* 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
@@ -27,4 +31,9 @@ public interface ContentFragment {
* been closed immediately.
*/
void onContentClosed();
/**
* Allows the MainActivity to delegate setting of the Toolbar title and menu
*/
void inflateToolbar(Menu menu, MenuInflater inflater, Context context);
}
@@ -273,7 +273,7 @@ public class MainActivity extends QKActivity implements SlidingMenu.OnOpenListen
inflater.inflate(R.menu.coversation_list, menu);
} else {
showBackButton(true);
((Fragment) mContent).onCreateOptionsMenu(menu, inflater);
mContent.inflateToolbar(menu, inflater, this);
}
return true;
@@ -22,7 +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, ContentFragment {
public abstract class QKContentFragment extends QKFragment implements LiveView, ContentFragment {
/**
* It's not strictly necessary, but subclasses should call through to super() in their
@@ -1,6 +1,7 @@
package com.moez.QKSMS.ui.compose;
import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
@@ -65,8 +66,8 @@ public class ComposeFragment extends QKContentFragment implements ActivityLaunch
* 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 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
*/
@@ -75,7 +76,7 @@ public class ComposeFragment extends QKContentFragment implements ActivityLaunch
// Check if we can reuse the passed fragment.
if (reuseFragment != null && reuseFragment instanceof ComposeFragment) {
f = (ComposeFragment)reuseFragment;
f = (ComposeFragment) reuseFragment;
} else {
f = new ComposeFragment();
}
@@ -113,14 +114,6 @@ public class ComposeFragment extends QKContentFragment implements ActivityLaunch
return view;
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.compose, menu);
mContext.setTitle(R.string.title_compose);
super.onCreateOptionsMenu(menu, inflater);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
@@ -174,6 +167,14 @@ public class ComposeFragment extends QKContentFragment implements ActivityLaunch
}
}
@Override
public void inflateToolbar(Menu menu, MenuInflater inflater, Context context) {
inflater.inflate(R.menu.compose, menu);
mContext.setTitle(R.string.title_compose);
super.onCreateOptionsMenu(menu, inflater);
}
/**
* @return the addresses of all the contacts in the AutoCompleteContactsView.
*/
@@ -291,14 +291,6 @@ public class MessageListFragment extends QKContentFragment implements ActivityLa
return view;
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.conversation, menu);
setTitle();
//super.onCreateOptionsMenu(menu, inflater);
}
@Override
public void onResume() {
super.onResume();
@@ -765,6 +757,14 @@ public class MessageListFragment extends QKContentFragment implements ActivityLa
}
}
@Override
public void inflateToolbar(Menu menu, MenuInflater inflater, Context context) {
inflater.inflate(R.menu.conversation, menu);
setTitle();
super.onCreateOptionsMenu(menu, inflater);
}
@Override
public void onSensorChanged(SensorEvent event) {
if (event.values[0] == 0) {
@@ -1,6 +1,7 @@
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;
@@ -101,14 +102,6 @@ public class SearchFragment extends QKContentFragment implements RecyclerCursorA
return view;
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.search, menu);
mContext.setTitle(R.string.title_search);
super.onCreateOptionsMenu(menu, inflater);
}
private void query() {
Contact.addListener(mContactListener);
@@ -141,6 +134,14 @@ public class SearchFragment extends QKContentFragment implements RecyclerCursorA
KeyboardUtils.showAndFocus(mContext, mQuery);
}
@Override
public void inflateToolbar(Menu menu, MenuInflater inflater, Context context) {
inflater.inflate(R.menu.search, menu);
mContext.setTitle(R.string.title_search);
super.onCreateOptionsMenu(menu, inflater);
}
@Override
public void onItemClick(SearchData data, View view) {
MainActivity mainActivity = (MainActivity) mContext;
@@ -21,12 +21,10 @@ import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
import android.preference.PreferenceScreen;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;
@@ -682,33 +680,6 @@ public class SettingsFragment extends PreferenceFragment implements Preference.O
}
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.settings, menu);
mContext.setTitle(R.string.title_settings);
MenuItem simplePrefs = menu.findItem(R.id.simple_settings);
if (mPrefs.getBoolean(SettingsFragment.SIMPLE_PREFS, true)) {
simplePrefs.setTitle(R.string.menu_show_all_prefs);
} else {
simplePrefs.setTitle(R.string.menu_show_fewer_prefs);
}
super.onCreateOptionsMenu(menu, inflater);
}
@Override
public void onPrepareOptionsMenu(Menu menu) {
super.onPrepareOptionsMenu(menu);
mContext.colorMenuIcons(menu, ThemeManager.getTextOnColorPrimary());
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
setHasOptionsMenu(true);
return super.onCreateView(inflater, container, savedInstanceState);
}
@Override
public void onDestroy() {
super.onDestroy();
@@ -745,4 +716,22 @@ public class SettingsFragment extends PreferenceFragment implements Preference.O
public void onContentClosed() {
}
@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);
MenuItem simplePrefs = menu.findItem(R.id.simple_settings);
if (mPrefs.getBoolean(SettingsFragment.SIMPLE_PREFS, true)) {
simplePrefs.setTitle(R.string.menu_show_all_prefs);
} else {
simplePrefs.setTitle(R.string.menu_show_fewer_prefs);
}
}
}