Example usage for android.widget ProgressBar setVisibility

List of usage examples for android.widget ProgressBar setVisibility

Introduction

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

Prototype

@RemotableViewMethod
public void setVisibility(@Visibility int visibility) 

Source Link

Document

Set the visibility state of this view.

Usage

From source file:com.pemikir.youtubeplus.VideoItemDetailFragment.java

public void updateInfo(VideoInfo info) {
    Activity a = getActivity();/*  w w w  .  j  av a  2s  . c  om*/
    try {
        ProgressBar progressBar = (ProgressBar) a.findViewById(R.id.detailProgressBar);
        TextView videoTitleView = (TextView) a.findViewById(R.id.detailVideoTitleView);
        TextView uploaderView = (TextView) a.findViewById(R.id.detailUploaderView);
        TextView viewCountView = (TextView) a.findViewById(R.id.detailViewCountView);
        TextView thumbsUpView = (TextView) a.findViewById(R.id.detailThumbsUpCountView);
        TextView thumbsDownView = (TextView) a.findViewById(R.id.detailThumbsDownCountView);
        TextView uploadDateView = (TextView) a.findViewById(R.id.detailUploadDateView);
        TextView descriptionView = (TextView) a.findViewById(R.id.detailDescriptionView);
        ImageView thumbnailView = (ImageView) a.findViewById(R.id.detailThumbnailView);
        ImageView uploaderThumbnailView = (ImageView) a.findViewById(R.id.detailUploaderThumbnailView);
        ImageView thumbsUpPic = (ImageView) a.findViewById(R.id.detailThumbsUpImgView);
        ImageView thumbsDownPic = (ImageView) a.findViewById(R.id.detailThumbsDownImgView);
        View textSeperationLine = a.findViewById(R.id.textSeperationLine);

        if (textSeperationLine != null) {
            textSeperationLine.setVisibility(View.VISIBLE);
        }
        progressBar.setVisibility(View.GONE);
        videoTitleView.setVisibility(View.VISIBLE);
        uploaderView.setVisibility(View.VISIBLE);
        uploadDateView.setVisibility(View.VISIBLE);
        viewCountView.setVisibility(View.VISIBLE);
        thumbsUpView.setVisibility(View.VISIBLE);
        thumbsDownView.setVisibility(View.VISIBLE);
        uploadDateView.setVisibility(View.VISIBLE);
        descriptionView.setVisibility(View.VISIBLE);
        thumbnailView.setVisibility(View.VISIBLE);
        uploaderThumbnailView.setVisibility(View.VISIBLE);
        thumbsUpPic.setVisibility(View.VISIBLE);
        thumbsDownPic.setVisibility(View.VISIBLE);

        switch (info.videoAvailableStatus) {
        case VideoInfo.VIDEO_AVAILABLE: {
            videoTitleView.setText(info.title);
            uploaderView.setText(info.uploader);
            viewCountView.setText(info.view_count + " " + a.getString(R.string.viewSufix));
            thumbsUpView.setText(info.like_count);
            thumbsDownView.setText(info.dislike_count);
            uploadDateView.setText(a.getString(R.string.uploadDatePrefix) + " " + info.upload_date);
            descriptionView.setText(Html.fromHtml(info.description));
            descriptionView.setMovementMethod(LinkMovementMethod.getInstance());

            ActionBarHandler.getHandler().setVideoInfo(info.webpage_url, info.title);

            // parse streams
            Vector<VideoInfo.VideoStream> streamsToUse = new Vector<>();
            for (VideoInfo.VideoStream i : info.videoStreams) {
                if (useStream(i, streamsToUse)) {
                    streamsToUse.add(i);
                }
            }
            VideoInfo.VideoStream[] streamList = new VideoInfo.VideoStream[streamsToUse.size()];
            for (int i = 0; i < streamList.length; i++) {
                streamList[i] = streamsToUse.get(i);
            }
            ActionBarHandler.getHandler().setStreams(streamList, info.audioStreams);
        }
            break;
        case VideoInfo.VIDEO_UNAVAILABLE_GEMA:
            thumbnailView.setImageBitmap(
                    BitmapFactory.decodeResource(getResources(), R.drawable.gruese_die_gema_unangebracht));
            break;
        case VideoInfo.VIDEO_UNAVAILABLE:
            thumbnailView.setImageBitmap(
                    BitmapFactory.decodeResource(getResources(), R.drawable.not_available_monkey));
            break;
        default:
            Log.e(TAG, "Video Availeble Status not known.");
        }

        if (autoPlayEnabled) {
            ActionBarHandler.getHandler().playVideo();
        }
    } catch (java.lang.NullPointerException e) {
        Log.w(TAG, "updateInfo(): Fragment closed before thread ended work... or else");
        e.printStackTrace();
    }
}

From source file:fr.bmartel.android.dotti.DottiActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_dotti);

    // Use this check to determine whether BLE is supported on the device. Then
    // you can selectively disable BLE-related features.
    if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
        Toast.makeText(this, "Bluetooth Smart is not supported on your device", Toast.LENGTH_SHORT).show();
        finish();//from w w  w  .  j ava  2s  .  c om
    }

    mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

    if (!mBluetoothAdapter.isEnabled()) {
        Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
    }

    final ProgressBar progress_bar = (ProgressBar) findViewById(R.id.scanningProgress);

    if (progress_bar != null)
        progress_bar.setEnabled(false);

    final Button button_stop_scanning = (Button) findViewById(R.id.stop_scanning_button);

    if (button_stop_scanning != null)
        button_stop_scanning.setEnabled(false);

    final TextView scanText = (TextView) findViewById(R.id.scanText);

    if (scanText != null)
        scanText.setText("");

    registerReceiver(mGattUpdateReceiver, makeGattUpdateIntentFilter());

    button_stop_scanning.setEnabled(false);

    final Button button_find_accessory = (Button) findViewById(R.id.scanning_button);

    button_stop_scanning.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            if (currentService != null && currentService.isScanning()) {

                currentService.stopScan();

                if (progress_bar != null) {
                    progress_bar.setEnabled(false);
                    progress_bar.setVisibility(View.GONE);
                }

                if (scanText != null)
                    scanText.setText("");

                if (button_stop_scanning != null)
                    button_stop_scanning.setEnabled(false);
            }
        }
    });

    button_find_accessory.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            triggerNewScan();
        }
    });

    if (mBluetoothAdapter.isEnabled()) {

        Intent intent = new Intent(this, DottiBtService.class);

        // bind the service to current activity and create it if it didnt exist before
        startService(intent);
        bound = bindService(intent, mServiceConnection, BIND_AUTO_CREATE);
    }
}

From source file:com.hichinaschool.flashcards.anki.Feedback.java

private void refreshInterface() {
    if (mAllowFeedback) {
        Resources res = getResources();
        Button btnSend = (Button) findViewById(R.id.btnFeedbackSend);
        Button btnKeepLatest = (Button) findViewById(R.id.btnFeedbackKeepLatest);
        Button btnClearAll = (Button) findViewById(R.id.btnFeedbackClearAll);
        ProgressBar pbSpinner = (ProgressBar) findViewById(R.id.pbFeedbackSpinner);

        int numErrors = mErrorReports.size();
        if (numErrors == 0 || mErrorsSent) {
            if (!mErrorsSent) {
                mLvErrorList.setVisibility(View.GONE);
            }/*from   w w  w.ja va  2 s . co m*/
            btnKeepLatest.setVisibility(View.GONE);
            btnClearAll.setVisibility(View.GONE);
            btnSend.setText(res.getString(R.string.feedback_send_feedback));
        } else {
            mLvErrorList.setVisibility(View.VISIBLE);
            btnKeepLatest.setVisibility(View.VISIBLE);
            btnClearAll.setVisibility(View.VISIBLE);
            btnSend.setText(res.getString(R.string.feedback_send_feedback_and_errors));
            refreshErrorListView();
            if (numErrors == 1) {
                btnKeepLatest.setEnabled(false);
            } else {
                btnKeepLatest.setEnabled(true);
            }
        }

        if (mPostingFeedback) {
            int buttonHeight = btnSend.getHeight();
            btnSend.setVisibility(View.GONE);
            pbSpinner.setVisibility(View.VISIBLE);
            LinearLayout topLine = (LinearLayout) findViewById(R.id.llFeedbackTopLine);
            topLine.setMinimumHeight(buttonHeight);

            mEtFeedbackText.setEnabled(false);
            mImm.hideSoftInputFromWindow(mEtFeedbackText.getWindowToken(), 0);
        } else {
            btnSend.setVisibility(View.VISIBLE);
            pbSpinner.setVisibility(View.GONE);
            mEtFeedbackText.setEnabled(true);
        }
    }
}

From source file:br.org.funcate.dynamicforms.views.GPictureView.java

public void refresh(final Context context) throws Exception {

    imageLayout.removeAllViewsInLayout();
    int increaseTime = 0;// using on runnable

    if (_pictures != null && _pictures.size() > 0) {

        Set<String> imageKeys = _pictures.keySet();
        for (final String imageId : imageKeys) {

            if (!_pictures.containsKey(imageId)) {
                // TODO: Here, write a log in logfile
                continue;
            } else {
                Map<String, String> imagePaths = _pictures.get(imageId);
                final String imagePath = imagePaths.get("thumbnail");
                final ProgressBar pgBar = getProgressBar(context);
                imageLayout.addView(pgBar);
                increaseTime++;//from  ww  w  .  j a  v  a 2 s  . c o m

                Handler handler = new Handler();
                handler.postDelayed(new Runnable() {
                    public void run() {
                        /*
                                                    byte[] image = ImageUtilities.getImageFromPath(imagePath, 2);
                                                    if (image != null && image.length > 0) {
                        Bitmap imageBitmap = ImageUtilities.getBitmapFromBlob(image);
                        try {
                            image = null;
                        } catch (Throwable t) {
                            t.printStackTrace();
                            getDefaultBitmap();
                            return;
                        }
                                
                        Bitmap thumbnail = ImageUtilities.makeThumbnail(imageBitmap);
                        if (imageBitmap.isRecycled()) imageBitmap.recycle();
                        */
                        if (imagePath != null && !imagePath.isEmpty() && (new File(imagePath)).exists()) {
                            pgBar.setVisibility(View.GONE);
                            imageLayout.addView(getImageView(context, imagePath, imageId));
                            imageLayout.invalidate();
                            //if (thumbnail.isRecycled()) thumbnail.recycle();
                        } else {
                            getDefaultBitmap();
                        }
                    }

                    public void getDefaultBitmap() {
                        pgBar.setVisibility(View.GONE);
                        Bitmap bitmapError = BitmapFactory.decodeResource(getResources(),
                                R.drawable.ic_stat_action_highlight_remove);
                        imageLayout.addView(getImageView(context, bitmapError, imageId));
                        imageLayout.invalidate();
                        // if (bitmapError.isRecycled()) bitmapError.recycle();
                    }
                }, increaseTime * 1000 + 1000);
            }
        }
    }
    if (newImagesFromCamera != null && newImagesFromCamera.size() > 0) {
        Set<String> imageKeys = newImagesFromCamera.keySet();
        for (final String imageId : imageKeys) {

            final String imagePath = newImagesFromCamera.get(imageId);
            final ProgressBar pgBar = getProgressBar(context);
            imageLayout.addView(pgBar);
            increaseTime++;

            Handler handler = new Handler();
            handler.postDelayed(new Runnable() {
                public void run() {
                    try {

                        if (imagePath != null && !imagePath.isEmpty() && (new File(imagePath)).exists()) {

                            pgBar.setVisibility(View.GONE);
                            imageLayout.addView(getImageView(context, imagePath, imageId));
                            imageLayout.invalidate();

                            /*
                            if (!ImageUtilities.resampleImage(imagePath)) {
                            getDefaultBitmap();
                            return;
                            }
                            byte[] image = ImageUtilities.getImageFromPath(imagePath, 2);
                            if (image != null) {
                            Bitmap imageBitmap = ImageUtilities.getBitmapFromBlob(image);
                            image = null;
                            Bitmap thumbnail = ImageUtilities.makeThumbnail(imageBitmap);
                            imageBitmap = null;
                            pgBar.setVisibility(View.GONE);
                            imageLayout.addView(getImageView(context, thumbnail, imageId));
                            thumbnail = null;
                            imageLayout.invalidate();
                            } else {
                            getDefaultBitmap();
                            }
                            */
                        }
                    } catch (Throwable e) {
                        e.printStackTrace();
                        getDefaultBitmap();
                    }
                }

                public void getDefaultBitmap() {
                    pgBar.setVisibility(View.GONE);
                    Bitmap bitmapError = BitmapFactory.decodeResource(getResources(),
                            R.drawable.ic_stat_action_highlight_remove);
                    imageLayout.addView(getImageView(context, bitmapError, imageId));
                    imageLayout.invalidate();
                }
            }, increaseTime * 1000 + 1000);

            if (!addedIdsToImageViews.containsValue(imagePath))
                addedIdsToImageViews.put(imageId, imagePath);
        }
    }

    imageLayout.invalidate();

}

From source file:net.olejon.mdapp.MedicationNlhFragment.java

@SuppressLint("SetJavaScriptEnabled")
@Override//  w  ww.  j  a  va2s. co m
public View onCreateView(LayoutInflater inflater, ViewGroup container, final Bundle savedInstanceState) {
    ViewGroup viewGroup = (ViewGroup) inflater.inflate(R.layout.fragment_medication_nlh, container, false);

    // Activity
    final Activity activity = getActivity();

    // Context
    final Context context = activity.getApplicationContext();

    // Tools
    final MyTools mTools = new MyTools(context);

    // Arguments
    Bundle bundle = getArguments();

    final String pageUri = bundle.getString("uri");

    // Progress bar
    final ProgressBar progressBar = (ProgressBar) activity
            .findViewById(R.id.medication_toolbar_progressbar_horizontal);

    // Toolbar
    final LinearLayout toolbarSearchLayout = (LinearLayout) activity
            .findViewById(R.id.medication_toolbar_search_layout);
    final EditText toolbarSearchEditText = (EditText) activity.findViewById(R.id.medication_toolbar_search);

    // Web view
    WEBVIEW = (WebView) viewGroup.findViewById(R.id.medication_nlh_content);

    WebSettings webSettings = WEBVIEW.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setAppCacheEnabled(true);
    webSettings.setDomStorageEnabled(true);
    webSettings.setAppCachePath(context.getCacheDir().getAbsolutePath());
    webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);

    WEBVIEW.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (!mTools.isDeviceConnected()) {
                mTools.showToast(getString(R.string.device_not_connected), 0);
                return true;
            } else if (url.matches(".*/[^#]+#[^/]+$")) {
                WEBVIEW.loadUrl(url.replaceAll("#[^/]+$", ""));
                return true;
            } else if (url.matches("^https?://.*?\\.pdf$")) {
                mTools.downloadFile(view.getTitle(), url);
                return true;
            }

            return false;
        }
    });

    WEBVIEW.setWebChromeClient(new WebChromeClient() {
        @Override
        public void onProgressChanged(WebView view, int newProgress) {
            if (newProgress == 100) {
                progressBar.setVisibility(View.INVISIBLE);
            } else {
                progressBar.setVisibility(View.VISIBLE);
                progressBar.setProgress(newProgress);

                toolbarSearchLayout.setVisibility(View.GONE);
                toolbarSearchEditText.setText("");
            }
        }
    });

    if (savedInstanceState == null) {
        WEBVIEW.loadUrl(pageUri);
    } else {
        WEBVIEW.restoreState(savedInstanceState);
    }

    return viewGroup;
}

From source file:org.tigase.mobile.accountstatus.AccountsStatusFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    this.view = inflater.inflate(R.layout.account_status, null);

    this.adapter = new ArrayAdapter<Jaxmpp>(getActivity().getApplicationContext(),
            R.layout.account_status_item) {

        @Override/*from w w w  .  j av  a 2 s.  co  m*/
        public View getView(int position, View convertView, ViewGroup parent) {
            View v = convertView;
            if (v == null) {
                v = inflater.inflate(R.layout.account_status_item, null);
            }

            Jaxmpp jaxmpp = getItem(position);

            final TextView accountName = (TextView) v.findViewById(R.id.account_name);
            final TextView accountDescription = (TextView) v.findViewById(R.id.account_item_description);
            final ImageView accountStatus = (ImageView) v.findViewById(R.id.account_status);
            final ImageView securityEmblem = (ImageView) v.findViewById(R.id.account_secured_emblem);
            final ProgressBar progressBar = (ProgressBar) v.findViewById(R.id.account_status_progress);
            final ImageView accountAvatar = (ImageView) v.findViewById(R.id.imageView1);

            final boolean established = jaxmpp.getSessionObject()
                    .getProperty(ResourceBinderModule.BINDED_RESOURCE_JID) != null;
            State st = jaxmpp.getSessionObject().getProperty(Connector.CONNECTOR_STAGE_KEY);
            if (st == null)
                st = State.disconnected;
            else if (st == State.connected && !established)
                st = State.connecting;

            boolean secured = st == State.disconnected ? false : jaxmpp.getConnector().isSecure();
            securityEmblem.setVisibility(st != State.disconnected && secured ? View.VISIBLE : View.GONE);

            String errorMessage = jaxmpp.getSessionObject().getProperty("messenger#error");

            if (st == State.disconnected && !TextUtils.isEmpty(errorMessage)) {
                accountDescription.setText("Error: " + errorMessage);
            } else
                accountDescription.setText("" + st);

            accountName.setText(jaxmpp.getSessionObject().getUserBareJid().toString());

            AvatarHelper.setAvatarToImageView(jaxmpp.getSessionObject().getUserBareJid(), accountAvatar);

            if (st == State.connected) {
                accountStatus.setImageResource(R.drawable.user_available);
                accountStatus.setVisibility(View.VISIBLE);
                progressBar.setVisibility(View.GONE);
            } else if (st == State.disconnected) {
                accountStatus.setImageResource(R.drawable.user_offline);
                accountStatus.setVisibility(View.VISIBLE);
                progressBar.setVisibility(View.GONE);
            } else {
                accountStatus.setVisibility(View.GONE);
                progressBar.setVisibility(View.VISIBLE);
            }
            return v;
        }

    };

    // loadData();

    ListView list = (ListView) view.findViewById(R.id.account_status_list);
    list.setAdapter(adapter);
    registerForContextMenu(list);

    return view;
}

From source file:jahirfiquitiva.iconshowcase.activities.WallpaperViewerActivity.java

@SuppressWarnings("ResourceAsColor")
@Override/*from ww  w.j  av a  2  s  . c  om*/
protected void onCreate(Bundle savedInstanceState) {

    ThemeUtils.onActivityCreateSetTheme(this);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        ThemeUtils.onActivityCreateSetNavBar(this);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    }

    super.onCreate(savedInstanceState);

    makeStatusBarIconsWhite();

    context = this;

    mPrefs = new Preferences(context);

    Intent intent = getIntent();
    String transitionName = intent.getStringExtra("transitionName");

    item = intent.getParcelableExtra("item");

    setContentView(R.layout.wallpaper_viewer_activity);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    if (getSupportActionBar() != null) {
        getSupportActionBar().setTitle("");
        getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_back_with_shadow);
        getSupportActionBar().setHomeButtonEnabled(true);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setDisplayShowHomeEnabled(true);
    }

    ToolbarColorizer.colorizeToolbar(toolbar, ContextCompat.getColor(context, android.R.color.white));

    toHide1 = (LinearLayout) findViewById(R.id.iconsA);
    toHide2 = (LinearLayout) findViewById(R.id.iconsB);

    int tintColor = ThemeUtils.darkOrLight(context, R.color.drawable_tint_dark, R.color.drawable_base_tint);

    Drawable save = IconUtils.getTintedIcon(context, R.drawable.ic_save, tintColor);

    Drawable apply = IconUtils.getTintedIcon(context, R.drawable.ic_apply_wallpaper, tintColor);

    Drawable info = IconUtils.getTintedIcon(context, R.drawable.ic_info, tintColor);

    ImageView saveIV = (ImageView) findViewById(R.id.download);
    if (item.isDownloadable()) {
        saveIV.setImageDrawable(save);
        saveIV.setOnClickListener(new DebouncedClickListener() {
            @Override
            public void onDebouncedClick(View v) {
                if (!PermissionUtils.canAccessStorage(context)) {
                    PermissionUtils.setViewerActivityAction("save");
                    PermissionUtils.requestStoragePermission(context);
                } else {
                    showDialogs("save");
                }
            }
        });
    } else {
        saveIV.setVisibility(View.GONE);
    }

    ImageView applyIV = (ImageView) findViewById(R.id.apply);
    applyIV.setImageDrawable(apply);
    applyIV.setOnClickListener(new DebouncedClickListener() {
        @Override
        public void onDebouncedClick(View v) {
            showApplyWallpaperDialog(item.getWallURL());
        }
    });

    ImageView infoIV = (ImageView) findViewById(R.id.info);
    infoIV.setImageDrawable(info);
    infoIV.setOnClickListener(new DebouncedClickListener() {
        @Override
        public void onDebouncedClick(View v) {
            ISDialogs.showWallpaperDetailsDialog(context, item.getWallName(), item.getWallAuthor(),
                    item.getWallDimensions(), item.getWallCopyright(), new DialogInterface.OnDismissListener() {
                        @Override
                        public void onDismiss(DialogInterface dialogInterface) {
                            //Do nothing
                        }
                    });
        }
    });

    TouchImageView mPhoto = (TouchImageView) findViewById(R.id.big_wallpaper);
    ViewCompat.setTransitionName(mPhoto, transitionName);

    layout = (RelativeLayout) findViewById(R.id.viewerLayout);

    TextView wallNameText = (TextView) findViewById(R.id.wallName);
    wallNameText.setText(item.getWallName());

    Bitmap bmp = null;
    String filename = getIntent().getStringExtra("image");
    try {
        if (filename != null) {
            FileInputStream is = context.openFileInput(filename);
            bmp = BitmapFactory.decodeStream(is);
            is.close();
        } else {
            bmp = null;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    int colorFromCachedPic;

    if (bmp != null) {
        colorFromCachedPic = ColorUtils.getPaletteSwatch(bmp).getTitleTextColor();
    } else {
        colorFromCachedPic = tintColor;
    }

    final ProgressBar spinner = (ProgressBar) findViewById(R.id.progress);
    spinner.getIndeterminateDrawable().setColorFilter(colorFromCachedPic, PorterDuff.Mode.SRC_IN);

    Drawable d;
    if (bmp != null) {
        d = new GlideBitmapDrawable(getResources(), bmp);
    } else {
        d = new ColorDrawable(ContextCompat.getColor(context, android.R.color.transparent));
    }

    if (mPrefs.getAnimationsEnabled()) {
        Glide.with(context).load(item.getWallURL()).placeholder(d).diskCacheStrategy(DiskCacheStrategy.SOURCE)
                .fitCenter().listener(new RequestListener<String, GlideDrawable>() {
                    @Override
                    public boolean onException(Exception e, String model, Target<GlideDrawable> target,
                            boolean isFirstResource) {
                        return false;
                    }

                    @Override
                    public boolean onResourceReady(GlideDrawable resource, String model,
                            Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
                        spinner.setVisibility(View.GONE);
                        return false;
                    }
                }).into(mPhoto);
    } else {
        Glide.with(context).load(item.getWallURL()).placeholder(d).dontAnimate()
                .diskCacheStrategy(DiskCacheStrategy.SOURCE).fitCenter()
                .listener(new RequestListener<String, GlideDrawable>() {
                    @Override
                    public boolean onException(Exception e, String model, Target<GlideDrawable> target,
                            boolean isFirstResource) {
                        return false;
                    }

                    @Override
                    public boolean onResourceReady(GlideDrawable resource, String model,
                            Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
                        spinner.setVisibility(View.GONE);
                        return false;
                    }
                }).into(mPhoto);
    }
}

From source file:jahirfiquitiva.iconshowcase.activities.AltWallpaperViewerActivity.java

@SuppressWarnings("ResourceAsColor")
@Override//  w w w . j av a2  s.c  o  m
protected void onCreate(Bundle savedInstanceState) {

    ThemeUtils.onActivityCreateSetTheme(this);

    setupFullScreen();

    super.onCreate(savedInstanceState);

    mPrefs = new Preferences(this);

    Intent intent = getIntent();
    String transitionName = intent.getStringExtra("transitionName");

    item = intent.getParcelableExtra("item");

    setContentView(R.layout.alt_wallpaper_viewer_activity);

    fab = (FloatingActionButton) findViewById(R.id.fab);
    applyFab = (FloatingActionButton) findViewById(R.id.applyFab);
    saveFab = (FloatingActionButton) findViewById(R.id.saveFab);
    infoFab = (FloatingActionButton) findViewById(R.id.infoFab);

    hideFab(applyFab);
    hideFab(saveFab);
    hideFab(infoFab);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    if (getSupportActionBar() != null) {
        getSupportActionBar().setTitle(item.getWallName());
        getSupportActionBar().setSubtitle(item.getWallAuthor());
        getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_back_with_shadow);
        changeToolbarTextAppearance(toolbar);
        getSupportActionBar().setHomeButtonEnabled(true);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setDisplayShowHomeEnabled(true);
    }

    if (Build.VERSION.SDK_INT < 19) {
        ToolbarColorizer.colorizeToolbar(toolbar, ContextCompat.getColor(this, android.R.color.white));
    }

    fab.setOnClickListener(new DebouncedClickListener() {
        @Override
        public void onDebouncedClick(View v) {
            if (fabOpened) {
                closeMenu();
            } else {
                openMenu();
            }
            fabOpened = !fabOpened;
        }
    });

    applyFab.setOnClickListener(new DebouncedClickListener() {
        @Override
        public void onDebouncedClick(View v) {
            showApplyWallpaperDialog(AltWallpaperViewerActivity.this, item.getWallURL());
        }
    });

    if (item.isDownloadable()) {
        saveFab.setOnClickListener(new DebouncedClickListener() {
            @Override
            public void onDebouncedClick(View v) {
                if (!PermissionUtils.canAccessStorage(AltWallpaperViewerActivity.this)) {
                    PermissionUtils.setViewerActivityAction("save");
                    PermissionUtils.requestStoragePermission(AltWallpaperViewerActivity.this);
                } else {
                    showDialogs("save");
                }
            }
        });
    } else {
        saveFab.setVisibility(View.GONE);
    }

    infoFab.setOnClickListener(new DebouncedClickListener() {
        @Override
        public void onDebouncedClick(View v) {
            ISDialogs.showWallpaperDetailsDialog(AltWallpaperViewerActivity.this, item.getWallName(),
                    item.getWallAuthor(), item.getWallDimensions(), item.getWallCopyright(),
                    new DialogInterface.OnDismissListener() {
                        @Override
                        public void onDismiss(DialogInterface dialogInterface) {
                            reshowFab(fab);
                            setupFullScreen();
                        }
                    });
        }
    });

    TouchImageView mPhoto = (TouchImageView) findViewById(R.id.big_wallpaper);
    ViewCompat.setTransitionName(mPhoto, transitionName);

    layout = (CoordinatorLayout) findViewById(R.id.viewerLayout);

    Bitmap bmp = null;
    String filename = getIntent().getStringExtra("image");
    try {
        if (filename != null) {
            FileInputStream is = openFileInput(filename);
            bmp = BitmapFactory.decodeStream(is);
            is.close();
        } else {
            bmp = null;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    int colorFromCachedPic;

    if (bmp != null) {
        colorFromCachedPic = ColorUtils.getPaletteSwatch(bmp).getBodyTextColor();
    } else {
        colorFromCachedPic = ThemeUtils.darkOrLight(this, R.color.drawable_tint_dark,
                R.color.drawable_base_tint);
    }

    final ProgressBar spinner = (ProgressBar) findViewById(R.id.progress);
    spinner.getIndeterminateDrawable().setColorFilter(colorFromCachedPic, PorterDuff.Mode.SRC_IN);

    Drawable d;
    if (bmp != null) {
        d = new GlideBitmapDrawable(getResources(), bmp);
    } else {
        d = new ColorDrawable(ContextCompat.getColor(this, android.R.color.transparent));
    }

    if (mPrefs.getAnimationsEnabled()) {
        Glide.with(this).load(item.getWallURL()).placeholder(d).diskCacheStrategy(DiskCacheStrategy.SOURCE)
                .fitCenter().listener(new RequestListener<String, GlideDrawable>() {
                    @Override
                    public boolean onException(Exception e, String model, Target<GlideDrawable> target,
                            boolean isFirstResource) {
                        return false;
                    }

                    @Override
                    public boolean onResourceReady(GlideDrawable resource, String model,
                            Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
                        spinner.setVisibility(View.GONE);
                        return false;
                    }
                }).into(mPhoto);
    } else {
        Glide.with(this).load(item.getWallURL()).placeholder(d).dontAnimate()
                .diskCacheStrategy(DiskCacheStrategy.SOURCE).fitCenter()
                .listener(new RequestListener<String, GlideDrawable>() {
                    @Override
                    public boolean onException(Exception e, String model, Target<GlideDrawable> target,
                            boolean isFirstResource) {
                        return false;
                    }

                    @Override
                    public boolean onResourceReady(GlideDrawable resource, String model,
                            Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
                        spinner.setVisibility(View.GONE);
                        return false;
                    }
                }).into(mPhoto);
    }
}

From source file:com.popdeem.sdk.uikit.activity.PDUIClaimActivity.java

private void claimReward() {

    final ProgressBar progressBar = (ProgressBar) findViewById(R.id.pd_progress_bar);
    progressBar.setVisibility(View.VISIBLE);

    final Button shareButton = (Button) findViewById(R.id.pd_claim_share_button);
    shareButton.setEnabled(false);//ww  w .j  av  a  2s  .com
    shareButton.animate().alpha(0.5f);

    claiming = true;
    int postTime = 1;
    String twitterToken = null;
    String twitterSecret = null;
    String facebookToken = null;

    if (mTwitterSwitch.isChecked() && PDSocialUtils.isTwitterLoggedIn()
            && TwitterCore.getInstance().getSessionManager().getActiveSession().getAuthToken().token != null
            && TwitterCore.getInstance().getSessionManager().getActiveSession().getAuthToken().secret != null) {
        twitterToken = TwitterCore.getInstance().getSessionManager().getActiveSession().getAuthToken().token;
        twitterSecret = TwitterCore.getInstance().getSessionManager().getActiveSession().getAuthToken().secret;
    } else if (mFacebookSwitch.isChecked()) {
        facebookToken = AccessToken.getCurrentAccessToken().getToken();
    }

    Realm realm = Realm.getDefaultInstance();
    PDRealmUserLocation userLocation = realm.where(PDRealmUserLocation.class).findFirst();

    String lat = "", lng = "", id = "";

    if (userLocation != null) {
        lat = String.valueOf(userLocation.getLatitude());
        lng = String.valueOf(userLocation.getLongitude());
        id = String.valueOf(userLocation.getId());
    }

    PDRealmUserDetails userDetails = realm.where(PDRealmUserDetails.class).findFirst();

    String instagramAccessToken = null;
    if (mInstagramSwitch.isChecked() && userDetails.getUserInstagram() != null
            && userDetails.getUserInstagram().getAccessToken() != null
            && !userDetails.getUserInstagram().getAccessToken().isEmpty()) {
        instagramAccessToken = userDetails.getUserInstagram().getAccessToken();
    }

    PDAPIClient.instance().claimDiscovery(pdbgScanResponseModel, facebookToken, twitterToken, twitterSecret,
            instagramAccessToken, lat, lng, id, mReward.getId(), this, new PDAPICallback<JsonObject>() {
                @Override
                public void success(JsonObject jsonObject) {
                    Log.i(TAG, "success: " + jsonObject.toString());
                    if (jsonObject.has("error")) {
                        new AlertDialog.Builder(PDUIClaimActivity.this).setTitle(R.string.pd_common_sorry_text)
                                .setMessage(jsonObject.get("error").getAsString())
                                .setPositiveButton(android.R.string.ok, null).create().show();
                    } else {
                        PDLog.d(PDUIClaimActivity.class, "claim: " + jsonObject.toString());
                        progressBar.setVisibility(View.GONE);
                        shareButton.setEnabled(true);
                        shareButton.animate().alpha(1.0f);

                        PDAbraLogEvent.log(PDAbraConfig.ABRA_EVENT_CLAIMED, new PDAbraProperties.Builder()
                                .add(PDAbraConfig.ABRA_PROPERTYNAME_SOCIAL_NETWORKS, readableNetworksChosen())
                                .add(PDAbraConfig.ABRA_PROPERTYNAME_PHOTO, mImageAdded ? "YES" : "NO")
                                .add(PDAbraConfig.ABRA_PROPERTYNAME_REWARD_TYPE,
                                        PDAbraUtils.keyForRewardType(mReward.getRewardType()))
                                .create());

                        //                    finishActivityAfterClaim("twitter");

                        Intent data = new Intent();
                        data.putExtra("id", mReward.getId());
                        data.putExtra("verificationNeeded", false);
                        setResult(RESULT_OK, data);
                        finish();
                        claiming = false;
                    }
                }

                @Override
                public void failure(int statusCode, Exception e) {
                    Log.e(TAG, e.toString());
                    new AlertDialog.Builder(PDUIClaimActivity.this).setTitle(R.string.pd_common_sorry_text)
                            .setMessage(R.string.pd_common_something_wrong_text)
                            .setPositiveButton(android.R.string.ok, null).create().show();
                }
            });

    realm.close();
}