Search in sources :

Example 6 with Picasso

use of com.squareup.picasso.Picasso in project Rashr by DsLNeXuS.

the class RecoverySystemFragment method onCreateView.

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    mActivity = (RashrActivity) getActivity();
    final ScrollView root = (ScrollView) inflater.inflate(R.layout.fragment_recovery_system, container, false);
    ButterKnife.bind(this, root);
    mContext = root.getContext();
    tvTitle.setText(mTitle.toUpperCase());
    tvDesc.setText(mDesc);
    ArrayList<String> formatedVersions = new ArrayList<>();
    for (String versionLinks : mVersions) {
        formatedVersions.add(formatName(versionLinks, mTitle));
    }
    final ArrayAdapter<String> adapter = new ArrayAdapter<>(root.getContext(), android.R.layout.simple_list_item_1, formatedVersions);
    spVersions.setAdapter(adapter);
    spVersions.setSelection(0);
    tvDev.setText(mDev);
    if (mLogo == 0) {
        imLogo.setVisibility(View.GONE);
    } else {
        imLogo.setImageResource(mLogo);
    }
    bFlash.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            flashSupportedRecovery(mTitle, mVersions.get(spVersions.getSelectedItemPosition()));
        }
    });
    if (mScreenshotURL == null) {
        ScreenshotLayout.setVisibility(View.GONE);
    } else {
        try {
            Downloader links = new Downloader(new URL(mScreenshotURL), new File(mContext.getExternalCacheDir(), "screenshots.json"));
            links.setOverrideFile(true);
            links.setOnDownloadListener(new Downloader.OnDownloadListener() {

                @Override
                public void onSuccess(File file) {
                    try {
                        String res = Common.fileContent(file);
                        JSONArray arr = new JSONArray(res);
                        for (int i = 0; i < arr.length(); i++) {
                            final String name = arr.get(i).toString();
                            // Skip file that lists content of url
                            if (name.equals("getScreenshots.php"))
                                continue;
                            if (name.equals("index.php"))
                                continue;
                            // All others are filenames of screenshots
                            AppCompatImageView iv = (AppCompatImageView) inflater.inflate(R.layout.recovery_screenshot, ScreenshotLayout, false);
                            ScreenshotLayout.addView(iv);
                            Picasso picasso = Picasso.with(mContext);
                            picasso.setLoggingEnabled(BuildConfig.DEBUG);
                            picasso.setIndicatorsEnabled(BuildConfig.DEBUG);
                            picasso.load(mScreenshotURL + "/" + name).placeholder(R.drawable.ic_launcher_web).into(iv);
                        }
                    } catch (JSONException | IOException e) {
                        onFail(e);
                    }
                }

                @Override
                public void onFail(Exception e) {
                    e.printStackTrace();
                }
            });
            links.download();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
    }
    return root;
}
Also used : MalformedURLException(java.net.MalformedURLException) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) Downloader(de.mkrtchyan.utils.Downloader) BindView(butterknife.BindView) View(android.view.View) AppCompatImageView(android.support.v7.widget.AppCompatImageView) AppCompatTextView(android.support.v7.widget.AppCompatTextView) ScrollView(android.widget.ScrollView) AppCompatImageView(android.support.v7.widget.AppCompatImageView) URL(java.net.URL) JSONException(org.json.JSONException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ScrollView(android.widget.ScrollView) Picasso(com.squareup.picasso.Picasso) File(java.io.File) ArrayAdapter(android.widget.ArrayAdapter)

Example 7 with Picasso

use of com.squareup.picasso.Picasso in project Tusky by tuskyapp.

the class TuskyApplication method initPicasso.

protected void initPicasso() {
    // Initialize Picasso configuration
    Picasso.Builder builder = new Picasso.Builder(this);
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
    builder.downloader(new OkHttp3Downloader(OkHttpUtils.getCompatibleClient(preferences)));
    if (BuildConfig.DEBUG) {
        builder.listener((picasso, uri, exception) -> exception.printStackTrace());
    }
    try {
        Picasso.setSingletonInstance(builder.build());
    } catch (IllegalStateException e) {
        throw new RuntimeException(e);
    }
}
Also used : SharedPreferences(android.content.SharedPreferences) Picasso(com.squareup.picasso.Picasso) OkHttp3Downloader(com.jakewharton.picasso.OkHttp3Downloader)

Example 8 with Picasso

use of com.squareup.picasso.Picasso in project Lets-Chat by kshitiz1007.

the class LetsChat method onCreate.

@Override
public void onCreate() {
    super.onCreate();
    mAuth = FirebaseAuth.getInstance();
    FirebaseUser mUser = mAuth.getCurrentUser();
    // ---DO IT WHENEVER YOU GET TIME---
    if (mUser != null) {
        // ---FIREBASE OFFLINE FEATURE---
        FirebaseDatabase.getInstance().setPersistenceEnabled(true);
        // ---PIACSSO OFFLINE FEATURE--
        mAuth = FirebaseAuth.getInstance();
        Picasso.Builder builder = new Picasso.Builder(this);
        builder.downloader(new OkHttpDownloader(this, Integer.MAX_VALUE));
        Picasso built = builder.build();
        built.setIndicatorsEnabled(true);
        built.setLoggingEnabled(true);
        Picasso.setSingletonInstance(built);
        // String user_id = mAuth.getCurrentUser().getUid();
        // Log.e("Current user inside : ",user_id);
        // ---SEETING TIME_STAMP ON DISCONNECT-----
        mUserDatabase = FirebaseDatabase.getInstance().getReference().child("users").child(mAuth.getCurrentUser().getUid());
        mUserDatabase.addValueEventListener(new ValueEventListener() {

            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                if (dataSnapshot != null) {
                    mUserDatabase.child("online").onDisconnect().setValue(ServerValue.TIMESTAMP);
                }
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {
            }
        });
    }
}
Also used : DatabaseError(com.google.firebase.database.DatabaseError) Picasso(com.squareup.picasso.Picasso) FirebaseUser(com.google.firebase.auth.FirebaseUser) OkHttpDownloader(com.squareup.picasso.OkHttpDownloader) ValueEventListener(com.google.firebase.database.ValueEventListener) DataSnapshot(com.google.firebase.database.DataSnapshot)

Example 9 with Picasso

use of com.squareup.picasso.Picasso in project sbt-android by scala-android.

the class DebugDataModule method providePicasso.

@Provides
@Singleton
Picasso providePicasso(OkHttpClient client, NetworkBehavior behavior, @IsMockMode boolean isMockMode, Application app) {
    Picasso.Builder builder = new Picasso.Builder(app).downloader(new OkHttpDownloader(client));
    if (isMockMode) {
        builder.addRequestHandler(new MockRequestHandler(behavior, app.getAssets()));
    }
    builder.listener((picasso, uri, exception) -> {
        Timber.e(exception, "Error while loading image " + uri);
    });
    return builder.build();
}
Also used : Picasso(com.squareup.picasso.Picasso) OkHttpDownloader(com.squareup.picasso.OkHttpDownloader) Singleton(javax.inject.Singleton) Provides(dagger.Provides)

Example 10 with Picasso

use of com.squareup.picasso.Picasso in project android-sdk-examples by IndoorAtlas.

the class MapsOverlayActivity method fetchFloorPlanBitmap.

/**
 * Download floor plan using Picasso library.
 */
private void fetchFloorPlanBitmap(final IAFloorPlan floorPlan) {
    final String url = floorPlan.getUrl();
    if (mLoadTarget == null) {
        mLoadTarget = new Target() {

            @Override
            public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
                Log.d(TAG, "onBitmap loaded with dimensions: " + bitmap.getWidth() + "x" + bitmap.getHeight());
                setupGroundOverlay(floorPlan, bitmap);
            }

            @Override
            public void onPrepareLoad(Drawable placeHolderDrawable) {
            // N/A
            }

            @Override
            public void onBitmapFailed(Drawable placeHolderDraweble) {
                showInfo("Failed to load bitmap");
                mOverlayFloorPlan = null;
            }
        };
    }
    RequestCreator request = Picasso.with(this).load(url);
    final int bitmapWidth = floorPlan.getBitmapWidth();
    final int bitmapHeight = floorPlan.getBitmapHeight();
    if (bitmapHeight > MAX_DIMENSION) {
        request.resize(0, MAX_DIMENSION);
    } else if (bitmapWidth > MAX_DIMENSION) {
        request.resize(MAX_DIMENSION, 0);
    }
    request.into(mLoadTarget);
}
Also used : Target(com.squareup.picasso.Target) Bitmap(android.graphics.Bitmap) Picasso(com.squareup.picasso.Picasso) Drawable(android.graphics.drawable.Drawable) RequestCreator(com.squareup.picasso.RequestCreator)

Aggregations

Picasso (com.squareup.picasso.Picasso)26 View (android.view.View)9 TextView (android.widget.TextView)7 RequestCreator (com.squareup.picasso.RequestCreator)7 ImageView (android.widget.ImageView)6 ArrayAdapter (android.widget.ArrayAdapter)5 ListView (android.widget.ListView)5 OkHttp3Downloader (com.jakewharton.picasso.OkHttp3Downloader)4 Bitmap (android.graphics.Bitmap)3 Drawable (android.graphics.drawable.Drawable)3 OkHttpDownloader (com.squareup.picasso.OkHttpDownloader)3 Target (com.squareup.picasso.Target)3 TargetApi (android.annotation.TargetApi)2 SharedPreferences (android.content.SharedPreferences)2 ViewTreeObserver (android.view.ViewTreeObserver)2 AbsListView (android.widget.AbsListView)2 AdapterView (android.widget.AdapterView)2 GridView (android.widget.GridView)2 Callback (com.squareup.picasso.Callback)2 LruCache (com.squareup.picasso.LruCache)2