Example usage for android.text.method LinkMovementMethod getInstance

List of usage examples for android.text.method LinkMovementMethod getInstance

Introduction

In this page you can find the example usage for android.text.method LinkMovementMethod getInstance.

Prototype

public static MovementMethod getInstance() 

Source Link

Usage

From source file:org.mariotaku.twidere.fragment.StatusFragment.java

public void displayStatus(final ParcelableStatus status) {
    onRefreshComplete();// w w w .  j  a va2 s. co m
    updatePullRefresh();
    final boolean status_changed = mStatus != null && status != null && !status.equals(mStatus);
    if (status_changed) {
        mAdapter.clear();
        // UCD
        ProfilingUtil.profile(getActivity(), mStatus.account_id, "End, " + mStatus.status_id);
    } else {
        mListView.setSelection(0);
    }
    mStatusId = -1;
    mAccountId = -1;
    mStatus = status;
    if (mStatus != null) {
        // UCD
        ProfilingUtil.profile(getActivity(), mStatus.account_id, "Start, " + mStatus.status_id);
        mAccountId = mStatus.account_id;
        mStatusId = mStatus.status_id;
    }
    clearPreviewImages();
    if (status == null || getActivity() == null)
        return;
    final Bundle args = getArguments();
    args.putLong(INTENT_KEY_ACCOUNT_ID, mAccountId);
    args.putLong(INTENT_KEY_STATUS_ID, mStatusId);
    args.putParcelable(INTENT_KEY_STATUS, status);
    mMenuBar.inflate(R.menu.menu_status);
    setMenuForStatus(getActivity(), mMenuBar.getMenu(), status);
    mMenuBar.show();

    updateUserColor();
    mProfileView.drawRight(getAccountColor(getActivity(), status.account_id));

    mNameView.setText(status.name);
    mNameView.setCompoundDrawablesWithIntrinsicBounds(0, 0,
            getUserTypeIconRes(status.is_verified, status.is_protected), 0);
    mScreenNameView.setText("@" + status.screen_name);
    mTextView.setText(Html.fromHtml(status.text_html));
    final TwidereLinkify linkify = new TwidereLinkify(mTextView);
    linkify.setOnLinkClickListener(
            new OnLinkClickHandler(getActivity(), mAccountId, status.is_possibly_sensitive));
    linkify.addAllLinks();
    final boolean is_reply = status.in_reply_to_status_id > 0;
    final String time = formatToLongTimeString(getActivity(), status.status_timestamp);
    final String source_html = status.source;
    setPullToRefreshEnabled(!mLoadMoreAutomatically && is_reply);
    if (!isEmpty(time) && !isEmpty(source_html)) {
        mTimeAndSourceView.setText(Html.fromHtml(getString(R.string.time_source, time, source_html)));
    } else if (isEmpty(time) && !isEmpty(source_html)) {
        mTimeAndSourceView.setText(Html.fromHtml(getString(R.string.source, source_html)));
    } else if (!isEmpty(time) && isEmpty(source_html)) {
        mTimeAndSourceView.setText(time);
    }
    mTimeAndSourceView.setMovementMethod(LinkMovementMethod.getInstance());
    final boolean display_screen_name = NAME_DISPLAY_OPTION_SCREEN_NAME
            .equals(mPreferences.getString(PREFERENCE_KEY_NAME_DISPLAY_OPTION, NAME_DISPLAY_OPTION_BOTH));
    mInReplyToView.setVisibility(is_reply ? View.VISIBLE : View.GONE);
    if (is_reply) {
        if (mLoadMoreAutomatically) {
            mInReplyToView.setText(getString(R.string.in_reply_to, "@" + status.in_reply_to_screen_name));
        } else {
            mInReplyToView.setText(getString(R.string.in_reply_to_pull_to_load_conversation,
                    "@" + status.in_reply_to_screen_name));
        }
    }

    if (mPreferences.getBoolean(PREFERENCE_KEY_DISPLAY_PROFILE_IMAGE, true)) {
        final boolean hires_profile_image = getResources().getBoolean(R.bool.hires_profile_image);
        mProfileImageLoader.displayImage(mProfileImageView,
                hires_profile_image ? getBiggerTwitterProfileImage(status.profile_image_url_string)
                        : status.profile_image_url_string);
    } else {
        mProfileImageView.setImageResource(R.drawable.ic_profile_image_default);
    }
    final List<ImageSpec> images = getImagesInStatus(status.text_html);
    mImagePreviewContainer.setVisibility(images.size() > 0 ? View.VISIBLE : View.GONE);
    loadPreviewImages(images);
    if (mPreferences.getBoolean(PREFERENCE_KEY_LOAD_MORE_AUTOMATICALLY, false)) {
        showPreviewImages();
    }
    mRetweetedStatusView.setVisibility(status.retweet_id > 0 ? View.VISIBLE : View.GONE);
    if (status.retweet_id > 0) {
        if (display_screen_name) {
            mRetweetedStatusView.setText(status.retweet_count > 1
                    ? getString(R.string.retweeted_by_with_count, status.retweeted_by_screen_name,
                            status.retweet_count - 1)
                    : getString(R.string.retweeted_by, status.retweeted_by_screen_name));
        } else {
            mRetweetedStatusView.setText(status.retweet_count > 1
                    ? getString(R.string.retweeted_by_with_count, status.retweeted_by_name,
                            status.retweet_count - 1)
                    : getString(R.string.retweeted_by, status.retweeted_by_name));
        }
    }
    mLocationView.setVisibility(ParcelableLocation.isValidLocation(status.location) ? View.VISIBLE : View.GONE);
    if (mLoadMoreAutomatically) {
        showFollowInfo(true);
        showLocationInfo(true);
        showConversation();
    } else {
        mFollowIndicator.setVisibility(View.GONE);
    }

}

From source file:net.networksaremadeofstring.rhybudd.ViewZenossEventFragment.java

/**
 * Called when the activity is first created.
 *//*from  w w  w. ja va2s. c  o  m*/
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    BugSenseHandler.initAndStartSession(getActivity(), "44a76a8c");

    settings = PreferenceManager.getDefaultSharedPreferences(getActivity());

    firstLoadHandler = new Handler() {
        public void handleMessage(Message msg) {
            //dialog.dismiss();
            try {
                if (EventObject.has("result")
                        && EventObject.getJSONObject("result").getBoolean("success") == true) {
                    EventDetails = EventObject.getJSONObject("result").getJSONArray("event").getJSONObject(0);

                    try {
                        //Log.e("Ack",EventDetails.getString("eventState"));
                        if (EventDetails.getString("eventState").equals("Acknowledged")
                                || EventDetails.getString("eventState").equals("1")) {
                            ackIcon.setImageResource(R.drawable.ic_acknowledged);
                            isAcknowledged = true;
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                        BugSenseHandler.sendExceptionMessage("ViewZenossEventFragment", "loadhandler ack image",
                                e);
                    }

                    //Log.e("EventDetails", EventDetails.toString(3));

                    try {
                        Title.setText(EventDetails.getString("device_title"));
                    } catch (Exception e) {
                        Title.setText("Unknown Device - Event Details");
                    }

                    try {
                        Component.setText(EventDetails.getString("component"));
                    } catch (Exception e) {
                        Component.setText("Unknown Component");
                    }

                    try {
                        if (!EventDetails.getString("eventClassKey").equals("")) {
                            EventClass.setText(EventDetails.getString("eventClassKey"));
                        } else {
                            EventClass.setText("Unknown Event Class");
                        }
                    } catch (Exception e) {
                        EventClass.setText("Unknown Event Class");
                    }

                    try {
                        //ImageView img = (ImageView) findViewById(R.id.summaryImage);

                        URLImageParser p = new URLImageParser(img, getActivity(), Summary);

                        String summaryText = EventDetails.getString("message");
                        Spanned htmlSpan = Html.fromHtml(summaryText, p, null);

                        //Log.e("summary",summaryText);
                        summaryText = summaryText.replaceAll("<img\\s*src=('|\")([^'>]+)'\\s*/>", "");
                        //Log.e("summary2",summaryText);

                        Summary.setText(Html.fromHtml(summaryText, null, null));

                        //Log.i("Summary", EventDetails.getString("message"));

                        try {
                            Summary.setMovementMethod(LinkMovementMethod.getInstance());
                        } catch (Exception e) {
                            e.printStackTrace();
                            BugSenseHandler.sendExceptionMessage("ViewZenossEventFragment",
                                    "set Summary MovementMethod", e);
                            //Worth a shot
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                        Summary.setText("No Summary available");
                    }

                    try {
                        FirstTime.setText(EventDetails.getString("firstTime"));
                    } catch (Exception e) {
                        FirstTime.setText("No Start Date Provided");
                    }

                    try {
                        LastTime.setText(EventDetails.getString("stateChange"));
                    } catch (Exception e) {
                        LastTime.setText("No Recent Date Provided");
                    }

                    try {
                        EventCount.setText("Count: " + EventDetails.getString("count"));
                    } catch (Exception e) {
                        EventCount.setText("Count: ??");
                    }

                    try {
                        agent.setText(EventDetails.getString("agent"));
                    } catch (Exception e) {
                        agent.setText("unknown");
                    }

                    try {
                        JSONArray Log = EventDetails.getJSONArray("log");

                        int LogEntryCount = Log.length();

                        if (LogEntryCount == 0) {
                            TextView newLog = new TextView(getActivity());
                            newLog.setText("No log entries could be found");
                            LogEntries = new String[1];
                            LogEntries[0] = "No log entries could be found";
                            logList.addView(newLog);
                        } else {
                            LogEntries = new String[LogEntryCount];

                            for (int i = 0; i < LogEntryCount; i++) {
                                LogEntries[i] = "<strong>" + Log.getJSONArray(i).getString(0)
                                        + "</strong> wrote " + Log.getJSONArray(i).getString(2)
                                        + "\n<br/><strong>At:</strong> " + Log.getJSONArray(i).getString(1);

                                TextView newLog = new TextView(getActivity());
                                newLog.setText(Html.fromHtml(LogEntries[i]));
                                newLog.setPadding(0, 6, 0, 6);

                                logList.addView(newLog);
                            }
                        }
                    } catch (Exception e) {
                        TextView newLog = new TextView(getActivity());
                        newLog.setText("No log entries could be found");
                        newLog.setPadding(0, 6, 0, 6);
                        logList.addView(newLog);
                    }

                    progressbar.setVisibility(View.INVISIBLE);
                } else {
                    //Log.e("EventObject",EventObject.toString(3));
                    String errMsg = ".";
                    if (EventObject.has("type") && EventObject.getString("type").equals("exception")
                            && EventObject.has("message"))
                        errMsg = ":\n" + EventObject.getString("message");

                    Toast.makeText(getActivity(),
                            "There was an error refreshing the Event details from Zenoss" + errMsg,
                            Toast.LENGTH_LONG).show();
                }
            } catch (Exception e) {
                try {
                    Toast.makeText(getActivity(),
                            "An error was encountered parsing the JSON. An error report has been sent.",
                            Toast.LENGTH_LONG).show();
                } catch (Exception e2) {
                    e.printStackTrace();
                    e2.printStackTrace();
                }

                BugSenseHandler.sendExceptionMessage("ViewZenossEventFragment",
                        "uncaught exception within firstload", e);
            }
        }
    };
}

From source file:com.open.file.manager.MainActivity.java

/**
 * Show dialog when "about" is clicked/*  www  . ja v  a2s. c  o  m*/
 */
private void showAboutDialog() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View aboutdialogview = inflater.inflate(R.layout.aboutdialog, null);
    builder.setView(aboutdialogview);
    TextView bodyview = (TextView) aboutdialogview.findViewById(R.id.aboutcontent);
    bodyview.setText(Html.fromHtml(getString(R.string.aboutBody)));
    bodyview.setMovementMethod(LinkMovementMethod.getInstance());
    builder.setTitle(R.string.about);
    builder.setPositiveButton("OK", null);
    builder.create().show();
}

From source file:es.farfuteam.vncpp.controller.ActivityTabs.java

/**
 * @return The new dialog/*from w  ww  .  j av a2s  .co  m*/
 * @brief Shows the dialog to indicate about info
 * @details Shows the dialog to indicate about info
 */
private Dialog createAboutDialog() {
    //necesario para poder clicar en los links
    final TextView message = new TextView(this);
    final SpannableString s = new SpannableString(this.getText(R.string.about_message));
    Linkify.addLinks(s, Linkify.WEB_URLS);
    message.setText(s);
    message.setMovementMethod(LinkMovementMethod.getInstance());

    return new AlertDialog.Builder(this).setTitle(R.string.about_title).setView(message)
            .setPositiveButton(R.string.about_ok, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // Auto-generated method stub

                }
            }).show();
}

From source file:org.sufficientlysecure.keychain.ui.ViewKeyKeybaseFragment.java

private void displaySpannableResult(SpannableStringBuilder ssb) {
    mProofVerifyHeader.setVisibility(View.VISIBLE);
    mProofVerifyDetail.setVisibility(View.VISIBLE);
    mProofVerifyDetail.setMovementMethod(LinkMovementMethod.getInstance());
    mProofVerifyDetail.setText(ssb);//from   w w  w . j  av  a  2s  . c om
}

From source file:com.gelakinetic.mtgfam.activities.MainActivity.java

public void showDialogFragment(final int id) {
    // DialogFragment.show() will take care of adding the fragment
    // in a transaction. We also want to remove any currently showing
    // dialog, so make our own transaction and take care of that here.
    this.showContent();
    FragmentTransaction ft = this.getSupportFragmentManager().beginTransaction();
    Fragment prev = getSupportFragmentManager().findFragmentByTag(FamiliarFragment.DIALOG_TAG);
    if (prev != null) {
        ft.remove(prev);//w  w  w. j av a  2 s.c om
    }

    // Create and show the dialog.
    FamiliarDialogFragment newFragment = new FamiliarDialogFragment() {

        @Override
        public void onDismiss(DialogInterface mDialog) {
            super.onDismiss(mDialog);
            if (bounceMenu) {
                getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
                bounceMenu = false;
                Runnable r = new Runnable() {

                    @Override
                    public void run() {
                        long timeStarted = System.currentTimeMillis();
                        Message msg = Message.obtain();
                        msg.arg1 = OPEN;
                        bounceHandler.sendMessage(msg);
                        while (System.currentTimeMillis() < (timeStarted + 1500)) {
                            ;
                        }
                        msg = Message.obtain();
                        msg.arg1 = CLOSE;
                        bounceHandler.sendMessage(msg);
                        runOnUiThread(new Runnable() {

                            @Override
                            public void run() {
                                getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED);
                            }
                        });
                    }
                };

                Thread t = new Thread(r);
                t.start();
            }
        }

        @Override
        public Dialog onCreateDialog(Bundle savedInstanceState) {
            switch (id) {
            case DONATEDIALOG: {
                AlertDialog.Builder builder = new AlertDialog.Builder(this.getActivity());
                builder.setTitle(R.string.main_donate_dialog_title);
                builder.setNeutralButton(R.string.dialog_thanks_anyway, new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                });

                LayoutInflater inflater = this.getActivity().getLayoutInflater();
                View dialoglayout = inflater.inflate(R.layout.about_dialog,
                        (ViewGroup) findViewById(R.id.dialog_layout_root));

                TextView text = (TextView) dialoglayout.findViewById(R.id.aboutfield);
                text.setText(ImageGetterHelper.jellyBeanHack(getString(R.string.main_donate_text)));
                text.setMovementMethod(LinkMovementMethod.getInstance());

                text.setTextSize(15);

                ImageView paypal = (ImageView) dialoglayout.findViewById(R.id.imageview1);
                paypal.setImageResource(R.drawable.paypal);
                paypal.setOnClickListener(new View.OnClickListener() {

                    public void onClick(View v) {
                        Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(
                                "https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=SZK4TAH2XBZNC&lc=US&item_name=MTG%20Familiar&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donate_LG%2egif%3aNonHosted"));

                        startActivity(myIntent);
                    }
                });
                ((ImageView) dialoglayout.findViewById(R.id.imageview2)).setVisibility(View.GONE);

                builder.setView(dialoglayout);
                return builder.create();
            }
            case ABOUTDIALOG: {
                AlertDialog.Builder builder = new AlertDialog.Builder(this.getActivity());

                // You have to catch the exception because the package stuff is all
                // run-time
                if (pInfo != null) {
                    builder.setTitle(getString(R.string.main_about) + " " + getString(R.string.app_name) + " "
                            + pInfo.versionName);
                } else {
                    builder.setTitle(getString(R.string.main_about) + " " + getString(R.string.app_name));
                }

                builder.setNeutralButton(R.string.dialog_thanks, new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                });

                LayoutInflater inflater = this.getActivity().getLayoutInflater();
                View dialoglayout = inflater.inflate(R.layout.about_dialog,
                        (ViewGroup) findViewById(R.id.dialog_layout_root));

                TextView text = (TextView) dialoglayout.findViewById(R.id.aboutfield);
                text.setText(ImageGetterHelper.jellyBeanHack(getString(R.string.main_about_text)));
                text.setMovementMethod(LinkMovementMethod.getInstance());

                builder.setView(dialoglayout);
                return builder.create();
            }
            case CHANGELOGDIALOG: {
                AlertDialog.Builder builder = new AlertDialog.Builder(this.getActivity());

                if (pInfo != null) {
                    builder.setTitle(getString(R.string.main_whats_new_in_title) + " " + pInfo.versionName);
                } else {
                    builder.setTitle(R.string.main_whats_new_title);
                }

                builder.setNeutralButton(R.string.dialog_enjoy, new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                });

                builder.setMessage(ImageGetterHelper.jellyBeanHack(getString(R.string.main_whats_new_text)));
                return builder.create();
            }
            default: {
                savedInstanceState.putInt("id", id);
                return super.onCreateDialog(savedInstanceState);
            }
            }
        }
    };
    newFragment.show(ft, FamiliarFragment.DIALOG_TAG);
}

From source file:com.android.mail.browse.MessageHeaderView.java

private void setDateText() {
    if (mIsSnappy) {
        mDateView.setText(mMessageHeaderItem.getTimestampLong());
        mDateView.setOnClickListener(null);
    } else {/*from  w w  w .j  a v a  2  s  . co  m*/
        mDateView.setMovementMethod(LinkMovementMethod.getInstance());
        mDateView.setText(Html.fromHtml(getResources().getString(R.string.date_and_view_details,
                mMessageHeaderItem.getTimestampLong())));
        StyleUtils.stripUnderlinesAndUrl(mDateView);
    }
}

From source file:net.czlee.debatekeeper.FormatChooserActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_format_chooser);
    DEBATING_TIMER_URI = getString(R.string.xml_uri);

    mFilesManager = new FormatXmlFilesManager(this);
    mStylesArrayAdapter = new DebateFormatEntryArrayAdapter(this, mStylesList,
            new FormatChooserActivityBinder());

    // Set the action bar
    ActionBar bar = getActionBar();/*from   www  . jav a 2  s .  c  o m*/
    if (bar != null)
        bar.setDisplayHomeAsUpEnabled(true);

    // Configure the checkbox
    CheckBox checkbox = (CheckBox) findViewById(R.id.formatChooser_lookForCustomCheckbox);
    checkbox.setMovementMethod(LinkMovementMethod.getInstance());
    checkbox.setOnClickListener(new LookForCustomCheckboxOnClickListener());
    mInitialLookForCustomFormats = mFilesManager.isLookingForUserFiles();
    checkbox.setChecked(mInitialLookForCustomFormats);

    // If we need it, ask the user for read permission. If it's not already granted, treat the
    // initial setting as false.
    if (mInitialLookForCustomFormats) {
        mInitialLookForCustomFormats = requestReadPermission(); // note: this method may show an alert to the user
    }

    // Populate the styles list
    populateStylesList();

    // Configure the ListView
    mStylesListView = (ListView) findViewById(R.id.formatChooser_stylesList);
    mStylesListView.setAdapter(mStylesArrayAdapter);
    mStylesListView.setOnItemClickListener(new StylesListViewOnItemClickListener());

    // Select and scroll to the incoming selection (if existent)
    String incomingFilename = getIntent().getStringExtra(EXTRA_XML_FILE_NAME);
    setSelectionAndScroll(incomingFilename);
}

From source file:foam.opensauces.StarwispBuilder.java

public void Build(final StarwispActivity ctx, final String ctxname, JSONArray arr, ViewGroup parent) {

    try {/*from  ww  w.  j av  a2s  .c  o m*/
        String type = arr.getString(0);

        //Log.i("starwisp","building started "+type);

        if (type.equals("build-fragment")) {
            String name = arr.getString(1);
            int ID = arr.getInt(2);
            Fragment fragment = ActivityManager.GetFragment(name);
            LinearLayout inner = new LinearLayout(ctx);
            inner.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3)));
            inner.setId(ID);
            FragmentTransaction fragmentTransaction = ctx.getSupportFragmentManager().beginTransaction();
            fragmentTransaction.add(ID, fragment);
            fragmentTransaction.commit();
            parent.addView(inner);
            return;
        }

        if (type.equals("linear-layout")) {
            LinearLayout v = new LinearLayout(ctx);
            v.setId(arr.getInt(1));
            v.setOrientation(BuildOrientation(arr.getString(2)));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3)));
            //v.setPadding(2,2,2,2);
            JSONArray col = arr.getJSONArray(4);
            v.setBackgroundColor(Color.argb(col.getInt(3), col.getInt(0), col.getInt(1), col.getInt(2)));
            parent.addView(v);
            JSONArray children = arr.getJSONArray(5);
            for (int i = 0; i < children.length(); i++) {
                Build(ctx, ctxname, new JSONArray(children.getString(i)), v);
            }
            return;
        }

        if (type.equals("draggable")) {
            final LinearLayout v = new LinearLayout(ctx);
            final int id = arr.getInt(1);
            v.setPadding(20, 20, 20, 20);
            v.setId(id);
            v.setOrientation(BuildOrientation(arr.getString(2)));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3)));
            v.setClickable(true);
            v.setFocusable(true);

            JSONArray col = arr.getJSONArray(4);
            v.setBackgroundResource(R.drawable.draggable);

            GradientDrawable drawable = (GradientDrawable) v.getBackground();
            final int colour = Color.argb(col.getInt(3), col.getInt(0), col.getInt(1), col.getInt(2));
            drawable.setColor(colour);

            parent.addView(v);
            JSONArray children = arr.getJSONArray(5);
            for (int i = 0; i < children.length(); i++) {
                Build(ctx, ctxname, new JSONArray(children.getString(i)), v);
            }

            // Sets a long click listener for the ImageView using an anonymous listener object that
            // implements the OnLongClickListener interface
            /*                v.setOnLongClickListener(new View.OnLongClickListener() {
            public boolean onLongClick(View vv) {
                if (id!=99) {
                    ClipData dragData = ClipData.newPlainText("simple text", ""+id);
                    View.DragShadowBuilder myShadow = new MyDragShadowBuilder(v);
                    Log.i("starwisp","start drag id "+vv.getId());
                    v.startDrag(dragData, myShadow, null, 0);
                    v.setVisibility(View.GONE);
                    return true;
                }
                return false;
            }
                            });
            */
            // Sets a long click listener for the ImageView using an anonymous listener object that
            // implements the OnLongClickListener interface
            v.setOnTouchListener(new View.OnTouchListener() {
                public boolean onTouch(View vv, MotionEvent event) {
                    if (event.getAction() == MotionEvent.ACTION_DOWN && id != 99) {
                        //                            ClipData dragData = ClipData.newPlainText("simple text", ""+id);

                        ClipData dragData = new ClipData(
                                new ClipDescription(null, new String[] { ClipDescription.MIMETYPE_TEXT_PLAIN }),
                                new ClipData.Item("" + id));

                        View.DragShadowBuilder myShadow = new MyDragShadowBuilder(v);
                        Log.i("starwisp", "start drag id " + vv.getId());
                        v.startDrag(dragData, myShadow, null, 0);
                        v.setVisibility(View.GONE);
                        return true;
                    }
                    return false;
                }
            });

            v.setOnDragListener(new View.OnDragListener() {
                public boolean onDrag(View vv, DragEvent event) {
                    final int action = event.getAction();
                    switch (action) {
                    case DragEvent.ACTION_DRAG_STARTED:
                        if (event.getClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) {
                            // returns true to indicate that the View can accept the dragged data.
                            return true;
                        } else {
                            // Returns false. During the current drag and drop operation, this View will
                            // not receive events again until ACTION_DRAG_ENDED is sent.
                            return false;
                        }
                    case DragEvent.ACTION_DRAG_ENTERED: {
                        return true;
                    }
                    case DragEvent.ACTION_DRAG_LOCATION:
                        return true;
                    case DragEvent.ACTION_DRAG_EXITED: {
                        return true;
                    }
                    case DragEvent.ACTION_DROP: {
                        ClipData.Item item = event.getClipData().getItemAt(0);
                        String dragData = item.getText().toString();
                        Log.i("starwisp", "Dragged view is " + dragData);
                        int otherid = Integer.parseInt(dragData);
                        View otherw = ctx.findViewById(otherid);
                        Log.i("starwisp", "removing from parent " + ((View) otherw.getParent()).getId());

                        // check we are not adding to ourself
                        if (id != otherid) {
                            ((ViewManager) otherw.getParent()).removeView(otherw);
                            Log.i("starwisp", "adding to " + id);
                            v.addView(otherw);
                        }
                        otherw.setVisibility(View.VISIBLE);
                        return true;
                    }
                    case DragEvent.ACTION_DRAG_ENDED: {
                        if (event.getResult()) {
                        } else {
                        }
                        ;
                        return true;
                    }
                    // An unknown action type was received.
                    default:
                        Log.e("starwisp", "Unknown action type received by OnDragListener.");
                        break;
                    }
                    ;
                    return true;
                }
            });
            return;
        }

        if (type.equals("frame-layout")) {
            FrameLayout v = new FrameLayout(ctx);
            v.setId(arr.getInt(1));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
            parent.addView(v);
            JSONArray children = arr.getJSONArray(3);
            for (int i = 0; i < children.length(); i++) {
                Build(ctx, ctxname, new JSONArray(children.getString(i)), v);
            }
            return;
        }

        /*
        if (type.equals("grid-layout")) {
        GridLayout v = new GridLayout(ctx);
        v.setId(arr.getInt(1));
        v.setRowCount(arr.getInt(2));
        //v.setColumnCount(arr.getInt(2));
        v.setOrientation(BuildOrientation(arr.getString(3)));
        v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4)));
                
        parent.addView(v);
        JSONArray children = arr.getJSONArray(5);
        for (int i=0; i<children.length(); i++) {
            Build(ctx,ctxname,new JSONArray(children.getString(i)), v);
        }
                
        return;
        }
        */

        if (type.equals("scroll-view")) {
            HorizontalScrollView v = new HorizontalScrollView(ctx);
            v.setId(arr.getInt(1));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
            parent.addView(v);
            JSONArray children = arr.getJSONArray(3);
            for (int i = 0; i < children.length(); i++) {
                Build(ctx, ctxname, new JSONArray(children.getString(i)), v);
            }
            return;
        }

        if (type.equals("scroll-view-vert")) {
            ScrollView v = new ScrollView(ctx);
            v.setId(arr.getInt(1));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
            parent.addView(v);
            JSONArray children = arr.getJSONArray(3);
            for (int i = 0; i < children.length(); i++) {
                Build(ctx, ctxname, new JSONArray(children.getString(i)), v);
            }
            return;
        }

        if (type.equals("view-pager")) {
            ViewPager v = new ViewPager(ctx);
            v.setId(arr.getInt(1));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
            v.setOffscreenPageLimit(3);
            final JSONArray items = arr.getJSONArray(3);

            v.setAdapter(new FragmentPagerAdapter(ctx.getSupportFragmentManager()) {

                @Override
                public int getCount() {
                    return items.length();
                }

                @Override
                public Fragment getItem(int position) {
                    try {
                        String fragname = items.getString(position);
                        return ActivityManager.GetFragment(fragname);
                    } catch (JSONException e) {
                        Log.e("starwisp", "Error parsing data " + e.toString());
                    }
                    return null;
                }
            });
            parent.addView(v);
            return;
        }

        if (type.equals("space")) {
            // Space v = new Space(ctx); (class not found runtime error??)
            TextView v = new TextView(ctx);
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
            parent.addView(v);
        }

        if (type.equals("image-view")) {
            ImageView v = new ImageView(ctx);
            v.setId(arr.getInt(1));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3)));

            String image = arr.getString(2);

            if (image.startsWith("/")) {
                Bitmap bitmap = BitmapFactory.decodeFile(image);
                v.setImageBitmap(bitmap);
            } else {
                int id = ctx.getResources().getIdentifier(image, "drawable", ctx.getPackageName());
                v.setImageResource(id);
            }

            parent.addView(v);
        }

        if (type.equals("text-view")) {
            TextView v = new TextView(ctx);
            v.setId(arr.getInt(1));
            v.setText(Html.fromHtml(arr.getString(2)));
            v.setTextSize(arr.getInt(3));
            v.setMovementMethod(LinkMovementMethod.getInstance());
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4)));
            v.setClickable(false);
            v.setEnabled(false);

            v.setOnTouchListener(new View.OnTouchListener() {
                public boolean onTouch(View vv, MotionEvent event) {
                    return false;
                }
            });

            if (arr.length() > 5) {
                if (arr.getString(5).equals("left")) {
                    v.setGravity(Gravity.LEFT);
                } else {
                    if (arr.getString(5).equals("fill")) {
                        v.setGravity(Gravity.FILL);
                    } else {
                        v.setGravity(Gravity.CENTER);
                    }
                }
            } else {
                v.setGravity(Gravity.LEFT);
            }
            v.setTypeface(((StarwispActivity) ctx).m_Typeface);
            parent.addView(v);
        }

        if (type.equals("debug-text-view")) {
            TextView v = (TextView) ctx.getLayoutInflater().inflate(R.layout.debug_text, null);
            //                v.setBackgroundResource(R.color.black);
            v.setId(arr.getInt(1));
            //                v.setText(Html.fromHtml(arr.getString(2)));
            //                v.setTextColor(R.color.white);
            //                v.setTextSize(arr.getInt(3));
            //                v.setMovementMethod(LinkMovementMethod.getInstance());
            //                v.setMaxLines(10);
            //                v.setVerticalScrollBarEnabled(true);
            //                v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4)));
            //v.setMovementMethod(new ScrollingMovementMethod());

            /*
            if (arr.length()>5) {
            if (arr.getString(5).equals("left")) {
                v.setGravity(Gravity.LEFT);
            } else {
                if (arr.getString(5).equals("fill")) {
                    v.setGravity(Gravity.FILL);
                } else {
                    v.setGravity(Gravity.CENTER);
                }
            }
            } else {
            v.setGravity(Gravity.LEFT);
            }
            v.setTypeface(((StarwispActivity)ctx).m_Typeface);*/
            parent.addView(v);
        }

        if (type.equals("web-view")) {
            WebView v = new WebView(ctx);
            v.setId(arr.getInt(1));
            v.setVerticalScrollBarEnabled(false);
            v.loadData(arr.getString(2), "text/html", "utf-8");
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3)));
            parent.addView(v);
        }

        if (type.equals("edit-text")) {
            final EditText v = new EditText(ctx);
            v.setId(arr.getInt(1));
            v.setText(arr.getString(2));
            v.setTextSize(arr.getInt(3));

            String inputtype = arr.getString(4);
            if (inputtype.equals("text")) {
                //v.setInputType(InputType.TYPE_CLASS_TEXT);
            } else if (inputtype.equals("numeric")) {
                v.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
            } else if (inputtype.equals("email")) {
                v.setInputType(InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS);
            }

            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(5)));
            v.setTypeface(((StarwispActivity) ctx).m_Typeface);
            final String fn = arr.getString(5);
            //v.setSingleLine(true);

            v.addTextChangedListener(new TextWatcher() {
                public void afterTextChanged(Editable s) {
                    CallbackArgs(ctx, ctxname, v.getId(), "\"" + s.toString() + "\"");
                }

                public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                }

                public void onTextChanged(CharSequence s, int start, int before, int count) {
                }
            });

            parent.addView(v);
        }

        if (type.equals("button")) {
            Button v = new Button(ctx);
            v.setId(arr.getInt(1));
            v.setText(arr.getString(2));
            v.setTextSize(arr.getInt(3));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4)));
            v.setTypeface(((StarwispActivity) ctx).m_Typeface);
            final String fn = arr.getString(5);
            v.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    Callback(ctx, ctxname, v.getId());
                }
            });

            parent.addView(v);
        }

        if (type.equals("toggle-button")) {
            ToggleButton v = new ToggleButton(ctx);
            if (arr.getString(5).equals("fancy")) {
                v = (ToggleButton) ctx.getLayoutInflater().inflate(R.layout.toggle_button_fancy, null);
            }

            if (arr.getString(5).equals("yes")) {
                v = (ToggleButton) ctx.getLayoutInflater().inflate(R.layout.toggle_button_yes, null);
            }

            if (arr.getString(5).equals("maybe")) {
                v = (ToggleButton) ctx.getLayoutInflater().inflate(R.layout.toggle_button_maybe, null);
            }

            if (arr.getString(5).equals("no")) {
                v = (ToggleButton) ctx.getLayoutInflater().inflate(R.layout.toggle_button_no, null);
            }

            v.setId(arr.getInt(1));
            v.setText(arr.getString(2));
            v.setTextSize(arr.getInt(3));
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4)));
            v.setTypeface(((StarwispActivity) ctx).m_Typeface);
            final String fn = arr.getString(6);
            v.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    String arg = "#f";
                    if (((ToggleButton) v).isChecked())
                        arg = "#t";
                    CallbackArgs(ctx, ctxname, v.getId(), arg);
                }
            });
            parent.addView(v);
        }

        if (type.equals("seek-bar")) {
            SeekBar v = new SeekBar(ctx);
            v.setId(arr.getInt(1));
            v.setMax(arr.getInt(2));
            v.setProgress(arr.getInt(2) / 2);
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3)));
            final String fn = arr.getString(4);

            v.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
                public void onProgressChanged(SeekBar v, int a, boolean s) {
                    CallbackArgs(ctx, ctxname, v.getId(), Integer.toString(a));
                }

                public void onStartTrackingTouch(SeekBar v) {
                }

                public void onStopTrackingTouch(SeekBar v) {
                }
            });
            parent.addView(v);
        }

        if (type.equals("spinner")) {
            Spinner v = new Spinner(ctx);
            final int wid = arr.getInt(1);
            v.setId(wid);
            final JSONArray items = arr.getJSONArray(2);
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3)));
            ArrayList<String> spinnerArray = new ArrayList<String>();

            for (int i = 0; i < items.length(); i++) {
                spinnerArray.add(items.getString(i));
            }

            ArrayAdapter spinnerArrayAdapter = new ArrayAdapter<String>(ctx, R.layout.spinner_item,
                    spinnerArray) {
                public View getView(int position, View convertView, ViewGroup parent) {
                    View v = super.getView(position, convertView, parent);
                    ((TextView) v).setTypeface(((StarwispActivity) ctx).m_Typeface);
                    return v;
                }
            };

            spinnerArrayAdapter.setDropDownViewResource(R.layout.spinner_layout);

            v.setAdapter(spinnerArrayAdapter);
            v.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                public void onItemSelected(AdapterView<?> a, View v, int pos, long id) {
                    try {
                        CallbackArgs(ctx, ctxname, wid, "\"" + items.getString(pos) + "\"");
                    } catch (JSONException e) {
                        Log.e("starwisp", "Error parsing data " + e.toString());
                    }
                }

                public void onNothingSelected(AdapterView<?> v) {
                }
            });

            parent.addView(v);
        }

        if (type.equals("canvas")) {
            StarwispCanvas v = new StarwispCanvas(ctx);
            final int wid = arr.getInt(1);
            v.setId(wid);
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
            v.SetDrawList(arr.getJSONArray(3));
            parent.addView(v);
        }

        if (type.equals("camera-preview")) {
            PictureTaker pt = new PictureTaker();
            CameraPreview v = new CameraPreview(ctx, pt);
            final int wid = arr.getInt(1);
            v.setId(wid);

            //              LinearLayout.LayoutParams lp =
            //  new LinearLayout.LayoutParams(minWidth, minHeight, 1);

            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));

            //                v.setLayoutParams(lp);
            parent.addView(v);
        }

        if (type.equals("button-grid")) {
            LinearLayout horiz = new LinearLayout(ctx);
            final int id = arr.getInt(1);
            final String buttontype = arr.getString(2);
            horiz.setId(id);
            horiz.setOrientation(LinearLayout.HORIZONTAL);
            parent.addView(horiz);
            int height = arr.getInt(3);
            int textsize = arr.getInt(4);
            LinearLayout.LayoutParams lp = BuildLayoutParams(arr.getJSONArray(5));
            JSONArray buttons = arr.getJSONArray(6);
            int count = buttons.length();
            int vertcount = 0;
            LinearLayout vert = null;

            for (int i = 0; i < count; i++) {
                JSONArray button = buttons.getJSONArray(i);

                if (vertcount == 0) {
                    vert = new LinearLayout(ctx);
                    vert.setId(0);
                    vert.setOrientation(LinearLayout.VERTICAL);
                    horiz.addView(vert);
                }
                vertcount = (vertcount + 1) % height;

                if (buttontype.equals("button")) {
                    Button b = new Button(ctx);
                    b.setId(button.getInt(0));
                    b.setText(button.getString(1));
                    b.setTextSize(textsize);
                    b.setLayoutParams(lp);
                    b.setTypeface(((StarwispActivity) ctx).m_Typeface);
                    final String fn = arr.getString(6);
                    b.setOnClickListener(new View.OnClickListener() {
                        public void onClick(View v) {
                            CallbackArgs(ctx, ctxname, id, "" + v.getId() + " #t");
                        }
                    });
                    vert.addView(b);
                } else if (buttontype.equals("toggle")) {
                    ToggleButton b = new ToggleButton(ctx);
                    b.setId(button.getInt(0));
                    b.setText(button.getString(1));
                    b.setTextSize(textsize);
                    b.setLayoutParams(lp);
                    b.setTypeface(((StarwispActivity) ctx).m_Typeface);
                    final String fn = arr.getString(6);
                    b.setOnClickListener(new View.OnClickListener() {
                        public void onClick(View v) {
                            String arg = "#f";
                            if (((ToggleButton) v).isChecked())
                                arg = "#t";
                            CallbackArgs(ctx, ctxname, id, "" + v.getId() + " " + arg);
                        }
                    });
                    vert.addView(b);
                }
            }
        }

    } catch (JSONException e) {
        Log.e("starwisp", "Error parsing [" + arr.toString() + "] " + e.toString());
    }

    //Log.i("starwisp","building ended");

}

From source file:org.navitproject.navit.Navit.java

@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
    switch (requestCode) {
    case MY_PERMISSIONS_REQUEST_ALL: {
        if (grantResults.length > 1 && grantResults[0] == PackageManager.PERMISSION_GRANTED
                && grantResults[1] == PackageManager.PERMISSION_GRANTED) {
            // ok, we got permissions
        } else {/*ww w  . j a v  a  2 s.  c om*/
            AlertDialog.Builder infobox = new AlertDialog.Builder(this);
            infobox.setTitle(getString(R.string.permissions_info_box_title)); // TRANS
            infobox.setCancelable(false);
            final TextView message = new TextView(this);
            message.setFadingEdgeLength(20);
            message.setVerticalFadingEdgeEnabled(true);
            RelativeLayout.LayoutParams rlp = new RelativeLayout.LayoutParams(
                    RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);
            message.setLayoutParams(rlp);
            final SpannableString s = new SpannableString(getString(R.string.permissions_not_granted)); // TRANS
            message.setText(s);
            message.setMovementMethod(LinkMovementMethod.getInstance());
            infobox.setView(message);
            // TRANS
            infobox.setPositiveButton(getString(R.string.initial_info_box_OK),
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface arg0, int arg1) {
                            exit();
                        }
                    });
            infobox.show();
        }
        return;
    }
    }
}