Live Wallpaper preferences problem - android

So I have this big stupid problem with the preferences in my live-wallpaper.
First, PreferenceManager.getDefaultSharedPreferences, doesn't work. I'm calling it in my Main class, a subclass of WallpaperService in the function onCreate. For the parameter, I first tried "this" and then this.getBaseContext(), but it doesn't matter. So, when I print the values, nothing shows up!
Second, I saw in another answer here that to put some default values, use something like PreferenceManager.setDefaultValues(this.getBaseContext(), R.xml.setting, true);. So, this, doesn't get my defaultValues at all. They're all zeros and even one values from my setting.xml doesn't show up in the list. I explicitly put a android:defaultValue for each of them.
Note that once I put values for each of them in the preferences, this problem doesn't happen. But still, for someone who installs my app, it needs to work on the first time it's launched.

Preferences are a bear. I always start with a working example, and then modify it to suit my needs; it's impossible to remember the formalisms :-). The "obvious" place to start is the "second" Cube example in the SDK, which uses a preferences activity to choose between cube and dodecahedron shapes. For something more sophisticated, you might wanna look at Moonblink's "Substrate" package, which combines multiple wallpapers, and has complex settings. Project home is here: http://code.google.com/p/moonblink/wiki/Substrate , then click Source at top left, then Browse, Trunk, Substrate, src, etc. GF

Related

(android) How to name an Activity, Fragment..etc

This is not a code question.
I was just naming a Fragment and it got so long that I got confused.
I'm not sure if the Fragment's name is appropriate because it's too long.
What is the right way to name Activity or Fragment?
When naming, does the word Fragment or Activity have to be included?
For example, MovieListFragment -> MovieList, MovieActivity -> Movie
It's because sometimes it gets too long if i include these.
Or does it matter if I include it and it's long?
There are more than 22 letters to make it easier to recognize the Fragment I'm trying to name.
It all depends on what you and your team are most comfortable with. It does not matter if the name becomes too long or too short. I always name my project files keeping in mind that if I come back to my project after few months I should not be confused with file names and it is pretty intuitive.
It is the right name when it's intention gets clear.
You should avoid abreviations like MLF or MLFragment.
MovieListFragment makes it perfectly clear.
This counts not just for class names but also for variable names.
Though the smaller the scope, shorter names are fine, like in a loop for example:
for (i in 0..array.lastIndex) {
// i might be some index
// the loop has a small scope, so it's easy to get its meaning
}
In other words, if you have to scroll pages of code up to get the idea what that name is, its probably not a good name.
Think about, when you are not looking at this code for long time and you are coming back, would you still get what that name means?
And don't make names shorter just to save 2-3 characters. Days where this kind of optimization were required are long gone, and the compiler will optimize it for you anyway.
It doesn't matter if you're working with Activities or fragments, Your Activity or fragment name should be simple and meaningful such that when friends or colleagues read your codes it will make sense to them. Your project files names should also give a pictorial idea of what each variable, function or class does.thus it doesn't matter if the name is long or short. finally adding the word Activity or Fragment when naming your Activity or Fragment does not make sense and I will advise you not to do it.

Xposed module for whatsapp implement last seen tweaks

I've developed an xposed module for whatsapp.
http://forum.xda-developers.com/xposed/modules/mod-whatsapp-extensions-add-extra-t3452784
I wanted to add feature to hide our own last seen still see others or report a fake last seen for eg: 1 Jan 1970.
I made following assumptions:
To do that first I hooked date and System.currentTimeInMillis methods to make whatsapp think its 1 Jan 1970. That worked but still last seen was shown perfectly.
Assumption: The last seen time value is directly taken from the server
Then I looked in the source to find where last_seen preference is referenced. Turns out it is only referenced in SettingsPrivacy activity's class.
Assumption: To hide our last seen and still see others we need to change last seen preference to 'visible to all' and turn that back to off once we get the last seen.
but the problem is it uses onPreferenceChangeListener. We cannot hook a method from the interface directly.
I cannot find the subclass which implements onPreferenceChangeListener as the classes shown in code are synthetic.
Please if anyone can help me with this, it will be great. I need to find which is preferencechangelistener for that preference. Rest I will manage.
This is kind of a brute force trick to get the implementation but I guess you can hook the app ClassLoader.loadClass and for each loaded class check if it implements the interface. If so hook its onPreferenceChangeListener.
I found a way to do it and its working.
http://forum.xda-developers.com/xposed/modules/mod-whatsapp-extensions-add-extra-t3452784
The way to do it is by hooking a method which takes a preference as argument. We create a preference ( com.whatsapp.preference.WAprivacy preference to be precise ) and then pass this preference with last seen set to desired value to the method. And we are done.
It is working so far.

I Want to use variable in cucumber feature file

There are scenarios in feature files wherein I've use the text "Foo" and on click its open a new page. this text sometime changes to "Foo1" or "Foo2" or to something else. to avoid line by line change in feature file for "Foo" to "Foo1" or "Foo2" is there any way that I can globally declare variable in top/bottom of the feature file where I can set the required text in variable on fly and I shall start executing my test instantly?
This change exist in many feature files and around 1000 lines in feature file. To get solution for this, I try on setting environment variables but I couldn't reach all the way till end this issue to solve. So can anyone help me on this?
Thanks in advance
What if you do the replacement in your step implementation instead? Then you could have the desired value in a separate file or pass it as arguments. That way you don't need to hard code the values.
Could scenario outlines help you in any way or is the value only changing depending on external changes?
My first thought was scenario outlines like #homaxto said.
Then I thought you might want to affect it by which system you are connected to. You can do this through configuration. I have done this with Fig_Newton.
You can either set an environment varaible or use one in the commandline. Or you can use #hook type tags. With a hook tag, you can have a tag at the top of a feature file that you can use to set a variable that affects how the steps operate (but it needs to be handled inside the step).

How to build a TinyDB with values from CheckBox and TextBox in App Inventor2?

I'm trying my best to learn App Inventor2.
Although I'm a little familiar with coding in Java with Eclipse and Android Studio and I'm aware of App Inventor limitations, I like most, the graphical interface and the visual objects, than developing an app all the way in code.
I'm having a screen in an app as the following image, that I need to achieve this functionality:
a. User checks a "CheckBox" related to an image of their liking.
b. User inputs some identification related (id1, id2) to this image.
c. Clicks the "Save" button to store this values (checkBox, id1,id2) to a TinyDB.
d. Clicks the "Reset" button to clear info stored in TinyDB (checkBox, id1,id2).
I know that TinyDB can only store text. I have tried to make a TinyDB with a tag as a list named "idList" and have it populated with the values from "checkBox", "id1","id2", without success. I believe that I'm knot checking weather the "checkBox" changed or something like that.
Can someone be kind enough to point me to the right direction following this logic, or point me to something better if I'm wrong?
Thank you all in advance for your answers.
in the button click event you need some logic to find out, which checkbox has been checked, something like this (pseudocode)
if checkbox1.checked then store the text 1,
elseif checkbox2.checked then store the text 2,
etc.
in TinyDB you can store a list with the result of that logic and the text from the textboxes like this
also you have to read the values from TinyDB again. Normally you do this in the Screen.Initialize event, example:
in case you do not like the advanced blocks, you can do the same with some regular blocks, too...
See also
How to work with Lists by Saj
How to work with Lists and Lists
of lists (pdf) by appinventor.org

Get an image URI in a preference screen!

So, what I'm actually looking for is this solution: Get/pick an image from Android's built-in Gallery app programmatically but working in a preference and not in an activity.
I created a class that I put in my setting and I want to use that class to be able to find the URI of an image selected by the user on its phone. I couldn't use the code in that link because of "startActivityForResult". Which is not available in a preference.
Any idea how to bypass this ?
PROGRESS REPORT:
So, I tried some stuff in the mean time. Instead, in my settings, I added the following:
<Preference
android:key="test"
android:title="open image"
android:persistent="true">
<intent android:action="android.intent.action.GET_CONTENT"
android:value="image/*"/>
</Preference>
First, instead of "GET_CONTENT", it was "PICK", but with it, I can only go with Google Docs and the Sim Card Tool Kit, which is far from the gallery or any thing to browse the file system.
With "GET_CONTENT", it crashes.
I also added the "android.permission.WRITE_EXTERNAL_STORAGE" premission, even if I just want to read. But I didn't found any (let put this as a sub question, if there's a way to just ask to read and not write).
PROGRESS REPORT #2
I replaced android:value by android:mimeType and I goes directly to the gallery. Now, just need to know if I really got the URI and it's solved.
PROGRESS REPORT #3
At this point, here's the real problem. When I go through my SharedPreferences, the value stays empty, even after selecting an images. So, I guess there a little hack to do. So now, that's the question. Based on the example of my preference screen above, how can I retrieve the value of "test", assuming that when the intent is called, it put it somewhere ?
I finally found a solution... it's not as feng shui as I would like, but it works.
I simply code the preference screen by hand and then I was able to access the "startActivityForResult" function.
From this point, it took 3 to 5 minutes to solve it and finalize all the details.
Hope it helps some people.
You have an example there: http://www.anddev.org/code-snippets-for-android-f33/preference-screen-with-custom-views-t8472.html
But the one I used was on google, but I couldn't find the link.

Categories

Resources