aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
authorsteckbrief <steckbrief@chefmail.de>2016-06-07 15:22:51 +0200
committersteckbrief <steckbrief@chefmail.de>2016-06-07 15:22:51 +0200
commitf7d2e1560377b36d3730922a2fadaee05a570b49 (patch)
tree1c99bd75d863d82a82495fabe434892ee76b9842 /src/main/java
parentc5c5b417ddd66b4611b0493c0e0a8349adbd34a4 (diff)
Related to FS#140, Logo implementation moved to FloatingActionButton
- Appcompat v7 dependency added - References adjusted to work correctly with appcompat v7
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/AbstractSearchableListItemActivity.java7
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/ConferenceDetailsActivity.java7
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/ContactDetailsActivity.java6
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/ConversationActivity.java89
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/EditAccountActivity.java15
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/ManageAccountActivity.java9
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/ShareWithActivity.java5
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/StartConversationActivity.java34
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/TrustKeysActivity.java6
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/VerifyOTRActivity.java13
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/XmppActivity.java66
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/listeners/AvatarLogoPositioningListener.java57
12 files changed, 110 insertions, 204 deletions
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);
- }
- }
-}