Example usage for android.webkit WebView setVisibility

List of usage examples for android.webkit WebView setVisibility

Introduction

In this page you can find the example usage for android.webkit WebView setVisibility.

Prototype

@RemotableViewMethod
public void setVisibility(@Visibility int visibility) 

Source Link

Document

Set the visibility state of this view.

Usage

From source file:com.jelly.music.player.Utils.Common.java

@Override
public void onCreate() {
    super.onCreate();

    //Application context.
    mContext = getApplicationContext();/*  w ww  .  j a va 2s  . c  o  m*/

    //SharedPreferences.
    mSharedPreferences = this.getSharedPreferences("com.jelly.music.player", Context.MODE_PRIVATE);

    //Init the database.
    mDBAccessHelper = new DBAccessHelper(mContext);

    //Playback kickstarter.
    mPlaybackKickstarter = new PlaybackKickstarter(this.getApplicationContext());

    //Picasso.
    mPicasso = new Picasso.Builder(mContext).build();

    //ImageLoader.
    mImageLoader = ImageLoader.getInstance();
    mImageLoaderConfiguration = new ImageLoaderConfiguration.Builder(getApplicationContext())
            .memoryCache(new WeakMemoryCache()).memoryCacheSizePercentage(13)
            .imageDownloader(new ByteArrayUniversalImageLoader(mContext)).build();
    mImageLoader.init(mImageLoaderConfiguration);

    //Init DisplayImageOptions.
    initDisplayImageOptions();

    //Log the user into Google Play Music only if the account is currently set up and active.
    if (mSharedPreferences.getBoolean("GOOGLE_PLAY_MUSIC_ENABLED", false) == true) {

        //Create a temp WebView to retrieve the user agent string.
        String userAgentString = "";
        if (mSharedPreferences.getBoolean("GOT_USER_AGENT", false) == false) {
            WebView webView = new WebView(getApplicationContext());
            webView.setVisibility(View.GONE);
            webView.loadUrl("http://www.google.com");
            userAgentString = webView.getSettings().getUserAgentString();
            mSharedPreferences.edit().putBoolean("GOT_USER_AGENT", true).commit();
            mSharedPreferences.edit().putString("USER_AGENT", userAgentString).commit();
            webView = null;
        }

        setGMusicClientCalls(GMusicClientCalls.getInstance(getApplicationContext()));
        GMusicClientCalls.setWebClientUserAgent(userAgentString);
        String accountName = mSharedPreferences.getString("GOOGLE_PLAY_MUSIC_ACCOUNT", "");

        //Authenticate with Google.
        AsyncGoogleMusicAuthenticationTask task = new AsyncGoogleMusicAuthenticationTask(mContext, false,
                accountName);
        task.execute();

    }

}

From source file:com.Duo.music.player.Utils.Common.java

@Override
public void onCreate() {
    super.onCreate();

    //Application context.
    mContext = getApplicationContext();/*w w  w .jav a 2s  .c  o m*/

    //SharedPreferences.
    mSharedPreferences = this.getSharedPreferences("com.jams.music.player", Context.MODE_PRIVATE);

    //Init the database.
    mDBAccessHelper = new DBAccessHelper(mContext);

    //Playback kickstarter.
    mPlaybackKickstarter = new PlaybackKickstarter(this.getApplicationContext());

    //Picasso.
    mPicasso = new Picasso.Builder(mContext).build();

    //ImageLoader.
    mImageLoader = ImageLoader.getInstance();
    mImageLoaderConfiguration = new ImageLoaderConfiguration.Builder(getApplicationContext())
            .memoryCache(new WeakMemoryCache()).memoryCacheSizePercentage(13)
            .imageDownloader(new ByteArrayUniversalImageLoader(mContext)).build();
    mImageLoader.init(mImageLoaderConfiguration);

    //Init DisplayImageOptions.
    initDisplayImageOptions();

    //Log the user into Google Play Music only if the account is currently set up and active.
    if (mSharedPreferences.getBoolean("GOOGLE_PLAY_MUSIC_ENABLED", false) == true) {

        //Create a temp WebView to retrieve the user agent string.
        String userAgentString = "";
        if (mSharedPreferences.getBoolean("GOT_USER_AGENT", false) == false) {
            WebView webView = new WebView(getApplicationContext());
            webView.setVisibility(View.GONE);
            webView.loadUrl("http://www.google.com");
            userAgentString = webView.getSettings().getUserAgentString();
            mSharedPreferences.edit().putBoolean("GOT_USER_AGENT", true).commit();
            mSharedPreferences.edit().putString("USER_AGENT", userAgentString).commit();
            webView = null;
        }

        setGMusicClientCalls(GMusicClientCalls.getInstance(getApplicationContext()));
        GMusicClientCalls.setWebClientUserAgent(userAgentString);
        String accountName = mSharedPreferences.getString("GOOGLE_PLAY_MUSIC_ACCOUNT", "");

        //Authenticate with Google.
        AsyncGoogleMusicAuthenticationTask task = new AsyncGoogleMusicAuthenticationTask(mContext, false,
                accountName);
        task.execute();

    }

}

From source file:com.elpstudio.player.externals.Common.java

@Override
public void onCreate() {
    super.onCreate();

    //Application context.
    mContext = getApplicationContext();//from w w w .  java  2s .  com

    sInstance = this;
    light = Typeface.createFromAsset(getApplicationContext().getAssets(), "segoeuil.ttf");
    reg = Typeface.createFromAsset(getApplicationContext().getAssets(), "segoeui.ttf");

    //SharedPreferences.
    mSharedPreferences = this.getSharedPreferences("com.jams.music.player", Context.MODE_PRIVATE);

    //Init the database.
    mDBAccessHelper = new DBAccessHelper(mContext);

    //Playback kickstarter.
    //mPlaybackKickstarter = new PlaybackKickstarter(this.getApplicationContext());

    //Picasso.
    // mPicasso = new Picasso.Builder(mContext).build();

    //ImageLoader.
    mImageLoader = ImageLoader.getInstance();
    mImageLoaderConfiguration = new ImageLoaderConfiguration.Builder(getApplicationContext())
            .memoryCache(new WeakMemoryCache()).memoryCacheSizePercentage(13)
            .imageDownloader(new ByteArrayUniversalImageLoader(mContext)).build();
    mImageLoader.init(mImageLoaderConfiguration);

    //Init DisplayImageOptions.
    initDisplayImageOptions();

    //Log the user into Google Play Music only if the account is currently set up and active.
    if (mSharedPreferences.getBoolean("GOOGLE_PLAY_MUSIC_ENABLED", false) == true) {

        //Create a temp WebView to retrieve the user agent string.
        String userAgentString = "";
        if (mSharedPreferences.getBoolean("GOT_USER_AGENT", false) == false) {
            WebView webView = new WebView(getApplicationContext());
            webView.setVisibility(View.GONE);
            webView.loadUrl("http://www.google.com");
            userAgentString = webView.getSettings().getUserAgentString();
            mSharedPreferences.edit().putBoolean("GOT_USER_AGENT", true).commit();
            mSharedPreferences.edit().putString("USER_AGENT", userAgentString).commit();
            webView = null;
        }

        /*setGMusicClientCalls(GMusicClientCalls.getInstance(getApplicationContext()));
        GMusicClientCalls.setWebClientUserAgent(userAgentString);
        String accountName = mSharedPreferences.getString("GOOGLE_PLAY_MUSIC_ACCOUNT", "");
                
        //Authenticate with Google.
        AsyncGoogleMusicAuthenticationTask task = new AsyncGoogleMusicAuthenticationTask(mContext, false, accountName);
        task.execute();
        */
    }

}

From source file:com.activiti.android.app.fragments.HelpDialogFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.app_webview, container, false);

    getToolbar().setVisibility(View.GONE);

    webView = (WebView) v.findViewById(R.id.webview);
    webView.getSettings().setJavaScriptEnabled(true);
    emptyView = v.findViewById(R.id.empty);
    emptyTextView = (TextView) v.findViewById(R.id.empty_text);
    emptyTextView.setText(Html.fromHtml(getString(R.string.error_offline)));

    final Activity activity = getActivity();

    defaultUrl = activity.getString(R.string.help_user_guide_default_url);

    webView.setWebViewClient(new WebViewClient() {
        boolean hasError = false;

        @Override/*from  ww  w  .j a  v a  2s. c om*/
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
            hasError = false;
            getActivity().setProgressBarIndeterminateVisibility(true);
            refreshIcon.setVisible(false);
        }

        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            super.onReceivedError(view, errorCode, description, failingUrl);

            // We redirect to default EN documentation if locale docs are
            // not available.
            if ((errorCode == ERROR_FILE_NOT_FOUND || errorCode == ERROR_HOST_LOOKUP) && !isDefault
                    && failingUrl.equals(rootUrl)) {
                hasError = true;
                view.loadUrl(defaultUrl);
                view.setVisibility(View.GONE);
            } else if (!ConnectivityUtils.hasInternetAvailable(getActivity())) {
                view.setVisibility(View.GONE);
                emptyView.setVisibility(View.VISIBLE);
                hasError = true;
            }
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            if (hasError) {
                view.setVisibility(View.GONE);
            } else {
                view.setVisibility(View.VISIBLE);
            }

            if (getActivity() != null) {
                getActivity().setProgressBarIndeterminateVisibility(false);
                refreshIcon.setVisible(true);
            }
        }

        public void onFormResubmission(WebView view, Message dontResend, Message resend) {
            resend.sendToTarget();
        }

    });

    webView.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN) {
                switch (keyCode) {
                case KeyEvent.KEYCODE_BACK:
                    if (webView.canGoBack()) {
                        webView.goBack();
                        return true;
                    }
                    break;
                }
            }
            return false;
        }
    });

    rootUrl = getUrl(activity);
    webView.loadUrl(rootUrl);

    return v;
}

From source file:org.alfresco.mobile.android.application.fragments.help.HelpDialogFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.app_webview, container, false);

    webView = (WebView) v.findViewById(org.alfresco.mobile.android.foundation.R.id.webview);
    webView.getSettings().setJavaScriptEnabled(true);
    emptyView = v.findViewById(org.alfresco.mobile.android.foundation.R.id.empty);
    emptyTextView = (TextView) v.findViewById(org.alfresco.mobile.android.foundation.R.id.empty_text);
    emptyTextView.setText(Html.fromHtml(getString(R.string.error_offline)));

    final FragmentActivity activity = getActivity();

    defaultUrl = activity.getString(R.string.help_user_guide_default_url);

    webView.setWebViewClient(new WebViewClient() {
        boolean hasError = false;

        @Override/* w  w  w  .  ja  v  a  2 s.c o m*/
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
            hasError = false;
            displayProgress(true);
            if (refreshIcon != null) {
                refreshIcon.setVisible(false);
            }
        }

        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            super.onReceivedError(view, errorCode, description, failingUrl);

            // We redirect to default EN documentation if locale docs are
            // not available.
            if ((errorCode == ERROR_FILE_NOT_FOUND || errorCode == ERROR_HOST_LOOKUP) && !isDefault
                    && failingUrl.equals(rootUrl)) {
                hasError = true;
                view.loadUrl(defaultUrl);
                view.setVisibility(View.GONE);
            } else if (!ConnectivityUtils.hasInternetAvailable(getActivity())) {
                view.setVisibility(View.GONE);
                emptyView.setVisibility(View.VISIBLE);
                hasError = true;
            }
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            if (getActivity() == null) {
                return;
            }
            super.onPageFinished(view, url);
            if (hasError) {
                view.setVisibility(View.GONE);
            } else {
                view.setVisibility(View.VISIBLE);
            }
            displayProgress(false);
            if (refreshIcon != null) {
                refreshIcon.setVisible(true);
            }
        }

        public void onFormResubmission(WebView view, Message dontResend, Message resend) {
            resend.sendToTarget();
        }

    });

    webView.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN) {
                switch (keyCode) {
                case KeyEvent.KEYCODE_BACK:
                    if (webView.canGoBack()) {
                        webView.goBack();
                        return true;
                    }
                    break;
                }
            }
            return false;
        }
    });

    rootUrl = getUrl(activity);
    webView.loadUrl(rootUrl);

    return v;
}

From source file:com.github.longkai.zhihu.ui.AnswerActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.answer);/*w w  w  .j ava  2  s . c om*/

    final TextView title = (TextView) findViewById(android.R.id.title);
    final WebView desc = (WebView) findViewById(R.id.description);
    final TextView nick = (TextView) findViewById(R.id.nick);
    final ImageView avatar = (ImageView) findViewById(R.id.avatar);
    final TextView status = (TextView) findViewById(R.id.status);
    final WebView answer = (WebView) findViewById(R.id.content);
    final TextView last_alter_date = (TextView) findViewById(R.id.last_alter_date);

    id = getIntent().getLongExtra(ANSWER_ID, 0);
    new AsyncQueryHandler(getContentResolver()) {
        @Override
        protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
            if (cursor.moveToNext()) {
                // 
                aid = cursor.getLong(cursor.getColumnIndex(ANSWER_ID));
                qid = cursor.getLong(cursor.getColumnIndex(QUESTION_ID));
                questionTitle = cursor.getString(cursor.getColumnIndex(TITLE));
                title.setText(questionTitle);
                String description = cursor.getString(cursor.getColumnIndex(DESCRIPTION));
                if (TextUtils.isEmpty(description)) {
                    desc.setVisibility(View.GONE);
                } else {
                    desc.loadDataWithBaseURL(null, description, "text/html", "utf-8", null);
                    desc.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
                    desc.setBackgroundColor(getResources().getColor(R.color.bgcolor));
                }

                // 
                uid = cursor.getString(cursor.getColumnIndex(UID));
                nick.setText(cursor.getString(cursor.getColumnIndex(NICK)));
                String src = cursor.getString(cursor.getColumnIndex(AVATAR));
                ZhihuApp.getImageLoader().get(src,
                        ImageLoader.getImageListener(avatar, R.drawable.ic_launcher, R.drawable.ic_launcher));
                status.setText(cursor.getString(cursor.getColumnIndex(STATUS)));

                // 
                String content = cursor.getString(cursor.getColumnIndex(ANSWER));
                answerDigest = content.length() > 50 ? content.substring(0, 50) : content;
                answer.loadDataWithBaseURL(null, content, "text/html", "utf-8", null);
                answer.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
                answer.setBackgroundColor(getResources().getColor(R.color.bgcolor));

                last_alter_date.setText(DateUtils
                        .getRelativeTimeSpanString(cursor.getLong(cursor.getColumnIndex(LAST_ALTER_DATE))));

                cursor.close();
            }
        }
    }.startQuery(0, null, Uri.parse(ZhihuProvider.BASE_URI + Constants.ITEMS + "/" + id), ITEM_PROJECTION, null,
            null, null);

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}

From source file:nya.miku.wishmaster.http.cloudflare.CloudflareChecker.java

private Cookie checkAntiDDOS(final CloudflareException exception, final HttpHost proxy, CancellableTask task,
        final Activity activity) {
    synchronized (lock) {
        if (processing)
            return null;
        processing = true;//w w w . j a v  a  2s.  com
    }
    processing2 = true;
    currentCookie = null;

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        CookieSyncManager.createInstance(activity);
        CookieManager.getInstance().removeAllCookie();
    } else {
        CompatibilityImpl.clearCookies(CookieManager.getInstance());
    }

    final ViewGroup layout = (ViewGroup) activity.getWindow().getDecorView().getRootView();
    final WebViewClient client = new WebViewClient() {
        @Override
        public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
            handler.proceed();
        }

        @Override
        public void onPageFinished(WebView webView, String url) {
            super.onPageFinished(webView, url);
            Logger.d(TAG, "Got Page: " + url);
            String value = null;
            try {
                String[] cookies = CookieManager.getInstance().getCookie(url).split("[;]");
                for (String cookie : cookies) {
                    if ((cookie != null) && (!cookie.trim().equals(""))
                            && (cookie.startsWith(" " + exception.getRequiredCookieName() + "="))) {
                        value = cookie.substring(exception.getRequiredCookieName().length() + 2);
                    }
                }
            } catch (NullPointerException e) {
                Logger.e(TAG, e);
            }
            if (value != null) {
                BasicClientCookieHC4 cf_cookie = new BasicClientCookieHC4(exception.getRequiredCookieName(),
                        value);
                cf_cookie.setDomain("." + Uri.parse(url).getHost());
                cf_cookie.setPath("/");
                currentCookie = cf_cookie;
                Logger.d(TAG, "Cookie found: " + value);
                processing2 = false;
            } else {
                Logger.d(TAG, "Cookie is not found");
            }
        }
    };

    activity.runOnUiThread(new Runnable() {
        @SuppressLint("SetJavaScriptEnabled")
        @Override
        public void run() {
            webView = new WebView(activity);
            webView.setVisibility(View.GONE);
            layout.addView(webView);
            webView.setWebViewClient(client);
            webView.getSettings().setUserAgentString(HttpConstants.USER_AGENT_STRING);
            webView.getSettings().setJavaScriptEnabled(true);
            webViewContext = webView.getContext();
            if (proxy != null)
                WebViewProxy.setProxy(webViewContext, proxy.getHostName(), proxy.getPort());
            webView.loadUrl(exception.getCheckUrl());
        }
    });

    long startTime = System.currentTimeMillis();
    while (processing2) {
        long time = System.currentTimeMillis() - startTime;
        if ((task != null && task.isCancelled()) || time > TIMEOUT) {
            processing2 = false;
        }
    }

    activity.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            try {
                layout.removeView(webView);
                webView.stopLoading();
                webView.clearCache(true);
                webView.destroy();
                webView = null;
            } finally {
                if (proxy != null)
                    WebViewProxy.setProxy(webViewContext, null, 0);
                processing = false;
            }
        }
    });

    return currentCookie;
}

From source file:im.vector.adapters.VectorMediasViewerAdapter.java

@Override
public Object instantiateItem(ViewGroup container, final int position) {
    View view = mLayoutInflater.inflate(R.layout.adapter_vector_medias_viewer, null, false);

    // hide the pie chart
    final PieFractionView pieFractionView = (PieFractionView) view.findViewById(R.id.media_slider_piechart);
    pieFractionView.setVisibility(View.GONE);

    final WebView imageWebView = (WebView) view.findViewById(R.id.media_slider_image_webview);
    final View videoLayout = view.findViewById(R.id.media_slider_videolayout);
    final ImageView thumbView = (ImageView) view.findViewById(R.id.media_slider_video_thumbnail);

    imageWebView.getSettings().setDisplayZoomControls(false);

    imageWebView.setOnLongClickListener(new View.OnLongClickListener() {
        @Override//from  w  ww  .j a  va2 s.  c  o  m
        public boolean onLongClick(View v) {
            VectorMediasViewerAdapter.this.onLongClick();
            return true;
        }
    });

    thumbView.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            VectorMediasViewerAdapter.this.onLongClick();
            return true;
        }
    });

    // black background
    view.setBackgroundColor(0xFF000000);
    imageWebView.setBackgroundColor(0xFF000000);
    videoLayout.setBackgroundColor(0xFF000000);

    final SlidableMediaInfo mediaInfo = mMediasMessagesList.get(position);
    String mediaUrl = mediaInfo.mMediaUrl;

    if (mediaInfo.mMessageType.equals(Message.MSGTYPE_IMAGE)) {
        imageWebView.setVisibility(View.VISIBLE);
        imageWebView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
        imageWebView.getSettings().setJavaScriptEnabled(true);
        imageWebView.getSettings().setLoadWithOverviewMode(true);
        imageWebView.getSettings().setUseWideViewPort(true);
        imageWebView.getSettings().setBuiltInZoomControls(true);

        videoLayout.setVisibility(View.GONE);

        final int rotationAngle = mediaInfo.mRotationAngle;
        final String mimeType = mediaInfo.mMimeType;
        File mediaFile = mMediasCache.mediaCacheFile(mediaUrl, mimeType);

        // is the high picture already downloaded ?
        if (null != mediaFile) {
            if (mHighResMediaIndex.indexOf(position) < 0) {
                mHighResMediaIndex.add(position);
            }
        } else {
            // try to retrieve the thumbnail
            mediaFile = mMediasCache.mediaCacheFile(mediaUrl, mMaxImageWidth, mMaxImageHeight, null);
        }

        // the thumbnail is not yet downloaded
        if (null == mediaFile) {
            // display nothing
            container.addView(view, 0);
            return view;
        }

        String mediaUri = "file://" + mediaFile.getPath();

        String css = computeCss(mediaUri, mMaxImageWidth, mMaxImageHeight, rotationAngle);
        final String viewportContent = "width=640";
        loadImage(imageWebView, Uri.parse(mediaUri), viewportContent, css);
        container.addView(view, 0);
    } else {
        loadVideo(position, view, mediaInfo.mThumbnailUrl, mediaUrl, mediaInfo.mMimeType);
        container.addView(view, 0);
    }

    // check if the media is downloading
    String downloadId = mMediasCache.downloadMedia(mContext, mSession.getHomeserverConfig(), mediaUrl,
            mediaInfo.mMimeType);

    if (null != downloadId) {
        pieFractionView.setVisibility(View.VISIBLE);
        pieFractionView.setFraction(mMediasCache.getProgressValueForDownloadId(downloadId));
        pieFractionView.setTag(downloadId);

        mMediasCache.addDownloadListener(downloadId, new MXMediaDownloadListener() {
            @Override
            public void onDownloadError(String downloadId, JsonElement jsonElement) {
                pieFractionView.setVisibility(View.GONE);
                MatrixError error = JsonUtils.toMatrixError(jsonElement);

                if ((null != error) && error.isSupportedErrorCode()) {
                    Toast.makeText(VectorMediasViewerAdapter.this.mContext, error.getLocalizedMessage(),
                            Toast.LENGTH_LONG).show();
                }
            }

            @Override
            public void onDownloadProgress(String aDownloadId, DownloadStats stats) {
                if (aDownloadId.equals(pieFractionView.getTag())) {
                    pieFractionView.setFraction(stats.mProgress);
                }
            }

            @Override
            public void onDownloadComplete(String aDownloadId) {
                if (aDownloadId.equals(pieFractionView.getTag())) {
                    pieFractionView.setVisibility(View.GONE);
                }
            }
        });
    }

    return view;
}

From source file:im.neon.adapters.VectorMediasViewerAdapter.java

@Override
public Object instantiateItem(ViewGroup container, final int position) {
    View view = mLayoutInflater.inflate(R.layout.adapter_vector_medias_viewer, null, false);

    // hide the pie chart
    final PieFractionView pieFractionView = (PieFractionView) view.findViewById(R.id.media_slider_piechart);
    pieFractionView.setVisibility(View.GONE);

    final WebView imageWebView = (WebView) view.findViewById(R.id.media_slider_image_webview);
    final View videoLayout = view.findViewById(R.id.media_slider_videolayout);
    final ImageView thumbView = (ImageView) view.findViewById(R.id.media_slider_video_thumbnail);

    imageWebView.getSettings().setDisplayZoomControls(false);

    imageWebView.setOnLongClickListener(new View.OnLongClickListener() {
        @Override//from   w  ww.  java2 s .  c o m
        public boolean onLongClick(View v) {
            VectorMediasViewerAdapter.this.onLongClick();
            return true;
        }
    });

    thumbView.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            VectorMediasViewerAdapter.this.onLongClick();
            return true;
        }
    });

    // black background
    view.setBackgroundColor(0xFF000000);
    imageWebView.setBackgroundColor(0xFF000000);
    videoLayout.setBackgroundColor(0xFF000000);

    final SlidableMediaInfo mediaInfo = mMediasMessagesList.get(position);
    String mediaUrl = mediaInfo.mMediaUrl;

    if (mediaInfo.mMessageType.equals(Message.MSGTYPE_IMAGE)) {
        imageWebView.setVisibility(View.VISIBLE);
        imageWebView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
        imageWebView.getSettings().setJavaScriptEnabled(true);
        imageWebView.getSettings().setLoadWithOverviewMode(true);
        imageWebView.getSettings().setUseWideViewPort(true);
        imageWebView.getSettings().setBuiltInZoomControls(true);

        videoLayout.setVisibility(View.GONE);

        final int rotationAngle = mediaInfo.mRotationAngle;

        if (TextUtils.isEmpty(mediaInfo.mMimeType)) {
            mediaInfo.mMimeType = "image/jpeg";
        }

        final String mimeType = mediaInfo.mMimeType;
        File mediaFile = mMediasCache.mediaCacheFile(mediaUrl, mimeType);

        // is the high picture already downloaded ?
        if (null != mediaFile) {
            if (mHighResMediaIndex.indexOf(position) < 0) {
                mHighResMediaIndex.add(position);
            }
        } else {
            // try to retrieve the thumbnail
            mediaFile = mMediasCache.mediaCacheFile(mediaUrl, mMaxImageWidth, mMaxImageHeight, null);
        }

        // the thumbnail is not yet downloaded
        if (null == mediaFile) {
            // display nothing
            container.addView(view, 0);
            return view;
        }

        String mediaUri = "file://" + mediaFile.getPath();

        String css = computeCss(mediaUri, mMaxImageWidth, mMaxImageHeight, rotationAngle);
        final String viewportContent = "width=640";
        loadImage(imageWebView, Uri.parse(mediaUri), viewportContent, css);
        container.addView(view, 0);
    } else {
        loadVideo(position, view, mediaInfo.mThumbnailUrl, mediaUrl, mediaInfo.mMimeType);
        container.addView(view, 0);
    }

    // check if the media is downloading
    String downloadId = mMediasCache.downloadMedia(mContext, mSession.getHomeserverConfig(), mediaUrl,
            mediaInfo.mMimeType, mediaInfo.mEncryptedFileInfo);

    if (null != downloadId) {
        pieFractionView.setVisibility(View.VISIBLE);
        pieFractionView.setFraction(mMediasCache.getProgressValueForDownloadId(downloadId));
        pieFractionView.setTag(downloadId);

        mMediasCache.addDownloadListener(downloadId, new MXMediaDownloadListener() {
            @Override
            public void onDownloadError(String downloadId, JsonElement jsonElement) {
                pieFractionView.setVisibility(View.GONE);
                MatrixError error = JsonUtils.toMatrixError(jsonElement);

                if ((null != error) && error.isSupportedErrorCode()) {
                    Toast.makeText(VectorMediasViewerAdapter.this.mContext, error.getLocalizedMessage(),
                            Toast.LENGTH_LONG).show();
                }
            }

            @Override
            public void onDownloadProgress(String aDownloadId, DownloadStats stats) {
                if (aDownloadId.equals(pieFractionView.getTag())) {
                    pieFractionView.setFraction(stats.mProgress);
                }
            }

            @Override
            public void onDownloadComplete(String aDownloadId) {
                if (aDownloadId.equals(pieFractionView.getTag())) {
                    pieFractionView.setVisibility(View.GONE);
                }
            }
        });
    }

    return view;
}

From source file:app.clirnet.com.clirnetapp.activity.LoginActivity.java

private void showDialog12() {

    final View checkBoxView = View.inflate(this, R.layout.alert_checkbox, null);
    final CheckBox checkBox = (CheckBox) checkBoxView.findViewById(R.id.checkBox);
    final WebView wv = (WebView) checkBoxView.findViewById(R.id.webview);

    //  checkBox.setText("Yes, I accept the terms and condition");
    final AlertDialog.Builder ad = new AlertDialog.Builder(this)
            // .setMessage(termsnconditiomessage)
            .setView(checkBoxView).setIcon(R.drawable.info).setTitle("Terms of Service");

    checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override//from  w  w w. j  ava2 s  . co m
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

            if (isChecked) {
                //Method will send radio button checked status to yes button for further process of redirection
                checkedStatus(true);

            } else {

                checkedStatus(false);
                Toast.makeText(getApplicationContext(), "Please accept the terms and condition to proceed ",
                        Toast.LENGTH_LONG).show();
            }

        }

    });

    wv.setVisibility(View.VISIBLE);
    wv.loadUrl("http://doctor.clirnet.com/doctor/patientcentral/termsandcondition");
    wv.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);

            return true;
        }
    });

    ad.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            //Toast.makeText(mContext.getApplicationContext(), "You have accepted the TOS. Welcom to the site", Toast.LENGTH_SHORT).show();
            if (responceCheck) {
                rememberTermsCondition("Yes");
                Intent intent = new Intent(getApplicationContext(), SplashActivity.class);
                startActivity(intent);
                new AppController().showToastMsg(getApplicationContext(), "Login Successful");
                startService();

            } else {
                new AppController().showToastMsg(getApplicationContext(),
                        "Please accept the terms and condition to proceed");
                // Toast.makeText(mContext.getApplicationContext(), "Please accept the terms and condition to proceed", Toast.LENGTH_SHORT).show();

            }

        }
    });
    ad.setNegativeButton("No", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            Toast.makeText(getApplicationContext(), "You have denied the TOS. You may not access the site",
                    Toast.LENGTH_SHORT).show();
            rememberTermsCondition("No");
        }
    });

    ad.setNeutralButton("Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            Toast.makeText(getApplicationContext(), "Please select yes or no", Toast.LENGTH_SHORT).show();
            rememberTermsCondition("No");
        }
    });

    ad.setCancelable(false);
    ad.setView(checkBoxView);
    ad.show();

}