Search in sources :

Example 1 with AutoCompletePeopleAdapter

use of com.klinker.android.twitter.adapters.AutoCompletePeopleAdapter in project Talon-for-Twitter by klinker24.

the class NewScheduledTweet method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    settings = AppSettings.getInstance(this);
    Utils.setUpTheme(this, settings);
    countHandler = new Handler();
    setContentView(R.layout.scheduled_new_tweet_activity);
    Intent intent = getIntent();
    sharedPrefs = getSharedPreferences("com.klinker.android.twitter_world_preferences", 0);
    context = this;
    mEditText = (EditText) findViewById(R.id.tweet_content);
    counter = (HoloTextView) findViewById(R.id.char_remaining);
    emojiButton = (ImageButton) findViewById(R.id.emojiButton);
    emojiKeyboard = (EmojiKeyboard) findViewById(R.id.emojiKeyboard);
    // if they are coming from the compose window with text, then display it
    if (getIntent().getBooleanExtra("has_text", false)) {
        mEditText.setText(getIntent().getStringExtra("text"));
        mEditText.setSelection(mEditText.getText().length());
    }
    final ListPopupWindow autocomplete = new ListPopupWindow(context);
    autocomplete.setAnchorView(mEditText);
    autocomplete.setHeight(Utils.toDP(100, context));
    autocomplete.setWidth(Utils.toDP(275, context));
    try {
        autocomplete.setAdapter(new AutoCompletePeopleAdapter(context, FollowersDataSource.getInstance(context).getCursor(settings.currentAccount, mEditText.getText().toString()), mEditText));
    } catch (Exception e) {
    // not really sure why
    }
    autocomplete.setPromptPosition(ListPopupWindow.POSITION_PROMPT_ABOVE);
    autocomplete.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            autocomplete.dismiss();
        }
    });
    mEditText.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 = mEditText.getText().toString();
            try {
                if (searchText.substring(searchText.length() - 1, searchText.length()).equals("@")) {
                    autocomplete.show();
                } else if (searchText.substring(searchText.length() - 1, searchText.length()).equals(" ")) {
                    autocomplete.dismiss();
                } else if (autocomplete.isShowing()) {
                    String[] split = mEditText.getText().toString().split(" ");
                    String adapterText;
                    if (split.length > 1) {
                        adapterText = split[split.length - 1];
                    } else {
                        adapterText = split[0];
                    }
                    adapterText = adapterText.replace("@", "");
                    autocomplete.setAdapter(new AutoCompletePeopleAdapter(context, FollowersDataSource.getInstance(context).getCursor(settings.currentAccount, adapterText), mEditText));
                }
            } catch (Exception e) {
                // there is no text
                try {
                    autocomplete.dismiss();
                } catch (Exception x) {
                // something went really wrong i guess haha
                }
            }
            countHandler.removeCallbacks(getCount);
            countHandler.postDelayed(getCount, 300);
        }
    });
    if (!sharedPrefs.getBoolean("keyboard_type", true)) {
        mEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_MULTI_LINE);
        mEditText.setImeOptions(EditorInfo.IME_ACTION_NONE);
    }
    startDate = intent.getStringExtra(ViewScheduledTweets.EXTRA_TIME);
    startMessage = intent.getStringExtra(ViewScheduledTweets.EXTRA_TEXT);
    if (TextUtils.isEmpty(startDate)) {
        startDate = "";
    }
    if (TextUtils.isEmpty(startMessage)) {
        startMessage = "";
    }
    final Calendar c = Calendar.getInstance();
    currentYear = c.get(Calendar.YEAR);
    currentMonth = c.get(Calendar.MONTH);
    currentDay = c.get(Calendar.DAY_OF_MONTH);
    currentHour = c.get(Calendar.HOUR_OF_DAY);
    currentMinute = c.get(Calendar.MINUTE);
    currentDate = new Date(currentYear, currentMonth, currentDay, currentHour, currentMinute);
    timeDisplay = (TextView) findViewById(R.id.currentTime);
    dateDisplay = (TextView) findViewById(R.id.currentDate);
    btDate = (Button) findViewById(R.id.setDate);
    btTime = (Button) findViewById(R.id.setTime);
    if (!startDate.equals("") && !startDate.equals("null")) {
        setDate = new Date(Long.parseLong(startDate));
        timeDone = true;
        btTime.setEnabled(true);
    } else {
        btTime.setEnabled(false);
    }
    if (mEditText.getText().toString().isEmpty()) {
        mEditText.setText(startMessage);
    }
    if (!startDate.equals("")) {
        Date startDateObj = new Date(Long.parseLong(startDate));
        if (sharedPrefs.getBoolean("hour_format", false)) {
            timeDisplay.setText(DateFormat.getTimeInstance(DateFormat.SHORT, Locale.GERMAN).format(startDateObj));
        } else {
            timeDisplay.setText(DateFormat.getTimeInstance(DateFormat.SHORT, Locale.US).format(startDateObj));
        }
        if (sharedPrefs.getBoolean("hour_format", false)) {
            dateDisplay.setText(DateFormat.getDateInstance(DateFormat.MEDIUM).format(startDateObj));
        } else {
            dateDisplay.setText(DateFormat.getDateInstance(DateFormat.MEDIUM).format(startDateObj));
        }
    }
    if (!settings.useEmoji) {
        emojiButton.setVisibility(View.GONE);
    } else {
        emojiKeyboard.setAttached((HoloEditText) mEditText);
        mEditText.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                if (emojiKeyboard.isShowing()) {
                    emojiKeyboard.setVisibility(false);
                }
            }
        });
        emojiButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(mEditText.getWindowToken(), 0);
                emojiKeyboard.toggleVisibility();
                RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) emojiKeyboard.getLayoutParams();
                params.topMargin = mEditText.getHeight();
                emojiKeyboard.setLayoutParams(params);
            }
        });
    }
    // sets the date button listener to call the dialog
    btDate.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            com.android.datetimepicker.date.DatePickerDialog.newInstance(reservationDate, currentYear, currentMonth, currentDay, settings.theme != AppSettings.THEME_LIGHT).show(getFragmentManager(), "date_picker");
            btTime.setEnabled(true);
        }
    });
    // sets the time button listener to call the dialog
    btTime.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            com.android.datetimepicker.time.TimePickerDialog dialog = com.android.datetimepicker.time.TimePickerDialog.newInstance(timeDate, currentHour, currentMinute, settings.militaryTime);
            if (settings.theme != AppSettings.THEME_LIGHT) {
                dialog.setThemeDark(true);
            }
            dialog.show(getFragmentManager(), "time_picker");
        }
    });
    // Inflate a "Done/Discard" custom action bar view.
    LayoutInflater inflater = (LayoutInflater) getActionBar().getThemedContext().getSystemService(LAYOUT_INFLATER_SERVICE);
    final View customActionBarView = inflater.inflate(R.layout.actionbar_done_discard, null);
    FrameLayout done = (FrameLayout) customActionBarView.findViewById(R.id.actionbar_done);
    ((TextView) done.findViewById(R.id.done)).setText(R.string.done_label);
    done.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            doneClick();
        }
    });
    FrameLayout discard = (FrameLayout) customActionBarView.findViewById(R.id.actionbar_discard);
    if (!TextUtils.isEmpty(getIntent().getStringExtra(ViewScheduledTweets.EXTRA_TIME))) {
        ((TextView) discard.findViewById(R.id.discard)).setText(R.string.delete);
    }
    discard.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            discardClick();
        }
    });
    // Show the custom action bar view and hide the normal Home icon and title.
    final ActionBar actionBar = getActionBar();
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM, ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE);
    actionBar.setCustomView(customActionBarView, new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
}
Also used : InputMethodManager(android.view.inputmethod.InputMethodManager) ListPopupWindow(android.widget.ListPopupWindow) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) HoloTextView(com.klinker.android.twitter.views.HoloTextView) TextView(android.widget.TextView) ActionBar(android.app.ActionBar) Calendar(java.util.Calendar) Handler(android.os.Handler) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) AutoCompletePeopleAdapter(com.klinker.android.twitter.adapters.AutoCompletePeopleAdapter) View(android.view.View) AdapterView(android.widget.AdapterView) HoloTextView(com.klinker.android.twitter.views.HoloTextView) TextView(android.widget.TextView) Date(java.util.Date) LayoutInflater(android.view.LayoutInflater) FrameLayout(android.widget.FrameLayout) RelativeLayout(android.widget.RelativeLayout) AdapterView(android.widget.AdapterView)

Example 2 with AutoCompletePeopleAdapter

use of com.klinker.android.twitter.adapters.AutoCompletePeopleAdapter 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(140 - 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

Intent (android.content.Intent)2 Handler (android.os.Handler)2 Editable (android.text.Editable)2 TextWatcher (android.text.TextWatcher)2 View (android.view.View)2 InputMethodManager (android.view.inputmethod.InputMethodManager)2 AdapterView (android.widget.AdapterView)2 ListPopupWindow (android.widget.ListPopupWindow)2 TextView (android.widget.TextView)2 AutoCompletePeopleAdapter (com.klinker.android.twitter.adapters.AutoCompletePeopleAdapter)2 ActionBar (android.app.ActionBar)1 AlertDialog (android.app.AlertDialog)1 PendingIntent (android.app.PendingIntent)1 DialogInterface (android.content.DialogInterface)1 Resources (android.content.res.Resources)1 TypedArray (android.content.res.TypedArray)1 Point (android.graphics.Point)1 Uri (android.net.Uri)1 Spannable (android.text.Spannable)1 Display (android.view.Display)1