Skip to content

Instantly share code, notes, and snippets.

View allenatwork's full-sized avatar

Allen Walker allenatwork

View GitHub Profile
/*
* Copyright (C) 2014 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@allenatwork
allenatwork / Working with SQLite command in Android
Last active August 31, 2017 09:13
Working with SQLite command in Android
1. adb shell
2. run-as your.package.name -> auto cd to app folder
3. cd databases
4. sqlite3 your_db
5. try some command: .databases, .tables, insert, select
6. to quit: .quit -> enter
===================
Count number of row: SELECT count(*) FROM COMPANY;
@allenatwork
allenatwork / Note.txt
Created August 30, 2017 04:04
Try - Catch
Exceptions are EXPENSIVE! A stack trace must be created (if used, eg logged etc) and special flow control handled
Exceptions should not be used for flow control - Exceptions are for the "exceptional"
Exceptions are the code's way of saying "I can't handle this situation and I'm giving up... you deal with it!", but here you can handle it... so handle it
-> use check is faster
@allenatwork
allenatwork / Handler_Message.txt
Last active August 28, 2017 08:05
Understand Handler, message, looper, messag queue
A detail talk about handler, message, looper, message queue
https://medium.com/@jagsaund/android-handler-internals-b5d49eba6977
package com.labo.kaji.relativepopupwindow;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.support.annotation.IntDef;
import android.support.annotation.NonNull;
import android.support.v4.widget.PopupWindowCompat;
import android.util.AttributeSet;
import android.view.Gravity;
package jp.co.neo.DCChat.common.utils;
import android.content.Context;
import android.support.annotation.StringRes;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
@allenatwork
allenatwork / keyboard.m
Created April 5, 2017 07:21
Show done button for UITextView
// Add toolbar to above keyboard
UIToolbar* numberToolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 50)];
numberToolbar.barStyle = UIBarStyleBlackTranslucent;
numberToolbar.items = [NSArray arrayWithObjects:
[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],
[[UIBarButtonItem alloc]initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(doneWithNumberPad)],
nil];
[numberToolbar sizeToFit];
_tvContent.inputAccessoryView = numberToolbar;
@allenatwork
allenatwork / DownloadTask
Created March 15, 2017 08:51
Download Task
public class DownLoadTask extends Thread {
private String mFilePath;
private String mDownLoadUrl;
private ProgressListener mProgressListener;
private OkHttpClient mClient;
public DownLoadTask(String filePath, String downLoadUrl, ProgressListener progressListener) {
mDownLoadUrl = downLoadUrl;
mFilePath = filePath;
# Created by https://www.gitignore.io/api/android,intellij
### Android ###
# Built application files
*.apk
*.ap_
# Files for the ART/Dalvik VM
*.dex
@allenatwork
allenatwork / android_eventbus.md
Created January 6, 2017 06:53 — forked from SandNerd/android_eventbus.md
Android EventBus

Event Bus

(EventBus) - Android optimized event bus that simplifies communication between Activities, Fragments, Threads, Services, etc. Less code, better quality.

An EventBus is a great tool for decoupling components in your application. Over the next few posts I will describe the ways that I have been using it to make my code cleaner, easier to read, and easier to test. But first, this week I want to discuss why I use an EventBus in the first place. In particular, I will compare its use to some alternative techniques.