diff options
author | lambroslambrou@chromium.org <lambroslambrou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-18 00:10:15 +0000 |
---|---|---|
committer | lambroslambrou@chromium.org <lambroslambrou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-18 00:10:15 +0000 |
commit | 2b653681887388a7cd7e26586cb94b87a393ad54 (patch) | |
tree | 3b87bfa381d83a75b0126599d36ea3ad6a4a76a5 | |
parent | f0779b5f9025898b681ea7b33e61e4682f19c224 (diff) | |
download | chromium_src-2b653681887388a7cd7e26586cb94b87a393ad54.zip chromium_src-2b653681887388a7cd7e26586cb94b87a393ad54.tar.gz chromium_src-2b653681887388a7cd7e26586cb94b87a393ad54.tar.bz2 |
Clear host list and show progress indicator when switching accounts.
When loading the host list, this replaces the main view with a spinning
progress indicator similar to the GMail example at
http://developer.android.com/design/building-blocks/progress.html#activity
BUG=351523
Review URL: https://codereview.chromium.org/200963002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@257543 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | remoting/android/java/src/org/chromium/chromoting/Chromoting.java | 22 | ||||
-rw-r--r-- | remoting/resources/android/layout/main.xml | 26 |
2 files changed, 40 insertions, 8 deletions
diff --git a/remoting/android/java/src/org/chromium/chromoting/Chromoting.java b/remoting/android/java/src/org/chromium/chromoting/Chromoting.java index 55352cd..ebf826c 100644 --- a/remoting/android/java/src/org/chromium/chromoting/Chromoting.java +++ b/remoting/android/java/src/org/chromium/chromoting/Chromoting.java @@ -23,6 +23,7 @@ import android.provider.Settings; import android.util.Log; import android.view.Menu; import android.view.MenuItem; +import android.view.View; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.TextView; @@ -69,6 +70,12 @@ public class Chromoting extends Activity implements JniInterface.ConnectionListe /** Refresh button. */ private MenuItem mRefreshButton; + /** Main view of this activity */ + private View mMainView; + + /** Progress view shown instead of the main view when the host list is loading. */ + private View mProgressView; + /** Greeting at the top of the displayed list. */ private TextView mGreeting; @@ -119,6 +126,12 @@ public class Chromoting extends Activity implements JniInterface.ConnectionListe dialog.show(); } + /** Shows or hides the progress indicator for loading the host list. */ + private void setHostListProgressVisible(boolean visible) { + mMainView.setVisibility(visible ? View.GONE : View.VISIBLE); + mProgressView.setVisibility(visible ? View.VISIBLE : View.GONE); + } + /** * Called when the activity is first created. Loads the native library and requests an * authentication token from the system. @@ -132,6 +145,8 @@ public class Chromoting extends Activity implements JniInterface.ConnectionListe mHostListLoader = new HostListLoader(); // Get ahold of our view widgets. + mMainView = findViewById(R.id.hostList_main); + mProgressView = findViewById(R.id.hostList_progress); mGreeting = (TextView)findViewById(R.id.hostList_greeting); mList = (ListView)findViewById(R.id.hostList_chooser); @@ -238,6 +253,7 @@ public class Chromoting extends Activity implements JniInterface.ConnectionListe private void refreshHostList() { mTriedNewAuthToken = false; + setHostListProgressVisible(true); // The refresh button simply makes use of the currently-chosen account. AccountManager.get(this).getAuthToken(mAccount, TOKEN_SCOPE, null, this, this, null); @@ -287,6 +303,9 @@ public class Chromoting extends Activity implements JniInterface.ConnectionListe getPreferences(MODE_PRIVATE).edit().putString("account_name", mAccount.name). putString("account_type", mAccount.type).apply(); + // The current host list is no longer valid for the new account, so clear the list. + mHosts = new HostInfo[0]; + updateUi(); refreshHostList(); return true; } @@ -296,6 +315,7 @@ public class Chromoting extends Activity implements JniInterface.ConnectionListe // Store a copy of the array, so that it can't be mutated by the HostListLoader. HostInfo // is an immutable type, so a shallow copy of the array is sufficient here. mHosts = Arrays.copyOf(hosts, hosts.length); + setHostListProgressVisible(false); updateUi(); } @@ -320,6 +340,7 @@ public class Chromoting extends Activity implements JniInterface.ConnectionListe if (explanation != null) { Toast.makeText(this, explanation, Toast.LENGTH_LONG).show(); + setHostListProgressVisible(false); return; } @@ -343,6 +364,7 @@ public class Chromoting extends Activity implements JniInterface.ConnectionListe Log.e("auth", "Fresh auth token was also rejected"); explanation = getString(R.string.error_authentication_failed); Toast.makeText(this, explanation, Toast.LENGTH_LONG).show(); + setHostListProgressVisible(false); } } diff --git a/remoting/resources/android/layout/main.xml b/remoting/resources/android/layout/main.xml index acb8462..25a958b 100644 --- a/remoting/resources/android/layout/main.xml +++ b/remoting/resources/android/layout/main.xml @@ -5,14 +5,24 @@ found in the LICENSE file. --> -<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" - android:orientation="vertical" +<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="match_parent" android:layout_width="match_parent"> - <TextView android:id="@+id/hostList_greeting" - android:layout_height="wrap_content" - android:layout_width="match_parent"/> - <ListView android:id="@+id/hostList_chooser" + <LinearLayout android:id="@+id/hostList_main" + android:orientation="vertical" android:layout_height="match_parent" - android:layout_width="match_parent"/> -</LinearLayout> + android:layout_width="match_parent"> + <TextView android:id="@+id/hostList_greeting" + android:layout_height="wrap_content" + android:layout_width="match_parent"/> + <ListView android:id="@+id/hostList_chooser" + android:layout_height="match_parent" + android:layout_width="match_parent"/> + </LinearLayout> + <ProgressBar android:id="@+id/hostList_progress" + android:layout_height="wrap_content" + android:layout_width="wrap_content" + android:layout_gravity="center" + android:visibility="gone" + style="@android:style/Widget.Holo.ProgressBar.Large"/> +</FrameLayout> |