Commits

Micha Kops committed 89c2816

initial import.

Comments (0)

Files changed (20)

+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="src" path="gen"/>
+	<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
+	<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
+	<classpathentry kind="output" path="bin/classes"/>
+</classpath>
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>android-fragment-example</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>com.android.ide.eclipse.adt.ApkBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>

AndroidManifest.xml

+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="com.hascode.android.app"
+    android:versionCode="1"
+    android:versionName="1.0" >
+
+    <uses-sdk android:minSdkVersion="15" />
+    <uses-permission android:name="android.permission.INTERNET"/>
+
+    <application
+        android:icon="@drawable/ic_launcher"
+        android:label="@string/app_name" android:debuggable="true" android:name="FragmentApplication">
+        <activity
+            android:label="@string/app_name"
+            android:name=".FragmentExampleActivity" >
+            <intent-filter >
+                <action android:name="android.intent.action.MAIN" />
+
+                <category android:name="android.intent.category.LAUNCHER" />
+            </intent-filter>
+        </activity>
+    </application>
+
+</manifest>
+-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>;
+}
+
+-keepclasseswithmembers class * {
+    public <init>(android.content.Context, android.util.AttributeSet);
+}
+
+-keepclasseswithmembers class * {
+    public <init>(android.content.Context, android.util.AttributeSet, int);
+}
+
+-keepclassmembers class * extends android.app.Activity {
+   public void *(android.view.View);
+}
+
+-keepclassmembers enum * {
+    public static **[] values();
+    public static ** valueOf(java.lang.String);
+}
+
+-keep class * implements android.os.Parcelable {
+  public static final android.os.Parcelable$Creator *;
+}

project.properties

+# 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,
+# "ant.properties", and override values to adapt the script to your
+# project structure.
+
+# Project target.
+target=android-15
Add a comment to this file

res/drawable-hdpi/ic_launcher.png

Added
New image
Add a comment to this file

res/drawable-ldpi/ic_launcher.png

Added
New image
Add a comment to this file

res/drawable-mdpi/ic_launcher.png

Added
New image

res/layout-1280x800/main.xml

+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/frags"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:orientation="horizontal" >
+
+    <!-- "Selection Fragment" -->
+    <fragment
+        android:id="@+id/selection_fragment"
+        android:layout_width="@dimen/selection_fragment"
+        android:layout_height="match_parent"
+        class="com.hascode.android.app.SelectionFragment" />
+    
+    <!-- "Display/News Fragment" -->
+    <fragment
+        android:id="@+id/news_fragment"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        class="com.hascode.android.app.NewsFragment" />
+
+</LinearLayout>

res/layout/list_item.xml

+<?xml version="1.0" encoding="utf-8"?>
+<TextView xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="fill_parent"
+    android:layout_height="fill_parent"
+    android:padding="10dp"
+    android:textSize="16sp" >
+</TextView>

res/layout/main.xml

+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/frags"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:orientation="horizontal" >
+
+    <!-- "Selection Fragment" -->
+    <fragment
+        android:id="@+id/selection_fragment"
+        android:layout_width="@dimen/selection_fragment"
+        android:layout_height="match_parent"
+        class="com.hascode.android.app.SelectionFragment" />
+    
+    <!-- "Display/News Fragment" -->
+    <fragment
+        android:id="@+id/news_fragment"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        class="com.hascode.android.app.NewsFragment" />
+
+</LinearLayout>

res/layout/news_fragment.xml

+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/linearLayout1"
+    android:layout_width="fill_parent"
+    android:layout_height="fill_parent" >
+
+    <WebView
+        android:id="@+id/webView"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent" />
+
+</LinearLayout>

res/layout/select_fragment.xml

+<?xml version="1.0" encoding="utf-8"?>
+<ListView xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent" >
+
+    
+
+</ListView>

res/values/dimen.xml

+
+    <resources>
+        <dimen name="selection_fragment">200sp</dimen>
+    </resources>

res/values/strings.xml

+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+    <string name="app_name">hasCode.com Android Fragment Tutorial App</string>
+
+</resources>

src/com/hascode/android/app/Article.java

+package com.hascode.android.app;
+
+public class Article {
+	private final String title;
+	private final String url;
+
+	public Article(final String title, final String url) {
+		super();
+		this.title = title;
+		this.url = url;
+	}
+
+	public String getTitle() {
+		return title;
+	}
+
+	public String getUrl() {
+		return url;
+	}
+
+	@Override
+	public String toString() {
+		return title;
+	}
+
+}

src/com/hascode/android/app/FragmentApplication.java

+package com.hascode.android.app;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import android.app.Application;
+
+public class FragmentApplication extends Application {
+	private final List<Article> links = new ArrayList<Article>();
+	{
+		links.add(new Article(
+				"Selenium WebDriver, Selenium Server and PageObjects by Example",
+				"http://www.hascode.com/2012/03/selenium-webdriver-selenium-server-and-pageobjects-by-example/"));
+		links.add(new Article("Ordering your JUnit Rules using a RuleChain",
+				"http://www.hascode.com/2012/02/ordering-your-junit-rules-using-a-rulechain/"));
+		links.add(new Article(
+				"JPA Persistence and Lucene Indexing combined in Hibernate Search",
+				"http://www.hascode.com/2012/02/jpa-persistence-and-lucene-indexing-combined-in-hibernate-search/"));
+		links.add(new Article(
+				"Neo4j Graph Database Tutorial: How to build a Route Planner and other Examples",
+				"http://www.hascode.com/2012/01/neo4j-graph-database-tutorial-how-to-build-a-route-planner-and-other-examples/"));
+		links.add(new Article(
+				"Create Mobile Websites using Java Server Faces and PrimeFaces Mobile",
+				"http://www.hascode.com/2012/01/create-mobile-websites-using-java-server-faces-and-primefaces-mobile/"));
+		links.add(new Article("Writing Styles and Themes on Android",
+				"http://www.hascode.com/2011/12/writing-styles-and-themes-on-android/"));
+		links.add(new Article(
+				"Managing Background Tasks on Android using the Alarm Manager",
+				"http://www.hascode.com/2011/11/managing-background-tasks-on-android-using-the-alarm-manager/"));
+		links.add(new Article(
+				"Finding Memory Leaks using Eclipse and the MemoryAnalyzer Plugin",
+				"http://www.hascode.com/2011/11/finding-memory-leaks-using-eclipse-and-the-memoryanalyzer-plugin/"));
+		links.add(new Article(
+				"Testing RESTful Web Services made easy using the REST-assured Framework",
+				"http://www.hascode.com/2011/10/testing-restful-web-services-made-easy-using-the-rest-assured-framework/"));
+		links.add(new Article(
+				"Maven Tomcat Plugin: Adding Authentication to an Embedded Tomcat",
+				"http://www.hascode.com/2011/10/maven-tomcat-plugin-adding-authentication-to-an-embedded-tomcat/"));
+	}
+
+	public List<Article> getLinks() {
+		return links;
+	}
+
+}

src/com/hascode/android/app/FragmentExampleActivity.java

+package com.hascode.android.app;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+import android.widget.ArrayAdapter;
+
+public class FragmentExampleActivity extends Activity implements
+		SelectionFragment.OnSelectListener {
+	private FragmentApplication app;
+
+	@Override
+	public void onCreate(final Bundle savedInstanceState) {
+		super.onCreate(savedInstanceState);
+		setContentView(R.layout.main);
+
+		app = (FragmentApplication) getApplication();
+		SelectionFragment selectionFragment = (SelectionFragment) getFragmentManager()
+				.findFragmentById(R.id.selection_fragment);
+
+		selectionFragment.setListAdapter(new ArrayAdapter<Article>(this,
+				R.layout.list_item, app.getLinks()));
+	}
+
+	@Override
+	public void onItemSelected(final int position) {
+		final Article article = app.getLinks().get(position);
+		NewsFragment newsFragment = (NewsFragment) getFragmentManager()
+				.findFragmentById(R.id.news_fragment);
+		if (newsFragment == null) {
+			Intent intent = new Intent(this, NewsFragment.class);
+			intent.putExtra("url", article.getUrl());
+			startActivity(intent);
+		} else {
+			newsFragment.updateContent(article.getUrl());
+		}
+
+	}
+}

src/com/hascode/android/app/NewsFragment.java

+package com.hascode.android.app;
+
+import android.app.Fragment;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.webkit.WebSettings;
+import android.webkit.WebView;
+
+public class NewsFragment extends Fragment {
+	public void updateContent(final String url) {
+		WebView webView = (WebView) getActivity().findViewById(R.id.webView);
+		// my blog is using javascript
+		WebSettings settings = webView.getSettings();
+		settings.setJavaScriptEnabled(true);
+		webView.loadUrl(url);
+	}
+
+	@Override
+	public View onCreateView(final LayoutInflater inflater,
+			final ViewGroup container, final Bundle savedInstanceState) {
+		return inflater.inflate(R.layout.news_fragment, container, false);
+	}
+}

src/com/hascode/android/app/SelectionFragment.java

+package com.hascode.android.app;
+
+import android.app.Activity;
+import android.app.ListFragment;
+import android.view.View;
+import android.widget.ListView;
+
+public class SelectionFragment extends ListFragment {
+	private OnSelectListener onSelectListener;
+
+	public interface OnSelectListener {
+		public void onItemSelected(final int position);
+	}
+
+	@Override
+	public void onAttach(final Activity activity) {
+		super.onAttach(activity);
+		onSelectListener = (OnSelectListener) activity;
+	}
+
+	@Override
+	public void onListItemClick(final ListView l, final View v,
+			final int position, final long id) {
+		onSelectListener.onItemSelected(position);
+	}
+
+}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.