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.

How are you old - date calendar age Java Android example


AD MOB

Calendar dateOfYourBirth = new GregorianCalendar(1998, Calendar.SEPTEMBER, 17); Calendar today = Calendar.getInstance(); Android example.


public class HoriziontalScrollActivity extends Activity {
	TextView txtV;
	Context cntx;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        txtV = (TextView)findViewById(R.id.idLabel);
        cntx = this;
        StringBuilder strBuild = new StringBuilder();

        // enter your date of birth
        Calendar dateOfYourBirth = new GregorianCalendar(1998, Calendar.SEPTEMBER, 17);
        Calendar today = Calendar.getInstance();
        int yourAge = today.get(Calendar.YEAR) - dateOfYourBirth.get(Calendar.YEAR);
        dateOfYourBirth.add(Calendar.YEAR, yourAge);
        if (today.before(dateOfYourBirth)) {
            yourAge--;
        }  
        strBuild.append("You are " + yourAge + " old!");
         txtV.setText(strBuild);
    }
}


397LW NO topic_id




AD

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


352

How to test dual panels - panes fragments on small device screen Android | how-to-test-dual-panels-fragments-on-small-device-screen-android


If You have old PC (Android in emulator with high screen resolution uses a lot of memory) or your testing phone have small screen, You can try this trick.
Rename layout folder for small device screen f.g. from layout into layout-swXXXdp and a large layout-sw600dp into layout.
Your phone with small screnn will do select xml file from renamed layout folder (for small screen).
You can to testing rotation with device en stability of fragments if an application changed orientation.
If you have old pc, you can try to make a new virtual device running on older version of Android, which uses less memory of computer.
For testing of rotation stability - application orientation changed - use on emulator Ctrl+F11, Ctrl+F12 key (Windows).

Important
Before the release of application, you have to rename layout folder to older name layout-sw600dp and layout-swXXXdp to layout.
213

Round number float - double to int - long Java example | round-number-float-to-int-java-example



int nf = Math.round(5.789f);
System.out.print(nf); // 6

float f = 28.611f; 
int n3 = Math.round(f);
System.out.println(n3); // 29

double d = 1234.56;
long lon = Math.round(d);
System.out.println(lon); // 1235

int diff = 90 - 40;
// float fDeleni = diff / 10; // error code
float fDeleni = (float)diff / 10.f; // ok
int nRound = Math.round(fDeleni);


// Caution:
int n2 = (int) 8.999f;
System.out.println(n2); // 8


183

HTC Sensation 4G | htc-sensation-4g


HTC Sensation 4G cena od 11 000 KCZ Kč (únor.2012)
Spokojenost uživatelů nadprůměrná.
HTC Sensation 4G je chytrý telefon s operačním systémem Android.
HTC Sensation 4G je (22.února2012) 10. nejpoužívanějším chytrým telefonem u programu Sky Map viz tabulka.


Výrobce HTC
Kompatibilní sítě GSM / GPRS / EDGE
850 900 1800 1900 MHz
UMTS / HSPA
850 1900 2100 nebo 900 1700 2100 MHz
HSDPA 14,4 Mbps
HSUPA 5.76 Mbps
První předvedení 19.května 2011
Zaváděcí cena US 199,99 dolarů
Nástupce HTC Sensation XE, HTC 4G Amaze
Rozměry 126.1 mm (4.96 v) H
65.4 mm 2,57 in) W
11.3 mm (0,44 in) D
Hmotnost 148 g
Operační systém Android 2.3.3 Gingerbread (upgrade až na 2.3.4),
HTC Sense 3.0 overlay

Procesor:
Dual-core CPU, 1.2 GHz Qualcomm MSM8260 Snapdragon, Sensation XE dual-core 1,5 GHz Qualcomm MSM8260 Snapdragon, Sensation XL jednoho jádra 1,5 GHz Qualcomm MSM8255 Snapdragon
GPU Qualcomm adreno 220, Sensation XL adreno 205

Paměť 768 MB RAM
4 GB (1 GB uživatelsky dostupných)
Paměť vyjmutelná: 8 GB microSD 2.0, podporuje až 32 GB

Baterie 1520 mAh vnitřní dobíjecí Li-ion vyměnitelné
Datové vstupy A-GPS, čidlo okolního osvětlení, digitální kompas, G-senzor, gyroskop, multi-touch kapacitní dotykový displej, snímač
Displej 4.3 v (110 mm) kapacitní S-LCD dotykový displej Gorilla skla s QHD (540 × 960) rozlišením na 256.15 PPI
Fotoaparát na zadní straně s 8 miliony pixelů (3264 x 2448) s automatickým ostřením a dvojitým LED bleskem a 1080p HD video záznamu @ 30 snímků / s, kohoutek k zaměření s digitálním zoomem
Fotoaparát na přední straně VGA pevné zaostření barevná kamera (0,3 megapixelů)
Kompatibilní média formáty audio AAC, AMR, OGG, M4A, MIDI, MP3, WAV, WMA
Video 1920 × 1080 (1080p HD) @ 30 snímků / s - 3GP, .3 G2, MP4, WMV, AVI, XVID
Vyzváněcí tóny a oznámení všechny kompatibilní audio formáty
Vibrace
Připojení 3.5 mm TRRS konektor, Bluetooth 3.0 s A2DP, FM přijímač (87,5 - 108 MHz) s RDS, Micro USB 2.0 (5-pin) port s Mobile High-Definition Link (MHL) pro USB nebo HDMI připojení, Wi-Fi 802.11b/g/n
Zdroj: wikipedia


HTC Sensation 4G photo pic image
HTC Sensation 4G
Zdroj obrázku: wikipedia
21

How to install mount SD card for Eclipse Android Emulator | how-install-sd-card-on-android-eclipse-emulator


If you want download some *.apk file from internet and try on your emulator you get error than you have to install SD card. You have to closing Android emulator.
Mount Android emulator SD card instruction

  1. In Eclipse go in menu Window - Android SDK and Avg Manager

  2. Select Virtual devices

  3. Select AVD Name where you need install SD card

  4. Click on Edit button

  5. In open dialog go to SD card - Size: and write 500

  6. Press button Edit AVD

  7. Run AVD emulator


Image how install SD card on Android emulator in Eclipse.



240

AsyncTask Example Android with ProgressBar | asynctask-example-android-with-progressbar


MainActivity.java

package com.asynctaskexample;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;

public class MainActivity extends Activity {
	private TextView textView;
	private ProgressBar progressBar;
	private DownloadWebPageTask mTask = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		textView = (TextView) findViewById(R.id.TextView01);
		downloadPage();
	}

	// AsyncTask <TypeOfVarArgParams , ProgressValue , ResultValue> .
	private class DownloadWebPageTask extends AsyncTask<String, Integer, String> {

		@Override
		protected void onPreExecute() {
			//textView.setText("Hello !!!");
			progressBar = (ProgressBar) findViewById(R.id.progressBar1);
			progressBar.setVisibility(View.VISIBLE);
			super.onPreExecute();
		}

		@Override
		protected void onProgressUpdate(Integer... values) {
			super.onProgressUpdate(values);

		}

		@Override
		protected String doInBackground(String... urls) {
			String response = "";
			for (String url : urls) {
				DefaultHttpClient client = new DefaultHttpClient();
				HttpGet httpGet = new HttpGet(url);
				try {
					HttpResponse execute = client.execute(httpGet);
					InputStream content = execute.getEntity().getContent();

					BufferedReader buffer = new BufferedReader(new InputStreamReader(
							content));
					String s = "";
					while ((s = buffer.readLine()) != null) {
						response += s;
					}

				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			return response;
		}

		@Override
		protected void onPostExecute(String result) {
			progressBar.setVisibility(View.INVISIBLE);
			textView.setText(result);
		}
	}

	private void downloadPage() {
		if (mTask != null
				&& mTask.getStatus() != DownloadWebPageTask.Status.FINISHED) {
			mTask.cancel(true);
		}
               // execute(String[]) you can put array of links to web pages, or array of Integer[] 
               // if first param is Integer[] etc.
		mTask = (DownloadWebPageTask) new DownloadWebPageTask()
				.execute(new String[] { "//android.okhelp.cz/android-market.html",
						"//android.okhelp.cz/android-market.html" });
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();

		if (mTask != null
				&& mTask.getStatus() != DownloadWebPageTask.Status.FINISHED) {
			mTask.cancel(true);
			mTask = null;
		}
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	}

}




activity_main.xml

<LinearLayout xmlns:android="//schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ProgressBar
        android:id="@+id/progressBar1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/TextView01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

</LinearLayout>



AndroidManifest.xml do not forget INTERNET uses-permission !!!!!!!

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



Editace: 2011-09-29 21:08:34
Počet článků v kategorii: 397
Url:how-are-you-old-date-calendar-age-java-android-example

AD
11 Share
Share
Tweet