Android Open Source - compCellScope Folder_ Chooser






From Project

Back to project page compCellScope.

License

The source code is released under:

MIT License

If you think the Android project compCellScope 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.wallerlab.compcellscope;
//from  w w  w.j a va  2  s .  c o  m
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Environment;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import java.io.File;


public class Folder_Chooser extends Activity {

    Button getPictures, selectDirectory;
    EditText location;
    final static String PREFS_NAME = "settings";
    final static String location_name = "location";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_folder__chooser);
        final SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);

        //File Stuff
        File default_loc = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + File.separator
                + "Research_Pics/");


        location = (EditText) findViewById(R.id.mod_Location);
        selectDirectory = (Button) findViewById(R.id.pick_directory);
        getPictures = (Button) findViewById(R.id.get_pictures);

        location.setText(settings.getString(location_name, default_loc.toString()));
        
        
        selectDirectory.setOnClickListener(new View.OnClickListener() {
          private String m_chosenDir = "";
            private boolean m_newFolderEnabled = true;
            
      @Override
      public void onClick(View v) {

                // Create DirectoryChooserDialog and register a callback 
                DirectoryChooserDialog directoryChooserDialog = 
                new DirectoryChooserDialog(Folder_Chooser.this, 
                    new DirectoryChooserDialog.ChosenDirectoryListener() 
                {
                    @Override
                    public void onChosenDir(String chosenDir) 
                    {
                        m_chosenDir = chosenDir;
                        File file = new File(m_chosenDir);
                        location.setText(file.toString());
                        if(file.exists()) {
                            SharedPreferences.Editor edit = settings.edit();
                            edit.putString(location_name, location.getText().toString());
                            edit.commit();
                            //startImageGalleryActivity();
                        }
                        else{
                            Toast.makeText(getPictures.getContext(), "This file does not exist", Toast.LENGTH_LONG).show();
                        }
                        
                        Toast.makeText(
                        Folder_Chooser.this, "Chosen directory: " + 
                          chosenDir, Toast.LENGTH_SHORT).show();
                    }
                }); 
                // Toggle new folder button enabling
                directoryChooserDialog.setNewFolderEnabled(m_newFolderEnabled);
                // Load directory chooser dialog for initial 'm_chosenDir' directory.
                // The registered callback will be called upon final directory selection.
                directoryChooserDialog.chooseDirectory(m_chosenDir);
                m_newFolderEnabled = ! m_newFolderEnabled;
        
      }
    });
        
        
        getPictures.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                File file = new File(location.getText().toString());
                if(file.exists()) {
                    SharedPreferences.Editor edit = settings.edit();
                    edit.putString(location_name, location.getText().toString());
                    edit.commit();
                    startImageGalleryActivity();
                }
                else{
                    Toast.makeText(getPictures.getContext(), "This file does not exist", Toast.LENGTH_LONG).show();
                }

            }
        });

    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.folder__chooser, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    protected void startImageGalleryActivity(){
        Intent intent = new Intent(this, Image_Gallery.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
    }


}




Java Source Code List

com.wallerlab.compcellscope.AcquireActivity.java
com.wallerlab.compcellscope.AcquireActivity.java
com.wallerlab.compcellscope.AcquireSettings.java
com.wallerlab.compcellscope.AcquireSurfaceView.java
com.wallerlab.compcellscope.AcquireSurfaceView.java
com.wallerlab.compcellscope.BluetoothActivity.java
com.wallerlab.compcellscope.BluetoothApplicationClass.java
com.wallerlab.compcellscope.BluetoothApplicationClass.java
com.wallerlab.compcellscope.BluetoothDeviceListActivity.java
com.wallerlab.compcellscope.BluetoothDeviceListActivity.java
com.wallerlab.compcellscope.BluetoothService.java
com.wallerlab.compcellscope.BluetoothService.java
com.wallerlab.compcellscope.BurstModeActivity.java
com.wallerlab.compcellscope.DirectoryChooserDialog.java
com.wallerlab.compcellscope.Folder_Chooser.java
com.wallerlab.compcellscope.ImageProgressTask.java
com.wallerlab.compcellscope.ImageProgressTask.java
com.wallerlab.compcellscope.Image_Gallery.java
com.wallerlab.compcellscope.MainActivity.java
com.wallerlab.compcellscope.MainActivity.java
com.wallerlab.compcellscope.MultiModeViewActivity.java
com.wallerlab.compcellscope.MultiModeView.java
com.wallerlab.compcellscope.PortraitCameraView.java