Project

Profile

Help

HostedRedmine.com has moved to the Planio platform. All logins and passwords remained the same. All users will be able to login and use Redmine just as before. Read more...

Task #624224 » 调用相机切换头像.txt

子琛 郝, 2016-12-25 08:25 AM

 
package com.example.administrator.missphoto;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.text.TextUtils;
import android.view.View;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.sharesdk.onekeyshare.OnekeyShare;

public class PersonnalMessage extends FirstActivity {
private String urlPath2;
private URL url;
private EditText passWord;
private EditText userName;
private TextView uaccount;
private TextView uname;
private String name,account;
String responseData = "";
private Button personnal_mine;
private TextView fanhui;
private TextView fenxiang;
private Button tuichu;
private ImageView personnal_touxiang;
private static final int IMAGE = 1;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.personnal_message);
personnal_touxiang = (ImageView) findViewById(R.id.personal_touxiang);
uaccount = (TextView) findViewById(R.id.personal_uaccount);
uname = (TextView) findViewById(R.id.personal_username);
fanhui = (TextView) findViewById(R.id.personal_fanhui);
fenxiang = (TextView) findViewById(R.id.personal_fenxiang);
tuichu = (Button) findViewById(R.id.personal_tuichu);

tuichu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = new Intent();
i.setClass(PersonnalMessage.this, FirstActivity.class);
startActivity(i);
}
});
fanhui.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = new Intent();
i.setClass(PersonnalMessage.this, MainActivity.class);
startActivity(i);
}
});
fenxiang.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View view) {

OnekeyShare oks = new OnekeyShare();
//?ر?sso??Ȩ
oks.disableSSOWhenAuthorize();
// title???⣬ӡ??ʼǡ????䡢??Ϣ??΢?š?????????QQ??QQ?ռ?ʹ??
oks.setTitle("????");
// titleUrl?DZ???????????ӣ?????Linked-in,QQ??QQ?ռ?ʹ??
oks.setTitleUrl("http://sharesdk.cn");
// text?Ƿ????ı???????ƽ̨????Ҫ????ֶ?
oks.setText("???Ƿ????ı?");
//????????ͼƬ??????΢??????????ͼƬ??Ҫͨ????˺?????߼?д??ӿڣ???????ע?͵?????????΢??
oks.setImageUrl("http://f1.sharesdk.cn/imgs/2014/02/26/owWpLZo_638x960.jpg");
// imagePath??ͼƬ?ı???·????Linked-In?????ƽ̨??֧?ִ˲???
//oks.setImagePath("/sdcard/test.jpg");//ȷ??SDcard??????ڴ???ͼƬ
// url????΢?ţ????????Ѻ?????Ȧ????ʹ??
oks.setUrl("http://sharesdk.cn");
// comment???Ҷ??????????????ۣ?????????????QQ?ռ?ʹ??
oks.setComment("???Dz????????ı?");
// site?Ƿ????????ݵ???վ???ƣ?????QQ?ռ?ʹ??
oks.setSite("ShareSDK");
// siteUrl?Ƿ????????ݵ???վ??ַ??????QQ?ռ?ʹ??
oks.setSiteUrl("http://sharesdk.cn");

// ????????GUI
oks.show(getBaseContext());
}
});
SharedPreferences preferences = getSharedPreferences("user", Context.MODE_PRIVATE);
String name = preferences.getString("name", "name");
String account = preferences.getString("account", "account");
uaccount.setText(account);
uname.setText(name);
}
public void onClick(View v) {
//???????
Intent intent = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, IMAGE);
}

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
//??ȡͼƬ·??
if (requestCode == IMAGE && resultCode == Activity.RESULT_OK && data != null) {
Uri selectedImage = data.getData();
String[] filePathColumns = {MediaStore.Images.Media.DATA};
Cursor c = getContentResolver().query(selectedImage, filePathColumns, null, null, null);
c.moveToFirst();
int columnIndex = c.getColumnIndex(filePathColumns[0]);
String imagePath = c.getString(columnIndex);
showImage(imagePath);
c.close();
}
}

//????ͼƬ
private void showImage(String imaePath){
Bitmap bm = BitmapFactory.decodeFile(imaePath);
personnal_touxiang.setImageBitmap(bm);
}

}
    (1-1/1)