15SrHM8GT8rOkCLHViEKlK-ejrCocgl6A Cooking & Coding: Android
Visualizzazione post con etichetta Android. Mostra tutti i post
Visualizzazione post con etichetta Android. Mostra tutti i post

lunedì 11 maggio 2015

Impostare la vecchia visualizzazione dei Preferiti di Google Chrome

lunedì, maggio 11, 2015
La nuova visualizzazione dei preferiti di google Chrome non è il massimo della vita, un pò troppo confusionaria e poco pratica. Per ritornare alla vecchia visualizzazione dei preferiti è necessario eseguire i seguenti step:
  • Aprire una nuova scheda in Google Chrome e questo nella barra degli indirizzi scrivi questo path
  • chrome://flags/#enhanced-bookmarks-experiment
  • Alla voce: Attiva i segnalibri avanzati
  • Cambiare la selezione da "default" a "disabled"
  • Riavviare Chrome

mercoledì 10 ottobre 2012

Android: Loading Photo and Show in new Activity

mercoledì, ottobre 10, 2012

LOADING PHOTO IN ANOTHER ACTIVITY

This is a very useful code because sometimes you need to load a photo from gallery or other location and showing in another activity. Create a new project on eclipse and insert the code below.

MainActivity.java



package com.lucapinta.loadshow;

import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;

import android.app.Activity;
import android.content.Intent;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.Display;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;


public class MainActivity extends Activity implements OnClickListener {
 
 Button choosePicture;
 Bitmap bmpFile;
 final String JPEG_PICTURE = "JPEG_PICTURE";
 
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);

  choosePicture = (Button) this.findViewById(R.id.button1);
  choosePicture.setOnClickListener(this);

} //end on Create

 //** Actiond load photo
 public void onClick(View v) {
  Intent choosePictureIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
  startActivityForResult(choosePictureIntent, 0);
 }

 
//*************** Metodo LoadGALLERY 
    protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
  super.onActivityResult(requestCode, resultCode, intent);

  if (resultCode == RESULT_OK) {
   Uri imageFileUri = intent.getData();
    bmpFile = loadBitmap(imageFileUri);

     } //end if
 }// end onAcitivity    
  
    
//************* Load Image   
   private Bitmap loadBitmap(Uri imageFileUri) {
    Display currentDisplay = getWindowManager().getDefaultDisplay();

    float dw = currentDisplay.getWidth();
    float dh = currentDisplay.getHeight();

    Bitmap returnBmp = Bitmap.createBitmap((int) dw, (int) dh, Bitmap.Config.ARGB_4444);

    try {
     // Load up the image's dimensions not the image itself
     BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options();
     bmpFactoryOptions.inJustDecodeBounds = true;
     returnBmp = BitmapFactory.decodeStream(getContentResolver().openInputStream(imageFileUri), null, bmpFactoryOptions);

     int heightRatio = (int) Math.ceil(bmpFactoryOptions.outHeight / dh);
     int widthRatio = (int) Math.ceil(bmpFactoryOptions.outWidth / dw);

     Log.v("HEIGHTRATIO", "" + heightRatio);
     Log.v("WIDTHRATIO", "" + widthRatio);

     // If both of the ratios are greater than 1, one of the sides of the
     // image is greater than the screen
     if (heightRatio > 1 && widthRatio > 1) {
      if (heightRatio > widthRatio) {
       // Height ratio is larger, scale according to it
       bmpFactoryOptions.inSampleSize = heightRatio;
      } else {
       // Width ratio is larger, scale according to it
       bmpFactoryOptions.inSampleSize = widthRatio;
      }
     }

     // Decode it for real
     bmpFactoryOptions.inJustDecodeBounds = false;
     returnBmp = BitmapFactory.decodeStream(getContentResolver().openInputStream(imageFileUri), null, bmpFactoryOptions);
    
    } catch (FileNotFoundException e) {
     Log.v("ERROR", e.toString());
    }

    ByteArrayOutputStream baos = new ByteArrayOutputStream();  
    returnBmp.compress(Bitmap.CompressFormat.PNG, 100, baos); //bmp is the bitmap object   
    byte[] b = baos.toByteArray();
    
    //Lunch image in another activity
   Intent nextActivity = new Intent(getApplicationContext(), ImageShow.class);
    nextActivity.putExtra(JPEG_PICTURE, b);
    startActivity(nextActivity);
    
    return returnBmp;
    
   } //loadImage


 
 
//*********************  Change 
    @Override 
    public void onConfigurationChanged(Configuration newConfig) {
     super.onConfigurationChanged(newConfig);
    } //end onCC

} //end class    

main.xml


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
       
<TableLayout android:layout_height="wrap_content" 
    android:layout_width="fill_parent"
 android:paddingTop="2sp" 
 android:paddingBottom="2sp"
 android:padding="3sp"  >
<TableRow>     
    

   <TextView
       android:id="@+id/textView1"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:text="Select Device"
       android:textAppearance="?android:attr/textAppearanceMedium" />

</TableRow>
<TableRow>

     <Button
          android:id="@+id/button1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Select Image" />

</TableRow>
</TableLayout>


</LinearLayout>


Follow me

In

Fli

Created with flickr badge.