From c1289a1ef908049b2759d9c644f3b11ed0fcc79c Mon Sep 17 00:00:00 2001 From: Arne Schwabe Date: Wed, 19 Nov 2014 00:03:19 +0100 Subject: Also change VPNPreferences to use sliding layout. --HG-- extra : rebase_source : 9bdc433edcc1edb0d1739fb3e63e6c1b27722840 --- .../de/blinkt/openvpn/activities/MainActivity.java | 80 ++++----------- .../blinkt/openvpn/activities/VPNPreferences.java | 109 ++++++++++++++++----- .../openvpn/fragments/ShowConfigFragment.java | 15 ++- .../openvpn/views/ScreenSlidePagerAdapter.java | 79 +++++++++++++++ main/src/main/res/layout-v21/config_fab.xml | 21 ++++ main/src/main/res/layout-v21/tabs.xml | 4 +- main/src/main/res/layout/allowed_vpn_apps.xml | 8 -- main/src/main/res/layout/basic_settings.xml | 1 + main/src/main/res/layout/config_fab.xml | 9 ++ main/src/main/res/layout/connections.xml | 2 + main/src/main/res/layout/viewconfig.xml | 27 ++--- main/src/main/res/layout/vpn_remote.xml | 82 ---------------- main/src/main/res/values/dimens.xml | 1 + main/src/main/res/values/strings.xml | 2 + 14 files changed, 248 insertions(+), 192 deletions(-) create mode 100644 main/src/main/java/de/blinkt/openvpn/views/ScreenSlidePagerAdapter.java create mode 100644 main/src/main/res/layout-v21/config_fab.xml create mode 100644 main/src/main/res/layout/config_fab.xml delete mode 100644 main/src/main/res/layout/vpn_remote.xml (limited to 'main') diff --git a/main/src/main/java/de/blinkt/openvpn/activities/MainActivity.java b/main/src/main/java/de/blinkt/openvpn/activities/MainActivity.java index d59640de..5e84e93b 100644 --- a/main/src/main/java/de/blinkt/openvpn/activities/MainActivity.java +++ b/main/src/main/java/de/blinkt/openvpn/activities/MainActivity.java @@ -5,23 +5,23 @@ package de.blinkt.openvpn.activities; +import android.annotation.TargetApi; +import android.app.ActionBar; import android.app.Activity; import android.app.Fragment; -import android.app.FragmentManager; import android.content.Intent; +import android.os.Build; import android.support.annotation.StringRes; -import android.support.v4n.app.FragmentStatePagerAdapter; import android.support.v4n.view.ViewPager; -import java.util.Vector; - import de.blinkt.openvpn.R; import de.blinkt.openvpn.fragments.AboutFragment; import de.blinkt.openvpn.fragments.FaqFragment; import de.blinkt.openvpn.fragments.GeneralSettings; +import de.blinkt.openvpn.fragments.LogFragment; import de.blinkt.openvpn.fragments.SendDumpFragment; import de.blinkt.openvpn.fragments.VPNProfileList; -import de.blinkt.openvpn.views.PagerSlidingTabStrip; +import de.blinkt.openvpn.views.ScreenSlidePagerAdapter; import de.blinkt.openvpn.views.SlidingTabLayout; import de.blinkt.openvpn.views.TabBarView; @@ -40,9 +40,12 @@ public class MainActivity extends Activity { // Instantiate a ViewPager and a PagerAdapter. mPager = (ViewPager) findViewById(R.id.pager); - mPagerAdapter = new ScreenSlidePagerAdapter(getFragmentManager()); - + mPagerAdapter = new ScreenSlidePagerAdapter(getFragmentManager(), this); + /* Toolbar and slider should have the same elevation */ + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + disableToolbarElevation(); + } @@ -55,72 +58,23 @@ public class MainActivity extends Activity { mPagerAdapter.addTab(R.string.crashdump, SendDumpFragment.class); } + mPagerAdapter.addTab(R.string.openvpn_log, LogFragment.class); + mPagerAdapter.addTab(R.string.about, AboutFragment.class); mPager.setAdapter(mPagerAdapter); - /*mSlidingTabLayout = (SlidingTabLayout) findViewById(R.id.slding_tabs); - mSlidingTabLayout.setViewPager(mPager); */ - TabBarView tabs = (TabBarView) findViewById(R.id.sliding_tabs); tabs.setViewPager(mPager); - - /* - if (false) { - Tab logtab = bar.newTab().setText("Log"); - logtab.setTabListener(new TabListener("log", LogFragment.class)); - bar.addTab(logtab); - }*/ - - - } - class Tab { - public Class fragmentClass; - String mName; - - public Tab(Class fClass, @StringRes String name){ - mName = name; - fragmentClass = fClass; - } - + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + private void disableToolbarElevation() { + ActionBar toolbar = getActionBar(); + toolbar.setElevation(0); } - private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter { - private Vector mTabs = new Vector(); - - public ScreenSlidePagerAdapter(FragmentManager fm) { - super(fm); - } - - @Override - public Fragment getItem(int position) { - try { - return mTabs.get(position).fragmentClass.newInstance(); - } catch (InstantiationException e) { - e.printStackTrace(); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } - return null; - } - - @Override - public CharSequence getPageTitle(int position) { - return mTabs.get(position).mName; - } - - @Override - public int getCount() { - return mTabs.size(); - } - - public void addTab(@StringRes int name, Class fragmentClass) { - mTabs.add(new Tab(fragmentClass, getString(name))); - } - } - @Override + @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); diff --git a/main/src/main/java/de/blinkt/openvpn/activities/VPNPreferences.java b/main/src/main/java/de/blinkt/openvpn/activities/VPNPreferences.java index 5bff4828..4eee5eea 100644 --- a/main/src/main/java/de/blinkt/openvpn/activities/VPNPreferences.java +++ b/main/src/main/java/de/blinkt/openvpn/activities/VPNPreferences.java @@ -5,23 +5,27 @@ package de.blinkt.openvpn.activities; -import java.util.List; - import android.annotation.TargetApi; +import android.app.ActionBar; +import android.app.Activity; import android.app.AlertDialog; -import android.app.Fragment; import android.content.DialogInterface; import android.content.Intent; import android.os.Build; import android.os.Bundle; import android.preference.PreferenceActivity; -import android.preference.PreferenceFragment; +import android.support.v4n.view.ViewPager; import android.view.Menu; import android.view.MenuItem; import de.blinkt.openvpn.R; import de.blinkt.openvpn.VpnProfile; import de.blinkt.openvpn.core.ProfileManager; +import de.blinkt.openvpn.fragments.AboutFragment; +import de.blinkt.openvpn.fragments.FaqFragment; +import de.blinkt.openvpn.fragments.GeneralSettings; +import de.blinkt.openvpn.fragments.LogFragment; +import de.blinkt.openvpn.fragments.SendDumpFragment; import de.blinkt.openvpn.fragments.Settings_Allowed_Apps; import de.blinkt.openvpn.fragments.Settings_Authentication; import de.blinkt.openvpn.fragments.Settings_Basic; @@ -32,9 +36,11 @@ import de.blinkt.openvpn.fragments.Settings_Obscure; import de.blinkt.openvpn.fragments.Settings_Routing; import de.blinkt.openvpn.fragments.ShowConfigFragment; import de.blinkt.openvpn.fragments.VPNProfileList; +import de.blinkt.openvpn.views.ScreenSlidePagerAdapter; +import de.blinkt.openvpn.views.TabBarView; -public class VPNPreferences extends PreferenceActivity { +public class VPNPreferences extends Activity { static final Class validFragments[] = new Class[] { Settings_Authentication.class, Settings_Basic.class, Settings_IP.class, @@ -44,14 +50,15 @@ public class VPNPreferences extends PreferenceActivity { private String mProfileUUID; private VpnProfile mProfile; + private ViewPager mPager; + private ScreenSlidePagerAdapter mPagerAdapter; - public VPNPreferences() { + public VPNPreferences() { super(); } @TargetApi(Build.VERSION_CODES.KITKAT) - @Override protected boolean isValidFragment(String fragmentName) { for (Class c: validFragments) if (c.getName().equals(fragmentName)) @@ -74,22 +81,7 @@ public class VPNPreferences extends PreferenceActivity { @Override protected void onResume() { super.onResume(); - Intent intent = getIntent(); - - - if(intent!=null) { - String profileUUID = intent.getStringExtra(getPackageName() + ".profileUUID"); - if(profileUUID==null) { - Bundle initialArguments = getIntent().getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS); - profileUUID = initialArguments.getString(getPackageName() + ".profileUUID"); - } - if(profileUUID!=null){ - - mProfileUUID = profileUUID; - mProfile = ProfileManager.get(this,mProfileUUID); - - } - } + getProfile(); // When a profile is deleted from a category fragment in hadset mod we need to finish // this activity as well when returning if (mProfile==null || mProfile.profileDleted) { @@ -98,7 +90,25 @@ public class VPNPreferences extends PreferenceActivity { } } - @Override + private void getProfile() { + Intent intent = getIntent(); + + if(intent!=null) { + String profileUUID = intent.getStringExtra(getPackageName() + ".profileUUID"); + if(profileUUID==null) { + Bundle initialArguments = getIntent().getBundleExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS); + profileUUID = initialArguments.getString(getPackageName() + ".profileUUID"); + } + if(profileUUID!=null){ + + mProfileUUID = profileUUID; + mProfile = ProfileManager.get(this, mProfileUUID); + + } + } + } + + @Override protected void onCreate(Bundle savedInstanceState) { mProfileUUID = getIntent().getStringExtra(getPackageName() + ".profileUUID"); if(savedInstanceState!=null){ @@ -113,10 +123,50 @@ public class VPNPreferences extends PreferenceActivity { } super.onCreate(savedInstanceState); - } + setContentView(R.layout.main_activity); + + /* Toolbar and slider should have the same elevation */ + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + disableToolbarElevation(); + } + + // Instantiate a ViewPager and a PagerAdapter. + mPager = (ViewPager) findViewById(R.id.pager); + mPagerAdapter = new ScreenSlidePagerAdapter(getFragmentManager(), this); + Bundle fragmentArguments = new Bundle(); + fragmentArguments.putString(getPackageName() + ".profileUUID",mProfileUUID); + mPagerAdapter.setFragmentArgs(fragmentArguments); + + mPagerAdapter.addTab(R.string.client_behaviour, Settings_Behaviour.class); + + mPagerAdapter.addTab(R.string.server_list, Settings_Connections.class); + + mPagerAdapter.addTab(R.string.basic, Settings_Basic.class); + mPagerAdapter.addTab(R.string.ipdns, Settings_IP.class); + mPagerAdapter.addTab(R.string.routing, Settings_Routing.class); + mPagerAdapter.addTab(R.string.settings_auth, Settings_Authentication.class); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) + mPagerAdapter.addTab(R.string.vpn_allowed_apps, Settings_Allowed_Apps.class); + + mPagerAdapter.addTab(R.string.advanced, Settings_Obscure.class); + mPagerAdapter.addTab(R.string.generated_config, ShowConfigFragment.class); + + + + + mPager.setAdapter(mPagerAdapter); + + TabBarView tabs = (TabBarView) findViewById(R.id.sliding_tabs); + tabs.setViewPager(mPager); + + } + + +/* @Override public void onBuildHeaders(List
target) { loadHeadersFromResource(R.xml.vpn_headers, target); @@ -130,7 +180,7 @@ public class VPNPreferences extends PreferenceActivity { } if (headerToRemove != null) target.remove(headerToRemove); - } + }*/ @Override public void onBackPressed() { @@ -176,5 +226,12 @@ public class VPNPreferences extends PreferenceActivity { finish(); } + + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + private void disableToolbarElevation() { + ActionBar toolbar = getActionBar(); + toolbar.setElevation(0); + } + } diff --git a/main/src/main/java/de/blinkt/openvpn/fragments/ShowConfigFragment.java b/main/src/main/java/de/blinkt/openvpn/fragments/ShowConfigFragment.java index 11a4842c..93af34af 100644 --- a/main/src/main/java/de/blinkt/openvpn/fragments/ShowConfigFragment.java +++ b/main/src/main/java/de/blinkt/openvpn/fragments/ShowConfigFragment.java @@ -7,6 +7,7 @@ package de.blinkt.openvpn.fragments; import android.app.Fragment; import android.content.Intent; +import android.os.Build; import android.os.Bundle; import android.view.LayoutInflater; import android.view.Menu; @@ -14,6 +15,7 @@ import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; +import android.widget.ImageButton; import android.widget.TextView; import de.blinkt.openvpn.R; import de.blinkt.openvpn.VpnProfile; @@ -30,6 +32,16 @@ public class ShowConfigFragment extends Fragment { final TextView cv = (TextView) v.findViewById(R.id.configview); int check=vp.checkProfile(getActivity()); + + ImageButton fabButton = (ImageButton) v.findViewById(R.id.share_config); + if (fabButton!=null) + fabButton.setOnClickListener( new View.OnClickListener() { + @Override + public void onClick(View v) { + shareConfig(); + } + }); + if(check!=R.string.no_error_found) { cv.setText(check); configtext = getString(check); @@ -70,7 +82,8 @@ public class ShowConfigFragment extends Fragment { @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { - inflater.inflate(R.menu.configmenu, menu); + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) + inflater.inflate(R.menu.configmenu, menu); } private void shareConfig() { diff --git a/main/src/main/java/de/blinkt/openvpn/views/ScreenSlidePagerAdapter.java b/main/src/main/java/de/blinkt/openvpn/views/ScreenSlidePagerAdapter.java new file mode 100644 index 00000000..e41583bf --- /dev/null +++ b/main/src/main/java/de/blinkt/openvpn/views/ScreenSlidePagerAdapter.java @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2012-2014 Arne Schwabe + * Distributed under the GNU GPL v2. For full terms see the file doc/LICENSE.txt + */ + +package de.blinkt.openvpn.views; + +import android.app.Fragment; +import android.app.FragmentManager; +import android.content.Context; +import android.content.res.Resources; +import android.os.Bundle; +import android.support.annotation.StringRes; +import android.support.v4n.app.FragmentStatePagerAdapter; + +import java.util.Vector; + +import de.blinkt.openvpn.activities.MainActivity; + +/** +* Created by arne on 18.11.14. +*/ +public class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter { + + private final Resources res; + private Bundle mFragmentArguments; + + public void setFragmentArgs(Bundle fragmentArguments) { + mFragmentArguments = fragmentArguments; + } + + static class Tab { + public Class fragmentClass; + String mName; + + public Tab(Class fClass, @StringRes String name){ + mName = name; + fragmentClass = fClass; + } + + } + + + private Vector mTabs = new Vector(); + + public ScreenSlidePagerAdapter(FragmentManager fm, Context c) { + super(fm); + res = c.getResources(); + } + + @Override + public Fragment getItem(int position) { + try { + Fragment fragment = mTabs.get(position).fragmentClass.newInstance(); + if (mFragmentArguments!=null) + fragment.setArguments(mFragmentArguments); + return fragment; + } catch (InstantiationException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + return null; + } + + @Override + public CharSequence getPageTitle(int position) { + return mTabs.get(position).mName; + } + + @Override + public int getCount() { + return mTabs.size(); + } + + public void addTab(@StringRes int name, Class fragmentClass) { + mTabs.add(new Tab(fragmentClass, res.getString(name))); + } +} diff --git a/main/src/main/res/layout-v21/config_fab.xml b/main/src/main/res/layout-v21/config_fab.xml new file mode 100644 index 00000000..9e7e4e6c --- /dev/null +++ b/main/src/main/res/layout-v21/config_fab.xml @@ -0,0 +1,21 @@ + + + + \ No newline at end of file diff --git a/main/src/main/res/layout-v21/tabs.xml b/main/src/main/res/layout-v21/tabs.xml index 095f863e..be6ce9f1 100644 --- a/main/src/main/res/layout-v21/tabs.xml +++ b/main/src/main/res/layout-v21/tabs.xml @@ -2,12 +2,14 @@ ~ Copyright (c) 2012-2014 Arne Schwabe ~ Distributed under the GNU GPL v2. For full terms see the file doc/LICENSE.txt --> - + \ No newline at end of file diff --git a/main/src/main/res/layout/allowed_vpn_apps.xml b/main/src/main/res/layout/allowed_vpn_apps.xml index b3d074e8..66665cb6 100644 --- a/main/src/main/res/layout/allowed_vpn_apps.xml +++ b/main/src/main/res/layout/allowed_vpn_apps.xml @@ -5,18 +5,10 @@ -