revised tablet ui. fixed #423

This commit is contained in:
iNPUTmice 2014-10-03 15:00:29 +02:00
parent 335152b191
commit 9ae52a235f
9 changed files with 177 additions and 119 deletions

View file

@ -1,11 +1,11 @@
<android.support.v4.widget.SlidingPaneLayout xmlns:android="http://schemas.android.com/apk/res/android" <eu.siacs.conversations.ui.SlidingPaneLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/slidingpanelayout" android:id="@+id/content_view_spl"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" > android:layout_height="match_parent" >
<LinearLayout <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="240dp" android:layout_width="300dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@color/primarybackground" android:background="@color/primarybackground"
android:orientation="vertical" > android:orientation="vertical" >
@ -27,4 +27,4 @@
android:orientation="vertical" > android:orientation="vertical" >
</LinearLayout> </LinearLayout>
</android.support.v4.widget.SlidingPaneLayout> </eu.siacs.conversations.ui.SlidingPaneLayout>

View file

@ -1,5 +1,5 @@
<android.support.v4.widget.SlidingPaneLayout xmlns:android="http://schemas.android.com/apk/res/android" <android.support.v4.widget.SlidingPaneLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/slidingpanelayout" android:id="@+id/content_view_spl"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" > android:layout_height="match_parent" >

View file

@ -1,11 +1,11 @@
<android.support.v4.widget.SlidingPaneLayout xmlns:android="http://schemas.android.com/apk/res/android" <android.support.v4.widget.SlidingPaneLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/slidingpanelayout" android:id="@+id/content_view_spl"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" > android:layout_height="match_parent" >
<LinearLayout <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="324dp" android:layout_width="400dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@color/primarybackground" android:background="@color/primarybackground"
android:orientation="vertical" > android:orientation="vertical" >

View file

@ -1,11 +1,11 @@
<android.support.v4.widget.SlidingPaneLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/slidingpanelayout" android:id="@+id/content_view_ll"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" > android:layout_height="match_parent"
android:orientation="horizontal">
<LinearLayout <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="320dp"
android:layout_width="288dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@color/primarybackground" android:background="@color/primarybackground"
android:orientation="vertical" > android:orientation="vertical" >
@ -23,8 +23,7 @@
android:id="@+id/selected_conversation" android:id="@+id/selected_conversation"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" > android:orientation="vertical" >
</LinearLayout> </LinearLayout>
</android.support.v4.widget.SlidingPaneLayout> </LinearLayout>

View file

@ -1,5 +1,5 @@
<android.support.v4.widget.SlidingPaneLayout xmlns:android="http://schemas.android.com/apk/res/android" <android.support.v4.widget.SlidingPaneLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/slidingpanelayout" android:id="@+id/content_view_spl"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" > android:layout_height="match_parent" >

View file

@ -59,8 +59,13 @@ public class ConversationActivity extends XmppActivity implements
private static final int ATTACHMENT_CHOICE_CHOOSE_IMAGE = 0x0301; private static final int ATTACHMENT_CHOICE_CHOOSE_IMAGE = 0x0301;
private static final int ATTACHMENT_CHOICE_TAKE_PHOTO = 0x0302; private static final int ATTACHMENT_CHOICE_TAKE_PHOTO = 0x0302;
private static final int ATTACHMENT_CHOICE_RECORD_VOICE = 0x0303; private static final int ATTACHMENT_CHOICE_RECORD_VOICE = 0x0303;
private static final String STATE_OPEN_CONVERSATION = "state_open_conversation";
private static final String STATE_PANEL_OPEN = "state_panel_open";
protected SlidingPaneLayout spl; private String mOpenConverstaion = null;
private boolean mPanelOpen = true;
private View mContentView;
private List<Conversation> conversationList = new ArrayList<Conversation>(); private List<Conversation> conversationList = new ArrayList<Conversation>();
private Conversation selectedConversation = null; private Conversation selectedConversation = null;
@ -90,18 +95,52 @@ public class ConversationActivity extends XmppActivity implements
return this.listView; return this.listView;
} }
public SlidingPaneLayout getSlidingPaneLayout() {
return this.spl;
}
public boolean shouldPaneBeOpen() { public boolean shouldPaneBeOpen() {
return paneShouldBeOpen; return paneShouldBeOpen;
} }
public void showConversationsOverview() {
if (mContentView instanceof SlidingPaneLayout) {
SlidingPaneLayout mSlidingPaneLayout = (SlidingPaneLayout) mContentView;
mSlidingPaneLayout.openPane();
}
}
public void hideConversationsOverview() {
if (mContentView instanceof SlidingPaneLayout) {
SlidingPaneLayout mSlidingPaneLayout = (SlidingPaneLayout) mContentView;
mSlidingPaneLayout.closePane();
}
}
public boolean isConversationsOverviewHideable() {
if (mContentView instanceof SlidingPaneLayout) {
SlidingPaneLayout mSlidingPaneLayout = (SlidingPaneLayout) mContentView;
return mSlidingPaneLayout.isSlideable();
} else {
return false;
}
}
public boolean isConversationsOverviewVisable() {
if (mContentView instanceof SlidingPaneLayout) {
SlidingPaneLayout mSlidingPaneLayout = (SlidingPaneLayout) mContentView;
return mSlidingPaneLayout.isOpen();
} else {
return true;
}
}
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
if (savedInstanceState != null) {
mOpenConverstaion = savedInstanceState.getString(
STATE_OPEN_CONVERSATION, null);
mPanelOpen = savedInstanceState.getBoolean(STATE_PANEL_OPEN, true);
}
setContentView(R.layout.fragment_conversations_overview); setContentView(R.layout.fragment_conversations_overview);
listView = (ListView) findViewById(R.id.list); listView = (ListView) findViewById(R.id.list);
@ -122,52 +161,59 @@ public class ConversationActivity extends XmppActivity implements
setSelectedConversation(conversationList.get(position)); setSelectedConversation(conversationList.get(position));
swapConversationFragment(); swapConversationFragment();
} else { } else {
spl.closePane(); hideConversationsOverview();
} }
} }
}); });
spl = (SlidingPaneLayout) findViewById(R.id.slidingpanelayout); mContentView = findViewById(R.id.content_view_spl);
spl.setParallaxDistance(150); if (mContentView==null) {
spl.setShadowResource(R.drawable.es_slidingpane_shadow); mContentView = findViewById(R.id.content_view_ll);
spl.setSliderFadeColor(0); }
spl.setPanelSlideListener(new PanelSlideListener() { if (mContentView instanceof SlidingPaneLayout) {
SlidingPaneLayout mSlidingPaneLayout = (SlidingPaneLayout) mContentView;
mSlidingPaneLayout.setParallaxDistance(150);
mSlidingPaneLayout.setShadowResource(R.drawable.es_slidingpane_shadow);
mSlidingPaneLayout.setSliderFadeColor(0);
mSlidingPaneLayout.setPanelSlideListener(new PanelSlideListener() {
@Override @Override
public void onPanelOpened(View arg0) { public void onPanelOpened(View arg0) {
paneShouldBeOpen = true; paneShouldBeOpen = true;
ActionBar ab = getActionBar(); ActionBar ab = getActionBar();
if (ab != null) { if (ab != null) {
ab.setDisplayHomeAsUpEnabled(false); ab.setDisplayHomeAsUpEnabled(false);
ab.setHomeButtonEnabled(false); ab.setHomeButtonEnabled(false);
ab.setTitle(R.string.app_name); ab.setTitle(R.string.app_name);
} }
invalidateOptionsMenu(); invalidateOptionsMenu();
hideKeyboard(); hideKeyboard();
if (xmppConnectionServiceBound) { if (xmppConnectionServiceBound) {
xmppConnectionService.getNotificationService().setOpenConversation(null); xmppConnectionService.getNotificationService()
} .setOpenConversation(null);
}
@Override
public void onPanelClosed(View arg0) {
paneShouldBeOpen = false;
if ((conversationList.size() > 0)
&& (getSelectedConversation() != null)) {
openConversation(getSelectedConversation());
if (!getSelectedConversation().isRead()) {
xmppConnectionService
.markRead(getSelectedConversation(),true);
listView.invalidateViews();
} }
} }
}
@Override @Override
public void onPanelSlide(View arg0, float arg1) { public void onPanelClosed(View arg0) {
// TODO Auto-generated method stub paneShouldBeOpen = false;
if ((conversationList.size() > 0)
&& (getSelectedConversation() != null)) {
openConversation(getSelectedConversation());
if (!getSelectedConversation().isRead()) {
xmppConnectionService.markRead(
getSelectedConversation(), true);
listView.invalidateViews();
}
}
}
} @Override
}); public void onPanelSlide(View arg0, float arg1) {
// TODO Auto-generated method stub
}
});
}
} }
public void openConversation(Conversation conversation) { public void openConversation(Conversation conversation) {
@ -179,13 +225,14 @@ public class ConversationActivity extends XmppActivity implements
|| activity.useSubjectToIdentifyConference()) { || activity.useSubjectToIdentifyConference()) {
ab.setTitle(getSelectedConversation().getName()); ab.setTitle(getSelectedConversation().getName());
} else { } else {
ab.setTitle(getSelectedConversation() ab.setTitle(getSelectedConversation().getContactJid()
.getContactJid().split("/")[0]); .split("/")[0]);
} }
} }
invalidateOptionsMenu(); invalidateOptionsMenu();
if (xmppConnectionServiceBound) { if (xmppConnectionServiceBound) {
xmppConnectionService.getNotificationService().setOpenConversation(conversation); xmppConnectionService.getNotificationService().setOpenConversation(
conversation);
} }
} }
@ -206,7 +253,7 @@ public class ConversationActivity extends XmppActivity implements
.findItem(R.id.action_invite); .findItem(R.id.action_invite);
MenuItem menuMute = (MenuItem) menu.findItem(R.id.action_mute); MenuItem menuMute = (MenuItem) menu.findItem(R.id.action_mute);
if ((spl.isOpen() && (spl.isSlideable()))) { if (isConversationsOverviewVisable() && isConversationsOverviewHideable()) {
menuArchive.setVisible(false); menuArchive.setVisible(false);
menuMucDetails.setVisible(false); menuMucDetails.setVisible(false);
menuContactDetails.setVisible(false); menuContactDetails.setVisible(false);
@ -216,7 +263,7 @@ public class ConversationActivity extends XmppActivity implements
menuClearHistory.setVisible(false); menuClearHistory.setVisible(false);
menuMute.setVisible(false); menuMute.setVisible(false);
} else { } else {
menuAdd.setVisible(!spl.isSlideable()); menuAdd.setVisible(!isConversationsOverviewHideable());
if (this.getSelectedConversation() != null) { if (this.getSelectedConversation() != null) {
if (this.getSelectedConversation().getLatestMessage() if (this.getSelectedConversation().getLatestMessage()
.getEncryption() != Message.ENCRYPTION_NONE) { .getEncryption() != Message.ENCRYPTION_NONE) {
@ -325,7 +372,7 @@ public class ConversationActivity extends XmppActivity implements
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) { if (item.getItemId() == android.R.id.home) {
spl.openPane(); showConversationsOverview();
return true; return true;
} else if (item.getItemId() == R.id.action_add) { } else if (item.getItemId() == R.id.action_add) {
startActivity(new Intent(this, StartConversationActivity.class)); startActivity(new Intent(this, StartConversationActivity.class));
@ -377,7 +424,7 @@ public class ConversationActivity extends XmppActivity implements
public void endConversation(Conversation conversation) { public void endConversation(Conversation conversation) {
conversation.setStatus(Conversation.STATUS_ARCHIVED); conversation.setStatus(Conversation.STATUS_ARCHIVED);
paneShouldBeOpen = true; paneShouldBeOpen = true;
spl.openPane(); showConversationsOverview();
xmppConnectionService.archiveConversation(conversation); xmppConnectionService.archiveConversation(conversation);
if (conversationList.size() > 0) { if (conversationList.size() > 0) {
setSelectedConversation(conversationList.get(0)); setSelectedConversation(conversationList.get(0));
@ -563,8 +610,8 @@ public class ConversationActivity extends XmppActivity implements
@Override @Override
public boolean onKeyDown(int keyCode, KeyEvent event) { public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) { if (keyCode == KeyEvent.KEYCODE_BACK) {
if (!spl.isOpen()) { if (!isConversationsOverviewVisable()) {
spl.openPane(); showConversationsOverview();
return false; return false;
} }
} }
@ -612,63 +659,71 @@ public class ConversationActivity extends XmppActivity implements
xmppConnectionService.removeOnConversationListChangedListener(); xmppConnectionService.removeOnConversationListChangedListener();
xmppConnectionService.removeOnAccountListChangedListener(); xmppConnectionService.removeOnAccountListChangedListener();
xmppConnectionService.removeOnRosterUpdateListener(); xmppConnectionService.removeOnRosterUpdateListener();
xmppConnectionService.getNotificationService().setOpenConversation(null); xmppConnectionService.getNotificationService().setOpenConversation(
null);
} }
super.onStop(); super.onStop();
} }
@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
savedInstanceState.putString(STATE_OPEN_CONVERSATION,
getSelectedConversation().getUuid());
savedInstanceState.putBoolean(STATE_PANEL_OPEN, isConversationsOverviewVisable());
super.onSaveInstanceState(savedInstanceState);
}
@Override @Override
void onBackendConnected() { void onBackendConnected() {
this.registerListener(); this.registerListener();
if (conversationList.size() == 0) { updateConversationList();
updateConversationList();
if (xmppConnectionService.getAccounts().size() == 0) {
startActivity(new Intent(this, EditAccountActivity.class));
} else if (conversationList.size() <= 0) {
startActivity(new Intent(this, StartConversationActivity.class));
finish();
} else if (mOpenConverstaion != null) {
selectConversationByUuid(mOpenConverstaion);
paneShouldBeOpen = mPanelOpen;
if (paneShouldBeOpen) {
showConversationsOverview();
}
swapConversationFragment();
mOpenConverstaion = null;
} else if (getIntent() != null
&& VIEW_CONVERSATION.equals(getIntent().getType())) {
String uuid = (String) getIntent().getExtras().get(CONVERSATION);
String text = getIntent().getExtras().getString(TEXT, null);
selectConversationByUuid(uuid);
paneShouldBeOpen = false;
swapConversationFragment().setText(text);
setIntent(null);
} else {
showConversationsOverview();
ConversationFragment selectedFragment = (ConversationFragment) getFragmentManager()
.findFragmentByTag("conversation");
if (selectedFragment != null) {
selectedFragment.onBackendConnected();
} else {
pendingImageUri = null;
setSelectedConversation(conversationList.get(0));
swapConversationFragment();
}
} }
if (getSelectedConversation() != null && pendingImageUri != null) { if (pendingImageUri != null) {
attachImageToConversation(getSelectedConversation(), attachImageToConversation(getSelectedConversation(),
pendingImageUri); pendingImageUri);
pendingImageUri = null; pendingImageUri = null;
} else {
pendingImageUri = null;
} }
ExceptionHelper.checkForCrash(this, this.xmppConnectionService);
}
if ((getIntent().getAction() != null) private void selectConversationByUuid(String uuid) {
&& (getIntent().getAction().equals(Intent.ACTION_VIEW) && (!handledViewIntent))) { for (int i = 0; i < conversationList.size(); ++i) {
if (getIntent().getType().equals( if (conversationList.get(i).getUuid().equals(uuid)) {
ConversationActivity.VIEW_CONVERSATION)) { setSelectedConversation(conversationList.get(i));
handledViewIntent = true;
String convToView = (String) getIntent().getExtras().get(
CONVERSATION);
for (int i = 0; i < conversationList.size(); ++i) {
if (conversationList.get(i).getUuid().equals(convToView)) {
setSelectedConversation(conversationList.get(i));
}
}
paneShouldBeOpen = false;
String text = getIntent().getExtras().getString(TEXT, null);
swapConversationFragment().setText(text);
}
} else {
if (xmppConnectionService.getAccounts().size() == 0) {
startActivity(new Intent(this, EditAccountActivity.class));
} else if (conversationList.size() <= 0) {
// add no history
startActivity(new Intent(this, StartConversationActivity.class));
finish();
} else {
spl.openPane();
// find currently loaded fragment
ConversationFragment selectedFragment = (ConversationFragment) getFragmentManager()
.findFragmentByTag("conversation");
if (selectedFragment != null) {
selectedFragment.onBackendConnected();
} else {
setSelectedConversation(conversationList.get(0));
swapConversationFragment();
}
ExceptionHelper.checkForCrash(this, this.xmppConnectionService);
} }
} }
} }

View file

@ -245,9 +245,7 @@ public class ConversationFragment extends Fragment {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
if (activity.getSlidingPaneLayout().isSlideable()) { activity.hideConversationsOverview();
activity.getSlidingPaneLayout().closePane();
}
} }
}); });
mEditMessage.setOnEditorActionListener(mEditorActionListener); mEditMessage.setOnEditorActionListener(mEditorActionListener);
@ -376,9 +374,9 @@ public class ConversationFragment extends Fragment {
int position = mEditMessage.length(); int position = mEditMessage.length();
Editable etext = mEditMessage.getText(); Editable etext = mEditMessage.getText();
Selection.setSelection(etext, position); Selection.setSelection(etext, position);
if (activity.getSlidingPaneLayout().isSlideable()) { if (activity.isConversationsOverviewHideable()) {
if (!activity.shouldPaneBeOpen()) { if (!activity.shouldPaneBeOpen()) {
activity.getSlidingPaneLayout().closePane(); activity.hideConversationsOverview();
activity.openConversation(conversation); activity.openConversation(conversation);
} }
} }

View file

@ -59,6 +59,7 @@ public abstract class XmppActivity extends Activity {
protected int mPrimaryTextColor; protected int mPrimaryTextColor;
protected int mSecondaryTextColor; protected int mSecondaryTextColor;
protected int mSecondaryBackgroundColor;
protected int mColorRed; protected int mColorRed;
protected int mColorOrange; protected int mColorOrange;
protected int mColorGreen; protected int mColorGreen;
@ -207,6 +208,7 @@ public abstract class XmppActivity extends Activity {
mColorOrange = getResources().getColor(R.color.orange); mColorOrange = getResources().getColor(R.color.orange);
mColorGreen = getResources().getColor(R.color.green); mColorGreen = getResources().getColor(R.color.green);
mPrimaryColor = getResources().getColor(R.color.primary); mPrimaryColor = getResources().getColor(R.color.primary);
mSecondaryBackgroundColor = getResources().getColor(R.color.secondarybackground);
if (getPreferences().getBoolean("use_larger_font", false)) { if (getPreferences().getBoolean("use_larger_font", false)) {
setTheme(R.style.ConversationsTheme_LargerText); setTheme(R.style.ConversationsTheme_LargerText);
} }
@ -519,6 +521,10 @@ public abstract class XmppActivity extends Activity {
return this.mPrimaryColor; return this.mPrimaryColor;
} }
public int getSecondaryBackgroundColor() {
return this.mSecondaryBackgroundColor;
}
class BitmapWorkerTask extends AsyncTask<Message, Void, Bitmap> { class BitmapWorkerTask extends AsyncTask<Message, Void, Bitmap> {
private final WeakReference<ImageView> imageViewReference; private final WeakReference<ImageView> imageViewReference;
private Message message = null; private Message message = null;

View file

@ -40,9 +40,9 @@ public class ConversationAdapter extends ArrayAdapter<Conversation> {
Conversation conv = getItem(position); Conversation conv = getItem(position);
if (this.activity instanceof ConversationActivity) { if (this.activity instanceof ConversationActivity) {
ConversationActivity activity = (ConversationActivity) this.activity; ConversationActivity activity = (ConversationActivity) this.activity;
if (!activity.getSlidingPaneLayout().isSlideable()) { if (!activity.isConversationsOverviewHideable()) {
if (conv == activity.getSelectedConversation()) { if (conv == activity.getSelectedConversation()) {
view.setBackgroundColor(0xffdddddd); view.setBackgroundColor(activity.getSecondaryBackgroundColor());
} else { } else {
view.setBackgroundColor(Color.TRANSPARENT); view.setBackgroundColor(Color.TRANSPARENT);
} }