Skip to content

Instantly share code, notes, and snippets.

View eneim's full-sized avatar
😀
the simple, the best

Nam Nguyen eneim

😀
the simple, the best
View GitHub Profile
@eneim
eneim / ENESquareImageView.java
Created July 7, 2014 00:41
Custom Square ImageView
/**
* A custom {@link ImageView} that is sized to be a perfect square, otherwise
* functions like a typical {@link ImageView}.
*
* @author Andrew Neal (andrewdneal@gmail.com)
*/
public class ENESquareImageView extends ImageView {
/**
* @param context
@eneim
eneim / themes.xml
Created November 19, 2014 08:57
official themes.xml from Android-21 API. I create a gist here for easily looking up Android theme's attribute names
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2006 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
@eneim
eneim / MainActivity.java
Created December 12, 2014 23:51
Sample Acitivty that uses Location API, Activity Recognition API
/*
* Copyright (C) 2013 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@eneim
eneim / ActivityRecognitionReceiverIntentService.java
Created December 12, 2014 23:51
IntentService that process the Activity Recognition Response/Result
package im.ene.lab.hakkify;
import android.app.IntentService;
import android.content.Intent;
import android.text.format.DateFormat;
import android.util.Log;
import com.google.android.gms.location.ActivityRecognitionResult;
import com.google.android.gms.location.DetectedActivity;
@eneim
eneim / MainActivity.java
Created December 27, 2014 03:32
update location and get address by GoogleApiClient
package im.ene.lab.androidlocation;
import android.content.Context;
import android.location.Address;
import android.location.Geocoder;
import android.location.Location;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
private void shareFacebook(String text)
{
String packageName = "com.facebook.katana";
String activityName = null;
// 該当パッケージをもつアプリで、ACTION_SENDに対応しているactivityを取得する
// 暗黙的インテントで表示されるリストから該当のアプリを探し出すという感じ
PackageManager pm = getPackageManager();
Intent intent = new Intent( Intent.ACTION_SEND );
intent.setType("text/plain");
private class DownloadTask extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... urls) {
HttpResponse response = null;
HttpGet httpGet = null;
HttpClient mHttpClient = null;
String s = "";
// check if the url is invalid
@eneim
eneim / gist:e4e630d372f98dc27de4
Created February 2, 2015 02:44
Android check Internet connection
public static boolean isNetworkAvailable(Context context) {
return ((ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo() != null;
}
Usage
if (isNetworkAvailable(context)) {
// available network
} else {
// no network
@eneim
eneim / gist:2260655317867e40369a
Created February 23, 2015 03:37
Japanese Phone regex
With hyphens:
^(0([1-9]{1}-?[1-9]\d{3}|[1-9]{2}-?\d{3}|[1-9]{2}\d{1}-?\d{2}|[1-9]{2}\d{2}-?\d{1})-?\d{4}|0[789]0-?\d{4}-?\d{4}|050-?\d{4}-?\d{4})$
Without hyphens:
^(0([1-9]{1}[1-9]\d{3}|[1-9]{2}\d{3}|[1-9]{2}\d{1}\d{2}|[1-9]{2}\d{2}\d{1})\d{4}|0[789]0\d{4}\d{4}|050\d{4}\d{4})$
Source: https://github.com/sakatam/a-better-jp-phone-regex

##Getting results from DialogFragments to another Fragment.

When setting up the DialogFragment make a call to Fragment.setTargetFragment()
Then from DialogFragment you can access the main fragment with Fragment.getTargetFragment()
Use interfaces to provide the required actions to the calling Fragment.

##Example code.

###AddFriendDialogFragment - Calls back to calling fragment.