Android Open Source - Munin-for-Android Adapter_ Graph View






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.adptr;
/* w  ww.j av a  2 s  .  co  m*/
import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.chteuchteu.munin.MuninFoo;
import com.chteuchteu.munin.R;
import com.chteuchteu.munin.hlpr.Util;
import com.chteuchteu.munin.obj.HTTPResponse_Bitmap;
import com.chteuchteu.munin.obj.MuninMaster;
import com.chteuchteu.munin.obj.MuninMaster.DynazoomAvailability;
import com.chteuchteu.munin.obj.MuninPlugin;
import com.chteuchteu.munin.obj.MuninServer;
import com.chteuchteu.munin.ui.Activity_GraphView;

import org.taptwo.android.widget.TitleProvider;

import uk.co.senab.photoview.PhotoViewAttacher;

public class Adapter_GraphView extends BaseAdapter implements TitleProvider {
  private static final int[] AVERAGE_GRAPH_DIMENSIONS = {455, 350};
  private MuninFoo muninFoo;
  private Activity_GraphView activity;
  private Context context;
  private LayoutInflater mInflater;
  private int count;

  public Adapter_GraphView(Activity_GraphView activity, MuninFoo muninFoo, Context context, int count) {
    this.activity = activity;
    this.muninFoo = muninFoo;
    this.count = count;
    this.context = context;
  }
  
  @Override
  public int getCount() {
    return count;
  }
  
  @Override
  public Object getItem(int position) {
    return position;
  }
  
  @Override
  public long getItemId(int position) {
    return position;
  }

  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    activity.updateAdapterPosition(position);

    if (convertView == null) {
      if (mInflater == null)
        mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      convertView = mInflater.inflate(R.layout.fragment_graphview, parent, false);
    }

    convertView.findViewById(R.id.error).setVisibility(View.GONE);
    
    if (activity.loadGraphs) {
      ImageView imageView = (ImageView) convertView.findViewById(R.id.tiv);
      ProgressBar progressBar = (ProgressBar) convertView.findViewById(R.id.progressbar);
      
      if (activity.isBitmapNull(position)) {
        //                                                                         Avoid serial execution
        new BitmapFetcher(imageView, progressBar, convertView, position, context).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
      }
      else {
        imageView.setImageBitmap(activity.getBitmap(position));
        progressBar.setVisibility(View.GONE);
      }
    }
    
    return convertView;
  }
  
  private class BitmapFetcher extends AsyncTask<Void, Integer, Void> {
    private ImageView imageView;
    private int position;
    private Context context;
    private ProgressBar progressBar;
    private View view;

    private MuninPlugin plugin;
    private MuninServer server;

    private HTTPResponse_Bitmap response;
    
    private BitmapFetcher (ImageView iv, ProgressBar progressBar, View view, int position, Context context) {
      super();
      this.imageView = iv;
      this.position = position;
      this.context = context;
      this.progressBar = progressBar;
      this.view = view;

            // ViewFlowMode : graphs / labels
      if (activity.viewFlowMode == Activity_GraphView.VIEWFLOWMODE_GRAPHS) {
        this.plugin = muninFoo.getCurrentServer().getPlugin(position);
        this.server = muninFoo.getCurrentServer();
      } else { // VIEWFLOWMODE_LABELS
        this.plugin = activity.label.getPlugins().get(position);
        this.server = this.plugin.getInstalledOn();
      }
    }
    
    @Override
    protected void onPreExecute() {
      super.onPreExecute();
      imageView.setImageBitmap(null);
      progressBar.setVisibility(View.VISIBLE);
      view.findViewById(R.id.error).setVisibility(View.GONE);
    }
    
    @Override
    protected Void doInBackground(Void... arg0) {
      if (activity.isBitmapNull(position)) {
        String imgUrl;
        if (server.getParent().isDynazoomAvailable() == DynazoomAvailability.TRUE
            && !Util.getPref(context, Util.PrefKeys.HDGraphs).equals("false")) {
          // Check if HD graph is really needed : if the standard-res bitmap isn't upscaled, it's OK
          float xScale = ((float) imageView.getWidth()) / AVERAGE_GRAPH_DIMENSIONS[0];
          float yScale = ((float) imageView.getHeight()) / AVERAGE_GRAPH_DIMENSIONS[1];
          float scale = (xScale <= yScale) ? xScale : yScale;

          // Acceptable upscaling factor
          MuninFoo.log("Upscaling factor = " + scale);
          if (scale > 2.5) {
            int[] graphsDimensions = Util.HDGraphs.getBestImageDimensions(imageView, context);
            imgUrl = plugin.getHDImgUrl(activity.load_period, true, graphsDimensions[0], graphsDimensions[1]);
          }
          else
            imgUrl = plugin.getImgUrl(activity.load_period);
        } else
          imgUrl = plugin.getImgUrl(activity.load_period);

        this.response = server.getParent().grabBitmap(imgUrl, muninFoo.getUserAgent());

        if (response.hasSucceeded())
          activity.addBitmap(Util.removeBitmapBorder(response.getBitmap()), position);
      }
      
      return null;
    }
    
    @Override
    protected void onPostExecute(Void result) {
      progressBar.setVisibility(View.GONE);

      if (!activity.isBitmapNull(position)) {
        imageView.setImageBitmap(activity.getBitmap(position));
        // PhotoViewAttacher
        if (Util.getPref(context, Util.PrefKeys.GraphsZoom).equals("true")) {
          if (!activity.photoViewAttached[position]) {
            activity.photoViewAttached[position] = true;
            PhotoViewAttacher mAttacher = new PhotoViewAttacher(imageView);
            if (mAttacher.getMidScale() < 2f)
              mAttacher.setMaxScale(2f);
          }
        }

        // If documentation shown && image just loaded: display it
        if (activity.iv_documentation != null) {
          Object tag = activity.iv_documentation.getTag();
          if (tag != null && tag.equals(plugin.getName()))
            activity.iv_documentation.setImageBitmap(activity.getBitmap(position));
        }
      } else {
        // Display error
        view.findViewById(R.id.error).setVisibility(View.VISIBLE);
        TextView errorText = (TextView) view.findViewById(R.id.error_text);
        Util.Fonts.setFont(context, errorText, Util.Fonts.CustomFont.Roboto_Regular);

        Util.Fonts.setFont(context, ((TextView) view.findViewById(R.id.error_title)), Util.Fonts.CustomFont.Roboto_Regular);

        if (response.getResponseCode() < 0) { // Not HTTP error
          if (response.getResponseCode() == HTTPResponse_Bitmap.UnknownHostExceptionError
              && !Util.isOnline(context))
            errorText.setText(context.getString(R.string.text30) + "\n" + response.getResponsePhrase());
          else
            errorText.setText(response.getResponsePhrase());
        }
        else
          errorText.setText(response.getResponseCode() + " - " + response.getResponsePhrase());

        // Allow user to disable HD Graphs / rescan HD Graphs URL
        if (!Util.getPref(context, Util.PrefKeys.HDGraphs).equals("false")
            && this.server.getParent().isDynazoomAvailable() == DynazoomAvailability.TRUE
            && Util.isOnline(context)) {
          Button rescanHdGraphsUrl = (Button) view.findViewById(R.id.error_rescanHdGraphsUrl);
          Button disableHdGraphs = (Button) view.findViewById(R.id.error_disableHdGraphs);
          rescanHdGraphsUrl.setVisibility(View.VISIBLE);
          disableHdGraphs.setVisibility(View.VISIBLE);

          Util.Fonts.setFont(context, rescanHdGraphsUrl, Util.Fonts.CustomFont.Roboto_Regular);
          Util.Fonts.setFont(context, disableHdGraphs, Util.Fonts.CustomFont.Roboto_Regular);

          disableHdGraphs.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
              server.getParent().setDynazoomAvailable(DynazoomAvailability.FALSE);
              MuninFoo.getInstance(context).sqlite.dbHlpr.updateMuninMaster(server.getParent());
              activity.fab.hide(true);
              activity.isFabShown = false;
              activity.actionRefresh();
            }
          });

          rescanHdGraphsUrl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
              new DynazoomUrlScanner(server.getParent(), context).execute();
            }
          });
        } else {
          view.findViewById(R.id.error_rescanHdGraphsUrl).setVisibility(View.GONE);
          view.findViewById(R.id.error_disableHdGraphs).setVisibility(View.GONE);
        }
      }

      // Connection type
      activity.updateConnectionType(response.getConnectionType());
    }
  }

  private class DynazoomUrlScanner extends AsyncTask<Void, Integer, Void> {
    private ProgressDialog dialog;
    private Context context;
    private MuninMaster master;

    private DynazoomUrlScanner(MuninMaster master, Context context) {
      this.master = master;
      this.context = context;
    }

    @Override
    protected void onPreExecute() {
      super.onPreExecute();
      dialog = ProgressDialog.show(context, "", context.getString(R.string.loading), true);
    }

    @Override
    protected Void doInBackground(Void... arg0) {
      master.rescan(context, muninFoo);

      return null;
    }

    @Override
    protected void onPostExecute(Void result) {
      if (dialog != null && dialog.isShowing()) {
        try {
          dialog.dismiss();
        } catch (Exception ex) { ex.printStackTrace(); }
      }

      if (master.isDynazoomAvailable() == DynazoomAvailability.FALSE) {
        activity.fab.hide(true);
        activity.isFabShown = false;
      }

      activity.actionRefresh();
    }
  }
  
  @Override
  public String getTitle(int position) {
    if (position < 0)
      return "";

    if (activity.viewFlowMode == Activity_GraphView.VIEWFLOWMODE_GRAPHS) {
      if (position > muninFoo.getCurrentServer().getPlugins().size())
        return "";

      return muninFoo.getCurrentServer().getPlugin(position).getFancyName();
    } else {
      if (position > activity.label.getPlugins().size())
        return "";

      return activity.label.getPlugins().get(position).getFancyName();
    }
  }
}




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