Example usage for android.widget ImageView setVisibility

List of usage examples for android.widget ImageView setVisibility

Introduction

In this page you can find the example usage for android.widget ImageView setVisibility.

Prototype

@RemotableViewMethod
    @Override
    public void setVisibility(int visibility) 

Source Link

Usage

From source file:de.baumann.hhsmoodle.popup.Popup_note.java

private void setNotesList() {

    //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[] { "note_title", "note_content", "note_creation" };
    final String search = sharedPref.getString("filter_note_subject", "");
    final Cursor row = db.fetchDataByFilter(search, "note_title");

    SimpleCursorAdapter adapter = new SimpleCursorAdapter(Popup_note.this, layoutstyle, row, column, xml_id,
            0) {/* w  ww  .java2 s  .c o  m*/
        @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 note_title = row2.getString(row2.getColumnIndexOrThrow("note_title"));
            final String note_content = row2.getString(row2.getColumnIndexOrThrow("note_content"));
            final String note_icon = row2.getString(row2.getColumnIndexOrThrow("note_icon"));
            final String note_attachment = row2.getString(row2.getColumnIndexOrThrow("note_attachment"));
            final String note_creation = row2.getString(row2.getColumnIndexOrThrow("note_creation"));

            View v = super.getView(position, convertView, parent);
            ImageView iv_icon = (ImageView) v.findViewById(R.id.icon_notes);
            ImageView iv_attachment = (ImageView) v.findViewById(R.id.att_notes);

            switch (note_icon) {
            case "3":
                iv_icon.setImageResource(R.drawable.circle_green);
                break;
            case "2":
                iv_icon.setImageResource(R.drawable.circle_yellow);
                break;
            case "1":
                iv_icon.setImageResource(R.drawable.circle_red);
                break;
            }

            switch (note_attachment) {
            case "":
                iv_attachment.setVisibility(View.GONE);
                break;
            default:
                iv_attachment.setVisibility(View.VISIBLE);
                iv_attachment.setImageResource(R.drawable.ic_attachment);
                break;
            }

            File file = new File(note_attachment);
            if (!file.exists()) {
                iv_attachment.setVisibility(View.GONE);
            }

            iv_icon.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {

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

                    ListAdapter adapter = new ArrayAdapter<Item>(Popup_note.this,
                            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(Popup_note.this)
                            .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), note_title, note_content, "3",
                                                note_attachment, note_creation);
                                        setNotesList();
                                    } else if (item == 1) {
                                        db.update(Integer.parseInt(_id), note_title, note_content, "2",
                                                note_attachment, note_creation);
                                        setNotesList();
                                    } else if (item == 2) {
                                        db.update(Integer.parseInt(_id), note_title, note_content, "1",
                                                note_attachment, note_creation);
                                        setNotesList();
                                    }
                                }
                            }).show();
                }
            });
            iv_attachment.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    helper_main.openAtt(Popup_note.this, lv, note_attachment);
                }
            });
            return v;
        }
    };

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

            Cursor row2 = (Cursor) lv.getItemAtPosition(position);
            final String _id = row2.getString(row2.getColumnIndexOrThrow("_id"));
            final String note_title = row2.getString(row2.getColumnIndexOrThrow("note_title"));
            final String note_content = row2.getString(row2.getColumnIndexOrThrow("note_content"));
            final String note_icon = row2.getString(row2.getColumnIndexOrThrow("note_icon"));
            final String note_attachment = row2.getString(row2.getColumnIndexOrThrow("note_attachment"));
            final String note_creation = row2.getString(row2.getColumnIndexOrThrow("note_creation"));

            final Button attachment2;
            final TextView textInput;

            LayoutInflater inflater = Popup_note.this.getLayoutInflater();

            final ViewGroup nullParent = null;
            final View dialogView = inflater.inflate(R.layout.dialog_note_show, nullParent);

            final String attName = note_attachment.substring(note_attachment.lastIndexOf("/") + 1);
            final String att = getString(R.string.app_att) + ": " + attName;

            attachment2 = (Button) dialogView.findViewById(R.id.button_att);
            if (attName.equals("")) {
                attachment2.setVisibility(View.GONE);
            } else {
                attachment2.setText(att);
            }
            File file2 = new File(note_attachment);
            if (!file2.exists()) {
                attachment2.setVisibility(View.GONE);
            }

            textInput = (TextView) dialogView.findViewById(R.id.note_text_input);
            textInput.setText(note_content);
            Linkify.addLinks(textInput, Linkify.WEB_URLS);

            attachment2.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    helper_main.openAtt(Popup_note.this, lv, note_attachment);
                }
            });

            final ImageView be = (ImageView) dialogView.findViewById(R.id.imageButtonPri);

            switch (note_icon) {
            case "3":
                be.setImageResource(R.drawable.circle_green);
                break;
            case "2":
                be.setImageResource(R.drawable.circle_yellow);
                break;
            case "1":
                be.setImageResource(R.drawable.circle_red);
                break;
            }

            android.app.AlertDialog.Builder dialog = new android.app.AlertDialog.Builder(Popup_note.this)
                    .setTitle(note_title).setView(dialogView)
                    .setPositiveButton(R.string.toast_yes, new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int whichButton) {
                            dialog.cancel();
                        }
                    }).setNegativeButton(R.string.note_edit, new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int whichButton) {
                            sharedPref.edit().putString("handleTextTitle", note_title)
                                    .putString("handleTextText", note_content)
                                    .putString("handleTextIcon", note_icon).putString("handleTextSeqno", _id)
                                    .putString("handleTextAttachment", note_attachment)
                                    .putString("handleTextCreate", note_creation).apply();
                            helper_main.switchToActivity(Popup_note.this, Activity_EditNote.class, false);
                        }
                    });
            dialog.show();
        }
    });

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

            Cursor row2 = (Cursor) lv.getItemAtPosition(position);
            final String _id = row2.getString(row2.getColumnIndexOrThrow("_id"));
            final String note_title = row2.getString(row2.getColumnIndexOrThrow("note_title"));
            final String note_content = row2.getString(row2.getColumnIndexOrThrow("note_content"));
            final String note_icon = row2.getString(row2.getColumnIndexOrThrow("note_icon"));
            final String note_attachment = row2.getString(row2.getColumnIndexOrThrow("note_attachment"));
            final String note_creation = row2.getString(row2.getColumnIndexOrThrow("note_creation"));

            final CharSequence[] options = { getString(R.string.note_edit), getString(R.string.note_share),
                    getString(R.string.todo_menu), getString(R.string.bookmark_createEvent),
                    getString(R.string.note_remove_note) };
            new AlertDialog.Builder(Popup_note.this)
                    .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.note_edit))) {
                                sharedPref.edit().putString("handleTextTitle", note_title)
                                        .putString("handleTextText", note_content)
                                        .putString("handleTextIcon", note_icon)
                                        .putString("handleTextSeqno", _id)
                                        .putString("handleTextAttachment", note_attachment)
                                        .putString("handleTextCreate", note_creation).apply();
                                helper_main.switchToActivity(Popup_note.this, Activity_EditNote.class, false);
                            }

                            if (options[item].equals(getString(R.string.note_share))) {
                                File attachment = new File(note_attachment);
                                Intent sharingIntent = new Intent(Intent.ACTION_SEND);
                                sharingIntent.setType("text/plain");
                                sharingIntent.putExtra(Intent.EXTRA_SUBJECT, note_title);
                                sharingIntent.putExtra(Intent.EXTRA_TEXT, note_content);

                                if (attachment.exists()) {
                                    Uri bmpUri = Uri.fromFile(attachment);
                                    sharingIntent.putExtra(Intent.EXTRA_STREAM, bmpUri);
                                }

                                startActivity(Intent.createChooser(sharingIntent,
                                        (getString(R.string.note_share_2))));
                            }

                            if (options[item].equals(getString(R.string.todo_menu))) {

                                Todo_DbAdapter db = new Todo_DbAdapter(Popup_note.this);
                                db.open();
                                if (db.isExist(note_title)) {
                                    Snackbar.make(lv, getString(R.string.toast_newTitle), Snackbar.LENGTH_LONG)
                                            .show();
                                } else {
                                    db.insert(note_title, note_content, "3", "true", helper_main.createDate());
                                    ViewPager viewPager = (ViewPager) Popup_note.this
                                            .findViewById(R.id.viewpager);
                                    viewPager.setCurrentItem(2);
                                    Popup_note.this.setTitle(R.string.todo_title);
                                    dialog.dismiss();
                                }
                            }

                            if (options[item].equals(getString(R.string.bookmark_createEvent))) {
                                Intent calIntent = new Intent(Intent.ACTION_INSERT);
                                calIntent.setType("vnd.android.cursor.item/event");
                                calIntent.putExtra(CalendarContract.Events.TITLE, note_title);
                                calIntent.putExtra(CalendarContract.Events.DESCRIPTION, note_content);
                                startActivity(calIntent);
                            }

                            if (options[item].equals(getString(R.string.note_remove_note))) {
                                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));
                                                setNotesList();
                                            }
                                        });
                                snackbar.show();
                            }
                        }
                    }).show();

            return true;
        }
    });

    if (lv.getAdapter().getCount() == 0) {
        new android.app.AlertDialog.Builder(this)
                .setMessage(helper_main.textSpannable(getString(R.string.toast_noEntry)))
                .setPositiveButton(this.getString(R.string.toast_yes), new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        finish();
                    }
                }).show();
        new Handler().postDelayed(new Runnable() {
            public void run() {
                finish();
            }
        }, 2000);
    }
}

From source file:com.android.systemui.statusbar.phone.NavigationBarView.java

private void addLightsOutButton(LinearLayout root, View v, boolean landscape, boolean empty) {

    ImageView addMe = new ImageView(mContext);
    addMe.setLayoutParams(v.getLayoutParams());
    addMe.setImageResource(/*  w ww .j a  va 2  s .  com*/
            empty ? R.drawable.ic_sysbar_lights_out_dot_large : R.drawable.ic_sysbar_lights_out_dot_small);
    addMe.setScaleType(ImageView.ScaleType.CENTER);
    addMe.setVisibility(empty ? View.INVISIBLE : View.VISIBLE);

    if (landscape)
        root.addView(addMe, 0);
    else
        root.addView(addMe);

}

From source file:com.mobicage.rogerthat.util.ui.SendMessageView.java

private ImageView generateImageView(final int imageButton, final int visible) {
    ImageView iv = new ImageView(mActivity);
    iv.setVisibility(visible);
    final int imageResourse = getImageResourceForKey(imageButton);
    if (imageResourse != 0)
        iv.setImageResource(imageResourse);
    iv.setOnClickListener(new SafeViewOnClickListener() {
        @Override//  ww w.jav  a  2s . com
        public void safeOnClick(View v) {
            processOnClickListenerForKey(imageButton);
        }
    });

    if (IMAGE_BUTTON_TEXT == imageButton) {
        iv.setColorFilter(UIUtils.imageColorFilter(ContextCompat.getColor(mActivity, R.color.mc_divider_gray)));
    }

    iv.setPadding(_5_DP_IN_PX, _5_DP_IN_PX, _5_DP_IN_PX, _5_DP_IN_PX);
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(_30_DP_IN_PX, _30_DP_IN_PX, 1.0f);
    iv.setLayoutParams(lp);
    return iv;
}

From source file:es.upv.riromu.arbre.main.MainActivity.java

private void setVisibility() {

    TextView imc = (TextView) findViewById(R.id.textView);
    imc.setVisibility(View.GONE);
    ImageButton sendButton = (ImageButton) findViewById(R.id.button_send);
    sendButton.setVisibility(View.GONE);
    ImageButton histButton = (ImageButton) findViewById(R.id.button_histogram);
    histButton.setVisibility(View.GONE);
    ImageButton revertButton = (ImageButton) findViewById(R.id.button_revert);
    revertButton.setVisibility(View.GONE);
    ImageView imagePalette = (ImageView) findViewById(R.id.palette);
    imagePalette.setVisibility(View.GONE);
}

From source file:de.tudarmstadt.informatik.secuso.phishedu2.PhishBaseActivity.java

protected void updateScore(View view) {
    if (view == null) {
        return;/*w  ww.j a v a 2s.c om*/
    }
    RelativeLayout scores = (RelativeLayout) view.findViewById(R.id.score_relative);
    if (scores != null) {
        TextView urlsText = (TextView) scores.findViewById(R.id.urls);
        TextView urlsGoalText = (TextView) scores.findViewById(R.id.urls_goal);
        ImageView lifeOne = (ImageView) scores.findViewById(R.id.life_1);
        ImageView lifeTwo = (ImageView) scores.findViewById(R.id.life_2);
        ImageView lifeThree = (ImageView) scores.findViewById(R.id.life_3);
        TextView LevelScoreText = (TextView) scores.findViewById(R.id.level_score);

        urlsText.setText(Integer.toString(BackendControllerImpl.getInstance().getCorrectlyFoundURLs()));
        urlsGoalText.setText(
                Integer.toString(BackendControllerImpl.getInstance().getLevelInfo().levelCorrectURLs()));
        LevelScoreText.setText(Integer.toString(BackendControllerImpl.getInstance().getLevelPoints()));

        int remaininLives = BackendControllerImpl.getInstance().getLifes();

        //now hide hearts if required
        switch (remaininLives) {
        case 0:
            //hide all hearts
            lifeOne.setVisibility(View.INVISIBLE);
            lifeTwo.setVisibility(View.INVISIBLE);
            lifeThree.setVisibility(View.INVISIBLE);
            break;
        case 1:
            //hide heart 1 and 2
            lifeOne.setVisibility(View.INVISIBLE);
            lifeTwo.setVisibility(View.INVISIBLE);
            break;
        case 2:
            //hide only heart 1
            lifeOne.setVisibility(View.INVISIBLE);
        default:
            break;
        }
    }
}

From source file:com.bexkat.feedlib.ItemListFragment.java

@Override
public void onActivityCreated(Bundle saveInstanceState) {
    String[] from = new String[] { ItemTable.COLUMN_TITLE, ItemTable.COLUMN_PUBDATE, ItemTable.COLUMN_READ,
            ItemTable.COLUMN_FAVORITE };
    int[] to = new int[] { R.id.row_title, R.id.row_pubdate, R.id.row_status, R.id.row_status };

    super.onActivityCreated(saveInstanceState);

    getListView().setOnItemLongClickListener(new OnItemLongClickListener() {

        @Override//from  ww  w . j  a va2 s .co  m
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            if (mActionMode != null) {
                return false;
            }
            ItemTable db = new ItemTable(getSherlockActivity());
            selectedItem = db.getItem(id);
            // Start the CAB using the ActionMode.Callback defined above
            mActionMode = getSherlockActivity().startActionMode(mActionModeCallback);
            view.setSelected(true);
            return true;
        }
    });

    mCursorAdapter = new SimpleCursorAdapter(getActivity(), R.layout.item_list, null, from, to,
            SimpleCursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
    mCursorAdapter.setViewBinder(new ViewBinder() {

        @Override
        public boolean setViewValue(View v, Cursor c, int index) {
            if (index == c.getColumnIndex(ItemTable.COLUMN_READ)) {
                ImageView iv = (ImageView) v;
                if (c.getInt(index) == DatabaseHelper.OFF)
                    iv.setImageResource(R.drawable.unread);
                return true;
            }
            if (index == c.getColumnIndex(ItemTable.COLUMN_PUBDATE)) {
                String date = mFormat.format(new Date(Long.parseLong(c.getString(index))));
                ((TextView) v).setText(date);
                return true;
            }
            if (index == c.getColumnIndex(ItemTable.COLUMN_FAVORITE)) {
                ImageView iv = (ImageView) v;
                if (c.getInt(index) == DatabaseHelper.ON)
                    iv.setImageResource(R.drawable.ic_favorite);
                if (c.getInt(c.getColumnIndex(ItemTable.COLUMN_READ)) == DatabaseHelper.ON
                        && c.getInt(index) == DatabaseHelper.OFF)
                    iv.setVisibility(View.INVISIBLE);
                else
                    iv.setVisibility(View.VISIBLE);
                return true;
            }
            return false;
        }

    });
    setListAdapter(mCursorAdapter);
    getLoaderManager().initLoader(0, null, this);
}

From source file:es.upv.riromu.arbre.main.MainActivity.java

public void showHistogram(View view) throws IOException {

    state[SHOW_HISTOGRAM] = true;//from   w  w w .  j  a  v  a 2s.  co  m

    // TextView imc = (TextView) findViewById(R.id.textView);
    //  imc.setBackgroundColor(Color.rgb(colours[COLOUR_R], colours[COLOUR_G], colours[COLOUR_B]));
    RangeSeekBar<Integer> rangeSeekBar = (RangeSeekBar<Integer>) findViewById(R.id.rangeseekbar);
    rangeSeekBar.setVisibility(View.GONE);
    ImageButton histButton = (ImageButton) findViewById(R.id.button_histogram);
    histButton.setVisibility(View.GONE);
    ImageButton revertButton = (ImageButton) findViewById(R.id.button_revert);
    revertButton.setVisibility(View.VISIBLE);
    ImageView imagePalette = (ImageView) findViewById(R.id.palette);
    imagePalette.setVisibility(View.GONE);
    ImageView imv = (ImageView) findViewById(R.id.image_intro);
    imv.setImageBitmap(histogram);

}

From source file:net.inbox.InboxMessage.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == 19091) {
        crypto_locked = true;//from www .ja v a  2 s.  co  m
        iv_gpg_crypto.setImageResource(R.drawable.padlock_open_inverse);
        msg_signature = data.getStringExtra("msg-signature");
        if (data.getIntExtra("ret-code", 0) == 92) {
            msg_contents = data.getStringExtra("message-crypto");

            // MIME parsing
            gpg_mime_parsing();
        }
        if (msg_signature != null && msg_signature.length() > 0) {
            final AppCompatActivity ct = this;
            ImageView iv_gpg_signature = (ImageView) findViewById(R.id.iv_gpg_signature);
            iv_gpg_signature.setVisibility(View.VISIBLE);
            iv_gpg_signature.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    Dialogs.dialog_server_ext(getString(R.string.open_pgp_message_signature), msg_signature,
                            ct);
                }
            });
        }
    }
}

From source file:org.tigase.mobile.accountstatus.AccountsStatusFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    this.view = inflater.inflate(R.layout.account_status, null);

    this.adapter = new ArrayAdapter<Jaxmpp>(getActivity().getApplicationContext(),
            R.layout.account_status_item) {

        @Override//from  w w  w  . j  ava2  s  .  c  o m
        public View getView(int position, View convertView, ViewGroup parent) {
            View v = convertView;
            if (v == null) {
                v = inflater.inflate(R.layout.account_status_item, null);
            }

            Jaxmpp jaxmpp = getItem(position);

            final TextView accountName = (TextView) v.findViewById(R.id.account_name);
            final TextView accountDescription = (TextView) v.findViewById(R.id.account_item_description);
            final ImageView accountStatus = (ImageView) v.findViewById(R.id.account_status);
            final ImageView securityEmblem = (ImageView) v.findViewById(R.id.account_secured_emblem);
            final ProgressBar progressBar = (ProgressBar) v.findViewById(R.id.account_status_progress);
            final ImageView accountAvatar = (ImageView) v.findViewById(R.id.imageView1);

            final boolean established = jaxmpp.getSessionObject()
                    .getProperty(ResourceBinderModule.BINDED_RESOURCE_JID) != null;
            State st = jaxmpp.getSessionObject().getProperty(Connector.CONNECTOR_STAGE_KEY);
            if (st == null)
                st = State.disconnected;
            else if (st == State.connected && !established)
                st = State.connecting;

            boolean secured = st == State.disconnected ? false : jaxmpp.getConnector().isSecure();
            securityEmblem.setVisibility(st != State.disconnected && secured ? View.VISIBLE : View.GONE);

            String errorMessage = jaxmpp.getSessionObject().getProperty("messenger#error");

            if (st == State.disconnected && !TextUtils.isEmpty(errorMessage)) {
                accountDescription.setText("Error: " + errorMessage);
            } else
                accountDescription.setText("" + st);

            accountName.setText(jaxmpp.getSessionObject().getUserBareJid().toString());

            AvatarHelper.setAvatarToImageView(jaxmpp.getSessionObject().getUserBareJid(), accountAvatar);

            if (st == State.connected) {
                accountStatus.setImageResource(R.drawable.user_available);
                accountStatus.setVisibility(View.VISIBLE);
                progressBar.setVisibility(View.GONE);
            } else if (st == State.disconnected) {
                accountStatus.setImageResource(R.drawable.user_offline);
                accountStatus.setVisibility(View.VISIBLE);
                progressBar.setVisibility(View.GONE);
            } else {
                accountStatus.setVisibility(View.GONE);
                progressBar.setVisibility(View.VISIBLE);
            }
            return v;
        }

    };

    // loadData();

    ListView list = (ListView) view.findViewById(R.id.account_status_list);
    list.setAdapter(adapter);
    registerForContextMenu(list);

    return view;
}

From source file:fr.paug.droidcon.ui.SessionsFragment.java

@Override
public void bindCollectionItemView(Context context, View view, int groupId, int indexInGroup, int dataIndex,
        Object tag) {/*from   w w  w  .ja va2  s . c  o m*/
    if (mCursor == null || !mCursor.moveToPosition(dataIndex)) {
        LOGW(TAG, "Can't bind collection view item, dataIndex=" + dataIndex
                + (mCursor == null ? ": cursor is null" : ": bad data index."));
        return;
    }

    final String sessionId = mCursor.getString(SessionsQuery.SESSION_ID);
    if (sessionId == null) {
        return;
    }

    // first, read session info from cursor and put it in convenience variables
    final String sessionTitle = mCursor.getString(SessionsQuery.TITLE);
    final String speakerNames = mCursor.getString(SessionsQuery.SPEAKER_NAMES);
    final String sessionAbstract = mCursor.getString(SessionsQuery.ABSTRACT);
    final long sessionStart = mCursor.getLong(SessionsQuery.SESSION_START);
    final long sessionEnd = mCursor.getLong(SessionsQuery.SESSION_END);
    final String roomName = mCursor.getString(SessionsQuery.ROOM_NAME);
    final String mainTag = mCursor.getString(SessionsQuery.MAIN_TAG);

    int sessionColor = mCursor.getInt(SessionsQuery.COLOR);
    sessionColor = sessionColor == 0 ? getResources().getColor(R.color.default_session_color) : sessionColor;
    final String snippet = mIsSearchCursor ? mCursor.getString(SessionsQuery.SNIPPET) : null;
    final Spannable styledSnippet = mIsSearchCursor ? buildStyledSnippet(snippet) : null;
    final boolean starred = mCursor.getInt(SessionsQuery.IN_MY_SCHEDULE) != 0;
    final String[] tags = mCursor.getString(SessionsQuery.TAGS).split(",");

    // now let's compute a few pieces of information from the data, which we will use
    // later to decide what to render where
    final boolean hasLivestream = !TextUtils.isEmpty(mCursor.getString(SessionsQuery.LIVESTREAM_URL));
    final long now = UIUtils.getCurrentTime(context);
    final boolean happeningNow = now >= sessionStart && now <= sessionEnd;

    // text that says "LIVE" if session is live, or empty if session is not live
    final String liveNowText = hasLivestream ? " " + UIUtils.getLiveBadgeText(context, sessionStart, sessionEnd)
            : "";

    // get reference to all the views in the layout we will need
    final TextView titleView = (TextView) view.findViewById(R.id.session_title);
    final TextView subtitleView = (TextView) view.findViewById(R.id.session_subtitle);
    final TextView shortSubtitleView = (TextView) view.findViewById(R.id.session_subtitle_short);
    final TextView snippetView = (TextView) view.findViewById(R.id.session_snippet);
    final TextView abstractView = (TextView) view.findViewById(R.id.session_abstract);
    final TextView categoryView = (TextView) view.findViewById(R.id.session_category);
    final View boxView = view.findViewById(R.id.info_box);
    final View sessionTargetView = view.findViewById(R.id.session_target);

    if (sessionColor == 0) {
        // use default
        sessionColor = mDefaultSessionColor;
    }
    sessionColor = UIUtils.scaleSessionColorToDefaultBG(sessionColor);

    ImageView photoView = (ImageView) view.findViewById(R.id.session_photo_colored);
    if (photoView != null) {
        if (!mPreloader.isDimensSet()) {
            final ImageView finalPhotoView = photoView;
            photoView.post(new Runnable() {
                @Override
                public void run() {
                    mPreloader.setDimens(finalPhotoView.getWidth(), finalPhotoView.getHeight());
                }
            });
        }
        // colored
        photoView.setColorFilter(UIUtils.setColorAlpha(sessionColor, UIUtils.SESSION_PHOTO_SCRIM_ALPHA));
    } else {
        photoView = (ImageView) view.findViewById(R.id.session_photo);
    }
    ((BaseActivity) getActivity()).getLPreviewUtils().setViewName(photoView, "photo_" + sessionId);

    // when we load a photo, it will fade in from transparent so the
    // background of the container must be the session color to avoid a white flash
    ViewParent parent = photoView.getParent();
    if (parent != null && parent instanceof View) {
        ((View) parent).setBackgroundColor(sessionColor);
    } else {
        photoView.setBackgroundColor(sessionColor);
    }

    String photo = mCursor.getString(SessionsQuery.PHOTO_URL);
    if (!TextUtils.isEmpty(photo)) {
        mImageLoader.loadImage(photo, photoView, true /*crop*/);
    } else {
        // cleaning the (potentially) recycled photoView, in case this session has no photo:
        //            photoView.setImageDrawable(null);
        photoView.setImageResource(R.drawable.default_session_img);
    }

    // render title
    titleView.setText(sessionTitle == null ? "?" : sessionTitle);

    // render subtitle into either the subtitle view, or the short subtitle view, as available
    if (subtitleView != null) {
        subtitleView.setText(UIUtils.formatSessionSubtitle(sessionStart, sessionEnd, roomName, mBuffer, context)
                + liveNowText);
    } else if (shortSubtitleView != null) {
        shortSubtitleView.setText(
                UIUtils.formatSessionSubtitle(sessionStart, sessionEnd, roomName, mBuffer, context, true)
                        + liveNowText);
    }

    // render category
    if (categoryView != null) {
        TagMetadata.Tag groupTag = mTagMetadata.getSessionGroupTag(tags);
        if (groupTag != null && !Config.Tags.SESSIONS.equals(groupTag.getId())) {
            categoryView.setText(groupTag.getName());
            categoryView.setVisibility(View.VISIBLE);
        } else {
            categoryView.setVisibility(View.GONE);
        }
    }

    // if a snippet view is available, render the session snippet there.
    if (snippetView != null) {
        if (mIsSearchCursor) {
            // render the search snippet into the snippet view
            snippetView.setText(styledSnippet);
        } else {
            // render speaker names and abstracts into the snippet view
            mBuffer.setLength(0);
            if (!TextUtils.isEmpty(speakerNames)) {
                mBuffer.append(speakerNames).append(". ");
            }
            if (!TextUtils.isEmpty(sessionAbstract)) {
                mBuffer.append(sessionAbstract);
            }
            snippetView.setText(mBuffer.toString());
        }
    }

    if (abstractView != null && !mIsSearchCursor) {
        // render speaker names and abstracts into the abstract view
        mBuffer.setLength(0);
        if (!TextUtils.isEmpty(speakerNames)) {
            mBuffer.append(speakerNames).append("\n\n");
        }
        if (!TextUtils.isEmpty(sessionAbstract)) {
            mBuffer.append(sessionAbstract);
        }
        abstractView.setText(mBuffer.toString());
    }

    // in expanded mode, the box background color follows the session color
    if (useExpandedMode()) {
        boxView.setBackgroundColor(sessionColor);
    }

    // show or hide the "in my schedule" indicator
    ImageView indicatorInSchedule = (ImageView) view.findViewById(R.id.indicator_in_schedule);
    indicatorInSchedule.setVisibility(starred ? View.VISIBLE : View.INVISIBLE);

    if (starred) {
        int resId = R.drawable.indicator_in_schedule;
        if (mainTag.equals(SessionDetailFragment.TOPIC_EVERYWHERE))
            resId = R.drawable.indicator_in_schedule_red;
        else if (mainTag.equals(SessionDetailFragment.TOPIC_DEVELOPMENT))
            resId = R.drawable.indicator_in_schedule_blue;
        else if (mainTag.equals(SessionDetailFragment.TOPIC_UI_UX))
            resId = R.drawable.indicator_in_schedule_amber;
        else if (mainTag.equals(SessionDetailFragment.TOPIC_OTHER))
            resId = R.drawable.indicator_in_schedule_indigo;

        indicatorInSchedule.setImageResource(resId);
    }

    // if we are in condensed mode and this card is the hero card (big card at the top
    // of the screen), set up the message card if necessary.
    if (!useExpandedMode() && groupId == HERO_GROUP_ID) {
        // this is the hero view, so we might want to show a message card
        final boolean cardShown = setupMessageCard(view);

        // if this is the wide hero layout, show or hide the card or the session abstract
        // view, as appropriate (they are mutually exclusive).
        final View cardContainer = view.findViewById(R.id.message_card_container_wide);
        final View abstractContainer = view.findViewById(R.id.session_abstract);
        if (cardContainer != null && abstractContainer != null) {
            cardContainer.setVisibility(cardShown ? View.VISIBLE : View.GONE);
            abstractContainer.setVisibility(cardShown ? View.GONE : View.VISIBLE);
            abstractContainer.setBackgroundColor(sessionColor);
        }
    }

    // if this session is live right now, display the "LIVE NOW" icon on top of it
    View liveNowBadge = view.findViewById(R.id.live_now_badge);
    if (liveNowBadge != null) {
        liveNowBadge.setVisibility(happeningNow && hasLivestream ? View.VISIBLE : View.GONE);
    }

    // if this view is clicked, open the session details view
    final View finalPhotoView = photoView;
    sessionTargetView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mCallbacks.onSessionSelected(sessionId, finalPhotoView);
        }
    });

    // animate this card
    if (dataIndex > mMaxDataIndexAnimated) {
        mMaxDataIndexAnimated = dataIndex;
    }
}