Bajar un paquete NuGet sin usar el package explorer

*** Instalar la extensión de Chrome NUTAKE *** Esto agrega un link en cada página del sitio nuget, y se puede bajar haciendo click.


O de otra forma, para hacerlo manual:

https://www.nuget.org/api/v2/package/{packageID}/{packageVersion}

Por ejemplo para bajar este paquete:



Poner esta url:

https://www.nuget.org/api/v2/package/Grid.Mvc/3.1.0-ci1032



Cambiar la imagen de un ImageView

private Bitmap bm1, bm2;

amarilloOff.setImageResource(R.drawable.amarillo_off);
bm1 = BitmapFactory.decodeResource(getResources(), R.drawable.amarillo_on);
bm2 = BitmapFactory.decodeResource(getResources(), R.drawable.amarillo_off);

amarilloOff.setImageBitmap(bm1);

Configurar Admob con Google Play Services en Android

1. Agregar en build.gradle la linea 'com.google.android.gms...'

apply plugin: 'android'
...

dependencies {
    compile 'com.android.support:appcompat-v7:+'
    compile 'com.google.android.gms:play-services:5.0.77'
}

IR A TOOLS / ANDROID / SYNC PROJECT WITH GRADLE FILES y esperar a que las referencias queden bien (no queden en rojo)

2. Agregar un import en el .java

import com.google.android.gms.ads.*;

3. Agregar en AndroidManifest.xml (dentro del tag <application>)

        <activity android:name="com.google.android.gms.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
        <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />

4. Antes del tag <application> agregar:

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

5. Usar este codigo en el MyActivity.java

package com.expressraider.admob;

import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;
import com.google.android.gms.ads.*;

public class MyActivity extends Activity {

    private AdView mAdView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_principal);

        //------------- ADS --------------------------//
        LinearLayout layout = new LinearLayout(this);
        layout.setOrientation(LinearLayout.VERTICAL);

        // Create a banner ad. The ad size and ad unit ID must be set before calling loadAd.
        mAdView = new AdView(this);
        mAdView.setAdSize(AdSize.SMART_BANNER);
        mAdView.setAdUnitId("ca-app-pub-0665940275249022/9155234413");

        mAdView.setLayoutParams(new FrameLayout.LayoutParams(
                FrameLayout.LayoutParams.WRAP_CONTENT,
                FrameLayout.LayoutParams.WRAP_CONTENT,
                Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM));

        TelephonyManager teleManager =(TelephonyManager)getBaseContext().getSystemService(Context.TELEPHONY_SERVICE);
        String device_id=teleManager.getDeviceId();

        //obtengo el id del telefono, para agregarlo como dispositivo de testing
        String android_id = Settings.Secure.getString(this.getContentResolver(), Settings.Secure.ANDROID_ID);
        String deviceId = md5(android_id).toUpperCase();

        AdRequest adRequest=new AdRequest.Builder()
                .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
                .addTestDevice(deviceId).build();

        FrameLayout.LayoutParams initialFrm = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT,
                FrameLayout.LayoutParams.WRAP_CONTENT,
                Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM);
        this.addContentView(mAdView, initialFrm);

        mAdView.loadAd(adRequest);
    }

    @Override
    public void onResume() {
        super.onResume();

        // Resume the AdView.
        mAdView.resume();
    }

    @Override
    public void onPause() {
        // Pause the AdView.
        mAdView.pause();

        super.onPause();
    }

    @Override
    public void onDestroy() {
        // Destroy the AdView.
        mAdView.destroy();

        super.onDestroy();
    }
}



6. Si da error cuando se ejecuta, ver en el LogCat esta linea:


7. En mAdView.setAdUnitId hay que poner el pub ID, que se obtiene de admob de esta forma:

ir a admob
ir a ficha Monetizar
ver en los bloques de anuncios, que dice ca-app-pub-0665940275249022/9155234413
ese es el que hay que poner.





ca-app-pub-0665940275249022/9155234413

Cannot resolve symbol Activity

Si aparecen errores de "Cannot resolve symbol..."

Verificar en app/build.gradle que las versiones se correspondan

por ej.

MAL:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 20
    buildToolsVersion "20.0.0"

    defaultConfig {
        applicationId "com.expressraider.prueba1"
        minSdkVersion 11
        targetSdkVersion 20
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:19.+'
}


BIEN

apply plugin: 'com.android.application'

android {
    compileSdkVersion 19
    buildToolsVersion "20.0.0"

    defaultConfig {
        applicationId "com.expressraider.prueba1"
        minSdkVersion 11
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:19.+'
}

Mantener seleccionado un item del ListView

public class MantMatriculas extends Activity {
    private ListView lstMatriculas;
    private View lastSelectedView = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mant_matriculas);

        lstMatriculas = (ListView)findViewById(R.id.lstMatriculas);

        ArrayList<String> values =
                new ArrayList<String>();

        values.add("matricula1");
        values.add("matricula2");
        values.add("matricula3");
        values.add("matricula4");

        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, android.R.id.text1, values);

        lstMatriculas.setAdapter(adapter);


        lstMatriculas.setItemsCanFocus(false);
        lstMatriculas.setChoiceMode(ListView.CHOICE_MODE_SINGLE);


        lstMatriculas.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            public void onItemClick(AdapterView<?> parentAdapter, View view, int position,
                                    long id) {
               
                if (lastSelectedView != null)
                {
                    lastSelectedView.setBackgroundColor(Color.TRANSPARENT);
                }
                lastSelectedView = view;

                view.setBackgroundColor(Color.CYAN);
            }
        });
    }
}

Centrar texto en TextView

1. Agregar un linear layout (horizontal)
2. Agregar un TextView dentro del linear layout
3. Setear la propiedad gravity del linear layout en Center (la gravity no la layout:gravity)