Skip to content

Instantly share code, notes, and snippets.

View shikajiro's full-sized avatar

shikajiro shikajiro

View GitHub Profile
@shikajiro
shikajiro / Main.java
Last active December 30, 2015 06:28
AnndroidAnnotationsによる一般的な@rest
@EActivity
public class HogeActivity{
@Rest WebApi webApi;
public void hoge(){
try{
UserJson json = webApi.getUser(1234);
return json;
}catch(RestClientException e){
//HTTPエラー処理
//RestClientException は非チェック例外
@shikajiro
shikajiro / MainActivity.java
Last active December 30, 2015 06:29
@backgroundと@UiThread
public class MainActivity extends Activity {
// 省略
@Background
void login(String username, String password) {
try {
webApi.login(username, password);
callbackLogin();
} catch (HttpClientErrorException e) {
callbackLoginMiss(e);
@shikajiro
shikajiro / MyPrefs.java
Created December 4, 2013 15:37
@SharedPrefのサンプル
@SharedPref(value=Scope.UNIQUE)
public interface MyPrefs {
@DefaultLong(-1) long userId();
}
@shikajiro
shikajiro / TimelineFragment.java
Created December 4, 2013 15:47
ListVIewのサンプル
@EFragment(R.layout.fragment_timeline)
public class TimelineFragment extends Fragment {
@ViewById ListView timelineListView;
@AfterViews
void onAfterViews(){
List<TimelineItem> items = Lists.newArrayList();
//itemsにデータ詰める
TimelineAdapter adapter = new TimelineAdapter(getActivity(), items);
timelineListView.setAdapter(adapter);
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="jp.hoge"
android:versionCode="1"
android:versionName="1.0" >
<application
android:name=".AppImpl_"
android:allowBackup="true"
android:icon="@drawable/icon"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
@shikajiro
shikajiro / AcceptActivity.java
Last active December 31, 2015 12:19
BTでデータを送信するコード
package com.example.ble;
import static android.bluetooth.BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE;
import static android.bluetooth.BluetoothAdapter.ACTION_REQUEST_ENABLE;
import static android.bluetooth.BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION;
import static android.bluetooth.BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE;
import static android.bluetooth.BluetoothAdapter.getDefaultAdapter;
import java.io.IOException;
import java.io.InputStream;
curl --header "Authorization: key=<server key>" --header Content-Type:"application/json" https://android.googleapis.com/gcm/send -d "{\"registration_ids\":[\"<registration id>\"],\"data\":{\"message\":\"Hello\"}}"
@shikajiro
shikajiro / file0.java
Created August 13, 2014 16:35
Androidでのテストで色々悩んだ結果robotiumになった件 ref: http://qiita.com/shikajiro@github/items/d28bf5eb4c9268f81131
public void testSayHello() {
//このclickで画面遷移すると仮定する。
onView(withId(R.id.greet_button))
.perform(click());
//遷移後の画面に"Hello Steve!"が表示されるが、このassertはOKだったりNGだったりする。
onView(withText("Hello Steve!"))
.check(matches(isDisplayed()));
}
@shikajiro
shikajiro / build.gradle
Created December 9, 2014 08:10
Deploygateにgradleからアップロードする際に、メッセージをコンソールから指定する ref: http://qiita.com/shikajiro/items/7a4f26cb4c5fff8b2a93
deploygate {
userName = "shikajiro"
token = "hogehoge"
apks {
release {
sourceFile = file("build/outputs/apk/app-release.apk")
message = deploygateMsg
}
debug {
@shikajiro
shikajiro / MainActivity.java
Last active August 29, 2015 14:15
AndroidからOAuth2を使ってGoogle SpreadSheetへアクセスする方法 ref: http://qiita.com/shikajiro/items/63200af32b280be48bb5
//※ここにユーザーアカウント選択画面があると素敵だと思います。
//oauth tokenの取得
String token;
try {
token = GoogleAuthUtil.getToken(this, "[email protected]", "oauth2:https://spreadsheets.google.com/feeds");
Log.i("TAG", token);
} catch (UserRecoverableAuthException e) {
//最初のアクセスの場合かならずここに来る。
//ユーザーに承認を求める画面が表示される。