test spinner in DialogFragment

This commit is contained in:
matsuo 2016-10-24 02:07:33 +09:00 committed by AndyScherzinger
parent a568f73a1f
commit ad16d4a4f5
No known key found for this signature in database
GPG key ID: 6CADC7E3523C308B
2 changed files with 70 additions and 4 deletions

View file

@ -0,0 +1,54 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
ownCloud Android client application
Copyright (C) 2012 Bartek Przybylski
Copyright (C) 2015 ownCloud Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2,
as published by the Free Software Foundation.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="clip_horizontal"
android:orientation="vertical"
android:padding="@dimen/standard_padding">
<TextView
android:text="TextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView"
tools:text="filename"/>
<EditText
android:id="@+id/user_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textNoSuggestions|textCapSentences"/>
<TextView
android:text="TextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView2"
tools:text="filetype"/>
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/file_type"/>
</LinearLayout>

View file

@ -51,9 +51,11 @@ import android.view.View;
import android.view.WindowManager.LayoutParams; import android.view.WindowManager.LayoutParams;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener; import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ListView; import android.widget.ListView;
import android.widget.Spinner;
import android.widget.Toast; import android.widget.Toast;
import com.owncloud.android.MainApp; import com.owncloud.android.MainApp;
@ -312,22 +314,32 @@ public class ReceiveExternalFilesActivity extends FileActivity
private class DialogInputUploadFilename extends DialogFragment { private class DialogInputUploadFilename extends DialogFragment {
@Override @Override
public Dialog onCreateDialog(Bundle savedInstamParentnceState) { public Dialog onCreateDialog(Bundle savedInstamParentnceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(ReceiveExternalFilesActivity.this);
LayoutInflater layout = LayoutInflater.from(getBaseContext()); LayoutInflater layout = LayoutInflater.from(getBaseContext());
View view = layout.inflate(R.layout.edit_box_dialog, null); View view = layout.inflate(R.layout.upload_file_dialog, null);
final EditText userInput = (EditText) view.findViewById(R.id.user_input); final EditText userInput = (EditText) view.findViewById(R.id.user_input);
userInput.setText(mServerFilename + mTmpFileSuffix); userInput.setText(mServerFilename + mTmpFileSuffix);
userInput.requestFocus(); userInput.requestFocus();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getBaseContext(), android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
adapter.add("Snipet text file(.txt)");
adapter.add("Internet shortcut file(.url)");
final Spinner spinner = (Spinner) view.findViewById(R.id.file_type);
spinner.setAdapter(adapter);
spinner.setSelection(1, false);
AlertDialog.Builder builder = new AlertDialog.Builder(ReceiveExternalFilesActivity.this);
builder.setView(view); builder.setView(view);
builder.setTitle("Input upload filename"); builder.setTitle("Input upload filename and filetype");
builder.setMessage("file type is " + builder.setMessage("file type is " +
(mTmpFileSuffix.equals(TEXT_FILE_SUFFIX) ? "Snipet text file" : (mTmpFileSuffix.equals(TEXT_FILE_SUFFIX) ? "Snipet text file" :
mTmpFileSuffix.equals(URL_FILE_SUFFIX) ? "Internet shortcut file" : "?") + "(" + mTmpFileSuffix + ")"); mTmpFileSuffix.equals(URL_FILE_SUFFIX) ? "Internet shortcut file" : "?") + "(" + mTmpFileSuffix + ")");
builder.setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() { builder.setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) { public void onClick(DialogInterface dialog,int id) {
int n = spinner.getSelectedItemPosition();
// verify if file name has suffix // verify if file name has suffix
String filename = userInput.getText().toString(); String filename = userInput.getText().toString();
if (!filename.endsWith(mTmpFileSuffix)){ if (!filename.endsWith(mTmpFileSuffix)){