Can't retrieve android preferences from preference.xml - android-fragments

I have been looking at preferences in android, but I think I must be getting something wrong.
My basic idea is to have a preference.xml file (located in res/xml), which stores a bunch of data, including ListPreference etc.
I have set default values in the XML, but when I try to retrieve the values in a separate fragment, it can't seem to find the preference.
Code of the function in my Fragment:
public static void attemptToAddToCalendar(final Context context, final SessionEntity session){
SharedPreferences sharedPreferences = context.getSharedPreferences("preferences", Context.MODE_PRIVATE);
Toast.makeText(context, "preferences are" + sharedPreferences.getString("pref_addToCalendarAutomatically-list", "Unknown"), Toast.LENGTH_LONG).show();
Code of the preferences.xml;
<ListPreference
android:key="pref_addToCalendarAutomatically-list"
android:entries="#array/pref_ARaddToCalendarAutomatically"
android:entryValues="#array/pref_ARaddToCalendarAutmaticallyValues"
android:defaultValue="2"
android:summary="Add favorites to calendar"
android:title="Calendar Options" ></ListPreference>
</PreferenceCategory>
The array
Now this will only output the text "preferences are Unknown", which evidently means it can't find the values. But I don't understand why.

Thank you for the comment! It was indeed only the layout. In hindsight it's kind of obvious, but I was kind of blind...
For anyone that stumbles across the same thing, I modified my code as follows:
Fragment function:
public static void attemptToAddToCalendar(final Context context, final SessionEntity session){
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
Toast.makeText(context, "preferences are " + sharedPreferences.getString("prefAddToCalendarAutomaticallylist", "Unknown"), Toast.LENGTH_LONG).show();
And the XML accordingly:
<ListPreference
android:key="prefAddToCalendarAutomaticallyList"
android:entries="#array/prefARaddToCalendarAutomatically"
android:entryValues="#array/prefARaddToCalendarAutomaticallyValues"
android:defaultValue="2"
android:summary="Add favorites to calendar"
android:title="Calendar Options" >
</ListPreference>
This was driving me nuts, so thanks again!

Related

JavaFX ComboBox store selected item in csv file

so I am using JavFX to create a form that stores all the answers in a csv file. I need to create a dropdown menu that allows the users to select an option, which is then recorded in the csv file. I have tried a lot of different options, however I think comboBox is the best option.
I have no problem creating the ComboBox, I only run into problems when it comes to the method to get the value of the box.
Can someone help me find a solution, or suggest what another JavaFX menu I can use?
This is the code I have right now:
public VBox setFamiliar(){
Button button = new Button();
button.setOnAction(e -> toString());
familiarComboBox = new ComboBox<>();
familiarVBox = new VBox();
familiarComboBox.getItems().addAll("Irmão", "Irmã", "Avó", "Avô", "Tio", "Tia", "Pai", "Mãe");
familiarVBox.getChildren().add(familiarComboBox);
familiarVBox.getChildren().add(button);
return familiarVBox;
}
Here I set the ComboBox, this part doesnt seem to have a problem because it appears and I can select an item. I created a separate void toString() method that sets the value of a variable to the current selected item
public void toString(ActionEvent e){
familiar = familiarComboBox.getSelectionModel().getSelectedItem().toString();
}
The problem is then in the get method to get the value that was selected.
public String getIrmao(){
if(familiar.equals("Irmão")){
return "2";
}
return "0";
I also tried to do familiarComboBox.getSelectionModel().getSelectedItem().equals(), and other variations of this combination.
If I understand your requirement -- that when a user makes a choice from the "Familiar" combo box, a value should be written immediately to a CSV file -- you don't need the getIrmao() method. You simply write the value out in the action which you are calling toString(...) (not a good choice of names), but which we will rename to handleFamiliarChange(...).
Now the method becomes
public void handleFamiliarChange(ActionEvent e){
final String familiar =
familiarComboBox.getSelectionModel().getSelectedItem().toString();
FileUtils.writeToCsvFile(familiar.equals("Irmão") ? 2 : 0);
}
where FileUtils.writeToCsvFile(...) is a method that does the file writing. Note that FileUtils is a class you have created to separate out file handling concerns -- your JavaFX view class should only concern itself with views.

Firebase Extension - Resize

I wanted to try the Resize-Firebase-Extension. Configuration seemed very easy and pictures i upload to that bucket are being handled. The new /thumbs folder appeared and telling by the given size a much smaller version of these images is displayed in the console. However these pics cant be opened (firebase console seems to crash: a new tab opens and redirects to project overview). Also the preview is not showing in console when in the thumbs folder.
I did add the content metadata like this:
if (byteArray != null){
StorageMetadata metadata = new StorageMetadata.Builder()
.setContentType("image/jpeg")
.setCustomMetadata("isGroupImage", isGroup)
.setCustomMetadata("areaNumber", userNumber)
.build();
mUploadtask =mStorageRef.putBytes(byteArray, metadata).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
#Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
callback.onSuccess(mStorageRef.toString());
Anything else to be taken care of for the function to work? Anyone else facing that problem?

Firebase ShortDynamicLink not completing task

Following is how I'm creating dynamic link
//Buiid dynamic link
DynamicLink dynamicLink = FirebaseDynamicLinks.getInstance().createDynamicLink()
.setLink(Uri.parse("https://www.chefcookrecipe.com/"))
.setDynamicLinkDomain("chefcookrecipe.page.link")
// Open links with this app on Android
.setAndroidParameters(new DynamicLink.AndroidParameters.Builder().build())
.buildDynamicLink();
String dynamicLongUri = dynamicLink.getUri().toString();
Toast.makeText(Edit_Recipes.this, dynamicLongUri, Toast.LENGTH_SHORT).show();
The same url:"https://www.chefcookrecipe.com/" is what I set as Deep link URL in firebase, and https://chefcook.page.link is my domain in firebase.
I'm getting the long link correctly. However, when I tried to generate short link with the following code
shortLinkTask.addOnCompleteListener(this, new OnCompleteListener<ShortDynamicLink>() {
#Override
public void onComplete(#NonNull Task<ShortDynamicLink> task) {
if (task.isSuccessful()) {
// Short link created
shortLink = task.getResult().getShortLink().toString();
Uri flowchartLink = task.getResult().getPreviewLink();
Toast.makeText(Edit_Recipes.this, shortLink, Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(Edit_Recipes.this, "null", Toast.LENGTH_SHORT).show();
}
}
});
I always get null. Please help I don't know what I'm missing.
I ran into same error couple of months ago. I spent all day finding what was wrong.
As long as it is reaching the conditional (if-else) statement, Your code is completely correct and nothing wrong at all.
Solution
It is usually a typographical error.
Calm yourself.
Make sure that both Deep link URL and Domain name are the same.(This is where the error usually lies). Do a copy and paste instead of typing.
I saw this issue, Don't use emulator, use real device.

Blackberry 10 SystemPrompt->inputField does not change value on user input

I need to display system input dialog: title, some text, input field, OK & Cancel buttons.
I'm new to BB development, so I carefully read docs and samples: http://developer.blackberry.com/native/documentation/cascades/ui/dialogs_toasts/prompts.html
and write the same code (let's say doc author cheated a bit in the most important part - not covering obtaining of user input with non-compiling source code - "qDebug() << "Prompt Accepted:" << text;").
void MainPage::showPrompt() {
SystemPrompt *dialog = new SystemPrompt();
dialog->inputField()->setDefaultText("TEST");
QObject::connect(dialog, SIGNAL(finished(bb::system::SystemUiResult::Type)),
this, SLOT(promptHandler(bb::system::SystemUiResult::Type)));
dialog->show();
}
void MainPage::promptHandler(bb::system::SystemUiResult::Type value) {
if (value == SystemUiResult::ConfirmButtonSelection) {
SystemPrompt *dialog = (SystemPrompt *)QObject::sender();
qDebug("text is: '%s'", qPrintable(dialog->inputField()->defaultText()));
}
}
Regardless of user input on device/simulator, inputField()->defaultText() value is always "TEST" as it was initialized.
How do I get the user input here? dialog->exec() does not change anything.
PS. Expert level question: And how do I allow empty input in SystemPrompt dialog (by default "OK" button becomes disabled on empty input).
Shame upon me. I did not read documentation carefully.
->inputFieldTextEntry() does contain the user input.
PS. First time I see such sophisticated logic of handling such simple thing as user input in text edit...

access defects from HP quality center using com4j (java)

i have been able to connect with HP QC project using com4j.
But now i want to be able to access the Defects using filters.
I dont know the actual field names of all the fields as i do not have admin rights for QC, so i cannot go to customization tab.
I want to know, how can i retrieve a defect record and output that record's columns using fieldnames.
later i want to save those records in an excel file! but that is for later.
please help me up with the CODE !
MY PROGRESS:
import ota.*;
public class comqc {
public void login(){
ITDConnection4 td = ClassFactory.createTDConnection();
td.initConnectionEx("https://qcbt10.saas.hp.com/qcbin");
System.out.println(td.connected());
td.connectProjectEx("domain", "project", "user", "pass");
System.out.println(td.dbName());
IBugFactory bugfactory = td.bugFactory().queryInterface(IBugFactory.class);
ITDFilter fil = bugfactory.filter().queryInterface(ITDFilter.class);
ITDField field = bugfactory.fields().queryInterface(ITDField.class);
}
public static void main(String args[]){
comqc obj = new comqc();
obj.login();
}
}
Thanks in advance!
was able to retrieve the defect by their fieldname! used this code!
IBug bug = bugfactory.item(55203).queryInterface(IBug.class);
System.out.println(bug.assignedTo());
earlier i was trying the first expression with item(1) or item(2) etc, and it was giving an error!
'item index' value is actually the 'defect ID' for the bug, so just needed to enter the correct defect ID and it worked!
but i can print values for only limited number of columns for a bug, not all, FOR NOW (Maybe they are not the predefined fields) !

Resources