summaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
authorParménides GV <parmegv@sdf.org>2014-12-03 17:46:02 +0100
committerParménides GV <parmegv@sdf.org>2014-12-03 20:43:39 +0100
commit63a16b8c4e6d67910000b78c7f4a2a5709d498ac (patch)
tree97a0ae4f7b82a9507e090c34fce113d475b7d60a /app/src
parentb4d6003265e49e537ec3fae16740de7885864520 (diff)
First orientation change doesn't crash.
Update gradle to 2.2.1.
Diffstat (limited to 'app/src')
-rw-r--r--app/src/debug/java/se/leap/bitmaskclient/ConfigurationWizard.java139
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/Dashboard.java3
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/FragmentManagerEnhanced.java4
-rw-r--r--app/src/release/java/se/leap/bitmaskclient/ConfigurationWizard.java106
4 files changed, 157 insertions, 95 deletions
diff --git a/app/src/debug/java/se/leap/bitmaskclient/ConfigurationWizard.java b/app/src/debug/java/se/leap/bitmaskclient/ConfigurationWizard.java
index 38084493..e28f758d 100644
--- a/app/src/debug/java/se/leap/bitmaskclient/ConfigurationWizard.java
+++ b/app/src/debug/java/se/leap/bitmaskclient/ConfigurationWizard.java
@@ -18,9 +18,7 @@ package se.leap.bitmaskclient;
import android.app.*;
import android.content.*;
-import android.content.res.AssetManager;
import android.os.*;
-import android.util.Log;
import android.view.*;
import android.widget.*;
import java.io.*;
@@ -33,9 +31,7 @@ import se.leap.bitmaskclient.NewProviderDialog.NewProviderDialogInterface;
import se.leap.bitmaskclient.ProviderAPIResultReceiver.Receiver;
import se.leap.bitmaskclient.ProviderDetailFragment.ProviderDetailFragmentInterface;
import se.leap.bitmaskclient.ProviderListContent.ProviderItem;
-import se.leap.bitmaskclient.FragmentManagerEnhanced;
import se.leap.bitmaskclient.eip.Constants;
-import se.leap.bitmaskclient.R;
/**
* Activity that builds and shows the list of known available providers.
@@ -52,6 +48,7 @@ implements ProviderListFragment.Callbacks, NewProviderDialogInterface, ProviderD
private TextView progressbar_description;
private ProviderListFragment provider_list_fragment;
private Intent mConfigState = new Intent();
+ private ProviderItem selected_provider;
final public static String TAG = ConfigurationWizard.class.getSimpleName();
final public static String TYPE_OF_CERTIFICATE = "type_of_certificate";
@@ -61,6 +58,9 @@ implements ProviderListFragment.Callbacks, NewProviderDialogInterface, ProviderD
final protected static String PROVIDER_SET = "PROVIDER SET";
final protected static String SERVICES_RETRIEVED = "SERVICES RETRIEVED";
final protected static String ASSETS_URL_FOLDER = "urls";
+
+ final private static String PROGRESSBAR_TEXT = TAG + "PROGRESSBAR_TEXT";
+ final private static String PROGRESSBAR_NUMBER = TAG + "PROGRESSBAR_NUMBER";
public ProviderAPIResultReceiver providerAPI_result_receiver;
private ProviderAPIBroadcastReceiver_Update providerAPI_broadcast_receiver_update;
@@ -68,32 +68,61 @@ implements ProviderListFragment.Callbacks, NewProviderDialogInterface, ProviderD
private static SharedPreferences preferences;
FragmentManagerEnhanced fragment_manager;
private static boolean setting_up_provider = false;
-
+ private String progressbar_text = "";
+ private String provider_name = "";
+ private int progress = -1;
+
+ @Override
+ protected void onSaveInstanceState(Bundle outState) {
+ if(mProgressBar != null)
+ outState.putInt(PROGRESSBAR_NUMBER, mProgressBar.getProgress());
+ if(progressbar_description != null)
+ outState.putString(PROGRESSBAR_TEXT, progressbar_description.getText().toString());
+ if(selected_provider != null)
+ outState.putString(Provider.NAME, selected_provider.name());
+ outState.putParcelable(ProviderAPI.RECEIVER_KEY, providerAPI_result_receiver);
+ super.onSaveInstanceState(outState);
+ }
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- preferences = getSharedPreferences(Dashboard.SHARED_PREFERENCES, MODE_PRIVATE);
- fragment_manager = new FragmentManagerEnhanced(getFragmentManager());
+ preferences = getSharedPreferences(Dashboard.SHARED_PREFERENCES, MODE_PRIVATE);
+ fragment_manager = new FragmentManagerEnhanced(getFragmentManager());
+
+ setUpInitialUI();
- setUpInitialUI();
+ loadPreseededProviders();
- loadPreseededProviders();
+ setUpProviderAPIResultReceiver();
- setUpProviderAPIResultReceiver();
-
- // Only create our fragments if we're not restoring a saved instance
- if ( savedInstanceState == null ){
- // TODO Some welcome screen?
- // We will need better flow control when we have more Fragments (e.g. user auth)
- setUpProviderList();
+ setUpProviderList();
+
+ if(savedInstanceState != null) {
+ progressbar_text = savedInstanceState.getString(PROGRESSBAR_TEXT, "");
+ provider_name = savedInstanceState.getString(Provider.NAME, "");
+ progress = savedInstanceState.getInt(PROGRESSBAR_NUMBER, -1);
+ providerAPI_result_receiver = savedInstanceState.getParcelable(ProviderAPI.RECEIVER_KEY);
+ providerAPI_result_receiver.setReceiver(this);
}
+ }
- // TODO: If exposing deep links into your app, handle intents here.
+ @Override
+ protected void onPostResume() {
+ super.onPostResume();
+ if(!progressbar_text.isEmpty() && !provider_name.isEmpty() && progress != -1) {
+ progressbar_description.setText(progressbar_text);
+ onItemSelectedUi(getProvider(provider_name));
+ mProgressBar.setProgress(progress);
+
+ progressbar_text = "";
+ provider_name = "";
+ progress = -1;
+ }
}
private void setUpInitialUI() {
- setContentView(R.layout.configuration_wizard_activity);
-
+ setContentView(R.layout.configuration_wizard_activity);
hideProgressBar();
}
@@ -119,15 +148,15 @@ implements ProviderListFragment.Callbacks, NewProviderDialogInterface, ProviderD
}
private void putProviderListFragment(ProviderListFragment fragment) {
-
fragment_manager.replace(R.id.configuration_wizard_layout, provider_list_fragment, ProviderListFragment.TAG);
}
- @Override
- protected void onDestroy() {
- super.onDestroy();
- unregisterReceiver(providerAPI_broadcast_receiver_update);
- }
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ if(providerAPI_broadcast_receiver_update != null)
+ unregisterReceiver(providerAPI_broadcast_receiver_update);
+ }
private void setUpProviderAPIResultReceiver() {
providerAPI_result_receiver = new ProviderAPIResultReceiver(new Handler());
@@ -153,12 +182,12 @@ implements ProviderListFragment.Callbacks, NewProviderDialogInterface, ProviderD
hideProgressBar();
setResult(RESULT_OK);
-
+
showProviderDetails();
}
} else if(resultCode == ProviderAPI.PROVIDER_NOK) {
hideProgressBar();
- preferences.edit().remove(Provider.KEY).commit();
+ preferences.edit().remove(Provider.KEY).apply();
setting_up_provider = false;
setResult(RESULT_CANCELED, mConfigState);
@@ -169,10 +198,10 @@ implements ProviderListFragment.Callbacks, NewProviderDialogInterface, ProviderD
else if(resultCode == ProviderAPI.CORRECTLY_DOWNLOADED_CERTIFICATE) {
mProgressBar.incrementProgressBy(1);
hideProgressBar();
-
- setResult(RESULT_OK);
-
+
showProviderDetails();
+
+ setResult(RESULT_OK);
} else if(resultCode == ProviderAPI.INCORRECTLY_DOWNLOADED_CERTIFICATE) {
hideProgressBar();
@@ -190,17 +219,20 @@ implements ProviderListFragment.Callbacks, NewProviderDialogInterface, ProviderD
@Override
public void onItemSelected(String id) {
//TODO Code 2 pane view
- ProviderItem selected_provider = getProvider(id);
- int provider_index = getProviderIndex(id);
-
- startProgressBar(provider_index+1);
- provider_list_fragment.hideAllBut(provider_index);
+ selected_provider = getProvider(id);
+ onItemSelectedUi(selected_provider);
boolean danger_on = true;
if(preferences.contains(ProviderItem.DANGER_ON))
danger_on = preferences.getBoolean(ProviderItem.DANGER_ON, false);
setUpProvider(selected_provider.providerMainUrl(), danger_on);
}
+
+ private void onItemSelectedUi(ProviderItem provider) {
+ startProgressBar();
+ int provider_index = getProviderIndex(provider.name());
+ provider_list_fragment.hideAllBut(provider_index);
+ }
@Override
public void onBackPressed() {
@@ -216,7 +248,8 @@ implements ProviderListFragment.Callbacks, NewProviderDialogInterface, ProviderD
mProgressBar.setVisibility(ProgressBar.GONE);
mProgressBar.setProgress(0);
progressbar_description.setVisibility(TextView.GONE);
- preferences.edit().remove(Provider.KEY).commit();
+
+ preferences.edit().remove(Provider.KEY).apply();
setting_up_provider = false;
showAllProviders();
}
@@ -254,19 +287,16 @@ implements ProviderListFragment.Callbacks, NewProviderDialogInterface, ProviderD
return null;
}
- private void startProgressBar() {
- mProgressBar.setVisibility(ProgressBar.VISIBLE);
- progressbar_description.setVisibility(TextView.VISIBLE);
- mProgressBar.setProgress(0);
- mProgressBar.setMax(3);
- }
-
- private void startProgressBar(int list_item_index) {
- startProgressBar();
- int measured_height = listItemHeight(list_item_index);
- mProgressBar.setTranslationY(measured_height);
- progressbar_description.setTranslationY(measured_height + mProgressBar.getHeight());
- }
+ private void startProgressBar() {
+ mProgressBar.setVisibility(ProgressBar.VISIBLE);
+ progressbar_description.setVisibility(TextView.VISIBLE);
+ mProgressBar.setProgress(0);
+ mProgressBar.setMax(3);
+
+ int measured_height = listItemHeight();
+ mProgressBar.setTranslationY(measured_height);
+ progressbar_description.setTranslationY(measured_height + mProgressBar.getHeight());
+ }
private int getProviderIndex(String id) {
int index = 0;
@@ -280,7 +310,7 @@ implements ProviderListFragment.Callbacks, NewProviderDialogInterface, ProviderD
return index;
}
- private int listItemHeight(int list_item_index) {
+ private int listItemHeight() {
ListView provider_list_view = (ListView)findViewById(android.R.id.list);
ListAdapter provider_list_adapter = provider_list_view.getAdapter();
View listItem = provider_list_adapter.getView(0, null, provider_list_view);
@@ -433,7 +463,7 @@ implements ProviderListFragment.Callbacks, NewProviderDialogInterface, ProviderD
DialogFragment newFragment = DownloadFailedDialog.newInstance(reason_to_fail);
newFragment.show(fragment_transaction, DownloadFailedDialog.TAG);
}
-
+
/**
* Once selected a provider, this fragment offers the user to log in,
* use it anonymously (if possible)
@@ -450,11 +480,11 @@ implements ProviderListFragment.Callbacks, NewProviderDialogInterface, ProviderD
public void showAndSelectProvider(String provider_main_url, boolean danger_on) {
if(getId(provider_main_url).isEmpty())
- showProvider(provider_main_url, danger_on);
+ showProvider(provider_main_url);
autoSelectProvider(provider_main_url, danger_on);
}
- private void showProvider(final String provider_main_url, final boolean danger_on) {
+ private void showProvider(final String provider_main_url) {
String provider_name = provider_main_url.replaceFirst("http[s]?://", "").replaceFirst("\\/", "_");
ProviderItem added_provider = new ProviderItem(provider_name, provider_main_url);
provider_list_fragment.addItem(added_provider);
@@ -467,8 +497,7 @@ implements ProviderListFragment.Callbacks, NewProviderDialogInterface, ProviderD
/**
* Asks ProviderAPI to download a new provider.json file
- * @param provider_name
- * @param provider_main_url
+n * @param provider_main_url
* @param danger_on tells if HTTPS client should bypass certificate errors
*/
public void setUpProvider(String provider_main_url, boolean danger_on) {
diff --git a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
index 8143d8d6..94de2fe8 100644
--- a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
+++ b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
@@ -86,7 +86,6 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
preferences = getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE);
fragment_manager = new FragmentManagerEnhanced(getFragmentManager());
handleVersion();
-
boolean provider_configured = preferences.getString(Constants.KEY, "").isEmpty();
if (provider_configured)
startActivityForResult(new Intent(this,ConfigurationWizard.class),CONFIGURE_LEAP);
@@ -136,7 +135,6 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
preferences.edit().putInt(Constants.PARSED_SERIAL, 0).apply();
preferences.edit().putBoolean(Constants.AUTHED_EIP, authed_eip).apply();
updateEipService();
- buildDashboard(false);
invalidateOptionsMenu();
if(data != null && data.hasExtra(LogInDialog.TAG)) {
logInDialog(Bundle.EMPTY);
@@ -205,7 +203,6 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
eip_fragment.setArguments(arguments);
}
- fragment_manager.removePreviousFragment(EipServiceFragment.TAG);
fragment_manager.replace(R.id.servicesCollection, eip_fragment, EipServiceFragment.TAG);
if (hide_and_turn_on_eip) {
diff --git a/app/src/main/java/se/leap/bitmaskclient/FragmentManagerEnhanced.java b/app/src/main/java/se/leap/bitmaskclient/FragmentManagerEnhanced.java
index c4844be9..49af9274 100644
--- a/app/src/main/java/se/leap/bitmaskclient/FragmentManagerEnhanced.java
+++ b/app/src/main/java/se/leap/bitmaskclient/FragmentManagerEnhanced.java
@@ -45,6 +45,10 @@ public class FragmentManagerEnhanced {
transaction.replace(containerViewId, fragment, tag).commit();
}
+ public FragmentTransaction beginTransaction() {
+ return generic_fragment_manager.beginTransaction();
+ }
+
public Fragment findFragmentByTag(String tag) {
return generic_fragment_manager.findFragmentByTag(tag);
}
diff --git a/app/src/release/java/se/leap/bitmaskclient/ConfigurationWizard.java b/app/src/release/java/se/leap/bitmaskclient/ConfigurationWizard.java
index d3203ab3..a25f49f1 100644
--- a/app/src/release/java/se/leap/bitmaskclient/ConfigurationWizard.java
+++ b/app/src/release/java/se/leap/bitmaskclient/ConfigurationWizard.java
@@ -18,9 +18,7 @@ package se.leap.bitmaskclient;
import android.app.*;
import android.content.*;
-import android.content.res.AssetManager;
import android.os.*;
-import android.util.Log;
import android.view.*;
import android.widget.*;
import java.io.*;
@@ -52,6 +50,7 @@ implements ProviderListFragment.Callbacks, NewProviderDialogInterface, ProviderD
private TextView progressbar_description;
private ProviderListFragment provider_list_fragment;
private Intent mConfigState = new Intent();
+ private ProviderItem selected_provider;
final public static String TAG = ConfigurationWizard.class.getSimpleName();
final public static String TYPE_OF_CERTIFICATE = "type_of_certificate";
@@ -61,6 +60,9 @@ implements ProviderListFragment.Callbacks, NewProviderDialogInterface, ProviderD
final protected static String PROVIDER_SET = "PROVIDER SET";
final protected static String SERVICES_RETRIEVED = "SERVICES RETRIEVED";
final protected static String ASSETS_URL_FOLDER = "urls";
+
+ final private static String PROGRESSBAR_TEXT = TAG + "PROGRESSBAR_TEXT";
+ final private static String PROGRESSBAR_NUMBER = TAG + "PROGRESSBAR_NUMBER";
public ProviderAPIResultReceiver providerAPI_result_receiver;
private ProviderAPIBroadcastReceiver_Update providerAPI_broadcast_receiver_update;
@@ -68,6 +70,21 @@ implements ProviderListFragment.Callbacks, NewProviderDialogInterface, ProviderD
private static SharedPreferences preferences;
FragmentManagerEnhanced fragment_manager;
private static boolean setting_up_provider = false;
+ private String progressbar_text = "";
+ private String provider_name = "";
+ private int progress = -1;
+
+ @Override
+ protected void onSaveInstanceState(Bundle outState) {
+ if(mProgressBar != null)
+ outState.putInt(PROGRESSBAR_NUMBER, mProgressBar.getProgress());
+ if(progressbar_description != null)
+ outState.putString(PROGRESSBAR_TEXT, progressbar_description.getText().toString());
+ if(selected_provider != null)
+ outState.putString(Provider.NAME, selected_provider.name());
+ outState.putParcelable(ProviderAPI.RECEIVER_KEY, providerAPI_result_receiver);
+ super.onSaveInstanceState(outState);
+ }
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -80,16 +97,31 @@ implements ProviderListFragment.Callbacks, NewProviderDialogInterface, ProviderD
loadPreseededProviders();
setUpProviderAPIResultReceiver();
-
- // Only create our fragments if we're not restoring a saved instance
- if ( savedInstanceState == null ) {
- // TODO Some welcome screen?
- // We will need better flow control when we have more Fragments (e.g. user auth)
- setUpProviderList();
+
+ setUpProviderList();
+
+ if ( savedInstanceState != null ) {
+ progressbar_text = savedInstanceState.getString(PROGRESSBAR_TEXT, "");
+ provider_name = savedInstanceState.getString(Provider.NAME, "");
+ progress = savedInstanceState.getInt(PROGRESSBAR_NUMBER, -1);
+ providerAPI_result_receiver = savedInstanceState.getParcelable(ProviderAPI.RECEIVER_KEY);
+ providerAPI_result_receiver.setReceiver(this);
}
+ }
- // TODO: If exposing deep links into your app, handle intents here.
- }
+ @Override
+ protected void onPostResume() {
+ super.onPostResume();
+ if(!progressbar_text.isEmpty() && !provider_name.isEmpty() && progress != -1) {
+ progressbar_description.setText(progressbar_text);
+ onItemSelectedUi(getProvider(provider_name));
+ mProgressBar.setProgress(progress);
+
+ progressbar_text = "";
+ provider_name = "";
+ progress = -1;
+ }
+ }
private void setUpInitialUI() {
setContentView(R.layout.configuration_wizard_activity);
@@ -122,11 +154,11 @@ implements ProviderListFragment.Callbacks, NewProviderDialogInterface, ProviderD
fragment_manager.replace(R.id.configuration_wizard_layout, provider_list_fragment, ProviderListFragment.TAG);
}
- @Override
- protected void onDestroy() {
- super.onDestroy();
- unregisterReceiver(providerAPI_broadcast_receiver_update);
- }
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ unregisterReceiver(providerAPI_broadcast_receiver_update);
+ }
private void setUpProviderAPIResultReceiver() {
providerAPI_result_receiver = new ProviderAPIResultReceiver(new Handler());
@@ -169,9 +201,9 @@ implements ProviderListFragment.Callbacks, NewProviderDialogInterface, ProviderD
mProgressBar.incrementProgressBy(1);
hideProgressBar();
- setResult(RESULT_OK);
-
showProviderDetails();
+
+ setResult(RESULT_OK);
} else if(resultCode == ProviderAPI.INCORRECTLY_DOWNLOADED_CERTIFICATE) {
hideProgressBar();
@@ -189,14 +221,16 @@ implements ProviderListFragment.Callbacks, NewProviderDialogInterface, ProviderD
@Override
public void onItemSelected(String id) {
//TODO Code 2 pane view
- ProviderItem selected_provider = getProvider(id);
- int provider_index = getProviderIndex(id);
-
- startProgressBar(provider_index+1);
- provider_list_fragment.hideAllBut(provider_index);
-
+ selected_provider = getProvider(id);
+ onItemSelectedUi(selected_provider);
setUpProvider(selected_provider.providerMainUrl());
}
+
+ private void onItemSelectedUi(ProviderItem provider) {
+ startProgressBar();
+ int provider_index = getProviderIndex(provider.name());
+ provider_list_fragment.hideAllBut(provider_index);
+ }
@Override
public void onBackPressed() {
@@ -212,6 +246,7 @@ implements ProviderListFragment.Callbacks, NewProviderDialogInterface, ProviderD
mProgressBar.setVisibility(ProgressBar.GONE);
mProgressBar.setProgress(0);
progressbar_description.setVisibility(TextView.GONE);
+
preferences.edit().remove(Provider.KEY).commit();
setting_up_provider = false;
showAllProviders();
@@ -250,19 +285,16 @@ implements ProviderListFragment.Callbacks, NewProviderDialogInterface, ProviderD
return null;
}
- private void startProgressBar() {
- mProgressBar.setVisibility(ProgressBar.VISIBLE);
- progressbar_description.setVisibility(TextView.VISIBLE);
- mProgressBar.setProgress(0);
- mProgressBar.setMax(3);
- }
-
- private void startProgressBar(int list_item_index) {
- startProgressBar();
- int measured_height = listItemHeight(list_item_index);
- mProgressBar.setTranslationY(measured_height);
- progressbar_description.setTranslationY(measured_height + mProgressBar.getHeight());
- }
+ private void startProgressBar() {
+ mProgressBar.setVisibility(ProgressBar.VISIBLE);
+ progressbar_description.setVisibility(TextView.VISIBLE);
+ mProgressBar.setProgress(0);
+ mProgressBar.setMax(3);
+
+ int measured_height = listItemHeight();
+ mProgressBar.setTranslationY(measured_height);
+ progressbar_description.setTranslationY(measured_height + mProgressBar.getHeight());
+ }
private int getProviderIndex(String id) {
int index = 0;
@@ -276,7 +308,7 @@ implements ProviderListFragment.Callbacks, NewProviderDialogInterface, ProviderD
return index;
}
- private int listItemHeight(int list_item_index) {
+ private int listItemHeight() {
ListView provider_list_view = (ListView)findViewById(android.R.id.list);
ListAdapter provider_list_adapter = provider_list_view.getAdapter();
View listItem = provider_list_adapter.getView(0, null, provider_list_view);