Android Open Source - HRForecast-WFM Analysis Main Activity






From Project

Back to project page HRForecast-WFM.

License

The source code is released under:

Copyright 2014 Ahmed Shafei

If you think the Android project HRForecast-WFM 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 de.hrf.workforcemanagement;
//from w  ww .  j  a  va  2s  . c om
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.Spinner;
import de.hrf.workforcemanagement.models.Chart;
import de.hrf.workforcemanagement.models.ChartType;
import de.hrf.workforcemanagement.models.Property;
import de.hrf.workforcemanagement.models.barchart.BarChart;
import de.hrf.workforcemanagement.models.bubblechart.BubbleChart;
import de.hrf.workforcemanagement.models.linechart.LineChart;
import de.hrf.workforcemanagement.models.piechart.PieChart;
import de.hrf.workforcemanagement.models.radarchart.RadarChart;
import de.hrf.workforcemanagement.models.stackedbarchart.StackedbarChart;
import de.hrf.workforcemanagement.parser.ChartParser;

public class AnalysisMainActivity extends FragmentActivity implements
    OnItemSelectedListener {

  private int chartFragmentContainerId = R.id.charts_detailContainer;
  private Fragment chartDetailFragment;

  private DrawerLayout mDrawerLayout;
  private LinearLayout mDrawerList;
  private LinearLayout rightDrawer;
  private ActionBarDrawerToggle mDrawerToggle;

  private CharSequence mDrawerTitle;
  private CharSequence mTitle;
  private String[] mPlanetTitles;
  ListView planetList;

  RowModel[] modelItems;
  ListView lv;

  Spinner spinner;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    // Remove notification bar
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
        WindowManager.LayoutParams.FLAG_FULLSCREEN);
    // set content view AFTER ABOVE sequence (to avoid crash)
    this.setContentView(R.layout.activity_main_analysis);

    mTitle = mDrawerTitle = getTitle();
    mPlanetTitles = getResources().getStringArray(R.array.planets_array);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

    mDrawerList = (LinearLayout) findViewById(R.id.left_drawer);
    rightDrawer = (LinearLayout) findViewById(R.id.right_drawer);
    // set a custom shadow that overlays the main content when the drawer
    // opens
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow,
        GravityCompat.START);

    // planetList = (ListView) findViewById(R.id.left_drawer1);
    //
    //
    // // set up the drawer's list view with items and click listener
    // planetList.setAdapter(new ArrayAdapter<String>(this,
    // R.layout.drawer_list_item, mPlanetTitles));
    // planetList.setOnItemClickListener(new DrawerItemClickListener());

    spinner = (Spinner) findViewById(R.id.category_spinner);
    // Create an ArrayAdapter using the string array and a default spinner
    // layout
    ArrayAdapter<CharSequence> adapter2 = ArrayAdapter.createFromResource(
        this, R.array.categories, android.R.layout.simple_spinner_item);
    // Specify the layout to use when the list of choices appears
    adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    // Apply the adapter to the spinner
    spinner.setAdapter(adapter2);

    spinner.setOnItemSelectedListener(this);

    lv = (ListView) findViewById(R.id.left_drawer2);

    modelItems = new RowModel[4];
    modelItems[0] = new RowModel("All", 1);
    modelItems[1] = new RowModel("Department 1", 1);
    modelItems[2] = new RowModel("Department 2", 1);
    modelItems[3] = new RowModel("Department 3", 1);

    CustomAdapter adapter = new CustomAdapter(this, modelItems);
    lv.setAdapter(adapter);

    // enable ActionBar app icon to behave as action to toggle nav drawer
    // getActionBar().setDisplayHomeAsUpEnabled(true);
    // getActionBar().setHomeButtonEnabled(true);

    // ActionBarDrawerToggle ties together the the proper interactions
    // between the sliding drawer and the action bar app icon
    mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
    mDrawerLayout, /* DrawerLayout object */
    R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
    R.string.drawer_open, /* "open drawer" description for accessibility */
    R.string.drawer_close /* "close drawer" description for accessibility */
    ) {
      public void onDrawerClosed(View view) {
        // getActionBar().setTitle(mTitle);
        invalidateOptionsMenu(); // creates call to
                      // onPrepareOptionsMenu()
      }

      public void onDrawerOpened(View drawerView) {
        // getActionBar().setTitle(mDrawerTitle);
        invalidateOptionsMenu(); // creates call to
                      // onPrepareOptionsMenu()
      }
    };
    mDrawerLayout.setDrawerListener(mDrawerToggle);

    if (savedInstanceState == null) {
      selectItem(0);
    }
  }

  /* The click listner for ListView in the navigation drawer */
  private class DrawerItemClickListener implements
      ListView.OnItemClickListener {
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position,
        long id) {
      selectItem(position);
    }
  }

  private void selectItem(int position) {
    // update the main content by replacing fragments
    Fragment fragment = new PlanetFragment();
    Bundle args = new Bundle();
    args.putInt(PlanetFragment.ARG_PLANET_NUMBER, position);
    fragment.setArguments(args);

    // FragmentManager fragmentManager = getFragmentManager();
    // fragmentManager.beginTransaction().replace(R.id.content_frame,
    // fragment).commit();

    // update selected item and title, then close the drawer
    // planetList.setItemChecked(position, true);
    // setTitle(mPlanetTitles[position]);
    mDrawerLayout.closeDrawer(mDrawerList);
  }

  // @Override
  // public void setTitle(CharSequence title) {
  // mTitle = title;
  // getActionBar().setTitle(mTitle);
  // }

  /**
   * When using the ActionBarDrawerToggle, you must call it during
   * onPostCreate() and onConfigurationChanged()...
   */

  @Override
  protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);
    // Sync the toggle state after onRestoreInstanceState has occurred.
    mDrawerToggle.syncState();
  }

  @Override
  public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    // Pass any configuration change to the drawer toggls
    mDrawerToggle.onConfigurationChanged(newConfig);
  }

  /**
   * Fragment that appears in the "content_frame", shows a planet
   */
  public static class PlanetFragment extends Fragment {
    public static final String ARG_PLANET_NUMBER = "planet_number";

    public PlanetFragment() {
      // Empty constructor required for fragment subclasses
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
      View rootView = inflater.inflate(R.layout.fragment_planet,
          container, false);
      int i = getArguments().getInt(ARG_PLANET_NUMBER);
      String planet = getResources()
          .getStringArray(R.array.planets_array)[i];

      int imageId = getResources().getIdentifier(
          planet.toLowerCase(Locale.getDefault()), "drawable",
          getActivity().getPackageName());
      ((ImageView) rootView.findViewById(R.id.image))
          .setImageResource(imageId);
      // getActivity().setTitle(planet);
      return rootView;
    }
  }

  public void onChartchanged(int chartId) {
    // FIXME Fetch corresponding chart from the SQLITE database
    try {
      // Currently, load a static chart from the assets folder
      ChartParser chartParser = new ChartParser();
      Chart chart = chartParser.parseXml(this.getAssets().open(
          "" + chartId+".xml"));
      loadChartFragment(chart);
      mDrawerLayout.closeDrawers();
    } catch (IOException e) {
      e.printStackTrace();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  private void loadChartFragment(Chart chart) {
    List<ChartType> charts = chart.getChartList();
    int numberOfCharts = charts.size();

    if (numberOfCharts == 1) { // single charts
      ChartType chartType = charts.get(0);
      // bar charts could be "vertical" or "horizontal"
      if (chartType instanceof BarChart) {
        String barChartOrientation = getBarChartOrientation(chartType);

        if (barChartOrientation.equals("vertical")) {
          chartDetailFragment = new BarChartFragment(chart);
        } else { // horizontal bar chart
          // TODO HorizontalBarChartFragment when the chart is ready
        }

      } else if (chartType instanceof LineChart) {
        chartDetailFragment = new LineChartFragment(chart);
      } else if (chartType instanceof PieChart) {
        chartDetailFragment = new PieChartFragment(chart);
      } else if (chartType instanceof StackedbarChart) {
        chartDetailFragment = new StackedBarChartFragment(chart);
      } else if (chartType instanceof RadarChart) {
        chartDetailFragment = new RadarChartFragment(chart);
      } else if (chartType instanceof BubbleChart) {
        chartDetailFragment = new BubbleChartFragment(chart);
      }

    } else if (numberOfCharts == 2) { // LineBar chart
      chartDetailFragment = new LineBarChartFragment(chart);
    }

    getSupportFragmentManager().beginTransaction()
        .replace(chartFragmentContainerId, chartDetailFragment)
        .commit();
  }

  private String getBarChartOrientation(ChartType chartType) {
    String barChartOrientation = "";
    ArrayList<Property> properties = chartType.getProperties();

    for (Property property : properties) {
      if (property.getType().equals("bar-orientation")) {
        barChartOrientation = property.getValue();
      }
    }

    return barChartOrientation;
  }

  @Override
  public void onItemSelected(AdapterView<?> parent, View view, int position,
      long id) {
    /**
     * Chart selection changed, notify the activity
     */
    this.onChartchanged(position);
  }

  @Override
  public void onNothingSelected(AdapterView<?> parent) {
    // TODO Auto-generated method stub

  }
}




Java Source Code List

de.hrf.workforcemanagement.AnalysisMainActivity.java
de.hrf.workforcemanagement.BarChartFragment.java
de.hrf.workforcemanagement.BubbleChartFragment.java
de.hrf.workforcemanagement.CustomAdapter.java
de.hrf.workforcemanagement.CustomOnItemSelectedListener.java
de.hrf.workforcemanagement.HorizontalBarChartFragment.java
de.hrf.workforcemanagement.LineBarChartFragment.java
de.hrf.workforcemanagement.LineChartFragment.java
de.hrf.workforcemanagement.MainActivity.java
de.hrf.workforcemanagement.PieChartFragment.java
de.hrf.workforcemanagement.RadarChartFragment.java
de.hrf.workforcemanagement.RowModel.java
de.hrf.workforcemanagement.StackedBarChartFragment.java
de.hrf.workforcemanagement.adapter.MetadataListAdapter.java
de.hrf.workforcemanagement.dialog.BaseDialog.java
de.hrf.workforcemanagement.dialog.MetadataListDialog.java
de.hrf.workforcemanagement.listener.ChartValueSelectedListener.java
de.hrf.workforcemanagement.models.Bar.java
de.hrf.workforcemanagement.models.ChartType.java
de.hrf.workforcemanagement.models.Chart.java
de.hrf.workforcemanagement.models.Color.java
de.hrf.workforcemanagement.models.CoreFilter.java
de.hrf.workforcemanagement.models.Dimension.java
de.hrf.workforcemanagement.models.Filter.java
de.hrf.workforcemanagement.models.MetadataList.java
de.hrf.workforcemanagement.models.Metadata.java
de.hrf.workforcemanagement.models.Property.java
de.hrf.workforcemanagement.models.SpecialChartXAxis.java
de.hrf.workforcemanagement.models.SpecialChartYAxis.java
de.hrf.workforcemanagement.models.StandardChartAxis.java
de.hrf.workforcemanagement.models.StandardChartXAxis.java
de.hrf.workforcemanagement.models.StandardChartYAxis.java
de.hrf.workforcemanagement.models.TestSerializer.java
de.hrf.workforcemanagement.models.barchart.BarChart.java
de.hrf.workforcemanagement.models.bubblechart.BubbleChart.java
de.hrf.workforcemanagement.models.bubblechart.BubbleData.java
de.hrf.workforcemanagement.models.bubblechart.BubbleYAxis.java
de.hrf.workforcemanagement.models.linechart.LineChart.java
de.hrf.workforcemanagement.models.linechart.LinePoint.java
de.hrf.workforcemanagement.models.piechart.PieChart.java
de.hrf.workforcemanagement.models.piechart.PieLabel.java
de.hrf.workforcemanagement.models.piechart.PieRegion.java
de.hrf.workforcemanagement.models.radarchart.RadarChart.java
de.hrf.workforcemanagement.models.radarchart.RadarRegion.java
de.hrf.workforcemanagement.models.radarchart.RadarYAxis.java
de.hrf.workforcemanagement.models.stackedbarchart.StackedbarChart.java
de.hrf.workforcemanagement.parser.ChartParser.java