Simple email application for Android. Original source code: https://framagit.org/dystopia-project/simple-email
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

120 lines
3.5 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. package eu.faircode.email;
  2. /*
  3. This file is part of FairEmail.
  4. FairEmail is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. NetGuard is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with NetGuard. If not, see <http://www.gnu.org/licenses/>.
  14. Copyright 2018 by Marcel Bokhorst (M66B)
  15. */
  16. import android.content.res.Configuration;
  17. import android.os.Bundle;
  18. import android.util.Log;
  19. import android.view.LayoutInflater;
  20. import android.view.View;
  21. import android.view.ViewGroup;
  22. import android.view.inputmethod.InputMethodManager;
  23. import androidx.appcompat.app.ActionBar;
  24. import androidx.appcompat.app.AppCompatActivity;
  25. import androidx.fragment.app.Fragment;
  26. import androidx.lifecycle.Lifecycle;
  27. public class FragmentEx extends Fragment {
  28. private String subtitle = " ";
  29. private boolean finish = false;
  30. protected void setSubtitle(int resid) {
  31. setSubtitle(getString(resid));
  32. }
  33. protected void setSubtitle(String subtitle) {
  34. this.subtitle = subtitle;
  35. updateSubtitle();
  36. }
  37. protected void finish() {
  38. if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED))
  39. getFragmentManager().popBackStack();
  40. else
  41. finish = true;
  42. }
  43. @Override
  44. public void onCreate(Bundle savedInstanceState) {
  45. Log.i(Helper.TAG, "Create " + this);
  46. super.onCreate(savedInstanceState);
  47. }
  48. @Override
  49. public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  50. Log.i(Helper.TAG, "Create view " + this);
  51. return super.onCreateView(inflater, container, savedInstanceState);
  52. }
  53. @Override
  54. public void onActivityCreated(Bundle savedInstanceState) {
  55. Log.i(Helper.TAG, "Activity " + this);
  56. super.onActivityCreated(savedInstanceState);
  57. }
  58. @Override
  59. public void onResume() {
  60. Log.i(Helper.TAG, "Resume " + this);
  61. super.onResume();
  62. updateSubtitle();
  63. if (finish) {
  64. getFragmentManager().popBackStack();
  65. finish = false;
  66. }
  67. }
  68. @Override
  69. public void onPause() {
  70. Log.i(Helper.TAG, "Pause " + this);
  71. super.onPause();
  72. }
  73. @Override
  74. public void onDetach() {
  75. super.onDetach();
  76. InputMethodManager im = getContext().getSystemService(InputMethodManager.class);
  77. View focused = getActivity().getCurrentFocus();
  78. if (focused != null)
  79. im.hideSoftInputFromWindow(focused.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
  80. }
  81. @Override
  82. public void onConfigurationChanged(Configuration newConfig) {
  83. Log.i(Helper.TAG, "Config " + this);
  84. super.onConfigurationChanged(newConfig);
  85. }
  86. @Override
  87. public void onDestroy() {
  88. Log.i(Helper.TAG, "Destroy " + this);
  89. super.onDestroy();
  90. }
  91. private void updateSubtitle() {
  92. AppCompatActivity activity = (AppCompatActivity) getActivity();
  93. if (activity != null) {
  94. ActionBar actionbar = activity.getSupportActionBar();
  95. if (actionbar != null)
  96. actionbar.setSubtitle(subtitle);
  97. }
  98. }
  99. }