Example usage for android.widget ImageView post

List of usage examples for android.widget ImageView post

Introduction

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

Prototype

public boolean post(Runnable action) 

Source Link

Document

Causes the Runnable to be added to the message queue.

Usage

From source file:im.neon.adapters.VectorMediasViewerAdapter.java

/**
 * Download the video file/*from w  ww . j  av a  2  s  .  c  o m*/
 * @param view the slider page view
 * @param position the item position
 * @param force true to do not check the auto playmode
 */
public void downloadVideo(final View view, final int position, boolean force) {
    final VideoView videoView = (VideoView) view.findViewById(R.id.media_slider_videoview);
    final ImageView thumbView = (ImageView) view.findViewById(R.id.media_slider_video_thumbnail);
    final PieFractionView pieFractionView = (PieFractionView) view.findViewById(R.id.media_slider_piechart);

    final SlidableMediaInfo mediaInfo = mMediasMessagesList.get(position);
    final String loadingUri = mediaInfo.mMediaUrl;
    final String thumbnailUrl = mediaInfo.mThumbnailUrl;

    // check if the media has been downloaded
    File file = mMediasCache.mediaCacheFile(loadingUri, mediaInfo.mMimeType);
    if (null != file) {
        mHighResMediaIndex.add(position);
        loadVideo(position, view, thumbnailUrl, Uri.fromFile(file).toString(), mediaInfo.mMimeType);

        if (position == mAutoPlayItemAt) {
            playVideo(view, videoView, mediaInfo.mMediaUrl, mediaInfo.mMimeType);
        }
        mAutoPlayItemAt = -1;
        return;
    }

    // the video download starts only when the user taps on click
    // let assumes it might configurable
    if (!force && (mAutoPlayItemAt != position)) {
        return;
    }

    // else download it
    String downloadId = mMediasCache.downloadMedia(mContext, mSession.getHomeserverConfig(), loadingUri,
            mediaInfo.mMimeType, mediaInfo.mEncryptedFileInfo);

    if (null != downloadId) {
        pieFractionView.setVisibility(View.VISIBLE);
        pieFractionView.setFraction(mMediasCache.getProgressValueForDownloadId(downloadId));
        pieFractionView.setTag(downloadId);

        mMediasCache.addDownloadListener(downloadId, new MXMediaDownloadListener() {

            @Override
            public void onDownloadError(String downloadId, JsonElement jsonElement) {
                MatrixError error = JsonUtils.toMatrixError(jsonElement);

                if ((null != error) && error.isSupportedErrorCode()) {
                    Toast.makeText(VectorMediasViewerAdapter.this.mContext, error.getLocalizedMessage(),
                            Toast.LENGTH_LONG).show();
                }
            }

            @Override
            public void onDownloadProgress(String aDownloadId, DownloadStats stats) {
                if (aDownloadId.equals(pieFractionView.getTag())) {
                    pieFractionView.setFraction(stats.mProgress);
                }
            }

            @Override
            public void onDownloadComplete(String aDownloadId) {
                if (aDownloadId.equals(pieFractionView.getTag())) {
                    pieFractionView.setVisibility(View.GONE);

                    final File mediaFile = mMediasCache.mediaCacheFile(loadingUri, mediaInfo.mMimeType);

                    if (null != mediaFile) {
                        mHighResMediaIndex.add(position);

                        Uri uri = Uri.fromFile(mediaFile);
                        final String newHighResUri = uri.toString();

                        thumbView.post(new Runnable() {
                            @Override
                            public void run() {
                                loadVideo(position, view, thumbnailUrl, newHighResUri, mediaInfo.mMimeType);

                                if (position == mAutoPlayItemAt) {
                                    playVideo(view, videoView, mediaInfo.mMediaUrl, mediaInfo.mMimeType);
                                    mAutoPlayItemAt = -1;
                                }
                            }
                        });
                    }
                }
            }
        });
    }
}

From source file:com.zoffcc.applications.zanavi.Navit.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);
    ////from  w ww. j  a  va2 s. co m
    menu.clear();

    // load the menu from XML
    getMenuInflater().inflate(R.menu.actionbaricons, menu);

    // NavitOverflowMenuItemID = R.id.item_overflow_menu_button;
    menu.findItem(R.id.share_menu_destination).setTitle(Navit.get_text("Share Destination"));
    menu.findItem(R.id.share_menu_location).setTitle(Navit.get_text("Share my Location"));
    menu.findItem(R.id.search_menu_offline).setTitle(get_text("address search (offline)"));
    menu.findItem(R.id.search_menu_online).setTitle(get_text("address search (online)"));
    menu.findItem(R.id.item_recentdest_menu_button).setTitle(get_text("Recent destinations"));
    menu.findItem(R.id.item_settings_menu_button).setTitle(get_text("Settings"));
    menu.findItem(R.id.item_search_menu_button).setTitle(get_text("Search"));

    // --- download icon ---
    menu.findItem(R.id.item_download_menu_button).setTitle(get_text("downloading map"));
    // --- download icon ---

    //
    menu.findItem(R.id.overflow_share_location).setTitle(Navit.get_text("Share my Location"));
    menu.findItem(R.id.overflow_share_destination).setTitle(Navit.get_text("Share Destination"));
    menu.findItem(R.id.overflow_settings).setTitle(Navit.get_text("Settings"));
    menu.findItem(R.id.overflow_zoom_to_route).setTitle(Navit.get_text("Zoom to Route"));

    if (ZANaviNormalDonateActivity.on_amazon_device) {
        menu.findItem(R.id.overflow_donate_item).setTitle(Navit.get_text("Donate"));
    } else {
        menu.findItem(R.id.overflow_donate_item).setTitle(Navit.get_text("Donate with Google Play"));
    }
    menu.findItem(R.id.overflow_donate_bitcoins_item).setTitle(Navit.get_text("Donate with Bitcoin"));
    //. TRANSLATORS: text to translate is: exit ZANavi
    menu.findItem(R.id.overflow_exit).setTitle(Navit.get_text("exit navit"));
    menu.findItem(R.id.overflow_toggle_poi).setTitle(Navit.get_text("toggle POI"));
    menu.findItem(R.id.overflow_announcer_on).setTitle(Navit.get_text("Announcer On"));
    menu.findItem(R.id.overflow_announcer_off).setTitle(Navit.get_text("Announcer Off"));
    menu.findItem(R.id.overflow_download_maps).setTitle(Navit.get_text("download maps"));
    menu.findItem(R.id.overflow_delete_maps).setTitle(Navit.get_text("delete maps"));
    menu.findItem(R.id.overflow_maps_age).setTitle(Navit.get_text("show Maps age"));
    menu.findItem(R.id.overflow_coord_dialog).setTitle(Navit.get_text("Coord Dialog"));
    menu.findItem(R.id.overflow_add_traffic_block).setTitle(Navit.get_text("add Traffic block"));
    menu.findItem(R.id.overflow_clear_traffic_block).setTitle(Navit.get_text("clear Traffic blocks"));
    menu.findItem(R.id.overflow_convert_gpx_file).setTitle(Navit.get_text("convert GPX file"));
    menu.findItem(R.id.overflow_replay_gps_file).setTitle(Navit.get_text("replay a ZANavi gps file"));
    menu.findItem(R.id.overflow_yaml_tests).setTitle(Navit.get_text("run YAML tests"));
    menu.findItem(R.id.overflow_clear_gpx_map).setTitle(Navit.get_text("clear GPX map"));
    // menu.findItem(R.id.overflow_dummy2)
    menu.findItem(R.id.overflow_demo_v_normal).setTitle(get_text("Demo Vehicle") + " [normal]");
    menu.findItem(R.id.overflow_demo_v_fast).setTitle(get_text("Demo Vehicle") + " [fast]");
    menu.findItem(R.id.overflow_speech_texts).setTitle(Navit.get_text("Speech Texts"));
    menu.findItem(R.id.overflow_nav_commands).setTitle(Navit.get_text("Nav. Commands"));
    menu.findItem(R.id.overflow_toggle_route_graph).setTitle(Navit.get_text("toggle Routegraph"));
    //menu.findItem(R.id.overflow_dummy1)
    menu.findItem(R.id.overflow_export_map_points_to_sdcard).setTitle(Navit.get_text("export Destinations"));
    menu.findItem(R.id.overflow_import_map_points_from_sdcard).setTitle(Navit.get_text("import Destinations"));
    menu.findItem(R.id.overflow_send_feedback).setTitle(Navit.get_text("send feedback"));
    menu.findItem(R.id.overflow_online_help).setTitle(Navit.get_text("online Help"));
    menu.findItem(R.id.overflow_about).setTitle(Navit.get_text("About"));
    //. TRANSLATORS: it means: "show current target in google maps"
    //. TRANSLATORS: please keep this text short, to fit in the android menu!
    menu.findItem(R.id.overflow_target_in_gmaps).setTitle(Navit.get_text("Target in gmaps"));
    //
    //
    menu.findItem(R.id.item_share_menu_button).setTitle(get_text("Share"));

    Display display_ = getWindowManager().getDefaultDisplay();
    Log.e("Navit", "Navit width in DP -> " + display_.getWidth() / Navit.metrics.density);
    Log.e("Navit", "Navit width in DP -> density=" + Navit.metrics.density);

    try {
        View v4 = findViewById(R.id.item_settings_menu_button);
        // Log.e("Navit", "Navit width in DP -> v4=" + v4);
        if ((v4 != null) && (v4.getWidth() > 0)) {
            Log.e("Navit", "Navit width in DP -> v4.w=" + v4.getWidth());
            MenuItem menuItem = menu.findItem(R.id.item_settings_menu_button);
            // Log.e("Navit", "Navit width in DP -> mi=" + menuItem);
            // Log.e("Navit", "Navit width in DP -> i=" + menuItem.getIcon());
            Log.e("Navit", "Navit width in DP -> i.w=" + menuItem.getIcon().getIntrinsicWidth());
            actionbar_item_width = (int) ((v4.getWidth() + (menuItem.getIcon().getIntrinsicWidth() * 1.5f))
                    / 2);
        } else {
            MenuItem menuItem = menu.findItem(R.id.item_settings_menu_button);
            // Log.e("Navit", "Navit width in DP -> mi=" + menuItem);
            // Log.e("Navit", "Navit width in DP -> i=" + menuItem.getIcon());
            Log.e("Navit", "Navit width in DP -> i.w=" + menuItem.getIcon().getIntrinsicWidth());
            actionbar_item_width = (int) ((menuItem.getIcon().getIntrinsicWidth()) * 1.7f);
        }

        actionbar_items_will_fit = display_.getWidth() / actionbar_item_width;
        Log.e("Navit", "Navit width in DP -> number of items that will fit=" + actionbar_items_will_fit);
        if (actionbar_items_will_fit > 6) // now we need to fit max. 6 items on actionbar
        {
            actionbar_all_items_will_fit = true;
        } else {
            actionbar_all_items_will_fit = false;
        }
    } catch (Exception e) {
        if ((display_.getWidth() / Navit.metrics.density) < NAVIT_MIN_HORIZONTAL_DP_FOR_ACTIONBAR) {
            actionbar_all_items_will_fit = false;
        } else {
            actionbar_all_items_will_fit = true;
        }
    }

    if (actionbar_all_items_will_fit == false) {
        menu.findItem(R.id.item_share_menu_button).setVisible(false);
        menu.findItem(R.id.overflow_share_location).setVisible(true);
        if (NavitGraphics.CallbackDestinationValid2() == 0) {
            menu.findItem(R.id.overflow_share_destination).setVisible(false);
        } else {
            menu.findItem(R.id.overflow_share_destination).setVisible(true);
        }

        if (actionbar_items_will_fit < 6) {
            // also push the settings icons to overflow menu
            menu.findItem(R.id.item_settings_menu_button).setVisible(false);
            menu.findItem(R.id.overflow_settings).setVisible(true);
        } else {
            menu.findItem(R.id.item_settings_menu_button).setVisible(true);
            menu.findItem(R.id.overflow_settings).setVisible(false);
        }
    } else {
        menu.findItem(R.id.item_settings_menu_button).setVisible(true);
        menu.findItem(R.id.overflow_settings).setVisible(false);
        menu.findItem(R.id.overflow_share_location).setVisible(false);
        menu.findItem(R.id.overflow_share_destination).setVisible(false);
        menu.findItem(R.id.item_share_menu_button).setVisible(true);
    }

    cur_menu = menu;

    System.out.println("down_icon:000");

    try {
        MenuItem downloadViewMenuItem = menu.findItem(R.id.item_download_menu_button);
        System.out.println("down_icon:001");
        downloadViewMenuItem.setVisible(true);
        System.out.println("down_icon:002");
        System.out.println("down_icon:003");
        android.widget.ImageView v = (android.widget.ImageView) MenuItemCompat
                .getActionView(menu.findItem(R.id.item_download_menu_button));
        System.out.println("down_icon:004");
        v.setVisibility(View.VISIBLE);
        if (v != null) {
            System.out.println("down_icon:005");
            v.setImageBitmap(null);
            System.out.println("down_icon:006");

            v.setBackgroundResource(R.drawable.anim_download_icon_2);
            final AnimationDrawable anim = (AnimationDrawable) v.getBackground();

            // ----------------------------------
            // thanks to: http://stackoverflow.com/questions/14686802/animationdrawable-is-not-working-on-2-3-6-android-version
            // ----------------------------------
            v.post(new Runnable() {
                public void run() {
                    try {
                        anim.start();
                        System.out.println("down_icon:006a");
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            });

            System.out.println("down_icon:007");

            v.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Intent mapdownload_cancel_activity = new Intent(Navit.this,
                            ZANaviDownloadMapCancelActivity.class);
                    mapdownload_cancel_activity
                            .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
                    startActivity(mapdownload_cancel_activity);
                }
            });
        }
    } catch (Exception e) {
        e.printStackTrace();
        System.out.println("down_icon:099:EE");
    }

    if (actionabar_download_icon_visible) {
        menu.findItem(R.id.item_download_menu_button).setVisible(true);
    } else {
        menu.findItem(R.id.item_download_menu_button).setVisible(false);
    }

    if (NavitGraphics.CallbackDestinationValid2() > 0) {
        menu.findItem(R.id.item_endnavigation_menu_button).setVisible(true);
        menu.findItem(R.id.item_endnavigation_menu_button).setTitle(get_text("Stop Navigation"));
        menu.findItem(R.id.overflow_zoom_to_route).setVisible(true);
        menu.findItem(R.id.overflow_target_in_gmaps).setVisible(true);
        menu.findItem(R.id.share_menu_destination).setVisible(true);
    } else {
        menu.findItem(R.id.item_endnavigation_menu_button).setVisible(false);
        menu.findItem(R.id.overflow_zoom_to_route).setVisible(false);
        menu.findItem(R.id.overflow_target_in_gmaps).setVisible(false);
        menu.findItem(R.id.share_menu_destination).setVisible(false);
    }

    if (Navit_Announcer == true) {
        menu.findItem(R.id.overflow_announcer_off).setVisible(true);
        menu.findItem(R.id.overflow_announcer_on).setVisible(false);
    } else {
        menu.findItem(R.id.overflow_announcer_off).setVisible(false);
        menu.findItem(R.id.overflow_announcer_on).setVisible(true);
    }

    if (p.PREF_enable_debug_functions) {
        menu.findItem(R.id.overflow_dummy2).setVisible(true);
        menu.findItem(R.id.overflow_demo_v_normal).setVisible(true);
        menu.findItem(R.id.overflow_demo_v_fast).setVisible(true);
        menu.findItem(R.id.overflow_speech_texts).setVisible(true);
        menu.findItem(R.id.overflow_nav_commands).setVisible(true);
        menu.findItem(R.id.overflow_toggle_route_graph).setVisible(true);
        menu.findItem(R.id.overflow_replay_gps_file).setVisible(true);
        menu.findItem(R.id.overflow_yaml_tests).setVisible(true);
    } else {
        menu.findItem(R.id.overflow_dummy2).setVisible(false);
        menu.findItem(R.id.overflow_demo_v_normal).setVisible(false);
        menu.findItem(R.id.overflow_demo_v_fast).setVisible(false);
        menu.findItem(R.id.overflow_speech_texts).setVisible(false);
        menu.findItem(R.id.overflow_nav_commands).setVisible(false);
        menu.findItem(R.id.overflow_toggle_route_graph).setVisible(false);
        menu.findItem(R.id.overflow_replay_gps_file).setVisible(false);
        menu.findItem(R.id.overflow_yaml_tests).setVisible(false);
    }

    return true;
}