Android Open Source - Munin-for-Android Widget_ Graph Widget_ Configure






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.wdget;
//from  w ww .j  av  a  2 s.  c o  m
import android.app.Activity;
import android.app.AlertDialog;
import android.appwidget.AppWidgetManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.CheckBox;
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.obj.GraphWidget;
import com.chteuchteu.munin.obj.MuninPlugin;
import com.chteuchteu.munin.obj.MuninServer;

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

public class Widget_GraphWidget_Configure extends Activity {
  private int mAppWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID;
  private MuninFoo muninFoo;
  private MuninServer selectedServer;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    
    muninFoo = MuninFoo.getInstance(this);
    
    // If the user closes window, don't create the widget
    setResult(RESULT_CANCELED);
    
    // Find widget id from launching intent
    Bundle extras = getIntent().getExtras();
    if (extras != null)
      mAppWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID,
          AppWidgetManager.INVALID_APPWIDGET_ID);
    
    // If they gave us an intent without the widget id, just bail.
    if (mAppWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID)
      finish();
    
    
    if (muninFoo.sqlite.dbHlpr.getGraphWidget(mAppWidgetId) == null) {
      final GraphWidget graphWidget = new GraphWidget();
      graphWidget.setWidgetId(mAppWidgetId);
      
      if (muninFoo != null) {
        LayoutInflater mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        final View dialogView = mInflater.inflate(R.layout.widget_configuration, null);

        final Context context = new ContextThemeWrapper(this, android.R.style.Theme_Holo_Light);

        final AlertDialog dialog = new AlertDialog.Builder(context)
          .setView(dialogView)
          .show();

        final ListView lv1 = (ListView) dialogView.findViewById(R.id.listview1); // servers
        final ListView lv2 = (ListView) dialogView.findViewById(R.id.listview2); // plugins
        final ListView lv3 = (ListView) dialogView.findViewById(R.id.listview3); // period
        
        if (muninFoo.getServers().size() == 0) {
          Toast.makeText(this, R.string.text37, Toast.LENGTH_SHORT).show();
          dialog.dismiss();
          finish();
        }
        if (!muninFoo.premium) {
          Toast.makeText(this, "Munin for Android features pack needed", Toast.LENGTH_SHORT).show();
          dialog.dismiss();
          finish();
        }
        
        ArrayList<HashMap<String,String>> list = new ArrayList<>();
        list.clear();
        HashMap<String,String> item;
        for(MuninServer server : muninFoo.getOrderedServers()) {
          item = new HashMap<>();
          item.put("line1", server.getName());
          item.put("line2", server.getServerUrl());
          list.add(item);
        }
        SimpleAdapter sa = new SimpleAdapter(context, list, R.layout.servers_list, new String[] { "line1","line2" }, new int[] {R.id.line_a, R.id.line_b});
        lv1.setAdapter(sa);
        lv1.setOnItemClickListener(new OnItemClickListener() {
          public void onItemClick(AdapterView<?> adapter, View view, int position, long arg) {
            String adresse = ((TextView) view.findViewById(R.id.line_b)).getText().toString();
            
            for (MuninServer s : muninFoo.getServers()) {
              if (s.getServerUrl().equals(adresse)) {
                selectedServer = s; break;
              }
            }
            
            // Populate lv2
            List<MuninPlugin> plugins = selectedServer.getPlugins();
            
            ArrayList<HashMap<String,String>> list2 = new ArrayList<>();
            list2.clear();
            HashMap<String,String> item2;
            for (MuninPlugin plugin : plugins) {
              item2 = new HashMap<>();
              item2.put("line1", plugin.getFancyName());
              item2.put("line2", plugin.getName());
              list2.add(item2);
            }
            SimpleAdapter sa2 = new SimpleAdapter(context, list2, R.layout.plugins_list,
                new String[] { "line1","line2" }, new int[] {R.id.line_a, R.id.line_b});
            lv2.setAdapter(sa2);
            
            lv2.setOnItemClickListener(new OnItemClickListener() {
              public void onItemClick(AdapterView<?> adapter, View view, int position, long arg) {
                String pluginName = ((TextView) view.findViewById(R.id.line_b)).getText().toString();

                for (MuninPlugin p : selectedServer.getPlugins()) {
                  if (p.getName().equals(pluginName))
                    graphWidget.setPlugin(p);
                }
                
                lv2.setVisibility(View.GONE);
                
                ArrayList<HashMap<String,String>> list3 = new ArrayList<>();

                String[] periods = { getString(R.string.text47_1), getString(R.string.text47_2),
                    getString(R.string.text47_3), getString(R.string.text47_4) };
                for (String str : periods) {
                  HashMap<String,String> item3 = new HashMap<>();
                  item3.put("line1", str);
                  list3.add(item3);
                }
                SimpleAdapter sa3 = new SimpleAdapter(context, list3, R.layout.widget_periodselection,
                    new String[] { "line1" }, new int[] {R.id.line_a});
                lv3.setAdapter(sa3);
                lv3.setOnItemClickListener(new OnItemClickListener() {
                  public void onItemClick(AdapterView<?> adapter, View view, int position, long arg) {
                    String[] periods = {"day", "week", "month", "year" };
                    graphWidget.setPeriod(periods[position]);
                    
                    LinearLayout ll = (LinearLayout) dialogView.findViewById(R.id.final_instructions);
                    lv3.setVisibility(View.GONE);
                    ll.setVisibility(View.VISIBLE);
                    ll.requestFocus();
                    final CheckBox cb = (CheckBox) dialogView.findViewById(R.id.checkbox_wifi);
                    final CheckBox cb2 = (CheckBox) dialogView.findViewById(R.id.checkbox_hidetitle);
                    Button btn = (Button) dialogView.findViewById(R.id.save);
                    
                    btn.setOnClickListener(new View.OnClickListener() {
                      public void onClick(View v) {
                        // Save & close
                        graphWidget.setWifiOnly(cb.isChecked());
                        graphWidget.setHideServerName(cb2.isChecked());
                        
                        muninFoo.sqlite.dbHlpr.insertGraphWidget(graphWidget);

                        configureWidget(getApplicationContext());
                        
                        // Make sure we pass back the original appWidgetId before closing the activity
                        Intent resultValue = new Intent();
                        resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId);
                        setResult(RESULT_OK, resultValue);
                        dialog.dismiss();
                        finish();
                      }
                    });
                  }
                });
                
                lv3.setVisibility(View.VISIBLE);
                lv3.requestFocus();
              }
            });
            
            lv1.setVisibility(View.GONE);
            
            lv2.setVisibility(View.VISIBLE);
            lv2.requestFocus();
          }
        });
        
        lv1.setVisibility(View.VISIBLE);
        lv1.requestFocus();
      }
    }
  }
  
  /**
   * Configures the created widget
   * @param context
   */
  private void configureWidget(Context context) {
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
    Widget_GraphWidget_WidgetProvider.updateAppWidget(context, appWidgetManager, mAppWidgetId, true);
  }
}




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