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:com.slushpupie.deskclock.DeskClock.java

protected Dialog onCreateDialog(int id) {
    switch (id) {
    case DIALOG_CHANGELOG:

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        // Standard AlertDialog does not support HTML-style links.
        // So rebuild the ScrollView->TextView with the appropriate
        // settings and set the view directly.
        TextView tv = new TextView(this);
        tv.setPadding(5, 5, 5, 5);/*w w w .  j a va2s.c o  m*/
        tv.setLinksClickable(true);
        tv.setMovementMethod(LinkMovementMethod.getInstance());
        tv.setText(R.string.changeLog);
        tv.setTextAppearance(this, android.R.style.TextAppearance_Medium);
        ScrollView sv = new ScrollView(this);
        sv.setPadding(14, 2, 10, 12);
        sv.addView(tv);
        builder.setView(sv).setCancelable(false).setTitle(R.string.changeLogTitle)
                .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(DeskClock.this);
                        SharedPreferences.Editor editor = prefs.edit();
                        editor.putBoolean("pref_changelog", false);
                        editor.putString("last_changelog", getString(R.string.app_version));
                        editor.commit();
                    }
                });
        return builder.create();
    default:
        return null;
    }
}

From source file:dcheungaa.procal.MainActivity.java

@SuppressWarnings("StatementWithEmptyBody")
@Override/*from   w  ww.  j  a v a  2 s  .  c om*/
@NonNull
public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.

    switch (item.getItemId()) {

    case R.id.nav_history:
        Intent intent = new Intent(MainActivity.context, HistoryActivity.class);
        startActivity(intent);
        return true;

    case R.id.nav_about:

        String credits = "<p>This piece of software used the work <a href=\"https://arxiv.org/abs/0908.3030v1\">\"A Java Math.BigDecimal Implementation of Core Mathematical Functions\" of Richard J. Mathar</a>, which was made available under the LGPL3.0 license as a library. As part of the obligations to the license, if the user wish to replace this library with their own, they may contact: <a href=\"mailto:dcheungaa@connect.ust.hk\">dcheungaa@connect.ust.hk</a></p>\n"
                + "\n" + "<p>Other code libraries used:</p>\n"
                + "<p><a href=\"https://github.com/atorstling/bychan\">Bychan</a><br>\n"
                + "<a href=\"https://github.com/evant/gradle-retrolambda\">Gradle-Retrolambda</a><br>\n"
                + "<a href=\"https://github.com/streamsupport/streamsupport\">SteamSupport</a></p>\n";

        final AlertDialog.Builder builder_add = new AlertDialog.Builder(MainActivity.this);
        builder_add.setTitle("About");
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        LinearLayout aboutLayout = (LinearLayout) inflater.inflate(R.layout.about_alert, null);
        builder_add.setView(aboutLayout);
        TextView aboutTextView = (TextView) aboutLayout.findViewById(R.id.about_content);
        aboutTextView.setText(Html.fromHtml(credits));
        aboutTextView.setMovementMethod(LinkMovementMethod.getInstance());

        builder_add.setPositiveButton("Close", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                dialog.dismiss();
            }
        });
        AlertDialog alert_add = builder_add.create();
        alert_add.show();
        return true;

    }

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}

From source file:de.mprengemann.hwr.timetabel.TimetableActivity.java

@SuppressWarnings("deprecation")
@Override/*from w ww  .j a va 2  s.  c o  m*/
protected Dialog onCreateDialog(int id) {

    AlertDialog.Builder builder;

    switch (id) {
    case NEW_TIMETABLEPLAN:
        builder = new AlertDialog.Builder(this);
        builder.setMessage(R.string.dialog_new_message);
        builder.setTitle(R.string.dialog_new_title);
        builder.setCancelable(false);
        builder.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                subjectFragment.clear();
                getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);

                refreshItem.setVisible(false);

                Parser p = new Parser(TimetableActivity.this, parsingListener);
                p.execute();
            }
        });
        builder.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(TimetableActivity.this);

                Calendar calendar = Calendar.getInstance();

                Editor edit = prefs.edit();
                edit.putLong(getString(R.string.prefs_lastUpdated_user), calendar.getTimeInMillis());

                calendar.set(Calendar.HOUR_OF_DAY, 0);
                calendar.set(Calendar.MINUTE, 0);
                calendar.set(Calendar.SECOND, 0);
                calendar.set(Calendar.MILLISECOND, 0);

                edit.putLong(getString(R.string.prefs_lastUpdated), calendar.getTimeInMillis());
                edit.commit();

                dialog.cancel();
            }
        });
        return builder.create();
    case LICENSE_DIALOG:
        builder = new AlertDialog.Builder(this);

        TextView textView = new TextView(this);
        textView.setMovementMethod(LinkMovementMethod.getInstance());
        textView.setText(R.string.text_license);
        textView.setLinksClickable(true);
        textView.setPadding(10, 10, 10, 10);

        builder.setView(textView);
        builder.setTitle(R.string.menu_license);
        builder.setCancelable(true);
        builder.setNeutralButton(android.R.string.ok, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();
            }
        });
        return builder.create();
    default:
        return super.onCreateDialog(id);
    }
}

From source file:com.google.reviewit.ServerSettingsFragment.java

private void displayCredentialsInfo(String url) {
    if (Strings.isNullOrEmpty(url)) {
        setGone(v(R.id.crendentialsInfo, R.id.credentialsInfoText, R.id.pasteCredentialsButton));
        return;//from  w  w w  .  j  a  va2  s . c  o  m
    }

    TextView credentialsInfo = (TextView) v(R.id.credentialsInfoText);
    credentialsInfo.setMovementMethod(LinkMovementMethod.getInstance());
    url = FormatUtil.ensureSlash(url);

    String host;
    try {
        host = new URL(url).getHost();
    } catch (MalformedURLException e) {
        setGone(v(R.id.crendentialsInfo, R.id.credentialsInfoText, R.id.pasteCredentialsButton));
        return;
    }

    if (host.endsWith(".googlesource.com")) {
        url += "new-password";
        credentialsInfo.setText(Html.fromHtml(getString(R.string.credentials_info_googlesource,
                createLink(url, getString(R.string.googlesource_obtain_password)))));
        setVisible(v(R.id.crendentialsInfo, R.id.credentialsInfoText, R.id.pasteCredentialsButton));
    } else {
        url += "#/settings/http-password";
        credentialsInfo.setText(Html.fromHtml(
                getString(R.string.credentials_info, createLink(url, getString(R.string.http_password)))));
        setGone(v(R.id.pasteCredentialsButton));
        setVisible(v(R.id.crendentialsInfo, R.id.credentialsInfoText));
    }
}

From source file:gr.scify.newsum.ui.SearchViewActivity.java

private void initTopicSpinner() {
    // Get topics in category. Null accepts all user sources. Modify
    // according to user selection
    final String[] saTopicIDs = SearchTopicActivity.saTopicIDs;
    final String[] saTitles = SearchTopicActivity.saTopicTitles;
    final String[] saDates = SearchTopicActivity.saTopicDates;
    // TODO add TopicInfo for SearchResults as well and parse accordingly

    // final String[] saTopicIDs = extras.getStringArray("searchresults");
    final TextView title = (TextView) findViewById(R.id.title);
    // Fill topic spinner
    ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(this,
            android.R.layout.simple_spinner_item, saTitles);

    final TextView tx = (TextView) findViewById(R.id.textView1);
    // tx.setMovementMethod(LinkMovementMethod.getInstance());
    //      final float minm = tx.getTextSize();
    //      final float maxm = (minm + 24);

    // create an invisible spinner just to control the summaries of the
    // category (i will use it later on Swipe)
    Spinner spinner = (Spinner) findViewById(R.id.spinner1);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);// w  ww  .  j  a va 2s . c o m

    // Scroll view init
    final ScrollView scroll = (ScrollView) findViewById(R.id.scrollView1);
    // Add selection event
    spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
        public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {

            // Show waiting dialog
            showWaitingDialog();

            // Changing summary
            loading = true;
            // Update visibility of rating bar
            final RatingBar rb = (RatingBar) findViewById(R.id.ratingBar);
            rb.setRating(0.0f);
            rb.setVisibility(View.VISIBLE);
            final TextView rateLbl = (TextView) findViewById(R.id.rateLbl);
            rateLbl.setVisibility(View.VISIBLE);

            scroll.scrollTo(0, 0);
            //            String[] saTopicIDs = sTopicIds.split(sSeparator);

            SharedPreferences settings = getSharedPreferences("urls", 0);
            // get user settings for sources
            String UserSources = settings.getString("UserLinks", "All");
            String[] Summary = NewSumServiceClient.getSummary(saTopicIDs[arg2], UserSources);
            if (Summary.length == 0) { // WORK. Updated: CHECK
                // Close waiting dialog
                closeWaitingDialog();

                AlertDialog.Builder alert = new AlertDialog.Builder(SearchViewActivity.this);
                alert.setMessage(R.string.shouldReloadSummaries);
                alert.setNeutralButton("Ok", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface arg0, int arg1) {
                        startActivity(new Intent(getApplicationContext(), NewSumUiActivity.class)
                                .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
                    }
                });
                alert.setCancelable(false);
                alert.show();
                loading = false;
                return;
            }
            // track summary views per Search and topic title
            if (getAnalyticsPref()) {
                EasyTracker.getTracker().sendEvent(VIEW_SUMMARY_ACTION, "From Search",
                        saTitles[arg2] + ": " + saDates[arg2], 0l);
            }
            // Generate summary text
            sText = ViewActivity.generateSummaryText(Summary, SearchViewActivity.this);
            pText = ViewActivity.generatesummarypost(Summary, SearchViewActivity.this);
            tx.setText(Html.fromHtml(sText));
            tx.setMovementMethod(LinkMovementMethod.getInstance());
            title.setText(saTitles[arg2] + ": " + saDates[arg2]);
            float defSize = tx.getTextSize();
            SharedPreferences usersize = getSharedPreferences("textS", 0);
            float newSize = usersize.getFloat("size", defSize);
            tx.setTextSize(TypedValue.COMPLEX_UNIT_PX, newSize);
            // update the TopicActivity with viewed item
            TopicActivity.addVisitedTopicID(saTopicIDs[arg2]);

            // Close waiting dialog
            closeWaitingDialog();

        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
        }

    });

}

From source file:com.master.metehan.filtereagle.ActivityMain.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    Log.i(TAG, "Create version=" + Util.getSelfVersionName(this) + "/" + Util.getSelfVersionCode(this));
    Util.logExtras(getIntent());//from   www.j  ava  2  s. c o  m

    if (Build.VERSION.SDK_INT < MIN_SDK) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.android);
        return;
    }

    Util.setTheme(this);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    running = true;

    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    boolean enabled = prefs.getBoolean("enabled", false);
    boolean initialized = prefs.getBoolean("initialized", false);
    SharedPreferences.Editor editor = prefs.edit();
    editor.putBoolean("registered", true).commit();
    editor.putBoolean("logged", false).commit();
    prefs.edit().remove("hint_system").apply();

    // Register app
    String key = this.getString(R.string.app_key);
    String server_url = this.getString(R.string.serverurl);
    Register register = new Register(server_url, key, getApplicationContext());
    register.registerApp();

    // Upgrade
    Receiver.upgrade(initialized, this);

    if (!getIntent().hasExtra(EXTRA_APPROVE)) {
        if (enabled)
            ServiceSinkhole.start("UI", this);
        else
            ServiceSinkhole.stop("UI", this);
    }

    // Action bar
    final View actionView = getLayoutInflater().inflate(R.layout.actionmain, null, false);
    ivIcon = (ImageView) actionView.findViewById(R.id.ivIcon);
    ivQueue = (ImageView) actionView.findViewById(R.id.ivQueue);
    swEnabled = (SwitchCompat) actionView.findViewById(R.id.swEnabled);
    ivMetered = (ImageView) actionView.findViewById(R.id.ivMetered);

    // Icon
    ivIcon.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View view) {
            menu_about();
            return true;
        }
    });

    // Title
    getSupportActionBar().setTitle(null);

    // Netguard is busy
    ivQueue.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View view) {
            int location[] = new int[2];
            actionView.getLocationOnScreen(location);
            Toast toast = Toast.makeText(ActivityMain.this, R.string.msg_queue, Toast.LENGTH_LONG);
            toast.setGravity(Gravity.TOP | Gravity.LEFT, location[0] + ivQueue.getLeft(),
                    Math.round(location[1] + ivQueue.getBottom() - toast.getView().getPaddingTop()));
            toast.show();
            return true;
        }
    });

    // On/off switch
    swEnabled.setChecked(enabled);
    swEnabled.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            Log.i(TAG, "Switch=" + isChecked);
            prefs.edit().putBoolean("enabled", isChecked).apply();

            if (isChecked) {
                try {
                    final Intent prepare = VpnService.prepare(ActivityMain.this);
                    if (prepare == null) {
                        Log.i(TAG, "Prepare done");
                        onActivityResult(REQUEST_VPN, RESULT_OK, null);
                    } else {
                        // Show dialog
                        LayoutInflater inflater = LayoutInflater.from(ActivityMain.this);
                        View view = inflater.inflate(R.layout.vpn, null, false);
                        dialogVpn = new AlertDialog.Builder(ActivityMain.this).setView(view)
                                .setCancelable(false)
                                .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        if (running) {
                                            Log.i(TAG, "Start intent=" + prepare);
                                            try {
                                                // com.android.vpndialogs.ConfirmDialog required
                                                startActivityForResult(prepare, REQUEST_VPN);
                                            } catch (Throwable ex) {
                                                Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                                                Util.sendCrashReport(ex, ActivityMain.this);
                                                onActivityResult(REQUEST_VPN, RESULT_CANCELED, null);
                                                prefs.edit().putBoolean("enabled", false).apply();
                                            }
                                        }
                                    }
                                }).setOnDismissListener(new DialogInterface.OnDismissListener() {
                                    @Override
                                    public void onDismiss(DialogInterface dialogInterface) {
                                        dialogVpn = null;
                                    }
                                }).create();
                        dialogVpn.show();
                    }
                } catch (Throwable ex) {
                    // Prepare failed
                    Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                    Util.sendCrashReport(ex, ActivityMain.this);
                    prefs.edit().putBoolean("enabled", false).apply();
                }

            } else
                ServiceSinkhole.stop("switch off", ActivityMain.this);
        }
    });
    if (enabled)
        checkDoze();

    // Network is metered
    ivMetered.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View view) {
            int location[] = new int[2];
            actionView.getLocationOnScreen(location);
            Toast toast = Toast.makeText(ActivityMain.this, R.string.msg_metered, Toast.LENGTH_LONG);
            toast.setGravity(Gravity.TOP | Gravity.LEFT, location[0] + ivMetered.getLeft(),
                    Math.round(location[1] + ivMetered.getBottom() - toast.getView().getPaddingTop()));
            toast.show();
            return true;
        }
    });

    getSupportActionBar().setDisplayShowCustomEnabled(true);
    getSupportActionBar().setCustomView(actionView);

    // Disabled warning
    TextView tvDisabled = (TextView) findViewById(R.id.tvDisabled);
    tvDisabled.setVisibility(enabled ? View.GONE : View.VISIBLE);

    // Application list
    RecyclerView rvApplication = (RecyclerView) findViewById(R.id.rvApplication);
    rvApplication.setHasFixedSize(true);
    rvApplication.setLayoutManager(new LinearLayoutManager(this));
    adapter = new AdapterRule(this);
    rvApplication.setAdapter(adapter);

    // Swipe to refresh
    TypedValue tv = new TypedValue();
    getTheme().resolveAttribute(R.attr.colorPrimary, tv, true);
    swipeRefresh = (SwipeRefreshLayout) findViewById(R.id.swipeRefresh);
    swipeRefresh.setColorSchemeColors(Color.WHITE, Color.WHITE, Color.WHITE);
    swipeRefresh.setProgressBackgroundColorSchemeColor(tv.data);
    swipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            Rule.clearCache(ActivityMain.this);
            ServiceSinkhole.reload("pull", ActivityMain.this);
            updateApplicationList(null);
        }
    });

    final LinearLayout llSystem = (LinearLayout) findViewById(R.id.llSystem);
    Button btnSystem = (Button) findViewById(R.id.btnSystem);
    boolean system = prefs.getBoolean("manage_system", false);
    boolean hint = prefs.getBoolean("hint_system", true);
    llSystem.setVisibility(!system && hint ? View.VISIBLE : View.GONE);
    btnSystem.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            prefs.edit().putBoolean("hint_system", false).apply();
            llSystem.setVisibility(View.GONE);
        }
    });

    // Listen for preference changes
    prefs.registerOnSharedPreferenceChangeListener(this);

    // Listen for rule set changes
    IntentFilter ifr = new IntentFilter(ACTION_RULES_CHANGED);
    LocalBroadcastManager.getInstance(this).registerReceiver(onRulesChanged, ifr);

    // Listen for queue changes
    IntentFilter ifq = new IntentFilter(ACTION_QUEUE_CHANGED);
    LocalBroadcastManager.getInstance(this).registerReceiver(onQueueChanged, ifq);

    // Listen for added/removed applications
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
    intentFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
    intentFilter.addDataScheme("package");
    registerReceiver(packageChangedReceiver, intentFilter);

    // First use
    if (!initialized) {
        // Create view
        LayoutInflater inflater = LayoutInflater.from(this);
        View view = inflater.inflate(R.layout.first, null, false);
        TextView tvFirst = (TextView) view.findViewById(R.id.tvFirst);
        tvFirst.setMovementMethod(LinkMovementMethod.getInstance());

        // Show dialog
        dialogFirst = new AlertDialog.Builder(this).setView(view).setCancelable(false)
                .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        if (running)
                            prefs.edit().putBoolean("initialized", true).apply();
                    }
                }).setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        if (running)
                            finish();
                    }
                }).setOnDismissListener(new DialogInterface.OnDismissListener() {
                    @Override
                    public void onDismiss(DialogInterface dialogInterface) {
                        dialogFirst = null;
                    }
                }).create();
        dialogFirst.show();
    }

    // Fill application list
    updateApplicationList(getIntent().getStringExtra(EXTRA_SEARCH));

    // Update IAB SKUs
    try {
        iab = new IAB(new IAB.Delegate() {
            @Override
            public void onReady(IAB iab) {
                try {
                    iab.updatePurchases();

                    if (!IAB.isPurchased(ActivityPro.SKU_LOG, ActivityMain.this))
                        prefs.edit().putBoolean("log", false).apply();
                    if (!IAB.isPurchased(ActivityPro.SKU_THEME, ActivityMain.this)) {
                        if (!"teal".equals(prefs.getString("theme", "teal")))
                            prefs.edit().putString("theme", "teal").apply();
                    }
                    if (!IAB.isPurchased(ActivityPro.SKU_SPEED, ActivityMain.this))
                        prefs.edit().putBoolean("show_stats", false).apply();
                } catch (Throwable ex) {
                    Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                } finally {
                    iab.unbind();
                }
            }
        }, this);
        iab.bind();
    } catch (Throwable ex) {
        Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
    }

    checkExtras(getIntent());
}

From source file:net.gsantner.opoc.util.ContextUtils.java

/**
 * Load html into a {@link Spanned} object and set the
 * {@link TextView}'s text using {@link TextView#setText(CharSequence)}
 *//*from w w w .j  av  a  2  s. c  o  m*/
public void setHtmlToTextView(TextView textView, String html) {
    textView.setMovementMethod(LinkMovementMethod.getInstance());
    textView.setText(new SpannableString(htmlToSpanned(html)));
}

From source file:com.yeldi.yeldibazaar.AppDetails.java

private void startViews() {

    // Populate the list...
    ApkListAdapter la = (ApkListAdapter) getListAdapter();
    for (DB.Apk apk : app.apks)
        la.addItem(apk);// w w w. java  2  s .co m
    la.notifyDataSetChanged();

    // Insert the 'infoView' (which contains the summary, various odds and
    // ends, and the description) into the appropriate place, if we're in
    // landscape mode. In portrait mode, we put it in the listview's
    // header..
    infoView = View.inflate(this, R.layout.appinfo, null);
    LinearLayout landparent = (LinearLayout) findViewById(R.id.landleft);
    headerView.removeAllViews();
    if (landparent != null) {
        landparent.addView(infoView);
        Log.d("FDroid", "Setting landparent infoview");
    } else {
        headerView.addView(infoView);
        Log.d("FDroid", "Setting header infoview");
    }

    // Set the icon...
    ImageView iv = (ImageView) findViewById(R.id.icon);
    File icon = new File(DB.getIconsPath(this), app.icon);
    if (icon.exists()) {
        iv.setImageDrawable(new BitmapDrawable(icon.getPath()));
    } else {
        iv.setImageResource(android.R.drawable.sym_def_app_icon);
    }

    // Set the title and other header details...
    TextView tv = (TextView) findViewById(R.id.title);
    tv.setText(app.name);
    tv = (TextView) findViewById(R.id.license);
    tv.setText(app.license);
    tv = (TextView) findViewById(R.id.status);

    tv = (TextView) infoView.findViewById(R.id.description);

    /*
     * The following is a quick solution to enable both text selection and
     * links. Causes glitches and crashes:
     * java.lang.IndexOutOfBoundsException: setSpan (-1 ... -1) starts
     * before 0
     * 
     * class CustomMovementMethod extends LinkMovementMethod {
     * 
     * @Override public boolean canSelectArbitrarily () { return true; } }
     * 
     * if (Utils.hasApi(11)) { tv.setTextIsSelectable(true);
     * tv.setMovementMethod(new CustomMovementMethod()); } else {
     * tv.setMovementMethod(LinkMovementMethod.getInstance()); }
     */

    tv.setMovementMethod(LinkMovementMethod.getInstance());

    // Need this to add the unimplemented support for ordered and unordered
    // lists to Html.fromHtml().
    class HtmlTagHandler implements TagHandler {
        int listNum;

        @Override
        public void handleTag(boolean opening, String tag, Editable output, XMLReader reader) {
            if (opening && tag.equals("ul")) {
                listNum = -1;
            } else if (opening && tag.equals("ol")) {
                listNum = 1;
            } else if (tag.equals("li")) {
                if (opening) {
                    if (listNum == -1) {
                        output.append("\t");
                    } else {
                        output.append("\t" + Integer.toString(listNum) + ". ");
                        listNum++;
                    }
                } else {
                    output.append('\n');
                }
            }
        }
    }
    tv.setText(Html.fromHtml(app.detail_description, null, new HtmlTagHandler()));

    tv = (TextView) infoView.findViewById(R.id.appid);
    tv.setText(app.id);

    tv = (TextView) infoView.findViewById(R.id.summary);
    tv.setText(app.summary);

    if (!app.apks.isEmpty()) {
        tv = (TextView) infoView.findViewById(R.id.permissions_list);

        CommaSeparatedList permsList = app.apks.get(0).detail_permissions;
        if (permsList == null) {
            tv.setText(getString(R.string.no_permissions) + '\n');
        } else {
            Iterator<String> permissions = permsList.iterator();
            StringBuilder sb = new StringBuilder();
            while (permissions.hasNext()) {
                String permissionName = permissions.next();
                try {
                    Permission permission = new Permission(this, permissionName);
                    sb.append("\t " + permission.getName() + '\n');
                } catch (NameNotFoundException e) {
                    Log.d("FDroid", "Can't find permission '" + permissionName + "'");
                }
            }
            tv.setText(sb.toString());
        }
        tv = (TextView) infoView.findViewById(R.id.permissions);
        tv.setText(getString(R.string.permissions_for_long, app.apks.get(0).version));
    }
}

From source file:io.github.hidroh.materialistic.ItemActivity.java

@SuppressWarnings("ConstantConditions")
private void bindData(@Nullable final WebItem story) {
    if (story == null) {
        return;//from  ww w.  j a  va2s.  c o m
    }
    mCustomTabsDelegate.mayLaunchUrl(Uri.parse(story.getUrl()), null, null);
    bindFavorite();
    mSessionManager.view(this, story.getId());
    mVoteButton.setVisibility(View.VISIBLE);
    mVoteButton.setOnClickListener(v -> vote(story));
    final TextView titleTextView = (TextView) findViewById(android.R.id.text2);
    if (story.isStoryType()) {
        titleTextView.setText(story.getDisplayedTitle());
        setTaskTitle(story.getDisplayedTitle());
        if (!TextUtils.isEmpty(story.getSource())) {
            TextView sourceTextView = (TextView) findViewById(R.id.source);
            sourceTextView.setText(story.getSource());
            sourceTextView.setVisibility(View.VISIBLE);
        }
    } else {
        CharSequence title = AppUtils.fromHtml(story.getDisplayedTitle());
        titleTextView.setText(title);
        setTaskTitle(title);
    }

    final TextView postedTextView = (TextView) findViewById(R.id.posted);
    postedTextView.setText(story.getDisplayedTime(this));
    postedTextView.append(story.getDisplayedAuthor(this, true, 0));
    postedTextView.setMovementMethod(LinkMovementMethod.getInstance());
    switch (story.getType()) {
    case Item.JOB_TYPE:
        postedTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_work_white_18dp, 0, 0, 0);
        break;
    case Item.POLL_TYPE:
        postedTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_poll_white_18dp, 0, 0, 0);
        break;
    }
    mAdapter = new ItemPagerAdapter(this, getSupportFragmentManager(),
            new ItemPagerAdapter.Builder().setItem(story).setShowArticle(!mExternalBrowser)
                    .setCacheMode(getIntent().getIntExtra(EXTRA_CACHE_MODE, ItemManager.MODE_DEFAULT))
                    .setDefaultViewMode(mStoryViewMode));
    mAdapter.bind(mViewPager, mTabLayout, mNavButton, mReplyButton);
    mTabLayout.addOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(mViewPager) {
        @Override
        public void onTabReselected(TabLayout.Tab tab) {
            mAppBar.setExpanded(true, true);
        }
    });
    if (story.isStoryType() && mExternalBrowser) {
        findViewById(R.id.header_card_view)
                .setOnClickListener(v -> AppUtils.openWebUrlExternal(ItemActivity.this, story, story.getUrl(),
                        mCustomTabsDelegate.getSession()));
    } else {
        findViewById(R.id.header_card_view).setClickable(false);
    }
    if (mFullscreen) {
        setFullscreen();
    }
}

From source file:foam.jellyfish.StarwispBuilder.java

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

    try {/*from www.jav a2 s.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("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)));
            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_NUMBER_FLAG_DECIMAL | 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);
            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) {
                    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,
                    android.R.layout.simple_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;
                }
            };

            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("nomadic")) {
            final int wid = arr.getInt(1);
            NomadicSurfaceView v = new NomadicSurfaceView(ctx, wid);
            v.setId(wid);
            v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));

            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");

}