com.chatwingsdk.views.CWChatButton.java Source code

Java tutorial

Introduction

Here is the source code for com.chatwingsdk.views.CWChatButton.java

Source

/*
 * Copyright (C) 2014 ChatWing
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.chatwingsdk.views;

import android.content.Context;
import android.content.Intent;
import android.util.AttributeSet;
import android.view.View;
import android.widget.Button;

import com.chatwingsdk.ChatWing;
import com.chatwingsdk.activities.CWChatActivity;

import org.apache.commons.codec.binary.Hex;
import org.apache.commons.codec.digest.DigestUtils;

/**
 * This class will help to drive you to {@link com.chatwingsdk.activities.CWChatActivity} with little
 * effort. This assumes the existing system has unique user_id. It doesnt have to be real user_id, you
 * can hash as long as it uniquely identify users.
 *
 * @author cuongthai
 */
public class CWChatButton extends Button implements View.OnClickListener {
    private String mUserId;

    @Override
    public void onClick(View view) {
        Intent intent = new Intent(getContext(), CWChatActivity.class);
        intent.putExtra(CWChatActivity.EXTRA_USER_HASH_KEY, mUserId);
        getContext().startActivity(intent);
    }

    public CWChatButton(Context context, AttributeSet attrs) {
        super(context, attrs);
        setOnClickListener(this);
    }

    public void registerUserId(String userId) {
        mUserId = userId;
    }
}