Search in sources :

Example 11 with ListPopupWindow

use of android.widget.ListPopupWindow in project AndroidChromium by JackyAndroid.

the class AppMenu method show.

/**
     * Creates and shows the app menu anchored to the specified view.
     *
     * @param context The context of the AppMenu (ensure the proper theme is set on this context).
     * @param anchorView The anchor {@link View} of the {@link ListPopupWindow}.
     * @param isByPermanentButton Whether or not permanent hardware button triggered it. (oppose to
     *                            software button or keyboard).
     * @param screenRotation Current device screen rotation.
     * @param visibleDisplayFrame The display area rect in which AppMenu is supposed to fit in.
     * @param screenHeight Current device screen height.
     * @param footerResourceId The resource id for a view to add to the end of the menu list.
     *                         Can be 0 if no such view is required.
     */
void show(Context context, View anchorView, boolean isByPermanentButton, int screenRotation, Rect visibleDisplayFrame, int screenHeight, int footerResourceId) {
    mPopup = new ListPopupWindow(context, null, android.R.attr.popupMenuStyle);
    mPopup.setModal(true);
    mPopup.setAnchorView(anchorView);
    mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED);
    int footerHeight = 0;
    if (footerResourceId != 0) {
        mPopup.setPromptPosition(ListPopupWindow.POSITION_PROMPT_BELOW);
        View promptView = LayoutInflater.from(context).inflate(footerResourceId, null);
        mPopup.setPromptView(promptView);
        int measureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
        promptView.measure(measureSpec, measureSpec);
        footerHeight = promptView.getMeasuredHeight();
    }
    mPopup.setOnDismissListener(new OnDismissListener() {

        @Override
        public void onDismiss() {
            if (mPopup.getAnchorView() instanceof ImageButton) {
                ((ImageButton) mPopup.getAnchorView()).setSelected(false);
            }
            if (mMenuItemEnterAnimator != null)
                mMenuItemEnterAnimator.cancel();
            mHandler.appMenuDismissed();
            mHandler.onMenuVisibilityChanged(false);
        }
    });
    // Some OEMs don't actually let us change the background... but they still return the
    // padding of the new background, which breaks the menu height.  If we still have a
    // drawable here even though our style says @null we should use this padding instead...
    Drawable originalBgDrawable = mPopup.getBackground();
    // an incorrectly drawn background.
    if (isByPermanentButton) {
        mPopup.setBackgroundDrawable(ApiCompatibilityUtils.getDrawable(context.getResources(), R.drawable.menu_bg));
    } else {
        mPopup.setBackgroundDrawable(ApiCompatibilityUtils.getDrawable(context.getResources(), R.drawable.edge_menu_bg));
        mPopup.setAnimationStyle(R.style.OverflowMenuAnim);
    }
    // animations.
    if (SysUtils.isLowEndDevice() || Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        mPopup.setAnimationStyle(0);
    }
    Rect bgPadding = new Rect();
    mPopup.getBackground().getPadding(bgPadding);
    int popupWidth = context.getResources().getDimensionPixelSize(R.dimen.menu_width) + bgPadding.left + bgPadding.right;
    mPopup.setWidth(popupWidth);
    mCurrentScreenRotation = screenRotation;
    mIsByPermanentButton = isByPermanentButton;
    // Extract visible items from the Menu.
    int numItems = mMenu.size();
    List<MenuItem> menuItems = new ArrayList<MenuItem>();
    for (int i = 0; i < numItems; ++i) {
        MenuItem item = mMenu.getItem(i);
        if (item.isVisible()) {
            menuItems.add(item);
        }
    }
    Rect sizingPadding = new Rect(bgPadding);
    if (isByPermanentButton && originalBgDrawable != null) {
        Rect originalPadding = new Rect();
        originalBgDrawable.getPadding(originalPadding);
        sizingPadding.top = originalPadding.top;
        sizingPadding.bottom = originalPadding.bottom;
    }
    // A List adapter for visible items in the Menu. The first row is added as a header to the
    // list view.
    mAdapter = new AppMenuAdapter(this, menuItems, LayoutInflater.from(context));
    mPopup.setAdapter(mAdapter);
    setMenuHeight(menuItems.size(), visibleDisplayFrame, screenHeight, sizingPadding, footerHeight);
    setPopupOffset(mPopup, mCurrentScreenRotation, visibleDisplayFrame, sizingPadding);
    mPopup.setOnItemClickListener(this);
    mPopup.show();
    mPopup.getListView().setItemsCanFocus(true);
    mPopup.getListView().setOnKeyListener(this);
    mHandler.onMenuVisibilityChanged(true);
    if (mVerticalFadeDistance > 0) {
        mPopup.getListView().setVerticalFadingEdgeEnabled(true);
        mPopup.getListView().setFadingEdgeLength(mVerticalFadeDistance);
    }
    // Don't animate the menu items for low end devices.
    if (!SysUtils.isLowEndDevice()) {
        mPopup.getListView().addOnLayoutChangeListener(new View.OnLayoutChangeListener() {

            @Override
            public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
                mPopup.getListView().removeOnLayoutChangeListener(this);
                runMenuItemEnterAnimations();
            }
        });
    }
}
Also used : Rect(android.graphics.Rect) OnDismissListener(android.widget.PopupWindow.OnDismissListener) Drawable(android.graphics.drawable.Drawable) ArrayList(java.util.ArrayList) MenuItem(android.view.MenuItem) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) ImageButton(android.widget.ImageButton) ListPopupWindow(android.widget.ListPopupWindow)

Example 12 with ListPopupWindow

use of android.widget.ListPopupWindow in project android_frameworks_base by ParanoidAndroid.

the class MenuPopupHelper method tryShow.

public boolean tryShow() {
    mPopup = new ListPopupWindow(mContext, null, com.android.internal.R.attr.popupMenuStyle);
    mPopup.setOnDismissListener(this);
    mPopup.setOnItemClickListener(this);
    mAdapter = new MenuAdapter(mMenu);
    mPopup.setAdapter(mAdapter);
    mPopup.setModal(true);
    View anchor = mAnchorView;
    if (anchor != null) {
        final boolean addGlobalListener = mTreeObserver == null;
        // Refresh to latest
        mTreeObserver = anchor.getViewTreeObserver();
        if (addGlobalListener)
            mTreeObserver.addOnGlobalLayoutListener(this);
        anchor.addOnAttachStateChangeListener(this);
        mPopup.setAnchorView(anchor);
    } else {
        return false;
    }
    mPopup.setContentWidth(Math.min(measureContentWidth(mAdapter), mPopupMaxWidth));
    mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED);
    mPopup.show();
    mPopup.getListView().setOnKeyListener(this);
    return true;
}
Also used : ListPopupWindow(android.widget.ListPopupWindow) View(android.view.View) AdapterView(android.widget.AdapterView)

Example 13 with ListPopupWindow

use of android.widget.ListPopupWindow in project XobotOS by xamarin.

the class MenuPopupHelper method tryShow.

public boolean tryShow() {
    mPopup = new ListPopupWindow(mContext, null, com.android.internal.R.attr.popupMenuStyle);
    mPopup.setOnDismissListener(this);
    mPopup.setOnItemClickListener(this);
    mAdapter = new MenuAdapter(mMenu);
    mPopup.setAdapter(mAdapter);
    mPopup.setModal(true);
    View anchor = mAnchorView;
    if (anchor != null) {
        final boolean addGlobalListener = mTreeObserver == null;
        // Refresh to latest
        mTreeObserver = anchor.getViewTreeObserver();
        if (addGlobalListener)
            mTreeObserver.addOnGlobalLayoutListener(this);
        anchor.addOnAttachStateChangeListener(this);
        mPopup.setAnchorView(anchor);
    } else {
        return false;
    }
    mPopup.setContentWidth(Math.min(measureContentWidth(mAdapter), mPopupMaxWidth));
    mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED);
    mPopup.show();
    mPopup.getListView().setOnKeyListener(this);
    return true;
}
Also used : ListPopupWindow(android.widget.ListPopupWindow) View(android.view.View) AdapterView(android.widget.AdapterView)

Example 14 with ListPopupWindow

use of android.widget.ListPopupWindow in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class DateTimeSettingsSetupWizard method showTimezonePicker.

private void showTimezonePicker(int anchorViewId) {
    View anchorView = findViewById(anchorViewId);
    if (anchorView == null) {
        Log.e(TAG, "Unable to find zone picker anchor view " + anchorViewId);
        return;
    }
    mTimeZonePopup = new ListPopupWindow(this, null);
    mTimeZonePopup.setWidth(anchorView.getWidth());
    mTimeZonePopup.setAnchorView(anchorView);
    mTimeZonePopup.setAdapter(mTimeZoneAdapter);
    mTimeZonePopup.setOnItemClickListener(this);
    mTimeZonePopup.setModal(true);
    mTimeZonePopup.show();
}
Also used : ListPopupWindow(android.widget.ListPopupWindow) View(android.view.View) AdapterView(android.widget.AdapterView)

Example 15 with ListPopupWindow

use of android.widget.ListPopupWindow in project Talon-for-Twitter by klinker24.

the class TweetFragment method setUIElements.

public void setUIElements(final View layout) {
    TextView nametv;
    TextView screennametv;
    TextView tweettv;
    ImageButton attachButton;
    ImageButton at;
    ImageButton quote = null;
    ImageButton viewRetweeters = null;
    final TextView retweetertv;
    final LinearLayout background;
    final ImageButton expand;
    final View favoriteButton;
    final View retweetButton;
    final TextView favoriteCount;
    final TextView retweetCount;
    final ImageButton overflow;
    final LinearLayout buttons;
    if (!addonTheme) {
        nametv = (TextView) layout.findViewById(R.id.name);
        screennametv = (TextView) layout.findViewById(R.id.screen_name);
        tweettv = (TextView) layout.findViewById(R.id.tweet);
        retweetertv = (TextView) layout.findViewById(R.id.retweeter);
        background = (LinearLayout) layout.findViewById(R.id.linLayout);
        expand = (ImageButton) layout.findViewById(R.id.expand);
        profilePic = (ImageView) layout.findViewById(R.id.profile_pic_contact);
        favoriteButton = (ImageButton) layout.findViewById(R.id.favorite);
        quote = (ImageButton) layout.findViewById(R.id.quote_button);
        retweetButton = (ImageButton) layout.findViewById(R.id.retweet);
        favoriteCount = (TextView) layout.findViewById(R.id.fav_count);
        retweetCount = (TextView) layout.findViewById(R.id.retweet_count);
        reply = (EditText) layout.findViewById(R.id.reply);
        replyButton = (ImageButton) layout.findViewById(R.id.reply_button);
        attachButton = (ImageButton) layout.findViewById(R.id.attach_button);
        overflow = (ImageButton) layout.findViewById(R.id.overflow_button);
        buttons = (LinearLayout) layout.findViewById(R.id.buttons);
        charRemaining = (TextView) layout.findViewById(R.id.char_remaining);
        at = (ImageButton) layout.findViewById(R.id.at_button);
        emojiButton = (ImageButton) layout.findViewById(R.id.emoji);
        emojiKeyboard = (EmojiKeyboard) layout.findViewById(R.id.emojiKeyboard);
        timetv = (TextView) layout.findViewById(R.id.time);
        pictureIv = (ImageView) layout.findViewById(R.id.imageView);
        attachImage = (ImageView) layout.findViewById(R.id.attach);
        viewRetweeters = (ImageButton) layout.findViewById(R.id.view_retweeters);
    } else {
        Resources res;
        try {
            res = context.getPackageManager().getResourcesForApplication(settings.addonThemePackage);
        } catch (Exception e) {
            res = null;
        }
        nametv = (TextView) layout.findViewById(res.getIdentifier("name", "id", settings.addonThemePackage));
        screennametv = (TextView) layout.findViewById(res.getIdentifier("screen_name", "id", settings.addonThemePackage));
        tweettv = (TextView) layout.findViewById(res.getIdentifier("tweet", "id", settings.addonThemePackage));
        retweetertv = (TextView) layout.findViewById(res.getIdentifier("retweeter", "id", settings.addonThemePackage));
        background = (LinearLayout) layout.findViewById(res.getIdentifier("linLayout", "id", settings.addonThemePackage));
        expand = (ImageButton) layout.findViewById(res.getIdentifier("expand", "id", settings.addonThemePackage));
        profilePic = (ImageView) layout.findViewById(res.getIdentifier("profile_pic", "id", settings.addonThemePackage));
        favoriteButton = layout.findViewById(res.getIdentifier("favorite", "id", settings.addonThemePackage));
        retweetButton = layout.findViewById(res.getIdentifier("retweet", "id", settings.addonThemePackage));
        favoriteCount = (TextView) layout.findViewById(res.getIdentifier("fav_count", "id", settings.addonThemePackage));
        retweetCount = (TextView) layout.findViewById(res.getIdentifier("retweet_count", "id", settings.addonThemePackage));
        reply = (EditText) layout.findViewById(res.getIdentifier("reply", "id", settings.addonThemePackage));
        replyButton = (ImageButton) layout.findViewById(res.getIdentifier("reply_button", "id", settings.addonThemePackage));
        attachButton = (ImageButton) layout.findViewById(res.getIdentifier("attach_button", "id", settings.addonThemePackage));
        overflow = (ImageButton) layout.findViewById(res.getIdentifier("overflow_button", "id", settings.addonThemePackage));
        buttons = (LinearLayout) layout.findViewById(res.getIdentifier("buttons", "id", settings.addonThemePackage));
        charRemaining = (TextView) layout.findViewById(res.getIdentifier("char_remaining", "id", settings.addonThemePackage));
        at = (ImageButton) layout.findViewById(res.getIdentifier("at_button", "id", settings.addonThemePackage));
        emojiButton = null;
        emojiKeyboard = null;
        timetv = (TextView) layout.findViewById(res.getIdentifier("time", "id", settings.addonThemePackage));
        pictureIv = (ImageView) layout.findViewById(res.getIdentifier("imageView", "id", settings.addonThemePackage));
        attachImage = (ImageView) layout.findViewById(res.getIdentifier("attach", "id", settings.addonThemePackage));
        try {
            viewRetweeters = (ImageButton) layout.findViewById(res.getIdentifier("view_retweeters", "id", settings.addonThemePackage));
        } catch (Exception e) {
        // it doesn't exist in the theme;
        }
        try {
            quote = (ImageButton) layout.findViewById(res.getIdentifier("quote_button", "id", settings.addonThemePackage));
        } catch (Exception e) {
        // didn't exist when the theme was created.
        }
    }
    Display display = ((Activity) context).getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    int width = size.x;
    if (reply != null) {
        userAutocomplete = new ListPopupWindow(context);
        userAutocomplete.setAnchorView(layout.findViewById(R.id.prompt_pos));
        userAutocomplete.setHeight(Utils.toDP(100, context));
        userAutocomplete.setWidth((int) (width * .75));
        userAutocomplete.setAdapter(new AutoCompletePeopleAdapter(context, FollowersDataSource.getInstance(context).getCursor(settings.currentAccount, reply.getText().toString()), reply));
        userAutocomplete.setPromptPosition(ListPopupWindow.POSITION_PROMPT_ABOVE);
        userAutocomplete.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                userAutocomplete.dismiss();
            }
        });
        hashtagAutocomplete = new ListPopupWindow(context);
        hashtagAutocomplete.setAnchorView(layout.findViewById(R.id.prompt_pos));
        hashtagAutocomplete.setHeight(Utils.toDP(100, context));
        hashtagAutocomplete.setWidth((int) (width * .75));
        hashtagAutocomplete.setAdapter(new AutoCompleteHashtagAdapter(context, HashtagDataSource.getInstance(context).getCursor(reply.getText().toString()), reply));
        hashtagAutocomplete.setPromptPosition(ListPopupWindow.POSITION_PROMPT_ABOVE);
        hashtagAutocomplete.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                hashtagAutocomplete.dismiss();
            }
        });
        reply.addTextChangedListener(new TextWatcher() {

            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
            }

            @Override
            public void afterTextChanged(Editable editable) {
                String searchText = reply.getText().toString();
                try {
                    if (searchText.substring(searchText.length() - 1, searchText.length()).equals("@")) {
                        userAutocomplete.show();
                    } else if (searchText.substring(searchText.length() - 1, searchText.length()).equals(" ")) {
                        userAutocomplete.dismiss();
                    } else if (userAutocomplete.isShowing()) {
                        String[] split = reply.getText().toString().split(" ");
                        String adapterText;
                        if (split.length > 1) {
                            adapterText = split[split.length - 1];
                        } else {
                            adapterText = split[0];
                        }
                        adapterText = adapterText.replace("@", "");
                        userAutocomplete.setAdapter(new AutoCompletePeopleAdapter(context, FollowersDataSource.getInstance(context).getCursor(settings.currentAccount, adapterText), reply));
                    }
                    if (searchText.substring(searchText.length() - 1, searchText.length()).equals("#")) {
                        hashtagAutocomplete.show();
                    } else if (searchText.substring(searchText.length() - 1, searchText.length()).equals(" ")) {
                        hashtagAutocomplete.dismiss();
                    } else if (hashtagAutocomplete.isShowing()) {
                        String[] split = reply.getText().toString().split(" ");
                        String adapterText;
                        if (split.length > 1) {
                            adapterText = split[split.length - 1];
                        } else {
                            adapterText = split[0];
                        }
                        adapterText = adapterText.replace("#", "");
                        hashtagAutocomplete.setAdapter(new AutoCompleteHashtagAdapter(context, HashtagDataSource.getInstance(context).getCursor(adapterText), reply));
                    }
                } catch (Exception e) {
                    // there is no text
                    try {
                        userAutocomplete.dismiss();
                    } catch (Exception x) {
                    // something went really wrong i guess haha
                    }
                    try {
                        hashtagAutocomplete.dismiss();
                    } catch (Exception x) {
                    }
                }
            }
        });
    }
    nametv.setTextSize(settings.textSize + 2);
    screennametv.setTextSize(settings.textSize);
    tweettv.setTextSize(settings.textSize);
    timetv.setTextSize(settings.textSize - 3);
    retweetertv.setTextSize(settings.textSize - 3);
    favoriteCount.setTextSize(13);
    retweetCount.setTextSize(13);
    if (reply != null) {
        reply.setTextSize(settings.textSize);
    }
    if (settings.addonTheme) {
        try {
            Resources resourceAddon = context.getPackageManager().getResourcesForApplication(settings.addonThemePackage);
            int back = resourceAddon.getIdentifier("reply_entry_background", "drawable", settings.addonThemePackage);
            reply.setBackgroundDrawable(resourceAddon.getDrawable(back));
        } catch (Exception e) {
        // theme does not include a reply entry box
        }
    }
    if (viewRetweeters != null) {
        viewRetweeters.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                // open up the activity to see who retweeted it
                Intent viewRetweeters = new Intent(context, ViewUsersPopup.class);
                viewRetweeters.putExtra("id", tweetId);
                startActivity(viewRetweeters);
            }
        });
    }
    if (quote != null) {
        quote.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                String text = tweet;
                switch(settings.quoteStyle) {
                    case AppSettings.QUOTE_STYLE_TWITTER:
                        text = " " + "https://twitter.com/" + screenName + "/status/" + tweetId;
                        break;
                    case AppSettings.QUOTE_STYLE_TALON:
                        text = "\"@" + screenName + ": " + text + "\" ";
                        break;
                    case AppSettings.QUOTE_STYLE_RT:
                        text = " RT @" + screenName + ": " + text;
                        break;
                }
                Intent intent;
                if (!secondAcc) {
                    intent = new Intent(context, ComposeActivity.class);
                } else {
                    intent = new Intent(context, ComposeSecAccActivity.class);
                }
                intent.putExtra("user", text);
                intent.putExtra("id", tweetId);
                startActivity(intent);
            }
        });
    }
    if (overflow != null) {
        overflow.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                if (buttons.getVisibility() == View.VISIBLE) {
                    Animation ranim = AnimationUtils.loadAnimation(context, R.anim.compose_rotate_back);
                    ranim.setFillAfter(true);
                    overflow.startAnimation(ranim);
                    Animation anim = AnimationUtils.loadAnimation(context, R.anim.slide_out_left);
                    anim.setDuration(300);
                    buttons.startAnimation(anim);
                    buttons.setVisibility(View.GONE);
                } else {
                    buttons.setVisibility(View.VISIBLE);
                    Animation ranim = AnimationUtils.loadAnimation(context, R.anim.compose_rotate);
                    ranim.setFillAfter(true);
                    overflow.startAnimation(ranim);
                    Animation anim = AnimationUtils.loadAnimation(context, R.anim.slide_in_right);
                    anim.setDuration(300);
                    buttons.startAnimation(anim);
                }
            }
        });
    }
    if (settings.theme == 0 && !addonTheme) {
        nametv.setTextColor(getResources().getColor(android.R.color.black));
        nametv.setShadowLayer(0, 0, 0, getResources().getColor(android.R.color.transparent));
        screennametv.setTextColor(getResources().getColor(android.R.color.black));
        screennametv.setShadowLayer(0, 0, 0, getResources().getColor(android.R.color.transparent));
    }
    View.OnClickListener profile = new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent viewProfile = new Intent(context, ProfilePager.class);
            viewProfile.putExtra("name", name);
            viewProfile.putExtra("screenname", screenName);
            viewProfile.putExtra("proPic", proPic);
            viewProfile.putExtra("tweetid", tweetId);
            viewProfile.putExtra("retweet", retweetertv.getVisibility() == View.VISIBLE);
            context.startActivity(viewProfile);
        }
    };
    if (picture && settings.combineProPicAndImage) {
        profilePic.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                context.startActivity(new Intent(context, PhotoViewerActivity.class).putExtra("url", webpage));
            }
        });
    } else {
        profilePic.setOnClickListener(profile);
    }
    nametv.setOnClickListener(profile);
    screennametv.setOnClickListener(profile);
    if (picture && pictureIv != null) {
        // if there is a picture already loaded
        Log.v("talon_picture_loading", "picture load started");
        mAttacher = new PhotoViewAttacher(pictureIv);
        mAttacher.setOnViewTapListener(new PhotoViewAttacher.OnViewTapListener() {

            @Override
            public void onViewTap(View view, float x, float y) {
                context.startActivity(new Intent(context, PhotoViewerActivity.class).putExtra("url", webpage));
            }
        });
        pictureIv.setVisibility(View.VISIBLE);
        ImageUtils.loadImage(context, pictureIv, webpage, App.getInstance(context).getBitmapCache());
        final Handler expansionHandler = new Handler();
        if (expand != null) {
            expand.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    if (!canUseExpand) {
                        return;
                    } else {
                        canUseExpand = false;
                    }
                    if (background.getVisibility() == View.VISIBLE) {
                        Animation ranim = AnimationUtils.loadAnimation(context, R.anim.drawer_rotate);
                        ranim.setFillAfter(true);
                        expand.startAnimation(ranim);
                        expansionHandler.removeCallbacksAndMessages(null);
                        expansionHandler.postDelayed(new Runnable() {

                            @Override
                            public void run() {
                                canUseExpand = true;
                            }
                        }, 400);
                    } else {
                        Animation ranim = AnimationUtils.loadAnimation(context, R.anim.drawer_rotate_back);
                        ranim.setFillAfter(true);
                        expand.startAnimation(ranim);
                        expansionHandler.removeCallbacksAndMessages(null);
                        expansionHandler.postDelayed(new Runnable() {

                            @Override
                            public void run() {
                                canUseExpand = true;
                            }
                        }, 400);
                    }
                    ExpansionAnimation expandAni = new ExpansionAnimation(background, 300);
                    background.startAnimation(expandAni);
                }
            });
        }
    } else {
        if (expand != null) {
            expand.setVisibility(View.GONE);
        }
    }
    nametv.setText(name);
    screennametv.setText("@" + screenName);
    tweettv.setText(tweet);
    tweettv.setTextIsSelectable(true);
    if (settings.useEmoji && (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT || EmojiUtils.ios)) {
        if (EmojiUtils.emojiPattern.matcher(tweet).find()) {
            final Spannable span = EmojiUtils.getSmiledText(context, Html.fromHtml(tweet.replaceAll("\n", "<br/>")));
            tweettv.setText(span);
        }
    }
    // Date tweetDate = new Date(time);
    String timeDisplay;
    if (!settings.militaryTime) {
        timeDisplay = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.US).format(time) + " " + DateFormat.getTimeInstance(DateFormat.SHORT, Locale.US).format(time);
    } else {
        timeDisplay = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.GERMAN).format(time) + " " + DateFormat.getTimeInstance(DateFormat.SHORT, Locale.GERMAN).format(time);
    }
    timetv.setText(timeDisplay);
    timetv.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            String data = "twitter.com/" + screenName + "/status/" + tweetId;
            Uri weburi = Uri.parse("http://" + data);
            Intent launchBrowser = new Intent(Intent.ACTION_VIEW, weburi);
            launchBrowser.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(launchBrowser);
        }
    });
    timetv.setOnLongClickListener(new View.OnLongClickListener() {

        @Override
        public boolean onLongClick(View view) {
            if (status != null) {
                // we allow them to mute the client
                final String client = android.text.Html.fromHtml(status.getSource()).toString();
                new AlertDialog.Builder(context).setTitle(context.getResources().getString(R.string.mute_client) + "?").setMessage(client).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        String current = sharedPrefs.getString("muted_clients", "");
                        sharedPrefs.edit().putString("muted_clients", current + client + "   ").commit();
                        sharedPrefs.edit().putBoolean("refresh_me", true).commit();
                        dialogInterface.dismiss();
                        ((Activity) context).finish();
                    }
                }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        dialogInterface.dismiss();
                    }
                }).create().show();
            } else {
                // tell them the client hasn't been found
                Toast.makeText(context, R.string.client_not_found, Toast.LENGTH_SHORT).show();
            }
            return false;
        }
    });
    if (retweeter.length() > 0) {
        retweetertv.setText(getResources().getString(R.string.retweeter) + retweeter);
        retweetertv.setVisibility(View.VISIBLE);
        isRetweet = true;
    }
    favoriteButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (isFavorited || !settings.crossAccActions) {
                favoriteStatus(favoriteCount, favoriteButton, tweetId, secondAcc ? TYPE_ACC_TWO : TYPE_ACC_ONE);
            } else if (settings.crossAccActions) {
                // dialog for favoriting
                String[] options = new String[3];
                options[0] = "@" + settings.myScreenName;
                options[1] = "@" + settings.secondScreenName;
                options[2] = context.getString(R.string.both_accounts);
                new AlertDialog.Builder(context).setItems(options, new DialogInterface.OnClickListener() {

                    public void onClick(final DialogInterface dialog, final int item) {
                        favoriteStatus(favoriteCount, favoriteButton, tweetId, item + 1);
                    }
                }).create().show();
            }
        }
    });
    retweetButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (!settings.crossAccActions) {
                retweetStatus(retweetCount, tweetId, retweetButton, secondAcc ? TYPE_ACC_TWO : TYPE_ACC_ONE);
            } else {
                // dialog for favoriting
                String[] options = new String[3];
                options[0] = "@" + settings.myScreenName;
                options[1] = "@" + settings.secondScreenName;
                options[2] = context.getString(R.string.both_accounts);
                new AlertDialog.Builder(context).setItems(options, new DialogInterface.OnClickListener() {

                    public void onClick(final DialogInterface dialog, final int item) {
                        retweetStatus(retweetCount, tweetId, retweetButton, item + 1);
                    }
                }).create().show();
            }
        }
    });
    retweetButton.setOnLongClickListener(new View.OnLongClickListener() {

        @Override
        public boolean onLongClick(View view) {
            new AlertDialog.Builder(context).setTitle(context.getResources().getString(R.string.remove_retweet)).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    new RemoveRetweet(tweetId, retweetButton).execute();
                }
            }).setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    dialogInterface.dismiss();
                }
            }).create().show();
            return false;
        }
    });
    // profilePic.loadImage(proPic, false, null);
    if (settings.addonTheme && settings.combineProPicAndImage && picture) {
        ImageUtils.loadImage(context, profilePic, webpage, App.getInstance(context).getBitmapCache());
    } else {
        ImageUtils.loadImage(context, profilePic, proPic, App.getInstance(context).getBitmapCache());
    }
    getInfo(favoriteButton, favoriteCount, retweetCount, tweetId, retweetButton);
    String text = tweet;
    String extraNames = "";
    String screenNameToUse;
    if (secondAcc) {
        screenNameToUse = settings.secondScreenName;
    } else {
        screenNameToUse = settings.myScreenName;
    }
    if (text.contains("@")) {
        for (String s : users) {
            if (!s.equals(screenNameToUse) && !extraNames.contains(s) && !s.equals(screenName)) {
                extraNames += "@" + s + " ";
            }
        }
    }
    if (retweeter != null && !retweeter.equals("") && !retweeter.equals(screenNameToUse) && !extraNames.contains(retweeter)) {
        extraNames += "@" + retweeter + " ";
    }
    String sendString = "";
    if (!screenName.equals(screenNameToUse)) {
        if (reply != null) {
            reply.setText("@" + screenName + " " + extraNames);
        }
        sendString = "@" + screenName + " " + extraNames;
    } else {
        if (reply != null) {
            reply.setText(extraNames);
        }
        sendString = extraNames;
    }
    if (settings.autoInsertHashtags && hashtags != null) {
        for (String s : hashtags) {
            if (!s.equals("")) {
                if (reply != null) {
                    reply.append("#" + s + " ");
                }
                sendString += "#" + s + " ";
            }
        }
    }
    final String fSendString = sendString;
    if (reply != null) {
        reply.setSelection(reply.getText().length());
    }
    if (!settings.sendToComposeWindow) {
        replyButton.setEnabled(false);
        replyButton.setAlpha(.4f);
    }
    replyButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (!settings.sendToComposeWindow) {
                try {
                    if (Integer.parseInt(charRemaining.getText().toString()) >= 0 || settings.twitlonger) {
                        if (Integer.parseInt(charRemaining.getText().toString()) < 0) {
                            new AlertDialog.Builder(context).setTitle(context.getResources().getString(R.string.tweet_to_long)).setMessage(context.getResources().getString(R.string.select_shortening_service)).setPositiveButton(R.string.twitlonger, new DialogInterface.OnClickListener() {

                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    replyToStatus(reply, tweetId, Integer.parseInt(charRemaining.getText().toString()));
                                }
                            }).setNeutralButton(R.string.pwiccer, new DialogInterface.OnClickListener() {

                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    try {
                                        Intent pwiccer = new Intent("com.t3hh4xx0r.pwiccer.requestImagePost");
                                        pwiccer.putExtra("POST_CONTENT", reply.getText().toString());
                                        startActivityForResult(pwiccer, 420);
                                    } catch (Throwable e) {
                                        // open the play store here
                                        // they don't have pwiccer installed
                                        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=com.t3hh4xx0r.pwiccer&hl=en")));
                                    }
                                }
                            }).setNegativeButton(R.string.edit, new DialogInterface.OnClickListener() {

                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    dialogInterface.dismiss();
                                }
                            }).create().show();
                        } else {
                            replyToStatus(reply, tweetId, Integer.parseInt(charRemaining.getText().toString()));
                        }
                    } else {
                        Toast.makeText(context, getResources().getString(R.string.tweet_to_long), Toast.LENGTH_SHORT).show();
                    }
                } catch (Exception e) {
                    Toast.makeText(context, getResources().getString(R.string.error), Toast.LENGTH_SHORT).show();
                }
            } else {
                Intent compose;
                if (!secondAcc) {
                    compose = new Intent(context, ComposeActivity.class);
                } else {
                    compose = new Intent(context, ComposeSecAccActivity.class);
                }
                if (fSendString.length() > 0) {
                    // for some reason it puts a extra space here
                    compose.putExtra("user", fSendString.substring(0, fSendString.length() - 1));
                }
                compose.putExtra("id", tweetId);
                compose.putExtra("reply_to_text", "@" + screenName + ": " + tweet);
                startActivity(compose);
            }
        }
    });
    if (attachButton != null) {
        attachButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                attachClick();
                overflow.performClick();
            }
        });
    }
    if (settings.openKeyboard) {
        new Handler().postDelayed(new Runnable() {

            @Override
            public void run() {
                if (reply != null) {
                    reply.requestFocus();
                    InputMethodManager inputMethodManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
                    inputMethodManager.toggleSoftInputFromWindow(reply.getApplicationWindowToken(), InputMethodManager.SHOW_FORCED, 0);
                }
            }
        }, 500);
    }
    if (charRemaining != null) {
        charRemaining.setText(AppSettings.getInstance(context).tweetCharacterCount - reply.getText().length() + "");
    }
    if (reply != null) {
        reply.setHint(context.getResources().getString(R.string.reply));
        reply.addTextChangedListener(new TextWatcher() {

            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
            }

            @Override
            public void afterTextChanged(Editable editable) {
                if (!replyButton.isEnabled()) {
                    replyButton.setEnabled(true);
                    replyButton.setAlpha(1.0f);
                }
                countHandler.removeCallbacks(getCount);
                countHandler.postDelayed(getCount, 200);
            }
        });
    }
    if (!settings.useEmoji || emojiButton == null) {
        try {
            emojiButton.setVisibility(View.GONE);
        } catch (Exception e) {
        // it is a custom layout, so the emoji isn't gonna work :(
        }
    } else {
        emojiKeyboard.setAttached((HoloEditText) reply);
        reply.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                if (emojiKeyboard.isShowing()) {
                    emojiKeyboard.setVisibility(false);
                    TypedArray a = context.getTheme().obtainStyledAttributes(new int[] { R.attr.emoji_button });
                    int resource = a.getResourceId(0, 0);
                    a.recycle();
                    emojiButton.setImageDrawable(getResources().getDrawable(R.drawable.ic_emoji_keyboard_dark));
                }
            }
        });
        emojiButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                if (emojiKeyboard.isShowing()) {
                    emojiKeyboard.setVisibility(false);
                    new Handler().postDelayed(new Runnable() {

                        @Override
                        public void run() {
                            InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
                            imm.showSoftInput(reply, 0);
                        }
                    }, 250);
                    TypedArray a = context.getTheme().obtainStyledAttributes(new int[] { R.attr.emoji_button });
                    int resource = a.getResourceId(0, 0);
                    a.recycle();
                    emojiButton.setImageDrawable(getResources().getDrawable(R.drawable.ic_emoji_keyboard_dark));
                } else {
                    InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.hideSoftInputFromWindow(reply.getWindowToken(), 0);
                    new Handler().postDelayed(new Runnable() {

                        @Override
                        public void run() {
                            emojiKeyboard.setVisibility(true);
                        }
                    }, 250);
                    TypedArray a = context.getTheme().obtainStyledAttributes(new int[] { R.attr.keyboardButton });
                    int resource = a.getResourceId(0, 0);
                    a.recycle();
                    emojiButton.setImageDrawable(getResources().getDrawable(R.drawable.ic_keyboard_light));
                }
            }
        });
    }
    if (at != null) {
        at.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                final QustomDialogBuilder qustomDialogBuilder = new QustomDialogBuilder(context, sharedPrefs.getInt("current_account", 1)).setTitle(getResources().getString(R.string.type_user)).setTitleColor(getResources().getColor(R.color.app_color)).setDividerColor(getResources().getColor(R.color.app_color));
                qustomDialogBuilder.setNegativeButton(getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        dialogInterface.dismiss();
                    }
                });
                qustomDialogBuilder.setPositiveButton(getResources().getString(R.string.add_user), new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        reply.append(qustomDialogBuilder.text.getText().toString());
                    }
                });
                qustomDialogBuilder.show();
                overflow.performClick();
            }
        });
    }
    // last bool is whether it should open in the external browser or not
    TextUtils.linkifyText(context, retweetertv, null, true, "", true);
    TextUtils.linkifyText(context, tweettv, null, true, "", true);
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) QustomDialogBuilder(com.klinker.android.twitter.utils.QustomDialogBuilder) InputMethodManager(android.view.inputmethod.InputMethodManager) Uri(android.net.Uri) AutoCompleteHashtagAdapter(com.klinker.android.twitter.adapters.AutoCompleteHashtagAdapter) PhotoViewerActivity(com.klinker.android.twitter.activities.photo_viewer.PhotoViewerActivity) ImageButton(android.widget.ImageButton) ViewUsersPopup(com.klinker.android.twitter.activities.tweet_viewer.users_popup.ViewUsersPopup) ListPopupWindow(android.widget.ListPopupWindow) TypedArray(android.content.res.TypedArray) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) TextView(android.widget.TextView) ExpansionAnimation(com.klinker.android.twitter.utils.ExpansionAnimation) Handler(android.os.Handler) AutoCompletePeopleAdapter(com.klinker.android.twitter.adapters.AutoCompletePeopleAdapter) Intent(android.content.Intent) Point(android.graphics.Point) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) PhotoViewAttacher(uk.co.senab.photoview.PhotoViewAttacher) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Point(android.graphics.Point) QustomDialogBuilder(com.klinker.android.twitter.utils.QustomDialogBuilder) Animation(android.view.animation.Animation) ExpansionAnimation(com.klinker.android.twitter.utils.ExpansionAnimation) AdapterView(android.widget.AdapterView) Resources(android.content.res.Resources) LinearLayout(android.widget.LinearLayout) Spannable(android.text.Spannable) Display(android.view.Display)

Aggregations

ListPopupWindow (android.widget.ListPopupWindow)15 View (android.view.View)12 AdapterView (android.widget.AdapterView)11 TextView (android.widget.TextView)6 ImageView (android.widget.ImageView)4 ImageButton (android.widget.ImageButton)3 Context (android.content.Context)2 Intent (android.content.Intent)2 Paint (android.graphics.Paint)2 Point (android.graphics.Point)2 Handler (android.os.Handler)2 Editable (android.text.Editable)2 TextWatcher (android.text.TextWatcher)2 ViewGroup (android.view.ViewGroup)2 InputMethodManager (android.view.inputmethod.InputMethodManager)2 ArrayAdapter (android.widget.ArrayAdapter)2 FrameLayout (android.widget.FrameLayout)2 AutoCompletePeopleAdapter (com.klinker.android.twitter.adapters.AutoCompletePeopleAdapter)2 ArrayList (java.util.ArrayList)2 ActionBar (android.app.ActionBar)1