Skip to content

Instantly share code, notes, and snippets.

public class ThreadingService {
private final Threader networkService;
private final Threader serialQueue;
private final Threader hsuiThreader;
private final Object syncLock = new Object();
public ThreadingService(Threader networkThreader, Threader serialQueue, Threader uiThreader) {
this.networkService = networkThreader;
this.serialQueue = serialQueue;
this.hsuiThreader = uiThreader;
public HSDownloaderResponse downloadResource(String url, Map<String, String> headers,
File saveToFile) {
boolean isSuccess = false;
int status = 404;
String mimetype = "";
String encoding = "utf-8";
String etag = "";
JSONObject responseHeadersJSON = new JSONObject();
FileOutputStream fos = null;
try {
public HSResponse makeRequest(HSRequest request) {
HttpsURLConnection connection = null;
OutputStream outputStream = null;
InputStream errorStream = null;
InputStream inputStream = null;
try {
connection = (HttpsURLConnection) new URL(request.getUrl()).openConnection();
connection.setRequestMethod(request.getMethod().name());
connection.setConnectTimeout(request.getTimeout());
for (Map.Entry<String, String> header : request.getHeaders().entrySet()) {
@smdevidan
smdevidan / webviewcache.java
Last active December 7, 2021 11:02
Webview caching logic
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
// Only cache GET calls
if (!"GET".equalsIgnoreCase(request.getMethod())) {
return super.shouldInterceptRequest(view, request);
}
// Init the cache config, fetch from network if not done already
List<String> urls = initCacheConfig();
@smdevidan
smdevidan / config.json
Last active December 7, 2021 10:17
Cache config example
{
ttl: 1234567890
urls: [
{
path:"/abc/content/abc.js"
ttl:1234567890
},
{
path:"/abc/content/efg.css"
ttl:1234567890
@smdevidan
smdevidan / AdjustablePillsInflator.java
Created July 5, 2020 15:01
Adjustable pills inflater
public void inflate(Context context,
double maxAvailableWidthScaleFactor,
LinearLayout containerView,
int selectOptionInflaterLayout,
int optionTextViewId,
List<String> pillTitles,
View.OnClickListener optionSelectionListener) {
List<LinearLayout> layouts = new ArrayList<>();
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="8dp">
<com.helpshift.views.HSTextView
android:id="@+id/selectable_option_text"
android:layout_width="wrap_content"