Load ImageView from URL in Android

Sometimes we need to show images in our Android application that are available in a remote server and can not be created as drawable resources. To load one of these images into an ImageView object, the image has to be turn from the URL into a bitmap. The following method solves this.

public boolean loadImageFromURL(String fileUrl, 
ImageView iv){
  try {

    URL myFileUrl = new URL (fileUrl);
    HttpURLConnection conn =
      (HttpURLConnection) myFileUrl.openConnection();
    conn.setDoInput(true);
    conn.connect();

    InputStream is = conn.getInputStream();
    iv.setImageBitmap(BitmapFactory.decodeStream(is));

    return true;

  } catch (MalformedURLException e) {
    e.printStackTrace();
  } catch (Exception e) {
    e.printStackTrace();
  }

  return false;
}

Remember to grant the permission “android.permission.INTERNET” in the AndroidManifest.xml file.

<uses-permission android:name="android.permission.INTERNET"/>

Read More

Gradient Background in Android

An easy way to change the style of your mobile application is to add gradient backgrounds to the view components. In this example, we are adding a gradient background to the elementes of a list view.

No gradient

Firstly, define the colors in your Android xml file of resources. If you do not have a file of color resources, create it in the /res/values folder.

Create Resource File

In this example, we are using two different tones of grey.

<resources> 
  <color name="greyMed">#C9C9C9</color> 
  <color name="greyLgt">#ECECEC</color> 
</resources> 

Next step is to create a drawable resource in /res/drawable folder with Shape as root element.

Create gradient xml file

In a list view item, the shape is a rectangle and the gradient is created inside this shape. The gradient tag has the startColor and endColor attributes, that configure the gradient color, and the angle attribute that configure the angle of the gradient in degrees.

Gradient 2 colors

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> 
  <gradient 
    android:startColor="@color/greyMed" 
    android:endColor="@color/greyLgt" 
    android:angle="90"> 
  </gradient> 
</shape>

The gradient tag has also the attribute centerColor.

gradient 3 colors

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> 
  <gradient 
    android:startColor="@color/greyMed" 
    android:centerColor="@color/greyLgt" 
    android:endColor="@color/greyMed" 
    android:angle="90"> 
  </gradient> 
</shape>

Or we can change the angle. The angle is an integer value that must be a multiple of 45. A value of 0 is left to right or a value of 90 is bottom to top.

Gradient 180 angle

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> 
  <gradient 
    android:startColor="@color/greyMed" 
    android:endColor="@color/greyLgt" 
    android:angle="135"> 
  </gradient> 
</shape>

Finally, another important attribute is the type. The attribute type has three valid values:

  • “linear”. This is the default value. A linear gradient as the previous examples.
  • “radial”. It requires to specify the attribute gradientRadius which is a float value.
  • “sweep”. A sweeping line gradient.

Read More

Reduce the file size of an image using Adobe Fireworks

The file size of images is very important to the optimization of a mobile application, website and above everything, a web mobile application.  Decreasing the file size of your images will allow your application to load faster and to reduce the amount of data transmitted.

Open Adobe Fireworks, load your image and press Ctrl + Shift + X to open the export window. Depending on the image format selection, some configuration parameters will be shown. On the right you will see the final image size. Once you are satisfied with your size, export it.

El tamaño de los ficheros de imagen es muy importante para la optimización de una aplicación móvil, un sitio web y sobretodo, una aplicación móvil basada en web. Reducir el tamaño de los ficheros de las imágenes va a permitir que tu aplicación cargue más rápido y que disminuya la cantidad de datos transferidos.

Abre Adobe Fireworks, carga la imagen y pulsa Ctrl + Mayús. + X o ve al menú “Archivo” > “Presentación preliminar de la imagen”. Según el formato de imagen que seleccionemos, aparecerán varios parámetros de configuración. En la parte derecha, se irá indicando el tamaño final de la imagen. Una vez conforme con el tamaño, dale al botón de exportar.

 Fireworks Option

 

Fireworks export

Version: Adobe Fireworks CS5, 11.0.1.7

Read More

How to hide Title and set Fullscreen mode in Android

To hide the activity view title programmatically, insert the following line in the onCreate method of the main activity:

requestWindowFeature(Window.FEATURE_NO_TITLE);

To set fullscreen mode, add this one:

getWindow().setFlags(
   WindowManager.LayoutParams.FLAG_FULLSCREEN,
   WindowManager.LayoutParams.FLAG_FULLSCREEN);

The onCreate method would look like:

@Override
public void onCreate (Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  requestWindowFeature(Window.FEATURE_NO_TITLE); 

  getWindow().setFlags(
    WindowManager.LayoutParams.FLAG_FULLSCREEN,
    WindowManager.LayoutParams.FLAG_FULLSCREEN);

  setContentView(R.layout.main);
}

Read More

Expand disk size with VMware vSphere Client

To expand the disk size of a virtual machine (VM) using VMware vSphere Client, are needed these two steps:

  1. Change the properties of the VM in vSphere Client.
  2. Resize the disk space from the guest operating system (OS) in the VM.

 Step 1

In vSphere Client, edit the properties of the VM using the option “Edit Settings”. In the properties window, select the hard disk to be extended and change its size (“Provisioned Size” option).

VM properties

To check this step, in the guest OS of the VM, verify the unallocated space on the disk. If you are using Windows Server, open the “Management Console” > “Disk Management”.

Step 2

The second step is to resize the disk space from the guest OS in the VM. In Window Server versions, use the Disk Management Tool.

In Windows Server 2003 or earlier versions, download Dell’s ExtPart utility from here. Extract it by default in c:\dell\ExtPart and run the executable. Windows Console will be prompted. Enter the volume and the size to expand it.

ExtPart in console

Job done.

Read More

My brand new blog

Welcome to my blog and my first official post.
I am a computer engineer, specializing in developing software, web applications and mobile applications (PHP, CSS, Java, HTML5, jquery, phonegap, iOS, Android, etc.).
I decided to start this blog/portfolio site to show part of my job and share my adventures in software development, engineering and research as a PhD student.

Bienvenidos a mi blog y primer post oficial.
Soy una ingeniera informática, especializada en desarrollo software, aplicaciones web y aplicaciones móviles (PHP, CSS, Java, HTML5, jquery, phonegap, iOS, Android, etc.).
He decidido crear este blog/portfolio para mostrar parte de mi trabajo y compartir mis aventuras en el desarrollo de software y en la investigación como estudiante de doctorado.

Read More