Permalink
Browse files

First Android App

Yamba - From the book "Learning Android"
  • Loading branch information...
0 parents commit ef6dd14cc0a55298a81c202666365dedb52d912e @igama committed Nov 29, 2011
@@ -0,0 +1,10 @@
+<?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="lib" path="jars/jtwitter.jar"/>
+ <classpathentry kind="lib" path="jars/signpost-core-1.2.1.1.jar"/>
+ <classpathentry kind="output" path="bin/classes"/>
+</classpath>
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>Yamba</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>
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="org.igamahq.yamba"
+ android:versionCode="1"
+ android:versionName="1.0" >
+
+ <uses-sdk android:minSdkVersion="10" />
+
+ <application
+ android:icon="@drawable/ic_launcher"
+ android:label="@string/app_name" >
+ <activity
+ android:label="@string/app_name"
+ android:name=".StatusActivity" >
+ <intent-filter >
+ <action android:name="android.intent.action.MAIN" />
+
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ </application>
+
+ <uses-permission android:name="android.permission.INTERNET" />
+</manifest>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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.
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.
Binary file not shown.
@@ -0,0 +1,31 @@
+/* AUTO-GENERATED FILE. DO NOT MODIFY.
+ *
+ * This class was automatically generated by the
+ * aapt tool from the resource data it found. It
+ * should not be modified by hand.
+ */
+
+package org.igamahq.yamba;
+
+public final class R {
+ public static final class attr {
+ }
+ public static final class drawable {
+ public static final int background=0x7f020000;
+ public static final int ic_launcher=0x7f020001;
+ }
+ public static final class id {
+ public static final int buttonUpdate=0x7f050002;
+ public static final int editText=0x7f050001;
+ public static final int textCount=0x7f050000;
+ }
+ public static final class layout {
+ public static final int status=0x7f030000;
+ }
+ public static final class string {
+ public static final int app_name=0x7f040000;
+ public static final int buttonUpdate=0x7f040003;
+ public static final int hintText=0x7f040002;
+ public static final int titleStatus=0x7f040001;
+ }
+}
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,40 @@
+-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 *;
+}
@@ -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,
+# "ant.properties", and override values to adapt the script to your
+# project structure.
+
+# Project target.
+target=android-10
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.
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.
@@ -0,0 +1,47 @@
+<?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="fill_parent"
+ android:background="@drawable/background"
+ android:orientation="vertical" >
+
+ <TextView
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:gravity="center"
+ android:textSize="30sp"
+ android:layout_margin="10dp"
+ android:text="@string/titleStatus"
+ android:textColor="@android:color/white" />
+
+ <!-- Text Counter TextView -->
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="right"
+ android:id="@+id/textCount"
+ android:text="000"
+ android:layout_marginRight="10dp" />
+
+ <EditText
+ android:id="@+id/editText"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:hint="@string/hintText"
+ android:gravity="top|center_horizontal"
+ android:inputType="textMultiLine"
+ android:background="#cfff"
+ android:textColor="@android:color/black" >
+ </EditText>
+
+ <!-- Update Button -->
+ <Button
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/buttonUpdate"
+ android:textSize="20sp"
+ android:id="@+id/buttonUpdate" >
+ </Button>
+
+</LinearLayout>
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+ <string name="app_name">Yamba</string>
+
+ <string name="titleStatus">Actividade Status!</string>
+ <string name="hintText">Mensagem de 140 caracteres</string>
+
+ <string name="buttonUpdate">Actualizar</string>
+
+</resources>
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+ <string name="app_name">Yamba</string>
+
+ <string name="titleStatus">Status Activity!</string>
+ <string name="hintText">Please enter your 140-character status</string>
+
+ <string name="buttonUpdate">Update</string>
+
+</resources>
@@ -0,0 +1,122 @@
+package org.igamahq.yamba;
+
+
+import winterwell.jtwitter.Twitter;
+import winterwell.jtwitter.TwitterException;
+
+import android.app.Activity;
+import android.graphics.Color;
+import android.os.AsyncTask;
+import android.os.Bundle;
+import android.text.Editable;
+import android.text.TextWatcher;
+import android.util.Log;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.TextView;
+import android.widget.Toast;
+
+/* public class StatusActivity extends Activity {
+ // Called when the activity is first created.
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.status);
+ }
+}*/
+
+ public class StatusActivity extends Activity implements OnClickListener, TextWatcher {
+ private static final String TAG = "StatusActivity";
+ EditText editText;
+ Button updateButton;
+ Twitter twitter;
+ TextView textCount;
+
+ /** Called when the activity is first created. */
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.status);
+
+ // Find views
+ editText = (EditText) findViewById(R.id.editText); //
+ updateButton = (Button) findViewById(R.id.buttonUpdate);
+ updateButton.setOnClickListener(this);
+
+ textCount = (TextView) findViewById(R.id.textCount); //
+ textCount.setText(Integer.toString(140)); //
+ textCount.setTextColor(Color.GREEN);
+
+ editText.addTextChangedListener(this); //attach TextWatcher to our editText field
+
+ // Connect to Twitter
+ twitter = new Twitter("student", "password");
+ twitter.setAPIRootUrl("http://yamba.marakana.com/api");
+ }
+
+
+ // Called when button is clicked
+ public void onClick(View v){
+ String status = editText.getText().toString();
+ new PostToTwitter().execute(status); //
+ Log.d(TAG, "onClicked");
+ }
+
+
+ // Asynchronously posts to twitter
+ class PostToTwitter extends AsyncTask<String, Integer, String> { //
+ // Called to initiate the background activity
+
+ @Override
+ protected String doInBackground(String... statuses){
+ try {
+ winterwell.jtwitter.Status status = twitter.updateStatus(statuses[0]);
+ return status.text;
+ } catch (TwitterException e) {
+ Log.e(TAG, e.toString());
+ e.printStackTrace();
+ return "Failed to post";
+ }
+ }
+
+ // Called when there's a status to be updated
+ @Override
+ protected void onProgressUpdate(Integer... values) { //
+ super.onProgressUpdate(values);
+ // Not used in this case
+ }
+
+ // Called once the background activity has completed
+ @Override
+ protected void onPostExecute(String result) { //
+ Toast.makeText(StatusActivity.this, result, Toast.LENGTH_LONG).show();
+ }
+
+
+ }//end posttotwitter
+
+ // TextWatcher Methods
+ public void afterTextChanged(Editable statusText){
+ int count = 140 - statusText.length();
+ textCount.setText(Integer.toString(count));
+ textCount.setTextColor(Color.GREEN);
+ if (count < 10)
+ textCount.setTextColor(Color.YELLOW);
+ if (count < 0)
+ textCount.setTextColor(Color.RED);
+ }
+
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) { //
+
+ }
+
+ public void onTextChanged(CharSequence s, int start, int before, int count) { //
+
+ }
+
+ }
+
+
+

0 comments on commit ef6dd14

Please sign in to comment.