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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
/*
* Copyright (C) 2010 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.browser;
import android.app.Activity;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Intent;
import android.content.res.Resources;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.net.ParseException;
import android.net.Uri;
import android.net.WebAddress;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.provider.Browser;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Date;
public class SaveToHomescreenDialog extends Activity {
private EditText mTitle;
private String mUrl;
private Bitmap mFavicon;
private Bitmap mTouchIcon;
private View.OnClickListener mOk = new View.OnClickListener() {
public void onClick(View v) {
if (save()) {
finish();
}
}
};
private View.OnClickListener mCancel = new View.OnClickListener() {
public void onClick(View v) {
finish();
}
};
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
requestWindowFeature(Window.FEATURE_LEFT_ICON);
setContentView(R.layout.browser_add_bookmark_const_url);
setTitle(R.string.create_shortcut_bookmark);
getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON,
R.drawable.ic_list_bookmark);
String title = null;
String url = null;
Bundle map = getIntent().getExtras();
if (map != null) {
title = map.getString("title");
}
mUrl = map.getString("url");
mFavicon = (Bitmap)map.getParcelable("favicon");
mTouchIcon = (Bitmap)map.getParcelable("touchIcon");
Bitmap icon = BookmarkUtils.createIcon(this, mTouchIcon, mFavicon,
BookmarkUtils.BookmarkIconType.ICON_HOME_SHORTCUT);
getWindow().setFeatureDrawable(Window.FEATURE_LEFT_ICON, new BitmapDrawable(icon));
mTitle = (EditText) findViewById(R.id.title);
mTitle.setText(title);
Button okButton = (Button) findViewById(R.id.OK);
okButton.setOnClickListener(mOk);
Button cancelButton = (Button) findViewById(R.id.cancel);
cancelButton.setOnClickListener(mCancel);
if (!getWindow().getDecorView().isInTouchMode()) {
okButton.requestFocus();
}
}
/**
* Parse the data entered in the dialog and send an intent to create an
* icon on the homescreen.
*/
private boolean save() {
String title = mTitle.getText().toString().trim();
String unfilteredUrl = BrowserActivity.fixUrl(mUrl);
if (title.length() == 0) {
mTitle.setError(getResources().getText(R.string.bookmark_needs_title));
return false;
}
String url = unfilteredUrl.trim();
sendBroadcast(BookmarkUtils.createAddToHomeIntent(this, url, title,
mTouchIcon, mFavicon));
setResult(RESULT_OK);
return true;
}
}
|