Search in sources :

Example 11 with NetworkedCacheableImageView

use of com.klinker.android.twitter.views.NetworkedCacheableImageView in project Talon-for-Twitter by klinker24.

the class DrawerActivity method setUpDrawer.

public void setUpDrawer(int number, final String actName) {
    int currentAccount = sharedPrefs.getInt("current_account", 1);
    for (int i = 0; i < TimelinePagerAdapter.MAX_EXTRA_PAGES; i++) {
        String pageIdentifier = "account_" + currentAccount + "_page_" + (i + 1);
        int type = sharedPrefs.getInt(pageIdentifier, AppSettings.PAGE_TYPE_NONE);
        if (type != AppSettings.PAGE_TYPE_NONE) {
            number++;
        }
    }
    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
    }
    actionBar = getActionBar();
    adapter = new MainDrawerArrayAdapter(context);
    MainDrawerArrayAdapter.setCurrent(context, number);
    TypedArray a = context.getTheme().obtainStyledAttributes(new int[] { R.attr.drawerIcon });
    int resource = a.getResourceId(0, 0);
    a.recycle();
    a = context.getTheme().obtainStyledAttributes(new int[] { R.attr.read_button });
    openMailResource = a.getResourceId(0, 0);
    a.recycle();
    a = context.getTheme().obtainStyledAttributes(new int[] { R.attr.unread_button });
    closedMailResource = a.getResourceId(0, 0);
    a.recycle();
    mDrawerLayout = (NotificationDrawerLayout) findViewById(R.id.drawer_layout);
    mDrawer = (LinearLayout) findViewById(R.id.left_drawer);
    HoloTextView name = (HoloTextView) mDrawer.findViewById(R.id.name);
    HoloTextView screenName = (HoloTextView) mDrawer.findViewById(R.id.screen_name);
    backgroundPic = (NetworkedCacheableImageView) mDrawer.findViewById(R.id.background_image);
    profilePic = (NetworkedCacheableImageView) mDrawer.findViewById(R.id.profile_pic_contact);
    final ImageButton showMoreDrawer = (ImageButton) mDrawer.findViewById(R.id.options);
    final LinearLayout logoutLayout = (LinearLayout) mDrawer.findViewById(R.id.logoutLayout);
    final Button logoutDrawer = (Button) mDrawer.findViewById(R.id.logoutButton);
    drawerList = (ListView) mDrawer.findViewById(R.id.drawer_list);
    notificationList = (EnhancedListView) findViewById(R.id.notificationList);
    try {
        mDrawerLayout = (NotificationDrawerLayout) findViewById(R.id.drawer_layout);
        mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, Gravity.START);
        mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow_rev, Gravity.END);
        mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
        mDrawerLayout, /* DrawerLayout object */
        resource, /* nav drawer icon to replace 'Up' caret */
        R.string.app_name, /* "open drawer" description */
        R.string.app_name) {

            /* "close drawer" description */
            public void onDrawerClosed(View view) {
                actionBar.setIcon(new ColorDrawable(getResources().getColor(android.R.color.transparent)));
                if (logoutVisible) {
                    Animation ranim = AnimationUtils.loadAnimation(context, R.anim.drawer_rotate_back);
                    ranim.setFillAfter(true);
                    showMoreDrawer.startAnimation(ranim);
                    logoutLayout.setVisibility(View.GONE);
                    drawerList.setVisibility(View.VISIBLE);
                    logoutVisible = false;
                }
                if (MainDrawerArrayAdapter.current > adapter.pageTypes.size()) {
                    actionBar.setTitle(actName);
                } else {
                    int position = mViewPager.getCurrentItem();
                    String title = "";
                    try {
                        title = "" + mSectionsPagerAdapter.getPageTitle(position);
                    } catch (NullPointerException e) {
                        title = "";
                    }
                    actionBar.setTitle(title);
                }
                try {
                    if (oldInteractions.getText().toString().equals(getResources().getString(R.string.new_interactions))) {
                        oldInteractions.setText(getResources().getString(R.string.old_interactions));
                        readButton.setImageResource(openMailResource);
                        notificationList.enableSwipeToDismiss();
                        notificationAdapter = new InteractionsCursorAdapter(context, InteractionsDataSource.getInstance(context).getUnreadCursor(DrawerActivity.settings.currentAccount));
                        notificationList.setAdapter(notificationAdapter);
                    }
                } catch (Exception e) {
                // don't have talon pull on
                }
                invalidateOptionsMenu();
            }

            public void onDrawerOpened(View drawerView) {
                actionBar.setTitle(getResources().getString(R.string.app_name));
                actionBar.setIcon(R.mipmap.ic_launcher);
                try {
                    notificationAdapter = new InteractionsCursorAdapter(context, InteractionsDataSource.getInstance(context).getUnreadCursor(settings.currentAccount));
                    notificationList.setAdapter(notificationAdapter);
                    notificationList.enableSwipeToDismiss();
                    oldInteractions.setText(getResources().getString(R.string.old_interactions));
                    readButton.setImageResource(openMailResource);
                    sharedPrefs.edit().putBoolean("new_notification", false).commit();
                } catch (Exception e) {
                // don't have talon pull on
                }
                invalidateOptionsMenu();
            }

            public void onDrawerSlide(View drawerView, float slideOffset) {
                super.onDrawerSlide(drawerView, slideOffset);
                if (!actionBar.isShowing()) {
                    actionBar.show();
                }
                if (translucent) {
                    statusBar.setVisibility(View.VISIBLE);
                }
            }
        };
        mDrawerLayout.setDrawerListener(mDrawerToggle);
    } catch (Exception e) {
    // landscape mode
    }
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setHomeButtonEnabled(true);
    showMoreDrawer.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (logoutLayout.getVisibility() == View.GONE) {
                Animation ranim = AnimationUtils.loadAnimation(context, R.anim.drawer_rotate);
                ranim.setFillAfter(true);
                showMoreDrawer.startAnimation(ranim);
                Animation anim = AnimationUtils.loadAnimation(context, R.anim.fade_out);
                anim.setAnimationListener(new Animation.AnimationListener() {

                    @Override
                    public void onAnimationStart(Animation animation) {
                    }

                    @Override
                    public void onAnimationEnd(Animation animation) {
                        drawerList.setVisibility(View.GONE);
                    }

                    @Override
                    public void onAnimationRepeat(Animation animation) {
                    }
                });
                anim.setDuration(300);
                drawerList.startAnimation(anim);
                Animation anim2 = AnimationUtils.loadAnimation(context, R.anim.fade_in);
                anim2.setAnimationListener(new Animation.AnimationListener() {

                    @Override
                    public void onAnimationStart(Animation animation) {
                    }

                    @Override
                    public void onAnimationEnd(Animation animation) {
                        logoutLayout.setVisibility(View.VISIBLE);
                    }

                    @Override
                    public void onAnimationRepeat(Animation animation) {
                    }
                });
                anim2.setDuration(300);
                logoutLayout.startAnimation(anim2);
                logoutVisible = true;
            } else {
                Animation ranim = AnimationUtils.loadAnimation(context, R.anim.drawer_rotate_back);
                ranim.setFillAfter(true);
                showMoreDrawer.startAnimation(ranim);
                Animation anim = AnimationUtils.loadAnimation(context, R.anim.fade_in);
                anim.setAnimationListener(new Animation.AnimationListener() {

                    @Override
                    public void onAnimationStart(Animation animation) {
                    }

                    @Override
                    public void onAnimationEnd(Animation animation) {
                        drawerList.setVisibility(View.VISIBLE);
                    }

                    @Override
                    public void onAnimationRepeat(Animation animation) {
                    }
                });
                anim.setDuration(300);
                drawerList.startAnimation(anim);
                Animation anim2 = AnimationUtils.loadAnimation(context, R.anim.fade_out);
                anim2.setAnimationListener(new Animation.AnimationListener() {

                    @Override
                    public void onAnimationStart(Animation animation) {
                    }

                    @Override
                    public void onAnimationEnd(Animation animation) {
                        logoutLayout.setVisibility(View.GONE);
                    }

                    @Override
                    public void onAnimationRepeat(Animation animation) {
                    }
                });
                anim2.setDuration(300);
                logoutLayout.startAnimation(anim2);
                logoutVisible = false;
            }
        }
    });
    logoutDrawer.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            logoutFromTwitter();
        }
    });
    final String sName = settings.myName;
    final String sScreenName = settings.myScreenName;
    final String backgroundUrl = settings.myBackgroundUrl;
    final String profilePicUrl = settings.myProfilePicUrl;
    final BitmapLruCache mCache = App.getInstance(context).getProfileCache();
    if (!backgroundUrl.equals("")) {
        backgroundPic.loadImage(backgroundUrl, false, null);
    //ImageUtils.loadImage(context, backgroundPic, backgroundUrl, mCache);
    } else {
        backgroundPic.setImageDrawable(getResources().getDrawable(R.drawable.default_header_background));
    }
    backgroundPic.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            try {
                mDrawerLayout.closeDrawer(Gravity.START);
            } catch (Exception e) {
            }
            new Handler().postDelayed(new Runnable() {

                @Override
                public void run() {
                    Intent viewProfile = new Intent(context, ProfilePager.class);
                    viewProfile.putExtra("name", sName);
                    viewProfile.putExtra("screenname", sScreenName);
                    viewProfile.putExtra("proPic", profilePicUrl);
                    viewProfile.putExtra("tweetid", 0);
                    viewProfile.putExtra("retweet", false);
                    viewProfile.putExtra("long_click", false);
                    context.startActivity(viewProfile);
                }
            }, 400);
        }
    });
    backgroundPic.setOnLongClickListener(new View.OnLongClickListener() {

        @Override
        public boolean onLongClick(View view) {
            try {
                mDrawerLayout.closeDrawer(Gravity.START);
            } catch (Exception e) {
            }
            new Handler().postDelayed(new Runnable() {

                @Override
                public void run() {
                    Intent viewProfile = new Intent(context, ProfilePager.class);
                    viewProfile.putExtra("name", sName);
                    viewProfile.putExtra("screenname", sScreenName);
                    viewProfile.putExtra("proPic", profilePicUrl);
                    viewProfile.putExtra("tweetid", 0);
                    viewProfile.putExtra("retweet", false);
                    viewProfile.putExtra("long_click", true);
                    context.startActivity(viewProfile);
                }
            }, 400);
            return false;
        }
    });
    try {
        name.setText(sName);
        screenName.setText("@" + sScreenName);
        name.setTextSize(15);
        screenName.setTextSize(15);
    } catch (Exception e) {
    // 7 inch tablet in portrait
    }
    try {
        if (settings.roundContactImages) {
            //profilePic.loadImage(profilePicUrl, false, null, NetworkedCacheableImageView.CIRCLE);
            ImageUtils.loadCircleImage(context, profilePic, profilePicUrl, mCache);
        } else {
            profilePic.loadImage(profilePicUrl, false, null);
            ImageUtils.loadImage(context, profilePic, profilePicUrl, mCache);
        }
    } catch (Exception e) {
    // empty path again
    }
    drawerList.setAdapter(adapter);
    drawerList.setOnItemClickListener(new MainDrawerClickListener(context, mDrawerLayout, mViewPager));
    // set up for the second account
    // number of accounts logged in
    int count = 0;
    if (sharedPrefs.getBoolean("is_logged_in_1", false)) {
        count++;
    }
    if (sharedPrefs.getBoolean("is_logged_in_2", false)) {
        count++;
    }
    RelativeLayout secondAccount = (RelativeLayout) findViewById(R.id.second_profile);
    HoloTextView name2 = (HoloTextView) findViewById(R.id.name_2);
    HoloTextView screenname2 = (HoloTextView) findViewById(R.id.screen_name_2);
    NetworkedCacheableImageView proPic2 = (NetworkedCacheableImageView) findViewById(R.id.profile_pic_2);
    name2.setTextSize(15);
    screenname2.setTextSize(15);
    final int current = sharedPrefs.getInt("current_account", 1);
    // make a second account
    if (count == 1) {
        name2.setText(getResources().getString(R.string.new_account));
        screenname2.setText(getResources().getString(R.string.tap_to_setup));
        secondAccount.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                if (canSwitch) {
                    if (current == 1) {
                        sharedPrefs.edit().putInt("current_account", 2).commit();
                    } else {
                        sharedPrefs.edit().putInt("current_account", 1).commit();
                    }
                    context.sendBroadcast(new Intent("com.klinker.android.twitter.STOP_PUSH_SERVICE"));
                    context.sendBroadcast(new Intent("com.klinker.android.twitter.MARK_POSITION"));
                    Intent login = new Intent(context, LoginActivity.class);
                    AppSettings.invalidate();
                    finish();
                    startActivity(login);
                }
            }
        });
    } else {
        // switch accounts
        if (current == 1) {
            name2.setText(sharedPrefs.getString("twitter_users_name_2", ""));
            screenname2.setText("@" + sharedPrefs.getString("twitter_screen_name_2", ""));
            try {
                if (settings.roundContactImages) {
                    //proPic2.loadImage(sharedPrefs.getString("profile_pic_url_2", ""), true, null, NetworkedCacheableImageView.CIRCLE);
                    ImageUtils.loadCircleImage(context, proPic2, sharedPrefs.getString("profile_pic_url_2", ""), mCache);
                } else {
                    //proPic2.loadImage(sharedPrefs.getString("profile_pic_url_2", ""), true, null);
                    ImageUtils.loadImage(context, proPic2, sharedPrefs.getString("profile_pic_url_2", ""), mCache);
                }
            } catch (Exception e) {
            }
            secondAccount.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    if (canSwitch) {
                        context.sendBroadcast(new Intent("com.klinker.android.twitter.STOP_PUSH_SERVICE"));
                        context.sendBroadcast(new Intent("com.klinker.android.twitter.MARK_POSITION").putExtra("current_account", current));
                        Toast.makeText(context, "Preparing to switch", Toast.LENGTH_SHORT).show();
                        // we want to wait a second so that the mark position broadcast will work
                        new Thread(new Runnable() {

                            @Override
                            public void run() {
                                try {
                                    Thread.sleep(1000);
                                } catch (Exception e) {
                                }
                                sharedPrefs.edit().putInt("current_account", 2).commit();
                                sharedPrefs.edit().remove("new_notifications").remove("new_retweets").remove("new_favorites").remove("new_follows").commit();
                                AppSettings.invalidate();
                                finish();
                                Intent next = new Intent(context, MainActivity.class);
                                startActivity(next);
                            }
                        }).start();
                    }
                }
            });
        } else {
            name2.setText(sharedPrefs.getString("twitter_users_name_1", ""));
            screenname2.setText("@" + sharedPrefs.getString("twitter_screen_name_1", ""));
            try {
                if (settings.roundContactImages) {
                    //proPic2.loadImage(sharedPrefs.getString("profile_pic_url_1", ""), true, null, NetworkedCacheableImageView.CIRCLE);
                    ImageUtils.loadCircleImage(context, proPic2, sharedPrefs.getString("profile_pic_url_1", ""), mCache);
                } else {
                    //proPic2.loadImage(sharedPrefs.getString("profile_pic_url_1", ""), true, null);
                    ImageUtils.loadImage(context, proPic2, sharedPrefs.getString("profile_pic_url_1", ""), mCache);
                }
            } catch (Exception e) {
            }
            secondAccount.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    if (canSwitch) {
                        context.sendBroadcast(new Intent("com.klinker.android.twitter.STOP_PUSH_SERVICE"));
                        context.sendBroadcast(new Intent("com.klinker.android.twitter.MARK_POSITION").putExtra("current_account", current));
                        Toast.makeText(context, "Preparing to switch", Toast.LENGTH_SHORT).show();
                        new Thread(new Runnable() {

                            @Override
                            public void run() {
                                try {
                                    Thread.sleep(1000);
                                } catch (Exception e) {
                                }
                                sharedPrefs.edit().putInt("current_account", 1).commit();
                                sharedPrefs.edit().remove("new_notifications").remove("new_retweets").remove("new_favorites").remove("new_follows").commit();
                                AppSettings.invalidate();
                                finish();
                                Intent next = new Intent(context, MainActivity.class);
                                startActivity(next);
                            }
                        }).start();
                    }
                }
            });
        }
    }
    statusBar = findViewById(R.id.activity_status_bar);
    statusBarHeight = Utils.getStatusBarHeight(context);
    navBarHeight = Utils.getNavBarHeight(context);
    try {
        RelativeLayout.LayoutParams statusParams = (RelativeLayout.LayoutParams) statusBar.getLayoutParams();
        statusParams.height = statusBarHeight;
        statusBar.setLayoutParams(statusParams);
    } catch (Exception e) {
        try {
            LinearLayout.LayoutParams statusParams = (LinearLayout.LayoutParams) statusBar.getLayoutParams();
            statusParams.height = statusBarHeight;
            statusBar.setLayoutParams(statusParams);
        } catch (Exception x) {
        // in the trends
        }
    }
    View navBarSeperater = findViewById(R.id.nav_bar_seperator);
    if (translucent && Utils.hasNavBar(context)) {
        try {
            RelativeLayout.LayoutParams navParams = (RelativeLayout.LayoutParams) navBarSeperater.getLayoutParams();
            navParams.height = navBarHeight;
            navBarSeperater.setLayoutParams(navParams);
        } catch (Exception e) {
            try {
                LinearLayout.LayoutParams navParams = (LinearLayout.LayoutParams) navBarSeperater.getLayoutParams();
                navParams.height = navBarHeight;
                navBarSeperater.setLayoutParams(navParams);
            } catch (Exception x) {
            // in the trends
            }
        }
    }
    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);
            drawerList.addFooterView(footer);
            drawerList.setFooterDividersEnabled(false);
        }
        View drawerStatusBar = findViewById(R.id.drawer_status_bar);
        LinearLayout.LayoutParams status2Params = (LinearLayout.LayoutParams) drawerStatusBar.getLayoutParams();
        status2Params.height = statusBarHeight;
        drawerStatusBar.setLayoutParams(status2Params);
        drawerStatusBar.setVisibility(View.VISIBLE);
        statusBar.setVisibility(View.VISIBLE);
        drawerStatusBar = findViewById(R.id.drawer_status_bar_2);
        status2Params = (LinearLayout.LayoutParams) drawerStatusBar.getLayoutParams();
        status2Params.height = statusBarHeight;
        drawerStatusBar.setLayoutParams(status2Params);
        drawerStatusBar.setVisibility(View.VISIBLE);
    }
    if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE || getResources().getBoolean(R.bool.isTablet)) {
        actionBar.setDisplayHomeAsUpEnabled(false);
    }
    if (!settings.pushNotifications || !settings.useInteractionDrawer) {
        try {
            mDrawerLayout.setDrawerLockMode(NotificationDrawerLayout.LOCK_MODE_LOCKED_CLOSED, Gravity.END);
        } catch (Exception e) {
        // no drawer?
        }
    } else {
        mDrawerLayout.setDrawerRightEdgeSize(this, .1f);
        try {
            if (Build.VERSION.SDK_INT < 18 && DrawerActivity.settings.uiExtras) {
                View viewHeader2 = ((Activity) context).getLayoutInflater().inflate(R.layout.ab_header, null);
                notificationList.addHeaderView(viewHeader2, null, false);
                notificationList.setHeaderDividersEnabled(false);
            }
        } catch (Exception e) {
        // i don't know why it does this to be honest...
        }
        notificationAdapter = new InteractionsCursorAdapter(context, InteractionsDataSource.getInstance(context).getUnreadCursor(DrawerActivity.settings.currentAccount));
        try {
            notificationList.setAdapter(notificationAdapter);
        } catch (Exception e) {
        }
        View viewHeader = ((Activity) context).getLayoutInflater().inflate(R.layout.interactions_footer_1, null);
        notificationList.addFooterView(viewHeader, null, false);
        oldInteractions = (HoloTextView) findViewById(R.id.old_interactions_text);
        readButton = (ImageView) findViewById(R.id.read_button);
        LinearLayout footer = (LinearLayout) viewHeader.findViewById(R.id.footer);
        footer.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                if (oldInteractions.getText().toString().equals(getResources().getString(R.string.old_interactions))) {
                    oldInteractions.setText(getResources().getString(R.string.new_interactions));
                    readButton.setImageResource(closedMailResource);
                    notificationList.disableSwipeToDismiss();
                    notificationAdapter = new InteractionsCursorAdapter(context, InteractionsDataSource.getInstance(context).getCursor(DrawerActivity.settings.currentAccount));
                } else {
                    oldInteractions.setText(getResources().getString(R.string.old_interactions));
                    readButton.setImageResource(openMailResource);
                    notificationList.enableSwipeToDismiss();
                    notificationAdapter = new InteractionsCursorAdapter(context, InteractionsDataSource.getInstance(context).getUnreadCursor(DrawerActivity.settings.currentAccount));
                }
                notificationList.setAdapter(notificationAdapter);
            }
        });
        if (DrawerActivity.translucent) {
            if (Utils.hasNavBar(context)) {
                View nav = new View(context);
                nav.setOnClickListener(null);
                nav.setOnLongClickListener(null);
                ListView.LayoutParams params = new ListView.LayoutParams(ListView.LayoutParams.MATCH_PARENT, Utils.getNavBarHeight(context));
                nav.setLayoutParams(params);
                notificationList.addFooterView(nav);
                notificationList.setFooterDividersEnabled(false);
            }
        }
        notificationList.setDismissCallback(new EnhancedListView.OnDismissCallback() {

            @Override
            public EnhancedListView.Undoable onDismiss(EnhancedListView listView, int position) {
                Log.v("talon_interactions_delete", "position to delete: " + position);
                InteractionsDataSource data = InteractionsDataSource.getInstance(context);
                data.markRead(settings.currentAccount, position);
                notificationAdapter = new InteractionsCursorAdapter(context, data.getUnreadCursor(DrawerActivity.settings.currentAccount));
                notificationList.setAdapter(notificationAdapter);
                oldInteractions.setText(getResources().getString(R.string.old_interactions));
                readButton.setImageResource(openMailResource);
                if (notificationAdapter.getCount() == 0) {
                    setNotificationFilled(false);
                }
                return null;
            }
        });
        notificationList.enableSwipeToDismiss();
        notificationList.setSwipeDirection(EnhancedListView.SwipeDirection.START);
        notificationList.setOnItemClickListener(new InteractionClickListener(context, mDrawerLayout, mViewPager));
    }
}
Also used : ActionBarDrawerToggle(com.klinker.android.twitter.views.ActionBarDrawerToggle) MainActivity(com.klinker.android.twitter.activities.MainActivity) InteractionsCursorAdapter(com.klinker.android.twitter.adapters.InteractionsCursorAdapter) ViewConfiguration(android.view.ViewConfiguration) Field(java.lang.reflect.Field) AsyncListView(org.lucasr.smoothie.AsyncListView) EnhancedListView(de.timroes.android.listview.EnhancedListView) InteractionClickListener(com.klinker.android.twitter.listeners.InteractionClickListener) TypedArray(android.content.res.TypedArray) LoginActivity(com.klinker.android.twitter.activities.setup.LoginActivity) Handler(android.os.Handler) MainDrawerClickListener(com.klinker.android.twitter.listeners.MainDrawerClickListener) HoloTextView(com.klinker.android.twitter.views.HoloTextView) NetworkedCacheableImageView(com.klinker.android.twitter.views.NetworkedCacheableImageView) AsyncListView(org.lucasr.smoothie.AsyncListView) View(android.view.View) HoloTextView(com.klinker.android.twitter.views.HoloTextView) EnhancedListView(de.timroes.android.listview.EnhancedListView) MainDrawerArrayAdapter(com.klinker.android.twitter.adapters.MainDrawerArrayAdapter) NetworkedCacheableImageView(com.klinker.android.twitter.views.NetworkedCacheableImageView) BitmapLruCache(uk.co.senab.bitmapcache.BitmapLruCache) ColorDrawable(android.graphics.drawable.ColorDrawable) Animation(android.view.animation.Animation) EnhancedListView(de.timroes.android.listview.EnhancedListView)

Example 12 with NetworkedCacheableImageView

use of com.klinker.android.twitter.views.NetworkedCacheableImageView in project Talon-for-Twitter by klinker24.

the class TimeLineCursorAdapter method newView.

@Override
public View newView(Context context, Cursor cursor, ViewGroup viewGroup) {
    View v = null;
    final ViewHolder holder = new ViewHolder();
    if (settings.addonTheme) {
        try {
            Context viewContext = null;
            if (res == null) {
                res = context.getPackageManager().getResourcesForApplication(settings.addonThemePackage);
            }
            try {
                viewContext = context.createPackageContext(settings.addonThemePackage, Context.CONTEXT_IGNORE_SECURITY);
            } catch (PackageManager.NameNotFoundException e) {
                e.printStackTrace();
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (res != null && viewContext != null) {
                int id = res.getIdentifier("tweet", "layout", settings.addonThemePackage);
                v = LayoutInflater.from(viewContext).inflate(res.getLayout(id), null);
                holder.name = (TextView) v.findViewById(res.getIdentifier("name", "id", settings.addonThemePackage));
                holder.screenTV = (TextView) v.findViewById(res.getIdentifier("screenname", "id", settings.addonThemePackage));
                holder.profilePic = (ImageView) v.findViewById(res.getIdentifier("profile_pic", "id", settings.addonThemePackage));
                holder.time = (TextView) v.findViewById(res.getIdentifier("time", "id", settings.addonThemePackage));
                holder.tweet = (TextView) v.findViewById(res.getIdentifier("tweet", "id", settings.addonThemePackage));
                holder.reply = (EditText) v.findViewById(res.getIdentifier("reply", "id", settings.addonThemePackage));
                holder.favorite = (ImageButton) v.findViewById(res.getIdentifier("favorite", "id", settings.addonThemePackage));
                holder.retweet = (ImageButton) v.findViewById(res.getIdentifier("retweet", "id", settings.addonThemePackage));
                holder.favCount = (TextView) v.findViewById(res.getIdentifier("fav_count", "id", settings.addonThemePackage));
                holder.retweetCount = (TextView) v.findViewById(res.getIdentifier("retweet_count", "id", settings.addonThemePackage));
                holder.expandArea = (LinearLayout) v.findViewById(res.getIdentifier("expansion", "id", settings.addonThemePackage));
                holder.replyButton = (ImageButton) v.findViewById(res.getIdentifier("reply_button", "id", settings.addonThemePackage));
                holder.image = (ImageView) v.findViewById(res.getIdentifier("image", "id", settings.addonThemePackage));
                holder.retweeter = (TextView) v.findViewById(res.getIdentifier("retweeter", "id", settings.addonThemePackage));
                holder.background = (LinearLayout) v.findViewById(res.getIdentifier("background", "id", settings.addonThemePackage));
                holder.charRemaining = (TextView) v.findViewById(res.getIdentifier("char_remaining", "id", settings.addonThemePackage));
                holder.playButton = (ImageView) v.findViewById(res.getIdentifier("play_button", "id", settings.addonThemePackage));
                try {
                    holder.quoteButton = (ImageButton) v.findViewById(res.getIdentifier("quote_button", "id", settings.addonThemePackage));
                    holder.shareButton = (ImageButton) v.findViewById(res.getIdentifier("share_button", "id", settings.addonThemePackage));
                } catch (Exception e) {
                // they don't exist because the theme was made before they were added
                }
                try {
                    holder.isAConversation = (ImageView) v.findViewById(res.getIdentifier("is_a_conversation", "id", settings.addonThemePackage));
                } catch (Exception e) {
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            v = inflater.inflate(layout, viewGroup, false);
            holder.name = (TextView) v.findViewById(R.id.name);
            holder.screenTV = (TextView) v.findViewById(R.id.screenname);
            holder.profilePic = (ImageView) v.findViewById(R.id.profile_pic);
            holder.time = (TextView) v.findViewById(R.id.time);
            holder.tweet = (TextView) v.findViewById(R.id.tweet);
            holder.reply = (EditText) v.findViewById(R.id.reply);
            holder.favorite = (ImageButton) v.findViewById(R.id.favorite);
            holder.retweet = (ImageButton) v.findViewById(R.id.retweet);
            holder.favCount = (TextView) v.findViewById(R.id.fav_count);
            holder.retweetCount = (TextView) v.findViewById(R.id.retweet_count);
            holder.expandArea = (LinearLayout) v.findViewById(R.id.expansion);
            holder.replyButton = (ImageButton) v.findViewById(R.id.reply_button);
            holder.image = (NetworkedCacheableImageView) v.findViewById(R.id.image);
            holder.retweeter = (TextView) v.findViewById(R.id.retweeter);
            holder.background = (LinearLayout) v.findViewById(R.id.background);
            holder.charRemaining = (TextView) v.findViewById(R.id.char_remaining);
            holder.playButton = (NetworkedCacheableImageView) v.findViewById(R.id.play_button);
            try {
                holder.quoteButton = (ImageButton) v.findViewById(R.id.quote_button);
                holder.shareButton = (ImageButton) v.findViewById(R.id.share_button);
            } catch (Exception x) {
            // theme was made before they were added
            }
            try {
                holder.isAConversation = (ImageView) v.findViewById(R.id.is_a_conversation);
            } catch (Exception x) {
            }
        }
    } else {
        v = inflater.inflate(layout, viewGroup, false);
        holder.name = (TextView) v.findViewById(R.id.name);
        holder.screenTV = (TextView) v.findViewById(R.id.screenname);
        holder.profilePic = (ImageView) v.findViewById(R.id.profile_pic);
        holder.time = (TextView) v.findViewById(R.id.time);
        holder.tweet = (TextView) v.findViewById(R.id.tweet);
        holder.reply = (EditText) v.findViewById(R.id.reply);
        holder.favorite = (ImageButton) v.findViewById(R.id.favorite);
        holder.retweet = (ImageButton) v.findViewById(R.id.retweet);
        holder.favCount = (TextView) v.findViewById(R.id.fav_count);
        holder.retweetCount = (TextView) v.findViewById(R.id.retweet_count);
        holder.expandArea = (LinearLayout) v.findViewById(R.id.expansion);
        holder.replyButton = (ImageButton) v.findViewById(R.id.reply_button);
        holder.image = (NetworkedCacheableImageView) v.findViewById(R.id.image);
        holder.retweeter = (TextView) v.findViewById(R.id.retweeter);
        holder.background = (LinearLayout) v.findViewById(R.id.background);
        holder.charRemaining = (TextView) v.findViewById(R.id.char_remaining);
        holder.playButton = (NetworkedCacheableImageView) v.findViewById(R.id.play_button);
        try {
            holder.quoteButton = (ImageButton) v.findViewById(R.id.quote_button);
            holder.shareButton = (ImageButton) v.findViewById(R.id.share_button);
        } catch (Exception x) {
        // theme was made before they were added
        }
        try {
            holder.isAConversation = (ImageView) v.findViewById(R.id.is_a_conversation);
        } catch (Exception x) {
        }
    }
    // sets up the font sizes
    holder.tweet.setTextSize(settings.textSize);
    holder.screenTV.setTextSize(settings.textSize - 2);
    holder.name.setTextSize(settings.textSize + 4);
    holder.time.setTextSize(settings.textSize - 3);
    holder.retweeter.setTextSize(settings.textSize - 3);
    holder.favCount.setTextSize(settings.textSize + 1);
    holder.retweetCount.setTextSize(settings.textSize + 1);
    holder.reply.setTextSize(settings.textSize);
    v.setTag(holder);
    return v;
}
Also used : Context(android.content.Context) EditText(android.widget.EditText) NetworkedCacheableImageView(com.klinker.android.twitter.views.NetworkedCacheableImageView) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) TwitterException(twitter4j.TwitterException) IOException(java.io.IOException) NetworkedCacheableImageView(com.klinker.android.twitter.views.NetworkedCacheableImageView) ImageButton(android.widget.ImageButton) PackageManager(android.content.pm.PackageManager) TextView(android.widget.TextView) NetworkedCacheableImageView(com.klinker.android.twitter.views.NetworkedCacheableImageView) ImageView(android.widget.ImageView) LinearLayout(android.widget.LinearLayout)

Example 13 with NetworkedCacheableImageView

use of com.klinker.android.twitter.views.NetworkedCacheableImageView in project Talon-for-Twitter by klinker24.

the class PicturesGridAdapter method getView.

public View getView(final int position, View convertView, ViewGroup parent) {
    if (convertView == null) {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.picture, null);
        AbsListView.LayoutParams params = new AbsListView.LayoutParams(gridWidth, gridWidth);
        convertView.setLayoutParams(params);
        ViewHolder holder = new ViewHolder();
        holder.iv = (NetworkedCacheableImageView) convertView.findViewById(R.id.picture);
        convertView.setTag(holder);
    }
    final ViewHolder holder = (ViewHolder) convertView.getTag();
    Status status = statuses.get(position);
    String url = text.get(position);
    Status thisStatus;
    String retweeter;
    final long time = status.getCreatedAt().getTime();
    long originalTime = 0;
    if (status.isRetweet()) {
        retweeter = status.getUser().getScreenName();
        thisStatus = status.getRetweetedStatus();
        originalTime = thisStatus.getCreatedAt().getTime();
    } else {
        retweeter = "";
        thisStatus = status;
    }
    final String fRetweeter = retweeter;
    final long fOriginalTime = originalTime;
    User user = thisStatus.getUser();
    final long id = thisStatus.getId();
    final String profilePic = user.getBiggerProfileImageURL();
    String tweetTexts = thisStatus.getText();
    final String name = user.getName();
    final String screenname = user.getScreenName();
    String[] html = TweetLinkUtils.getLinksInStatus(thisStatus);
    final String tweetText = html[0];
    final String picUrl = html[1];
    final String otherUrl = html[2];
    final String hashtags = html[3];
    final String users = html[4];
    if (url.contains(" ")) {
        url = url.split(" ")[0];
    }
    holder.url = url;
    holder.iv.loadImage(url, false, new NetworkedCacheableImageView.OnImageLoadedListener() {

        @Override
        public void onImageLoaded(CacheableBitmapDrawable result) {
            holder.iv.setBackgroundDrawable(null);
        }
    });
    holder.iv.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            setPics();
            Intent viewImage = new Intent(context, PhotoPagerActivity.class);
            viewImage.putExtra("url", pics);
            viewImage.putExtra("start_page", position);
            context.startActivity(viewImage);
        }
    });
    holder.iv.setOnLongClickListener(new View.OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
            String link;
            boolean displayPic = !picUrl.equals("");
            if (displayPic) {
                link = picUrl;
            } else {
                link = otherUrl.split("  ")[0];
            }
            Log.v("tweet_page", "clicked");
            Intent viewTweet = new Intent(context, TweetPager.class);
            viewTweet.putExtra("name", name);
            viewTweet.putExtra("screenname", screenname);
            viewTweet.putExtra("time", time);
            viewTweet.putExtra("tweet", tweetText);
            viewTweet.putExtra("retweeter", fRetweeter);
            viewTweet.putExtra("webpage", link);
            viewTweet.putExtra("other_links", otherUrl);
            viewTweet.putExtra("picture", displayPic);
            viewTweet.putExtra("tweetid", id);
            viewTweet.putExtra("proPic", profilePic);
            viewTweet.putExtra("users", users);
            viewTweet.putExtra("hashtags", hashtags);
            context.startActivity(viewTweet);
            return false;
        }
    });
    return convertView;
}
Also used : Status(twitter4j.Status) User(twitter4j.User) AbsListView(android.widget.AbsListView) TweetPager(com.klinker.android.twitter.activities.tweet_viewer.TweetPager) Intent(android.content.Intent) NetworkedCacheableImageView(com.klinker.android.twitter.views.NetworkedCacheableImageView) AbsListView(android.widget.AbsListView) View(android.view.View) PhotoPagerActivity(com.klinker.android.twitter.activities.photo_viewer.PhotoPagerActivity) NetworkedCacheableImageView(com.klinker.android.twitter.views.NetworkedCacheableImageView) LayoutInflater(android.view.LayoutInflater) CacheableBitmapDrawable(uk.co.senab.bitmapcache.CacheableBitmapDrawable)

Aggregations

NetworkedCacheableImageView (com.klinker.android.twitter.views.NetworkedCacheableImageView)13 View (android.view.View)10 HoloTextView (com.klinker.android.twitter.views.HoloTextView)6 Intent (android.content.Intent)4 LinearLayout (android.widget.LinearLayout)4 CacheableBitmapDrawable (uk.co.senab.bitmapcache.CacheableBitmapDrawable)4 Context (android.content.Context)3 ImageView (android.widget.ImageView)3 TextView (android.widget.TextView)3 IOException (java.io.IOException)3 PackageManager (android.content.pm.PackageManager)2 TypedArray (android.content.res.TypedArray)2 Point (android.graphics.Point)2 ColorDrawable (android.graphics.drawable.ColorDrawable)2 Handler (android.os.Handler)2 Editable (android.text.Editable)2 TextWatcher (android.text.TextWatcher)2 LayoutInflater (android.view.LayoutInflater)2 AbsListView (android.widget.AbsListView)2 EditText (android.widget.EditText)2