Skip to content

Instantly share code, notes, and snippets.

Avatar

Ali Muzaffar alphamu

View GitHub Profile
@alphamu
alphamu / Android-TextViewWithFont.java
Last active Dec 29, 2015
A textview that can use a custom font without having to set it in code all the time
View Android-TextViewWithFont.java
public class TextViewWithFont extends TextView {
private Context mContext;
private String mFont;
public TextViewWithFont(Context context) {
super(context, null);
mContext = context;
init();
}
View activity_frosted_view.xml
<FrameLayout ...>
<ImageView
android:id="@+id/imgBg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/baking"/>
<ScrollView
@alphamu
alphamu / CallMultipartRequest.java
Last active Oct 26, 2017
An implementation of Request<String> for Google Volley which posts data using `multipart/form-data`. Volley by default uses `application/x-www-form-urlencoded` which may not be supported by all services.
View CallMultipartRequest.java
import com.android.volley.AuthFailureError;
import com.android.volley.NetworkResponse;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyLog;
import com.android.volley.toolbox.HttpHeaderParser;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
@alphamu
alphamu / android - SquareLinearLayout
Created Sep 16, 2013
Android LinearLayout with the same height as width.
View android - SquareLinearLayout
import android.content.Context;
import android.util.AttributeSet;
import android.widget.LinearLayout;
public class SquareLinearLayout extends LinearLayout {
public SquareLinearLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
@alphamu
alphamu / HorizontalBarView.java
Last active Apr 29, 2019
A View that displayers a horizontal bar like the kind that is used in a bar chart.
View HorizontalBarView.java
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.view.View;
@alphamu
alphamu / AbstractParcelDiskCache.java
Last active May 2, 2019 — forked from VladSumtsov/DiskCache
Encrypted persisted and cached Parcelable data disklrucache and facebook conceal on Android.
View AbstractParcelDiskCache.java
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
import com.facebook.android.crypto.keychain.SharedPrefsBackedKeyChain;
import com.facebook.crypto.Crypto;
@alphamu
alphamu / activity_frosted_toolbar.xml
Created Oct 13, 2016
Sample layout for frosted toolbar talk
View activity_frosted_toolbar.xml
<android.support.design.widget.CoordinatorLayout>
<ImageView
android:id="@+id/imgBgBlur"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/app_bar_height"
android:scaleType="matrix"
android:visibility="visible" />
@alphamu
alphamu / CalendarDayDifference.java
Last active May 4, 2019
Returns the difference between the provided date and now. The difference is in actual calendar days rather than time difference based. This means 01/Jan/2015 23:50 and 02/Jan/2015 00:01AM has a difference of 1 day.
View CalendarDayDifference.java
/**
* Returns the difference between the provided date and now.
* The difference is in actual calendar days rather than time difference based.
* This means 01/Jan/2015 23:50 and 02/Jan/2015 00:01AM has a difference of 1 day.
*
* @param date The date from which the difference to today has to be calculated.
* @return difference in calendar days.
*/
public static int getRealDayDifference(Date date) {
String timeString = null;
@alphamu
alphamu / BitmapUploadUsingSslHttpStack.java
Last active May 4, 2019
Simple implementation of SslHttpStack using Apache 4.2 api (compiled under a different package name so it doesn't conflict with Android). Using the SslHttpStack to upload bitmaps.
View BitmapUploadUsingSslHttpStack.java
HttpClient client = sslHttpStack.getmHttpClient();
HttpEntityEnclosingRequestBase entityRequest;
entityRequest = new HttpPost("http://my-server.com.au/my-api/customer/data");
MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create();
entityBuilder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
entityBuilder.addTextBody("someparameter", params.toString()); //params in this case is a JSONObject
String uniqueListingId = "images_to_upload"; //used to name any images being uploaded
int count = 0;
@alphamu
alphamu / Percentages expressed as HEX values
Last active May 4, 2019
Hexadecimal percentages from from 0 - 100 in increments of 5. These are particularly useful for alpha values in ARGB strings.
View Percentages expressed as HEX values
100% — FF
95% — F2
90% — E6
85% — D9
80% — CC
75% — BF
70% — B3
65% — A6
60% — 99
55% — 8C