Android: Change your avatar and save with Bmob (shown as a circle)

Source: Internet
Author: User

Write a project these days before writing the login registration interface is not related to the Avatar and database so it is better to achieve this with the Avatar part can be implemented and the third-party database on the Internet third-party database I am using Bmob bmob Home
It's convenient, let's take a look at the results

So there's actually a lot of stuff in there.
So this blog is going to show you how to do this in a few ways.
1 bmob Basic configuration and the use of registered logins
2 Click the Edit button to appear in the album and then display it to the original avatar position after selecting one
3 Avatar set to circle Select a new avatar no matter what shape can be displayed as a circle
4 Uploading Avatar to Bmob
5 think the bottom two buttons look good (I think it looks good) um, the implementation of the border

OK, let's get started:
The use of a bmob base configuration and Registration login
Bmob's homepage has a link to register an account first and then first use the Android Bmob Quick Start
This is mainly about the first time you need to configure the use of something to be aware of
It's very detailed, but there are a lot of places to watch
I'm writing about some of the problems I've encountered.
1. Be aware that as is not required to copy the package, just write the code in the build.
But do not import the package to repeat, such as his big bag contains the text message service that, no need to write the writing will be wrong
2 Be sure to add a statement that allows networking operations in the configuration file
3 Be sure to initialize the Bmob is to put the key in their own oncreat () inside
Well, it's just the beginning.
Down is to use Bmob bmob Android Development Documentation
Development documentation very detailed I'll take a look at my registration for this project as an example to see how I use it.
First of all, my users in addition to the user name and password also need the mailbox picture phone and other information
So I inherited Bmobuser and wrote my own user class.
Note the user name and password are not required to be rewritten

 Public  class ipetuser extends bmobuser {    PrivateString Emile;PrivateInteger Mobile;PrivateBmobfile image; Public void Setemile(String Emile) { This. Emile = Emile; } Public void Setmobile(Integer Mobile) { This. mobile = Mobile; } PublicStringGetemile() {returnEmile } PublicIntegerGetmobile() {returnMobile } Public void setimage(Bmobfile image) { This. image = Image; } PublicBmobfileGetImage() {returnImage }}

The Avatar uses the Bmobfile type
As for how to make a talk about Avatar upload and look at

 IpetUser user = new IpetUser();

You can then put the information you entered by using the User.set () method
Again through the User.signup () registration is very simple
This part will be here if there are any problems to discuss
two. Click the Edit button to display the photo album and select one before displaying it to the original avatar position.
I am using the system to bring my own album
In the Modify button, a intent object is built first
and designate his ACTION as intent.action_get_content.
Then set the necessary parameters through Startactivityforresult (intent, 1); method to open the photo album program Select photos
Check the code.

 modify_head.setOnClickListener(new View.OnClickListener() {            @Override            publicvoidonClick(View v) {                new Intent();                /* 开启Pictures画面Type设定为image */                intent.setType("image/*");                /* 使用Intent.ACTION_GET_CONTENT这个Action */                intent.setAction(Intent.ACTION_GET_CONTENT);                /* 取得相片后返回本画面 */                1);            }        });

So the point is in startActivityForResult(intent, 1); there.

  protected void Onactivityresult(intRequestcode,intResultCode, Intent data) {if(ResultCode = = RESULT_OK)            {URI uri = Data.getdata (); Path = Getimagepath (URI,NULL); Contentresolver CR = This. Getcontentresolver ();Try{LOG.E ("Qwe", path.tostring ()); Bitmap Bitmap = Bitmapfactory.decodestream (Cr.openinputstream (URI));/ * Set Bitmap to ImageView * /Res_head.setimagebitmap (bitmap); }Catch(FileNotFoundException e) {LOG.E ("Qwe", E.getmessage (), E); }        }Super. Onactivityresult (Requestcode, ResultCode, data); }PrivateStringGetimagepath(Uri Uri, String seletion) {String Path =NULL; cursor cursor = getcontentresolver (). Query (URI,NULL, Seletion,NULL,NULL);if(Cursor! =NULL) {if(Cursor.movetofirst ())            {Path = cursor.getstring (Cursor.getcolumnindex (MediaStore.Audio.Media.DATA));        } cursor.close (); }returnPath }

It is important to note that path is the true path of the picture because it requires a real path when uploading
three. Set the avatar to a circle Select a new avatar no matter what shape can be displayed as a circle
This was meant to be written by myself, but there were some problems in the process, so I used a git
Very convenient
Use the steps like this
1. Inside the Gradle

dependencies {    ...    ‘de.hdodenhof:circleimageview:2.0.0‘}

2 use in XML this is the same as ImageView. The last two attributes are the one that can be used to frame a picture.

<de.hdodenhof.circleimageview.CircleImageView    xmlns:app="http://schemas.android.com/apk/res-auto"    android:id="@+id/head_image"    android:layout_width="120dp"    android:layout_height="120dp"    android:src="@mipmap/cat"    android:layout_centerHorizontal="true"    android:layout_marginTop="60dp"    app:civ_border_width="0.5dp"    app:civ_border_color="#4a9bec" />

In the Java code, this

 res_head = (CircleImageView)findViewById(R.id.head_image);

Well, I'm ready for a while.
Well, that's going to happen.
four uploading avatar to Bmob
Ernenennenenen I've been stuck here all night. Print out the reason for each volume is always filename empty
Take a look at the steps,
1 Adding an image column on Bmob
2 Constructing Bmobfile types

file=new BmobFile(Susername,null,newFile(path).toString());

3 Set in user.setImage(file);
Ok!!!!!!!!!!!!!
But yesterday, I had a problem. Only one parameter is passed in the constructed type
So you can look at the construction method and try it over and over again until you get all three parameters in order to register a success.
Look at the database that was not registered before

After

And then there's the column. Image that column only stores the filename image in the file

probably implemented in the Bmob store picture
Five. I think I wrote a button that looks good.

  <Button            android:id="@+id/registre_button_signup"            android:layout_weight="10"            android:layout_width="0dp"            android:textSize="15dp"            android:hint="Sign up"            android:background="@drawable/sign_button"            android:layout_height="40dp" />

Sign_button selector because clicks are effective

<?xml version= "1.0" encoding= "Utf-8"?  <selector  xmlns:android  = "http://schemas.android.com/apk/res/android" ;  <item  android:state_pressed  =< Span class= "Hljs-value" > "false"  android:drawable  =" @drawable/sign_seletor_nopressed "/> < item  android:state_pressed  = "true"  android:drawable  =" @drawable/sign_seletor_pressed "/>  </selector ;  

Sign_seletor_nopressed

<?xml version= "1.0" encoding= "UTF-8"?><layer-list xmlns:android="Http://schemas.android.com/apk/res/android">     <!--box color values --<item>    <shape>        <solid android:color="#17abe3" />        <corners Android:radius="20DP" />    </shape></Item>    <!--body background color values --    <item android:bottom="1DP" android:right="1DP" Android : Top="1DP" android:left="1DP">        <shape>            <gradient  android: StartColor  = "#ffffff"  android:centercolor  = "#ffffff"  android:endcolor  =
     
       "#ffffff" 
      android:type  = "Linear"  android:angle  = "all"  
    
     android:centerx  =
      "0.5"  
     android:centery  =
      "0.5" /> 
                <padding android:left="2DP" android:top="2DP" android: right ="2DP"android:bottom="2DP" />                            <!--should be rounded --and            <corners Android:radius="20DP" />        </shape>    </Item></layer-list>

Sign_seletor_pressed

<?xml version= "1.0" encoding= "UTF-8"?><layer-list xmlns:android="Http://schemas.android.com/apk/res/android">     <!--box color values --<item>    <shape>        <solid android:color="#17abe3" />        <corners Android:radius="20DP" />    </shape></Item>    <!--body background color values --    <item android:bottom="1DP" android:right="1DP" Android : Top="1DP" android:left="1DP">        <shape>            <gradient  android: StartColor  = "#7bbfea"  android:centercolor  = "#7bbfea"  android:endcolor  =
     
       "#7bbfea" 
      android:type  = "Linear"  android:angle  = "all"  
    
     android:centerx  =
      "0.5"  
     android:centery  =
      "0.5" /> 
                <padding android:left="2DP" android:top="2DP" android: right ="2DP"android:bottom="2DP" />                            <!--should be rounded --and            <corners Android:radius="20DP" />        </shape>    </Item></layer-list>

This part over.

Oh oh oh oh oh oh oh oh oh oh oh a little messy
But next time I will be able to write an avatar registration login!

Android: Change your avatar and save with Bmob (shown as a circle)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.