Example usage for android.widget TextView setVisibility

List of usage examples for android.widget TextView setVisibility

Introduction

In this page you can find the example usage for android.widget TextView setVisibility.

Prototype

@RemotableViewMethod
public void setVisibility(@Visibility int visibility) 

Source Link

Document

Set the visibility state of this view.

Usage

From source file:com.granita.tasks.TaskListFragment.java

@Override
public void onFlingStart(ListView listView, View listElement, int position, int direction) {

    // control the visibility of the views that reveal behind a flinging element regarding the fling direction
    int rightFlingViewId = mGroupDescriptor.getElementViewDescriptor().getFlingRevealRightViewId();
    int leftFlingViewId = mGroupDescriptor.getElementViewDescriptor().getFlingRevealLeftViewId();
    TextView rightFlingView = null;
    TextView leftFlingView = null;//from   ww  w.  j a  va  2  s  .  c  o  m

    if (rightFlingViewId != -1) {
        rightFlingView = (TextView) listElement.findViewById(rightFlingViewId);
    }
    if (leftFlingViewId != -1) {
        leftFlingView = (TextView) listElement.findViewById(leftFlingViewId);
    }

    Resources resources = getActivity().getResources();

    // change title and icon regarding the task status
    long packedPos = mExpandableListView.getExpandableListPosition(position);
    if (ExpandableListView.getPackedPositionType(packedPos) == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
        ExpandableListAdapter listAdapter = mExpandableListView.getExpandableListAdapter();
        Cursor cursor = (Cursor) listAdapter.getChild(ExpandableListView.getPackedPositionGroup(packedPos),
                ExpandableListView.getPackedPositionChild(packedPos));

        if (cursor != null) {
            int taskStatus = cursor.getInt(cursor.getColumnIndex(Instances.STATUS));
            if (leftFlingView != null && rightFlingView != null) {
                if (taskStatus == Instances.STATUS_COMPLETED) {
                    leftFlingView.setText(R.string.fling_task_delete);
                    leftFlingView.setCompoundDrawablesWithIntrinsicBounds(
                            resources.getDrawable(R.drawable.content_discard), null, null, null);
                    rightFlingView.setText(R.string.fling_task_uncomplete);
                    rightFlingView.setCompoundDrawablesWithIntrinsicBounds(null, null,
                            resources.getDrawable(R.drawable.content_remove_light), null);
                } else {
                    leftFlingView.setText(R.string.fling_task_complete);
                    leftFlingView.setCompoundDrawablesWithIntrinsicBounds(
                            resources.getDrawable(R.drawable.ic_action_complete), null, null, null);
                    rightFlingView.setText(R.string.fling_task_edit);
                    rightFlingView.setCompoundDrawablesWithIntrinsicBounds(null, null,
                            resources.getDrawable(R.drawable.content_edit), null);
                }
            }
        }
    }

    if (rightFlingView != null) {
        rightFlingView.setVisibility(direction != FlingDetector.LEFT_FLING ? View.GONE : View.VISIBLE);
    }
    if (leftFlingView != null) {
        leftFlingView.setVisibility(direction != FlingDetector.RIGHT_FLING ? View.GONE : View.VISIBLE);
    }

}

From source file:com.initialxy.cordova.themeablebrowser.ThemeableBrowser.java

/**
 * Display a new browser with the specified URL.
 *
 * @param url//from w  w w .  j  a  va 2s .c o m
 * @param features
 * @return
 */
public String showWebPage(final String url, final Options features) {
    final CordovaWebView thatWebView = this.webView;

    // Create dialog in new thread
    Runnable runnable = new Runnable() {
        @SuppressLint("NewApi")
        public void run() {
            // Let's create the main dialog
            dialog = new ThemeableBrowserDialog(cordova.getActivity(), android.R.style.Theme_Black_NoTitleBar,
                    features.hardwareback);
            if (!features.disableAnimation) {
                dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog;
            }
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setCancelable(true);
            dialog.setThemeableBrowser(getThemeableBrowser());

            // Main container layout
            ViewGroup main = null;

            if (features.fullscreen) {
                main = new FrameLayout(cordova.getActivity());
            } else {
                main = new LinearLayout(cordova.getActivity());
                ((LinearLayout) main).setOrientation(LinearLayout.VERTICAL);
            }

            // Toolbar layout
            Toolbar toolbarDef = features.toolbar;
            FrameLayout toolbar = new FrameLayout(cordova.getActivity());
            toolbar.setBackgroundColor(hexStringToColor(
                    toolbarDef != null && toolbarDef.color != null ? toolbarDef.color : "#ffffffff"));
            toolbar.setLayoutParams(new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT,
                    dpToPixels(toolbarDef != null ? toolbarDef.height : TOOLBAR_DEF_HEIGHT)));

            if (toolbarDef != null && (toolbarDef.image != null || toolbarDef.wwwImage != null)) {
                try {
                    Drawable background = getImage(toolbarDef.image, toolbarDef.wwwImage,
                            toolbarDef.wwwImageDensity);
                    setBackground(toolbar, background);
                } catch (Resources.NotFoundException e) {
                    emitError(ERR_LOADFAIL,
                            String.format("Image for toolbar, %s, failed to load", toolbarDef.image));
                } catch (IOException ioe) {
                    emitError(ERR_LOADFAIL,
                            String.format("Image for toolbar, %s, failed to load", toolbarDef.wwwImage));
                }
            }

            // Left Button Container layout
            LinearLayout leftButtonContainer = new LinearLayout(cordova.getActivity());
            FrameLayout.LayoutParams leftButtonContainerParams = new FrameLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            leftButtonContainerParams.gravity = Gravity.LEFT | Gravity.CENTER_VERTICAL;
            leftButtonContainer.setLayoutParams(leftButtonContainerParams);
            leftButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL);

            // Right Button Container layout
            LinearLayout rightButtonContainer = new LinearLayout(cordova.getActivity());
            FrameLayout.LayoutParams rightButtonContainerParams = new FrameLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            rightButtonContainerParams.gravity = Gravity.RIGHT | Gravity.CENTER_VERTICAL;
            rightButtonContainer.setLayoutParams(rightButtonContainerParams);
            rightButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL);

            // Edit Text Box
            edittext = new EditText(cordova.getActivity());
            RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
            textLayoutParams.addRule(RelativeLayout.RIGHT_OF, 1);
            textLayoutParams.addRule(RelativeLayout.LEFT_OF, 5);
            edittext.setLayoutParams(textLayoutParams);
            edittext.setSingleLine(true);
            edittext.setText(url);
            edittext.setInputType(InputType.TYPE_TEXT_VARIATION_URI);
            edittext.setImeOptions(EditorInfo.IME_ACTION_GO);
            edittext.setInputType(InputType.TYPE_NULL); // Will not except input... Makes the text NON-EDITABLE
            edittext.setOnKeyListener(new View.OnKeyListener() {
                public boolean onKey(View v, int keyCode, KeyEvent event) {
                    // If the event is a key-down event on the "enter" button
                    if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                        navigate(edittext.getText().toString());
                        return true;
                    }
                    return false;
                }
            });

            // Back button
            final Button back = createButton(features.backButton, "back button", new View.OnClickListener() {
                public void onClick(View v) {
                    emitButtonEvent(features.backButton, inAppWebView.getUrl());

                    if (features.backButtonCanClose && !canGoBack()) {
                        closeDialog();
                    } else {
                        goBack();
                    }
                }
            });

            if (back != null) {
                back.setEnabled(features.backButtonCanClose);
            }

            // Forward button
            final Button forward = createButton(features.forwardButton, "forward button",
                    new View.OnClickListener() {
                        public void onClick(View v) {
                            emitButtonEvent(features.forwardButton, inAppWebView.getUrl());

                            goForward();
                        }
                    });

            if (forward != null) {
                forward.setEnabled(false);
            }

            // Close/Done button
            Button close = createButton(features.closeButton, "close button", new View.OnClickListener() {
                public void onClick(View v) {
                    emitButtonEvent(features.closeButton, inAppWebView.getUrl());
                    closeDialog();
                }
            });

            // Menu button
            Spinner menu = features.menu != null ? new MenuSpinner(cordova.getActivity()) : null;
            if (menu != null) {
                menu.setLayoutParams(
                        new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
                menu.setContentDescription("menu button");
                setButtonImages(menu, features.menu, DISABLED_ALPHA);

                // We are not allowed to use onClickListener for Spinner, so we will use
                // onTouchListener as a fallback.
                menu.setOnTouchListener(new View.OnTouchListener() {
                    @Override
                    public boolean onTouch(View v, MotionEvent event) {
                        if (event.getAction() == MotionEvent.ACTION_UP) {
                            emitButtonEvent(features.menu, inAppWebView.getUrl());
                        }
                        return false;
                    }
                });

                if (features.menu.items != null) {
                    HideSelectedAdapter<EventLabel> adapter = new HideSelectedAdapter<EventLabel>(
                            cordova.getActivity(), android.R.layout.simple_spinner_item, features.menu.items);
                    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                    menu.setAdapter(adapter);
                    menu.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                        @Override
                        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
                            if (inAppWebView != null && i < features.menu.items.length) {
                                emitButtonEvent(features.menu.items[i], inAppWebView.getUrl(), i);
                            }
                        }

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

            // Title
            final TextView title = features.title != null ? new TextView(cordova.getActivity()) : null;
            final TextView subtitle = features.title != null ? new TextView(cordova.getActivity()) : null;
            if (title != null) {
                FrameLayout.LayoutParams titleParams = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                        LayoutParams.FILL_PARENT);
                titleParams.gravity = Gravity.CENTER;
                title.setLayoutParams(titleParams);
                title.setSingleLine();
                title.setEllipsize(TextUtils.TruncateAt.END);
                title.setGravity(Gravity.CENTER | Gravity.TOP);
                title.setTextColor(
                        hexStringToColor(features.title.color != null ? features.title.color : "#000000ff"));
                title.setTypeface(title.getTypeface(), Typeface.BOLD);
                title.setTextSize(TypedValue.COMPLEX_UNIT_PT, 8);

                FrameLayout.LayoutParams subtitleParams = new FrameLayout.LayoutParams(
                        LayoutParams.MATCH_PARENT, LayoutParams.FILL_PARENT);
                titleParams.gravity = Gravity.CENTER;
                subtitle.setLayoutParams(subtitleParams);
                subtitle.setSingleLine();
                subtitle.setEllipsize(TextUtils.TruncateAt.END);
                subtitle.setGravity(Gravity.CENTER | Gravity.BOTTOM);
                subtitle.setTextColor(hexStringToColor(
                        features.title.subColor != null ? features.title.subColor : "#000000ff"));
                subtitle.setTextSize(TypedValue.COMPLEX_UNIT_PT, 6);
                subtitle.setVisibility(View.GONE);

                if (features.title.staticText != null) {
                    title.setGravity(Gravity.CENTER);
                    title.setText(features.title.staticText);
                } else {
                    subtitle.setVisibility(View.VISIBLE);
                }
            }

            // WebView
            inAppWebView = new WebView(cordova.getActivity());
            final ViewGroup.LayoutParams inAppWebViewParams = features.fullscreen
                    ? new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)
                    : new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 0);
            if (!features.fullscreen) {
                ((LinearLayout.LayoutParams) inAppWebViewParams).weight = 1;
            }
            inAppWebView.setLayoutParams(inAppWebViewParams);
            inAppWebView.setWebChromeClient(new InAppChromeClient(thatWebView));
            WebViewClient client = new ThemeableBrowserClient(thatWebView, new PageLoadListener() {

                @Override
                public void onPageStarted(String url) {
                    if (inAppWebView != null && title != null && features.title != null
                            && features.title.staticText == null && features.title.showPageTitle
                            && features.title.loadingText != null) {
                        title.setText(features.title.loadingText);
                        subtitle.setText(url);
                    }
                }

                @Override
                public void onPageFinished(String url, boolean canGoBack, boolean canGoForward) {
                    if (inAppWebView != null && title != null && features.title != null
                            && features.title.staticText == null && features.title.showPageTitle) {
                        title.setText(inAppWebView.getTitle());
                        subtitle.setText(inAppWebView.getUrl());
                    }

                    if (back != null) {
                        back.setEnabled(canGoBack || features.backButtonCanClose);
                    }

                    if (forward != null) {
                        forward.setEnabled(canGoForward);
                    }
                }
            });
            inAppWebView.setWebViewClient(client);
            WebSettings settings = inAppWebView.getSettings();
            settings.setJavaScriptEnabled(true);
            settings.setJavaScriptCanOpenWindowsAutomatically(true);
            settings.setBuiltInZoomControls(features.zoom);
            settings.setDisplayZoomControls(false);
            settings.setPluginState(android.webkit.WebSettings.PluginState.ON);

            //Toggle whether this is enabled or not!
            Bundle appSettings = cordova.getActivity().getIntent().getExtras();
            boolean enableDatabase = appSettings == null
                    || appSettings.getBoolean("ThemeableBrowserStorageEnabled", true);
            if (enableDatabase) {
                String databasePath = cordova.getActivity().getApplicationContext()
                        .getDir("themeableBrowserDB", Context.MODE_PRIVATE).getPath();
                settings.setDatabasePath(databasePath);
                settings.setDatabaseEnabled(true);
            }
            settings.setDomStorageEnabled(true);

            if (features.clearcache) {
                CookieManager.getInstance().removeAllCookie();
            } else if (features.clearsessioncache) {
                CookieManager.getInstance().removeSessionCookie();
            }

            inAppWebView.loadUrl(url);
            inAppWebView.getSettings().setLoadWithOverviewMode(true);
            inAppWebView.getSettings().setUseWideViewPort(true);
            inAppWebView.requestFocus();
            inAppWebView.requestFocusFromTouch();

            // Add buttons to either leftButtonsContainer or
            // rightButtonsContainer according to user's alignment
            // configuration.
            int leftContainerWidth = 0;
            int rightContainerWidth = 0;

            if (features.customButtons != null) {
                for (int i = 0; i < features.customButtons.length; i++) {
                    final BrowserButton buttonProps = features.customButtons[i];
                    final int index = i;
                    Button button = createButton(buttonProps, String.format("custom button at %d", i),
                            new View.OnClickListener() {
                                @Override
                                public void onClick(View view) {
                                    if (inAppWebView != null) {
                                        emitButtonEvent(buttonProps, inAppWebView.getUrl(), index);
                                    }
                                }
                            });

                    if (ALIGN_RIGHT.equals(buttonProps.align)) {
                        rightButtonContainer.addView(button);
                        rightContainerWidth += button.getLayoutParams().width;
                    } else {
                        leftButtonContainer.addView(button, 0);
                        leftContainerWidth += button.getLayoutParams().width;
                    }
                }
            }

            // Back and forward buttons must be added with special ordering logic such
            // that back button is always on the left of forward button if both buttons
            // are on the same side.
            if (forward != null && features.forwardButton != null
                    && !ALIGN_RIGHT.equals(features.forwardButton.align)) {
                leftButtonContainer.addView(forward, 0);
                leftContainerWidth += forward.getLayoutParams().width;
            }

            if (back != null && features.backButton != null && ALIGN_RIGHT.equals(features.backButton.align)) {
                rightButtonContainer.addView(back);
                rightContainerWidth += back.getLayoutParams().width;
            }

            if (back != null && features.backButton != null && !ALIGN_RIGHT.equals(features.backButton.align)) {
                leftButtonContainer.addView(back, 0);
                leftContainerWidth += back.getLayoutParams().width;
            }

            if (forward != null && features.forwardButton != null
                    && ALIGN_RIGHT.equals(features.forwardButton.align)) {
                rightButtonContainer.addView(forward);
                rightContainerWidth += forward.getLayoutParams().width;
            }

            if (menu != null) {
                if (features.menu != null && ALIGN_RIGHT.equals(features.menu.align)) {
                    rightButtonContainer.addView(menu);
                    rightContainerWidth += menu.getLayoutParams().width;
                } else {
                    leftButtonContainer.addView(menu, 0);
                    leftContainerWidth += menu.getLayoutParams().width;
                }
            }

            if (close != null) {
                if (features.closeButton != null && ALIGN_RIGHT.equals(features.closeButton.align)) {
                    rightButtonContainer.addView(close);
                    rightContainerWidth += close.getLayoutParams().width;
                } else {
                    leftButtonContainer.addView(close, 0);
                    leftContainerWidth += close.getLayoutParams().width;
                }
            }

            // Add the views to our toolbar
            toolbar.addView(leftButtonContainer);
            // Don't show address bar.
            // toolbar.addView(edittext);
            toolbar.addView(rightButtonContainer);

            if (title != null) {
                int titleMargin = Math.max(leftContainerWidth, rightContainerWidth);

                FrameLayout.LayoutParams titleParams = (FrameLayout.LayoutParams) title.getLayoutParams();
                titleParams.setMargins(titleMargin, 8, titleMargin, 0);
                toolbar.addView(title);
            }

            if (subtitle != null) {
                int subtitleMargin = Math.max(leftContainerWidth, rightContainerWidth);

                FrameLayout.LayoutParams subtitleParams = (FrameLayout.LayoutParams) subtitle.getLayoutParams();
                subtitleParams.setMargins(subtitleMargin, 0, subtitleMargin, 8);
                toolbar.addView(subtitle);
            }

            if (features.fullscreen) {
                // If full screen mode, we have to add inAppWebView before adding toolbar.
                main.addView(inAppWebView);
            }

            // Don't add the toolbar if its been disabled
            if (features.location) {
                // Add our toolbar to our main view/layout
                main.addView(toolbar);
            }

            if (!features.fullscreen) {
                // If not full screen, we add inAppWebView after adding toolbar.
                main.addView(inAppWebView);
            }

            WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
            lp.copyFrom(dialog.getWindow().getAttributes());
            lp.width = WindowManager.LayoutParams.MATCH_PARENT;
            lp.height = WindowManager.LayoutParams.MATCH_PARENT;

            dialog.setContentView(main);
            dialog.show();
            dialog.getWindow().setAttributes(lp);
            // the goal of openhidden is to load the url and not display it
            // Show() needs to be called to cause the URL to be loaded
            if (features.hidden) {
                dialog.hide();
            }
        }
    };
    this.cordova.getActivity().runOnUiThread(runnable);
    return "";
}

From source file:com.android.mms.ui.MessageUtils.java

public static void setSubIconAndLabel(int subId, String subName, TextView subView) {
    Log.i(TAG, "setSubIconAndLabel subId=" + subId);
    int textColor = 0;
    if (subView == null) {
        return;/*from  w  ww  .j  a  va 2  s  . co  m*/
    }
    int activeSubCount = SubscriptionManager.from(MmsApp.getApplication()).getActiveSubscriptionInfoCount();

    if (subName == null && activeSubCount > 1) {
        SubscriptionInfo subInfo = SubscriptionManager.from(MmsApp.getApplication())
                .getActiveSubscriptionInfo(subId);
        Log.d(TAG, "subInfo=" + subInfo);
        if (null != subInfo) {
            if ((subInfo.getSimSlotIndex() == SubscriptionManager.SIM_NOT_INSERTED)
                    || (subInfo.getSimSlotIndex() == SubscriptionManager.INVALID_SUBSCRIPTION_ID)) {
                Log.i(TAG, "current not insert sim card");
            } else {
                subName = subInfo.getDisplayName().toString();
                textColor = subInfo.getIconTint();
            }
        } else {
            Log.i(TAG, "subInfo is null ");
        }
    }

    if (subName == null || activeSubCount <= 1) {
        subView.setVisibility(View.GONE);
    } else {
        subView.setVisibility(View.VISIBLE);
        subView.setTextColor(textColor);
        subView.setText(subName);
    }
}

From source file:com.andrewshu.android.reddit.threads.ThreadsListActivity.java

public static void fillThreadsListItemView(int position, View view, ThingInfo item, ListActivity activity,
        HttpClient client, RedditSettings settings,
        ThumbnailOnClickListenerFactory thumbnailOnClickListenerFactory) {

    Resources res = activity.getResources();

    TextView titleView = (TextView) view.findViewById(R.id.title);
    TextView votesView = (TextView) view.findViewById(R.id.votes);
    TextView numCommentsSubredditView = (TextView) view.findViewById(R.id.numCommentsSubreddit);
    TextView nsfwView = (TextView) view.findViewById(R.id.nsfw);
    //        TextView submissionTimeView = (TextView) view.findViewById(R.id.submissionTime);
    ImageView voteUpView = (ImageView) view.findViewById(R.id.vote_up_image);
    ImageView voteDownView = (ImageView) view.findViewById(R.id.vote_down_image);
    View thumbnailContainer = view.findViewById(R.id.thumbnail_view);
    FrameLayout thumbnailFrame = (FrameLayout) view.findViewById(R.id.thumbnail_frame);
    ImageView thumbnailImageView = (ImageView) view.findViewById(R.id.thumbnail);
    ProgressBar indeterminateProgressBar = (ProgressBar) view.findViewById(R.id.indeterminate_progress);

    // Set the title and domain using a SpannableStringBuilder
    SpannableStringBuilder builder = new SpannableStringBuilder();
    String title = item.getTitle();
    if (title == null)
        title = "";
    SpannableString titleSS = new SpannableString(title);
    int titleLen = title.length();
    titleSS.setSpan(// w ww. j av a2s. c  o m
            new TextAppearanceSpan(activity,
                    Util.getTextAppearanceResource(settings.getTheme(), android.R.style.TextAppearance_Large)),
            0, titleLen, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    String domain = item.getDomain();
    if (domain == null)
        domain = "";
    int domainLen = domain.length();
    SpannableString domainSS = new SpannableString("(" + item.getDomain() + ")");
    domainSS.setSpan(
            new TextAppearanceSpan(activity,
                    Util.getTextAppearanceResource(settings.getTheme(), android.R.style.TextAppearance_Small)),
            0, domainLen + 2, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    if (Util.isLightTheme(settings.getTheme())) {
        if (item.isClicked()) {
            ForegroundColorSpan fcs = new ForegroundColorSpan(res.getColor(R.color.purple));
            titleSS.setSpan(fcs, 0, titleLen, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        } else {
            ForegroundColorSpan fcs = new ForegroundColorSpan(res.getColor(R.color.blue));
            titleSS.setSpan(fcs, 0, titleLen, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        domainSS.setSpan(new ForegroundColorSpan(res.getColor(R.color.gray_50)), 0, domainLen + 2,
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    } else {
        if (item.isClicked()) {
            ForegroundColorSpan fcs = new ForegroundColorSpan(res.getColor(R.color.gray_50));
            titleSS.setSpan(fcs, 0, titleLen, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        domainSS.setSpan(new ForegroundColorSpan(res.getColor(R.color.gray_75)), 0, domainLen + 2,
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }

    builder.append(titleSS).append(" ").append(domainSS);
    titleView.setText(builder);

    votesView.setText("" + item.getScore());
    numCommentsSubredditView.setText(Util.showNumComments(item.getNum_comments()) + "  " + item.getSubreddit());

    if (item.isOver_18()) {
        nsfwView.setVisibility(View.VISIBLE);
    } else {
        nsfwView.setVisibility(View.GONE);
    }

    // Set the up and down arrow colors based on whether user likes
    if (settings.isLoggedIn()) {
        if (item.getLikes() == null) {
            voteUpView.setImageResource(R.drawable.vote_up_gray);
            voteDownView.setImageResource(R.drawable.vote_down_gray);
            votesView.setTextColor(res.getColor(R.color.gray_75));
        } else if (item.getLikes() == true) {
            voteUpView.setImageResource(R.drawable.vote_up_red);
            voteDownView.setImageResource(R.drawable.vote_down_gray);
            votesView.setTextColor(res.getColor(R.color.arrow_red));
        } else {
            voteUpView.setImageResource(R.drawable.vote_up_gray);
            voteDownView.setImageResource(R.drawable.vote_down_blue);
            votesView.setTextColor(res.getColor(R.color.arrow_blue));
        }
    } else {
        voteUpView.setImageResource(R.drawable.vote_up_gray);
        voteDownView.setImageResource(R.drawable.vote_down_gray);
        votesView.setTextColor(res.getColor(R.color.gray_75));
    }

    // Thumbnails open links
    if (thumbnailContainer != null) {
        if (Common.shouldLoadThumbnails(activity, settings)) {
            thumbnailContainer.setVisibility(View.VISIBLE);

            if (item.getUrl() != null) {
                OnClickListener thumbnailOnClickListener = thumbnailOnClickListenerFactory
                        .getThumbnailOnClickListener(item, activity);
                if (thumbnailOnClickListener != null) {
                    thumbnailFrame.setOnClickListener(thumbnailOnClickListener);
                }
            }

            // Show thumbnail based on ThingInfo
            if ("default".equals(item.getThumbnail()) || "self".equals(item.getThumbnail())
                    || StringUtils.isEmpty(item.getThumbnail())) {
                indeterminateProgressBar.setVisibility(View.GONE);
                thumbnailImageView.setVisibility(View.VISIBLE);
                thumbnailImageView.setImageResource(R.drawable.go_arrow);
            } else {
                indeterminateProgressBar.setVisibility(View.GONE);
                thumbnailImageView.setVisibility(View.VISIBLE);
                if (item.getThumbnailBitmap() != null) {
                    thumbnailImageView.setImageBitmap(item.getThumbnailBitmap());
                } else {
                    thumbnailImageView.setImageBitmap(null);
                    new ShowThumbnailsTask(activity, client, R.drawable.go_arrow)
                            .execute(new ThumbnailLoadAction(item, thumbnailImageView, position));
                }
            }

            // Set thumbnail background based on current theme
            if (Util.isLightTheme(settings.getTheme()))
                thumbnailFrame.setBackgroundResource(R.drawable.thumbnail_background_light);
            else
                thumbnailFrame.setBackgroundResource(R.drawable.thumbnail_background_dark);
        } else {
            // if thumbnails disabled, hide thumbnail icon
            thumbnailContainer.setVisibility(View.GONE);
        }
    }
}

From source file:cm.aptoide.pt.ManageRepos.java

private void validateRepo(final String originalUriString, final boolean editMode) {

    final ViewDisplayRepo originalRepo;

    LayoutInflater li = LayoutInflater.from(ctx);
    View view = li.inflate(R.layout.addrepo, null);

    final TextView sec_msg = (TextView) view.findViewById(R.id.sec_msg);
    final TextView sec_msg2 = (TextView) view.findViewById(R.id.sec_msg2);

    final EditText sec_user = (EditText) view.findViewById(R.id.sec_user);
    final EditText sec_pwd = (EditText) view.findViewById(R.id.sec_pwd);

    final EditText uri = (EditText) view.findViewById(R.id.edit_uri);

    final CheckBox sec = (CheckBox) view.findViewById(R.id.secure_chk);
    sec.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                sec_user.setEnabled(true);
                sec_pwd.setEnabled(true);
            } else {
                sec_user.setEnabled(false);
                sec_pwd.setEnabled(false);
            }//from w  w  w . j  av  a2s. c  o m
        }
    });

    Builder p = new AlertDialog.Builder(theme).setView(view);
    alrt = p.create();
    CharSequence actionButtonString;
    if (editMode) {

        originalRepo = repos.getRepo(originalUriString.hashCode());
        if (originalRepo.requiresLogin()) {
            sec.setChecked(true);
            sec_user.setText(originalRepo.getLogin().getUsername());
            sec_pwd.setText(originalRepo.getLogin().getPassword());
        } else {
            sec.setChecked(false);
        }

        alrt.setIcon(R.drawable.ic_menu_edit);
        alrt.setTitle(getText(R.string.edit_repo));
        actionButtonString = getText(R.string.edit);
    } else {

        originalRepo = null;
        sec.setChecked(false);

        alrt.setIcon(R.drawable.ic_menu_add);
        alrt.setTitle(getText(R.string.add_repo));
        actionButtonString = getText(R.string.add);
    }

    alrt.setButton(actionButtonString, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int which) {
            String uriString = uri.getText().toString();

            String user = null;
            String pwd = null;

            if (sec.isChecked()) {
                user = sec_user.getText().toString();
                pwd = sec_pwd.getText().toString();
            }

            Message msg = new Message();
            uriString = uriCheck(uriString);
            sec_msg.setVisibility(View.GONE);
            sec_msg2.setVisibility(View.GONE);

            returnStatus result = checkServerConnection(uriString, user, pwd);
            switch (result) {
            case OK:
                Log.d("Aptoide-ManageRepo", "return ok");
                msg.obj = 0;
                if (isRepoManaged(uriString) && ((originalRepo != null && originalRepo.requiresLogin())
                        ? (originalRepo.getLogin().getUsername().equals(user)
                                && originalRepo.getLogin().getPassword().equals(pwd))
                        : true)) {
                    Toast.makeText(ctx, "Repo " + uriString + " already exists.", 5000).show();
                    //                     finish();
                } else {
                    ViewRepository newRepo = new ViewRepository(uriString);
                    if (isRepoManaged(uriString)) {
                        if (user != null && pwd != null) {
                            reposManager.removeLogin(newRepo.getHashid());
                        } else {
                            newRepo.setLogin(new ViewLogin(user, pwd));
                            reposManager.updateLogin(newRepo);
                        }
                    } else {
                        if (user != null && pwd != null) {
                            newRepo.setLogin(new ViewLogin(user, pwd));
                        }
                        if (originalUriString != null) {
                            removeDisplayRepo(originalUriString.hashCode());
                        }
                        addDisplayRepo(newRepo);
                        refreshReposList();
                    }

                    alrt.dismiss();
                }
                break;

            case LOGIN_REQUIRED:
                Log.d("Aptoide-ManageRepo", "return login_required");
                sec_msg2.setText(getText(R.string.login_required));
                sec_msg2.setVisibility(View.VISIBLE);
                msg.obj = 1;

                break;

            case BAD_LOGIN:
                Log.d("Aptoide-ManageRepo", "return bad_login");
                sec_msg2.setText(getText(R.string.bad_login));
                sec_msg2.setVisibility(View.VISIBLE);
                msg.obj = 1;
                break;

            case FAIL:
                Log.d("Aptoide-ManageRepo", "return fail");
                uriString = uriString.substring(0, uriString.length() - 1) + ".bazaarandroid.com/";
                Log.d("Aptoide-ManageRepo", "repo uri: " + uriString);
                msg.obj = 1;
                break;

            default:
                Log.d("Aptoide-ManageRepo", "return exception");
                uriString = uriString.substring(0, uriString.length() - 1) + ".bazaarandroid.com/";
                Log.d("Aptoide-ManageRepo", "repo uri: " + uriString);
                msg.obj = 1;
                break;
            }
            if (result.equals(returnStatus.FAIL) || result.equals(returnStatus.EXCEPTION)) {
                returnStatus result2 = checkServerConnection(uriString, user, pwd);
                switch (result2) {
                case OK:
                    Log.d("Aptoide-ManageRepo", "return ok");
                    msg.obj = 0;
                    if (isRepoManaged(uriString) && ((originalRepo != null && originalRepo.requiresLogin())
                            ? (originalRepo.getLogin().getUsername().equals(user)
                                    && originalRepo.getLogin().getPassword().equals(pwd))
                            : true)) {
                        Toast.makeText(ctx, "Repo " + uriString + " already exists.", 5000).show();
                        //                        finish();
                    } else {
                        ViewRepository newRepo = new ViewRepository(uriString);
                        if (isRepoManaged(uriString)) {
                            if (user != null && pwd != null) {
                                reposManager.removeLogin(newRepo.getHashid());
                            } else {
                                newRepo.setLogin(new ViewLogin(user, pwd));
                                reposManager.updateLogin(newRepo);
                            }
                        } else {
                            if (user != null && pwd != null) {
                                newRepo.setLogin(new ViewLogin(user, pwd));
                            }
                            if (originalUriString != null) {
                                removeDisplayRepo(originalUriString.hashCode());
                            }
                            addDisplayRepo(newRepo);
                            refreshReposList();
                        }

                        alrt.dismiss();
                    }
                    break;

                case LOGIN_REQUIRED:
                    Log.d("Aptoide-ManageRepo", "return login_required");
                    sec_msg2.setText(getText(R.string.login_required));
                    sec_msg2.setVisibility(View.VISIBLE);
                    msg.obj = 1;

                    break;

                case BAD_LOGIN:
                    Log.d("Aptoide-ManageRepo", "return bad_login");
                    sec_msg2.setText(getText(R.string.bad_login));
                    sec_msg2.setVisibility(View.VISIBLE);
                    msg.obj = 1;
                    break;

                case FAIL:
                    Log.d("Aptoide-ManageRepo", "return fail");
                    sec_msg.setText(getText(R.string.cant_connect));
                    sec_msg.setVisibility(View.VISIBLE);
                    msg.obj = 1;

                    break;

                default:
                    Log.d("Aptoide-ManageRepo", "return exception");
                    msg.obj = 1;
                    break;
                }
            }
            invalidRepo.sendMessage(msg);
        }
    });

    alrt.setButton2(getText(R.string.cancel), new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            alrt.dismiss();
        }
    });
    alrt.show();
    if (originalUriString != null) {
        uri.setText(originalUriString);
    }
}

From source file:pt.aptoide.backupapps.ManageRepos.java

private void validateRepo(final String originalUriString, final boolean editMode) {

    final ViewDisplayRepo originalRepo;

    LayoutInflater li = LayoutInflater.from(ctx);
    View view = li.inflate(R.layout.addrepo, null);

    final TextView sec_msg = (TextView) view.findViewById(R.id.sec_msg);
    final TextView sec_msg2 = (TextView) view.findViewById(R.id.sec_msg2);

    final EditText sec_user = (EditText) view.findViewById(R.id.sec_user);
    final EditText sec_pwd = (EditText) view.findViewById(R.id.sec_pwd);

    final EditText uri = (EditText) view.findViewById(R.id.edit_uri);

    final CheckBox sec = (CheckBox) view.findViewById(R.id.secure_chk);
    sec.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                sec_user.setEnabled(true);
                sec_pwd.setEnabled(true);
            } else {
                sec_user.setEnabled(false);
                sec_pwd.setEnabled(false);
            }//  ww w .  jav  a 2s .  c o m
        }
    });

    Builder p = new AlertDialog.Builder(theme).setView(view);
    alrt = p.create();
    CharSequence actionButtonString;
    if (editMode) {

        originalRepo = repos.getRepo(originalUriString.hashCode());
        if (originalRepo.requiresLogin()) {
            sec.setChecked(true);
            sec_user.setText(originalRepo.getLogin().getUsername());
            sec_pwd.setText(originalRepo.getLogin().getPassword());
        } else {
            sec.setChecked(false);
        }

        alrt.setIcon(R.drawable.ic_menu_edit);
        alrt.setTitle(getText(R.string.edit_repo));
        actionButtonString = getText(R.string.edit);
    } else {

        originalRepo = null;
        sec.setChecked(false);

        alrt.setIcon(R.drawable.ic_menu_add);
        alrt.setTitle(getText(R.string.add_repo));
        actionButtonString = getText(R.string.add);
    }

    alrt.setButton(actionButtonString, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int which) {
            String uriString = uri.getText().toString();

            String user = null;
            String pwd = null;

            if (sec.isChecked()) {
                user = sec_user.getText().toString();
                pwd = sec_pwd.getText().toString();
            }

            Message msg = new Message();
            uriString = uriCheck(uriString);
            sec_msg.setVisibility(View.GONE);
            sec_msg2.setVisibility(View.GONE);

            returnStatus result = checkServerConnection(uriString, user, pwd);
            switch (result) {
            case OK:
                Log.d("Aptoide-ManageRepo", "return ok");
                msg.obj = 0;
                if (isRepoManaged(uriString) && ((originalRepo != null && originalRepo.requiresLogin())
                        ? (originalRepo.getLogin().getUsername().equals(user)
                                && originalRepo.getLogin().getPassword().equals(pwd))
                        : true)) {
                    Toast.makeText(ctx, "Repo " + uriString + " already exists.", 5000).show();
                    //                     finish();
                } else {
                    ViewRepository newRepo = new ViewRepository(uriString);
                    if (isRepoManaged(uriString)) {
                        if (user != null && pwd != null) {
                            reposManager.removeLogin(newRepo.getHashid());
                        } else {
                            newRepo.setLogin(new ViewLogin(user, pwd));
                            reposManager.updateLogin(newRepo);
                        }
                    } else {
                        if (user != null && pwd != null) {
                            newRepo.setLogin(new ViewLogin(user, pwd));
                        }
                        if (originalUriString != null) {
                            removeDisplayRepo(originalUriString.hashCode());
                        }
                        addDisplayRepo(newRepo);
                        refreshReposList();
                    }

                    alrt.dismiss();
                }
                break;

            case LOGIN_REQUIRED:
                Log.d("Aptoide-ManageRepo", "return login_required");
                sec_msg2.setText(getText(R.string.login_required));
                sec_msg2.setVisibility(View.VISIBLE);
                msg.obj = 1;

                break;

            case BAD_LOGIN:
                Log.d("Aptoide-ManageRepo", "return bad_login");
                sec_msg2.setText(getText(R.string.check_login));
                sec_msg2.setVisibility(View.VISIBLE);
                msg.obj = 1;
                break;

            case FAIL:
                Log.d("Aptoide-ManageRepo", "return fail");
                uriString = uriString.substring(0, uriString.length() - 1) + Constants.DOMAIN_APTOIDE_STORE;
                Log.d("Aptoide-ManageRepo", "repo uri: " + uriString);
                msg.obj = 1;
                break;

            default:
                Log.d("Aptoide-ManageRepo", "return exception");
                uriString = uriString.substring(0, uriString.length() - 1) + Constants.DOMAIN_APTOIDE_STORE;
                Log.d("Aptoide-ManageRepo", "repo uri: " + uriString);
                msg.obj = 1;
                break;
            }
            if (result.equals(returnStatus.FAIL) || result.equals(returnStatus.EXCEPTION)) {
                returnStatus result2 = checkServerConnection(uriString, user, pwd);
                switch (result2) {
                case OK:
                    Log.d("Aptoide-ManageRepo", "return ok");
                    msg.obj = 0;
                    if (isRepoManaged(uriString) && ((originalRepo != null && originalRepo.requiresLogin())
                            ? (originalRepo.getLogin().getUsername().equals(user)
                                    && originalRepo.getLogin().getPassword().equals(pwd))
                            : true)) {
                        Toast.makeText(ctx, "Repo " + uriString + " already exists.", 5000).show();
                        //                        finish();
                    } else {
                        ViewRepository newRepo = new ViewRepository(uriString);
                        if (isRepoManaged(uriString)) {
                            if (user != null && pwd != null) {
                                reposManager.removeLogin(newRepo.getHashid());
                            } else {
                                newRepo.setLogin(new ViewLogin(user, pwd));
                                reposManager.updateLogin(newRepo);
                            }
                        } else {
                            if (user != null && pwd != null) {
                                newRepo.setLogin(new ViewLogin(user, pwd));
                            }
                            if (originalUriString != null) {
                                removeDisplayRepo(originalUriString.hashCode());
                            }
                            addDisplayRepo(newRepo);
                            refreshReposList();
                        }

                        alrt.dismiss();
                    }
                    break;

                case LOGIN_REQUIRED:
                    Log.d("Aptoide-ManageRepo", "return login_required");
                    sec_msg2.setText(getText(R.string.login_required));
                    sec_msg2.setVisibility(View.VISIBLE);
                    msg.obj = 1;

                    break;

                case BAD_LOGIN:
                    Log.d("Aptoide-ManageRepo", "return bad_login");
                    sec_msg2.setText(getText(R.string.check_login));
                    sec_msg2.setVisibility(View.VISIBLE);
                    msg.obj = 1;
                    break;

                case FAIL:
                    Log.d("Aptoide-ManageRepo", "return fail");
                    sec_msg.setText(getText(R.string.cant_connect));
                    sec_msg.setVisibility(View.VISIBLE);
                    msg.obj = 1;

                    break;

                default:
                    Log.d("Aptoide-ManageRepo", "return exception");
                    msg.obj = 1;
                    break;
                }
            }
            invalidRepo.sendMessage(msg);
        }
    });

    alrt.setButton2(getText(R.string.cancel), new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            alrt.dismiss();
        }
    });
    alrt.show();
    if (originalUriString != null) {
        uri.setText(originalUriString);
    }
}

From source file:com.kll.collect.android.activities.FormEntryActivity.java

/**
 * Creates a view given the View type and an event
 *
 * @param event//  www . j a v  a 2 s .  com
 * @param advancingPage
 *            -- true if this results from advancing through the form
 * @return newly created View
 */
private View createView(int event, boolean advancingPage, int swipeCase) {
    FormController formController = Collect.getInstance().getFormController();
    /*   setTitle(getString(R.string.app_name) + " > "
    + formController.getFormTitle());*/
    int questioncount = formController.getFormDef().getDeepChildCount();

    switch (event) {
    case FormEntryController.EVENT_BEGINNING_OF_FORM:
        progressValue = 0.0;
        progressUpdate(progressValue, questioncount);
        View startView = View.inflate(this, R.layout.form_entry_start, null);
        /*setTitle(getString(R.string.app_name) + " > "
              + formController.getFormTitle());*/

        Drawable image = null;
        File mediaFolder = formController.getMediaFolder();
        String mediaDir = mediaFolder.getAbsolutePath();
        BitmapDrawable bitImage = null;
        // attempt to load the form-specific logo...
        // this is arbitrarily silly
        bitImage = new BitmapDrawable(getResources(), mediaDir + File.separator + "form_logo.png");

        if (bitImage != null && bitImage.getBitmap() != null && bitImage.getIntrinsicHeight() > 0
                && bitImage.getIntrinsicWidth() > 0) {
            image = bitImage;
        }

        if (image == null) {
            // show the opendatakit zig...
            // image =
            // getResources().getDrawable(R.drawable.opendatakit_zig);
            ((ImageView) startView.findViewById(R.id.form_start_bling)).setVisibility(View.GONE);
        } else {
            ImageView v = ((ImageView) startView.findViewById(R.id.form_start_bling));
            v.setImageDrawable(image);
            v.setContentDescription(formController.getFormTitle());
        }

        // change start screen based on navigation prefs
        String navigationChoice = PreferenceManager.getDefaultSharedPreferences(this)
                .getString(PreferencesActivity.KEY_NAVIGATION, PreferencesActivity.KEY_NAVIGATION);
        Boolean useSwipe = false;
        Boolean useButtons = false;
        ImageView ia = ((ImageView) startView.findViewById(R.id.image_advance));
        ImageView ib = ((ImageView) startView.findViewById(R.id.image_backup));
        TextView ta = ((TextView) startView.findViewById(R.id.text_advance));
        TextView tb = ((TextView) startView.findViewById(R.id.text_backup));
        TextView d = ((TextView) startView.findViewById(R.id.description));

        if (navigationChoice != null) {
            if (navigationChoice.contains(PreferencesActivity.NAVIGATION_SWIPE)) {
                useSwipe = true;
            }
            if (navigationChoice.contains(PreferencesActivity.NAVIGATION_BUTTONS)) {
                useButtons = true;
            }
        }
        if (useSwipe && !useButtons) {
            d.setText(getString(R.string.swipe_instructions, formController.getFormTitle()));
        } else if (useButtons && !useSwipe) {
            ia.setVisibility(View.GONE);
            ib.setVisibility(View.GONE);
            ta.setVisibility(View.GONE);
            tb.setVisibility(View.GONE);
            d.setText(getString(R.string.buttons_instructions, formController.getFormTitle()));
        } else {
            d.setText(getString(R.string.swipe_buttons_instructions, formController.getFormTitle()));
        }

        if (mBackButton.isShown()) {
            mBackButton.setEnabled(false);
        }
        if (mNextButton.isShown()) {
            mNextButton.setEnabled(true);
        }

        return startView;
    case FormEntryController.EVENT_END_OF_FORM:
        progressValue = questioncount;
        progressUpdate(progressValue, questioncount);
        View endView = View.inflate(this, R.layout.form_entry_end, null);

        ((ImageView) endView.findViewById(R.id.completed))
                .setImageDrawable(getResources().getDrawable(R.drawable.complete_tick));
        ((TextView) endView.findViewById(R.id.description))
                .setText(getString(R.string.save_enter_data_description, formController.getFormTitle()));

        // checkbox for if finished or ready to send
        final CheckBox instanceComplete = ((CheckBox) endView.findViewById(R.id.mark_finished));
        instanceComplete.setChecked(isInstanceComplete(true));

        if (!mAdminPreferences.getBoolean(AdminPreferencesActivity.KEY_MARK_AS_FINALIZED, true)) {
            instanceComplete.setVisibility(View.GONE);
        }

        // edittext to change the displayed name of the instance
        final EditText saveAs = (EditText) endView.findViewById(R.id.save_name);

        // disallow carriage returns in the name
        InputFilter returnFilter = new InputFilter() {
            public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart,
                    int dend) {
                for (int i = start; i < end; i++) {
                    if (Character.getType((source.charAt(i))) == Character.CONTROL) {
                        return "";
                    }
                }
                return null;
            }
        };
        saveAs.setFilters(new InputFilter[] { returnFilter });
        String saveName = getSaveName();

        if (saveName == null) {
            // no meta/instanceName field in the form -- see if we have a
            // name for this instance from a previous save attempt...
            if (getContentResolver().getType(getIntent().getData()) == InstanceColumns.CONTENT_ITEM_TYPE) {
                Uri instanceUri = getIntent().getData();
                Cursor instance = null;
                try {
                    instance = getContentResolver().query(instanceUri, null, null, null, null);
                    if (instance.getCount() == 1) {
                        instance.moveToFirst();
                        saveName = instance.getString(instance.getColumnIndex(InstanceColumns.DISPLAY_NAME));
                    }
                } finally {
                    if (instance != null) {
                        instance.close();
                    }
                }
            }
            if (saveName == null) {
                // last resort, default to the form title
                saveName = formController.getFormTitle();
            }
            // present the prompt to allow user to name the form
            TextView sa = (TextView) endView.findViewById(R.id.save_form_as);
            sa.setVisibility(View.VISIBLE);
            saveAs.setText(saveName);
            saveAs.setEnabled(true);
            saveAs.setVisibility(View.VISIBLE);
        } else {
            // if instanceName is defined in form, this is the name -- no
            // revisions
            // display only the name, not the prompt, and disable edits
            TextView sa = (TextView) endView.findViewById(R.id.save_form_as);
            sa.setVisibility(View.GONE);
            saveAs.setText(saveName);
            saveAs.setEnabled(false);
            saveAs.setBackgroundColor(Color.WHITE);
            saveAs.setVisibility(View.VISIBLE);
        }

        // override the visibility settings based upon admin preferences
        if (!mAdminPreferences.getBoolean(AdminPreferencesActivity.KEY_SAVE_AS, true)) {
            saveAs.setVisibility(View.GONE);
            TextView sa = (TextView) endView.findViewById(R.id.save_form_as);
            sa.setVisibility(View.GONE);
        }

        // Create 'save' button
        ((Button) endView.findViewById(R.id.save_exit_button)).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Collect.getInstance().getActivityLogger().logInstanceAction(this, "createView.saveAndExit",
                        instanceComplete.isChecked() ? "saveAsComplete" : "saveIncomplete");
                // Form is marked as 'saved' here.
                if (saveAs.getText().length() < 1) {
                    Toast.makeText(FormEntryActivity.this, R.string.save_as_error, Toast.LENGTH_SHORT).show();
                } else {
                    saveDataToDisk(EXIT, instanceComplete.isChecked(), saveAs.getText().toString());
                }
            }
        });

        if (mBackButton.isShown()) {
            mBackButton.setEnabled(true);
        }
        if (mNextButton.isShown()) {
            mNextButton.setEnabled(false);
        }

        return endView;
    case FormEntryController.EVENT_QUESTION:
    case FormEntryController.EVENT_GROUP:
    case FormEntryController.EVENT_REPEAT:
        ODKView odkv = null;
        // should only be a group here if the event_group is a field-list
        try {
            double depth = (double) formController.getFormIndex().getDepth();
            double local_index = (double) formController.getFormIndex().getLocalIndex();
            double instance_index = (double) formController.getFormIndex().getInstanceIndex();
            Log.i("Question coint", Integer.toString(questioncount));

            Log.i("Depth", Integer.toString(formController.getFormIndex().getDepth()));
            Log.i("Local Index", Integer.toString(formController.getFormIndex().getLocalIndex()));
            Log.i("Instance Index", Integer.toString(formController.getFormIndex().getInstanceIndex()));

            if (swipeCase == NEXT) {

                Log.i("progressValue", Double.toString(progressValue));

            }
            if (swipeCase == PREVIOUS) {
                progressValue = progressValue - (1 - (instance_index * local_index / questioncount * depth));

                Log.i("progressValue", Double.toString(progressValue));
            }
            Log.i("progressValue", Double.toString(progressValue));
            progressUpdate(progressValue, questioncount);
            FormEntryPrompt[] prompts = formController.getQuestionPrompts();
            FormEntryCaption[] groups = formController.getGroupsForCurrentIndex();
            odkv = new ODKView(this, formController.getQuestionPrompts(), groups, advancingPage);
            Log.i(t, "created view for group "
                    + (groups.length > 0 ? groups[groups.length - 1].getLongText() : "[top]") + " "
                    + (prompts.length > 0 ? prompts[0].getQuestionText() : "[no question]"));
        } catch (RuntimeException e) {
            Log.e(t, e.getMessage(), e);
            // this is badness to avoid a crash.
            try {
                event = formController.stepToNextScreenEvent();
                createErrorDialog(e.getMessage(), DO_NOT_EXIT);
            } catch (JavaRosaException e1) {
                Log.e(t, e1.getMessage(), e1);
                createErrorDialog(e.getMessage() + "\n\n" + e1.getCause().getMessage(), DO_NOT_EXIT);
            }
            return createView(event, advancingPage, swipeCase);
        }

        // Makes a "clear answer" menu pop up on long-click
        for (QuestionWidget qw : odkv.getWidgets()) {
            if (!qw.getPrompt().isReadOnly()) {
                registerForContextMenu(qw);
            }
        }

        if (mBackButton.isShown() && mNextButton.isShown()) {
            mBackButton.setEnabled(true);
            mNextButton.setEnabled(true);
        }
        return odkv;
    default:
        Log.e(t, "Attempted to create a view that does not exist.");
        // this is badness to avoid a crash.
        try {
            event = formController.stepToNextScreenEvent();
            createErrorDialog(getString(R.string.survey_internal_error), EXIT);
        } catch (JavaRosaException e) {
            Log.e(t, e.getMessage(), e);
            createErrorDialog(e.getCause().getMessage(), EXIT);
        }
        return createView(event, advancingPage, swipeCase);
    }

}

From source file:com.max2idea.android.limbo.main.LimboActivity.java

private void promptPrio(final Activity activity) {
    // TODO Auto-generated method stub

    final AlertDialog alertDialog;
    alertDialog = new AlertDialog.Builder(activity).create();
    alertDialog.setTitle("Enable High Priority!");

    TextView textView = new TextView(activity);
    textView.setVisibility(View.VISIBLE);
    textView.setId(201012010);//  w  ww .j  av a 2s. c  o m
    textView.setText(
            "Warning! High Priority might increase emulation speed but " + "will slow your phone down!");

    alertDialog.setView(textView);
    final Handler handler = this.handler;

    // alertDialog.setMessage(body);
    alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            LimboSettingsManager.setPrio(activity, true);
        }
    });
    alertDialog.setButton2("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            mPrio.setChecked(false);
            return;
        }
    });
    alertDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialog) {
            mPrio.setChecked(false);
        }
    });
    alertDialog.show();
}

From source file:com.max2idea.android.limbo.main.LimboActivity.java

private void promptImportMachines() {
    // TODO Auto-generated method stub

    final AlertDialog alertDialog;
    alertDialog = new AlertDialog.Builder(activity).create();
    alertDialog.setTitle("Import Machines");

    RelativeLayout mLayout = new RelativeLayout(this);
    mLayout.setId(12222);//from w  ww . j a  v  a  2s  .c  om

    TextView imageNameView = new TextView(activity);
    imageNameView.setVisibility(View.VISIBLE);
    imageNameView.setId(201012010);
    imageNameView.setText(
            "Step 1: Place the machine.CSV file you export previously under \"limbo\" directory in your SD card.\n"
                    + "Step 2: WARNING: Any machine with the same name will be replaced!\n"
                    + "Step 3: Press \"OK\".\n");

    RelativeLayout.LayoutParams searchViewParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    mLayout.addView(imageNameView, searchViewParams);
    alertDialog.setView(mLayout);

    final Handler handler = this.handler;

    // alertDialog.setMessage(body);
    alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            // For each line create a Machine
            progDialog = ProgressDialog.show(activity, "Please Wait", "Importing Machines...", true);

            ImportMachines importer = new ImportMachines();
            importer.execute();
        }
    });
    alertDialog.setButton2("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {

            return;
        }
    });
    alertDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialog) {

            return;

        }
    });
    alertDialog.show();

}