FairEmail/app/src/main/java/eu/faircode/email/FragmentEx.java

89 lines
2.6 KiB
Java
Raw Normal View History

package eu.faircode.email;
2018-08-11 16:13:22 +00:00
import android.content.res.Configuration;
import android.os.Bundle;
import android.util.Log;
2018-08-12 17:51:57 +00:00
import android.view.LayoutInflater;
2018-08-06 08:39:28 +00:00
import android.view.View;
2018-08-12 17:51:57 +00:00
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
2018-08-08 06:55:47 +00:00
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
public class FragmentEx extends Fragment {
2018-08-06 12:05:43 +00:00
private String subtitle = " ";
protected void setSubtitle(int resid) {
setSubtitle(getString(resid));
}
protected void setSubtitle(String subtitle) {
this.subtitle = subtitle;
updateSubtitle();
}
2018-08-11 16:13:22 +00:00
@Override
public void onCreate(Bundle savedInstanceState) {
Log.i(Helper.TAG, "Create " + this.getClass().getName());
super.onCreate(savedInstanceState);
}
2018-08-12 17:51:57 +00:00
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Log.i(Helper.TAG, "Create view " + this.getClass().getName());
return super.onCreateView(inflater, container, savedInstanceState);
}
2018-08-11 16:13:22 +00:00
@Override
public void onActivityCreated(Bundle savedInstanceState) {
Log.i(Helper.TAG, "Activity " + this.getClass().getName());
super.onActivityCreated(savedInstanceState);
}
@Override
public void onResume() {
2018-08-11 16:13:22 +00:00
Log.i(Helper.TAG, "Resume " + this.getClass().getName());
super.onResume();
updateSubtitle();
}
2018-08-11 16:13:22 +00:00
@Override
public void onPause() {
Log.i(Helper.TAG, "Pause " + this.getClass().getName());
super.onPause();
}
@Override
public void onDetach() {
super.onDetach();
InputMethodManager im = getContext().getSystemService(InputMethodManager.class);
2018-08-06 12:05:43 +00:00
View focused = getActivity().getCurrentFocus();
if (focused != null)
im.hideSoftInputFromWindow(focused.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}
2018-08-11 16:13:22 +00:00
@Override
public void onConfigurationChanged(Configuration newConfig) {
Log.i(Helper.TAG, "Config " + this.getClass().getName());
super.onConfigurationChanged(newConfig);
}
@Override
public void onDestroy() {
Log.i(Helper.TAG, "Destroy " + this.getClass().getName());
super.onDestroy();
}
private void updateSubtitle() {
AppCompatActivity activity = (AppCompatActivity) getActivity();
if (activity != null) {
ActionBar actionbar = activity.getSupportActionBar();
if (actionbar != null)
actionbar.setSubtitle(subtitle);
}
}
}