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 / createFileFromInputStream.java
Last active September 5, 2018 01:40
create File From InputStream
private File createFileFromInputStream(InputStream inputStream,String fileName) {
String path = "";
File file = new File(Environment.getExternalStorageDirectory(),
"Files/");
if (!file.exists()) {
if (!file.mkdirs())
Log.d("Files", "Folder not created");
else
@osama-raddad
osama-raddad / file_from_raw.java
Created September 9, 2015 08:26
read file from raw
InputStream stream = mActivity.getResources().openRawResource(R.raw.file_name);
@osama-raddad
osama-raddad / RecyclerView.java
Created December 17, 2015 07:30
animate RecyclerView
public class CustomAdapter extends RecyclerView.Adapter<CustomAdapter.ViewHolder>
{
private Context context;
// The items to display in your RecyclerView
private ArrayList<String> items;
// Allows to remember the last item shown on screen
private int lastPosition = -1;
public static class ViewHolder extends RecyclerView.ViewHolder
@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 / new_gist_file.java
Created March 17, 2016 20:23
VideoView Form SD
VideoView videoView =(VideoView) findViewById(R.id.videoViewId);
Uri uri = Uri.parse(Environment.getExternalStorageDirectory().getAbsolutePath()+"/yourvideo");
videoView.setVideoURI(uri);
videoView.start();