[DEV][LIBRARY][2.0.2] Android Async TaskManager - Android Software/Hacking General [Developers Only]

Android Async TaskManager
AsyncTask is a great tool, allowing one to run background tasks while interacting with the UI before, while and after. However it does come with a few issues, mostly related to the way Android act when a user flips the screen or in other ways creates a detachment of the UI. AsyncTask is not equipped to handle these circumstances.
TaskManager is an extension of AsyncTask which fixes it's issues (Based on an idea of Santiago Lezica) and on top of that, provides additional features.
Source & Documentation
https://github.com/SpazeDog/taskmanager
Features
Makes sure that UI inteaction waits until the UI is pressent
Makes sure that flipping the screen does not produce multiple instances running the same tasks
Adds a new inteaction to AsyncTask onUIReady() and onUIPause() which is invoked whenever the UI is detached and re-attached
Compatible with both native fragments and the support library
Helper methods that makes it easy to use it in both Activities and Fragments
Deviates
Like mentioned above, this is based on the idea of Santiago Lezica whom made a pretty decent example. There was however a few things that bothered me, which made me decide to build my own from scratch.
The tasks should only be handled by the Task class and not be divided between the Task and the Manager. The Managers job should only be to keep track of the UI status and then report to the Tasks whenever this changes. It is then up to the Task what action should be taken depending on the current state.
I was missing the onUIReady() and onUIPause() methods which helps deal with attachment and detachment of the UI from within each individual task. Usefull to handle things like Progress Dialogs.
Using onActivityCreated() and onDetach() in the Manager does not work properly. They execute upon screen flip, but not on application pause and resume, which is also an attachment and detachment of the UI.
It is fine to include the AsyncTask onProgressUpdate() method, but without including publishProgress(), you can't really use it for anything.
The onPreExecute() method should be managed via the pending method like the rest of the methods, otherwise you will end up with a lot of application crashes.
If one should decide to built an application for newer Android versions only, there is no reason to use the support library, so there should be support for both.
I also wanted something that could return the current object. getActivity() is fine when working in an Activity, but this should also be able to run from within fragments. So a getObject() was added.
How it works
Take a look at Santiago's blog
Code:
public class MyActivity extends Activity {
private ProgressDialog mProgressDialog;
@[URL="http://forum.xda-developers.com/member.php?u=439709"]override[/URL]
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
new Task<Context, Void, Boolean>(this, "nameOfMyAsyncLoader") {
@[URL="http://forum.xda-developers.com/member.php?u=439709"]override[/URL]
protected void onUIReady() {
((MyActivity) getObject()).mProgressDialog = ProgressDialog.show( (Activity) getActivityObject(), "", "Loading...");
}
@[URL="http://forum.xda-developers.com/member.php?u=439709"]override[/URL]
protected void doInBackground(Context... params) {
return someMethod( params[0] );
}
@[URL="http://forum.xda-developers.com/member.php?u=439709"]override[/URL]
protected void onPostExecute(Boolean result) {
((MyActivity) getObject()).mProgressDialog.dismiss();
if ( result ) {
...
} else {
...
}
}
}.execute( getApplicationContext() );
}
}
No mater if you execute this from within an Activity, Fragment or the same using the Support Library, you just parse this to the constructor. If you execute it from within a fragment, you need to make sure that you parsed a Tag Name when you added it with FragmentManager. TaskManager does not save instances of the object you parse, it just saves the information needed for it to find it again. With fragments, this means Tag Names. Without it, getObject() will return NULL on Fragments.
Download Pre-built Jar
2.0.2 (2013-06-28) (MD5: 88dbced8ebc4db9dea1b9cf12ab0da40)
[Default Mirror] SourceForge.net

Related

[Q] GPS-tracking acting weird.

Hello!
Firstly, I don’t speak english very well. But I beg your indulgence.
I have some troubles with every GPS tracking apps I’ve installed on my Omnia W (I8350). While I start the tracking and locking my phone, it’s tracking quite well.
BUT, if I want to write a SMS or something. I have to press on the Windows-button to come out to the main menu, and the GPS-tracking will stop. But the time counter continues unaffected.
I think it’s a bit weird behavior. I have testet, Endomondo, Sports Tracker, SmartRunner, Runtastic. And all of these apps acts at same way.
Is this normally? Is it the OS, which stops the GPS-device, while the app is minimized?
It's the OS, yes. In theory, an app could continue GPS tracking in the background, but since that's not officially allowed (you'd need to mess with the APIs in ways Microsoft doesn't approve of) it wouldn't be allowed into the Marketplace.
@GoodDayToDie
Do you know any working hack that will allow app continue tracking in the background? Maybe some registry changing?
If app cannot get to Marketplace, it is not problem for me. I want to create GPS tracking in background only for myself.
At the max it will work with screen lock though Endomodo doesnt support but others do. And Yes its a problem with Windows Phone API not allowing intensive tasks to run in background.
May be a custom app can do which somebody can sideload but then its for one few people.
Well, the dehydration tweak that Jaxbot found (and yes, it's a registry change) allows an app to keep running in the background. That doesn't guarantee it will actually keep tracking - the app still gets notified that it's leaving the foreground, and a "well behaved" app might stop using resources like the GPS when it gets that notification - but it makes it possible. Normally I'd direct you to my MultiTaskToggle app, which is a very simple and user-friendly way to change this value, but it doesn't work on second-gen Samsung phones at this time.
GoodDayToDie said:
Well, the dehydration tweak that Jaxbot found (and yes, it's a registry change) allows an app to keep running in the background. That doesn't guarantee it will actually keep tracking - the app still gets notified that it's leaving the foreground, and a "well behaved" app might stop using resources like the GPS when it gets that notification - but it makes it possible. Normally I'd direct you to my MultiTaskToggle app, which is a very simple and user-friendly way to change this value, but it doesn't work on second-gen Samsung phones at this time.
Click to expand...
Click to collapse
I am pretty sure that just keeps it in memory, but not actually running. I downloaded the source code to see what it does and manually applied the registry change. It allows fast resume from any app, even if it was not recompiled for Mango. This is good for apps, such as Angry Birds, which would otherwise dehydrate, and need to restart. But, when using it, you can see that if you launch a bird, and then switch out. Wait a while. Then switch back to it. You can see that the launched bird has not moved since switching to a different app. It is possible that the app is suspending by responding to the fact that it is being pushed into the background.
Most apps that display time, or a timer that counts are not actually counting. What they do to display it get an initial time value when the timer starts. Then they get the time and subtract the initial time from it. So, an app that seems to count seconds, even when in the background is really just successfully get the current time and subtracting the original time before suspension. They may use a timer control to schedule the frequency that this calculation is made.
To verify, it would be good to test with a simple program that does something like:
Code:
[FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]namespace[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] TestCountApp
{
[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff] public[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]partial[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]class[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]Form1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] : [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]Form
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] {
[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff] public[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] Form1()
{
InitializeComponent();
}
[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff] int[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] i = 0;
[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff] private[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] btnStart_Click([/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]object[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] sender, [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]EventArgs[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] e)
{
timer1.Start();
}
[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff] private[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] timer1_Tick([/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]object[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] sender, [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]EventArgs[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] e)
{
[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff] int[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] val = 0;
[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff] try
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] {
val = [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2].Parse(tbText.Text.ToString());
}
[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff] catch[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] ([/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]Exception[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] ex)
{
}
i++;
tbText.Text = i.ToString();
}
[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff] private[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] btnStop_Click([/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]object[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] sender, [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]EventArgs[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] e)
{
timer1.Stop();
}
}
}
of course the timer class might automatically suspend for Windows Phone.
So, a simple for loop might be better.
Code:
[FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]namespace[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] TestCountApp
{
[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff] public[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]partial[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]class[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]Form1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] : [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]Form
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] {
[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff] public[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] Form1()
{
InitializeComponent();
}
[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2][/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff] private[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] btnStart_Click([/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]object[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] sender, [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]EventArgs[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] e)
{
[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff] for[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] ([/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] i = 0; i < 60; i++)
{
tbText.Text = i.ToString();
System.Threading.[/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]Thread[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2].Sleep(1000);
}
}
[/SIZE][/FONT][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] }
}
If it is background processing, you should see 59, after returning to the app. It will remain blank until the end.
[/SIZE][/SIZE][/FONT][/FONT][/SIZE][/FONT][/SIZE][/FONT]
GoodDayToDie said:
Well, the dehydration tweak that Jaxbot found (and yes, it's a registry change) allows an app to keep running in the background. That doesn't guarantee it will actually keep tracking - the app still gets notified that it's leaving the foreground, and a "well behaved" app might stop using resources like the GPS when it gets that notification - but it makes it possible. Normally I'd direct you to my MultiTaskToggle app, which is a very simple and user-friendly way to change this value, but it doesn't work on second-gen Samsung phones at this time.
Click to expand...
Click to collapse
Unfortunatelly it doesn't help, because OS is suspending app executing. OS is just keeping app in memory.
Anyway I can use background task in debug build with LaunchForTest method that will allow me execute background code as often I want. However background task cannot access fresh GPS data. It can only used cached data which is refreshed every 15 minutes. Is any way to force GPS to refresh it's data when using GPS from background agent?
OK, in reverse order:
@Mendoza32: You are quite incorrect; the change to the registry I was talking about actually causes the OS to *not* suspend apps. It can cause problems for some of them. In Mango, an app is *always* kept in memory when it's backgrounded. Apps that weren't recompiled for Mango can't take advantage of this and will do a full rehydrate anyhow, but they don't hve to (using a process listing, you can see that the suspended processes are still in memory). However, even with the tweak, a few things are cut off, like audio (and possibly GPS). See my response to JVH3 for more info...
As for a background agent, there's no official way. I think if you abuse one of the background audio decoder agent classes, you might be able to make an agent that runs in the background and can access the GPS. I haven't tried, though, and there's no chance of it getting into the Marketplace.
@JVH3: If you read the really old threads on the subject, you'll see that the app really does keep running in the background. For example, you can create an app that will pop a MessageBox (which always goes to the foreground) after 10 seconds, start it and immediately hit the Windows key. A few seconds later, you'll get the message box. More practically, you can use this hack to do things like run the WebServer app (any version) in the background, and browse it in the foreground on the phone's IE (pointing to 127.0.0.1). This would be impossible if the app were suspened, obviously...
As for Angry Birds, the game is in fact pausing the XNA update/render loop when notified that it's going into the background. In theory, this allows it to save the entire current game state, including the flying bird, such that when you resume the app (from dehydration, or so it thinks), that bird is exactly where it was and you've lost no progress. I suspect it is actually doing this. On the other hand, a game like Puzzle Quest 2 (which is rather poorly behaved regarding dehydration) quite obviously does *not* suspend the update/render loop. It's a turn-based game, so there is no gameplay problem, but there are certain real-time graphical effects that, when you "resume" the game, will all render simultaneously. Additionally, the phone will get quite warm and use a lot of battery (and other games will run slowly) because Puzzle Quest 2 still eating CPU and GPU time in the background.
GoodDayToDie said:
As for a background agent, there's no official way. I think if you abuse one of the background audio decoder agent classes, you might be able to make an agent that runs in the background and can access the GPS. I haven't tried, though, and there's no chance of it getting into the Marketplace.
Click to expand...
Click to collapse
I do not want put app in Marketplace. It's only for me
GoodDayToDie said:
@JVH3: If you read the really old threads on the subject, you'll see that the app really does keep running in the background. For example, you can create an app that will pop a MessageBox (which always goes to the foreground) after 10 seconds, start it and immediately hit the Windows key. A few seconds later, you'll get the message box.
Click to expand...
Click to collapse
Could you provide some sample code how to display this message box when app is in background? I tried this but without any luck. Maybe I'm missing something.
Did you have the no-suspend/dehydrate tweak enabled? It should be simple (event handler for a button or something:
Thread.Sleep(10000); MessageBox.Show("Alert from background app");
Thank you very much GoodDayToDie. I see how it works now. As long as GUI thread is blocked, then background threads keep working (also the GPS). One drawback is that I cannot go back to my app. It just keep displaying "Resuming...", but this is because GUI thread is blocked.
@GoodDayToDie
I was all wrong. Blocking GUI thread doesn't help in anything, because OS is killing app.
Please take a look at this sample code:
Code:
using System;
using System.Diagnostics;
using System.IO.IsolatedStorage;
using System.Threading;
using System.Windows;
using Microsoft.Phone.Controls;
namespace PhoneAppBackgroundTest
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(MainPage_Loaded);
}
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
this.Loaded -= this.MainPage_Loaded;
this.DisplayLastUpdateTime();
}
private void buttonBackgroundThread_Click(object sender, RoutedEventArgs e)
{
ThreadPool.QueueUserWorkItem((s) =>
{
while (true)
{
this.UpdateLastUpdateTime();
Debug.WriteLine(DateTime.Now.ToString());
Thread.Sleep(1000);
}
});
}
private void buttonBlockGUIThread_Click(object sender, RoutedEventArgs e)
{
while (true)
{
Thread.Sleep(1000);
}
}
private string lastUpdateKey = "lastUpdate";
private void DisplayLastUpdateTime()
{
string value;
if (IsolatedStorageSettings.ApplicationSettings.TryGetValue<string>(this.lastUpdateKey, out value))
{
MessageBox.Show("last update time: " + value);
}
}
private void UpdateLastUpdateTime()
{
if (IsolatedStorageSettings.ApplicationSettings.Contains(this.lastUpdateKey))
IsolatedStorageSettings.ApplicationSettings.Remove(this.lastUpdateKey);
IsolatedStorageSettings.ApplicationSettings.Add(this.lastUpdateKey, DateTime.Now.ToString());
IsolatedStorageSettings.ApplicationSettings.Save();
}
}
}
Button "buttonBackgroundThread" is starting new background thread which updates settings value and display current time to Output window. When you press this button you will see in Ouput, that current time is displaying each second. When you use window key, then current time is no longer displaying in Output. So the thread gets suspended. When you go back to app it start to work again.
When you press on button "buttonBackgroundThread" and "buttonBlockGUIThread" and use window key, you will see that current time is keep displaying in Output. This works when you have debugger attached. If you follow this scenario on device without attached degubber you will see that app is getting killed by OS. To prove that app is displaing last update time at start.
So my question is: how to get managed threads keep running while app is in background? I'm attaching sample project, so you can test on your device and see that managed thread get suspended when you use window key.
Is maybe some way to use native threads that won't get suspended? I see your WebServer can run while app is in background. However you used native listeners.

Link contact adress to Nokia Drive

I use my7rom on my Omnia 7.
Is there anyway to link a contacts adress to Nokia Drive instead of Maps (stock wp7 app). It would be much more practical if Nokia Drive opened a navigation session instead.
Anyone up for the challenge? A reg-tweak perhaps?
// Manneman
Skickat från Windows Phone 7.8
There's two parts here. The first is identifying the correct "filetype" or URI scheme that is used for navigation. That shouldn't be too hard; a little digging in HKCU should reveal it. We already know about ones like callto: and http: and I'm actually (slowly) working on an app to allow people to easily change them. The second part is finding the correct command to load that address or route in the Nokia Maps app. If the app supports pinning routes or destinations to Start, this is probably possible. If not, it may not be possible in the app. Most apps aren't designed to accept command-line parameters, so even if you make them the default handler for a given filetype or URI scheme, they ignore the value you send them and just start as though launched from Start.
GoodDayToDie said:
If the app supports pinning routes or destinations to Start, this is probably possible.
Click to expand...
Click to collapse
Nokia Drive supports pinning to start so it should be possible. Unfortunately I can't tell you exact command line parameters 'cause my Lumia 900 still "in jail"
Let me see if I have a copy of the Nokia Drive XAP handy. I'll need to decompile it to figure out the correct parameters for launching it with the intent of navigating to a specific location. Note also that this might not be possible directly - for example, the app might store a list of locations internally, and the tiles only provide an index into that list rather than providing the location directly - but that just requires another layer of indirection.
In that case, you create an app that gets registered as the navigation handler, and in response to a navigation request, it writes the requested location into the Nokia Drive app and then chain-launches Nokia Drive with the index of the newly written location. That's just an example of one way that this might go wrong, but overall, the odds are actually pretty good. Obviously, all of this will require, at a minimum, write access to the HKCR hive in the registry.
Ah, guys! You are so kind helping me out. I´m really certain alot of members in the WP7 section would love for this to work!
// Manneman
GoodDayToDie said:
I'll need to decompile it to figure out the correct parameters for launching it with the intent of navigating to a specific location
Click to expand...
Click to collapse
GoodDayToDie, you may try much simpler solution. Just create assembly (dll) to show startup parameters in message box, and replace main Nokia Drive dll (but pin some location first).
That's actually harder than it sounds; even if the app is sideloaded (which would mean I already have the DLL) my fake would have to mimic the internal structure of the real app to a degree (namespaces, class names, default actions, etc.). That's not hard, but decompiling .NET is pretty trivial too.
AFAIR, Nokia Drive is obfuscated (but I'm not 100% sure). Also, you don't need to duplicate all names and structures; just a stuff mentioned in WMAppManifest (I hope so). BTW, I forgot: I still have unlocked handset; if I'll found time, will try today later.
Update: tried but without of luck What I did:
- installed Nokia Drive first;
- downloaded map and pinned current location;
- created fake app with same app guid and namespace name ("Drive"), and performed app update (that operation completely override whole solution but NokiaDrive tile still pinned to the start screen);
- tried a few different page names (_default.xaml, QuickStartPage.xaml, DestinationPickerPage.xaml, FavoritesPage.xaml) with code
Code:
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
MessageBox.Show("Hello from fake dll");
if (e.NavigationMode == System.Windows.Navigation.NavigationMode.New)
{
string[] keys = NavigationContext.QueryString.Keys.ToArray();
string[] values = NavigationContext.QueryString.Values.ToArray();
string param = "";
for (int i = 0; i < keys.Length; i++)
{
param += keys[i] + " -> " + values[i] + "\n";
}
MessageBox.Show("parameters: " + param);
}
}
But result always the same: app doesn't start from the pinned tile
Update 2: Finally, I did it
The trick is:
- do the same as I've described above (you should have pinned tile from ND);
- add following code to the start page:
Code:
public MainPage()
{
InitializeComponent();
var appTile = ShellTile.ActiveTiles.Last();
if (appTile != null)
{
//MessageBox.Show(appTile.NavigationUri.OriginalString);
EmailComposeTask emailTask = new EmailComposeTask();
emailTask.Subject = "NokiaDrive pinned parameters";
emailTask.Body = appTile.NavigationUri.OriginalString;
try
{
emailTask.Show();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK);
}
}
}
- run app as usual (not from tile);
We allset - all params are sent to our email (I'm too lazy to manually copy all stuff )
Here we are (start parameters; bold values are changed for privacy reason ):
/_default?destination.name=200 SomeName Street&destination.latitude=49.5255378801376&destination.longitude=-72.4296837244183&destination.address.street=SomeName Street&destination.address.houseno=200&destination.address.district=&destination.address.county=&destination.address.city=SomeCity&destination.address.state=&destination.address.country=USA&destination.address.postcode=05720&destination.hashCode=371767793destination.address.statecode=MA&pinnedFrom=Favorites
P.S. Just found: Navigon also has ability to pin address to the start tile So, if you find the way to modify map protocol (or how it calls), it will be a really nice hack! BTW, could you remind me: do we have ability to launch assembly by GUID (on the full-/policy-unlocked phones)? If "yes", it's possible to write a real nice "proxy" app to handle map requests
I don't know about launching assemblies directly, but it's certainly possible to launch apps by GUID. It doesn't even require anything more than dev-unlock in fact (although of course you can only launch apps that you could launch anyhow). So yes, a proxy app is totally possible. That's actually what I'm working on (started as a project to make a Kindle ebook file loader, that would pur .mobi/.prc file in the Kindle app's folder and then launch the app).
GoodDayToDie, could you please, take a look to the registry, for default map protocol handler and figure out how to change that stuff? I'm pretty busy these days (and probably will be extremely busy couple of next months) but we can cooperate and create this app...
I'll investigate, but you're not the only one busy. If you've noticed a lack of software from me recently, it's due to the nex job I got some months back; I love it, but it leaves me with a lot less time for phone hacking if I want to still have a life outside of that.
With that said, this actually ties into the work I'm already doing with things like filetype handling and default browser switching. I can send you my HKCRlib, at a minimum; it's a library that simplifies interacting with HKCR, including creating backups of important values when they change, and reverting the backups.
GoodDayToDie, truly, I'm not much interested (personally) in that hack 'cause I can't use it for my Lumia 900. So it's only for the community needs but because of lack of time, I believe, we may put it on hold.

Non android java java files

I have android central and no one has responded so i figure i would try here.
I hava a college class for "intro to java"
And would you know it we have java files that i would LOVE TO EDIT ON MY TABLET
I have found java code viewers and allow some tiny amount of editing but NO ONE ALLOWS me to run code.
Example:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner kb= new Scanner(System.in);
double page;
double pheight;
double pweight;
double bmr;
int activity;
double burned;
String a1="Sedentary, little or no exercise, desk job.";
String a2="Lightly active (light exercise 1 to 3 times a week).";
String a3="Moderately active (Exercise 3 to 5 times a week.";
String a4="Very active (Exercise 6 to 7 times a week).";
String a5="Extra active (Exercises two times a day. Includes running marathon etc).";
System.out.println("What is your age?");
page = kb.nextDouble();
System.out.println("What is your Height (in inches)?");
pheight = kb.nextDouble();
System.out.println("How much do you weight(in pounds)?");
pweight = kb.nextDouble();
bmr= 66 + 6.2*pweight + 152.4*pheight - 6.8*page;
System.out.println("Please enter the correct numbe rthat goes with our life style.");
System.out.println(a1+"|1.2|");
System.out.println(a2+"|1.375|");
System.out.println(a3+"|1.55|)");
System.out.println(a4+"|1.725|");
System.out.println(a5+"|1.9|");
activity =kb.nextInt();
burned = bmr*activity;
System.out.println("Your age is :"+ page);
System.out.println("Your height is :"+pheight +"in.");
System.out.println("You weight is :"+pweight+"lb.");
if (activity== 1.2)
{
System.out.println("The activity factor -"+a1);
}
if (activity== 1.375)
{
System.out.println("The activity factor -"+a2);
}
if (activity== 1.55)
{
System.out.println("The activity factor -"+a3);
}
if (activity== 1.725)
{
System.out.println("The activity factor -"+a4);
}
if (activity== 1.9)
{
System.out.println("The activity factor -"+a5);
}
System.out.println("The bmr is-"+ bmr);
System.out.println("You burned "+ burned);
}
}
No app that i can find can you this simple program and thus making my college class EXTREMELY hard
Please some one help
Sent from my GT-N8013 using xda app-developers app
Your Java instructor will surely have told y'all about compilation to bytecode with the JDK, running bytecode in the JVM, etc. There is no Java Virtual Machine (not to be confused with the Dalvik virtual machine) for Android, at least that I know of.
Your best options for running Java code "on" your tablet are:
SSHing to a server where you can compile your Java programs on the command line, presumably through some linked storage enabling you to do your editing on Android.
Editing your Java programs on your tablet and then using a website like http://ideone.com to run your code.
Honestly, though, this is going to be much more cumbersome than working on a laptop or desktop.
EDIT: See also this thread, especially the last post: http://forum.xda-developers.com/showthread.php?t=1452666
If you're comfortable with working in a terminal, I highly recommend TerminalIDE. It's what I used for the first term of Java programming in college last year (in fact, I think it was the only app that allowed Java compilation at the time).
There's also AIDE which is great for developing Android apps, but probably not so much for following along in class, since for even basic GUI stuff, you'd have to figure out how to do it the Android way (which is very different from swing), and I'm not sure how it'd handle console apps (maybe fine, but then you'd have to deal with switching windows to a terminal emulator, such as TerminalIDE, anyway... probably best to just use TerminalIDE from the start).

[APP][DEV][16/10-1.0][29/11-2.0-BETA] BuildBox [Rom-Kitchen/Ota][4.0+]

BuildBox
The main intend of this application is to provide an easy to use, but powerful way to serve updates and addons for developers to their users, but it doesn't stop there, it also can be used by the user itself as batch flashing tool for files on the internal or external sd (openrecoveryscript supporting recovery and root are prerequisite).
But please keep in mind, this is still beta stage, so far all is stable, but the code itself needs refactoring still and some additional features i want to add are still missing, also the included images are far from being great.
Why i built this?
Most of the current alternatives public available seemed not as powerful as they could be, because of the fact that they are closed source i started to build something similar myself from scratch.
What does it serve?
Tabbed UI
Nested lists within the tabs (in theory infinite levels of nesting [but for usability i wouldn't recommend more than 5 steps])
Detail views with many optional fields, like description, changelog, developers, images,...
Completely remotly configured content using json
Optional Md5 verfification
Download queue
Changelist of added, removed, updated & downgraded items
Sorting of download queue by drag & drop
Concurrent downloads to achieve full use of bandwidth (configurable amount)
Backup and restore of download queues
Support of every host with direct link capabilities
Support of hosts with up to 5 redirects (note: still direct link redirects, download webpages don't get handled)
Internal retry or resume (if supported by the server) functionality to avoid broken downloads because of unstable connections (up to 5 retries)
Direct install of apks
"External" link handling
Direct flash capabilities (if an openrecoveryscript supporting recovery is installed)
Adding of zips from storage to the queue
Backup/wipe options before flashing
Queue filter to only flash Successful/Done (Successful=downloaded+md5sum correct, Done=donwloaded+no md5sum provided) downloads (md5mismatches can optional be taken in as well)
OTA updates
Configurable interval for update check
Update version filter to avoid multiple notifications per version
New version check on startup
Image recycling and scaling (if an image is used more than once [identified by it's url], it will be downloaded only once and simply reused, also it will be scaled to the fitting size of the view to take as less bandwidth and ram as possible)
more to come...
Why json and not xml?
Xml is pretty good for local configuration, but json is the way to go when it comes to remote content.
It is highly mutable, lightweight and easy to use. Also the possibility for typos and errors is much less than with xml, because simple brackets and key value pairs are used instead of tags.
Last but not least, json files are about half of the sice of xml files if the same content is provided and the possible use of a webservice to provide it is pretty simple.
How to use as rom developer?
The application uses build.prop properties to configure rom update url, content url, rom version and default download directoy.
For update and content url there are also string resources present (to be able to publish the app to the play store to provide the rom itself with it e.g.).
All of this properties are optional (if they are not provided default values are taken).
Build.prop sample
Code:
buildbox.downloaddir=/storage/sdcard0/TestRom
buildbox.version=1.0.3c1
buildbox.updateurl=http://www.test.com/Rom.json
buildbox.contenturl=http://www.test.com/Content.json
Common content description
At the content json all root items will be shown as tabs, everything inside them are listitems.
Every item containing another list of items must contain the "children" property.
Every item containing a detail item must contain the "detail" property instead.
Key Value pair description
Common properties:
Code:
"title": "some value" -> this is the title of the chapter/listitem/detailitem (depends on the item type) (if the detailview doesn't contain a title property it will be taken from it's parent)
"device": "GT-I9300" -> this value is used to filter content which is only available for specific devices, it is compared with the ro.product.model build.prop property (because it is almost untouched by moders)
"thumbnailurl": "some url" -> this is the thumbnail shown at a listitem, it will be loaded asynchronous
"children": [ { some child items } ] -> this property is used to identify that this item contains another list
"detail" : { some detail properties } -> this property is used to identify this item as last item before a detail view is shown
Additional detail properties:
Code:
"version": "some version" -> sets the version (must not be inside the detail item, can also be inside his parent)
"description": "some text" -> sets the description (basic html notation can be used for formating)
"type": "zip" -> possible values are zip, apk, web, other, this will override the basic behaviour of parsing the mime type and will directly threaten it as the provided type [if external is used and the url property is given the url property will be taken for opening instead of the first webpages link])
"md5": "a md5sum" -> sets the md5sum of the package (only used for download verification if provided)
"url": "some url" -> the url where the item can be downloaded from
"webpages": [ "some url",
"some other url",
....
] -> if no url provided the first item of this array will be taken as external link, but in common provided as hyperlinks on the detail view to support pages
"images": [ "some url",
"some other url",
....
] -> used to show screenshots,... within the detail view (also loaded asynchronous)
"changelog": [ "a change",
"another change",
......
] -> to show a changelog, also supports html notation
"developers": [ { "some developer name": "" },
{ "another developer name": "some donation or profile page" },
......
] -> used to show the realted developers, if a donation or profile url is given the name will be shown as hyperlink, if it's empty as plain text
Server File Samples
Content.json:
Code:
[{
"title":"Apps",
"device":"GT-I9300", [B]//optional, compared with the ro.product.model build.prop property, to shows items for specific devices only (can be put at every level inside the nesting of an item, except inside a detail item)[/B]
"thumbnailurl":"http://ms-team-hd.tectas.eu/images/Apps.png",
"children": [
{"title":"4.2 Camera/Gallery",
"detail":
{"description":"Aosp Camera from android 4.2 with sphere photo feature",
"url":"http://ms-team-hd.tectas.eu/download.php?file=Addons/Apps/4.2Camera_App.zip",
"md5":"10cfc3983156d42a9dbafe7bc8265257"
}
},
{"title":"4.2 Clock",
"detail": {
"url":"http://ms-team-hd.tectas.eu/download.php?file=Addons/Apps/4.2-Clock_App.zip",
"md5":"8334f1ed2ec79efbe4199a86fda7ee58"
}
},
{"title":"4.2 Keyboard",
"detail": {
"url":"http://ms-team-hd.tectas.eu/download.php?file=Addons/Apps/4.2Keyboard_App.zip",
"md5":"de0d134795217b21ccbeb0f1b7dd3cdd"
}
}
]
},{
"title":"Bloat",
"thumbnailurl":"http://ms-team-hd.tectas.eu/images/Bloat.png",
"children": [
{"title":"Calculator",
"detail":
{"webpages": [
"http://ms-team-hd.tectas.eu/download.php?file=Addons/Bloat/Calculator_App.zip"
],
"md5":"6adbc0077f7aac1f25ed584cff5c4d0e"
}
},
{"title":"SPlanner",
"detail": {
"url":"http://ms-team-hd.tectas.eu/download.php?file=Addons/Bloat/SPlanner_App.zip",
"md5":"2949654d704a59cdbd17b7227b825d37"
}
}
]
},{
"title":"Themes",
"thumbnailurl":"http://ms-team-hd.tectas.eu/images/Themes.png",
"children": [{
"title":"Battery Mods",
"thumbnailurl":"http://ms-team-hd.tectas.eu/images/Battery.png",
"children": [
{"title":"Blue Battery",
"thumbnailurl":"http://ms-team-hd.tectas.eu/Addons/Battery/Images/BlueBattery.png",
"detail":
{"description":"Stock battery icon in blue made by raubkatze",
"url":"http://ms-team-hd.tectas.eu/download.php?file=Addons/Battery/BlueBattery_Mod.zip",
"md5":"f1bc5f90dc284df34fb0c8d2d9044330"
}
},
{"title":"Blue Battery Percentage",
"thumbnailurl":"http://ms-team-hd.tectas.eu/Addons/Battery/Images/BlueBatteryPercentage.png",
"detail": {
"description":"Stock battery icon in blue with percentage made by thisiskindacrap",
"url":"http://ms-team-hd.tectas.eu/download.php?file=Addons/Battery/BlueBatteryPercentage_Mod.zip"
}
},
{"title":"Blue Battery Circle",
"thumbnailurl":"http://ms-team-hd.tectas.eu/Addons/Battery/Images/BlueCircle.png",
"detail": {
"description":"Blue circle battericon with percentage in the center made by raubkatze",
"url":"http://ms-team-hd.tectas.eu/download.php?file=Addons/Battery/BlueCircle_Mod.apk", //apk extension will be read and the install dialog will pop up
"md5":"c43c2734846ced3db5ed5987d5647bae"
}
}
]
},{
"title":"Framework Themes",
"thumbnailurl":"http://ms-team-hd.tectas.eu/images/Apps.png",
"children": [{
"title":"Elegant Theme",
"detail": {
"describtion":"Eye-Candy Theme by ThilinaC",
"url":"https://docs.google.com/uc?export=download&confirm=no_antivirus&id=0B8AYcerB14i3YVBmTEM4b0tzOVU",
"md5":"5e0d5a4578f01cfa8b357e79193f070b"
}
},{
"title":"MS Team Blackbean Theme",
"detail": {
"description":"Black and white theme made by alvin551",
"url":"https://docs.google.com/uc?export=download&confirm=no_antivirus&id=0B8AYcerB14i3VmUwWTVKdWZ6UWM",
"md5":"93442e1fb4197e554ebdb1c8ff9c52a1"
}
},{
"title":"MS Team HD Theme",
"detail": {
"description":"Holo style theme. The theme is not originally created by MS Team HD, it uses parts of many other themes. All credits to the creators of the themes this is based on.",
"url":"http://ms-team-hd.tectas.eu/download.php?file=Addons/Themes/MS-Team-HD_Theme.zip",
"md5":"15eec7c80db7acbaccd939f827d806e9"
}
}
]
},{
"title":"Multiwondow Themes",
"children": [{
"title":"Multiwindow Blackbean",
"detail": {
"description":"Multiwindow theme made by alvin551",
"url":"http://ms-team-hd.tectas.eu/download.php?file=Addons/Themes/Flashbar-BlackBean_Mod.zip",
"md5":"4be1c0da1d77121de9627dd2570fee00"
}
},{
"title":"Multiwindow Black Glass",
"detail": {
"url":"http://ms-team-hd.tectas.eu/download.php?file=Addons/Themes/Flashbar-Glass-Black_Mod.zip",
"md5":"b8befba0558fdd954c8c73563761565c"
}
},{
"title":"Multiwindow Blue Glass",
"detail": {
"url":"http://ms-team-hd.tectas.eu/download.php?file=Addons/Themes/Flashbar-Glass-Blue_Mod.zip",
"md5":"d98c0cd04fc3240b372a78911a09c865"
}
}
]
}
]
}
]
Rom.json (which contains basically nothing less than a detailitem, means all optional properties used here can also be used at detail items within the Content.json):
Code:
{
"title": "MS Team HD", [B]//optional if parent item is present[/B]
"version": "9.0.1", [B]//optional[/B]
"description": "test", [B]//optional[/B]
"type": "zip", [B]//optional[/B]
"md5": "75a3a73d3ac941cc83f90dd80d000477", [B]//optional[/B]
"url": "http://ms-team-hd.tectas.eu/download.php?file=Rom/MS-Team-HD_9.0.1_XXEMA2.7z", [B]//optional[/B]
"webpages" : [
"http://forum.xda-developers.com/showthread.php?t=1886332",
"http://ms-team-hd.tectas.eu"
], [B]//optional[/B]
"images": [
"http://ms-team-hd.tectas.eu/Winscp-Screenshot.png"
], [B] //optional[/B]
"changelog": [
"change1",
"change2"
], [B]//optional[/B]
"developers": [
{ "tester": "" },
{ "tester2": "http://test" }
] [B]//optional[/B]
}
NOTE: if you simply want to take and alter this examples, remove the comments (everthing starting with //) they are not supported within json.
Is it open source?
Yes, the java packges are licensed under lgpl, which means they can be integrated within every other application without publishing the source, only if the code inside the packages themself is altered the code has to be published. I have chosen this approach in the open sense of android, everyone is allowed to fork/clone my github repository and do whatever he likes with the code, i just want possible fixes or enhancements to be public available for everyone (also fell free to send me pull requests if you like), that's at least my view of what open source means, all should work together to make the best out of something, if they like to, otherwise, take what is already served or find someone able to do the needed changes.
Wait, two repositories? Why the hell...
Well, it's pretty simple, the library part already includes everything which is needed to get the work done, except of one thing, the main activity. It "only" includes an generic abstract activity which serves the fitting implementations to get it's job done without taking into account how the main activity is build up (be it tabed, with lists or whatever). To make your own UI set up on this activity it serves abstract methods you have to implement to handle e.g. viewing the download queue, updating it while downloading,...
But that's as well only a nice to have and should give you more possibilities if you want to use them, if your fine with the tabed UI I built, simply take the application repository, override the resources you like (if you want to) and your already done. I also splitted it up for easier maintenance, the library part is generic and if something needs to be done another way you're able to by simply deriving from the given interfaces or classes itself within your application, the application itself is always specific (even when the differences can be close to none), so i would have to integrate the changes of the library part allover again to the different branches, if it would be included in one single repository, that way all is detached and much easier to maintain.
Common Information
The source itself can be found here (Application), here (library) and here (gradle base for android studio), feel free to send me pull requests
The generic apk is also available at the play store (NOTE: don't flash files from it unless you use a GT-I9300, also note the broken downloads are intended to show the different states).
Changelog
The full list of commits can be viewed here (application) and here (library)
1.0:
Changelist support (listing of updated, added, removed and downgraded packages at startup)
no additional file or work needed, except the present version property at items which should be able to show as downgraded or updated, everything else is done by the app itself
0.9.7.1:
Fixed Index out of bounds crash
Fixed 2 nullpointer crashes
Started to add changelist of content support (changelist of added or removed items from the remoterepository)
0.9.7:
Improved install logic
Improved build.prop property reading
Fixed wrong finished state at service while downloads still processing
0.9.6:
Fixed showing of restore menu item directly after backup;
Fixed caching/loading of download queue onStop/onRestart;
Fixed removing of cached queue onDestroy;
Fixed crash at add file dialog if it is closed before choosing an activity;
Fixed wrong "all finished respond" of service while still processing;
0.9.5:
Completely revised the structure of buildbox (is now splitted into 2 repositories, one for the library [includes the whole logic, main views,...] and one for the implementation of the main activity and for resource overriding [MainActivity, TabAdapter, ...)
Added device filter property (can be applied at every level except at the detail items) (uses the ro.product.model build.prop property for comparsion)
Many fixes and enhancements
0.9.3:
Fixed adding files from storage
Fixed crash at startup without internet connection available
0.9.2:
Apk handling fix
Recovery script fix
0.9.1:
Revised Install procedure for apks (thx to lowveld for the hint)
Fixed root shell command execution (sry)
small additional changes
​
XDA:DevDB Information
BuildBox, a App for the No Device
Contributors
Tectas, http://forum.xda-developers.com/member.php?u=4189659
Version Information
Status: Stable
Current Stable Version: 1.0
Stable Release Date: 2013-10-17
Current Beta Version: 2.0
Beta Release Date: 2013-11-29
Created 2013-11-26
Last Updated 2013-11-29
Reserved
Beta Changelog (To get automatic updates of the beta via play store, join the BuildBox Community and use the opt-in link)
The full list of commits of the test branch can be viewed here (application/2.0-dev branch) and here (library/2.0-dev branch)
2.0:
OnDemand loding of json items (means not the full list must be provided as one file, it can contain urls to other json files which get loaded on demand)
complete overhaul of UI - dropped tabs, g+ dropdown instead, sidebar not present yet, but in the lane already
Hello.!
i m due to make a rom next month, was thinking where to start, guess u solved the problem
anu.cool said:
Hello.!
i m due to make a rom next month, was thinking where to start, guess u solved the problem
Click to expand...
Click to collapse
Happy i could help you decide^^
If you have any thoughts for enhancement, just tell
Beta Added
Like said, 2.0 is BETA, it's not properly working yet (backstack doesn't work completely yet) and not everything is present what should yet (sidebar), the basic features from 1.0 are still functional though.
Beta Changelog
The full list of commits can be viewed here (application) and here (library)
2.0:
OnDemand loding of json items (means not the full list must be provided as one file/webserviceresponse, it can contain urls to other json files which get loaded on demand)
complete overhaul of UI - dropped tabs, g+ dropdown instead, sidebar not present yet, but in the lane already
New beta is ready to download, backstack is fixed.
Tectas said:
New beta is ready to download, backstack is fixed.
Click to expand...
Click to collapse
How do we get on the beta channel for this app?
Sent from my SGH-I337 using Tapatalk
Sc4ryB3ar said:
How do we get on the beta channel for this app?
Sent from my SGH-I337 using Tapatalk
Click to expand...
Click to collapse
Just switch to the downloads tab, there is the beta download as well.
Gesendet von meinem GT-I9300 mit Tapatalk
BuildBox community added with beta testing over play store opt in.
BuildBox Community

[App][Code project][5.0+]Rom Control app for devs

Hello ya'all,
This is gonna be a long op, I dunno where to start...
Sooooo... a while ago a friend (@tdunham) asked if we could share a settings app we made for our rom(s) (future rom(s).... as we are lazy bums). Since we mostly aimlessly wander around xda and help other devs instead of releasing our stuff, we figured... what the hell, we might as well make it into a source code project in a java-unexpirienced-dev format. So here we go!
About the project:
This app has a main function of coordinating content resolver entries between user end (your rom control app) and mods end (when you use content resolver to reitrieve settings storage database entry keys in various modded system apps).
Basically, you create a preference item, such as switch preference f.e, and when the user switches it, an entry is being overwritten in Settings.System. From there, your modded apps, according to your mods, can read the value and do some stuff...
Needless to say that this app requires, among many other things, your ability to mod system apps to use content resolver. If this doesn't mean anything to you, you're in a wrong place.
If you wish to learn more about modding smali using content resolver, you need to first get introduced to 2 amazing threads:
1. Creating and Understanding smali mods by @Goldie - if you are not fluent in that thread, you will not need this app.
2. Galaxy s5 unified mods and guides thread by @tdunham - not all guides there are using content resolver, but lately more and more are. In any case it's a great place to ask questions, learn and contribute.
Nuff said about modding, now to the project
Project characteristics:
The project is a source code project. Meaning we are not providing an application and you will not be using it by decompiling it with apktool. There are so many reasons for that that I don't know where to start. Mainly - it's bad enough samsung has made hackers out of all of us and we need to decompile and backdoor their system apps to mod them. What we can provide in source code - we will. We strongly believe in the freedom of code and we share it unconditionally (almost).
Now what is that "almost? part? Simple... You do NOT need to credit us in any of your work, you do NOT need to thank us, you do NOT need to ask permission to use this project in your rom, you also do NOT need to donate to us (you also can't, we don't have a donate button). YOU DO NEED TO RESPECT THE FREEDOM OF CODE! That means that this code is given to you under the GNU GPL (General Public License). You can review it fully here.
The most relevant part to our discussion is as following:
...For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights...
Click to expand...
Click to collapse
That being said, the only thing that is required of you is that you keep sharing the code. We are not going to run around xda and "police" people using the code and not providing source. We rely on your word, that by agreeing to use the open source, you will keep it public and provide your sources as well for others to use. This VOIDS xda rule number 12, stating that each dev owns their work. Becasue the rule also states that work that is provided by a lisence that negates exclusivity, is therefore not exclusive. Any work based on this code is not to be held exclusive. And if another developer wants to use an app you built based on this code, you have an obligation to provide your sources and to keep those updated to most recent version of the app you release in order to be compliant.
Thread rules and disclaimaers:
The code is 100% original and written by us (myself and @wuby986) for this specific project. All the classes imported from public open source repositories are annotated with original developer signature and our modifications are annotated and dated as well.
To answer most asked question so far - we don't know how it is different from a custom settings app by ficeto. We have never used it in our roms and we have nerver seen it's code (neither have you). Both apps share the same idea of integrating preferences into settings db using content resolver. You are free to use any app you like. We are not saying which app is better or worse. This is seriously not a competition.
This project requires extensive knowledge in android development. As mentioned above, if you don't know how to mod system, this app is of no use to you. We will not be answering questions about smali mods.
This project requires basic knowledge in operating android studio. You need to have it installed and operational in order to work with the code. You need to have android sdk and all the support libraries updated.
This project requires SOME coding expirience or AT LEAST an open mind to getting a crash course. You will not be required to do heavy java lifting to use this app, but it would help if you knew alittle bit.
We cannot teach you how to use android studio, debug problems related to it and so on. We will provide basic instructions as to how to add items to the navigation drawer list, how to add preference fragments with ease, we will explain the idea of out code and different preferences to you. Beyond that - it's on you. We cannot and will not teach you to be a programmer. If you want to know more - the web is wide and google is your friend.
We cannot debug your code problems. This thread is for development discussion related to the project itself. If you need some requests, questions regarding exsisting code, remarks, improvements, you're more than welcome to join a github project and commit your code for everyone's benefit.
Nuff said about rules, moving forward:
Project sources:
Github source for the Rom Control application is here
Github source for the template to add preference fragment for this specific app is here
Initial instructions:
Download and install Android Studio and android sdk for your platform. Make sure all are updated
Go to the preference fragment repository and download the master as zip. Extract the zip contents into /your android adt directory/android-studio/plugins/android/lib/templates/other/
Reopen android studio
File > New > Project from Version Control > Git
The git repository is https://github.com/daxgirl/CustomSettingsForDevs.git
Specify your parent directory and directory to contain the project (will be suggested by studio)
Clone from git
Done you have the project on your pc. Wait for it to sync and build gradle.
The next couple of posts will explain extensively how to operate the app and create customize it to your rom's needs.
XDA:DevDB Information
[App][Code project][5.0+]Rom Control app for devs, App for all devices (see above for details)
Contributors
daxgirl, wuby986
Version Information
Status: Testing
Current Stable Version: 1.0
Created 2015-06-30
Last Updated 2016-04-12
Basic info and app structure
Basic info and app structure:
This application is Navigation Drawer application material design style. It uses app cpmpat in order to use the pager adapter. This can make theming alittle bit tricky, but we provided 2 themes for now which you can modify in styles.
Navigation drawer opens from the left and it contains for now example of navigation items list. For now we have 4 preference fragments and the last items is to set theme. You can add or remove fragments as you wish. The process will be fully explained.
The fragments in the main view container are being replaced based on a position of clicked item in the navigation drawer list. Remember (we will get back to it again), positions in any array begin from 0. That means that for now we have 0,1,2,3,4 items in the arrays that construct the navigation items list. When we add one, we will need to add a title and an icon (both in corresponding positions) and also add our new fragment to a special method which makes the selected items to show specific fragment. We will discuss it at lenght.
For now application contains only preference fragments. If you feel confident and know what you're doing, you can add all kinda fragments and navigation items (even more activities). We concentrate here on preference fragments, because this is the essence.
Each navigation fragment has a java class which extends PreferenceFragment and an xml file inside res/xml folder, where the preferences exist for each fragment. Once launched for the first time, each fragment will create a shared preferences file inside our "home" directory. Our directory is in /data/data/com.wubydax.romcontrol/. There you will find several files and dirs. One of them is called shared_prefs. Inside it each fragment will host it's preference xml file. The name of this file will be identical (by our design) to the name of the xml file for that fragment in /res/xml folder. Once the fragment displayed for the first time, the shared preferences file for it is created and being populated by the default values you set. We will explain later which preferences must have defaultValue set and which preferences MUST NOT.
If you open the java class for any PreferenceFragment, f.e. UIPrefsFragment.java, you will see that the code is very small. That is because we wanted to make things easier for you and we created a class called HandlePreferenceFragment.java, which manages all the work of the fragments.
When you create a new Preference Fragment using a template for android studio we provided, The fragment and it's xml file are created for you automatically. All you will have to do is add it to the item selector in the navigation drawer, of course give it a name and an icon, and you can gop ahead and populate the xml file with preferences. You will not need to touch java anymore if you don't want to.
We have the usual preferences that you know of, like SwitchPreference, CheckboxPreference, ListPreference etc, and we have our own "special" preferences to make your life easier. Those are IntentDialogPreference (to choose an app and write it's intent to the database for you to use in your mods to open apps), FilePreference (to control some booleans by creating and deleting file), we have 2 special kinds of PreferenceScreens: one for running shell scripts and one for creating intent to open apps from the control app. Those preferences will have special kind of keys, which we will demonstrate. You will not need to flash your scripts when flashing your rom. All your scripts will be managed in the assets folder and copied on run time to our home directory and executed from there. You don't need to worry about permissions, all is taken care of. Just place your scripts inside the assets folder before you compile the sources. Sae thing with opening apps as intents, all you need to do is put a main activity full name as PreferenceScreen key. Everything else is taken care of, including displaying icon. The preference will not show at all if the user doen's have an app installed. So no crashes upon clicking on non existing intents. They will just vanish from the list.
The preference files inside the project on github contains BOGUS preferences to use as an example. We will go over all of them (most contained inside first fragment - UIPrefsFragment). They are all active. But they should not trigger any mod, as you should not have those keys in your database. You can see f.e. that preference fragment "Useful apps" has like 5 preferences for app intent. some of them have bogus intent. They will not display when you run your app. They are therer to demonstrate that if the app doesn't exist, you should not worry about FC of Rom Control. It takes care of itself.
The first time the app boots it asks for root permissions. If the device is not rooted or permissions not granted, the app will never run. You all run rooted and modded roms, this app is not for stock. If you wish to disable this function, we will provide that option.
Reboot menu - on the right upper corner of the action bar you will see a reboot icon. Clicking it will show a display of 5 reboot actions: reboot, hotboot, reboot recovery, reboot download, reboot systemui. Youc an access those easily no matter what fragment you're in. Clicking outside of them or clicking back button will make the menu disappear. clicking on one of them will result in immidiate reboot function. Those are root related finctions. We can make them no root dependant once you all use an app in your /system/priv-app. Which, btw, is where we recommend it goes.
How does it work?
For the first time an app is opened (or any time an ap is opened), there is a special method inside HandlePreferenceFragment that is called initAllKeys();. This method goes over all the preferences contained inside the shared preferences for that fragment. One by one it checks their key name, checks if they are of type boolean (true or false), of tipe integer (number) or of type string (words). Then it checks what preference they belong to. It checks if the key for that preference exists in your settings storage database, if it does not - it creates all keys. If the key exists in the database but is different from what the app has - it replaces the one in the app preferences with what you have in your system. That is why it's important for most preferences to set the defaultValue that you wish to be the default, beucase the first time the app launches, it will create all the keys in the system database. once the process is done(you will not see or feel it), your preferences are yours to control. Once a user clicks on Checkbox, if it's selected (isChecked), it writes 1 to the key for that preference inside the Settings.System. and vice versa. Any change in the preferences is being registered immidiately. So your mods can be updated (provided you have observers, of course, or else you might need to reboot apps, just like you always did). Inside the class HandlePreferenceFragment there is a method updateDatabase. it is being called from a method that "wacthes"/"listens" to any change in preference.
That is, basically, all. This is how it works. Everything else is cosmetics made for your convinience and mostly based on your requests. F.e. running shell scripts, FilePreference, App picker preferences was requested by other developers to be included so we had to find a way to build in. Now you can all enjoy. Any further requests are welcome.
Overall structure in studio:
One you have opened the project in studio, you have the following structure tree on your left. Make sure you have chosen the "project" tab (far left edge of the screen) to see it:
Inside the libs folder we have the roottools jar made by the amazing @Stericson and the next folder that is of interest is the src/main. This is where the app as you know it (from apktool) is hosted. You can see inside the res folder all our resources.
If you need to change the icon for the app you need to place it inside mipmap folders. It's called ic_launcher.png. For nice app icons generator visit here . Inside the values-21 folder there is the styles.xml file that you need to edit if you want to change theme colors. Nice site for coherent material palette is here and google documentation is here.
In the main drawables folder you will find those:
As you can see there are two images there that are relevant to you: header_image and header_image_light (for both themes). Thopse are the header images for the navigation drawer. You can replace them with your own. The reference to them is inside /layout/fragment_navigation_drawer.xml as you can see here:
.
Here it's used as an attribute. You can read more about using attrs in android docs. Just replace the images and keep the names.
Inside of the resolution dependant drawable folders you can find the images for the items in the navigation drawer:
Here you can replace, move and add your own. Good resources for icons are: here and here and you can find many more out there.
Inside the assets folder we have a folder named scripts. It's important the name remains "scripts".
It's used in java code to copy the assets on runtime to our home dir. Inside scripts you put your shell scripts that you wish to run using the script running method. scripts have to be called with .sh in the end. When you create a PreferenceScreen that needs to run scripts, you give it a key like this: android:key = "script#nameofourscript". You do not add the .sh in the key. Look at the example inside ui_prefs.xml in PreferenceScreen with key android:key = "script#test". This runs the script that is currently found in assets. which basically writes into a file on your sdcard. Here you can put scripts as complex a you like. The code checkes for the exit code of the script. as long as it is 0, it will print a toast "executed successfully" upon clicking your preference. To try it run the app on your phone and click on a preference screen with summary "Click see what happens". Make sure your scripts are well formed and test them before including. Remember that you're under sudo. Linux shell will execute anything under sudo without asking.
Inside the /res/xml folder are our preference xml files. This will be your main playground. In those files we will be adding the preference items to appear in each of your fragments.
And finally for the java classes:
Here is where all the work is being done in real time. If you don't have expirience, you won't have to go there besides when you need to add the more nav drawer items.
Adding a new fragment and navigation drawer list item:
1. Provided you read the OP instructions and cloned the Rom Control Preference Fragment template repository into /your android adt directory/android-studio/plugins/android/lib/templates/other/, you need to restart android studio and we are ready to go.
2. Right click on the main java package of out application and navigate to New > Fragment > Fragment (6thGear Preference Fragment) like you can see on the picture below:
Once you click on adding the fragment the foloowing window will open:
As you can see the initial names are: for fragment - BlankFragment and for xml blank_prefs. You can change it as you like. BUT! Leave the word Fragment. Once you change the FIRST part of the fragment name, the first part of the prefs file name will be changed automatically. See the img below:
So we have chosen to create a new fragment called PowerMenuFragent and below that we have the preference xml name. the name is automatically generated as you put in your class name for the fragment. The java naming convention states that a class must begin with capital letter and all meaningful words in class name must also begin with capital letter. The xml name generator will split the word Fragment from your class name and make the other words into xml legal name form separated by under score and will add _prefs in the end. So it becomes power_menu_prefs.xml.
Click "finish" and you have a new fragment class and a new xml file for it inside /xml folder. The fragment will look like this:
You don't need to edit it. It's done in template. It instantiates the class called HandlePreferenceFragment and refers to it's main methods. For more infor you can read my annotations in the HPF class.
Your new xml file is now empty and contains an empty preference screen like so:
We will populate it with preferences later.
Now we need to make this new fragment REACHABLE for user. So we need to add an item to the navigation drawer sections. Let's do that:
1. Open /values/strings.xml and find an array of strings. we will add our new item name in a place we want. In this case I will add it after the Framework section (in blue):
Code:
<string-array name="nav_drawer_items">
<item>SystemUI Mods</item>
<item>Phone Mods</item>
<item>Framework and General</item>
[COLOR="Blue"][B]<item>Power Menu</item>[/B][/COLOR]
<item>Useful Apps</item>
<item>Set Theme</item>
</string-array>
2. Now you will need a new icon to appear to the left of the section name in nav drawer. You can add your own icon at this point. It's a good practice to add images for all resolutions. But who are we kidding? You're making a rom for one device. So to remind you, s4, note3, s5 are xxhdpi and note4, s6 are xxxhdpi. I will use existing icon called ic_reboot.png for this section.
3. Now we need to get our hands dirty and go into java alittle. Open MainViewActivity and find the following method. This method is well annotated for your use. So you can refer to it every time you add an item for reference of how-to. Observe the new blue item:
Code:
//Creates a list of NavItem objects to retrieve elements for the Navigation Drawer list of choices
public List<NavItem> getMenu() {
List<com.wubydax.romcontrol.NavItem> items = new ArrayList<>();
/*String array of item names is located in strings.xml under name nav_drawer_items
* If you wish to add more items you need to:
* 1. Add item to nav_drawer_items array
* 2. Add a valid material design icon/image to dir drawable
* 3. Add that image ID to the integer array below (int[] mIcons
* 4. The POSITION of your new item in the string array MUST CORRESPOND to the position of your image in the integer array mIcons
* 5. Create new PreferenceFragment or your own fragment or a method that you would like to invoke when a user clicks on your new item
* 6. Continue down this file to a method onNavigationDrawerItemSelected(int position) - next method
* 7. Add an action based on position. Remember that positions in array are beginning at 0. So if your item is number 6 in array, it will have a position of 5... etc
* 8. You need to add same items to the int array in NavigationDrawerFragment, which has the same method*/
String[] mTitles = getResources().getStringArray(R.array.nav_drawer_items);
int[] mIcons =
{R.drawable.ic_ui_mods,
R.drawable.ic_phone_mods,
R.drawable.ic_general_framework,
[B][COLOR="Blue"]R.drawable.ic_reboot,[/COLOR][/B]
R.drawable.ic_apps,
R.drawable.ic_settings};
for (int i = 0; i < mTitles.length && i < mIcons.length; i++) {
com.wubydax.romcontrol.NavItem current = new com.wubydax.romcontrol.NavItem();
current.setText(mTitles[i]);
current.setDrawable(mIcons[i]);
items.add(current);
}
return items;
}
As you can see I added a line R.drawable.ic_reboot. What is it? This is an equivalent to public id in smali. It is in fact an integer. So it appears inside integer array called mIcons. Our respurces in android are referenced by capital R. then we have the resource type, in this case - drawable, and then the item name (without extension). Note the order of the id in the array, I added my string after the framework string. So I also add the id for the drawable after the id of the framework drawable. This is vital to understand, as the list is being populated on runtime based on items positions. Items in an array are separated by comma.
4. Now open NavigationDrawerFragment class and you will find the same method there. Please add the same id in the same way there. You MUST do so in both classes every time.
5. Now we go back to the MainViewActivity and we find the following method. it will be right after the getMenu() method we just edited. The method is called onNavigationDrawerItemSelected(int position). This method is responsible for performing action based on which navigation drawer item is clicked by a user. Positions are the positions of items in the List of our objects. So we have so far 6 items out arrays (strings and drawable id integers). That means their positions are 0,1,2,3,4,5 respectively. Look at the method as it appears in the original code:
Code:
@Override
public void onNavigationDrawerItemSelected(int position) {
/* update the main content by replacing fragments
* See more detailed instructions on the thread or in annotations to the previous method*/
setTitle(getMenu().get(position).getText());
switch (position) {
case 0:
getFragmentManager().beginTransaction().addToBackStack(null).replace(R.id.container, new UIPrefsFragment()).commitAllowingStateLoss();
break;
case 1:
getFragmentManager().beginTransaction().addToBackStack(null).replace(R.id.container, new PhonePrefsFragment()).commitAllowingStateLoss();
break;
case 2:
getFragmentManager().beginTransaction().addToBackStack(null).replace(R.id.container, new FrameworksGeneralFragment()).commitAllowingStateLoss();
break;
case 3:
getFragmentManager().beginTransaction().addToBackStack(null).replace(R.id.container, new AppLinksFragment()).commitAllowingStateLoss();
break;
case 4:
showThemeChooserDialog();
break;
}
}
Here we have switch case based on position of an item. This is the same as saying: if the position of an item is 0, perform this action, else, if the position is 1, perform that action and so on. Only in this case we say: compiler, switch cases based on integer - in case 0: do something, in case 1: do something else. So we need to add an item after the framework section. Framework section has position of 2 (it's item number 3). So now we add our new fragment like so:
Code:
@Override
public void onNavigationDrawerItemSelected(int position) {
/* update the main content by replacing fragments
* See more detailed instructions on the thread or in annotations to the previous method*/
setTitle(getMenu().get(position).getText());
switch (position) {
case 0:
getFragmentManager().beginTransaction().addToBackStack(null).replace(R.id.container, new UIPrefsFragment()).commitAllowingStateLoss();
break;
case 1:
getFragmentManager().beginTransaction().addToBackStack(null).replace(R.id.container, new PhonePrefsFragment()).commitAllowingStateLoss();
break;
case 2:
getFragmentManager().beginTransaction().addToBackStack(null).replace(R.id.container, new FrameworksGeneralFragment()).commitAllowingStateLoss();
break;
[COLOR="blue"][B]case 3:
getFragmentManager().beginTransaction().addToBackStack(null).replace(R.id.container, new PowerMenuFragment()).commitAllowingStateLoss();
break;[/B][/COLOR]
case [COLOR="blue"][B]4[/B][/COLOR]:
getFragmentManager().beginTransaction().addToBackStack(null).replace(R.id.container, new AppLinksFragment()).commitAllowingStateLoss();
break;
case [COLOR="blue"][B]5[/B][/COLOR]:
showThemeChooserDialog();
break;
}
}
Note how the new case is now number 3 and the positions of the following cases need to be increased.
Now we can run our app and and there is our new section item:
That's it for this post. Post #3 we will talk about different preference kinds we have and how to use them.
Till then...
To be continued.....​
Handling different kinds of preferences:
Now we roll with populating our preference fragments. Each preference fragment is unique for your needs, depends on your use, your modded apps and categories. All we do, as mentioned above, is provide you with preferences to communicate with your modded system apps using ContentResolver class.
For each preference I will explain:
Does it write preferences into shared preferences? and if it does...
What kind of object it writes to shared preferences of our app?
What kind of value we then write into SettingsSystem database?
What kind of key it uses and why?
SwitchPreference/CheckboxPreference:
Images:
You MUST provide defaultValue for ANY switch preference you create
It writes boolean (true or false) into the shared preferences
We copy it as integer (1 or 0) into the Settings.System database
It mush have a unique key, none of existent in databse. It must be the same key as you use in your mod for that function. F.e. statusbar_clock_visibility. Clock can be either visible or invisible. So switch preference will serve us good here. Also will checkbox preference. In your mod when you retrieve and integer using ContentResolver you specify the default value (if the key is not found). You have to specify the same default value here. If in smaly it was 0x1,. then in the app it must be android:defaultValue = "true". YOU MUST SPECIFY DEFAULT!
In preference xml inside your empty PreferenceScreen claws, you add this:
Code:
<SwitchPreference
android:defaultValue="true"
android:key="clock_visibility"
android:summaryOff="Clock is hidden"
android:summaryOn="Clock is visible"
android:title="Set Clock Visibility" />
Code:
<CheckBoxPreference
android:defaultValue="false"
android:key="brightness_visibility"
android:summaryOff="Brightness slider hidden"
android:summaryOn="Brightness slider is visible"
android:title="Notification Brightness Visibility" />
This is all you need. The key will work automatically. The first time the user runs your app it will look for that key in the database, if it finds it, it will copy the value into our app and the switch will be set accordingly, if it does not find it, it will copy the defaultvalue of your preference to the database.
Of course the proper way of using strings for title and summary is by using string resources. In android studio you can create strings resources after you have typed the string. F.e. click on one of the strings, like for title, and on your keyboard press alt+enter. You will be given an option to extract string resource. That is all up to you. If your app is only in english, you don't really need to do that.
ListPreference:
Usually you would create list preference by specifying <ListPreference..../>. We had added some functionality to native android preferences for List and EditText. So we have our own classes that extend those preferences. So when we create a list preference we use our own class, so the preference looks like this:
Code:
<com.wubydax.romcontrol.prefs.MyListPreference
android:defaultValue="2"
android:entries="@array/clock_position_entries"
android:entryValues="@array/clock_position_values"
android:key="any_clock_position"
android:title="Status Bar Clock Position" />
Once you open < in studio and start typing com..... it will give you the options of preferences existing in our app. Just choose the one you need and it will create the name for it. Don't worry if you mistype, it will not compile.
List preference in android persists string. That means that it writes object of string type into the shared preferences. You need to create 2 string arrays for each list preference. One for Entries - what is displayed in the dialog as single choice items for user. and One is for entryValues (what is being written into the preferences). You can from your mod read them as integers or strings using content resolver. f.e., if your values are 200, 300, 400, android will persist them as strings. But when you restrieve them from database in your systemui smali mod, f.e., you can call either getInt (to get them as integers) or getString to get them as strings. Of course strings array like bread, milk, cookies cannot be retrieved as integer. But a string 200 can be either.
When you retrieve a default value in your smali mod, you retrieve f.e. 200. so YOU NEED TO SET 200 as defaultValue. Or in the above case, it's 2. YOU MUST SPECIFY THE DEFAULT STRING!
You do not specify summary for this preference, we take care of it in code. like so:
EditTextPreference:
Code:
Code:
<com.wubydax.romcontrol.prefs.MyEditTextPreference
android:defaultValue="simpletext"
android:key="carrier_text"
android:title="Set Custom Carrier Text" />
This preference also persists string. It also writes string into the database. You retrieve it only as string. Because you can't control what user types. You don't want your modded systemui to crash because a user inputted "bread" and you are trying to read it as integer.
YOU MUST SPECIFY THE DEFAULT STRING for EditTextPreference.
ColorPickerPreference:
Writes and integer into the sharedpreferences and we retrieve integer into the database.
Color integers are special. I will not go into how and why. I have created a utility helper app for devs for this purpose. The app's main function is to convert hex string to integers or to reverse smali hex string. You can find an apk and explanations how to use it here.
Remember, YOU MUST-MUST-MUST SPECIFY defaultValue for ColorPicker in our app!!! and YOU MUST USE ACTUAL INTEGERS to do so properly. Just trust us on that. It's no biggie. You use our app for hex converter to both create your default smali hex value and to create an integer for this app.
The code for ColorPickerPreference:
Code:
<com.wubydax.romcontrol.prefs.ColorPickerPreference
alphaSlider="true"
android:defaultValue="-16777215"
android:key="clock_color"
android:title="Choose Clock Color" />
As you can see this android:defaultValue="-16777215" is an actual integer for color black. You get it by using our app. You put 000000 into the first text field and click the button. The integer that you get is -16777215. We also have color preview available. It's a very useful tool. Use it and you can never go wrong with neither integers nor smali inverse hex values for your default color.
Now note the special attribute called "alphaSlider" in the code. This is a boolean type. By default it's false. Meaning you can create color picker preference with or withour transparency option.
SeekBarPreference - the SLIDER:
Writes integer of the slideer progress into the database. The moment your finger has stopped tracking the bar, an integer is being registered into the sharedpreference and then being retrieved into the databasse.
Code:
<com.wubydax.romcontrol.prefs.SeekBarPreference
min="0"
unitsRight="Kb/s"
android:defaultValue="10"
android:key="network_traffic_autohide_threshold"
android:max="100"
android:title="Autohide Threshold" />
YOU MUST SET DEFAULT VALUE!!!! IN INTEGER!
You can specify special values such as unitsRight, like "%" or "Kb/s" and so on. You can specify the min and the max value. You probably better not specify the summary. But you can if you want.
IntentDialogPreference - App Chooser:
Code:
<com.wubydax.romcontrol.prefs.IntentDialogPreference
includeSearch="true"
setSeparatorString="\##"
android:key="choosen_app_gear"
android:title="Choose App" />
This is a very special preference kind. It was created by request from @rompnit. They use intents from database to open apps in certain mods. You will have to ask them on @tdunham thread how and when they use it. We created this preference from scratch specifically for them. This is a completely custom kind of android preference. It displays a dialog of all your LAUNCHABLE apps (apps that have default launch intent that can be retrieved by using PackageManager method getLaunchIntentForPackage. In other words - all apps that appear in your launcher will appear on the dialog.
What happens when you click on an app? What is being written into preferences is a special kind of string. The srting might look like this: com.android.settings/com.android.settings.Settings or it might look like this com.android.settings##com.android.settings.Settings... this is what you need to create basic intent. You need package name and activity name. What separates them is up to you. You will need to split them in your smali mod into package name and activity name to create intent. We have created 2 special attributes for this preference:
1. setSeparatorString =this is what will separate the package name from the class name. The default (if you don't specify) is "/". Remember that if you use chars that must be escaped in xml, f.e. like hash(#), you need to escfape them by backslash, like so setSeparatorString = "\##".
2. includeSearch - this is a boolean type of attribute. It is false by default. If you specify true, the search field will appear on the dialog above the apps list, allowing your users to search for an app by name inside the list adapter. We also included a list alphabetical indexer. So it's up to you if it's necessary.
Once the app is chosen, the summary for the preference is set to the app name and the icon on the right side will be the app icon.
Your database will contain now the basic component for the intent. What you do with it in your smali is up to you.
DO NOT SET DEFAULT VALUE FOR THIS PREFERENCE!!!
FilePreference:
This is very special kind of preference requested by @tdunham. What is does it creates and deletes file with a certain name in our home files dir. It is located at /data/data/com.wubydax.romcontrol/files
Code:
<com.wubydax.romcontrol.prefs.FilePreference
android:key=[COLOR="red"]"testfile"[/COLOR]
android:summaryOff="File doesn't exist"
android:summaryOn="File exists"
android:title="Test File Preference" />
The reason this is used by some devs, apparently, is when you need to mod smali file, which originates in a class that does not take context as parameter. Without context you cannot call the ContentResolver, so you cannot retrieve from the database. So what you can do instead is create a boolean condition based on existence or non existence of a certain file. File class does not require context. All it needs is to be instantiated as object and be given a string as path. For exampple:
Code:
[COLOR="Green"]File[/COLOR] [COLOR="Blue"]file[/COLOR] = new [COLOR="green"]File[/COLOR]("[COLOR="Purple"]/data/data/com.wubydax.romcontrol/testfile[/COLOR]");
means that object file of class File is a file located at /data/data/com.wubydax.romcontrol/ and called "testfile". In java class File you have a method (boolean) which is called "exists". So a condition can be made like this:
Code:
if(file.exists){
int i = 1;
} else {
i = 0;
}
So you can create a boolean method that will return 0 or 1 based on existence of the file at certain location.
This is the idea behind this preference.
The key for this preference is THE NAME OF THE FILE.
YOU DO NOT SPECIFY THE DEFAULT!!!
The preference looks like switch preference. But it acts differently. Youc an specify summaryOn and Off as you need. It does not write into database. It just creates and deletes the file.
Script executing PreferenceScreen:
As entioned above you can create PreferenceScreen which will execute shell scripts upon click. Example:
Code:
<PreferenceScreen
android:key=[COLOR="Red"]"script#test"[/COLOR]
android:summary="Click see what happens"
android:title="New Preference Screen" />
Note the key format. It has to begin with script#! The part after the hash (#) is the name of the script you wish to execute, in this case the script is test.sh which you can find in the source you pulled inside assets folder..
Where are the scripts??? You put them inside assets folder (see post #2). You name your scripts f.e. test.sh script (has to end with .sh). But you do not add the .sh extension to the string (we do that in code).
Every time your app launches it checks for scripts in the assets folder. It wants to make sure all the scripts ar being copied to our home dir. Inside files folder there we create a folder called scripts. All your scripts will be automatically copied there from assets, given permission 0755 and ready to be executed.
Wgen a user clicks on a Script Executing PreferenceScreen, the app looks if a script with that name exists in our files dir. If it does, it attemts to execute it. I have explained in post #2. We also check just in case that the script is executable. There is native java method to do that. So if you or your user just add a script to the scripts folder in home directory and forgot to make it 0755, we do that for you in java with this method:
Code:
if (script.exists()) {
[COLOR="Blue"][B]boolean isChmoded = script.canExecute() ? true : false;
if (!isChmoded) {
script.setExecutable(true);
}[/B][/COLOR]
Command command = new Command(0, pathToScript) {
@Override
public void commandCompleted(int id, int exitcode) {
super.commandCompleted(id, exitcode);
if (exitcode != 0) {
Toast.makeText(c, String.valueOf(exitcode), Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(c, "Executed Successfully", Toast.LENGTH_SHORT).show();
}
}
};
try {
RootTools.getShell(true).add(command);
} catch (IOException e) {
e.printStackTrace();
} catch (TimeoutException e) {
e.printStackTrace();
} catch (RootDeniedException e) {
e.printStackTrace();
}
}
Make suer your scripts are of valid shell format, test them separately before you put them in the app. Be careful, all the scripts are being executed under sudo. Means anything you write shall be done. Do not make mistakes in your script. Adding su to your scripts is not necessary. We execute them as root anyway.
So...
Create a shell script and test it on your device
Place it inside the assets folder of your app
Call it f.e. killbill.sh
Create a PreferenceScreen entry and givie it a key android:key = "script#killbill"
Compile the app
Clicking on that preference should execute killbill.sh which will now be foind in /data/data/com.wibydax.romcontrol/files/scripts/killbill.sh and have permissions 0755.
DO NOT SET DEFAULT FOR PreferenceScreen EVER!!!
Intent opening Preference Screen:
Code:
<PreferenceScreen
android:key=[COLOR="Red"]"com.wubydax.gearreboot.RebootActivity"[/COLOR]
android:summary="Opens TWSwipe app to help you choose a different swipe activity"
android:title="Reset TWSwipe Action" />
This is a regular preference screen, so it would seem, but it has a special function. Usually, in order to open an intent with PreferenceScreen, you need to specify a whole lot of intent rules, like action, target class, target package and so on. We have made your life easy. If you want to link to an app from your rom control application, all you need to do is to specify the activity you wish to run as a key to this preference.
You are not allowed to use "." in any other preference key. If you use "." the app will read it as possible intent. If it cannot resolve it, it will make it disappear from the list.
This kind of preference is fully automated. Once the app reads the key, it does all the work for you, it sets the icon for the preference as the app icon, it creates a viable intent.
If the user doesn't have an app that you link to installed, the app will never appear in the preferences. So the user can never click on it. Because otherwise it would give FC to the app.
Nested PreferenceScreen:
If you include regular preference screen, you never need to set a key. Preference screen that envelops the items inside of it will always lead to a nested preference screen that has some included preferences. and so on. We have a loop running through your entire preference tree and detecting all your preference screen and differentiating them by their abilities (being script executing, being intents and so on).
Nested Preference Screen would look like this:
Code:
[COLOR="Red"]<PreferenceScreen
android:summary="New Preference screen"
android:title="New Preference Screen">[/COLOR] [COLOR="Green"]<-- Start of nested preference screen[/COLOR]
<PreferenceCategory android:title="new category" />
<CheckBoxPreference
android:key="text_checkbox"
android:title="Checkbox" />
<SwitchPreference
android:key="test_switch"
android:title="Switch" />
[COLOR="Red"]</PreferenceScreen>[/COLOR] [COLOR="Green"]<-- End of nested preference screen[/COLOR]
Inside of it you can have more preferences and more preference screens.
PreferenceCategory:
Preference category is an enveloping kinda preference. It is different in color and appearence then the rest. It makes sub-portions of preference screen look separate from each other and easier to identify. F.e.:
Code:
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
[COLOR="Red"] <PreferenceCategory android:title="Status Bar Mods">[/COLOR] [COLOR="Green"]<-- start of preference category[/COLOR]
<SwitchPreference
android:defaultValue="true"
android:key="clock_visibility"
android:summaryOff="Clock is hidden"
android:summaryOn="Clock is visible"
android:title="Set Clock Visibility" />
<CheckBoxPreference
android:defaultValue="false"
android:key="brightness_visibility"
android:summaryOff="Brightness slider hidden"
android:summaryOn="Brightness slider is visible"
android:title="Notification Brightness Visibility" />
<com.wubydax.romcontrol.prefs.MyListPreference
android:defaultValue="2"
android:entries="@array/clock_position_entries"
android:entryValues="@array/clock_position_values"
android:key="any_clock_position"
android:title="Status Bar Clock Position" />
<com.wubydax.romcontrol.prefs.MyEditTextPreference
android:defaultValue="simpletext"
android:key="carrier_text"
android:title="Set Custom Carrier Text"
/>
<com.wubydax.romcontrol.prefs.ColorPickerPreference
alphaSlider="true"
android:defaultValue="-16777215"
android:key="clock_color"
android:title="Choose Clock Color" />
<PreferenceScreen
android:key="script#test"
android:summary="Click see what happens"
android:title="New Preference Screen" />
<com.wubydax.romcontrol.prefs.SeekBarPreference
min="0"
unitsRight="Kb/s"
android:defaultValue="10"
android:icon="@null"
android:key="network_traffic_autohide_threshold"
android:max="100"
android:title="Autohide Threshold" />
<PreferenceScreen
android:summary="New Preference screen"
android:title="New Preference Screen">
<PreferenceCategory android:title="new category" />
<CheckBoxPreference
android:key="text_checkbox"
android:title="Checkbox" />
<SwitchPreference
android:key="test_switch"
android:title="Switch" />
</PreferenceScreen>
<com.wubydax.romcontrol.prefs.IntentDialogPreference
includeSearch="true"
setSeparatorString="\##"
android:key="choosen_app_gear"
android:title="Choose App" />
<com.wubydax.romcontrol.prefs.FilePreference
android:key="testfile"
android:summaryOff="File doesn't exist"
android:summaryOn="File exists"
android:title="Test File Preference" />
[COLOR="red"]</PreferenceCategory>[/COLOR] [COLOR="Green"]<-- end of PreferenceCategory[/COLOR]
</PreferenceScreen>
This is it for now, more per demand and need. Have fun!​
General tips and tricks
Some tips and tricks
Running app and debugging:
Android studio provides you with built in logcat. Not only that you can debug the app you're working on, you can debug any app you're modding too. Just need to specify the filter for the logcat and the package name. Dig in and you will find some cool features.
You need to have unknown souces enabled and usb debugging enabled to run your compiled app directly on your device.
1. You can install and run this app as user app. It does not need to be system app. For now no features require it. You can of course include it as system app in your rom. We recommend pulling the base.apk from data folder and pushing to /system/priv-app
2. You do not need USB cable to debug and run your app from studio. There is anifty app I am using. You can download it here https://play.google.com/store/apps/details?id=com.ttxapps.wifiadb&hl=en. All you need to do is open the command line on your pc and type adb connect <ip number of your phone in the network>:5555. The app will provide you with an IP number.
Now studio will recognize your device as USB debugging device even though it's not connected with usb cable. I just hate cables.......
Including key specific functions:
For now all our work is done automatically for us. You click a preference and the work is done. But what if you have a key that you want to do alittle more with than just write into database? I will give you an example.
We have a SwitchPreference in our app that enables/disables call recording. That mod requires restart of InCallUI.apk. Now you can of course restart it by creating a Script Running PreferenceScreen item called Reboot InCallUI and it will be fine. That's what you have been doing so far. But let me show you what you can do now that you own your source code.
We have two ways to kill that app. Silently (without user knowing - very cool) or informing the user. Let me show you how it would be done.
Let's say you create a preference for call recording:
Code:
<[COLOR="red"]SwitchPreference[/COLOR]
android:defaultValue="true"
android:key="[COLOR="Red"]toggle_call_recording[/COLOR]"
android:summaryOff="Call recording is disabled"
android:summaryOn="Call recording is enabled"
android:title="Enable/Disable Call Recording" />
The two things we need to know is the key and the class instance of preference - which is SwitchPreference.
Let us go to the java class HandlePreferenceFragments and find a method called public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key){}}. In android studio you can search through class by pressing ctrl+f.
In that method we have switch by the preference class name (INSTANCE). So we have this case:
Code:
case "SwitchPreference":
SwitchPreference s = (SwitchPreference) pf.findPreference(key);
s.setChecked(sharedPreferences.getBoolean(key, true));
break;
What this means is: if the preference is of kind SwitchPreference, when the preference is changes, do something..... So.... let us do something with our SPECIFIC switch preference for our SPPECIFIC key!!!
Let us try this:
The silent way:
Code:
case "SwitchPreference":
SwitchPreference s = (SwitchPreference) pf.findPreference(key);
s.setChecked(sharedPreferences.getBoolean(key, true));
[COLOR="Blue"][B]if (key.equals("toggle_call_recording")) {
Command c = new Command(0, "pkill com.android.incallui");
try {
RootTools.getShell(true).add(c);
} catch (IOException e) {
e.printStackTrace();
} catch (TimeoutException e) {
e.printStackTrace();
} catch (RootDeniedException e) {
e.printStackTrace();
}
}[/B][/COLOR]
break;
This will kill the InCallUI every time the user switches that switch. So what happened here? The user switched the switch, the boolean got written to the database (in a different method), then the app relevant to this key was restarted. Next time a user makes a call - the call recording will be updated!!!
Now let us do it in a no silent way:
Let us inform the user. We have a little method in that class called public void appRebootRequired(final String pckgName) { ...}. Let us try to use it...
So let us go back to our onSharedPreferencesChanged method and instaed of the condition we used silently, we do something like this:
Code:
case "SwitchPreference":
SwitchPreference s = (SwitchPreference) pf.findPreference(key);
s.setChecked(sharedPreferences.getBoolean(key, true));
[COLOR="blue"][B]if (key.equals("toggle_call_recording")) {
appRebootRequired("com.android.incallui");
}[/B][/COLOR]
break;
The user clicks on the preference and see what happens:
Now for InCallUI it might be better to restart the app silently. Since the change is not visible to user anyway. But if you need to restart systemui, then it might be better to inform the user. So all you need to do is instead of passing a string "com.android.incallui" pass a string "com.android systemui". The method will do everything automatically. See how the dialog changes:
Adding more than one special key
If you need to add more than one special key (see popst #3 for instructions and explanations), you have 2 options:
1. We can go on with the if/else conditions, like so:
Code:
case "SwitchPreference":
SwitchPreference s = (SwitchPreference) pf.findPreference(key);
s.setChecked(sharedPreferences.getBoolean(key, true));
[COLOR="blue"][B] if (key.equals("toggle_call_recording")) {
appRebootRequired("com.android.incallui");
} else if (key.equals("some_other_key")) {
//do something you want
} else if (key.equals("again_some_key")) {
//do something different
}[/B][/COLOR]
break;
2. Or we make a switch for that based on key. Like so:
Code:
case "SwitchPreference":
SwitchPreference s = (SwitchPreference) pf.findPreference(key);
s.setChecked(sharedPreferences.getBoolean(key, true));
[COLOR="Blue"][B]switch (key){
case("toggle_call_recording"):
appRebootRequired("com.android.incallui");
break;
case("toggle_clock_visibility"):
appRebootRequired("com.android.systemui");
break;
case("some_other_key"):
//do something
break;
case("some_other_different_key"):
//do something different
break;
}[/B][/COLOR]
break;
Please note:
You can add the specific conditions to any preferences
You need to add them to the same preference instance as the preference that the key belongs to. Right now I showed how to do it for switch preference. You can do the same for any preference. If the key belongs to checkbox preference, you need to put the conditions inside the case of the "CheckBoxPreference" and so on
You need to make sure your condition comes AFTER our built in lines. Like in this case I added it after the initiation of the object and setChecked
You need to finish your conditions BEFORE the main break; of the case.
More to come at later time and per demand...
Huge THANK YOU @daxgirl & @Wuby986 for this!! Folks will love this app!!
Awesome!! Glad to see you have finally released it. I'm sure it'll be fantastic!!
HIZZAH!!! Kudos to wuby and daxgirl!!!
And just when I thought I could take a break from Android.....
The Sickness said:
And just when I thought I could take a break from Android.....
Click to expand...
Click to collapse
You??? Duh.......
Sent from my awesome g920f powered by 6thGear
Thebear j koss said:
View attachment 3384150
HIZZAH!!! Kudos to wuby and daxgirl!!!
Click to expand...
Click to collapse
Mostly to daxgirl
She will say no, but is true
The Sickness said:
And just when I thought I could take a break from Android.....
Click to expand...
Click to collapse
Eheehhehe there is always a good reason to start again
Delivered as promised, great work you 2, thanks a million bunch to you both & to your great testers.
PS : @daxgirl @Wuby986 any chance this app will have the phone make us coffee in the morning ! ( kidding, Sorry )
@daxgirl and @Wuby986 you guys really rock? thanks, thanks and thanks! ?
claude96 said:
Delivered as promised, great work you 2, thanks a million bunch to you both & to your great testers.
PS : @daxgirl @Wuby986 any chance this app will have the phone make us coffee in the morning ! ( kidding, Sorry )
Click to expand...
Click to collapse
Over the past couple weeks @tdunham and @ rompnit definitely tried to make us do that. .. the answer is... of you can make your coffee machine get context and use content resolver, we will deliver the toggle to trigger your morning pleasure
Sent from my awesome g920f powered by 6thGear
daxgirl said:
Over the past couple weeks @tdunham and @ rompnit definitely tried to make us do that. .. the answer is... of you can make your coffee machine get context and use content resolver, we will deliver the toggle to trigger your morning pleasure
Sent from my awesome g920f powered by 6thGear
Click to expand...
Click to collapse
@daxgirl I'm sure if anyone can !, you can, but unfortunately my coffee machine doesn't speak android at all:crying:, anyway thanks a million bunch for all your great work & help & all ( best of luck with the new upcoming rom btw:good: )
claude96 said:
@daxgirl I'm sure if anyone can !, you can, but unfortunately my coffee machine doesn't speak android at all:crying:, anyway thanks a million bunch for all your great work & help & all ( best of luck with the new upcoming rom btw:good: )
Click to expand...
Click to collapse
Thanks! We really appreciate!
As for the rom. .. it will be awhile I guess...
In a mean while I will get back to writing instructions.
Some screenies added to the op...
Sent from my awesome g920f powered by 6thGear
daxgirl said:
Thanks! We really appreciate!
As for the rom. .. it will be awhile I guess...
In a mean while I will get back to writing instructions.
Some screenies added to the op...
Sent from my awesome g920f powered by 6thGear
Click to expand...
Click to collapse
You're most welcome, and thank you of course ( pics ( app ) looks great btw )
PS : about your rom, a word to the wise ( if I may ! ), just make it bug free as much as possible ( witch is no problem for you I'm sure ), don't throw everything in it at 1st ( users will always want more and new stuff of course, normal ! ), again thanks a million and best of luck, keep up the great work.
Amazing! Now I need to fold up my sleeves and start learning something.
Sent from my SM-N9005 using Tapatalk
claude96 said:
You're most welcome, and thank you of course ( pics ( app ) looks great btw )
PS : about your rom, a word to the wise ( if I may ! ), just make it bug free as much as possible ( witch is no problem for you I'm sure ), don't throw everything in it at 1st ( users will always want more and new stuff of course, normal ! ), again thanks a million and best of luck, keep up the great work.
Click to expand...
Click to collapse
This is a wonderful idea and this is exactly our intention always. We are not for being the best or the fastest or the most unique. We are all that in our hearts It's just we are too jumpy from thing to thing... and we never manage to finish a rom between all our ideas... I am starting to think we might not have been meant to
kmokhtar79 said:
Amazing! Now I need to fold up my sleeves and start learning something.
Sent from my SM-N9005 using Tapatalk
Click to expand...
Click to collapse
My dear friend, if anyone can, YOU CAN!!! I have every faith in you!!!
Second post with instructions now contains an explanation of basic idea and how the app works... The rest after I wake up. It's almost 5am here and I am semi conscious... See ya guys tomorrow!
great, good job as always, i was thinking about one thing: when we add a new mod we learned to put our "key" in settings system database, so my idea is:there is a way to make a general observer that read all the "key" in system database so as to update our choices in real time?

Categories

Resources