From 8ed3d1ab8356e9ef3201c5933335572f8df492dd Mon Sep 17 00:00:00 2001 From: cyBerta Date: Sat, 12 May 2018 00:58:56 +0200 Subject: #8889 change navigation drawer introduction behavior - hide navigation drawer after 1,5 sec and show a little blue dot at the burger menu after 3 sec --- .../drawer/NavigationDrawerFragment.java | 41 ++++++++++++++++++--- app/src/main/res/drawable/ic_menu_color_point.png | Bin 0 -> 2454 bytes app/src/main/res/drawable/ic_menu_default.png | Bin 0 -> 2454 bytes 3 files changed, 35 insertions(+), 6 deletions(-) create mode 100644 app/src/main/res/drawable/ic_menu_color_point.png create mode 100644 app/src/main/res/drawable/ic_menu_default.png diff --git a/app/src/main/java/se/leap/bitmaskclient/drawer/NavigationDrawerFragment.java b/app/src/main/java/se/leap/bitmaskclient/drawer/NavigationDrawerFragment.java index 6e39e9ed..28925efc 100644 --- a/app/src/main/java/se/leap/bitmaskclient/drawer/NavigationDrawerFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/drawer/NavigationDrawerFragment.java @@ -23,6 +23,7 @@ import android.content.Intent; import android.content.SharedPreferences; import android.content.res.Configuration; import android.os.Bundle; +import android.os.Handler; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.view.GravityCompat; @@ -96,6 +97,7 @@ public class NavigationDrawerFragment extends Fragment { private View mFragmentContainerView; private ArrayAdapter accountListAdapter; private DrawerSettingsAdapter settingsListAdapter; + private Toolbar mToolbar; private boolean mFromSavedInstanceState; private boolean mUserLearnedDrawer; @@ -150,7 +152,14 @@ public class NavigationDrawerFragment extends Fragment { */ public void setUp(int fragmentId, DrawerLayout drawerLayout) { AppCompatActivity activity = (AppCompatActivity) getActivity(); - ActionBar actionBar = activity.getSupportActionBar(); + mDrawerLayout = drawerLayout; + + mToolbar = mDrawerLayout.findViewById(R.id.toolbar); + activity.setSupportActionBar(mToolbar); + + final ActionBar actionBar = activity.getSupportActionBar(); + actionBar.setDisplayHomeAsUpEnabled(true); + actionBar.setHomeButtonEnabled(true); mDrawerSettingsListView = mDrawerView.findViewById(R.id.settingsList); mDrawerSettingsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @@ -176,7 +185,6 @@ public class NavigationDrawerFragment extends Fragment { settingsListAdapter.addItem(getSimpleTextInstance(getString(about_fragment_title), ABOUT)); mDrawerSettingsListView.setAdapter(settingsListAdapter); - mDrawerAccountsListView = mDrawerView.findViewById(R.id.accountList); mDrawerAccountsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override @@ -194,13 +202,10 @@ public class NavigationDrawerFragment extends Fragment { mDrawerAccountsListView.setAdapter(accountListAdapter); mFragmentContainerView = activity.findViewById(fragmentId); - mDrawerLayout = drawerLayout; // set a custom shadow that overlays the main content when the drawer opens mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); - actionBar.setDisplayHomeAsUpEnabled(true); - actionBar.setHomeButtonEnabled(true); // ActionBarDrawerToggle ties together the the proper interactions // between the navigation drawer and the action bar app icon. mDrawerToggle = new ActionBarDrawerToggle( @@ -232,16 +237,40 @@ public class NavigationDrawerFragment extends Fragment { // the navigation drawer automatically in the future. mUserLearnedDrawer = true; preferences.edit().putBoolean(PREF_USER_LEARNED_DRAWER, true).apply(); + mToolbar.setNavigationIcon(R.drawable.ic_menu_default); } getActivity().invalidateOptionsMenu(); // calls onPrepareOptionsMenu() } }; + Handler navigationDrawerHandler = new Handler(); // If the user hasn't 'learned' about the drawer, open it to introduce them to the drawer, // per the navigation drawer design guidelines. if (!mUserLearnedDrawer && !mFromSavedInstanceState) { - mDrawerLayout.openDrawer(mFragmentContainerView); + mDrawerLayout.openDrawer(mFragmentContainerView, false); + navigationDrawerHandler.postDelayed(new Runnable() { + @Override + public void run() { + mDrawerLayout.closeDrawer(mFragmentContainerView, true); + } + }, 1500); + navigationDrawerHandler.postDelayed(new Runnable() { + @Override + public void run() { + mToolbar.setNavigationIcon(R.drawable.ic_menu_color_point); + mToolbar.playSoundEffect(android.view.SoundEffectConstants.CLICK); + } + }, 3000); + + } else if (!mUserLearnedDrawer) { + navigationDrawerHandler.postDelayed(new Runnable() { + @Override + public void run() { + mToolbar.setNavigationIcon(R.drawable.ic_menu_color_point); + mToolbar.playSoundEffect(android.view.SoundEffectConstants.CLICK); + } + }, 1500); } // Defer code dependent on restoration of previous instance state. diff --git a/app/src/main/res/drawable/ic_menu_color_point.png b/app/src/main/res/drawable/ic_menu_color_point.png new file mode 100644 index 00000000..ef4b0e51 Binary files /dev/null and b/app/src/main/res/drawable/ic_menu_color_point.png differ diff --git a/app/src/main/res/drawable/ic_menu_default.png b/app/src/main/res/drawable/ic_menu_default.png new file mode 100644 index 00000000..e0d29163 Binary files /dev/null and b/app/src/main/res/drawable/ic_menu_default.png differ -- cgit v1.2.3 From c5f445fabcbfa6f045aa5f3e5341909468259aed Mon Sep 17 00:00:00 2001 From: cyBerta Date: Sat, 12 May 2018 01:00:41 +0200 Subject: add missing copyright note --- .../java/se/leap/bitmaskclient/views/VpnStateImage.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/app/src/main/java/se/leap/bitmaskclient/views/VpnStateImage.java b/app/src/main/java/se/leap/bitmaskclient/views/VpnStateImage.java index 2efd83d6..86761642 100644 --- a/app/src/main/java/se/leap/bitmaskclient/views/VpnStateImage.java +++ b/app/src/main/java/se/leap/bitmaskclient/views/VpnStateImage.java @@ -1,3 +1,19 @@ +/** + * Copyright (c) 2018 LEAP Encryption Access Project and contributers + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package se.leap.bitmaskclient.views; import android.content.Context; -- cgit v1.2.3 From 24149d46a63d28c8fb9d7f7134001f9188958f70 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Thu, 24 May 2018 00:23:49 +0200 Subject: #8889 fix review findings and refactor code for better readability --- .../drawer/NavigationDrawerFragment.java | 237 ++++++++++++--------- 1 file changed, 142 insertions(+), 95 deletions(-) diff --git a/app/src/main/java/se/leap/bitmaskclient/drawer/NavigationDrawerFragment.java b/app/src/main/java/se/leap/bitmaskclient/drawer/NavigationDrawerFragment.java index f9adede7..dcb96158 100644 --- a/app/src/main/java/se/leap/bitmaskclient/drawer/NavigationDrawerFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/drawer/NavigationDrawerFragment.java @@ -25,6 +25,7 @@ import android.content.res.Configuration; import android.os.Build; import android.os.Bundle; import android.os.Handler; +import android.support.annotation.NonNull; import android.support.v4.app.DialogFragment; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; @@ -47,18 +48,17 @@ import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.CompoundButton; import android.widget.ListView; -import android.widget.Toast; import se.leap.bitmaskclient.ConfigHelper; import se.leap.bitmaskclient.DrawerSettingsAdapter; import se.leap.bitmaskclient.DrawerSettingsAdapter.DrawerSettingsItem; -import se.leap.bitmaskclient.FragmentManagerEnhanced; -import se.leap.bitmaskclient.fragments.AlwaysOnDialog; import se.leap.bitmaskclient.EipFragment; +import se.leap.bitmaskclient.FragmentManagerEnhanced; import se.leap.bitmaskclient.Provider; import se.leap.bitmaskclient.ProviderListActivity; import se.leap.bitmaskclient.R; import se.leap.bitmaskclient.fragments.AboutFragment; +import se.leap.bitmaskclient.fragments.AlwaysOnDialog; import se.leap.bitmaskclient.fragments.LogFragment; import static android.content.Context.MODE_PRIVATE; @@ -91,6 +91,7 @@ public class NavigationDrawerFragment extends Fragment { * expands it. This shared preference tracks this. */ private static final String PREF_USER_LEARNED_DRAWER = "navigation_drawer_learned"; + private static final String TAG = NavigationDrawerFragment.class.getName(); /** * Helper component that ties the action bar to the navigation drawer. @@ -106,8 +107,9 @@ public class NavigationDrawerFragment extends Fragment { private DrawerSettingsAdapter settingsListAdapter; private Toolbar mToolbar; - private boolean mFromSavedInstanceState; private boolean mUserLearnedDrawer; + private volatile boolean wasPaused; + private volatile boolean shouldCloseOnResume; private String mTitle; @@ -127,9 +129,6 @@ public class NavigationDrawerFragment extends Fragment { // drawer. See PREF_USER_LEARNED_DRAWER for details. preferences = getContext().getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE); mUserLearnedDrawer = preferences.getBoolean(PREF_USER_LEARNED_DRAWER, false); - if (savedInstanceState != null) { - mFromSavedInstanceState = true; - } } @Override @@ -151,6 +150,23 @@ public class NavigationDrawerFragment extends Fragment { return mDrawerLayout != null && mDrawerLayout.isDrawerOpen(mFragmentContainerView); } + @Override + public void onResume() { + super.onResume(); + wasPaused = false; + if (shouldCloseOnResume) { + closeDrawerWithDelay(2000); + showDottedIconWithDelay(3000); + } + // + } + + @Override + public void onPause() { + super.onPause(); + wasPaused = true; + } + /** * Users of this fragment must call this method to set up the navigation drawer interactions. * @@ -158,70 +174,44 @@ public class NavigationDrawerFragment extends Fragment { * @param drawerLayout The DrawerLayout containing this fragment's UI. */ public void setUp(int fragmentId, DrawerLayout drawerLayout) { - AppCompatActivity activity = (AppCompatActivity) getActivity(); + final AppCompatActivity activity = (AppCompatActivity) getActivity(); + mFragmentContainerView = activity.findViewById(fragmentId); mDrawerLayout = drawerLayout; - + // set a custom shadow that overlays the main content when the drawer opens + mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); mToolbar = mDrawerLayout.findViewById(R.id.toolbar); - activity.setSupportActionBar(mToolbar); - final ActionBar actionBar = activity.getSupportActionBar(); - actionBar.setDisplayHomeAsUpEnabled(true); - actionBar.setHomeButtonEnabled(true); + final ActionBar actionBar = setupActionBar(mToolbar); + settingsListAdapter = setupSettingsListAdapter(); + mDrawerSettingsListView = setupSettingsListView(); + accountListAdapter = new ArrayAdapter<>(actionBar.getThemedContext(), + R.layout.v_single_list_item, + android.R.id.text1); + refreshAccountListAdapter(); + mDrawerAccountsListView = setupAccountsListView(); + mDrawerToggle = setupActionBarDrawerToggle(drawerLayout, mToolbar, activity); - mDrawerSettingsListView = mDrawerView.findViewById(R.id.settingsList); - mDrawerSettingsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { - @Override - public void onItemClick(AdapterView parent, View view, int position, long id) { - selectItem(parent, position); - } - }); - settingsListAdapter = new DrawerSettingsAdapter(getLayoutInflater()); - if (getContext() != null) { - settingsListAdapter.addItem(getSwitchInstance(getString(R.string.save_battery), - getSaveBattery(getContext()), - BATTERY_SAVER, - new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean newStateIsChecked) { - onSwitchItemSelected(BATTERY_SAVER, newStateIsChecked); - } - })); + if (!mUserLearnedDrawer) { + openNavigationDrawerForFirstTimeUsers(); } - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - settingsListAdapter.addItem(getSimpleTextInstance(getString(R.string.always_on_vpn), ALWAYS_ON)); - } - settingsListAdapter.addItem(getSimpleTextInstance(getString(switch_provider_menu_option), SWITCH_PROVIDER)); - settingsListAdapter.addItem(getSimpleTextInstance(getString(log_fragment_title), LOG)); - settingsListAdapter.addItem(getSimpleTextInstance(getString(about_fragment_title), ABOUT)); - mDrawerSettingsListView.setAdapter(settingsListAdapter); - mDrawerAccountsListView = mDrawerView.findViewById(R.id.accountList); - mDrawerAccountsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + // Defer code dependent on restoration of previous instance state. + mDrawerLayout.post(new Runnable() { @Override - public void onItemClick(AdapterView parent, View view, int position, long id) { - selectItem(parent, position); + public void run() { + mDrawerToggle.syncState(); } }); + mDrawerLayout.addDrawerListener(mDrawerToggle); + } - accountListAdapter = new ArrayAdapter<>(actionBar.getThemedContext(), - R.layout.v_single_list_item, - android.R.id.text1); - - createListAdapterData(); - - mDrawerAccountsListView.setAdapter(accountListAdapter); - - mFragmentContainerView = activity.findViewById(fragmentId); - - // set a custom shadow that overlays the main content when the drawer opens - mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); - + private ActionBarDrawerToggle setupActionBarDrawerToggle(final DrawerLayout drawerLayout, final Toolbar toolbar, final AppCompatActivity activity) { // ActionBarDrawerToggle ties together the the proper interactions // between the navigation drawer and the action bar app icon. - mDrawerToggle = new ActionBarDrawerToggle( - getActivity(), - mDrawerLayout, - (Toolbar) drawerLayout.findViewById(R.id.toolbar), + ActionBarDrawerToggle drawerToggle = new ActionBarDrawerToggle( + activity, + drawerLayout, + toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close ) { @@ -232,7 +222,7 @@ public class NavigationDrawerFragment extends Fragment { return; } - getActivity().invalidateOptionsMenu(); // calls onPrepareOptionsMenu() + activity.invalidateOptionsMenu(); // calls onPrepareOptionsMenu() } @Override @@ -250,48 +240,106 @@ public class NavigationDrawerFragment extends Fragment { mToolbar.setNavigationIcon(R.drawable.ic_menu_default); } - getActivity().invalidateOptionsMenu(); // calls onPrepareOptionsMenu() + activity.invalidateOptionsMenu(); // calls onPrepareOptionsMenu() } }; + return drawerToggle; + } - Handler navigationDrawerHandler = new Handler(); - // If the user hasn't 'learned' about the drawer, open it to introduce them to the drawer, - // per the navigation drawer design guidelines. - if (!mUserLearnedDrawer && !mFromSavedInstanceState) { - mDrawerLayout.openDrawer(mFragmentContainerView, false); - navigationDrawerHandler.postDelayed(new Runnable() { - @Override - public void run() { - mDrawerLayout.closeDrawer(mFragmentContainerView, true); - } - }, 1500); - navigationDrawerHandler.postDelayed(new Runnable() { - @Override - public void run() { - mToolbar.setNavigationIcon(R.drawable.ic_menu_color_point); - mToolbar.playSoundEffect(android.view.SoundEffectConstants.CLICK); - } - }, 3000); + private ListView setupAccountsListView() { + ListView drawerAccountsListView = mDrawerView.findViewById(R.id.accountList); + drawerAccountsListView.setAdapter(accountListAdapter); + drawerAccountsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + selectItem(parent, position); + } + }); + return drawerAccountsListView; + } + + private ListView setupSettingsListView() { + ListView drawerSettingsListView = mDrawerView.findViewById(R.id.settingsList); + drawerSettingsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + selectItem(parent, position); + } + }); + drawerSettingsListView.setAdapter(settingsListAdapter); + return drawerSettingsListView; + } - } else if (!mUserLearnedDrawer) { - navigationDrawerHandler.postDelayed(new Runnable() { - @Override - public void run() { + private DrawerSettingsAdapter setupSettingsListAdapter() { + DrawerSettingsAdapter settingsListAdapter = new DrawerSettingsAdapter(getLayoutInflater()); + if (getContext() != null) { + settingsListAdapter.addItem(getSwitchInstance(getString(R.string.save_battery), + getSaveBattery(getContext()), + BATTERY_SAVER, + new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean newStateIsChecked) { + onSwitchItemSelected(BATTERY_SAVER, newStateIsChecked); + } + })); + } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + settingsListAdapter.addItem(getSimpleTextInstance(getString(R.string.always_on_vpn), ALWAYS_ON)); + } + settingsListAdapter.addItem(getSimpleTextInstance(getString(switch_provider_menu_option), SWITCH_PROVIDER)); + settingsListAdapter.addItem(getSimpleTextInstance(getString(log_fragment_title), LOG)); + settingsListAdapter.addItem(getSimpleTextInstance(getString(about_fragment_title), ABOUT)); + return settingsListAdapter; + } + + private ActionBar setupActionBar(Toolbar toolbar) { + AppCompatActivity activity = (AppCompatActivity) getActivity(); + activity.setSupportActionBar(toolbar); + final ActionBar actionBar = activity.getSupportActionBar(); + actionBar.setDisplayHomeAsUpEnabled(true); + actionBar.setHomeButtonEnabled(true); + return actionBar; + } + + private void openNavigationDrawerForFirstTimeUsers() { + if (mUserLearnedDrawer) { + return; + } + + mDrawerLayout.openDrawer(mFragmentContainerView, false); + closeDrawerWithDelay(2000); + showDottedIconWithDelay(3000); + + } + + private void showDottedIconWithDelay(long delay) { + final Handler navigationDrawerHandler = new Handler(); + navigationDrawerHandler.postDelayed(new Runnable() { + @Override + public void run() { + if (!wasPaused) { mToolbar.setNavigationIcon(R.drawable.ic_menu_color_point); mToolbar.playSoundEffect(android.view.SoundEffectConstants.CLICK); } - }, 1500); - } - // Defer code dependent on restoration of previous instance state. - mDrawerLayout.post(new Runnable() { + } + }, delay); + } + + @NonNull + private void closeDrawerWithDelay(long delay) { + final Handler navigationDrawerHandler = new Handler(); + navigationDrawerHandler.postDelayed(new Runnable() { @Override public void run() { - mDrawerToggle.syncState(); - } - }); - mDrawerLayout.addDrawerListener(mDrawerToggle); + if (!wasPaused) { + mDrawerLayout.closeDrawer(mFragmentContainerView, true); + } else { + shouldCloseOnResume = true; + } + } + }, delay); } private void selectItem(AdapterView list, int position) { @@ -394,7 +442,6 @@ public class NavigationDrawerFragment extends Fragment { if (mDrawerToggle.onOptionsItemSelected(item)) { return true; } - return super.onOptionsItemSelected(item); } @@ -458,7 +505,7 @@ public class NavigationDrawerFragment extends Fragment { arguments.putParcelable(PROVIDER_KEY, currentProvider); fragment.setArguments(arguments); } else { - Log.d("Drawer", String.format("Selected position %d", position)); + Log.d(TAG, String.format("Selected position %d", position)); DrawerSettingsItem settingsItem = settingsListAdapter.getItem(position); switch (settingsItem.getItemType()) { case SWITCH_PROVIDER: @@ -505,12 +552,12 @@ public class NavigationDrawerFragment extends Fragment { public void refresh() { - createListAdapterData(); + refreshAccountListAdapter(); accountListAdapter.notifyDataSetChanged(); mDrawerAccountsListView.setAdapter(accountListAdapter); } - private void createListAdapterData() { + private void refreshAccountListAdapter() { accountListAdapter.clear(); String providerName = ConfigHelper.getProviderName(preferences); if (providerName == null) { -- cgit v1.2.3 From dc4e74975afcba8a694ec23666c538dc761277b1 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Mon, 11 Jun 2018 00:05:40 +0200 Subject: #8889 further changes after code review --- .../drawer/NavigationDrawerFragment.java | 42 ++++++++++------------ 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/se/leap/bitmaskclient/drawer/NavigationDrawerFragment.java b/app/src/main/java/se/leap/bitmaskclient/drawer/NavigationDrawerFragment.java index dcb96158..faff7494 100644 --- a/app/src/main/java/se/leap/bitmaskclient/drawer/NavigationDrawerFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/drawer/NavigationDrawerFragment.java @@ -100,7 +100,6 @@ public class NavigationDrawerFragment extends Fragment { private DrawerLayout mDrawerLayout; private View mDrawerView; - private ListView mDrawerSettingsListView; private ListView mDrawerAccountsListView; private View mFragmentContainerView; private ArrayAdapter accountListAdapter; @@ -158,7 +157,6 @@ public class NavigationDrawerFragment extends Fragment { closeDrawerWithDelay(2000); showDottedIconWithDelay(3000); } - // } @Override @@ -181,15 +179,15 @@ public class NavigationDrawerFragment extends Fragment { mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); mToolbar = mDrawerLayout.findViewById(R.id.toolbar); - final ActionBar actionBar = setupActionBar(mToolbar); - settingsListAdapter = setupSettingsListAdapter(); - mDrawerSettingsListView = setupSettingsListView(); + final ActionBar actionBar = setupActionBar(); + setupSettingsListAdapter(); + setupSettingsListView(); accountListAdapter = new ArrayAdapter<>(actionBar.getThemedContext(), R.layout.v_single_list_item, android.R.id.text1); refreshAccountListAdapter(); - mDrawerAccountsListView = setupAccountsListView(); - mDrawerToggle = setupActionBarDrawerToggle(drawerLayout, mToolbar, activity); + setupAccountsListView(); + setupActionBarDrawerToggle(activity); if (!mUserLearnedDrawer) { openNavigationDrawerForFirstTimeUsers(); @@ -205,13 +203,13 @@ public class NavigationDrawerFragment extends Fragment { mDrawerLayout.addDrawerListener(mDrawerToggle); } - private ActionBarDrawerToggle setupActionBarDrawerToggle(final DrawerLayout drawerLayout, final Toolbar toolbar, final AppCompatActivity activity) { + private void setupActionBarDrawerToggle(final AppCompatActivity activity) { // ActionBarDrawerToggle ties together the the proper interactions // between the navigation drawer and the action bar app icon. - ActionBarDrawerToggle drawerToggle = new ActionBarDrawerToggle( + mDrawerToggle = new ActionBarDrawerToggle( activity, - drawerLayout, - toolbar, + mDrawerLayout, + mToolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close ) { @@ -243,22 +241,20 @@ public class NavigationDrawerFragment extends Fragment { activity.invalidateOptionsMenu(); // calls onPrepareOptionsMenu() } }; - return drawerToggle; } - private ListView setupAccountsListView() { - ListView drawerAccountsListView = mDrawerView.findViewById(R.id.accountList); - drawerAccountsListView.setAdapter(accountListAdapter); - drawerAccountsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + private void setupAccountsListView() { + mDrawerAccountsListView = mDrawerView.findViewById(R.id.accountList); + mDrawerAccountsListView.setAdapter(accountListAdapter); + mDrawerAccountsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView parent, View view, int position, long id) { selectItem(parent, position); } }); - return drawerAccountsListView; } - private ListView setupSettingsListView() { + private void setupSettingsListView() { ListView drawerSettingsListView = mDrawerView.findViewById(R.id.settingsList); drawerSettingsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override @@ -267,11 +263,10 @@ public class NavigationDrawerFragment extends Fragment { } }); drawerSettingsListView.setAdapter(settingsListAdapter); - return drawerSettingsListView; } - private DrawerSettingsAdapter setupSettingsListAdapter() { - DrawerSettingsAdapter settingsListAdapter = new DrawerSettingsAdapter(getLayoutInflater()); + private void setupSettingsListAdapter() { + settingsListAdapter = new DrawerSettingsAdapter(getLayoutInflater()); if (getContext() != null) { settingsListAdapter.addItem(getSwitchInstance(getString(R.string.save_battery), getSaveBattery(getContext()), @@ -289,12 +284,11 @@ public class NavigationDrawerFragment extends Fragment { settingsListAdapter.addItem(getSimpleTextInstance(getString(switch_provider_menu_option), SWITCH_PROVIDER)); settingsListAdapter.addItem(getSimpleTextInstance(getString(log_fragment_title), LOG)); settingsListAdapter.addItem(getSimpleTextInstance(getString(about_fragment_title), ABOUT)); - return settingsListAdapter; } - private ActionBar setupActionBar(Toolbar toolbar) { + private ActionBar setupActionBar() { AppCompatActivity activity = (AppCompatActivity) getActivity(); - activity.setSupportActionBar(toolbar); + activity.setSupportActionBar(mToolbar); final ActionBar actionBar = activity.getSupportActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setHomeButtonEnabled(true); -- cgit v1.2.3 From 1494f0248de623dcdcc5367235240d63de046897 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Thu, 14 Jun 2018 22:04:13 +0200 Subject: rebuild docker image with ndk r16b --- docker/android-ndk/Dockerfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docker/android-ndk/Dockerfile b/docker/android-ndk/Dockerfile index 49b08dcc..6a13f414 100644 --- a/docker/android-ndk/Dockerfile +++ b/docker/android-ndk/Dockerfile @@ -36,4 +36,6 @@ ENV PATH ${PATH}:${ANDROID_NDK_HOME} # Accept all licenses RUN yes | sdkmanager --licenses -RUN sdkmanager --list \ No newline at end of file +RUN sdkmanager --list + +RUN echo "done" \ No newline at end of file -- cgit v1.2.3 From ad86a65002f5e56a9dcc8195afd0738ad8f0fbb0 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Mon, 18 Jun 2018 20:45:22 +0200 Subject: #8889 another round of polishing --- .../drawer/NavigationDrawerFragment.java | 125 ++++++++++----------- 1 file changed, 61 insertions(+), 64 deletions(-) diff --git a/app/src/main/java/se/leap/bitmaskclient/drawer/NavigationDrawerFragment.java b/app/src/main/java/se/leap/bitmaskclient/drawer/NavigationDrawerFragment.java index 050da415..be4bdf99 100644 --- a/app/src/main/java/se/leap/bitmaskclient/drawer/NavigationDrawerFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/drawer/NavigationDrawerFragment.java @@ -97,25 +97,27 @@ public class NavigationDrawerFragment extends Fragment { */ private static final String PREF_USER_LEARNED_DRAWER = "navigation_drawer_learned"; private static final String TAG = NavigationDrawerFragment.class.getName(); + public static final int TWO_SECONDS = 2000; + public static final int THREE_SECONDS = 3500; /** * Helper component that ties the action bar to the navigation drawer. */ - private ActionBarDrawerToggle mDrawerToggle; + private ActionBarDrawerToggle drawerToggle; - private DrawerLayout mDrawerLayout; - private View mDrawerView; - private ListView mDrawerAccountsListView; - private View mFragmentContainerView; + private DrawerLayout drawerLayout; + private View drawerView; + private ListView drawerAccountsListView; + private View fragmentContainerView; private ArrayAdapter accountListAdapter; private DrawerSettingsAdapter settingsListAdapter; - private Toolbar mToolbar; + private Toolbar toolbar; - private boolean mUserLearnedDrawer; + private boolean userLearnedDrawer; private volatile boolean wasPaused; private volatile boolean shouldCloseOnResume; - private String mTitle; + private String title; private SharedPreferences preferences; @@ -123,35 +125,32 @@ public class NavigationDrawerFragment extends Fragment { private boolean showEnableExperimentalFeature = false; AlertDialog alertDialog; - public NavigationDrawerFragment() { - } - @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - // Read in the flag indicating whether or not the user has demonstrated awareness of the + // Reads in the flag indicating whether or not the user has demonstrated awareness of the // drawer. See PREF_USER_LEARNED_DRAWER for details. preferences = getContext().getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE); - mUserLearnedDrawer = preferences.getBoolean(PREF_USER_LEARNED_DRAWER, false); + userLearnedDrawer = preferences.getBoolean(PREF_USER_LEARNED_DRAWER, false); } @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); - // Indicate that this fragment would like to influence the set of actions in the action bar. + // Indicates that this fragment would like to influence the set of actions in the action bar. setHasOptionsMenu(true); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - mDrawerView = inflater.inflate(R.layout.f_drawer_main, container, false); + drawerView = inflater.inflate(R.layout.f_drawer_main, container, false); restoreFromSavedInstance(savedInstanceState); - return mDrawerView; + return drawerView; } public boolean isDrawerOpen() { - return mDrawerLayout != null && mDrawerLayout.isDrawerOpen(mFragmentContainerView); + return drawerLayout != null && drawerLayout.isDrawerOpen(fragmentContainerView); } @Override @@ -159,8 +158,8 @@ public class NavigationDrawerFragment extends Fragment { super.onResume(); wasPaused = false; if (shouldCloseOnResume) { - closeDrawerWithDelay(2000); - showDottedIconWithDelay(3000); + closeDrawerWithDelay(); + showDottedIconWithDelay(); } } @@ -178,11 +177,11 @@ public class NavigationDrawerFragment extends Fragment { */ public void setUp(int fragmentId, DrawerLayout drawerLayout) { final AppCompatActivity activity = (AppCompatActivity) getActivity(); - mFragmentContainerView = activity.findViewById(fragmentId); - mDrawerLayout = drawerLayout; + fragmentContainerView = activity.findViewById(fragmentId); + this.drawerLayout = drawerLayout; // set a custom shadow that overlays the main content when the drawer opens - mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); - mToolbar = mDrawerLayout.findViewById(R.id.toolbar); + this.drawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); + toolbar = this.drawerLayout.findViewById(R.id.toolbar); final ActionBar actionBar = setupActionBar(); setupSettingsListAdapter(); @@ -194,27 +193,27 @@ public class NavigationDrawerFragment extends Fragment { setupAccountsListView(); setupActionBarDrawerToggle(activity); - if (!mUserLearnedDrawer) { + if (!userLearnedDrawer) { openNavigationDrawerForFirstTimeUsers(); } // Defer code dependent on restoration of previous instance state. - mDrawerLayout.post(new Runnable() { + this.drawerLayout.post(new Runnable() { @Override public void run() { - mDrawerToggle.syncState(); + drawerToggle.syncState(); } }); - mDrawerLayout.addDrawerListener(mDrawerToggle); + this.drawerLayout.addDrawerListener(drawerToggle); } private void setupActionBarDrawerToggle(final AppCompatActivity activity) { // ActionBarDrawerToggle ties together the the proper interactions // between the navigation drawer and the action bar app icon. - mDrawerToggle = new ActionBarDrawerToggle( + drawerToggle = new ActionBarDrawerToggle( activity, - mDrawerLayout, - mToolbar, + drawerLayout, + toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close ) { @@ -224,8 +223,7 @@ public class NavigationDrawerFragment extends Fragment { if (!isAdded()) { return; } - - activity.invalidateOptionsMenu(); // calls onPrepareOptionsMenu() + activity.invalidateOptionsMenu(); } @Override @@ -235,23 +233,22 @@ public class NavigationDrawerFragment extends Fragment { return; } - if (!mUserLearnedDrawer) { + if (!userLearnedDrawer) { // The user manually opened the drawer; store this flag to prevent auto-showing // the navigation drawer automatically in the future. - mUserLearnedDrawer = true; + userLearnedDrawer = true; preferences.edit().putBoolean(PREF_USER_LEARNED_DRAWER, true).apply(); - mToolbar.setNavigationIcon(R.drawable.ic_menu_default); + toolbar.setNavigationIcon(R.drawable.ic_menu_default); } - - activity.invalidateOptionsMenu(); // calls onPrepareOptionsMenu() + activity.invalidateOptionsMenu(); } }; } private void setupAccountsListView() { - mDrawerAccountsListView = mDrawerView.findViewById(R.id.accountList); - mDrawerAccountsListView.setAdapter(accountListAdapter); - mDrawerAccountsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + drawerAccountsListView = drawerView.findViewById(R.id.accountList); + drawerAccountsListView.setAdapter(accountListAdapter); + drawerAccountsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView parent, View view, int position, long id) { selectItem(parent, position); @@ -260,7 +257,7 @@ public class NavigationDrawerFragment extends Fragment { } private void setupSettingsListView() { - ListView drawerSettingsListView = mDrawerView.findViewById(R.id.settingsList); + ListView drawerSettingsListView = drawerView.findViewById(R.id.settingsList); drawerSettingsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView parent, View view, int position, long id) { @@ -296,7 +293,7 @@ public class NavigationDrawerFragment extends Fragment { private ActionBar setupActionBar() { AppCompatActivity activity = (AppCompatActivity) getActivity(); - activity.setSupportActionBar(mToolbar); + activity.setSupportActionBar(toolbar); final ActionBar actionBar = activity.getSupportActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setHomeButtonEnabled(true); @@ -304,52 +301,52 @@ public class NavigationDrawerFragment extends Fragment { } private void openNavigationDrawerForFirstTimeUsers() { - if (mUserLearnedDrawer) { + if (userLearnedDrawer) { return; } - mDrawerLayout.openDrawer(mFragmentContainerView, false); - closeDrawerWithDelay(2000); - showDottedIconWithDelay(3000); + drawerLayout.openDrawer(fragmentContainerView, false); + closeDrawerWithDelay(); + showDottedIconWithDelay(); } - private void showDottedIconWithDelay(long delay) { + private void showDottedIconWithDelay() { final Handler navigationDrawerHandler = new Handler(); navigationDrawerHandler.postDelayed(new Runnable() { @Override public void run() { if (!wasPaused) { - mToolbar.setNavigationIcon(R.drawable.ic_menu_color_point); - mToolbar.playSoundEffect(android.view.SoundEffectConstants.CLICK); + toolbar.setNavigationIcon(R.drawable.ic_menu_color_point); + toolbar.playSoundEffect(android.view.SoundEffectConstants.CLICK); } } - }, delay); + }, THREE_SECONDS); } @NonNull - private void closeDrawerWithDelay(long delay) { + private void closeDrawerWithDelay() { final Handler navigationDrawerHandler = new Handler(); navigationDrawerHandler.postDelayed(new Runnable() { @Override public void run() { if (!wasPaused) { - mDrawerLayout.closeDrawer(mFragmentContainerView, true); + drawerLayout.closeDrawer(fragmentContainerView, true); } else { shouldCloseOnResume = true; } } - }, delay); + }, TWO_SECONDS); } private void selectItem(AdapterView list, int position) { if (list != null) { ((ListView) list).setItemChecked(position, true); } - if (mDrawerLayout != null) { - mDrawerLayout.closeDrawer(mFragmentContainerView); + if (drawerLayout != null) { + drawerLayout.closeDrawer(fragmentContainerView); } onTextItemSelected(list, position); } @@ -428,12 +425,12 @@ public class NavigationDrawerFragment extends Fragment { public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); // Forward the new configuration the drawer toggle component. - mDrawerToggle.onConfigurationChanged(newConfig); + drawerToggle.onConfigurationChanged(newConfig); } @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { - if (mDrawerLayout != null && isDrawerOpen()) { + if (drawerLayout != null && isDrawerOpen()) { showGlobalContextActionBar(); } super.onCreateOptionsMenu(menu, inflater); @@ -441,7 +438,7 @@ public class NavigationDrawerFragment extends Fragment { @Override public boolean onOptionsItemSelected(MenuItem item) { - if (mDrawerToggle.onOptionsItemSelected(item)) { + if (drawerToggle.onOptionsItemSelected(item)) { return true; } return super.onOptionsItemSelected(item); @@ -498,8 +495,8 @@ public class NavigationDrawerFragment extends Fragment { Fragment fragment = null; String fragmentTag = null; - if (parent == mDrawerAccountsListView) { - mTitle = getString(R.string.vpn_fragment_title); + if (parent == drawerAccountsListView) { + title = getString(R.string.vpn_fragment_title); fragment = new EipFragment(); fragmentTag = EipFragment.TAG; Bundle arguments = new Bundle(); @@ -514,11 +511,11 @@ public class NavigationDrawerFragment extends Fragment { getActivity().startActivityForResult(new Intent(getActivity(), ProviderListActivity.class), REQUEST_CODE_SWITCH_PROVIDER); break; case LOG: - mTitle = getString(log_fragment_title); + title = getString(log_fragment_title); fragment = new LogFragment(); break; case ABOUT: - mTitle = getString(about_fragment_title); + title = getString(about_fragment_title); fragment = new AboutFragment(); break; case ALWAYS_ON: @@ -552,7 +549,7 @@ public class NavigationDrawerFragment extends Fragment { ActionBar actionBar = getActionBar(); if (actionBar != null) { actionBar.setDisplayShowTitleEnabled(true); - actionBar.setSubtitle(mTitle); + actionBar.setSubtitle(title); } } @@ -560,7 +557,7 @@ public class NavigationDrawerFragment extends Fragment { public void refresh() { refreshAccountListAdapter(); accountListAdapter.notifyDataSetChanged(); - mDrawerAccountsListView.setAdapter(accountListAdapter); + drawerAccountsListView.setAdapter(accountListAdapter); } private void refreshAccountListAdapter() { -- cgit v1.2.3