Permalink
Browse files

Changed to using OAuth to authenticate with Twitter.

Changed tapping on tweets to go to mobile.twitter.com instead of m.twitter.com.
  • Loading branch information...
jjc1138
jjc1138 committed Aug 15, 2010
1 parent ad1156e commit 0d0ce60350ca17c83522114f86a68bd58b83854b
View
@@ -3,5 +3,8 @@
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="lib" path="libs/commons-lang-2.4.jar"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="lib" path="libs/signpost-commonshttp4-1.2.1.1.jar"/>
<classpathentry kind="lib" path="libs/signpost-core-1.2.1.1.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
@@ -0,0 +1,12 @@
#Fri Aug 13 22:58:50 BST 2010
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6
View
@@ -19,6 +19,10 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".TwitterAuth"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar">
</activity>
<service android:name=".Fetcher"
android:permission="net.jjc1138.android.twitter.privateservices" />
<receiver android:name=".AlarmReceiver" />
View
@@ -0,0 +1,13 @@
# 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.
# Indicates whether an apk should be generated for each density.
split.density=false
# Project target.
target=android-8
View
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/browser"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:visibility="invisible"
/>
View
@@ -43,26 +43,14 @@
style="?android:listSeparatorTextViewStyle"
android:layout_marginTop="15sp"
/>
<TextView
<TextView android:id="@+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/username"
/>
<EditText android:id="@+id/username"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true"
/>
<TextView
<Button android:id="@+id/sign_in"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/password"
/>
<EditText android:id="@+id/password"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:password="true"
android:singleLine="true"
android:text="@string/sign_in"
/>
<TextView
android:layout_width="fill_parent"
View
@@ -20,11 +20,17 @@
<string name="vibrate">vibration</string>
<string name="lights">light flashing</string>
<string name="account">Twitter Account</string>
<string name="username">Your username or e-mail address</string>
<string name="password">Password</string>
<string name="sign_in">Sign in</string>
<string name="signed_in_as">Signed in as %1$s</string>
<string name="change_account">Use a different account</string>
<string name="save_settings">Apply/save settings</string>
<string name="reset_settings">Reset to saved settings</string>
<string name="follow_link">Follow @nanoTweeter for updates about new versions.</string>
<string name="unauthorized"><!-- This has to be short to fit in the notification. -->Username or password is wrong.</string>
<string name="unauthorized"><!-- This has to be short to fit in the notification. -->Unauthorized. Please sign in again.</string>
<string name="notification_is_message">(Direct message)</string>
<string name="fetching_request_token">Contacting Twitter...</string>
<string name="fetching_access_token">Checking Twitter access...</string>
<string name="upgraders_need_to_sign_in_again">Hello!\n\nTwitter have changed the way they do signing in for apps, so you need to sign in again to keep using nanoTweeter.\n\nSorry for the inconvenience!</string>
<string name="ok">OK</string>
<string name="sign_in_again_later">I\'ll do it later</string>
</resources>
@@ -0,0 +1,175 @@
package net.jjc1138.android.twitter;
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Handler;
import android.os.SystemClock;
/**
* <code>ActivityTask</code> is a utility for managing a background thread that
* interacts with an <code>Activity</code>. It allows the thread to survive the
* activity being destroyed and recreated on configuration changes.
*
* To use <code>ActivityTask</code>:
*
* 1) Create a class extending <code>ActivityTask&lt;A&gt;</code>, where A is
* the Activity that the task will work with. Override <code>run()</code> and
* in that method do whatever should be done in the background. You can also
* optionally override <code>makeProgressDialog()</code> to return a
* <code>ProgressDialog</code> that should be displayed while the task is
* running. It is crucial that <code>run()</code> must not attempt to access
* the <code>ProgressDialog</code>, the activity UI, or any other part of the
* system that is accessed through <code>Activity</code>, because the
* activity may be destroyed at any time while the task is executing.
*
* At the end of your <code>run()</code> method you will want to update the
* UI. To do that you must call the <code>ActivityTask</code> instance's
* <code>finish()</code> method, passing it an
* <code>ActivityTask.Finisher</code> instance. The finisher's
* <code>finish()</code> method will be called with an instance of your
* activity as a parameter. That activity instance may be the original
* activity that started the task, or it may be a new one if there were
* configuration changes since the task was started.
*
* <strong>Caution:</strong>
* It is crucially important that you only access the activity through the
* parameter, and not via any implicit access that you might have to the
* original activity if you define your <code>ActivityTask</code> as an inner
* class inside your activity class. It can be helpful to temporarily change
* your overridden methods to be static, and check the compiler errors to see
* if you have inadvertently used any implicit access.
*
* 2) Add an instance variable to your <code>Activity</code> to store an
* instance of <code>ActivityTask&lt;A&gt;</code> (again, where A is your
* activity class).
*
* 3) In your activity's <code>onCreate()</code>, retrieve any running task by
* using <code>getLastNonConfigurationInstance()</code> and storing the
* result into the instance variable created in step 2. If it is not null
* then call <code>newActivity(this)</code> on it.
*
* 4) In your activity's <code>onDestroy()</code>, call
* <code>activityDestroyed()</code> on your <code>ActivityTask</code>
* instance if it is not null.
*
* 5) Override <code>onRetainNonConfigurationInstance()></code> and return the
* instance variable defined in step 2.
*
* 6) When you want to start your task create a new instance of the class you
* created in step 1 and assign it to the instance variable defined in step
* 2. Creating the instance will immediately start the background task and
* display the progress dialog if you defined one.
*/
public abstract class ActivityTask<A extends Activity> {
protected ProgressDialog makeProgressDialog(A activity) { return null; }
protected abstract void run();
public interface Finisher<A extends Activity> {
public void finish(A activity);
}
protected final void finish(final Finisher<A> finisher) {
new Thread() {
@Override
public void run() {
long start = SystemClock.uptimeMillis();
while (true) {
// The Activity may be destroyed when we get here. If so,
// keep retrying until we have a new one:
try {
final Handler h = handler;
h.post(new Runnable() {
@Override
public void run() {
if (activity == null || done) {
return;
}
if (h != handler) {
// The activity was destroyed and recreated
// in between the time when this Runnable
// was posted and the time when it started
// running, so we are running on the UI
// thread of the now-destroyed activity.
// (As far as I know the UI thread doesn't
// change when an activity is recreated, so
// this condition should be impossible to
// reach, but better safe than sorry.)
return;
}
// We are now on the UI thread with an Activity
// that hasn't been destroyed, so we can
// guarantee that it won't be destroyed while
// this method is running (since destruction has
// to happen on the UI thread).
done = true;
if (progress != null) {
progress.dismiss();
}
finisher.finish(activity);
activity = null;
progress = null;
handler = null;
}
});
} catch (NullPointerException e) {
// handler can be null if the Activity was just
// destroyed.
}
if (done || SystemClock.uptimeMillis() - start > timeout) {
// It is not guaranteed that
// Activity.getLastNonConfigurationInstance() will
// return what was returned from
// Activity.onRetainNonConfigurationInstance(), so our
// newActivity() may never be called. In that case we
// simply give up after a reasonable timeout period.
break;
}
Thread.yield();
}
}
}.start();
}
public ActivityTask(A activity) {
newActivity(activity);
new Thread() {
@Override
public void run() {
ActivityTask.this.run();
}
}.start();
}
public final void newActivity(A activity) {
if (done) {
return;
}
this.activity = activity;
handler = new Handler();
progress = makeProgressDialog(activity);
if (progress != null) {
progress.show();
}
}
public final void activityDestroyed() {
if (progress != null) {
progress.dismiss();
progress = null;
}
activity = null;
handler = null;
}
public final boolean isDone() {
return done;
}
private static final long timeout = 10000;
private volatile boolean done = false;
private A activity;
private ProgressDialog progress;
private Handler handler;
}
Oops, something went wrong.

0 comments on commit 0d0ce60

Please sign in to comment.