Last active
October 26, 2015 02:34
-
-
Save shts/b10ff515d50b9533dffe to your computer and use it in GitHub Desktop.
This file contains 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 jp.shts.android.nogirepo; | |
public class AppUser extends Person { | |
AppUser(String id, String url, String name) { | |
super(Type.APP_USER, id, url, name); | |
} | |
public static List<AppUser> findByIds(List<String> idList) { | |
// ParseUser | |
ParseQuery<ParseObject> query = ParseQuery.getQuery("AppUser"); | |
query.whereContainedIn("social_id", idList); | |
List<ParseUser> users = query.findInBackground(); | |
return users; | |
} | |
public static void findByIds(List<String> idList, FindCallback<AppUser> callback) { | |
// ParseUser | |
ParseQuery<ParseObject> query = ParseQuery.getQuery("AppUser"); | |
query.whereContainedIn("social_id", idList); | |
query.findInBackground(callback); | |
} | |
} |
This file contains 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 jp.shts.android.nogirepo; | |
import jp.shts.android.nogirepo.Person.Type; | |
import org.json.JSONArray; | |
import org.json.JSONException; | |
import org.json.JSONObject; | |
import android.content.ContentValues; | |
import android.util.Pair; | |
/** | |
* | |
{ | |
"talk": [ | |
{ | |
"person": { | |
"type": "member", | |
"_id": "a", | |
"name": "a", | |
"url": "a" | |
}, | |
"say": "hello" | |
}, | |
{ | |
"person": { | |
"type": "app_user", | |
"_id": "a", | |
"name": "a", | |
"url": "a" | |
}, | |
"say": "hello" | |
}, | |
{ | |
"person": { | |
"type": "member", | |
"_id": "a", | |
"name": "a", | |
"url": "a" | |
}, | |
"say": "hello" | |
} | |
] | |
} | |
* | |
*/ | |
public class Talk extends PairList<Person, String> { | |
public static Talk createFrom(JSONObject jsonObject) { | |
Talk talk = new Talk(); | |
if (jsonObject == null) { | |
// return Empty Object | |
return talk; | |
} | |
try { | |
JSONArray rootObject = (JSONArray) jsonObject.get("talk"); | |
final int N = rootObject.length(); | |
for (int i = 0; i < N; i++) { | |
JSONObject object = (JSONObject) rootObject.get(i); | |
JSONObject personObject = object.getJSONObject("person"); | |
String typeString = personObject.getString("type"); | |
String _id = personObject.getString("_id"); | |
String name = personObject.getString("name"); | |
String url = personObject.getString("url"); | |
String say = object.getString("say"); | |
Type personType = Type.from(typeString); | |
if (personType == Type.APP_USER) { | |
talk.add(new AppUser(_id, name, url), say); | |
} else if (personType == Type.MEMBER) { | |
talk.add(new Member(_id, name, url), say); | |
} | |
} | |
} catch (JSONException e) { | |
// | |
} | |
return talk; | |
} | |
public JSONArray toJSONArray() { | |
JSONArray talk = new JSONArray(); | |
try { | |
for (Pair<Person, String> pair : this) { | |
JSONObject jsonObject = new JSONObject(); | |
JSONObject person = new JSONObject(); | |
person.put("_id", pair.first.id); | |
person.put("name", pair.first.name); | |
person.put("url", pair.first.url); | |
jsonObject.put("person", person); | |
jsonObject.put("say", pair.second); | |
talk.put(jsonObject); | |
} | |
return talk; | |
} catch (JSONException e) { | |
} | |
return talk; | |
} | |
public void load(String id) { | |
} | |
} |
This file contains 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
public class TwitterApiClient { | |
private TwitterApiClient() {} | |
public abstract class TwitterApiResponseHandler { | |
private Handler mHandler; | |
public TwitterApiResponseHandler() {} | |
public TwitterApiResponseHandler(Looper looper) { | |
mHandler = new Handler(looper); | |
} | |
public void notify(final String responseBody) { | |
if (mHandler != null) { | |
mHandler.post(new Runnable() { | |
@Override | |
public void run() { | |
onFinish(responseBody); | |
} | |
}); | |
} else { | |
onFinish(responseBody); | |
} | |
} | |
public abstract void onFinish(String responseBody); | |
} | |
private static final HandlerThread WORKER_THREAD = new HandlerThread("TwitterApiClient-Thread"); | |
private static final Handler WORKER; | |
static { | |
WORKER_THREAD.start(); | |
WORKER = new Handler(WORKER_THREAD.getLooper()); | |
} | |
public abstract class GetLinkedTwitterFriendsResponseHandler extends TwitterApiResponseHandler { | |
public GetLinkedTwitterFriendsResponseHandler() { | |
super(); | |
} | |
public GetLinkedTwitterFriendsResponseHandler(Looper looper) { | |
super(looper); | |
} | |
@Override | |
public void onFinish(String responseBody) { | |
TwitterFriends friends = TwitterFriends.from(responseBody); | |
// Get linked friends from twitter friends. | |
List<AppUser> appUserList = AppUser.findByIds(friends.getIdList()); | |
handler.onFinish(appUserList); | |
} | |
public abstract void onFinish(List<AppUser> appUserList); | |
} | |
public static void getAllLinkedTwitterFriend(final GetLinkedTwitterFriendsResponseHandler handler) { | |
get(handler); | |
} | |
private static void get(final TwitterApiResponseHandler handler) { | |
WORKER.post(new Runnable() { | |
@Override | |
public void run() { | |
final String responseBody = syncGetAllFriends(); | |
handler.onFinish(appUserList); | |
} | |
}); | |
} | |
private static String syncGetAllFriends() { | |
String twitterId = ParseTwitterUtils.getTwitter().getId(); | |
String url = "https://api.twitter.com/1.1/friends/ids.json?user_id=" + twitterId; | |
HttpGet verifyGet = new HttpGet(url); | |
ParseTwitterUtils.getTwitter().signRequest(verifyGet); | |
return execute(verifyGet); | |
} | |
private String execute(HttpGet verifyGet) { | |
HttpClient client = new DefaultHttpClient(); | |
try { | |
return client.execute(verifyGet, new ResponseHandler<String>() { | |
@Override | |
public String handleResponse(HttpResponse response) | |
throws ClientProtocolException, IOException { | |
// response.getStatusLine().getStatusCode()でレスポンスコードを判定する。 | |
// 正常に通信できた場合、HttpStatus.SC_OK(HTTP 200)となる。 | |
switch (response.getStatusLine().getStatusCode()) { | |
case HttpStatus.SC_OK: | |
// レスポンスデータを文字列として取得する。 | |
// byte[]として読み出したいときはEntityUtils.toByteArray()を使う。 | |
return EntityUtils.toString(response.getEntity(), "UTF-8"); | |
case HttpStatus.SC_NOT_FOUND: | |
throw new RuntimeException("データないよ!"); //FIXME | |
default: | |
throw new RuntimeException("なんか通信エラーでた"); //FIXME | |
} | |
} | |
}); | |
} catch (ClientProtocolException e) { | |
throw new RuntimeException(e); //FIXME | |
} catch (IOException e) { | |
throw new RuntimeException(e); //FIXME | |
} finally { | |
// ここではfinallyでshutdown()しているが、HttpClientを使い回す場合は、 | |
// 適切なところで行うこと。当然だがshutdown()したインスタンスは通信できなくなる。 | |
httpClient.getConnectionManager().shutdown(); | |
} | |
} | |
} | |
This file contains 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
public class TwitterFriend { | |
// id | |
public String id_str; | |
public in id; | |
// name | |
public String name; | |
public String screen_name; | |
// image | |
public String profile_image_url; | |
public String profile_image_url_https; | |
// color | |
public String profile_sidebar_fill_color; | |
public String profile_sidebar_border_color; | |
public String profile_link_color; | |
public String profile_text_color; | |
public String profile_background_color; | |
public static Friend from(JSONObject jsonObject) { | |
Friend friend = new Friend(); | |
try { | |
friend.id_str = jsonObject.getString("id_str"); | |
friend.id = jsonObject.getInt("id"); | |
friend.name = jsonObject.getString("name"); | |
friend.screen_name = jsonObject.getString("screen_name"); | |
friend.profile_image_url = jsonObject.getString("profile_image_url"); | |
friend.profile_image_url_https = jsonObject.getString("profile_image_url_https"); | |
friend.profile_sidebar_fill_color = jsonObject.getString("profile_sidebar_fill_color"); | |
friend.profile_sidebar_border_color = jsonObject.getString("profile_sidebar_border_color"); | |
friend.profile_link_color = jsonObject.getString("profile_link_color"); | |
friend.profile_text_color = jsonObject.getString("profile_text_color"); | |
friend.profile_background_color = jsonObject.getString("profile_background_color"); | |
} catch (JSONException e) { | |
// | |
} | |
return friend; | |
} | |
} |
This file contains 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
public class TwitterFriends extends ArrayList<TwitterFriend> { | |
private TwitterFriends() {} | |
public static TwitterFriends from(String jsonString) { | |
if (TextUtils.isEmpty(jsonString)) { | |
return new TwitterFriends(); | |
} | |
JSONArray rootObject = new JSONArray(jsonString); | |
final int N = rootObject.size(); | |
for (int i = 0; i < N; i++) { | |
add(TwitterFriend.from(rootObject.get(i))); | |
} | |
} | |
public ArrayList<String> getIdList() { | |
ArrayList<String> list = new ArrayList<String>(); | |
for (TwitterFriend friend : this) { | |
list.add(friend.id_str); | |
} | |
return list; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fab policy
https://www.google.com/design/spec/components/buttons-floating-action-button.html#buttons-floating-action-button-transitions
Fab押下時にFab上部に表示するminiボタンは3~6まで。
ex)自分、メンバー、メンバーを追加
Lib
https://android-arsenal.com/details/1/1781
-> アイコンをカスタムできない。依存ライブラリが多い
https://github.com/konifar/fab-transformation
-> うすくてシンプル。Android 2.3+
-> inboxっぽい実装ができそう。minSdkVersion=14
Color
primary
673AB7
primary-dark
512DA8
accent
FF4081
accent-dark
F50057
http://developer.android.com/intl/ja/training/material/theme.html#ColorPalette