Merge pull request #485 from veeti/tabswipe

Add tab swiping to contacts picker
This commit is contained in:
Moxie Marlinspike 2013-12-16 12:50:41 -08:00
commit 60f5363da0
5 changed files with 110 additions and 95 deletions

View File

@ -5,8 +5,8 @@
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout android:id="@+id/fragment_container"
android:layout_height="match_parent"
android:layout_width="match_parent"/>
<android.support.v4.view.ViewPager android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>

View File

@ -8,21 +8,11 @@
android:layout_height="fill_parent"
android:fastScrollEnabled="true"/>
<ScrollView android:id="@android:id/empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true">
<TextView android:id="@+id/emptyText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
<TextView android:id="@android:id/empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center|center_vertical"
android:text="@string/contact_selection_group_activity__no_contacts"
android:textSize="20sp"
android:textColor="?android:attr/textColorSecondary"
android:paddingLeft="10dip"
android:paddingRight="10dip"
android:paddingTop="10dip"
android:lineSpacingMultiplier="0.92"
/>
</ScrollView>
android:textSize="20sp" />
</LinearLayout>

View File

@ -9,20 +9,11 @@
android:layout_height="fill_parent"
android:fastScrollEnabled="true" />
<ScrollView android:id="@android:id/empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true">
<TextView android:id="@+id/emptyText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
<TextView android:id="@android:id/empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center|center_vertical"
android:text="@string/contact_selection_group_activity__no_contacts"
android:textSize="20sp"
android:textColor="?android:attr/textColorSecondary"
android:paddingLeft="10dip"
android:paddingRight="10dip"
android:paddingTop="10dip"
android:lineSpacingMultiplier="0.92"
/>
</ScrollView>
android:textSize="20sp" />
</LinearLayout>

View File

@ -10,21 +10,11 @@
android:layout_height="fill_parent"
android:fastScrollEnabled="true" />
<ScrollView android:id="@android:id/empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
<TextView android:id="@+id/emptyText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
<TextView android:id="@android:id/empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center|center_vertical"
android:text="@string/contact_selection_recent_activity__no_recent_calls"
android:textSize="20sp"
android:textColor="?android:attr/textColorSecondary"
android:paddingLeft="10dip"
android:paddingRight="10dip"
android:paddingTop="10dip"
android:lineSpacingMultiplier="0.92"
/>
</ScrollView>
android:textSize="20sp" />
</LinearLayout>

View File

@ -20,7 +20,9 @@ import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.ViewPager;
import org.thoughtcrime.securesms.recipients.Recipients;
import org.thoughtcrime.securesms.util.DynamicTheme;
@ -44,6 +46,7 @@ public class ContactSelectionActivity extends PassphraseRequiredSherlockFragment
private final DynamicTheme dynamicTheme = new DynamicTheme();
private ViewPager viewPager;
private ContactSelectionListFragment contactsFragment;
private ContactSelectionGroupsFragment groupsFragment;
private ContactSelectionRecentFragment recentFragment;
@ -61,9 +64,9 @@ public class ContactSelectionActivity extends PassphraseRequiredSherlockFragment
setContentView(R.layout.contact_selection_activity);
setupContactsTab();
setupGroupsTab();
setupRecentTab();
setupFragments();
setupViewPager();
setupTabs();
}
@Override
@ -104,56 +107,97 @@ public class ContactSelectionActivity extends PassphraseRequiredSherlockFragment
finish();
}
private ActionBar.Tab constructTab(final Fragment fragment) {
ActionBar actionBar = this.getSupportActionBar();
ActionBar.Tab tab = actionBar.newTab();
private void setupViewPager() {
viewPager = (ViewPager) findViewById(R.id.pager);
viewPager.setAdapter(new SelectionPagerAdapter());
viewPager.setOnPageChangeListener(new TabSwitchingPageListener());
}
tab.setTabListener(new TabListener(){
@Override
public void onTabSelected(Tab tab, FragmentTransaction ignore) {
FragmentManager manager = ContactSelectionActivity.this.getSupportFragmentManager();
FragmentTransaction ft = manager.beginTransaction();
private void setupTabs() {
int[] icons = new int[] { R.drawable.ic_tab_contacts, R.drawable.ic_tab_groups, R.drawable.ic_tab_recent };
ft.add(R.id.fragment_container, fragment);
ft.commit();
for (int i = 0; i < icons.length; i++) {
ActionBar.Tab tab = getSupportActionBar().newTab();
tab.setIcon(icons[i]);
tab.setTabListener(new ViewPagerTabListener(i));
getSupportActionBar().addTab(tab);
}
}
private void setupFragments() {
contactsFragment = new ContactSelectionListFragment();
groupsFragment = new ContactSelectionGroupsFragment();
recentFragment = new ContactSelectionRecentFragment();
}
private class SelectionPagerAdapter extends FragmentPagerAdapter {
public SelectionPagerAdapter() {
super(getSupportFragmentManager());
}
@Override
public void onTabUnselected(Tab tab, FragmentTransaction ignore) {
FragmentManager manager = ContactSelectionActivity.this.getSupportFragmentManager();
FragmentTransaction ft = manager.beginTransaction();
ft.remove(fragment);
ft.commit();
public Fragment getItem(int i) {
switch (i) {
case 0:
return contactsFragment;
case 1:
return groupsFragment;
case 2:
default:
return recentFragment;
}
}
@Override
public void onTabReselected(Tab tab, FragmentTransaction ft) {}
});
return tab;
public int getCount() {
return 3;
}
private void setupContactsTab() {
contactsFragment = (ContactSelectionListFragment)Fragment.instantiate(this,
ContactSelectionListFragment.class.getName());
ActionBar.Tab contactsTab = constructTab(contactsFragment);
contactsTab.setIcon(R.drawable.ic_tab_contacts);
this.getSupportActionBar().addTab(contactsTab);
}
private void setupGroupsTab() {
groupsFragment = (ContactSelectionGroupsFragment)Fragment.instantiate(this,
ContactSelectionGroupsFragment.class.getName());
ActionBar.Tab groupsTab = constructTab(groupsFragment);
groupsTab.setIcon(R.drawable.ic_tab_groups);
this.getSupportActionBar().addTab(groupsTab);
private class ViewPagerTabListener implements TabListener {
private int tabIndex;
public ViewPagerTabListener(int index) {
tabIndex = index;
}
private void setupRecentTab() {
recentFragment = (ContactSelectionRecentFragment)Fragment.instantiate(this,
ContactSelectionRecentFragment.class.getName());
ActionBar.Tab recentTab = constructTab(recentFragment);
recentTab.setIcon(R.drawable.ic_tab_recent);
this.getSupportActionBar().addTab(recentTab);
@Override
public void onTabSelected(Tab tab, FragmentTransaction fragmentTransaction) {
viewPager.setCurrentItem(tabIndex);
}
@Override
public void onTabUnselected(Tab tab, FragmentTransaction fragmentTransaction) {
}
@Override
public void onTabReselected(Tab tab, FragmentTransaction fragmentTransaction) {
}
}
private class TabSwitchingPageListener implements ViewPager.OnPageChangeListener {
@Override
public void onPageScrolled(int i, float v, int i2) {
}
@Override
public void onPageSelected(int i) {
getSupportActionBar().setSelectedNavigationItem(i);
}
@Override
public void onPageScrollStateChanged(int i) {
}
}
}