360手机助手 v3.3.0版本的 MD5 值为:127c345ad16bbebee6e347381328afd0

以下内容为反编译后的 ShareActivity.java 源代码,内容仅作参考


package com.qihoo.appstore.activities;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.text.InputFilter;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.text.style.TextAppearanceSpan;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import com.qihoo.appstore.iconmanager.RemoteIconView;
import com.qihoo.freewifi.push.R;
import com.qihoo.speedometer.Config;
import com.qihoo.speedometer.HttpConst;
import com.qihoo.speedometer.measurements.HttpTask;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.regex.Pattern;

public class ShareActivity extends StatFragmentActivity implements View.OnClickListener {

    private static final String f701a = ShareActivity.class.getSimpleName();

    private EditText f702b;
    private ImageView c;
    private ImageView d;
    private TextView e;
    private RemoteIconView f;
    private ProgressDialog g;
    private TextView h;
    private ProgressBar s;
    private String i = Config.INVALID_IP;
    private String j = Config.INVALID_IP;
    private boolean k = false;
    private boolean l = false;
    private Bitmap m = null;
    private final Handler n = new Handler();
    private com.qihoo.appstore.share.u o = null;
    private boolean p = true;
    private String q = Config.INVALID_IP;
    private int r = 0;
    private boolean t = false;

    public int a(String str) {
        int i = 0;
        while (Pattern.compile("[^\\x00-\\xff]", 0).matcher(str).find()) {
            i++;
        }
        int length = str.length() - i;
        return length % 2 != 0 ? i + ((length + 1) / 2) : i + (length / 2);
    }

    public SpannableStringBuilder a(int i) {
        if (i > 10) {
            String format = String.format(getResources().getString(R.string.share_text_left), Integer.valueOf(i));
            SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(format);
            spannableStringBuilder.setSpan(new TextAppearanceSpan(this, R.style.share_text_count_hint), 0, format.length(), 17);
            return spannableStringBuilder;
        }
        if (i < 0 || i > 10) {
            String format2 = String.format(getResources().getString(R.string.share_text_left), 0);
            SpannableStringBuilder spannableStringBuilder2 = new SpannableStringBuilder(format2);
            int indexOf = format2.indexOf(Config.INVALID_IP + 0);
            if (indexOf < 0) {
                return null;
            }
            int length = (Config.INVALID_IP + 0).length();
            spannableStringBuilder2.setSpan(new TextAppearanceSpan(this, R.style.share_text_count_hint), 0, format2.length(), 17);
            spannableStringBuilder2.setSpan(new TextAppearanceSpan(this, R.style.share_text_count_hint1), indexOf, length + indexOf, 17);
            return spannableStringBuilder2;
        }
        String format3 = String.format(getResources().getString(R.string.share_text_left), Integer.valueOf(i));
        SpannableStringBuilder spannableStringBuilder3 = new SpannableStringBuilder(format3);
        int indexOf2 = format3.indexOf(Config.INVALID_IP + i);
        if (indexOf2 < 0) {
            return null;
        }
        int length2 = (Config.INVALID_IP + i).length();
        spannableStringBuilder3.setSpan(new TextAppearanceSpan(this, R.style.share_text_count_hint), 0, format3.length(), 17);
        spannableStringBuilder3.setSpan(new TextAppearanceSpan(this, R.style.share_text_count_hint1), indexOf2, length2 + indexOf2, 17);
        return spannableStringBuilder3;
    }

    public void b(int i) {
        int i2 = R.string.share_failed;
        com.qihoo.appstore.utils.bk.e(f701a, "Weibo error " + i);
        m();
        switch (i) {
            case HttpConst.ERROR_CODE_FAIL_NO_PKG_INFO:
                i2 = R.string.share_auth_failed;
                break;
            case 1003:
                i2 = R.string.share_failed_repeat;
                break;
            case 1004:
                i2 = R.string.share_failed_toolong;
                break;
            case 1008:
            case 1009:
                i2 = R.string.share_auth_need_reauthorize;
                j();
                break;
        }
        if (i2 == -1) {
            return;
        }
        runOnUiThread(new hy(this, i2));
    }

    private void e() {
        this.f.setVisibility(8);
        this.s.setVisibility(0);
        this.n.postDelayed(new ic(this), 1000L);
    }

    private void f() {
        i();
        this.f702b.setText(this.j);
        if (!TextUtils.isEmpty(this.i)) {
            Uri parse = Uri.parse(this.i);
            String scheme = parse.getScheme();
            String str = Config.INVALID_IP;
            if (scheme == null || !scheme.startsWith(HttpTask.TYPE)) {
                this.k = true;
                str = this.i;
            } else {
                this.l = true;
                if (getIntent() != null) {
                    str = getIntent().getStringExtra("share.pic.uri.local");
                }
            }
            if (TextUtils.isEmpty(str)) {
                this.f.a(parse.toString(), R.drawable.default_download);
            } else {
                this.n.post(new id(this, str));
            }
        } else if (this.r == 2) {
            h();
        } else if (this.r == 0) {
            g();
        }
        int a2 = 100 - a(this.j);
        if (a2 <= 0) {
            return;
        }
        this.h.setText(a(a2));
    }

    private void g() {
        this.k = false;
        this.l = true;
        this.i = "http://p3.qhimg.com/t018a713971a484df7e.jpg";
        this.f.a(this.i, R.drawable.default_download);
    }

    private void h() {
        int i = 0;
        try {
            this.i = Config.INVALID_IP;
            File a2 = com.qihoo.appstore.l.b.a.a(com.qihoo.appstore.l.b.a.f1824b);
            if (!a2.isDirectory() && !a2.mkdirs()) {
                this.i = Config.INVALID_IP;
                return;
            }
            this.i = "http://p1.qhimg.com/t0141d24540ced137b6.png";
            this.k = false;
            this.l = true;
            File file = new File(a2.getPath() + "/music_pic.jpg");
            String path = file.getPath();
            if (file.exists()) {
                this.n.post(new ie(this, path));
                return;
            }
            InputStream open = getAssets().open("music_pic.jpg");
            FileOutputStream fileOutputStream = new FileOutputStream(file);
            byte[] bArr = new byte[1444];
            while (true) {
                int read = open.read(bArr);
                if (read == -1) {
                    open.close();
                    fileOutputStream.close();
                    this.n.post(new Cif(this));
                    return;
                }
                i += read;
                fileOutputStream.write(bArr, 0, read);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void i() {
        this.f702b.addTextChangedListener(new ig(this));
        this.f702b.setFilters(new InputFilter[]{new ih(this, 100)});
    }

    private void j() {
        Activity parent = getParent() == null ? this : getParent();
        com.qihoo.appstore.share.a.a(parent, 1).a(parent, (com.qihoo.appstore.share.q) new hx(this), true);
    }

    private boolean k() {
        return a(this.j) > 100;
    }

    private void l() {
        if (this.g == null) {
            this.g = new ProgressDialog(this);
        }
        if (this.g.isShowing()) {
            return;
        }
        this.g.setMessage(getString(R.string.share_sending));
        this.g.setOnCancelListener(new hz(this));
        this.g.show();
    }

    public void m() {
        try {
            if (this.g == null || !this.g.isShowing()) {
                return;
            }
            this.g.dismiss();
        } catch (Exception e) {
        }
    }

    public void a() {
    }

    public void b() {
    }

    public final void c() {
        if (getParent() == null || getParent() != MainActivity.e()) {
            return;
        }
        ((InputMethodManager) getSystemService("input_method")).hideSoftInputFromWindow(this.f702b.getApplicationWindowToken(), 0);
        MainActivity.e().onKeyDown(4, new KeyEvent(0, 4));
    }

    @Override
    public void onActivityResult(int i, int i2, Intent intent) {
        super.onActivityResult(i, i2, intent);
        com.qihoo.appstore.share.a.a(this, 1).a(i, i2, intent);
    }

    @Override
    public void onClick(View view) {
        int id = view.getId();
        if (id != R.id.btn_share) {
            if (id == R.id.icon_sina_weibo) {
                if (!this.o.a()) {
                    j();
                    return;
                } else if (this.p) {
                    this.p = true;
                    this.c.setImageDrawable(getResources().getDrawable(R.drawable.sina_weibo_on));
                    return;
                } else {
                    this.p = true;
                    this.c.setImageDrawable(getResources().getDrawable(R.drawable.sina_weibo_on));
                    return;
                }
            }
            return;
        }
        if (!this.p) {
            Toast.makeText(this, R.string.share_not_select_target, 0).show();
            return;
        }
        if (TextUtils.isEmpty(this.j)) {
            Toast.makeText(this, R.string.share_not_content, 0).show();
            return;
        }
        if (k()) {
            Toast.makeText(this, R.string.share_failed_toolong, 0).show();
        }
        if (!this.o.a()) {
            j();
            return;
        }
        com.qihoo.appstore.share.a a2 = com.qihoo.appstore.share.a.a(this, 1);
        if (this.k) {
            l();
            a2.a(this, this.j + (this.t ? Config.INVALID_IP : this.q), this.i, new hu(this));
        } else if (this.l) {
            l();
            a2.b(this, this.j + (this.t ? Config.INVALID_IP : this.q), this.i, new hv(this));
        } else {
            l();
            a2.a(this, this.j + (this.t ? Config.INVALID_IP : this.q), new hw(this));
        }
    }

    @Override
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        this.mStatTag = "share";
        setContentView(R.layout.share_activity);
        Intent intent = getIntent();
        if (intent != null) {
            this.i = intent.getStringExtra("share.pic.uri");
            this.j = intent.getStringExtra("share.content");
            this.q = intent.getStringExtra("share.content.url");
            this.r = intent.getIntExtra("share.type", 0);
            if (this.q == null) {
                this.q = Config.INVALID_IP;
            }
            if (getPackageName().equalsIgnoreCase(intent.getStringExtra("share.content.package"))) {
                this.t = true;
                this.j = getResources().getString(R.string.share_self_content);
            }
        }
        this.f702b = (EditText) findViewById(R.id.etEdit);
        this.c = (ImageView) findViewById(R.id.icon_sina_weibo);
        this.c.setOnClickListener(this);
        this.d = (ImageView) findViewById(R.id.icon_weixin);
        this.d.setOnClickListener(this);
        this.e = (TextView) findViewById(R.id.btn_share);
        this.e.setOnClickListener(this);
        this.f = (RemoteIconView) findViewById(R.id.image_preview);
        this.f.setOnClickListener(this);
        View findViewById = findViewById(R.id.layout_image_preview);
        if (findViewById != null && com.qihoo.appstore.utils.ct.a(this.i) && this.r == 4) {
            findViewById.setVisibility(8);
        }
        this.s = (ProgressBar) findViewById(R.id.loading_image_RefreshBar);
        this.o = com.qihoo.appstore.share.u.a(this);
        this.h = (TextView) findViewById(R.id.text_count);
        findViewById(R.id.titleScan).setVisibility(8);
        findViewById(R.id.titleSearch).setVisibility(8);
        findViewById(R.id.titleIcon).setVisibility(8);
        View findViewById2 = findViewById(R.id.titleBack);
        findViewById2.setVisibility(0);
        findViewById2.setOnClickListener(new ht(this));
        ((TextView) findViewById(R.id.titleText)).setText(R.string.share_title);
        f();
        if (intent != null && this.r == 3 && (TextUtils.isEmpty(this.i) || TextUtils.isEmpty(this.q))) {
            this.l = true;
            String stringExtra = intent.getStringExtra("share.content.package");
            if (!TextUtils.isEmpty(stringExtra)) {
                new ia(this, stringExtra).execute(new Void[0]);
            }
            e();
        }
        this.f702b.requestFocus();
        this.f702b.setSelection(0);
        this.n.postDelayed(new ib(this, (InputMethodManager) getSystemService("input_method")), 500L);
        View findViewById3 = findViewById(R.id.switcher);
        if (findViewById3 != null) {
            findViewById3.setVisibility(8);
        }
    }

    @Override
    public boolean onKeyDown(int i, KeyEvent keyEvent) {
        if (i == 82) {
            return true;
        }
        if (i == 4 && this.f702b.isFocused()) {
            c();
            return true;
        }
        if (i != 84) {
            return super.onKeyDown(i, keyEvent);
        }
        return true;
    }
}