List of usage examples for android.content Intent EXTRA_SHORTCUT_ICON_RESOURCE
String EXTRA_SHORTCUT_ICON_RESOURCE
To view the source code for android.content Intent EXTRA_SHORTCUT_ICON_RESOURCE.
Click Source Link
From source file:de.baumann.hhsmoodle.data_bookmarks.Bookmarks_Fragment.java
public void setBookmarksList() { //display data final int layoutstyle = R.layout.list_item_notes; int[] xml_id = new int[] { R.id.textView_title_notes, R.id.textView_des_notes, R.id.textView_create_notes }; String[] column = new String[] { "bookmarks_title", "bookmarks_content", "bookmarks_creation" }; final Cursor row = db.fetchAllData(getActivity()); adapter = new SimpleCursorAdapter(getActivity(), layoutstyle, row, column, xml_id, 0) { @Override/*from ww w . ja v a 2s . c om*/ public View getView(final int position, View convertView, ViewGroup parent) { Cursor row = (Cursor) lv.getItemAtPosition(position); final String _id = row.getString(row.getColumnIndexOrThrow("_id")); final String bookmarks_title = row.getString(row.getColumnIndexOrThrow("bookmarks_title")); final String bookmarks_content = row.getString(row.getColumnIndexOrThrow("bookmarks_content")); final String bookmarks_icon = row.getString(row.getColumnIndexOrThrow("bookmarks_icon")); final String bookmarks_attachment = row .getString(row.getColumnIndexOrThrow("bookmarks_attachment")); final String bookmarks_creation = row.getString(row.getColumnIndexOrThrow("bookmarks_creation")); View v = super.getView(position, convertView, parent); ImageView iv_icon = (ImageView) v.findViewById(R.id.icon_notes); final ImageView iv_attachment = (ImageView) v.findViewById(R.id.att_notes); switch (bookmarks_icon) { case "01": iv_icon.setImageResource(R.drawable.circle_red); break; case "02": iv_icon.setImageResource(R.drawable.circle_yellow); break; case "03": iv_icon.setImageResource(R.drawable.circle_green); break; case "04": iv_icon.setImageResource(R.drawable.ic_school_grey600_48dp); break; case "05": iv_icon.setImageResource(R.drawable.ic_view_dashboard_grey600_48dp); break; case "06": iv_icon.setImageResource(R.drawable.ic_face_profile_grey600_48dp); break; case "07": iv_icon.setImageResource(R.drawable.ic_calendar_grey600_48dp); break; case "08": iv_icon.setImageResource(R.drawable.ic_chart_areaspline_grey600_48dp); break; case "09": iv_icon.setImageResource(R.drawable.ic_bell_grey600_48dp); break; case "10": iv_icon.setImageResource(R.drawable.ic_settings_grey600_48dp); break; case "11": iv_icon.setImageResource(R.drawable.ic_web_grey600_48dp); break; case "12": iv_icon.setImageResource(R.drawable.ic_magnify_grey600_48dp); break; case "13": iv_icon.setImageResource(R.drawable.ic_pencil_grey600_48dp); break; case "14": iv_icon.setImageResource(R.drawable.ic_check_grey600_48dp); break; case "15": iv_icon.setImageResource(R.drawable.ic_clock_grey600_48dp); break; case "16": iv_icon.setImageResource(R.drawable.ic_bookmark_grey600_48dp); break; } switch (bookmarks_attachment) { case "": iv_attachment.setVisibility(View.VISIBLE); iv_attachment.setImageResource(R.drawable.star_outline); break; default: iv_attachment.setVisibility(View.VISIBLE); iv_attachment.setImageResource(R.drawable.star_grey); break; } iv_attachment.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { if (bookmarks_attachment.equals("")) { if (db.isExistFav("true")) { Snackbar.make(lv, R.string.bookmark_setFav_not, Snackbar.LENGTH_LONG).show(); } else { iv_attachment.setImageResource(R.drawable.star_grey); db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content, bookmarks_icon, "true", bookmarks_creation); setBookmarksList(); sharedPref.edit().putString("favoriteURL", bookmarks_content) .putString("favoriteTitle", bookmarks_title).apply(); Snackbar.make(lv, R.string.bookmark_setFav, Snackbar.LENGTH_LONG).show(); } } else { iv_attachment.setImageResource(R.drawable.star_outline); db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content, bookmarks_icon, "", bookmarks_creation); setBookmarksList(); } } }); iv_icon.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { final helper_main.Item[] items = { new helper_main.Item(getString(R.string.note_priority_2), R.drawable.circle_red), new helper_main.Item(getString(R.string.note_priority_1), R.drawable.circle_yellow), new helper_main.Item(getString(R.string.note_priority_0), R.drawable.circle_green), new helper_main.Item(getString(R.string.text_tit_11), R.drawable.ic_school_grey600_48dp), new helper_main.Item(getString(R.string.text_tit_1), R.drawable.ic_view_dashboard_grey600_48dp), new helper_main.Item(getString(R.string.text_tit_2), R.drawable.ic_face_profile_grey600_48dp), new helper_main.Item(getString(R.string.text_tit_8), R.drawable.ic_calendar_grey600_48dp), new helper_main.Item(getString(R.string.text_tit_3), R.drawable.ic_chart_areaspline_grey600_48dp), new helper_main.Item(getString(R.string.text_tit_4), R.drawable.ic_bell_grey600_48dp), new helper_main.Item(getString(R.string.text_tit_5), R.drawable.ic_settings_grey600_48dp), new helper_main.Item(getString(R.string.text_tit_6), R.drawable.ic_web_grey600_48dp), new helper_main.Item(getString(R.string.text_tit_7), R.drawable.ic_magnify_grey600_48dp), new helper_main.Item(getString(R.string.title_notes), R.drawable.ic_pencil_grey600_48dp), new helper_main.Item(getString(R.string.text_tit_9), R.drawable.ic_check_grey600_48dp), new helper_main.Item(getString(R.string.text_tit_10), R.drawable.ic_clock_grey600_48dp), new helper_main.Item(getString(R.string.title_bookmarks), R.drawable.ic_bookmark_grey600_48dp), }; ListAdapter adapter = new ArrayAdapter<helper_main.Item>(getActivity(), android.R.layout.select_dialog_item, android.R.id.text1, items) { @NonNull public View getView(int position, View convertView, @NonNull ViewGroup parent) { //Use super class to create the View View v = super.getView(position, convertView, parent); TextView tv = (TextView) v.findViewById(android.R.id.text1); tv.setTextSize(18); tv.setCompoundDrawablesWithIntrinsicBounds(items[position].icon, 0, 0, 0); //Add margin between image and text (support various screen densities) int dp5 = (int) (24 * getResources().getDisplayMetrics().density + 0.5f); tv.setCompoundDrawablePadding(dp5); return v; } }; new AlertDialog.Builder(getActivity()) .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }).setAdapter(adapter, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { if (item == 0) { db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content, "01", bookmarks_attachment, bookmarks_creation); setBookmarksList(); } else if (item == 1) { db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content, "02", bookmarks_attachment, bookmarks_creation); setBookmarksList(); } else if (item == 2) { db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content, "03", bookmarks_attachment, bookmarks_creation); setBookmarksList(); } else if (item == 3) { db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content, "04", bookmarks_attachment, bookmarks_creation); setBookmarksList(); } else if (item == 4) { db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content, "05", bookmarks_attachment, bookmarks_creation); setBookmarksList(); } else if (item == 5) { db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content, "06", bookmarks_attachment, bookmarks_creation); setBookmarksList(); } else if (item == 6) { db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content, "07", bookmarks_attachment, bookmarks_creation); setBookmarksList(); } else if (item == 7) { db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content, "08", bookmarks_attachment, bookmarks_creation); setBookmarksList(); } else if (item == 8) { db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content, "09", bookmarks_attachment, bookmarks_creation); setBookmarksList(); } else if (item == 9) { db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content, "10", bookmarks_attachment, bookmarks_creation); setBookmarksList(); } else if (item == 10) { db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content, "11", bookmarks_attachment, bookmarks_creation); setBookmarksList(); } else if (item == 11) { db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content, "12", bookmarks_attachment, bookmarks_creation); setBookmarksList(); } else if (item == 12) { db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content, "13", bookmarks_attachment, bookmarks_creation); setBookmarksList(); } else if (item == 13) { db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content, "14", bookmarks_attachment, bookmarks_creation); setBookmarksList(); } else if (item == 14) { db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content, "15", bookmarks_attachment, bookmarks_creation); setBookmarksList(); } else if (item == 15) { db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content, "16", bookmarks_attachment, bookmarks_creation); setBookmarksList(); } } }).show(); } }); return v; } }; //display data by filter final String note_search = sharedPref.getString("filter_bookmarksBY", "bookmarks_title"); sharedPref.edit().putString("filter_bookmarksBY", "bookmarks_title").apply(); filter.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) { } public void beforeTextChanged(CharSequence s, int start, int count, int after) { } public void onTextChanged(CharSequence s, int start, int before, int count) { adapter.getFilter().filter(s.toString()); } }); adapter.setFilterQueryProvider(new FilterQueryProvider() { public Cursor runQuery(CharSequence constraint) { return db.fetchDataByFilter(constraint.toString(), note_search); } }); lv.setAdapter(adapter); //onClick function lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterview, View view, int position, long id) { Cursor row2 = (Cursor) lv.getItemAtPosition(position); final String bookmarks_content = row2.getString(row2.getColumnIndexOrThrow("bookmarks_content")); sharedPref.edit().putString("load_next", "true").apply(); sharedPref.edit().putString("loadURL", bookmarks_content).apply(); ViewPager viewPager = (ViewPager) getActivity().findViewById(R.id.viewpager); viewPager.setCurrentItem(0); } }); lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { Cursor row2 = (Cursor) lv.getItemAtPosition(position); final String _id = row2.getString(row2.getColumnIndexOrThrow("_id")); final String bookmarks_title = row2.getString(row2.getColumnIndexOrThrow("bookmarks_title")); final String bookmarks_content = row2.getString(row2.getColumnIndexOrThrow("bookmarks_content")); final String bookmarks_icon = row2.getString(row2.getColumnIndexOrThrow("bookmarks_icon")); final String bookmarks_attachment = row2 .getString(row2.getColumnIndexOrThrow("bookmarks_attachment")); final String bookmarks_creation = row2.getString(row2.getColumnIndexOrThrow("bookmarks_creation")); final CharSequence[] options = { getString(R.string.number_edit_entry), getString(R.string.bookmark_remove_bookmark), getString(R.string.todo_menu), getString(R.string.bookmark_createNote), getString(R.string.count_create), getString(R.string.bookmark_createShortcut), getString(R.string.bookmark_createEvent) }; new AlertDialog.Builder(getActivity()) .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }).setItems(options, new DialogInterface.OnClickListener() { @SuppressWarnings("ConstantConditions") @Override public void onClick(DialogInterface dialog, int item) { if (options[item].equals(getString(R.string.number_edit_entry))) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); View dialogView = View.inflate(getActivity(), R.layout.dialog_edit_title, null); final EditText edit_title = (EditText) dialogView.findViewById(R.id.pass_title); edit_title.setHint(R.string.bookmark_edit_title); edit_title.setText(bookmarks_title); builder.setView(dialogView); builder.setTitle(R.string.bookmark_edit_title); builder.setPositiveButton(R.string.toast_yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String inputTag = edit_title.getText().toString().trim(); db.update(Integer.parseInt(_id), inputTag, bookmarks_content, bookmarks_icon, bookmarks_attachment, bookmarks_creation); setBookmarksList(); Snackbar.make(lv, R.string.bookmark_added, Snackbar.LENGTH_SHORT).show(); } }); builder.setNegativeButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }); final AlertDialog dialog2 = builder.create(); // Display the custom alert dialog on interface dialog2.show(); helper_main.showKeyboard(getActivity(), edit_title); } if (options[item].equals(getString(R.string.todo_menu))) { Todo_helper.newTodo(getActivity(), bookmarks_title, "", ""); } if (options[item].equals(getString(R.string.count_create))) { Count_helper.newCount(getActivity(), bookmarks_title, bookmarks_content, getActivity().getString(R.string.note_content), false); } if (options[item].equals(getString(R.string.bookmark_createEvent))) { helper_main.createCalendarEvent(getActivity(), bookmarks_title, bookmarks_content); } if (options[item].equals(getString(R.string.bookmark_remove_bookmark))) { Snackbar snackbar = Snackbar .make(lv, R.string.note_remove_confirmation, Snackbar.LENGTH_LONG) .setAction(R.string.toast_yes, new View.OnClickListener() { @Override public void onClick(View view) { db.delete(Integer.parseInt(_id)); setBookmarksList(); } }); snackbar.show(); } if (options[item].equals(getString(R.string.bookmark_createNote))) { Notes_helper.newNote(getActivity(), bookmarks_title, bookmarks_content, "", "", "", ""); } if (options[item].equals(getString(R.string.bookmark_createShortcut))) { Intent i = new Intent(); i.setAction(Intent.ACTION_VIEW); i.setData(Uri.parse(bookmarks_content)); Intent shortcut = new Intent(); shortcut.putExtra("android.intent.extra.shortcut.INTENT", i); shortcut.putExtra("android.intent.extra.shortcut.NAME", "THE NAME OF SHORTCUT TO BE SHOWN"); shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, bookmarks_title); shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext( getActivity().getApplicationContext(), R.mipmap.ic_launcher)); shortcut.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); getActivity().sendBroadcast(shortcut); Snackbar.make(lv, R.string.toast_shortcut, Snackbar.LENGTH_LONG).show(); } } }).show(); return true; } }); }
From source file:nl.mpcjanssen.simpletask.AddTask.java
private void setupShortcut() { Intent shortcutIntent = new Intent(Intent.ACTION_MAIN); shortcutIntent.setClassName(this, this.getClass().getName()); Intent intent = new Intent(); intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.shortcut_addtask_name)); Parcelable iconResource = Intent.ShortcutIconResource.fromContext(this, R.drawable.ic_launcher); intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource); setResult(RESULT_OK, intent);/*from ww w. j a v a 2 s . c om*/ }
From source file:kr.wdream.storyshop.AndroidUtilities.java
private static Intent createShortcutIntent(long did, boolean forDelete) { Intent shortcutIntent = new Intent(ApplicationLoader.applicationContext, OpenChatReceiver.class); int lower_id = (int) did; int high_id = (int) (did >> 32); TLRPC.User user = null;/*from w ww .j ava 2 s . c om*/ TLRPC.Chat chat = null; if (lower_id == 0) { shortcutIntent.putExtra("encId", high_id); TLRPC.EncryptedChat encryptedChat = MessagesController.getInstance().getEncryptedChat(high_id); if (encryptedChat == null) { return null; } user = MessagesController.getInstance().getUser(encryptedChat.user_id); } else if (lower_id > 0) { shortcutIntent.putExtra("userId", lower_id); user = MessagesController.getInstance().getUser(lower_id); } else if (lower_id < 0) { chat = MessagesController.getInstance().getChat(-lower_id); shortcutIntent.putExtra("chatId", -lower_id); } else { return null; } if (user == null && chat == null) { return null; } String name; TLRPC.FileLocation photo = null; if (user != null) { name = ContactsController.formatName(user.first_name, user.last_name); if (user.photo != null) { photo = user.photo.photo_small; } } else { name = chat.title; if (chat.photo != null) { photo = chat.photo.photo_small; } } shortcutIntent.setAction("com.tmessages.openchat" + did); shortcutIntent.addFlags(0x4000000); Intent addIntent = new Intent(); addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name); addIntent.putExtra("duplicate", false); if (!forDelete) { Bitmap bitmap = null; if (photo != null) { try { File path = FileLoader.getPathToAttach(photo, true); bitmap = BitmapFactory.decodeFile(path.toString()); if (bitmap != null) { int size = AndroidUtilities.dp(58); Bitmap result = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); result.eraseColor(Color.TRANSPARENT); Canvas canvas = new Canvas(result); BitmapShader shader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); if (roundPaint == null) { roundPaint = new Paint(Paint.ANTI_ALIAS_FLAG); bitmapRect = new RectF(); } float scale = size / (float) bitmap.getWidth(); canvas.save(); canvas.scale(scale, scale); roundPaint.setShader(shader); bitmapRect.set(0, 0, bitmap.getWidth(), bitmap.getHeight()); canvas.drawRoundRect(bitmapRect, bitmap.getWidth(), bitmap.getHeight(), roundPaint); canvas.restore(); Drawable drawable = ApplicationLoader.applicationContext.getResources() .getDrawable(R.drawable.book_logo); int w = AndroidUtilities.dp(15); int left = size - w - AndroidUtilities.dp(2); int top = size - w - AndroidUtilities.dp(2); drawable.setBounds(left, top, left + w, top + w); drawable.draw(canvas); try { canvas.setBitmap(null); } catch (Exception e) { //don't promt, this will crash on 2.x } bitmap = result; } } catch (Throwable e) { FileLog.e("tmessages", e); } } if (bitmap != null) { addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, bitmap); } else { if (user != null) { if (user.bot) { addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource .fromContext(ApplicationLoader.applicationContext, R.drawable.book_bot)); } else { addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource .fromContext(ApplicationLoader.applicationContext, R.drawable.book_user)); } } else if (chat != null) { if (ChatObject.isChannel(chat) && !chat.megagroup) { addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource .fromContext(ApplicationLoader.applicationContext, R.drawable.book_channel)); } else { addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource .fromContext(ApplicationLoader.applicationContext, R.drawable.book_group)); } } } } return addIntent; }
From source file:com.ferdi2005.secondgram.AndroidUtilities.java
private static Intent createShortcutIntent(long did, boolean forDelete) { Intent shortcutIntent = new Intent(ApplicationLoader.applicationContext, OpenChatReceiver.class); int lower_id = (int) did; int high_id = (int) (did >> 32); TLRPC.User user = null;//www . java 2 s .c o m TLRPC.Chat chat = null; if (lower_id == 0) { shortcutIntent.putExtra("encId", high_id); TLRPC.EncryptedChat encryptedChat = MessagesController.getInstance().getEncryptedChat(high_id); if (encryptedChat == null) { return null; } user = MessagesController.getInstance().getUser(encryptedChat.user_id); } else if (lower_id > 0) { shortcutIntent.putExtra("userId", lower_id); user = MessagesController.getInstance().getUser(lower_id); } else if (lower_id < 0) { chat = MessagesController.getInstance().getChat(-lower_id); shortcutIntent.putExtra("chatId", -lower_id); } else { return null; } if (user == null && chat == null) { return null; } String name; TLRPC.FileLocation photo = null; if (user != null) { name = ContactsController.formatName(user.first_name, user.last_name); if (user.photo != null) { photo = user.photo.photo_small; } } else { name = chat.title; if (chat.photo != null) { photo = chat.photo.photo_small; } } shortcutIntent.setAction("com.tmessages.openchat" + did); shortcutIntent.addFlags(0x4000000); Intent addIntent = new Intent(); addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name); addIntent.putExtra("duplicate", false); if (!forDelete) { Bitmap bitmap = null; if (photo != null) { try { File path = FileLoader.getPathToAttach(photo, true); bitmap = BitmapFactory.decodeFile(path.toString()); if (bitmap != null) { int size = AndroidUtilities.dp(58); Bitmap result = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); result.eraseColor(Color.TRANSPARENT); Canvas canvas = new Canvas(result); BitmapShader shader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); if (roundPaint == null) { roundPaint = new Paint(Paint.ANTI_ALIAS_FLAG); bitmapRect = new RectF(); } float scale = size / (float) bitmap.getWidth(); canvas.save(); canvas.scale(scale, scale); roundPaint.setShader(shader); bitmapRect.set(0, 0, bitmap.getWidth(), bitmap.getHeight()); canvas.drawRoundRect(bitmapRect, bitmap.getWidth(), bitmap.getHeight(), roundPaint); canvas.restore(); Drawable drawable = ApplicationLoader.applicationContext.getResources() .getDrawable(R.drawable.book_logo); int w = AndroidUtilities.dp(15); int left = size - w - AndroidUtilities.dp(2); int top = size - w - AndroidUtilities.dp(2); drawable.setBounds(left, top, left + w, top + w); drawable.draw(canvas); try { canvas.setBitmap(null); } catch (Exception e) { //don't promt, this will crash on 2.x } bitmap = result; } } catch (Throwable e) { FileLog.e(e); } } if (bitmap != null) { addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, bitmap); } else { if (user != null) { if (user.bot) { addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource .fromContext(ApplicationLoader.applicationContext, R.drawable.book_bot)); } else { addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource .fromContext(ApplicationLoader.applicationContext, R.drawable.book_user)); } } else if (chat != null) { if (ChatObject.isChannel(chat) && !chat.megagroup) { addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource .fromContext(ApplicationLoader.applicationContext, R.drawable.book_channel)); } else { addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource .fromContext(ApplicationLoader.applicationContext, R.drawable.book_group)); } } } } return addIntent; }
From source file:nl.mpcjanssen.simpletask.Simpletask.java
public void createFilterShortcut(@NotNull ActiveFilter filter) { final Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT"); Intent target = new Intent(Constants.INTENT_START_FILTER); filter.saveInIntent(target);//w w w .j a v a 2s .c o m target.putExtra("name", filter.getName()); // Setup target intent for shortcut shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, target); // Set shortcut icon Intent.ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(this, R.drawable.ic_launcher); shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes); shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, filter.getName()); sendBroadcast(shortcut); }
From source file:de.baumann.browser.Browser_right.java
@SuppressLint("SetJavaScriptEnabled") @Override/*from w w w .ja va 2s .c o m*/ public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_search) { urlBar.setVisibility(View.GONE); editText.setVisibility(View.VISIBLE); helper_editText.showKeyboard(Browser_right.this, editText, 3, "", getString(R.string.app_search_hint)); } if (id == R.id.action_history) { helper_main.switchToActivity(Browser_right.this, Popup_history.class, "", false); } if (id == R.id.action_search_chooseWebsite) { helper_editText.editText_searchWeb(editText, Browser_right.this); } if (id == R.id.action_pass) { helper_main.switchToActivity(Browser_right.this, Popup_pass.class, "", false); sharedPref.edit().putString("pass_copy_url", mWebView.getUrl()).apply(); sharedPref.edit().putString("pass_copy_title", mWebView.getTitle()).apply(); } if (id == R.id.action_toggle) { sharedPref.edit().putString("started", "yes").apply(); if (Uri.parse(mWebView.getUrl()).getHost().length() == 0) { domain = getString(R.string.app_domain); } else { domain = Uri.parse(mWebView.getUrl()).getHost(); } final String whiteList = sharedPref.getString("whiteList", ""); AlertDialog.Builder builder = new AlertDialog.Builder(Browser_right.this); View dialogView = View.inflate(Browser_right.this, R.layout.dialog_toggle, null); Switch sw_java = (Switch) dialogView.findViewById(R.id.switch1); Switch sw_pictures = (Switch) dialogView.findViewById(R.id.switch2); Switch sw_location = (Switch) dialogView.findViewById(R.id.switch3); Switch sw_cookies = (Switch) dialogView.findViewById(R.id.switch4); final ImageButton whiteList_js = (ImageButton) dialogView.findViewById(R.id.imageButton_js); if (whiteList.contains(domain)) { whiteList_js.setImageResource(R.drawable.check_green); } else { whiteList_js.setImageResource(R.drawable.close_red); } if (sharedPref.getString("java_string", "True").equals(getString(R.string.app_yes))) { sw_java.setChecked(true); } else { sw_java.setChecked(false); } if (sharedPref.getString("pictures_string", "True").equals(getString(R.string.app_yes))) { sw_pictures.setChecked(true); } else { sw_pictures.setChecked(false); } if (sharedPref.getString("loc_string", "True").equals(getString(R.string.app_yes))) { sw_location.setChecked(true); } else { sw_location.setChecked(false); } if (sharedPref.getString("cookie_string", "True").equals(getString(R.string.app_yes))) { sw_cookies.setChecked(true); } else { sw_cookies.setChecked(false); } whiteList_js.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (whiteList.contains(domain)) { whiteList_js.setImageResource(R.drawable.close_red); String removed = whiteList.replaceAll(domain, ""); sharedPref.edit().putString("whiteList", removed).apply(); } else { whiteList_js.setImageResource(R.drawable.check_green); sharedPref.edit().putString("whiteList", whiteList + " " + domain).apply(); } } }); sw_java.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { sharedPref.edit().putString("java_string", getString(R.string.app_yes)).apply(); mWebView.getSettings().setJavaScriptEnabled(true); } else { sharedPref.edit().putString("java_string", getString(R.string.app_no)).apply(); mWebView.getSettings().setJavaScriptEnabled(false); } } }); sw_pictures.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { sharedPref.edit().putString("pictures_string", getString(R.string.app_yes)).apply(); mWebView.getSettings().setLoadsImagesAutomatically(true); } else { sharedPref.edit().putString("pictures_string", getString(R.string.app_no)).apply(); mWebView.getSettings().setLoadsImagesAutomatically(false); } } }); sw_location.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { sharedPref.edit().putString("loc_string", getString(R.string.app_yes)).apply(); mWebView.getSettings().setGeolocationEnabled(true); helper_main.grantPermissionsLoc(Browser_right.this); } else { sharedPref.edit().putString("loc_string", getString(R.string.app_no)).apply(); mWebView.getSettings().setGeolocationEnabled(false); } } }); sw_cookies.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { sharedPref.edit().putString("cookie_string", getString(R.string.app_yes)).apply(); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.setAcceptCookie(true); } else { sharedPref.edit().putString("cookie_string", getString(R.string.app_no)).apply(); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.setAcceptCookie(false); } } }); builder.setView(dialogView); builder.setTitle(R.string.menu_toggle_title); builder.setPositiveButton(R.string.toast_yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { mWebView.reload(); } }); builder.setNegativeButton(R.string.menu_settings, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { sharedPref.edit().putString("pass_copy_url", mWebView.getUrl()).apply(); sharedPref.edit().putString("lastActivity", "browser_right").apply(); helper_main.switchToActivity(Browser_right.this, Activity_settings.class, "", true); } }); final AlertDialog dialog = builder.create(); // Display the custom alert dialog on interface dialog.show(); } if (id == R.id.menu_save_screenshot) { screenshot(); } if (id == R.id.menu_save_bookmark) { urlBar.setVisibility(View.GONE); editText.setVisibility(View.VISIBLE); helper_editText.editText_saveBookmark(editText, Browser_right.this, mWebView); } if (id == R.id.menu_save_readLater) { DbAdapter_ReadLater db = new DbAdapter_ReadLater(Browser_right.this); db.open(); if (db.isExist(mWebView.getUrl())) { Snackbar.make(editText, getString(R.string.toast_newTitle), Snackbar.LENGTH_LONG).show(); } else { db.insert(helper_webView.getTitle(mWebView), mWebView.getUrl(), "", "", helper_main.createDate()); Snackbar.make(mWebView, R.string.bookmark_added, Snackbar.LENGTH_LONG).show(); } } if (id == R.id.menu_save_pass) { helper_editText.editText_savePass(Browser_right.this, mWebView, mWebView.getTitle(), mWebView.getUrl()); } if (id == R.id.menu_createShortcut) { Intent i = new Intent(); i.setAction(Intent.ACTION_VIEW); i.setClassName(Browser_right.this, "de.baumann.browser.Browser_left"); i.setData(Uri.parse(mWebView.getUrl())); Intent shortcut = new Intent(); shortcut.putExtra("android.intent.extra.shortcut.INTENT", i); shortcut.putExtra("android.intent.extra.shortcut.NAME", "THE NAME OF SHORTCUT TO BE SHOWN"); shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, mWebView.getTitle()); shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource .fromContext(Browser_right.this.getApplicationContext(), R.mipmap.ic_launcher)); shortcut.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); Browser_right.this.sendBroadcast(shortcut); Snackbar.make(mWebView, R.string.menu_createShortcut_success, Snackbar.LENGTH_SHORT).show(); } if (id == R.id.menu_share_screenshot) { Intent sharingIntent = new Intent(Intent.ACTION_SEND); sharingIntent.setType("image/png"); sharingIntent.putExtra(Intent.EXTRA_SUBJECT, mWebView.getTitle()); sharingIntent.putExtra(Intent.EXTRA_TEXT, mWebView.getUrl()); Uri bmpUri = Uri.fromFile(shareFile); sharingIntent.putExtra(Intent.EXTRA_STREAM, bmpUri); startActivity(Intent.createChooser(sharingIntent, (getString(R.string.app_share_screenshot)))); } if (id == R.id.menu_share_link) { Intent sharingIntent = new Intent(Intent.ACTION_SEND); sharingIntent.setType("text/plain"); sharingIntent.putExtra(Intent.EXTRA_SUBJECT, mWebView.getTitle()); sharingIntent.putExtra(Intent.EXTRA_TEXT, mWebView.getUrl()); startActivity(Intent.createChooser(sharingIntent, (getString(R.string.app_share_link)))); } if (id == R.id.menu_share_link_copy) { String url = mWebView.getUrl(); ClipboardManager clipboard = (ClipboardManager) Browser_right.this .getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setPrimaryClip(ClipData.newPlainText("text", url)); Snackbar.make(mWebView, R.string.context_linkCopy_toast, Snackbar.LENGTH_SHORT).show(); } if (id == R.id.action_downloads) { helper_main.switchToActivity(Browser_right.this, Popup_files.class, "", false); } if (id == R.id.action_search_go) { String text = editText.getText().toString(); helper_webView.openURL(Browser_right.this, mWebView, editText); helper_editText.hideKeyboard(Browser_right.this, editText, 0, text, getString(R.string.app_search_hint)); helper_editText.editText_EditorAction(editText, Browser_right.this, mWebView, urlBar); urlBar.setVisibility(View.VISIBLE); editText.setVisibility(View.GONE); } if (id == R.id.action_search_onSite) { urlBar.setVisibility(View.GONE); editText.setVisibility(View.VISIBLE); helper_editText.showKeyboard(Browser_right.this, editText, 1, "", getString(R.string.app_search_hint)); helper_editText.editText_FocusChange_searchSite(editText, Browser_right.this); helper_editText.editText_searchSite(editText, Browser_right.this, mWebView, urlBar); } if (id == R.id.action_search_onSite_go) { String text = editText.getText().toString(); if (text.startsWith(getString(R.string.app_search))) { helper_editText.editText_searchSite(editText, Browser_right.this, mWebView, urlBar); } else { mWebView.findAllAsync(text); helper_editText.hideKeyboard(Browser_right.this, editText, 1, getString(R.string.app_search) + " " + text, getString(R.string.app_search_hint_site)); } } if (id == R.id.action_prev) { mWebView.findNext(false); } if (id == R.id.action_next) { mWebView.findNext(true); } if (id == R.id.action_cancel) { urlBar.setVisibility(View.VISIBLE); urlBar.setText(mWebView.getTitle()); editText.setVisibility(View.GONE); helper_editText.editText_FocusChange(editText, Browser_right.this); helper_editText.editText_EditorAction(editText, Browser_right.this, mWebView, urlBar); helper_editText.hideKeyboard(Browser_right.this, editText, 0, mWebView.getTitle(), getString(R.string.app_search_hint)); } if (id == R.id.action_save_bookmark) { helper_editText.editText_saveBookmark_save(editText, Browser_right.this, mWebView); urlBar.setVisibility(View.VISIBLE); editText.setVisibility(View.GONE); } return super.onOptionsItemSelected(item); }
From source file:com.songcode.materialnotes.ui.NoteEditActivity.java
private void sendToDesktop() { /**/*from www. j a v a 2 s .c o m*/ * Before send message to home, we should make sure that current * editing note is exists in databases. So, for new note, firstly * save it */ if (!mWorkingNote.existInDatabase()) { saveNote(); } if (mWorkingNote.getNoteId() > 0) { Intent sender = new Intent(); Intent shortcutIntent = new Intent(this, NoteEditActivity.class); shortcutIntent.setAction(Intent.ACTION_VIEW); shortcutIntent.putExtra(Intent.EXTRA_UID, mWorkingNote.getNoteId()); sender.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); sender.putExtra(Intent.EXTRA_SHORTCUT_NAME, makeShortcutIconTitle(mWorkingNote.getContent())); sender.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(this, R.drawable.icon_app)); sender.putExtra("duplicate", true); sender.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); showToast(R.string.info_note_enter_desktop); sendBroadcast(sender); } else { /** * There is the condition that user has input nothing (the note is * not worthy saving), we have no note id, remind the user that he * should input something */ Log.e(TAG, "Send to desktop error"); showToast(R.string.error_note_empty_for_send_to_desktop); } }
From source file:de.baumann.browser.Browser_left.java
@SuppressLint("SetJavaScriptEnabled") @Override/*from w w w . java 2 s . c om*/ public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_search) { urlBar.setVisibility(View.GONE); editText.setVisibility(View.VISIBLE); helper_editText.showKeyboard(Browser_left.this, editText, 3, "", getString(R.string.app_search_hint)); } if (id == R.id.action_history) { helper_main.switchToActivity(Browser_left.this, Popup_history.class, "", false); } if (id == R.id.action_search_chooseWebsite) { helper_editText.editText_searchWeb(editText, Browser_left.this); } if (id == R.id.action_pass) { helper_main.switchToActivity(Browser_left.this, Popup_pass.class, "", false); sharedPref.edit().putString("pass_copy_url", mWebView.getUrl()).apply(); sharedPref.edit().putString("pass_copy_title", mWebView.getTitle()).apply(); } if (id == R.id.action_toggle) { sharedPref.edit().putString("started", "yes").apply(); if (Uri.parse(mWebView.getUrl()).getHost().length() == 0) { domain = getString(R.string.app_domain); } else { domain = Uri.parse(mWebView.getUrl()).getHost(); } final String whiteList = sharedPref.getString("whiteList", ""); AlertDialog.Builder builder = new AlertDialog.Builder(Browser_left.this); View dialogView = View.inflate(Browser_left.this, R.layout.dialog_toggle, null); Switch sw_java = (Switch) dialogView.findViewById(R.id.switch1); Switch sw_pictures = (Switch) dialogView.findViewById(R.id.switch2); Switch sw_location = (Switch) dialogView.findViewById(R.id.switch3); Switch sw_cookies = (Switch) dialogView.findViewById(R.id.switch4); final ImageButton whiteList_js = (ImageButton) dialogView.findViewById(R.id.imageButton_js); if (whiteList.contains(domain)) { whiteList_js.setImageResource(R.drawable.check_green); } else { whiteList_js.setImageResource(R.drawable.close_red); } if (sharedPref.getString("java_string", "True").equals(getString(R.string.app_yes))) { sw_java.setChecked(true); } else { sw_java.setChecked(false); } if (sharedPref.getString("pictures_string", "True").equals(getString(R.string.app_yes))) { sw_pictures.setChecked(true); } else { sw_pictures.setChecked(false); } if (sharedPref.getString("loc_string", "True").equals(getString(R.string.app_yes))) { sw_location.setChecked(true); } else { sw_location.setChecked(false); } if (sharedPref.getString("cookie_string", "True").equals(getString(R.string.app_yes))) { sw_cookies.setChecked(true); } else { sw_cookies.setChecked(false); } whiteList_js.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (whiteList.contains(domain)) { whiteList_js.setImageResource(R.drawable.close_red); String removed = whiteList.replaceAll(domain, ""); sharedPref.edit().putString("whiteList", removed).apply(); } else { whiteList_js.setImageResource(R.drawable.check_green); sharedPref.edit().putString("whiteList", whiteList + " " + domain).apply(); } } }); sw_java.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { sharedPref.edit().putString("java_string", getString(R.string.app_yes)).apply(); mWebView.getSettings().setJavaScriptEnabled(true); } else { sharedPref.edit().putString("java_string", getString(R.string.app_no)).apply(); mWebView.getSettings().setJavaScriptEnabled(false); } } }); sw_pictures.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { sharedPref.edit().putString("pictures_string", getString(R.string.app_yes)).apply(); mWebView.getSettings().setLoadsImagesAutomatically(true); } else { sharedPref.edit().putString("pictures_string", getString(R.string.app_no)).apply(); mWebView.getSettings().setLoadsImagesAutomatically(false); } } }); sw_location.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { sharedPref.edit().putString("loc_string", getString(R.string.app_yes)).apply(); mWebView.getSettings().setGeolocationEnabled(true); helper_main.grantPermissionsLoc(Browser_left.this); } else { sharedPref.edit().putString("loc_string", getString(R.string.app_no)).apply(); mWebView.getSettings().setGeolocationEnabled(false); } } }); sw_cookies.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { sharedPref.edit().putString("cookie_string", getString(R.string.app_yes)).apply(); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.setAcceptCookie(true); } else { sharedPref.edit().putString("cookie_string", getString(R.string.app_no)).apply(); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.setAcceptCookie(false); } } }); builder.setView(dialogView); builder.setTitle(R.string.menu_toggle_title); builder.setPositiveButton(R.string.toast_yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { mWebView.reload(); } }); builder.setNegativeButton(R.string.menu_settings, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { sharedPref.edit().putString("pass_copy_url", mWebView.getUrl()).apply(); sharedPref.edit().putString("lastActivity", "browser_left").apply(); helper_main.switchToActivity(Browser_left.this, Activity_settings.class, "", true); } }); final AlertDialog dialog = builder.create(); // Display the custom alert dialog on interface dialog.show(); } if (id == R.id.menu_save_screenshot) { screenshot(); } if (id == R.id.menu_save_bookmark) { urlBar.setVisibility(View.GONE); editText.setVisibility(View.VISIBLE); helper_editText.editText_saveBookmark(editText, Browser_left.this, mWebView); } if (id == R.id.menu_save_readLater) { DbAdapter_ReadLater db = new DbAdapter_ReadLater(Browser_left.this); db.open(); if (db.isExist(mWebView.getUrl())) { Snackbar.make(editText, getString(R.string.toast_newTitle), Snackbar.LENGTH_LONG).show(); } else { db.insert(helper_webView.getTitle(mWebView), mWebView.getUrl(), "", "", helper_main.createDate()); Snackbar.make(mWebView, R.string.bookmark_added, Snackbar.LENGTH_LONG).show(); } } if (id == R.id.menu_save_pass) { helper_editText.editText_savePass(Browser_left.this, mWebView, mWebView.getTitle(), mWebView.getUrl()); } if (id == R.id.menu_createShortcut) { Intent i = new Intent(); i.setAction(Intent.ACTION_VIEW); i.setClassName(Browser_left.this, "de.baumann.browser.Browser_left"); i.setData(Uri.parse(mWebView.getUrl())); Intent shortcut = new Intent(); shortcut.putExtra("android.intent.extra.shortcut.INTENT", i); shortcut.putExtra("android.intent.extra.shortcut.NAME", "THE NAME OF SHORTCUT TO BE SHOWN"); shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, mWebView.getTitle()); shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource .fromContext(Browser_left.this.getApplicationContext(), R.mipmap.ic_launcher)); shortcut.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); Browser_left.this.sendBroadcast(shortcut); Snackbar.make(mWebView, R.string.menu_createShortcut_success, Snackbar.LENGTH_SHORT).show(); } if (id == R.id.menu_share_screenshot) { Intent sharingIntent = new Intent(Intent.ACTION_SEND); sharingIntent.setType("image/png"); sharingIntent.putExtra(Intent.EXTRA_SUBJECT, mWebView.getTitle()); sharingIntent.putExtra(Intent.EXTRA_TEXT, mWebView.getUrl()); Uri bmpUri = Uri.fromFile(shareFile); sharingIntent.putExtra(Intent.EXTRA_STREAM, bmpUri); startActivity(Intent.createChooser(sharingIntent, (getString(R.string.app_share_screenshot)))); } if (id == R.id.menu_share_link) { Intent sharingIntent = new Intent(Intent.ACTION_SEND); sharingIntent.setType("text/plain"); sharingIntent.putExtra(Intent.EXTRA_SUBJECT, mWebView.getTitle()); sharingIntent.putExtra(Intent.EXTRA_TEXT, mWebView.getUrl()); startActivity(Intent.createChooser(sharingIntent, (getString(R.string.app_share_link)))); } if (id == R.id.menu_share_link_copy) { String url = mWebView.getUrl(); ClipboardManager clipboard = (ClipboardManager) Browser_left.this .getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setPrimaryClip(ClipData.newPlainText("text", url)); Snackbar.make(mWebView, R.string.context_linkCopy_toast, Snackbar.LENGTH_SHORT).show(); } if (id == R.id.action_downloads) { helper_main.switchToActivity(Browser_left.this, Popup_files.class, "", false); } if (id == R.id.action_search_go) { String text = editText.getText().toString(); helper_webView.openURL(Browser_left.this, mWebView, editText); helper_editText.hideKeyboard(Browser_left.this, editText, 0, text, getString(R.string.app_search_hint)); helper_editText.editText_EditorAction(editText, Browser_left.this, mWebView, urlBar); urlBar.setVisibility(View.VISIBLE); editText.setVisibility(View.GONE); } if (id == R.id.action_search_onSite) { urlBar.setVisibility(View.GONE); editText.setVisibility(View.VISIBLE); helper_editText.showKeyboard(Browser_left.this, editText, 1, "", getString(R.string.app_search_hint)); helper_editText.editText_FocusChange_searchSite(editText, Browser_left.this); helper_editText.editText_searchSite(editText, Browser_left.this, mWebView, urlBar); } if (id == R.id.action_search_onSite_go) { String text = editText.getText().toString(); if (text.startsWith(getString(R.string.app_search))) { helper_editText.editText_searchSite(editText, Browser_left.this, mWebView, urlBar); } else { mWebView.findAllAsync(text); helper_editText.hideKeyboard(Browser_left.this, editText, 1, getString(R.string.app_search) + " " + text, getString(R.string.app_search_hint_site)); } } if (id == R.id.action_prev) { mWebView.findNext(false); } if (id == R.id.action_next) { mWebView.findNext(true); } if (id == R.id.action_cancel) { urlBar.setVisibility(View.VISIBLE); urlBar.setText(mWebView.getTitle()); editText.setVisibility(View.GONE); helper_editText.editText_FocusChange(editText, Browser_left.this); helper_editText.editText_EditorAction(editText, Browser_left.this, mWebView, urlBar); helper_editText.hideKeyboard(Browser_left.this, editText, 0, mWebView.getTitle(), getString(R.string.app_search_hint)); } if (id == R.id.action_save_bookmark) { helper_editText.editText_saveBookmark_save(editText, Browser_left.this, mWebView); urlBar.setVisibility(View.VISIBLE); editText.setVisibility(View.GONE); } return super.onOptionsItemSelected(item); }
From source file:de.baumann.browser.Browser.java
@SuppressLint("SetJavaScriptEnabled") @Override// ww w . j a v a 2 s . co m public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_search) { mWebView.stopLoading(); String text = editText.getText().toString(); String searchEngine = sharedPref.getString("searchEngine", "https://startpage.com/do/search?query="); String wikiLang = sharedPref.getString("wikiLang", "en"); if (text.length() > 3) { subStr = text.substring(3); } if (text.equals(mWebView.getTitle()) || text.isEmpty()) { helper_editText.showKeyboard(Browser.this, editText, 3, "", getString(R.string.app_search_hint)); } else { helper_editText.hideKeyboard(Browser.this, editText, 0, text, getString(R.string.app_search_hint)); helper_editText.editText_EditorAction(editText, Browser.this, mWebView); if (text.startsWith("www")) { mWebView.loadUrl("http://" + text); } else if (text.contains("http")) { mWebView.loadUrl(text); } else if (text.contains(".w ")) { mWebView.loadUrl("https://" + wikiLang + ".wikipedia.org/wiki/Spezial:Suche?search=" + subStr); } else if (text.startsWith(".f ")) { mWebView.loadUrl("https://www.flickr.com/search/?advanced=1&license=2%2C3%2C4%2C5%2C6%2C9&text=" + subStr); } else if (text.startsWith(".m ")) { mWebView.loadUrl("https://metager.de/meta/meta.ger3?focus=web&eingabe=" + subStr); } else if (text.startsWith(".g ")) { mWebView.loadUrl("https://github.com/search?utf8=&q=" + subStr); } else if (text.startsWith(".s ")) { if (Locale.getDefault().getLanguage().contentEquals("de")) { mWebView.loadUrl( "https://startpage.com/do/search?query=" + subStr + "&lui=deutsch&l=deutsch"); } else { mWebView.loadUrl("https://startpage.com/do/search?query=" + subStr); } } else if (text.startsWith(".G ")) { if (Locale.getDefault().getLanguage().contentEquals("de")) { mWebView.loadUrl("https://www.google.de/search?&q=" + subStr); } else { mWebView.loadUrl("https://www.google.com/search?&q=" + subStr); } } else if (text.startsWith(".y ")) { if (Locale.getDefault().getLanguage().contentEquals("de")) { mWebView.loadUrl("https://www.youtube.com/results?hl=de&gl=DE&search_query=" + subStr); } else { mWebView.loadUrl("https://www.youtube.com/results?search_query=" + subStr); } } else if (text.startsWith(".d ")) { if (Locale.getDefault().getLanguage().contentEquals("de")) { mWebView.loadUrl("https://duckduckgo.com/?q=" + subStr + "&kl=de-de&kad=de_DE&k1=-1&kaj=m&kam=osm&kp=-1&kak=-1&kd=1&t=h_&ia=web"); } else { mWebView.loadUrl("https://duckduckgo.com/?q=" + subStr); } } else { if (searchEngine.contains("https://duckduckgo.com/?q=")) { if (Locale.getDefault().getLanguage().contentEquals("de")) { mWebView.loadUrl("https://duckduckgo.com/?q=" + text + "&kl=de-de&kad=de_DE&k1=-1&kaj=m&kam=osm&kp=-1&kak=-1&kd=1&t=h_&ia=web"); } else { mWebView.loadUrl("https://duckduckgo.com/?q=" + text); } } else if (searchEngine.contains("https://metager.de/meta/meta.ger3?focus=web&eingabe=")) { if (Locale.getDefault().getLanguage().contentEquals("de")) { mWebView.loadUrl("https://metager.de/meta/meta.ger3?focus=web&eingabe=" + text); } else { mWebView.loadUrl("https://metager.de/meta/meta.ger3?focus=web&eingabe=" + text + "&focus=web&encoding=utf8&lang=eng"); } } else if (searchEngine.contains("https://startpage.com/do/search?query=")) { if (Locale.getDefault().getLanguage().contentEquals("de")) { mWebView.loadUrl( "https://startpage.com/do/search?query=" + text + "&lui=deutsch&l=deutsch"); } else { mWebView.loadUrl("https://startpage.com/do/search?query=" + text); } } else { mWebView.loadUrl(searchEngine + text); } } } } if (id == R.id.action_history) { helper_main.switchToActivity(Browser.this, Popup_history.class, "", false); } if (id == R.id.action_search3) { helper_editText.editText_searchWeb(editText, Browser.this); } if (id == R.id.action_pass) { helper_main.switchToActivity(Browser.this, Popup_pass.class, "", false); sharedPref.edit().putString("pass_copy_url", mWebView.getUrl()).apply(); sharedPref.edit().putString("pass_copy_title", mWebView.getTitle()).apply(); } if (id == R.id.action_toggle) { sharedPref.edit().putString("started", "yes").apply(); String link = mWebView.getUrl(); int domainInt = link.indexOf("//") + 2; final String domain = link.substring(domainInt, link.indexOf('/', domainInt)); final String whiteList = sharedPref.getString("whiteList", ""); AlertDialog.Builder builder = new AlertDialog.Builder(Browser.this); View dialogView = View.inflate(Browser.this, R.layout.dialog_toggle, null); Switch sw_java = (Switch) dialogView.findViewById(R.id.switch1); Switch sw_pictures = (Switch) dialogView.findViewById(R.id.switch2); Switch sw_location = (Switch) dialogView.findViewById(R.id.switch3); Switch sw_cookies = (Switch) dialogView.findViewById(R.id.switch4); final ImageButton whiteList_js = (ImageButton) dialogView.findViewById(R.id.imageButton_js); if (whiteList.contains(domain)) { whiteList_js.setImageResource(R.drawable.check_green); } else { whiteList_js.setImageResource(R.drawable.close_red); } if (sharedPref.getString("java_string", "True").equals(getString(R.string.app_yes))) { sw_java.setChecked(true); } else { sw_java.setChecked(false); } if (sharedPref.getString("pictures_string", "True").equals(getString(R.string.app_yes))) { sw_pictures.setChecked(true); } else { sw_pictures.setChecked(false); } if (sharedPref.getString("loc_string", "True").equals(getString(R.string.app_yes))) { sw_location.setChecked(true); } else { sw_location.setChecked(false); } if (sharedPref.getString("cookie_string", "True").equals(getString(R.string.app_yes))) { sw_cookies.setChecked(true); } else { sw_cookies.setChecked(false); } whiteList_js.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (whiteList.contains(domain)) { whiteList_js.setImageResource(R.drawable.close_red); String removed = whiteList.replaceAll(domain, ""); sharedPref.edit().putString("whiteList", removed).apply(); } else { whiteList_js.setImageResource(R.drawable.check_green); sharedPref.edit().putString("whiteList", whiteList + " " + domain).apply(); } } }); sw_java.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { sharedPref.edit().putString("java_string", getString(R.string.app_yes)).apply(); mWebView.getSettings().setJavaScriptEnabled(true); } else { sharedPref.edit().putString("java_string", getString(R.string.app_no)).apply(); mWebView.getSettings().setJavaScriptEnabled(false); } } }); sw_pictures.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { sharedPref.edit().putString("pictures_string", getString(R.string.app_yes)).apply(); mWebView.getSettings().setLoadsImagesAutomatically(true); } else { sharedPref.edit().putString("pictures_string", getString(R.string.app_no)).apply(); mWebView.getSettings().setLoadsImagesAutomatically(false); } } }); sw_location.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { sharedPref.edit().putString("loc_string", getString(R.string.app_yes)).apply(); mWebView.getSettings().setGeolocationEnabled(true); helper_main.grantPermissionsLoc(Browser.this); } else { sharedPref.edit().putString("loc_string", getString(R.string.app_no)).apply(); mWebView.getSettings().setGeolocationEnabled(false); } } }); sw_cookies.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { sharedPref.edit().putString("cookie_string", getString(R.string.app_yes)).apply(); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.setAcceptCookie(true); } else { sharedPref.edit().putString("cookie_string", getString(R.string.app_no)).apply(); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.setAcceptCookie(false); } } }); builder.setView(dialogView); builder.setTitle(R.string.menu_toggle_title); builder.setPositiveButton(R.string.toast_yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { mWebView.reload(); } }); builder.setNegativeButton(R.string.menu_settings, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { sharedPref.edit().putString("pass_copy_url", mWebView.getUrl()).apply(); sharedPref.edit().putString("lastActivity", "browser").apply(); helper_main.switchToActivity(Browser.this, Activity_settings.class, "", true); } }); final AlertDialog dialog = builder.create(); // Display the custom alert dialog on interface dialog.show(); } if (id == R.id.action_save) { final CharSequence[] options = { getString(R.string.menu_save_screenshot), getString(R.string.menu_save_bookmark), getString(R.string.menu_save_readLater), getString(R.string.menu_save_pass), getString(R.string.menu_createShortcut) }; new AlertDialog.Builder(Browser.this) .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }).setItems(options, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { if (options[item].equals(getString(R.string.menu_save_bookmark))) { helper_editText.editText_saveBookmark(editText, Browser.this, mWebView); } if (options[item].equals(getString(R.string.menu_save_pass))) { helper_editText.editText_savePass(Browser.this, mWebView, mWebView.getTitle(), mWebView.getUrl()); } if (options[item].equals(getString(R.string.menu_save_readLater))) { try { final Database_ReadLater db = new Database_ReadLater(Browser.this); db.addBookmark(mWebView.getTitle(), mWebView.getUrl()); db.close(); Snackbar.make(mWebView, R.string.readLater_added, Snackbar.LENGTH_SHORT).show(); } catch (Exception e) { e.printStackTrace(); } } if (options[item].equals(getString(R.string.menu_save_screenshot))) { screenshot(); } if (options[item].equals(getString(R.string.menu_createShortcut))) { Intent i = new Intent(); i.setAction(Intent.ACTION_VIEW); i.setClassName(Browser.this, "de.baumann.browser.Browser"); i.setData(Uri.parse(mWebView.getUrl())); Intent shortcut = new Intent(); shortcut.putExtra("android.intent.extra.shortcut.INTENT", i); shortcut.putExtra("android.intent.extra.shortcut.NAME", "THE NAME OF SHORTCUT TO BE SHOWN"); shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, mWebView.getTitle()); shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource .fromContext(Browser.this.getApplicationContext(), R.mipmap.ic_launcher)); shortcut.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); Browser.this.sendBroadcast(shortcut); Snackbar.make(mWebView, R.string.menu_createShortcut_success, Snackbar.LENGTH_SHORT) .show(); } } }).show(); } if (id == R.id.action_share) { final CharSequence[] options = { getString(R.string.menu_share_screenshot), getString(R.string.menu_share_link), getString(R.string.menu_share_link_copy) }; new AlertDialog.Builder(Browser.this) .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }).setItems(options, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { if (options[item].equals(getString(R.string.menu_share_link))) { Intent sharingIntent = new Intent(Intent.ACTION_SEND); sharingIntent.setType("text/plain"); sharingIntent.putExtra(Intent.EXTRA_SUBJECT, mWebView.getTitle()); sharingIntent.putExtra(Intent.EXTRA_TEXT, mWebView.getUrl()); startActivity( Intent.createChooser(sharingIntent, (getString(R.string.app_share_link)))); } if (options[item].equals(getString(R.string.menu_share_screenshot))) { screenshot(); if (shareFile.exists()) { Intent sharingIntent = new Intent(Intent.ACTION_SEND); sharingIntent.setType("image/png"); sharingIntent.putExtra(Intent.EXTRA_SUBJECT, mWebView.getTitle()); sharingIntent.putExtra(Intent.EXTRA_TEXT, mWebView.getUrl()); Uri bmpUri = Uri.fromFile(shareFile); sharingIntent.putExtra(Intent.EXTRA_STREAM, bmpUri); startActivity(Intent.createChooser(sharingIntent, (getString(R.string.app_share_screenshot)))); } } if (options[item].equals(getString(R.string.menu_share_link_copy))) { String url = mWebView.getUrl(); ClipboardManager clipboard = (ClipboardManager) Browser.this .getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setPrimaryClip(ClipData.newPlainText("text", url)); Snackbar.make(mWebView, R.string.context_linkCopy_toast, Snackbar.LENGTH_SHORT) .show(); } } }).show(); } if (id == R.id.action_downloads) { String startDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) .getPath(); helper_main.openFilePicker(Browser.this, mWebView, startDir); } if (id == R.id.action_searchSite) { mWebView.stopLoading(); helper_editText.editText_FocusChange_searchSite(editText, Browser.this); helper_editText.editText_searchSite(editText, Browser.this, mWebView); } if (id == R.id.action_search2) { String text = editText.getText().toString(); if (text.startsWith(getString(R.string.app_search))) { helper_editText.editText_searchSite(editText, Browser.this, mWebView); } else { mWebView.findAllAsync(text); helper_editText.hideKeyboard(Browser.this, editText, 1, getString(R.string.app_search) + " " + text, getString(R.string.app_search_hint_site)); } } if (id == R.id.action_prev) { mWebView.findNext(false); } if (id == R.id.action_next) { mWebView.findNext(true); } if (id == R.id.action_cancel) { helper_editText.editText_FocusChange(editText, Browser.this); helper_editText.editText_EditorAction(editText, Browser.this, mWebView); helper_editText.hideKeyboard(Browser.this, editText, 0, mWebView.getTitle(), getString(R.string.app_search_hint)); } if (id == R.id.action_save_bookmark) { helper_editText.editText_saveBookmark_save(editText, Browser.this, mWebView); } return super.onOptionsItemSelected(item); }
From source file:com.amaze.filemanager.fragments.Main.java
private void addShortcut(Layoutelements path) { //Adding shortcut for MainActivity //on Home screen Intent shortcutIntent = new Intent(getActivity().getApplicationContext(), MainActivity.class); shortcutIntent.putExtra("path", path.getDesc()); shortcutIntent.setAction(Intent.ACTION_MAIN); shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); Intent addIntent = new Intent(); addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, new File(path.getDesc()).getName()); addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(getActivity(), R.mipmap.ic_launcher)); addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); getActivity().sendBroadcast(addIntent); }