xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/bg_2">
<RelativeLayout
android:id="@+id/absoluteLayout1"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
>
<Button
android:id="@+id/lanjut"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:background="#575c5c"
android:text="Selanjutnya" />
<Button
android:id="@+id/balik"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:background="#575c5c"
android:text="Kembali" />
</RelativeLayout>
<TextView
android:id="@+id/judul"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_gravity="center"
android:gravity="center"
android:text="judul"
android:textAppearance="?android:attr/textAppearanceMedium" />
<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/absoluteLayout1"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true" >
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="280dp"
android:layout_height="164dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:gravity="center" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/isi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="isi" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/relativeLayout1"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/judul"
android:background="@drawable/back1" >
<ImageView
android:id="@+id/gambar"
android:layout_width="280dp"
android:layout_height="146dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
</RelativeLayout>
</RelativeLayout>
public void loadImagesFromAsset() {
try {
InputStream ims =null;
ims = getAssets().open(gambar);
Drawable d = Drawable.createFromStream(ims, null);
Img.setImageDrawable(d);
}
catch (IOException e) {e.printStackTrace();}
}
package com.example.downloadfrwebserver;
import java.io.BufferedInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLConnection;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.util.Log;
import android.view.Menu;
public class MainActivity extends Activity {
// Progress Dialog
private ProgressDialog pDialog;
public static final int progress_bar_type = 0;
// File url to download
private static String file_url = "http://192.168.1.2/AJAXAJAXDUNK/test.jpg";
//http://www.qwikisoft.com/demo/ashade/20001.kml
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new DownloadFileFromURL().execute(file_url);
}
/**
* Showing Dialog
* */
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case progress_bar_type: // we set this to 0
pDialog = new ProgressDialog(this);
pDialog.setMessage("Downloading file. Please wait...");
pDialog.setIndeterminate(false);
pDialog.setMax(100);
pDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
pDialog.setCancelable(true);
pDialog.show();
return pDialog;
default:
return null;
}
}
/**
* Background Async Task to download file
* */
class DownloadFileFromURL extends AsyncTask<String, String, String> {
/**
* Before starting background thread Show Progress Bar Dialog
* */
@Override
protected void onPreExecute() {
super.onPreExecute();
showDialog(progress_bar_type);
}
/**
* Downloading file in background thread
* */
@Override
protected String doInBackground(String... f_url) {
int count;
try {
URL url = new URL(f_url[0]);
URLConnection conection = url.openConnection();
conection.connect();
// this will be useful so that you can show a tipical 0-100%
// progress bar
int lenghtOfFile = conection.getContentLength();
// download the file
InputStream input = new BufferedInputStream(url.openStream(),
8192);
// Output stream
OutputStream output = new FileOutputStream(Environment
.getExternalStorageDirectory().toString()
+ "/2011.kml");
byte data[] = new byte[1024];
long total = 0;
while ((count = input.read(data)) != -1) {
total += count;
// publishing the progress....
// After this onProgressUpdate will be called
publishProgress("" + (int) ((total * 100) / lenghtOfFile));
// writing data to file
output.write(data, 0, count);
}
// flushing output
output.flush();
// closing streams
output.close();
input.close();
} catch (Exception e) {
Log.e("Error: ", e.getMessage());
}
return null;
}
/**
* Updating progress bar
* */
protected void onProgressUpdate(String... progress) {
// setting progress percentage
pDialog.setProgress(Integer.parseInt(progress[0]));
}
/**
* After completing background task Dismiss the progress dialog
* **/
@Override
protected void onPostExecute(String file_url) {
// dismiss the dialog after the file was downloaded
dismissDialog(progress_bar_type);
}
}
}
package com.example.formtabstd2lp2maray;
import android.app.Activity;
import android.app.TabActivity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TabHost;
import android.widget.TabWidget;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TabHost.TabContentFactory;
import android.widget.TabHost.TabSpec;
//Custom Tabs
public class formTabStd2Lp2mAray extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TabHost host = this.getTabHost();
host.addTab(host.newTabSpec("one")
.setIndicator("APLIKASI", getResources().getDrawable(R.drawable.icon1))
.setContent(new Intent(this, profil.class)));
Intent intentCari= new Intent().setClass(this, tentang.class);
host.addTab(host.newTabSpec("two")
.setIndicator("PENCARIAN")
.setContent(intentCari));
host.addTab(host.newTabSpec("three")
.setIndicator("KOSAKATA")
.setContent(new Intent(this, profil.class)));
//.setContent(R.id.details);// TableLayout atau linierlayout
host.setCurrentTab(0);
}
}
package com.lp2m.pdfdemo;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import com.itextpdf.text.Document;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;
//import com.cete.androidexamples.dynamicpdf.helloworld.Document;
//import com.cete.androidexamples.dynamicpdf.helloworld.Exception;
//import com.cete.androidexamples.dynamicpdf.helloworld.Paragraph;
//import com.cete.androidexamples.dynamicpdf.helloworld.String;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Font;
import com.lowagie.text.HeaderFooter;
import com.lowagie.text.Image;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Phrase;
import com.lowagie.text.pdf.PdfWriter;
public class MainActivity extends Activity {
private Button b;
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b= (Button)findViewById(R.id.button1);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
baca();
}});
}
void baca(){
String path ="";
try {
path = Environment.getExternalStorageDirectory()+"/hello/";
File file = new File(path+"hello.pdf");
if(!file.exists()){
file.getParentFile().mkdirs();
try {
file.createNewFile();
}
catch (IOException e) {
}
}
Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream(Environment.getExternalStorageDirectory()
+File.separator
+"hello" //folder name
+File.separator
+"hello.pdf"));
document.open();
document.add(new Paragraph("Hello World 1" ));
document.add(new Paragraph("Hello World 2"));
document.add(new Paragraph("Hello World 3"));
document.add(new Paragraph("Hello World 4"));
document.close();
Log.d("OK", "done");
Toast.makeText(this, "Sukses Generate PDF :"+path, Toast.LENGTH_SHORT).show();
}
catch(Exception ee){
Toast.makeText(this, "Gagal Generate PDF :"+path, Toast.LENGTH_SHORT).show();
}
}
// public void createPDF() {
// Document doc = new Document();
// try {
// String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/droidText";
//
// File dir = new File(path);
// if(!dir.exists())
// dir.mkdirs();
//
// Log.d("PDFCreator", "PDF Path: " + path);
//
//
// File file = new File(dir, "sample.pdf");
// FileOutputStream fOut = new FileOutputStream(file);
//
// PdfWriter.getInstance(doc, fOut);
//
// //open the document
// doc.open();
//
//
// Paragraph p1 = new Paragraph("Hi! I am generating my first PDF using DroidText");
// Font paraFont= new Font(Font.COURIER);
// p1.setAlignment(Paragraph.ALIGN_CENTER);
// p1.setFont(paraFont);
//
// //add paragraph to document
// doc.add(p1);
//
// Paragraph p2 = new Paragraph("This is an example of a simple paragraph");
// Font paraFont2= new Font(Font.COURIER,14.0f,Color.GREEN);
// p2.setAlignment(Paragraph.ALIGN_CENTER);
// p2.setFont(paraFont2);
//
// doc.add(p2);
//
// ByteArrayOutputStream stream = new ByteArrayOutputStream();
// Bitmap bitmap = BitmapFactory.decodeResource(getBaseContext().getResources(), R.drawable.android);
// bitmap.compress(Bitmap.CompressFormat.JPEG, 100 , stream);
// Image myImg = Image.getInstance(stream.toByteArray());
// myImg.setAlignment(Image.MIDDLE);
//
// //add image to document
// doc.add(myImg);
//
// //set footer
// Phrase footerText = new Phrase("This is an example of a footer");
// HeaderFooter pdfFooter = new HeaderFooter(footerText, false);
// doc.setFooter(pdfFooter);
//
//
//
// } catch (DocumentException de) {
// Log.e("PDFCreator", "DocumentException:" + de);
// } catch (IOException e) {
// Log.e("PDFCreator", "ioException:" + e);
// }
// finally
// {
// doc.close();
// }
//
// }
}
GESTURE:
package com.example.seven.gesturemandarin;
import android.Manifest;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Environment;
import android.support.v4.app.ActivityCompat;
import android.view.View;
import android.widget.Button;
import android.widget.Switch;
import com.example.seven.gesturemandarin.R;
import com.example.seven.gesturemandarin.view.DrawingArea;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class DrawingTestActivity extends Activity {
private DrawingArea drawingArea;
private Button btnCek, btnBersih;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ActivityCompat.requestPermissions(this,new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},00);
btnBersih = (Button) findViewById(R.id.clear_btn);
btnCek = (Button) findViewById(R.id.check_btn);
btnCek.setOnClickListener(new View.OnClickListener() {
public void onClick(View vi)
{
btnCek.setVisibility(View.INVISIBLE);
btnBersih.setVisibility(View.INVISIBLE);
View v = getWindow().getDecorView().getRootView();
v.setDrawingCacheEnabled(true);
Bitmap bmp = Bitmap.createBitmap(v.getDrawingCache());
v.setDrawingCacheEnabled(false);
try {
FileOutputStream fos = new FileOutputStream(new File(Environment
.getExternalStorageDirectory().toString(), "SCREEN"
+ System.currentTimeMillis() + ".png"));
bmp.compress(Bitmap.CompressFormat.PNG, 100, fos);
fos.flush();
fos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Intent i = new Intent (DrawingTestActivity.this, DrawingTestActivity.class);
startActivity(i);
finish();
}
});
}
@Override
public void onPause() {
super.onPause();
drawingArea.trimMemory();
}
@Override
public void onResume() {
super.onResume();
initDrawingArea();
}
private void initDrawingArea() {
if (drawingArea == null) {
drawingArea = (DrawingArea) findViewById(R.id.drawing_area);
drawingArea.initTrailDrawer();
drawingArea.onMarkerSelected();
}
}
/** on click, see layout.xml */
public void onQuillSelected(View view) {
drawingArea.onQuillSelected();
}
/** on click, see layout.xml */
public void onMarkerSelected(View view) {
drawingArea.onMarkerSelected();
}
/** on click, see layout.xml */
public void onClearSelected(View view) {
drawingArea.onClearSelected();
}
/** on click, see layout.xml */
public void onMultistrokeSwitchToggled(View view) {
Switch toggle = (Switch) view;
drawingArea.onMultistrokeSwitchToggled(toggle.isChecked());
}
}
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.seven.gesturemandarin.DrawingTestActivity" >
<Button
android:id="@+id/btn_tes"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="@string/check"
android:onClick="onCheck"
android:visibility="gone"/>
<LinearLayout
android:id="@+id/toolbar"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center|bottom">
<Button
android:id="@+id/check_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/check"
/>
<Button
android:id="@+id/clear_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/clear"
android:onClick="onClearSelected"
/>
</LinearLayout>
<com.example.seven.gesturemandarin.view.DrawingArea
android:id="@+id/drawing_area"
android:layout_above="@id/toolbar"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/white" />
</RelativeLayout>
ANDROID PDF2:
package com.asfa.androidpdf;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Font;
import com.lowagie.text.HeaderFooter;
import com.lowagie.text.Image;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Phrase;
import com.lowagie.text.pdf.PdfWriter;
public class MainActivity extends Activity {
private Button b;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b= (Button)findViewById(R.id.button1);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
createPDF();
}
});
}
public void createPDF()
{
Document doc = new Document();
try {
String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/droidText";
File dir = new File(path);
if(!dir.exists())
dir.mkdirs();
Log.d("PDFCreator", "PDF Path: " + path);
File file = new File(dir, "sample.pdf");
FileOutputStream fOut = new FileOutputStream(file);
PdfWriter.getInstance(doc, fOut);
//open the document
doc.open();
Paragraph p1 = new Paragraph("Hi! Saya membuat file PDF dengan DroidText");
Font paraFont= new Font(Font.COURIER);
p1.setAlignment(Paragraph.ALIGN_CENTER);
p1.setFont(paraFont);
//add paragraph to document
doc.add(p1);
Paragraph p2 = new Paragraph("Ini adalah contoh paragraf sederhana");
Font paraFont2= new Font(Font.COURIER,14.0f,Color.GREEN);
p2.setAlignment(Paragraph.ALIGN_CENTER);
p2.setFont(paraFont2);
doc.add(p2);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
Bitmap bitmap = BitmapFactory.decodeResource(getBaseContext().getResources(), R.drawable.logo);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100 , stream);
Image myImg = Image.getInstance(stream.toByteArray());
myImg.setAlignment(Image.MIDDLE);
//add image to document
doc.add(myImg);
//set footer
Phrase footerText = new Phrase("This is an example of a footer");
HeaderFooter pdfFooter = new HeaderFooter(footerText, false);
doc.setFooter(pdfFooter);
} catch (DocumentException de) {
Log.e("PDFCreator", "DocumentException:" + de);
} catch (IOException e) {
Log.e("PDFCreator", "ioException:" + e);
}
finally
{
doc.close();
}
//Buka file pdf otomatis dengan pdf reader
File file= new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/droidText/sample.pdf");
if (file.exists())
{
Uri path = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(path, "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
try {
startActivity(intent);
finish();
}
catch (ActivityNotFoundException e) {
Toast.makeText(MainActivity.this, "Tidak Ada aplikasi untuk membuka file PDF", Toast.LENGTH_SHORT).show();
}
}
}
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<Button android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Buat PDF" />
</RelativeLayout>
Tidak ada komentar:
Posting Komentar