Android Open Source - Munin-for-Android Activity_ Grid






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.ui;
/*w ww.j a  v a2s .co m*/
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.ActionBar;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.SpinnerAdapter;
import android.widget.TextView;
import android.widget.Toast;

import com.chteuchteu.munin.R;
import com.chteuchteu.munin.hlpr.DrawerHelper;
import com.chteuchteu.munin.hlpr.GridDownloadHelper;
import com.chteuchteu.munin.hlpr.Util;
import com.chteuchteu.munin.hlpr.Util.Fonts;
import com.chteuchteu.munin.hlpr.Util.Fonts.CustomFont;
import com.chteuchteu.munin.hlpr.Util.TransitionStyle;
import com.chteuchteu.munin.obj.Grid;
import com.chteuchteu.munin.obj.GridItem;
import com.chteuchteu.munin.obj.MuninPlugin.Period;

import java.util.List;

public class Activity_Grid extends MuninActivity {
  public static boolean  editing;
  private Grid      grid;
  private LinearLayout  container;
  private ImageView    fs_iv;
  
  public static MenuItem menu_refresh;
  public static MenuItem menu_edit;
  public static MenuItem menu_period;
  public static MenuItem menu_open;
  
  private Period currentPeriod;
  
  public static boolean  updating;
  private Handler    mHandler;
  private Runnable    mHandlerTask;
  
  @SuppressWarnings("deprecation")
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_grid);
    super.onContentViewSet();
    dh.setDrawerActivity(this);

    editing = false;
    updating = false;
    
    if (Util.getPref(this, Util.PrefKeys.ScreenAlwaysOn).equals("true"))
      getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    
    fs_iv = (ImageView) findViewById(R.id.fullscreen_iv);
    
    container = (LinearLayout) findViewById(R.id.grid_root_container);
    currentPeriod = Util.getDefaultPeriod(this);
    if (menu_period != null)
      menu_period.setTitle(currentPeriod.getLabel(this));
    
    setupGrid();
    
    
    // ActionBar spinner if needed
    final List<String> gridsNames = muninFoo.sqlite.dbHlpr.getGridsNames();
    if (gridsNames.size() > 1) {
      actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
      actionBar.setDisplayShowTitleEnabled(false);
      
      // Get current index
      int index = -1;
      int i=0;
      for (String gridName : gridsNames) {
        if (gridName.equals(grid.name))
          index = i;
        i++;
      }
      final int currentSelectedIndex = index;
      
      SpinnerAdapter spinnerAdapter = new ArrayAdapter<>(getApplicationContext(),
          android.R.layout.simple_spinner_dropdown_item, gridsNames);
      
      ActionBar.OnNavigationListener navigationListener = new ActionBar.OnNavigationListener() {
        @Override
        public boolean onNavigationItemSelected(int itemPosition, long itemId) {
          if (itemPosition != currentSelectedIndex) {
            Intent intent = new Intent(Activity_Grid.this, Activity_Grid.class);
            intent.putExtra("gridName", gridsNames.get(itemPosition));
            startActivity(intent);
            // Animation : RTL / LTR
            if (itemPosition > currentSelectedIndex)
              Util.setTransition(context, TransitionStyle.DEEPER);
            else
              Util.setTransition(context, TransitionStyle.SHALLOWER);
          }
          return false;
        }
      };
      actionBar.setListNavigationCallbacks(spinnerAdapter, navigationListener);
      if (currentSelectedIndex != -1)
        actionBar.setSelectedNavigationItem(currentSelectedIndex);
    }
    
    // On rotate : onRetainNonConfigurationInstance has been called.
    // Let's get back some values (grid period for example)
    Activity_Grid beforeOnRotate = (Activity_Grid) getLastNonConfigurationInstance();
    if (beforeOnRotate != null)
      this.currentPeriod = beforeOnRotate.currentPeriod;
    
    
    grid.dHelper = new GridDownloadHelper(grid);
    grid.dHelper.init(3, currentPeriod);
    grid.dHelper.start(false);
    
    
    findViewById(R.id.add_line_bottom).setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View v) {
        grid.addLine(context, true);
      }
    });
    findViewById(R.id.add_column_right).setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View v) {
        grid.addColumn(context, true);
      }
    });
    findViewById(R.id.fullscreen).setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View v) {
        hidePreview();
      }
    });
    
    Fonts.setFont(this, (TextView) findViewById(R.id.fullscreen_tv), CustomFont.Roboto_Regular);
    
    if (grid.items.size() == 0)
      edit();
    
    // Launch periodical check
    if (Util.getPref(this, Util.PrefKeys.AutoRefresh).equals("true")) {
      mHandler = new Handler();
      final int INTERVAL = 1000 * 60 * 5;
      mHandlerTask = new Runnable() {
        @Override 
        public void run() {
          if (!updating)
            autoRefresh();
          mHandler.postDelayed(mHandlerTask, INTERVAL);
        }
      };
      mHandlerTask.run();
    }
  }
  
  /*/**
   * Retain period on rotate
   * @return
   *//*
  public  Object onRetainNonConfigurationInstance() {
    return this;
  }*/
  
  private void hidePreview() {
    grid.currentlyOpenedPlugin = null;
    if (menu_refresh != null)  menu_refresh.setVisible(true);
    if (menu_edit != null)    menu_edit.setVisible(true);
    if (menu_period != null)  menu_period.setVisible(true);
    if (menu_open != null)    menu_open.setVisible(false);

    Util.Animations.animate(findViewById(R.id.fullscreen), Util.Animations.CustomAnimation.FADE_OUT,
        Util.Animations.AnimationSpeed.MEDIUM, new Runnable() {
          @Override
          public void run() {
            findViewById(R.id.fullscreen).setVisibility(View.GONE);
            fs_iv.setImageBitmap(null);
            ((TextView) ((Activity) context).findViewById(R.id.fullscreen_tv)).setText("");
          }
        });
  }
  
  private void setupGrid() {
    if (!Util.isOnline(this))
      Toast.makeText(this, getString(R.string.text30), Toast.LENGTH_LONG).show();
    
    container.removeAllViews();
    grid = null;
    
    Intent thisIntent = getIntent();
    if (thisIntent != null && thisIntent.getExtras() != null && thisIntent.getExtras().containsKey("gridName")) {
      String gridName = thisIntent.getExtras().getString("gridName");
      grid = muninFoo.sqlite.dbHlpr.getGrid(this, muninFoo, gridName);
    }
    
    if (grid == null)
      startActivity(new Intent(this, Activity_Grids.class));
    
    actionBar.setTitle(getText(R.string.text75) + " " + grid.name);
    
    grid.setupLayout();
    container.addView(grid.buildLayout(this));
    grid.updateLayoutSizes(this);
  }
  
  protected void createOptionsMenu() {
    super.createOptionsMenu();

    getMenuInflater().inflate(R.menu.grid, menu);
    menu_refresh = menu.findItem(R.id.menu_refresh);
    menu_edit = menu.findItem(R.id.menu_edit);
    menu_period = menu.findItem(R.id.menu_period);
    menu_open = menu.findItem(R.id.menu_open);
    menu_refresh.setVisible(!editing);
    if (editing)  menu_edit.setIcon(R.drawable.ic_action_navigation_check);
    else       menu_edit.setIcon(R.drawable.ic_action_image_edit);
    menu_period.setTitle(currentPeriod.getLabel(this));
  }
  
  private void edit() {
    if (menu_refresh != null)  menu_refresh.setVisible(editing);
    if (menu_period != null)  menu_period.setVisible(editing);
    
    if (editing) { // Cancel edit
      grid.cancelEdit(this);
      if (menu_edit != null) menu_edit.setIcon(R.drawable.ic_action_image_edit);
      grid.toggleFootersVisibility(true);
      muninFoo.sqlite.dbHlpr.saveGridItemsRelations(grid);
    } else { // Edit
      grid.edit(this);
      if (menu_edit != null) menu_edit.setIcon(R.drawable.ic_action_navigation_check);
      grid.toggleFootersVisibility(false);
    }
    
    editing = !editing;
  }
  
  private void refresh() {
    // Update each GridItem with the currentPeriod
    for (GridItem item : grid.items)
      item.setPeriod(this.currentPeriod);
    
    if (!Util.isOnline(this))
      Toast.makeText(this, getString(R.string.text30), Toast.LENGTH_LONG).show();
    grid.dHelper.period = this.currentPeriod;
    grid.dHelper.start(true);
  }
  
  private void autoRefresh() {
    grid.dHelper.period = this.currentPeriod;
    grid.dHelper.start(true);
  }
  
  private void openGraph() {
    if (grid.currentlyOpenedPlugin == null)
      return;
    grid.f.setCurrentServer(grid.currentlyOpenedPlugin.getInstalledOn());
    Intent i = new Intent(context, Activity_GraphView.class);
    i.putExtra("plugin", grid.currentlyOpenedPlugin.getName());
    i.putExtra("from", "grid");
    Intent gridIntent = ((Activity) context).getIntent();
    if (gridIntent != null && gridIntent.getExtras() != null && gridIntent.getExtras().containsKey("gridName"))
      i.putExtra("fromGrid", gridIntent.getExtras().getString("gridName"));
    context.startActivity(i);
    Util.setTransition(context, TransitionStyle.DEEPER);
  }

  @Override
  public DrawerHelper.DrawerMenuItem getDrawerMenuItem() { return DrawerHelper.DrawerMenuItem.Grid; }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    super.onOptionsItemSelected(item);

    switch (item.getItemId()) {
      case R.id.menu_refresh: refresh(); return true;
      case R.id.menu_edit: edit(); return true;
      case R.id.period_day:
        this.currentPeriod = Period.DAY;
        menu_period.setTitle(currentPeriod.getLabel(context));
        refresh();
        return true;
      case R.id.period_week:
        this.currentPeriod = Period.WEEK;
        menu_period.setTitle(currentPeriod.getLabel(context));
        refresh();
        return true;
      case R.id.period_month:
        this.currentPeriod = Period.MONTH;
        menu_period.setTitle(currentPeriod.getLabel(context));
        refresh();
        return true;
      case R.id.period_year:
        this.currentPeriod = Period.YEAR;
        menu_period.setTitle(currentPeriod.getLabel(context));
        refresh();
        return true;
      case R.id.menu_open: openGraph(); return true;
    }

    return true;
  }
  
  @Override
  public void onBackPressed() {
    if (findViewById(R.id.fullscreen).getVisibility() == View.VISIBLE)
      hidePreview();
    else {
      if (editing)
        edit(); // quit edit mode
      else {
        Intent intent = new Intent(this, Activity_Grids.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intent);
        Util.setTransition(context, TransitionStyle.SHALLOWER);
      }
    }
  }
  
  @Override
  public void onStop() {
    super.onStop();
    
    if (Util.getPref(this, Util.PrefKeys.ScreenAlwaysOn).equals("true"))
      getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
  }
}




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