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" android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"> xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout android:id="@+id/fragment_container" <android.support.v4.view.ViewPager android:id="@+id/pager"
android:layout_height="match_parent" android:layout_width="match_parent"
android:layout_width="match_parent"/> android:layout_height="match_parent" />
</LinearLayout> </LinearLayout>

View File

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

View File

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

View File

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

View File

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