diff options
author | Artur Dryomov <artur.dryomov@gmail.com> | 2013-09-06 18:48:29 +0300 |
---|---|---|
committer | Artur Dryomov <artur.dryomov@gmail.com> | 2013-09-07 11:55:53 +0300 |
commit | 2eb19ddb3f5f82efc4ffc882178ca3c6b7886e51 (patch) | |
tree | 44e82aa6d5ca22044431a1c5ce0c9f7b098d206c /android/sdremote | |
parent | 275aeab07405b3a07ead39b20ccbc65f4f842c03 (diff) |
Add showing helper messages while searching computers.
Change progress bars from large to average size as well.
* It makes them consistent with other Google apps.
* It brings better LAF for Gingerbread.
Change-Id: Id25a42c9735c3c9948c507eacfbfd64d90d87435
Diffstat (limited to 'android/sdremote')
5 files changed, 140 insertions, 13 deletions
diff --git a/android/sdremote/res/layout/fragment_computer_connection.xml b/android/sdremote/res/layout/fragment_computer_connection.xml index 6ad129044918..4caf01c2c5ce 100644 --- a/android/sdremote/res/layout/fragment_computer_connection.xml +++ b/android/sdremote/res/layout/fragment_computer_connection.xml @@ -8,7 +8,7 @@ <ProgressBar android:id="@+id/progress_bar" - style="?android:progressBarStyleLarge" + style="?android:progressBarStyle" android:layout_gravity="center" android:layout_width="wrap_content" android:layout_height="wrap_content"/> diff --git a/android/sdremote/res/layout/fragment_computers_list.xml b/android/sdremote/res/layout/fragment_computers_list.xml new file mode 100644 index 000000000000..c780bab0463b --- /dev/null +++ b/android/sdremote/res/layout/fragment_computers_list.xml @@ -0,0 +1,41 @@ +<?xml version="1.0" encoding="utf-8"?> +<ViewAnimator xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@+id/view_animator" + android:inAnimation="@android:anim/fade_in" + android:outAnimation="@android:anim/fade_out" + android:layout_width="match_parent" + android:layout_height="match_parent"> + + <LinearLayout + android:animateLayoutChanges="true" + android:id="@+id/container_progress" + android:orientation="vertical" + android:gravity="center" + android:paddingLeft="@dimen/padding_horizontal_progress_layout" + android:paddingRight="@dimen/padding_horizontal_progress_layout" + android:layout_width="match_parent" + android:layout_height="match_parent"> + + <ProgressBar + android:id="@+id/progress_bar" + style="?android:progressBarStyle" + android:layout_width="wrap_content" + android:layout_height="wrap_content"/> + + <TextView + android:id="@+id/text_progress_message" + android:text="@string/message_search_wifi" + android:gravity="center_horizontal" + android:visibility="invisible" + android:paddingTop="@dimen/padding_vertical_progress_message" + android:layout_width="match_parent" + android:layout_height="wrap_content"/> + + </LinearLayout> + + <ListView + android:id="@android:id/list" + android:layout_width="match_parent" + android:layout_height="match_parent"/> + +</ViewAnimator>
\ No newline at end of file diff --git a/android/sdremote/res/values/dimens.xml b/android/sdremote/res/values/dimens.xml index 00054a38185d..05c730363378 100644 --- a/android/sdremote/res/values/dimens.xml +++ b/android/sdremote/res/values/dimens.xml @@ -19,10 +19,12 @@ <dimen name="padding_horizontal_connection_layout">40dp</dimen> <dimen name="padding_horizontal_action_bar_button">20dp</dimen> <dimen name="padding_horizontal_action_bar_divider">12dp</dimen> + <dimen name="padding_horizontal_progress_layout">40dp</dimen> <dimen name="padding_vertical_pin">8dp</dimen> <dimen name="padding_vertical_error_message">12dp</dimen> <dimen name="padding_vertical_edit">8dp</dimen> + <dimen name="padding_vertical_progress_message">8dp</dimen> <dimen name="margin_vertical_action_bar_divider">12dp</dimen> <dimen name="margin_slide">8dp</dimen> diff --git a/android/sdremote/res/values/strings.xml b/android/sdremote/res/values/strings.xml index c4e5a73486a2..02e2cde11066 100644 --- a/android/sdremote/res/values/strings.xml +++ b/android/sdremote/res/values/strings.xml @@ -38,6 +38,8 @@ <string name="message_impress_pairing_check">If you have Bluetooth pairing issues check instructions related to your desktop OS.</string> <string name="message_ip_address_validation">Type in a valid IP address.</string> <string name="message_time_is_up">Time is up!</string> + <string name="message_search_wifi">Make sure LibreOffice is running on a computer on the same WiFi network.</string> + <string name="message_search_bluetooth">Make sure LibreOffice is running on a computer with Bluetooth enabled.</string> <string name="hint_ip_address">IP address</string> <string name="hint_name">Name (optional)</string> diff --git a/android/sdremote/src/org/libreoffice/impressremote/fragment/ComputersFragment.java b/android/sdremote/src/org/libreoffice/impressremote/fragment/ComputersFragment.java index fffd1cfb5566..c8928470b61f 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/fragment/ComputersFragment.java +++ b/android/sdremote/src/org/libreoffice/impressremote/fragment/ComputersFragment.java @@ -10,6 +10,7 @@ package org.libreoffice.impressremote.fragment; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.TimeUnit; import android.app.Activity; import android.content.BroadcastReceiver; @@ -19,12 +20,19 @@ import android.content.Intent; import android.content.IntentFilter; import android.content.ServiceConnection; import android.os.Bundle; +import android.os.Handler; import android.os.IBinder; import android.support.v4.content.LocalBroadcastManager; import android.view.ContextMenu; +import android.view.LayoutInflater; import android.view.View; +import android.view.ViewGroup; +import android.view.animation.Animation; +import android.view.animation.AnimationUtils; import android.widget.AdapterView; import android.widget.ListView; +import android.widget.TextView; +import android.widget.ViewAnimator; import com.actionbarsherlock.app.SherlockListFragment; import com.actionbarsherlock.view.MenuItem; @@ -34,7 +42,9 @@ import org.libreoffice.impressremote.R; import org.libreoffice.impressremote.communication.CommunicationService; import org.libreoffice.impressremote.communication.Server; -public class ComputersFragment extends SherlockListFragment implements ServiceConnection { +public class ComputersFragment extends SherlockListFragment implements ServiceConnection, Runnable { + private static final int SHOWING_PROGRESS_MESSAGE_DELAY_IN_SECONDS = 10; + public static enum Type { WIFI, BLUETOOTH } @@ -61,6 +71,11 @@ public class ComputersFragment extends SherlockListFragment implements ServiceCo } @Override + public View onCreateView(LayoutInflater aInflater, ViewGroup aContainer, Bundle aSavedInstanceState) { + return aInflater.inflate(R.layout.fragment_computers_list, aContainer, false); + } + + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -88,7 +103,6 @@ public class ComputersFragment extends SherlockListFragment implements ServiceCo @Override public void onServiceConnected(ComponentName aComponentName, IBinder aBinder) { CommunicationService.CBinder aServiceBinder = (CommunicationService.CBinder) aBinder; - mCommunicationService = aServiceBinder.getService(); mCommunicationService.startSearch(); @@ -103,8 +117,12 @@ public class ComputersFragment extends SherlockListFragment implements ServiceCo if (getComputers().isEmpty()) { hideComputersList(); + setUpProgressMessage(); + tearDownComputersAdapter(); } else { + setUpComputersAdapter(); + fillComputersAdapter(); showComputersList(); } } @@ -114,20 +132,83 @@ public class ComputersFragment extends SherlockListFragment implements ServiceCo } private void hideComputersList() { - setListAdapter(null); + ViewAnimator aViewAnimator = getViewAnimator(); + ViewGroup aProgressBarLayout = getProgressBarLayout(); - setListShown(false); + aViewAnimator.setDisplayedChild(aViewAnimator.indexOfChild(aProgressBarLayout)); } - private void showComputersList() { - if (!isComputersAdapterExist()) { - setUpComputersAdapter(); + private ViewAnimator getViewAnimator() { + return (ViewAnimator) getView().findViewById(R.id.view_animator); + } + + private ViewGroup getProgressBarLayout() { + return (ViewGroup) getView().findViewById(R.id.container_progress); + } + + private void setUpProgressMessage() { + new Handler().postDelayed(this, TimeUnit.SECONDS.toMillis(SHOWING_PROGRESS_MESSAGE_DELAY_IN_SECONDS)); + } + + @Override + public void run() { + if (isShowingProgressMessageRequired()) { + showProgressMessage(); } + } - getComputersAdapter().clear(); - getComputersAdapter().add(getComputers()); + private boolean isShowingProgressMessageRequired() { + return getProgressMessageView().getVisibility() == View.INVISIBLE; + } - setListShown(true); + private TextView getProgressMessageView() { + return (TextView) getView().findViewById(R.id.text_progress_message); + } + + private void showProgressMessage() { + TextView aProgressMessageView = getProgressMessageView(); + Animation aFadeInAnimation = AnimationUtils.loadAnimation(getActivity(), android.R.anim.fade_in); + + aProgressMessageView.setText(getProgressMessage()); + + aProgressMessageView.startAnimation(aFadeInAnimation); + aProgressMessageView.setVisibility(View.VISIBLE); + } + + private String getProgressMessage() { + switch (mType) { + case WIFI: + return getString(R.string.message_search_wifi); + + case BLUETOOTH: + return getString(R.string.message_search_bluetooth); + + default: + return ""; + } + } + + private void tearDownComputersAdapter() { + getComputesList().setAdapter(null); + } + + private ListView getComputesList() { + return (ListView) getView().findViewById(android.R.id.list); + } + + private void showComputersList() { + ViewAnimator aViewAnimator = getViewAnimator(); + ListView aComputersList= getComputesList(); + + aViewAnimator.setDisplayedChild(aViewAnimator.indexOfChild(aComputersList)); + } + + private void setUpComputersAdapter() { + if (isComputersAdapterExist()) { + return; + } + + setListAdapter(new ComputersAdapter(getActivity())); } private boolean isComputersAdapterExist() { @@ -138,8 +219,9 @@ public class ComputersFragment extends SherlockListFragment implements ServiceCo return (ComputersAdapter) getListAdapter(); } - private void setUpComputersAdapter() { - setListAdapter(new ComputersAdapter(getActivity())); + private void fillComputersAdapter() { + getComputersAdapter().clear(); + getComputersAdapter().add(getComputers()); } private List<Server> getComputers() { |