diff options
author | Xavi Artigas <xartigas@fluendo.com> | 2012-11-06 13:19:27 +0100 |
---|---|---|
committer | Xavi Artigas <xartigas@fluendo.com> | 2012-11-06 13:19:27 +0100 |
commit | d6448c8b2e06f8c984d3227760a5f5b4ff5d34dd (patch) | |
tree | 0000e41d1afe17da513fa593a96d426a0d22fa7c /gst-sdk/tutorials/android-tutorial-5 | |
parent | deb87d4a23ed1d089c545bdca8cca08bda0b9193 (diff) |
Major revamp of the file chooser dialog to: Remove unused code/layout/strings, remember last visited folder, add a cancel button and beautify a bit the dialogs.
Diffstat (limited to 'gst-sdk/tutorials/android-tutorial-5')
-rw-r--r-- | gst-sdk/tutorials/android-tutorial-5/res/drawable-ldpi/file.png | bin | 571 -> 1102 bytes | |||
-rw-r--r-- | gst-sdk/tutorials/android-tutorial-5/res/drawable-ldpi/folder.png | bin | 392 -> 1552 bytes | |||
-rw-r--r-- | gst-sdk/tutorials/android-tutorial-5/res/layout/file_dialog_main.xml | 103 | ||||
-rw-r--r-- | gst-sdk/tutorials/android-tutorial-5/res/layout/file_dialog_row.xml | 28 | ||||
-rwxr-xr-x | gst-sdk/tutorials/android-tutorial-5/res/values/strings.xml | 12 | ||||
-rw-r--r-- | gst-sdk/tutorials/android-tutorial-5/src/com/gst_sdk_tutorials/tutorial_5/Tutorial5.java | 14 | ||||
-rw-r--r-- | gst-sdk/tutorials/android-tutorial-5/src/com/lamerman/FileDialog.java | 120 | ||||
-rw-r--r-- | gst-sdk/tutorials/android-tutorial-5/src/com/lamerman/SelectionMode.java | 34 |
8 files changed, 77 insertions, 234 deletions
diff --git a/gst-sdk/tutorials/android-tutorial-5/res/drawable-ldpi/file.png b/gst-sdk/tutorials/android-tutorial-5/res/drawable-ldpi/file.png Binary files differindex fa45699..6a64f0e 100644 --- a/gst-sdk/tutorials/android-tutorial-5/res/drawable-ldpi/file.png +++ b/gst-sdk/tutorials/android-tutorial-5/res/drawable-ldpi/file.png diff --git a/gst-sdk/tutorials/android-tutorial-5/res/drawable-ldpi/folder.png b/gst-sdk/tutorials/android-tutorial-5/res/drawable-ldpi/folder.png Binary files differindex 0108ed9..d54f034 100644 --- a/gst-sdk/tutorials/android-tutorial-5/res/drawable-ldpi/folder.png +++ b/gst-sdk/tutorials/android-tutorial-5/res/drawable-ldpi/folder.png diff --git a/gst-sdk/tutorials/android-tutorial-5/res/layout/file_dialog_main.xml b/gst-sdk/tutorials/android-tutorial-5/res/layout/file_dialog_main.xml index c803522..3e33d06 100644 --- a/gst-sdk/tutorials/android-tutorial-5/res/layout/file_dialog_main.xml +++ b/gst-sdk/tutorials/android-tutorial-5/res/layout/file_dialog_main.xml @@ -1,66 +1,39 @@ <?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 diff --git a/gst-sdk/tutorials/android-tutorial-5/res/layout/file_dialog_row.xml b/gst-sdk/tutorials/android-tutorial-5/res/layout/file_dialog_row.xml index 18c8c62..6e52625 100644 --- a/gst-sdk/tutorials/android-tutorial-5/res/layout/file_dialog_row.xml +++ b/gst-sdk/tutorials/android-tutorial-5/res/layout/file_dialog_row.xml @@ -1,15 +1,23 @@ <?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 diff --git a/gst-sdk/tutorials/android-tutorial-5/res/values/strings.xml b/gst-sdk/tutorials/android-tutorial-5/res/values/strings.xml index 6907077..272fafa 100755 --- a/gst-sdk/tutorials/android-tutorial-5/res/values/strings.xml +++ b/gst-sdk/tutorials/android-tutorial-5/res/values/strings.xml @@ -4,13 +4,9 @@ <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> diff --git a/gst-sdk/tutorials/android-tutorial-5/src/com/gst_sdk_tutorials/tutorial_5/Tutorial5.java b/gst-sdk/tutorials/android-tutorial-5/src/com/gst_sdk_tutorials/tutorial_5/Tutorial5.java index 621e246..9243e34 100644 --- a/gst-sdk/tutorials/android-tutorial-5/src/com/gst_sdk_tutorials/tutorial_5/Tutorial5.java +++ b/gst-sdk/tutorials/android-tutorial-5/src/com/gst_sdk_tutorials/tutorial_5/Tutorial5.java @@ -1,19 +1,17 @@ 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; @@ -25,6 +23,7 @@ import android.widget.TextView; 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 @@ -48,6 +47,7 @@ public class Tutorial5 extends Activity implements SurfaceHolder.Callback, OnSee 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; @@ -68,6 +68,7 @@ public class Tutorial5 extends Activity implements SurfaceHolder.Callback, OnSee 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"); @@ -95,8 +96,7 @@ public class Tutorial5 extends Activity implements SurfaceHolder.Callback, OnSee 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); } }); @@ -299,6 +299,8 @@ public class Tutorial5 extends Activity implements SurfaceHolder.Callback, OnSee 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(); } } diff --git a/gst-sdk/tutorials/android-tutorial-5/src/com/lamerman/FileDialog.java b/gst-sdk/tutorials/android-tutorial-5/src/com/lamerman/FileDialog.java index 6f3a953..96ff132 100644 --- a/gst-sdk/tutorials/android-tutorial-5/src/com/lamerman/FileDialog.java +++ b/gst-sdk/tutorials/android-tutorial-5/src/com/lamerman/FileDialog.java @@ -1,4 +1,4 @@ -// 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. @@ -33,8 +33,6 @@ import java.util.HashMap; 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; @@ -42,14 +40,13 @@ import android.os.Bundle; 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. * @@ -89,39 +86,18 @@ public class FileDialog extends ListActivity { */ 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>(); @@ -136,9 +112,6 @@ public class FileDialog extends ListActivity { 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); @@ -153,58 +126,20 @@ public class FileDialog extends ListActivity { } }); - 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); @@ -334,20 +269,13 @@ public class FileDialog extends ListActivity { 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() { @@ -368,15 +296,10 @@ public class FileDialog extends ListActivity { 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; @@ -385,29 +308,4 @@ public class FileDialog extends ListActivity { } } - /** - * 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); - } } diff --git a/gst-sdk/tutorials/android-tutorial-5/src/com/lamerman/SelectionMode.java b/gst-sdk/tutorials/android-tutorial-5/src/com/lamerman/SelectionMode.java deleted file mode 100644 index d20d50c..0000000 --- a/gst-sdk/tutorials/android-tutorial-5/src/com/lamerman/SelectionMode.java +++ /dev/null @@ -1,34 +0,0 @@ -// 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; -} |