Okhelp.cz

Recepty, články, nápady, programování. Dříve dum-zahrada, finance, internet a know-how.okhelp.cz Pro lepší výsledky hledání používejte i diakritiku.

Download file from URL


Download image file from URL to ImageView Java Android source example code.



Context context = thisClass.this;
Drawable image = ImageOperations(context,
"//www.okhelp.cz/images/android/ad_4.png"
,"image.jpg");
ImageView imgView;
imgView = (ImageView)findViewById(R.id.idImageView);
imgView.setImageDrawable(image);

	private Drawable ImageOperations(Context ctx, String url, String saveFilename) {
		try {
			InputStream is = (InputStream) this.fetch(url);
			Drawable d = Drawable.createFromStream(is, "src");
			return d;
		} catch (MalformedURLException e) {
			e.printStackTrace();
			return null;
		} catch (IOException e) {
			e.printStackTrace();
			return null;
		}
	}

	public Object fetch(String address) throws MalformedURLException,IOException {
		URL url = new URL(address);
		Object content = url.getContent();
		return content;
	}

397LW NO topic_id



Další témata ....(Topics)


8

Display screen size resolution density dimension Android | display-screen-dimension


Get display, screen resolution - dimension Android phone development example source code.

 Display display = getWindowManager().getDefaultDisplay();
int nWidth = display.getWidth();
int nHeight = display.getHeight();

          DisplayMetrics metrics = new DisplayMetrics();
            getWindowManager().getDefaultDisplay().getMetrics(metrics);
            //get density per inch for example: 120 , 160 , 240
            mXDpi = metrics.xdpi; // 160 The exact physical pixels per inch of the screen in the X dimension. 
            mYDpi = metrics.ydpi;

// density
int nDensity = metrics.densityDpi; // 160 screen density expressed as dots-per-inch

          float  mMetersToPixelsX = mXDpi / 0.0254f; // 1 inch == 0.0254 metre
          float  mMetersToPixelsY = mYDpi / 0.0254f;
          
// Resolution
// The total number of physical pixels on a screen.
int wPix = metrics.widthPixels; // 320 The absolute width of the display in pixels.
int hPix = metrics.heightPixels; // 480 The absolute height of the display in pixels.
int nWidthDisplay = (wPix < hPix)? wPix : hPix;

float nWidthScreenInInch = wPix / mXDpi; //320 / 160 == 2.0 in inch.
float nHeightScreenInInch = hPix / mYDpi; //480 / 160 == 3.0 in inch.

// for example:
// density 120 per inch
//width 320 pix / 120 dpi == width 2.66 inch
//height 480 pix / 120 dpi == height 4.0 inch 

// density 240 per inch
//width 320 pix / 240 dpi == width 1.33 inch
//height 480 pix / 240 dpi == height 2.0 inch 




Example:
HTC Desire HD
11 (4.3) Diagonal cm (in)
480×800 Resolution
85 (217) ppcm (PPI - Pixels per inch)

480 / 217 = 2.21 inch
800 / 217 = 3.69 inch
Math.sqrt( 2.21*2.21 + 3.69 * 3.69) = 4.3 inch - diagonal

//en.wikipedia.org/wiki/Pixels_per_inch
//en.wikipedia.org/wiki/Dots_per_inch

Typical screen widths:

320dp: a typical phone screen (240x320 ldpi, 320x480 mdpi, 480x800 hdpi, etc).
480dp: a tweener tablet like the Streak (480x800 mdpi).
600dp: a 7” tablet (600x1024 mdpi).
720dp: a 10” tablet (720x1280 mdpi, 800x1280 mdpi, etc).


Emulator skins in the Android SDK
//developer.android.com/guide/practices/screens_support.html









































Low density (120), ldpi

Medium density (160), mdpi

High density (240), hdpi

Extra high density (320), xhdpi

Small screen
QVGA (240x320) 480x640

Normal screen
WQVGA400 (240x400)

WQVGA432 (240x432)
HVGA (320x480) WVGA800 (480x800)

WVGA854 (480x854)

600x1024
640x960

Large screen
WVGA800** (480x800)

WVGA854** (480x854)
WVGA800* (480x800)

WVGA854* (480x854)

600x1024

Extra Large screen
1024x600 WXGA (1280x800)

1024x768
1280x768
1536x1152
1920x1152

1920x1200
2048x1536
2560x1536

2560x1600
* To emulate this configuration, specify a
custom density of 160 when creating an AVD that uses a WVGA800 or WVGA854 skin.

** To emulate this configuration, specify a custom density of 120 when creating an AVD that
uses a WVGA800 or WVGA854 skin.

† This skin is available with the Android 3.0 platform
349

Android Google Maps Night Mode | android-google-maps-night-mode


If you want save battery, select "Satelite map" from map menu and reduce the brightness of the display.

android-google-maps-night-mode-as-satelite-map.jpg
145

Compressing converting a bitmap to PNG format Android example | compressing-converting-a-bitmap-to-png-format-android-example



public class MainActivity extends Activity {
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(new SampleView(this));
	}

	private static Bitmap codec(Bitmap src, Bitmap.CompressFormat format,
			int quality) {
		ByteArrayOutputStream os = new ByteArrayOutputStream();
		src.compress(format, quality, os);

		byte[] array = os.toByteArray();
		return BitmapFactory.decodeByteArray(array, 0, array.length);
	}

	private static class SampleView extends View {

		// CONSTRUCTOR
		public SampleView(Context context) {
			super(context);
			setFocusable(true);

		}
		@Override
		protected void onDraw(Canvas canvas) {
			Paint paint = new Paint();
			
			canvas.drawColor(Color.YELLOW);
            
        
			Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.flower_blue);
             
			Bitmap bPNGcompress = codec(bmp, Bitmap.CompressFormat.PNG, 0);

		   int h = bmp.getHeight();
           
           canvas.drawBitmap(bmp, 10,10, paint);
           canvas.drawBitmap(bPNGcompress, 10,10 + h + 10, paint);
           
		}

	}
}

259

Two boolean as one parameter value in function Java | two-boolean-as-one-parameter-value-in-function-java



boolean fc(boolean b) {
	return b;
}// end fc
		boolean bA = true;
		boolean bB = true;
		boolean bC = bA || bB; // true

		bA = true;
		bB = false;
		bC = bA || bB; // true

		bA = false;
		bB = true;
		bC = bA || bB; // true

		bA = false;
		bB = false;
		bC = bA || bB; // false
		
			if(!fc(bB||bA))
			System.out.println("false"); // false
                        else 
			System.out.println("true"); 


305

WebView.loadData utf-8 encoding Android | webview-loaddata-utf-8-encoding-android


Try this solution:

String DATA = "Html text....bla bla bla. Hellou world!  čšřžěéá";
String HEADERHTML = 
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">" 
+"<html>  <head>  <meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">"  
+"</head>  <body>";
String FOOTERHTML = "</body></html>";
WebView mWebView.loadData(HEADERHTML+DATA+FOOTERHTML,"text/html; charset=UTF-8",null);



Editace: 2013-12-09 13:25:41
Počet článků v kategorii: 397
Url:download-file-from-url
Share
Share
Tweet