Android Open Source - Crescendo Main Activity






From Project

Back to project page Crescendo.

License

The source code is released under:

GNU General Public License

If you think the Android project Crescendo 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.crescendo.crescendo;
/*from  www .  java  2  s. c  o m*/
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;


public class MainActivity extends Activity {
  
  List<Map<String, String>> projlist = new ArrayList <Map<String,String>>();
  HashSet<String> filenames= new HashSet<String>();
  SimpleAdapter projAdapter;
  ListView listview; 

  
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    
    
    String[] from = {"title","genre"};
    int[] to = {android.R.id.text1, android.R.id.text2};
    projAdapter = new SimpleAdapter(this, projlist, android.R.layout.simple_list_item_2, from, to);
    listview = (ListView) findViewById(R.id.Rhy_listview);
    listview.setAdapter(projAdapter);
    File f= getFilesDir();
    File[] fs=f.listFiles();
    for (int i=0; i<fs.length;i++){
      String name = fs[i].getName();
      int pos = name.lastIndexOf(".");
      if (pos > 0) {
          name = name.substring(0, pos);
      }
        filenames.add(name);
        Map <String,String> m = new HashMap <String,String>();
        m.put("title", fs[i].getName());
        try {
          ObjectInputStream in= new ObjectInputStream(openFileInput(fs[i].getName()));
          String x=(String)in.readObject();
          for (int n=0; n<x.length();n++){
            if (x.charAt(n)==';'){
              x=x.substring(0, n);
            }
          }
          in.close();
          m.put("genre", x);
          projlist.add(m);
          projAdapter.notifyDataSetChanged();
        } catch (FileNotFoundException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        } catch (ClassNotFoundException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
    }
    final MainActivity main=this;
    
    listview.setLongClickable(true);
    listview.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {

      @Override
      public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
          int arg2, long arg3) {
        final String x=  ((TextView) arg1.findViewById (android.R.id.text1)).getText().toString();
        final int remover=arg2;
        new AlertDialog.Builder(main)
        .setTitle("Delete Project")
        .setMessage("Do you want to delete your project?")
        .setIcon(android.R.drawable.ic_dialog_alert)
        .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {                    
                   
                   @Override
                     public void onClick(DialogInterface dialog, int id) {
                  
                     File f= new File(main.getFilesDir()+File.separator+x+".txt");
                     f.delete();
                     filenames.remove(x);
                     projlist.remove(remover);
                     projAdapter.notifyDataSetChanged();

                                      
                     }
                 })
                 .setNegativeButton(R.string.cancel, null).show();
        return false;
      }
    });
    listview.setOnItemClickListener(new OnItemClickListener() 
    {
        @SuppressWarnings("unchecked")
      @Override public void onItemClick(AdapterView<?> arg0, View listitem,int position, long arg3)
        { 
            TextView title = (TextView) listitem.findViewById (android.R.id.text1);
            HashMap<String, String> mapper=(HashMap<String, String>) main.projAdapter.getItem(position);
            String stitle =  title.getText().toString();
            Object[] sgen = mapper.values().toArray();
            String sgenre="bugged";
            for (int i=0;i<sgen.length;i++){
              if (!(sgen[i].toString().equals(stitle))){
                sgenre=sgen[i].toString();
              }
            }
          Toast.makeText(MainActivity.this, stitle, Toast.LENGTH_LONG).show();
          
          Intent editIntent = new Intent(MainActivity.this, texteditor.class);
          editIntent.putExtra("ProjName", stitle);
          Log.d("Genre", sgenre);
          editIntent.putExtra("ProjGenre", sgenre);
          startActivity(editIntent);   
        }      
    });
    
    final Button button = (Button) findViewById(R.id.add);
    button.setOnClickListener(new View.OnClickListener() {
      public void onClick(View v) {
        
          AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
            LayoutInflater inflater = getLayoutInflater();
            
            final View dialogView = inflater.inflate(R.layout.project_dialog, null);
            builder.setView(dialogView)
                   
            .setPositiveButton(R.string.dialogposbutton, new DialogInterface.OnClickListener() {
                      
                     
                     @Override
                       public void onClick(DialogInterface dialog, int id) {
                        
                            EditText t= (EditText) dialogView.findViewById(R.id.dialogT);
                    EditText g= (EditText) dialogView.findViewById(R.id.dialogG);
                    if (filenames.add(t.getText().toString())){
                    Map <String,String> m = new HashMap <String,String>();
                    m.put("title", t.getText().toString());
                    m.put("genre", g.getText().toString());
                    
                    projlist.add(m);
                    projAdapter.notifyDataSetChanged();
                    }
                    else{
                        Toast.makeText(MainActivity.this, "Already a project of that name", Toast.LENGTH_LONG).show();

                    }
          
                    
                       }
                   })
                   .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                      public void onClick(DialogInterface dialog, int id) {
                           
                       }
                   });      
            builder.show();
        }
    });
    return;
  }
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return false;
  }
}




Java Source Code List

com.crescendo.crescendo.MainActivity.java
com.crescendo.crescendo.NewProjectDialog.java
com.crescendo.crescendo.RhyInput.java
com.crescendo.crescendo.RhymeDictionary.java
com.crescendo.crescendo.RhymeGetter.java
com.crescendo.crescendo.aboutactivity.java
com.crescendo.crescendo.songs.java
com.crescendo.crescendo.texteditor.java