Skip to content

Instantly share code, notes, and snippets.

View PrashamTrivedi's full-sized avatar
🏠
Working from home

Prasham Trivedi PrashamTrivedi

🏠
Working from home
View GitHub Profile
@PrashamTrivedi
PrashamTrivedi / studio_alternate.sh
Last active December 19, 2015 10:18
Android Studio's alternative launcher script which bypasses the requirement to have JAVA_HOME set as path.
#!/bin/sh
#
# ---------------------------------------------------------------------
# Android Studio startup script.
# ---------------------------------------------------------------------
#
message()
{
TITLE="Cannot start Android Studio"
@PrashamTrivedi
PrashamTrivedi / AppExternalFileWriter.java
Last active February 25, 2023 06:45
File writer that helps you to write files in your own applocation directory in SD Card
package com.phtrivedi.opensource.externalfilewriter;
import android.content.Context;
import android.os.Environment;
import android.os.StatFs;
import android.text.TextUtils;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
@PrashamTrivedi
PrashamTrivedi / build_publish.gradle
Created August 27, 2013 11:32
Gradle code to publish an artifact in maven local and local file repository (So that it can be added to other maven project later)
apply plugin: 'maven-publish'
group = 'grpId'
version = '1.0.1-SNAPSHOT'
android.libraryVariants
publishing {
publications {
@PrashamTrivedi
PrashamTrivedi / android embed tabs
Created December 3, 2013 03:29
android : Embed tabs as a part of actionbar.... as done in shazaam apps
//In onCreate after initializing actionbar
int currentapiVersion = android.os.Build.VERSION.SDK_INT;
if (currentapiVersion >= VERSION_CODES.ICE_CREAM_SANDWICH) {
// Do something for froyo and above versions
try {
Field actionBarField = actionBar.getClass().getDeclaredField("mActionBar");
actionBarField.setAccessible(true);
enableEmbeddedTabs(actionBarField.get(actionBar));
} catch (Exception e) {
Log.e(TAG, "Error enabling embedded tabs", e);
@PrashamTrivedi
PrashamTrivedi / KitkatFilesHandler.java
Last active June 17, 2017 16:04
FilePicker Kitkat
package com.zoomimob_faculty.utils;
import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.os.Environment;
import android.provider.DocumentsContract;
// more information here: http://blog.tomtasche.at/2012/10/use-built-in-feedback-mechanism-on.html
try {
int i = 3 / 0;
} catch (Exception e) {
ApplicationErrorReport report = new ApplicationErrorReport();
report.packageName = report.processName = getApplication()
.getPackageName();
report.time = System.currentTimeMillis();
report.type = ApplicationErrorReport.TYPE_CRASH;
@PrashamTrivedi
PrashamTrivedi / gradle file for client module
Last active August 29, 2015 14:04
Files I use to build the project, Includes VMOptions and gradle files.
apply plugin: 'com.android.application'
repositories {
maven {
url 'http://google-api-client-libraries.appspot.com/mavenrepo'
}
mavenCentral()
mavenLocal()
}
@PrashamTrivedi
PrashamTrivedi / AnalyticsLogger.java
Created August 22, 2014 02:58
Wrapper Class to work with google analytics.
package com.celites.wishnu.utils;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.SharedPreferences;
import android.util.DisplayMetrics;
import com.celites.wishnu.R;
<link rel="import" href="../core-icon-button/core-icon-button.html">
<link rel="import" href="../core-toolbar/core-toolbar.html">
<polymer-element name="my-element">
<template>
<style>
:host {
position: absolute;
width: 100%;
@PrashamTrivedi
PrashamTrivedi / CommaEllipsizeDemo.java
Last active August 29, 2015 14:20
TextUtils class
/**
* This is to demo comma ellipsize
* Output will be: 2014 fifa worldcup quarterfinalists were Germany,Argentina,Netherlands,Brasil and 4 more
*/
private void commaEllipsizeDemo(TextView text) {
//Following is the original text, which will be ellipsied
final String string = "Germany,Argentina,Netherlands,Brasil,France,Belgium,Costa Rica,Colombia";
//Fetch the textpaint from above text
final TextPaint paint = text.getPaint();
//Following is the text which will be shown anyway.