diff options
19 files changed, 208 insertions, 231 deletions
diff --git a/build.gradle b/build.gradle index de4d418e..d8f2ae3a 100644 --- a/build.gradle +++ b/build.gradle @@ -55,6 +55,8 @@ dependencies { // Android dependencies compile 'com.android.support:support-v13:23.2.0' + compile 'com.android.support:appcompat-v7:23.2.1' + compile 'com.android.support:design:23.2.1' } ext { diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml index ca369a5d..f2d0a51e 100644 --- a/src/main/AndroidManifest.xml +++ b/src/main/AndroidManifest.xml @@ -25,7 +25,7 @@ android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" - android:theme="@style/ConversationsTheme" + android:theme="@style/ConversationsPlusTheme" tools:replace="android:label" android:name="de.thedevstack.conversationsplus.ConversationsPlusApplication"> <service android:name=".services.XmppConnectionService" /> @@ -43,7 +43,8 @@ android:name=".ui.ConversationActivity" android:label="@string/app_name" android:launchMode="singleTask" - android:windowSoftInputMode="stateHidden"> + android:windowSoftInputMode="stateHidden" + android:theme="@style/ConversationsPlusTheme.NoActionBar"> <intent-filter> <action android:name="android.intent.action.MAIN"/> @@ -54,7 +55,8 @@ android:name=".ui.StartConversationActivity" android:configChanges="orientation|screenSize" android:label="@string/title_activity_start_conversation" - android:launchMode="singleTask"> + android:launchMode="singleTask" + android:theme="@style/ConversationsPlusTheme.ActionBar"> <intent-filter> <action android:name="android.intent.action.SENDTO"/> @@ -81,7 +83,8 @@ </activity> <activity android:name=".ui.SettingsActivity" - android:label="@string/title_activity_settings"/> + android:label="@string/title_activity_settings" + android:theme="@style/ConversationsPlusTheme.ActionBar"/> <activity android:name=".ui.ChooseContactActivity" android:label="@string/title_activity_choose_contact"/> diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/AbstractSearchableListItemActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/AbstractSearchableListItemActivity.java index b8e57f47..df33e665 100644 --- a/src/main/java/de/thedevstack/conversationsplus/ui/AbstractSearchableListItemActivity.java +++ b/src/main/java/de/thedevstack/conversationsplus/ui/AbstractSearchableListItemActivity.java @@ -2,6 +2,7 @@ package de.thedevstack.conversationsplus.ui; import android.content.Context; import android.os.Bundle; +import android.support.v4.view.MenuItemCompat; import android.text.Editable; import android.text.TextWatcher; import android.view.Menu; @@ -26,7 +27,7 @@ public abstract class AbstractSearchableListItemActivity extends XmppActivity { private EditText mSearchEditText; - private final MenuItem.OnActionExpandListener mOnActionExpandListener = new MenuItem.OnActionExpandListener() { + private final MenuItemCompat.OnActionExpandListener mOnActionExpandListener = new MenuItemCompat.OnActionExpandListener() { @Override public boolean onMenuItemActionExpand(final MenuItem item) { @@ -103,11 +104,11 @@ public abstract class AbstractSearchableListItemActivity extends XmppActivity { public boolean onCreateOptionsMenu(final Menu menu) { getMenuInflater().inflate(R.menu.choose_contact, menu); final MenuItem menuSearchView = menu.findItem(R.id.action_search); - final View mSearchView = menuSearchView.getActionView(); + final View mSearchView = MenuItemCompat.getActionView(menuSearchView); mSearchEditText = (EditText) mSearchView .findViewById(R.id.search_field); mSearchEditText.addTextChangedListener(mSearchTextWatcher); - menuSearchView.setOnActionExpandListener(mOnActionExpandListener); + MenuItemCompat.setOnActionExpandListener(menuSearchView, mOnActionExpandListener); return true; } diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/ConferenceDetailsActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/ConferenceDetailsActivity.java index 2a3cd7fe..c0ddb2f6 100644 --- a/src/main/java/de/thedevstack/conversationsplus/ui/ConferenceDetailsActivity.java +++ b/src/main/java/de/thedevstack/conversationsplus/ui/ConferenceDetailsActivity.java @@ -247,10 +247,9 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers mInviteButton = (Button) findViewById(R.id.invite); mInviteButton.setOnClickListener(inviteListener); mConferenceType = (TextView) findViewById(R.id.muc_conference_type); - if (getActionBar() != null) { - getActionBar().setHomeButtonEnabled(true); - getActionBar().setDisplayHomeAsUpEnabled(true); - } + + this.enableHomeButtonAsUp(); + mEditNickButton.setOnClickListener(new OnClickListener() { @Override diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/ContactDetailsActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/ContactDetailsActivity.java index 3ca9fce7..96946be8 100644 --- a/src/main/java/de/thedevstack/conversationsplus/ui/ContactDetailsActivity.java +++ b/src/main/java/de/thedevstack/conversationsplus/ui/ContactDetailsActivity.java @@ -216,10 +216,8 @@ public class ContactDetailsActivity extends XmppActivity implements OnAccountUpd }); keys = (LinearLayout) findViewById(R.id.details_contact_keys); tags = (LinearLayout) findViewById(R.id.tags); - if (getActionBar() != null) { - getActionBar().setHomeButtonEnabled(true); - getActionBar().setDisplayHomeAsUpEnabled(true); - } + + this.enableHomeButtonAsUp(); this.showDynamicTags = ConversationsPlusPreferences.showDynamicTags(); } diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/ConversationActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/ConversationActivity.java index af8eeea1..abe82b24 100644 --- a/src/main/java/de/thedevstack/conversationsplus/ui/ConversationActivity.java +++ b/src/main/java/de/thedevstack/conversationsplus/ui/ConversationActivity.java @@ -1,7 +1,8 @@ package de.thedevstack.conversationsplus.ui; import android.annotation.SuppressLint; -import android.app.ActionBar; +import android.support.design.widget.FloatingActionButton; +import android.support.v7.app.ActionBar; import android.app.AlertDialog; import android.app.FragmentTransaction; import android.app.PendingIntent; @@ -18,21 +19,19 @@ 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.widget.Toolbar; import android.util.Log; import android.util.Pair; import android.view.Gravity; import android.view.KeyEvent; -import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.view.Surface; import android.view.View; -import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.CheckBox; -import android.widget.ImageView; import android.widget.PopupMenu; import android.widget.PopupMenu.OnMenuItemClickListener; import android.widget.TextView; @@ -52,7 +51,6 @@ import de.thedevstack.conversationsplus.ConversationsPlusPreferences; import de.thedevstack.conversationsplus.services.AvatarService; import de.thedevstack.conversationsplus.ui.dialogs.UserDecisionDialog; import de.thedevstack.conversationsplus.ui.listeners.AvatarLogoOnClickListener; -import de.thedevstack.conversationsplus.ui.listeners.AvatarLogoPositioningListener; import de.thedevstack.conversationsplus.ui.listeners.ResizePictureUserDecisionListener; import de.thedevstack.conversationsplus.utils.ConversationUtil; import de.timroes.android.listview.EnhancedListView; @@ -119,8 +117,6 @@ public class ConversationActivity extends XmppActivity protected boolean mUsingEnterKey = false; private View mContentView; - private View avatarLogoView; - private View titleView; private List<Conversation> conversationList = new ArrayList<>(); private Conversation swipedConversation = null; @@ -185,6 +181,7 @@ public class ConversationActivity extends XmppActivity @Override protected void onCreate(final Bundle savedInstanceState) { + this.useDefaultActionBar = false; super.onCreate(savedInstanceState); if (savedInstanceState != null) { mOpenConverstaion = savedInstanceState.getString(STATE_OPEN_CONVERSATION, null); @@ -199,6 +196,10 @@ public class ConversationActivity extends XmppActivity setContentView(R.layout.fragment_conversations_overview); + Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); + setSupportActionBar(toolbar); + this.disableHomeButtonAsUp(); + this.mConversationFragment = new ConversationFragment(); FragmentTransaction transaction = getFragmentManager().beginTransaction(); transaction.replace(R.id.selected_conversation, this.mConversationFragment, "conversation"); @@ -208,11 +209,6 @@ public class ConversationActivity extends XmppActivity this.listAdapter = new ConversationAdapter(this, conversationList); listView.setAdapter(this.listAdapter); - if (getActionBar() != null) { - getActionBar().setDisplayHomeAsUpEnabled(false); - getActionBar().setHomeButtonEnabled(false); - } - listView.setOnItemClickListener(new OnItemClickListener() { @Override @@ -356,18 +352,18 @@ public class ConversationActivity extends XmppActivity } private void updateActionBarTitle(boolean titleShouldBeName) { - final ActionBar ab = getActionBar(); + final ActionBar ab = getSupportActionBar(); if (ab != null) { - if (null == this.titleView || null == this.avatarLogoView) { - this.initializeCustomActionBarViews(ab); - } - TextView title = (TextView) this.titleView.findViewById(R.id.conversationsTitle); + TextView title = (TextView) findViewById(R.id.cplusTitle); + FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); + final Conversation conversation = getSelectedConversation(); if (titleShouldBeName && conversation != null) { - this.toggleShowCustomActionBarView(ab, true); - this.showLogoAvatar(); - ab.setDisplayHomeAsUpEnabled(true); - ab.setHomeButtonEnabled(true); + ab.setDisplayHomeAsUpEnabled(true); + ab.setHomeButtonEnabled(true); + fab.setImageBitmap(AvatarService.getInstance().getCircled(getSelectedConversation(), getResources().getDimensionPixelSize(R.dimen.design_fab_image_size))); + fab.setOnClickListener(new AvatarLogoOnClickListener(getSelectedConversation())); + fab.setVisibility(View.VISIBLE); if (conversation.getMode() == Conversation.MODE_SINGLE || ConversationsPlusPreferences.useSubject()) { title.setText(conversation.getName()); @@ -375,57 +371,14 @@ public class ConversationActivity extends XmppActivity title.setText(conversation.getJid().toBareJid().toString()); } } else { - this.toggleShowCustomActionBarView(ab, false); - ab.setDisplayHomeAsUpEnabled(false); - ab.setHomeButtonEnabled(false); + ab.setDisplayHomeAsUpEnabled(false); + ab.setHomeButtonEnabled(false); title.setText(R.string.app_name); - this.hideLogoAvatar(); + fab.setVisibility(View.GONE); } } } - private void toggleShowCustomActionBarView(ActionBar ab, boolean show) { - if (show) { - ab.setDisplayShowTitleEnabled(false); - ab.setDisplayShowCustomEnabled(true); - } else { - ab.setDisplayShowTitleEnabled(true); - ab.setDisplayShowCustomEnabled(false); - } - } - - private void initializeCustomActionBarViews(ActionBar ab) { - if (null == this.titleView) { - this.titleView = LayoutInflater.from(this).inflate(R.layout.title, null); - ab.setCustomView(this.titleView); - } - if (null == this.avatarLogoView) { - this.avatarLogoView = LayoutInflater.from(this).inflate(R.layout.logo_view, null, false); - ViewGroup decorViewGroup = (ViewGroup) getWindow().getDecorView(); - decorViewGroup.addView(avatarLogoView); - int resId = getResources().getIdentifier("action_bar_container", "id", "android"); - final View actionBarView = decorViewGroup.findViewById(resId); - if (actionBarView != null) { - actionBarView.getViewTreeObserver().addOnGlobalLayoutListener(new AvatarLogoPositioningListener(actionBarView, avatarLogoView)); - } - } - } - - private void hideLogoAvatar() { - if (null != this.avatarLogoView) { - this.avatarLogoView.setVisibility(View.GONE); - } - } - - private void showLogoAvatar() { - if (null != this.avatarLogoView) { - ImageView avatarView = (ImageView) this.avatarLogoView.findViewById(R.id.logoViewAvatar); - avatarView.setImageBitmap(AvatarService.getInstance().getCircled(getSelectedConversation(), getPixel(56))); - avatarLogoView.setVisibility(View.VISIBLE); - avatarView.setOnClickListener(new AvatarLogoOnClickListener(getSelectedConversation())); - } - } - private void openConversation() { this.updateActionBarTitle(); this.invalidateOptionsMenu(); @@ -1144,7 +1097,7 @@ public class ConversationActivity extends XmppActivity super.onResume(); final int theme = findTheme(); final boolean usingEnterKey = ConversationsPlusPreferences.displayEnterKey(); - if (this.mTheme != theme || usingEnterKey != mUsingEnterKey) { + if (this.useDefaultActionBar && (this.mTheme != theme || usingEnterKey != mUsingEnterKey)) { recreate(); } this.mActivityPaused = false; diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/EditAccountActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/EditAccountActivity.java index 1a868949..dbbacf3f 100644 --- a/src/main/java/de/thedevstack/conversationsplus/ui/EditAccountActivity.java +++ b/src/main/java/de/thedevstack/conversationsplus/ui/EditAccountActivity.java @@ -5,7 +5,6 @@ import android.app.AlertDialog.Builder; import android.app.PendingIntent; import android.content.DialogInterface; import android.content.Intent; -import android.content.SharedPreferences; import android.graphics.Bitmap; import android.net.Uri; import android.os.Bundle; @@ -512,14 +511,10 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate this.messageFingerprint = getIntent().getStringExtra("fingerprint"); if (!mInitMode) { this.mRegisterNew.setVisibility(View.GONE); - if (getActionBar() != null) { - getActionBar().setTitle(getString(R.string.account_details)); - } + this.setActionBarTitle(R.string.account_details); } else { this.mAvatar.setVisibility(View.GONE); - if (getActionBar() != null) { - getActionBar().setTitle(R.string.action_add_account); - } + this.setActionBarTitle(R.string.action_add_account); } } this.mShowOptions = ConversationsPlusPreferences.showConnectionOptions(); @@ -541,11 +536,7 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate updateAccountInformation(true); } } else if (this.xmppConnectionService.getAccounts().size() == 0) { - if (getActionBar() != null) { - getActionBar().setDisplayHomeAsUpEnabled(false); - getActionBar().setDisplayShowHomeEnabled(false); - getActionBar().setHomeButtonEnabled(false); - } + this.disableHomeButtonAsUp(); TextViewUtil.disable(mCancelButton, ConversationsPlusColors.secondaryText()); } if (Config.DOMAIN_LOCK == null) { diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/ManageAccountActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/ManageAccountActivity.java index e376b6b3..1d704a9d 100644 --- a/src/main/java/de/thedevstack/conversationsplus/ui/ManageAccountActivity.java +++ b/src/main/java/de/thedevstack/conversationsplus/ui/ManageAccountActivity.java @@ -1,6 +1,5 @@ package de.thedevstack.conversationsplus.ui; -import android.app.ActionBar; import android.app.AlertDialog; import android.content.ActivityNotFoundException; import android.content.DialogInterface; @@ -61,11 +60,9 @@ public class ManageAccountActivity extends XmppActivity implements OnAccountUpda accountList.clear(); accountList.addAll(xmppConnectionService.getAccounts()); } - ActionBar actionBar = getActionBar(); - if (actionBar != null) { - actionBar.setHomeButtonEnabled(this.accountList.size() > 0); - actionBar.setDisplayHomeAsUpEnabled(this.accountList.size() > 0); - } + + this.setHomeButtonAsUpEnabled(this.accountList.size() > 0); + invalidateOptionsMenu(); mAccountAdapter.notifyDataSetChanged(); } diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/ShareWithActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/ShareWithActivity.java index 28e8beb8..99e59b12 100644 --- a/src/main/java/de/thedevstack/conversationsplus/ui/ShareWithActivity.java +++ b/src/main/java/de/thedevstack/conversationsplus/ui/ShareWithActivity.java @@ -143,10 +143,7 @@ public class ShareWithActivity extends XmppActivity implements XmppConnectionSer protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - if (getActionBar() != null) { - getActionBar().setDisplayHomeAsUpEnabled(false); - getActionBar().setHomeButtonEnabled(false); - } + this.disableHomeButtonAsUp(); setContentView(R.layout.share_with); setTitle(getString(R.string.title_activity_sharewith)); diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/StartConversationActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/StartConversationActivity.java index 2dc8d1a5..e2fa9410 100644 --- a/src/main/java/de/thedevstack/conversationsplus/ui/StartConversationActivity.java +++ b/src/main/java/de/thedevstack/conversationsplus/ui/StartConversationActivity.java @@ -3,12 +3,8 @@ package de.thedevstack.conversationsplus.ui; import android.Manifest; import android.annotation.SuppressLint; import android.annotation.TargetApi; -import android.app.ActionBar; -import android.app.ActionBar.Tab; -import android.app.ActionBar.TabListener; import android.app.AlertDialog; import android.app.Fragment; -import android.app.FragmentTransaction; import android.app.ListFragment; import android.content.Context; import android.content.DialogInterface; @@ -23,7 +19,12 @@ import android.os.Build; import android.os.Bundle; import android.os.Parcelable; import android.support.v13.app.FragmentPagerAdapter; +import android.support.v4.app.FragmentTransaction; +import android.support.v4.view.MenuItemCompat; import android.support.v4.view.ViewPager; +import android.support.v7.app.ActionBar; +import android.support.v7.app.ActionBar.Tab; +import android.support.v7.app.ActionBar.TabListener; import android.text.Editable; import android.text.TextWatcher; import android.view.ContextMenu; @@ -97,7 +98,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU private AtomicBoolean mRequestedContactsPermission = new AtomicBoolean(false); private final int REQUEST_SYNC_CONTACTS = 0x3b28cf; - private MenuItem.OnActionExpandListener mOnActionExpandListener = new MenuItem.OnActionExpandListener() { + private MenuItemCompat.OnActionExpandListener mOnActionExpandListener = new MenuItemCompat.OnActionExpandListener() { @Override public boolean onMenuItemActionExpand(MenuItem item) { @@ -147,8 +148,8 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU private ViewPager.SimpleOnPageChangeListener mOnPageChangeListener = new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { - if (getActionBar() != null) { - getActionBar().setSelectedNavigationItem(position); + if (getSupportActionBar() != null) { + getSupportActionBar().setSelectedNavigationItem(position); } onTabChanged(); } @@ -195,7 +196,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU setContentView(R.layout.activity_start_conversation); this.mHideOfflineContacts = ConversationsPlusPreferences.hideOffline(); mViewPager = (ViewPager) 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) @@ -519,12 +520,11 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU MenuItem menuHideOffline = menu.findItem(R.id.action_hide_offline); 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); + MenuItemCompat.setOnActionExpandListener(mMenuSearchView, mOnActionExpandListener); + View mSearchView = MenuItemCompat.getActionView(mMenuSearchView); + mSearchEditText = (EditText) mSearchView.findViewById(R.id.search_field); mSearchEditText.addTextChangedListener(mSearchTextWatcher); - if (getActionBar().getSelectedNavigationIndex() == 0) { + if (getSupportActionBar().getSelectedNavigationIndex() == 0) { menuCreateConference.setVisible(false); } else { menuCreateContact.setVisible(false); @@ -637,11 +637,9 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU } } final Intent intent = getIntent(); - final ActionBar ab = getActionBar(); - if (intent != null && intent.getBooleanExtra("init",false) && ab != null) { - ab.setDisplayShowHomeEnabled(false); - ab.setDisplayHomeAsUpEnabled(false); - ab.setHomeButtonEnabled(false); + + if (intent != null && intent.getBooleanExtra("init",false)) { + this.disableHomeButtonAsUp(); } this.mKnownHosts = xmppConnectionService.getKnownHosts(); this.mKnownConferenceHosts = xmppConnectionService.getKnownConferenceHosts(); diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/TrustKeysActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/TrustKeysActivity.java index dfddbb78..1c9c18aa 100644 --- a/src/main/java/de/thedevstack/conversationsplus/ui/TrustKeysActivity.java +++ b/src/main/java/de/thedevstack/conversationsplus/ui/TrustKeysActivity.java @@ -94,11 +94,7 @@ public class TrustKeysActivity extends XmppActivity implements OnKeyStatusUpdate mSaveButton = (Button) findViewById(R.id.save_button); mSaveButton.setOnClickListener(mSaveButtonListener); - - if (getActionBar() != null) { - getActionBar().setHomeButtonEnabled(true); - getActionBar().setDisplayHomeAsUpEnabled(true); - } + this.enableHomeButtonAsUp(); } private void populateView() { diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/VerifyOTRActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/VerifyOTRActivity.java index 4f1c9fc7..d1d74d5f 100644 --- a/src/main/java/de/thedevstack/conversationsplus/ui/VerifyOTRActivity.java +++ b/src/main/java/de/thedevstack/conversationsplus/ui/VerifyOTRActivity.java @@ -255,27 +255,20 @@ public class VerifyOTRActivity extends XmppActivity implements XmppConnectionSer protected void updateView() { if (this.mConversation.hasValidOtrSession()) { - final ActionBar actionBar = getActionBar(); this.mVerificationExplain.setText(R.string.no_otr_session_found); invalidateOptionsMenu(); switch(this.mode) { case MODE_ASK_QUESTION: - if (actionBar != null ) { - actionBar.setTitle(R.string.ask_question); - } + this.setActionBarTitle(R.string.ask_question); this.updateViewAskQuestion(); break; case MODE_ANSWER_QUESTION: - if (actionBar != null ) { - actionBar.setTitle(R.string.smp_requested); - } + this.setActionBarTitle(R.string.smp_requested); this.updateViewAnswerQuestion(); break; case MODE_MANUAL_VERIFICATION: default: - if (actionBar != null ) { - actionBar.setTitle(R.string.manually_verify); - } + this.setActionBarTitle(R.string.manually_verify); this.updateViewManualVerification(); break; } diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/XmppActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/XmppActivity.java index 726facac..6d6e5e3f 100644 --- a/src/main/java/de/thedevstack/conversationsplus/ui/XmppActivity.java +++ b/src/main/java/de/thedevstack/conversationsplus/ui/XmppActivity.java @@ -3,8 +3,6 @@ package de.thedevstack.conversationsplus.ui; import android.Manifest; import android.annotation.SuppressLint; import android.annotation.TargetApi; -import android.app.ActionBar; -import android.app.Activity; import android.app.AlertDialog; import android.app.AlertDialog.Builder; import android.app.PendingIntent; @@ -17,7 +15,6 @@ import android.content.DialogInterface.OnClickListener; import android.content.Intent; import android.content.IntentSender.SendIntentException; import android.content.ServiceConnection; -import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.content.res.Resources; @@ -38,7 +35,9 @@ import android.os.Handler; import android.os.IBinder; import android.os.PowerManager; import android.os.SystemClock; -import android.preference.PreferenceManager; +import android.support.annotation.StringRes; +import android.support.v7.app.ActionBar; +import android.support.v7.app.AppCompatActivity; import android.text.InputType; import android.util.DisplayMetrics; import android.view.Menu; @@ -86,12 +85,13 @@ import de.thedevstack.conversationsplus.services.XmppConnectionService; import de.thedevstack.conversationsplus.services.XmppConnectionService.XmppConnectionBinder; import de.thedevstack.conversationsplus.utils.CryptoHelper; import de.thedevstack.conversationsplus.utils.ExceptionHelper; +import de.thedevstack.conversationsplus.utils.ui.TextViewUtil; import de.thedevstack.conversationsplus.xmpp.OnKeyStatusUpdated; import de.thedevstack.conversationsplus.xmpp.OnUpdateBlocklist; import de.thedevstack.conversationsplus.xmpp.jid.InvalidJidException; import de.thedevstack.conversationsplus.xmpp.jid.Jid; -public abstract class XmppActivity extends Activity { +public abstract class XmppActivity extends AppCompatActivity { protected static final int REQUEST_ANNOUNCE_PGP = 0x0101; protected static final int REQUEST_INVITE_TO_CONVERSATION = 0x0102; @@ -103,6 +103,7 @@ public abstract class XmppActivity extends Activity { public XmppConnectionService xmppConnectionService; public boolean xmppConnectionServiceBound = false; protected boolean registeredListeners = false; + protected boolean useDefaultActionBar = true; private DisplayMetrics metrics; protected int mTheme; @@ -348,12 +349,11 @@ public abstract class XmppActivity extends Activity { super.onCreate(savedInstanceState); metrics = getResources().getDisplayMetrics(); ExceptionHelper.init(getApplicationContext()); - this.mTheme = findTheme(); - setTheme(this.mTheme); - final ActionBar ab = getActionBar(); - if (ab!=null) { - ab.setDisplayHomeAsUpEnabled(true); - } + if (this.useDefaultActionBar) { + this.mTheme = findTheme(); + setTheme(this.mTheme); + enableHomeButtonAsUp(); + } } @Override @@ -369,6 +369,46 @@ public abstract class XmppActivity extends Activity { return super.onCreateOptionsMenu(menu); } + protected void enableHomeButtonAsUp() { + this.setHomeButtonAsUpEnabled(true); + } + + protected void disableHomeButtonAsUp() { + this.setHomeButtonAsUpEnabled(false); + } + + protected void setHomeButtonAsUpEnabled(boolean enabled) { + ActionBar ab = getSupportActionBar(); + if (null != ab) { + ab.setHomeButtonEnabled(enabled); + ab.setDisplayHomeAsUpEnabled(enabled); + } + } + + protected void setActionBarTitle(String titleText) { + if (this.useDefaultActionBar) { + ActionBar ab = getSupportActionBar(); + if (null != ab) { + ab.setTitle(titleText); + } + } else { + TextView title = (TextView) findViewById(R.id.cplusTitle); + title.setText(titleText); + } + } + + protected void setActionBarTitle(@StringRes int resid) { + if (this.useDefaultActionBar) { + ActionBar ab = getSupportActionBar(); + if (null != ab) { + ab.setTitle(resid); + } + } else { + TextView title = (TextView) findViewById(R.id.cplusTitle); + title.setText(resid); + } + } + protected boolean isOptimizingBattery() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE); @@ -960,9 +1000,9 @@ public abstract class XmppActivity extends Activity { protected int findTheme() { if (ConversationsPlusPreferences.useLargerFont()) { - return R.style.ConversationsTheme_LargerText; + return R.style.ConversationsPlusTheme_LargerText; } else { - return R.style.ConversationsTheme; + return R.style.ConversationsPlusTheme; } } diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/listeners/AvatarLogoPositioningListener.java b/src/main/java/de/thedevstack/conversationsplus/ui/listeners/AvatarLogoPositioningListener.java deleted file mode 100644 index e6846d9b..00000000 --- a/src/main/java/de/thedevstack/conversationsplus/ui/listeners/AvatarLogoPositioningListener.java +++ /dev/null @@ -1,57 +0,0 @@ -package de.thedevstack.conversationsplus.ui.listeners; - -import android.os.Build; -import android.view.View; -import android.view.ViewTreeObserver; - -import de.thedevstack.conversationsplus.R; - -/** - * This listener aims to position the avatar logo. - */ -public class AvatarLogoPositioningListener implements ViewTreeObserver.OnGlobalLayoutListener { - private View actionBarView; - private View avatarLogoView; - - public AvatarLogoPositioningListener(View actionBarView, View avatarLogoView) { - this.actionBarView = actionBarView; - this.avatarLogoView = avatarLogoView; - } - - @Override - public void onGlobalLayout() { - // Measure views - int[] location = new int[2]; - this.actionBarView.getLocationOnScreen(location); - - int[] logoLocation = new int[2]; - this.avatarLogoView.getLocationOnScreen(logoLocation); - - int[] titleViewLocation = new int[2]; - View titleView = this.actionBarView.findViewById(R.id.conversationsTitle); - int oldTitleViewLeftPadding = 0; - if (null != titleView) { - // Remove the listener only if all necessary view elements are there - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { - this.actionBarView.getViewTreeObserver().removeOnGlobalLayoutListener(this); - } else { - this.actionBarView.getViewTreeObserver().removeGlobalOnLayoutListener(this); - } - - titleView.getLocationOnScreen(titleViewLocation); - int avatarWidth = (int) (58 * titleView.getResources().getDisplayMetrics().density); - int newTitleViewLeftPadding = titleViewLocation[0] + avatarWidth; - titleView.setPadding(newTitleViewLeftPadding, titleView.getPaddingTop(), 0, 0); - oldTitleViewLeftPadding = titleViewLocation[0]; - } - - // Add top padding if necessary - if (location[1] > logoLocation[1]) { - int actionBarViewHeight = this.actionBarView.getMeasuredHeight(); - int newAvatarLogoTopPadding = location[1]; // Move to the top padding of the action bar (below the notification bar) - newAvatarLogoTopPadding += actionBarViewHeight; - newAvatarLogoTopPadding -= 58 * avatarLogoView.getResources().getDisplayMetrics().density * 0.6; - this.avatarLogoView.setPadding(oldTitleViewLeftPadding, newAvatarLogoTopPadding, 0, 0); - } - } -} diff --git a/src/main/res/layout/fragment_conversations_overview.xml b/src/main/res/layout/fragment_conversations_overview.xml index 2223219a..662c50e9 100644 --- a/src/main/res/layout/fragment_conversations_overview.xml +++ b/src/main/res/layout/fragment_conversations_overview.xml @@ -1,8 +1,14 @@ -<android.support.v4.widget.SlidingPaneLayout xmlns:android="http://schemas.android.com/apk/res/android" - android:id="@+id/content_view_spl" - android:layout_width="match_parent" - android:layout_height="match_parent" > + + <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:fitsSystemWindows="true"> + <android.support.v4.widget.SlidingPaneLayout + android:id="@+id/content_view_spl" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:paddingTop="?attr/actionBarSize"> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="@dimen/conversations_overview_width" @@ -18,7 +24,6 @@ android:divider="@color/black12" android:dividerHeight="1dp" /> </LinearLayout> - <LinearLayout android:id="@+id/selected_conversation" android:layout_width="fill_parent" @@ -27,4 +32,53 @@ android:orientation="vertical" > </LinearLayout> -</android.support.v4.widget.SlidingPaneLayout>
\ No newline at end of file + </android.support.v4.widget.SlidingPaneLayout> + + <android.support.design.widget.AppBarLayout + android:id="@+id/app_bar" + android:layout_width="match_parent" + android:layout_height="180dp" + android:fitsSystemWindows="true" + app:expanded="false" + android:theme="@style/ConversationsPlusTheme.AppBarOverlay"> + + <android.support.design.widget.CollapsingToolbarLayout + android:id="@+id/toolbar_layout" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:fitsSystemWindows="true" + app:contentScrim="?attr/colorPrimary" + app:layout_scrollFlags="scroll|exitUntilCollapsed"> + + <android.support.v7.widget.Toolbar + android:id="@+id/toolbar" + android:layout_width="match_parent" + android:layout_height="?attr/actionBarSize" + app:layout_collapseMode="pin" + android:layout_marginLeft="72dp" + app:popupTheme="@style/ConversationsPlusTheme.PopupOverlay"> + <TextView + android:id="@+id/cplusTitle" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:text="@string/app_name" + android:gravity="center_vertical" + android:textSize="16dp"/> + </android.support.v7.widget.Toolbar> + + </android.support.design.widget.CollapsingToolbarLayout> + </android.support.design.widget.AppBarLayout> + + <android.support.design.widget.FloatingActionButton + android:id="@+id/fab" + android:layout_width="56dp" + android:layout_height="56dp" + android:layout_marginLeft="16dp" + android:layout_marginTop="16dp" + app:layout_anchorGravity="top|start" + android:padding="0dp" + app:borderWidth="0dp" + app:fabSize="normal" + android:visibility="gone"/> + + </android.support.design.widget.CoordinatorLayout>
\ 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 a89d71ff..89ffbaa4 100644 --- a/src/main/res/menu/start_conversation.xml +++ b/src/main/res/menu/start_conversation.xml @@ -1,9 +1,9 @@ <?xml version="1.0" encoding="utf-8"?> -<menu xmlns:android="http://schemas.android.com/apk/res/android"> +<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> <item android:id="@+id/action_search" - android:actionLayout="@layout/actionview_search" + app:actionLayout="@layout/actionview_search" android:icon="?attr/icon_search" android:showAsAction="collapseActionView|always" android:title="@string/search" /> diff --git a/src/main/res/values-v21/themes.xml b/src/main/res/values-v21/themes.xml index 57cb9dc3..7a60e789 100644 --- a/src/main/res/values-v21/themes.xml +++ b/src/main/res/values-v21/themes.xml @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="utf-8"?> <resources> - <style name="ConversationsTheme" parent="@android:style/Theme.Material.Light.DarkActionBar"> + <style name="ConversationsTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar"> <item name="android:colorPrimary">@color/primary</item> <item name="android:colorPrimaryDark">@color/primary_dark</item> <item name="android:colorAccent">@color/accent</item> diff --git a/src/main/res/values/dimens.xml b/src/main/res/values/dimens.xml index 99a292fd..dcb00025 100644 --- a/src/main/res/values/dimens.xml +++ b/src/main/res/values/dimens.xml @@ -10,4 +10,5 @@ <dimen name="ambilwarna_hueWidth">30dp</dimen> <dimen name="ambilwarna_spacer">8dp</dimen> <dimen name="action_bar_title_text_size">18dp</dimen> <!-- redefinition here, because no access to original from android --> + <dimen name="design_fab_image_size">56dp</dimen> </resources> diff --git a/src/main/res/values/themes.xml b/src/main/res/values/themes.xml index 0deb3a6e..e1f8b5b8 100644 --- a/src/main/res/values/themes.xml +++ b/src/main/res/values/themes.xml @@ -1,13 +1,13 @@ <?xml version="1.0" encoding="utf-8"?> <resources> - <style name="ConversationsTheme" parent="@android:style/Theme.Holo.Light.DarkActionBar"> - <item name="android:actionBarStyle">@style/ConversationsActionBar</item> - <item name="android:actionBarWidgetTheme">@style/ConversationsActionBarWidget</item> - <item name="android:actionBarTabStyle">@style/ConversationsActionBarTabs</item> + <style name="ConversationsPlusTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar"> <item name="TextSizeInfo">12sp</item> <item name="TextSizeBody">14sp</item> <item name="TextSizeHeadline">20sp</item> + <item name="colorPrimary">@color/primary</item> + <item name="colorPrimaryDark">@color/primaryTextOnDark</item> + <item name="colorAccent">@color/secondaryBackground</item> <item name="EmojiconSizeBody">19sp</item> <item name="EmojiconSizeInput">24sp</item> @@ -36,28 +36,39 @@ <item name="attr/icon_share">@drawable/ic_action_share</item> </style> - <style name="ConversationsTheme.LargerText" parent="ConversationsTheme"> + <style name="ConversationsPlusTheme.LargerText" parent="ConversationsPlusTheme"> <item name="TextSizeInfo">14sp</item> <item name="TextSizeBody">16sp</item> <item name="TextSizeHeadline">22sp</item> <item name="EmojiconSizeBody">22sp</item> </style> - <style name="ConversationsActionBar" parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse"> + <style name="ConversationsPlusTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" /> + + <style name="ConversationsPlusTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" /> + + <style name="ConversationsPlusTheme.NoActionBar"> + <item name="windowActionBar">false</item> + <item name="windowNoTitle">true</item> + </style> + + <style name="ConversationsPlusTheme.ActionBar"> + <item name="android:actionBarStyle">@style/ConversationsActionBar</item> + <item name="android:actionBarWidgetTheme">@style/ConversationsActionBarWidget</item> + <item name="android:actionBarTabStyle">@style/ConversationsActionBarTabs</item> + </style> + + <style name="ConversationsActionBar" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse"> <item name="android:background">@color/primary</item> <item name="android:backgroundStacked">@color/primary_dark</item> <item name="android:displayOptions">showHome|homeAsUp|showTitle</item> <item name="android:icon">@android:color/transparent</item> - <item name="android:windowActionBarOverlay">true</item> </style> - - <style name="ConversationsActionBarWidget" parent="android:Theme.Holo.Light"> - <item name="android:popupMenuStyle">@android:style/Widget.Holo.Light.PopupMenu</item> - <item name="android:dropDownListViewStyle">@android:style/Widget.Holo.Light.ListView.DropDown</item> + <style name="ConversationsActionBarWidget" parent="@style/Theme.AppCompat.Light"> + <item name="android:popupMenuStyle">@style/Widget.AppCompat.Light.PopupMenu</item> + <item name="android:dropDownListViewStyle">@style/Widget.AppCompat.Light.ListView.DropDown</item> </style> - - <style name="ConversationsActionBarTabs" parent="@android:style/Widget.Holo.ActionBar.TabView"> + <style name="ConversationsActionBarTabs" parent="@style/Widget.AppCompat.ActionBar.TabView"> <item name="android:background">@drawable/actionbar_tab_indicator</item> </style> - </resources>
\ No newline at end of file |