Android Open Source - ParticlePlay Custom Element Manager Activity






From Project

Back to project page ParticlePlay.

License

The source code is released under:

GNU General Public License

If you think the Android project ParticlePlay 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.droidinteractive.particleplay.custom;
/*//  w  ww .j av  a  2 s . com
 * Copyright (c) 2010 Ragdoll Games
 * Copyright (c) 2010-2014 Droid Interactive
 * Copyright (c) 2010-2014 IDKJava Team
 * 
 * This file is part of Particle Play.
 * 
 * Particle Play is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Particle Play is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Particle Play. If not, see <http://www.gnu.org/licenses/>.
 */
import java.io.File;
import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;

import com.droidinteractive.particleplay.game.FileManager;
import com.droidinteractive.particleplay.R;

/**
 * File format:
 * NAME\n
 * COLLISION ARRAY (space separated)\n
 * SPECIALS ARRAY (space separated)
 */
public class CustomElementManagerActivity extends Activity
{
  private static ImageButton actionButton;
  private static TableRow tr;
  private static LinearLayout buttonContainer;
  private static Resources res;
  
  
  public void onCreate(Bundle savedInstanceState)
  {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.custom_element_manager_activity);
    res = getResources();
    
    Button createElementButton = (Button) findViewById(R.id.create_particle_button);
    createElementButton.setOnClickListener(new OnClickListener()
    {
      @Override
      public void onClick(View v)
      {
        startActivity(new Intent(CustomElementManagerActivity.this, CustomElementActivity.class));
      }
    });
  }
  @Override
  protected void onResume()
  {
    super.onResume();
    CustomElementManager.refresh(this);
    ArrayList<CustomElement> elements = CustomElementManager.getElementList();
    
    // Clear the existing list
    TableLayout tl = (TableLayout)findViewById(R.id.loads_container);
    tl.removeAllViews();
    
    //Go through and find all the save files and dynamically add them
    int length = elements.size();
    if(length != 0)
    {
      for(int i = 0; i < length; i++)
      {
        if (elements.get(i).isValid())
        {
          addEntity(elements.get(i).name, elements.get(i).getFilename(), elements.get(i).getCopy());
        }
      }
    }
    else
    {
      tr = new TableRow(this);
      tr.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
      tr.setGravity(Gravity.CENTER);
      
      TextView tv = new TextView(this);
      tv.setText(res.getText(R.string.no_particle));
      
      tr.addView(tv);
      tl.addView(tr);
    }
  }
  
    public void addEntity(String elementName, String filename, int copy)
    {
      final String filenameFinal = filename;
        
        //Create a TableLayout object associated with the TableLayout in the .xml file
        TableLayout tl = (TableLayout)findViewById(R.id.loads_container);
        //Create a LinearLayout to contain our row
        buttonContainer = new LinearLayout(this);
    //Set some properties
    //tr.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
    buttonContainer.setBackgroundResource(R.drawable.load_state_tr_bg);
    buttonContainer.setLongClickable(true);
    buttonContainer.setClickable(true);
    buttonContainer.setPadding(25, 10, 25, 10);
    buttonContainer.setGravity(Gravity.RIGHT);
    
    //Create a TextView to hold the element name
    TextView nameTextView = new TextView(this);
    String versionTag = (copy == 0) ? "" : " (" + String.valueOf(copy) + ")";
    nameTextView.setText(elementName + versionTag);
    nameTextView.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1));
    //filename.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
    
    //Makes use of DisplayMetrics to create an automatic dip unit :)
    //filename.setPadding((int)(16 * SCALE + 0.5f), 0, 0, 0);
    //Add the TextView to the TableRow
    buttonContainer.addView(nameTextView);

    //Set buttonContainer's gravity to right with a 16dip right padding
    //buttonContainer.setPadding(0, 0, (int)(16 * SCALE + 0.5f), 0);
    //buttonContainer.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, 50));
    
        // Edit element button
        actionButton = new ImageButton(this);
        actionButton.setBackgroundResource(R.drawable.load_state_select);
        actionButton.setLayoutParams(new LayoutParams(
                        LayoutParams.WRAP_CONTENT, 
                        LayoutParams.WRAP_CONTENT));
        actionButton.setOnClickListener
        (
        new OnClickListener()
        {
          public void onClick(View v)
          {
            Intent i = new Intent(CustomElementManagerActivity.this, CustomElementActivity.class);
            i.putExtra("filename", filenameFinal);
            startActivity(i);
          }
        }
        );
        buttonContainer.addView(actionButton);
        
        // Delete button
        actionButton = new ImageButton(this);
        actionButton.setBackgroundResource(R.drawable.load_state_delete);
        actionButton.setLayoutParams(new LayoutParams(
                LayoutParams.WRAP_CONTENT, 
                LayoutParams.WRAP_CONTENT));
    actionButton.setOnClickListener
    (
      new OnClickListener()
      {
        public void onClick(View v)
        {
          // Delete the custom element file
          (new File(FileManager.ROOT_DIR + FileManager.ELEMENTS_DIR + filenameFinal + FileManager.ELEMENT_EXT)).delete();
          
          // Update the view accordingly
          ViewGroup parent = (ViewGroup) v.getParent().getParent();
          parent.removeView((View) v.getParent());
          TableLayout tl = (TableLayout)findViewById(R.id.loads_container);
          if(tl.getChildCount() == 0)
          {
            tr = new TableRow(getBaseContext());
            tr.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
            tr.setGravity(Gravity.CENTER);
            
            TextView tv = new TextView(getBaseContext());
            tv.setText(res.getText(R.string.no_particle));
            
            tr.addView(tv);
            tl.addView(tr);
          }
        }
      }
    );
    buttonContainer.addView(actionButton);
        
        // Click on the entire row
        buttonContainer.setOnClickListener
        (
          new OnClickListener()
          {
                public void onClick(View viewParam)
                {
            Intent i = new Intent(CustomElementManagerActivity.this, CustomElementActivity.class);
            i.putExtra("filename", filenameFinal);
            startActivity(i);
                }
          }
        );
        
        // Add the created row to our TableLayout
        tl.addView(buttonContainer, new LayoutParams(
                LayoutParams.MATCH_PARENT, 
                LayoutParams.WRAP_CONTENT));
    }
}




Java Source Code List

com.droidinteractive.colorpicker.ColorPickerBox.java
com.droidinteractive.colorpicker.ColorPickerDialog.java
com.droidinteractive.colorpicker.widget.ColorPickerPreferenceWidgetView.java
com.droidinteractive.colorpicker.widget.ColorPickerPreference.java
com.droidinteractive.particleplay.FixMeActivity.java
com.droidinteractive.particleplay.Globals.java
com.droidinteractive.particleplay.LoadStateActivity.java
com.droidinteractive.particleplay.MainActivity.java
com.droidinteractive.particleplay.MenuActivity.java
com.droidinteractive.particleplay.SaveStateActivity.java
com.droidinteractive.particleplay.SplashActivity.java
com.droidinteractive.particleplay.custom.CustomElementActivity.java
com.droidinteractive.particleplay.custom.CustomElementAdvancedActivity.java
com.droidinteractive.particleplay.custom.CustomElementBasicActivity.java
com.droidinteractive.particleplay.custom.CustomElementManagerActivity.java
com.droidinteractive.particleplay.custom.CustomElementManager.java
com.droidinteractive.particleplay.custom.CustomElement.java
com.droidinteractive.particleplay.game.ActionItem.java
com.droidinteractive.particleplay.game.Control.java
com.droidinteractive.particleplay.game.CustomElementManager.java
com.droidinteractive.particleplay.game.FileManager.java
com.droidinteractive.particleplay.game.MenuBar.java
com.droidinteractive.particleplay.game.PopupWindows.java
com.droidinteractive.particleplay.game.QuickAction.java
com.droidinteractive.particleplay.game.SandView.java
com.droidinteractive.particleplay.game.SaveManager.java
com.droidinteractive.particleplay.game.Temperature.java
com.droidinteractive.particleplay.preferences.AlphaPatternDrawable.java
com.droidinteractive.particleplay.preferences.ColorPickerDialogPref.java
com.droidinteractive.particleplay.preferences.ColorPickerPanelView.java
com.droidinteractive.particleplay.preferences.ColorPickerPreference.java
com.droidinteractive.particleplay.preferences.ColorPickerView.java
com.droidinteractive.particleplay.preferences.PreferencesActivity.java
com.droidinteractive.particleplay.preferences.Preferences.java
com.droidinteractive.particleplay.preferences.SeekBarPreference.java
com.droidinteractive.slidingdrawer.OnDrawerCloseListener.java
com.droidinteractive.slidingdrawer.OnDrawerOpenListener.java
com.droidinteractive.slidingdrawer.OnDrawerScrollListener.java
com.droidinteractive.slidingdrawer.SlidingDrawer.java