Skip to content

Instantly share code, notes, and snippets.

View osama-raddad's full-sized avatar
💻
Working

Osama Raddad osama-raddad

💻
Working
View GitHub Profile
@osama-raddad
osama-raddad / Network.java
Last active January 7, 2016 13:51 — forked from showsky/Network.java
Network Info
public class Network {
public static DhcpInfo getNetworkInfo(Context context) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
android.net.NetworkInfo activeNetworkInfo = cm.getActiveNetworkInfo();
switch (activeNetworkInfo.getType()) {
case ConnectivityManager.TYPE_ETHERNET:
return null;
case ConnectivityManager.TYPE_WIFI:
@osama-raddad
osama-raddad / colors_material.xml
Created March 2, 2016 09:35
Material Design Colors ( Resources )
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Material Design Colors -->
<color name="md_red_50">#ffffebee</color>
<color name="md_red_100">#ffffcdd2</color>
<color name="md_red_200">#ffef9a9a</color>
<color name="md_red_300">#ffe57373</color>
<color name="md_red_400">#ffef5350</color>
@osama-raddad
osama-raddad / get phone number.java
Last active March 2, 2016 15:11
get phone number
//get phone number
TelephonyManager tm = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
String imei = tm.getDeviceId();
String tel = tm.getLine1Number();
@osama-raddad
osama-raddad / android-resources.md
Created March 2, 2016 15:55
[android] android resources

Some useful libraries, samples, tools

Forked from: Cesar Díez (https://github.com/cesards)

* In titles means it has been categorized more than once (in different categories)

LIBRARIES


@osama-raddad
osama-raddad / launchGoogleMaps.java
Last active March 7, 2016 09:41 — forked from ursimon/gist:6423907
Android launchGoogleMaps
private void launchGoogleMaps(String name, String vicinity) {
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?q="+name+","+vicinity));
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity"); // this is the magic
startActivity(intent);
}

Event Bus

(EventBus) - Android optimized event bus that simplifies communication between Activities, Fragments, Threads, Services, etc. Less code, better quality.

An EventBus is a great tool for decoupling components in your application. Over the next few posts I will describe the ways that I have been using it to make my code cleaner, easier to read, and easier to test. But first, this week I want to discuss why I use an EventBus in the first place. In particular, I will compare its use to some alternative techniques.

@osama-raddad
osama-raddad / README.md
Created May 18, 2016 14:25 — forked from polbins/README.md
Android Response Caching using Retrofit 1.9 + OkHttp 2.2

Android REST Controller with Cache-Control

Android REST Controller with Simple Cache Control Headers using Retrofit 1.9.0 + OkHttp 2.2.0

OkHttpClient client = new OkHttpClient();
Proxy proxy = new Proxy(Proxy.Type.HTTP, InetSocketAddress.createUnresolved("192.168.1.105", 8081);
client.setProxy(proxy);
@osama-raddad
osama-raddad / gist:30c2292037120ff4e4e0b81ba13427df
Created December 27, 2016 18:00 — forked from polbins/gist:437297ed7587c100e57d
Sample use of OkHttp + Retrofit Application Interceptor for Resending Requests w/ Refreshed Tokens
OkHttpClient okHttpClient = new OkHttpClient();
okHttpClient.interceptors().add(mRefreshAndRetryInterceptor);
mRestAdapter = new RestAdapter.Builder()
...
.setClient(new OkClient(okHttpClient))
.build();
private final Interceptor mRefreshAndRetryInterceptor = new Interceptor() {
@osama-raddad
osama-raddad / TwoWayBoundString.java
Created January 29, 2017 10:44 — forked from Nilzor/TwoWayBoundString.java
Tow-way data bound string, based on Blog by Fabio Colini
import android.databinding.BaseObservable;
import android.databinding.BindingAdapter;
import android.databinding.BindingConversion;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;
import java.io.Serializable;