Android Open Source - YahooWeather Share Activity






From Project

Back to project page YahooWeather.

License

The source code is released under:

GNU General Public License

If you think the Android project YahooWeather listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.imlongluo.weather.share;
// w w  w.j  a  v  a 2  s .  c o  m
import java.io.File;
import java.io.FileOutputStream;

import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.onekeyshare.OnekeyShare;

import com.imlongluo.weather.apis.YahooWeatherLog;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.Display;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.imlongluo.weather.R;

public class ShareActivity extends Activity {
    private static final String TAG = ShareActivity.class.getSimpleName();

    private ImageView mWeatherImage;
    private TextView mWeatherDetail;
    private Button mShareButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.share);

        String weatherDetail = getIntent().getStringExtra("weather");

        Log.d(TAG, "weatherDetail=" + weatherDetail);

        mWeatherImage = (ImageView) findViewById(R.id.weather_screen);
        mWeatherDetail = (TextView) findViewById(R.id.weather_detail);

        mShareButton = (Button) findViewById(R.id.btn_share);
        mShareButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                showShare();
            }
        });

        mWeatherDetail.setText(weatherDetail);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    @Override
    protected void onRestart() {
        super.onRestart();
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onStart() {
        super.onStart();
    }

    @Override
    protected void onStop() {
        super.onStop();
    }

    @Override
    public void openContextMenu(View view) {
        super.openContextMenu(view);
    }

    @Override
    public void openOptionsMenu() {
        super.openOptionsMenu();
    }

    private void showShare() {
        // String shareString = mTvTitle.getText().toString() +
        // mTvWeather0.getText().toString();
        String shareTitleString = "YahooWeather By Long Luo";

        // YahooWeatherLog.d("showShare, title=" + shareTitleString +
        // ",content=" + shareString);

        ShareSDK.initSDK(this);
        OnekeyShare oks = new OnekeyShare();
        // ?????sso???
        oks.disableSSOWhenAuthorize();

        // ?????????otification???????????????
        oks.setNotification(R.drawable.ic_launcher, getString(R.string.app_name));
        // title?????????????????????????????????????Q??????

        oks.setTitle(getString(R.string.share));
        // oks.setTitle("");

        // titleUrl?????????????????????????????Q??????
        oks.setTitleUrl("http://imlongluo.com");

        // text??????????????????????????????????
        oks.setText("?????????????");
        // oks.setText(shareString);

        // imagePath????????????????????inked-In??????????????????????????

        GetAndSaveCurrentScreenImage();
        // oks.setImagePath("/sdcard/test.jpg");
        oks.setImagePath("SDCard/YahooWeather/ScreenImage/Screen1.png");

        // url????????????????????????????????????
        oks.setUrl("http://imlongluo.com/weather");

        // comment??????????????????????????????????Q??????
        oks.setComment("??????????????");

        // site???????????????????????????????QQ??????
        oks.setSite(getString(R.string.app_name));
        // siteUrl?????????????????????????????????QQ??????
        oks.setSiteUrl("http://imlongluo.com");

        // ??????????GUI
        oks.show(this);
    }

    private void shareToWechatMoments(File file) {
        Intent intent = new Intent();
        ComponentName comp = new ComponentName("com.tencent.mm",
                "com.tencent.mm.ui.tools.ShareToTimeLineUI");
        intent.setComponent(comp);
        intent.setAction("android.intent.action.SEND");
        intent.setType("image/*");
        intent.putExtra(Intent.EXTRA_TEXT, "From Yahoo Weather, http://www.imlongluo.com/weather");
        intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
        startActivity(intent);
    }

    /**
     * ??????????????????????????
     */
    private void GetAndSaveCurrentScreenImage() {
        // 1.?????Bitmap
        WindowManager windowManager = getWindowManager();
        Display display = windowManager.getDefaultDisplay();
        int w = display.getWidth();
        int h = display.getHeight();

        Bitmap Bmp = Bitmap.createBitmap(w, h, Config.ARGB_8888);

        // 2.????????
        View decorview = this.getWindow().getDecorView();
        decorview.setDrawingCacheEnabled(true);
        Bmp = decorview.getDrawingCache();

        String SavePath = getSDCardPath() + "/YahooWeather/ScreenImage";

        // 3.???Bitmap
        try {
            File path = new File(SavePath);
            // ?????
            String filepath = SavePath + "/Screen1.png";
            File file = new File(filepath);
            if (!path.exists()) {
                path.mkdirs();
            }
            if (!file.exists()) {
                file.createNewFile();
            }

            FileOutputStream fos = null;
            fos = new FileOutputStream(file);
            if (null != fos) {
                Bmp.compress(Bitmap.CompressFormat.PNG, 90, fos);
                fos.flush();
                fos.close();

                Toast.makeText(ShareActivity.this, "Image Save SDCard/YahooWeather/ScreenImage/",
                        Toast.LENGTH_LONG).show();
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * ???SDCard?????????????
     *
     * @return
     */
    private String getSDCardPath() {
        File sdcardDir = null;
        // ?????SDCard?????????
        boolean sdcardExist = Environment.getExternalStorageState().equals(
                android.os.Environment.MEDIA_MOUNTED);
        if (sdcardExist) {
            sdcardDir = Environment.getExternalStorageDirectory();
        }

        return sdcardDir.toString();
    }
}




Java Source Code List

cn.sharesdk.demo.wxapi.WXEntryActivity.java
cn.sharesdk.onekeyshare.CustomerLogo.java
cn.sharesdk.onekeyshare.EditPage.java
cn.sharesdk.onekeyshare.FollowList.java
cn.sharesdk.onekeyshare.OnekeyShare.java
cn.sharesdk.onekeyshare.PicViewer.java
cn.sharesdk.onekeyshare.PlatformGridView.java
cn.sharesdk.onekeyshare.Shake2Share.java
cn.sharesdk.onekeyshare.ShareContentCustomizeCallback.java
cn.sharesdk.onekeyshare.ShareCore.java
com.imlongluo.weather.MainActivity.java
com.imlongluo.weather.WeatherApplication.java
com.imlongluo.weather.apis.AsciiUtils.java
com.imlongluo.weather.apis.ImageUtils.java
com.imlongluo.weather.apis.NetworkUtils.java
com.imlongluo.weather.apis.UserLocationUtils.java
com.imlongluo.weather.apis.WOEIDInfo.java
com.imlongluo.weather.apis.WOEIDUtils.java
com.imlongluo.weather.apis.WeatherInfo.java
com.imlongluo.weather.apis.YahooWeatherConsts.java
com.imlongluo.weather.apis.YahooWeatherExceptionListener.java
com.imlongluo.weather.apis.YahooWeatherInfoListener.java
com.imlongluo.weather.apis.YahooWeatherLog.java
com.imlongluo.weather.apis.YahooWeather.java
com.imlongluo.weather.lbs.LocationGetter.java
com.imlongluo.weather.lbs.LocationManagerActivity.java
com.imlongluo.weather.settings.SettingsActivity.java
com.imlongluo.weather.share.ShareActivity.java
com.imlongluo.weather.utils.Constants.java
com.imlongluo.weather.utils.Utils.java