package mobile.about;
import com.mobile.learning.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
public class about extends Activity implements
OnClickListener {
/**
Called when the activity is first created. */
@Override
public void
onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.about);
}
public
void onClick(View v) {
//
TODO Auto-generated method stub
}
}
<?xml version="1.0"
encoding="utf-8"?>
<AbsoluteLayout
android:id="@+id/AbsoluteLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#ffffff">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textColor="#000000"
android:gravity="left"
android:layout_x="10dip" android:layout_y="115dip"
android:id="@+id/aboutIsi"
android:text="INI ABOUT
OPTIONAL :)"></TextView>
<TextView android:layout_width="wrap_content"
android:textSize="20px" android:gravity="center"
android:text="SELAMAT DATANG DI MOBILE LEARNING"
android:layout_height="wrap_content" android:id="@+id/aboutJudul"
android:textStyle="bold"
android:textColor="#000000"
android:layout_x="0dip" android:layout_y="28dip"></TextView>
</AbsoluteLayout>
Berita
package mobile.berita;
import mobile.config.koneksi;
import mobile.kelas.rss.RSSFeed;
import mobile.kelas.rss.RSSHandler;
import mobile.kelas.rss.RSSItem;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import com.mobile.learning.R;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
public class berita extends ListActivity {
public
koneksi linkurl;
String
SERVER_URL;
private
RSSFeed myRssFeed = null;
/** Called when
the activity is first created. */
@Override
public void
onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mainrss);
try {
linkurl = new
koneksi("mobile/berita.php");
SERVER_URL
= linkurl.getUrl();
URL
rssUrl = new URL(SERVER_URL);
SAXParserFactory
mySAXParserFactory = SAXParserFactory.newInstance();
SAXParser
mySAXParser = mySAXParserFactory.newSAXParser();
XMLReader
myXMLReader = mySAXParser.getXMLReader();
RSSHandler
myRSSHandler = new RSSHandler();
myXMLReader.setContentHandler(myRSSHandler);
InputSource
myInputSource = new InputSource(rssUrl.openStream());
myXMLReader.parse(myInputSource);
myRssFeed
= myRSSHandler.getFeed();
}
catch (MalformedURLException e) {
//
TODO Auto-generated catch block
e.printStackTrace();
}
catch (ParserConfigurationException e) {
//
TODO Auto-generated catch block
e.printStackTrace();
}
catch (SAXException e) {
//
TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e) {
//
TODO Auto-generated catch block
e.printStackTrace();
}
if
(myRssFeed!=null)
{
TextView
feedTitle = (TextView)findViewById(R.id.feedtitle);
TextView
feedDescribtion = (TextView)findViewById(R.id.feeddescribtion);
TextView
feedPubdate = (TextView)findViewById(R.id.feedpubdate);
TextView
feedLink = (TextView)findViewById(R.id.feedlink);
feedTitle.setText(myRssFeed.getTitle());
feedDescribtion.setText(myRssFeed.getDescription());
feedPubdate.setText(myRssFeed.getPubdate());
feedLink.setText(myRssFeed.getLink());
ArrayAdapter<RSSItem>
adapter =
new ArrayAdapter<RSSItem>(this,
android.R.layout.simple_list_item_1,myRssFeed.getList());
setListAdapter(adapter);
}
}
@Override
protected
void onListItemClick(ListView l, View v, int position, long id) {
//
TODO Auto-generated method stub
Intent
intent = new Intent(this,beritaDetail.class);
Bundle
bundle = new Bundle();
bundle.putString("keyTitle",
myRssFeed.getItem(position).getTitle());
bundle.putString("keyDescription",
myRssFeed.getItem(position).getDescription());
bundle.putString("keyLink",
myRssFeed.getItem(position).getLink());
bundle.putString("keyPubdate",
myRssFeed.getItem(position).getPubdate());
intent.putExtras(bundle);
startActivity(intent);
}
}
<?xml version="1.0"
encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/detailstitle" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/detailsdescription" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:autoLink="web"
android:id="@+id/detailslink" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/detailspubdate" />
</LinearLayout>
package mobile.berita;
import com.mobile.learning.R;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class beritaDetail extends Activity {
@Override
protected
void onCreate(Bundle savedInstanceState) {
//
TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.detailberita);
TextView
detailsTitle = (TextView)findViewById(R.id.detailstitle);
TextView
detailsDescription = (TextView)findViewById(R.id.detailsdescription);
TextView
detailsPubdate = (TextView)findViewById(R.id.detailspubdate);
TextView
detailsLink = (TextView)findViewById(R.id.detailslink);
Bundle
bundle = this.getIntent().getExtras();
detailsTitle.setText(bundle.getString("keyTitle"));
detailsDescription.setText(bundle.getString("keyDescription"));
detailsPubdate.setText(bundle.getString("keyPubdate"));
detailsLink.setText(bundle.getString("keyLink"));
}
}
Upload
package mobile.upload;
import mobile.config.koneksi;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import com.mobile.learning.R;
import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
public class upload extends ListActivity {
public
koneksi linkurl;
String
SERVER_URL;
private
List<String> item = null;
private
List<String> path = null;
private
String root="/";
private
EditText myPathText;
/** Called when
the activity is first created. */
@Override
public void
onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.upload);
Bundle bundle
= this.getIntent().getExtras();
final String
param1 = bundle.getString("idc");
final String
param2 = bundle.getString("idtgs");
final String
param3 = bundle.getString("idu");
Button up =
(Button) findViewById(R.id.uploading);
myPathText =
(EditText) findViewById(R.id.alamat);
getDir(root);
up.setOnClickListener(new OnClickListener() {
public
void onClick(View v) {
//
TODO Auto-generated method stub
try
{
linkurl
= new
koneksi("/uploadProses.php?idc="+param1+"&idtgs="+param2+"&idu="+param3);
SERVER_URL
= linkurl.getUrl();
Uploader
uploader = new Uploader();
uploader.setUrlAndFile(SERVER_URL,
((EditText)findViewById(R.id.alamat)).getText().toString(),(TextView)(findViewById(R.id.info)));
uploader.execute();
}
catch(Exception
e)
{
((EditText)findViewById(R.id.alamat)).setText(e.toString());
}
}
});
}
private void
getDir(String dirPath)
{
myPathText.setText(dirPath);
item = new
ArrayList<String>();
path = new
ArrayList<String>();
File f = new File(dirPath);
File[] files = f.listFiles();
if(!dirPath.equals(root))
{
item.add(root);
path.add(root);
item.add("../");
path.add(f.getParent());
}
for(int i=0; i < files.length;
i++)
{
File
file = files[i];
path.add(file.getPath());
if(file.isDirectory())
item.add(file.getName()
+ "/");
else
item.add(file.getName());
}
ArrayAdapter<String> fileList
=
new
ArrayAdapter<String>(this, R.layout.row, item);
setListAdapter(fileList);
}
@Override
protected
void onListItemClick(ListView l, View v, int position, long id) {
File
file = new File(path.get(position));
if
(file.isDirectory())
{
if(file.canRead())
getDir(path.get(position));
else
{
new
AlertDialog.Builder(this)
.setTitle("["
+ file.getName() + "] folder can't be read!")
.setPositiveButton("OK",
new
DialogInterface.OnClickListener() {
public
void onClick(DialogInterface dialog, int which) {
//
TODO Auto-generated method stub
}
}).show();
}
}
else
{
myPathText.setText(file.getPath());
}
}
}
<?xml version="1.0"
encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:background="#ffffff"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/info"
android:text="INFO"
android:textColor="#000000"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/path"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<EditText
android:id="@+id/alamat"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:layout_x="20dip"
android:layout_y="100dip"></EditText>
<Button
android:layout_height="50px"
android:layout_width="120px"
android:textStyle="bold"
android:text="UPLOAD"
android:id="@+id/uploading"></Button>
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@android:id/empty"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text="No Data"
/>
</LinearLayout>
package mobile.upload;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import android.os.AsyncTask;
import android.widget.TextView;
public class Uploader extends AsyncTask<Object, String,
Object>
{
URL
connectURL;
String
params;
String
responseString;
String
fileName;
byte[]
dataToServer;
FileInputStream
fileInputStream;
TextView
info;
void
setUrlAndFile(String urlString, String fileName, TextView info)
{
this.info
= info;
try
{
fileInputStream
= new FileInputStream(fileName);
connectURL
= new URL(urlString);
}
catch(Exception
e)
{
publishProgress(e.toString());
}
this.fileName
= fileName;
}
synchronized
void doUpload()
{
String
lineEnd = "\r\n";
String
twoHyphens = "--";
String
boundary = "*****";
try
{
publishProgress("Sedang
Upload...");
HttpURLConnection
conn = (HttpURLConnection) connectURL.openConnection();
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setUseCaches(false);
conn.setRequestMethod("POST");
conn.setRequestProperty("Connection",
"Keep-Alive");
conn.setRequestProperty("Content-Type",
"multipart/form-data;boundary="+boundary);
DataOutputStream
dos = new DataOutputStream( conn.getOutputStream() );
dos.writeBytes(twoHyphens
+ boundary + lineEnd);
dos.writeBytes("Content-Disposition:
form-data; name=\"userfile\";filename=\"" + fileName
+"\"" + lineEnd);
dos.writeBytes(lineEnd);
int
bytesAvailable = fileInputStream.available();
int
maxBufferSize = 1024;
int
bufferSize = Math.min(bytesAvailable, maxBufferSize);
byte[]
buffer = new byte[bufferSize];
int
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
while
(bytesRead > 0)
{
dos.write(buffer,
0, bufferSize);
bytesAvailable
= fileInputStream.available();
bufferSize
= Math.min(bytesAvailable, maxBufferSize);
bytesRead
= fileInputStream.read(buffer, 0, bufferSize);
}
dos.writeBytes(lineEnd);
dos.writeBytes(twoHyphens
+ boundary + twoHyphens + lineEnd);
fileInputStream.close();
dos.flush();
InputStream
is = conn.getInputStream();
int
ch;
StringBuffer
buff = new StringBuffer();
while((ch=is.read())!=-1)
{
buff.append((char)ch);
}
publishProgress(buff.toString());
dos.close();
}
catch
(Exception e)
{
publishProgress(e.toString());
}
}
@Override
protected
Object doInBackground(Object... arg0) {
doUpload();
return
null;
}
protected
void onProgressUpdate(String... progress) {
this.info.setText(progress[0]);
}
}
..
package mobile.upload;
import mobile.config.koneksi;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import com.mobile.learning.R;
import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
public class uploadUpdate extends ListActivity {
public
koneksi linkurl;
String
SERVER_URL;
private
List<String> item = null;
private
List<String> path = null;
private
String root="/";
private
EditText myPathText;
/** Called when
the activity is first created. */
@Override
public void
onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.upload);
Bundle bundle
= this.getIntent().getExtras();
final String
param1 = bundle.getString("idc");
final String
param2 = bundle.getString("idtgs");
final String
param3 = bundle.getString("idu");
final String
param4 = bundle.getString("idas");
Button up =
(Button) findViewById(R.id.uploading);
myPathText =
(EditText) findViewById(R.id.alamat);
getDir(root);
up.setOnClickListener(new OnClickListener() {
public
void onClick(View v) {
//
TODO Auto-generated method stub
try
{
linkurl
= new
koneksi("/uploadUpdate.php?idc="+param1+"&idtgs="+param2+"&idu="+param3+"&idas="+param4);
SERVER_URL
= linkurl.getUrl();
Uploader
uploader = new Uploader();
uploader.setUrlAndFile(SERVER_URL,
((EditText)findViewById(R.id.alamat)).getText().toString(),(TextView)(findViewById(R.id.info)));
uploader.execute();
}
catch(Exception
e)
{
((EditText)findViewById(R.id.alamat)).setText(e.toString());
}
}
});
}
private void
getDir(String dirPath)
{
myPathText.setText(dirPath);
item = new
ArrayList<String>();
path = new
ArrayList<String>();
File f = new File(dirPath);
File[] files = f.listFiles();
if(!dirPath.equals(root))
{
item.add(root);
path.add(root);
item.add("../");
path.add(f.getParent());
}
for(int i=0; i < files.length;
i++)
{
File
file = files[i];
path.add(file.getPath());
if(file.isDirectory())
item.add(file.getName()
+ "/");
else
item.add(file.getName());
}
ArrayAdapter<String> fileList
=
new
ArrayAdapter<String>(this, R.layout.row, item);
setListAdapter(fileList);
}
@Override
protected
void onListItemClick(ListView l, View v, int position, long id) {
File
file = new File(path.get(position));
if
(file.isDirectory())
{
if(file.canRead())
getDir(path.get(position));
else
{
new
AlertDialog.Builder(this)
.setTitle("["
+ file.getName() + "] folder can't be read!")
.setPositiveButton("OK",
new
DialogInterface.OnClickListener() {
public
void onClick(DialogInterface dialog, int which) {
//
TODO Auto-generated method stub
}
}).show();
}
}
else
{
myPathText.setText(file.getPath());
}
}
}
Bersambung...

Tidak ada komentar:
Posting Komentar