Example usage for android.widget TextView setCompoundDrawablesWithIntrinsicBounds

List of usage examples for android.widget TextView setCompoundDrawablesWithIntrinsicBounds

Introduction

In this page you can find the example usage for android.widget TextView setCompoundDrawablesWithIntrinsicBounds.

Prototype

@android.view.RemotableViewMethod
public void setCompoundDrawablesWithIntrinsicBounds(@Nullable Drawable left, @Nullable Drawable top,
        @Nullable Drawable right, @Nullable Drawable bottom) 

Source Link

Document

Sets the Drawables (if any) to appear to the left of, above, to the right of, and below the text.

Usage

From source file:co.nerdart.ourss.adapter.FeedsCursorAdapter.java

@Override
protected void bindChildView(View view, Context context, Cursor cursor) {
    view.findViewById(R.id.indicator).setVisibility(View.INVISIBLE);

    TextView textView = ((TextView) view.findViewById(android.R.id.text1));
    long feedId = cursor.getLong(idPosition);
    if (feedId == mSelectedFeedId) {
        view.setBackgroundResource(android.R.color.holo_blue_dark);
    } else {// www. java  2s . c om
        view.setBackgroundResource(android.R.color.transparent);
    }

    TextView updateTextView = ((TextView) view.findViewById(android.R.id.text2));
    updateTextView.setVisibility(View.VISIBLE);

    if (cursor.isNull(errorPosition)) {
        long timestamp = cursor.getLong(lastUpdateColumn);

        // Date formatting is expensive, look at the cache
        String formattedDate = mFormattedDateCache.get(timestamp);
        if (formattedDate == null) {
            Date date = new Date(timestamp);

            formattedDate = context.getString(R.string.update) + COLON
                    + (timestamp == 0 ? context.getString(R.string.never)
                            : new StringBuilder(Constants.DATE_FORMAT.format(date)).append(' ')
                                    .append(Constants.TIME_FORMAT.format(date)));
            mFormattedDateCache.put(timestamp, formattedDate);
        }

        updateTextView.setText(formattedDate);
    } else {
        updateTextView.setText(new StringBuilder(context.getString(R.string.error)).append(COLON)
                .append(cursor.getString(errorPosition)));
    }

    byte[] iconBytes = cursor.getBlob(iconPosition);

    if (iconBytes != null && iconBytes.length > 0) {
        Bitmap bitmap = BitmapFactory.decodeByteArray(iconBytes, 0, iconBytes.length);

        if (bitmap != null && bitmap.getHeight() > 0 && bitmap.getWidth() > 0) {
            int bitmapSizeInDip = UiUtils.dpToPixel(18);

            if (bitmap.getHeight() != bitmapSizeInDip) {
                bitmap = Bitmap.createScaledBitmap(bitmap, bitmapSizeInDip, bitmapSizeInDip, false);
            }
            textView.setCompoundDrawablesWithIntrinsicBounds(new BitmapDrawable(context.getResources(), bitmap),
                    null, null, null);
        } else {
            textView.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
        }
    } else {
        view.setTag(null);
        textView.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
    }

    int unreadCount;
    synchronized (mUnreadItemsByFeed) {
        unreadCount = mUnreadItemsByFeed.get(feedId);
    }

    if (unreadCount > 0) {
        textView.setEnabled(true);
        updateTextView.setEnabled(true);
    } else {
        textView.setEnabled(false);
        updateTextView.setEnabled(false);
    }
    textView.setText(
            (cursor.isNull(namePosition) ? cursor.getString(linkPosition) : cursor.getString(namePosition))
                    + (unreadCount > 0 ? " (" + unreadCount + ")" : ""));

    View sortView = view.findViewById(R.id.sortitem);
    if (!sortViews.contains(sortView)) { // as we are reusing views, this is fine
        sortViews.add(sortView);
    }
    sortView.setVisibility(feedSort ? View.VISIBLE : View.GONE);
}

From source file:de.baumann.hhsmoodle.data_count.Count_Fragment.java

public void setCountList() {

    if (isFABOpen) {
        closeFABMenu();// w  ww  . ja va  2s .c  o  m
    }

    //display data
    final int layoutstyle = R.layout.list_item_notes;
    int[] xml_id = new int[] { R.id.textView_title_notes, R.id.textView_des_notes, R.id.textView_create_notes };
    String[] column = new String[] { "count_title", "count_content", "count_creation" };
    final Cursor row = db.fetchAllData(getActivity());
    adapter = new SimpleCursorAdapter(getActivity(), layoutstyle, row, column, xml_id, 0) {
        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {

            Cursor row2 = (Cursor) lv.getItemAtPosition(position);
            final String _id = row2.getString(row2.getColumnIndexOrThrow("_id"));
            final String count_title = row2.getString(row2.getColumnIndexOrThrow("count_title"));
            final String count_content = row2.getString(row2.getColumnIndexOrThrow("count_content"));
            final String count_icon = row2.getString(row2.getColumnIndexOrThrow("count_icon"));
            final String count_attachment = row2.getString(row2.getColumnIndexOrThrow("count_attachment"));
            final String count_creation = row2.getString(row2.getColumnIndexOrThrow("count_creation"));

            View v = super.getView(position, convertView, parent);
            final TextView tv = (TextView) v.findViewById(R.id.text);

            if (count_attachment.isEmpty()) {

                tv.setText(count_content);

                new Handler().postDelayed(new Runnable() {
                    public void run() {
                        int n = tv.getLineCount();

                        StringBuilder sb = new StringBuilder(n);
                        for (int i = 0; i < n; ++i) {
                            sb.append("0" + '\n');
                        }
                        String result = sb.toString();

                        db.update(Integer.parseInt(_id), count_title, count_content, count_icon, result,
                                count_creation);
                        setCountList();
                    }
                }, 500);
            }

            ImageView iv_icon = (ImageView) v.findViewById(R.id.icon_notes);
            helper_main.switchIcon(getActivity(), count_icon, "count_icon", iv_icon);

            iv_icon.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {

                    final helper_main.Item[] items = {
                            new helper_main.Item(getString(R.string.note_priority_0), R.drawable.circle_green),
                            new helper_main.Item(getString(R.string.note_priority_1), R.drawable.circle_yellow),
                            new helper_main.Item(getString(R.string.note_priority_2), R.drawable.circle_red), };

                    ListAdapter adapter = new ArrayAdapter<helper_main.Item>(getActivity(),
                            android.R.layout.select_dialog_item, android.R.id.text1, items) {
                        @NonNull
                        public View getView(int position, View convertView, @NonNull ViewGroup parent) {
                            //Use super class to create the View
                            View v = super.getView(position, convertView, parent);
                            TextView tv = (TextView) v.findViewById(android.R.id.text1);
                            tv.setTextSize(18);
                            tv.setCompoundDrawablesWithIntrinsicBounds(items[position].icon, 0, 0, 0);
                            //Add margin between image and text (support various screen densities)
                            int dp5 = (int) (24 * getResources().getDisplayMetrics().density + 0.5f);
                            tv.setCompoundDrawablePadding(dp5);

                            return v;
                        }
                    };

                    new AlertDialog.Builder(getActivity())
                            .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

                                public void onClick(DialogInterface dialog, int whichButton) {
                                    dialog.cancel();
                                }
                            }).setAdapter(adapter, new DialogInterface.OnClickListener() {

                                public void onClick(DialogInterface dialog, int item) {
                                    if (item == 0) {
                                        db.update(Integer.parseInt(_id), count_title, count_content, "3",
                                                count_attachment, count_creation);
                                        setCountList();
                                    } else if (item == 1) {
                                        db.update(Integer.parseInt(_id), count_title, count_content, "2",
                                                count_attachment, count_creation);
                                        setCountList();
                                    } else if (item == 2) {
                                        db.update(Integer.parseInt(_id), count_title, count_content, "1",
                                                count_attachment, count_creation);
                                        setCountList();
                                    }
                                }
                            }).show();
                }
            });
            return v;
        }
    };

    //display data by filter
    final String note_search = sharedPref.getString("filter_countBY", "note_title");
    sharedPref.edit().putString("filter_countBY", "note_title").apply();
    filter.addTextChangedListener(new TextWatcher() {
        public void afterTextChanged(Editable s) {
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        public void onTextChanged(CharSequence s, int start, int before, int count) {
            adapter.getFilter().filter(s.toString());
        }
    });
    adapter.setFilterQueryProvider(new FilterQueryProvider() {
        public Cursor runQuery(CharSequence constraint) {
            return db.fetchDataByFilter(constraint.toString(), note_search);
        }
    });

    lv.setAdapter(adapter);
    //onClick function
    lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterview, View view, int position, long id) {

            if (isFABOpen) {
                closeFABMenu();
            }

            Cursor row2 = (Cursor) lv.getItemAtPosition(position);
            final String _id = row2.getString(row2.getColumnIndexOrThrow("_id"));
            final String count_title = row2.getString(row2.getColumnIndexOrThrow("count_title"));
            final String count_content = row2.getString(row2.getColumnIndexOrThrow("count_content"));
            final String count_icon = row2.getString(row2.getColumnIndexOrThrow("count_icon"));
            final String count_attachment = row2.getString(row2.getColumnIndexOrThrow("count_attachment"));
            final String count_creation = row2.getString(row2.getColumnIndexOrThrow("count_creation"));

            sharedPref.edit().putString("count_title", count_title).apply();
            sharedPref.edit().putString("count_content", count_content).apply();
            sharedPref.edit().putString("count_seqno", _id).apply();
            sharedPref.edit().putString("count_icon", count_icon).apply();
            sharedPref.edit().putString("count_create", count_creation).apply();
            sharedPref.edit().putString("count_attachment", count_attachment).apply();

            helper_main.switchToActivity(getActivity(), Activity_count.class, false);
        }
    });

    lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {

            if (isFABOpen) {
                closeFABMenu();
            }

            Cursor row2 = (Cursor) lv.getItemAtPosition(position);
            final String _id = row2.getString(row2.getColumnIndexOrThrow("_id"));
            final String count_title = row2.getString(row2.getColumnIndexOrThrow("count_title"));
            final String count_content = row2.getString(row2.getColumnIndexOrThrow("count_content"));
            final String count_icon = row2.getString(row2.getColumnIndexOrThrow("count_icon"));
            final String count_attachment = row2.getString(row2.getColumnIndexOrThrow("count_attachment"));
            final String count_creation = row2.getString(row2.getColumnIndexOrThrow("count_creation"));

            final CharSequence[] options = { getString(R.string.number_edit_entry),
                    getString(R.string.bookmark_remove_bookmark), getString(R.string.todo_share),
                    getString(R.string.bookmark_createNote), getString(R.string.bookmark_createEvent) };
            new AlertDialog.Builder(getActivity())
                    .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int whichButton) {
                            dialog.cancel();
                        }
                    }).setItems(options, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int item) {
                            if (options[item].equals(getString(R.string.number_edit_entry))) {

                                AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
                                View dialogView = View.inflate(getActivity(), R.layout.dialog_edit_title, null);

                                final EditText edit_title = (EditText) dialogView.findViewById(R.id.pass_title);
                                edit_title.setHint(R.string.bookmark_edit_title);
                                edit_title.setText(count_title);

                                builder.setView(dialogView);
                                builder.setTitle(R.string.bookmark_edit_title);
                                builder.setPositiveButton(R.string.toast_yes,
                                        new DialogInterface.OnClickListener() {

                                            public void onClick(DialogInterface dialog, int whichButton) {

                                                String inputTag = edit_title.getText().toString().trim();
                                                db.update(Integer.parseInt(_id), inputTag, count_content,
                                                        count_icon, count_attachment, count_creation);
                                                setCountList();
                                                Snackbar.make(lv, R.string.bookmark_added,
                                                        Snackbar.LENGTH_SHORT).show();
                                            }
                                        });
                                builder.setNegativeButton(R.string.toast_cancel,
                                        new DialogInterface.OnClickListener() {

                                            public void onClick(DialogInterface dialog, int whichButton) {
                                                dialog.cancel();
                                            }
                                        });

                                final AlertDialog dialog2 = builder.create();
                                // Display the custom alert dialog on interface
                                dialog2.show();
                                helper_main.showKeyboard(getActivity(), edit_title);
                            }

                            if (options[item].equals(getString(R.string.todo_share))) {
                                Intent sharingIntent = new Intent(Intent.ACTION_SEND);
                                sharingIntent.setType("text/plain");
                                sharingIntent.putExtra(Intent.EXTRA_SUBJECT, count_title);
                                sharingIntent.putExtra(Intent.EXTRA_TEXT, count_content);
                                startActivity(Intent.createChooser(sharingIntent,
                                        (getString(R.string.note_share_2))));
                            }

                            if (options[item].equals(getString(R.string.bookmark_createEvent))) {
                                helper_main.createCalendarEvent(getActivity(), count_title, count_content);
                            }

                            if (options[item].equals(getString(R.string.bookmark_remove_bookmark))) {
                                Snackbar snackbar = Snackbar
                                        .make(lv, R.string.note_remove_confirmation, Snackbar.LENGTH_LONG)
                                        .setAction(R.string.toast_yes, new View.OnClickListener() {
                                            @Override
                                            public void onClick(View view) {
                                                db.delete(Integer.parseInt(_id));
                                                setCountList();
                                            }
                                        });
                                snackbar.show();
                            }

                            if (options[item].equals(getString(R.string.bookmark_createNote))) {
                                Notes_helper.newNote(getActivity(), count_title, count_content, "", "", "", "");
                            }

                        }
                    }).show();

            return true;
        }
    });
}

From source file:com.lgallardo.youtorrentcontroller.TorrentDetailsFragment.java

public void updateDetails(Torrent torrent) {

    try {//from w w w.  j  a  v  a2  s  .co m

        // Hide herderInfo in phone's view
        if (getActivity().findViewById(R.id.one_frame) != null) {
            MainActivity.headerInfo.setVisibility(View.GONE);
        }

        // Get values from current activity
        name = torrent.getFile();
        size = torrent.getSize();
        hash = torrent.getHash();
        ratio = torrent.getRatio();
        state = torrent.getState();
        peersConnected = torrent.getPeersConnected();
        peersInSwarm = torrent.getPeersInSwarm();
        seedsConnected = torrent.getSeedsConnected();
        seedsInSwarm = torrent.getSeedInSwarm();
        progress = torrent.getProgress();
        priority = torrent.getPriority();
        eta = torrent.getEta();
        uploadSpeed = torrent.getUploadSpeed();
        downloadSpeed = torrent.getDownloadSpeed();
        downloaded = torrent.getDownloaded();

        int index = torrent.getProgress().indexOf(".");

        if (index == -1) {
            index = torrent.getProgress().indexOf(",");

            if (index == -1) {
                index = torrent.getProgress().length();
            }
        }

        percentage = torrent.getProgress().substring(0, index);

        int donwloadSpeedWeigth = torrent.getDownloadSpeedWeight();
        int uploadSpeedWeigth = torrent.getUploadSpeedWeight();

        FragmentManager fragmentManager = getFragmentManager();

        TorrentDetailsFragment detailsFragment = null;

        if (getActivity().findViewById(R.id.one_frame) != null) {
            detailsFragment = (TorrentDetailsFragment) fragmentManager.findFragmentByTag("firstFragment");
        } else {
            detailsFragment = (TorrentDetailsFragment) fragmentManager.findFragmentByTag("secondFragment");
        }

        View rootView = detailsFragment.getView();

        TextView nameTextView = (TextView) rootView.findViewById(R.id.torrentName);
        TextView sizeTextView = (TextView) rootView.findViewById(R.id.torrentSize);
        TextView ratioTextView = (TextView) rootView.findViewById(R.id.torrentRatio);
        TextView priorityTextView = (TextView) rootView.findViewById(R.id.torrentPriority);
        TextView stateTextView = (TextView) rootView.findViewById(R.id.torrentState);
        TextView leechsTextView = (TextView) rootView.findViewById(R.id.torrentLeechs);
        TextView seedsTextView = (TextView) rootView.findViewById(R.id.torrentSeeds);
        TextView progressTextView = (TextView) rootView.findViewById(R.id.torrentProgress);
        TextView hashTextView = (TextView) rootView.findViewById(R.id.torrentHash);

        TextView etaTextView = (TextView) rootView.findViewById(R.id.torrentEta);
        TextView uploadSpeedTextView = (TextView) rootView.findViewById(R.id.torrentUploadSpeed);
        TextView downloadSpeedTextView = (TextView) rootView.findViewById(R.id.torrentDownloadSpeed);

        CheckBox sequentialDownloadCheckBox;
        CheckBox firstLAstPiecePrioCheckBox;

        nameTextView.setText(name);
        ratioTextView.setText(ratio);
        stateTextView.setText(state);
        leechsTextView.setText("" + peersConnected + " (" + peersInSwarm + ")");
        seedsTextView.setText("" + seedsConnected + " (" + seedsInSwarm + ")");
        progressTextView.setText(progress);
        hashTextView.setText(hash);
        priorityTextView.setText(priority);
        etaTextView.setText(eta);

        // Set Downloaded vs Total size
        sizeTextView.setText(downloaded + " / " + size);

        // Only for Pro version
        if (MainActivity.packageName.equals("com.lgallardo.youtorrentcontrollerpro")) {
            downloadSpeedTextView.setText(Character.toString('\u2193') + " " + downloadSpeed);
            uploadSpeedTextView.setText(Character.toString('\u2191') + " " + uploadSpeed);

            // Set progress bar
            ProgressBar progressBar = (ProgressBar) rootView.findViewById(R.id.progressBar1);
            TextView percentageTV = (TextView) rootView.findViewById(R.id.percentage);

            progressBar.setProgress(Integer.parseInt(percentage));
            percentageTV.setText(percentage + "%");

        } else {
            downloadSpeedTextView.setText(downloadSpeed);
            uploadSpeedTextView.setText(uploadSpeed);
        }

        nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.error, 0, 0, 0);

        //            Log.d("Debug", "TorrentDetailsFragment - state: " + state);

        if ("paused".equals(state)) {
            nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.paused, 0, 0, 0);
        }

        if ("downloading".equals(state)) {
            nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.stalleddl, 0, 0, 0);

            if (donwloadSpeedWeigth > 0 || seedsConnected > 0 || peersConnected > 0) {
                nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.downloading, 0, 0, 0);
            }
        }

        if ("seeding".equals(state)) {
            nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.stalledup, 0, 0, 0);

            if (uploadSpeedWeigth > 0 || seedsConnected > 0 || peersConnected > 0) {
                nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.uploading, 0, 0, 0);
            }
        }

        if ("queued".equals(state)) {
            nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.queued, 0, 0, 0);
        }

        if ("checking".equals(state)) {
            nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_action_recheck, 0, 0, 0);
        }

        if ("stopped".equals(state)) {
            nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_action_stopped, 0, 0, 0);
        }

        //            // Get Content files in background
        //            qBittorrentContentFile qcf = new qBittorrentContentFile();
        //            qcf.execute(new View[]{rootView});
        //
        //            // Get trackers in background
        //            qBittorrentTrackers qt = new qBittorrentTrackers();
        //            qt.execute(new View[]{rootView});
        //
        //            // Get General info in background
        //            qBittorrentGeneralInfoTask qgit = new qBittorrentGeneralInfoTask();
        //            qgit.execute(new View[]{rootView});

    } catch (Exception e) {

        Log.e("Debug", "TorrentDetailsFragment - onCreateView: " + e.toString());
    }

}

From source file:com.lgallardo.youtorrentcontroller.TorrentDetailsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    // Tell the host activity that your fragment has menu options that it
    // wants to add/replace/delete using the onCreateOptionsMenu method.
    setHasOptionsMenu(true);/*from   www . j  a  v  a  2  s .c  om*/

    View rootView;

    rootView = inflater.inflate(R.layout.torrent_details, container, false);

    // Get Refresh Listener
    refreshListener = (RefreshListener) getActivity();
    mSwipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.details_refresh_layout);

    if (mSwipeRefreshLayout != null) {
        mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                refreshListener.swipeRefresh();
            }
        });
    }

    // Hide herderInfo and title in phone's view
    if (getActivity().findViewById(R.id.one_frame) != null && MainActivity.headerInfo != null) {
        MainActivity.headerInfo.setVisibility(View.GONE);
        //            ((MainActivity) getActivity()).getSupportActionBar().setDisplayShowTitleEnabled(false);

        ((MainActivity) getActivity()).setTitle("");
    }

    savePath = "";
    creationDate = "";
    comment = "";
    uploadRateLimit = "";
    downloadRateLimit = "";
    totalWasted = "";
    totalUploaded = "";
    totalDownloaded = "";
    timeElapsed = "";
    nbConnections = "";
    shareRatio = "";

    try {

        if (savedInstanceState != null) {

            // Get saved values
            name = savedInstanceState.getString("torrentDetailName", "");
            size = savedInstanceState.getString("torrentDetailSize", "");
            hash = savedInstanceState.getString("torrentDetailHash", "");
            ratio = savedInstanceState.getString("torrentDetailRatio", "");
            state = savedInstanceState.getString("torrentDetailState", "");
            peersConnected = savedInstanceState.getInt("torrentDetailPeersConnected", 0);
            peersInSwarm = savedInstanceState.getInt("torrentDetailPeersInSwarm", 0);
            seedsConnected = savedInstanceState.getInt("torrentDetailSeedsConnected", 0);
            seedsInSwarm = savedInstanceState.getInt("torrentDetailSeedsInSwarm", 0);
            progress = savedInstanceState.getString("torrentDetailProgress", "");
            priority = savedInstanceState.getString("torrentDetailPriority", "");
            eta = savedInstanceState.getString("torrentDetailEta", "");
            uploadSpeed = savedInstanceState.getString("torrentDetailUploadSpeed", "");
            downloadSpeed = savedInstanceState.getString("torrentDetailDownloadSpeed", "");
            downloaded = savedInstanceState.getString("torrentDetailDownloaded", "");
            hashToUpdate = hash;

            // Only for Pro version
            if (MainActivity.packageName.equals("com.lgallardo.youtorrentcontrollerpro")) {
                int index = progress.indexOf(".");

                if (index == -1) {
                    index = progress.indexOf(",");

                    if (index == -1) {
                        index = progress.length();
                    }
                }

                percentage = progress.substring(0, index);
            }

        } else {

            // Get values from current activity
            name = this.torrent.getFile();
            size = this.torrent.getSize();
            hash = this.torrent.getHash();
            ratio = this.torrent.getRatio();
            state = this.torrent.getState();
            peersConnected = this.torrent.getPeersConnected();
            peersInSwarm = this.torrent.getPeersInSwarm();
            seedsConnected = this.torrent.getSeedsConnected();
            seedsInSwarm = this.torrent.getSeedInSwarm();
            progress = this.torrent.getProgress();
            priority = this.torrent.getPriority();
            eta = this.torrent.getEta();
            uploadSpeed = this.torrent.getUploadSpeed();
            downloadSpeed = this.torrent.getDownloadSpeed();
            hashToUpdate = hash;
            downloaded = this.torrent.getDownloaded();

            // Only for Pro version
            if (MainActivity.packageName.equals("com.lgallardo.youtorrentcontrollerpro")) {
                int index = this.torrent.getProgress().indexOf(".");

                if (index == -1) {
                    index = this.torrent.getProgress().indexOf(",");

                    if (index == -1) {
                        index = this.torrent.getProgress().length();
                    }
                }

                percentage = this.torrent.getProgress().substring(0, index);
            }
        }

        int donwloadSpeedWeigth = torrent.getDownloadSpeedWeight();
        int uploadSpeedWeigth = torrent.getUploadSpeedWeight();

        TextView nameTextView = (TextView) rootView.findViewById(R.id.torrentName);
        TextView sizeTextView = (TextView) rootView.findViewById(R.id.torrentSize);
        TextView ratioTextView = (TextView) rootView.findViewById(R.id.torrentRatio);
        TextView progressTextView = (TextView) rootView.findViewById(R.id.torrentProgress);
        TextView stateTextView = (TextView) rootView.findViewById(R.id.torrentState);
        TextView priorityTextView = (TextView) rootView.findViewById(R.id.torrentPriority);
        TextView leechsTextView = (TextView) rootView.findViewById(R.id.torrentLeechs);
        TextView seedsTextView = (TextView) rootView.findViewById(R.id.torrentSeeds);
        TextView hashTextView = (TextView) rootView.findViewById(R.id.torrentHash);
        TextView etaTextView = (TextView) rootView.findViewById(R.id.torrentEta);
        TextView uploadSpeedTextView = (TextView) rootView.findViewById(R.id.torrentUploadSpeed);
        TextView downloadSpeedTextView = (TextView) rootView.findViewById(R.id.torrentDownloadSpeed);

        CheckBox sequentialDownloadCheckBox;
        CheckBox firstLAstPiecePrioCheckBox;

        nameTextView.setText(name);
        ratioTextView.setText(ratio);
        stateTextView.setText(state);
        leechsTextView.setText("" + peersConnected + " (" + peersInSwarm + ")");
        seedsTextView.setText("" + seedsConnected + " (" + seedsInSwarm + ")");
        progressTextView.setText(progress);
        hashTextView.setText(hash);
        etaTextView.setText(eta);
        priorityTextView.setText(priority);

        // Set Downloaded vs Total size
        sizeTextView.setText(downloaded + " / " + size);

        // Only for Pro version
        if (MainActivity.packageName.equals("com.lgallardo.youtorrentcontrollerpro")) {
            downloadSpeedTextView.setText(Character.toString('\u2193') + " " + downloadSpeed);
            uploadSpeedTextView.setText(Character.toString('\u2191') + " " + uploadSpeed);

            // Set progress bar
            ProgressBar progressBar = (ProgressBar) rootView.findViewById(R.id.progressBar1);
            TextView percentageTV = (TextView) rootView.findViewById(R.id.percentage);

            progressBar.setProgress(Integer.parseInt(percentage));
            percentageTV.setText(percentage + "%");
        } else {
            downloadSpeedTextView.setText(downloadSpeed);
            uploadSpeedTextView.setText(uploadSpeed);
        }

        nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.error, 0, 0, 0);

        //            Log.d("Debug", "TorrentDetailsFragment - state: " + state);

        if ("paused".equals(state)) {
            nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.paused, 0, 0, 0);
        }

        if ("downloading".equals(state)) {
            nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.stalleddl, 0, 0, 0);

            if (donwloadSpeedWeigth > 0 || seedsConnected > 0 || peersConnected > 0) {
                nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.downloading, 0, 0, 0);
            }
        }

        if ("seeding".equals(state)) {
            nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.stalledup, 0, 0, 0);

            if (uploadSpeedWeigth > 0 || seedsConnected > 0 || peersConnected > 0) {
                nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.uploading, 0, 0, 0);
            }
        }

        if ("queued".equals(state)) {
            nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.queued, 0, 0, 0);
        }

        if ("checking".equals(state)) {
            nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_action_recheck, 0, 0, 0);
        }

        if ("stopped".equals(state)) {
            nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_action_stopped, 0, 0, 0);
        }

        //            // Get Content files in background
        //            qBittorrentContentFile qcf = new qBittorrentContentFile();
        //            qcf.execute(new View[]{rootView});
        //
        //            // Get trackers in background
        //            qBittorrentTrackers qt = new qBittorrentTrackers();
        //            qt.execute(new View[]{rootView});
        //
        //            // Get general info in background
        //            qBittorrentGeneralInfoTask qgit = new qBittorrentGeneralInfoTask();
        //            qgit.execute(new View[]{rootView});

    } catch (Exception e) {
        Log.e("Debug", "TorrentDetailsFragment - onCreateView: " + e.toString());
    }

    if (MainActivity.packageName.equals("com.lgallardo.youtorrentcontroller")) {
        // Load banner
        loadBanner();
    }

    return rootView;
}

From source file:org.telegram.ui.ChatActivity.java

private void setTypingAnimation(boolean start) {
    TextView subtitle = (TextView) parentActivity.findViewById(R.id.action_bar_subtitle);
    if (subtitle == null) {
        final int subtitleId = parentActivity.getResources().getIdentifier("action_bar_subtitle", "id",
                "android");
        subtitle = (TextView) parentActivity.findViewById(subtitleId);
    }// w ww .  j  a v  a  2s.  com
    if (subtitle != null) {
        if (start) {
            try {
                if (currentChat != null) {
                    subtitle.setCompoundDrawablesWithIntrinsicBounds(R.drawable.typing_dots_chat, 0, 0, 0);
                } else {
                    subtitle.setCompoundDrawablesWithIntrinsicBounds(R.drawable.typing_dots, 0, 0, 0);
                }
                subtitle.setCompoundDrawablePadding(Utilities.dp(4));
                AnimationDrawable mAnim = (AnimationDrawable) subtitle.getCompoundDrawables()[0];
                mAnim.setAlpha(200);
                mAnim.start();
            } catch (Exception e) {
                FileLog.e("tmessages", e);
            }
        } else {
            subtitle.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
        }
    }
}

From source file:org.telegram.ui.ChatActivity.java

private void updateSubtitle() {
    if (isFinish) {
        return;//  w w  w  . jav a  2s  .c o  m
    }

    if (paused || getActivity() == null) {
        return;
    }

    ActionBar actionBar = parentActivity.getSupportActionBar();

    TextView title = (TextView) parentActivity.findViewById(R.id.action_bar_title);
    if (title == null) {
        final int subtitleId = parentActivity.getResources().getIdentifier("action_bar_title", "id", "android");
        title = (TextView) parentActivity.findViewById(subtitleId);
    }

    if (currentChat != null) {
        actionBar.setTitle(currentChat.title);
        if (title != null) {
            title.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
            title.setCompoundDrawablePadding(0);
        }
    } else if (currentUser != null) {
        if (currentUser.id != 333000 && ContactsController.Instance.contactsDict.get(currentUser.id) == null
                && (ContactsController.Instance.contactsDict.size() != 0
                        || !ContactsController.Instance.loadingContacts)) {
            if (currentUser.phone != null && currentUser.phone.length() != 0) {
                actionBar.setTitle(PhoneFormat.Instance.format("+" + currentUser.phone));
            } else {
                actionBar.setTitle(Utilities.formatName(currentUser.first_name, currentUser.last_name));
            }
        } else {
            actionBar.setTitle(Utilities.formatName(currentUser.first_name, currentUser.last_name));
        }

        if (title != null) {
            if (currentEncryptedChat != null) {
                title.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_lock_white, 0, 0, 0);
                title.setCompoundDrawablePadding(Utilities.dp(4));
            } else {
                title.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
                title.setCompoundDrawablePadding(0);
            }
        }
    }

    CharSequence printString = MessagesController.Instance.printingStrings.get(dialog_id);
    if (printString == null || printString.length() == 0) {
        lastPrintString = null;
        setTypingAnimation(false);
        if (currentChat != null) {
            if (currentChat instanceof TLRPC.TL_chatForbidden) {
                actionBar.setSubtitle(getStringEntry(R.string.YouWereKicked));
            } else if (currentChat.left) {
                actionBar.setSubtitle(getStringEntry(R.string.YouLeft));
            } else {
                if (onlineCount > 0 && currentChat.participants_count != 0) {
                    actionBar.setSubtitle(String.format("%d %s, %d %s", currentChat.participants_count,
                            getStringEntry(R.string.Members), onlineCount, getStringEntry(R.string.Online)));
                } else {
                    actionBar.setSubtitle(String.format("%d %s", currentChat.participants_count,
                            getStringEntry(R.string.Members)));
                }
            }
        } else if (currentUser != null) {
            if (currentUser.status == null) {
                actionBar.setSubtitle(getStringEntry(R.string.Offline));
            } else {
                int currentTime = ConnectionsManager.Instance.getCurrentTime();
                if (currentUser.status.expires > currentTime || currentUser.status.was_online > currentTime) {
                    actionBar.setSubtitle(getStringEntry(R.string.Online));
                } else {
                    if (currentUser.status.was_online <= 10000 && currentUser.status.expires <= 10000) {
                        actionBar.setSubtitle(getStringEntry(R.string.Invisible));
                    } else {
                        int value = currentUser.status.was_online;
                        if (value == 0) {
                            value = currentUser.status.expires;
                        }
                        actionBar.setSubtitle(Utilities.formatDateOnline(value));
                    }
                }
            }
        }
    } else {
        lastPrintString = printString;
        actionBar.setSubtitle(printString);
        setTypingAnimation(true);
    }
}

From source file:org.telegram.ui.ChatActivity.java

private void fixLayout() {
    if (chatListView != null) {
        ViewTreeObserver obs = chatListView.getViewTreeObserver();
        obs.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
            @Override// w  w w  .  jav  a 2s.c om
            public boolean onPreDraw() {
                if (parentActivity == null) {
                    chatListView.getViewTreeObserver().removeOnPreDrawListener(this);
                    return false;
                }
                WindowManager manager = (WindowManager) ApplicationLoader.applicationContext
                        .getSystemService(Activity.WINDOW_SERVICE);
                Display display = manager.getDefaultDisplay();
                int rotation = display.getRotation();
                int height;
                int currentActionBarHeight = parentActivity.getSupportActionBar().getHeight();

                if (currentActionBarHeight != Utilities.dp(48) && currentActionBarHeight != Utilities.dp(40)) {
                    height = currentActionBarHeight;
                } else {
                    height = Utilities.dp(48);
                    if (rotation == Surface.ROTATION_270 || rotation == Surface.ROTATION_90) {
                        height = Utilities.dp(40);
                    }
                }

                if (avatarImageView != null) {
                    RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) avatarImageView
                            .getLayoutParams();
                    params.width = height;
                    params.height = height;
                    avatarImageView.setLayoutParams(params);
                }

                chatListView.getViewTreeObserver().removeOnPreDrawListener(this);

                if (currentEncryptedChat != null) {
                    TextView title = (TextView) parentActivity.findViewById(R.id.action_bar_title);
                    if (title == null) {
                        final int subtitleId = parentActivity.getResources().getIdentifier("action_bar_title",
                                "id", "android");
                        title = (TextView) parentActivity.findViewById(subtitleId);
                    }
                    if (title != null) {
                        title.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_lock_white, 0, 0, 0);
                        title.setCompoundDrawablePadding(Utilities.dp(4));
                    }
                }

                return false;
            }
        });
    }
}

From source file:edu.cmu.cylab.starslinger.view.HomeActivity.java

protected AlertDialog.Builder xshowChangeSenderOptions(final Activity act, Bundle args) {
    final ArrayList<UseContactItem> items = new ArrayList<UseContactItem>();
    boolean isContactInUse = args.getBoolean(extra.CREATED);
    final String pName = args.getString(extra.NAME);
    byte[] pPhoto = args.getByteArray(extra.PHOTO);
    String pLookupKey = args.getString(extra.CONTACT_LOOKUP_KEY);
    if (!TextUtils.isEmpty(pName)) {
        items.add(new UseContactItem(String.format(act.getString(R.string.menu_UseProfilePerson), pName),
                pPhoto, pLookupKey, UCType.PROFILE));
    }/*from  w w w .  j  a  va2s . c  o  m*/
    int i = 0;
    String cName = args.getString(extra.NAME + i);
    byte[] cPhoto = args.getByteArray(extra.PHOTO + i);
    String cLookupKey = args.getString(extra.CONTACT_LOOKUP_KEY + i);
    while (!TextUtils.isEmpty(cName)) {
        items.add(new UseContactItem(String.format(act.getString(R.string.menu_UseContactPerson), cName),
                cPhoto, cLookupKey, UCType.CONTACT));
        i++;
        cName = args.getString(extra.NAME + i);
        cPhoto = args.getByteArray(extra.PHOTO + i);
        cLookupKey = args.getString(extra.CONTACT_LOOKUP_KEY + i);
    }
    items.add(new UseContactItem(act.getString(R.string.menu_UseNoContact), UCType.NONE));
    items.add(new UseContactItem(act.getString(R.string.menu_UseAnother), UCType.ANOTHER));
    items.add(new UseContactItem(act.getString(R.string.menu_CreateNew), UCType.NEW));
    items.add(new UseContactItem(act.getString(R.string.menu_EditName), UCType.EDIT_NAME));
    if (isContactInUse) {
        items.add(new UseContactItem(act.getString(R.string.menu_EditContact), UCType.EDIT_CONTACT));
    }

    AlertDialog.Builder ad = new AlertDialog.Builder(act);
    ad.setTitle(R.string.title_MyIdentity);
    ad.setOnCancelListener(new DialogInterface.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialog) {
            dialog.dismiss();
        }
    });
    ListAdapter adapter = new ArrayAdapter<UseContactItem>(act, android.R.layout.select_dialog_item,
            android.R.id.text1, items) {
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View v = super.getView(position, convertView, parent);
            TextView tv = (TextView) v.findViewById(android.R.id.text1);
            UseContactItem item = items.get(position);

            if (item.contact) {
                Drawable d;
                if (item.icon != null) {
                    Bitmap bm = BitmapFactory.decodeByteArray(item.icon, 0, item.icon.length, null);
                    d = new BitmapDrawable(getResources(), bm);
                } else {
                    d = getResources().getDrawable(R.drawable.ic_silhouette);
                }
                int avatar_size_list = (int) getResources().getDimension(R.dimen.avatar_size_list);
                d.setBounds(0, 0, avatar_size_list, avatar_size_list);
                tv.setCompoundDrawables(null, null, d, null);
                tv.setCompoundDrawablePadding((int) getResources().getDimension(R.dimen.size_5dp));
            } else {
                tv.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
            }

            return v;
        }
    };
    ad.setAdapter(adapter, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int item) {
            dialog.dismiss();
            switch (items.get(item).type) {
            case PROFILE:
                // user wants to use found profile as a personal contact
                // save these for lookup and display purposes
                SafeSlingerPrefs.setContactName(pName);
                SafeSlingerPrefs.setContactLookupKey(items.get(item).contactLookupKey);
                refreshView();
                break;
            case CONTACT:
                // user wants to use found contact as a personal contact
                SafeSlingerPrefs.setContactName(getContactName(items.get(item).contactLookupKey));
                SafeSlingerPrefs.setContactLookupKey(items.get(item).contactLookupKey);
                refreshView();
                break;
            case ANOTHER:
                // user wants to choose new contact for themselves
                showPickContact(RESULT_PICK_CONTACT_SENDER);
                break;
            case NONE:
                // user wants to remove link to address book
                SafeSlingerPrefs.setContactLookupKey(null);
                refreshView();
                break;
            case NEW:
                // user wants to create new contact
                showAddContact(SafeSlingerPrefs.getContactName());
                break;
            case EDIT_CONTACT:
                // user wants to edit contact
                showEditContact(RESULT_PICK_CONTACT_SENDER);
                break;
            case EDIT_NAME:
                // user wants to edit name
                showSettings();
                refreshView();
                break;
            }
        }
    });

    return ad;
}

From source file:com.lgallardo.qbittorrentclient.TorrentDetailsFragment.java

public void updateDetails(Torrent torrent) {

    //        Log.d("Debug", "Updating details");

    try {//from  ww w. j a va2  s  .  c  o m

        // Hide herderInfo in phone's view
        if (getActivity().findViewById(R.id.one_frame) != null) {
            MainActivity.headerInfo.setVisibility(View.GONE);
        }

        // Get values from current activity
        name = torrent.getFile();
        size = torrent.getSize();
        hash = torrent.getHash();
        ratio = torrent.getRatio();
        state = torrent.getState();
        leechs = torrent.getLeechs();
        seeds = torrent.getSeeds();
        progress = torrent.getProgress();
        priority = torrent.getPriority();
        eta = torrent.getEta();
        uploadSpeed = torrent.getUploadSpeed();
        downloadSpeed = torrent.getDownloadSpeed();
        downloaded = torrent.getDownloaded();
        addedOn = torrent.getAddedOn();
        completionOn = torrent.getCompletionOn();
        label = torrent.getLabel();

        int index = torrent.getProgress().indexOf(".");

        if (index == -1) {
            index = torrent.getProgress().indexOf(",");

            if (index == -1) {
                index = torrent.getProgress().length();
            }
        }

        percentage = torrent.getProgress().substring(0, index);

        FragmentManager fragmentManager = getFragmentManager();

        TorrentDetailsFragment detailsFragment = null;

        if (getActivity().findViewById(R.id.one_frame) != null) {
            detailsFragment = (TorrentDetailsFragment) fragmentManager.findFragmentByTag("firstFragment");
        } else {
            detailsFragment = (TorrentDetailsFragment) fragmentManager.findFragmentByTag("secondFragment");
        }

        View rootView = detailsFragment.getView();

        TextView nameTextView = (TextView) rootView.findViewById(R.id.torrentName);
        TextView sizeTextView = (TextView) rootView.findViewById(R.id.torrentSize);
        TextView ratioTextView = (TextView) rootView.findViewById(R.id.torrentRatio);
        TextView priorityTextView = (TextView) rootView.findViewById(R.id.torrentPriority);
        TextView stateTextView = (TextView) rootView.findViewById(R.id.torrentState);
        TextView leechsTextView = (TextView) rootView.findViewById(R.id.torrentLeechs);
        TextView seedsTextView = (TextView) rootView.findViewById(R.id.torrentSeeds);
        TextView progressTextView = (TextView) rootView.findViewById(R.id.torrentProgress);
        TextView hashTextView = (TextView) rootView.findViewById(R.id.torrentHash);

        TextView etaTextView = (TextView) rootView.findViewById(R.id.torrentEta);
        TextView uploadSpeedTextView = (TextView) rootView.findViewById(R.id.torrentUploadSpeed);
        TextView downloadSpeedTextView = (TextView) rootView.findViewById(R.id.torrentDownloadSpeed);

        CheckBox sequentialDownloadCheckBox;
        CheckBox firstLAstPiecePrioCheckBox;

        nameTextView.setText(name);
        ratioTextView.setText(ratio);
        stateTextView.setText(state);
        leechsTextView.setText(leechs);
        seedsTextView.setText(seeds);
        progressTextView.setText(progress);
        hashTextView.setText(hash);
        priorityTextView.setText(priority);
        etaTextView.setText(eta);

        if (MainActivity.qb_version.equals("3.2.x")) {
            sequentialDownloadCheckBox = (CheckBox) rootView.findViewById(R.id.torrentSequentialDownload);
            firstLAstPiecePrioCheckBox = (CheckBox) rootView.findViewById(R.id.torrentFirstLastPiecePrio);

            sequentialDownloadCheckBox.setChecked(torrent.getSequentialDownload());
            firstLAstPiecePrioCheckBox.setChecked(torrent.getisFirstLastPiecePrio());

            TextView addedOnTextView = (TextView) rootView.findViewById(R.id.torrentAddedOn);
            TextView completionOnTextView = (TextView) rootView.findViewById(R.id.torrentCompletionOn);

            TextView labelTextView = (TextView) rootView.findViewById(R.id.torrentLabel);

            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm");

            if (addedOn != null && !(addedOn.equals("null")) && !(addedOn.equals("4294967295"))) {
                if (Integer.parseInt(MainActivity.qb_api) < 10) {
                    // Old time format 2016-07-25T20:52:07
                    addedOnTextView
                            .setText(new SimpleDateFormat("dd/MM/yyyy - HH:mm").format(sdf.parse(addedOn)));
                } else {
                    // New unix timestamp format 4294967295
                    addedOnTextView.setText(Common.timestampToDate(addedOn));
                }
            } else {
                addedOnTextView.setText("");
            }

            if (completionOn != null && !(completionOn.equals("null"))
                    && !(completionOn.equals("4294967295"))) {

                if (Integer.parseInt(MainActivity.qb_api) < 10) {
                    // Old time format 2016-07-25T20:52:07
                    completionOnTextView.setText(
                            new SimpleDateFormat("dd/MM/yyyy - HH:mm").format(sdf.parse(completionOn)));
                } else {
                    // New unix timestamp format 4294967295
                    completionOnTextView.setText(Common.timestampToDate(completionOn));
                }
            } else {
                completionOnTextView.setText("");
            }

            if (label != null && !(label.equals("null"))) {
                labelTextView.setText(label);
            } else {
                labelTextView.setText("");
            }

        }

        // Set Downloaded vs Total size
        sizeTextView.setText(downloaded + " / " + size);

        // Only for Pro version
        if (MainActivity.packageName.equals("com.lgallardo.qbittorrentclientpro")) {
            downloadSpeedTextView.setText(Character.toString('\u2193') + " " + downloadSpeed);
            uploadSpeedTextView.setText(Character.toString('\u2191') + " " + uploadSpeed);

            // Set progress bar
            ProgressBar progressBar = (ProgressBar) rootView.findViewById(R.id.progressBar1);
            TextView percentageTV = (TextView) rootView.findViewById(R.id.percentage);

            progressBar.setProgress(Integer.parseInt(percentage));
            percentageTV.setText(percentage + "%");

        } else {
            downloadSpeedTextView.setText(downloadSpeed);
            uploadSpeedTextView.setText(uploadSpeed);
        }

        nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_action_recheck, 0, 0, 0);

        if ("pausedUP".equals(state) || "pausedDL".equals(state)) {
            nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.paused, 0, 0, 0);
        }

        if ("stalledUP".equals(state)) {
            nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.stalledup, 0, 0, 0);
        }

        if ("stalledDL".equals(state)) {
            nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.stalleddl, 0, 0, 0);
        }

        if ("downloading".equals(state)) {
            nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.downloading, 0, 0, 0);
        }

        if ("uploading".equals(state) || "forcedUP".equals(state)) {
            nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.uploading, 0, 0, 0);
        }

        if ("queuedDL".equals(state) || "queuedUP".equals(state)) {
            nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.queued, 0, 0, 0);
        }

        if ("checkingDL".equals(state) || "checkingUP".equals(state)) {
            nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_action_recheck, 0, 0, 0);
        }

        if ("error".equals(state) || "missingFiles".equals(state) || "unknown".equals(state)) {
            nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.error, 0, 0, 0);
        }

        //            // Get Content files in background
        ContentFileTask cft = new ContentFileTask();
        cft.execute(new String[] { hash });

        // Get trackers in background
        TrackersTask tt = new TrackersTask();
        tt.execute(new String[] { hash });

        // Get General info labels
        generalInfoItems = new ArrayList<GeneralInfoItem>();

        generalInfoItems.add(new GeneralInfoItem(getString(R.string.torrent_details_save_path), null,
                GeneralInfoItem.GENERALINFO, "generalInfo"));
        generalInfoItems.add(new GeneralInfoItem(getString(R.string.torrent_details_created_date), null,
                GeneralInfoItem.GENERALINFO, "generalInfo"));
        generalInfoItems.add(new GeneralInfoItem(getString(R.string.torrent_details_comment), null,
                GeneralInfoItem.GENERALINFO, "generalInfo"));
        generalInfoItems.add(new GeneralInfoItem(getString(R.string.torrent_details_total_wasted), null,
                GeneralInfoItem.GENERALINFO, "generalInfo"));
        generalInfoItems.add(new GeneralInfoItem(getString(R.string.torrent_details_total_uploaded), null,
                GeneralInfoItem.GENERALINFO, "generalInfo"));
        generalInfoItems.add(new GeneralInfoItem(getString(R.string.torrent_details_total_downloaded), null,
                GeneralInfoItem.GENERALINFO, "generalInfo"));
        generalInfoItems.add(new GeneralInfoItem(getString(R.string.torrent_details_time_elapsed), null,
                GeneralInfoItem.GENERALINFO, "generalInfo"));
        generalInfoItems.add(new GeneralInfoItem(getString(R.string.torrent_details_num_connections), null,
                GeneralInfoItem.GENERALINFO, "generalInfo"));
        generalInfoItems.add(new GeneralInfoItem(getString(R.string.torrent_details_share_ratio), null,
                GeneralInfoItem.GENERALINFO, "generalInfo"));
        generalInfoItems.add(new GeneralInfoItem(getString(R.string.torrent_details_upload_rate_limit), null,
                GeneralInfoItem.GENERALINFO, "generalInfo"));
        generalInfoItems.add(new GeneralInfoItem(getString(R.string.torrent_details_download_rate_limit), null,
                GeneralInfoItem.GENERALINFO, "generalInfo"));

        // Get General info in background;
        GeneralInfoTask git = new GeneralInfoTask();
        git.execute(new String[] { hash });

    } catch (Exception e) {

        Log.e("Debug", "TorrentDetailsFragment - onCreateView: " + e.toString());
    }

}

From source file:com.lgallardo.qbittorrentclient.TorrentDetailsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    // Tell the host activity that your fragment has menu options that it
    // wants to add/replace/delete using the onCreateOptionsMenu method.
    setHasOptionsMenu(true);//w  w  w  .j  av a 2  s. c  o m

    View rootView;

    if (MainActivity.qb_version.equals("3.2.x")) {
        rootView = inflater.inflate(R.layout.torrent_details, container, false);
    } else {
        rootView = inflater.inflate(R.layout.torrent_details_old, container, false);
    }

    mRecyclerView = (RecyclerView) rootView.findViewById(R.id.RecyclerViewContentFiles); // Assigning the RecyclerView Object to the xml View
    rAdapter = new ContentFilesRecyclerViewAdapter((MainActivity) getActivity(), getActivity(),
            new ArrayList<TorrentDetailsItem>());
    rAdapter.notifyDataSetChanged();

    mRecyclerViewTrackers = (RecyclerView) rootView.findViewById(R.id.RecyclerViewTrackers); // Assigning the RecyclerView Object to the xml View
    trackerAdapter = new TrackersRecyclerViewAdapter((MainActivity) getActivity(), getActivity(),
            new ArrayList<TorrentDetailsItem>());
    trackerAdapter.notifyDataSetChanged();

    mRecyclerViewGeneralInfo = (RecyclerView) rootView.findViewById(R.id.RecyclerViewGeneralInfo); // Assigning the RecyclerView Object to the xml View
    generalInfoAdapter = new GeneralInfoRecyclerViewAdapter((MainActivity) getActivity(), getActivity(),
            new ArrayList<GeneralInfoItem>());
    generalInfoAdapter.notifyDataSetChanged();

    if (mRecyclerView == null) {
        Log.d("Debug", "mRecyclerView is null");
    }

    if (rAdapter == null) {
        Log.d("Debug", "rAdapter is null");
    }

    try {
        mRecyclerView.setAdapter(rAdapter);
        mRecyclerViewTrackers.setAdapter(trackerAdapter);
        mRecyclerViewGeneralInfo.setAdapter(generalInfoAdapter);

        mLayoutManager = new LinearLayoutManager(rootView.getContext()); // Creating a layout Manager
        mLayoutManagerTrackers = new LinearLayoutManager(rootView.getContext()); // Creating a layout Manager
        mLayoutManagerGeneralInfo = new LinearLayoutManager(rootView.getContext()); // Creating a layout Manager

        mRecyclerView.setLayoutManager(mLayoutManager); // Setting the layout Manager
        mRecyclerViewTrackers.setLayoutManager(mLayoutManagerTrackers); // Setting the layout Manager
        mRecyclerViewGeneralInfo.setLayoutManager(mLayoutManagerGeneralInfo); // Setting the layout Manager
    } catch (Exception e) {
        Log.e("Debug", e.toString());
    }

    // TODO: Check if this can be removed
    registerForContextMenu(mRecyclerView);
    //        registerForContextMenu(mRecyclerViewTrackers);
    //        registerForContextMenu(mRecyclerViewGeneralInfo);

    // Get Refresh Listener
    refreshListener = (RefreshListener) getActivity();
    mSwipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.details_refresh_layout);

    if (mSwipeRefreshLayout != null) {
        mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                refreshListener.swipeRefresh();
            }
        });
    }

    // Hide herderInfo and title in phone's view
    if (getActivity().findViewById(R.id.one_frame) != null && MainActivity.headerInfo != null) {
        MainActivity.headerInfo.setVisibility(View.GONE);

        ((MainActivity) getActivity()).setTitle("");
    }

    savePath = "";
    creationDate = "";
    comment = "";
    uploadRateLimit = "";
    downloadRateLimit = "";
    totalWasted = "";
    totalUploaded = "";
    totalDownloaded = "";
    timeElapsed = "";
    nbConnections = "";
    shareRatio = "";

    try {

        if (savedInstanceState != null) {

            // Get saved values
            name = savedInstanceState.getString("torrentDetailName", "");
            size = savedInstanceState.getString("torrentDetailSize", "");
            hash = savedInstanceState.getString("torrentDetailHash", "");
            ratio = savedInstanceState.getString("torrentDetailRatio", "");
            state = savedInstanceState.getString("torrentDetailState", "");
            leechs = savedInstanceState.getString("torrentDetailLeechs", "");
            seeds = savedInstanceState.getString("torrentDetailSeeds", "");
            progress = savedInstanceState.getString("torrentDetailProgress", "");
            priority = savedInstanceState.getString("torrentDetailPriority", "");
            eta = savedInstanceState.getString("torrentDetailEta", "");
            uploadSpeed = savedInstanceState.getString("torrentDetailUploadSpeed", "");
            downloadSpeed = savedInstanceState.getString("torrentDetailDownloadSpeed", "");
            downloaded = savedInstanceState.getString("torrentDetailDownloaded", "");
            addedOn = savedInstanceState.getString("torrentDetailsAddedOn", "");
            completionOn = savedInstanceState.getString("torrentDetailsCompletionOn", "");
            label = savedInstanceState.getString("torrentDetailsLabel", "");
            hashToUpdate = hash;

            // Only for Pro version
            if (MainActivity.packageName.equals("com.lgallardo.qbittorrentclientpro")) {
                int index = progress.indexOf(".");

                if (index == -1) {
                    index = progress.indexOf(",");

                    if (index == -1) {
                        index = progress.length();
                    }
                }

                percentage = progress.substring(0, index);
            }

        } else {

            // Get values from current activity
            name = this.torrent.getFile();
            size = this.torrent.getSize();
            hash = this.torrent.getHash();
            ratio = this.torrent.getRatio();
            state = this.torrent.getState();
            leechs = this.torrent.getLeechs();
            seeds = this.torrent.getSeeds();
            progress = this.torrent.getProgress();
            priority = this.torrent.getPriority();
            eta = this.torrent.getEta();
            uploadSpeed = this.torrent.getUploadSpeed();
            downloadSpeed = this.torrent.getDownloadSpeed();
            downloaded = this.torrent.getDownloaded();
            addedOn = this.torrent.getAddedOn();
            completionOn = this.torrent.getCompletionOn();
            label = this.torrent.getLabel();

            hashToUpdate = hash;

            // Only for Pro version
            if (MainActivity.packageName.equals("com.lgallardo.qbittorrentclientpro")) {
                int index = this.torrent.getProgress().indexOf(".");

                if (index == -1) {
                    index = this.torrent.getProgress().indexOf(",");

                    if (index == -1) {
                        index = this.torrent.getProgress().length();
                    }
                }

                percentage = this.torrent.getProgress().substring(0, index);
            }
        }

        TextView nameTextView = (TextView) rootView.findViewById(R.id.torrentName);
        TextView sizeTextView = (TextView) rootView.findViewById(R.id.torrentSize);
        TextView ratioTextView = (TextView) rootView.findViewById(R.id.torrentRatio);
        TextView progressTextView = (TextView) rootView.findViewById(R.id.torrentProgress);
        TextView stateTextView = (TextView) rootView.findViewById(R.id.torrentState);
        TextView priorityTextView = (TextView) rootView.findViewById(R.id.torrentPriority);
        TextView leechsTextView = (TextView) rootView.findViewById(R.id.torrentLeechs);
        TextView seedsTextView = (TextView) rootView.findViewById(R.id.torrentSeeds);
        TextView hashTextView = (TextView) rootView.findViewById(R.id.torrentHash);
        TextView etaTextView = (TextView) rootView.findViewById(R.id.torrentEta);
        TextView uploadSpeedTextView = (TextView) rootView.findViewById(R.id.torrentUploadSpeed);
        TextView downloadSpeedTextView = (TextView) rootView.findViewById(R.id.torrentDownloadSpeed);

        CheckBox sequentialDownloadCheckBox;
        CheckBox firstLAstPiecePrioCheckBox;

        nameTextView.setText(name);
        ratioTextView.setText(ratio);
        stateTextView.setText(state);
        leechsTextView.setText(leechs);
        seedsTextView.setText(seeds);
        progressTextView.setText(progress);
        hashTextView.setText(hash);
        etaTextView.setText(eta);
        priorityTextView.setText(priority);

        if (MainActivity.qb_version.equals("3.2.x")) {
            sequentialDownloadCheckBox = (CheckBox) rootView.findViewById(R.id.torrentSequentialDownload);
            firstLAstPiecePrioCheckBox = (CheckBox) rootView.findViewById(R.id.torrentFirstLastPiecePrio);

            sequentialDownloadCheckBox.setChecked(this.torrent.getSequentialDownload());
            firstLAstPiecePrioCheckBox.setChecked(this.torrent.getisFirstLastPiecePrio());

            TextView addedOnTextView = (TextView) rootView.findViewById(R.id.torrentAddedOn);
            TextView completionOnTextView = (TextView) rootView.findViewById(R.id.torrentCompletionOn);
            TextView labelTextView = (TextView) rootView.findViewById(R.id.torrentLabel);

            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm");

            if (addedOn != null && !(addedOn.equals("null")) && !(addedOn.equals("4294967295"))) {
                if (Integer.parseInt(MainActivity.qb_api) < 10) {
                    // Old time format 2016-07-25T20:52:07
                    addedOnTextView
                            .setText(new SimpleDateFormat("dd/MM/yyyy - HH:mm").format(sdf.parse(addedOn)));
                } else {
                    // New unix timestamp format 4294967295
                    addedOnTextView.setText(Common.timestampToDate(addedOn));
                }
            } else {
                addedOnTextView.setText("");
            }

            if (completionOn != null && !(completionOn.equals("null"))
                    && !(completionOn.equals("4294967295"))) {

                if (Integer.parseInt(MainActivity.qb_api) < 10) {
                    // Old time format 2016-07-25T20:52:07
                    completionOnTextView.setText(
                            new SimpleDateFormat("dd/MM/yyyy - HH:mm").format(sdf.parse(completionOn)));
                } else {
                    // New unix timestamp format 4294967295
                    completionOnTextView.setText(Common.timestampToDate(completionOn));
                }
            } else {
                completionOnTextView.setText("");
            }

            if (label != null && !(label.equals("null"))) {
                labelTextView.setText(label);
            } else {
                labelTextView.setText("");
            }

        }

        // Set Downloaded vs Total size
        sizeTextView.setText(downloaded + " / " + size);

        // Only for Pro version
        if (MainActivity.packageName.equals("com.lgallardo.qbittorrentclientpro")) {
            downloadSpeedTextView.setText(Character.toString('\u2193') + " " + downloadSpeed);
            uploadSpeedTextView.setText(Character.toString('\u2191') + " " + uploadSpeed);

            // Set progress bar
            ProgressBar progressBar = (ProgressBar) rootView.findViewById(R.id.progressBar1);
            TextView percentageTV = (TextView) rootView.findViewById(R.id.percentage);

            progressBar.setProgress(Integer.parseInt(percentage));
            percentageTV.setText(percentage + "%");
        } else {
            downloadSpeedTextView.setText(downloadSpeed);
            uploadSpeedTextView.setText(uploadSpeed);
        }

        nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_action_recheck, 0, 0, 0);

        // Set status icon
        if ("pausedUP".equals(state) || "pausedDL".equals(state)) {
            nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.paused, 0, 0, 0);
        }

        if ("stalledUP".equals(state)) {
            nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.stalledup, 0, 0, 0);
        }

        if ("stalledDL".equals(state)) {
            nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.stalleddl, 0, 0, 0);
        }

        if ("downloading".equals(state)) {
            nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.downloading, 0, 0, 0);
        }

        if ("uploading".equals(state) || "forcedUP".equals(state)) {
            nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.uploading, 0, 0, 0);
        }

        if ("queuedDL".equals(state) || "queuedUP".equals(state)) {
            nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.queued, 0, 0, 0);
        }

        if ("checkingDL".equals(state) || "checkingUP".equals(state)) {
            nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_action_recheck, 0, 0, 0);
        }

        if ("error".equals(state) || "missingFiles".equals(state) || "unknown".equals(state)) {
            nameTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.error, 0, 0, 0);
        }

        // Get Content files in background
        ContentFileTask cft = new ContentFileTask();
        cft.execute(new String[] { hash });

        // Get trackers in background
        TrackersTask tt = new TrackersTask();
        tt.execute(new String[] { hash });

        // Get General info labels
        generalInfoItems = new ArrayList<GeneralInfoItem>();

        generalInfoItems.add(new GeneralInfoItem(getString(R.string.torrent_details_save_path), null,
                GeneralInfoItem.GENERALINFO, "generalInfo"));
        generalInfoItems.add(new GeneralInfoItem(getString(R.string.torrent_details_created_date), null,
                GeneralInfoItem.GENERALINFO, "generalInfo"));
        generalInfoItems.add(new GeneralInfoItem(getString(R.string.torrent_details_comment), null,
                GeneralInfoItem.GENERALINFO, "generalInfo"));
        generalInfoItems.add(new GeneralInfoItem(getString(R.string.torrent_details_total_wasted), null,
                GeneralInfoItem.GENERALINFO, "generalInfo"));
        generalInfoItems.add(new GeneralInfoItem(getString(R.string.torrent_details_total_uploaded), null,
                GeneralInfoItem.GENERALINFO, "generalInfo"));
        generalInfoItems.add(new GeneralInfoItem(getString(R.string.torrent_details_total_downloaded), null,
                GeneralInfoItem.GENERALINFO, "generalInfo"));
        generalInfoItems.add(new GeneralInfoItem(getString(R.string.torrent_details_time_elapsed), null,
                GeneralInfoItem.GENERALINFO, "generalInfo"));
        generalInfoItems.add(new GeneralInfoItem(getString(R.string.torrent_details_num_connections), null,
                GeneralInfoItem.GENERALINFO, "generalInfo"));
        generalInfoItems.add(new GeneralInfoItem(getString(R.string.torrent_details_share_ratio), null,
                GeneralInfoItem.GENERALINFO, "generalInfo"));
        generalInfoItems.add(new GeneralInfoItem(getString(R.string.torrent_details_upload_rate_limit), null,
                GeneralInfoItem.GENERALINFO, "generalInfo"));
        generalInfoItems.add(new GeneralInfoItem(getString(R.string.torrent_details_download_rate_limit), null,
                GeneralInfoItem.GENERALINFO, "generalInfo"));

        // Get general info in background
        GeneralInfoTask git = new GeneralInfoTask();
        git.execute(new String[] { hash });

    } catch (Exception e) {
        Log.e("Debug", "TorrentDetailsFragment - onCreateView: " + e.toString());
    }

    if (MainActivity.packageName.equals("com.lgallardo.qbittorrentclient")) {
        // Load banner
        loadBanner();
    }

    return rootView;
}