Android Open Source - Munin-for-Android Dynazoom Helper






From Project

Back to project page Munin-for-Android.

License

The source code is released under:

GNU General Public License

If you think the Android project Munin-for-Android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.chteuchteu.munin.hlpr;
//  ww w.ja  va2 s  . c o  m

import android.content.Context;
import android.graphics.Bitmap;
import android.os.AsyncTask;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.ProgressBar;

import com.chteuchteu.munin.R;
import com.chteuchteu.munin.obj.MuninPlugin;
import com.chteuchteu.munin.obj.MuninServer;
import com.edmodo.rangebar.RangeBar;

public final class DynazoomHelper {
  private static int GRAPH_LEFT_MARGIN = 155;
  private static int GRAPH_RIGHT_MARGIN = 50;
  // Because of the bitmap shadow
  private static int GRAPH_TOP_MARGIN = 7;
  private static int GRAPH_BOTTOM_MARGIN = 13;

  public static int RANGEBAR_TICKS_COUNT = 30;

  public static void updateHighlightedArea(View highlightArea1, View highlightArea2, RangeBar rangeBar, ImageView imageView) {
    int[] steps = { rangeBar.getLeftIndex(),  rangeBar.getRightIndex() };
    int[] highlightedAreaX1 = getHighlightedAreaFromSteps(steps, RANGEBAR_TICKS_COUNT, imageView.getWidth(), 1);
    int[] highlightedAreaX2 = getHighlightedAreaFromSteps(steps, RANGEBAR_TICKS_COUNT, imageView.getWidth(), 2);

    // If we try to get the imageView position, we'll only get top=0, height=(full screen) since
    // the imageView layout_width && layout_height == MATCH_PARENT
    int[] bitmapPosition = Util.getBitmapPositionInsideImageView(imageView);

    int left, top, width, height;

    top = bitmapPosition[1] + GRAPH_TOP_MARGIN;
    height = bitmapPosition[3] - (GRAPH_TOP_MARGIN + GRAPH_BOTTOM_MARGIN);

    // Left mask
    left = highlightedAreaX1[0];
    width = highlightedAreaX1[1] - highlightedAreaX1[0];
    setLayoutParams(highlightArea1, width, height, left, top);

    // Right mask
    left = highlightedAreaX2[0];
    width = highlightedAreaX2[1] - highlightedAreaX2[0];
    setLayoutParams(highlightArea2, width, height, left, top);
  }

  private static void setLayoutParams(View view, int width, int height, int left, int top) {
    FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) view.getLayoutParams();
    layoutParams.width = width;
    layoutParams.height = height;
    layoutParams.leftMargin = left;
    layoutParams.topMargin = top;

    view.setLayoutParams(layoutParams);
    view.invalidate();
  }

  public static int[] getHighlightedAreaFromSteps(int[] steps, int nbSteps, int imageViewWidth, int highlightedAreaIndex) {
    int[] areaXDimens = new int[2];

    int imgX1 = DynazoomHelper.GRAPH_LEFT_MARGIN;
    int imgX2 = imageViewWidth - DynazoomHelper.GRAPH_RIGHT_MARGIN;
    int imgXDiff = imgX2 - imgX1;

    int hlAreaX1 = 0, hlAreaX2 = 0;

    if (highlightedAreaIndex == 1) {
      hlAreaX1 = 3;
      hlAreaX2 = steps[0] * imgXDiff / nbSteps + imgX1;
    } else if (highlightedAreaIndex == 2) {
      hlAreaX1 = steps[1] * imgXDiff / nbSteps + imgX1;
      hlAreaX2 = imageViewWidth - 13;
    }

    areaXDimens[0] = hlAreaX1;
    areaXDimens[1] = hlAreaX2;
    return areaXDimens;
  }

  public static class DynazoomFetcher extends AsyncTask<Void, Integer, Void> {
    private MuninServer server;
    private MuninPlugin plugin;
    private long pinPoint1;
    private long pinPoint2;

    private ImageView imageView;
    private ProgressBar progressBar;

    private Context context;
    private String userAgent;

    private Bitmap bitmap;

    public DynazoomFetcher (MuninPlugin plugin, ImageView iv, ProgressBar progressBar, Context context, String userAgent,
                            long pinPoint1, long pinPoint2) {
      super();
      this.server = plugin.getInstalledOn();
      this.plugin = plugin;
      this.pinPoint1 = pinPoint1;
      this.pinPoint2 = pinPoint2;

      this.imageView = iv;
      this.progressBar = progressBar;

      this.context = context;
      this.userAgent = userAgent;

      this.bitmap = null;
    }

    @Override
    protected void onPreExecute() {
      super.onPreExecute();
      imageView.setImageBitmap(null);
      progressBar.setVisibility(View.VISIBLE);
    }

    @Override
    protected Void doInBackground(Void... arg0) {
      int[] graphsDimensions = Util.HDGraphs.getBestImageDimensions(imageView, context);

      String imgUrl = plugin.getHDImgUrl(pinPoint1, pinPoint2, true, graphsDimensions[0], graphsDimensions[1]);

      bitmap = Util.removeBitmapBorder(server.getParent().grabBitmap(imgUrl, userAgent).getBitmap());
      bitmap = Util.dropShadow(bitmap);

      return null;
    }

    @Override
    protected void onPostExecute(Void result) {
      progressBar.setVisibility(View.GONE);

      if (bitmap != null)
        imageView.setImageBitmap(bitmap);
      else {
        // It seems that can actually fire OutOfMemoryError (BitmapFactory.nativeDecodeAsset)
        try {
          imageView.setImageResource(R.drawable.download_error);
        } catch (Exception e) { e.printStackTrace(); }
      }
    }
  }
}




Java Source Code List

com.chteuchteu.munin.BootReceiver.java
com.chteuchteu.munin.CustomSSLFactory.java
com.chteuchteu.munin.MuninFoo.java
com.chteuchteu.munin.Service_Notifications.java
com.chteuchteu.munin.adptr.Adapter_ExpandableListView.java
com.chteuchteu.munin.adptr.Adapter_GraphView.java
com.chteuchteu.munin.adptr.Adapter_IconList.java
com.chteuchteu.munin.adptr.Adapter_SeparatedList.java
com.chteuchteu.munin.exc.ImportExportWebserviceException.java
com.chteuchteu.munin.exc.NullMuninFooException.java
com.chteuchteu.munin.exc.TrialExpirationDateReached.java
com.chteuchteu.munin.hlpr.BillingService.java
com.chteuchteu.munin.hlpr.DatabaseHelper.java
com.chteuchteu.munin.hlpr.DigestUtils.java
com.chteuchteu.munin.hlpr.DocumentationHelper.java
com.chteuchteu.munin.hlpr.DrawerHelper.java
com.chteuchteu.munin.hlpr.DynazoomHelper.java
com.chteuchteu.munin.hlpr.EncryptionHelper.java
com.chteuchteu.munin.hlpr.GridDownloadHelper.java
com.chteuchteu.munin.hlpr.I18nHelper.java
com.chteuchteu.munin.hlpr.ImportExportHelper.java
com.chteuchteu.munin.hlpr.JSONHelper.java
com.chteuchteu.munin.hlpr.MediaScannerUtil.java
com.chteuchteu.munin.hlpr.NetHelper.java
com.chteuchteu.munin.hlpr.SQLite.java
com.chteuchteu.munin.hlpr.Util.java
com.chteuchteu.munin.obj.AlertsWidget.java
com.chteuchteu.munin.obj.GraphWidget.java
com.chteuchteu.munin.obj.GridItem.java
com.chteuchteu.munin.obj.Grid.java
com.chteuchteu.munin.obj.HTTPResponse_Bitmap.java
com.chteuchteu.munin.obj.HTTPResponse.java
com.chteuchteu.munin.obj.Label.java
com.chteuchteu.munin.obj.MuninMaster.java
com.chteuchteu.munin.obj.MuninPlugin.java
com.chteuchteu.munin.obj.MuninServer.java
com.chteuchteu.munin.obj.SearchResult.java
com.chteuchteu.munin.ui.Activity_About.java
com.chteuchteu.munin.ui.Activity_AlertsPluginSelection.java
com.chteuchteu.munin.ui.Activity_Alerts.java
com.chteuchteu.munin.ui.Activity_GoPremium.java
com.chteuchteu.munin.ui.Activity_GraphView.java
com.chteuchteu.munin.ui.Activity_Grid.java
com.chteuchteu.munin.ui.Activity_Grids.java
com.chteuchteu.munin.ui.Activity_Label.java
com.chteuchteu.munin.ui.Activity_Labels.java
com.chteuchteu.munin.ui.Activity_Main.java
com.chteuchteu.munin.ui.Activity_Notifications.java
com.chteuchteu.munin.ui.Activity_Plugins.java
com.chteuchteu.munin.ui.Activity_Server.java
com.chteuchteu.munin.ui.Activity_ServersEdit.java
com.chteuchteu.munin.ui.Activity_Servers.java
com.chteuchteu.munin.ui.Activity_Settings.java
com.chteuchteu.munin.ui.HackyDrawerLayout.java
com.chteuchteu.munin.ui.MuninActivity.java
com.chteuchteu.munin.wdget.Widget_AlertsWidget_Configure.java
com.chteuchteu.munin.wdget.Widget_AlertsWidget_ViewsFactory.java
com.chteuchteu.munin.wdget.Widget_AlertsWidget_WidgetProvider.java
com.chteuchteu.munin.wdget.Widget_AlertsWidget_WidgetService.java
com.chteuchteu.munin.wdget.Widget_GraphWidget_Configure.java
com.chteuchteu.munin.wdget.Widget_GraphWidget_WidgetProvider.java
com.mobeta.android.dslv.DragSortController.java
com.mobeta.android.dslv.DragSortCursorAdapter.java
com.mobeta.android.dslv.DragSortItemViewCheckable.java
com.mobeta.android.dslv.DragSortItemView.java
com.mobeta.android.dslv.DragSortListView.java
com.mobeta.android.dslv.ResourceDragSortCursorAdapter.java
com.mobeta.android.dslv.SimpleDragSortCursorAdapter.java
com.mobeta.android.dslv.SimpleFloatViewManager.java
org.taptwo.android.widget.CircleFlowIndicator.java
org.taptwo.android.widget.FlowIndicator.java
org.taptwo.android.widget.TitleFlowIndicator.java
org.taptwo.android.widget.TitleProvider.java
org.taptwo.android.widget.ViewFlow.java
uk.co.senab.photoview.Compat.java
uk.co.senab.photoview.IPhotoView.java
uk.co.senab.photoview.PhotoViewAttacher.java
uk.co.senab.photoview.PhotoView.java
uk.co.senab.photoview.SDK16.java
uk.co.senab.photoview.ScrollerProxy.java
uk.co.senab.photoview.VersionedGestureDetector.java