Permalink
Browse files

xml parsing of online manifest and more

  • Loading branch information...
1 parent b4a128c commit fb41391d20ed7cbc47c5c78e1ad4222664a41a48 @romanbb committed Aug 2, 2012
View
@@ -14,3 +14,7 @@ gen/
# Local configuration file (sdk path, etc)
local.properties
+
+.classpath
+project.properties
+.project
View
@@ -5,7 +5,7 @@ LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := $(call all-subdir-java-files) $(call all-renderscript-files-under, src)
-LOCAL_PACKAGE_NAME := FNVPapers
+LOCAL_PACKAGE_NAME := SwagPapers
LOCAL_CERTIFICATE := shared
include $(BUILD_PACKAGE)
View
@@ -6,24 +6,26 @@
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="16" />
-
+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.SET_WALLPAPER" />
<uses-permission android:name="android.permission.INTERNET" />
-
+
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
- android:name=".Wallpaper"
+ android:name=".WallpaperActivity"
android:label="@string/title_activity_wallpaper" >
<intent-filter>
<action android:name="android.intent.action.SET_WALLPAPER" />
+
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
- <activity android:name=".Preview"
+ <activity
+ android:name=".Preview"
android:configChanges="orientation|screenSize" />
<activity android:name=".Vote" />
</application>
Deleted file not rendered
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Deleted file not rendered
@@ -54,7 +54,7 @@
android:layout_weight="1"
android:orientation="horizontal" >
- <ImageView
+ <com.aokp.swagpapers.ThumbnailView
android:id="@+id/imageView1"
android:layout_width="0dp"
android:layout_height="match_parent"
@@ -64,7 +64,7 @@
android:layout_marginTop="5dp"
android:layout_weight="1" />
- <ImageView
+ <com.aokp.swagpapers.ThumbnailView
android:id="@+id/imageView2"
android:layout_width="0dp"
android:layout_height="match_parent"
@@ -81,19 +81,19 @@
android:layout_weight="1"
android:orientation="horizontal" >
- <ImageView
+ <com.aokp.swagpapers.ThumbnailView
android:id="@+id/imageView3"
- android:layout_width="wrap_content"
+ android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:layout_weight="1" />
- <ImageView
+ <com.aokp.swagpapers.ThumbnailView
android:id="@+id/imageView4"
- android:layout_width="wrap_content"
+ android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
View
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent" >
+
+ <View
+ android:id="@+id/top_bar"
+ android:layout_width="wrap_content"
+ android:layout_height="42dip"
+ android:layout_alignParentTop="true"
+ android:background="#7F000000" />
+
+ <LinearLayout
+ android:layout_width="wrap_content"
+ android:layout_height="42dip"
+ android:layout_alignParentTop="true"
+ android:gravity="center_vertical" >
+
+ <TextView
+ android:id="@+id/name"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="8dip"
+ android:ellipsize="end"
+ android:singleLine="true"
+ android:text="name"
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ android:textColor="@android:color/white" />
+
+ <TextView
+ android:id="@+id/author"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="16dip"
+ android:ellipsize="end"
+ android:singleLine="true"
+ android:text="author"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ android:textColor="@android:color/white" />
+ </LinearLayout>
+
+ <ImageView
+ android:id="@+id/thumb"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:layout_below="@+id/top_bar"
+ android:layout_marginBottom="5dp"
+ android:layout_marginLeft="5dp"
+ android:layout_marginRight="5dp"
+ android:layout_marginTop="5dp"
+ android:contentDescription="@null"
+ android:scaleType="centerCrop"
+ android:src="@drawable/thumbnail" />
+
+</RelativeLayout>
View
@@ -1,21 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
- <!-- Where to download wallpapers from -->
- <string name="config_wallpaper_url_prefix">http://dl.dropbox.com/u/87565/AOKP/wallpapers/</string>
-
- <!-- Prefix of each wallpaper -->
- <string name="config_wallpaper_name_prefix">aokp_</string>
-
- <!-- Wallpaper extention -->
- <string name="config_wallpaper_extention">.png</string>
-
- <!-- Thumbnail suffix -->
- <string name="config_wallpaper_thumbnail_suffix">_small</string>
-
- <!-- Where to store the wallpapers (just the folder name) -->
- <string name="config_wallpaper_sdcard_dl_location">AOKP</string>
-
- <!-- Directory to download wallpapers to on external storage. Leave blank for "/sdcard/" -->
- <string name="config_wallpaper_download_loc"></string>
+ <!-- Where to store the wallpapers (just the folder name) -->
+ <string name="config_wallpaper_sdcard_dl_location">AOKP</string>
+
+ <!-- Directory to download wallpapers to on external storage. Leave blank for "/sdcard/" -->
+ <string name="config_wallpaper_download_loc"></string>
+
+ <!-- url to the wallpaper manifest -->
+ <string name="config_wallpaper_manifest_url">http://romanbb.github.com/swagpapers_manifest/wallpaper_manifest.xml</string>
+
</resources>
View
@@ -1,7 +1,7 @@
<resources>
- <string name="app_name">FNV Wallpapers</string>
- <string name="title_activity_wallpaper">FNV Wallpapers</string>
+ <string name="app_name">SwagPapers</string>
+ <string name="title_activity_wallpaper">Swag Papers</string>
<string name="back">Previous</string>
<string name="next">Next</string>
<string name="page">Page: </string>
@@ -0,0 +1,93 @@
+
+package com.aokp.swagpapers;
+
+import android.util.Log;
+
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
+public class ManifestXmlParser extends DefaultHandler {
+
+ private static final String TAG = "ManifestXMLParser";
+
+ ArrayList<WallpaperCategory> wallpaperCategories = new ArrayList<WallpaperCategory>();
+ WallpaperCategory currentCategory;
+ String value = null;
+
+ public ArrayList<WallpaperCategory> parse(File xmlFile) throws IOException {
+ try {
+ SAXParserFactory factory = SAXParserFactory.newInstance();
+ SAXParser saxParser = factory.newSAXParser();
+ saxParser.parse(xmlFile, this);
+ return wallpaperCategories;
+ } catch (ParserConfigurationException ex) {
+ Log.e(TAG, "", ex);
+ } catch (SAXException ex) {
+ Log.e(TAG, "", ex);
+ }
+ return null;
+ }
+
+ @Override
+ public void startElement(String uri, String localName, String qName,
+ org.xml.sax.Attributes attributes) throws SAXException {
+ if (qName.equalsIgnoreCase("category")) {
+ // create a new instance of employee
+ currentCategory = new WallpaperCategory(attributes.getValue("id"),
+ attributes.getValue("name"));
+ } else if (qName.equalsIgnoreCase("wallpaper")) {
+
+ Wallpaper wp = new Wallpaper();
+
+ String url = attributes.getValue("url");
+ String xmlThumbUrl = attributes.getValue("thumbUrl");
+ String author = attributes.getValue("author");
+ String date = attributes.getValue("date");
+ String name = attributes.getValue("name");
+
+ wp.setName(name != null ? name : "");
+ wp.setAuthor(author != null ? author : "");
+ wp.setDate(date != null ? date : "");
+ wp.setThumbUrl(xmlThumbUrl != null ? xmlThumbUrl : generateThumbUrl(url));
+ wp.setUrl(url);
+
+ currentCategory.addWallpaper(wp);
+
+ }
+ super.startElement(uri, localName, qName, attributes);
+ }
+
+ private String generateThumbUrl(String url) {
+ String prefix = url.substring(0, url.lastIndexOf("."));
+ String extention = url.substring(url.lastIndexOf("."));
+
+ String generatedUrl = prefix + "_small" + extention;
+ Log.i(TAG, "thumb url generated: " + generatedUrl);
+ return generatedUrl;
+ }
+
+ @Override
+ public void characters(char[] ch, int start, int length) throws SAXException {
+ value = new String(ch, start, length);
+ }
+
+ @Override
+ public void endElement(String uri, String localName, String qName) throws SAXException {
+
+ if (qName.equalsIgnoreCase("category")) {
+ wallpaperCategories.add(currentCategory);
+ } else if (qName.equalsIgnoreCase("wallpaper")) {
+
+ }
+
+ }
+}
@@ -1,20 +1,8 @@
package com.aokp.swagpapers;
-import java.io.BufferedInputStream;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.URL;
-import java.net.URLConnection;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-
-import com.koushikdutta.urlimageviewhelper.UrlImageViewHelper;
-
import android.app.ActionBar;
+import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.app.WallpaperManager;
@@ -24,7 +12,6 @@
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.os.Bundle;
-import android.os.Environment;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
@@ -35,12 +22,30 @@
import android.widget.ImageView;
import android.widget.Toast;
-public class Preview extends Wallpaper {
+import com.koushikdutta.urlimageviewhelper.UrlImageViewHelper;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URL;
+import java.net.URLConnection;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+public class Preview extends Activity {
+
+ final static String TAG = "Preview";
String link = "";
ProgressDialog mProgressDialog;
public static final int DIALOG_DOWNLOAD_PROGRESS = 0;
+ String fileDest = null;
+ String fileName = null;
+
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -60,20 +65,20 @@ public void onCreate(Bundle savedInstanceState) {
Log.d("PREVIEW", "url: " + link);
UrlImageViewHelper.setUrlDrawable(p, link);
} else {
- Intent home = new Intent(Preview.this, Wallpaper.class);
+ Intent home = new Intent(Preview.this, WallpaperActivity.class);
Toast.makeText(getApplicationContext(), "Something went wrong", Toast.LENGTH_LONG)
.show();
startActivity(home);
finish();
}
// Check if the FNV folder exists already
- File f = new File(getSvDir());
- Log.i(tag, "Check for external SD: " + f.getAbsolutePath());
+ File f = new File(WallpaperActivity.getSvDir(getApplicationContext()));
+ Log.i(TAG, "Check for external SD: " + f.getAbsolutePath());
if (f.isDirectory() && f.exists()) {
- Log.i(tag, "FNV folder exists");
+ Log.i(TAG, "FNV folder exists");
} else {
- Log.i(tag, "FNV folder does not exist. Creating...");
+ Log.i(TAG, "FNV folder does not exist. Creating...");
f.mkdirs();
}
@@ -263,7 +268,9 @@ protected String doInBackground(String... aurl) {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss");
Date now = new Date();
- fileName = formatter.format(now) + ext;
+ fileName = formatter.format(now)
+ + aurl[0].substring(aurl[0].lastIndexOf("."), aurl[0].length());
+ // TODO better way of finding the extention
int lengthOfFile = conexion.getContentLength();
Log.d("ANDRO_ASYNC", "Lenght of file: " + lengthOfFile);
@@ -305,4 +312,12 @@ protected void onPostExecute(String unused) {
Toast.LENGTH_LONG).show();
}
}
+
+ String getDlDir() {
+ return WallpaperActivity.getDlDir(getApplicationContext());
+ }
+
+ String getSvDir() {
+ return WallpaperActivity.getSvDir(getApplicationContext());
+ }
}
Oops, something went wrong.

0 comments on commit fb41391

Please sign in to comment.