diff options
author | Parménides GV <parmegv@sdf.org> | 2013-07-04 21:44:16 +0200 |
---|---|---|
committer | cyBerta <richy@cyborgsociety.org> | 2013-11-15 23:02:37 +0100 |
commit | 4256f21a0a27032fd37bdf9b428009da5b7ba27a (patch) | |
tree | 088369da03ec2763c4176a659dc7918bfc7f9ac7 /src/se/leap/bitmaskclient | |
parent | be3f2ba04e96bc21a1c9c0459218a1d964af1945 (diff) |
Added a progressbar to ConfigurationWizard.
It resizes the provider list, pushing it down to show the progressbar
up, and back to the original layout after the operation.
Diffstat (limited to 'src/se/leap/bitmaskclient')
-rw-r--r-- | src/se/leap/bitmaskclient/ConfigurationWizard.java | 84 | ||||
-rw-r--r-- | src/se/leap/bitmaskclient/ProviderListFragment.java | 8 |
2 files changed, 64 insertions, 28 deletions
diff --git a/src/se/leap/bitmaskclient/ConfigurationWizard.java b/src/se/leap/bitmaskclient/ConfigurationWizard.java index c03d7c9e..ea85361d 100644 --- a/src/se/leap/bitmaskclient/ConfigurationWizard.java +++ b/src/se/leap/bitmaskclient/ConfigurationWizard.java @@ -38,6 +38,8 @@ import android.os.Handler; import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ProgressBar;
/**
* Activity that builds and shows the list of known available providers.
@@ -51,7 +53,7 @@ public class ConfigurationWizard extends Activity implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogInterface, ProviderDetailFragment.ProviderDetailFragmentInterface, Receiver {
private ProviderItem mSelectedProvider;
- private ProgressDialog mProgressDialog;
+ private ProgressBar mProgressBar;
private Intent mConfigState = new Intent();
final public static String TYPE_OF_CERTIFICATE = "type_of_certificate";
@@ -68,6 +70,8 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn super.onCreate(savedInstanceState);
setContentView(R.layout.configuration_wizard_activity);
+ mProgressBar = (ProgressBar) findViewById(R.id.progressbar);
+ mProgressBar.setVisibility(ProgressBar.INVISIBLE);
providerAPI_result_receiver = new ProviderAPIResultReceiver(new Handler());
providerAPI_result_receiver.setReceiver(this);
@@ -80,17 +84,29 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn if ( savedInstanceState == null ){
// TODO Some welcome screen?
// We will need better flow control when we have more Fragments (e.g. user auth)
- ProviderListFragment providerList = new ProviderListFragment();
+ ProviderListFragment provider_list_fragment = new ProviderListFragment();
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction()
- .add(R.id.configuration_wizard_layout, providerList, "providerlist")
+ .add(R.id.configuration_wizard_layout, provider_list_fragment, getResources().getString(R.string.provider_list_fragment_tag))
.commit();
}
// TODO: If exposing deep links into your app, handle intents here.
}
+ private void refreshProviderList(int top_padding) {
+ ProviderListFragment providerList = new ProviderListFragment();
+ Bundle top_padding_bundle = new Bundle();
+ top_padding_bundle.putInt(getResources().getString(R.string.top_padding), top_padding);
+ providerList.setArguments(top_padding_bundle);
+
+ FragmentManager fragmentManager = getFragmentManager();
+ fragmentManager.beginTransaction()
+ .replace(R.id.configuration_wizard_layout, providerList, getResources().getString(R.string.provider_list_fragment_tag))
+ .commit();
+ }
+
@Override
public void onReceiveResult(int resultCode, Bundle resultData) {
if(resultCode == ProviderAPI.CORRECTLY_UPDATED_PROVIDER_DOT_JSON) {
@@ -103,62 +119,76 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn ConfigHelper.saveSharedPref(EIP.ALLOWED_ANON, provider_json.getJSONObject(Provider.SERVICE).getBoolean(EIP.ALLOWED_ANON));
mConfigState.setAction(PROVIDER_SET);
- if(mProgressDialog != null) mProgressDialog.dismiss();
- mProgressDialog = ProgressDialog.show(this, getResources().getString(R.string.config_wait_title), getResources().getString(R.string.config_connecting_provider), true);
- mProgressDialog.setMessage(getResources().getString(R.string.config_downloading_services));
+ if(!mProgressBar.isShown())
+ startProgressBar();
+ mProgressBar.incrementProgressBy(1);
if(resultData.containsKey(Provider.NAME))
mSelectedProvider = getProvider(resultData.getString(Provider.NAME));
- ProviderListFragment providerList = new ProviderListFragment();
-
- FragmentManager fragmentManager = getFragmentManager();
- fragmentManager.beginTransaction()
- .replace(R.id.configuration_wizard_layout, providerList, "providerlist")
- .commit();
+ refreshProviderList(30);
downloadJSONFiles(mSelectedProvider);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
-
- mProgressDialog.dismiss();
+ mProgressBar.setVisibility(ProgressBar.GONE);
+ refreshProviderList(0);
//Toast.makeText(this, getResources().getString(R.string.config_error_parsing), Toast.LENGTH_LONG);
setResult(RESULT_CANCELED, mConfigState);
}
- } + }
else if(resultCode == ProviderAPI.INCORRECTLY_UPDATED_PROVIDER_DOT_JSON) {
String reason_to_fail = resultData.getString(ProviderAPI.ERRORS);
- showDownloadFailedDialog(getCurrentFocus(), reason_to_fail); - mProgressDialog.dismiss();
+ showDownloadFailedDialog(getCurrentFocus(), reason_to_fail);
+ refreshProviderList(0);
+ mProgressBar.setVisibility(ProgressBar.GONE);
setResult(RESULT_CANCELED, mConfigState);
}
else if(resultCode == ProviderAPI.CORRECTLY_DOWNLOADED_JSON_FILES) {
+ mProgressBar.incrementProgressBy(1);
if (ConfigHelper.getBoolFromSharedPref(EIP.ALLOWED_ANON)){
- mProgressDialog.setMessage(getResources().getString(R.string.config_downloading_certificates));
mConfigState.putExtra(SERVICES_RETRIEVED, true);
downloadAnonCert();
} else {
- mProgressDialog.dismiss();
+ mProgressBar.incrementProgressBy(1);
+ mProgressBar.setVisibility(ProgressBar.GONE);
+ refreshProviderList(0);
//Toast.makeText(getApplicationContext(), R.string.success, Toast.LENGTH_LONG).show();
setResult(RESULT_OK);
- finish();
+ showProviderDetails(getCurrentFocus());
}
}
else if(resultCode == ProviderAPI.INCORRECTLY_DOWNLOADED_JSON_FILES) {
- //Toast.makeText(getApplicationContext(), R.string.incorrectly_downloaded_json_files_message, Toast.LENGTH_LONG).show(); + //Toast.makeText(getApplicationContext(), R.string.incorrectly_downloaded_json_files_message, Toast.LENGTH_LONG).show();
+<<<<<<< HEAD:src/se/leap/bitmaskclient/ConfigurationWizard.java
String reason_to_fail = resultData.getString(ProviderAPI.ERRORS);
- showDownloadFailedDialog(getCurrentFocus(), reason_to_fail); + showDownloadFailedDialog(getCurrentFocus(), reason_to_fail);
+=======
+ refreshProviderList(0);
+ mProgressBar.setVisibility(ProgressBar.GONE);
+>>>>>>> ed8ca1d... Added a progressbar to ConfigurationWizard.:src/se/leap/leapclient/ConfigurationWizard.java
setResult(RESULT_CANCELED, mConfigState);
}
else if(resultCode == ProviderAPI.CORRECTLY_DOWNLOADED_CERTIFICATE) {
- mProgressDialog.dismiss();
+ mProgressBar.incrementProgressBy(1);
+ mProgressBar.setVisibility(ProgressBar.GONE);
+ refreshProviderList(0);
setResult(RESULT_OK);
showProviderDetails(getCurrentFocus());
} else if(resultCode == ProviderAPI.INCORRECTLY_DOWNLOADED_CERTIFICATE) {
- mProgressDialog.dismiss();
+ refreshProviderList(0);
+ mProgressBar.setVisibility(ProgressBar.GONE);
//Toast.makeText(getApplicationContext(), R.string.incorrectly_downloaded_certificate_message, Toast.LENGTH_LONG).show();
setResult(RESULT_CANCELED, mConfigState);
}
}
+
+ private void startProgressBar() {
+ FragmentManager fragmentManager = getFragmentManager();
+ fragmentManager.findFragmentByTag(getResources().getString(R.string.provider_list_fragment_tag)).getView().setPadding(8, 30, 8, 0);
+ mProgressBar.setVisibility(ProgressBar.VISIBLE);
+ mProgressBar.setProgress(0);
+ mProgressBar.setMax(3);
+ }
/**
* Callback method from {@link ProviderListFragment.Callbacks}
@@ -168,7 +198,7 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn public void onItemSelected(String id) {
//TODO Code 2 pane view
ProviderItem selected_provider = getProvider(id);
- mProgressDialog = ProgressDialog.show(this, getResources().getString(R.string.config_wait_title), getResources().getString(R.string.config_connecting_provider), true);
+ startProgressBar();
mSelectedProvider = selected_provider;
saveProviderJson(mSelectedProvider);
}
@@ -252,8 +282,8 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn ConfigHelper.saveSharedPref(Provider.KEY, provider_json);
ConfigHelper.saveSharedPref(EIP.ALLOWED_ANON, provider_json.getJSONObject(Provider.SERVICE).getBoolean(EIP.ALLOWED_ANON));
ConfigHelper.saveSharedPref(ProviderItem.DANGER_ON, provider.danger_on);
-
- mProgressDialog.setMessage(getResources().getString(R.string.config_downloading_services));
+
+ mProgressBar.incrementProgressBy(1);
downloadJSONFiles(mSelectedProvider);
}
} catch (JSONException e) {
diff --git a/src/se/leap/bitmaskclient/ProviderListFragment.java b/src/se/leap/bitmaskclient/ProviderListFragment.java index 82c4bdc8..05cd4b78 100644 --- a/src/se/leap/bitmaskclient/ProviderListFragment.java +++ b/src/se/leap/bitmaskclient/ProviderListFragment.java @@ -90,7 +90,7 @@ public class ProviderListFragment extends ListFragment { @Override
public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
+ super.onCreate(savedInstanceState);
content_adapter = new ArrayAdapter<ProviderListContent.ProviderItem>(
getActivity(),
android.R.layout.simple_list_item_activated_2,
@@ -128,6 +128,12 @@ public class ProviderListFragment extends ListFragment { && savedInstanceState.containsKey(STATE_ACTIVATED_POSITION)) {
setActivatedPosition(savedInstanceState.getInt(STATE_ACTIVATED_POSITION));
}
+ String top_padding_key = getResources().getString(R.string.top_padding);
+ if(getArguments() != null && getArguments().containsKey(top_padding_key)) {
+ int topPadding = getArguments().getInt(top_padding_key);
+ View current_view = getView();
+ getView().setPadding(current_view.getPaddingLeft(), topPadding, current_view.getPaddingRight(), current_view.getPaddingBottom());
+ }
}
@Override
|