I've set default font for the whole Application by creating a BaseApplication extending Application but the fonts aren't working for just a specific activity(only one of the many) and the manifest is all right.
@Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
act = this;
t = this;
hashtags = new ArrayList<String>();
setContentView(R.layout.showpost);
Intent intent = new Intent(this.getIntent());
user_id = intent.getIntExtra("user_id", -1);
String s = intent.getStringExtra("info");
Log.d("test", "showpost" + s);
try {
JSONObject mInfo = new JSONObject(s);
useS = mInfo.getString("used");
id = mInfo.getInt("id");
user = mInfo.getInt("user");
nickname = mInfo.getString("userString");
desc = mInfo.getString("longdesc");
likes = mInfo.getInt("likes");
scraps = mInfo.getInt("scraps");
imgpath = mInfo.getString("image");
longdesc = new SpannableString(desc);
int lasthash = -1, i, len = desc.length();
for (i = 0; i < len; i++) {
Log.d("test", "i=" + i + "/last=" + lasthash + "/char=" + desc.charAt(i));
if (i == 0 && desc.charAt(i) == '#') lasthash = i;
else if (desc.charAt(i) == '#' && desc.charAt(i - 1) == ' ' || desc.charAt(i) == '#' && desc.charAt(i - 1) == '\n')
lasthash = i;
else if (desc.charAt(i) == ' ' && lasthash != -1 || desc.charAt(i) == '\n' && lasthash != -1) {
hashtags.add(desc.substring(lasthash + 1, i));
longdesc.setSpan(new ClickableSpan() {
@Override
public void onClick(View widget) {
// TODO add check if widget instanceof TextView
TextView tv = (TextView) widget;
// TODO add check if tv.getText() instanceof Spanned
Spanned s = (Spanned) tv.getText();
int start = s.getSpanStart(this);
int end = s.getSpanEnd(this);
}
}, lasthash + 1, i, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
lasthash = -1;
}
}
if (lasthash != -1) {
longdesc.setSpan(new ClickableSpan() {
@Override
public void onClick(View widget) {
// TODO add check if widget instanceof TextView
TextView tv = (TextView) widget;
// TODO add check if tv.getText() instanceof Spanned
Spanned s = (Spanned) tv.getText();
int start = s.getSpanStart(this);
int end = s.getSpanEnd(this);
Log.d("test", "onClick [" + s.subSequence(start, end) + "]");
}
}, lasthash + 1, i, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
hashtags.add(desc.substring(lasthash + 1, i));
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Bundle bundle = getIntent().getExtras();
top = bundle.getInt("top");
left = bundle.getInt("left");
width = bundle.getInt("width");
height = bundle.getInt("height");
SV_showpost = (ScrollView) findViewById(R.id.SV_showpost);
IV_showpost_profile = (ImageView) findViewById(R.id.IV_showpost_profile);
IV_showpost_image = (ImageView) findViewById(R.id.IV_showpost_image);
IV_showpost_like = (ImageView) findViewById(R.id.IV_showpost_like);
IV_showpost_scrap = (ImageView) findViewById(R.id.IV_showpost_scrap);
IV_showpost_profile.setOnClickListener(this);
IV_showpost_like.setOnClickListener(this);
IV_showpost_scrap.setOnClickListener(this);
TV_showpost_desc = (TextView) findViewById(R.id.TV_showpost_desc);
TV_showpost_likescrap = (TextView) findViewById(R.id.TV_showpost_likescrap);
TV_showpost_userid = (TextView) findViewById(R.id.TV_showpost_userid);
RV_showpost_hash = (RecyclerView) findViewById(R.id.RV_showpost_hash);
RV_showpost_hash.setHasFixedSize(true);
LinearLayoutManager llm = new LinearLayoutManager(this);
llm.setOrientation(LinearLayoutManager.HORIZONTAL);
RV_showpost_hash.setLayoutManager(llm);
RV_showpost_hash.setAdapter(new HashAdapter(hashtags));
TV_showpost_desc.setText(longdesc);
TV_showpost_userid.setText(nickname);
TV_showpost_likescrap.setText(likes + likestring + scraps + scrapstring);
ItemClickSupport.addTo(RV_showpost_hash).setOnItemClickListener(new ItemClickSupport.OnItemClickListener() {
@Override
public void onItemClicked(RecyclerView recyclerView, int position, View v) {
Intent it = new Intent(t, Search.class);
it.putExtra("user_id", user_id);
it.putExtra("search", hashtags.get(position));
it.putExtra("searchUser", false);
startActivityForResult(it,0);
return;
}
});
/*
DisplayMetrics outMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(outMetrics);
int h = outMetrics.heightPixels;
int hh = h/2;
int ww = hh*888/1774;
LinearLayout.LayoutParams LP1 = new LinearLayout.LayoutParams(ww, hh);
LP1.gravity = Gravity.CENTER;
IV_showpost.setLayoutParams(LP1);
IV_showpost.setImageDrawable(Drawable.createFromPath(getFilesDir() + "/postimage/" + imgpath));
IV_showpost.setScaleType(ImageView.ScaleType.FIT_XY);*/
TV_showpost_userid.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new ShowProfileAsync().execute();
}
});
SV_showpost.smoothScrollTo(0, 0);
if (savedInstanceState == null) {
ViewTreeObserver observer = SV_showpost.getViewTreeObserver();
observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
SV_showpost.getViewTreeObserver().removeOnPreDrawListener(this);
int[] screenLocation = new int[2];
SV_showpost.getLocationOnScreen(screenLocation);
mLeft = screenLocation[0];
mTop = screenLocation[1];
Log.d("test", "mLeft" + mLeft + "//mTop" + mTop);
mLeftDelta = left - screenLocation[0];
mTopDelta = top - screenLocation[1];
mWidthScale = (float) width / SV_showpost.getWidth();
mHeightScale = (float) height / SV_showpost.getHeight();
runEnterAnimation();
return true;
}
});
}
}
here is the onCreate(), no much deal. The only difference in Intent is that this activity starts with a special animation with overridePendingTransitions() on. But deleting the line does not help so I don't think that's a big deal.
I've been struggling for hours please help or suggest any points for me to look up... Is there anyway you can exclude specific activities from the Application settings without the other parts where you can set font at?
Do all your activities override setting the baseContext? Can you show me how it's applied in your project. onCreate has nothing to do with that. Do you define the CalligraphyConfig in the Application onCreate?
I've set default font for the whole Application by creating a BaseApplication extending Application but the fonts aren't working for just a specific activity(only one of the many) and the manifest is all right.
here is the onCreate(), no much deal. The only difference in Intent is that this activity starts with a special animation with overridePendingTransitions() on. But deleting the line does not help so I don't think that's a big deal.
I've been struggling for hours please help or suggest any points for me to look up... Is there anyway you can exclude specific activities from the Application settings without the other parts where you can set font at?