summaryrefslogtreecommitdiff
path: root/app/src/main/java/se/leap
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/se/leap')
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java10
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/Dashboard.java16
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/DownloadFailedDialog.java9
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/FragmentManagerEnhanced.java4
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/MainActivity.java46
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/NavigationDrawerFragment.java4
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/VpnFragment.java22
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/userstatus/SessionDialog.java21
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatusFragment.java5
9 files changed, 89 insertions, 48 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java b/app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java
index 52c8f8e5..75a653c0 100644
--- a/app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java
+++ b/app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java
@@ -17,9 +17,6 @@
package se.leap.bitmaskclient;
-import android.app.Activity;
-import android.app.DialogFragment;
-import android.app.FragmentTransaction;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@@ -27,6 +24,9 @@ import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
+import android.support.v4.app.DialogFragment;
+import android.support.v4.app.FragmentTransaction;
+import android.support.v7.app.AppCompatActivity;
import android.view.Display;
import android.view.Menu;
import android.view.MenuItem;
@@ -68,7 +68,7 @@ import static android.view.View.VISIBLE;
* @author cyberta
*/
-public abstract class BaseConfigurationWizard extends Activity
+public abstract class BaseConfigurationWizard extends AppCompatActivity
implements NewProviderDialog.NewProviderDialogInterface, ProviderDetailFragment.ProviderDetailFragmentInterface, DownloadFailedDialog.DownloadFailedDialogInterface, ProviderAPIResultReceiver.Receiver {
@InjectView(R.id.progressbar_configuration_wizard)
protected ProgressBar mProgressBar;
@@ -134,7 +134,7 @@ public abstract class BaseConfigurationWizard extends Activity
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
preferences = getSharedPreferences(Constants.SHARED_PREFERENCES, MODE_PRIVATE);
- fragment_manager = new FragmentManagerEnhanced(getFragmentManager());
+ fragment_manager = new FragmentManagerEnhanced(getSupportFragmentManager());
provider_manager = ProviderManager.getInstance(getAssets(), getExternalFilesDir(null));
setUpInitialUI();
diff --git a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
index 1eed484c..0d3af13f 100644
--- a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
+++ b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
@@ -17,15 +17,15 @@
package se.leap.bitmaskclient;
import android.annotation.SuppressLint;
-import android.app.Activity;
import android.app.AlertDialog;
-import android.app.FragmentTransaction;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.os.Handler;
+import android.support.v4.app.FragmentTransaction;
+import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
@@ -56,7 +56,7 @@ import static se.leap.bitmaskclient.Constants.REQUEST_CODE_SWITCH_PROVIDER;
* @author Sean Leonard <meanderingcode@aetherislands.net>
* @author parmegv
*/
-public class Dashboard extends Activity {
+public class Dashboard extends AppCompatActivity {
public static final String TAG = Dashboard.class.getSimpleName();
@@ -91,7 +91,7 @@ public class Dashboard extends Activity {
super.onCreate(savedInstanceState);
dashboardReceiver = new DashboardReceiver(this);
preferences = getSharedPreferences(Constants.SHARED_PREFERENCES, MODE_PRIVATE);
- fragment_manager = new FragmentManagerEnhanced(getFragmentManager());
+ fragment_manager = new FragmentManagerEnhanced(getSupportFragmentManager());
providerAPI_result_receiver = new ProviderAPIResultReceiver(new Handler(), dashboardReceiver);
@@ -305,7 +305,7 @@ public class Dashboard extends Activity {
* has caused to start Dashboard
* @return the created VPNFragment
*/
- private VpnFragment prepareEipFragment(boolean hideAndTurnOnEipOnBoot) {
+ public static VpnFragment prepareEipFragment(boolean hideAndTurnOnEipOnBoot) {
VpnFragment eip_fragment = new VpnFragment();
if (hideAndTurnOnEipOnBoot && !isAlwaysOn()) {
@@ -323,7 +323,7 @@ public class Dashboard extends Activity {
* checks if Android's VPN feature 'always-on' is enabled for Bitmask
* @return true if 'always-on' is enabled false if not
*/
- private boolean isAlwaysOn() {
+ private static boolean isAlwaysOn() {
return preferences.getBoolean(EIP_IS_ALWAYS_ON, false);
}
@@ -418,11 +418,11 @@ public class Dashboard extends Activity {
String password = resultData.getString(SessionDialog.PASSWORD);
dashboard.user_status_fragment.logIn(username, password);
} else if (resultCode == ProviderAPI.FAILED_SIGNUP) {
- Dashboard.sessionDialog(resultData);
+ MainActivity.sessionDialog(resultData);
} else if (resultCode == ProviderAPI.SUCCESSFUL_LOGIN) {
Dashboard.downloadVpnCertificate();
} else if (resultCode == ProviderAPI.FAILED_LOGIN) {
- Dashboard.sessionDialog(resultData);
+ MainActivity.sessionDialog(resultData);
} else if (resultCode == ProviderAPI.SUCCESSFUL_LOGOUT) {
if (switching_provider) dashboard.switchProvider();
} else if (resultCode == ProviderAPI.LOGOUT_FAILED) {
diff --git a/app/src/main/java/se/leap/bitmaskclient/DownloadFailedDialog.java b/app/src/main/java/se/leap/bitmaskclient/DownloadFailedDialog.java
index da32dbd4..d6d89b58 100644
--- a/app/src/main/java/se/leap/bitmaskclient/DownloadFailedDialog.java
+++ b/app/src/main/java/se/leap/bitmaskclient/DownloadFailedDialog.java
@@ -16,9 +16,12 @@
*/
package se.leap.bitmaskclient;
-import android.app.*;
-import android.content.*;
-import android.os.*;
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.content.DialogInterface;
+import android.os.Bundle;
+import android.support.v4.app.DialogFragment;
/**
* Implements a dialog to show why a download failed.
diff --git a/app/src/main/java/se/leap/bitmaskclient/FragmentManagerEnhanced.java b/app/src/main/java/se/leap/bitmaskclient/FragmentManagerEnhanced.java
index 8ba7fa34..9594cea0 100644
--- a/app/src/main/java/se/leap/bitmaskclient/FragmentManagerEnhanced.java
+++ b/app/src/main/java/se/leap/bitmaskclient/FragmentManagerEnhanced.java
@@ -16,7 +16,9 @@
*/
package se.leap.bitmaskclient;
-import android.app.*;
+import android.support.v4.app.Fragment;
+import android.support.v4.app.FragmentManager;
+import android.support.v4.app.FragmentTransaction;
public class FragmentManagerEnhanced {
diff --git a/app/src/main/java/se/leap/bitmaskclient/MainActivity.java b/app/src/main/java/se/leap/bitmaskclient/MainActivity.java
index 8cd6357c..2f07f162 100644
--- a/app/src/main/java/se/leap/bitmaskclient/MainActivity.java
+++ b/app/src/main/java/se/leap/bitmaskclient/MainActivity.java
@@ -2,9 +2,12 @@ package se.leap.bitmaskclient;
import android.content.Context;
+import android.content.Intent;
+import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
+import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
@@ -14,11 +17,17 @@ import android.view.ViewGroup;
import android.support.v4.widget.DrawerLayout;
import se.leap.bitmaskclient.fragments.LogFragment;
+import se.leap.bitmaskclient.userstatus.SessionDialog;
public class MainActivity extends AppCompatActivity
implements NavigationDrawerFragment.NavigationDrawerCallbacks {
+ private static Provider provider = new Provider();
+ private static FragmentManagerEnhanced fragmentManager;
+ private SharedPreferences preferences;
+
+
/**
* Fragment managing the behaviors, interactions and presentation of the navigation drawer.
*/
@@ -40,42 +49,52 @@ public class MainActivity extends AppCompatActivity
getSupportFragmentManager().findFragmentById(R.id.navigation_drawer);
mTitle = getTitle();
+ fragmentManager = new FragmentManagerEnhanced(getSupportFragmentManager());
+ preferences = getSharedPreferences(Constants.SHARED_PREFERENCES, MODE_PRIVATE);
// Set up the drawer.
mNavigationDrawerFragment.setUp(
R.id.navigation_drawer,
(DrawerLayout) findViewById(R.id.drawer_layout));
+
}
@Override
public void onNavigationDrawerItemSelected(int position) {
// update the main content by replacing fragments
FragmentManager fragmentManager = getSupportFragmentManager();
- Fragment fragment;
+ Fragment fragment = null;
switch (position) {
case 1:
+ // TODO STOP VPN
+ // if (provider.hasEIP()) eip_fragment.stopEipIfPossible();
+ preferences.edit().clear().apply();
+ startActivityForResult(new Intent(this, ConfigurationWizard.class), Constants.REQUEST_CODE_SWITCH_PROVIDER);
+ break;
case 2:
- fragment = PlaceholderFragment.newInstance();
+ fragment = new LogFragment();
break;
default:
- fragment = new LogFragment();
+ fragment = new VpnFragment();
break;
}
- fragmentManager.beginTransaction()
- .replace(R.id.container, fragment)
- .commit();
+ if (fragment != null) {
+ fragmentManager.beginTransaction()
+ .replace(R.id.container, fragment)
+ .commit();
+ }
onSectionAttached(position);
}
public void onSectionAttached(int number) {
switch (number) {
case 1:
- mTitle = getString(R.string.title_section2);
+ mTitle = getString(R.string.switch_provider_menu_option);
break;
case 2:
- mTitle = getString(R.string.title_section3);
+ mTitle = getString(R.string.log_fragment_title);
break;
default:
- mTitle = getString(R.string.log_fragment_title);
+ mTitle = getString(R.string.vpn_fragment_title);
break;
}
restoreActionBar();
@@ -118,4 +137,13 @@ public class MainActivity extends AppCompatActivity
}
}
+ public static void sessionDialog(Bundle resultData) {
+ try {
+ FragmentTransaction transaction = fragmentManager.removePreviousFragment(SessionDialog.TAG);
+ SessionDialog.getInstance(provider, resultData).show(transaction, SessionDialog.TAG);
+ } catch (IllegalStateException e) {
+ e.printStackTrace();
+ }
+ }
+
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/NavigationDrawerFragment.java b/app/src/main/java/se/leap/bitmaskclient/NavigationDrawerFragment.java
index bb0d8f46..b8a9e5b1 100644
--- a/app/src/main/java/se/leap/bitmaskclient/NavigationDrawerFragment.java
+++ b/app/src/main/java/se/leap/bitmaskclient/NavigationDrawerFragment.java
@@ -123,9 +123,9 @@ public class NavigationDrawerFragment extends Fragment {
android.R.layout.simple_list_item_activated_1,
android.R.id.text1,
new String[]{
+ getString(R.string.vpn_fragment_title),
+ getString(R.string.switch_provider_menu_option),
getString(R.string.log_fragment_title),
- getString(R.string.title_section2),
- getString(R.string.title_section3),
}));
mDrawerListView.setItemChecked(mCurrentSelectedPosition, true);
mFragmentContainerView = activity.findViewById(fragmentId);
diff --git a/app/src/main/java/se/leap/bitmaskclient/VpnFragment.java b/app/src/main/java/se/leap/bitmaskclient/VpnFragment.java
index 2b968769..e16ab75c 100644
--- a/app/src/main/java/se/leap/bitmaskclient/VpnFragment.java
+++ b/app/src/main/java/se/leap/bitmaskclient/VpnFragment.java
@@ -18,7 +18,6 @@ package se.leap.bitmaskclient;
import android.app.Activity;
import android.app.AlertDialog;
-import android.app.Fragment;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
@@ -30,6 +29,7 @@ import android.os.Handler;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.ResultReceiver;
+import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
@@ -127,7 +127,6 @@ public class VpnFragment extends Fragment implements Observer {
if (arguments != null && arguments.containsKey(START_EIP_ON_BOOT) && arguments.getBoolean(START_EIP_ON_BOOT)) {
startEipFromScratch();
}
-
return view;
}
@@ -170,7 +169,7 @@ public class VpnFragment extends Fragment implements Observer {
else if (canLogInToStartEIP()) {
wants_to_connect = true;
Bundle bundle = new Bundle();
- Dashboard.sessionDialog(bundle);
+ MainActivity.sessionDialog(bundle);
} else {
Log.d(TAG, "WHAT IS GOING ON HERE?!");
// TODO: implement a fallback: check if vpncertificate was not downloaded properly or give
@@ -305,12 +304,17 @@ public class VpnFragment extends Fragment implements Observer {
public void update(Observable observable, Object data) {
if (observable instanceof EipStatus) {
eip_status = (EipStatus) observable;
- getActivity().runOnUiThread(new Runnable() {
- @Override
- public void run() {
- handleNewState();
- }
- });
+ Activity activity = getActivity();
+ if (activity != null) {
+ getActivity().runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ handleNewState();
+ }
+ });
+ } else {
+ Log.e("VpnFragment", "activity is null");
+ }
}
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/userstatus/SessionDialog.java b/app/src/main/java/se/leap/bitmaskclient/userstatus/SessionDialog.java
index 61349490..440b02fa 100644
--- a/app/src/main/java/se/leap/bitmaskclient/userstatus/SessionDialog.java
+++ b/app/src/main/java/se/leap/bitmaskclient/userstatus/SessionDialog.java
@@ -16,15 +16,18 @@
*/
package se.leap.bitmaskclient.userstatus;
-import android.app.*;
-import android.content.*;
-import android.os.*;
-import android.view.*;
-import android.widget.*;
-
-import butterknife.*;
-import se.leap.bitmaskclient.ProviderAPI;
-import se.leap.bitmaskclient.VpnFragment;
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.content.DialogInterface;
+import android.os.Bundle;
+import android.support.v4.app.DialogFragment;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.EditText;
+import android.widget.TextView;
+
+import butterknife.ButterKnife;
+import butterknife.InjectView;
import se.leap.bitmaskclient.Provider;
import se.leap.bitmaskclient.R;
diff --git a/app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatusFragment.java b/app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatusFragment.java
index f4be3ea1..a991e88e 100644
--- a/app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatusFragment.java
+++ b/app/src/main/java/se/leap/bitmaskclient/userstatus/UserStatusFragment.java
@@ -1,9 +1,9 @@
package se.leap.bitmaskclient.userstatus;
import android.app.Activity;
-import android.app.Fragment;
import android.os.Bundle;
import android.os.Handler;
+import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -19,6 +19,7 @@ import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;
import se.leap.bitmaskclient.Dashboard;
+import se.leap.bitmaskclient.MainActivity;
import se.leap.bitmaskclient.Provider;
import se.leap.bitmaskclient.ProviderAPI;
import se.leap.bitmaskclient.ProviderAPICommand;
@@ -90,7 +91,7 @@ public class UserStatusFragment extends Fragment implements Observer, SessionDia
if(status.isLoggedIn())
logOut();
else if(status.isLoggedOut())
- Dashboard.sessionDialog(Bundle.EMPTY);
+ MainActivity.sessionDialog(Bundle.EMPTY);
else if(status.inProgress())
cancelLoginOrSignup();
}