• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2007 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.example.codelab.rssexample;
18 
19 import android.app.Activity;
20 import android.content.Intent;
21 import android.view.View.OnClickListener;
22 import android.view.View;
23 import android.widget.Button;
24 import android.widget.TextView;
25 import android.text.TextUtils;
26 import android.os.Bundle;
27 
28 /*** Form to add a new RSS feed.
29  It is a dialog form,**/
30 public class AddRssItem extends Activity {
31 
32     // Button handler for Submit/Cancel.
33     // It is a dialog style form because it's declared as such
34     // in the manifest.
35     private OnClickListener mClickListener = new OnClickListener(){
36         public void onClick(View v){
37             if(v.getId() == R.id.submit){
38                 String title = ((TextView) findViewById(R.id.title_textbox)).getText().toString();
39                 String url = ((TextView) findViewById(R.id.url_textbox)).getText().toString();
40                 if(TextUtils.isEmpty(title) || TextUtils.isEmpty(url)){
41                     showAlert("Missing Values",
42                               "You must specify both a title and a URL value",
43                               "OK",
44                               null, false, null);
45                     return;
46                 }
47                 Intent res = new Intent("Accepted");
48                 res.putExtra(RssContentProvider.TITLE, title);
49                 res.putExtra(RssContentProvider.URL, url);
50                 res.putExtra(RssContentProvider.LAST_UPDATED, 0);
51                 res.putExtra(RssContentProvider.CONTENT, "<html><body><h2>Not updated yet.</h2></body></html>");
52                 setResult(RESULT_OK, res);
53             }
54             else
55                 setResult(RESULT_CANCELED, (new Intent()).setAction("Canceled" + v.getId()));
56 
57             finish();
58 
59         }
60     };
61 
62     @Override
onCreate(Bundle savedInstanceState)63     public void onCreate(Bundle savedInstanceState){
64         super.onCreate(savedInstanceState);
65         setContentView(R.layout.add_item);
66         setTitle(getString(R.string.add_item_label));
67 
68         Button btn = (Button) findViewById(R.id.cancel);
69         btn.setOnClickListener(mClickListener);
70 
71         btn = (Button) findViewById(R.id.submit);
72         btn.setOnClickListener(mClickListener);
73     }
74 
75 }
76