This repository was archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathFacebookUtilities.java
More file actions
69 lines (61 loc) · 2.31 KB
/
FacebookUtilities.java
File metadata and controls
69 lines (61 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package com.uwflow.flow_android.util;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.util.Log;
import com.crashlytics.android.Crashlytics;
import com.uwflow.flow_android.constant.Constants;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
/**
* Created by jasperfung on 2/28/14.
*/
public class FacebookUtilities {
/**
* Creates an intent to view a user on Facebook. Attempts to use the Facebook app if installed, falling back to web.
* @param context
* @param fbid The user's Facebook ID.
* @return
*/
public static Intent getOpenFBProfileIntent(Context context, String fbid) {
try {
context.getPackageManager()
.getPackageInfo("com.facebook.katana", 0);
return new Intent(Intent.ACTION_VIEW,
Uri.parse(String.format("fb://profile/%s", fbid)));
} catch (Exception e) {
return new Intent(Intent.ACTION_VIEW,
Uri.parse(String.format("https://www.facebook.com/profile.php?id=%s", fbid)));
}
}
public static Bitmap getFacebookProfilePicture(String url){
if (url != null) {
try {
URL imageURL = new URL(url);
Bitmap bitmap = BitmapFactory.decodeStream(imageURL.openConnection().getInputStream());
return bitmap;
} catch (MalformedURLException e) {
Log.e(Constants.UW_FLOW, "Error creating image URL: " + e);
Crashlytics.logException(e);
} catch (IOException e) {
Log.e(Constants.UW_FLOW, "Error opening connection during image fetch: " + e);
Crashlytics.logException(e);
}
}
return null;
}
public static void viewUserOnFacebook(Context context, String facebookId) {
Intent profileIntent = FacebookUtilities.getOpenFBProfileIntent(context, facebookId);
context.startActivity(profileIntent);
}
public static String getFirstWord(String string) {
String firstWord = null;
if(string.contains(" ")){
firstWord= string.substring(0, string.indexOf(" "));
}
return firstWord;
}
}