新大陆云平台配置(2)

简介: 云平台登陆代码详解开启应用登陆云平台


开启应用

效果如图所示:

image.png

image.png

首先位Switch控件建造一些自定义view,在drawable文件夹下建立六个文件,分别位:open_track,open_thumb,close_track,close_thumb;track,thumb

open_track代码如下:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
        <!-- 高度30   此处设置宽度无效-->
        <size android:height="40dp"/>
        <!-- 圆角弧度 15 -->
        <corners android:radius="15dp"/>
        <!-- 变化率  定义从左到右的颜色不变 -->
        <gradient
            android:endColor="#66ff33"
            android:startColor="#66ff33" />
</shape>

close_track代码如下:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <size android:height="40dp" android:width="40dp"/>
    <corners android:radius="20dp"/>
    <gradient android:startColor="#eeeeee"
        android:endColor="#eeeeee"/>
    <stroke android:width="1dp"
            android:color="#666666"/>
</shape>

open_thumb代码如下:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle" >
    <!-- 高度40 -->
    <size android:height="40dp" android:width="40dp"/>
    <!-- 圆角弧度 20 -->
    <corners android:radius="20dp"/>
    <!-- 变化率 -->
    <gradient
        android:endColor="#eeeeee"
        android:startColor="#eeeeee" />
    <stroke android:width="1dp"
        android:color="#33da33"/>
</shape>

close_thumb代码如下:

<shape xmlns:android="http://schemas.android.com/apk/res/android">
        android:shape="rectangle" >
    <size android:height="40dp" android:width="40dp"/>
    <!-- 圆角弧度 20 -->
    <corners android:radius="20dp"/>
    <!-- 变化率 -->
    <gradient
        android:endColor="#eeeeee"
        android:startColor="#eeeeee" />
    <stroke android:width="1dp"
        android:color="#666666"/>
</shape>

track代码如下:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_checked="true" android:drawable="@drawable/open_track"/>
    <item android:drawable="@drawable/shut_track"/>
</selector>

thumb代码如下:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_checked="true" android:drawable="@drawable/open_thumb"/>
    <item android:drawable="@drawable/shut_thumb"/>
</selector>

最后应用到布局中

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@drawable/background1">
    <ImageView
        android:layout_width="150dp"
        android:layout_height="150dp"
        android:src="@drawable/home"
        android:layout_gravity="center"
        android:layout_marginTop="100dp"/>
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="智能家居"
        android:textSize="30sp"
        android:layout_gravity="center"
        android:layout_marginLeft="100dp"
        android:textColor="#00ffcc"
        android:layout_marginTop="20dp"
        />
    <Switch
        android:id="@+id/Open"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:thumb="@drawable/thumb"
        android:track="@drawable/track"
        android:layout_gravity="center"
        android:layout_marginTop="50dp"/>
</LinearLayout>


登陆云平台

建造一个Login活动

效果图如下图所示:

image.png

点击旁边的小眼睛可以查看密码

image.png

login.xml代码如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@drawable/background">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:orientation="vertical">
        <ImageView
            android:layout_width="150dp"
            android:layout_height="100dp"
            android:layout_gravity="center"
            android:layout_marginTop="50dp"
            android:layout_marginLeft="20dp"
            android:src="@drawable/home"
            android:scaleType="fitStart"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="智能家居"
            android:gravity="center"
            android:layout_gravity="center"
            android:textSize="30sp"
            android:textColor="#000000"
            android:layout_marginBottom="30dp"
            android:layout_marginTop="10dp"/>
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_marginBottom="10dp">
        <TextView
            android:layout_width="100dp"
            android:layout_height="50dp"
            android:text="账 号:"
            android:textSize="25sp"
            android:textColor="#000000"/>
        <EditText
            android:id="@+id/username"
            android:layout_width="250dp"
            android:layout_height="50dp"
            android:background="@drawable/passwordbox"
            android:hint="用户名"
            android:paddingLeft="20dp"
            android:textColor="#ff000000"
            android:textSize="20sp"
            android:layout_marginLeft="0dp"/>
    </LinearLayout>
    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="#000000" />
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="60dp"
        >
        <TextView
            android:id="@+id/TipsPassWord"
            android:layout_width="100dp"
            android:layout_height="50dp"
            android:text="密 码:"
            android:textSize="25sp"
            android:textColor="#000000"
            android:layout_marginLeft="0dp"
            android:layout_marginTop="10dp"/>
        <EditText
            android:id="@+id/password"
            android:layout_width="250dp"
            android:layout_height="50dp"
            android:background="@drawable/passwordbox"
            android:hint="密    码"
            android:paddingLeft="22dp"
            android:textColor="#ff000000"
            android:textSize="20sp"
            android:password="true"
            android:layout_toRightOf="@+id/TipsPassWord"
            android:layout_marginTop="10dp"/>
        <ImageView
            android:id="@+id/notseethepassword"
            android:layout_width="60dp"
            android:layout_height="50dp"
            android:scaleType="fitCenter"
            android:background="@drawable/passwordbox"
            android:layout_toRightOf="@+id/password"
            android:layout_marginTop="10dp"/>
        <!--<ImageButton
            android:id="@+id/seethepassword"
            android:layout_width="60dp"
            android:layout_height="50dp"
            android:src="@mipmap/openeye"
            android:scaleType="fitCenter"
            android:background="#ffffff"
            android:layout_marginLeft="320dp"
            android:visibility="invisible"
            />-->
    </RelativeLayout>
    <Button
        android:id="@+id/login"
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:layout_gravity="center"
        android:text="登 陆"
        android:textColor="#ffffffff"
        android:textSize="20sp"
        android:background="@drawable/login"
        android:layout_marginTop="10dp"
        />
</LinearLayout>

先看一下怎么变小眼睛的代码

定一个boolean变量,用于判断是否显示密码

private boolean Smalleye = true;
private void OnClick(){
        OnClick onClick = new OnClick();
        Login.setOnClickListener(onClick);
        //SeeThePassWord.setOnClickListener(onClick);
        NotSeePassWord.setOnClickListener(onClick);
    }
    private class OnClick implements View.OnClickListener{
        @Override
        public void onClick(View v) {
            switch (v.getId()){
                case R.id.login:
                    SignIn();
                   break;
                case R.id.notseethepassword:
                    if (Smalleye == true)
                    {
                        SeeThePassWordMethod(); //显示密码
                        Smalleye = !Smalleye;
                    }else {
                        NotSeeThePassWordMethod(); //隐藏密码
                        Smalleye = !Smalleye;
                    }
                    break;
            }
        }
    }
    private void NotSeeThePassWordMethod(){
        NotSeePassWord.setImageResource(R.drawable.closeeye);
       PassWord.setTransformationMethod(PasswordTransformationMethod.getInstance());
    }
    private void SeeThePassWordMethod(){
        NotSeePassWord.setImageResource(R.drawable.openeye);
      PassWord.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
    }

下面为登陆云平台代码:

private void SignIn(){
        String platformAddress = NewloadParameter.IP_DEFAULT_VALUE;  //网址加端口号
        String LoginUserName = UserName.getText().toString();
        String LoginPassWord = PassWord.getText().toString();
        if (TextUtils.isEmpty(platformAddress)){
            Toast.makeText(this,"请配置新大陆云平台信息",Toast.LENGTH_SHORT).show();
            return;
        }
        if (TextUtils.isEmpty(LoginUserName) || TextUtils.isEmpty(LoginPassWord)){
            Toast.makeText(this,"账号或者密码不能为空",Toast.LENGTH_SHORT).show();
            return;
        }
        NetWorkBusiness netWorkBusiness = new NetWorkBusiness("",platformAddress);
        netWorkBusiness.signIn(new SignIn(LoginUserName, LoginPassWord), new NCallBack<BaseResponseEntity<User>>(getApplicationContext()) {
            @Override
            protected void onResponse(BaseResponseEntity<User> response) {
            }
            @Override
            public void onResponse(Call<BaseResponseEntity<User>> call, Response<BaseResponseEntity<User>> response) {
                super.onResponse(call, response);
                BaseResponseEntity<User> baseResponseEntity = response.body(); //获取请求
                if (baseResponseEntity != null){
                    //获取访问令牌
                    String accestoken = baseResponseEntity.getResultObj().getAccessToken();
                    Intent intent = new Intent(Login.this,MainActivity.class);
                    Bundle bundle = new Bundle();
                    bundle.putString("accestoken",accestoken);
                    intent.putExtras(bundle); // 传递令牌
                    startActivity(intent);
                    finish();
                }
            }
        });
  }

下面为全部代码:

package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.text.method.HideReturnsTransformationMethod;
import android.text.method.PasswordTransformationMethod;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.Toast;
import cn.com.newland.nle_sdk.requestEntity.SignIn;
import cn.com.newland.nle_sdk.responseEntity.User;
import cn.com.newland.nle_sdk.responseEntity.base.BaseResponseEntity;
import cn.com.newland.nle_sdk.util.NCallBack;
import cn.com.newland.nle_sdk.util.NetWorkBusiness;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
public class Login extends AppCompatActivity {
    private Button Login;
    private EditText UserName,PassWord;
    private ImageView NotSeePassWord;
    private boolean Smalleye = true;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login2);
        InitView();
        OnClick();
       NotSeePassWord.setImageResource(R.drawable.closeeye);
    }
    private void InitView(){
        Login = findViewById(R.id.login);
        UserName = findViewById(R.id.username);
        PassWord = findViewById(R.id.password);
       // SeeThePassWord = findViewById(R.id.seethepassword);
        NotSeePassWord = findViewById(R.id.notseethepassword);
    }
    private void OnClick(){
        OnClick onClick = new OnClick();
        Login.setOnClickListener(onClick);
        //SeeThePassWord.setOnClickListener(onClick);
        NotSeePassWord.setOnClickListener(onClick);
    }
    private class OnClick implements View.OnClickListener{
        @Override
        public void onClick(View v) {
            switch (v.getId()){
                case R.id.login:
                    SignIn();
                   break;
                case R.id.notseethepassword:
                    if (Smalleye == true)
                    {
                        SeeThePassWordMethod();
                        Smalleye = !Smalleye;
                    }else {
                        NotSeeThePassWordMethod();
                        Smalleye = !Smalleye;
                    }
                    break;
            }
        }
    }
    private void NotSeeThePassWordMethod(){
        NotSeePassWord.setImageResource(R.drawable.closeeye);
        PassWord.setTransformationMethod(PasswordTransformationMethod.getInstance());
    }
    private void SeeThePassWordMethod(){
        NotSeePassWord.setImageResource(R.drawable.openeye);
       PassWord.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
    }
    private void SignIn(){
        String platformAddress = NewloadParameter.IP_DEFAULT_VALUE;  //网址加端口号
        String LoginUserName = UserName.getText().toString();
        String LoginPassWord = PassWord.getText().toString();
        if (TextUtils.isEmpty(platformAddress)){
            Toast.makeText(this,"请配置新大陆云平台信息",Toast.LENGTH_SHORT).show();
            return;
        }
        if (TextUtils.isEmpty(LoginUserName) || TextUtils.isEmpty(LoginPassWord)){
            Toast.makeText(this,"账号或者密码不能为空",Toast.LENGTH_SHORT).show();
            return;
        }
        NetWorkBusiness netWorkBusiness = new NetWorkBusiness("",platformAddress);
        netWorkBusiness.signIn(new SignIn(LoginUserName, LoginPassWord), new NCallBack<BaseResponseEntity<User>>(getApplicationContext()) {
            @Override
            protected void onResponse(BaseResponseEntity<User> response) {
            }
            @Override
            public void onResponse(Call<BaseResponseEntity<User>> call, Response<BaseResponseEntity<User>> response) {
                super.onResponse(call, response);
                BaseResponseEntity<User> baseResponseEntity = response.body(); //获取请求
                if (baseResponseEntity != null){
                    //获取访问令牌
                    String accestoken = baseResponseEntity.getResultObj().getAccessToken();
                    Intent intent = new Intent(Login.this,MainActivity.class);
                    Bundle bundle = new Bundle();
                    bundle.putString("accestoken",accestoken);
                    intent.putExtras(bundle); // 传递令牌
                    startActivity(intent);
                    finish();
                }
            }
        });
  }
}

我一开始用AVD运行程序,运行不了,然后用雷电模拟器运行了然后登陆成功了。

然后就可以在云平台开发者中心看见自己创建的应用上线成功了

相关文章
|
7月前
|
安全 API 数据安全/隐私保护
云安全中心-云平台配置检查CIEM查询到的Ram相关的检查项,能否在阿里云OpenAPI查到同样的?
云安全中心-云平台配置检查CIEM查询到的Ram相关的检查项,能否在阿里云OpenAPI查到同样的?
69 1
|
域名解析 缓存 运维
|
存储 安全 Linux
创建云平台 8 Day____________**安装和配置红帽企业 Linux 和 CentOS**
创建云平台 8 Day____________**安装和配置红帽企业 Linux 和 CentOS**
118 0
创建云平台 8 Day____________**安装和配置红帽企业 Linux 和 CentOS**
|
关系型数据库 MySQL API
搭建云平台5 Day_________如何在控制器节点上安装和配置代号为 nova 的计算服务
搭建云平台5 Day_________如何在控制器节点上安装和配置代号为 nova 的计算服务
116 0
搭建云平台5 Day_________如何在控制器节点上安装和配置代号为 nova 的计算服务
|
前端开发 关系型数据库 MySQL
搭建云平台 3 Day _______**如何安装配置云计算的认证服务**
搭建云平台 3 Day _______**如何安装配置云计算的认证服务**
158 0
搭建云平台 3 Day _______**如何安装配置云计算的认证服务**
|
开发工具 Android开发
新大陆云平台配置(1)
下载云平台Android–SDK 云平台Android–SDK下载
313 0
新大陆云平台配置(1)
|
JavaScript
将阿里云上的nodejs应用配置成SAP云平台上destination的目的地之后
一日突发奇想,将阿里云上一个nodejs应用配置成SAP WebIDE里的Destination指向的url:
将阿里云上的nodejs应用配置成SAP云平台上destination的目的地之后
|
安全
SAP云平台和SAP C4C之间的OAuth2.0配置
SAP云平台和SAP C4C之间的OAuth2.0配置
SAP云平台和SAP C4C之间的OAuth2.0配置
如何将SAP UI5应用配置到SAP云平台Fiori Launchpad里
如何将SAP UI5应用配置到SAP云平台Fiori Launchpad里
101 0
如何将SAP UI5应用配置到SAP云平台Fiori Launchpad里
|
8月前
|
机器学习/深度学习 Kubernetes Cloud Native
SAP 云平台 (Cloud Platform) 架构概述
SAP 云平台 (Cloud Platform) 架构概述
170 1