Skip to content

Instantly share code, notes, and snippets.

View esabook's full-sized avatar
🛰️
Seeking planet

esabook

🛰️
Seeking planet
View GitHub Profile
@esabook
esabook / __Utils.java
Created May 14, 2019 03:53
hide soft keyboard
/**
* @param v
*/
public static void hideKeyboard(View v) {
if (v == null || v.getContext() == null) return;
InputMethodManager imm = (InputMethodManager)
v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null && imm.isAcceptingText()) {
imm.hideSoftInputFromWindow(v.getRootView().getWindowToken(), 0);
@esabook
esabook / StringDeserializer.java
Created May 15, 2019 15:05
gson string deserializer
public class StringDeserializer implements JsonDeserializer<String> {
@Override
public String deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
if (json.isJsonObject()) {
return json.toString();
} else {
return json.getAsString();
}
}
}
@esabook
esabook / __FragmentWebBrowser.java
Created May 15, 2019 15:08
setup monitored webview
protected void setupWebview() {
webChromeClient = new WebChromeClient() {
@Override
public void onProgressChanged(WebView view, int newProgress) {
super.onProgressChanged(view, newProgress);
boolean onGoing = newProgress != 100;
vBinding.setOnGoing(onGoing);
vBinding.action.setImageResource(onGoing ? R.drawable.ic_cancel : R.drawable.ic_refresh);
vBinding.setCanBack(view.canGoBack());
vBinding.setCanForward(view.canGoForward());
@esabook
esabook / __ResponseDTO.java
Created May 15, 2019 15:09
generic object mapper, REST pattern
////TODO: change to generic T model
public class __ResponseDTO<T>{
public T data;
public String ContinuationToken;
public Boolean status;
public String msg;
}
@esabook
esabook / __IReportService.kt
Created May 15, 2019 15:11
retrofit with filterable query
interface __IReportService {
@GET("ticket/list")
fun getReports(@QueryMap(encoded = true) queries: ReportQuery): Call<__ResponseDTO<Array<__ReportDTO>>>
@POST("ticket/create")
fun postReport(@Body body: __ReportDTO): Call<__ResponseDTO<__ReportDTO>>
@POST("ticket/{ticketId}/update")
fun postUpdateReport(@Path("ticketId") ticketiId: String, @Body body: __ReportDTO): Call<__ResponseDTO<__ReportDTO>>
@esabook
esabook / __GlobalApp.java
Created May 15, 2019 15:13
targetting distibution group of appcenter.ms
/**
*
*/
void initAppCenter() {
// setup app center for crashlytics
Distribute.setListener(new __UpdateListener());
AppCenter.start(this, APPCENTER_SECRET_KEY, Analytics.class, Crashes.class, Distribute.class);
AppCenter.setEnabled(!BuildConfig.DEBUG);
SharedPreferencesManager.initialize(this);
@esabook
esabook / BatteryScanActivity.java
Created May 15, 2019 15:16
get current android orientation
private int getCurrentOrientation() {
int rotation = getWindowManager().getDefaultDisplay().getRotation();
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
switch (rotation) {
case Surface.ROTATION_0:
case Surface.ROTATION_90:
return ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
default:
return ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
}
@esabook
esabook / __WalletSwitcherDialogFragment.java
Created May 15, 2019 15:30
bootom sheet fragment BottomSheetBehavior
/**
* @param dialog
*/
protected void setupDialogBehavior(Dialog dialog) {
dialog.setOnShowListener(dialog1 -> {
BottomSheetDialog d = (BottomSheetDialog) dialog;
View v = d.findViewById(android.support.design.R.id.design_bottom_sheet);
if (v != null) {
@esabook
esabook / __ReportDetail.java
Created May 15, 2019 15:34
access Android local image
@Override
public void onAddAttachments() {
boolean shouldShowReqPermission = !ActivityCompat.shouldShowRequestPermissionRationale(
__GlobalApp.getActivity(),
Manifest.permission.READ_EXTERNAL_STORAGE);
boolean isNeedPermission = ActivityCompat.checkSelfPermission(getActivity(),
Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED;
// dialog request permission
if (isNeedPermission) {
@esabook
esabook / __ReportDetail.java
Created May 15, 2019 15:36
send Android local image as web-form for retrofit
void sendImage(String uriString) {
Uri selectedImage = Uri.parse(uriString);
String[] filePathColumn = {MediaStore.Images.Media.DATA};
// Get the cursor
Cursor cursor = getActivity().getContentResolver().query(selectedImage, filePathColumn, null, null, null);
if (cursor == null) return;
// Move to first row
cursor.moveToFirst();
//Get the column index of MediaStore.Images.Media.DATA
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);