From 6e89427d5e8bd6bf833710e257ef58a1e40f45cf Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Fri, 16 Feb 2018 12:06:05 +0100 Subject: [PATCH] started work on migrating to appcompat --- .../ui/ConversationActivity.java | 6 +-- .../ui/StartConversationActivity.java | 53 +++++++++---------- .../siacs/conversations/ui/XmppActivity.java | 3 +- src/main/res/menu/change_presence.xml | 9 ++-- src/main/res/menu/choose_contact.xml | 9 ++-- src/main/res/menu/contact_details.xml | 17 +++--- src/main/res/menu/conversations.xml | 27 +++++----- src/main/res/menu/editaccount.xml | 17 +++--- src/main/res/menu/manageaccounts.xml | 9 ++-- src/main/res/menu/manageaccounts_context.xml | 5 +- src/main/res/menu/muc_details.xml | 17 +++--- src/main/res/menu/publish_avatar.xml | 5 +- src/main/res/menu/select_multiple.xml | 5 +- src/main/res/menu/share_with.xml | 5 +- src/main/res/menu/start_conversation.xml | 19 +++---- src/main/res/menu/trust_keys.xml | 5 +- src/main/res/menu/verify_otr.xml | 9 ++-- src/main/res/values-v21/themes.xml | 52 +++++++++--------- 18 files changed, 142 insertions(+), 130 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java index 6f00b3731..20b2ca274 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java @@ -1,7 +1,6 @@ package eu.siacs.conversations.ui; import android.annotation.SuppressLint; -import android.app.ActionBar; import android.app.AlertDialog; import android.app.FragmentTransaction; import android.app.PendingIntent; @@ -20,6 +19,7 @@ import android.provider.MediaStore; import android.provider.Settings; import android.support.v4.widget.SlidingPaneLayout; import android.support.v4.widget.SlidingPaneLayout.PanelSlideListener; +import android.support.v7.app.ActionBar; import android.util.Log; import android.util.Pair; import android.view.Gravity; @@ -214,7 +214,7 @@ public class ConversationActivity extends XmppActivity this.listView.setAdapter(this.listAdapter); this.listView.setSwipeDirection(EnhancedListView.SwipeDirection.END); - final ActionBar actionBar = getActionBar(); + final ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE); } @@ -359,7 +359,7 @@ public class ConversationActivity extends XmppActivity } private void updateActionBarTitle(boolean titleShouldBeName) { - final ActionBar ab = getActionBar(); + final ActionBar ab = getSupportActionBar(); final Conversation conversation = getSelectedConversation(); if (ab != null) { if (titleShouldBeName && conversation != null) { diff --git a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java index cd22e402f..a9350f277 100644 --- a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java @@ -2,15 +2,8 @@ package eu.siacs.conversations.ui; import android.Manifest; import android.annotation.SuppressLint; -import android.app.ActionBar; -import android.app.ActionBar.Tab; -import android.app.ActionBar.TabListener; import android.app.AlertDialog; import android.app.Dialog; -import android.app.Fragment; -import android.app.FragmentManager; -import android.app.FragmentTransaction; -import android.app.ListFragment; import android.app.PendingIntent; import android.content.ActivityNotFoundException; import android.content.Context; @@ -21,8 +14,14 @@ import android.content.pm.PackageManager; import android.net.Uri; import android.os.Build; import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; +import android.support.v4.app.FragmentTransaction; +import android.support.v4.app.ListFragment; +import android.support.v4.view.MenuItemCompat; import android.support.v4.view.PagerAdapter; import android.support.v4.view.ViewPager; +import android.support.v7.app.ActionBar; import android.text.Editable; import android.text.SpannableString; import android.text.Spanned; @@ -78,8 +77,8 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU public int conference_context_id; public int contact_context_id; - private Tab mContactsTab; - private Tab mConferencesTab; + private ActionBar.Tab mContactsTab; + private ActionBar.Tab mConferencesTab; private ViewPager mViewPager; private ListPagerAdapter mListPagerAdapter; private List contacts = new ArrayList<>(); @@ -118,29 +117,30 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU } }; private boolean mHideOfflineContacts = false; - private TabListener mTabListener = new TabListener() { + private ActionBar.TabListener mTabListener = new ActionBar.TabListener() { @Override - public void onTabUnselected(Tab tab, FragmentTransaction ft) { + public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) { return; } @Override - public void onTabSelected(Tab tab, FragmentTransaction ft) { + public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) { mViewPager.setCurrentItem(tab.getPosition()); onTabChanged(); } @Override - public void onTabReselected(Tab tab, FragmentTransaction ft) { + public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) { return; } }; private ViewPager.SimpleOnPageChangeListener mOnPageChangeListener = new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { - if (getActionBar() != null) { - getActionBar().setSelectedNavigationItem(position); + ActionBar actionBar = getSupportActionBar(); + if (actionBar != null) { + actionBar.setSelectedNavigationItem(position); } onTabChanged(); } @@ -165,7 +165,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU private TextView.OnEditorActionListener mSearchDone = new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { - int pos = getActionBar().getSelectedNavigationIndex(); + int pos = getSupportActionBar().getSelectedNavigationIndex(); if (pos == 0) { if (contacts.size() == 1) { openConversationForContact((Contact) contacts.get(0)); @@ -240,18 +240,16 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU new EmojiService(this).init(); setContentView(R.layout.activity_start_conversation); mViewPager = findViewById(R.id.start_conversation_view_pager); - ActionBar actionBar = getActionBar(); + ActionBar actionBar = getSupportActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); - mContactsTab = actionBar.newTab().setText(R.string.contacts) - .setTabListener(mTabListener); - mConferencesTab = actionBar.newTab().setText(R.string.conferences) - .setTabListener(mTabListener); + mContactsTab = actionBar.newTab().setText(R.string.contacts).setTabListener(mTabListener); + mConferencesTab = actionBar.newTab().setText(R.string.conferences).setTabListener(mTabListener); actionBar.addTab(mContactsTab); actionBar.addTab(mConferencesTab); mViewPager.setOnPageChangeListener(mOnPageChangeListener); - mListPagerAdapter = new ListPagerAdapter(getFragmentManager()); + mListPagerAdapter = new ListPagerAdapter(getSupportFragmentManager()); mViewPager.setAdapter(mListPagerAdapter); mConferenceAdapter = new ListItemAdapter(this, conferences); @@ -598,18 +596,17 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU menuHideOffline.setChecked(this.mHideOfflineContacts); mMenuSearchView = menu.findItem(R.id.action_search); mMenuSearchView.setOnActionExpandListener(mOnActionExpandListener); - View mSearchView = mMenuSearchView.getActionView(); - mSearchEditText = (EditText) mSearchView - .findViewById(R.id.search_field); + View mSearchView = MenuItemCompat.getActionView(mMenuSearchView); + mSearchEditText = (EditText) mSearchView.findViewById(R.id.search_field); mSearchEditText.addTextChangedListener(mSearchTextWatcher); mSearchEditText.setOnEditorActionListener(mSearchDone); - if (getActionBar().getSelectedNavigationIndex() == 0) { + if (getSupportActionBar().getSelectedNavigationIndex() == 0) { menuCreateConference.setVisible(false); } else { menuCreateContact.setVisible(false); } if (mInitialJid != null) { - mMenuSearchView.expandActionView(); + MenuItemCompat.expandActionView(mMenuSearchView); mSearchEditText.append(mInitialJid); filter(mInitialJid); } @@ -769,7 +766,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU } } final Intent intent = getIntent(); - final ActionBar ab = getActionBar(); + final ActionBar ab = getSupportActionBar(); boolean init = intent != null && intent.getBooleanExtra("init", false); boolean noConversations = xmppConnectionService.getConversations().size() == 0; if ((init || noConversations) && ab != null) { diff --git a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java index 9a19bc4f0..3c6e8acb2 100644 --- a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java @@ -38,6 +38,7 @@ import android.os.PowerManager; import android.os.SystemClock; import android.preference.PreferenceManager; import android.support.v4.content.ContextCompat; +import android.support.v7.app.AppCompatActivity; import android.text.InputType; import android.util.DisplayMetrics; import android.util.Pair; @@ -80,7 +81,7 @@ import eu.siacs.conversations.xmpp.OnUpdateBlocklist; import eu.siacs.conversations.xmpp.jid.InvalidJidException; import eu.siacs.conversations.xmpp.jid.Jid; -public abstract class XmppActivity extends Activity { +public abstract class XmppActivity extends AppCompatActivity { public static final String EXTRA_ACCOUNT = "account"; protected static final int REQUEST_ANNOUNCE_PGP = 0x0101; diff --git a/src/main/res/menu/change_presence.xml b/src/main/res/menu/change_presence.xml index f3dfadfd0..845ca87e1 100644 --- a/src/main/res/menu/change_presence.xml +++ b/src/main/res/menu/change_presence.xml @@ -1,17 +1,18 @@ - + \ No newline at end of file diff --git a/src/main/res/menu/choose_contact.xml b/src/main/res/menu/choose_contact.xml index 4a7553f31..8921e7c2a 100644 --- a/src/main/res/menu/choose_contact.xml +++ b/src/main/res/menu/choose_contact.xml @@ -1,24 +1,25 @@ - + diff --git a/src/main/res/menu/contact_details.xml b/src/main/res/menu/contact_details.xml index b8d9ee64b..09881ce11 100644 --- a/src/main/res/menu/contact_details.xml +++ b/src/main/res/menu/contact_details.xml @@ -1,18 +1,19 @@ - + \ No newline at end of file diff --git a/src/main/res/menu/conversations.xml b/src/main/res/menu/conversations.xml index 4c724d27d..aff5e434f 100644 --- a/src/main/res/menu/conversations.xml +++ b/src/main/res/menu/conversations.xml @@ -1,70 +1,71 @@ - + \ No newline at end of file diff --git a/src/main/res/menu/editaccount.xml b/src/main/res/menu/editaccount.xml index 770fbaa8a..cb1d16fe4 100644 --- a/src/main/res/menu/editaccount.xml +++ b/src/main/res/menu/editaccount.xml @@ -1,9 +1,10 @@ - + @@ -42,7 +43,7 @@ android:id="@+id/action_server_info_show_more" android:checkable="true" android:checked="false" - android:showAsAction="never" + app:showAsAction="never" android:title="@string/server_info_show_more"/> \ No newline at end of file diff --git a/src/main/res/menu/manageaccounts.xml b/src/main/res/menu/manageaccounts.xml index ffa692a0b..724b9a75d 100644 --- a/src/main/res/menu/manageaccounts.xml +++ b/src/main/res/menu/manageaccounts.xml @@ -1,14 +1,15 @@ - + @@ -21,7 +22,7 @@ \ No newline at end of file diff --git a/src/main/res/menu/manageaccounts_context.xml b/src/main/res/menu/manageaccounts_context.xml index d8b0093e6..34395f81f 100644 --- a/src/main/res/menu/manageaccounts_context.xml +++ b/src/main/res/menu/manageaccounts_context.xml @@ -1,5 +1,6 @@ - + - + \ No newline at end of file diff --git a/src/main/res/menu/publish_avatar.xml b/src/main/res/menu/publish_avatar.xml index 1bffb2961..5e8f7f079 100644 --- a/src/main/res/menu/publish_avatar.xml +++ b/src/main/res/menu/publish_avatar.xml @@ -1,8 +1,9 @@ - + \ No newline at end of file diff --git a/src/main/res/menu/select_multiple.xml b/src/main/res/menu/select_multiple.xml index 4240849fd..039a07218 100644 --- a/src/main/res/menu/select_multiple.xml +++ b/src/main/res/menu/select_multiple.xml @@ -1,9 +1,10 @@ - + + app:showAsAction="always" /> diff --git a/src/main/res/menu/share_with.xml b/src/main/res/menu/share_with.xml index bc51f4625..28b82937d 100644 --- a/src/main/res/menu/share_with.xml +++ b/src/main/res/menu/share_with.xml @@ -1,11 +1,12 @@ - + \ No newline at end of file diff --git a/src/main/res/menu/start_conversation.xml b/src/main/res/menu/start_conversation.xml index 327709fa1..e32869d6c 100644 --- a/src/main/res/menu/start_conversation.xml +++ b/src/main/res/menu/start_conversation.xml @@ -1,21 +1,22 @@ - + \ No newline at end of file diff --git a/src/main/res/menu/trust_keys.xml b/src/main/res/menu/trust_keys.xml index 903047678..5619ada61 100644 --- a/src/main/res/menu/trust_keys.xml +++ b/src/main/res/menu/trust_keys.xml @@ -1,9 +1,10 @@ - + \ No newline at end of file diff --git a/src/main/res/menu/verify_otr.xml b/src/main/res/menu/verify_otr.xml index 42b66ad5b..6517ae0b1 100644 --- a/src/main/res/menu/verify_otr.xml +++ b/src/main/res/menu/verify_otr.xml @@ -1,19 +1,20 @@ - + + app:showAsAction="never" /> \ No newline at end of file diff --git a/src/main/res/values-v21/themes.xml b/src/main/res/values-v21/themes.xml index 449669773..1f34e1517 100644 --- a/src/main/res/values-v21/themes.xml +++ b/src/main/res/values-v21/themes.xml @@ -1,16 +1,16 @@ - -