blob: 15f0aeafc69221bee13ba07a6828cb0da943a6a2 [file] [log] [blame]
Ben Murdocheecb4e62010-07-06 16:30:38 +01001/*
2 * Copyright (C) 2010 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
17package com.android.browser;
18
19import android.app.Activity;
20import android.content.ComponentName;
21import android.content.ContentResolver;
22import android.content.Intent;
23import android.content.res.Resources;
24import android.database.Cursor;
25import android.graphics.Bitmap;
26import android.graphics.drawable.BitmapDrawable;
27import android.net.ParseException;
28import android.net.Uri;
29import android.net.WebAddress;
30import android.os.Bundle;
31import android.os.Handler;
32import android.os.Message;
33import android.provider.Browser;
34import android.util.Log;
35import android.view.View;
36import android.view.Window;
37import android.widget.Button;
38import android.widget.CheckBox;
39import android.widget.EditText;
40import android.widget.TextView;
41import android.widget.Toast;
42
43import java.io.File;
44import java.io.FileOutputStream;
45import java.io.IOException;
46import java.net.URI;
47import java.net.URISyntaxException;
48import java.util.Date;
49
50public class SaveToHomescreenDialog extends Activity {
51
52 private EditText mTitle;
53 private String mUrl;
54 private Bitmap mFavicon;
55 private Bitmap mTouchIcon;
56
57 private View.OnClickListener mOk = new View.OnClickListener() {
58 public void onClick(View v) {
59 if (save()) {
60 finish();
61 }
62 }
63 };
64
65 private View.OnClickListener mCancel = new View.OnClickListener() {
66 public void onClick(View v) {
67 finish();
68 }
69 };
70
71 protected void onCreate(Bundle icicle) {
72 super.onCreate(icicle);
73 requestWindowFeature(Window.FEATURE_LEFT_ICON);
74 setContentView(R.layout.browser_add_bookmark_const_url);
75 setTitle(R.string.create_shortcut_bookmark);
76 getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON,
77 R.drawable.ic_list_bookmark);
78
79 String title = null;
80 String url = null;
81 Bundle map = getIntent().getExtras();
82 if (map != null) {
83 title = map.getString("title");
84 }
85
86 mUrl = map.getString("url");
87 mFavicon = (Bitmap)map.getParcelable("favicon");
88 mTouchIcon = (Bitmap)map.getParcelable("touchIcon");
89
90 Bitmap icon = BookmarkUtils.createIcon(this, mTouchIcon, mFavicon,
91 BookmarkUtils.BookmarkIconType.ICON_HOME_SHORTCUT);
92 getWindow().setFeatureDrawable(Window.FEATURE_LEFT_ICON, new BitmapDrawable(icon));
93
94 mTitle = (EditText) findViewById(R.id.title);
95 mTitle.setText(title);
96
97 Button okButton = (Button) findViewById(R.id.OK);
98 okButton.setOnClickListener(mOk);
99
100 Button cancelButton = (Button) findViewById(R.id.cancel);
101 cancelButton.setOnClickListener(mCancel);
102
103 if (!getWindow().getDecorView().isInTouchMode()) {
104 okButton.requestFocus();
105 }
106 }
107
108 /**
109 * Parse the data entered in the dialog and send an intent to create an
110 * icon on the homescreen.
111 */
112 private boolean save() {
113 String title = mTitle.getText().toString().trim();
114 String unfilteredUrl = BrowserActivity.fixUrl(mUrl);
115 if (title.length() == 0) {
116 mTitle.setError(getResources().getText(R.string.bookmark_needs_title));
117 return false;
118 }
119
120 String url = unfilteredUrl.trim();
121
122 sendBroadcast(BookmarkUtils.createAddToHomeIntent(this, url, title,
123 mTouchIcon, mFavicon));
124 setResult(RESULT_OK);
125 return true;
126 }
127}