You are on page 1of 137
maestros del web CURSO ANDROID Desarrollo de aplicaciones moéviles ew Care Pes PROGRAMACION INTERMEDIO CURSO ANDROID 10 af SSS a Disposicién inicial ‘Arrancamos descargando el cédigo base’ que debe ser importado hacia un proyecto nuevo. En mi caso, el cédigo descargado lo tengo en el folder "/Users/ykro/Desktop/LectorFeedMDWBase": pore Projects Select 8 ectry to 0c or xin Kone projec. O weecrer areca 0 see wc > ros Scares UinwserOemea rane Sara) aay CO Copy projects into workspace NN I at pret worn et En este cédigo encontrards algunas cosas de ayuda para el desarrollo del proyecto. Si quisieran iniciar desde cero, con un proyecto nuevo, lo minimo que deberian hacer para tenerlo listo es: > Darle permiso a la aplicacién para que pueda accesar a internet Para hacer esto, vamos al archivo ancroidManifest. xm] y justo antes de la etiqueta que cierra manifest colocamos: Disefio El disefio tendré 2 botones para iniciar/cerrar sesién y 2 etiquetas para mostrar el status. En el caso de Facebook, vamos a utilizar el botén incluido en el ejemplo del SDK implementado en una clase llamada LoginButton. Tener un LinearLayout con orientacién vertical en el archivo de disejio principal. Para lograr esto, en el archivo /res/layout /ma in. xml es necesario tener: COTS ay github & http://www forosdehweb.com/t165/ https://github.com/androidMDW/guia9completo CURSO ANDROID 116 af Sao os ee Conclusi6n En este capitulo hemos visto varias cosas: > Utilizacién de un proyecto como libreria (SDK de Facebook para Android), es posible crear un proyecto sin Activities si no Gnicamente con cédigo para ser utilizado por terceros. En este caso, nosotros aprovechamos este cédigo creado por alguien mas para nuestra aplicaci6n. > Uso de librerias externas a través de archivos JAR que se vuelven parte del proyecto, en nuestra aplicacién de demo de esta forma incluimos OAuth SignPost. > Conexién con APIs de terceros (Facebook & Twitter) para lograr la autenticacién, vimos dos opcio- nes que podemos manejar para poder identificar a los usuarios de nuestras aplicaciones. La libre- ria de OAuth SignPost es posible utilizarla también con algunos otros proveedores que trabajan también con OAuth. 10 awe Conectandonos con Apis de Google Conectandonos con Apis de Google Enel decimo capitulo seguimos trabajando con APIs esta vez utilizaremos conexion con 2 APIs de Google: el de traduccion y el de busqueda de videos en YouTube. Conexi6n con APIs de Google La aplicacién que realizaremos nos permitiré realizar la traduccién de un texto pequefio de espafiol a inglés y ademas realizar una busqueda en YouTube. Queremos que al finalizar se vea asi: CURSO ANDROID 119 KE SSS SS Sy 2 eee eee Disposicion inicial El tipo de requisiciones que realizaremos a estos APIs no necesita de autenticacién entonces no nece- sitamos validar ningiin tipo de credenciales. Si quisiéramos, por ejemplo, subir un video a YouTube si seria necesario autenticarnos. Para no realizar el trabajo desde cero nos apoyaremos en 2 librerias, una para cada API: Pagina del proyecto: google-api-translate-java * Cédigo fuente disponible en Github para descargar * Pagina del proyecto: google-api-java-client * La libreria para descargar * vvvy Vamos a usar esta libreria en este demo sin preocuparnos mucho del tamajio final de la aplicacién, al usarla en un ambiente de produccién es muy importante utilizar ProGuard para reducir el tamafio, encuentran instrucciones detalladas en http://code.google.com/p/google-api-java-client/wiki/Setup Vamos a importar varias librerias al proyecto, no utilizaremos cédigo base de nuevo para seguir paso a paso la configuracién: > Para la parte de traduccién, es un tinico archivo llamado: google-api-translate-java-0.95 > Para la parte de YouTube, del archivo zip que descargamos vamos a elegir 4 archivos, esta descarga trae varias librerias y sus fuentes, la descripcidn la encuentran en htto://code.google. Je-api-java-client/wiki/Setup nosotros vamos a utilizar del directorio raiz. > google-api-client-1.4.1-beta > google-api-client-googleapis-1.4.1-beta ‘Ademés, para la conexién HTTP y el parsing de JSON otras 2 de las dependencias: del archivo descar- gado de google-api-java-client dentro de la carpeta dependencies necesitamos: > guava-r09 1 “1 htto://goosle ittp://google-api-translate-java.googlecode.com/files/google-api-translate-java-0.95.jar 2 http://github.com/richmidwinter/google-api-translate-java 3 http://code. google,com/p/google-api-java-client/ 4 http://google-api-java-client.googlecade.com/files/google-api-java-client-1.4.1-beta.zip CURSO ANDROID 12 af SSS SS > Se ee Se 1. | LinearLayout con arreglo horizontal (para la etiqueta y el boton). 2 | ListView para los elementos del feed. Nuestro archivo /res/layout /ma in. xm quedaria entonces de la siguiente forma: Jcssigo evant CURSO ANDROID 122 KE SSS SS Sy 2 eee eee Disejio El disefio tendré 2 partes, para la traduccién utilizaremos un TextView que le indique al usuario que hacer eTextview android: Layout_width= android: layout_height= fill_parent” /arap_content” android: text: > "Ingrese €1 t Luego un LinearLayout para mostrar en fila un EditText para recibir la cadena a traducir y un botén para realizar la traduccién: Por ultimo otro TextView que muestre el resultado. Para la siguiente seccién, la de busqueda en YouTube de manera similar que el caso anterior indicamos al usuario a través de un TextView que debe ingresar el parémetro de busqueda: Terminamos con un ListView para mostrar el resultado de la busqueda: El disefio completo queda de la siguiente form CURSO ANDROID 124 « "fill_parent” "a+id/etQueryText” android:hint="Android sdk” android: layout_width="wrap_content” android: layout_height: dpocthanstagpees Agregando cédigo Para el manejo de la respuesta de YouTube (en JSON) vamos a construir clases de Java que represen- ten esta respuesta de tal forma que el proceso de parsing sea més sencillo. Estas clases serén internas y estaticas (mds informacion en download.oracle.com’) dentro de la clase de nuestra Activity principal. Construiremos 3 clases: Una para representar el resultado completo del request, una lista de items se llamara Video Feed, public static class VideoFeed { Okey List
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
Rating: 4 out of 5 stars
4/5 (5819)
  • The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
    The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
    From Everand
    The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
    Rating: 4 out of 5 stars
    4/5 (1092)
  • Never Split the Difference: Negotiating As If Your Life Depended On It
    Never Split the Difference: Negotiating As If Your Life Depended On It
    From Everand
    Never Split the Difference: Negotiating As If Your Life Depended On It
    Rating: 4.5 out of 5 stars
    4.5/5 (845)
  • Principles: Life and Work
    Principles: Life and Work
    From Everand
    Principles: Life and Work
    Rating: 4 out of 5 stars
    4/5 (609)
  • The Glass Castle: A Memoir
    The Glass Castle: A Memoir
    From Everand
    The Glass Castle: A Memoir
    Rating: 4.5 out of 5 stars
    4.5/5 (1717)
  • Grit: The Power of Passion and Perseverance
    Grit: The Power of Passion and Perseverance
    From Everand
    Grit: The Power of Passion and Perseverance
    Rating: 4 out of 5 stars
    4/5 (590)
  • Sing, Unburied, Sing: A Novel
    Sing, Unburied, Sing: A Novel
    From Everand
    Sing, Unburied, Sing: A Novel
    Rating: 4 out of 5 stars
    4/5 (1104)
  • Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
    Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
    From Everand
    Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
    Rating: 4 out of 5 stars
    4/5 (897)
  • Shoe Dog: A Memoir by the Creator of Nike
    Shoe Dog: A Memoir by the Creator of Nike
    From Everand
    Shoe Dog: A Memoir by the Creator of Nike
    Rating: 4.5 out of 5 stars
    4.5/5 (540)
  • The Perks of Being a Wallflower
    The Perks of Being a Wallflower
    From Everand
    The Perks of Being a Wallflower
    Rating: 4.5 out of 5 stars
    4.5/5 (2104)
  • The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
    The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
    From Everand
    The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
    Rating: 4.5 out of 5 stars
    4.5/5 (348)
  • Bad Feminist: Essays
    Bad Feminist: Essays
    From Everand
    Bad Feminist: Essays
    Rating: 4 out of 5 stars
    4/5 (1018)
  • Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
    Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
    From Everand
    Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
    Rating: 4.5 out of 5 stars
    4.5/5 (474)
  • Her Body and Other Parties: Stories
    Her Body and Other Parties: Stories
    From Everand
    Her Body and Other Parties: Stories
    Rating: 4 out of 5 stars
    4/5 (822)
  • The Outsider: A Novel
    The Outsider: A Novel
    From Everand
    The Outsider: A Novel
    Rating: 4 out of 5 stars
    4/5 (1866)
  • The Emperor of All Maladies: A Biography of Cancer
    The Emperor of All Maladies: A Biography of Cancer
    From Everand
    The Emperor of All Maladies: A Biography of Cancer
    Rating: 4.5 out of 5 stars
    4.5/5 (271)
  • The Sympathizer: A Novel (Pulitzer Prize for Fiction)
    The Sympathizer: A Novel (Pulitzer Prize for Fiction)
    From Everand
    The Sympathizer: A Novel (Pulitzer Prize for Fiction)
    Rating: 4.5 out of 5 stars
    4.5/5 (122)
  • Angela's Ashes: A Memoir
    Angela's Ashes: A Memoir
    From Everand
    Angela's Ashes: A Memoir
    Rating: 4.5 out of 5 stars
    4.5/5 (441)
  • Brooklyn: A Novel
    Brooklyn: A Novel
    From Everand
    Brooklyn: A Novel
    Rating: 3.5 out of 5 stars
    3.5/5 (1947)
  • The Little Book of Hygge: Danish Secrets to Happy Living
    The Little Book of Hygge: Danish Secrets to Happy Living
    From Everand
    The Little Book of Hygge: Danish Secrets to Happy Living
    Rating: 3.5 out of 5 stars
    3.5/5 (401)
  • A Man Called Ove: A Novel
    A Man Called Ove: A Novel
    From Everand
    A Man Called Ove: A Novel
    Rating: 4.5 out of 5 stars
    4.5/5 (4770)
  • Steve Jobs
    Steve Jobs
    From Everand
    Steve Jobs
    Rating: 4.5 out of 5 stars
    4.5/5 (808)
  • The World Is Flat 3.0: A Brief History of the Twenty-first Century
    The World Is Flat 3.0: A Brief History of the Twenty-first Century
    From Everand
    The World Is Flat 3.0: A Brief History of the Twenty-first Century
    Rating: 3.5 out of 5 stars
    3.5/5 (2259)
  • The Yellow House: A Memoir (2019 National Book Award Winner)
    The Yellow House: A Memoir (2019 National Book Award Winner)
    From Everand
    The Yellow House: A Memoir (2019 National Book Award Winner)
    Rating: 4 out of 5 stars
    4/5 (98)
  • Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
    Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
    From Everand
    Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
    Rating: 4.5 out of 5 stars
    4.5/5 (266)
  • The Art of Racing in the Rain: A Novel
    The Art of Racing in the Rain: A Novel
    From Everand
    The Art of Racing in the Rain: A Novel
    Rating: 4 out of 5 stars
    4/5 (4208)
  • A Tree Grows in Brooklyn
    A Tree Grows in Brooklyn
    From Everand
    A Tree Grows in Brooklyn
    Rating: 4.5 out of 5 stars
    4.5/5 (1929)
  • Team of Rivals: The Political Genius of Abraham Lincoln
    Team of Rivals: The Political Genius of Abraham Lincoln
    From Everand
    Team of Rivals: The Political Genius of Abraham Lincoln
    Rating: 4.5 out of 5 stars
    4.5/5 (234)
  • Yes Please
    Yes Please
    From Everand
    Yes Please
    Rating: 4 out of 5 stars
    4/5 (1902)
  • A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
    A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
    From Everand
    A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
    Rating: 3.5 out of 5 stars
    3.5/5 (231)
  • The Woman in Cabin 10
    The Woman in Cabin 10
    From Everand
    The Woman in Cabin 10
    Rating: 3.5 out of 5 stars
    3.5/5 (2522)
  • Fear: Trump in the White House
    Fear: Trump in the White House
    From Everand
    Fear: Trump in the White House
    Rating: 3.5 out of 5 stars
    3.5/5 (738)
  • Wolf Hall: A Novel
    Wolf Hall: A Novel
    From Everand
    Wolf Hall: A Novel
    Rating: 4 out of 5 stars
    4/5 (3811)
  • John Adams
    John Adams
    From Everand
    John Adams
    Rating: 4.5 out of 5 stars
    4.5/5 (2409)
  • On Fire: The (Burning) Case for a Green New Deal
    On Fire: The (Burning) Case for a Green New Deal
    From Everand
    On Fire: The (Burning) Case for a Green New Deal
    Rating: 4 out of 5 stars
    4/5 (74)
  • The Light Between Oceans: A Novel
    The Light Between Oceans: A Novel
    From Everand
    The Light Between Oceans: A Novel
    Rating: 4.5 out of 5 stars
    4.5/5 (789)
  • Manhattan Beach: A Novel
    Manhattan Beach: A Novel
    From Everand
    Manhattan Beach: A Novel
    Rating: 3.5 out of 5 stars
    3.5/5 (792)
  • The Constant Gardener: A Novel
    The Constant Gardener: A Novel
    From Everand
    The Constant Gardener: A Novel
    Rating: 3.5 out of 5 stars
    3.5/5 (104)
  • The Unwinding: An Inner History of the New America
    The Unwinding: An Inner History of the New America
    From Everand
    The Unwinding: An Inner History of the New America
    Rating: 4 out of 5 stars
    4/5 (45)
  • Rise of ISIS: A Threat We Can't Ignore
    Rise of ISIS: A Threat We Can't Ignore
    From Everand
    Rise of ISIS: A Threat We Can't Ignore
    Rating: 3.5 out of 5 stars
    3.5/5 (137)
  • Little Women
    Little Women
    From Everand
    Little Women
    Rating: 4 out of 5 stars
    4/5 (104)