Android Open Source - codemap Workspace Fragment






From Project

Back to project page codemap.

License

The source code is released under:

GNU General Public License

If you think the Android project codemap 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.hdweiss.codemap.view.workspace;
/*from   w w w .j  a v a  2s .c o  m*/
import android.app.Fragment;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;

import com.hdweiss.codemap.R;
import com.hdweiss.codemap.data.CodeMapApp;
import com.hdweiss.codemap.util.CodeMapPoint;
import com.hdweiss.codemap.util.Utils;
import com.hdweiss.codemap.view.CodeMapActivity;
import com.hdweiss.codemap.view.workspace.browser.WorkspaceBrowser;
import com.hdweiss.codemap.view.workspace.outline.OutlineBrowser;

public class WorkspaceFragment extends Fragment implements
    SharedPreferences.OnSharedPreferenceChangeListener {
  public static final String WORKSPACE_NAME = "workspace_name";
  public static final String PROJECT_NAME = "project_name";
  private static final String ZOOM = "zoom";
  private static final String SCROLL_X = "scrollX";
  private static final String SCROLL_Y = "scrollY";
  
  private WorkspaceController controller;
  private WorkspaceView codeMapView;
  private OutlineBrowser outlineBrowser;
  private WorkspaceBrowser workspaceBrowser;
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
      Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);

    setHasOptionsMenu(true);
        
    View view = inflater.inflate(R.layout.workspace, container, false);
    codeMapView = (WorkspaceView) view.findViewById(R.id.codemap);
    outlineBrowser = (OutlineBrowser) view.findViewById(R.id.outline_browser);
    workspaceBrowser = (WorkspaceBrowser) view.findViewById(R.id.workspace_browser);

    init();
    
    SharedPreferences prefs = PreferenceManager
        .getDefaultSharedPreferences(getActivity());
    prefs.registerOnSharedPreferenceChangeListener(this);

    if(savedInstanceState != null)
      restoreInstanceState(savedInstanceState);
    
    return view;
  }
  
  private void init() {
    String projectName = getArguments().getString(PROJECT_NAME);
    String workspaceName = getArguments().getString(WORKSPACE_NAME);
    
    this.controller = new WorkspaceController(projectName, workspaceName, getActivity());
    controller.setView(codeMapView);
    ((CodeMapApp) getActivity().getApplication()).addController(controller);

    outlineBrowser.setController(controller);
    workspaceBrowser.setController(controller, (CodeMapActivity) getActivity());
  }
  
  public void restoreInstanceState(Bundle savedInstanceState) {
    if(savedInstanceState != null) {
      float zoom = savedInstanceState.getFloat(ZOOM);
      int scrollX = savedInstanceState.getInt(SCROLL_X);
      int scrollY = savedInstanceState.getInt(SCROLL_Y);

      codeMapView.setScaleFactor(zoom, new CodeMapPoint(0, 0));
      codeMapView.setScrollX(scrollX);
      codeMapView.setScrollY(scrollY);
    }
  }
  
  @Override
  public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putFloat(ZOOM, codeMapView.getScaleFactor());
    outState.putInt(SCROLL_X, codeMapView.getScrollX());
    outState.putInt(SCROLL_Y, codeMapView.getScrollY());
  }


  @Override
  public void onResume() {
    super.onResume();
    this.getActivity().registerReceiver(receiver, filter);
  }

  @Override
  public void onPause() {
    this.getActivity().unregisterReceiver(receiver);
    super.onPause();
  }

  
  @Override
  public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    inflater.inflate(R.menu.workspace, menu);
  }

  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    
    switch (item.getItemId()) {
    case R.id.codemap_clear:
      codeMapView.clear();
      return true;
      
    case R.id.codemap_resetZoom:
      codeMapView.setScaleFactor(1, new CodeMapPoint(0,0));
      return true;
      
    case R.id.workspace_delete:
      workspaceBrowser.handleLongClick(item);
      return true;
      
    default:
      return super.onOptionsItemSelected(item);
    }
  }
  

  @Override
  public void onDestroy() {
    controller.saveCodeMapState();
    super.onDestroy();
  }
  
  
  public static final String INTENT_REFRESH = "com.hdweiss.codemap.codebrowser.refresh";
  private IntentFilter filter = new IntentFilter(INTENT_REFRESH);
  private BroadcastReceiver receiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context c, Intent i) {
      String action = i.getStringExtra("action");
      
      if (action == null)
        outlineBrowser.refresh();
      else if (action.equals("workspace"))
        workspaceBrowser.refresh();
    }
  };
  
  public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
      String key) {
    if (key.equals("sourceFontSize")) {
      int fontSize = Utils.getSourceFontsize(getActivity());
      codeMapView.setFontSize(fontSize);
    }
  }

}




Java Source Code List

com.hdweiss.codemap.data.CodeMapApp.java
com.hdweiss.codemap.data.CscopeEntry.java
com.hdweiss.codemap.data.CscopeWrapper.java
com.hdweiss.codemap.data.Cscope.java
com.hdweiss.codemap.data.ICodeMapItem.java
com.hdweiss.codemap.data.JGitWrapper.java
com.hdweiss.codemap.data.ProjectController.java
com.hdweiss.codemap.data.Project.java
com.hdweiss.codemap.data.SerializableItem.java
com.hdweiss.codemap.data.SerializableLink.java
com.hdweiss.codemap.util.AbsoluteLayout.java
com.hdweiss.codemap.util.CodeMapCursorPoint.java
com.hdweiss.codemap.util.CodeMapPoint.java
com.hdweiss.codemap.util.FlowLayout.java
com.hdweiss.codemap.util.ObjectSerializer.java
com.hdweiss.codemap.util.SpanUtils.java
com.hdweiss.codemap.util.SyntaxHighlighter.java
com.hdweiss.codemap.util.Utils.java
com.hdweiss.codemap.util.ZoomableAbsoluteLayout.java
com.hdweiss.codemap.util.ZoomableLinearLayout.java
com.hdweiss.codemap.view.CodeMapActivity.java
com.hdweiss.codemap.view.CodeMapTabListener.java
com.hdweiss.codemap.view.Preferences.java
com.hdweiss.codemap.view.project.ProjectAdapter.java
com.hdweiss.codemap.view.project.ProjectBrowser.java
com.hdweiss.codemap.view.project.ProjectItemView.java
com.hdweiss.codemap.view.project.ProjectWizard.java
com.hdweiss.codemap.view.workspace.CollisionManager.java
com.hdweiss.codemap.view.workspace.FindDeclarationTask.java
com.hdweiss.codemap.view.workspace.WorkspaceController.java
com.hdweiss.codemap.view.workspace.WorkspaceFragment.java
com.hdweiss.codemap.view.workspace.WorkspaceStateLoader.java
com.hdweiss.codemap.view.workspace.WorkspaceState.java
com.hdweiss.codemap.view.workspace.WorkspaceViewListeners.java
com.hdweiss.codemap.view.workspace.WorkspaceView.java
com.hdweiss.codemap.view.workspace.browser.WorkspaceBrowserAdapter.java
com.hdweiss.codemap.view.workspace.browser.WorkspaceBrowser.java
com.hdweiss.codemap.view.workspace.fragments.CodeMapAnnotation.java
com.hdweiss.codemap.view.workspace.fragments.CodeMapFunction.java
com.hdweiss.codemap.view.workspace.fragments.CodeMapImage.java
com.hdweiss.codemap.view.workspace.fragments.CodeMapItem.java
com.hdweiss.codemap.view.workspace.fragments.CodeMapLink.java
com.hdweiss.codemap.view.workspace.fragments.FunctionLinkSpan.java
com.hdweiss.codemap.view.workspace.outline.CscopeEntryAdapter.java
com.hdweiss.codemap.view.workspace.outline.OutlineAdapter.java
com.hdweiss.codemap.view.workspace.outline.OutlineBrowser.java
com.hdweiss.codemap.view.workspace.outline.OutlineItemComparator.java
com.hdweiss.codemap.view.workspace.outline.OutlineItemView.java
com.hdweiss.codemap.view.workspace.outline.OutlineItem.java