This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static String getDecimalFormat(double value) { | |
String newValue = new DecimalFormat("#.##").format(value); | |
if (!newValue.contains(".")) { | |
return newValue + ".00"; | |
} else { | |
return newValue.split("\\.")[1].length() == 1 ? (newValue + "0") : newValue; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static double roundUp(double toRound) { | |
if (toRound % 100 == 0) return toRound; | |
double wholeNumber = toRound * 100; | |
double roundedValue = Math.ceil(wholeNumber / 10.0) * 10; | |
return roundedValue / 100; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void showError(Context context, ResponseBody responseBody) { | |
JSONObject jObjError = null; | |
try { | |
jObjError = new JSONObject(responseBody.string()); | |
} catch (Exception e) { | |
} | |
try { | |
JSONObject data = jObjError.getJSONObject("errors"); | |
Iterator<String> errorKeys = data.keys(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension StringCasingExtension on String { | |
String toCapitalized() => | |
length > 0 ? '${this[0].toUpperCase()}${substring(1).toLowerCase()}' : ''; | |
String toTitleCase() => replaceAll(RegExp(' +'), ' ') | |
.split(' ') | |
.map((str) => str.toCapitalized()) | |
.join(' '); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static LatLngBounds getBounds(List<LatLng> polylineCoordinates) { | |
double x0, x1, y0, y1; | |
for (LatLng latLng in polylineCoordinates) { | |
if (latLng.latitude != null && latLng.longitude != null) { | |
if (x0 == null) { | |
x0 = x1 = latLng.latitude; | |
y0 = y1 = latLng.longitude; | |
} else { | |
if (latLng.latitude > x1) x1 = latLng.latitude; | |
if (latLng.latitude < x0) x0 = latLng.latitude; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static List<LatLng> decodeEncodedPolyline(String encoded) { | |
List<LatLng> poly = []; | |
int index = 0, len = encoded.length; | |
int lat = 0, lng = 0; | |
while (index < len) { | |
int b, shift = 0, result = 0; | |
do { | |
b = encoded.codeUnitAt(index++) - 63; | |
result |= (b & 0x1f) << shift; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String packageNames = "cat,dog,cat,cow"; | |
var map = Map<String, int>(); | |
List<String> ps = []; | |
packageNames.split(",").forEach((element) { | |
if (!map.containsKey(element)) { | |
map[element] = 1; | |
} else { | |
map[element] = map[element]! + 1; | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// register receiver | |
IntentFilter filter = new IntentFilter("ABCD"); | |
registerReceiver(receiver, filter); | |
// reveicer | |
BroadcastReceiver receiver = new BroadcastReceiver() { | |
@Override | |
public void onReceive(Context context, Intent intent) { | |
try { | |
dialog.dismiss(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void hideKeyboard(Activity activity) { | |
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE); | |
//Find the currently focused view, so we can grab the correct window token from it. | |
View view = activity.getCurrentFocus(); | |
//If no view currently has focus, create a new one, just so we can grab a window token from it | |
if (view == null) { | |
view = new View(activity); | |
} | |
imm.hideSoftInputFromWindow(view.getWindowToken(), 0); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static File bitmapToFile(Bitmap bitmap) { | |
// File name like "image.png" | |
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); | |
String fileNameToSave = sdf.format(new Date()); | |
//create a file to write bitmap data | |
File file = null; | |
try { | |
file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + File.separator + fileNameToSave + ".png"); | |
file.createNewFile(); |
NewerOlder