Skip to content

Instantly share code, notes, and snippets.

@ayushhgoyal
ayushhgoyal / test_gcm.php
Last active October 1, 2015 15:46 — forked from phpfiddle/fiddle_090817.php
[ Posted by Ayush ] This is php code to test android push notifications (GCM) online. Just replace API key and device ids. It will send a notification with key "alert". It can be executed here: http://phpfiddle.org/main/code/c12cf0475e97f3cf19c1 (Shortcut: F9)
<?php
// API access key from Google API's Console
define( 'API_ACCESS_KEY', 'AIzaSyDD5cwKE6O252bVA766Lyo2cQhG7RbShWA' );
$registrationIds = array("erKXJiDIdiY:APA91bE3N0Bfh6e7tpIT2qcHBD_vqg6ObMQHyrbXEAf6MQqeHcGSauArLzoQRvWb7VpHY_hReEdfw3WxU5Ybk95dWnGT2KAQmC9cHAajuDQx5kJu1Ic2QJKuu3vYNtuRAo6edfuMrbJj" );
// prep the bundle
@ayushhgoyal
ayushhgoyal / RelativeTimeStamp.java
Created September 14, 2015 15:46
Time converter utility that converts date object into smaller and relative time stamps like 2s, 2m, 4h and so on.
package com.dbws.fk.utils;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
/**
* Created by ayush on 14/9/15.
*/
@ayushhgoyal
ayushhgoyal / Custom Gradle Build Script for exporting APKs with svn version in name
Last active September 1, 2015 07:43
Using this snippet in gradle will copy the apk to dropbox folder (you can change the path wherever you want it to export) and renames it with current svn revision of the project. Add this in "buildTypes" - parallel to "dependencies".
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
applicationVariants.all { variant ->
variant.outputs.each { output ->
def outputFile = output.outputFile
// println()
@ayushhgoyal
ayushhgoyal / ShpUtil.java
Created July 20, 2015 07:28
This class can be used to perform SharedPref operations without writing boiler plate code.
package com.dbws.cm.utils;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.util.Log;
/**
* Created by ayushhgoyal on 3/2/15.
*/
@ayushhgoyal
ayushhgoyal / Facebook.java
Created January 10, 2015 08:20
Get User Info From Facebook (after setting up sdk and key hash)
private static Session openActiveSession(Activity activity,
boolean allowLoginUI, Session.StatusCallback statusCallback) {
OpenRequest openRequest = new OpenRequest(activity);
openRequest.setPermissions(Arrays.asList("user_birthday", "email", "user_location"));
openRequest.setCallback(statusCallback);
Session session = new Session.Builder(activity).build();
if (SessionState.CREATED_TOKEN_LOADED.equals(session.getState())
|| allowLoginUI) {
@ayushhgoyal
ayushhgoyal / LogWrapper.java
Created December 15, 2014 11:33
Awesome logcat
package com.dbws.golf2.util;
import android.util.Log;
/**
* Created by ayushhgoyal on 16/11/14.
*/
public class LogWrapper {
static String className;
@ayushhgoyal
ayushhgoyal / VisibilityUtil.java
Created September 5, 2014 11:43
This utility class allows to change visibility of multiple views in one call.
public class VisibilityUtil {
public static void setViewVisible(View... views) {
for (View v : views) {
v.setVisibility(View.VISIBLE);
}
}
public static void setViewGone(View... views) {
for (View v : views) {
@ayushhgoyal
ayushhgoyal / CustomRequest.java
Last active April 21, 2022 15:30
Custom Volley Request
public class CustomRequest extends Request<JSONObject> {
private Response.Listener<JSONObject> listener;
private Map<String, String> params;
private ProgressDialog progressDialog;
private Context context;
public ProgressDialog getProgressDialog() {
return progressDialog;
}
@ayushhgoyal
ayushhgoyal / ShrinkableTextView.java
Last active January 4, 2016 19:09
These files can be used to implement shrinkable textviews in android projects, textview will change its textSize according to the length of data being set in textview. Values are supposed to be played with.
public class ShrinkableTextView extends TextView {
public ShrinkableTextView(Context context) {
super(context);
}
public ShrinkableTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
@ayushhgoyal
ayushhgoyal / ChangeEditTextBackground
Created September 26, 2013 14:10
Change background of an Edittext. Changing EditText background with normal properties makes it horrible..use this one line code to change it.
<your-widget-component-that-has-a-background-color>.getBackground().setColorFilter(Color.<your-desired-color>, PorterDuff.Mode.MULTIPLY);