summaryrefslogtreecommitdiff
path: root/src/de/blinkt/openvpn/FileSelectLayout.java
blob: 2eba95150d753bbfd46cae8820c029494c09658b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package de.blinkt.openvpn;

import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lamerman.FileDialog;
import com.lamerman.SelectionMode;

public class FileSelectLayout extends LinearLayout implements OnClickListener {

	private TextView mData;
	private Fragment mFragment;
	private int mTaskId;
	private Button mSelectButton;

	public FileSelectLayout( Context context,AttributeSet attrset) {
		super(context,attrset);
		inflate(getContext(), R.layout.file_select, this);
		
		TypedArray ta = context.obtainStyledAttributes(attrset,R.styleable.FileSelectLayout);
		
		String title = ta.getString(R.styleable.FileSelectLayout_title);
		
		TextView tview = (TextView) findViewById(R.id.file_title);
		tview.setText(title);
		
		mData = (TextView) findViewById(R.id.file_selected_item);
		mSelectButton = (Button) findViewById(R.id.file_select_button);
		mSelectButton.setOnClickListener(this);

	}

	public void setFragment(Fragment fragment, int i)
	{
		mTaskId = i;
		mFragment = fragment;
	}
	
	public void getCertificateFileDialog() {
		Intent startFC = new Intent(getContext(),FileDialog.class);
		startFC.putExtra(FileDialog.START_PATH, "/sdcard");
		startFC.putExtra(FileDialog.SELECTION_MODE, SelectionMode.MODE_OPEN);
		
		mFragment.startActivityForResult(startFC,mTaskId);
	}

	
	public String getData() {
		return mData.getText().toString();
	}

	public void setData(String data) {
		mData.setText(data);
		
	}

	@Override
	public void onClick(View v) {
		if(v == mSelectButton) {
			getCertificateFileDialog();
		}
	}

	
}