package net.x4a42.volksempfaenger.ui;

import net.x4a42.volksempfaenger.R;
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager.LayoutParams;
import android.widget.Button;
import android.widget.EditText;

public class AddSubscriptionActivity extends Activity implements
		OnClickListener {

	private EditText editTextUrl;
	private Button buttonAdd;
	private Button buttonCancel;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setTitle(R.string.title_add_subscription);
		setContentView(R.layout.add_subscription);

		LayoutParams params = getWindow().getAttributes();
		params.width = LayoutParams.MATCH_PARENT;
		getWindow().setAttributes(params);

		editTextUrl = (EditText) findViewById(R.id.edittext_url);
		buttonAdd = (Button) findViewById(R.id.button_add);
		buttonCancel = (Button) findViewById(R.id.button_cancel);

		buttonAdd.setOnClickListener(this);
		buttonCancel.setOnClickListener(this);
	}

	@Override
	public void onStart() {
		super.onStart();

		Uri data = getIntent().getData();
		if (data != null) {
			editTextUrl.setText(data.toString());
		}
	}

	@Override
	public void onResume() {
		super.onResume();
		ExternalStorageHelper.assertExternalStorageWritable(this);
	}

	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.button_add:
			subscribeToFeed();
			return;
		case R.id.button_cancel:
			finish();
			return;
		}
	}

	private void subscribeToFeed() {
		String feedUrl = editTextUrl.getText().toString();

		new AddFeedTask(getApplicationContext()).execute(feedUrl);
		finish();
	}
}

@@ -43,64 +43,199 @@
 ort 
-net.x4a42.volksempfaenger.R;%0Aimport android.app.Activity
+java.net.MalformedURLException;%0Aimport java.net.URL;%0A%0Aimport net.x4a42.volksempfaenger.R;%0Aimport android.app.Activity;%0Aimport android.content.ClipData;%0Aimport android.content.ClipboardManager
 ;%0Aim
@@ -1375,16 +1375,485 @@
 ing());%0A
+%09%09%7D else %7B%0A%09%09%09// see if there is a link in the clipboard%0A%09%09%09ClipboardManager cm = (ClipboardManager) getSystemService(Activity.CLIPBOARD_SERVICE);%0A%09%09%09ClipData clip = cm.getPrimaryClip();%0A%09%09%09if (clip != null) %7B%0A%09%09%09%09ClipData.Item item = clip.getItemAt(0);%0A%09%09%09%09if (item != null && item.getText() != null) %7B%0A%09%09%09%09%09try %7B%0A%09%09%09%09%09%09URL url = new URL(item.getText().toString());%0A%09%09%09%09%09%09editTextUrl.setText(url.toString());%0A%09%09%09%09%09%7D catch (MalformedURLException e) %7B%0A%09%09%09%09%09%7D%0A%09%09%09%09%7D%0A%09%09%09%7D%0A
 %09%09%7D%0A%09%7D%0A%0A

Insert URL from clipboard automatically into the textfield