use of uk.co.senab.bitmapcache.BitmapLruCache in project Talon-for-Twitter by klinker24.
the class ProfileMentionsFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
screenName = getArguments().getString("screen_name");
settings = AppSettings.getInstance(context);
sharedPrefs = context.getSharedPreferences("com.klinker.android.twitter_world_preferences", 0);
this.inflater = LayoutInflater.from(context);
layout = inflater.inflate(R.layout.list_fragment, null);
listView = (AsyncListView) layout.findViewById(R.id.listView);
spinner = (LinearLayout) layout.findViewById(R.id.spinner);
BitmapLruCache cache = App.getInstance(context).getBitmapCache();
ArrayListLoader loader = new ArrayListLoader(cache, context);
ItemManager.Builder builder = new ItemManager.Builder(loader);
builder.setPreloadItemsEnabled(true).setPreloadItemsCount(50);
builder.setThreadPoolSize(4);
listView.setItemManager(builder.build());
listView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView absListView, int i) {
}
@Override
public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
final int lastItem = firstVisibleItem + visibleItemCount;
if (lastItem == totalItemCount && canRefresh && hasMore) {
getMore();
}
}
});
doSearch();
return layout;
}
use of uk.co.senab.bitmapcache.BitmapLruCache in project Talon-for-Twitter by klinker24.
the class TweetWearableService method onMessageReceived.
@Override
public void onMessageReceived(MessageEvent messageEvent) {
final WearableUtils wearableUtils = new WearableUtils();
final BitmapLruCache cache = App.getInstance(this).getBitmapCache();
if (markReadHandler == null) {
markReadHandler = new Handler();
}
final String message = new String(messageEvent.getData());
Log.d(TAG, "got message: " + message);
final GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this).addApi(Wearable.API).build();
ConnectionResult connectionResult = googleApiClient.blockingConnect(30, TimeUnit.SECONDS);
if (!connectionResult.isSuccess()) {
Log.e(TAG, "Failed to connect to GoogleApiClient.");
return;
}
if (message.equals(KeyProperties.GET_DATA_MESSAGE)) {
AppSettings settings = AppSettings.getInstance(this);
Cursor tweets = HomeDataSource.getInstance(this).getWearCursor(settings.currentAccount);
PutDataMapRequest dataMap = PutDataMapRequest.create(KeyProperties.PATH);
ArrayList<String> names = new ArrayList<String>();
ArrayList<String> screennames = new ArrayList<String>();
ArrayList<String> bodies = new ArrayList<String>();
ArrayList<String> ids = new ArrayList<String>();
if (tweets != null && tweets.moveToLast()) {
do {
String name = tweets.getString(tweets.getColumnIndex(HomeSQLiteHelper.COLUMN_NAME));
String screenname = tweets.getString(tweets.getColumnIndex(HomeSQLiteHelper.COLUMN_SCREEN_NAME));
String pic = tweets.getString(tweets.getColumnIndex(HomeSQLiteHelper.COLUMN_PRO_PIC));
String body = tweets.getString(tweets.getColumnIndex(HomeSQLiteHelper.COLUMN_TEXT));
long id = tweets.getLong(tweets.getColumnIndex(HomeSQLiteHelper.COLUMN_TWEET_ID));
String retweeter;
try {
retweeter = tweets.getString(tweets.getColumnIndex(HomeSQLiteHelper.COLUMN_RETWEETER));
} catch (Exception e) {
retweeter = "";
}
screennames.add(screenname);
names.add(name);
if (TextUtils.isEmpty(retweeter)) {
body = pic + KeyProperties.DIVIDER + body + KeyProperties.DIVIDER;
} else {
body = pic + KeyProperties.DIVIDER + body + "<br><br>" + getString(R.string.retweeter) + retweeter + KeyProperties.DIVIDER;
}
bodies.add(Html.fromHtml(body.replace("<p>", KeyProperties.LINE_BREAK)).toString());
ids.add(id + "");
} while (tweets.moveToPrevious() && tweets.getCount() - tweets.getPosition() < MAX_ARTICLES_TO_SYNC);
tweets.close();
}
dataMap.getDataMap().putStringArrayList(KeyProperties.KEY_USER_NAME, names);
dataMap.getDataMap().putStringArrayList(KeyProperties.KEY_USER_SCREENNAME, screennames);
dataMap.getDataMap().putStringArrayList(KeyProperties.KEY_TWEET, bodies);
dataMap.getDataMap().putStringArrayList(KeyProperties.KEY_ID, ids);
// light background with orange accent or theme color accent
dataMap.getDataMap().putInt(KeyProperties.KEY_PRIMARY_COLOR, Color.parseColor("#dddddd"));
if (settings.addonTheme) {
dataMap.getDataMap().putInt(KeyProperties.KEY_ACCENT_COLOR, settings.accentInt);
} else {
dataMap.getDataMap().putInt(KeyProperties.KEY_ACCENT_COLOR, getResources().getColor(R.color.orange_primary_color));
}
dataMap.getDataMap().putLong(KeyProperties.KEY_DATE, System.currentTimeMillis());
for (String node : wearableUtils.getNodes(googleApiClient)) {
byte[] bytes = dataMap.asPutDataRequest().getData();
Wearable.MessageApi.sendMessage(googleApiClient, node, KeyProperties.PATH, bytes);
Log.v(TAG, "sent " + bytes.length + " bytes of data to node " + node);
}
} else if (message.startsWith(KeyProperties.MARK_READ_MESSAGE)) {
markReadHandler.removeCallbacksAndMessages(null);
markReadHandler.postDelayed(new Runnable() {
@Override
public void run() {
String[] messageContent = message.split(KeyProperties.DIVIDER);
final long id = Long.parseLong(messageContent[1]);
final AppSettings settings = AppSettings.getInstance(TweetWearableService.this);
try {
HomeDataSource.getInstance(TweetWearableService.this).markPosition(settings.currentAccount, id);
} catch (Throwable t) {
t.printStackTrace();
}
sendBroadcast(new Intent("com.klinker.android.twitter.CLEAR_PULL_UNREAD"));
final SharedPreferences sharedPrefs = getSharedPreferences("com.klinker.android.twitter_world_preferences", 0);
// mark tweetmarker if they use it
if (AppSettings.getInstance(TweetWearableService.this).tweetmarker) {
new Thread(new Runnable() {
@Override
public void run() {
TweetMarkerHelper helper = new TweetMarkerHelper(settings.currentAccount, sharedPrefs.getString("twitter_screen_name_" + settings.currentAccount, ""), Utils.getTwitter(TweetWearableService.this, settings), sharedPrefs);
helper.sendCurrentId("timeline", id);
startService(new Intent(TweetWearableService.this, HandleScrollService.class));
}
}).start();
} else {
startService(new Intent(TweetWearableService.this, HandleScrollService.class));
}
}
}, 5000);
} else if (message.startsWith(KeyProperties.REQUEST_FAVORITE)) {
final long tweetId = Long.parseLong(message.split(KeyProperties.DIVIDER)[1]);
new Thread(new Runnable() {
@Override
public void run() {
try {
Utils.getTwitter(TweetWearableService.this, AppSettings.getInstance(TweetWearableService.this)).createFavorite(tweetId);
} catch (Exception e) {
}
}
}).start();
} else if (message.startsWith(KeyProperties.REQUEST_COMPOSE)) {
final String status = message.split(KeyProperties.DIVIDER)[1];
new Thread(new Runnable() {
@Override
public void run() {
try {
Utils.getTwitter(TweetWearableService.this, AppSettings.getInstance(TweetWearableService.this)).updateStatus(status);
} catch (Exception e) {
}
}
}).start();
} else if (message.startsWith(KeyProperties.REQUEST_RETWEET)) {
final long tweetId = Long.parseLong(message.split(KeyProperties.DIVIDER)[1]);
new Thread(new Runnable() {
@Override
public void run() {
try {
Utils.getTwitter(TweetWearableService.this, AppSettings.getInstance(TweetWearableService.this)).retweetStatus(tweetId);
} catch (Exception e) {
}
}
}).start();
} else if (message.startsWith(KeyProperties.REQUEST_REPLY)) {
final String tweet = message.split(KeyProperties.DIVIDER)[1];
final long replyToId = Long.parseLong(message.split(KeyProperties.DIVIDER)[2]);
final StatusUpdate status = new StatusUpdate(tweet);
status.setInReplyToStatusId(replyToId);
new Thread(new Runnable() {
@Override
public void run() {
try {
Utils.getTwitter(TweetWearableService.this, AppSettings.getInstance(TweetWearableService.this)).updateStatus(status);
} catch (Exception e) {
}
}
}).start();
} else if (message.startsWith(KeyProperties.REQUEST_IMAGE)) {
final String url = message.split(KeyProperties.DIVIDER)[1];
Bitmap image = null;
try {
cache.get(url).getBitmap();
} catch (Exception e) {
}
if (image != null) {
image = adjustImage(image);
sendImage(image, url, wearableUtils, googleApiClient);
} else {
// download it
new Thread(new Runnable() {
@Override
public void run() {
try {
HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
InputStream is = new BufferedInputStream(conn.getInputStream());
Bitmap image = decodeSampledBitmapFromResourceMemOpt(is, 500, 500);
try {
is.close();
} catch (Exception e) {
}
try {
conn.disconnect();
} catch (Exception e) {
}
cache.put(url, image);
image = adjustImage(image);
sendImage(image, url, wearableUtils, googleApiClient);
} catch (Exception e) {
}
}
}).start();
}
} else {
Log.e(TAG, "message not recognized");
}
}
use of uk.co.senab.bitmapcache.BitmapLruCache in project Talon-for-Twitter by klinker24.
the class ChoosenListActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
overridePendingTransition(R.anim.activity_slide_up, R.anim.activity_slide_down);
context = this;
sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
settings = AppSettings.getInstance(this);
if (settings.advanceWindowed) {
setUpWindow();
}
Utils.setUpPopupTheme(this, settings);
actionBar = getActionBar();
actionBar.setTitle(getResources().getString(R.string.lists));
setContentView(R.layout.ptr_list_layout);
if (!settings.isTwitterLoggedIn) {
Intent login = new Intent(context, LoginActivity.class);
startActivity(login);
finish();
}
mPullToRefreshLayout = (FullScreenSwipeRefreshLayout) findViewById(R.id.swipe_refresh_layout);
spinner = (LinearLayout) findViewById(R.id.list_progress);
mPullToRefreshLayout.setOnRefreshListener(new FullScreenSwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
onRefreshStarted();
}
});
if (settings.addonTheme) {
mPullToRefreshLayout.setColorScheme(settings.accentInt, SwipeProgressBar.COLOR2, settings.accentInt, SwipeProgressBar.COLOR3);
} else {
if (settings.theme != AppSettings.THEME_LIGHT) {
mPullToRefreshLayout.setColorScheme(context.getResources().getColor(R.color.app_color), SwipeProgressBar.COLOR2, context.getResources().getColor(R.color.app_color), SwipeProgressBar.COLOR3);
} else {
mPullToRefreshLayout.setColorScheme(context.getResources().getColor(R.color.app_color), getResources().getColor(R.color.light_ptr_1), context.getResources().getColor(R.color.app_color), getResources().getColor(R.color.light_ptr_2));
}
}
listView = (AsyncListView) findViewById(R.id.listView);
listView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView absListView, int i) {
}
@Override
public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
final int lastItem = firstVisibleItem + visibleItemCount;
if (lastItem == totalItemCount && canRefresh) {
getLists();
}
}
});
BitmapLruCache cache = App.getInstance(context).getBitmapCache();
ArrayListLoader loader = new ArrayListLoader(cache, context);
ItemManager.Builder builder = new ItemManager.Builder(loader);
builder.setPreloadItemsEnabled(true).setPreloadItemsCount(50);
builder.setThreadPoolSize(4);
listView.setItemManager(builder.build());
listName = getIntent().getStringExtra("list_name");
listId = Long.parseLong(getIntent().getStringExtra("list_id"));
actionBar.setTitle(listName);
getLists();
Utils.setActionBar(context);
}
use of uk.co.senab.bitmapcache.BitmapLruCache in project Talon-for-Twitter by klinker24.
the class TimelineSearchFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater, container, null);
translucent = getArguments().getBoolean("translucent", false);
searchQuery = getArguments().getString("search");
settings = AppSettings.getInstance(context);
inflater = LayoutInflater.from(context);
layout = inflater.inflate(R.layout.ptr_list_layout, null);
mPullToRefreshLayout = (FullScreenSwipeRefreshLayout) layout.findViewById(R.id.swipe_refresh_layout);
mPullToRefreshLayout.setFullScreen(false);
mPullToRefreshLayout.setOnRefreshListener(new FullScreenSwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
onRefreshStarted();
}
});
if (settings.addonTheme) {
mPullToRefreshLayout.setColorScheme(settings.accentInt, SwipeProgressBar.COLOR2, settings.accentInt, SwipeProgressBar.COLOR3);
} else {
if (settings.theme != AppSettings.THEME_LIGHT) {
mPullToRefreshLayout.setColorScheme(context.getResources().getColor(R.color.app_color), SwipeProgressBar.COLOR2, context.getResources().getColor(R.color.app_color), SwipeProgressBar.COLOR3);
} else {
mPullToRefreshLayout.setColorScheme(context.getResources().getColor(R.color.app_color), getResources().getColor(R.color.light_ptr_1), context.getResources().getColor(R.color.app_color), getResources().getColor(R.color.light_ptr_2));
}
}
listView = (AsyncListView) layout.findViewById(R.id.listView);
if (translucent) {
if (Utils.hasNavBar(context)) {
View footer = new View(context);
footer.setOnClickListener(null);
footer.setOnLongClickListener(null);
ListView.LayoutParams params = new ListView.LayoutParams(ListView.LayoutParams.MATCH_PARENT, Utils.getNavBarHeight(context));
footer.setLayoutParams(params);
listView.addFooterView(footer);
listView.setFooterDividersEnabled(false);
}
}
spinner = (LinearLayout) layout.findViewById(R.id.list_progress);
spinner.setVisibility(View.GONE);
BitmapLruCache cache = App.getInstance(context).getBitmapCache();
CursorListLoader loader = new CursorListLoader(cache, context);
ItemManager.Builder builder = new ItemManager.Builder(loader);
builder.setPreloadItemsEnabled(true).setPreloadItemsCount(10);
builder.setThreadPoolSize(2);
listView.setItemManager(builder.build());
doSearch(searchQuery);
return layout;
}
use of uk.co.senab.bitmapcache.BitmapLruCache in project Talon-for-Twitter by klinker24.
the class NearbyTweets method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
sharedPrefs = context.getSharedPreferences("com.klinker.android.twitter_world_preferences", 0);
settings = AppSettings.getInstance(context);
layout = inflater.inflate(R.layout.profiles_list, null);
listView = (AsyncListView) layout.findViewById(R.id.listView);
BitmapLruCache cache = App.getInstance(context).getBitmapCache();
ArrayListLoader loader = new ArrayListLoader(cache, context);
ItemManager.Builder builder = new ItemManager.Builder(loader);
builder.setPreloadItemsEnabled(true).setPreloadItemsCount(10);
builder.setThreadPoolSize(2);
listView.setItemManager(builder.build());
listView.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView absListView, int i) {
}
@Override
public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
final int lastItem = firstVisibleItem + visibleItemCount;
if (lastItem == totalItemCount && canRefresh) {
getMore();
}
}
});
if (DrawerActivity.translucent) {
if (Utils.hasNavBar(context)) {
View footer = new View(context);
footer.setOnClickListener(null);
footer.setOnLongClickListener(null);
ListView.LayoutParams params = new ListView.LayoutParams(ListView.LayoutParams.MATCH_PARENT, Utils.getNavBarHeight(context));
footer.setLayoutParams(params);
listView.addFooterView(footer);
listView.setFooterDividersEnabled(false);
}
}
buildGoogleApiClient();
getTweets();
return layout;
}
Aggregations