Skip to content
Browse files

Initial Commit

  • Loading branch information...
0 parents commit 46da51808df79a7e9d12337695aa6fb1829674b6 @donnfelker committed Apr 9, 2011
7 .classpath
@@ -0,0 +1,7 @@
+<?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="output" path="bin"/>
+</classpath>
22 .gitignore
@@ -0,0 +1,22 @@
+tmp/
+target/
+out/
+obj
+bin
+gen
+_ReSharper.*
+*.csproj.user
+*.resharper.user
+*.resharper
+*.suo
+*.cache
+*~
+*.swp
+/Build
+/build
+NDependOut
+*.Publish.xml
+build
+raw/audio/**/*
+.idea/
+
33 .project
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>ColorsSample</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>
18 AndroidManifest.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.agilevent.colorssample"
+ android:versionCode="1"
+ android:versionName="1.0">
+ <uses-sdk android:minSdkVersion="11" />
+
+ <application android:icon="@drawable/icon" android:label="@string/app_name">
+ <activity android:name=".ColorsActivity"
+ android:label="@string/app_name">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+
+ </application>
+</manifest>
11 default.properties
@@ -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-11
36 proguard.cfg
@@ -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 *;
+}
BIN res/drawable-hdpi/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN res/drawable-ldpi/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN res/drawable-mdpi/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN res/drawable/ic_menu_add.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN res/drawable/ic_menu_info_details.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN res/drawable/ic_menu_refresh.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 res/layout/add.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="horizontal"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ >
+ <TextView
+ android:text="Color:"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textAppearance="@android:style/TextAppearance.Medium"
+ />
+ <EditText
+ android:id="@+id/color"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="4dip"
+ android:width="160sp"
+ android:inputType="text"
+ android:imeActionId="1337"
+ android:imeOptions="actionDone"
+ android:hint="Red:#FF0000"
+ />
+</LinearLayout>
7 res/layout/color_detail.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:id="@+id/color_detail_layout">
+</LinearLayout>
21 res/layout/main.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="horizontal"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ >
+
+ <fragment class="com.agilevent.colorssample.ColorsFragment"
+ android:id="@+id/colors"
+ android:layout_weight="30"
+ android:layout_width="0px"
+ android:layout_height="fill_parent"
+ />
+ <fragment class="com.agilevent.colorssample.ColorDetailFragment"
+ android:id="@+id/details"
+ android:layout_weight="70"
+ android:layout_width="0px"
+ android:layout_height="fill_parent"
+ />
+
+</LinearLayout>
15 res/menu/color_menu.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="utf-8"?>
+<menu xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:id="@+id/add"
+ android:title="Add"
+ android:icon="@drawable/ic_menu_add"
+ android:actionLayout="@layout/add"
+ android:showAsAction="ifRoom"/>
+ <item android:id="@+id/reset"
+ android:title="Reset"
+ android:icon="@drawable/ic_menu_refresh"
+ android:showAsAction="ifRoom|withText"/>
+ <item android:id="@+id/about"
+ android:title="About"
+ android:icon="@drawable/ic_menu_info_details" />
+</menu>
5 res/values/strings.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <string name="hello">Hello World, ColorsActivity!</string>
+ <string name="app_name">ColorsSample</string>
+</resources>
5 src/com/agilevent/colorssample/ColorChangedListener.java
@@ -0,0 +1,5 @@
+package com.agilevent.colorssample;
+
+public interface ColorChangedListener {
+ void onColorChanged(SimpleColor color);
+}
23 src/com/agilevent/colorssample/ColorDetailFragment.java
@@ -0,0 +1,23 @@
+package com.agilevent.colorssample;
+
+import android.app.Fragment;
+import android.view.View;
+import android.widget.Toast;
+
+public class ColorDetailFragment extends Fragment implements ColorChangedListener {
+
+ protected View layout;
+
+ @Override
+ public View onCreateView(android.view.LayoutInflater inflater, android.view.ViewGroup container, android.os.Bundle savedInstanceState) {
+ layout = inflater.inflate(R.layout.color_detail, container);
+ return layout;
+ };
+
+ @Override
+ public void onColorChanged(SimpleColor color) {
+ layout.setBackgroundColor(color.getColor());
+ Toast.makeText(getActivity(), "Backgournd color changed to: " + color.getName(), Toast.LENGTH_SHORT);
+ }
+
+}
21 src/com/agilevent/colorssample/ColorFactory.java
@@ -0,0 +1,21 @@
+package com.agilevent.colorssample;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import android.graphics.Color;
+
+public class ColorFactory {
+ public static List<SimpleColor> getColors( ){
+ List<SimpleColor> colors = new ArrayList<SimpleColor>();
+
+ colors.add(new SimpleColor("Red", Color.parseColor("#ff0000")));
+ colors.add(new SimpleColor("Green", Color.parseColor("#00e130")));
+ colors.add(new SimpleColor("Blue", Color.parseColor("#007eff")));
+
+
+ return colors;
+ }
+
+
+}
109 src/com/agilevent/colorssample/ColorsActivity.java
@@ -0,0 +1,109 @@
+package com.agilevent.colorssample;
+
+
+
+import android.app.Activity;
+import android.graphics.Color;
+import android.os.Bundle;
+import android.view.KeyEvent;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.view.MenuItem;
+import android.view.inputmethod.InputMethodManager;
+import android.widget.ArrayAdapter;
+import android.widget.EditText;
+import android.widget.TextView;
+import android.widget.Toast;
+
+public class ColorsActivity extends Activity {
+
+ protected ColorsFragment cf;
+ protected ColorDetailFragment cdf;
+
+ /** Called when the activity is first created. */
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ setContentView(R.layout.main);
+
+ // 1. Get ColorsFragment
+ // 2. Get ColorDetailFragment
+ // 3. Set the listener of the ColorFragment to that of the ColorFragment
+ cf = (ColorsFragment)getFragmentManager().findFragmentById(R.id.colors);
+ cdf = (ColorDetailFragment)getFragmentManager().findFragmentById(R.id.details);
+ cf.setColorChangedListener(cdf);
+
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ new MenuInflater(this).inflate(R.menu.color_menu, menu);
+
+ EditText add=(EditText)menu
+ .findItem(R.id.add)
+ .getActionView()
+ .findViewById(R.id.color);
+
+ add.setOnEditorActionListener(onAdd);
+
+ return(super.onCreateOptionsMenu(menu));
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+
+
+ case R.id.reset:
+ cf.reset();
+ return(true);
+
+ case R.id.about:
+ case android.R.id.home:
+ Toast.makeText(this,"Color Sample App. Uses Fragments and the Action Bar",Toast.LENGTH_LONG).show();
+ return(true);
+ }
+
+ return(super.onOptionsItemSelected(item));
+ }
+
+
+ @SuppressWarnings("unchecked")
+ private void addColor(String colorWithCode) {
+ ArrayAdapter<SimpleColor> adapter = (ArrayAdapter<SimpleColor>) cf.getListAdapter();
+
+ String colorName = colorWithCode.substring(0, colorWithCode.indexOf(':'));
+ String colorHex = colorWithCode.substring(colorWithCode.indexOf(':') + 1, colorWithCode.length());
+
+
+ adapter.add(new SimpleColor(colorName, Color.parseColor(colorHex)));
+ }
+
+
+ private TextView.OnEditorActionListener onAdd=
+ new TextView.OnEditorActionListener() {
+ public boolean onEditorAction(TextView v, int actionId,
+ KeyEvent event) {
+ if (event==null || event.getAction()==KeyEvent.ACTION_UP) {
+
+ addColor(v.getText().toString());
+
+ // Clear it out now
+ v.setText("");
+
+ InputMethodManager imm=(InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
+
+ imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
+ }
+
+ return(true);
+ }
+ };
+
+
+
+
+
+
+}
74 src/com/agilevent/colorssample/ColorsFragment.java
@@ -0,0 +1,74 @@
+package com.agilevent.colorssample;
+
+import java.util.List;
+
+import android.app.ListFragment;
+import android.graphics.Color;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ArrayAdapter;
+import android.widget.ListView;
+import android.widget.TextView;
+
+public class ColorsFragment extends ListFragment {
+
+ protected List<SimpleColor> colors;
+ protected ColorChangedListener listener;
+
+ @Override
+ public void onActivityCreated(Bundle savedInstanceState) {
+
+ super.onActivityCreated(savedInstanceState);
+
+ colors = ColorFactory.getColors();
+
+ setListAdapter(new ColorsAdapter());
+ }
+
+ @Override
+ public void onListItemClick(ListView l, View v, int position, long id) {
+
+ // Notify listener that a color has been changed.
+ if(listener != null)
+ listener.onColorChanged(colors.get(position));
+
+ }
+
+ public void setColorChangedListener(ColorChangedListener listener) {
+ this.listener = listener;
+ }
+
+ class ColorsAdapter extends ArrayAdapter<SimpleColor> {
+
+ public ColorsAdapter() {
+ super(getActivity(), android.R.layout.simple_list_item_activated_1, colors);
+ }
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+
+ if(convertView == null) {
+ convertView= LayoutInflater.from(getActivity()).inflate(android.R.layout.simple_list_item_activated_1, null);
+ }
+
+ SimpleColor color = colors.get(position);
+ convertView.setTag(color);
+ TextView colorName = (TextView)convertView.findViewById(android.R.id.text1);
+ colorName.setText(color.getName());
+
+ return convertView;
+ }
+
+ }
+
+ public void reset() {
+ // Uses the colors object, which only has our defaults in it.
+ colors = ColorFactory.getColors();
+ setListAdapter(new ColorsAdapter());
+
+ // Notify listener that it should reset it self to transparent.
+ listener.onColorChanged(new SimpleColor("transparent", Color.parseColor("#00000000")));
+ }
+}
31 src/com/agilevent/colorssample/SimpleColor.java
@@ -0,0 +1,31 @@
+package com.agilevent.colorssample;
+
+public class SimpleColor {
+
+ String name;
+ int color;
+
+ public SimpleColor(String name, int color) {
+ this.name = name;
+ this.color = color;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public int getColor() {
+ return color;
+ }
+
+ public void setColor(int color) {
+ this.color = color;
+ }
+
+
+
+}

0 comments on commit 46da518

Please sign in to comment.
Something went wrong with that request. Please try again.