Ctrl+KB | toggle side bar |
Ctrl+Shift+P | command prompt |
Ctrl+` | python console |
Ctrl+N | new file |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://www.akitaonrails.com/2012/09/03/why-documentary-at-rubyconf-2012-denver | |
Date: Thu, 19 Apr 2007 17:38:59 -0500 | |
From: why the lucky stiff <[email protected]> | |
To: [email protected] | |
Subject: SPAM: Re: Invitation for an Interview for Brazilian Blog | |
On Wed, Apr 18, 2007 at 10:28:25AM -0300, Fabio Akita wrote: | |
> First of all let me introduce myself, my name is Fabio Akita, I've written | |
> the first brazilian Rails book called "Repensando a Web com Rails". I have a |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://www.smashingmagazine.com/2010/05/15/why-a-tale-of-a-post-modern-genius/ | |
I do not write tests for my code. I do not write very many comments. I | |
change styles very frequently. And most of all, I shun the predominant | |
styles of coding, because that would go against the very essence of | |
experimentation. In short: all I do is muck around. | |
So, my way of measuring a great programmer is different from some | |
prevailing thought on the subject. I would like to hear what Matz | |
would say about this. You should ask him, seriously. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int dipValue = 200; // we whant to convert this dip value to pix | |
Resources r = getResources(); | |
float pix = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dipValue, r.getDisplayMetrics()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.company.app.utils; | |
import android.graphics.Bitmap; | |
import android.graphics.Canvas; | |
import android.graphics.Paint; | |
import android.graphics.PorterDuffXfermode; | |
import android.graphics.Rect; | |
import android.graphics.RectF; | |
import android.graphics.Bitmap.Config; | |
import android.graphics.PorterDuff.Mode; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Indicates whether the specified action can be used as an intent. This | |
* method queries the package manager for installed packages that can | |
* respond to an intent with the specified action. If no suitable package is | |
* found, this method returns false. | |
* | |
* @param context The application's environment. | |
* @param action The Intent action to check for availability. | |
* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- do not use null on LayoutInflater.inflate | |
- use FrameLayout or LinearLayout instead of RelativeLayout as the latter takes at least 2 passes on layout | |
- use ViewHolder pattern |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private boolean isMyServiceRunning() { | |
ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); | |
for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { | |
if (MyService.class.getName().equals(service.service.getClassName())) { | |
return true; | |
} | |
} | |
return false; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
If your service is going to be part of you application then you are making it way more complex than it needs to be. Since you have a simple use case of getting some data from a RESTful Web Service, you should look into ResultReceiver and IntentService. | |
This Service + ResultReceiver pattern works by starting or binding to the service with startService() when you want to do some action. You can specify the operation to perform and pass in your ResultReceiver (the activity) through the extras in the Intent. | |
In the service you implement onHandleIntent to do the operation that is specified in the Intent. When the operation is completed you use the passed in ResultReceiver to send a message back to the Activity at which point onReceiveResult will be called. | |
So for example, you want to pull some data from your Web Service. | |
You create the intent and call startService. | |
The operation in the service starts and it sends the activity a message saying it started |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I think you will enjoy my extremely comprehensive and working example! | |
Rotation works, and the dialog survives. | |
You can cancel the task and dialog by pressing the back button (if you want this behaviour). | |
It uses fragments. | |
The layout of the fragment underneath the activity changes properly when the device rotates. | |
There is a complete source code download and a precompiled APK so you can see if the behaviour is what you want. | |
Edit | |
As requested by Brad Larson I have reproduced most of the linked solution below. Also since I posted it I have been pointed to AsyncTaskLoader. I'm not sure it is totally applicable to the same problems, but you should check it out anyway. |