FreeRDP
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Modules Pages
ShortcutsActivity.java
1/*
2 Android Shortcut activity
3
4 Copyright 2013 Thincast Technologies GmbH, Author: Martin Fleisz
5
6 This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
7 If a copy of the MPL was not distributed with this file, You can obtain one at
8 http://mozilla.org/MPL/2.0/.
9*/
10
11package com.freerdp.freerdpcore.presentation;
12
13import android.app.AlertDialog;
14import android.app.ListActivity;
15import android.content.Context;
16import android.content.DialogInterface;
17import android.content.Intent;
18import android.net.Uri;
19import android.os.Bundle;
20import android.os.Parcelable;
21import android.view.View;
22import android.widget.AdapterView;
23import android.widget.EditText;
24import android.widget.TextView;
25
26import com.freerdp.freerdpcore.R;
27import com.freerdp.freerdpcore.application.GlobalApp;
28import com.freerdp.freerdpcore.domain.BookmarkBase;
29import com.freerdp.freerdpcore.services.SessionRequestHandlerActivity;
30import com.freerdp.freerdpcore.utils.BookmarkArrayAdapter;
31
32import java.util.ArrayList;
33
34public class ShortcutsActivity extends ListActivity
35{
36
37 public static final String TAG = "ShortcutsActivity";
38
39 @Override public void onCreate(Bundle savedInstanceState)
40 {
41
42 super.onCreate(savedInstanceState);
43
44 Intent intent = getIntent();
45 if (Intent.ACTION_CREATE_SHORTCUT.equals(intent.getAction()))
46 {
47 // set listeners for the list view
48 getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {
49 public void onItemClick(AdapterView<?> parent, View view, int position, long id)
50 {
51 String refStr = view.getTag().toString();
52 String defLabel =
53 ((TextView)(view.findViewById(R.id.bookmark_text1))).getText().toString();
54 setupShortcut(refStr, defLabel);
55 }
56 });
57 }
58 else
59 {
60 // just exit
61 finish();
62 }
63 }
64
65 @Override public void onResume()
66 {
67 super.onResume();
68 // create bookmark cursor adapter
69 ArrayList<BookmarkBase> bookmarks = GlobalApp.getManualBookmarkGateway().findAll();
70 BookmarkArrayAdapter bookmarkAdapter =
71 new BookmarkArrayAdapter(this, android.R.layout.simple_list_item_2, bookmarks);
72 getListView().setAdapter(bookmarkAdapter);
73 }
74
75 public void onPause()
76 {
77 super.onPause();
78 getListView().setAdapter(null);
79 }
80
109 private void setupShortcut(String strRef, String defaultLabel)
110 {
111 final String paramStrRef = strRef;
112 final String paramDefaultLabel = defaultLabel;
113 final Context paramContext = this;
114
115 // display edit dialog to the user so he can specify the shortcut name
116 final EditText input = new EditText(this);
117 input.setText(defaultLabel);
118
119 AlertDialog.Builder builder = new AlertDialog.Builder(this);
120 builder.setTitle(R.string.dlg_title_create_shortcut)
121 .setMessage(R.string.dlg_msg_create_shortcut)
122 .setView(input)
123 .setPositiveButton(
124 android.R.string.ok,
125 new DialogInterface.OnClickListener() {
126 @Override public void onClick(DialogInterface dialog, int which)
127 {
128 String label = input.getText().toString();
129 if (label.length() == 0)
130 label = paramDefaultLabel;
131
132 Intent shortcutIntent = new Intent(Intent.ACTION_VIEW);
133 shortcutIntent.setClassName(paramContext,
134 SessionRequestHandlerActivity.class.getName());
135 shortcutIntent.setData(Uri.parse(paramStrRef));
136
137 // Then, set up the container intent (the response to the caller)
138 Intent intent = new Intent();
139 intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
140 intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, label);
141 Parcelable iconResource = Intent.ShortcutIconResource.fromContext(
142 paramContext, R.drawable.icon_launcher_freerdp);
143 intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);
144
145 // Now, return the result to the launcher
146 setResult(RESULT_OK, intent);
147 finish();
148 }
149 })
150 .setNegativeButton(android.R.string.cancel,
151 new DialogInterface.OnClickListener() {
152 @Override public void onClick(DialogInterface dialog, int which)
153 {
154 dialog.dismiss();
155 }
156 })
157 .create()
158 .show();
159 }
160}