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:org.numixproject.hermes.activity.ConversationActivity.java

/**
 * On create/*  w w w  . j  a  v a2 s .  co  m*/
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //Initialize Facebook SDK
    FacebookSdk.sdkInitialize(getApplicationContext());

    tinydb = new TinyDB(getApplicationContext());

    serverId = getIntent().getExtras().getInt("serverId");
    server = Hermes.getInstance().getServerById(serverId);

    loadPinnedItems();
    loadRecentItems();

    server.setAutoJoinChannels(pinnedRooms);

    // Remove duplicates from Recent items
    HashSet hs = new HashSet();
    hs.addAll(recentList);
    recentList.clear();
    recentList.addAll(hs);
    saveRecentItems();

    Settings settings = new Settings(this);

    // Finish activity if server does not exist anymore - See #55
    if (server == null) {
        this.finish();
    }

    String key = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA5B4Oomgmm2D8XVSxh1DIFGtU3p1N2w6Xi2ZO7MoeZRAhvVjk3B8MfrOatlO9HfozRGhEkCkq0MfstB4Cjci3dsnYZieNmHOVYIFBWERqdwfdtnUIfI554xFsAC3Ah7PTP3MwKE7qTT1VLTTHxxsE7GH4sLtvLwrAzsVrLK+dgQk+e9bDJMvhhEPBgabRFaTvKaTtSzB/BBwrCa5mv0pte6WfrNbugFjiAJC43b7NNY2PV9UA8mukiBNZ9mPrK5fZeSEfcVqenyqbvZZG+P+O/cohAHbIEzPMuAS1EBf0VBsZtm3fjQ45PgCvEB7Ye3ucfR9BQ9ADjDwdqivExvXndQIDAQAB";

    inAppPayments = new iap();

    bp = inAppPayments.getBilling(this, key);
    bp.loadOwnedPurchasesFromGoogle();

    // Load AdMob Ads
    if (!inAppPayments.isPurchased()) {
        mInterstitialAd = new InterstitialAd(this);
        mInterstitialAd.setAdUnitId("ca-app-pub-2834532364021285/7438037454");
        requestNewInterstitial();

        mInterstitialAd.setAdListener(new AdListener() {
            @Override
            public void onAdClosed() {
                requestNewInterstitial();
            }
        });
    }

    try {
        setTitle(server.getTitle());
    } catch (Exception e) {
    }

    isFirstTimeStarred = tinydb.getBoolean("isFirstTimeStarred", true);
    isFirstTimeRefresh = tinydb.getBoolean("isFirstTimeRefresh", true);
    setContentView(R.layout.conversations);
    boolean isLandscape = (getResources()
            .getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE);

    final ImageView sendButton = (ImageView) findViewById(R.id.send_button);
    sendButton.setVisibility(View.GONE);

    input = (AutoCompleteTextView) findViewById(R.id.input);
    input.setOnKeyListener(inputKeyListener);
    input.addTextChangedListener(new TextWatcher() {

        @Override
        public void afterTextChanged(Editable s) {
            // Do nothing
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            // Do nothing
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (input.getText().toString().equals("")) {
                sendButton.setVisibility(View.GONE);
            } else {
                sendButton.setVisibility(View.VISIBLE);
            }
        }
    });

    pager = (ViewPager) findViewById(R.id.pager);
    pagerAdapter = new ConversationPagerAdapter(this, server);
    pager.setAdapter(pagerAdapter);

    final float density = getResources().getDisplayMetrics().density;

    indicator = (ConversationIndicator) findViewById(R.id.titleIndicator);
    indicator.setServer(server);
    indicator.setViewPager(pager);
    indicator.setFooterColor(Color.parseColor("#d1d1d1"));
    indicator.setFooterLineHeight(1);
    indicator.setPadding(10, 10, 10, 10);
    indicator.setFooterIndicatorStyle(IndicatorStyle.Underline);
    indicator.setFooterIndicatorHeight(2 * density);
    indicator.setSelectedColor(0xFF222222);
    indicator.setSelectedBold(false);
    indicator.setBackgroundColor(Color.parseColor("#fff5f5f5"));

    historySize = settings.getHistorySize();

    if (server.getStatus() == Status.PRE_CONNECTING) {
        server.clearConversations();
        pagerAdapter.clearConversations();
        server.getConversation(ServerInfo.DEFAULT_NAME).setHistorySize(historySize);
    }

    indicator.setTextSize(TypedValue.COMPLEX_UNIT_SP, 35);

    input.setTypeface(Typeface.SANS_SERIF);

    // Optimization : cache field lookups
    Collection<Conversation> mConversations = server.getConversations();

    for (Conversation conversation : mConversations) {
        // Only scroll to new conversation if it was selected before
        if (conversation.getStatus() == Conversation.STATUS_SELECTED) {
            onNewConversation(conversation.getName());
        } else {
            createNewConversation(conversation.getName());
        }
    }

    input.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            openSoftKeyboard(v);
            updateAutoComplete();
        }
    });

    conversationLayout = (FrameLayout) findViewById(R.id.conversationFragment);
    conversationLayout.setVisibility(LinearLayout.INVISIBLE);
    roomsLayout = (FrameLayout) findViewById(R.id.roomsLayout);

    // Create a new scrollback history
    scrollback = new Scrollback();
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    swipeRefresh = (SwipeRefreshLayout) findViewById(R.id.swipeRefresh);
    swipeRefresh.setColorSchemeResources(R.color.refresh_progress_1, R.color.refresh_progress_2,
            R.color.refresh_progress_3);

    swipeRefresh.getViewTreeObserver()
            .addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
                @Override
                public void onScrollChanged() {
                    Rect scrollBounds = new Rect();
                    swipeRefresh.getHitRect(scrollBounds);
                    TextView firstItem = (TextView) findViewById(R.id.firstItem);
                    if (firstItem.getLocalVisibleRect(scrollBounds)) {
                        if (conversationLayout.getVisibility() != View.VISIBLE) {
                            swipeRefresh.setEnabled(true);
                        } else {
                            swipeRefresh.setEnabled(false);
                        }
                    } else {
                        swipeRefresh.setEnabled(false);
                    }
                }
            });
    swipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            if (swipeRefresh.getScrollY() == 0) {
                refreshActivity();
            }
        }
    });

    // Adapter section
    roomsList = (ExpandableHeightListView) findViewById(R.id.roomsActivityList);
    roomsList.setExpanded(true);

    SwipeDismissListViewTouchListener touchListener = new SwipeDismissListViewTouchListener(roomsList,
            new SwipeDismissListViewTouchListener.DismissCallbacks() {

                @Override
                public boolean canDismiss(int position) {
                    return true;
                }

                @Override
                public void onDismiss(ListView listView, int[] reverseSortedPositions) {
                    for (int position : reverseSortedPositions) {
                        roomAdapter.remove(position);
                    }
                    roomAdapter.notifyDataSetChanged();
                    if (Math.random() * 100 < 30) {
                        showAd();
                    }
                }
            });
    roomsList.setOnTouchListener(touchListener);
    // Setting this scroll listener is required to ensure that during ListView scrolling,
    // we don't look for swipes.
    roomsList.setOnScrollListener(touchListener.makeScrollListener());

    ArrayList<String> channels = new ArrayList<String>();
    ArrayList<String> query = new ArrayList<String>();

    channels = server.getCurrentChannelNames();
    query = server.getCurrentQueryNames();

    for (int i = 0; i < channels.size(); i++) {
        try {
            Conversation conversation = server.getConversation(channels.get(i));
            int Mentions = conversation.getNewMentions();

            RoomsList.add(channels.get(i));
            MentionsList.add(Mentions);

        } catch (Exception E) {
            // Do nothing
        }
    }

    // FAB section
    fab = (FloatingActionButton) findViewById(R.id.room_fab);
    fab.setOnTouchListener(new View.OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_UP) {
                joinRoom(v);
            }
            return true;
        }
    });

    roomAdapter = new mentionsAdapter(RoomsList, MentionsList);
    roomsList.setAdapter(roomAdapter);
    roomsList.setEmptyView(findViewById(R.id.roomsActivityList_empty));

    roomsList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // Set conversation VISIBLE
            invalidateOptionsMenu();
            swipeRefresh.setEnabled(false);

            int pagerPosition;
            String name;

            // Find channel name from TextView
            TextView roomName = (TextView) view.findViewById(R.id.room_name);
            name = roomName.getText().toString();

            // Find room's position in pager
            pagerPosition = pagerAdapter.getPositionByName(name);

            // Set position in pager
            pager.setCurrentItem(pagerPosition, true);
            showConversationLayout();

        }
    });

    // Click on Others
    CardView otherCard = (CardView) findViewById(R.id.card_view_other);
    otherCard.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            invalidateOptionsMenu();
            swipeRefresh.setEnabled(false);
            pager.setCurrentItem(0);

            showConversationLayout();
        }
    });

    int counter;
    for (counter = 0; counter < recentList.size(); counter++) {
        if (RoomsList.contains(recentList.get(counter))) {
            recentList.remove(counter);
            saveRecentItems();
        }
    }

    LinearLayout recentLabel = (LinearLayout) findViewById(R.id.recentName);
    if (recentList.size() != 0) {
        recentLabel.setVisibility(View.VISIBLE);
    } else {
        recentLabel.setVisibility(View.GONE);
    }

    recentView = (ExpandableHeightListView) findViewById(R.id.recentList);
    loadLastItems();
    int k;
    for (k = 0; k < lastRooms.size(); k++) {
        String lastRoom = lastRooms.get(k);
        if (RoomsList.contains(lastRoom)) {
        } else {
            recentList.add(lastRoom);

        }
    }
    lastRooms.clear();
    saveLastItems();
    saveRecentItems();

    recentAdapter = new recentAdapter(recentList);
    recentView.setAdapter(recentAdapter);
    recentView.setExpanded(true);
    recentView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapter, View v, int position, long arg3) {
            final String room = (String) recentAdapter.getRoomAtPosition(position);
            if (RoomsList.size() > 0) {
                invalidateOptionsMenu();
                new Thread() {
                    @Override
                    public void run() {
                        try {
                            binder.getService().getConnection(serverId).joinChannel(room);
                        } catch (Exception E) {
                            // Do nothing
                        }
                    }
                }.start();
                recentList.remove(position);
                saveRecentItems();
                refreshActivity();
            } else {
                new Thread() {
                    @Override
                    public void run() {
                        try {
                            binder.getService().getConnection(serverId).joinChannel(room);
                        } catch (Exception E) {
                            // Do nothing
                        }
                    }
                }.start();
                saveRecentItems();
                refreshActivity();
            }
        }
    });

    SwipeDismissListViewTouchListener touchListenerRecent = new SwipeDismissListViewTouchListener(recentView,
            new SwipeDismissListViewTouchListener.DismissCallbacks() {
                @Override
                public boolean canDismiss(int position) {
                    return true;
                }

                @Override
                public void onDismiss(ListView listView, int[] reverseSortedPositions) {
                    for (int position : reverseSortedPositions) {
                        recentAdapter.remove(position);
                        saveRecentItems();
                    }
                    recentAdapter.notifyDataSetChanged();
                    if (Math.random() * 100 < 10) {
                        showAd();
                    }
                }
            });
    recentView.setOnTouchListener(touchListenerRecent);
    // Setting this scroll listener is required to ensure that during ListView scrolling,
    // we don't look for swipes.
    recentView.setOnScrollListener(touchListenerRecent.makeScrollListener());
}

From source file:dev.datvt.cloudtracks.sound_cloud.LocalTracksFragment.java

public void showMenus() {
    menus = new ArrayList<>();
    mm.removeAllViews();//from w  ww  .  j  av a2  s. co m

    LayoutInflater lf = LayoutInflater.from(ctx);

    for (int i = 0; i < 4; i++) {

        View con;
        con = lf.inflate(R.layout.fragment_local_main, null);

        ImageView art = (ImageView) con.findViewById(R.id.artM);
        ImageView shuf = (ImageView) con.findViewById(R.id.shuffleM);
        ImageView del = (ImageView) con.findViewById(R.id.delM);
        TextView mn = (TextView) con.findViewById(R.id.nameM);
        final TextView numberSong = (TextView) con.findViewById(R.id.noM);
        numberSong.setVisibility(View.VISIBLE);
        Menu m;

        m = new Menu(con, art, mn, numberSong);

        if (i == PLAYLIST) {
            art.setImageResource(R.drawable.custom_playlist);
            mn.setText(getString(R.string.playlist));

            con.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    try {
                        setUpListPlaylist();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    lnBack.setVisibility(View.VISIBLE);
                }
            });

            if (ToolsHelper.getListPlaylist() != null) {
                numberSong.setText(ToolsHelper.getListPlaylist().size() + " " + getString(R.string.playlist));
            }
        } else if (i == RECENT) {
            art.setImageResource(R.drawable.custom_recent);
            mn.setText(getString(R.string.recent));
            shuf.setVisibility(View.VISIBLE);
            m.shuffle = shuf;

            m.shuffle.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    ExecuterU ex = new ExecuterU(ctx, getString(R.string.scanning)) {
                        @Override
                        public void doIt() {
                            ArrayList<Track> tracks = ToolsHelper.getPlayList(ctx, "recent.lst");
                            localTracks = tracks;
                        }

                        @Override
                        public void doNe() {
                            ArrayList<Track> tracks = localTracks;
                            Collections.shuffle(tracks);
                            if (tracks.size() > 0) {
                                mListener.onListFragmentInteraction(tracks, tracks.get(0), 0,
                                        ToolsHelper.IS_LOCAL);
                            } else {
                                ToolsHelper.toast(ctx, getString(R.string.empty_playlist));
                            }
                        }
                    };
                    ex.execute();
                }
            });

            con.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    mm.setVisibility(View.GONE);
                    lnBack.setVisibility(View.VISIBLE);
                    ref.setVisibility(View.VISIBLE);
                    ExecuterU ex = new ExecuterU(ctx, getString(R.string.scanning)) {

                        @Override
                        public void doIt() {
                            baseLocal = ToolsHelper.getPlayList(ctx, "recent.lst");
                        }

                        @Override
                        public void doNe() {
                            setUpList(baseLocal);
                        }
                    };
                    ex.execute();
                }
            });

            if (ToolsHelper.getPlayList(ctx, "recent.lst") != null) {
                numberSong.setText(
                        ToolsHelper.getPlayList(ctx, "recent.lst").size() + " " + getString(R.string.songs));
            }

        } else if (i == DOWNLOAD) {
            art.setImageResource(R.drawable.custom_download);
            mn.setText(getString(R.string.download));
            shuf.setVisibility(View.VISIBLE);
            m.shuffle = shuf;

            m.shuffle.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    ExecuterU ex = new ExecuterU(ctx, getString(R.string.scanning)) {
                        @Override
                        public void doIt() {
                            ArrayList<Track> tracks = ToolsHelper.getPlayList(ctx, "download.lst");
                            localTracks = tracks;
                        }

                        @Override
                        public void doNe() {
                            ArrayList<Track> tracks = localTracks;
                            Collections.shuffle(tracks);
                            if (tracks.size() > 0) {
                                mListener.onListFragmentInteraction(tracks, tracks.get(0), 0,
                                        ToolsHelper.IS_LOCAL);
                            } else {
                                ToolsHelper.toast(ctx, getString(R.string.empty_playlist));
                            }
                        }
                    };
                    ex.execute();
                }
            });

            con.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    mm.setVisibility(View.GONE);
                    lnBack.setVisibility(View.VISIBLE);
                    ref.setVisibility(View.VISIBLE);
                    ExecuterU ex = new ExecuterU(ctx, getString(R.string.scanning)) {

                        @Override
                        public void doIt() {
                            baseLocal = ToolsHelper.getPlayList(ctx, "download.lst");
                        }

                        @Override
                        public void doNe() {
                            setUpList(baseLocal);
                        }
                    };
                    ex.execute();
                }
            });

            if (ToolsHelper.getPlayList(ctx, "download.lst") != null) {
                numberSong.setText(
                        ToolsHelper.getPlayList(ctx, "download.lst").size() + " " + getString(R.string.songs));
            }

        } else if (i == LOCAL) {
            art.setImageResource(R.drawable.custom_local);
            mn.setText(getString(R.string.local));
            shuf.setVisibility(View.VISIBLE);
            m.shuffle = shuf;

            m.shuffle.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    ExecuterU ex = new ExecuterU(ctx, getString(R.string.scanning)) {

                        @Override
                        public void doIt() {
                            if (localTracks.size() > 0) {
                                localTracks.clear();
                            }
                            getAllSongs();
                        }

                        @Override
                        public void doNe() {
                            ArrayList<Track> tracks = localTracks;
                            Collections.shuffle(tracks);
                            if (tracks.size() > 0) {
                                mListener.onListFragmentInteraction(tracks, tracks.get(0), 0,
                                        ToolsHelper.IS_LOCAL);
                            } else {
                                ToolsHelper.toast(ctx, getString(R.string.empty_playlist));
                            }
                        }

                    };
                    ex.execute();
                }
            });

            con.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    mm.setVisibility(View.GONE);
                    lnBack.setVisibility(View.VISIBLE);
                    ref.setVisibility(View.VISIBLE);

                    try {
                        ExecuterU ex = new ExecuterU(ctx, getString(R.string.scanning)) {
                            @Override
                            public void doIt() {
                                getAllSongs();
                            }

                            @Override
                            public void doNe() {
                                setUpList(localTracks);
                            }
                        };
                        ex.execute();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            });

            numberSong.setText(getCountSong() + " " + getString(R.string.songs));
        }

        if (MyApplication.CAN_DOWNLOAD) {
            menus.add(m);
            mm.addView(con);
        } else {
            if (i != DOWNLOAD) {
                menus.add(m);
                mm.addView(con);
            }
        }
    }
}

From source file:dev.datvt.cloudtracks.sound_cloud.LocalTracksFragment.java

public void setUpListPlaylist() {
    menus = new ArrayList<>();
    mm.removeAllViews();//from w  ww .j ava 2 s . c  o m
    LayoutInflater lf = LayoutInflater.from(ctx);

    if (true) {
        LinearLayout con;
        con = (LinearLayout) lf.inflate(R.layout.fragment_local_main, null);
        ImageView art = (ImageView) con.findViewById(R.id.artM);
        ImageView shuf = (ImageView) con.findViewById(R.id.shuffleM);
        ImageView del = (ImageView) con.findViewById(R.id.delM);
        TextView mn = (TextView) con.findViewById(R.id.nameM);
        TextView sn = (TextView) con.findViewById(R.id.noM);

        con.setGravity(Gravity.CENTER);
        art.setImageResource(R.drawable.icon_add_press);
        mn.setText(getString(R.string.create_new));

        art.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                showChangeLangDialog();
            }
        });
        mm.addView(con);
    }

    final ArrayList<String> names = ToolsHelper.getListPlaylist();

    if (names.size() > 0) {
        for (int i = 0; i < ToolsHelper.getListPlaylist().size(); i++) {
            View con;

            con = lf.inflate(R.layout.fragment_local_main, null);
            ImageView art = (ImageView) con.findViewById(R.id.artM);
            ImageView shuf = (ImageView) con.findViewById(R.id.shuffleM);
            ImageView del = (ImageView) con.findViewById(R.id.delM);
            TextView mn = (TextView) con.findViewById(R.id.nameM);
            TextView sn = (TextView) con.findViewById(R.id.noM);

            Menu m;

            art.setImageResource(R.drawable.default_nhaccuatui);
            shuf.setImageResource(R.drawable.ic_shuffle);
            shuf.setVisibility(View.VISIBLE);
            del.setImageResource(R.drawable.ic_delete);
            del.setVisibility(View.VISIBLE);
            mn.setText(names.get(i).replace(".lst", ""));
            sn.setText(
                    "" + ToolsHelper.getPlayList(ctx, names.get(i)).size() + " " + getString(R.string.songs));
            sn.setVisibility(View.VISIBLE);

            final String playlistname = names.get(i);

            con.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    mm.setVisibility(View.GONE);
                    lnBack.setVisibility(View.VISIBLE);
                    ref.setVisibility(View.VISIBLE);
                    ExecuterU ex = new ExecuterU(ctx, getString(R.string.scanning)) {

                        @Override
                        public void doIt() {
                            baseLocal = ToolsHelper.getPlayList(ctx, playlistname);
                        }

                        @Override
                        public void doNe() {
                            setUpList(baseLocal);
                        }
                    };
                    ex.execute();
                }
            });

            del.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    File f = new File(MainActivity.folder + "/Playlist/" + playlistname);
                    f.delete();
                    setUpListPlaylist();
                }
            });

            shuf.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    ExecuterU ex = new ExecuterU(ctx, getString(R.string.scanning)) {
                        @Override
                        public void doIt() {
                            ArrayList<Track> tracks = ToolsHelper.getPlayList(ctx, playlistname);
                            localTracks = tracks;
                        }

                        @Override
                        public void doNe() {
                            ArrayList<Track> tracks = localTracks;
                            Collections.shuffle(tracks);
                            if (tracks.size() > 0) {
                                if (tracks.get(0).bpm == ToolsHelper.IS_LOCAL)
                                    mListener.onListFragmentInteraction(tracks, tracks.get(0), 0,
                                            ToolsHelper.IS_LOCAL);
                                else {
                                    mListener.onListFragmentInteraction(tracks, tracks.get(0), 0,
                                            ToolsHelper.DOWNLOAD_CODE);
                                }
                            } else {
                                ToolsHelper.toast(ctx, getString(R.string.empty_playlist));
                            }
                        }
                    };
                    ex.execute();
                }
            });

            m = new Menu(con, art, mn, sn);
            menus.add(m);
            mm.addView(con);
        }
    }
}

From source file:com.tweetlanes.android.view.ProfileFragment.java

void configureView() {

    TextView fullNameTextView = (TextView) mProfileView.findViewById(R.id.fullNameTextView);
    TextView followingTextView = (TextView) mProfileView.findViewById(R.id.followState);
    TextView descriptionTextView = (TextView) mProfileView.findViewById(R.id.bioTextView);
    TextView tweetCount = (TextView) mProfileView.findViewById(R.id.tweetCountLabel);
    TextView followingCount = (TextView) mProfileView.findViewById(R.id.followingCountLabel);
    TextView followersCount = (TextView) mProfileView.findViewById(R.id.followersCountLabel);
    TextView favoritesCount = (TextView) mProfileView.findViewById(R.id.favorites_count);
    LinearLayout linkLayout = (LinearLayout) mProfileView.findViewById(R.id.linkLayout);
    TextView link = (TextView) mProfileView.findViewById(R.id.link);
    LinearLayout locationLayout = (LinearLayout) mProfileView.findViewById(R.id.locationLayout);
    TextView location = (TextView) mProfileView.findViewById(R.id.location);
    LinearLayout detailsLayout = (LinearLayout) mProfileView.findViewById(R.id.detailsLayout);
    ImageView privateAccountImage = (ImageView) mProfileView.findViewById(R.id.private_account_image);
    mFriendshipButton = (Button) mProfileView.findViewById(R.id.friendship_button);
    mFriendshipDivider = (View) mProfileView.findViewById(R.id.friendship_divider);

    if (mUser != null) {
        ImageView avatar = (ImageView) mProfileView.findViewById(R.id.profileImage);
        //String imageUrl = TwitterManager.getProfileImageUrl(mUser.getScreenName(), TwitterManager.ProfileImageSize.ORIGINAL);
        String imageUrl = mUser.getProfileImageUrl(TwitterManager.ProfileImageSize.ORIGINAL);
        UrlImageViewHelper.setUrlDrawable(avatar, imageUrl, R.drawable.ic_contact_picture);
        //avatar.setImageURL(imageUrl);

        ImageView coverImage = (ImageView) mProfileView.findViewById(R.id.coverImage);
        if (coverImage != null) {
            String url = mUser.getCoverImageUrl();
            if (url != null) {
                UrlImageViewHelper.setUrlDrawable(coverImage, url, R.drawable.ic_contact_picture);
            }//w ww  . j a v a2 s.  c  o  m
        }

        fullNameTextView.setText(mUser.getName());
        if (mFollowsLoggedInUser != null && mFollowsLoggedInUser.booleanValue() == true) {
            followingTextView.setText(R.string.follows_you);
        } else {
            followingTextView.setText(null);
        }

        String description = mUser.getDescription();
        if (description != null) {
            String descriptionMarkup = TwitterUtil.getTextMarkup(description);
            descriptionTextView.setText(Html.fromHtml(descriptionMarkup + " "));
            descriptionTextView.setMovementMethod(LinkMovementMethod.getInstance());
            URLSpanNoUnderline.stripUnderlines(descriptionTextView);
        }

        detailsLayout.setVisibility(View.VISIBLE);
        privateAccountImage.setVisibility(mUser.getProtected() ? View.VISIBLE : View.GONE);

        tweetCount.setText(Util.getPrettyCount(mUser.getStatusesCount()));
        followingCount.setText(Util.getPrettyCount(mUser.getFriendsCount()));
        followersCount.setText(Util.getPrettyCount(mUser.getFollowersCount()));
        if (favoritesCount != null) {
            favoritesCount.setText(Util.getPrettyCount(mUser.getFavoritesCount()));
        }

        if (mUser.getUrl() != null) {
            linkLayout.setVisibility(View.VISIBLE);
            //link.setText(mUser.getUrl());
            //URLSpanNoUnderline.stripUnderlines(link);
            link.setText(Html.fromHtml("<a href=\"" + mUser.getUrl() + "\">" + mUser.getUrl() + "</a>"));
            link.setMovementMethod(LinkMovementMethod.getInstance());
            URLSpanNoUnderline.stripUnderlines(link);
        } else {
            linkLayout.setVisibility(View.GONE);
        }

        if (mUser.getLocation() != null) {
            locationLayout.setVisibility(View.VISIBLE);
            location.setText(mUser.getLocation());
        } else {
            locationLayout.setVisibility(View.GONE);
        }

        configureFriendshipButtonVisibility(mLoggedInUserFollows);

        getBaseLaneActivity().setComposeTweetDefault();
    } else {
        fullNameTextView.setText(null);
        followingTextView.setText(null);
        descriptionTextView.setText(null);

        detailsLayout.setVisibility(View.GONE);
        linkLayout.setVisibility(View.GONE);
        locationLayout.setVisibility(View.GONE);
        mFriendshipButton.setVisibility(View.GONE);
        mFriendshipDivider.setVisibility(View.GONE);
        privateAccountImage.setVisibility(View.GONE);
    }
}

From source file:com.andrewshu.android.reddit.comments.CommentsListActivity.java

public static void fillCommentsListItemView(View view, ThingInfo item, RedditSettings settings) {
    // Set the values of the Views for the CommentsListItem

    TextView votesView = (TextView) view.findViewById(R.id.votes);
    TextView submitterView = (TextView) view.findViewById(R.id.submitter);
    TextView bodyView = (TextView) view.findViewById(R.id.body);

    TextView submissionTimeView = (TextView) view.findViewById(R.id.submissionTime);
    ImageView voteUpView = (ImageView) view.findViewById(R.id.vote_up_image);
    ImageView voteDownView = (ImageView) view.findViewById(R.id.vote_down_image);

    try {/*from  w ww .  j  a  v a  2s.co  m*/
        votesView.setText(Util.showNumPoints(item.getUps() - item.getDowns()));
    } catch (NumberFormatException e) {
        // This happens because "ups" comes after the potentially long "replies" object,
        // so the ListView might try to display the View before "ups" in JSON has been parsed.
        if (Constants.LOGGING)
            Log.e(TAG, "getView, normal comment", e);
    }
    if (item.getSSAuthor() != null)
        submitterView.setText(item.getSSAuthor());
    else
        submitterView.setText(item.getAuthor());
    submissionTimeView.setText(Util.getTimeAgo(item.getCreated_utc()));

    if (item.getSpannedBody() != null)
        bodyView.setText(item.getSpannedBody());
    else
        bodyView.setText(item.getBody());

    setCommentIndent(view, item.getIndent(), settings);

    if (voteUpView != null && voteDownView != null) {
        if (item.getLikes() == null || "[deleted]".equals(item.getAuthor())) {
            voteUpView.setVisibility(View.GONE);
            voteDownView.setVisibility(View.GONE);
        } else if (Boolean.TRUE.equals(item.getLikes())) {
            voteUpView.setVisibility(View.VISIBLE);
            voteDownView.setVisibility(View.GONE);
        } else if (Boolean.FALSE.equals(item.getLikes())) {
            voteUpView.setVisibility(View.GONE);
            voteDownView.setVisibility(View.VISIBLE);
        }
    }
}

From source file:com.t2.compassionMeditation.Graphs1Activity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.i(TAG, this.getClass().getSimpleName() + ".onCreate()");

    // We don't want the screen to timeout in this activity
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

    this.requestWindowFeature(Window.FEATURE_NO_TITLE); // This needs to happen BEFORE setContentView
    setContentView(R.layout.graphs_activity_layout);
    mInstance = this;

    sharedPref = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    mLoggingEnabled = SharedPref.getBoolean(this, "enable_logging", true);
    mDatabaseEnabled = SharedPref.getBoolean(this, "database_enabled", false);
    mAntHrmEnabled = SharedPref.getBoolean(this, "enable_ant_hrm", false);

    mInternalSensorMonitoring = SharedPref.getBoolean(this, "inernal_sensor_monitoring_enabled", false);

    if (mAntHrmEnabled) {
        mHeartRateSource = HEARTRATE_ANT;
    } else {//from   w w w .jav a  2  s. co  m
        mHeartRateSource = HEARTRATE_ZEPHYR;
    }

    // The session start time will be used as session id
    // Note this also sets session start time
    // **** This session ID will be prepended to all JSON data stored
    //      in the external database until it's changed (by the start
    //      of a new session.
    Calendar cal = Calendar.getInstance();
    SharedPref.setBioSessionId(sharedPref, cal.getTimeInMillis());

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss", Locale.US);
    String sessionDate = sdf.format(new Date());
    String userId = SharedPref.getString(this, "SelectedUser", "");
    long sessionId = SharedPref.getLong(this, "bio_session_start_time", 0);

    mDataOutHandler = new DataOutHandler(this, userId, sessionDate, mAppId,
            DataOutHandler.DATA_TYPE_EXTERNAL_SENSOR, sessionId);

    if (mDatabaseEnabled) {
        TelephonyManager telephonyManager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
        String myNumber = telephonyManager.getLine1Number();

        String remoteDatabaseUri = SharedPref.getString(this, "database_sync_name",
                getString(R.string.database_uri));
        //            remoteDatabaseUri += myNumber; 

        Log.d(TAG, "Initializing database at " + remoteDatabaseUri); // TODO: remove
        try {
            mDataOutHandler.initializeDatabase(dDatabaseName, dDesignDocName, dDesignDocId, byDateViewName,
                    remoteDatabaseUri);
        } catch (DataOutHandlerException e) {
            Log.e(TAG, e.toString());
            e.printStackTrace();
        }
        mDataOutHandler.setRequiresAuthentication(false);

    }

    mBioDataProcessor.initialize(mDataOutHandler);

    if (mLoggingEnabled) {
        mDataOutHandler.enableLogging(this);
    }

    if (mLogCatEnabled) {
        mDataOutHandler.enableLogCat();
    }

    // Log the version
    try {
        PackageManager packageManager = getPackageManager();
        PackageInfo info = packageManager.getPackageInfo(getPackageName(), 0);
        mApplicationVersion = info.versionName;
        String versionString = mAppId + " application version: " + mApplicationVersion;

        DataOutPacket packet = new DataOutPacket();
        packet.add(DataOutHandlerTags.version, versionString);
        try {
            mDataOutHandler.handleDataOut(packet);
        } catch (DataOutHandlerException e) {
            Log.e(TAG, e.toString());
            e.printStackTrace();
        }

    } catch (NameNotFoundException e) {
        Log.e(TAG, e.toString());
    }

    // Set up UI elements
    Resources resources = this.getResources();
    AssetManager assetManager = resources.getAssets();

    mPauseButton = (Button) findViewById(R.id.buttonPause);
    mAddMeasureButton = (Button) findViewById(R.id.buttonAddMeasure);
    mTextInfoView = (TextView) findViewById(R.id.textViewInfo);
    mMeasuresDisplayText = (TextView) findViewById(R.id.measuresDisplayText);

    // Don't actually show skin conductance meter unless we get samples
    ImageView image = (ImageView) findViewById(R.id.imageView1);
    image.setImageResource(R.drawable.signal_bars0);

    // Check to see of there a device configured for EEG, if so then show the skin conductance meter
    String tmp = SharedPref.getString(this, "EEG", null);

    if (tmp != null) {
        image.setVisibility(View.VISIBLE);
    } else {
        image.setVisibility(View.INVISIBLE);
    }

    // Initialize SPINE by passing the fileName with the configuration properties
    try {
        mManager = SPINEFactory.createSPINEManager("SPINETestApp.properties", resources);
    } catch (InstantiationException e) {
        Log.e(TAG, "Exception creating SPINE manager: " + e.toString());
        e.printStackTrace();
    }

    try {
        currentMindsetData = new MindsetData(this);
    } catch (Exception e1) {
        Log.e(TAG, "Exception creating MindsetData: " + e1.toString());
        e1.printStackTrace();
    }

    // Establish nodes for BSPAN

    // Create a broadcast receiver. Note that this is used ONLY for command messages from the service
    // All data from the service goes through the mail SPINE mechanism (received(Data data)).
    // See public void received(Data data)
    this.mCommandReceiver = new SpineReceiver(this);

    int itemId = 0;
    eegPos = itemId; // eeg always comes first
    mBioParameters.clear();

    // First create GraphBioParameters for each of the EEG static params (ie mindset)
    for (itemId = 0; itemId < MindsetData.NUM_BANDS + 2; itemId++) { // 2 extra, for attention and meditation
        GraphBioParameter param = new GraphBioParameter(itemId, MindsetData.spectralNames[itemId], "", true);
        param.isShimmer = false;
        mBioParameters.add(param);
    }

    // Now create all of the potential dynamic GBraphBioParameters (GSR, EMG, ECG, EEG, HR, Skin Temp, Resp Rate
    //       String[] paramNamesStringArray = getResources().getStringArray(R.array.parameter_names);
    String[] paramNamesStringArray = getResources().getStringArray(R.array.parameter_names_less_eeg);

    for (String paramName : paramNamesStringArray) {
        if (paramName.equalsIgnoreCase("not assigned"))
            continue;

        GraphBioParameter param = new GraphBioParameter(itemId, paramName, "", true);

        if (paramName.equalsIgnoreCase("gsr")) {
            gsrPos = itemId;
            param.isShimmer = true;
            param.shimmerSensorConstant = SPINESensorConstants.SHIMMER_GSR_SENSOR;
            param.shimmerNode = getShimmerNode();
        }

        if (paramName.equalsIgnoreCase("emg")) {
            emgPos = itemId;
            param.isShimmer = true;
            param.shimmerSensorConstant = SPINESensorConstants.SHIMMER_EMG_SENSOR;
            param.shimmerNode = getShimmerNode();
        }

        if (paramName.equalsIgnoreCase("ecg")) {
            ecgPos = itemId;
            param.isShimmer = true;
            param.shimmerSensorConstant = SPINESensorConstants.SHIMMER_ECG_SENSOR;
            param.shimmerNode = getShimmerNode();
        }

        if (paramName.equalsIgnoreCase("heart rate")) {
            heartRatePos = itemId;
            param.isShimmer = false;
        }

        if (paramName.equalsIgnoreCase("resp rate")) {
            respRatePos = itemId;
            param.isShimmer = false;
        }

        if (paramName.equalsIgnoreCase("skin temp")) {
            skinTempPos = itemId;
            param.isShimmer = false;
        }

        if (paramName.equalsIgnoreCase("EHealth Airflow")) {
            eHealthAirFlowPos = itemId;
            param.isShimmer = false;
        }

        if (paramName.equalsIgnoreCase("EHealth Temp")) {
            eHealthTempPos = itemId;
            param.isShimmer = false;
        }

        if (paramName.equalsIgnoreCase("EHealth SpO2")) {
            eHealthSpO2Pos = itemId;
            param.isShimmer = false;
        }

        if (paramName.equalsIgnoreCase("EHealth Heartrate")) {
            eHealthHeartRatePos = itemId;
            param.isShimmer = false;
        }

        if (paramName.equalsIgnoreCase("EHealth GSR")) {
            eHealthGSRPos = itemId;
            param.isShimmer = false;
        }

        itemId++;
        mBioParameters.add(param);
    }

    // Since These are static nodes (Non-spine) we have to manually put them in the active node list
    Node mindsetNode = null;
    mindsetNode = new Node(new Address("" + Constants.RESERVED_ADDRESS_MINDSET)); // Note that the sensor id 0xfff1 (-15) is a reserved id for this particular sensor
    mManager.getActiveNodes().add(mindsetNode);

    Node zepherNode = null;
    zepherNode = new Node(new Address("" + Constants.RESERVED_ADDRESS_ZEPHYR));
    mManager.getActiveNodes().add(zepherNode);

    // The arduino node is programmed to look like a static Spine node
    // Note that currently we don't have  to turn it on or off - it's always streaming
    // Since Spine (in this case) is a static node we have to manually put it in the active node list
    // Since the 
    final int RESERVED_ADDRESS_ARDUINO_SPINE = 1; // 0x0001
    mSpineNode = new Node(new Address("" + RESERVED_ADDRESS_ARDUINO_SPINE));
    mManager.getActiveNodes().add(mSpineNode);

    final String sessionName;

    // Check to see if we were requested to play back a previous session
    try {
        Bundle bundle = getIntent().getExtras();

        if (bundle != null) {
            sessionName = bundle.getString(BioZenConstants.EXTRA_SESSION_NAME);

            AlertDialog.Builder alert = new AlertDialog.Builder(this);
            alert.setTitle("Replay Session " + sessionName + "?");
            alert.setMessage("Make sure to turn off all Bluetooth Sensors!");

            alert.setPositiveButton(R.string.alert_dialog_ok, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {

                    try {
                        mDataOutHandler.logNote("Replaying data from session " + sessionName);
                    } catch (DataOutHandlerException e) {
                        Log.e(TAG, e.toString());
                        e.printStackTrace();
                    }

                    replaySessionData(sessionName);
                    AlertDialog.Builder alert1 = new AlertDialog.Builder(mInstance);
                    alert1.setTitle("INFO");
                    alert1.setMessage("Replay of session complete!");
                    alert1.show();

                }
            });
            alert.show();
        }

    } catch (Exception e) {
        Log.e(TAG, e.toString());
        e.printStackTrace();
    }

    if (mInternalSensorMonitoring) {
        // IntentSender Launches our service scheduled with with the alarm manager 
        mBigBrotherService = PendingIntent.getService(Graphs1Activity.this, 0,
                new Intent(Graphs1Activity.this, BigBrotherService.class), 0);

        long firstTime = SystemClock.elapsedRealtime();
        // Schedule the alarm!
        AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
        am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, mPollingPeriod * 1000,
                mBigBrotherService);

        // Tell the user about what we did.
        Toast.makeText(Graphs1Activity.this, R.string.service_scheduled, Toast.LENGTH_LONG).show();

    }

    //testFIRFilter();

    //       testHR();

}

From source file:de.dfki.iui.opentok.cordova.plugin.OpenTokPlugin.java

private void doUpdateViewIcon(final ImageView icon, final LayoutParams newLayoutParams, final int ressourceId,
        final int visibility) {
    this.cordova.getActivity().runOnUiThread(new Runnable() {
        @Override//from  ww w  .java2  s .co m
        public void run() {
            icon.setLayoutParams(newLayoutParams);
            icon.setImageResource(ressourceId);
            icon.setVisibility(visibility);
        }
    });
}

From source file:com.shafiq.mytwittle.view.ProfileFragment.java

void configureView() {

    TextView fullNameTextView = (TextView) mProfileView.findViewById(R.id.fullNameTextView);
    TextView followingTextView = (TextView) mProfileView.findViewById(R.id.followState);
    TextView descriptionTextView = (TextView) mProfileView.findViewById(R.id.bioTextView);
    TextView tweetCount = (TextView) mProfileView.findViewById(R.id.tweetCountLabel);
    TextView followingCount = (TextView) mProfileView.findViewById(R.id.followingCountLabel);
    TextView followersCount = (TextView) mProfileView.findViewById(R.id.followersCountLabel);
    TextView favoritesCount = (TextView) mProfileView.findViewById(R.id.favorites_count);
    LinearLayout linkLayout = (LinearLayout) mProfileView.findViewById(R.id.linkLayout);
    TextView link = (TextView) mProfileView.findViewById(R.id.link);
    LinearLayout locationLayout = (LinearLayout) mProfileView.findViewById(R.id.locationLayout);
    TextView location = (TextView) mProfileView.findViewById(R.id.location);
    LinearLayout detailsLayout = (LinearLayout) mProfileView.findViewById(R.id.detailsLayout);
    ImageView privateAccountImage = (ImageView) mProfileView.findViewById(R.id.private_account_image);
    mFriendshipButton = (Button) mProfileView.findViewById(R.id.friendship_button);
    mFriendshipDivider = (View) mProfileView.findViewById(R.id.friendship_divider);

    if (mUser != null) {
        ImageView avatar = (ImageView) mProfileView.findViewById(R.id.profileImage);
        // String imageUrl =
        // TwitterManager.getProfileImageUrl(mUser.getScreenName(),
        // TwitterManager.ProfileImageSize.ORIGINAL);
        String imageUrl = mUser.getProfileImageUrl(TwitterManager.ProfileImageSize.ORIGINAL);
        UrlImageViewHelper.setUrlDrawable(avatar, imageUrl, R.drawable.ic_contact_picture);
        // avatar.setImageURL(imageUrl);

        ImageView coverImage = (ImageView) mProfileView.findViewById(R.id.coverImage);
        if (coverImage != null) {
            String url = mUser.getCoverImageUrl();
            if (url != null) {
                UrlImageViewHelper.setUrlDrawable(coverImage, url, R.drawable.ic_contact_picture);
            }//from   ww w .j a v  a2s .  co m
        }

        fullNameTextView.setText(mUser.getName());
        if (mFollowsLoggedInUser != null && mFollowsLoggedInUser.booleanValue() == true) {
            followingTextView.setText(R.string.follows_you);
        } else {
            followingTextView.setText(null);
        }

        String description = mUser.getDescription();
        if (description != null) {
            String descriptionMarkup = TwitterUtil.getTextMarkup(description);
            descriptionTextView.setText(Html.fromHtml(descriptionMarkup + " "));
            descriptionTextView.setMovementMethod(LinkMovementMethod.getInstance());
            URLSpanNoUnderline.stripUnderlines(descriptionTextView);
        }

        detailsLayout.setVisibility(View.VISIBLE);
        privateAccountImage.setVisibility(mUser.getProtected() ? View.VISIBLE : View.GONE);

        tweetCount.setText(Util.getPrettyCount(mUser.getStatusesCount()));
        followingCount.setText(Util.getPrettyCount(mUser.getFriendsCount()));
        followersCount.setText(Util.getPrettyCount(mUser.getFollowersCount()));
        if (favoritesCount != null) {
            favoritesCount.setText(Util.getPrettyCount(mUser.getFavoritesCount()));
        }

        if (mUser.getUrl() != null) {
            linkLayout.setVisibility(View.VISIBLE);
            // link.setText(mUser.getUrl());
            // URLSpanNoUnderline.stripUnderlines(link);
            link.setText(Html.fromHtml("<a href=\"" + mUser.getUrl() + "\">" + mUser.getUrl() + "</a>"));
            link.setMovementMethod(LinkMovementMethod.getInstance());
            URLSpanNoUnderline.stripUnderlines(link);
        } else {
            linkLayout.setVisibility(View.GONE);
        }

        if (mUser.getLocation() != null) {
            locationLayout.setVisibility(View.VISIBLE);
            location.setText(mUser.getLocation());
        } else {
            locationLayout.setVisibility(View.GONE);
        }

        configureFriendshipButtonVisibility(mLoggedInUserFollows);

        getBaseLaneActivity().setComposeTweetDefault();
    } else {
        fullNameTextView.setText(null);
        followingTextView.setText(null);
        descriptionTextView.setText(null);

        detailsLayout.setVisibility(View.GONE);
        linkLayout.setVisibility(View.GONE);
        locationLayout.setVisibility(View.GONE);
        mFriendshipButton.setVisibility(View.GONE);
        mFriendshipDivider.setVisibility(View.GONE);
        privateAccountImage.setVisibility(View.GONE);
    }
}

From source file:com.popdeem.sdk.uikit.activity.PDUIClaimActivity.java

private void setPic(String path, int orientation) {
    ImageView mImageView = (ImageView) findViewById(R.id.pd_claim_share_image_view);

    int targetW = mImageView.getWidth();
    int targetH = mImageView.getHeight();

    mImageAdded = true;//ww  w .  j  a  v a2  s  . c  om
    image = PDUIImageUtils.getResizedBitmap(path, 500, 500, orientation);
    mImageView.setImageBitmap(image);
    twitterURI = saveBitmapToInternalCache(this, image);
    mImageView.setVisibility(View.VISIBLE);
    mImageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (ContextCompat.checkSelfPermission(PDUIClaimActivity.this,
                    Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
                new AlertDialog.Builder(PDUIClaimActivity.this)
                        .setTitle(getString(R.string.pd_storage_permissions_title_string))
                        .setMessage(getString(R.string.pd_storage_permission_rationale_string))
                        .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                ActivityCompat.requestPermissions(PDUIClaimActivity.this,
                                        new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, 123);
                            }
                        }).setNegativeButton(android.R.string.no, null).create().show();
            } else {
                showAddPictureChoiceDialog();
            }
        }
    });
}

From source file:de.baumann.quitsmoking.fragments.FragmentNotes.java

private void setNotesList() {

    ArrayList<HashMap<String, String>> mapList = new ArrayList<>();

    try {/*from   w w  w  .  ja  v  a  2 s  .co m*/
        Database_Notes db = new Database_Notes(getActivity());
        ArrayList<String[]> bookmarkList = new ArrayList<>();
        db.getBookmarks(bookmarkList, getActivity());
        if (bookmarkList.size() == 0) {
            db.loadInitialData();
            db.getBookmarks(bookmarkList, getActivity());
        }
        db.close();

        for (String[] strAry : bookmarkList) {
            HashMap<String, String> map = new HashMap<>();
            map.put("seqno", strAry[0]);
            map.put("title", strAry[1]);
            map.put("cont", strAry[2]);
            map.put("icon", strAry[3]);
            map.put("attachment", strAry[4]);
            map.put("createDate", strAry[5]);
            mapList.add(map);
        }

        SimpleAdapter simpleAdapter = new SimpleAdapter(getActivity(), mapList, R.layout.list_item_notes,
                new String[] { "title", "cont", "createDate" },
                new int[] { R.id.textView_title_notes, R.id.textView_des_notes, R.id.textView_create_notes }) {
            @Override
            public View getView(final int position, View convertView, ViewGroup parent) {

                @SuppressWarnings("unchecked")
                HashMap<String, String> map = (HashMap<String, String>) listView.getItemAtPosition(position);
                final String title = map.get("title");
                final String cont = map.get("cont");
                final String seqnoStr = map.get("seqno");
                final String icon = map.get("icon");
                final String attachment = map.get("attachment");
                final String create = map.get("createDate");

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

                switch (icon) {
                case "1":
                    i.setImageResource(R.drawable.emoticon_neutral);
                    break;
                case "2":
                    i.setImageResource(R.drawable.emoticon_happy);
                    break;
                case "3":
                    i.setImageResource(R.drawable.emoticon_sad);
                    break;
                case "4":
                    i.setImageResource(R.drawable.emoticon);
                    break;
                case "5":
                    i.setImageResource(R.drawable.emoticon_cool);
                    break;
                case "6":
                    i.setImageResource(R.drawable.emoticon_dead);
                    break;
                case "7":
                    i.setImageResource(R.drawable.emoticon_excited);
                    break;
                case "8":
                    i.setImageResource(R.drawable.emoticon_tongue);
                    break;
                case "9":
                    i.setImageResource(R.drawable.emoticon_devil);
                    break;
                }
                switch (attachment) {
                case "":
                    i2.setVisibility(View.GONE);
                    break;
                default:
                    i2.setVisibility(View.VISIBLE);
                    break;
                }

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

                i.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View arg0) {

                        final FragmentNotes.Item[] items = {
                                new FragmentNotes.Item(getString(R.string.text_tit_1),
                                        R.drawable.emoticon_neutral),
                                new FragmentNotes.Item(getString(R.string.text_tit_2),
                                        R.drawable.emoticon_happy),
                                new FragmentNotes.Item(getString(R.string.text_tit_3), R.drawable.emoticon_sad),
                                new FragmentNotes.Item(getString(R.string.text_tit_4), R.drawable.emoticon),
                                new FragmentNotes.Item(getString(R.string.text_tit_5),
                                        R.drawable.emoticon_cool),
                                new FragmentNotes.Item(getString(R.string.text_tit_6),
                                        R.drawable.emoticon_dead),
                                new FragmentNotes.Item(getString(R.string.text_tit_7),
                                        R.drawable.emoticon_excited),
                                new FragmentNotes.Item(getString(R.string.text_tit_8),
                                        R.drawable.emoticon_tongue),
                                new FragmentNotes.Item(getString(R.string.text_tit_9),
                                        R.drawable.emoticon_devil) };

                        ListAdapter adapter = new ArrayAdapter<FragmentNotes.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.goal_cancel, new DialogInterface.OnClickListener() {

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

                                    public void onClick(DialogInterface dialog, int item) {
                                        if (item == 0) {
                                            changeIcon(seqnoStr, title, cont, "1", attachment, create);
                                        } else if (item == 1) {
                                            changeIcon(seqnoStr, title, cont, "2", attachment, create);
                                        } else if (item == 2) {
                                            changeIcon(seqnoStr, title, cont, "3", attachment, create);
                                        } else if (item == 3) {
                                            changeIcon(seqnoStr, title, cont, "4", attachment, create);
                                        } else if (item == 4) {
                                            changeIcon(seqnoStr, title, cont, "5", attachment, create);
                                        } else if (item == 5) {
                                            changeIcon(seqnoStr, title, cont, "6", attachment, create);
                                        } else if (item == 6) {
                                            changeIcon(seqnoStr, title, cont, "7", attachment, create);
                                        } else if (item == 7) {
                                            changeIcon(seqnoStr, title, cont, "8", attachment, create);
                                        } else if (item == 8) {
                                            changeIcon(seqnoStr, title, cont, "9", attachment, create);
                                        } else if (item == 9) {
                                            changeIcon(seqnoStr, title, cont, "10", attachment, create);
                                        }
                                    }
                                }).show();
                    }
                });
                i2.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View arg0) {
                        openAtt(attachment);
                    }
                });

                return v;
            }
        };

        listView.setAdapter(simpleAdapter);

    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
}