Search in sources :

Example 11 with BitmapLruCache

use of uk.co.senab.bitmapcache.BitmapLruCache in project Talon-for-Twitter by klinker24.

the class SearchedTrendsActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    overridePendingTransition(R.anim.activity_slide_up, R.anim.activity_slide_down);
    try {
        ViewConfiguration config = ViewConfiguration.get(this);
        Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
        if (menuKeyField != null) {
            menuKeyField.setAccessible(true);
            menuKeyField.setBoolean(config, false);
        }
    } catch (Exception ex) {
    // Ignore
    }
    context = this;
    sharedPrefs = context.getSharedPreferences("com.klinker.android.twitter_world_preferences", 0);
    settings = AppSettings.getInstance(this);
    if (settings.advanceWindowed) {
        setUpWindow();
    }
    Utils.setUpPopupTheme(context, settings);
    actionBar = getActionBar();
    actionBar.setTitle(getResources().getString(R.string.search));
    setContentView(R.layout.ptr_list_layout);
    mPullToRefreshLayout = (FullScreenSwipeRefreshLayout) findViewById(R.id.swipe_refresh_layout);
    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);
    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) {
                getMore();
            }
        }
    });
    spinner = (LinearLayout) findViewById(R.id.list_progress);
    spinner.setVisibility(View.GONE);
    handleIntent(getIntent());
    Utils.setActionBar(context);
}
Also used : ArrayListLoader(com.klinker.android.twitter.adapters.ArrayListLoader) ItemManager(org.lucasr.smoothie.ItemManager) FullScreenSwipeRefreshLayout(com.klinker.android.twitter.views.swipe_refresh_layout.FullScreenSwipeRefreshLayout) AbsListView(android.widget.AbsListView) TwitterException(twitter4j.TwitterException) Point(android.graphics.Point) ViewConfiguration(android.view.ViewConfiguration) Field(java.lang.reflect.Field) BitmapLruCache(uk.co.senab.bitmapcache.BitmapLruCache)

Example 12 with BitmapLruCache

use of uk.co.senab.bitmapcache.BitmapLruCache in project Talon-for-Twitter by klinker24.

the class SavedSearchFragment method setUpListScroll.

@Override
public void setUpListScroll() {
    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) {
                getMore();
            }
        }
    });
}
Also used : BitmapLruCache(uk.co.senab.bitmapcache.BitmapLruCache) ArrayListLoader(com.klinker.android.twitter.adapters.ArrayListLoader) ItemManager(org.lucasr.smoothie.ItemManager) AbsListView(android.widget.AbsListView)

Example 13 with BitmapLruCache

use of uk.co.senab.bitmapcache.BitmapLruCache in project Talon-for-Twitter by klinker24.

the class PreCacheService method onHandleIntent.

@Override
public void onHandleIntent(Intent intent) {
    if (DEBUG) {
        Log.v("talon_pre_cache", "starting the service, current time: " + Calendar.getInstance().getTime().toString());
    }
    // if they want it only over wifi and they are on mobile data
    if (getSharedPreferences("com.klinker.android.twitter_world_preferences", 0).getBoolean("pre_cache_wifi_only", false) && Utils.getConnectionStatus(this)) {
        if (DEBUG) {
            Log.v("talon_pre_cache", "quit for connection");
        }
        // just quit because we don't want it to happen
        return;
    }
    BitmapLruCache mCache = App.getInstance(this).getBitmapCache();
    AppSettings settings = AppSettings.getInstance(this);
    Cursor cursor = HomeDataSource.getInstance(this).getUnreadCursor(settings.currentAccount);
    if (cursor.moveToFirst()) {
        if (DEBUG) {
            Log.v("talon_pre_cache", "found database and moved to first picture. cursor size: " + cursor.getCount());
        }
        boolean cont = true;
        do {
            String profilePic = cursor.getString(cursor.getColumnIndex(HomeSQLiteHelper.COLUMN_PRO_PIC));
            String imageUrl = cursor.getString(cursor.getColumnIndex(HomeSQLiteHelper.COLUMN_PIC_URL));
            if (!mCache.contains(profilePic)) {
                try {
                    HttpURLConnection conn = (HttpURLConnection) new URL(profilePic).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) {
                    }
                    if (settings.roundContactImages) {
                        image = ImageUtils.getCircle(image, this);
                    }
                    mCache.put(profilePic, image);
                } catch (Throwable e) {
                    if (DEBUG) {
                        Log.v("talon_pre_cache", "found an exception while downloading profile pic");
                        e.printStackTrace();
                    }
                    // just stop I guess
                    cont = false;
                }
            }
            if (!imageUrl.equals("")) {
                if (!mCache.contains(imageUrl)) {
                    try {
                        if (!imageUrl.contains(" ")) {
                            HttpURLConnection conn = (HttpURLConnection) new URL(imageUrl).openConnection();
                            InputStream is = new BufferedInputStream(conn.getInputStream());
                            Bitmap image = decodeSampledBitmapFromResourceMemOpt(is, 1000, 1000);
                            try {
                                is.close();
                            } catch (Exception e) {
                            }
                            try {
                                conn.disconnect();
                            } catch (Exception e) {
                            }
                            mCache.put(imageUrl, image);
                        } else {
                            String[] pics = imageUrl.split(" ");
                            Bitmap[] bitmaps = new Bitmap[pics.length];
                            // need to download all of them, then combine them
                            for (int i = 0; i < pics.length; i++) {
                                String s = pics[i];
                                // The bitmap isn't cached so download from the web
                                HttpURLConnection conn = (HttpURLConnection) new URL(s).openConnection();
                                InputStream is = new BufferedInputStream(conn.getInputStream());
                                Bitmap b = decodeSampledBitmapFromResourceMemOpt(is, 1000, 1000);
                                try {
                                    is.close();
                                } catch (Exception e) {
                                }
                                try {
                                    conn.disconnect();
                                } catch (Exception e) {
                                }
                                // Add to cache
                                try {
                                    mCache.put(s, b);
                                    // throw it into our bitmap array for later
                                    bitmaps[i] = b;
                                } catch (Exception e) {
                                }
                            }
                            // now that we have all of them, we need to put them together
                            Bitmap combined = ImageUtils.combineBitmaps(this, bitmaps);
                            try {
                                mCache.put(imageUrl, combined);
                            } catch (Exception e) {
                            }
                        }
                    } catch (Throwable e) {
                        if (DEBUG) {
                            Log.v("talon_pre_cache", "found an exception while downloading image");
                            e.printStackTrace();
                        }
                        // just stop I guess
                        cont = false;
                    }
                }
            }
        } while (cursor.moveToNext() && cont);
        if (DEBUG) {
            Log.v("talon_pre_cache", "done with service. time: " + Calendar.getInstance().getTime().toString());
        }
    }
}
Also used : AppSettings(com.klinker.android.twitter.settings.AppSettings) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) Cursor(android.database.Cursor) URL(java.net.URL) BitmapLruCache(uk.co.senab.bitmapcache.BitmapLruCache) Bitmap(android.graphics.Bitmap) HttpURLConnection(java.net.HttpURLConnection) BufferedInputStream(java.io.BufferedInputStream)

Example 14 with BitmapLruCache

use of uk.co.senab.bitmapcache.BitmapLruCache in project Talon-for-Twitter by klinker24.

the class TwitterSearchFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, null);
    this.translucent = getArguments().getBoolean("translucent", false);
    this.searchQuery = getArguments().getString("search");
    this.onlyStatus = getArguments().getBoolean("only_status", false);
    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);
    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 (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);
    if (searchQuery != null && !searchQuery.equals("")) {
        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());
    }
    if (onlyStatus) {
        try {
            findStatus(Long.parseLong(searchQuery));
        } catch (Exception e) {
        }
    } else {
        doSearch(searchQuery);
    }
    return layout;
}
Also used : ArrayListLoader(com.klinker.android.twitter.adapters.ArrayListLoader) ItemManager(org.lucasr.smoothie.ItemManager) FullScreenSwipeRefreshLayout(com.klinker.android.twitter.views.swipe_refresh_layout.FullScreenSwipeRefreshLayout) AbsListView(android.widget.AbsListView) AsyncListView(org.lucasr.smoothie.AsyncListView) View(android.view.View) AbsListView(android.widget.AbsListView) ListView(android.widget.ListView) BitmapLruCache(uk.co.senab.bitmapcache.BitmapLruCache) AsyncListView(org.lucasr.smoothie.AsyncListView) AbsListView(android.widget.AbsListView) ListView(android.widget.ListView)

Example 15 with BitmapLruCache

use of uk.co.senab.bitmapcache.BitmapLruCache in project Talon-for-Twitter by klinker24.

the class UserSearchFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    this.translucent = getArguments().getBoolean("translucent", false);
    this.searchQuery = getArguments().getString("search").replaceAll("@", "");
    searchQuery = searchQuery.replace(" TOP", "");
    searchQuery = searchQuery.replace(" -RT", "");
    this.onlyProfile = getArguments().getBoolean("only_profile", false);
    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);
    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) {
                getMoreUsers(searchQuery.replace("@", ""));
            }
        }
    });
    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);
    if (searchQuery != null && !searchQuery.equals("") && !searchQuery.contains("@")) {
        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());
    }
    doUserSearch(searchQuery);
    return layout;
}
Also used : ArrayListLoader(com.klinker.android.twitter.adapters.ArrayListLoader) ItemManager(org.lucasr.smoothie.ItemManager) FullScreenSwipeRefreshLayout(com.klinker.android.twitter.views.swipe_refresh_layout.FullScreenSwipeRefreshLayout) AbsListView(android.widget.AbsListView) AsyncListView(org.lucasr.smoothie.AsyncListView) View(android.view.View) AbsListView(android.widget.AbsListView) ListView(android.widget.ListView) BitmapLruCache(uk.co.senab.bitmapcache.BitmapLruCache) AsyncListView(org.lucasr.smoothie.AsyncListView) AbsListView(android.widget.AbsListView) ListView(android.widget.ListView)

Aggregations

BitmapLruCache (uk.co.senab.bitmapcache.BitmapLruCache)21 ItemManager (org.lucasr.smoothie.ItemManager)16 ArrayListLoader (com.klinker.android.twitter.adapters.ArrayListLoader)14 AbsListView (android.widget.AbsListView)11 AsyncListView (org.lucasr.smoothie.AsyncListView)11 View (android.view.View)10 Intent (android.content.Intent)6 ListView (android.widget.ListView)6 FullScreenSwipeRefreshLayout (com.klinker.android.twitter.views.swipe_refresh_layout.FullScreenSwipeRefreshLayout)6 Bitmap (android.graphics.Bitmap)4 URL (java.net.URL)4 Point (android.graphics.Point)3 Handler (android.os.Handler)3 ViewConfiguration (android.view.ViewConfiguration)3 LinearLayout (android.widget.LinearLayout)3 HoloTextView (com.klinker.android.twitter.views.text.HoloTextView)3 BufferedInputStream (java.io.BufferedInputStream)3 InputStream (java.io.InputStream)3 Field (java.lang.reflect.Field)3 HttpURLConnection (java.net.HttpURLConnection)3