Changeset View
Changeset View
Standalone View
Standalone View
src/it/reyboz/bustorino/middleware/GeneralActivity.java
Show First 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | public abstract class GeneralActivity extends AppCompatActivity { | ||||
public void hideKeyboard() { | public void hideKeyboard() { | ||||
View view = getCurrentFocus(); | View view = getCurrentFocus(); | ||||
if (view != null) { | if (view != null) { | ||||
((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)) | ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)) | ||||
.hideSoftInputFromWindow(view.getWindowToken(), | .hideSoftInputFromWindow(view.getWindowToken(), | ||||
InputMethodManager.HIDE_NOT_ALWAYS); | InputMethodManager.HIDE_NOT_ALWAYS); | ||||
} | } | ||||
} | } | ||||
public boolean isConnected() { | |||||
ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); | |||||
NetworkInfo networkInfo = connMgr.getActiveNetworkInfo(); | |||||
return networkInfo != null && networkInfo.isConnected(); | |||||
} | |||||
public void showToastMessage(int messageID, boolean short_lenght) { | public 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(getApplicationContext(), messageID, length).show(); | Toast.makeText(getApplicationContext(), messageID, length).show(); | ||||
} | } | ||||
public void assertLocationPermissions() { | |||||
if(ContextCompat.checkSelfPermission(getApplicationContext(),Manifest.permission.ACCESS_FINE_LOCATION)!=PackageManager.PERMISSION_GRANTED){ | |||||
ActivityCompat.requestPermissions(this,new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, PERMISSION_REQUEST_POSITION); | |||||
} | |||||
} | |||||
public int askForPermissionIfNeeded(String permission, int requestID){ | public int askForPermissionIfNeeded(String permission, int requestID){ | ||||
if(ContextCompat.checkSelfPermission(getApplicationContext(),permission)==PackageManager.PERMISSION_GRANTED){ | if(ContextCompat.checkSelfPermission(getApplicationContext(),permission)==PackageManager.PERMISSION_GRANTED){ | ||||
return PERMISSION_OK; | return PERMISSION_OK; | ||||
} | } | ||||
//need to ask for the permission | //need to ask for the permission | ||||
//consider scenario when we have already asked for permission | //consider scenario when we have already asked for permission | ||||
boolean alreadyAsked = false; | boolean alreadyAsked = false; | ||||
▲ Show 20 Lines • Show All 45 Lines • Show Last 20 Lines |
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