Example usage for android.widget ImageView ImageView

List of usage examples for android.widget ImageView ImageView

Introduction

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

Prototype

public ImageView(Context context) 

Source Link

Usage

From source file:de.mrapp.android.preference.AbstractColorPickerPreference.java

@Override
protected final View onCreateView(final ViewGroup parent) {
    View view = super.onCreateView(parent);
    LinearLayout widgetFrame = (LinearLayout) view.findViewById(android.R.id.widget_frame);
    widgetFrame.setVisibility(View.VISIBLE);
    previewView = new ImageView(getContext());
    widgetFrame.addView(previewView, createPreviewLayoutParams());
    adaptPreviewView();//from   w ww .  jav  a  2 s  . c o m
    return view;
}

From source file:net.bluehack.ui.MediaActivity.java

@Override
public View createView(Context context) {
    actionBar.setBackButtonDrawable(new BackDrawable(false));
    actionBar.setTitle("");
    actionBar.setAllowOverlayTitle(false);
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override//  w ww  .java 2  s . co  m
        public void onItemClick(int id) {
            if (id == -1) {
                if (actionBar.isActionModeShowed()) {
                    for (int a = 1; a >= 0; a--) {
                        selectedFiles[a].clear();
                    }
                    cantDeleteMessagesCount = 0;
                    actionBar.hideActionMode();
                    listView.invalidateViews();
                } else {
                    finishFragment();
                }
            } else if (id == shared_media_item) {
                if (selectedMode == 0) {
                    return;
                }
                selectedMode = 0;
                switchToCurrentSelectedMode();
            } else if (id == files_item) {
                if (selectedMode == 1) {
                    return;
                }
                selectedMode = 1;
                switchToCurrentSelectedMode();
            } else if (id == links_item) {
                if (selectedMode == 3) {
                    return;
                }
                selectedMode = 3;
                switchToCurrentSelectedMode();
            } else if (id == music_item) {
                if (selectedMode == 4) {
                    return;
                }
                selectedMode = 4;
                switchToCurrentSelectedMode();
            } else if (id == delete) {
                if (getParentActivity() == null) {
                    return;
                }
                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                builder.setMessage(LocaleController.formatString("AreYouSureDeleteMessages",
                        R.string.AreYouSureDeleteMessages, LocaleController.formatPluralString("items",
                                selectedFiles[0].size() + selectedFiles[1].size())));
                builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                builder.setPositiveButton(LocaleController.getString("OK", R.string.OK),
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                for (int a = 1; a >= 0; a--) {
                                    ArrayList<Integer> ids = new ArrayList<>(selectedFiles[a].keySet());
                                    ArrayList<Long> random_ids = null;
                                    TLRPC.EncryptedChat currentEncryptedChat = null;
                                    int channelId = 0;
                                    if (!ids.isEmpty()) {
                                        MessageObject msg = selectedFiles[a].get(ids.get(0));
                                        if (channelId == 0 && msg.messageOwner.to_id.channel_id != 0) {
                                            channelId = msg.messageOwner.to_id.channel_id;
                                        }
                                    }
                                    if ((int) dialog_id == 0) {
                                        currentEncryptedChat = MessagesController.getInstance()
                                                .getEncryptedChat((int) (dialog_id >> 32));
                                    }
                                    if (currentEncryptedChat != null) {
                                        random_ids = new ArrayList<>();
                                        for (HashMap.Entry<Integer, MessageObject> entry : selectedFiles[a]
                                                .entrySet()) {
                                            MessageObject msg = entry.getValue();
                                            if (msg.messageOwner.random_id != 0 && msg.type != 10) {
                                                random_ids.add(msg.messageOwner.random_id);
                                            }
                                        }
                                    }
                                    MessagesController.getInstance().deleteMessages(ids, random_ids,
                                            currentEncryptedChat, channelId);
                                    selectedFiles[a].clear();
                                }
                                actionBar.hideActionMode();
                                actionBar.closeSearchField();
                                cantDeleteMessagesCount = 0;
                            }
                        });
                builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                showDialog(builder.create());
            } else if (id == forward) {
                Bundle args = new Bundle();
                args.putBoolean("onlySelect", true);
                args.putInt("dialogsType", 1);
                DialogsActivity fragment = new DialogsActivity(args);
                fragment.setDelegate(new DialogsActivity.DialogsActivityDelegate() {
                    @Override
                    public void didSelectDialog(DialogsActivity fragment, long did, boolean param) {
                        int lower_part = (int) did;
                        if (lower_part != 0) {
                            Bundle args = new Bundle();
                            args.putBoolean("scrollToTopOnResume", true);
                            if (lower_part > 0) {
                                args.putInt("user_id", lower_part);
                            } else if (lower_part < 0) {
                                args.putInt("chat_id", -lower_part);
                            }
                            if (!MessagesController.checkCanOpenChat(args, fragment)) {
                                return;
                            }

                            ArrayList<MessageObject> fmessages = new ArrayList<>();
                            for (int a = 1; a >= 0; a--) {
                                ArrayList<Integer> ids = new ArrayList<>(selectedFiles[a].keySet());
                                Collections.sort(ids);
                                for (Integer id : ids) {
                                    if (id > 0) {
                                        fmessages.add(selectedFiles[a].get(id));
                                    }
                                }
                                selectedFiles[a].clear();
                            }
                            cantDeleteMessagesCount = 0;
                            actionBar.hideActionMode();

                            NotificationCenter.getInstance()
                                    .postNotificationName(NotificationCenter.closeChats);

                            ChatActivity chatActivity = new ChatActivity(args);
                            presentFragment(chatActivity, true);
                            chatActivity.showReplyPanel(true, null, fmessages, null, false, false);

                            if (!AndroidUtilities.isTablet()) {
                                removeSelfFromStack();
                            }
                        } else {
                            fragment.finishFragment();
                        }
                    }
                });
                presentFragment(fragment);
            }
        }
    });

    for (int a = 1; a >= 0; a--) {
        selectedFiles[a].clear();
    }
    cantDeleteMessagesCount = 0;
    actionModeViews.clear();

    final ActionBarMenu menu = actionBar.createMenu();
    searchItem = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true)
            .setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() {
                @Override
                public void onSearchExpand() {
                    dropDownContainer.setVisibility(View.GONE);
                    searching = true;
                }

                @Override
                public void onSearchCollapse() {
                    dropDownContainer.setVisibility(View.VISIBLE);
                    if (selectedMode == 1) {
                        documentsSearchAdapter.search(null);
                    } else if (selectedMode == 3) {
                        linksSearchAdapter.search(null);
                    } else if (selectedMode == 4) {
                        audioSearchAdapter.search(null);
                    }
                    searching = false;
                    searchWas = false;
                    switchToCurrentSelectedMode();
                }

                @Override
                public void onTextChanged(EditText editText) {
                    String text = editText.getText().toString();
                    if (text.length() != 0) {
                        searchWas = true;
                        switchToCurrentSelectedMode();
                    }
                    if (selectedMode == 1) {
                        if (documentsSearchAdapter == null) {
                            return;
                        }
                        documentsSearchAdapter.search(text);
                    } else if (selectedMode == 3) {
                        if (linksSearchAdapter == null) {
                            return;
                        }
                        linksSearchAdapter.search(text);
                    } else if (selectedMode == 4) {
                        if (audioSearchAdapter == null) {
                            return;
                        }
                        audioSearchAdapter.search(text);
                    }
                }
            });
    searchItem.getSearchField().setHint(LocaleController.getString("Search", R.string.Search));
    searchItem.setVisibility(View.GONE);

    dropDownContainer = new ActionBarMenuItem(context, menu, 0);
    dropDownContainer.setSubMenuOpenSide(1);
    dropDownContainer.addSubItem(shared_media_item,
            LocaleController.getString("SharedMediaTitle", R.string.SharedMediaTitle), 0);
    dropDownContainer.addSubItem(files_item,
            LocaleController.getString("DocumentsTitle", R.string.DocumentsTitle), 0);
    if ((int) dialog_id != 0) {
        dropDownContainer.addSubItem(links_item, LocaleController.getString("LinksTitle", R.string.LinksTitle),
                0);
        dropDownContainer.addSubItem(music_item, LocaleController.getString("AudioTitle", R.string.AudioTitle),
                0);
    } else {
        TLRPC.EncryptedChat currentEncryptedChat = MessagesController.getInstance()
                .getEncryptedChat((int) (dialog_id >> 32));
        if (currentEncryptedChat != null
                && AndroidUtilities.getPeerLayerVersion(currentEncryptedChat.layer) >= 46) {
            dropDownContainer.addSubItem(music_item,
                    LocaleController.getString("AudioTitle", R.string.AudioTitle), 0);
        }
    }
    actionBar.addView(dropDownContainer, 0,
            LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT,
                    Gravity.TOP | Gravity.LEFT, AndroidUtilities.isTablet() ? 64 : 56, 0, 40, 0));
    dropDownContainer.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            dropDownContainer.toggleSubMenu();
        }
    });

    dropDown = new TextView(context);
    dropDown.setGravity(Gravity.LEFT);
    dropDown.setSingleLine(true);
    dropDown.setLines(1);
    dropDown.setMaxLines(1);
    dropDown.setEllipsize(TextUtils.TruncateAt.END);
    dropDown.setTextColor(0xffffffff);
    dropDown.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    dropDown.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_arrow_drop_down, 0);
    dropDown.setCompoundDrawablePadding(AndroidUtilities.dp(4));
    dropDown.setPadding(0, 0, AndroidUtilities.dp(10), 0);
    dropDownContainer.addView(dropDown, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT,
            LayoutHelper.WRAP_CONTENT, Gravity.CENTER_VERTICAL, 16, 0, 0, 0));

    final ActionBarMenu actionMode = actionBar.createActionMode();

    selectedMessagesCountTextView = new NumberTextView(actionMode.getContext());
    selectedMessagesCountTextView.setTextSize(18);
    selectedMessagesCountTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    selectedMessagesCountTextView.setTextColor(0xff737373);
    selectedMessagesCountTextView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return true;
        }
    });
    actionMode.addView(selectedMessagesCountTextView,
            LayoutHelper.createLinear(0, LayoutHelper.MATCH_PARENT, 1.0f, 65, 0, 0, 0));

    if ((int) dialog_id != 0) {
        actionModeViews.add(actionMode.addItem(forward, R.drawable.ic_ab_fwd_forward,
                Theme.ACTION_BAR_MODE_SELECTOR_COLOR, null, AndroidUtilities.dp(54)));
    }
    actionModeViews.add(actionMode.addItem(delete, R.drawable.ic_ab_fwd_delete,
            Theme.ACTION_BAR_MODE_SELECTOR_COLOR, null, AndroidUtilities.dp(54)));

    photoVideoAdapter = new SharedPhotoVideoAdapter(context);
    documentsAdapter = new SharedDocumentsAdapter(context, 1);
    audioAdapter = new SharedDocumentsAdapter(context, 4);
    documentsSearchAdapter = new MediaSearchAdapter(context, 1);
    audioSearchAdapter = new MediaSearchAdapter(context, 4);
    linksSearchAdapter = new MediaSearchAdapter(context, 3);
    linksAdapter = new SharedLinksAdapter(context);

    FrameLayout frameLayout;
    fragmentView = frameLayout = new FrameLayout(context);

    listView = new SectionsListView(context);
    listView.setDivider(null);
    listView.setDividerHeight(0);
    listView.setDrawSelectorOnTop(true);
    listView.setClipToPadding(false);
    frameLayout.addView(listView,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) {
            if ((selectedMode == 1 || selectedMode == 4) && view instanceof SharedDocumentCell) {
                MediaActivity.this.onItemClick(i, view, ((SharedDocumentCell) view).getMessage(), 0);
            } else if (selectedMode == 3 && view instanceof SharedLinkCell) {
                MediaActivity.this.onItemClick(i, view, ((SharedLinkCell) view).getMessage(), 0);
            }
        }
    });
    listView.setOnScrollListener(new AbsListView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
            if (scrollState == SCROLL_STATE_TOUCH_SCROLL && searching && searchWas) {
                AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
            }
            scrolling = scrollState != SCROLL_STATE_IDLE;
        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            if (searching && searchWas) {
                return;
            }
            if (visibleItemCount != 0 && firstVisibleItem + visibleItemCount > totalItemCount - 2
                    && !sharedMediaData[selectedMode].loading) {
                int type;
                if (selectedMode == 0) {
                    type = SharedMediaQuery.MEDIA_PHOTOVIDEO;
                } else if (selectedMode == 1) {
                    type = SharedMediaQuery.MEDIA_FILE;
                } else if (selectedMode == 2) {
                    type = SharedMediaQuery.MEDIA_AUDIO;
                } else if (selectedMode == 4) {
                    type = SharedMediaQuery.MEDIA_MUSIC;
                } else {
                    type = SharedMediaQuery.MEDIA_URL;
                }
                if (!sharedMediaData[selectedMode].endReached[0]) {
                    sharedMediaData[selectedMode].loading = true;
                    SharedMediaQuery.loadMedia(dialog_id, 0, 50, sharedMediaData[selectedMode].max_id[0], type,
                            true, classGuid);
                } else if (mergeDialogId != 0 && !sharedMediaData[selectedMode].endReached[1]) {
                    sharedMediaData[selectedMode].loading = true;
                    SharedMediaQuery.loadMedia(mergeDialogId, 0, 50, sharedMediaData[selectedMode].max_id[1],
                            type, true, classGuid);
                }
            }
        }
    });
    listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int i, long id) {
            if ((selectedMode == 1 || selectedMode == 4) && view instanceof SharedDocumentCell) {
                SharedDocumentCell cell = (SharedDocumentCell) view;
                MessageObject message = cell.getMessage();
                return MediaActivity.this.onItemLongClick(message, view, 0);
            } else if (selectedMode == 3 && view instanceof SharedLinkCell) {
                SharedLinkCell cell = (SharedLinkCell) view;
                MessageObject message = cell.getMessage();
                return MediaActivity.this.onItemLongClick(message, view, 0);
            }
            return false;
        }
    });

    for (int a = 0; a < 6; a++) {
        cellCache.add(new SharedPhotoVideoCell(context));
    }

    emptyView = new LinearLayout(context);
    emptyView.setOrientation(LinearLayout.VERTICAL);
    emptyView.setGravity(Gravity.CENTER);
    emptyView.setVisibility(View.GONE);
    emptyView.setBackgroundColor(0xfff0f0f0);
    frameLayout.addView(emptyView,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    emptyView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return true;
        }
    });

    emptyImageView = new ImageView(context);
    emptyView.addView(emptyImageView,
            LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT));

    emptyTextView = new TextView(context);
    emptyTextView.setTextColor(0xff8a8a8a);
    emptyTextView.setGravity(Gravity.CENTER);
    emptyTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 17);
    emptyTextView.setPadding(AndroidUtilities.dp(40), 0, AndroidUtilities.dp(40), AndroidUtilities.dp(128));
    emptyView.addView(emptyTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT,
            LayoutHelper.WRAP_CONTENT, Gravity.CENTER, 0, 24, 0, 0));

    progressView = new LinearLayout(context);
    progressView.setGravity(Gravity.CENTER);
    progressView.setOrientation(LinearLayout.VERTICAL);
    progressView.setVisibility(View.GONE);
    progressView.setBackgroundColor(0xfff0f0f0);
    frameLayout.addView(progressView,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));

    ProgressBar progressBar = new ProgressBar(context);
    progressView.addView(progressBar,
            LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT));

    switchToCurrentSelectedMode();

    if (!AndroidUtilities.isTablet()) {
        frameLayout.addView(new PlayerView(context, this), LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
                39, Gravity.TOP | Gravity.LEFT, 0, -36, 0, 0));
    }

    return fragmentView;
}

From source file:com.facebook.android.friendsmash.GameFragment.java

void setLives(int lives) {
    this.lives = lives;

    if (getActivity() != null) {
        // Update the livesContainer
        livesContainer.removeAllViews();
        for (int i = 0; i < lives; i++) {
            ImageView heartImageView = new ImageView(getActivity());
            heartImageView.setImageResource(R.drawable.heart_red);
            livesContainer.addView(heartImageView);
        }//w  w w. j av  a 2s.  com

        if (lives <= 0) {
            // User has no lives left, so end the game, passing back the score
            Bundle bundle = new Bundle();
            bundle.putInt("score", getScore());

            Intent i = new Intent();
            i.putExtras(bundle);

            getActivity().setResult(Activity.RESULT_OK, i);
            getActivity().finish();
        }
    }
}

From source file:kr.wdream.ui.MediaActivity.java

@Override
public View createView(Context context) {
    Log.d(LOG_TAG, "createView");
    actionBar.setBackButtonDrawable(new BackDrawable(false));
    actionBar.setTitle("");
    actionBar.setAllowOverlayTitle(false);
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override/*from   www. jav  a 2s . co m*/
        public void onItemClick(int id) {
            if (id == -1) {
                if (actionBar.isActionModeShowed()) {
                    for (int a = 1; a >= 0; a--) {
                        selectedFiles[a].clear();
                    }
                    cantDeleteMessagesCount = 0;
                    actionBar.hideActionMode();
                    listView.invalidateViews();
                } else {
                    finishFragment();
                }
            } else if (id == shared_media_item) {
                if (selectedMode == 0) {
                    return;
                }
                selectedMode = 0;
                switchToCurrentSelectedMode();
            } else if (id == files_item) {
                if (selectedMode == 1) {
                    return;
                }
                selectedMode = 1;
                switchToCurrentSelectedMode();
            } else if (id == links_item) {
                if (selectedMode == 3) {
                    return;
                }
                selectedMode = 3;
                switchToCurrentSelectedMode();
            } else if (id == music_item) {
                if (selectedMode == 4) {
                    return;
                }
                selectedMode = 4;
                switchToCurrentSelectedMode();
            } else if (id == delete) {
                if (getParentActivity() == null) {
                    return;
                }
                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                builder.setMessage(LocaleController.formatString("AreYouSureDeleteMessages",
                        kr.wdream.storyshop.R.string.AreYouSureDeleteMessages,
                        LocaleController.formatPluralString("items",
                                selectedFiles[0].size() + selectedFiles[1].size())));
                builder.setTitle(LocaleController.getString("AppName", kr.wdream.storyshop.R.string.AppName));
                builder.setPositiveButton(LocaleController.getString("OK", kr.wdream.storyshop.R.string.OK),
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                for (int a = 1; a >= 0; a--) {
                                    ArrayList<Integer> ids = new ArrayList<>(selectedFiles[a].keySet());
                                    ArrayList<Long> random_ids = null;
                                    TLRPC.EncryptedChat currentEncryptedChat = null;
                                    int channelId = 0;
                                    if (!ids.isEmpty()) {
                                        MessageObject msg = selectedFiles[a].get(ids.get(0));
                                        if (channelId == 0 && msg.messageOwner.to_id.channel_id != 0) {
                                            channelId = msg.messageOwner.to_id.channel_id;
                                        }
                                    }
                                    if ((int) dialog_id == 0) {
                                        currentEncryptedChat = MessagesController.getInstance()
                                                .getEncryptedChat((int) (dialog_id >> 32));
                                    }
                                    if (currentEncryptedChat != null) {
                                        random_ids = new ArrayList<>();
                                        for (HashMap.Entry<Integer, MessageObject> entry : selectedFiles[a]
                                                .entrySet()) {
                                            MessageObject msg = entry.getValue();
                                            if (msg.messageOwner.random_id != 0 && msg.type != 10) {
                                                random_ids.add(msg.messageOwner.random_id);
                                            }
                                        }
                                    }
                                    MessagesController.getInstance().deleteMessages(ids, random_ids,
                                            currentEncryptedChat, channelId);
                                    selectedFiles[a].clear();
                                }
                                actionBar.hideActionMode();
                                actionBar.closeSearchField();
                                cantDeleteMessagesCount = 0;
                            }
                        });
                builder.setNegativeButton(
                        LocaleController.getString("Cancel", kr.wdream.storyshop.R.string.Cancel), null);
                showDialog(builder.create());
            } else if (id == forward) {
                Bundle args = new Bundle();
                args.putBoolean("onlySelect", true);
                args.putInt("dialogsType", 1);
                DialogsActivity fragment = new DialogsActivity(args);
                fragment.setDelegate(new DialogsActivity.DialogsActivityDelegate() {
                    @Override
                    public void didSelectDialog(DialogsActivity fragment, long did, boolean param) {
                        int lower_part = (int) did;
                        if (lower_part != 0) {
                            Bundle args = new Bundle();
                            args.putBoolean("scrollToTopOnResume", true);
                            if (lower_part > 0) {
                                args.putInt("user_id", lower_part);
                            } else if (lower_part < 0) {
                                args.putInt("chat_id", -lower_part);
                            }
                            if (!MessagesController.checkCanOpenChat(args, fragment)) {
                                return;
                            }

                            ArrayList<MessageObject> fmessages = new ArrayList<>();
                            for (int a = 1; a >= 0; a--) {
                                ArrayList<Integer> ids = new ArrayList<>(selectedFiles[a].keySet());
                                Collections.sort(ids);
                                for (Integer id : ids) {
                                    if (id > 0) {
                                        fmessages.add(selectedFiles[a].get(id));
                                    }
                                }
                                selectedFiles[a].clear();
                            }
                            cantDeleteMessagesCount = 0;
                            actionBar.hideActionMode();

                            NotificationCenter.getInstance()
                                    .postNotificationName(NotificationCenter.closeChats);

                            ChatActivity chatActivity = new ChatActivity(args);
                            presentFragment(chatActivity, true);
                            chatActivity.showReplyPanel(true, null, fmessages, null, false, false);

                            if (!AndroidUtilities.isTablet()) {
                                removeSelfFromStack();
                            }
                        } else {
                            fragment.finishFragment();
                        }
                    }
                });
                presentFragment(fragment);
            }
        }
    });

    for (int a = 1; a >= 0; a--) {
        selectedFiles[a].clear();
    }
    cantDeleteMessagesCount = 0;
    actionModeViews.clear();

    final ActionBarMenu menu = actionBar.createMenu();
    searchItem = menu.addItem(0, kr.wdream.storyshop.R.drawable.ic_ab_search).setIsSearchField(true)
            .setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() {
                @Override
                public void onSearchExpand() {
                    dropDownContainer.setVisibility(View.GONE);
                    searching = true;
                }

                @Override
                public void onSearchCollapse() {
                    dropDownContainer.setVisibility(View.VISIBLE);
                    if (selectedMode == 1) {
                        documentsSearchAdapter.search(null);
                    } else if (selectedMode == 3) {
                        linksSearchAdapter.search(null);
                    } else if (selectedMode == 4) {
                        audioSearchAdapter.search(null);
                    }
                    searching = false;
                    searchWas = false;
                    switchToCurrentSelectedMode();
                }

                @Override
                public void onTextChanged(EditText editText) {
                    String text = editText.getText().toString();
                    if (text.length() != 0) {
                        searchWas = true;
                        switchToCurrentSelectedMode();
                    }
                    if (selectedMode == 1) {
                        if (documentsSearchAdapter == null) {
                            return;
                        }
                        documentsSearchAdapter.search(text);
                    } else if (selectedMode == 3) {
                        if (linksSearchAdapter == null) {
                            return;
                        }
                        linksSearchAdapter.search(text);
                    } else if (selectedMode == 4) {
                        if (audioSearchAdapter == null) {
                            return;
                        }
                        audioSearchAdapter.search(text);
                    }
                }
            });
    searchItem.getSearchField()
            .setHint(LocaleController.getString("Search", kr.wdream.storyshop.R.string.Search));
    searchItem.setVisibility(View.GONE);

    dropDownContainer = new ActionBarMenuItem(context, menu, 0);
    dropDownContainer.setSubMenuOpenSide(1);
    dropDownContainer.addSubItem(shared_media_item,
            LocaleController.getString("SharedMediaTitle", kr.wdream.storyshop.R.string.SharedMediaTitle), 0);
    dropDownContainer.addSubItem(files_item,
            LocaleController.getString("DocumentsTitle", kr.wdream.storyshop.R.string.DocumentsTitle), 0);
    if ((int) dialog_id != 0) {
        dropDownContainer.addSubItem(links_item,
                LocaleController.getString("LinksTitle", kr.wdream.storyshop.R.string.LinksTitle), 0);
        dropDownContainer.addSubItem(music_item,
                LocaleController.getString("AudioTitle", kr.wdream.storyshop.R.string.AudioTitle), 0);
    } else {
        TLRPC.EncryptedChat currentEncryptedChat = MessagesController.getInstance()
                .getEncryptedChat((int) (dialog_id >> 32));
        if (currentEncryptedChat != null
                && AndroidUtilities.getPeerLayerVersion(currentEncryptedChat.layer) >= 46) {
            dropDownContainer.addSubItem(music_item,
                    LocaleController.getString("AudioTitle", kr.wdream.storyshop.R.string.AudioTitle), 0);
        }
    }
    actionBar.addView(dropDownContainer, 0,
            LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT,
                    Gravity.TOP | Gravity.LEFT, AndroidUtilities.isTablet() ? 64 : 56, 0, 40, 0));
    dropDownContainer.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            dropDownContainer.toggleSubMenu();
        }
    });

    dropDown = new TextView(context);
    dropDown.setGravity(Gravity.LEFT);
    dropDown.setSingleLine(true);
    dropDown.setLines(1);
    dropDown.setMaxLines(1);
    dropDown.setEllipsize(TextUtils.TruncateAt.END);
    dropDown.setTextColor(0xffffffff);
    dropDown.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    dropDown.setCompoundDrawablesWithIntrinsicBounds(0, 0, kr.wdream.storyshop.R.drawable.ic_arrow_drop_down,
            0);
    dropDown.setCompoundDrawablePadding(AndroidUtilities.dp(4));
    dropDown.setPadding(0, 0, AndroidUtilities.dp(10), 0);
    dropDownContainer.addView(dropDown, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT,
            LayoutHelper.WRAP_CONTENT, Gravity.CENTER_VERTICAL, 16, 0, 0, 0));

    final ActionBarMenu actionMode = actionBar.createActionMode();

    selectedMessagesCountTextView = new NumberTextView(actionMode.getContext());
    selectedMessagesCountTextView.setTextSize(18);
    selectedMessagesCountTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    selectedMessagesCountTextView.setTextColor(0xff737373);
    selectedMessagesCountTextView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return true;
        }
    });
    actionMode.addView(selectedMessagesCountTextView,
            LayoutHelper.createLinear(0, LayoutHelper.MATCH_PARENT, 1.0f, 65, 0, 0, 0));

    if ((int) dialog_id != 0) {
        actionModeViews.add(actionMode.addItem(forward, kr.wdream.storyshop.R.drawable.ic_ab_fwd_forward,
                Theme.ACTION_BAR_MODE_SELECTOR_COLOR, null, AndroidUtilities.dp(54)));
    }
    actionModeViews.add(actionMode.addItem(delete, kr.wdream.storyshop.R.drawable.ic_ab_fwd_delete,
            Theme.ACTION_BAR_MODE_SELECTOR_COLOR, null, AndroidUtilities.dp(54)));

    photoVideoAdapter = new SharedPhotoVideoAdapter(context);
    documentsAdapter = new SharedDocumentsAdapter(context, 1);
    audioAdapter = new SharedDocumentsAdapter(context, 4);
    documentsSearchAdapter = new MediaSearchAdapter(context, 1);
    audioSearchAdapter = new MediaSearchAdapter(context, 4);
    linksSearchAdapter = new MediaSearchAdapter(context, 3);
    linksAdapter = new SharedLinksAdapter(context);

    FrameLayout frameLayout;
    fragmentView = frameLayout = new FrameLayout(context);

    listView = new SectionsListView(context);
    listView.setDivider(null);
    listView.setDividerHeight(0);
    listView.setDrawSelectorOnTop(true);
    listView.setClipToPadding(false);
    frameLayout.addView(listView,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) {
            if ((selectedMode == 1 || selectedMode == 4) && view instanceof SharedDocumentCell) {
                MediaActivity.this.onItemClick(i, view, ((SharedDocumentCell) view).getMessage(), 0);
            } else if (selectedMode == 3 && view instanceof SharedLinkCell) {
                MediaActivity.this.onItemClick(i, view, ((SharedLinkCell) view).getMessage(), 0);
            }
        }
    });
    listView.setOnScrollListener(new AbsListView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
            if (scrollState == SCROLL_STATE_TOUCH_SCROLL && searching && searchWas) {
                AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
            }
            scrolling = scrollState != SCROLL_STATE_IDLE;
        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            if (searching && searchWas) {
                return;
            }
            if (visibleItemCount != 0 && firstVisibleItem + visibleItemCount > totalItemCount - 2
                    && !sharedMediaData[selectedMode].loading) {
                int type;
                if (selectedMode == 0) {
                    type = SharedMediaQuery.MEDIA_PHOTOVIDEO;
                } else if (selectedMode == 1) {
                    type = SharedMediaQuery.MEDIA_FILE;
                } else if (selectedMode == 2) {
                    type = SharedMediaQuery.MEDIA_AUDIO;
                } else if (selectedMode == 4) {
                    type = SharedMediaQuery.MEDIA_MUSIC;
                } else {
                    type = SharedMediaQuery.MEDIA_URL;
                }
                if (!sharedMediaData[selectedMode].endReached[0]) {
                    sharedMediaData[selectedMode].loading = true;
                    SharedMediaQuery.loadMedia(dialog_id, 0, 50, sharedMediaData[selectedMode].max_id[0], type,
                            true, classGuid);
                } else if (mergeDialogId != 0 && !sharedMediaData[selectedMode].endReached[1]) {
                    sharedMediaData[selectedMode].loading = true;
                    SharedMediaQuery.loadMedia(mergeDialogId, 0, 50, sharedMediaData[selectedMode].max_id[1],
                            type, true, classGuid);
                }
            }
        }
    });
    listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int i, long id) {
            if ((selectedMode == 1 || selectedMode == 4) && view instanceof SharedDocumentCell) {
                SharedDocumentCell cell = (SharedDocumentCell) view;
                MessageObject message = cell.getMessage();
                return MediaActivity.this.onItemLongClick(message, view, 0);
            } else if (selectedMode == 3 && view instanceof SharedLinkCell) {
                SharedLinkCell cell = (SharedLinkCell) view;
                MessageObject message = cell.getMessage();
                return MediaActivity.this.onItemLongClick(message, view, 0);
            }
            return false;
        }
    });

    for (int a = 0; a < 6; a++) {
        cellCache.add(new SharedPhotoVideoCell(context));
    }

    emptyView = new LinearLayout(context);
    emptyView.setOrientation(LinearLayout.VERTICAL);
    emptyView.setGravity(Gravity.CENTER);
    emptyView.setVisibility(View.GONE);
    emptyView.setBackgroundColor(0xfff0f0f0);
    frameLayout.addView(emptyView,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    emptyView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return true;
        }
    });

    emptyImageView = new ImageView(context);
    emptyView.addView(emptyImageView,
            LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT));

    emptyTextView = new TextView(context);
    emptyTextView.setTextColor(0xff8a8a8a);
    emptyTextView.setGravity(Gravity.CENTER);
    emptyTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 17);
    emptyTextView.setPadding(AndroidUtilities.dp(40), 0, AndroidUtilities.dp(40), AndroidUtilities.dp(128));
    emptyView.addView(emptyTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT,
            LayoutHelper.WRAP_CONTENT, Gravity.CENTER, 0, 24, 0, 0));

    progressView = new LinearLayout(context);
    progressView.setGravity(Gravity.CENTER);
    progressView.setOrientation(LinearLayout.VERTICAL);
    progressView.setVisibility(View.GONE);
    progressView.setBackgroundColor(0xfff0f0f0);
    frameLayout.addView(progressView,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));

    ProgressBar progressBar = new ProgressBar(context);
    progressView.addView(progressBar,
            LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT));

    switchToCurrentSelectedMode();

    if (!AndroidUtilities.isTablet()) {
        frameLayout.addView(new PlayerView(context, this), LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
                39, Gravity.TOP | Gravity.LEFT, 0, -36, 0, 0));
    }

    return fragmentView;
}

From source file:io.bunnyblue.noticedog.app.lockscreen.ui.LockScreenWidget.java

View duplicateView(View view) {
    Bitmap b = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Config.ARGB_8888);
    view.draw(new Canvas(b));
    ImageView imageView = new ImageView(this.context);
    imageView.setImageBitmap(b);//from  w w w  . ja v  a2s .c om
    return imageView;
}

From source file:im.vector.services.EventStreamService.java

/**
 * Prepare a notification for the expected event.
 * @param event the event/* www  .jav  a2s .c  om*/
 * @param roomState the room state
 * @param bingRule the bing rule
 */
public void prepareNotification(Event event, RoomState roomState, BingRule bingRule) {
    String uid = computeEventUID(event);

    if (mPendingNotifications.indexOf(uid) >= 0) {
        Log.d(LOG_TAG, "prepareNotification : don't bing - the event was already binged");
        checkNotification();
        return;
    }

    mPendingNotifications.add(uid);

    // define a bing rule if it is not provided
    if (null == bingRule) {
        bingRule = mDefaultBingRule;
    }

    if (!mGcmRegistrationManager.areDeviceNotificationsAllowed()) {
        Log.d(LOG_TAG, "prepareNotification : the push has been disable on this device");
        return;
    }

    if (event.isCallEvent()) {
        prepareCallNotification(event, bingRule);
        return;
    }

    final String roomId = event.roomId;

    // Just don't bing for the room the user's currently in
    if (!VectorApp.isAppInBackground() && (roomId != null)
            && event.roomId.equals(ViewedRoomTracker.getInstance().getViewedRoomId())) {
        Log.d(LOG_TAG, "prepareNotification : don't bing because it is the currently opened room");
        return;
    }

    String senderID = event.getSender();
    // FIXME: Support event contents with no body
    if (!event.content.getAsJsonObject().has("body")) {
        // only the membership events are supported
        if (!Event.EVENT_TYPE_STATE_ROOM_MEMBER.equals(event.type) && !event.isCallEvent()) {
            Log.d(LOG_TAG, "onBingEvent : don't bing - no body and not a call event");
            return;
        }
    }

    MXSession session = Matrix.getMXSession(getApplicationContext(), event.getMatrixId());

    // invalid session ?
    // should never happen.
    // But it could be triggered because of multi accounts management.
    // The dedicated account is removing but some pushes are still received.
    if ((null == session) || !session.isAlive()) {
        Log.d(LOG_TAG, "prepareNotification : don't bing - no session");
        return;
    }

    Room room = session.getDataHandler().getRoom(roomId);

    // invalid room ?
    if (null == room) {
        Log.d(LOG_TAG, "prepareNotification : don't bing - the room does not exist");
        return;
    }

    boolean isInvitationEvent = false;
    String body;

    if (Event.EVENT_TYPE_STATE_ROOM_MEMBER.equals(event.type)) {
        body = EventDisplay.getMembershipNotice(getApplicationContext(), event, roomState);

        try {
            isInvitationEvent = "invite"
                    .equals(event.getContentAsJsonObject().getAsJsonPrimitive("membership").getAsString());
        } catch (Exception e) {
            Log.e(LOG_TAG, "prepareNotification : invitation parsing failed");
        }

    } else {
        body = event.getContentAsJsonObject().getAsJsonPrimitive("body").getAsString();
    }

    String from = "";
    Bitmap largeBitmap = null;

    // when the event is an invitation one
    // don't check if the sender ID is known because the members list are not yet downloaded
    if (!isInvitationEvent) {
        RoomMember member = room.getMember(senderID);

        // invalid member
        if (null == member) {
            return;
        }

        from = member.getName();

        // is there any avatar url
        if (!TextUtils.isEmpty(member.avatarUrl)) {
            int size = getApplicationContext().getResources()
                    .getDimensionPixelSize(R.dimen.profile_avatar_size);

            // check if the thumbnail is already downloaded
            File f = session.getMediasCache().thumbnailCacheFile(member.avatarUrl, size);

            if (null != f) {
                BitmapFactory.Options options = new BitmapFactory.Options();
                options.inPreferredConfig = Bitmap.Config.ARGB_8888;
                largeBitmap = BitmapFactory.decodeFile(f.getPath(), options);
            } else {
                session.getMediasCache().loadAvatarThumbnail(session.getHomeserverConfig(),
                        new ImageView(getApplicationContext()), member.avatarUrl, size);
            }
        }
    }

    if (null == largeBitmap) {
        largeBitmap = VectorUtils.getAvatar(getApplicationContext(), VectorUtils.getAvatarColor(senderID),
                TextUtils.isEmpty(from) ? senderID : from, true);
    }

    mNotificationSessionId = session.getCredentials().userId;
    mNotificationRoomId = roomId;
    mNotificationEventId = event.eventId;

    Log.d(LOG_TAG, "prepareNotification : with sound "
            + bingRule.isDefaultNotificationSound(bingRule.notificationSound()));

    mLatestNotification = NotificationUtils.buildMessageNotification(EventStreamService.this, from,
            session.getCredentials().userId, Matrix.getMXSessions(getApplicationContext()).size() > 1,
            largeBitmap, CommonActivityUtils.getBadgeCount(), body, event.roomId,
            getRoomName(session, room, event),
            bingRule.isDefaultNotificationSound(bingRule.notificationSound()), isInvitationEvent);
}

From source file:com.keylesspalace.tusky.activity.ComposeActivity.java

private void addMediaToQueue(QueuedMedia.Type type, Bitmap preview, Uri uri, long mediaSize) {
    final QueuedMedia item = new QueuedMedia(type, uri, new ImageView(this), mediaSize);
    ImageView view = item.preview;
    Resources resources = getResources();
    int side = resources.getDimensionPixelSize(R.dimen.compose_media_preview_side);
    int margin = resources.getDimensionPixelSize(R.dimen.compose_media_preview_margin);
    int marginBottom = resources.getDimensionPixelSize(R.dimen.compose_media_preview_margin_bottom);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(side, side);
    layoutParams.setMargins(margin, 0, margin, marginBottom);
    view.setLayoutParams(layoutParams);// w w w.j ava 2 s . com
    view.setScaleType(ImageView.ScaleType.CENTER_CROP);
    view.setImageBitmap(preview);

    view.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            removeMediaFromQueue(item);
        }
    });
    mediaPreviewBar.addView(view);
    mediaQueued.add(item);
    int queuedCount = mediaQueued.size();
    if (queuedCount == 1) {
        /* The media preview bar is actually not inset in the EditText, it just overlays it and
         * is aligned to the bottom. But, so that text doesn't get hidden under it, extra
         * padding is added at the bottom of the EditText. */
        int totalHeight = side + margin + marginBottom;
        textEditor.setPadding(textEditor.getPaddingLeft(), textEditor.getPaddingTop(),
                textEditor.getPaddingRight(), totalHeight);
        // If there's one video in the queue it is full, so disable the button to queue more.
        if (item.type == QueuedMedia.Type.VIDEO) {
            disableMediaPicking();
        }
    } else if (queuedCount >= Status.MAX_MEDIA_ATTACHMENTS) {
        // Limit the total media attachments, also.
        disableMediaPicking();
    }
    if (queuedCount >= 1) {
        showMarkSensitive(true);
    }
    waitForMediaLatch.countUp();
    if (mediaSize > STATUS_MEDIA_SIZE_LIMIT && type == QueuedMedia.Type.IMAGE) {
        downsizeMedia(item);
    } else {
        uploadMedia(item);
    }
}

From source file:com.ushahidi.android.app.ui.phone.AddReportActivity.java

@Override
public View makeView() {
    ImageView i = new ImageView(this);
    i.setAdjustViewBounds(true);//w  w  w.j ava 2 s. c om
    i.setScaleType(ImageView.ScaleType.FIT_CENTER);
    i.setLayoutParams(new ImageSwitcher.LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT));

    return i;
}

From source file:im.neon.services.EventStreamService.java

/**
 * Prepare a notification for the expected event.
 * @param event the event//ww  w .j  a  v  a2  s.co m
 * @param roomState the room state
 * @param bingRule the bing rule
 */
public void prepareNotification(Event event, RoomState roomState, BingRule bingRule) {
    String uid = computeEventUID(event);

    if (mPendingNotifications.indexOf(uid) >= 0) {
        Log.d(LOG_TAG, "prepareNotification : don't bing - the event was already binged");
        checkNotification();
        return;
    }

    mPendingNotifications.add(uid);

    // define a bing rule if it is not provided
    if (null == bingRule) {
        bingRule = mDefaultBingRule;
    }

    if (!mGcmRegistrationManager.areDeviceNotificationsAllowed()) {
        Log.d(LOG_TAG, "prepareNotification : the push has been disable on this device");
        return;
    }

    if (event.isCallEvent()) {
        prepareCallNotification(event, bingRule);
        return;
    }

    final String roomId = event.roomId;

    // Just don't bing for the room the user's currently in
    if (!VectorApp.isAppInBackground() && (roomId != null)
            && event.roomId.equals(ViewedRoomTracker.getInstance().getViewedRoomId())) {
        Log.d(LOG_TAG, "prepareNotification : don't bing because it is the currently opened room");
        return;
    }

    String senderID = event.getSender();
    // FIXME: Support event contents with no body
    if (!event.getContent().getAsJsonObject().has("body")) {
        // only the membership events are supported
        if (!Event.EVENT_TYPE_STATE_ROOM_MEMBER.equals(event.getType()) && !event.isCallEvent()) {
            Log.d(LOG_TAG, "onBingEvent : don't bing - no body and not a call event");
            return;
        }
    }

    MXSession session = Matrix.getMXSession(getApplicationContext(), event.getMatrixId());

    // invalid session ?
    // should never happen.
    // But it could be triggered because of multi accounts management.
    // The dedicated account is removing but some pushes are still received.
    if ((null == session) || !session.isAlive()) {
        Log.d(LOG_TAG, "prepareNotification : don't bing - no session");
        return;
    }

    Room room = session.getDataHandler().getRoom(roomId);

    // invalid room ?
    if (null == room) {
        Log.d(LOG_TAG, "prepareNotification : don't bing - the room does not exist");
        return;
    }

    boolean isInvitationEvent = false;

    EventDisplay eventDisplay = new EventDisplay(getApplicationContext(), event, roomState);
    eventDisplay.setPrependMessagesWithAuthor(false);
    String body = eventDisplay.getTextualDisplay().toString();

    if (TextUtils.isEmpty(body)) {
        Log.e(LOG_TAG, "prepareNotification : the event " + event.eventId + " cannot be displayed");
        return;
    }

    if (Event.EVENT_TYPE_STATE_ROOM_MEMBER.equals(event.getType())) {
        try {
            isInvitationEvent = "invite"
                    .equals(event.getContentAsJsonObject().getAsJsonPrimitive("membership").getAsString());
        } catch (Exception e) {
            Log.e(LOG_TAG, "prepareNotification : invitation parsing failed");
        }
    }

    String from = "";
    Bitmap largeBitmap = null;

    // when the event is an invitation one
    // don't check if the sender ID is known because the members list are not yet downloaded
    if (!isInvitationEvent) {
        RoomMember member = room.getMember(senderID);

        // invalid member
        if (null == member) {
            return;
        }

        from = member.getName();

        // is there any avatar url
        if (!TextUtils.isEmpty(member.avatarUrl)) {
            int size = getApplicationContext().getResources()
                    .getDimensionPixelSize(R.dimen.profile_avatar_size);

            // check if the thumbnail is already downloaded
            File f = session.getMediasCache().thumbnailCacheFile(member.avatarUrl, size);

            if (null != f) {
                BitmapFactory.Options options = new BitmapFactory.Options();
                options.inPreferredConfig = Bitmap.Config.ARGB_8888;
                try {
                    largeBitmap = BitmapFactory.decodeFile(f.getPath(), options);
                } catch (OutOfMemoryError oom) {
                    Log.e(LOG_TAG, "decodeFile failed with an oom");
                }
            } else {
                session.getMediasCache().loadAvatarThumbnail(session.getHomeserverConfig(),
                        new ImageView(getApplicationContext()), member.avatarUrl, size);
            }
        }
    }

    if (null == largeBitmap) {
        largeBitmap = VectorUtils.getAvatar(getApplicationContext(), VectorUtils.getAvatarColor(senderID),
                TextUtils.isEmpty(from) ? senderID : from, true);
    }

    mNotificationSessionId = session.getCredentials().userId;
    mNotificationRoomId = roomId;
    mNotificationEventId = event.eventId;

    Log.d(LOG_TAG, "prepareNotification : with sound "
            + bingRule.isDefaultNotificationSound(bingRule.notificationSound()));

    mLatestNotification = NotificationUtils.buildMessageNotification(EventStreamService.this, from,
            session.getCredentials().userId, Matrix.getMXSessions(getApplicationContext()).size() > 1,
            largeBitmap, CommonActivityUtils.getBadgeCount(), body, event.roomId,
            getRoomName(session, room, event),
            bingRule.isDefaultNotificationSound(bingRule.notificationSound()), isInvitationEvent);
}

From source file:org.de.jmg.learn._MainActivity.java

public void getVokabel(final boolean showBeds, boolean LoadNext, boolean requestFocusEdWord, boolean DontPrompt)
        throws Exception {

    if (iv != null) {
        iv.setVisibility(View.GONE);
    }//  ww  w .j a  v a  2 s. c o m
    if (iv2 != null)
        iv2.setVisibility(View.GONE);
    try {
        if (_btnRight == null)
            return;
        EndEdit(DontPrompt);
        setBtnsEnabled(true);
        if (showBeds && _vok.getIndex() >= 1) {
            _btnRight.setEnabled(true);
            _btnWrong.setEnabled(true);
            _btnEdit.setEnabled(true);
            _btnSkip.setEnabled(true);
            _btnView.setEnabled(true);
        } else {
            _btnRight.setEnabled(false);
            _btnWrong.setEnabled(false);
            if (_vok.getIndex() < 1) {
                _btnEdit.setEnabled(false);
                _btnSkip.setEnabled(false);
                _btnView.setEnabled(false);
            }
        }
        if (LoadNext)
            _vok.setLernIndex((short) (_vok.getLernIndex() + 1));

        View v;
        TextView t;
        String txtBed = getString(R.string.cloze);

        if (showBeds) {
            v = findViewById(R.id.txtMeaning1);
            t = (TextView) v;
            assert t != null;
            t.setText(lib.getSpanableString(_vok.getBedeutung1()));
            txtBed = t.getText().toString();
        }

        v = findViewById(R.id.word);
        t = (TextView) v;
        assert t != null;
        String txtWord = getString(R.string.cloze);
        if (!_vok.reverse || showBeds) {
            t.setText(lib.getSpanableString(_vok.getWort()), TextView.BufferType.SPANNABLE);
            txtWord = t.getText().toString();
            txtWord = replaceClozes(txtWord, txtBed);
            speak(txtWord, _vok.getLangWord(), "word", true);
        } else {
            t.setText("");
        }

        if (_vok.getSprache() == EnumSprachen.Hebrew || _vok.getSprache() == EnumSprachen.Griechisch
                || (_vok.getFontWort().getName().equalsIgnoreCase("Cardo"))) {
            t.setTypeface(_vok.TypefaceCardo);
            _txtedWord.setTypeface(_vok.TypefaceCardo);
        } else {
            t.setTypeface(Typeface.DEFAULT);
            _txtedWord.setTypeface(Typeface.DEFAULT);
        }
        t.scrollTo(0, 0);

        v = findViewById(R.id.Comment);
        t = (TextView) v;
        assert t != null;
        t.setVisibility(View.VISIBLE);

        SpannableString tspanKom = lib.getSpanableString(_vok.getKommentar());
        URLSpan[] urlSpans = tspanKom.getSpans(0, tspanKom.length(), URLSpan.class);
        for (final URLSpan span : urlSpans) {
            int start = tspanKom.getSpanStart(span);
            int end = tspanKom.getSpanEnd(span);
            String txt = tspanKom.toString().substring(start, end);
            if (txtIsPicture(txt)) {
                tspanKom.removeSpan(span);
                tspanKom.setSpan(new urlclickablespan(span.getURL()) {
                    @Override
                    public void onClick(View widget) {
                        Bitmap b;
                        try {
                            b = lib.downloadpicture(this.url);
                        } catch (Exception ex) {
                            b = null;
                        }
                        if (b != null) {
                            if (iv == null) {
                                iv = new ImageView(context);
                                SetTouchListener(iv);
                            }
                            b = resizeBM(b);
                            iv.setImageBitmap(b);
                            if (iv.getParent() == null) {
                                try {
                                    LayoutParams p = _txtMeaning1.getLayoutParams();
                                    //p.width = LayoutParams.WRAP_CONTENT;
                                    //p.height = LayoutParams.WRAP_CONTENT;
                                    rellayoutMain.addView(iv, p);
                                } catch (Exception ex) {
                                    Log.e("addImageView", ex.getMessage(), ex);
                                }
                            } else {
                                Log.d("ImageView", "exists");
                            }
                            _txtMeaning1.setVisibility(View.GONE);
                            iv.setVisibility(View.VISIBLE);
                        }
                    }
                }, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
        }
        t.setText(tspanKom, TextView.BufferType.SPANNABLE);

        if (_vok.getSprache() == EnumSprachen.Hebrew || _vok.getSprache() == EnumSprachen.Griechisch
                || (_vok.getFontKom().getName().equalsIgnoreCase("Cardo"))) {
            t.setTypeface(_vok.TypefaceCardo);
            _txtedKom.setTypeface(_vok.TypefaceCardo);
        } else {
            t.setTypeface(Typeface.DEFAULT);
            _txtedKom.setTypeface(Typeface.DEFAULT);
        }
        if (_isSmallDevice && libString.IsNullOrEmpty(t.getText().toString())) {
            t.setVisibility(View.GONE);
        } else {
            t.setVisibility(View.VISIBLE);
        }
        t.scrollTo(0, 0);

        v = findViewById(R.id.txtMeaning1);
        t = (TextView) v;
        assert t != null;
        if (!libString.IsNullOrEmpty(_vok.getBedeutung2())) {
            t.setImeOptions(EditorInfo.IME_ACTION_NEXT);
        }
        if (_vok.reverse || showBeds) {
            SpannableString tspan = lib.getSpanableString(_vok.getBedeutung1());
            //final String picname = _main.getString(R.string.picture);
            t.setVisibility(View.VISIBLE);
            if (txtIsPicture(tspan.toString())) {
                URLSpan urlspn[] = tspan.getSpans(0, tspan.length(), URLSpan.class);
                for (URLSpan url : urlspn) {
                    Bitmap b;
                    try {
                        b = lib.downloadpicture(url.getURL());
                    } catch (Exception ex) {
                        b = null;
                    }
                    if (b != null) {
                        if (iv == null) {
                            iv = new ImageView(context);
                            SetTouchListener(iv);
                        }
                        b = resizeBM(b);
                        iv.setImageBitmap(b);
                        if (iv.getParent() == null) {
                            try {
                                LayoutParams p = t.getLayoutParams();
                                //p.width = LayoutParams.WRAP_CONTENT;
                                //p.height = LayoutParams.WRAP_CONTENT;
                                rellayoutMain.addView(iv, p);
                            } catch (Exception ex) {
                                Log.e("Imagview", ex.getMessage(), ex);
                            }
                        } else {
                            Log.d("ImageView", "exists");
                        }
                        t.setVisibility(View.GONE);
                        iv.setVisibility(View.VISIBLE);
                    }
                }

            } else {
                // iv.setVisibility(View.GONE);
                t.setVisibility(View.VISIBLE);
            }

            t.setText(tspan);
        } else {
            t.setText(Vokabel.getComment(_vok.getBedeutung1()));
        }
        if (_vok.reverse || showBeds) {
            String txt = t.getText().toString();
            txt = replaceClozes(txt, txtWord);
            speak(txt, _vok.getLangMeaning(), "meaning1", _vok.reverse);
        }
        if (_vok.getFontBed().getName().equalsIgnoreCase("Cardo")) {
            t.setTypeface(_vok.TypefaceCardo);
        } else {
            t.setTypeface(Typeface.DEFAULT);
        }
        t.setOnFocusChangeListener(FocusListenerMeaning1);
        t.scrollTo(0, 0);

        v = findViewById(R.id.txtMeaning2);
        t = (TextView) v;
        assert t != null;
        t.setText((_vok.reverse || showBeds ? _vok.getBedeutung2() : Vokabel.getComment(_vok.getBedeutung2())));
        if (_vok.getFontBed().getName().equalsIgnoreCase("Cardo")) {
            t.setTypeface(_vok.TypefaceCardo);
        } else {
            t.setTypeface(Typeface.DEFAULT);
        }
        if (libString.IsNullOrEmpty(_vok.getBedeutung2()) || _vok.getCardMode()) {
            t.setVisibility(View.GONE);
            _txtMeaning1.setImeOptions(EditorInfo.IME_ACTION_DONE);
        } else {
            t.setVisibility(View.VISIBLE);
            _txtMeaning1.setImeOptions(EditorInfo.IME_ACTION_NEXT);
            if (_vok.reverse || showBeds) {
                String txt = t.getText().toString();
                //if (txtWord != null)
                //   txt = txt.replaceAll("_{2,}", txtWord).replaceAll("\\.{4,}", txtWord);
                speak(txt, _vok.getLangMeaning(), "meaning2");
            }
        }

        v = findViewById(R.id.txtMeaning3);
        t = (TextView) v;
        assert t != null;
        t.setText((_vok.reverse || showBeds ? _vok.getBedeutung3() : Vokabel.getComment(_vok.getBedeutung3())));
        if (_vok.getFontBed().getName().equalsIgnoreCase("Cardo")) {
            t.setTypeface(_vok.TypefaceCardo);
        } else {
            t.setTypeface(Typeface.DEFAULT);
        }
        if (libString.IsNullOrEmpty(_vok.getBedeutung3()) || _vok.getCardMode()) {
            t.setVisibility(View.GONE);
            _txtMeaning2.setImeOptions(EditorInfo.IME_ACTION_DONE);
        } else {
            t.setVisibility(View.VISIBLE);
            _txtMeaning2.setImeOptions(EditorInfo.IME_ACTION_NEXT);
            _txtMeaning3.setImeOptions(EditorInfo.IME_ACTION_DONE);
            if (_vok.reverse || showBeds) {
                String txt = t.getText().toString();
                //if (txtWord != null)
                //   txt = txt.replaceAll("_{2,}", txtWord).replaceAll("\\.{4,}", txtWord);
                speak(txt, _vok.getLangMeaning(), "meaning3");
            }
        }

        if (_vok.reverse && showBeds)
            speak(txtWord, _vok.getLangWord(), "word");

        lib.setBgEditText(_txtMeaning1, _MeaningBG);
        lib.setBgEditText(_txtMeaning2, _MeaningBG);
        lib.setBgEditText(_txtMeaning3, _MeaningBG);
        if (!_isSmallDevice && !requestFocusEdWord) {
            _txtMeaning1.requestFocus();
        } else {
            if (!requestFocusEdWord)
                _txtWord.requestFocus();
            else
                _txtedWord.requestFocus();
        }
        SetActionBarTitle();

        _scrollView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

            @Override
            public void onGlobalLayout() {

                lib.removeLayoutListener(_scrollView.getViewTreeObserver(), this);
                hideKeyboard();
                if (showBeds) {
                    _scrollView.scrollTo(0, _txtMeaning1.getTop());
                } else {
                    _txtWord.requestFocus();
                    _scrollView.fullScroll(View.FOCUS_UP);
                }
            }
        });

    } catch (Exception e) {

        lib.ShowException(_main, e);
    }

}