Create Image From View Screen Android
WebView_webview = (WebView)findViewById(R.id.webViewMapa);
_webview.getSettings().setBuiltInZoomControls(true);
_webview.setBackgroundColor(Color.parseColor("#E8EAE8"));
// _webview.loadUrl( ... some your page
Bitmap b = Bitmap.createBitmap(_webview.getWidth()/2, _webview.getHeight(), Bitmap.Config.ARGB_8888);
// you can to draw on bitmap
Canvas c = new Canvas(b);
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setStrokeWidth(15.f);
paint.setColor(Color.RED);
paint.setStyle(Paint.Style.STROKE);
//paint.setShadowLayer(5.f, 0, 5.f, 0xFF000000);
_webview.draw(c); // put into canvas content of view like image
c.drawLine(70, 0, 150, 350, paint);// draw some line
//Rect oval = new Rect(0, 0, 100, 100);
//c.drawArc(oval, 0, 180, false, paint);
// you can show bitmap in other view
((ImageView)findViewById(R.id.imageView1)).setImageBitmap(b);
396LW NO topic_id
AD
Další témata ....(Topics)
String sFileContent = readFile("myfile.txt",StandardCharsets.UTF_8);
static String readFile(String path, Charset encoding)
throws IOException
{
byte[] encoded = Files.readAllBytes(Paths.get(path));
return encoding.decode(ByteBuffer.wrap(encoded)).toString();
}
// write file
String sOut = "text blah hello world etc.";
writeToFile(sOut"someName.txt");
static void writeToFile(String sB,String name) {
String folder = ("c:\\folder\");
File f = new File(folder+ name);
BufferedWriter writer = null;
writer = new BufferedWriter( new OutputStreamWriter(
new FileOutputStream( folder+name),"UTF-8"));
writer.write( sB);
if ( writer != null)
writer.close( );
}
Dil 4. ArticleFragment.java
V 1. dílu jsme se něco dozvěděli od XML souborech a typu procesoru pro správný běh Android Studia a emulátoru různých typů zařizení s Androidem.
V 2. dílu jsme rozebrali MainActivity.java
V 3. dílu jsme se zabývali HeadlinesFragment.java
V tomto dílu se podíváme na ArticleFragment.java soubor.
Používáme příklad i zip porojekt z https://developer.android.com/training/basics/fragments/creating.html Pozorně si jej nastudujte.
V 1. dílu jsme se něco dozvěděli od XML souborech a typu procesoru pro správný běh Android Studia a emulátoru různých typů zařizení s Androidem.
V 2. dílu jsme rozebrali MainActivity.java
V 3. dílu jsme se zabývali HeadlinesFragment.java
V tomto dílu se podíváme na ArticleFragment.java soubor.
Používáme příklad i zip porojekt z https://developer.android.com/training/basics/fragments/creating.html Pozorně si jej nastudujte.
package com.example.android.fragments;
// knihovna pro nižší verze Androidu
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
// extends Fragment - už nebude obsahovat funkci onCreate jako v Activity
// ale onCreateView
public class ArticleFragment extends Fragment {
// důležité pro uložení argumentu - argumentů (hodnot)
// pro obnovení předchozího stavu obsahu obrazovky
// např. při rotaci zařízení atd.
final static String ARG_POSITION = "position";
int mCurrentPosition = -1;
TextView article; // uložen do globální proměnné, v originale
// odchycen v updateArticleView() ale tam vracel NULL
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Když je activity znovu vytvořena (např. při rotaci zařízení),
// obnoví, v našem případě, text článku, jehož pozice
// byla uložena pomocí
// public void onSaveInstanceState(Bundle outState) viz níže
// důležité zejména pro dual-panel (dva panely vedle sebe)
if (savedInstanceState != null) {
mCurrentPosition = savedInstanceState.getInt(ARG_POSITION);
}
// umístíme, aktivujeme příslušný layout
// zde je zajímavé, že layout můžete měnit.
// Např. při kliknutí na pložku 1 v HeadlinesFragment
// zde můžete ochytit pozici a dle toho zvolit
// příslušný layout, který chcete zobrazit ve fragmentu
// ALE pak si musíte pohlídat ID prvků, které bude ten JINÝ
// layout obsahovat
// Oproti originalu odchytíme TextView již zde, v originalu to vyhazovalo chybu
View rootView = inflater.inflate(R.layout.vnitrek, container, false);
article = (TextView) rootView.findViewById(R.id.article);
return rootView;
}
@Override
public void onStart() {
super.onStart();
// Při startu fragmentu, zkontrolujte, zda existují nějaké argumenty
// předané do fragmentu.
// OnStart() je právě to správné místo, kde to udělat,
// protože layout s jednotlivými elementy byl již
// naloděn - aktivován, a můžeme bezpečně použít metody,
// které potřebují, aby jednotlivá ID elementů layoutu byla již
// aktivní, použitelná a nevracela NULL, což by mělo za následek
// pád aplikace
Bundle args = getArguments();
if (args != null) {
// vypsaní obsahu článku pomocí předaného argumentu (pozice) z HeadlinesFragment.java
updateArticleView(args.getInt(ARG_POSITION));
} else if (mCurrentPosition != -1) {
// vypsání článku dle pozice uložené např. při rotaci zařízení
// mCurrentPosition je definována (odchycena) v onCreateView
updateArticleView(mCurrentPosition);
}
}
/**
funkce která vypíše obsah článku do TextView.
Jako parametr int position je pozice položky,
na kterou bylo kliknuto v ListView v HeadlinesFragment.java
*/
public void updateArticleView(int position) {
// na rozdíl od Activity se ve Fragment používá k
// získání id ne jen findViewById()
// ALE getActivity().findViewById()
//Tento kod vracel article == NULL , PROTO bylo nutno odchytit TextView
// v onCreateView()
//TextView article = (TextView) getActivity().findViewById(R.id.article);
// vložení textu článku do TextView z Ipsum.java
// je to pole stringů, kde position je pozice stringu v poli
// static String[] Articles = {"","",""};
if (article != null)
article.setText(Ipsum.Articles[position]);
mCurrentPosition = position;
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
// Uložení pozice článku - elementu, či jiných argumentů důležitých
// pro obnovení stavu v onCreateView() např. při rotaci zařízení
outState.putInt(ARG_POSITION, mCurrentPosition);
// TIP: zde můžeme vždy při rotaci zařízení podstrčit náhodnou pozici
// článku pomocí
// randomNum = minimum + (int)(Math.random() * maximum);
// a vytvořit tak zábavnou hru, například pro náhodné
// vypsání přísloví, či nějakého fyzikálního zákona atd.
// Stačí pak aby uživatel jen pootočil zařízení od 90° a zpět,
// k vypsání nové položky
}
}
Screen Android example source code for developers.
Get orientation of screen.
Get orientation of screen.
public int getScreenOrientation() {
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
return 1; // Portrait Mode
}else if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
return 2; // Landscape mode
}
return 0;
}
Try reboot device.
Start device with start button on side of phone.
Screen will go to light black color.
Long press Start button for menu:
Power off
Reboot
Airplane mode
Reboot item is in same level like Start button.
Click on the screen - (Hear a click)
Now find OK button , it is under Reboot item on right side of screen.
Press OK (Hear a click)
Wait a moment.
If device to do nothing , try short press Start button (sreen will black)
and again to press Start button. If screen go to light black color,
try again find Reboot item as written above.
Start device with start button on side of phone.
Screen will go to light black color.
Long press Start button for menu:
Power off
Reboot
Airplane mode
Reboot item is in same level like Start button.
Click on the screen - (Hear a click)
Now find OK button , it is under Reboot item on right side of screen.
Press OK (Hear a click)
Wait a moment.
If device to do nothing , try short press Start button (sreen will black)
and again to press Start button. If screen go to light black color,
try again find Reboot item as written above.
"id cannot be resolved or is not a field” error
If you copy project to workspace or some code from other project you can get this error.
Try remove or add import your R file:
Check xml files.
Clean project by menu Project-Clean
Maybe you have to create new project end copy old source files to new project folders.
If you copy project to workspace or some code from other project you can get this error.
Try remove or add import your R file:
import com.example.app.R
Check xml files.
Clean project by menu Project-Clean
Maybe you have to create new project end copy old source files to new project folders.
Editace: 2013-07-08 07:38:23
Počet článků v kategorii: 396
Url:create-image-from-view-screen-android