Skip to content

Commit

Permalink
Guy to refactor fontello.
Browse files Browse the repository at this point in the history
  • Loading branch information
s-aska committed Jan 22, 2014
1 parent 80ac26d commit a2ffccd
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 28 deletions.
26 changes: 15 additions & 11 deletions src/info/justaway/JustawayApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.res.Configuration;
import android.graphics.Typeface;
import android.text.TextUtils;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
Expand Down Expand Up @@ -42,8 +44,9 @@
public class JustawayApplication extends Application {

private static JustawayApplication sApplication;
private static ImageLoader mImageLoader;
private static DisplayImageOptions mRoundedDisplayImageOptions;
private static ImageLoader sImageLoader;
private static DisplayImageOptions sRoundedDisplayImageOptions;
private static Typeface sFontello;
private ResponseList<UserList> mUserLists;

public ResponseList<UserList> getUserLists() {
Expand Down Expand Up @@ -78,15 +81,14 @@ public String getUserListScreenName(int id) {
return null;
}

/**
* 毎回キャストしなくて良いように
*
* @return アプリケーションのインスタンス
*/
public static JustawayApplication getApplication() {
return sApplication;
}

public static Typeface getFontello() {
return sFontello;
}

@Override
public void onCreate() {
super.onCreate();
Expand All @@ -106,15 +108,17 @@ public void onCreate() {

ImageLoader.getInstance().init(config);

mImageLoader = ImageLoader.getInstance();
sImageLoader = ImageLoader.getInstance();

mRoundedDisplayImageOptions = new DisplayImageOptions.Builder()
sRoundedDisplayImageOptions = new DisplayImageOptions.Builder()
.cacheInMemory(true)
.cacheOnDisc(true)
.resetViewBeforeLoading(true)
.displayer(new FadeInRoundedBitmapDisplayer(5))
.build();

sFontello = Typeface.createFromAsset(getAssets(), "fontello.ttf");

// 例外発生時の処理を指定(スタックトレースを保存)
if (BuildConfig.DEBUG) {
Thread.setDefaultUncaughtExceptionHandler(new MyUncaughtExceptionHandler(sApplication));
Expand All @@ -127,7 +131,7 @@ public void displayImage(String url, ImageView view) {
return;
}
view.setTag(url);
mImageLoader.displayImage(url, view);
sImageLoader.displayImage(url, view);
}

public void displayRoundedImage(String url, ImageView view) {
Expand All @@ -136,7 +140,7 @@ public void displayRoundedImage(String url, ImageView view) {
return;
}
view.setTag(url);
mImageLoader.displayImage(url, view, mRoundedDisplayImageOptions);
sImageLoader.displayImage(url, view, sRoundedDisplayImageOptions);
}

/*
Expand Down
4 changes: 2 additions & 2 deletions src/info/justaway/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ protected void onCreate(Bundle savedInstanceState) {
* ActionBarのタブに頼っていない為、自力でsetCurrentItemでタブを動かしている
* タブの切替がスワイプだけで良い場合はこの処理すら不要
*/
Typeface fontello = Typeface.createFromAsset(getAssets(), "fontello.ttf");
Typeface fontello = JustawayApplication.getFontello();
Button home = (Button) findViewById(R.id.action_timeline);
Button interactions = (Button) findViewById(R.id.action_interactions);
Button directMessage = (Button) findViewById(R.id.action_direct_message);
Expand Down Expand Up @@ -214,7 +214,7 @@ public void setupTab() {
ArrayList<Integer> tabs = mApplication.loadTabs();
int position = 2;
for (Integer tab : tabs) {
Typeface fontello = Typeface.createFromAsset(getAssets(), "fontello.ttf");
Typeface fontello = JustawayApplication.getFontello();
// 標準のタブを動的に生成する時に実装する
if (tab > 0) {
Button button = new Button(this);
Expand Down
13 changes: 6 additions & 7 deletions src/info/justaway/PostActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ public class PostActivity extends FragmentActivity {
private Long mInReplyToStatusId;
private File mImgPath;
private DraftFragment mDraftDialog;
private Typeface mFontello;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -68,7 +67,7 @@ protected void onCreate(Bundle savedInstanceState) {

JustawayApplication application = JustawayApplication.getApplication();

mFontello = Typeface.createFromAsset(getAssets(), "fontello.ttf");
Typeface fontello = JustawayApplication.getFontello();

mEditText = (EditText) findViewById(R.id.status);
mTextView = (TextView) findViewById(R.id.count);
Expand All @@ -78,10 +77,10 @@ protected void onCreate(Bundle savedInstanceState) {
mDraftButton = (Button) findViewById(R.id.word);
mTwitter = application.getTwitter();

mTweetButton.setTypeface(mFontello);
mImgButton.setTypeface(mFontello);
mSuddenlyButton.setTypeface(mFontello);
mDraftButton.setTypeface(mFontello);
mTweetButton.setTypeface(fontello);
mImgButton.setTypeface(fontello);
mSuddenlyButton.setTypeface(fontello);
mDraftButton.setTypeface(fontello);

Intent intent = getIntent();
String status = intent.getStringExtra("status");
Expand Down Expand Up @@ -445,7 +444,7 @@ public View getView(final int position, View convertView, ViewGroup parent) {
final String draft = mDraftLists.get(position);

((TextView) view.findViewById(R.id.word)).setText(draft);
((TextView) view.findViewById(R.id.trash)).setTypeface(mFontello);
((TextView) view.findViewById(R.id.trash)).setTypeface(JustawayApplication.getFontello());

view.setOnClickListener(new View.OnClickListener() {
@Override
Expand Down
2 changes: 1 addition & 1 deletion src/info/justaway/ProfileActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected void onCreate(Bundle savedInstanceState) {
((TextView) findViewById(R.id.statuses_count)).setTextColor(mColorBlue);
((TextView) findViewById(R.id.statuses_count_label)).setTextColor(mColorBlue);

Typeface fontello = Typeface.createFromAsset(getAssets(), "fontello.ttf");
Typeface fontello = JustawayApplication.getFontello();
((TextView) findViewById(R.id.collapse_label)).setTypeface(fontello);

// インテント経由での起動をサポート
Expand Down
4 changes: 2 additions & 2 deletions src/info/justaway/SearchActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected void onCreate(Bundle savedInstanceState) {

Button search = (Button) findViewById(R.id.search);
Button tweet = (Button) findViewById(R.id.tweet);
Typeface fontello = Typeface.createFromAsset(mContext.getAssets(), "fontello.ttf");
Typeface fontello = JustawayApplication.getFontello();
search.setTypeface(fontello);
tweet.setTypeface(fontello);

Expand Down Expand Up @@ -335,7 +335,7 @@ public View getView(final int position, View convertView, ViewGroup parent) {
final SavedSearch word = mWordLists.get(position);

((TextView) view.findViewById(R.id.word)).setText(word.getQuery());
((TextView) view.findViewById(R.id.trash)).setTypeface(Typeface.createFromAsset(getAssets(), "fontello.ttf"));
((TextView) view.findViewById(R.id.trash)).setTypeface(JustawayApplication.getFontello());

view.setOnClickListener(new View.OnClickListener() {
@Override
Expand Down
2 changes: 1 addition & 1 deletion src/info/justaway/SignInActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected void onCreate(Bundle savedInstanceState) {
mCallbackURL = getString(R.string.twitter_callback_url);
mTwitter = application.getTwitter();

Typeface fontello = Typeface.createFromAsset(this.getAssets(), "fontello.ttf");
Typeface fontello = JustawayApplication.getFontello();
TextView button = (TextView) findViewById(R.id.action_start_oauth);
button.setTypeface(fontello);
button.setOnClickListener(new View.OnClickListener() {
Expand Down
3 changes: 1 addition & 2 deletions src/info/justaway/adapter/FriendListAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ public View getView(int position, View convertView, ViewGroup parent) {
description.setVisibility(View.GONE);
}

Typeface fontello = Typeface.createFromAsset(mContext.getAssets(), "fontello.ttf");

Typeface fontello = JustawayApplication.getFontello();
if (user.isProtected()) {
((TextView) view.findViewById(R.id.fontello_lock)).setTypeface(fontello);
view.findViewById(R.id.fontello_lock).setVisibility(View.VISIBLE);
Expand Down
4 changes: 2 additions & 2 deletions src/info/justaway/adapter/TwitterAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public View getView(int position, View convertView, ViewGroup parent) {

private void renderMessage(ViewHolder holder, final DirectMessage message) {

Typeface fontello = Typeface.createFromAsset(mContext.getAssets(), "fontello.ttf");
Typeface fontello = JustawayApplication.getFontello();
long userId = JustawayApplication.getApplication().getUserId();

holder.do_retweet.setVisibility(View.GONE);
Expand Down Expand Up @@ -327,7 +327,7 @@ private void renderStatus(final ViewHolder holder, final Status status, Status r

long userId = JustawayApplication.getApplication().getUserId();

Typeface fontello = Typeface.createFromAsset(mContext.getAssets(), "fontello.ttf");
Typeface fontello = JustawayApplication.getFontello();

if (status.getFavoriteCount() > 0) {
holder.fav_count.setText(String.valueOf(status.getFavoriteCount()));
Expand Down

0 comments on commit a2ffccd

Please sign in to comment.