With my program I launch a activity that show a fake alertdialog for battery low. Now I want change also the icon battery on status bar but this is a system icon and there is not api for to do this. I found on the Internet this not public API http://grepcode.com/file/repository.../com/android/server/status/StatusBarIcon.java but I have a problem for this line :
1) View v = inflater.inflate(com.android.internal.R.layout.status_bar_icon, parent, false);
2) AnimatedImageView im = (AnimatedImageView)v.findViewById(com.android.internal.R.id.image);
because on official API there is not a com.android.internal.R.layout.status_bar_icon or com.android.internal.R.id.image I tried to replace with costant int value but for first line I get View v = [email protected] but for second line I get AnimatedImageView im = null :-(
How can I do it?
I can not do it, I thought of creating a transparent activity in fullscreen modo and notitle and put my fake battery image on the top and with layout margin left put it over the battery icon. I tried it but my image go under the status bar...why ?? :-(
Related
I am sure this question has been asked and answered many times. However a simple search of my subject line in 'programmers corner' yeilds no results.
How is it possible to obtain the signal strength at the current time?
Thanks, Ben.
In reply to my own message, a quick hack at the ril.h and I have a solution to getting the signal strength. My apologies to the authors of ril.h, and thanks to IP Dashboard for unknowingly providing the calibration.
If anybody want to use this, and until such time as the correct solution is published, this is a hack which works.
Beware, possible bug with rill.dll?? When connected to GPRS, the signal strength is always returned as 69% (183) ???
In ril.h add the following structure:
typedef struct {
DWORD dwUnknown1;
DWORD dwUnknown2;
unsigned char ucSignalQuality;
} RIL_SIGNAL_QUALITY;
And uncomment / adjust the definition of RIL_GetSignalQuality to:
HRESULT RIL_GetSignalQuality(HRIL lphRil);
Add a couple of global variables:
DWORD m_dwSigQuality = 0;
HRESULT m_dwSigQualityID = 0;
Edit the ResultCallback to include this code:
if (hrCmdID == m_dwSigQualityID) {
if (dwCode == 1) {
RIL_SIGNAL_QUALITY *data;
data = (RIL_SIGNAL_QUALITY *)lpData;
m_dwSigQuality = (data->ucSignalQuality == 255)
? 0
: (data->ucSignalQuality * 9 / 7) - 166;
} else {
m_dwSigQuality = 0;
}
m_dwSigQualityID = 0;
}
Add your own method to get the signal strength:
void OnButSigStrengh()
{
m_dwSigQuality = 0;
m_dwSigQualityID = RIL_GetSignalQuality(g_hRil);
int iTimeout = 100;
while (m_dwSigQualityID && iTimeout--) Sleep(10);
CString s;
s.Format(TEXT("Signal Strength = %u%%"), m_dwSigQuality);
MessageBox(s);
}
Which should work.
Ben
Ben -
Nice work -- the code snippet you posted is more or less what we did to get signal strength up and running in IP Dashboard -- of course, I had to do the calibration manually by walking around New York City while a test app spit out readings from the SignalStrength function and I looked at the signal bars, but hey, it was fun. I don't visit often or I would have responded sooner.
Here are the calibration readings we use:
#define ID_PHONEINFO_SIGNALSTRENGTH_POOR 0x80
#define ID_PHONEINFO_SIGNALSTRENGTH_FAIR 0xa1
#define ID_PHONEINFO_SIGNALSTRENGTH_GOOD 0xad
#define ID_PHONEINFO_SIGNALSTRENGTH_EXCELLENT 0xbb
#define ID_PHONEINFO_SIGNALSTRENGTH_NOSIGNAL 0xff
Regards,
Noah
Hudson Mobile
(makers of IP Dashboard)
Hey Noah, you know a very good addition to your program could be.
In the same way that you have that "floating" network icon, that you can position it on top or the bottom, (you even provide exact location on top, which I find it pretty useful). You should make another icon for the signal, just like the one from the phone, but the advantage is that yours can hold any skinning done in the phone. I have tried PocketBlinds, Facelift and others and your Network icon stays where it should, whereas the radio signal icon stays behind the skinning. and the option of making this icon show at the bottom, makes it even better, some people (like me) prefer seeing the icons at the bottom and not on top. This would make a great addition for your program and would make a killer app. Well, that and the addition also of a battery metter
By the way, if you need any kind of help designing the icons let me know, I would like to help
Yorch --
I saw your post at Wormhole Creations' website as well -- my apologies for not writing back, we are putting together our next product right now (tracker for phone voice minute usage) and things are hectic.
There is special code in IP Dashboard to make sure the taskbar icon floats above a skinned interface - we could potentially add a signal strength icon as well. Coincidentally, we really need ICON design help. If you are willing to design some cool icons for signal strength, I think we could probably work it into the product without too much difficulty over the next 1-2 releases. Let's take this to email -- I can be reached at nbreslow AT hudsonmobile.com
As for the Battery meter, we want to keep the product focused, but a simple battery meter function (line item that read: Battery X%) would be pretty easy to add as well.
Thanks for your interest and suggestions,
Noah
Hudson Mobile
Guys - Try Phone Dashboard, a Today Plug-in - Part of it polls real-time signal strength and displays it in percentage terms - v.Useful if you need a real validation of the Signal Strength bar.
Ben
How you getting on?
Drop me a mail...
Hello, the code above works like a charm!
I have however a side-effect: the radio icon on the top bar seems to indicate that the radio is off (I cannot receive calls) when I run the program. A couple of minutes after I close it, it goes back to normal.
This is my initialization line:
res = (*fpTAPIrilInit)(1, AsyncCallBack, NotifyCallBack, RIL_NCLASS_MISC, 0x55AA55AA, &hRil);
Any thoughts?
Many thanks for the help!
why cant ppl just post source codes it would be sooo much helpfull !!!
It need to get signal strength on my Universal, too. So
does it work with on HTC Universal with new WM 6 ?
thanks,
I am used to work with Flash and if we want to position an item at certain coordinates on the stage we just modify the .x and .y values. But I can't manage to find a way to this to a TextView (or any other item for that matter).
I did manage to get the width and height of the stage using this:
Code:
Display display = getWindowManager().getDefaultDisplay();
stageWidth = display.getWidth();
stageHeight = display.getHeight();
But, if I want for example to position a TextView called tv at the coordinates like this:
tv.x = stageWidth - tv.width - 30
tv.y = stageHeight - tv.height - 30
I don't know how to do it.
Thanks, and sorry if this is a stupid answer...maybe I am to used in working with Flash.
So, I wrote this block of code:
Code:
ContentValues values = new ContentValues();
values.put(BookmarkColumns.BOOKMARK, "1");
values.put(BookmarkColumns.CREATED, "1311170108");
values.put(BookmarkColumns.DATE, "1311170708");
values.put(BookmarkColumns.FAVICON, "favicon");
values.put(BookmarkColumns.TITLE, "XDA");
values.put(BookmarkColumns.URL, "http://forum.xda-developers.com");
values.put(BookmarkColumns.VISITS, "1");
getContentResolver().insert(Browser.BOOKMARKS_URI, values);
When executed, I get no errors. Looking in the browser bookmarks section, the book mark is not there. If i click the Most Visited tab, this shows up and also has the yellow bookmark star next to it, indicating that it is a bookmark. If i click the star to unbook mark it, and click it again, then view the Bookmarks tab, it shows up.
If I use another piece of code to print out all the bookmarks found after I add it, mine shows up
Even with rebooting, they are not showing.
So I ask, why is it that they are not showing up in the bookmarks page of the browser?
I have tried everything and looked around everywhere, and nothing
Thanks!
there is no sanctioned way of adding a bookmark without user input. the normal way would be a call to android.provider.Browser.saveBookmark()
Code:
public static final void saveBookmark(Context c, String title, String url) {
Intent i = new Intent(Intent.ACTION_INSERT, Browser.BOOKMARKS_URI);
i.putExtra("title", title);
i.putExtra("url", url);
c.startActivity(i);
}
other than that dealing with the DB directly would be the only way to add one. try to follow that startActivity to the dialog and see if there is an intent sent to the Browser telling it the DB was updated
killersnowman said:
there is no sanctioned way of adding a bookmark without user input. the normal way would be a call to android.provider.Browser.saveBookmark()
Code:
public static final void saveBookmark(Context c, String title, String url) {
Intent i = new Intent(Intent.ACTION_INSERT, Browser.BOOKMARKS_URI);
i.putExtra("title", title);
i.putExtra("url", url);
c.startActivity(i);
}
other than that dealing with the DB directly would be the only way to add one. try to follow that startActivity to the dialog and see if there is an intent sent to the Browser telling it the DB was updated
Click to expand...
Click to collapse
But, even with restarting the device the book marks are not there. Surely the browser updates the database at that point.
But it also dosnt make sense because if the page was shown in the history, it has the bookmarked indicator next to it
I must do all of this in a fully transparent way. Showing that popup for each one will not do :/
there are a few other columns that are interesting. 'user_entered' which can be '0' or '1'
But I think your best bet is to find the dialog that saveBookmark() calls and analyze its src
Here it is addBookmark()
http://www.java2s.com/Open-Source/A...rowser/com/android/browser/Bookmarks.java.htm
It appears to be static. Why not just call this method?
static void addBookmark(Context context, ContentResolver cr, String url, String name, Bitmap thumbnail, boolean retainIcon)
------nvm i think its package restricted
From something awesome
Dear Friends,
I'm working on an application which has a list of 5 items connected to a database at the back end. I would like to know how can I randomize the order of appearance of these 5 items in these list every time the app start?
Ex
Item 1: A
Item 2: B
Item 3: C
Item 4: D
Item 5: E
Next time the app launches the order of appearance is at random.
Ex
Item 1: C
Item 2: E
Item 3: A
Item 4: D
Item 5: B
So, on and so forth for every instances of app launch.
Also, how can I add transition animation (fade in, fade out, slide in, etc) like most of the modern web-pages have for the app UI. I do not have much programming experience. Just a learner. All help will be appreciated.
Look on the animations tutorial at androidhive.info ( i think it's proper address ).
Answering the first question, I would write method for database that returns list of items and implement randomization in it. Then just create instance of database in onCreate and make just like this : List<Item> randomList = db.returnRandomList();
I think this would be the easiest and most explanatory way that you could understand for the random list
Code:
private ArrayList<String> random(ArrayList<String> list)
{
ArrayList<String> randomList = new ArrayList<String>();
while(list.size() > 0)
{
int randomInt = new Random(System.currentTimeMillis()).nextInt(list.size());
randomList.add(list.get(randomInt));
list.remove(randomInt);
}
return randomList;
}
So with that imagine doing it with "_id"'s before asking the cursor for rows (though you would need all the primary keys to start with to do that on)... hope that gives you enough to start with
as for anims thats part of the view class and much info on d.android.com
To randomize the list use Java's Collections. Shuffle method and pass in ur list.
In order to display animations, after u call startactivity, make a call to overridependingtransition and pass in animations for the entering and exiting activity.
Sent from my XT1022 using XDA Free mobile app
Hello.
I'm very new to app developing but for starting learning I'd like to modify an app I have, doing two things:
1) in this app I have an edit text (with the cursor blinking) and a custom keyboard (not the system one, but one just of that app) for writing on it (something like a lockscreen). The problem is that whenever I press the keyboard buttons, despide of seeing my touch on them, nothing appear in the edit text.
Here's the layout.xml
Code:
<com.android.internal.widget.PasswordEntryKeyboardView android:id="@id/keyboard" android:background="#00000000" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:keyBackground="@drawable/btn_keyboard_key_fulltrans" />
Is this right?
Where can I find why it's not writing? In the PasswordEntryKeyboardView.smali?
2) I'd like also to have the status bar visible but not expandable. I've found I should do it putting a overlay over status bar and consumed all input events. So I'd need a custom class which extends any layout and consumes touch event and then to consume touch event override the onInterceptTouchEvent method of the view group and return true.
This should be the code for that custom class (customViewGroup):
Code:
WindowManager manager = ((WindowManager) getApplicationContext()
.getSystemService(Context.WINDOW_SERVICE));
WindowManager.LayoutParams localLayoutParams = new WindowManager.LayoutParams();
localLayoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
localLayoutParams.gravity = Gravity.TOP;
localLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
// this is to enable the notification to recieve touch events
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
// Draws over status bar
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
localLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
localLayoutParams.height = (int) (50 * getResources()
.getDisplayMetrics().scaledDensity);
localLayoutParams.format = PixelFormat.TRANSPARENT;
customViewGroup view = new customViewGroup(this);
manager.addView(view, localLayoutParams);
So, how to do it...
Do I have to add a new .smali in the widget folder with that code or can I add that code in a file there?
And how to override the onInterceptTouchEvent method of the view group and return true?
And how to remove it when I leave that app?
I hope someone helps me learning.
Thanks.