Draw Rect Android basic example
drawRect(), Paint, setStroke(), setStyle(), Canvas example source code.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new SampleView(this));
}
private static class SampleView extends View {
// CONSTRUCTOR
public SampleView(Context context) {
super(context);
setFocusable(true);
}
@Override
protected void onDraw(Canvas canvas) {
canvas.drawColor(Color.CYAN);
Paint p = new Paint();
// smooths
p.setAntiAlias(true);
p.setColor(Color.RED);
p.setStyle(Paint.Style.STROKE);
p.setStrokeWidth(4.5f);
// opacity
//p.setAlpha(0x80); //
//drawRect (float left, float top, float right, float bottom, Paint paint)
canvas.drawRect(10, 10, 30, 30, p);
}
}
}
396LW NO topic_id
AD
Další témata ....(Topics)
drawArc(), Canvas, Paint, setStyle()
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new SampleView(this));
}
private static class SampleView extends View {
// CONSTRUCTOR
public SampleView(Context context) {
super(context);
setFocusable(true);
}
@Override
protected void onDraw(Canvas canvas) {
canvas.drawColor(Color.CYAN);
Paint p = new Paint();
// smooths
p.setAntiAlias(true);
p.setColor(Color.RED);
p.setStyle(Paint.Style.STROKE);
p.setStrokeWidth(5);
// opacity
//p.setAlpha(0x80); //
RectF rectF = new RectF(50, 20, 100, 80);
canvas.drawOval(rectF, p);
p.setColor(Color.BLACK);
canvas.drawArc (rectF, 90, 45, true, p);
}
}
}
Cut, shear, clip, snip, crop a bitmap, picture, image Android example
public class ApokusActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new SampleView(this));
}
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);
// you need to insert a image flower_blue into res/drawable folder
paint.setFilterBitmap(true);
Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(),
R.drawable.flower_blue);
Bitmap croppedBmp = Bitmap.createBitmap(bitmapOrg, 0, 0,
bitmapOrg.getWidth() / 2, bitmapOrg.getHeight());
int h = bitmapOrg.getHeight();
canvas.drawBitmap(bitmapOrg, 10, 10, paint);
canvas.drawBitmap(croppedBmp, 10, 10 + h + 10, paint);
}
}
}
Kvalitní mobilní telefon pro rok 2012 by měl mít tyto, nebo ještě lepší parametry.
Značka Samsung , HTC, LG, Motorola, Sony Ericsson, ZTE Blade
Verze operačního systému Android 2.2 a vyšší.
Procesor a jeho frekvence Qualcomm 800MHz a vyšší.
Paměť RAM 512MB a více.
Paměť ROM 512MB.
Displej a jeho rozlišení 4,3 palce rozlišení 480x800 pixelů pro snadné ovládání a čtení a schopnost zobrazit 16 milionů barev.
Technologie 3G data, WiFi, BlueTooth, GPS přijímač, fotoaparát 3 Mpix, autofokus, diodový blesk.
Výdrž baterie minimálně 1 den a více.
3G internet.
Značka Samsung , HTC, LG, Motorola, Sony Ericsson, ZTE Blade
Verze operačního systému Android 2.2 a vyšší.
Procesor a jeho frekvence Qualcomm 800MHz a vyšší.
Paměť RAM 512MB a více.
Paměť ROM 512MB.
Displej a jeho rozlišení 4,3 palce rozlišení 480x800 pixelů pro snadné ovládání a čtení a schopnost zobrazit 16 milionů barev.
Technologie 3G data, WiFi, BlueTooth, GPS přijímač, fotoaparát 3 Mpix, autofokus, diodový blesk.
Výdrž baterie minimálně 1 den a více.
3G internet.
The Android WebView changing the height according to text size.
If you need to change the height to a minimum try this source:
If you need to change the height to a minimum try this source:
//public void loadDataWithBaseURL (String baseUrl, String data, String mimeType, String encoding, String historyUrl)
WebView _webView; // findById(.....
String entryContent = "";
_webView.loadDataWithBaseURL(
"blabol",// javascript i styly
entryContent, null,
"utf-8", null
);
MainActivity.java
activity_main.xml
AndroidManifest.xml do not forget INTERNET uses-permission !!!!!!!
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: 2013-12-09 13:11:19
Počet článků v kategorii: 396
Url:draw-rect-android-basic-example