Example usage for android.content Context CLIPBOARD_SERVICE

List of usage examples for android.content Context CLIPBOARD_SERVICE

Introduction

In this page you can find the example usage for android.content Context CLIPBOARD_SERVICE.

Prototype

String CLIPBOARD_SERVICE

To view the source code for android.content Context CLIPBOARD_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.content.ClipboardManager for accessing and modifying the contents of the global clipboard.

Usage

From source file:net.ustyugov.jtalk.activity.vcard.VCardActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        finish();/*from   w w  w  .j av  a  2s  .  c o  m*/
        break;
    case R.id.refresh:
        new LoadTask().execute();
        break;
    case R.id.copy:
        ClipData.Item clipItem = new ClipData.Item(jid);
        String[] mimes = { "text/plain" };
        ClipData copyData = new ClipData(jid, mimes, clipItem);
        android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService(
                Context.CLIPBOARD_SERVICE);
        clipboard.setPrimaryClip(copyData);
    }
    return true;
}

From source file:com.easemob.chatuidemo.activity.BaseChatActivity.java

private void setUpView() {
    iv_emoticons_normal.setOnClickListener(this);
    iv_emoticons_checked.setOnClickListener(this);
    // position = getIntent().getIntExtra("position", -1);
    clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
    manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    wakeLock = ((PowerManager) getSystemService(Context.POWER_SERVICE))
            .newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "demo");
    // ???/*  w w w .j a v a2s.co  m*/
    chatType = getIntent().getIntExtra("chatType", CHATTYPE_SINGLE);

    if (chatType == CHATTYPE_SINGLE) { // ??
        toChatUsername = getIntent().getStringExtra("userId");
        Map<String, RobotUser> robotMap = ((DemoHXSDKHelper) HXSDKHelper.getInstance()).getRobotList();
        if (robotMap != null && robotMap.containsKey(toChatUsername)) {
            isRobot = true;
            String nick = robotMap.get(toChatUsername).getNick();
            if (!TextUtils.isEmpty(nick)) {
                setName(nick);
            } else {
                setName(toChatUsername);
            }
        } else {
            setName(toChatUsername);
        }
    }

    onConversationInit();
    onListViewCreation();
}

From source file:com.dnielfe.manager.utils.SimpleUtils.java

public static void savetoClipBoard(final Context co, String dir1) {
    android.content.ClipboardManager clipboard = (android.content.ClipboardManager) co
            .getSystemService(Context.CLIPBOARD_SERVICE);
    android.content.ClipData clip = android.content.ClipData.newPlainText("Copied Text", dir1);
    clipboard.setPrimaryClip(clip);//from ww  w .j  av  a2s . co  m
    Toast.makeText(co, "'" + dir1 + "' " + co.getString(R.string.copiedtoclipboard), Toast.LENGTH_SHORT).show();
}

From source file:com.github.dfa.diaspora_android.ui.ContextMenuWebView.java

@Override
protected void onCreateContextMenu(ContextMenu menu) {
    super.onCreateContextMenu(menu);

    HitTestResult result = getHitTestResult();

    MenuItem.OnMenuItemClickListener handler = new MenuItem.OnMenuItemClickListener() {
        public boolean onMenuItemClick(MenuItem item) {
            HitTestResult result = getHitTestResult();
            String url = result.getExtra();
            switch (item.getItemId()) {
            //Save image to external memory
            case ID_SAVE_IMAGE: {
                boolean writeToStoragePermitted = true;
                if (android.os.Build.VERSION.SDK_INT >= 23) {
                    int hasWRITE_EXTERNAL_STORAGE = parentActivity
                            .checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE);
                    if (hasWRITE_EXTERNAL_STORAGE != PackageManager.PERMISSION_GRANTED) {
                        writeToStoragePermitted = false;
                        if (!parentActivity.shouldShowRequestPermissionRationale(
                                Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
                            new AlertDialog.Builder(parentActivity).setMessage(R.string.permissions_image)
                                    .setPositiveButton(context.getText(android.R.string.yes),
                                            new DialogInterface.OnClickListener() {
                                                @Override
                                                public void onClick(DialogInterface dialog, int which) {
                                                    if (android.os.Build.VERSION.SDK_INT >= 23)
                                                        parentActivity.requestPermissions(new String[] {
                                                                Manifest.permission.WRITE_EXTERNAL_STORAGE },
                                                                MainActivity.REQUEST_CODE__ACCESS_EXTERNAL_STORAGE);
                                                }
                                            })
                                    .setNegativeButton(context.getText(android.R.string.no), null).show();
                        }//from w w w . ja v  a 2s .c  om
                        parentActivity.requestPermissions(
                                new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE },
                                MainActivity.REQUEST_CODE__ACCESS_EXTERNAL_STORAGE);
                    }
                }
                if (writeToStoragePermitted) {
                    if (url != null) {
                        Uri source = Uri.parse(url);
                        DownloadManager.Request request = new DownloadManager.Request(source);
                        File destinationFile = new File(Environment.getExternalStorageDirectory()
                                + "/Pictures/Diaspora/" + System.currentTimeMillis() + ".png");
                        request.setDestinationUri(Uri.fromFile(destinationFile));
                        ((DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE)).enqueue(request);
                        Toast.makeText(context, context.getText(R.string.share__toast_saved_image_to_location)
                                + " " + destinationFile.getAbsolutePath(), Toast.LENGTH_LONG).show();
                    }
                }
            }
                break;

            case ID_SHARE_IMAGE:
                if (url != null) {
                    boolean writeToStoragePermitted = true;
                    if (android.os.Build.VERSION.SDK_INT >= 23) {
                        int hasWRITE_EXTERNAL_STORAGE = parentActivity
                                .checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE);
                        if (hasWRITE_EXTERNAL_STORAGE != PackageManager.PERMISSION_GRANTED) {
                            writeToStoragePermitted = false;
                            if (!parentActivity.shouldShowRequestPermissionRationale(
                                    Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
                                new AlertDialog.Builder(parentActivity).setMessage(R.string.permissions_image)
                                        .setPositiveButton(context.getText(android.R.string.yes),
                                                new DialogInterface.OnClickListener() {
                                                    @Override
                                                    public void onClick(DialogInterface dialog, int which) {
                                                        if (android.os.Build.VERSION.SDK_INT >= 23)
                                                            parentActivity.requestPermissions(new String[] {
                                                                    Manifest.permission.WRITE_EXTERNAL_STORAGE },
                                                                    MainActivity.REQUEST_CODE__ACCESS_EXTERNAL_STORAGE);
                                                    }
                                                })
                                        .setNegativeButton(context.getText(android.R.string.no), null).show();
                            } else {
                                parentActivity.requestPermissions(
                                        new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE },
                                        MainActivity.REQUEST_CODE__ACCESS_EXTERNAL_STORAGE);
                            }
                        }
                    }
                    if (writeToStoragePermitted) {
                        final Uri local = Uri.parse(Environment.getExternalStorageDirectory()
                                + "/Pictures/Diaspora/" + System.currentTimeMillis() + ".png");
                        new ImageDownloadTask(null, local.getPath()) {
                            @Override
                            protected void onPostExecute(Bitmap result) {
                                Uri myUri = Uri.fromFile(new File(local.getPath()));
                                Intent sharingIntent = new Intent();
                                sharingIntent.setAction(Intent.ACTION_SEND);
                                sharingIntent.putExtra(Intent.EXTRA_STREAM, myUri);
                                sharingIntent.setType("image/png");
                                sharingIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                                context.startActivity(Intent.createChooser(sharingIntent,
                                        getResources().getString(R.string.action_share_dotdotdot)));
                            }
                        }.execute(url);
                    }
                } else {
                    Toast.makeText(context, "Cannot share image: url is null", Toast.LENGTH_SHORT).show();
                }

                break;

            case ID_IMAGE_EXTERNAL_BROWSER:
                if (url != null) {
                    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                    context.startActivity(intent);
                }
                break;

            //Copy url to clipboard
            case ID_COPY_LINK:
                if (url != null) {
                    ClipboardManager clipboard = (ClipboardManager) context
                            .getSystemService(Context.CLIPBOARD_SERVICE);
                    clipboard.setPrimaryClip(ClipData.newPlainText("text", url));
                    Toast.makeText(context, R.string.share__toast_link_address_copied, Toast.LENGTH_SHORT)
                            .show();
                }
                break;

            //Try to share link to other apps
            case ID_SHARE_LINK:
                if (url != null) {
                    Intent sendIntent = new Intent();
                    sendIntent.setAction(Intent.ACTION_SEND);
                    sendIntent.putExtra(Intent.EXTRA_TEXT, url);
                    sendIntent.setType("text/plain");
                    context.startActivity(Intent.createChooser(sendIntent,
                            getResources().getText(R.string.context_menu_share_link)));
                }
                break;
            }
            return true;
        }
    };

    //Build context menu
    if (result.getType() == HitTestResult.IMAGE_TYPE
            || result.getType() == HitTestResult.SRC_IMAGE_ANCHOR_TYPE) {
        // Menu options for an image.
        menu.setHeaderTitle(result.getExtra());
        menu.add(0, ID_SAVE_IMAGE, 0, context.getString(R.string.context_menu_save_image))
                .setOnMenuItemClickListener(handler);
        menu.add(0, ID_IMAGE_EXTERNAL_BROWSER, 0,
                context.getString(R.string.context_menu_open_external_browser))
                .setOnMenuItemClickListener(handler);
        menu.add(0, ID_SHARE_IMAGE, 0, context.getString(R.string.context_menu_share_image))
                .setOnMenuItemClickListener(handler);
    } else if (result.getType() == HitTestResult.ANCHOR_TYPE
            || result.getType() == HitTestResult.SRC_ANCHOR_TYPE) {
        // Menu options for a hyperlink.
        menu.setHeaderTitle(result.getExtra());
        menu.add(0, ID_COPY_LINK, 0, context.getString(R.string.context_menu_copy_link))
                .setOnMenuItemClickListener(handler);
        menu.add(0, ID_SHARE_LINK, 0, context.getString(R.string.context_menu_share_link))
                .setOnMenuItemClickListener(handler);
    }
}

From source file:com.github.dfa.diaspora_android.web.ContextMenuWebView.java

@Override
protected void onCreateContextMenu(ContextMenu menu) {
    super.onCreateContextMenu(menu);

    HitTestResult result = getHitTestResult();

    MenuItem.OnMenuItemClickListener handler = new MenuItem.OnMenuItemClickListener() {
        public boolean onMenuItemClick(MenuItem item) {
            HitTestResult result = getHitTestResult();
            String url = result.getExtra();
            switch (item.getItemId()) {
            //Save image to external memory
            case ID_SAVE_IMAGE: {
                boolean writeToStoragePermitted = true;
                if (android.os.Build.VERSION.SDK_INT >= 23) {
                    int hasWRITE_EXTERNAL_STORAGE = parentActivity
                            .checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE);
                    if (hasWRITE_EXTERNAL_STORAGE != PackageManager.PERMISSION_GRANTED) {
                        writeToStoragePermitted = false;
                        if (!parentActivity.shouldShowRequestPermissionRationale(
                                Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
                            new AlertDialog.Builder(parentActivity).setMessage(R.string.permissions_image)
                                    .setPositiveButton(context.getText(android.R.string.yes),
                                            new DialogInterface.OnClickListener() {
                                                @Override
                                                public void onClick(DialogInterface dialog, int which) {
                                                    if (android.os.Build.VERSION.SDK_INT >= 23)
                                                        parentActivity.requestPermissions(new String[] {
                                                                Manifest.permission.WRITE_EXTERNAL_STORAGE },
                                                                MainActivity.REQUEST_CODE__ACCESS_EXTERNAL_STORAGE);
                                                }
                                            })
                                    .setNegativeButton(context.getText(android.R.string.no), null).show();
                        }//  ww w.  j a v  a  2s . c o m
                        parentActivity.requestPermissions(
                                new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE },
                                MainActivity.REQUEST_CODE__ACCESS_EXTERNAL_STORAGE);
                    }
                }
                if (writeToStoragePermitted) {
                    if (url != null) {
                        Uri source = Uri.parse(url);
                        DownloadManager.Request request = new DownloadManager.Request(source);
                        File destinationFile = new File(Environment.getExternalStorageDirectory()
                                + "/Pictures/Diaspora/" + System.currentTimeMillis() + ".png");
                        request.setDestinationUri(Uri.fromFile(destinationFile));
                        ((DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE)).enqueue(request);

                        Toast.makeText(context, context.getText(R.string.share__toast_saved_image_to_location)
                                + " " + destinationFile.getAbsolutePath(), Toast.LENGTH_LONG).show();
                    }
                }
            }
                break;

            case ID_SHARE_IMAGE:
                if (url != null) {
                    boolean writeToStoragePermitted = true;
                    if (android.os.Build.VERSION.SDK_INT >= 23) {
                        int hasWRITE_EXTERNAL_STORAGE = parentActivity
                                .checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE);
                        if (hasWRITE_EXTERNAL_STORAGE != PackageManager.PERMISSION_GRANTED) {
                            writeToStoragePermitted = false;
                            if (!parentActivity.shouldShowRequestPermissionRationale(
                                    Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
                                new AlertDialog.Builder(parentActivity).setMessage(R.string.permissions_image)
                                        .setPositiveButton(context.getText(android.R.string.yes),
                                                new DialogInterface.OnClickListener() {
                                                    @Override
                                                    public void onClick(DialogInterface dialog, int which) {
                                                        if (android.os.Build.VERSION.SDK_INT >= 23)
                                                            parentActivity.requestPermissions(new String[] {
                                                                    Manifest.permission.WRITE_EXTERNAL_STORAGE },
                                                                    MainActivity.REQUEST_CODE__ACCESS_EXTERNAL_STORAGE);
                                                    }
                                                })
                                        .setNegativeButton(context.getText(android.R.string.no), null).show();
                            } else {
                                parentActivity.requestPermissions(
                                        new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE },
                                        MainActivity.REQUEST_CODE__ACCESS_EXTERNAL_STORAGE);
                            }
                        }
                    }
                    if (writeToStoragePermitted) {
                        final Uri local = Uri.parse(Environment.getExternalStorageDirectory()
                                + "/Pictures/Diaspora/" + System.currentTimeMillis() + ".png");
                        new ImageDownloadTask(null, local.getPath()) {
                            @Override
                            protected void onPostExecute(Bitmap result) {
                                Uri myUri = Uri.fromFile(new File(local.getPath()));
                                Intent sharingIntent = new Intent();
                                sharingIntent.setAction(Intent.ACTION_SEND);
                                sharingIntent.putExtra(Intent.EXTRA_STREAM, myUri);
                                sharingIntent.setType("image/png");
                                sharingIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                                context.startActivity(Intent.createChooser(sharingIntent,
                                        getResources().getString(R.string.action_share_dotdotdot)));
                            }
                        }.execute(url);
                    }
                } else {
                    Toast.makeText(context, "Cannot share image: url is null", Toast.LENGTH_SHORT).show();
                }

                break;

            case ID_IMAGE_EXTERNAL_BROWSER:
                if (url != null) {
                    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                    context.startActivity(intent);
                }
                break;

            //Copy url to clipboard
            case ID_COPY_LINK:
                if (url != null) {
                    ClipboardManager clipboard = (ClipboardManager) context
                            .getSystemService(Context.CLIPBOARD_SERVICE);
                    clipboard.setPrimaryClip(ClipData.newPlainText("text", url));
                    Toast.makeText(context, R.string.share__toast_link_address_copied, Toast.LENGTH_SHORT)
                            .show();
                }
                break;

            //Try to share link to other apps
            case ID_SHARE_LINK:
                if (url != null) {
                    Intent sendIntent = new Intent();
                    sendIntent.setAction(Intent.ACTION_SEND);
                    sendIntent.putExtra(Intent.EXTRA_TEXT, url);
                    sendIntent.setType("text/plain");
                    context.startActivity(Intent.createChooser(sendIntent,
                            getResources().getText(R.string.context_menu_share_link)));
                }
                break;
            }
            return true;
        }
    };

    //Build context menu
    if (result.getType() == HitTestResult.IMAGE_TYPE
            || result.getType() == HitTestResult.SRC_IMAGE_ANCHOR_TYPE) {
        // Menu options for an image.
        menu.setHeaderTitle(result.getExtra());
        menu.add(0, ID_SAVE_IMAGE, 0, context.getString(R.string.context_menu_save_image))
                .setOnMenuItemClickListener(handler);
        menu.add(0, ID_IMAGE_EXTERNAL_BROWSER, 0,
                context.getString(R.string.context_menu_open_external_browser))
                .setOnMenuItemClickListener(handler);
        menu.add(0, ID_SHARE_IMAGE, 0, context.getString(R.string.context_menu_share_image))
                .setOnMenuItemClickListener(handler);
    } else if (result.getType() == HitTestResult.ANCHOR_TYPE
            || result.getType() == HitTestResult.SRC_ANCHOR_TYPE) {
        // Menu options for a hyperlink.
        menu.setHeaderTitle(result.getExtra());
        menu.add(0, ID_COPY_LINK, 0, context.getString(R.string.context_menu_copy_link))
                .setOnMenuItemClickListener(handler);
        menu.add(0, ID_SHARE_LINK, 0, context.getString(R.string.context_menu_share_link))
                .setOnMenuItemClickListener(handler);
    }
}

From source file:net.vivekiyer.GAL.CorporateContactRecordFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    final AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();

    // Get the selected item from the listview adapter
    final KeyValuePair kvp = m_adapter.getItem(info.position);

    switch (item.getItemId()) {
    case MENU_ID_CALL:
        Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" //$NON-NLS-1$
                + kvp.getValue()));/*from   w  ww . j a va 2 s . c o  m*/
        startActivity(intent);
        break;
    case MENU_ID_SMS:
        intent = new Intent(Intent.ACTION_SENDTO, Uri.parse("smsto:" //$NON-NLS-1$
                + kvp.getValue()));
        startActivity(intent);
        break;
    case MENU_ID_COPY_TO_CLIPBOARD:
        final ClipboardManager clipboard = (ClipboardManager) getActivity()
                .getSystemService(Context.CLIPBOARD_SERVICE);
        clipboard.setText(kvp.getValue());
        Toast.makeText(this.getActivity(), getString(R.string.text_copied_to_clipboard), Toast.LENGTH_SHORT)
                .show();
        break;
    case MENU_ID_EDIT_BEFORE_CALL:
        intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" //$NON-NLS-1$
                + kvp.getValue()));
        startActivity(intent);
        break;
    case MENU_ID_EMAIL:
        intent = new Intent(android.content.Intent.ACTION_SEND);
        intent.setType("text/plain"); //$NON-NLS-1$
        intent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { kvp.getValue() });
        startActivity(Intent.createChooser(intent, getString(R.string.send_mail)));
        break;
    default:
        return super.onContextItemSelected(item);
    }
    return true;
}

From source file:com.googlecode.networklog.LogFragment.java

@SuppressWarnings("deprecation")
public void copySourceIp(ListItem item) {
    String srcAddr;/*from www  . jav a 2s  . com*/
    String srcPort;

    if (NetworkLog.resolveHosts && NetworkLog.resolveCopies) {
        String resolved = NetworkLog.resolver.resolveAddress(item.srcAddr);

        if (resolved != null) {
            srcAddr = resolved;
        } else {
            srcAddr = item.srcAddr;
        }
    } else {
        srcAddr = item.srcAddr;
    }

    if (NetworkLog.resolvePorts && NetworkLog.resolveCopies) {
        srcPort = NetworkLog.resolver.resolveService(String.valueOf(item.srcPort));
    } else {
        srcPort = String.valueOf(item.srcPort);
    }

    ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);

    /* newer API 11 clipboard unsupported on older devices
       ClipData clip = ClipData.newPlainText("NetworkLog Source IP", srcAddr + ":" + srcPort);
       clipboard.setPrimaryClip(clip);
       */

    /* use older deprecated ClipboardManager to support older devices */
    clipboard.setText(srcAddr + ":" + srcPort);
}

From source file:net.news.inrss.fragment.EntryFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (mEntriesIds != null) {
        final Activity activity = getActivity();

        switch (item.getItemId()) {
        case R.id.menu_star: {
            mFavorite = !mFavorite;//from  w ww  . j  a  va2 s  .  c  o m

            if (mFavorite) {
                item.setTitle(R.string.menu_unstar).setIcon(R.drawable.ic_star);
            } else {
                item.setTitle(R.string.menu_star).setIcon(R.drawable.ic_star_border);
            }

            final Uri uri = ContentUris.withAppendedId(mBaseUri, mEntriesIds[mCurrentPagerPos]);
            new Thread() {
                @Override
                public void run() {
                    ContentValues values = new ContentValues();
                    values.put(EntryColumns.IS_FAVORITE, mFavorite ? 1 : 0);
                    ContentResolver cr = MainApplication.getContext().getContentResolver();
                    cr.update(uri, values, null, null);

                    // Update the cursor
                    Cursor updatedCursor = cr.query(uri, null, null, null, null);
                    updatedCursor.moveToFirst();
                    mEntryPagerAdapter.setUpdatedCursor(mCurrentPagerPos, updatedCursor);
                }
            }.start();
            break;
        }
        case R.id.menu_share: {
            Cursor cursor = mEntryPagerAdapter.getCursor(mCurrentPagerPos);
            if (cursor != null) {
                String link = cursor.getString(mLinkPos);
                if (link != null) {
                    String title = cursor.getString(mTitlePos);
                    startActivity(Intent.createChooser(
                            new Intent(Intent.ACTION_SEND).putExtra(Intent.EXTRA_SUBJECT, title)
                                    .putExtra(Intent.EXTRA_TEXT, link).setType(Constants.MIMETYPE_TEXT_PLAIN),
                            getString(R.string.menu_share)));
                }
            }
            break;
        }
        case R.id.menu_full_screen: {
            setImmersiveFullScreen(true);
            break;
        }
        case R.id.menu_copy_clipboard: {
            Cursor cursor = mEntryPagerAdapter.getCursor(mCurrentPagerPos);
            String link = cursor.getString(mLinkPos);
            ClipboardManager clipboard = (ClipboardManager) activity
                    .getSystemService(Context.CLIPBOARD_SERVICE);
            ClipData clip = ClipData.newPlainText("Copied Text", link);
            clipboard.setPrimaryClip(clip);

            Toast.makeText(activity, R.string.copied_clipboard, Toast.LENGTH_SHORT).show();
            break;
        }
        case R.id.menu_mark_as_unread: {
            final Uri uri = ContentUris.withAppendedId(mBaseUri, mEntriesIds[mCurrentPagerPos]);
            new Thread() {
                @Override
                public void run() {
                    ContentResolver cr = MainApplication.getContext().getContentResolver();
                    cr.update(uri, FeedData.getUnreadContentValues(), null, null);
                }
            }.start();
            activity.finish();
            break;
        }
        case R.id.menu_open_in_browser: {
            Cursor cursor = mEntryPagerAdapter.getCursor(mCurrentPagerPos);
            if (cursor != null) {
                String link = cursor.getString(mLinkPos);
                if (link != null) {
                    Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(link));
                    startActivity(browserIntent);
                }
            }
            break;
        }
        case R.id.menu_switch_full_original: {
            if (mPreferFullText) {
                getActivity().runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        mPreferFullText = false;
                        Log.d(TAG, "run: manual call of displayEntry(), fullText=false");
                        mEntryPagerAdapter.displayEntry(mCurrentPagerPos, null, true);
                    }
                });
            } else {
                Cursor cursor = mEntryPagerAdapter.getCursor(mCurrentPagerPos);
                final boolean alreadyMobilized = !cursor.isNull(mMobilizedHtmlPos);

                if (alreadyMobilized) {
                    Log.d(TAG, "onOptionsItemSelected: alreadyMobilized");
                    mPreferFullText = true;
                    activity.runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Log.d(TAG, "run: manual call of displayEntry(), fullText=true");
                            mEntryPagerAdapter.displayEntry(mCurrentPagerPos, null, true);
                        }
                    });
                } else if (!isRefreshing()) {
                    Log.d(TAG, "onOptionsItemSelected: about to load article...");
                    mPreferFullText = false;
                    ConnectivityManager connectivityManager = (ConnectivityManager) activity
                            .getSystemService(Context.CONNECTIVITY_SERVICE);
                    final NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();

                    // since we have acquired the networkInfo, we use it for basic checks
                    if (networkInfo != null && networkInfo.getState() == NetworkInfo.State.CONNECTED) {
                        FetcherService.addEntriesToMobilize(new long[] { mEntriesIds[mCurrentPagerPos] });
                        activity.startService(new Intent(activity, FetcherService.class)
                                .setAction(FetcherService.ACTION_MOBILIZE_FEEDS));
                    } else {
                        activity.runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                Toast.makeText(activity, R.string.network_error, Toast.LENGTH_SHORT).show();
                            }
                        });
                        Log.d(TAG, "onOptionsItemSelected: cannot load article. no internet connection.");
                    }
                } else {
                    Log.d(TAG, "onOptionsItemSelected: refreshing already in progress");
                }
            }
            mShowFullContentItem.setChecked(mPreferFullText);
            break;
        }
        default:
            break;
        }
    }

    return super.onOptionsItemSelected(item);
}

From source file:net.yolosec.upckeygen.ui.NetworkFragment.java

private void displayResults() {
    if (passwordList.isEmpty()) {
        root.findViewById(R.id.loading_spinner).setVisibility(View.GONE);
        messages.setText(R.string.msg_errnomatches);

    } else {//  w ww  .  j  av a2 s  .c  o  m
        WiFiKey wiFiKey = passwordList.get(0);
        boolean isUbee = TextUtils.isEmpty(wiFiKey.getSerial());

        final ListView list = (ListView) root.findViewById(R.id.list_keys);
        Collections.sort(passwordList, new Comparator<WiFiKey>() {
            @Override
            public int compare(WiFiKey lhs, WiFiKey rhs) {
                if (lhs.getBandType() != rhs.getBandType()) {
                    return lhs.getBandType() < rhs.getBandType() ? -1 : 1;
                }

                final String serialL = lhs.getSerial();
                final String serialR = rhs.getSerial();
                if (serialL == null && serialR != null) {
                    return -1;
                } else if (serialL != null && serialR == null) {
                    return 1;
                } else if (serialL != null && !serialL.equals(serialR)) {
                    return serialL.compareTo(serialR);
                }

                return lhs.getKey().compareTo(rhs.getKey());
            }
        });

        list.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                final WiFiKey key = (WiFiKey) parent.getItemAtPosition(position);
                Toast.makeText(getActivity(), getString(R.string.msg_copied, key.getKey()), Toast.LENGTH_SHORT)
                        .show();

                if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {
                    android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getActivity()
                            .getSystemService(Context.CLIPBOARD_SERVICE);
                    clipboard.setText(key.getKey());
                } else {
                    android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getActivity()
                            .getSystemService(Context.CLIPBOARD_SERVICE);
                    android.content.ClipData clip = android.content.ClipData.newPlainText("key", key.getKey());
                    clipboard.setPrimaryClip(clip);
                }

                openWifiSettings();
            }
        });
        if (isUbee) {
            list.setAdapter(
                    new WiFiKeyUbeeAdapter(getActivity(), android.R.layout.simple_list_item_1, passwordList));
        } else {
            list.setAdapter(
                    new WiFiKeyAdapter(getActivity(), android.R.layout.simple_list_item_1, passwordList));
        }

        root.showNext();
    }
}

From source file:com.wellsandwhistles.android.redditsp.reddit.api.RedditAPICommentAction.java

public static void onActionMenuItemSelected(final RedditRenderableComment renderableComment,
        final RedditCommentView commentView, final AppCompatActivity activity,
        final CommentListingFragment commentListingFragment, final RedditCommentAction action,
        final RedditChangeDataManager changeDataManager) {

    final RedditComment comment = renderableComment.getParsedComment().getRawComment();

    switch (action) {

    case UPVOTE:/*from   w  ww. j a  v  a2 s  .  co m*/
        action(activity, comment, RedditAPI.ACTION_UPVOTE, changeDataManager);
        break;

    case DOWNVOTE:
        action(activity, comment, RedditAPI.ACTION_DOWNVOTE, changeDataManager);
        break;

    case UNVOTE:
        action(activity, comment, RedditAPI.ACTION_UNVOTE, changeDataManager);
        break;

    case SAVE:
        action(activity, comment, RedditAPI.ACTION_SAVE, changeDataManager);
        break;

    case UNSAVE:
        action(activity, comment, RedditAPI.ACTION_UNSAVE, changeDataManager);
        break;

    case REPORT:

        new AlertDialog.Builder(activity).setTitle(R.string.action_report)
                .setMessage(R.string.action_report_sure)
                .setPositiveButton(R.string.action_report, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(final DialogInterface dialog, final int which) {
                        action(activity, comment, RedditAPI.ACTION_REPORT, changeDataManager);
                    }
                }).setNegativeButton(R.string.dialog_cancel, null).show();

        break;

    case REPLY: {
        final Intent intent = new Intent(activity, CommentReplyActivity.class);
        intent.putExtra(CommentReplyActivity.PARENT_ID_AND_TYPE_KEY, comment.getIdAndType());
        intent.putExtra(CommentReplyActivity.PARENT_MARKDOWN_KEY,
                StringEscapeUtils.unescapeHtml4(comment.body));
        activity.startActivity(intent);
        break;
    }

    case EDIT: {
        final Intent intent = new Intent(activity, CommentEditActivity.class);
        intent.putExtra("commentIdAndType", comment.getIdAndType());
        intent.putExtra("commentText", StringEscapeUtils.unescapeHtml4(comment.body));
        activity.startActivity(intent);
        break;
    }

    case DELETE: {
        new AlertDialog.Builder(activity).setTitle(R.string.accounts_delete).setMessage(R.string.delete_confirm)
                .setPositiveButton(R.string.action_delete, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(final DialogInterface dialog, final int which) {
                        action(activity, comment, RedditAPI.ACTION_DELETE, changeDataManager);
                    }
                }).setNegativeButton(R.string.dialog_cancel, null).show();
        break;
    }

    case COMMENT_LINKS:
        final HashSet<String> linksInComment = comment.computeAllLinks();

        if (linksInComment.isEmpty()) {
            General.quickToast(activity, R.string.error_toast_no_urls_in_comment);

        } else {

            final String[] linksArr = linksInComment.toArray(new String[linksInComment.size()]);

            final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
            builder.setItems(linksArr, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    LinkHandler.onLinkClicked(activity, linksArr[which], false);
                    dialog.dismiss();
                }
            });

            final AlertDialog alert = builder.create();
            alert.setTitle(R.string.action_comment_links);
            alert.setCanceledOnTouchOutside(true);
            alert.show();
        }

        break;

    case SHARE:

        final Intent mailer = new Intent(Intent.ACTION_SEND);
        mailer.setType("text/plain");
        mailer.putExtra(Intent.EXTRA_SUBJECT, "Comment by " + comment.author + " on Reddit");

        // TODO this currently just dumps the markdown
        mailer.putExtra(Intent.EXTRA_TEXT, StringEscapeUtils.unescapeHtml4(comment.body) + "\r\n\r\n"
                + comment.getContextUrl().generateNonJsonUri().toString());

        activity.startActivityForResult(Intent.createChooser(mailer, activity.getString(R.string.action_share)),
                1);

        break;

    case COPY_TEXT: {
        ClipboardManager manager = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
        // TODO this currently just dumps the markdown
        manager.setText(StringEscapeUtils.unescapeHtml4(comment.body));
        break;
    }

    case COPY_URL: {
        ClipboardManager manager = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
        // TODO this currently just dumps the markdown
        manager.setText(comment.getContextUrl().context(null).generateNonJsonUri().toString());
        break;
    }

    case COLLAPSE: {
        commentListingFragment.handleCommentVisibilityToggle(commentView);
        break;
    }

    case USER_PROFILE:
        LinkHandler.onLinkClicked(activity, new UserProfileURL(comment.author).toString());
        break;

    case PROPERTIES:
        CommentPropertiesDialog.newInstance(comment).show(activity.getSupportFragmentManager(), null);
        break;

    case GO_TO_COMMENT: {
        LinkHandler.onLinkClicked(activity, comment.getContextUrl().context(null).toString());
        break;
    }

    case CONTEXT: {
        LinkHandler.onLinkClicked(activity, comment.getContextUrl().toString());
        break;
    }
    case ACTION_MENU:
        showActionMenu(activity, commentListingFragment, renderableComment, commentView, changeDataManager,
                comment.isArchived());
        break;

    case BACK:
        activity.onBackPressed();
        break;
    }
}