Skip to content

Instantly share code, notes, and snippets.

View msomu's full-sized avatar

Somasundaram M msomu

View GitHub Profile
@msomu
msomu / fragments.java
Created April 21, 2015 10:31
This is used to find the number of fragments that are on the current activity
@Override
public void onBackPressed() {
//for testing purpose
//returns the number of fragments on the Activity
int count = fragmentManager.getBackStackEntryCount();
//displays the fragments that are present on the activity with their names
for (int i=count-1;i>=0;i--){
String name = fragmentManager.getBackStackEntryAt(i).getName();
Config.l("Count :"+i+" name :"+name);
}
@msomu
msomu / actionbar_gradient_dark.xml
Created September 25, 2015 18:27
A gist for showing textview on the Image view, this util is for giving grey background to the image
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<gradient
android:angle="90"
android:endColor="@android:color/transparent"
android:startColor="@android:color/black" />
<corners android:radius="0dp" />
</shape>
@msomu
msomu / Class.java
Created September 25, 2015 20:09
A small time util to convert TimeStamp into momments ago
public void setTime(String time) {
if (!TextUtils.isEmpty(time)) {
CharSequence relativeTimeSpanString = DateUtils.getRelativeTimeSpanString(Long.valueOf(time), System.currentTimeMillis(), DateUtils.SECOND_IN_MILLIS, DateUtils.FORMAT_ABBREV_RELATIVE);
this.time = relativeTimeSpanString.toString();
} else {
this.time = "";
}
}
@msomu
msomu / URIBuilder.java
Created October 6, 2015 18:43
this is how url should be appended
// Will contain the raw JSON response as a string.
String forecastJsonStr = null;
String format = "json";
String units = "metric";
int numDays = 7;
// Construct the URL for the OpenWeatherMap query
// Possible parameters are avaiable at OWM's forecast API page, at
// http://openweathermap.org/API#forecast
@msomu
msomu / layout.xml
Created October 7, 2015 12:06
Edit Text will automatically make the first letter capital
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@android:color/transparent"
android:focusable="true"
android:gravity="top"
android:hint="@string/post_update"
android:inputType="textCapSentences"
@msomu
msomu / class.java
Created October 28, 2015 14:38
make a textview link
String str_text = "<a href=http://www.google.com >Google</a>";
textView.setMovementMethod(LinkMovementMethod.getInstance());
textView.setText(Html.fromHtml(str_text));
textView.setLinkTextColor(Color.BLUE);
@msomu
msomu / Adapter.java
Created November 3, 2015 17:35
This gist will show you how to make staggeredgridlayout with images height fixed.
@Override
public void onBindViewHolder(ViewHolderDetail holder, int position) {
DataModel item = items.get(position);
if (item.getHeight() != 0 && item.getWidth() != 0) {
float width = activity.getWindowManager().getDefaultDisplay().getWidth();
float margin = ConvertionUtil.convertDpToPixel(8, activity);
width = (width - (3 * margin)) / 2;
float i = width / ((float) item.getWidth());
float imageHeight = i * (item.getHeight());
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) holder.image.getLayoutParams();
@msomu
msomu / ValidateUtils.java
Last active December 2, 2015 07:46
My Validate Utils
import android.app.Activity;
import android.support.design.widget.TextInputLayout;
import android.view.View;
import android.view.WindowManager;
import android.widget.EditText;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@msomu
msomu / angular.js
Created January 28, 2016 14:39
Angular HttpService
// Simple GET request example:
$http({
method: 'GET',
url: '/someUrl'
}).then(function successCallback(response) {
// this callback will be called asynchronously
// when the response is available
}, function errorCallback(response) {
// called asynchronously if an error occurs
// or server returns response with an error status.
@msomu
msomu / Image.java
Created February 2, 2016 11:51
Image
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.net.Uri;
import android.util.Log;
import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;