-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
xml parsing of online manifest and more
- Loading branch information
Showing
18 changed files
with
706 additions
and
337 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,21 +1,13 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | <?xml version="1.0" encoding="utf-8"?> | ||
<resources> | <resources> | ||
|
|
||
<!-- Where to download wallpapers from --> | <!-- Where to store the wallpapers (just the folder name) --> | ||
<string name="config_wallpaper_url_prefix">http://dl.dropbox.com/u/87565/AOKP/wallpapers/</string> | <string name="config_wallpaper_sdcard_dl_location">AOKP</string> | ||
|
|
||
<!-- Prefix of each wallpaper --> | <!-- Directory to download wallpapers to on external storage. Leave blank for "/sdcard/" --> | ||
<string name="config_wallpaper_name_prefix">aokp_</string> | <string name="config_wallpaper_download_loc"></string> | ||
|
|
||
<!-- Wallpaper extention --> | <!-- url to the wallpaper manifest --> | ||
<string name="config_wallpaper_extention">.png</string> | <string name="config_wallpaper_manifest_url">http://romanbb.github.com/swagpapers_manifest/wallpaper_manifest.xml</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> | |||
</resources> | </resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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")) { | |||
|
|||
} | |||
|
|||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.