Java Code Examples for com.socks.jiandan.base.ConstantString

The following examples show how to use com.socks.jiandan.base.ConstantString. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: JianDan_OkHttpWithVolley   Source File: ShareUtil.java    License: Apache License 2.0 6 votes vote down vote up
public static void sharePicture(Activity activity, String url) {

        String[] urlSplits = url.split("\\.");

        File cacheFile = ImageLoader.getInstance().getDiskCache().get(url);

        //如果不存在,则使用缩略图进行分享
        if (!cacheFile.exists()) {
            String picUrl = url;
            picUrl = picUrl.replace("mw600", "small").replace("mw1200", "small").replace
                    ("large", "small");
            cacheFile = ImageLoader.getInstance().getDiskCache().get(picUrl);
        }

        File newFile = new File(CacheUtil.getSharePicName
                (cacheFile, urlSplits));

        if (FileUtil.copyTo(cacheFile, newFile)) {
            ShareUtil.sharePicture(activity, newFile.getAbsolutePath(),
                    "分享自煎蛋 " + url);
        } else {
            ShowToast.Short(ConstantString.LOAD_SHARE);
        }
    }
 
Example 2
Source Project: JianDan   Source File: ShareUtil.java    License: Apache License 2.0 6 votes vote down vote up
public static void sharePicture(Activity activity, String url) {

        String[] urlSplits = url.split("\\.");

        File cacheFile = ImageLoader.getInstance().getDiskCache().get(url);

        //如果不存在,则使用缩略图进行分享
        if (!cacheFile.exists()) {
            String picUrl = url;
            picUrl = picUrl.replace("mw600", "small").replace("mw1200", "small").replace
                    ("large", "small");
            cacheFile = ImageLoader.getInstance().getDiskCache().get(picUrl);
        }

        File newFile = new File(CacheUtil.getSharePicName
                (cacheFile, urlSplits));

        if (FileUtil.copyTo(cacheFile, newFile)) {
            ShareUtil.sharePicture(activity, newFile.getAbsolutePath(),
                    "分享自煎蛋 " + url);
        } else {
            ShowToast.Short(ConstantString.LOAD_SHARE);
        }
    }
 
Example 3
Source Project: JianDanRxJava   Source File: ShareUtil.java    License: Apache License 2.0 6 votes vote down vote up
public static void sharePicture(Activity activity, String url) {

        String[] urlSplits = url.split("\\.");

        File cacheFile = ImageLoader.getInstance().getDiskCache().get(url);

        //如果不存在,则使用缩略图进行分享
        if (!cacheFile.exists()) {
            String picUrl = url;
            picUrl = picUrl.replace("mw600", "small").replace("mw1200", "small").replace
                    ("large", "small");
            cacheFile = ImageLoader.getInstance().getDiskCache().get(picUrl);
        }

        File newFile = new File(CacheUtil.getSharePicName
                (cacheFile, urlSplits));

        if (FileUtil.copyTo(cacheFile, newFile)) {
            ShareUtil.sharePicture(activity, newFile.getAbsolutePath(),
                    "分享自煎蛋 " + url);
        } else {
            ToastHelper.Short(ConstantString.LOAD_SHARE);
        }
    }
 
Example 4
Source Project: JianDanRxJava   Source File: JokeAdapter.java    License: Apache License 2.0 6 votes vote down vote up
private void loadCache() {
    Subscription subscription = Observable
            .create((Observable.OnSubscribe<ArrayList<Joke>>)
                    subscriber -> {
                        subscriber.onNext(JokeCache.getInstance(mActivity).getCacheByPage(page));
                        subscriber.onCompleted();
                    })
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .doOnNext(jokes -> {
                if (page == 1) {
                    mJokes.clear();
                    ToastHelper.Short(ConstantString.LOAD_NO_NETWORK);
                }
            })
            .subscribe(jokes -> {
                mJokes.addAll(jokes);
                notifyDataSetChanged();
                mLoadFinisCallBack.loadFinish(null);
                mLoadResultCallBack.onSuccess(LoadResultCallBack.SUCCESS_OK, null);
            });
    mActivity.addSubscription(subscription);
}
 
Example 5
Source Project: JianDanRxJava   Source File: PictureAdapter.java    License: Apache License 2.0 6 votes vote down vote up
private void loadCache() {
    Subscription subscription = Observable.create((Observable.OnSubscribe<ArrayList<Picture>>) subscriber -> {
        subscriber.onNext(PictureCache.getInstance(mActivity).getCacheByPage(page));
        subscriber.onCompleted();
    }).compose(JDApi.applySchedulers())
            .doOnNext(pictures -> {
                if (page == 1) {
                    mPictures.clear();
                    ToastHelper.Short(ConstantString.LOAD_NO_NETWORK);
                }
            })
            .subscribe(pictures -> {
                mPictures.addAll(pictures);
                notifyDataSetChanged();
                mLoadResultCallBack.onSuccess(LoadResultCallBack.SUCCESS_OK, null);
                mLoadFinisCallBack.loadFinish(null);
            });
    mActivity.addSubscription(subscription);
}
 
Example 6
Source Project: JianDanRxJava   Source File: PictureAdapter.java    License: Apache License 2.0 6 votes vote down vote up
private void getCommentCounts(final List<Picture> pictures) {

        StringBuilder sb = new StringBuilder();
        for (Picture joke : pictures) {
            sb.append("comment-").append(joke.getComment_ID()).append(",");
        }

        JDApi.getCommentNumber(sb.toString())
                .doOnCompleted(() -> PictureCache.getInstance(mActivity).addResultCache(GsonHelper.toString(mPictures), page))
                .subscribe(commentNumbers -> {
                    mLoadResultCallBack.onSuccess(LoadResultCallBack.SUCCESS_OK, null);
                    mLoadFinisCallBack.loadFinish(null);

                    for (int i = 0; i < pictures.size(); i++) {
                        pictures.get(i).setComment_counts(commentNumbers.get(i).comments + "");
                    }

                    PictureAdapter.this.mPictures.addAll(pictures);
                    notifyDataSetChanged();
                }, e -> {
                    ToastHelper.Short(ConstantString.LOAD_FAILED);
                    mLoadFinisCallBack.loadFinish(null);
                    mLoadResultCallBack.onError(LoadResultCallBack.ERROR_NET);
                });
    }
 
Example 7
Source Project: JianDanRxJava   Source File: FreshNewsAdapter.java    License: Apache License 2.0 6 votes vote down vote up
private void loadFromCache() {
    Observable.create(new Observable.OnSubscribe<ArrayList<FreshNews>>() {
        @Override
        public void call(Subscriber<? super ArrayList<FreshNews>> subscriber) {
            subscriber.onNext(FreshNewsCache.getInstance(mActivity).getCacheByPage(page));
            subscriber.onCompleted();
        }
    }).compose(JDApi.applySchedulers())
            .doOnNext(freshNewses -> {
                if (page == 1) {
                    mFreshNews.clear();
                    ToastHelper.Short(ConstantString.LOAD_NO_NETWORK);
                }
            })
            .subscribe(freshNewses -> {
                mFreshNews.addAll(freshNewses);
                notifyDataSetChanged();
                mLoadResultCallBack.onSuccess(LoadResultCallBack.SUCCESS_OK, null);
                mLoadFinisCallBack.loadFinish(null);
            });
}
 
Example 8
Source Project: JianDanRxJava   Source File: VideoAdapter.java    License: Apache License 2.0 6 votes vote down vote up
private void loadCache() {
    Subscription subscription = Observable.create((Observable.OnSubscribe<ArrayList<Video>>) subscriber -> {
        subscriber.onNext(VideoCache.getInstance(mActivity).getCacheByPage(page));
        subscriber.onCompleted();
    }).compose(JDApi.applySchedulers())
            .doOnNext(videos -> {
                if (page == 1) {
                    mVideos.clear();
                    ToastHelper.Short(ConstantString.LOAD_NO_NETWORK);
                }
            })
            .subscribe(videos -> {
                mVideos.addAll(videos);
                notifyDataSetChanged();
                mLoadResultCallBack.onSuccess(LoadResultCallBack.SUCCESS_OK, null);
                mLoadFinisCallBack.loadFinish(null);
            });
    mActivity.addSubscription(subscription);
}
 
Example 9
Source Project: JianDan_OkHttp   Source File: ShareUtil.java    License: Apache License 2.0 6 votes vote down vote up
public static void sharePicture(Activity activity, String url) {

        String[] urlSplits = url.split("\\.");

        File cacheFile = ImageLoader.getInstance().getDiskCache().get(url);

        //如果不存在,则使用缩略图进行分享
        if (!cacheFile.exists()) {
            String picUrl = url;
            picUrl = picUrl.replace("mw600", "small").replace("mw1200", "small").replace
                    ("large", "small");
            cacheFile = ImageLoader.getInstance().getDiskCache().get(picUrl);
        }

        File newFile = new File(CacheUtil.getSharePicName
                (cacheFile, urlSplits));

        if (FileUtil.copyTo(cacheFile, newFile)) {
            ShareUtil.sharePicture(activity, newFile.getAbsolutePath(),
                    "分享自煎蛋 " + url);
        } else {
            ShowToast.Short(ConstantString.LOAD_SHARE);
        }
    }
 
Example 10
Source Project: JianDan_OkHttpWithVolley   Source File: FileUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 保存图片
 *
 * @param activity
 * @param picUrl
 */
public static void savePicture(Activity activity, String picUrl, LoadFinishCallBack loadFinishCallBack) {

    boolean isSmallPic = false;
    String[] urls = picUrl.split("\\.");
    File cacheFile = ImageLoader.getInstance().getDiskCache().get(picUrl);

    //如果是GIF格式,优先保存GIF动态图,如果不存在,则保存缩略图
    if (!cacheFile.exists()) {
        String cacheUrl = picUrl.replace("mw600", "small").replace("mw1200", "small")
                .replace("large", "small");
        cacheFile = ImageLoader.getInstance().getDiskCache().get(cacheUrl);
        isSmallPic = true;
    }

    File picDir = new File(CacheUtil.getSaveDirPath());

    if (!picDir.exists()) {
        picDir.mkdir();
    }

    final File newFile = new File(picDir, CacheUtil.getSavePicName(cacheFile, urls));

    if (FileUtil.copyTo(cacheFile, newFile)) {
        Bundle bundle = new Bundle();
        bundle.putBoolean(BaseActivity.DATA_IS_SIAMLL_PIC, isSmallPic);
        bundle.putString(BaseActivity.DATA_FILE_PATH, newFile.getAbsolutePath());
        loadFinishCallBack.loadFinish(bundle);
    } else {
        ShowToast.Short(ConstantString.SAVE_FAILED);
    }

}
 
Example 11
@Override
public void onScanCompleted(String path, Uri uri) {
    Looper.prepare();
    if (isSmallPic) {
        ShowToast.Short(ConstantString.SAVE_SMALL_SUCCESS + " \n相册" + File.separator + CacheUtil
                .FILE_SAVE + File.separator + newFile.getName());
    } else {
        ShowToast.Short(ConstantString.SAVE_SUCCESS + " \n相册" + File.separator + CacheUtil
                .FILE_SAVE + File.separator + newFile.getName());
    }
    Looper.loop();
}
 
Example 12
Source Project: JianDan_OkHttpWithVolley   Source File: TextUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static void copy(Activity activity, String copyText) {
    ClipboardManager clip = (ClipboardManager)
            activity.getSystemService(Context
                    .CLIPBOARD_SERVICE);
    clip.setPrimaryClip(ClipData.newPlainText
            (null, copyText));
    ShowToast.Short(ConstantString.COPY_SUCCESS);
}
 
Example 13
Source Project: JianDan_OkHttpWithVolley   Source File: JokeAdapter.java    License: Apache License 2.0 5 votes vote down vote up
private void loadCache() {
    mLoadFinisCallBack.loadFinish(null);
    mLoadResultCallBack.onSuccess(LoadResultCallBack.SUCCESS_OK, null);
    JokeCache jokeCacheUtil = JokeCache.getInstance(mActivity);
    if (page == 1) {
        mJokes.clear();
        ShowToast.Short(ConstantString.LOAD_NO_NETWORK);
    }
    mJokes.addAll(jokeCacheUtil.getCacheByPage(page));
    notifyDataSetChanged();
}
 
Example 14
Source Project: JianDan_OkHttpWithVolley   Source File: PictureAdapter.java    License: Apache License 2.0 5 votes vote down vote up
private void loadCache() {

        mLoadResultCallBack.onSuccess(LoadResultCallBack.SUCCESS_OK, null);
        mLoadFinisCallBack.loadFinish(null);
        PictureCache pictureCacheUtil = PictureCache.getInstance(mActivity);
        if (page == 1) {
            pictures.clear();
            ShowToast.Short(ConstantString.LOAD_NO_NETWORK);
        }
        pictures.addAll(pictureCacheUtil.getCacheByPage(page));
        notifyDataSetChanged();

    }
 
Example 15
Source Project: JianDan_OkHttpWithVolley   Source File: PictureAdapter.java    License: Apache License 2.0 5 votes vote down vote up
private void getCommentCounts(final ArrayList<Picture> pictures) {

        StringBuilder sb = new StringBuilder();
        for (Picture joke : pictures) {
            sb.append("comment-" + joke.getComment_ID() + ",");
        }

        RequestManager.addRequest(new Request4CommentCounts(CommentNumber.getCommentCountsURL(sb.toString()), new Response
                .Listener<ArrayList<CommentNumber>>() {

            @Override
            public void onResponse(ArrayList<CommentNumber> response) {

                mLoadResultCallBack.onSuccess(LoadResultCallBack.SUCCESS_OK, null);
                mLoadFinisCallBack.loadFinish(null);

                for (int i = 0; i < pictures.size(); i++) {
                    pictures.get(i).setComment_counts(response.get(i).getComments() + "");
                }
                if (page == 1) {
                    PictureAdapter.this.pictures.clear();
                    PictureCache.getInstance(mActivity).clearAllCache();
                }
                PictureAdapter.this.pictures.addAll(pictures);
                notifyDataSetChanged();
                //加载完毕后缓存
                PictureCache.getInstance(mActivity).addResultCache(JSONParser.toString
                        (pictures), page);
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                ShowToast.Short(ConstantString.LOAD_FAILED);
                mLoadFinisCallBack.loadFinish(null);
                mLoadResultCallBack.onError(LoadResultCallBack.ERROR_NET, error.getMessage());
            }
        }
        ), mActivity);
    }
 
Example 16
Source Project: JianDan_OkHttpWithVolley   Source File: VideoAdapter.java    License: Apache License 2.0 5 votes vote down vote up
private void loadCache() {

        mLoadResultCallBack.onSuccess(LoadResultCallBack.SUCCESS_OK, null);
        mLoadFinisCallBack.loadFinish(null);
        VideoCache videoCacheUtil = VideoCache.getInstance(mActivity);
        if (page == 1) {
            mVideos.clear();
            ShowToast.Short(ConstantString.LOAD_NO_NETWORK);
        }
        mVideos.addAll(videoCacheUtil.getCacheByPage(page));
        notifyDataSetChanged();

    }
 
Example 17
Source Project: JianDan_OkHttpWithVolley   Source File: VideoFragment.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onError(int code, String msg) {
    loading.stop();
    ShowToast.Short(ConstantString.LOAD_FAILED);
    if (mSwipeRefreshLayout.isRefreshing()) {
        mSwipeRefreshLayout.setRefreshing(false);
    }
}
 
Example 18
@Override
public void onError(int code, String msg) {
    loading.stop();
    ShowToast.Short(ConstantString.LOAD_FAILED);
    if (mSwipeRefreshLayout.isRefreshing()) {
        mSwipeRefreshLayout.setRefreshing(false);
    }
}
 
Example 19
@JavascriptInterface
public void img_loaded_error() {
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            ShowToast.Short(ConstantString.LOAD_FAILED);
        }
    });
}
 
Example 20
@Override
public void onResponse(Boolean response) {
    dialog.dismiss();
    if (response) {
        setResult(RESULT_OK);
        finish();
    } else {
        ShowToast.Short(ConstantString.COMMENT_FAILED);
    }
}
 
Example 21
Source Project: JianDan   Source File: FileUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 保存图片
 *
 * @param activity
 * @param picUrl
 */
public static void savePicture(Activity activity, String picUrl, LoadFinishCallBack loadFinishCallBack) {

    boolean isSmallPic = false;
    String[] urls = picUrl.split("\\.");
    File cacheFile = ImageLoader.getInstance().getDiskCache().get(picUrl);

    //如果是GIF格式,优先保存GIF动态图,如果不存在,则保存缩略图
    if (!cacheFile.exists()) {
        String cacheUrl = picUrl.replace("mw600", "small").replace("mw1200", "small")
                .replace("large", "small");
        cacheFile = ImageLoader.getInstance().getDiskCache().get(cacheUrl);
        isSmallPic = true;
    }

    File picDir = new File(CacheUtil.getSaveDirPath());

    if (!picDir.exists()) {
        picDir.mkdir();
    }

    final File newFile = new File(picDir, CacheUtil.getSavePicName(cacheFile, urls));

    if (FileUtil.copyTo(cacheFile, newFile)) {
        Bundle bundle = new Bundle();
        bundle.putBoolean(BaseActivity.DATA_IS_SIAMLL_PIC, isSmallPic);
        bundle.putString(BaseActivity.DATA_FILE_PATH, newFile.getAbsolutePath());
        loadFinishCallBack.loadFinish(bundle);
    } else {
        ShowToast.Short(ConstantString.SAVE_FAILED);
    }

}
 
Example 22
Source Project: JianDan   Source File: JDMediaScannerConnectionClient.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onScanCompleted(String path, Uri uri) {
    Looper.prepare();
    if (isSmallPic) {
        ShowToast.Short(ConstantString.SAVE_SMALL_SUCCESS + " \n相册" + File.separator + CacheUtil
                .FILE_SAVE + File.separator + newFile.getName());
    } else {
        ShowToast.Short(ConstantString.SAVE_SUCCESS + " \n相册" + File.separator + CacheUtil
                .FILE_SAVE + File.separator + newFile.getName());
    }
    Looper.loop();
}
 
Example 23
Source Project: JianDan   Source File: TextUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static void copy(Activity activity, String copyText) {
    ClipboardManager clip = (ClipboardManager)
            activity.getSystemService(Context
                    .CLIPBOARD_SERVICE);
    clip.setPrimaryClip(ClipData.newPlainText
            (null, copyText));
    ShowToast.Short(ConstantString.COPY_SUCCESS);
}
 
Example 24
Source Project: JianDan   Source File: JokeAdapter.java    License: Apache License 2.0 5 votes vote down vote up
private void loadCache() {
    mLoadFinisCallBack.loadFinish(null);
    mLoadResultCallBack.onSuccess(LoadResultCallBack.SUCCESS_OK, null);
    JokeCache jokeCacheUtil = JokeCache.getInstance(mActivity);
    if (page == 1) {
        mJokes.clear();
        ShowToast.Short(ConstantString.LOAD_NO_NETWORK);
    }
    mJokes.addAll(jokeCacheUtil.getCacheByPage(page));
    notifyDataSetChanged();
}
 
Example 25
Source Project: JianDan   Source File: PictureAdapter.java    License: Apache License 2.0 5 votes vote down vote up
private void loadCache() {

        mLoadResultCallBack.onSuccess(LoadResultCallBack.SUCCESS_OK, null);
        mLoadFinisCallBack.loadFinish(null);
        PictureCache pictureCacheUtil = PictureCache.getInstance(mActivity);
        if (page == 1) {
            pictures.clear();
            ShowToast.Short(ConstantString.LOAD_NO_NETWORK);
        }
        pictures.addAll(pictureCacheUtil.getCacheByPage(page));
        notifyDataSetChanged();

    }
 
Example 26
Source Project: JianDan   Source File: PictureAdapter.java    License: Apache License 2.0 5 votes vote down vote up
private void getCommentCounts(final ArrayList<Picture> pictures) {

        StringBuilder sb = new StringBuilder();
        for (Picture joke : pictures) {
            sb.append("comment-" + joke.getComment_ID() + ",");
        }

        RequestManager.addRequest(new Request4CommentCounts(CommentNumber.getCommentCountsURL(sb.toString()), new Response
                .Listener<ArrayList<CommentNumber>>() {

            @Override
            public void onResponse(ArrayList<CommentNumber> response) {

                mLoadResultCallBack.onSuccess(LoadResultCallBack.SUCCESS_OK, null);
                mLoadFinisCallBack.loadFinish(null);

                for (int i = 0; i < pictures.size(); i++) {
                    pictures.get(i).setComment_counts(response.get(i).getComments() + "");
                }
                if (page == 1) {
                    PictureAdapter.this.pictures.clear();
                    PictureCache.getInstance(mActivity).clearAllCache();
                }
                PictureAdapter.this.pictures.addAll(pictures);
                notifyDataSetChanged();
                //加载完毕后缓存
                PictureCache.getInstance(mActivity).addResultCache(JSONParser.toString
                        (pictures), page);
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                ShowToast.Short(ConstantString.LOAD_FAILED);
                mLoadFinisCallBack.loadFinish(null);
                mLoadResultCallBack.onError(LoadResultCallBack.ERROR_NET, error.getMessage());
            }
        }
        ), mActivity);
    }
 
Example 27
Source Project: JianDan   Source File: VideoAdapter.java    License: Apache License 2.0 5 votes vote down vote up
private void loadCache() {

        mLoadResultCallBack.onSuccess(LoadResultCallBack.SUCCESS_OK, null);
        mLoadFinisCallBack.loadFinish(null);
        VideoCache videoCacheUtil = VideoCache.getInstance(mActivity);
        if (page == 1) {
            mVideos.clear();
            ShowToast.Short(ConstantString.LOAD_NO_NETWORK);
        }
        mVideos.addAll(videoCacheUtil.getCacheByPage(page));
        notifyDataSetChanged();

    }
 
Example 28
Source Project: JianDan   Source File: VideoFragment.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onError(int code, String msg) {
    loading.stop();
    ShowToast.Short(ConstantString.LOAD_FAILED);
    if (mSwipeRefreshLayout.isRefreshing()) {
        mSwipeRefreshLayout.setRefreshing(false);
    }
}
 
Example 29
Source Project: JianDan   Source File: FreshNewsFragment.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onError(int code, String msg) {
    loading.stop();
    ShowToast.Short(ConstantString.LOAD_FAILED);
    if (mSwipeRefreshLayout.isRefreshing()) {
        mSwipeRefreshLayout.setRefreshing(false);
    }
}
 
Example 30
Source Project: JianDan   Source File: ImageDetailActivity.java    License: Apache License 2.0 5 votes vote down vote up
@JavascriptInterface
public void img_loaded_error() {
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            ShowToast.Short(ConstantString.LOAD_FAILED);
        }
    });
}