Changeset View
Changeset View
Standalone View
Standalone View
src/it/reyboz/bustorino/fragments/ScreenBaseFragment.java
- This file was moved from src/it/reyboz/bustorino/fragments/BaseFragment.java.
package it.reyboz.bustorino.fragments; | package it.reyboz.bustorino.fragments; | ||||
import android.content.Context; | import android.content.Context; | ||||
import android.content.SharedPreferences; | import android.content.SharedPreferences; | ||||
import android.view.View; | import android.view.View; | ||||
import android.view.inputmethod.InputMethodManager; | import android.view.inputmethod.InputMethodManager; | ||||
import android.widget.Toast; | import android.widget.Toast; | ||||
import androidx.annotation.Nullable; | |||||
import androidx.fragment.app.Fragment; | import androidx.fragment.app.Fragment; | ||||
import com.google.android.material.floatingactionbutton.FloatingActionButton; | |||||
import it.reyboz.bustorino.BuildConfig; | import it.reyboz.bustorino.BuildConfig; | ||||
import static android.content.Context.MODE_PRIVATE; | import static android.content.Context.MODE_PRIVATE; | ||||
public abstract class BaseFragment extends Fragment { | public abstract class ScreenBaseFragment extends Fragment { | ||||
protected String PREF_FILE= BuildConfig.APPLICATION_ID+".fragment_prefs"; | protected String PREF_FILE= BuildConfig.APPLICATION_ID+".fragment_prefs"; | ||||
protected void setOption(String optionName, boolean value) { | protected void setOption(String optionName, boolean value) { | ||||
Context mContext = getContext(); | Context mContext = getContext(); | ||||
SharedPreferences.Editor editor = mContext.getSharedPreferences(PREF_FILE, MODE_PRIVATE).edit(); | SharedPreferences.Editor editor = mContext.getSharedPreferences(PREF_FILE, MODE_PRIVATE).edit(); | ||||
editor.putBoolean(optionName, value); | editor.putBoolean(optionName, value); | ||||
editor.commit(); | editor.commit(); | ||||
} | } | ||||
protected boolean getOption(String optionName, boolean optDefault) { | protected boolean getOption(String optionName, boolean optDefault) { | ||||
Context mContext = getContext(); | Context mContext = getContext(); | ||||
SharedPreferences preferences = mContext.getSharedPreferences(PREF_FILE, MODE_PRIVATE); | SharedPreferences preferences = mContext.getSharedPreferences(PREF_FILE, MODE_PRIVATE); | ||||
return preferences.getBoolean(optionName, optDefault); | return preferences.getBoolean(optionName, optDefault); | ||||
} | } | ||||
protected void showToastMessage(int messageID, boolean short_lenght) { | protected void showToastMessage(int messageID, boolean short_lenght) { | ||||
final int length = short_lenght ? Toast.LENGTH_SHORT : Toast.LENGTH_LONG; | final int length = short_lenght ? Toast.LENGTH_SHORT : Toast.LENGTH_LONG; | ||||
Toast.makeText(getContext(), messageID, length).show(); | Toast.makeText(getContext(), messageID, length).show(); | ||||
} | } | ||||
public void hideKeyboard() { | public void hideKeyboard() { | ||||
if (getActivity()==null) return; | |||||
View view = getActivity().getCurrentFocus(); | View view = getActivity().getCurrentFocus(); | ||||
if (view != null) { | if (view != null) { | ||||
((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE)) | ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE)) | ||||
.hideSoftInputFromWindow(view.getWindowToken(), | .hideSoftInputFromWindow(view.getWindowToken(), | ||||
InputMethodManager.HIDE_NOT_ALWAYS); | InputMethodManager.HIDE_NOT_ALWAYS); | ||||
} | } | ||||
} | } | ||||
/** | |||||
* Find the view on which the snackbar should be shown | |||||
* @return | |||||
*/ | |||||
@Nullable | |||||
public abstract View getBaseViewForSnackBar(); | |||||
} | } |
Public contents are in Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) or GNU Free Documentation License (at your option) unless otherwise noted. · Contact / Register