android


Cant apply Custom font on app widget service


final Handler handler = new Handler();
timer = new Timer();
TimerTask updateWidget = new TimerTask() {
#Override
public void run() {
handler.post(new Runnable() {
public void run() {
if (flag&&flag1) {
flag = false;
flag1=false;
try {
image = BitmapFactory.decodeStream((InputStream) new URL("http://openweathermap.org/img/w/"
+ prefs.getString("image", "") + ".png").getContent());
} catch (IOException e) {
e.printStackTrace();
}
if (state == 0) {
remoteViews.setTextViewText(R.id.more_less, "Show more");
remoteViews.setViewVisibility(R.id.weather_icon1, View.GONE);
remoteViews.setTextViewText(R.id.temperature, prefs.getString("vTemperature", "") + "" + unit);
// remoteViews.setImageViewBitmap(R.id.temperature, getFontBitmap((prefs.getString("vTemperature", "") + "" + unit).toString(), Color.WHITE, 100));
remoteViews.setImageViewBitmap(R.id.weather_icon, image);
if (city.length() > 12) {
remoteViews.setTextViewTextSize(R.id.city, TypedValue.COMPLEX_UNIT_PX, 50f);
} else {
remoteViews.setTextViewTextSize(R.id.city, TypedValue.COMPLEX_UNIT_PX, 80f);
}
remoteViews.setTextViewText(R.id.city, city);
remoteViews.setTextViewText(R.id.mainDescription, prefs.getString("mainDescription", ""));
description = prefs.getString("description", "");
if (description.length() > 1) {
description = description.substring(0, 1).toUpperCase() + description.substring(1).toLowerCase();
}
remoteViews.setTextViewText(R.id.description, description);
// remoteViews.setImageViewBitmap(R.id.description, buildUpdate(description));
} else {
remoteViews.setTextViewText(R.id.more_less, "Show less");
remoteViews.setViewVisibility(R.id.weather_icon1, View.VISIBLE);
remoteViews.setTextViewText(R.id.time_1, String.valueOf(timeList.get(0)));
remoteViews.setTextViewText(R.id.time_2, String.valueOf(timeList.get(1)));
remoteViews.setTextViewText(R.id.time_3, String.valueOf(timeList.get(2)));
remoteViews.setTextViewText(R.id.time_4, String.valueOf(timeList.get(3)));
remoteViews.setTextViewText(R.id.time_5, String.valueOf(timeList.get(4)));
remoteViews.setTextViewText(R.id.temperature_1, minTempList.get(0) + "" + unit + "\\" + maxTempList.get(0) + "" + unit);
remoteViews.setTextViewText(R.id.temperature_2, minTempList.get(1) + "" + unit + "\\" + maxTempList.get(1) + "" + unit);
remoteViews.setTextViewText(R.id.temperature_3, minTempList.get(2) + "" + unit + "\\" + maxTempList.get(2) + "" + unit);
remoteViews.setTextViewText(R.id.temperature_4, minTempList.get(3) + "" + unit + "\\" + maxTempList.get(3) + "" + unit);
remoteViews.setTextViewText(R.id.temperature_5, minTempList.get(4) + "" + unit + "\\" + maxTempList.get(4) + "" + unit);
remoteViews.setImageViewBitmap(R.id.icon_1, decodeBitmap(iconList.get(0)));
remoteViews.setImageViewBitmap(R.id.icon_2, decodeBitmap(iconList.get(1)));
remoteViews.setImageViewBitmap(R.id.icon_3, decodeBitmap(iconList.get(2)));
remoteViews.setImageViewBitmap(R.id.icon_4, decodeBitmap(iconList.get(3)));
remoteViews.setImageViewBitmap(R.id.icon_5, decodeBitmap(iconList.get(4)));
remoteViews.setTextViewText(R.id.temperature, prefs.getString("vTemperature", "") + "" + unit);
// remoteViews.setImageViewBitmap(R.id.temperature, getFontBitmap((prefs.getString("vTemperature", "") + "" + unit).toString(), Color.WHITE, 100));
remoteViews.setImageViewBitmap(R.id.weather_icon, image);
if (city.length() > 12) {
remoteViews.setTextViewTextSize(R.id.city, TypedValue.COMPLEX_UNIT_PX, 50f);
} else {
remoteViews.setTextViewTextSize(R.id.city, TypedValue.COMPLEX_UNIT_PX, 80f);
}
remoteViews.setTextViewText(R.id.city, city);
remoteViews.setTextViewText(R.id.mainDescription, prefs.getString("mainDescription", ""));
description = prefs.getString("description", "");
if (description.length() > 1) {
description = description.substring(0, 1).toUpperCase() + description.substring(1).toLowerCase();
}
remoteViews.setTextViewText(R.id.description, description);
}
appWidgetManager.updateAppWidget(widgetId, remoteViews);
if (timer != null) {
timer.cancel();
timer.purge();
timer = null;
}
}
}
});
}
};
timer.schedule(updateWidget, 0, 200);
}
stopSelf();
return START_NOT_STICKY;
}
and bitmap is
private Bitmap getFontBitmap( String text, int color, float fontSizeSP) {
int fontSizePX = convertDiptoPix(fontSizeSP);
int pad = (fontSizePX / 9);
Paint paint = new Paint();
Typeface typeface = Typeface.createFromAsset(getAssets(), "fonts/Clock2017R.ttf");
paint.setAntiAlias(true);
paint.setTypeface(typeface);
paint.setColor(color);
paint.setTextSize(fontSizePX);
// paint.setShadowLayer(2, 1, 1, Color.DKGRAY);
int textWidth = (int) (paint.measureText(text) + pad * 2);
int height = (int) (fontSizePX / 0.75);
Bitmap bitmap = Bitmap.createBitmap(textWidth, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
canvas.drawText(text, pad, fontSizePX, paint);
return bitmap;
}
private int convertDiptoPix( float dip) {
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dip, getResources().getDisplayMetrics());
}
When i set remoteViews.setImageBitamp i get problem loading widget error.
I tried several methods but can't get it working .Even tried Calligraphy library but i still get problem loading widget error
Note:
I don't see any error in logcat too.
So kindly help me

Related Links

Will Google Cloud Messaging service run smoothly on completion of trial period of Google cloud platform
Receiving Emails
Update the recycler view textview?
How to use weight for android:layout_marginLeft attribute android
Deserializing a complex JSON (several nested elements) with Gson
Move all the markers on the map to their updated/new current location periodically as users moves
Toolbar custom theme title/subtitle padding issue
Why is this xamarin android menu text not showing?
why is the run button grayed out in Android Studio
Disable swiping in ViewPager
xamarin.forms image appears on all devices, but not on windows10 tablet
on button click get data from each view
how to apply jobschedular below lolipop
Add search functionality in list view
Android Location “going for a walk” by itself
Providing Integers.xml for different screen densities

Categories

HOME
notepad++
eclipse
twitter-bootstrap-3
paraview
apache-spark-mllib
mstest
shiro
appcelerator
access
spring-data-mongodb
tivoli
permissions
x264
polling
webix
modal-dialog
special-characters
joomla3.0
bing-maps
performancepoint
pcl-crypto
project-intu
automatic-ref-counting
docx
mongodb-csharp
mathprog
red5
git-extensions
soci
swagger-2.0
charles
apache2.4
named-entity-recognition
epsilon
dynamically-generated
angularjs-components
spotipy
subclass
carrierwave
kudu
github3.py
nested-lists
baidu-map
batching
openproject
filesystemwatcher
odroid
metaprogramming
jvmti
dcmtk
wc
memory-mapping
stylecop
globalize
netbeans6.8
dbcontext
pair-programming
context-switch
static-cast
cmp
gameplay-kit
macaulay2
hclust
jclouds
cassia
upx
libvlc
state-restoration
jdi
cgi-bin
finalbuilder
typemock
dronekit-android
cwrsync
qtwebengine
procedural-programming
cross-join
exceldatareader
jbake
administration
metatrader5
rcaller
live555
winginx
authlogic
amslidemenu
scriptaculous
visual-studio-express
light
dtmf
script#
rolify
http-status-code-410
device-width
curb
iboutlet
correlated-subquery
mapping-by-code
kqueue
hibernateexception
saxparseexception
matlab-load
pylucene
nhprof
photolibrary
metaweblog
maven-1
folding
duplex
interop-domino
sifr3
business-model
image-capture
idatareader

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App