Skip to content

Instantly share code, notes, and snippets.

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

Eduardo José Medina Alfaro emedinaa

🏠
Working from home
View GitHub Profile
@emedinaa
emedinaa / gist:6732449
Created September 27, 2013 17:56
Force close Android Application
protected void exitApp() {
// force close app
android.os.Process.killProcess(android.os.Process.myPid());
}
@emedinaa
emedinaa / android convert dp to pixel
Created October 4, 2013 03:10
Convert dp to Pixel and px to DP
public static int dpToPx(int dp)
{
return (int) (dp * Resources.getSystem().getDisplayMetrics().density);
}
public static int pxToDp(int px)
{
return (int) (px / Resources.getSystem().getDisplayMetrics().density);
}
@emedinaa
emedinaa / android_string
Last active August 29, 2015 14:10
android display double quotes(")
//http://unicode-table.com/es/
String message = "esto es un "+'\u0022'+"hola"+'\u0022';
System.out.println("message "+message);
Log.i("CONSOLE", "message "+message);
//output
message esto es un "hola"
@emedinaa
emedinaa / Example Butter Knife
Created December 23, 2014 20:35
Example Butter Knife
// http://jakewharton.github.io/butterknife/
//activity
public class MyActivity extends Activity
{
@InjectView(R.id.ibuClose) ImageButton ibuClose;
@InjectView(R.id.lviMyAlerts) ListView lviMyAlerts;
@Override
protected void onCreate(Bundle savedInstanceState)
{
@emedinaa
emedinaa / Example AsyncTaskLoader
Last active August 29, 2015 14:12
Example AsyncTaskLoader
public class MyLoader extends AsyncTaskLoader<String> {
boolean isLoading = false;
String result =null;
public PromotionsLoader(Context context)
{
super(context);
connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
@emedinaa
emedinaa / Example WebServices
Created December 23, 2014 20:59
Example WebServices
@Override
public String loadInBackground() {
if(NetworkConnectivityUtils.hasNetworkConnectivity(connectivityManager))
{
MyEntity entity = new MyEntity();
Gson gson = new Gson();
String json = gson.toJson(entity);
request = new SoapObject(NAMESPACE, METHOD_NAME);
@emedinaa
emedinaa / Intent Google Maps
Created June 26, 2015 16:51
Cuando quieren lanzar al mapa ,agregar un marcador con un Intent y te devuelve un error.
public static void launchGoogleMaps(Context context, double latitude, double longitude) {
String coordinates = "http://maps.google.com/maps?daddr=" + latitude + "," + longitude;
Intent intent = new Intent( Intent.ACTION_VIEW, Uri.parse(coordinates) );
context.startActivity(intent );
}
@emedinaa
emedinaa / gist:f5b46c9a7ee4cd7e24a8
Created June 26, 2015 20:38
Pasar información desde un listview a otra actividad
private void populateData()
{
MyAdapter adapter= new MyAdapter(getActivity(),reqMyEntityList);
lviRequest.setAdapter(adapter);
lviRequest.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
MyEntity myEntity= (MyEntity)adapterView.getAdapter().getItem(i);
gotoActivity(myEntity);
@emedinaa
emedinaa / gist:45d673e19c6b8754d33a
Created June 26, 2015 20:48
Cambiar fragments y pasar parámetros
private void changeFragment(Bundle args, int content, Fragment fragment, String tag)
{
if (args != null) fragment.setArguments(args);
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction().replace(content, fragment, tag).commit();
}
@emedinaa
emedinaa / gist:90db3a227c48d5726649
Created June 26, 2015 20:54
Recibir parámetros en un Fragments
private String mParam1;
private int mParam2;
public void loadData() {
if (getArguments() != null) {
mParam1 = getArguments().getString("MYSTRING");
mParam2 = getArguments().getInt("MYINT");
}
}