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 / 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 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 / 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 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 / 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:549d7528d1e022a03024
Last active August 29, 2015 14:23
Configuración build.gradle SDK 19 con Gradle 1.0.0
apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "com.isil.am1lesson4"
minSdkVersion 11
targetSdkVersion 19
@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");
}
}
@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: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 / DpToPxAndPxToDp
Created October 7, 2015 15:31 — forked from laaptu/DpToPxAndPxToDp
Android convert dp to px and vice versa
public static float convertPixelsToDp(float px){
DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics();
float dp = px / (metrics.densityDpi / 160f);
return Math.round(dp);
}
public static float convertDpToPixel(float dp){
DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics();
float px = dp * (metrics.densityDpi / 160f);
return Math.round(px);