Skip to content

Instantly share code, notes, and snippets.

View nalitzis's full-sized avatar
🎯
Focusing

Adolfo Bulfoni nalitzis

🎯
Focusing
  • Amsterdam
View GitHub Profile
@nalitzis
nalitzis / gist:2667108
Created May 12, 2012 15:11
Unit test with AsyncTask
public class NetworkTasksTest extends InstrumentationTestCase{
public void testGetMedia() throws Throwable{
final Context context = getInstrumentation().getTargetContext();
final CountDownLatch signal = new CountDownLatch(1);
final NetworkTasks networkTasks = new NetworkTasks(context, new GetMediaListener(signal));
runTestOnUiThread(new Runnable() {
public void testGetMedia() throws Throwable{
final Context context = getInstrumentation().getTargetContext();
final CountDownLatch signal = new CountDownLatch(1);
final NetworkTasks networkTasks = new NetworkTasks(context, new GetMediaListener(signal));
runTestOnUiThread(new Runnable() {
public void run() {
Media media = new Media();
media.setId("179");
public void getMedia(Media m){
AsyncTask<Media, Void, Throwable> task = new GetMediaAsycnTask<Media,Void,Throwable>();
task.execute();
}
private abstract class CallbackListener implements INetworkTasksListener{
private CountDownLatch signal;
CallbackListener(CountDownLatch signal){
this.signal = signal;
}
public void onSuccess(Media... medias) {
signal.countDown();
@nalitzis
nalitzis / gist:2857519
Created June 2, 2012 09:34
Audio record
public static final int FREQUENCY = 44100;
public static final int CHANNEL_CONFIGURATION = AudioFormat.CHANNEL_CONFIGURATION_MONO;
public static final int AUDIO_ENCODING = AudioFormat.ENCODING_PCM_16BIT;
private void recordSound(){
File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/"+RECORDED_FILENAME);
// Delete any previous recording.
if (file.exists())
private void mixFiles(){
try {
InputStream is1 = getResources().openRawResource(R.raw.test1);
List<Short> music1 = createMusicArray(is1);
InputStream is2 = getResources().openRawResource(R.raw.test2);
List<Short> music2 = createMusicArray(is2);
InputStream is3 = getResources().openRawResource(R.raw.test3);
List<Short> music3 = createMusicArray(is3);
private void mixFiles(){
try {
InputStream is1 = getResources().openRawResource(R.raw.test1);
List<Short> music1 = createMusicArray(is1);
InputStream is2 = getResources().openRawResource(R.raw.test2);
List<Short> music2 = createMusicArray(is2);
InputStream is3 = getResources().openRawResource(R.raw.test3);
List<Short> music3 = createMusicArray(is3);
@nalitzis
nalitzis / gist:3885194
Created October 13, 2012 16:18
animation when deleting a view
- (IBAction)deleteTapped:(id)sender {
[_delegate contentViewWillDelete:self];
[UIView animateWithDuration:0.5 animations:^{
self.alpha = 0.0f;
CGAffineTransform rotate = CGAffineTransformRotate(self.transform, 1);
CGAffineTransform translate = CGAffineTransformTranslate(self.transform, 300, -100);
self.transform = CGAffineTransformConcat(rotate, translate);
} completion:^(BOOL finished){
[self removeFromSuperview];
-(NSArray *)findAfterViewsAfter:(ContentView *)contentView{
int viewIndex = contentView.tag;
NSMutableArray *afterViews = [NSMutableArray array];
BOOL isBefore = YES;
for(int i=0; i < _views.count; i++){
ContentView *currentView = [_views objectAtIndex:i];
if(currentView.tag == viewIndex){
isBefore = NO;
continue;
@nalitzis
nalitzis / gist:3885215
Created October 13, 2012 16:22
translating up views
-(void)translateUp:(NSArray *)views{
[UIView animateWithDuration:0.5 animations:^{
for(ContentView *contentView in views){
contentView.transform = CGAffineTransformTranslate(contentView.transform, 0, -contentView.frame.size.height -_initialOffset);
}
}];
}