Skip to content

Instantly share code, notes, and snippets.

View tolmachevroman's full-sized avatar

Roman Tolmachev tolmachevroman

  • Santiago, Chile
View GitHub Profile
@tolmachevroman
tolmachevroman / TestActivity.java
Last active August 29, 2015 14:14
Resumable file upload to Nginx powered server
public class TestActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sample);
if(!isUploading) {
// EditText view with file path
@tolmachevroman
tolmachevroman / Snippet.java
Last active August 29, 2015 14:14
Fit all the markers on the map
LatLngBounds.Builder builder = new LatLngBounds.Builder();
//mMarkers is a List<Marker> with your markers
for (Marker marker : mMarkers) {
builder.include(marker.getPosition());
}
LatLngBounds bounds = builder.build();
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngBounds(bounds, PADDING); //padding between screen borders and extreme right/left markers
@tolmachevroman
tolmachevroman / Manifest.xml
Created February 5, 2015 13:02
Open Url using custom Scheme
<!-- http://development.server.com/confirmations/eMkVMRppXUbV5F8Xd17W from browser address bar -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="development.server.com"
android:scheme="http" />
@tolmachevroman
tolmachevroman / BadRequestException.java
Created February 6, 2015 19:19
Custom Error Handler for Retrofit
public class BadRequestException extends Exception {
public BadRequestException() { super(); }
public BadRequestException(String message) { super(message); }
public BadRequestException(String message, Throwable cause) { super(message, cause); }
public BadRequestException(Throwable cause) { super(cause); }
}
@tolmachevroman
tolmachevroman / DrawPanel.java
Created February 6, 2015 19:23
Drawing view, allows to draw multicolor lines with finger
package com.test.app.widgets;
import java.util.ArrayList;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.util.AttributeSet;
@tolmachevroman
tolmachevroman / ToggleEditText.java
Last active April 26, 2024 11:01
Custom View for Toggle Edit Text
package com.test.app;
import com.test.app.R;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.CompoundButton;
@tolmachevroman
tolmachevroman / CameraPreview.java
Last active September 23, 2019 02:33
Camera Preview to render camera capture in real time + take photo + resize it + upload it to the server
import android.content.Context;
import android.hardware.Camera;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import java.io.IOException;
import java.util.List;
public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback {
@tolmachevroman
tolmachevroman / VideoFilesAdapter.java
Last active August 29, 2015 14:15
AsynTask loader for Video Thumbnails
///
///Your adapter code
///
public View getView(int position, View convertView, ViewGroup parent) {
//example of usage
//let holder.image be some ImageView, mContentUri some video file Uri
new VideoThumbnailLoader(getContext(), holder.image, MediaStore.Images.Thumbnails.MICRO_KIND).execute(mContentUri);
@tolmachevroman
tolmachevroman / DownloadProgressCounter.java
Last active December 14, 2023 17:39
Reflect DownloadManager progress of downloading multiple files in ProgressBar widget
/**
* Fetches how many bytes have been downloaded so far and updates ProgressBar
*/
class DownloadProgressCounter extends Thread {
private final long downloadId;
private final DownloadManager.Query query;
private Cursor cursor;
private int lastBytesDownloadedSoFar;
private int totalBytes;
@tolmachevroman
tolmachevroman / adb_internet_reboot.sh
Created July 2, 2015 14:11
This shell script allows you to emulate frequent connection drop outs on your device via ADB
for i in {1..5}
do
adb shell settings put global airplane_mode_on 1
adb shell am broadcast -a android.intent.action.AIRPLANE_MODE --ez state true
sleep $(( ( RANDOM % 10 ) + 10 ))
adb shell settings put global airplane_mode_on 0
adb shell am broadcast -a android.intent.action.AIRPLANE_MODE --ez state false
sleep $(( ( RANDOM % 10 ) + 10 ))
done