Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffxchu committed Sep 25, 2011
1 parent 11e3eaf commit 6422a4a
Show file tree
Hide file tree
Showing 8 changed files with 599 additions and 599 deletions.
Expand Up @@ -12,30 +12,30 @@
*/
public class FoursquareOauthApp extends UiApplication {

/*
* Default client id for the testing purpose
* Your can register your application client id at https://foursquare.com/oauth/register
*/
public static final String TEST_CLIENT_ID = "CTHTLACET0NMF4BKB1KHXY11BNWVJZ0UIGQFKXW4LWPJ3LXE";
/*
* Default callback (redirect) url for the testing purpose.
* This should be your application url.
*/
public static final String TEST_CALLBACK_URL = "http://www.google.com";
/**
* Entry point for demo application
* @param args Command line arguments
*/
public static void main(String[] args) {
FoursquareOauthApp application = new FoursquareOauthApp();
application.enterEventDispatcher();
}
public FoursquareOauthApp() {
pushScreen(new OauthDisplayScreen(TEST_CLIENT_ID, TEST_CALLBACK_URL));
}
/*
* Default client id for the testing purpose
* Your can register your application client id at https://foursquare.com/oauth/register
*/
public static final String TEST_CLIENT_ID = "CTHTLACET0NMF4BKB1KHXY11BNWVJZ0UIGQFKXW4LWPJ3LXE";
/*
* Default callback (redirect) url for the testing purpose.
* This should be your application url.
*/
public static final String TEST_CALLBACK_URL = "http://www.google.com";
/**
* Entry point for demo application
* @param args Command line arguments
*/
public static void main(String[] args) {
FoursquareOauthApp application = new FoursquareOauthApp();
application.enterEventDispatcher();
}
public FoursquareOauthApp() {
pushScreen(new OauthDisplayScreen(TEST_CLIENT_ID, TEST_CALLBACK_URL));
}
}
56 changes: 28 additions & 28 deletions FoursquareOauthExample/src/com/foursquare/bb/oauth/Log4Device.java
Expand Up @@ -12,33 +12,33 @@
*/
public class Log4Device {

private static long GUID = 0L;
private static final String APPNAME = "4sqOauth[3party]";
static {
String classname = Log4Device.class.getName();
String guidstr = classname + ".GUID";
GUID = StringUtilities.stringHashToLong(guidstr);
// register event logger
EventLogger.register(GUID, APPNAME, EventLogger.ALWAYS_LOG);
}
private Log4Device() { /* make class singleton */ }
private static long GUID = 0L;
private static final String APPNAME = "4sqOauth[3party]";
static {
String classname = Log4Device.class.getName();
String guidstr = classname + ".GUID";
GUID = StringUtilities.stringHashToLong(guidstr);
// register event logger
EventLogger.register(GUID, APPNAME, EventLogger.ALWAYS_LOG);
}
private Log4Device() { /* make class singleton */ }

public static void log(String message) {
byte[] data = message.getBytes();
if (DeviceInfo.isSimulator()) {
try {
System.out.println(new String(data, "UTF-8"));
}
catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
else {
EventLogger.logEvent(GUID, data, EventLogger.ALWAYS_LOG);
}
}
public static void log(String message) {
byte[] data = message.getBytes();
if (DeviceInfo.isSimulator()) {
try {
System.out.println(new String(data, "UTF-8"));
}
catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
else {
EventLogger.logEvent(GUID, data, EventLogger.ALWAYS_LOG);
}
}
}
Expand Up @@ -6,7 +6,7 @@
* @author Jeff Hu (jeff4sq@gmail.com)
*/
public interface OauthTokenChangeListener {
public void tokenChanged(String token);
public void tokenChanged(String token);
}
Expand Up @@ -17,31 +17,31 @@
*
*/
public class AnimationLabelField extends VerticalFieldManager {
protected static final int VPADDING = 5;
protected static final int VPADDING = 5;
protected static final int HPADDING = 5;
private LabelField mLabelField;
private Bitmap mImage;
public AnimationLabelField(String labelText) {
super(Manager.FIELD_HCENTER);
mImage = getAnimationImage();
Field progressAnimatedField = createAnimatedImageField(mImage);
Field progressLabelField = new LabelField(labelText, FIELD_VCENTER) {
protected void paint(Graphics graphics) {
Font font = graphics.getFont();
int alpha = graphics.getGlobalAlpha();
graphics.setGlobalAlpha(195);
graphics.setFont(Font.getDefault().derive(Font.PLAIN, Font.getDefault().getHeight() * 2/3));
super.paint(graphics);
graphics.setFont(font);
graphics.setGlobalAlpha(alpha);
}
};
int imageHeight = mImage.getHeight();
int fontHeight = progressLabelField.getFont().getHeight();
private LabelField mLabelField;
private Bitmap mImage;
public AnimationLabelField(String labelText) {
super(Manager.FIELD_HCENTER);
mImage = getAnimationImage();
Field progressAnimatedField = createAnimatedImageField(mImage);
Field progressLabelField = new LabelField(labelText, FIELD_VCENTER) {
protected void paint(Graphics graphics) {
Font font = graphics.getFont();
int alpha = graphics.getGlobalAlpha();
graphics.setGlobalAlpha(195);
graphics.setFont(Font.getDefault().derive(Font.PLAIN, Font.getDefault().getHeight() * 2/3));
super.paint(graphics);
graphics.setFont(font);
graphics.setGlobalAlpha(alpha);
}
};
int imageHeight = mImage.getHeight();
int fontHeight = progressLabelField.getFont().getHeight();
if (imageHeight > fontHeight) {
int diffPadding = (imageHeight - fontHeight) >> 1;
progressAnimatedField.setPadding(VPADDING, HPADDING, 0, HPADDING);
Expand All @@ -51,78 +51,78 @@ protected void paint(Graphics graphics) {
progressLabelField.setPadding(VPADDING, HPADDING, 0, HPADDING);
progressAnimatedField.setPadding(VPADDING + diffPadding, HPADDING, diffPadding, HPADDING);
}
HorizontalFieldManager hfm = new HorizontalFieldManager(Manager.FIELD_VCENTER|Manager.FIELD_HCENTER);
hfm.add(progressAnimatedField);
hfm.add(progressLabelField);
add(hfm);
setPadding(2, 2, 2, 2);
}
protected Bitmap getAnimationImage() {
return Bitmap.getBitmapResource("progress.png");
}
protected void applyTheme(Graphics graphics, boolean arg) {
// do nothing
}
protected Field createAnimatedImageField(Bitmap image) {
return new AnimatedImageField(image, NON_FOCUSABLE|FIELD_VCENTER|FIELD_HCENTER);
}
public void updateText(String text) {
mLabelField.setText(text);
}
private static class AnimatedImageField extends Field implements Runnable {
private Bitmap mImage;
private int mCurrentFrame = 0;
private int mInvokeId = -1;
private int mFrameWidth;
private int mFrameHeight;
private int mFrames;
public AnimatedImageField(Bitmap image, long style) {
super(style | Field.NON_FOCUSABLE);
mImage = image;
mFrameHeight = mFrameWidth = mImage.getHeight();
mFrames = mImage.getWidth() / mFrameHeight;
}
public void run() {
if (isVisible()) {
invalidate();
}
}
protected void onDisplay() {
super.onDisplay();
if (mInvokeId == -1) {
mInvokeId = UiApplication.getUiApplication().invokeLater(this, 275, true);
}
}
protected void onUndisplay() {
super.onUndisplay();
if (mInvokeId != -1) {
UiApplication.getUiApplication().cancelInvokeLater(mInvokeId);
mInvokeId = -1;
}
}
protected void layout(int width, int height) {
setExtent(Math.min(width, mFrameWidth), Math.min(height, mFrameHeight));
}
protected void paint(Graphics graphics) {
graphics.drawBitmap(0, 0, mFrameWidth, mFrameHeight, mImage, mFrameWidth * mCurrentFrame, 0);
++mCurrentFrame;
if (mCurrentFrame >= mFrames) {
mCurrentFrame = 0;
}
}
} // Class AnimatedImageField
} // Class AnimationLabelField
HorizontalFieldManager hfm = new HorizontalFieldManager(Manager.FIELD_VCENTER|Manager.FIELD_HCENTER);
hfm.add(progressAnimatedField);
hfm.add(progressLabelField);
add(hfm);
setPadding(2, 2, 2, 2);
}
protected Bitmap getAnimationImage() {
return Bitmap.getBitmapResource("progress.png");
}
protected void applyTheme(Graphics graphics, boolean arg) {
// do nothing
}
protected Field createAnimatedImageField(Bitmap image) {
return new AnimatedImageField(image, NON_FOCUSABLE|FIELD_VCENTER|FIELD_HCENTER);
}
public void updateText(String text) {
mLabelField.setText(text);
}
private static class AnimatedImageField extends Field implements Runnable {
private Bitmap mImage;
private int mCurrentFrame = 0;
private int mInvokeId = -1;
private int mFrameWidth;
private int mFrameHeight;
private int mFrames;
public AnimatedImageField(Bitmap image, long style) {
super(style | Field.NON_FOCUSABLE);
mImage = image;
mFrameHeight = mFrameWidth = mImage.getHeight();
mFrames = mImage.getWidth() / mFrameHeight;
}
public void run() {
if (isVisible()) {
invalidate();
}
}
protected void onDisplay() {
super.onDisplay();
if (mInvokeId == -1) {
mInvokeId = UiApplication.getUiApplication().invokeLater(this, 275, true);
}
}
protected void onUndisplay() {
super.onUndisplay();
if (mInvokeId != -1) {
UiApplication.getUiApplication().cancelInvokeLater(mInvokeId);
mInvokeId = -1;
}
}
protected void layout(int width, int height) {
setExtent(Math.min(width, mFrameWidth), Math.min(height, mFrameHeight));
}
protected void paint(Graphics graphics) {
graphics.drawBitmap(0, 0, mFrameWidth, mFrameHeight, mImage, mFrameWidth * mCurrentFrame, 0);
++mCurrentFrame;
if (mCurrentFrame >= mFrames) {
mCurrentFrame = 0;
}
}
} // Class AnimatedImageField
} // Class AnimationLabelField

0 comments on commit 6422a4a

Please sign in to comment.