Work done so far.
No files matched your search
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.studentersamfundet.app"
|
||||
android:versionCode="1"
|
||||
android:versionName="1.0">
|
||||
<uses-sdk android:minSdkVersion="8" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
|
||||
<uses-permission android:name="android.permission.INTERNET" ></uses-permission>
|
||||
|
||||
<application android:icon="@drawable/icon" android:label="@string/app_name">
|
||||
<activity android:name=".DnsActivity"
|
||||
android:label="@string/app_name">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name=".ProgramList"></activity>
|
||||
|
||||
</application>
|
||||
</manifest>
|
||||
@@ -0,0 +1,11 @@
|
||||
# This file is automatically generated by Android Tools.
|
||||
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
|
||||
#
|
||||
# This file must be checked in Version Control Systems.
|
||||
#
|
||||
# To customize properties used by the Ant build system use,
|
||||
# "build.properties", and override values to adapt the script to your
|
||||
# project structure.
|
||||
|
||||
# Project target.
|
||||
target=android-8
|
||||
@@ -0,0 +1,36 @@
|
||||
-optimizationpasses 5
|
||||
-dontusemixedcaseclassnames
|
||||
-dontskipnonpubliclibraryclasses
|
||||
-dontpreverify
|
||||
-verbose
|
||||
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
|
||||
|
||||
-keep public class * extends android.app.Activity
|
||||
-keep public class * extends android.app.Application
|
||||
-keep public class * extends android.app.Service
|
||||
-keep public class * extends android.content.BroadcastReceiver
|
||||
-keep public class * extends android.content.ContentProvider
|
||||
-keep public class * extends android.app.backup.BackupAgentHelper
|
||||
-keep public class * extends android.preference.Preference
|
||||
-keep public class com.android.vending.licensing.ILicensingService
|
||||
|
||||
-keepclasseswithmembernames class * {
|
||||
native <methods>;
|
||||
}
|
||||
|
||||
-keepclasseswithmembernames class * {
|
||||
public <init>(android.content.Context, android.util.AttributeSet);
|
||||
}
|
||||
|
||||
-keepclasseswithmembernames class * {
|
||||
public <init>(android.content.Context, android.util.AttributeSet, int);
|
||||
}
|
||||
|
||||
-keepclassmembers enum * {
|
||||
public static **[] values();
|
||||
public static ** valueOf(java.lang.String);
|
||||
}
|
||||
|
||||
-keep class * implements android.os.Parcelable {
|
||||
public static final android.os.Parcelable$Creator *;
|
||||
}
|
||||
|
After Width: | Height: | Size: 28 KiB |
|
After Width: | Height: | Size: 4.0 KiB |
|
After Width: | Height: | Size: 41 KiB |
|
After Width: | Height: | Size: 28 KiB |
|
After Width: | Height: | Size: 1.7 KiB |
|
After Width: | Height: | Size: 41 KiB |
|
After Width: | Height: | Size: 28 KiB |
|
After Width: | Height: | Size: 2.5 KiB |
|
After Width: | Height: | Size: 41 KiB |
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent" android:layout_height="fill_parent">
|
||||
<!-- Header -->
|
||||
<include layout="@layout/header" android:id="@+id/header"
|
||||
android:layout_height="80dip" android:layout_width="fill_parent" />
|
||||
|
||||
<!-- Program list (Added in Java.) -->
|
||||
|
||||
<!-- Footer -->
|
||||
<include layout="@layout/footer" android:id="@+id/footer" android:layout_height="wrap_content"
|
||||
android:layout_width="fill_parent" android:layout_alignParentBottom="true" />
|
||||
|
||||
</RelativeLayout>
|
||||
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/bottom_buttons" android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content" >
|
||||
<TextView
|
||||
android:id="@+id/program_button"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:ellipsize="end"
|
||||
android:textSize="40px"
|
||||
android:textStyle="bold"
|
||||
android:layout_marginLeft="20dip"
|
||||
android:onClick="clickHandler"
|
||||
android:clickable="true"
|
||||
android:text="@string/program_button" />
|
||||
<TextView
|
||||
android:id="@+id/bli_med_button"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_weight="0"
|
||||
android:layout_gravity="right"
|
||||
android:textSize="40px"
|
||||
android:textStyle="bold"
|
||||
android:layout_marginRight="20dip"
|
||||
android:onClick="clickHandler"
|
||||
android:clickable="true"
|
||||
android:text="@string/bli_med_button" />
|
||||
</LinearLayout>
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent" android:layout_height="80dip"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content" android:src="@drawable/dnstest"
|
||||
android:layout_gravity="center_vertical" android:layout_marginLeft="10dip"
|
||||
android:layout_marginRight="10dip" />
|
||||
|
||||
</LinearLayout>
|
||||
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent" android:layout_height="fill_parent">
|
||||
|
||||
<!-- Header -->
|
||||
<include layout="@layout/header" android:id="@+id/header"
|
||||
android:layout_height="80dip" android:layout_width="fill_parent" />
|
||||
|
||||
<!-- Formålsparagraf -->
|
||||
<ImageView android:layout_width="fill_parent"
|
||||
android:id="@+id/paragraph"
|
||||
android:layout_marginTop="100px"
|
||||
android:layout_height="wrap_content" android:layout_below="@id/header"
|
||||
android:src="@drawable/partest" />
|
||||
|
||||
<!-- Bli med-tekst -->
|
||||
<TextView
|
||||
android:id="@+id/join_us_textview"
|
||||
android:layout_marginTop="10px"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_below="@id/header"
|
||||
android:layout_weight="1"
|
||||
android:layout_marginLeft="20dip"
|
||||
android:text="@string/join_us" />
|
||||
|
||||
<!-- Footer -->
|
||||
<include layout="@layout/footer" android:id="@+id/footer" android:layout_height="wrap_content"
|
||||
android:layout_width="fill_parent" android:layout_alignParentBottom="true" />
|
||||
</RelativeLayout>
|
||||
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="app_name">Det Norske Studentersamfund</string>
|
||||
<string name="program_button">PROGRAM</string>
|
||||
<string name="bli_med_button">BLI MED</string>
|
||||
<string name="error_noconnection_firstart">Ingen nettilkobling. Du må være tilkoblet nettet for å se programmet.</string>
|
||||
<string name="error_noconnection_noupdate">Ingen nettilkobling. Programmet er altså ikke oppdatert.</string>
|
||||
<string name="join_us">Booke band, tappe øl eller lede politiske debatter? Du vil garantert finne noe av interesse hvis du har lyst til å bli aktiv i en av de mange foreningene som driver DNS. Her lærer vi alt du ikke hører om på forelesningene. Praktisk erfaring og utfordringer som kan være gull verdt når den voksne verden en gang banker på døren.\n\nHva vil du huske fra studietiden? Lesesalen? Pensum? Eksamensnerver? Det er nå du har sjansen til å skape minnene som varer hele livet. Venner, fester, gallamiddager og nach så lenge du orker.\n\n “Vi gir deg minnene fra studietiden du aldri vil glemme.”\n\nTa kontakt på blimed@studentersamfundet.no for mer informasjon!</string>
|
||||
</resources>
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.studentersamfundet.app;
|
||||
|
||||
public class DataHandler {
|
||||
Event events;
|
||||
|
||||
void insert(String id, String title, String description, String date, String location, String category) {
|
||||
int intId = Integer.parseInt(id);
|
||||
if (get(intId) != null)
|
||||
return;
|
||||
|
||||
Event e = new Event(intId, title, description, date, location, category);
|
||||
|
||||
if (events == null)
|
||||
events = e;
|
||||
else {
|
||||
Event tmp = events;
|
||||
while (tmp.next != null)
|
||||
tmp = tmp.next;
|
||||
tmp.next = e;
|
||||
}
|
||||
}
|
||||
|
||||
Event get(int id) {
|
||||
Event e = events;
|
||||
while (e != null && e.id != id)
|
||||
e = e.next;
|
||||
return e;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
package com.studentersamfundet.app;
|
||||
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class DnsActivity extends Activity {
|
||||
public static final String PREFS_NAME = "DnsPrefs";
|
||||
public static final String feedURL = "http://folk.uio.no/larsjeng/test.xml";
|
||||
public static final String localURL = "/data/com.studentersamfundet.app/files/dns_events";
|
||||
public static FeedFetcher feed = new FeedFetcher();
|
||||
public static XmlParser parser = new XmlParser();
|
||||
public DataHandler dh;
|
||||
Context context = null;
|
||||
|
||||
/** Called when the activity is first created. */
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.main);
|
||||
|
||||
|
||||
View tmp = this.findViewById(R.id.join_us_textview);
|
||||
tmp.setVisibility(View.INVISIBLE);
|
||||
|
||||
context = getApplicationContext();
|
||||
SharedPreferences prefs = getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
|
||||
boolean firstStart = prefs.getBoolean("firstStart", false);
|
||||
|
||||
// Is it the first time the app is started?
|
||||
if (!firstStart) {
|
||||
// Do we have intarwebs?
|
||||
// YAY = Fetch the feed.
|
||||
// NAY = Inform about no connection.
|
||||
if (checkConnection()) {
|
||||
NodeList itemNodes = feed.fetch(feedURL, this, true);
|
||||
dh = parser.parse(itemNodes);
|
||||
} else {
|
||||
Toast toast = Toast.makeText(context, R.string.error_noconnection_firstart, Toast.LENGTH_LONG);
|
||||
toast.show();
|
||||
}
|
||||
} else {
|
||||
if (checkConnection()) {
|
||||
NodeList itemNodes = feed.fetch(feedURL, this, true);
|
||||
dh = parser.parse(itemNodes);
|
||||
} else {
|
||||
NodeList itemNodes = feed.fetch(localURL, this, false);
|
||||
dh = parser.parse(itemNodes);
|
||||
|
||||
Toast toast = Toast.makeText(context, R.string.error_noconnection_noupdate, Toast.LENGTH_LONG);
|
||||
toast.show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void clickHandler(View v) {
|
||||
if (v.getId() == R.id.program_button) {
|
||||
startActivity(new Intent(context, ProgramList.class));
|
||||
} else if (v.getId() == R.id.bli_med_button) {
|
||||
View j = this.findViewById(R.id.bli_med_button);
|
||||
ImageView p = (ImageView)this.findViewById(R.id.paragraph);
|
||||
View t = this.findViewById(R.id.join_us_textview);
|
||||
|
||||
j.setClickable(false);
|
||||
p.setVisibility(View.INVISIBLE);
|
||||
t.setVisibility(View.VISIBLE);
|
||||
|
||||
// FIX ON BACK PRESSED!
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed () {
|
||||
View t = this.findViewById(R.id.join_us_textview);
|
||||
if (t.getVisibility() == View.VISIBLE) {
|
||||
View j = this.findViewById(R.id.bli_med_button);
|
||||
ImageView p = (ImageView)this.findViewById(R.id.paragraph);
|
||||
j.setClickable(true);
|
||||
t.setVisibility(View.INVISIBLE);
|
||||
p.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
finish();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* Check for Internet connection. */
|
||||
boolean checkConnection() {
|
||||
ConnectivityManager conMan
|
||||
= (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
NetworkInfo netInfo = conMan.getActiveNetworkInfo();
|
||||
return netInfo != null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.studentersamfundet.app;
|
||||
|
||||
public class Event {
|
||||
int id;
|
||||
String title;
|
||||
String description;
|
||||
String date;
|
||||
String location;
|
||||
String category;
|
||||
Event next;
|
||||
|
||||
Event(int id, String title, String description, String date, String location, String category) {
|
||||
this.id = id;
|
||||
this.title = title;
|
||||
this.description = description;
|
||||
this.date = date;
|
||||
this.location = location;
|
||||
this.category = category;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
package com.studentersamfundet.app;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
public class FeedFetcher {
|
||||
String curLastBuild = "";
|
||||
|
||||
private InputStream OpenHttpConnection(String URL) throws IOException {
|
||||
InputStream in = null;
|
||||
int response = -1;
|
||||
URL url = new URL(URL);
|
||||
URLConnection con = url.openConnection();
|
||||
|
||||
if (!(con instanceof HttpURLConnection))
|
||||
throw new IOException("Not an HTTP connection!");
|
||||
|
||||
try {
|
||||
HttpURLConnection httpCon = (HttpURLConnection) con;
|
||||
httpCon.setAllowUserInteraction(false);
|
||||
httpCon.setInstanceFollowRedirects(true);
|
||||
httpCon.setRequestMethod("GET");
|
||||
httpCon.connect();
|
||||
|
||||
response = httpCon.getResponseCode();
|
||||
|
||||
if (response == HttpURLConnection.HTTP_OK)
|
||||
in = httpCon.getInputStream();
|
||||
} catch (Exception e) {
|
||||
throw new IOException("Error connecting.");
|
||||
}
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
public NodeList fetch(String URL, Context c, boolean con) {
|
||||
InputStream in = null;
|
||||
NodeList itemNodes = null;
|
||||
|
||||
try {
|
||||
if (con) {
|
||||
in = OpenHttpConnection(URL);
|
||||
saveFile(in, c);
|
||||
in = OpenHttpConnection(URL);
|
||||
} else
|
||||
in = new FileInputStream(URL);
|
||||
Document doc = null;
|
||||
DocumentBuilderFactory dbf =
|
||||
DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder db;
|
||||
|
||||
try {
|
||||
db = dbf.newDocumentBuilder();
|
||||
doc = db.parse(in);
|
||||
} catch (ParserConfigurationException e) {
|
||||
} catch (SAXException e) {}
|
||||
|
||||
doc.getDocumentElement().normalize();
|
||||
|
||||
// Retrieve all the <item> nodes.
|
||||
itemNodes = doc.getElementsByTagName("item");
|
||||
in.close();
|
||||
} catch (IOException e) {}
|
||||
return itemNodes;
|
||||
}
|
||||
|
||||
void saveFile(InputStream in, Context c) {
|
||||
InputStreamReader isr = new InputStreamReader(in);
|
||||
int charRead;
|
||||
int BUFFER_SIZE = 2000;
|
||||
String FILENAME = "dns_events";
|
||||
String str = "";
|
||||
char[] inputBuffer = new char[BUFFER_SIZE];
|
||||
|
||||
try {
|
||||
while ((charRead = isr.read(inputBuffer))>0) {
|
||||
String readString = String.copyValueOf(inputBuffer, 0, charRead);
|
||||
str += readString;
|
||||
inputBuffer = new char[BUFFER_SIZE];
|
||||
}
|
||||
in.close();
|
||||
} catch (IOException e) {}
|
||||
|
||||
try {
|
||||
FileOutputStream fos = c.openFileOutput(FILENAME, Context.MODE_PRIVATE);
|
||||
fos.write(str.getBytes());
|
||||
fos.close();
|
||||
} catch (FileNotFoundException e) {
|
||||
} catch (IOException e){}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.studentersamfundet.app;
|
||||
|
||||
import android.app.ListActivity;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ListAdapter;
|
||||
import android.widget.ListView;
|
||||
|
||||
public class ProgramList extends ListActivity {
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
// setContentView(R.layout.event_list);
|
||||
|
||||
// View v = this.findViewById(R.id.program_button);
|
||||
// v.setClickable(false);
|
||||
|
||||
View header = getLayoutInflater().inflate(R.layout.header, null);
|
||||
View footer = getLayoutInflater().inflate(R.layout.footer, null);
|
||||
|
||||
ListView listView = getListView();
|
||||
listView.addHeaderView(header);
|
||||
listView.addFooterView(footer);
|
||||
|
||||
ListAdapter adapter = createAdapter();
|
||||
setListAdapter(adapter);
|
||||
}
|
||||
|
||||
protected ListAdapter createAdapter() {
|
||||
String[] vals = populateList();
|
||||
ListAdapter adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, vals);
|
||||
|
||||
return adapter;
|
||||
}
|
||||
|
||||
public String[] populateList() {
|
||||
String[] val = new String[10];
|
||||
val[0] = "test!";
|
||||
val[1] = "test2";
|
||||
val[2] = "test3";
|
||||
val[3] = "test3";
|
||||
val[4] = "test3";
|
||||
val[5] = "test3";
|
||||
val[6] = "test3";
|
||||
val[7] = "test3";
|
||||
val[8] = "test3";
|
||||
val[9] = "test3";
|
||||
return val;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.studentersamfundet.app;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
public class XmlParser {
|
||||
public static DataHandler dh;
|
||||
|
||||
public XmlParser() {
|
||||
dh = new DataHandler();
|
||||
}
|
||||
|
||||
DataHandler parse(NodeList itemNodes) {
|
||||
String id = "";
|
||||
String title = "";
|
||||
String description = "";
|
||||
String date = "";
|
||||
String location = "";
|
||||
String category = "";
|
||||
// String pictureUrl = ""; Necessary?
|
||||
|
||||
for (int i = 0; i < itemNodes.getLength(); i++) {
|
||||
Node itemNode = itemNodes.item(i);
|
||||
|
||||
if (itemNode.getNodeType() == Node.ELEMENT_NODE) {
|
||||
// Convert the Node into an Element.
|
||||
Element itemElement = (Element) itemNode;
|
||||
|
||||
// Get all elements under the <item> element.
|
||||
NodeList idNodes = (itemElement).getElementsByTagName("id");
|
||||
NodeList titleNodes = (itemElement).getElementsByTagName("title");
|
||||
NodeList descriptionNodes = (itemElement).getElementsByTagName("description");
|
||||
NodeList dateNodes = (itemElement).getElementsByTagName("date");
|
||||
NodeList locationNodes = (itemElement).getElementsByTagName("location");
|
||||
NodeList categoryNodes = (itemElement).getElementsByTagName("category");
|
||||
|
||||
// Convert a Node into an Element.
|
||||
Element idElement = (Element) idNodes.item(0);
|
||||
Element titleElement = (Element) titleNodes.item(0);
|
||||
Element descriptionElement = (Element) descriptionNodes.item(0);
|
||||
Element dateElement = (Element) dateNodes.item(0);
|
||||
Element locationElement = (Element) locationNodes.item(0);
|
||||
Element categoryElement = (Element) categoryNodes.item(0);
|
||||
|
||||
// Get all the child nodes.
|
||||
NodeList idTextNodes = ((Node) idElement).getChildNodes();
|
||||
NodeList titleTextNodes = ((Node) titleElement).getChildNodes();
|
||||
NodeList descriptionTextNodes = ((Node) descriptionElement).getChildNodes();
|
||||
NodeList dateTextNodes = ((Node) dateElement).getChildNodes();
|
||||
NodeList locationTextNodes = ((Node) locationElement).getChildNodes();
|
||||
NodeList categoryTextNodes = ((Node) categoryElement).getChildNodes();
|
||||
|
||||
// Retrieve the text.
|
||||
id = ((Node) idTextNodes.item(0)).getNodeValue();
|
||||
title = ((Node) titleTextNodes.item(0)).getNodeValue();
|
||||
description = ((Node) descriptionTextNodes.item(0)).getNodeValue();
|
||||
date = ((Node) dateTextNodes.item(0)).getNodeValue();
|
||||
location = ((Node) locationTextNodes.item(0)).getNodeValue();
|
||||
category = ((Node) categoryTextNodes.item(0)).getNodeValue();
|
||||
dh.insert(id, title, description, date, location, category);
|
||||
}
|
||||
}
|
||||
return dh;
|
||||
}
|
||||
}
|
||||