summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--android/sdremote/res/layout/activity_computers.xml6
-rw-r--r--android/sdremote/src/org/libreoffice/impressremote/activity/ComputersActivity.java62
-rw-r--r--android/sdremote/src/org/libreoffice/impressremote/adapter/ComputersPagerAdapter.java42
-rw-r--r--android/sdremote/src/org/libreoffice/impressremote/fragment/ComputersFragment.java12
-rw-r--r--android/sdremote/src/org/libreoffice/impressremote/util/ActionBarTabListener.java46
5 files changed, 105 insertions, 63 deletions
diff --git a/android/sdremote/res/layout/activity_computers.xml b/android/sdremote/res/layout/activity_computers.xml
new file mode 100644
index 000000000000..6e5332d1ea67
--- /dev/null
+++ b/android/sdremote/res/layout/activity_computers.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<android.support.v4.view.ViewPager
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/pager_computers"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"/> \ No newline at end of file
diff --git a/android/sdremote/src/org/libreoffice/impressremote/activity/ComputersActivity.java b/android/sdremote/src/org/libreoffice/impressremote/activity/ComputersActivity.java
index 14ace705a644..3a5bbb6beb88 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/activity/ComputersActivity.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/activity/ComputersActivity.java
@@ -10,23 +10,26 @@ package org.libreoffice.impressremote.activity;
import android.content.Intent;
import android.os.Bundle;
-import android.support.v4.app.Fragment;
+import android.support.v4.app.FragmentTransaction;
+import android.support.v4.view.PagerAdapter;
+import android.support.v4.view.ViewPager;
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
-import org.libreoffice.impressremote.util.ActionBarTabListener;
-import org.libreoffice.impressremote.fragment.ComputersFragment;
+import org.libreoffice.impressremote.adapter.ComputersPagerAdapter;
import org.libreoffice.impressremote.util.Intents;
import org.libreoffice.impressremote.R;
-public class ComputersActivity extends SherlockFragmentActivity {
+public class ComputersActivity extends SherlockFragmentActivity implements ActionBar.TabListener, ViewPager.OnPageChangeListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_computers);
setUpTabs();
+ setUpComputersPager();
}
private void setUpTabs() {
@@ -37,26 +40,59 @@ public class ComputersActivity extends SherlockFragmentActivity {
}
private ActionBar.Tab buildBluetoothServersTab() {
- ComputersFragment aFragment = ComputersFragment.newInstance(
- ComputersFragment.Type.BLUETOOTH);
-
- return buildActionBarTab(aFragment, R.string.title_bluetooth);
+ return buildActionBarTab(R.string.title_bluetooth);
}
- private ActionBar.Tab buildActionBarTab(Fragment aFragment, int aTitleResourceId) {
+ private ActionBar.Tab buildActionBarTab(int aTitleResourceId) {
ActionBar.Tab aTab = getSupportActionBar().newTab();
- aTab.setTabListener(new ActionBarTabListener(aFragment));
+ aTab.setTabListener(this);
aTab.setText(aTitleResourceId);
return aTab;
}
+ @Override
+ public void onTabSelected(ActionBar.Tab aTab, FragmentTransaction aTransaction) {
+ getComputersPager().setCurrentItem(aTab.getPosition());
+ }
+
+ private ViewPager getComputersPager() {
+ return (ViewPager) findViewById(R.id.pager_computers);
+ }
+
+ @Override
+ public void onTabUnselected(ActionBar.Tab aTab, FragmentTransaction aTransaction) {
+ }
+
+ @Override
+ public void onTabReselected(ActionBar.Tab aTab, FragmentTransaction aTransaction) {
+ }
+
private ActionBar.Tab buildWiFiServersTab() {
- ComputersFragment aFragment = ComputersFragment.newInstance(
- ComputersFragment.Type.WIFI);
+ return buildActionBarTab(R.string.title_wifi);
+ }
+
+ private void setUpComputersPager() {
+ getComputersPager().setAdapter(buildComputersPagerAdapter());
+ getComputersPager().setOnPageChangeListener(this);
+ }
+
+ private PagerAdapter buildComputersPagerAdapter() {
+ return new ComputersPagerAdapter(getSupportFragmentManager());
+ }
+
+ @Override
+ public void onPageSelected(int aPosition) {
+ getSupportActionBar().setSelectedNavigationItem(aPosition);
+ }
+
+ @Override
+ public void onPageScrolled(int aPosition, float aPositionOffset, int aPositionOffsetPixels) {
+ }
- return buildActionBarTab(aFragment, R.string.title_wifi);
+ @Override
+ public void onPageScrollStateChanged(int aPosition) {
}
@Override
diff --git a/android/sdremote/src/org/libreoffice/impressremote/adapter/ComputersPagerAdapter.java b/android/sdremote/src/org/libreoffice/impressremote/adapter/ComputersPagerAdapter.java
new file mode 100644
index 000000000000..5a4ddaada85a
--- /dev/null
+++ b/android/sdremote/src/org/libreoffice/impressremote/adapter/ComputersPagerAdapter.java
@@ -0,0 +1,42 @@
+package org.libreoffice.impressremote.adapter;
+
+import android.support.v4.app.Fragment;
+import android.support.v4.app.FragmentManager;
+import android.support.v4.app.FragmentPagerAdapter;
+
+import org.libreoffice.impressremote.fragment.ComputersFragment;
+
+public class ComputersPagerAdapter extends FragmentPagerAdapter {
+ private static final int PAGER_SIZE = 2;
+
+ private static final class PagerPositions {
+ private PagerPositions() {
+ }
+
+ public static final int BLUETOOTH = 0;
+ public static final int WIFI = 1;
+ }
+
+ public ComputersPagerAdapter(FragmentManager aFragmentManager) {
+ super(aFragmentManager);
+ }
+
+ @Override
+ public Fragment getItem(int aPosition) {
+ switch (aPosition) {
+ case PagerPositions.BLUETOOTH:
+ return ComputersFragment.newInstance(ComputersFragment.Type.BLUETOOTH);
+
+ case PagerPositions.WIFI:
+ return ComputersFragment.newInstance(ComputersFragment.Type.WIFI);
+
+ default:
+ return null;
+ }
+ }
+
+ @Override
+ public int getCount() {
+ return PAGER_SIZE;
+ }
+}
diff --git a/android/sdremote/src/org/libreoffice/impressremote/fragment/ComputersFragment.java b/android/sdremote/src/org/libreoffice/impressremote/fragment/ComputersFragment.java
index 18491d6cc73e..fffd1cfb5566 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/fragment/ComputersFragment.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/fragment/ComputersFragment.java
@@ -97,10 +97,6 @@ public class ComputersFragment extends SherlockListFragment implements ServiceCo
}
private void loadComputers() {
- if (!isAdded()) {
- return;
- }
-
if (!isServiceBound()) {
return;
}
@@ -196,6 +192,8 @@ public class ComputersFragment extends SherlockListFragment implements ServiceCo
super.onResume();
registerIntentsReceiver();
+
+ loadComputers();
}
private void registerIntentsReceiver() {
@@ -277,6 +275,12 @@ public class ComputersFragment extends SherlockListFragment implements ServiceCo
@Override
public boolean onContextItemSelected(android.view.MenuItem aMenuItem) {
+ if (!getUserVisibleHint()) {
+ // Wrong context menu could be dispatched.
+ // Android’s issue #20065.
+ return false;
+ }
+
int aComputerPosition = getListItemPosition(aMenuItem);
Server aComputer = getComputersAdapter().getItem(aComputerPosition);
diff --git a/android/sdremote/src/org/libreoffice/impressremote/util/ActionBarTabListener.java b/android/sdremote/src/org/libreoffice/impressremote/util/ActionBarTabListener.java
deleted file mode 100644
index e21911adaee2..000000000000
--- a/android/sdremote/src/org/libreoffice/impressremote/util/ActionBarTabListener.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- */
-package org.libreoffice.impressremote.util;
-
-import android.support.v4.app.Fragment;
-import android.support.v4.app.FragmentTransaction;
-
-import com.actionbarsherlock.app.ActionBar;
-
-public class ActionBarTabListener implements ActionBar.TabListener {
- private final Fragment mTabFragment;
-
- public ActionBarTabListener(Fragment aTabFragment) {
- mTabFragment = aTabFragment;
- }
-
- @Override
- public void onTabSelected(ActionBar.Tab aTab, FragmentTransaction aFragmentTransaction) {
- if (mTabFragment.isDetached()) {
- aFragmentTransaction.attach(mTabFragment);
- }
-
- aFragmentTransaction.replace(android.R.id.content, mTabFragment);
- }
-
- @Override
- public void onTabUnselected(ActionBar.Tab aTab, FragmentTransaction aFragmentTransaction) {
- if (mTabFragment.isDetached()) {
- return;
- }
-
- aFragmentTransaction.detach(mTabFragment);
- }
-
- @Override
- public void onTabReselected(ActionBar.Tab aTab, FragmentTransaction aFragmentTransaction) {
- }
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */