Browse Source

Hide keyboard on detaching fragment

Do we really need to do this ourselves, Google?
main
M66B 6 years ago
parent
commit
8d42f6809f
13 changed files with 72 additions and 87 deletions
  1. +3
    -9
      app/src/main/java/eu/faircode/email/FragmentAccount.java
  2. +3
    -9
      app/src/main/java/eu/faircode/email/FragmentAccounts.java
  3. +3
    -9
      app/src/main/java/eu/faircode/email/FragmentCompose.java
  4. +1
    -2
      app/src/main/java/eu/faircode/email/FragmentEula.java
  5. +42
    -0
      app/src/main/java/eu/faircode/email/FragmentEx.java
  6. +3
    -9
      app/src/main/java/eu/faircode/email/FragmentFolder.java
  7. +3
    -9
      app/src/main/java/eu/faircode/email/FragmentFolders.java
  8. +3
    -9
      app/src/main/java/eu/faircode/email/FragmentIdentities.java
  9. +3
    -9
      app/src/main/java/eu/faircode/email/FragmentIdentity.java
  10. +1
    -2
      app/src/main/java/eu/faircode/email/FragmentMessage.java
  11. +1
    -2
      app/src/main/java/eu/faircode/email/FragmentMessages.java
  12. +3
    -9
      app/src/main/java/eu/faircode/email/FragmentSetup.java
  13. +3
    -9
      app/src/main/java/eu/faircode/email/FragmentWebView.java

+ 3
- 9
app/src/main/java/eu/faircode/email/FragmentAccount.java View File

@ -25,11 +25,9 @@ import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.TextInputLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.AsyncTaskLoader;
import android.support.v4.content.Loader;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
@ -56,7 +54,7 @@ import javax.mail.Folder;
import javax.mail.MessagingException;
import javax.mail.Session;
public class FragmentAccount extends Fragment {
public class FragmentAccount extends FragmentEx {
private List<Provider> providers;
private EditText etName;
@ -82,6 +80,8 @@ public class FragmentAccount extends Fragment {
@Override
@Nullable
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
setSubtitle(R.string.title_edit_account);
View view = inflater.inflate(R.layout.fragment_account, container, false);
// Get arguments
@ -164,12 +164,6 @@ public class FragmentAccount extends Fragment {
return view;
}
@Override
public void onResume() {
super.onResume();
((AppCompatActivity) getActivity()).getSupportActionBar().setSubtitle(R.string.title_edit_account);
}
private static class PutLoader extends AsyncTaskLoader<Throwable> {
private Bundle args;


+ 3
- 9
app/src/main/java/eu/faircode/email/FragmentAccounts.java View File

@ -25,9 +25,7 @@ import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.constraint.Group;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
@ -37,7 +35,7 @@ import android.widget.ProgressBar;
import java.util.List;
public class FragmentAccounts extends Fragment {
public class FragmentAccounts extends FragmentEx {
private RecyclerView rvAccount;
private ProgressBar pbWait;
private Group grpReady;
@ -48,6 +46,8 @@ public class FragmentAccounts extends Fragment {
@Override
@Nullable
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
setSubtitle(R.string.title_list_accounts);
View view = inflater.inflate(R.layout.fragment_accounts, container, false);
// Get controls
@ -93,10 +93,4 @@ public class FragmentAccounts extends Fragment {
return view;
}
@Override
public void onResume() {
super.onResume();
((AppCompatActivity) getActivity()).getSupportActionBar().setSubtitle(R.string.title_list_accounts);
}
}

+ 3
- 9
app/src/main/java/eu/faircode/email/FragmentCompose.java View File

@ -29,12 +29,10 @@ import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.constraint.Group;
import android.support.design.widget.BottomNavigationView;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.AsyncTaskLoader;
import android.support.v4.content.Loader;
import android.support.v7.app.AppCompatActivity;
import android.text.Html;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
@ -65,7 +63,7 @@ import javax.mail.internet.InternetAddress;
import static android.app.Activity.RESULT_OK;
public class FragmentCompose extends Fragment {
public class FragmentCompose extends FragmentEx {
private boolean once = false;
private String thread = null;
private long rid = -1;
@ -88,6 +86,8 @@ public class FragmentCompose extends Fragment {
@Override
@Nullable
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
setSubtitle(R.string.title_compose);
View view = inflater.inflate(R.layout.fragment_compose, container, false);
// Get arguments
@ -210,12 +210,6 @@ public class FragmentCompose extends Fragment {
return view;
}
@Override
public void onResume() {
super.onResume();
((AppCompatActivity) getActivity()).getSupportActionBar().setSubtitle(R.string.title_compose);
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.menu_message, menu);


+ 1
- 2
app/src/main/java/eu/faircode/email/FragmentEula.java View File

@ -24,13 +24,12 @@ import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
public class FragmentEula extends Fragment {
public class FragmentEula extends FragmentEx {
@Override
@Nullable


+ 42
- 0
app/src/main/java/eu/faircode/email/FragmentEx.java View File

@ -0,0 +1,42 @@
package eu.faircode.email;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.view.inputmethod.InputMethodManager;
public class FragmentEx extends Fragment {
private String subtitle = "";
protected void setSubtitle(int resid) {
setSubtitle(getString(resid));
}
protected void setSubtitle(String subtitle) {
this.subtitle = subtitle;
updateSubtitle();
}
@Override
public void onResume() {
super.onResume();
updateSubtitle();
}
@Override
public void onDetach() {
super.onDetach();
InputMethodManager im = getContext().getSystemService(InputMethodManager.class);
im.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}
private void updateSubtitle() {
AppCompatActivity activity = (AppCompatActivity) getActivity();
if (activity != null) {
ActionBar actionbar = activity.getSupportActionBar();
if (actionbar != null)
actionbar.setSubtitle(subtitle);
}
}
}

+ 3
- 9
app/src/main/java/eu/faircode/email/FragmentFolder.java View File

@ -25,11 +25,9 @@ import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.constraint.Group;
import android.support.v4.app.Fragment;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.AsyncTaskLoader;
import android.support.v4.content.Loader;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
@ -41,7 +39,7 @@ import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.Toast;
public class FragmentFolder extends Fragment {
public class FragmentFolder extends FragmentEx {
private CheckBox cbSynchronize;
private EditText etAfter;
private Button btnOk;
@ -51,6 +49,8 @@ public class FragmentFolder extends Fragment {
@Override
@Nullable
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
setSubtitle(R.string.title_edit_folder);
View view = inflater.inflate(R.layout.fragment_folder, container, false);
// Get arguments
@ -99,12 +99,6 @@ public class FragmentFolder extends Fragment {
return view;
}
@Override
public void onResume() {
super.onResume();
((AppCompatActivity) getActivity()).getSupportActionBar().setSubtitle(R.string.title_edit_folder);
}
private static class PutLoader extends AsyncTaskLoader<Throwable> {
private Bundle args;


+ 3
- 9
app/src/main/java/eu/faircode/email/FragmentFolders.java View File

@ -25,8 +25,6 @@ import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.constraint.Group;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
@ -37,7 +35,7 @@ import android.widget.Toast;
import java.util.List;
public class FragmentFolders extends Fragment {
public class FragmentFolders extends FragmentEx {
private RecyclerView rvFolder;
private ProgressBar pbWait;
private Group grpReady;
@ -48,6 +46,8 @@ public class FragmentFolders extends Fragment {
@Override
@Nullable
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
setSubtitle(R.string.title_list_folders);
View view = inflater.inflate(R.layout.fragment_folders, container, false);
// Get controls
@ -92,10 +92,4 @@ public class FragmentFolders extends Fragment {
return view;
}
@Override
public void onResume() {
super.onResume();
((AppCompatActivity) getActivity()).getSupportActionBar().setSubtitle(R.string.title_list_folders);
}
}

+ 3
- 9
app/src/main/java/eu/faircode/email/FragmentIdentities.java View File

@ -25,9 +25,7 @@ import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.constraint.Group;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
@ -37,7 +35,7 @@ import android.widget.ProgressBar;
import java.util.List;
public class FragmentIdentities extends Fragment {
public class FragmentIdentities extends FragmentEx {
private RecyclerView rvIdentity;
private ProgressBar pbWait;
private Group grpReady;
@ -48,6 +46,8 @@ public class FragmentIdentities extends Fragment {
@Override
@Nullable
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
setSubtitle(R.string.title_list_identities);
View view = inflater.inflate(R.layout.fragment_identities, container, false);
// Get controls
@ -93,10 +93,4 @@ public class FragmentIdentities extends Fragment {
return view;
}
@Override
public void onResume() {
super.onResume();
((AppCompatActivity) getActivity()).getSupportActionBar().setSubtitle(R.string.title_list_identities);
}
}

+ 3
- 9
app/src/main/java/eu/faircode/email/FragmentIdentity.java View File

@ -25,11 +25,9 @@ import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.TextInputLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.AsyncTaskLoader;
import android.support.v4.content.Loader;
import android.support.v7.app.AppCompatActivity;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
@ -54,7 +52,7 @@ import java.util.Properties;
import javax.mail.Session;
import javax.mail.Transport;
public class FragmentIdentity extends Fragment {
public class FragmentIdentity extends FragmentEx {
private List<Provider> providers;
private Spinner spProfile;
@ -75,6 +73,8 @@ public class FragmentIdentity extends Fragment {
@Override
@Nullable
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
setSubtitle(R.string.title_edit_identity);
View view = inflater.inflate(R.layout.fragment_identity, container, false);
// Get arguments
@ -188,12 +188,6 @@ public class FragmentIdentity extends Fragment {
return view;
}
@Override
public void onResume() {
super.onResume();
((AppCompatActivity) getActivity()).getSupportActionBar().setSubtitle(R.string.title_edit_identity);
}
private static class PutLoader extends AsyncTaskLoader<Throwable> {
private Bundle args;


+ 1
- 2
app/src/main/java/eu/faircode/email/FragmentMessage.java View File

@ -29,7 +29,6 @@ import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.constraint.Group;
import android.support.design.widget.BottomNavigationView;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.AsyncTaskLoader;
@ -66,7 +65,7 @@ import java.util.Locale;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class FragmentMessage extends Fragment {
public class FragmentMessage extends FragmentEx {
private TextView tvTime;
private TextView tvFrom;
private TextView tvTo;


+ 1
- 2
app/src/main/java/eu/faircode/email/FragmentMessages.java View File

@ -28,7 +28,6 @@ import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.constraint.Group;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.Fragment;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.AsyncTaskLoader;
import android.support.v4.content.Loader;
@ -44,7 +43,7 @@ import android.widget.TextView;
import java.util.List;
public class FragmentMessages extends Fragment {
public class FragmentMessages extends FragmentEx {
private RecyclerView rvMessage;
private TextView tvNoEmail;
private ProgressBar pbWait;


+ 3
- 9
app/src/main/java/eu/faircode/email/FragmentSetup.java View File

@ -27,10 +27,8 @@ import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -44,7 +42,7 @@ import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class FragmentSetup extends Fragment {
public class FragmentSetup extends FragmentEx {
private Button btnAccount;
private ProgressBar pbAccount;
private TextView tvAccountDone;
@ -69,6 +67,8 @@ public class FragmentSetup extends Fragment {
@Override
@Nullable
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
setSubtitle(R.string.title_setup);
View view = inflater.inflate(R.layout.fragment_setup, container, false);
// Get controls
@ -248,12 +248,6 @@ public class FragmentSetup extends Fragment {
return view;
}
@Override
public void onResume() {
super.onResume();
((AppCompatActivity) getActivity()).getSupportActionBar().setSubtitle(R.string.title_setup);
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
boolean has = (grantResults.length > 0);


+ 3
- 9
app/src/main/java/eu/faircode/email/FragmentWebView.java View File

@ -22,8 +22,6 @@ package eu.faircode.email;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -35,7 +33,7 @@ import android.widget.ProgressBar;
// https://developer.android.com/reference/android/webkit/WebView
public class FragmentWebView extends Fragment {
public class FragmentWebView extends FragmentEx {
private String url = null;
@Override
@ -58,6 +56,7 @@ public class FragmentWebView extends Fragment {
webview.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
setSubtitle(url);
return false;
}
});
@ -72,13 +71,8 @@ public class FragmentWebView extends Fragment {
url = getArguments().getString("link");
webview.loadUrl(url);
setSubtitle(url);
return view;
}
@Override
public void onResume() {
super.onResume();
((AppCompatActivity) getActivity()).getSupportActionBar().setSubtitle(url);
}
}

Loading…
Cancel
Save