Android Open Source - Munin-for-Android Activity_ Grids






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  va  2 s . com*/
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;

import com.chteuchteu.munin.MuninFoo;
import com.chteuchteu.munin.R;
import com.chteuchteu.munin.hlpr.DrawerHelper;
import com.chteuchteu.munin.hlpr.Util;
import com.chteuchteu.munin.hlpr.Util.TransitionStyle;
import com.chteuchteu.munin.obj.Grid;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;


public class Activity_Grids extends MuninActivity {
  private ArrayList<HashMap<String, String>> list;
  private ListView listview;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

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

    actionBar.setTitle(getString(R.string.button_grid));

    listview = (ListView) findViewById(R.id.listview);
    list = new ArrayList<>();

    updateList();
  }
  
  private void updateList() {
    list.clear();
    listview.setAdapter(null);
    
    List<Grid> gridsList = muninFoo.sqlite.dbHlpr.getGrids(this, muninFoo);
    
    if (gridsList.size() == 0)
      findViewById(R.id.grids_nogrid).setVisibility(View.VISIBLE);
    else {
      for (Grid g : gridsList) {
                HashMap<String,String> item = new HashMap<>();
        item.put("line1", g.name);
        item.put("line2", g.getFullWidth() + " x " + g.getFullHeight());
        list.add(item);
      }
      SimpleAdapter sa = new SimpleAdapter(this, list, R.layout.gridselection_list, new String[] { "line1","line2" }, new int[] {R.id.line_a, R.id.line_b});
      listview.setAdapter(sa);
      
      listview.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> adapter, View view, int position, long arg) {
          TextView gridName = (TextView) view.findViewById(R.id.line_a);
          Intent intent = new Intent(Activity_Grids.this, Activity_Grid.class);
          intent.putExtra("gridName", gridName.getText().toString());
          startActivity(intent);
          Util.setTransition(context, TransitionStyle.DEEPER);
        }
      });
      
      listview.setOnItemLongClickListener(new OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> adapter, final View view, int position, long arg) {
          // Display actions list
          AlertDialog.Builder builderSingle = new AlertDialog.Builder(context);
          final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(
              context, android.R.layout.simple_list_item_1);
          arrayAdapter.add(context.getString(R.string.rename_grid));
          arrayAdapter.add(context.getString(R.string.text73)); // Delete grid

          builderSingle.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
              final TextView gridNameTextView = (TextView) view.findViewById(R.id.line_a);
              final String gridName = gridNameTextView.getText().toString();

              switch (which) {
                case 0: // Rename grid
                  final EditText input = new EditText(context);
                  input.setText(gridName);

                  new AlertDialog.Builder(context)
                      .setTitle(R.string.rename_grid)
                      .setView(input)
                      .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {
                          String value = input.getText().toString();
                          if (!value.equals(gridName)) {
                            // Check if there's a grid with this name
                            boolean alreadyExists = muninFoo.sqlite.dbHlpr.gridExists(value);
                            if (!alreadyExists) {
                              MuninFoo.getInstance(context).sqlite.dbHlpr.updateGridName(gridName, value);
                              gridNameTextView.setText(value);
                            } else
                              Toast.makeText(context, R.string.text09, Toast.LENGTH_SHORT).show();
                          }
                          dialog.dismiss();
                        }
                      }).setNegativeButton(R.string.text64, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                    }
                  }).show();
                  break;
                case 1: // Delete grid
                  new AlertDialog.Builder(context)
                      .setTitle(R.string.delete)
                      .setMessage(R.string.text80)
                      .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                          Grid grid = muninFoo.sqlite.dbHlpr.getGrid(context, muninFoo, gridName);
                          muninFoo.sqlite.dbHlpr.deleteGrid(grid);
                          updateList();
                        }
                      })
                      .setNegativeButton(R.string.no, null)
                      .show();

                  break;
              }
            }
          });
          builderSingle.show();

          return true;
        }
      });
    }
  }
  
  private void add() {
    final LinearLayout ll = new LinearLayout(this);
    ll.setOrientation(LinearLayout.VERTICAL);
    ll.setPadding(10, 30, 10, 10);
    final EditText input = new EditText(this);
    ll.addView(input);
    
    AlertDialog.Builder b = new AlertDialog.Builder(Activity_Grids.this)
    .setTitle(getText(R.string.text69))
    .setView(ll)
    .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
      public void onClick(DialogInterface dialog, int whichButton) {
        // Overrided by the CustomListener class
      }
    })
    .setNegativeButton(getText(R.string.text64), new DialogInterface.OnClickListener() {
      public void onClick(DialogInterface dialog, int whichButton) { }
    });
    AlertDialog d = b.create();
    d.show();
    Button okButton = d.getButton(DialogInterface.BUTTON_POSITIVE);
    okButton.setOnClickListener(new CustomListener(input, d));
  }


  @Override
  public DrawerHelper.DrawerMenuItem getDrawerMenuItem() { return DrawerHelper.DrawerMenuItem.Grid; }

  protected void createOptionsMenu() {
    super.createOptionsMenu();
    
    getMenuInflater().inflate(R.menu.grids, menu);
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    super.onOptionsItemSelected(item);

    switch (item.getItemId()) {
      case R.id.menu_add:
        add();
        return true;
    }

    return true;
  }
  
  @Override
  public void onBackPressed() {
    Intent intent = new Intent(this, Activity_Main.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivity(intent);
    Util.setTransition(context, TransitionStyle.SHALLOWER);
  }
  
  private class CustomListener implements View.OnClickListener {
    private final Dialog dialog;
    private final EditText input;
    private CustomListener(EditText input, Dialog dialog) {
      this.dialog = dialog;
      this.input = input;
    }
    
    @Override
    public void onClick(View v) {
      String value = input.getText().toString();
      if (!value.equals("")) {
        List<String> existingNames = muninFoo.sqlite.dbHlpr.getGridsNames();
        boolean available = true;
        for (String s : existingNames) {
          if (s.equals(value))
            available = false;
        }
        if (available) {
          muninFoo.sqlite.dbHlpr.insertGrid(new Grid(value, muninFoo));
          dialog.dismiss();
          Intent i = new Intent(Activity_Grids.this, Activity_Grid.class);
          i.putExtra("gridName", value);
          startActivity(i);
          Util.setTransition(context, TransitionStyle.DEEPER);
        }
        else
          Toast.makeText(context, getString(R.string.text74), Toast.LENGTH_LONG).show();
      }
    }
  }
}




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