<?xml version="1.0" encoding="utf-8"?>
-<RelativeLayout android:id="@+id/relativeLayout01"
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical" android:layout_width="fill_parent"
- android:layout_height="fill_parent">
-
- <LinearLayout android:id="@+id/fdLinearLayoutList"
- android:orientation="vertical" android:layout_width="fill_parent"
- android:layout_height="wrap_content" android:layout_alignParentBottom="true">
-
- <LinearLayout android:id="@+id/fdLinearLayoutSelect"
- android:orientation="vertical" android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_alignParentBottom="true" android:paddingLeft="10dp"
- android:paddingRight="10dp" android:paddingBottom="5dp">
-
- <LinearLayout android:orientation="horizontal"
- android:layout_width="fill_parent" android:layout_height="fill_parent">
- <Button android:id="@+id/fdButtonNew" android:layout_height="wrap_content"
- android:layout_width="0dip" android:layout_weight=".3"
- android:text="@string/nnew"></Button>
- <Button android:id="@+id/fdButtonSelect" android:layout_height="wrap_content"
- android:layout_width="0dip" android:layout_weight=".7"
- android:text="@string/select"></Button>
- </LinearLayout>
- </LinearLayout>
-
- <LinearLayout android:id="@+id/fdLinearLayoutCreate"
- android:orientation="vertical" android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_alignParentBottom="true" android:paddingLeft="10dp"
- android:paddingRight="10dp" android:paddingBottom="5dp">
- <TextView android:id="@+id/textViewFilename" android:text="@string/file_name"
- android:layout_width="fill_parent" android:layout_height="wrap_content" />
- <EditText android:text="" android:id="@+id/fdEditTextFile"
- android:layout_width="fill_parent" android:layout_height="wrap_content"></EditText>
-
- <LinearLayout android:orientation="horizontal"
- android:layout_width="fill_parent" android:layout_height="fill_parent">
- <Button android:id="@+id/fdButtonCancel" android:layout_height="wrap_content"
- android:layout_width="0dip" android:layout_weight=".3"
- android:text="@string/cancel"></Button>
- <Button android:id="@+id/fdButtonCreate" android:layout_height="wrap_content"
- android:layout_width="0dip" android:layout_weight=".7"
- android:text="@string/create"></Button>
- </LinearLayout>
- </LinearLayout>
-
- </LinearLayout>
-
- <LinearLayout android:orientation="vertical"
- android:layout_width="fill_parent" android:layout_height="fill_parent"
- android:layout_above="@+id/fdLinearLayoutList">
- <TextView android:id="@+id/path" android:layout_width="fill_parent"
- android:layout_height="wrap_content" />
- <ListView android:id="@android:id/list" android:layout_width="fill_parent"
- android:layout_height="fill_parent" />
- <TextView android:id="@android:id/empty"
- android:layout_width="fill_parent" android:layout_height="fill_parent"
- android:text="@string/no_data" />
- </LinearLayout>
-
-
-
-
-</RelativeLayout>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:layout_above="@+id/fdLinearLayoutList"
+ android:orientation="vertical" >
+
+ <TextView
+ android:id="@+id/path"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content" />
+
+ <ListView
+ android:id="@android:id/list"
+ android:layout_width="fill_parent"
+ android:layout_height="0dip"
+ android:layout_weight="1" />
+
+ <LinearLayout
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal" >
+
+ <Button
+ android:id="@+id/fdButtonCancel"
+ android:layout_width="0dip"
+ android:layout_height="wrap_content"
+ android:layout_weight=".3"
+ android:text="@string/button_cancel" />
+
+ <Button
+ android:id="@+id/fdButtonSelect"
+ android:layout_width="0dip"
+ android:layout_height="wrap_content"
+ android:layout_weight=".7"
+ android:text="@string/button_select" />
+ </LinearLayout>
+
+</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
-
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent" android:layout_height="fill_parent">
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent" >
+
+ <ImageView
+ android:id="@+id/fdrowimage"
+ android:layout_width="wrap_content"
+ android:layout_height="36dp"
+ android:layout_alignParentLeft="true"
+ android:contentDescription="@string/icon" />
- <ImageView android:layout_alignParentLeft="true" android:id="@+id/fdrowimage"
- android:layout_height="35dp" android:layout_width="wrap_content"
- android:paddingRight="5dp" android:paddingLeft="3dp"></ImageView>
- <TextView android:text="@+id/fdrowtext" android:layout_width="wrap_content"
- android:id="@+id/fdrowtext" android:layout_toRightOf="@+id/fdrowimage"
- android:layout_alignTop="@+id/fdrowimage" android:layout_alignBottom="@+id/fdrowimage"
- android:gravity="center_vertical" android:layout_height="35dp"
- android:textSize="23dp"></TextView>
+ <TextView
+ android:id="@+id/fdrowtext"
+ android:layout_width="wrap_content"
+ android:layout_height="36dp"
+ android:layout_alignBottom="@+id/fdrowimage"
+ android:layout_alignTop="@+id/fdrowimage"
+ android:layout_toRightOf="@+id/fdrowimage"
+ android:gravity="center_vertical"
+ android:textSize="23dp" />
</RelativeLayout>
\ No newline at end of file
<string name="button_play">Play</string>
<string name="button_stop">Stop</string>
<string name="button_select">Select</string>
- <string name="filechooser_name">Android tutorial 5</string>
+ <string name="button_cancel">Cancel</string>
+ <string name="filechooser_name">Select a file</string>
<string name="location">Location</string>
- <string name="cant_read_folder">folder can\'t be read!</string>
- <string name="nnew">New</string>
- <string name="select">Select</string>
- <string name="file_name">File name:</string>
- <string name="cancel">Cancel</string>
- <string name="create">Save</string>
- <string name="no_data">No Data</string>
+ <string name="cant_read_folder">folder cannot be read</string>
+ <string name="icon">Icon</string>
</resources>
package com.gst_sdk_tutorials.tutorial_5;
+import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
-import com.lamerman.FileDialog;
-import com.lamerman.SelectionMode;
-
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
-import android.util.Log;
import android.os.Bundle;
import android.os.Environment;
import android.os.PowerManager;
+import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.widget.Toast;
import com.gstreamer.GStreamer;
+import com.lamerman.FileDialog;
public class Tutorial5 extends Activity implements SurfaceHolder.Callback, OnSeekBarChangeListener {
private native void nativeInit(); // Initialize native code, build pipeline, etc
private final String defaultMediaUri = "http://docs.gstreamer.com/media/sintel_trailer-368p.ogv";
static private final int PICK_FILE_CODE = 1;
+ private String last_folder;
private PowerManager.WakeLock wake_lock;
setContentView(R.layout.main);
+ last_folder = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES).getAbsolutePath();
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
wake_lock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "Android Aurena");
select.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent i = new Intent(getBaseContext(), FileDialog.class);
- i.putExtra(FileDialog.START_PATH, Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES).getAbsolutePath());
- i.putExtra(FileDialog.SELECTION_MODE, SelectionMode.MODE_OPEN);
+ i.putExtra(FileDialog.START_PATH, last_folder);
startActivityForResult(i, PICK_FILE_CODE);
}
});
if (resultCode == RESULT_OK && requestCode == PICK_FILE_CODE) {
mediaUri = "file://" + data.getStringExtra(FileDialog.RESULT_PATH);
position = 0;
+ last_folder = new File (data.getStringExtra(FileDialog.RESULT_PATH)).getParent();
+ Log.i("GStreamer", "Setting last_folder to " + last_folder);
setMediaUri();
}
}
-// From http://code.google.com/p/android-file-dialog/
+// Based on http://code.google.com/p/android-file-dialog/
//
// Copyright (c) 2011, 2012, Alexander Ponomarev <alexander.ponomarev.1@gmail.com>
// All rights reserved.
import java.util.List;
import java.util.TreeMap;
-import com.gst_sdk_tutorials.tutorial_5.R;
-
import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.DialogInterface;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
-import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
-import android.widget.EditText;
-import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
+import com.gst_sdk_tutorials.tutorial_5.R;
+
/**
* Activity para escolha de arquivos/diretorios.
*
*/
public static final String RESULT_PATH = "RESULT_PATH";
- /**
- * Parametro de entrada da Activity: tipo de selecao: pode criar novos paths
- * ou nao. Padrao: nao permite.
- *
- * @see {@link SelectionMode}
- */
- public static final String SELECTION_MODE = "SELECTION_MODE";
-
- /**
- * Parametro de entrada da Activity: se e permitido escolher diretorios.
- * Padrao: falso.
- */
- public static final String CAN_SELECT_DIR = "CAN_SELECT_DIR";
private List<String> path = null;
private TextView myPath;
- private EditText mFileName;
private ArrayList<HashMap<String, Object>> mList;
private Button selectButton;
- private LinearLayout layoutSelect;
- private LinearLayout layoutCreate;
- private InputMethodManager inputManager;
private String parentPath;
private String currentPath = ROOT;
- private int selectionMode = SelectionMode.MODE_CREATE;
-
private String[] formatFilter = null;
- private boolean canSelectDir = false;
-
private File selectedFile;
private HashMap<String, Integer> lastPositions = new HashMap<String, Integer>();
setContentView(R.layout.file_dialog_main);
myPath = (TextView) findViewById(R.id.path);
- mFileName = (EditText) findViewById(R.id.fdEditTextFile);
-
- inputManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
selectButton = (Button) findViewById(R.id.fdButtonSelect);
selectButton.setEnabled(false);
}
});
- final Button newButton = (Button) findViewById(R.id.fdButtonNew);
- newButton.setOnClickListener(new OnClickListener() {
-
- public void onClick(View v) {
- setCreateVisible(v);
-
- mFileName.setText("");
- mFileName.requestFocus();
- }
- });
-
- selectionMode = getIntent().getIntExtra(SELECTION_MODE, SelectionMode.MODE_CREATE);
-
formatFilter = getIntent().getStringArrayExtra(FORMAT_FILTER);
- canSelectDir = getIntent().getBooleanExtra(CAN_SELECT_DIR, false);
-
- if (selectionMode == SelectionMode.MODE_OPEN) {
- newButton.setEnabled(false);
- }
-
- layoutSelect = (LinearLayout) findViewById(R.id.fdLinearLayoutSelect);
- layoutCreate = (LinearLayout) findViewById(R.id.fdLinearLayoutCreate);
- layoutCreate.setVisibility(View.GONE);
-
final Button cancelButton = (Button) findViewById(R.id.fdButtonCancel);
cancelButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
- setSelectVisible(v);
+ setResult(RESULT_CANCELED);
+ finish();
}
});
- final Button createButton = (Button) findViewById(R.id.fdButtonCreate);
- createButton.setOnClickListener(new OnClickListener() {
-
- public void onClick(View v) {
- if (mFileName.getText().length() > 0) {
- getIntent().putExtra(RESULT_PATH, currentPath + "/" + mFileName.getText());
- setResult(RESULT_OK, getIntent());
- finish();
- }
- }
- });
String startPath = getIntent().getStringExtra(START_PATH);
startPath = startPath != null ? startPath : ROOT;
- if (canSelectDir) {
- File file = new File(startPath);
- selectedFile = file;
- selectButton.setEnabled(true);
- }
getDir(startPath);
ListView lv = (ListView) findViewById (android.R.id.list);
File file = new File(path.get(position));
- setSelectVisible(v);
-
if (file.isDirectory()) {
selectButton.setEnabled(false);
if (file.canRead()) {
lastPositions.put(currentPath, position);
getDir(path.get(position));
- if (canSelectDir) {
- selectedFile = file;
- v.setSelected(true);
- selectButton.setEnabled(true);
- }
} else {
- new AlertDialog.Builder(this).setIcon(R.drawable.gst_sdk_icon)
+ new AlertDialog.Builder(this).setIcon(android.R.drawable.stat_sys_warning)
.setTitle("[" + file.getName() + "] " + getText(R.string.cant_read_folder))
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
if ((keyCode == KeyEvent.KEYCODE_BACK)) {
selectButton.setEnabled(false);
- if (layoutCreate.getVisibility() == View.VISIBLE) {
- layoutCreate.setVisibility(View.GONE);
- layoutSelect.setVisibility(View.VISIBLE);
+ if (!currentPath.equals(ROOT)) {
+ getDir(parentPath);
} else {
- if (!currentPath.equals(ROOT)) {
- getDir(parentPath);
- } else {
- return super.onKeyDown(keyCode, event);
- }
+ return super.onKeyDown(keyCode, event);
}
return true;
}
}
- /**
- * Define se o botao de CREATE e visivel.
- *
- * @param v
- */
- private void setCreateVisible(View v) {
- layoutCreate.setVisibility(View.VISIBLE);
- layoutSelect.setVisibility(View.GONE);
-
- inputManager.hideSoftInputFromWindow(v.getWindowToken(), 0);
- selectButton.setEnabled(false);
- }
-
- /**
- * Define se o botao de SELECT e visivel.
- *
- * @param v
- */
- private void setSelectVisible(View v) {
- layoutCreate.setVisibility(View.GONE);
- layoutSelect.setVisibility(View.VISIBLE);
-
- inputManager.hideSoftInputFromWindow(v.getWindowToken(), 0);
- selectButton.setEnabled(false);
- }
}
+++ /dev/null
-// From http://code.google.com/p/android-file-dialog/
-//
-// Copyright (c) 2011, 2012, Alexander Ponomarev <alexander.ponomarev.1@gmail.com>
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without modification,
-// are permitted provided that the following conditions are met:
-//
-// Redistributions of source code must retain the above copyright notice, this list
-// of conditions and the following disclaimer. Redistributions in binary form must
-// reproduce the above copyright notice, this list of conditions and the following
-// disclaimer in the documentation and/or other materials provided with the distribution.
-// Neither the name of the <ORGANIZATION> nor the names of its contributors may be used
-// to endorse or promote products derived from this software without specific prior
-// written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
-// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
-// SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
-// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
-// TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
-// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
-// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
-// DAMAGE.
-
-package com.lamerman;
-
-public class SelectionMode {
- public static final int MODE_CREATE = 0;
-
- public static final int MODE_OPEN = 1;
-}