[Q] Get facebook contacts in Android? - Android Q&A, Help & Troubleshooting

hi.
How can get facebook contacts in Android?
Codeļ¼š
Uri FACEBOOK_FRIEND = Uri.parse("content://com.facebook.katana.provider.FriendsProvider/friends");
String[] projection = new String[]{
"user_id",
"user_name",
"user_image",
"user_image_url"
};
Cursor cursor = cr.query(FACEBOOK_FRIEND,projection,null,null,null);
while(cursor.moveNext()){
}
Nexus1(2.3) not avaiable.
Moto moto mb511(2.1) avaiable.

Related

[Q] How to get access to MediaController progressbar?

I currently have a mediacontroller that I am using to control a video in a videoview. I am trying to get access to the seekbar/progressbar and am having no luck. I found somethign on google that I thought would work, and it does in fact seem to return back an object, but when I try to assign my own listener to the click event or even just set the visibility of the seekbar to invisible, it doesnt do anything. Any ideas as to what I am doing wrong?
Code:
int topContainerId = getResources().getIdentifier("mediacontroller_progress", "id", "android");
SeekBar seekbar = (SeekBar) mMediaCont.findViewById(topContainerId);
seekbar.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
Log.d("In slider onclick", "WE HAVE LIFT OFF");
}
});

Ruby script

I am in an introduction to programming class and have some questions on a script I am working on. Anyone familiar with the Ruby
(.rb) language. Thanks
Sent from my Nexus 7 using xda app-developers app
Not really sure why this is in the Rezound QA...
I'm not familiar with Ruby (other than just looking at some code a few times)... but what's the issue you're having exactly?
lol I figured I would get that exact response, but it seemed like a good place to ask to be honest. I have this set of code here, Im not cut out for programming and was looking for help this is the pseudocode for the project I am working on.
MAXLINELENGTH = 40
codes = ['.-', '-...', '-.-.', '-..', '.', '..-.',
'--.', '....', '..', '.---', '-.-', '.-..',
'--', '-.', '---', '.--.', '--.-', '.-.',
'...', '-', '..-', '...-', '.--', '-..-',
'-.--', '--..','.----', '..---', '...--',
'....-', '.....', '-....', '--...', '---..',
'----.', '-----']
chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
f1 = File.open("index.txt", "w")
f2 = File.open("index.txt", "r")
Initialize line_length = 0
while character = fin.getc
if index = chars.index(character.upcase)
code.getc
Print code to fout
Print " " to fout
line_length = line_length + code.length + 2
end
elsif character == " "
Print " " to. fout
line_length += code.lenght + 4
end
if line_length >= MAXLINELENGTH
Print new line character to fout.print "\n"
Reset line_length to 0
end
end
fout.close
fin.close
Basically the goal is to print letters and numbers to a documnet labeled idex.txt but the user input characters would be translated in morse code in the txt document
zkrp5108 said:
lol I figured I would get that exact response, but it seemed like a good place to ask to be honest. I have this set of code here, Im not cut out for programming and was looking for help this is the pseudocode for the project I am working on.
MAXLINELENGTH = 40
codes = ['.-', '-...', '-.-.', '-..', '.', '..-.',
'--.', '....', '..', '.---', '-.-', '.-..',
'--', '-.', '---', '.--.', '--.-', '.-.',
'...', '-', '..-', '...-', '.--', '-..-',
'-.--', '--..','.----', '..---', '...--',
'....-', '.....', '-....', '--...', '---..',
'----.', '-----']
chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
f1 = File.open("index.txt", "w")
f2 = File.open("index.txt", "r")
Initialize line_length = 0
while character = fin.getc
if index = chars.index(character.upcase)
code.getc
Print code to fout
Print " " to fout
line_length = line_length + code.length + 2
end
elsif character == " "
Print " " to. fout
line_length += code.lenght + 4
end
if line_length >= MAXLINELENGTH
Print new line character to fout.print "\n"
Reset line_length to 0
end
end
fout.close
fin.close
Basically the goal is to print letters and numbers to a documnet labeled idex.txt but the user input characters would be translated in morse code in the txt document
Click to expand...
Click to collapse
So your taking input and converting to Morse code then logging it to a text document? Never tried that language but it looks similar to visual basic.
If so, I don't see a loop set up to parse through the input string. You will need to iterate through each character, then I'm assuming there is a separate class (or function?) that will return the Morse code for each character.
Sorry I've only ever used c++ and java
Sent from my ADR6425LVW using xda app-developers app
Squirrel1620 said:
So your taking input and converting to Morse code then logging it to a text document? Never tried that language but it looks similar to visual basic.
If so, I don't see a loop set up to parse through the input string. You will need to iterate through each character, then I'm assuming there is a separate class (or function?) that will return the Morse code for each character.
Sorry I've only ever used c++ and java
Sent from my ADR6425LVW using xda app-developers app
Click to expand...
Click to collapse
Yea Im really bad at this, I was super excited to learn it but its not going well. I cant think in a rules and order kinda thing, I'm just more free thinking I need to be able to change stuff to however I want. So I just don't understand what I am looking at lol.
zkrp5108 said:
Yea Im really bad at this, I was super excited to learn it but its not going well. I cant think in a rules and order kinda thing, I'm just more free thinking I need to be able to change stuff to however I want. So I just don't understand what I am looking at lol.
Click to expand...
Click to collapse
Well I'm self taught I guess it's just a personality thing lol. Basically think of coding like this : write this program : make a pb+j sandwich, literally write down EVERY step you need to do in order to make it... Kinda weird analogy, but depending on how deep you go that could end up being tens of thousands of lines of code.
So in your case write down on paper EVERY step you need to do to get morse code from the input and write it to a text file. That will be your pseudocode now you need to translate that into code. Remember Google is your friend when you need to find the syntax needed to do what you want.
Wish I had more free time and experience in ruby to help
Sent from my ADR6425LVW using xda app-developers app
Easiest thing to do, will be to loop through the entire input string and parse each letter at a time. Had to do a morse-code conversion program in several older languages (Pascal, Fortran, Ada, C, C++) for my Programming Languages course last semester. Pseudocode was something like:
Get input from user (or parse an input file).
Store input into a string (or a string array if multiple lines).
Loop through string and check each letter individually and look up what the morse-code equivalent is.
Store the morse code equivalent in a new string inside the loop.
When you hit the end of the string (end of the loop), save the morse string to a file.
In the loop, checking each individual letter, a case statement (or if else-if else's) will be the easiest (more typing, but easier logic).
So, for example, here's a C++ version that I wrote for my class last semester:
Code:
#include <cstdlib>
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
string search(char character);
int main()
{
string encryptionString = "";
string morseString = "";
cout << "Enter a sentence, containing only letters and blanks \nand ending with a period, to convert to morse code: " << endl;
getline(cin, encryptionString);
//remove ending period, if it exists
if(encryptionString[encryptionString.length() - 1] == '.')
{
encryptionString.erase(encryptionString.length() - 1);
}//if
for(int i = 0; i < encryptionString.length(); i++)
{
encryptionString[i] = toupper(encryptionString[i]);
}//for
int index = 0;
while(index < encryptionString.length())
{
if(encryptionString[index] != ' ' || encryptionString[index] != '\n')
{
cout << " ";
morseString = search(encryptionString[index]);
cout << morseString;
}
else
{
cout << endl;
morseString = "";
}
index++;
}//while
cin.ignore();
cout << "\n\nPress enter to exit...";
cin.get();
return 0;
}//main
string search(char character)
{
string returnString = "";
if(character >= 65 || character <= 90 )
{
switch(character)
{
case 'A':
returnString = ".-";
break;
case 'B':
returnString = "-...";
break;
case 'C':
returnString = "-.-.";
break;
case 'D':
returnString = "-..";
break;
case 'E':
returnString = ".";
break;
case 'F':
returnString = "..-.";
break;
case 'G':
returnString = "--.";
break;
case 'H':
returnString = "....";
break;
case 'I':
returnString = "..";
break;
case 'J':
returnString = ".---";
break;
case 'K':
returnString = "-.-";
break;
case 'L':
returnString = ".-..";
break;
case 'M':
returnString = "--";
break;
case 'N':
returnString = "-.";
break;
case 'O':
returnString = "---";
break;
case 'P':
returnString = ".--.";
break;
case 'Q':
returnString = "--.-";
break;
case 'R':
returnString = ".-.";
break;
case 'S':
returnString = "...";
break;
case 'T':
returnString = "-";
break;
case 'U':
returnString = "..-";
break;
case 'V':
returnString = "...-";
break;
case 'W':
returnString = ".--";
break;
case 'X':
returnString = "-..-";
break;
case 'Y':
returnString = "-.--";
break;
case 'Z':
returnString = "--..";
break;
}//switch
}//if
return returnString;
}//search
For you, you would instead print to a file instead of print to screen. You'll need to look up the exact syntax for Ruby, but should be easy.

[Q] How to trigger a onKeyShortCut event

I find that there is a function onKeyShortCut in every View Component, but when I read the SDK document, I find that the function can only be trigger by the function setShortcut in menuitem component, is there any other way to trigger this event, for example, through send a keyEvent.
Solution to the keyShortcut
cuibuaa said:
I find that there is a function onKeyShortCut in every View Component, but when I read the SDK document, I find that the function can only be trigger by the function setShortcut in menuitem component, is there any other way to trigger this event, for example, through send a keyEvent.
Click to expand...
Click to collapse
After I check the souce code of the android platform, I find that when a keyEvent happened, the event passed to ViewRoot before to the windows, and then the windows pass it to the child component in the, and finally to the Activity. From the code in ViewRootImpl.java, I find the condition to trigger this event.
if (event.getAction() == KeyEvent.ACTION_DOWN
&& event.isCtrlPressed()
&& event.getRepeatCount() == 0
&& !KeyEvent.isModifierKey(event.getKeyCode())) {
if (mView.dispatchKeyShortcutEvent(event)) {
finishInputEvent(q, true);
return;
}
}
It means if a KeyEvent includes Ctrl keycode, repeatCount = 0, and no other function keys, it will deliver it to the View component. So I make a KeyEvent like the following
KeyEvent keyevent_parse = new KeyEvent(System.currentTimeMillis(),System.currentTimeMillis(),KeyEvent.ACTION_DOWN,KeyEvent.KEYCODE_V,0,KeyEvent.META_CTRL_MASK);
Then it works, you can use this to release a parse function to any textView component.

Need help with voice recognition application dev

I'm developing an augmentative communication application for use on Kindle Fire. I'm using Fire HD 6 as my test device. I'm working in Xamarin, C#.
I know there is a speech recognizer on the device as the microphone icon appears on the keyboard and I can use it to populate the search window. However, my andoid speech recognizer code is not working. I get the "recognizer not present" error. Here is the code that I'm working with:
public class VoiceRecognition : Activity
{
private static String TAG = "VoiceRecognition";
private const int VOICE_RECOGNITION_REQUEST_CODE = 1234;
private ListView mList;
public Handler mHandler;
private Spinner mSupportedLanguageView;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
mHandler = new Handler();
SetContentView(Resource.Layout.Main);
Button speakButton = FindViewById<Button>(Resource.Id.btnRecord);
// Check to see if a recognition activity is present
PackageManager pm = PackageManager;
IList<ResolveInfo> activities = pm.QueryIntentActivities(new Intent(RecognizerIntent.ActionRecognizeSpeech), 0);
if (activities.Count != 0)
speakButton.Click += speakButton_Click;
else
{
speakButton.Enabled = false;
speakButton.Text = "Recognizer not present";
}
}
Click to expand...
Click to collapse
This code is obviously not going to work, but I don't know where to go from here. How can I access the voice recognizer on this device?
Thanks!

Processing MotionEvent from stylus on Android

Hello everybody
Unfortunately, I have too few post to make a thread in the " Android Software Development" forum. I would be very happy if this post can be moved to it.
I'm using an Android 5.1 tablet with a stylus (also supporting pressure). The below code shows how I process a motion event from the stylus. I have read about it in the Android documentation but it is still not that clear to me what exactly happens.
Especially historySize and pointerCount are unclear to me. Why is there a pointerCount, i.e. several position and pressure values? That a history has a certain size (i.e. historySize) is clear to me but why do we have this history?
So let's say I have one event from my stylus. In my understanding this event should just produce one position and pressure value but with the below code it can (and will) generate several values. Why?
Also the timestamps are not that clear to me. All values in the pointerCount-Loop have the same timestamp (timestampEvent) but every value in the history has a timestampOffset. How can I get the difference in milliseconds between the timestampOffset and timestampEvent?
Or should the stylus events processed in another way than I do?
Thank you very much for the answers and have a nice weekend.
Code:
public static void processMotionEvent(MotionEvent ev) {
long timestampEvent = ev.getEventTime();
String action = MotionEvent.actionToString(ev.getAction());
float offsetX = ev.getRawX()-ev.getX();
float offsetY = ev.getRawY()-ev.getY();
final int historySize = ev.getHistorySize();
final int pointerCount = ev.getPointerCount();
for (int h = 0; h < historySize; h++) {
long timestampOffset = ev.getHistoricalEventTime(h);
for (int p = 0; p < pointerCount; p++) {
float positionX = ev.getHistoricalX(p, h) + offsetX;
float positionY = ev.getHistoricalY(p, h) + offsetY;
float pressure = ev.getHistoricalPressure(p, h);
}
}
for (int p = 0; p < pointerCount; p++) {
float positionX = ev.getX(p) + offsetX;
float positionY = ev.getY(p) + offsetY;
float pressure = ev.getPressure();
}
}

Categories

Resources